/* OrderCounter Video — phone-first meetings app.
   App shell: left sidebar (collapses to a top bar + drawer on phones) and a
   content area that switches between a LOBBY view and an IN-MEETING view.
   Dark theme + CSS variables preserved from the original test page. The
   in-meeting video UI (stage / strip / tiles / transcript / scribe) keeps the
   same ids/classes the engine drives. */

:root {
  color-scheme: dark;
  --bg: #0f1115;
  --panel: #161a22;
  --panel-2: #1b2029;
  --line: #283041;
  --text: #e8eaed;
  --muted: #9aa0a6;
  --accent: #ee572c;
  --danger: #e5484d;
  --radius: 10px;
  --sidebar-w: 232px;
  --bar-h: 52px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  /* themeable surfaces — dark defaults; overridden by .ocv-light */
  --stage-bg: #000;
  --hover: var(--hover);
  --avatar-bg: radial-gradient(circle at 50% 40%, #38405a, #1b2029);
  --avatar-text: #fff;
  --shadow: var(--shadow);
  --rec-bg: rgba(229,72,77,.16);
  --rec-text: #ffb4b6;
  --log-bg: #0a0c10;
  --log-text: #b7c0cd;
}

/* Light theme — blends into the Partner Portal (orange + grayscale on white).
   Activated by html.ocv-light (set from ?theme=light / implied by ?embed=1). */
.ocv-light {
  color-scheme: light;
  --bg: #fafbfc;
  --panel: #ffffff;
  --panel-2: #f4f5f8;
  --line: #e5e7eb;
  --text: #1f2430;
  --muted: #6b7280;
  --accent: #ee572c;
  --danger: #e5484d;
  --stage-bg: #e6eaef;
  --hover: #e9edf2;
  --avatar-bg: radial-gradient(circle at 50% 40%, #eef1f5, #cfd6df);
  --avatar-text: #434a58;
  --shadow: rgba(17,20,24,.18);
  --rec-bg: rgba(229,72,77,.12);
  --rec-text: #b3261e;
  --log-bg: #f4f5f8;
  --log-text: #434a58;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden; /* no page scroll; views manage their own scroll */
}

/* ---------- buttons (shared) ---------- */
button { font: inherit; cursor: pointer; border-radius: 8px; border: 1px solid transparent; color: var(--text); }
button:disabled { opacity: .45; cursor: default; }
.btn { padding: .6rem 1rem; font-size: .9rem; font-weight: 600; background: var(--panel-2); border: 1px solid var(--line); }
.btn:hover:not(:disabled) { background: var(--hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); }
.link-btn { background: none; border: none; color: var(--muted); font-size: .8rem; padding: .2rem 0; text-align: left; }
.link-btn:hover { color: var(--text); }
.icon-btn {
  background: transparent; border: 1px solid transparent; color: var(--text);
  width: 40px; height: 40px; min-width: 40px; font-size: 1.25rem; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center; border-radius: 9px;
}
.icon-btn:hover { background: var(--panel-2); }

/* ---------- app shell ---------- */
#appShell { display: flex; height: 100%; width: 100%; }

/* Embedded in a host page (Partner Portal "Video Meetings" tab via iframe): the
   host supplies its own nav chrome, so hide our sidebar/mobile bar and let the
   content fill the frame. Activated by the ?embed=1 boot param. */
.ocv-embed #sidebar,
.ocv-embed #mobileBar { display: none !important; }

#mobileBar { display: none; }
#navBackdrop {
  position: fixed; inset: 0; background: var(--shadow); z-index: 40;
}

#sidebar {
  flex: 0 0 var(--sidebar-w); width: var(--sidebar-w);
  background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 1rem .75rem;
  padding-top: calc(1rem + var(--safe-t));
}
#sidebar .brand { font-weight: 800; font-size: 1.05rem; letter-spacing: .01em; padding: .3rem .5rem .9rem; }
#sidebar .brand span { color: var(--accent); margin-left: .28em; }
.nav-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .25rem; }
.nav-item {
  width: 100%; text-align: left; background: transparent; border: 1px solid transparent;
  padding: .7rem .7rem; font-size: .92rem; border-radius: 9px; display: flex; align-items: center; gap: .6rem;
  min-height: 44px;
}
.nav-item:hover { background: var(--panel-2); }
.nav-item.active { background: var(--panel-2); border-color: var(--line); color: #fff; }
.nav-ico { font-size: 1.05rem; opacity: .9; }
.nav-foot { margin-top: auto; color: var(--muted); font-size: .68rem; padding: .5rem; line-height: 1.4; }

#content { flex: 1; min-width: 0; min-height: 0; position: relative; overflow: hidden; }
.view { position: absolute; inset: 0; display: flex; flex-direction: column; }
.view[hidden] { display: none; }

/* ---------- lobby view ---------- */
#lobbyView { overflow: auto; }
.lobby-wrap { max-width: 680px; margin: 0 auto; width: 100%; padding: 1.4rem 1.1rem calc(2rem + var(--safe-b)); }
.lobby-h { font-size: 1.5rem; margin: .2rem 0 1.1rem; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem 1.05rem; margin-bottom: 1rem;
}
.card-h { font-size: 1rem; margin: 0 0 .7rem; }
.card-h-row { display: flex; align-items: baseline; justify-content: space-between; gap: .5rem; margin-bottom: .6rem; }
.card-h-row .card-h { margin: 0; }
.field { display: flex; flex-direction: column; gap: .3rem; }
.field.inline { flex-direction: row; align-items: center; gap: .5rem; }
.field-label { font-size: .74rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.field-hint { color: var(--muted); font-size: .76rem; margin: .5rem 0 0; }
input[type="text"], select {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: .65rem .65rem; font-size: .95rem; width: 100%; min-height: 44px;
}
input[type="text"]:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }

.new-meeting-row { display: flex; gap: .6rem; }
.new-meeting-row input { flex: 1; }
.new-meeting-row .btn { flex: 0 0 auto; white-space: nowrap; }
.adv-panel { margin-top: .7rem; padding-top: .7rem; border-top: 1px solid var(--line); }
.adv-panel .field.inline .field-label { white-space: nowrap; }
.adv-panel select { max-width: 18rem; }
.inline-msg { margin-top: .6rem; font-size: .82rem; }
.inline-msg.err { color: var(--danger); }
.inline-msg.ok { color: #22c55e; }

.list-status { font-size: .72rem; color: var(--muted); }
.meeting-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .55rem; }
.meeting-row {
  display: flex; align-items: center; gap: .8rem; padding: .75rem .85rem;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 9px;
}
.meeting-row .mr-main { flex: 1; min-width: 0; }
.meeting-row .mr-title { font-weight: 600; font-size: .95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meeting-row .mr-meta { color: var(--muted); font-size: .76rem; margin-top: .2rem; }
.meeting-row .mr-meta .dot { margin: 0 .35em; opacity: .6; }
.meeting-row .join-btn {
  flex: 0 0 auto; background: var(--accent); border-color: var(--accent); color: #fff;
  padding: .55rem 1.15rem; font-weight: 600; font-size: .9rem; border-radius: 8px; min-height: 44px;
}
.meeting-row .join-btn:hover { filter: brightness(1.08); }
.empty-state { color: var(--muted); font-size: .85rem; padding: .4rem .2rem; }

/* ---------- in-meeting view ---------- */
#meetingView { background: var(--bg); }
#meetingHeader {
  display: flex; align-items: center; gap: .6rem; padding: .5rem .8rem;
  padding-top: calc(.5rem + var(--safe-t));
  background: var(--panel); border-bottom: 1px solid var(--line); flex: 0 0 auto;
}
.mh-titles { min-width: 0; flex: 1; }
.mh-title { font-weight: 700; font-size: .98rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mh-sub { color: var(--muted); font-size: .76rem; }
.rec-pill {
  display: inline-flex; align-items: center; gap: .4rem; flex: 0 0 auto;
  background: var(--rec-bg); border: 1px solid var(--danger); color: var(--rec-text);
  padding: .3rem .6rem; border-radius: 999px; font-size: .78rem; font-variant-numeric: tabular-nums;
}
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: recblink 1s steps(2,start) infinite; }
@keyframes recblink { 50% { opacity: .25; } }

#meetingBody { flex: 1; min-height: 0; display: flex; flex-direction: row; }
#meetingMain { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; }

/* ---- stage ---- */
#stageArea {
  flex: 1; min-height: 0; position: relative; margin: .6rem .8rem 0;
  background: var(--stage-bg); border-radius: var(--radius); overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
.stage-empty { color: var(--muted); font-size: .9rem; }
#stageTile { position: absolute; inset: 0; }
#stageTile video { width: 100%; height: 100%; object-fit: contain; background: var(--stage-bg); }
.stage-label {
  position: absolute; left: .6rem; bottom: .6rem; font-size: .8rem;
  background: rgba(0,0,0,.55); padding: .2rem .5rem; border-radius: 6px;
}

/* ---- participant strip ---- */
#strip {
  display: flex; gap: .6rem; padding: .6rem .8rem; overflow-x: auto; align-items: stretch;
  min-height: 120px; flex: 0 0 auto;
}
#remotes { display: contents; }
.tile {
  position: relative; flex: 0 0 auto; width: 180px; aspect-ratio: 4 / 3;
  background: var(--stage-bg); border-radius: var(--radius); overflow: hidden;
  border: 2px solid transparent; cursor: pointer;
}
.tile.pinned { border-color: var(--accent); }
.tile.screen { border-color: #3b82f6; }
.tile.speaking { box-shadow: 0 0 0 2px #22c55e inset, 0 0 10px rgba(34,197,94,.5); }
.tile.pinned.speaking { box-shadow: 0 0 10px rgba(34,197,94,.5); }
.tile video { width: 100%; height: 100%; object-fit: cover; background: var(--stage-bg); display: block; }
.tile .label {
  position: absolute; left: .4rem; bottom: .4rem; font-size: .72rem;
  background: rgba(0,0,0,.55); padding: .14rem .42rem; border-radius: 5px; max-width: 90%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tile.me .label { background: rgba(238,87,44,.7); }

.avatar {
  position: absolute; inset: 0; display: none; align-items: center; justify-content: center;
  font-size: 1.6rem; font-weight: 600; color: var(--avatar-text);
  background: var(--avatar-bg);
}
.tile.camoff .avatar, #stageTile.camoff .avatar { display: flex; }
.tile.camoff video { visibility: hidden; }
.badge-mic { position: absolute; right: .4rem; top: .4rem; width: 12px; height: 12px; border-radius: 50%; background: #22c55e; }
.tile.muted .badge-mic { background: var(--danger); }

/* ---- transcript + scribe side panel ---- */
#sidePanel {
  flex: 0 0 320px; min-height: 0; display: flex; flex-direction: column; gap: .6rem;
  padding: .6rem .8rem .6rem 0; overflow: hidden;
}
.notes-tabs { display: none; gap: .4rem; }
.notes-tab {
  flex: 1; background: var(--panel-2); border: 1px solid var(--line); color: var(--muted);
  padding: .55rem; font-size: .82rem; border-radius: 8px; min-height: 40px;
}
.notes-tab.active { color: #fff; border-color: var(--accent); }
.side-section {
  flex: 1 1 50%; min-height: 0; display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
}
.side-head {
  padding: .5rem .7rem; font-size: .8rem; font-weight: 700; letter-spacing: .04em;
  text-transform: uppercase; color: var(--muted);
  background: var(--panel-2); border-bottom: 1px solid var(--line);
}
.side-body { flex: 1; min-height: 0; overflow: auto; padding: .55rem .7rem; }
.side-empty { color: var(--muted); font-size: .78rem; line-height: 1.4; }

.tx-line { font-size: .82rem; line-height: 1.4; margin: 0 0 .45rem; }
.tx-line .tx-who { color: var(--accent); font-weight: 600; margin-right: .35rem; }
.tx-line.interim { opacity: .65; font-style: italic; }
.tx-line.interim .tx-who { color: var(--muted); }

.scribe-block { margin-bottom: .85rem; }
.scribe-block h4 { margin: 0 0 .35rem; font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.scribe-list { list-style: none; margin: 0; padding: 0; }
.scribe-list li {
  display: flex; align-items: flex-start; gap: .4rem; padding: .35rem 0;
  border-bottom: 1px solid var(--line); font-size: .82rem; line-height: 1.35;
}
.scribe-list li:last-child { border-bottom: none; }
.scribe-list .si-text { flex: 1; min-width: 0; }
.scribe-list .si-owner { color: var(--muted); font-size: .72rem; display: block; margin-top: .1rem; }
.scribe-list li.accepted .si-text, .scribe-list li.accepted .si-owner { text-decoration: line-through; opacity: .55; }
.accept-btn {
  flex: 0 0 auto; background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 6px; padding: .28rem .55rem; font-size: .72rem; min-height: 32px;
}
.accept-btn:hover:not(:disabled) { background: var(--hover); }
.accept-btn.done { background: #22c55e; border-color: #22c55e; color: #06210f; }
.scribe-summary { font-size: .82rem; line-height: 1.45; white-space: pre-wrap; }

/* ---- bottom control bar ---- */
#controlsBar {
  display: flex; gap: .5rem; align-items: stretch; justify-content: center; flex-wrap: wrap;
  padding: .55rem .7rem; padding-bottom: calc(.55rem + var(--safe-b));
  background: var(--panel); border-top: 1px solid var(--line); flex: 0 0 auto; position: relative;
}
.ctl-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .15rem;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  min-width: 64px; min-height: 56px; padding: .35rem .55rem; border-radius: 12px; font-size: .68rem;
}
.ctl-btn:hover:not(:disabled) { background: var(--hover); }
.ctl-btn .ctl-ico { font-size: 1.2rem; line-height: 1; }
.ctl-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.ctl-btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.ctl-btn.recording { background: var(--danger); border-color: var(--danger); color: #fff; }
.ctl-btn.ghost-ctl { background: transparent; }
.notes-only { display: none; } /* only shown on phones where the panel is a sheet */

.dev-popover {
  position: absolute; bottom: calc(100% + .4rem); right: .7rem; z-index: 30;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: .7rem; display: flex; flex-direction: column; gap: .55rem; min-width: 220px;
  box-shadow: 0 8px 24px var(--shadow);
}
.dev-popover[hidden] { display: none; }
.dev { display: flex; flex-direction: column; gap: .2rem; font-size: .72rem; color: var(--muted); }
.dev select { min-height: 40px; }

/* ---- log panel (dev) ---- */
#logPanel { position: fixed; left: 0; right: 0; bottom: 0; background: var(--log-bg); border-top: 1px solid var(--line); z-index: 60; }
#logPanel.collapsed { display: none; }
#log { height: 160px; overflow: auto; white-space: pre-wrap; padding: .6rem .9rem; font-family: ui-monospace, "Cascadia Code", monospace; font-size: .72rem; color: var(--log-text); }

/* =================================================================
   PHONE-FIRST: narrow widths -> sidebar becomes a top bar + drawer,
   content single-column, notes become a bottom sheet, controls thumb-row.
   ================================================================= */
@media (max-width: 860px) {
  #mobileBar {
    display: flex; align-items: center; gap: .5rem;
    height: calc(var(--bar-h) + var(--safe-t)); padding: var(--safe-t) .5rem 0;
    background: var(--panel); border-bottom: 1px solid var(--line);
    position: fixed; top: 0; left: 0; right: 0; z-index: 50;
  }
  .m-brand { font-weight: 800; font-size: .95rem; }
  .m-brand::after { content: ""; }
  .m-title { margin-left: auto; color: var(--muted); font-size: .82rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 45%; }

  #appShell { padding-top: calc(var(--bar-h) + var(--safe-t)); }

  /* sidebar slides in as a drawer */
  #sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 45;
    transform: translateX(-100%); transition: transform .2s ease;
    padding-top: calc(1rem + var(--safe-t) + var(--bar-h));
  }
  #appShell.nav-open #sidebar { transform: translateX(0); }
  #appShell:not(.nav-open) #navBackdrop { display: none; }

  /* hide the in-meeting back button hint? keep it. content fills below the bar */
  #meetingHeader { padding-top: .5rem; } /* mobile bar already provides top safe area */

  /* notes panel becomes a slide-up sheet toggled by the Notes control */
  #meetingBody { flex-direction: column; }
  #sidePanel {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 35;
    flex-direction: column; padding: .6rem .7rem calc(.6rem + var(--safe-b));
    height: 62vh; background: var(--bg); border-top: 1px solid var(--line);
    border-radius: 14px 14px 0 0; box-shadow: 0 -8px 24px var(--shadow);
    transform: translateY(100%); transition: transform .2s ease;
  }
  #sidePanel.open { transform: translateY(0); }
  .notes-tabs { display: flex; }
  /* tab toggle: show only the active panel */
  #sidePanel[data-active="transcript"] [data-panel="scribe"] { display: none; }
  #sidePanel[data-active="scribe"] [data-panel="transcript"] { display: none; }
  .side-section { flex: 1 1 auto; }

  .notes-only { display: flex; } /* show Notes control on phones */

  /* controls: equal thumb row, allow horizontal scroll only inside the bar if truly tight */
  #controlsBar { flex-wrap: nowrap; overflow-x: auto; justify-content: space-between; }
  .ctl-btn { flex: 1 1 0; min-width: 54px; }
  .ctl-btn.ghost-ctl { flex: 0 0 auto; }

  .tile { width: 132px; }
  .new-meeting-row { flex-direction: column; }
  .new-meeting-row .btn { width: 100%; }
}

/* very narrow phones: tighten control labels but keep 44px+ targets */
@media (max-width: 400px) {
  .ctl-btn { min-width: 48px; padding: .35rem .3rem; }
  .ctl-btn .ctl-lbl { font-size: .62rem; }
  .tile { width: 120px; }
}
