:root {
  color-scheme: dark;
  --bg: #101312;
  --panel: #181d1b;
  --border: #303833;
  --text: #f4f7f5;
  --muted: #a8b3ad;
  --accent: #4fb286;
  --danger: #e45d5d;
  /* Amber, distinct from --danger on purpose: danger marks the destructive
     things (ending a call), caution marks a choice that merely costs you
     something. Using red here would overstate "you'll lose the video". */
  --caution: #d9a441;
  --caution-tint: rgba(217, 164, 65, 0.14);
  --button: #26302b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  min-height: 100vh;
}

.operator-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 100vh;
  padding: 12px;
  gap: 12px;
}

.operator-bar {
  display: flex;
  align-items: center;
  min-height: 44px;
}

.operator-identity {
  margin-left: auto;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.operator-gate {
  display: grid;
  place-content: center;
  min-height: 0;
  padding: 24px;
}

.gate-card {
  width: 100%;
  max-width: 420px;
  padding: 28px 24px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  text-align: center;
}

.gate-icon {
  font-size: 44px;
  line-height: 1;
}

.gate-card h1 {
  margin: 14px 0 8px;
  font-size: 24px;
  font-weight: 700;
}

.gate-lead {
  margin: 0 0 20px;
  color: var(--muted);
  line-height: 1.5;
}

.gate-steps {
  margin: 0 0 20px;
  padding-left: 22px;
  text-align: left;
  display: grid;
  gap: 12px;
  line-height: 1.5;
}

.gate-steps strong {
  color: var(--accent);
}

.gate-waiting {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.gate-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: gate-spin 0.9s linear infinite;
}

@keyframes gate-spin {
  to {
    transform: rotate(360deg);
  }
}

.operator-call-stage {
  position: relative;
  overflow: hidden;
  width: 100%;
  min-height: 0;
  background: #060706;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.video-panel {
  min-width: 0;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}

.operator-picker {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.operator-picker-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 650;
  color: var(--muted);
}

.operator-picker-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.operator-picker-list .operator-item {
  min-height: 38px;
}

.media-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.65fr);
  gap: 12px;
  flex: 1;
  min-height: 420px;
}

.stream-stage,
.call-stage {
  position: relative;
  overflow: hidden;
  width: 100%;
  height: 100%;
  background: #060706;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.stream-frame,
.stream-video {
  width: 100%;
  height: 100%;
  border: 0;
  background: #000;
}

.empty-state {
  display: grid;
  place-content: center;
  height: 100%;
  padding: 24px;
  text-align: center;
}

.empty-state h1 {
  margin: 0 0 8px;
  font-size: 28px;
  font-weight: 650;
}

.call-empty {
  gap: 12px;
}

.call-empty h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 650;
}

.elapsed-row {
  display: grid;
  gap: 6px;
  justify-items: center;
}

.elapsed-row span {
  color: var(--muted);
  font-size: 14px;
  text-transform: uppercase;
}

.elapsed-row strong {
  font-size: 42px;
  font-weight: 750;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.call-stage iframe {
  width: 100% !important;
  height: 100% !important;
  border: 0 !important;
}

.operator-call-stage iframe {
  width: 100% !important;
  height: 100% !important;
  border: 0 !important;
}

.operator-specialist-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
}

.operator-specialist-video:not(.hidden) + .empty-state {
  position: absolute;
  inset: auto 12px 12px;
  height: auto;
  min-height: 0;
  padding: 12px;
  place-content: center;
  background: rgba(6, 7, 6, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
}

.empty-state p,
.hint {
  color: var(--muted);
}

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 20px;
  background: var(--panel);
  border-left: 1px solid var(--border);
}

.status-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 32px;
  font-weight: 650;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--muted);
}

.status-dot.active {
  background: var(--accent);
}

.status-dot.error {
  background: var(--danger);
}

.metrics {
  display: grid;
  gap: 12px;
  margin: 0;
}

.metrics div {
  display: grid;
  gap: 4px;
}

.metrics dt {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.metrics dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.operators {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.operators h2 {
  margin: 0;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.operator-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  max-width: 320px;
  margin: 0 auto;
}

.operator-item {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  color: inherit;
  font: inherit;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  overflow-wrap: anywhere;
}

.operator-item:hover:not(:disabled) {
  border-color: var(--accent);
}

.operator-item.selected {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.operator-item.mine {
  border-color: var(--accent);
  color: var(--accent);
}

.operator-item.busy,
.operator-item:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  background: var(--button);
  text-decoration: none;
  cursor: pointer;
  font: inherit;
}

.button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #07100c;
  font-weight: 700;
}

.button.danger {
  color: #ffecec;
  border-color: #7a3434;
  background: #3a1d1d;
}

.button.disabled {
  pointer-events: none;
  opacity: 0.45;
}

.speak-form {
  display: grid;
  gap: 10px;
}

.speak-form label,
.bridge-header {
  font-weight: 650;
}

textarea {
  width: 100%;
  resize: vertical;
  min-height: 92px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  color: var(--text);
  background: #0e1110;
  font: inherit;
}

.hint {
  margin: 0;
  font-size: 13px;
  line-height: 1.4;
}

.audio-bridge {
  display: grid;
  gap: 10px;
}

.bridge-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.bridge-header span:last-child {
  color: var(--muted);
  text-align: right;
}

.audio-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.audio-actions.single-action {
  grid-template-columns: 1fr;
}

.links {
  display: grid;
  gap: 8px;
  margin-top: auto;
}

.links a {
  color: var(--muted);
  overflow-wrap: anywhere;
}

.hidden {
  display: none;
}

/* ======================================================================
   Specialist app — guided, full-screen flow
   ====================================================================== */

.app {
  min-height: 100vh;
}

/* Centered card steps: name, operator picker, calling */
.view {
  min-height: 100vh;
  display: grid;
  place-content: center;
  padding: 24px;
}

/* Only one step is on screen at a time. `.view` sets display:grid, so a plain
   `.hidden` (equal specificity, declared earlier) would lose and leave every
   step stacked into one long page — this keeps hidden steps hidden. The photo
   tray (display:flex) hits the same trap. */
.view.hidden,
.view-call.hidden,
.photo-tray.hidden,
.photo-viewer.hidden {
  display: none;
}

.app-card {
  width: 100%;
  max-width: 400px;
  padding: 32px 28px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.app-card.wide {
  max-width: 600px;
  text-align: left;
}

/* Let the operator list fill the wider card instead of the 320px cap it
   inherits from the operator-page chooser. */
.app-card .operator-list {
  max-width: none;
  margin: 0;
}

.brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 4px;
}

.brand-mark {
  font-size: 26px;
  color: var(--accent);
  line-height: 1;
}

.brand-name {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.app-card h1 {
  margin: 0;
  font-size: 24px;
  font-weight: 700;
}

.app-card .lead {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.call-target {
  margin: -6px 0 0;
  font-size: 17px;
  font-weight: 650;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.op-name,
.call-operator {
  overflow-wrap: anywhere;
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.card-head-main {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.icon-button {
  flex-shrink: 0;
  display: grid;
  place-content: center;
  width: 38px;
  height: 38px;
  margin-top: 2px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--button);
  color: var(--text);
  cursor: pointer;
}

.icon-button:hover {
  border-color: var(--accent);
}

.card-head h1 {
  margin-bottom: 4px;
}

.identity-badge {
  flex-shrink: 0;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--button);
  border: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.text-input {
  width: 100%;
  min-height: 46px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #0e1110;
  color: var(--text);
  font: inherit;
}

.text-input:focus {
  outline: none;
  border-color: var(--accent);
}

.button.block {
  width: 100%;
}

.empty-hint {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.op-name {
  font-weight: 650;
}

.op-tag {
  margin-left: auto;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--button);
  color: var(--muted);
}

.op-tag.available {
  background: rgba(79, 178, 134, 0.16);
  color: var(--accent);
}

.op-tag.busy {
  opacity: 0.85;
}

/* Video-quality picker on the operator-selection page. */
.quality-picker {
  margin: 4px 0 18px;
}

.quality-label {
  display: block;
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 650;
  color: var(--muted);
}

.segmented {
  display: inline-flex;
  padding: 3px;
  gap: 3px;
  background: var(--button);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.segment {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  min-width: 92px;
  padding: 7px 16px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 650;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}

.segment:hover {
  color: var(--text);
}

.segment.is-active {
  background: rgba(79, 178, 134, 0.16);
  color: var(--accent);
}

.segment-sub {
  font-size: 11px;
  font-weight: 600;
  opacity: 0.85;
}

.quality-hint {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: gate-spin 0.9s linear infinite;
  flex-shrink: 0;
}

.spinner.large {
  width: 40px;
  height: 40px;
  border-width: 3px;
  margin: 0 auto 4px;
}

/* Full-screen live call */
.view-call {
  position: fixed;
  inset: 0;
  background: #000;
  overflow: hidden;
}

.view-call .stream-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}

.self-view {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 200px;
  height: 132px;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: #111;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
  transform: scaleX(-1);
  z-index: 2;
}

.call-topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 22px;
  z-index: 3;
  background: linear-gradient(rgba(0, 0, 0, 0.55), rgba(0, 0, 0, 0));
  pointer-events: none;
}

.call-operator {
  font-size: 16px;
  font-weight: 650;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
}

.call-timer {
  font-variant-numeric: tabular-nums;
  font-weight: 650;
  padding: 5px 12px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.42);
  font-size: 14px;
}

.call-hint {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 1;
  padding: 14px 18px;
  border-radius: 10px;
  background: rgba(6, 7, 6, 0.7);
  color: var(--muted);
  text-align: center;
  max-width: 80%;
}

.call-controls {
  position: absolute;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  display: flex;
  gap: 18px;
  z-index: 3;
}

/* Prototype: floating tray of stills captured during the session. */
.photo-tray {
  position: absolute;
  top: 72px;
  right: 18px;
  bottom: 120px;
  z-index: 3;
  width: 132px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(6, 7, 6, 0.72);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.photo-tray-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

/* Two ways to capture a still, with very different costs. The styling carries
   that: `primary` is the one to reach for, `caution` is the one that stops the
   video. Rank is expressed three ways over — fill, size, and position — so it
   survives without colour (see also the caption under the caution button). */
.photo-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: 8px;
  cursor: pointer;
}

.photo-btn:disabled {
  opacity: 0.55;
  cursor: default;
}

/* Default action: the only solid fill in the tray, so the eye lands here. */
.photo-btn.primary {
  padding: 8px;
  border: 1px solid var(--accent);
  background: var(--accent);
  /* Dark ink on the accent fill — var(--text) on this green fails contrast. */
  color: #0c1310;
  font-size: 12px;
  font-weight: 600;
}

.photo-btn.primary:hover:not(:disabled) {
  background: #5cc294;
  border-color: #5cc294;
}

/* Discouraged action: no fill, no border, muted and a size down, so at a glance
   it reads as a footnote to the button above rather than a peer of it. It stays
   fully enabled — it's the only route to camera-resolution stills. */
.photo-btn.caution {
  width: 100%;
  padding: 4px 6px;
  border: 1px solid transparent;
  background: none;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
}

/* Caution surfaces on intent rather than at rest: amber the moment you aim at
   it, so the cost lands before the click and not as decoration. */
.photo-btn.caution:hover:not(:disabled),
.photo-btn.caution:focus-visible {
  border-color: var(--caution);
  background: var(--caution-tint);
  color: var(--text);
}

/* Rule + inset separate "the exception" from the default action above it. */
.photo-btn-alt {
  margin-top: 2px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.photo-tray-note {
  display: flex;
  align-items: flex-start;
  gap: 4px;
  margin: 4px 2px 0;
  font-size: 10px;
  line-height: 1.35;
  color: var(--muted);
}

.photo-note-icon {
  flex: none;
  margin-top: 1px;
  color: var(--caution);
}

.photo-tray-empty {
  font-size: 11px;
  color: var(--muted);
  text-align: center;
  padding: 6px 0;
}

.photo-tray-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  min-height: 0;
}

.photo-thumb {
  position: relative;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: none;
  cursor: pointer;
  line-height: 0;
}

.photo-thumb:hover {
  border-color: var(--accent);
}

.photo-thumb img {
  display: block;
  width: 100%;
  border-radius: 7px;
}

.photo-thumb .photo-thumb-badge {
  position: absolute;
  bottom: 4px;
  right: 4px;
  padding: 1px 5px;
  border-radius: 5px;
  background: rgba(0, 0, 0, 0.6);
  color: var(--text);
  font-size: 10px;
  line-height: 1.4;
}

/* Full-screen viewer for a single captured still. */
.photo-viewer {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  background: rgba(0, 0, 0, 0.85);
}

.photo-viewer-toolbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px;
}

.pv-zoom-level {
  min-width: 48px;
  text-align: center;
  font-size: 13px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.pv-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}

.pv-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.photo-viewer-stage {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  padding: 16px;
}

.photo-viewer-stage img {
  max-width: 100%;
  max-height: 100%;
  transform-origin: center center;
  transition: transform 0.1s ease-out;
}

.control-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  border: 0;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font: inherit;
}

.control-btn .ctrl-icon {
  display: grid;
  place-content: center;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.16);
  backdrop-filter: blur(6px);
  transition: background 0.15s ease, border-color 0.15s ease;
}

.control-btn:hover .ctrl-icon {
  background: rgba(255, 255, 255, 0.2);
}

.control-btn.off .ctrl-icon {
  background: rgba(228, 93, 93, 0.22);
  border-color: rgba(228, 93, 93, 0.5);
  color: #ffd7d7;
}

.control-btn.danger .ctrl-icon {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.control-btn.danger:hover .ctrl-icon {
  background: #d24a4a;
}

.ctrl-label {
  font-size: 12px;
  color: var(--muted);
}

@media (max-width: 640px) {
  .self-view {
    width: 128px;
    height: 86px;
    top: 14px;
    right: 14px;
  }

  .control-btn .ctrl-icon {
    width: 52px;
    height: 52px;
  }

  .call-controls {
    gap: 14px;
  }
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .media-grid {
    grid-template-columns: 1fr;
    height: auto;
  }

  .side-panel {
    border-left: 0;
    border-top: 1px solid var(--border);
  }

  .stream-stage {
    height: 58vh;
    min-height: 320px;
  }

  .call-stage {
    height: 44vh;
    min-height: 340px;
  }

  .actions {
    grid-template-columns: 1fr;
  }
}
