/* Supervisor Console — styles.
   Vocabulary: mint = you are silent (safe), red = you are audible (live), amber = needs attention. */

:root {
  --bg: #111820;
  --surface: #18212c;
  --surface-2: #202b38;
  --line: #2b3745;
  --line-strong: #3b4858;
  --text: #e9eef4;
  --text-2: #b7c2cf;
  --muted: #8d9cae;

  --safe: #4fd1a8;
  --safe-ink: #0c2a21;
  --safe-tint: rgba(79, 209, 168, 0.12);

  --live: #c9301e;
  --live-bright: #ff5a44;
  --live-ink: #ffb3a8;
  --live-tint: rgba(255, 90, 68, 0.14);
  --live-bar: #2a1512;

  --warn: #f2b544;
  --warn-ink: #ffd98a;
  --warn-tint: rgba(242, 181, 68, 0.12);

  --focus: #ffffff;
  --r-sm: 6px;
  --r: 10px;
  --r-lg: 14px;
  --top-h: 52px;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, "Helvetica Neue", Arial, sans-serif;
  font-variant-numeric: tabular-nums;
  min-height: 100dvh;
}
@media (max-width: 879px) { body { font-size: 16px; } }

[hidden] { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
button { font: inherit; }
h1, h2, h3, p { margin: 0; }
.ic { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ── top: header + status strip (sticky) ─────────────────────────────── */
.top { position: sticky; top: 0; z-index: 20; background: var(--bg); }
.hdr {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 16px; min-height: var(--top-h);
  border-bottom: 1px solid var(--line);
}
.hdr h1 { font-size: 15px; font-weight: 600; letter-spacing: 0.01em; white-space: nowrap; min-width: 0; }
.hdr .org { color: var(--muted); font-weight: 400; }
@media (max-width: 560px) { .hdr .org { display: none; } }
@media (max-width: 480px) { .who { display: none; } .conn { margin-left: auto; } }
.who { margin-left: auto; font-size: 13px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40vw; }
.who:empty { display: none; }
.who:empty + .conn { margin-left: auto; }
.conn { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-2); white-space: nowrap; }
.conn::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.conn[data-kind="ok"]::before { background: var(--safe); }
.conn[data-kind="err"]::before { background: var(--live-bright); }
.conn[data-kind="err"] { color: var(--live-ink); }
.iconbtn {
  width: 40px; height: 40px; display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid transparent; border-radius: var(--r); background: transparent; color: var(--text-2); cursor: pointer;
}
.iconbtn:hover { background: var(--surface-2); color: var(--text); }

/* The tally strip. Read it like a broadcast ON-AIR light. */
.statusbar {
  position: relative;
  display: flex; align-items: center; gap: 14px;
  padding: 12px 16px 12px 28px; min-height: 66px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.statusbar::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 8px; }
.statusbar .ic { width: 28px; height: 28px; }
.status-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.status-text strong { font-size: 18px; letter-spacing: 0.02em; }
.status-text span { font-size: 14px; color: var(--text-2); }

body[data-state="listening"] .statusbar::before { background: var(--safe); }
body[data-state="listening"] .statusbar .ic { color: var(--safe); }

body[data-state="live"] .statusbar,
body[data-state="live-nomic"] .statusbar {
  background: var(--live); color: #fff; border-bottom-color: var(--live);
  padding-left: 32px;
}
body[data-state="live"] .statusbar::before,
body[data-state="live-nomic"] .statusbar::before {
  width: 16px;
  background: repeating-linear-gradient(135deg, #fff 0 7px, transparent 7px 14px);
}
body[data-state="live"] .status-text span,
body[data-state="live-nomic"] .status-text span { color: rgba(255, 255, 255, 0.92); }
body[data-state="live"] .status-text strong::before {
  content: ""; display: inline-block; width: 12px; height: 12px; border-radius: 50%;
  background: #fff; margin-right: 10px; vertical-align: -1px;
  animation: blink 1.1s steps(1, end) infinite;
}
@keyframes blink { 50% { opacity: 0.25; } }
body[data-state="live"] .hdr { border-bottom-color: var(--live); }

/* Viewport hazard frame while audible */
.live-frame {
  display: none; position: fixed; inset: 0; z-index: 50; pointer-events: none;
  border: 7px solid transparent;
  border-image: repeating-linear-gradient(135deg, var(--live-bright) 0 12px, #3a0d08 12px 24px) 7;
}
body[data-state="live"] .live-frame,
body[data-state="live-nomic"] .live-frame { display: block; }

/* ── mic level meter ─────────────────────────────────────────────────── */
.meter { display: flex; gap: 3px; align-items: flex-end; height: 28px; margin-left: auto; flex: none; padding: 2px 0; }
.meter i { width: 5px; height: 100%; background: rgba(255, 255, 255, 0.28); border-radius: 1px; }
.meter i.on { background: #fff; }
.meter i:nth-child(n+12).on { background: #ffd98a; }

/* ── layout ──────────────────────────────────────────────────────────── */
.layout {
  max-width: 1180px; margin: 0 auto; padding: 16px;
  display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr);
}
@media (min-width: 880px) {
  .layout { grid-template-columns: minmax(340px, 440px) minmax(0, 1fr); gap: 24px; padding: 24px; align-items: start; }
  .layout > .notice { grid-column: 1 / -1; margin: 0; }
}
@media (max-width: 879px) {
  .session { order: -1; }
  .session-empty { order: 1; }
  .layout > .notice { margin: 0; }
}
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 16px; }

/* ── call list ───────────────────────────────────────────────────────── */
.calls-head { display: flex; align-items: baseline; gap: 10px; margin: 0 0 12px; }
.calls-head h2 { font-size: 15px; font-weight: 600; }
.count { font-size: 13px; color: var(--muted); }
.updated { margin-left: auto; font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.updated[data-stale="true"] { color: var(--warn); }

.call-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; container-type: inline-size; }
.call-list.is-stale .call { opacity: 0.6; }
.call {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 14px;
  display: grid; gap: 10px 12px; grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas: "head head" "meta meta" "btn btn";
}
.call.is-mine { border-color: var(--safe); box-shadow: inset 4px 0 0 var(--safe); }
@container (min-width: 480px) {
  .call { grid-template-areas: "head head" "meta btn"; align-items: end; }
}
.call-head { grid-area: head; display: flex; align-items: baseline; gap: 12px; }
.call-who { display: flex; flex-direction: column; min-width: 0; }
.call-num { font-size: 19px; font-weight: 600; letter-spacing: 0.01em; }
.call-ref { font-size: 13.5px; color: var(--text-2); }
.call-dur { margin-left: auto; font-size: 15px; color: var(--text-2); white-space: nowrap; }
.call-dur::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--safe); margin-right: 7px; vertical-align: 1px; }
.call-meta { grid-area: meta; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.call .btn-listen { grid-area: btn; }

.chip {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; line-height: 1.3;
  padding: 3px 9px; border-radius: 999px; border: 1px solid var(--line-strong); color: var(--text-2); white-space: nowrap;
}
.chip-warn { border-color: rgba(242, 181, 68, 0.55); color: var(--warn-ink); background: var(--warn-tint); }
.chip-safe { border-color: rgba(79, 209, 168, 0.55); color: var(--safe); background: var(--safe-tint); }
.chip-live { border-color: rgba(255, 90, 68, 0.6); color: var(--live-ink); background: var(--live-tint); }

.empty { text-align: center; padding: 36px 16px; border: 1px dashed var(--line-strong); border-radius: var(--r-lg); color: var(--text-2); }
.empty .ic { width: 32px; height: 32px; color: var(--muted); }
.empty h3 { margin: 10px 0 4px; font-size: 15px; color: var(--text); }
.empty p { font-size: 14px; }

/* ── buttons ─────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 16px; border-radius: var(--r);
  border: 1px solid var(--line-strong); background: var(--surface-2); color: var(--text);
  font-weight: 600; font-size: 15px; cursor: pointer; user-select: none; -webkit-tap-highlight-color: transparent;
  transition: background-color 0.15s, border-color 0.15s, transform 0.08s;
}
.btn:hover:not(:disabled) { border-color: #55667a; background: #26333f; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn .ic { width: 18px; height: 18px; }
.btn-listen { border-color: rgba(79, 209, 168, 0.55); color: var(--safe); background: transparent; }
.btn-listen:hover:not(:disabled) { background: var(--safe-tint); border-color: var(--safe); }
.btn-takeover { border-color: var(--live-bright); color: var(--live-ink); background: transparent; }
.btn-takeover:hover:not(:disabled) { background: var(--live-tint); border-color: var(--live-bright); }
.btn-danger { background: var(--live); border-color: var(--live); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #e0361f; border-color: #e0361f; }
.btn-safe { background: var(--safe); border-color: var(--safe); color: var(--safe-ink); }
.btn-safe:hover:not(:disabled) { background: #66dcb6; border-color: #66dcb6; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.btn-grow { flex: 1 1 200px; }

/* ── session ─────────────────────────────────────────────────────────── */
.session-head h2 { font-size: 19px; font-weight: 600; }
.session-head h2:focus { outline: none; }
.session-sub { font-size: 13.5px; color: var(--muted); margin-top: 2px; overflow-wrap: anywhere; }
.plist { list-style: none; margin: 14px 0 0; padding: 0; border-top: 1px solid var(--line); }
.plist li { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 10px 0; border-bottom: 1px solid var(--line); min-height: 54px; }
.plist .ic { width: 22px; height: 22px; color: var(--muted); }
.plist li.is-speaking .ic { color: var(--safe); }
.p-text { display: flex; flex-direction: column; min-width: 0; flex: 1 1 150px; line-height: 1.3; }
.p-kind { font-size: 12.5px; color: var(--muted); }
.p-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.p-state { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; margin-left: auto; }
.p-state:empty { display: none; }
.bars { display: inline-flex; gap: 2px; align-items: flex-end; height: 11px; }
.bars i { display: block; width: 3px; background: currentColor; border-radius: 1px; transform-origin: bottom; animation: bar 0.9s ease-in-out infinite; }
.bars i:nth-child(1) { height: 50%; }
.bars i:nth-child(2) { height: 100%; animation-delay: 0.15s; }
.bars i:nth-child(3) { height: 70%; animation-delay: 0.3s; }
@keyframes bar { 50% { transform: scaleY(0.3); } }

.notice {
  display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; margin-top: 12px;
  border-radius: var(--r); border: 1px solid var(--line-strong); background: var(--surface-2); font-size: 14px;
}
.notice .ic { width: 20px; height: 20px; margin-top: 2px; }
.notice > span { flex: 1; }
.notice .btn { margin-left: auto; min-height: 36px; padding: 0 12px; font-size: 14px; }
.notice .err-close { width: 32px; height: 32px; margin: -6px -6px -6px 0; color: inherit; flex: none; }
.notice .err-close:hover { background: rgba(255, 255, 255, 0.12); }
.notice .btn + .err-close { margin-left: 0; }
.notice-loud .err-close { width: 36px; height: 36px; }
.notice-warn { border-color: rgba(242, 181, 68, 0.5); background: var(--warn-tint); color: var(--warn-ink); }
.notice-err { border-color: rgba(255, 90, 68, 0.5); background: var(--live-tint); color: var(--live-ink); }
.notice-err .btn-ghost { color: var(--live-ink); border-color: rgba(255, 90, 68, 0.5); }
.notice-loud { border-width: 2px; border-color: var(--live-bright); background: #3a1410; color: #fff; font-size: 15.5px; padding: 14px; }
.notice-loud .ic { color: var(--live-bright); width: 24px; height: 24px; }
.notice strong { font-weight: 700; }

.actions { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.actions-row { display: flex; gap: 10px; flex-wrap: wrap; }
.confirm { background: var(--surface-2); border: 1px solid var(--line-strong); border-radius: var(--r); padding: 12px; }
.confirm p { margin: 0 0 12px; font-size: 14.5px; }
.confirm-timer { height: 2px; background: var(--line-strong); margin-top: 12px; overflow: hidden; }
.confirm-timer i { display: block; height: 100%; background: var(--text-2); transform-origin: left; }
.confirm-timer i.run { animation: drain 8s linear forwards; }
@keyframes drain { from { transform: scaleX(1); } to { transform: scaleX(0); } }

/* Phone: actions pinned to the thumb zone, coloured by state */
@media (max-width: 879px) {
  body:not([data-state="idle"]) .actions {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; margin: 0;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    background: var(--surface); border-top: 4px solid var(--safe);
  }
  body[data-state="live"] .actions, body[data-state="live-nomic"] .actions { background: var(--live-bar); border-top-color: var(--live-bright); }
  body:not([data-state="idle"]) .layout { padding-bottom: 160px; }
  body:not([data-state="idle"]) .toast { bottom: 150px; }
  .btn-grow { min-height: 52px; flex-basis: 100%; }
  #actionsMain #btnDropBot, #actionsMain #btnLeave { flex: 1 1 0; border-color: var(--line-strong); }
  body:not([data-state="idle"]) .layout { padding-bottom: 190px; }
}

/* ── placeholder (no call selected) ──────────────────────────────────── */
.session-empty h2 { font-size: 17px; font-weight: 600; }
.session-empty > p { color: var(--text-2); margin-top: 6px; max-width: 60ch; }
.legend { display: grid; gap: 12px; margin: 18px 0 0; padding: 0; }
.legend > div { display: flex; gap: 12px; align-items: flex-start; }
.legend .ic { color: var(--muted); margin-top: 2px; }
.legend dt { font-weight: 600; }
.legend dd { margin: 0; color: var(--text-2); font-size: 14px; }
.legend dt.k-live { color: var(--live-ink); }
.legend dt.k-safe { color: var(--safe); }

/* ── settings dialog ─────────────────────────────────────────────────── */
dialog {
  background: var(--surface); color: var(--text); border: 1px solid var(--line-strong);
  border-radius: var(--r-lg); padding: 20px; width: min(440px, calc(100vw - 32px));
}
dialog::backdrop { background: rgba(5, 8, 12, 0.7); }
dialog h2 { font-size: 17px; font-weight: 600; }
dialog form > p { color: var(--text-2); font-size: 14px; margin-top: 4px; }
label { display: block; font-size: 13.5px; color: var(--text-2); margin: 14px 0 6px; }
input {
  font: inherit; width: 100%; min-height: 44px; background: var(--bg);
  border: 1px solid var(--line-strong); color: var(--text); border-radius: var(--r); padding: 8px 12px;
}
input:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.input-row { display: flex; gap: 8px; }
.input-row .btn { min-height: 44px; padding: 0 12px; flex: none; }
.hint { font-size: 12.5px; color: var(--muted); margin: 6px 0 0; }
dialog .actions-row { margin-top: 18px; }

/* ── toast ───────────────────────────────────────────────────────────── */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 60;
  background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: var(--r);
  font-size: 14px; font-weight: 500; max-width: calc(100vw - 32px); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .confirm-timer { display: none; }
}
