:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --border: #dde2ea;
  --text: #18202b;
  --muted: #5f6b7a;
  --accent: #2563eb;
  --accent-contrast: #ffffff;
  --danger: #dc2626;
  --ok: #16a34a;
  --warn: #d97706;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 4px 16px rgb(16 24 40 / 6%);
  color-scheme: light dark;
}
/* Dark mode: the system's setting, or the account menu's override (data-theme, set by theme.js). Keep both lists the same. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1419;
    --surface: #182029;
    --surface-2: #212b36;
    --border: #2c3846;
    --text: #e6ebf1;
    --muted: #9aa7b5;
    --accent: #4b8bff;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%);
  }
}
:root[data-theme="dark"] {
  --bg: #0f1419;
  --surface: #182029;
  --surface-2: #212b36;
  --border: #2c3846;
  --text: #e6ebf1;
  --muted: #9aa7b5;
  --accent: #4b8bff;
  --shadow: 0 1px 2px rgb(0 0 0 / 40%);
  color-scheme: dark;
}
:root[data-theme="light"] { color-scheme: light; }

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hidden { display: none !important; }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.stack > * + * { margin-top: .75rem; }

/* ---------- controls */
button, .btn {
  font: inherit;
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .55rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
button:hover, .btn:hover { background: var(--surface-2); }
button:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-danger { color: var(--danger); }
.btn-danger.solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-sm { padding: .3rem .65rem; font-size: .85rem; }
button.active, .btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

label { display: block; font-weight: 500; font-size: .9rem; margin-bottom: .25rem; }
input, select, textarea {
  font: inherit;
  width: 100%;
  padding: .55rem .7rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}
input:disabled, select:disabled, textarea:disabled { opacity: .6; cursor: not-allowed; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.field + .field { margin-top: .85rem; }
label.checkbox { display: flex; align-items: center; gap: .4rem; font-weight: 400; margin: .4rem 0 0; cursor: pointer; }
label.checkbox input { width: auto; margin: 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
}
.error { color: var(--danger); font-size: .9rem; min-height: 1.3em; }

.badge {
  display: inline-block; padding: .1rem .55rem; border-radius: 999px;
  font-size: .78rem; font-weight: 600; text-transform: capitalize;
  background: var(--surface-2); color: var(--muted);
}
.badge.waiting { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.badge.active { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.badge.mic-state { display: inline-flex; align-items: center; gap: .35rem; text-transform: none; }

/* ---------- layout */
.topbar {
  display: flex; align-items: center; gap: 1rem;
  padding: .75rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 1.1rem; display: flex; align-items: center; gap: .5rem; text-decoration: none; color: var(--text); }
/* Signed-in user's icon; opens the menu with their name, Profile, the dark mode switch and Sign out. */
.user-menu { position: relative; }
.user-menu-btn { padding: .25rem; gap: .5rem; border-color: transparent; background: transparent; color: var(--muted); font-size: .85rem; }
.user-menu-btn:hover, .user-menu-btn[aria-expanded="true"] { background: var(--surface-2); color: var(--text); }
.avatar { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--surface-2); color: var(--muted); }
.avatar .icon { width: 18px; height: 18px; }
.menu {
  position: absolute; right: 0; top: calc(100% + .35rem); z-index: 50; min-width: 160px;
  display: flex; flex-direction: column; padding: .3rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.menu > a, .menu > button {
  display: block; width: 100%; text-align: left; padding: .5rem .7rem; border: none; border-radius: 6px;
  background: transparent; color: var(--text); text-decoration: none; font-size: .9rem;
}
.menu > a:hover, .menu > button:hover, .menu > :focus-visible { background: var(--surface-2); }
.menu > a[aria-current="page"] { font-weight: 600; }
/* Dark mode switch: a sliding button, on when the page is dark. */
.menu > .theme-switch { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.switch-track { flex: none; width: 36px; height: 20px; padding: 2px; border-radius: 999px; background: var(--muted); transition: background-color .15s; }
.switch-track::before {
  content: ""; display: block; width: 16px; height: 16px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 2px rgb(0 0 0 / 30%); transition: transform .15s;
}
[aria-checked="true"] > .switch-track { background: var(--accent); }
[aria-checked="true"] > .switch-track::before { transform: translateX(16px); }
@media (prefers-reduced-motion: reduce) { .switch-track, .switch-track::before { transition: none; } }
@media (forced-colors: active) {
  .switch-track { border: 1px solid ButtonText; padding: 1px; }
  .switch-track::before { background: ButtonText; }
}
/* Who is signed in, above the menu items. */
.menu-head {
  padding: .45rem .7rem .55rem; margin-bottom: .3rem; border-bottom: 1px solid var(--border);
  font-size: .85rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 260px;
}
.brand-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.container { max-width: 1100px; margin: 0 auto; padding: 1.5rem 1rem 3rem; }
.grid-2 { display: grid; grid-template-columns: 340px 1fr; gap: 1.25rem; align-items: start; }
@media (max-width: 860px) { .grid-2 { grid-template-columns: 1fr; } }
.field-pair { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }

.center-page { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.center-page .card { width: 100%; max-width: 400px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .6rem .5rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: none; }
.table-wrap { overflow-x: auto; }

.link-box {
  display: flex; gap: .5rem; align-items: center;
  background: var(--surface-2); border-radius: 8px; padding: .5rem .5rem .5rem .75rem;
}
.join-code { display: grid; gap: .3rem; margin-top: .6rem; }
.join-code-digits { font-size: 2rem; font-weight: 700; letter-spacing: .12em; font-variant-numeric: tabular-nums; line-height: 1.1; }
.join-code-digits.spent { color: var(--muted); text-decoration: line-through; }
.link-box code { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .85rem; }

/* ---------- profile */
.container.narrow { max-width: 760px; }
.details { display: grid; grid-template-columns: max-content 1fr; gap: .4rem 1.25rem; margin: 0; }
.details dt { color: var(--muted); font-size: .9rem; }
.details dd { margin: 0; overflow-wrap: anywhere; }
.method { padding-top: 1rem; }
.method + .method { margin-top: 1rem; border-top: 1px solid var(--border); }
.method h3 { font-size: 1rem; margin: 0; display: flex; align-items: center; gap: .5rem; }
.method h3 + p { margin: .25rem 0 0; }
/* ---------- admin */
.link-btn { padding: 0; border: none; background: none; color: var(--accent); font-weight: 600; text-align: left; white-space: normal; }
.link-btn:hover { text-decoration: underline; }
.sort-btn {
  padding: 0; border: none; background: none; gap: .3rem;
  font: inherit; text-transform: inherit; letter-spacing: inherit; color: inherit;
}
.sort-btn:hover { color: var(--text); }
.sort-btn::after { content: "↕"; opacity: .35; }
th[aria-sort] .sort-btn { color: var(--text); }
th[aria-sort="ascending"] .sort-btn::after { content: "↑"; opacity: 1; }
th[aria-sort="descending"] .sort-btn::after { content: "↓"; opacity: 1; }
.pager { margin-top: .75rem; }
.list-filters { margin-bottom: .75rem; flex-wrap: wrap; }
.list-filters input[type="search"] { flex: 1 1 220px; width: auto; padding: .3rem .6rem; font-size: .85rem; }
.bulk-bar {
  margin-bottom: .75rem; padding: .4rem .6rem; border-radius: 8px; flex-wrap: wrap;
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}
.select-col { width: 1.5rem; }
.select-col input { width: auto; margin: 0; }
.pager-size { width: auto; padding: .3rem .5rem; }
.admin-layout { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 1.5rem; align-items: start; }
.admin-nav { position: sticky; top: 1rem; display: flex; flex-direction: column; gap: .15rem; }
.admin-nav h1 { margin: 0 0 .6rem .75rem; }
.admin-nav a { padding: .5rem .75rem; border-radius: 8px; color: var(--text); text-decoration: none; }
.admin-nav a:hover { background: var(--surface-2); }
.admin-nav a[aria-current="page"] { background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent); font-weight: 600; }
@media (max-width: 760px) {
  .admin-layout { grid-template-columns: 1fr; gap: 1rem; }
  .admin-nav { position: static; flex-direction: row; flex-wrap: wrap; }
  .admin-nav h1 { width: 100%; margin-left: 0; }
}
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: .85rem 1.25rem; }
.hint { margin: .3rem 0 0; }
.notice { border-left: 4px solid var(--warn); }
.hint[data-default]::after { content: " " attr(data-default); }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }

.totp-setup { display: grid; grid-template-columns: 180px 1fr; gap: 1.25rem; align-items: start; margin-top: 1rem; }
@media (max-width: 560px) { .totp-setup { grid-template-columns: 1fr; } }
/* QR codes need dark-on-light to scan, whatever the theme. */
.qr { background: #fff; padding: 10px; border-radius: 8px; border: 1px solid var(--border); width: 180px; }
.qr-large { width: 260px; max-width: 100%; margin-left: auto; margin-right: auto; }
.qr svg { display: block; width: 100%; height: auto; }
.secret { display: block; background: var(--surface-2); border-radius: 8px; padding: .5rem .75rem; font-size: .9rem; letter-spacing: .05em; overflow-wrap: anywhere; }
.code-input { font-size: 1.25rem; letter-spacing: .3em; font-variant-numeric: tabular-nums; max-width: 12ch; }

dialog {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  padding: 1.25rem; width: min(420px, 92vw);
}
dialog::backdrop { background: rgb(0 0 0 / 45%); }
dialog.wide { width: min(720px, 94vw); }
.subhead { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: .5rem 0 0; }
.dialog-section { padding-top: .5rem; }
/* Section titles stand apart from the grey field labels under them. */
.dialog-section h3 {
  font-size: 1rem; font-weight: 700; color: var(--text); margin: 0 0 .75rem;
  padding: .2rem 0 .45rem .65rem; border-left: 3px solid var(--accent); border-bottom: 1px solid var(--border);
}
.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: .35rem;
  padding: 2rem 1rem; text-align: center; cursor: pointer; font-weight: 400; margin: 0;
  border: 2px dashed var(--border); border-radius: var(--radius); background: var(--surface-2);
}
.dropzone.over { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--surface-2)); }
.link { color: var(--accent); text-decoration: underline; }
.import-table { max-height: 45vh; overflow-y: auto; margin-top: .5rem; }
.import-table td { font-size: .85rem; }
.import-table .ok { color: var(--ok); }
.import-table .fail { color: var(--danger); }

#toast {
  position: fixed; left: 50%; bottom: 5.5rem; transform: translateX(-50%);
  background: #18202b; color: #fff; padding: .6rem 1rem; border-radius: 8px;
  font-size: .9rem; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 100;
}
#toast.show { opacity: 1; }

/* ---------- video stage (viewer + onsite) */
.stage {
  position: relative;
  background: #000;
  overflow: hidden;
  display: grid; place-items: center;
}
/* Pinned to the stage so object-fit: contain letterboxes the whole picture. Percentage
   heights don't resolve inside the grid, which let portrait video overflow and get cropped. */
.stage video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; display: block; }
.stage-overlay {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  color: #cfd8e3; text-align: center; padding: 1rem;
  pointer-events: none;
}
/* The link and join code box shown while waiting for the onsite person. The overlay normally
   lets clicks through to the video; with the box showing it takes them, and scrolls if short. */
.stage-overlay:has(.share-card:not(.hidden)) { pointer-events: auto; overflow-y: auto; place-items: safe center; }
.share-card {
  width: min(580px, 100%); margin: 1.5rem auto 0; padding: 1.5rem;
  background: var(--surface); color: var(--text); border: 2px solid var(--accent); border-radius: 14px;
  box-shadow: 0 12px 40px rgb(0 0 0 / 45%); animation: share-glow 2.4s ease-in-out infinite;
}
.share-card h2 { margin: 0 0 .35rem; font-size: 1.35rem; }
.share-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: .6rem; margin: 1.1rem 0 .75rem; }
.share-big { flex-direction: column; gap: .45rem; padding: .9rem .5rem; font-size: 1rem; font-weight: 600; white-space: normal; }
.share-big .icon { width: 28px; height: 28px; }
.share-card-code { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.share-card-code > div > button { padding: .6rem 1.2rem; font-size: 1rem; }
@keyframes share-glow {
  0%, 100% { box-shadow: 0 12px 40px rgb(0 0 0 / 45%), 0 0 0 0 color-mix(in srgb, var(--accent) 45%, transparent); }
  50% { box-shadow: 0 12px 40px rgb(0 0 0 / 45%), 0 0 0 8px color-mix(in srgb, var(--accent) 15%, transparent); }
}
@media (prefers-reduced-motion: reduce) { .share-card { animation: none; } }
.pointer {
  position: absolute; width: 44px; height: 44px; margin: -22px 0 0 -22px;
  border-radius: 50%; border: 3px solid #ff3b30; box-shadow: 0 0 0 3px rgb(255 255 255 / 70%);
  pointer-events: none; animation: pulse 1s ease-out 3; opacity: 0; transition: opacity .3s;
}
.pointer.show { opacity: 1; }
/* Where the agent asked the onsite camera to focus: a square, like a camera app. */
.focus-mark {
  position: absolute; width: 56px; height: 56px; margin: -28px 0 0 -28px;
  border: 2px solid #facc15; box-shadow: 0 0 0 1px rgb(0 0 0 / 40%);
  pointer-events: none; animation: pulse 1s ease-out 1; opacity: 0; transition: opacity .3s;
}
.focus-mark.show { opacity: 1; }
/* Where the onsite device just read a barcode while scanning. */
.barcode-mark {
  position: absolute; border: 2px solid var(--ok); border-radius: 4px;
  box-shadow: 0 0 0 1px rgb(0 0 0 / 45%);
  pointer-events: none; animation: barcode-mark 1.6s ease-out forwards;
}
@keyframes barcode-mark {
  0% { opacity: 0; transform: scale(1.15); }
  15% { opacity: 1; transform: scale(1); }
  75% { opacity: 1; }
  100% { opacity: 0; }
}
@media (prefers-reduced-motion: reduce) { .barcode-mark { animation: none; } }
/* Camera controls on the video's right edge, top to bottom: flashlight, zoom, tap to focus.
   A hidden one closes the gap. On a narrow video they sit above the toolbar, clear of its buttons. */
.viewer .stage { container-type: inline-size; }
.video-corner { position: absolute; right: 1rem; bottom: 1rem; z-index: 2; display: flex; flex-direction: column; align-items: center; gap: .5rem; }
@container (max-width: 780px) {
  .video-corner { bottom: 6.65rem; }
  .stage.controls-hidden .video-corner { bottom: 1rem; }
}
.corner-btn { width: 42px; height: 42px; padding: 0; background: rgb(15 20 25 / 75%); border-color: rgb(255 255 255 / 20%); color: #fff; backdrop-filter: blur(6px); }
.corner-btn:hover { background: rgb(15 20 25 / 90%); }
.corner-btn.active { background: var(--accent); border-color: var(--accent); }
/* Vertical zoom slider. */
.zoom-overlay {
  display: flex; flex-direction: column; align-items: center; gap: .3rem; width: 42px; padding: .5rem 0;
  background: rgb(15 20 25 / 75%); border-radius: 12px; color: #fff; font-weight: 600; line-height: 1;
  backdrop-filter: blur(6px);
}
.zoom-overlay input {
  /* Top is the most zoomed in. */
  writing-mode: vertical-lr; direction: rtl;
  width: 1.5rem; height: min(180px, 30vh); padding: 0; border: none; background: transparent; accent-color: #facc15;
}
#focus-btn.active { background: #ca8a04; border-color: #ca8a04; }
.stage.focusing video { cursor: cell; }
@keyframes pulse {
  0% { transform: scale(.6); }
  50% { transform: scale(1.15); }
  100% { transform: scale(1); }
}
.stats {
  position: absolute; left: .75rem; top: .75rem;
  background: rgb(0 0 0 / 55%); color: #fff; font-size: .78rem;
  padding: .25rem .55rem; border-radius: 6px; font-variant-numeric: tabular-nums;
  border: none; cursor: pointer;
}
.stats:hover, .stats[aria-expanded="true"] { background: rgb(0 0 0 / 75%); }
.stats-panel {
  position: absolute; left: .75rem; top: 2.6rem; z-index: 3;
  width: min(380px, calc(100% - 1.5rem)); max-height: calc(100% - 7.5rem); overflow-y: auto;
  background: rgb(15 20 25 / 90%); color: #fff; border-radius: 10px; padding: .6rem .8rem .8rem;
  font-size: .8rem; font-variant-numeric: tabular-nums; cursor: default; backdrop-filter: blur(6px);
}
.stats-panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: .25rem; }
.stats-panel-head button { background: transparent; border: none; color: #fff; font-size: 1.2rem; line-height: 1; padding: .1rem .4rem; }
.stats-panel-head button:hover { background: rgb(255 255 255 / 12%); }
.stats-tabs { display: flex; gap: .25rem; }
.stats-tabs button {
  background: transparent; border: none; color: #9aa7b5; font-size: .8rem; font-weight: 600;
  padding: .25rem .55rem; border-radius: 6px;
}
.stats-tabs button:hover { background: rgb(255 255 255 / 10%); color: #fff; }
.stats-tabs button[aria-selected="true"] { background: rgb(255 255 255 / 16%); color: #fff; }
.perm-table { display: grid; grid-template-columns: 1fr auto auto; gap: .3rem .6rem; align-items: center; }
.perm-head { font-size: .7rem; color: #9aa7b5; text-align: center; }
.perm { display: inline-block; min-width: 6.5rem; text-align: center; padding: .1rem .45rem; border-radius: 999px; font-size: .72rem; background: rgb(255 255 255 / 10%); color: #cfd8e3; }
.perm.granted { background: rgb(22 163 74 / 30%); color: #86efac; }
.perm.denied { background: rgb(220 38 38 / 35%); color: #fca5a5; }
.perm.prompt { background: rgb(217 119 6 / 25%); color: #fcd34d; }
.perm-row { grid-template-columns: 1fr auto; }
.perm-hint { margin: .4rem 0 0; padding: .4rem .55rem; border-radius: 6px; background: rgb(217 119 6 / 20%); color: #fde68a; }
.stats-section + .stats-section { margin-top: .6rem; }
.stats-section h4 { margin: 0 0 .25rem; font-size: .7rem; text-transform: uppercase; letter-spacing: .05em; color: #9aa7b5; }
.stat-row { display: grid; grid-template-columns: 1fr auto 80px; gap: .6rem; align-items: center; padding: .12rem 0; }
.stat-label { color: #cfd8e3; }
.stat-value { text-align: right; }
.stat-value.warn { color: #fbbf24; }
.stat-empty { margin: 0; color: #9aa7b5; }
.spark { width: 80px; height: 18px; display: block; }
.spark polyline { fill: none; stroke: #60a5fa; stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid rgb(255 255 255 / 25%); border-top-color: #fff;
  animation: spin 1s linear infinite; margin: 0 auto .75rem;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- agent viewer */
.viewer { display: grid; grid-template-columns: 1fr 600px; height: calc(100vh - 57px); }
.viewer .stage { height: 100%; cursor: crosshair; }
.viewer aside { border-left: 1px solid var(--border); background: var(--surface); overflow-y: auto; padding: 1rem; }
.viewer aside > :not(.hidden) ~ :not(.hidden) { margin-top: 1.25rem; padding-top: 1.25rem; border-top: 1px solid var(--border); }
.viewer aside h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
/* The right-hand menu can be hidden to give the video the full width. */
.viewer.menu-hidden { grid-template-columns: 1fr; }
.viewer.menu-hidden aside { display: none; }
.stage:fullscreen .menu-tab { display: none; }
/* A chat message came in while the menu was hidden (the count is .chat-tab-count). */
.menu-tab.has-unread { border-color: var(--accent); animation: unread-pulse 1.5s ease-in-out infinite; }
@keyframes unread-pulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 60%, transparent); }
  50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--accent) 0%, transparent); }
}
@media (prefers-reduced-motion: reduce) { .menu-tab.has-unread { animation: none; box-shadow: 0 0 0 2px var(--accent); } }
.panel > summary { display: flex; align-items: center; gap: .5rem; cursor: pointer; list-style: none; user-select: none; }
.panel > summary::-webkit-details-marker { display: none; }
.panel > summary h3 { margin: 0; }
.panel > summary::after {
  content: ""; width: .45rem; height: .45rem; margin: 0 .2rem 0 auto;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  transform: rotate(45deg); transition: transform .15s;
}
.panel:not([open]) > summary::after { transform: rotate(-45deg); }
.panel[open] > summary { margin-bottom: .75rem; }
/* A panel's main buttons sit in its title while it's collapsed (see dockInTitle). */
.panel > summary .title-row { flex: 1; min-width: 0; margin-left: .25rem; }
.panel > :not(summary) .title-only { display: none; }
#link-section > .title-row { margin-top: .5rem; }
.select-sm { width: auto; padding: .3rem .5rem; font-size: .85rem; }
.subpanel { background: var(--surface-2); border-radius: 8px; padding: .75rem; }
/* Styled apart from the field labels inside the panel. */
.subpanel h4 {
  margin: 0 0 .7rem; padding-bottom: .45rem; border-bottom: 1px solid var(--border);
  font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--accent);
}
.subpanel button { width: 100%; }
/* Microphone level: a green-amber-red scale, with the unlit part covered from the right. */
.meter {
  position: relative; height: 8px; margin-top: .45rem; border-radius: 4px; overflow: hidden;
  background: linear-gradient(90deg, var(--ok) 0 65%, var(--warn) 65% 85%, var(--danger) 85%);
}
.meter > span { position: absolute; top: 0; right: 0; bottom: 0; width: 100%; background: var(--border); }
.meter.off { opacity: .5; }

/* Toolbar "Unmute Them" / "Unmute Me" while muted: a level bar along the bottom, and a pulse when that person talks. */
.level-btn { position: relative; overflow: hidden; }
.level-btn::after {
  content: ""; position: absolute; left: 0; bottom: 0; height: 3px;
  width: calc(var(--level, 0) * 100%); background: var(--ok); transition: width .1s linear;
}
.level-btn.talking { border-color: var(--ok); animation: talk-pulse 1s ease-in-out infinite; }
@keyframes talk-pulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 55%, transparent); }
  50% { box-shadow: 0 0 0 4px color-mix(in srgb, var(--ok) 25%, transparent); }
}
@media (prefers-reduced-motion: reduce) { .level-btn.talking { animation: none; box-shadow: 0 0 0 2px var(--ok); } }
.subpanel .row button { width: auto; }
/* Same red as the unread count on the menu tab (.chat-tab-count). */
.badge.unread { background: #ef4444; color: #fff; text-transform: none; }

/* ---------- chat (agent panel + onsite drawer) */
.chat-log {
  display: flex; flex-direction: column; gap: .5rem;
  height: 240px; overflow-y: auto; padding: .6rem;
  background: var(--surface-2); border-radius: 8px;
}
.chat-log:empty::before { content: "No messages yet."; color: var(--muted); font-size: .85rem; margin: auto; }
.chat-msg { max-width: 85%; align-self: flex-start; }
.chat-msg.mine { align-self: flex-end; text-align: right; }
.chat-text {
  display: inline-block; text-align: left; padding: .4rem .65rem; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--border);
  white-space: pre-wrap; overflow-wrap: anywhere; user-select: text;
}
.chat-msg.mine .chat-text { background: var(--accent); border-color: var(--accent); color: #fff; }
.chat-meta { font-size: .72rem; color: var(--muted); margin-top: .15rem; }
.chat-form { display: flex; gap: .5rem; margin-top: .5rem; }
.chat-form input { flex: 1; min-width: 0; }
.chat-file {
  display: inline-flex; gap: .55rem; align-items: flex-start; text-align: left; max-width: 100%;
  padding: .5rem .65rem; border-radius: 10px; background: var(--surface); border: 1px solid var(--border);
}
.chat-file > .icon { color: var(--muted); margin-top: .1rem; }
.chat-file-body { display: flex; flex-direction: column; align-items: flex-start; gap: .25rem; min-width: 0; }
.chat-file-name { font-weight: 600; overflow-wrap: anywhere; }
.chat-file-meta, .chat-file-note { font-size: .78rem; color: var(--muted); }
.chat-file.failed .chat-file-meta { color: var(--danger); }
.chat-file progress { width: 12rem; max-width: 100%; }
progress { width: 100%; accent-color: var(--accent); }

/* ---------- files (send dialog, files sent) */
.file-list { display: flex; flex-direction: column; gap: .4rem; }
#library-list { max-height: 40vh; overflow-y: auto; margin-top: .5rem; }
#library-list:empty { display: none; }
.file-row { display: flex; align-items: center; gap: .6rem; padding: .5rem .65rem; background: var(--surface-2); border-radius: 8px; }
.file-row-body { flex: 1; min-width: 0; }
.file-row-name { font-weight: 600; overflow-wrap: anywhere; }
/* Barcodes section: one row per code, scrolling once there are many. */
.barcode-list { display: flex; flex-direction: column; gap: .4rem; max-height: 40vh; overflow-y: auto; padding-right: .25rem; }
.barcode-value { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-weight: 600; overflow-wrap: anywhere; user-select: text; }
.barcode-row.flash { animation: barcode-flash 1.6s ease-out; }
@keyframes barcode-flash {
  0%, 40% { box-shadow: 0 0 0 2px var(--accent); }
  100% { box-shadow: 0 0 0 2px transparent; }
}
@media (prefers-reduced-motion: reduce) { .barcode-row.flash { animation: none; box-shadow: 0 0 0 2px var(--accent); } }
.toolbar {
  position: absolute; bottom: 2.4rem; left: 50%; transform: translateX(-50%);
  display: flex; gap: .5rem; background: rgb(15 20 25 / 75%); padding: .5rem; border-radius: 12px;
  backdrop-filter: blur(6px);
}
.toolbar button { background: transparent; border-color: rgb(255 255 255 / 20%); color: #fff; }
.toolbar button:hover { background: rgb(255 255 255 / 12%); }
.toolbar button.active { background: var(--accent); border-color: var(--accent); }
/* The toolbar can be hidden to clear the video; its tab sits on the video's bottom edge, under it. */
.stage.controls-hidden .toolbar { display: none; }
.chat-tab.controls-tab {
  right: auto; top: auto; bottom: 0; left: 50%; transform: translateX(-50%);
  padding: .3rem .5rem .2rem; border-radius: 10px 10px 0 0;
  border-right: 1px solid rgb(255 255 255 / 25%); border-bottom: none;
}
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: .5rem; }
/* Lots of snapshots scroll inside the grid, and the download button stays in view below it. */
.viewer .gallery { max-height: 50vh; overflow-y: auto; padding-right: .25rem; }
#download-snaps { position: sticky; bottom: 0; }
.panel[open] > summary .snap-count { display: none; }
.snap-actions { justify-content: flex-end; }
.snap { position: relative; margin: 0; min-width: 0; }
.gallery a { display: block; aspect-ratio: 4 / 3; border-radius: 6px; overflow: hidden; background: var(--surface-2); }
.snap-delete {
  position: absolute; top: 4px; right: 4px;
  padding: 0 .4rem; min-height: 0; font-size: 1.1rem; line-height: 1.4;
  background: rgb(0 0 0 / 55%); color: #fff; border: none;
}
.snap-delete:hover { background: var(--danger); }
.snap-send { position: absolute; top: 4px; left: 4px; padding: .2rem .3rem; background: rgb(0 0 0 / 55%); color: #fff; border: none; }
.snap-send:hover { background: var(--accent); }
.snap-send .icon { width: 16px; height: 16px; }
/* Chat is gone once the session ends, so there's nowhere to send to. */
#chat-section.hidden ~ #snapshots-section .snap-send,
#chat-section.ended ~ #snapshots-section .snap-send { display: none; }
#chat-section.drop-target { outline: 2px dashed var(--accent); outline-offset: 4px; border-radius: 4px; }
.snap-name { margin-top: .3rem; padding: .25rem .45rem; font-size: .8rem; }
.gallery img { width: 100%; height: 100%; object-fit: cover; display: block; }
@media (max-width: 1100px) {
  .viewer { grid-template-columns: 1fr; height: auto; }
  .viewer .stage { height: 60vh; }
  .viewer aside { border-left: none; }
  /* The menu sits under the video here, so it can't be hidden. */
  .viewer .menu-tab { display: none; }
  .viewer.menu-hidden aside { display: block; }
}

/* ---------- snapshot viewer */
#snap-viewer { width: 96vw; height: 94vh; max-width: none; max-height: none; padding: 0; overflow: hidden; }
#snap-viewer[open] { display: grid; grid-template-columns: 170px minmax(0, 1fr); }
.sv-rail { display: flex; flex-direction: column; gap: .5rem; padding: .5rem; overflow-y: auto; border-right: 1px solid var(--border); }
.sv-thumb { flex: none; width: 100%; aspect-ratio: 4 / 3; padding: 0; overflow: hidden; border-radius: 6px; background: var(--surface-2); }
.sv-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.sv-thumb[aria-current] { outline: 3px solid var(--accent); outline-offset: -3px; }
.sv-main { display: flex; flex-direction: column; min-width: 0; min-height: 0; container-type: inline-size; }
/* Top bar: name and details | Edit & mark up | view controls. Narrow: one wrapping row, with the
   Edit button just left of the zoom controls. Wide: three columns, so the button is truly centred. */
.sv-head { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; padding: .5rem .75rem; border-bottom: 1px solid var(--border); }
.sv-head > .sv-head-side:first-child { flex: 1 1 auto; min-width: 0; }
.sv-head-end { justify-content: flex-end; }
@container (min-width: 1100px) {
  .sv-head { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); }
}
.sv-head input { flex: 0 1 260px; width: auto; min-width: 8rem; padding: .3rem .6rem; font-size: .85rem; }
.sv-tools { padding: .4rem .75rem; flex-wrap: wrap; gap: .35rem; border-bottom: 1px solid var(--border); }
.sv-tools [aria-pressed="true"], .sv-options [aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.sv-tools { gap: .5rem; }
/* Edit, Mark up and History: separate boxed groups, each with a small label. */
.sv-group { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem; padding: .25rem .4rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); }
.sv-group-label { margin: 0 .2rem 0 .1rem; font-size: .7rem; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.sv-colors { display: inline-flex; gap: .3rem; margin-left: .3rem; }
.sv-divider { width: 1px; height: 1.4rem; margin: 0 .25rem; background: var(--border); }
.sv-color { width: 1.6rem; height: 1.6rem; padding: 0; border-radius: 50%; border: 2px solid var(--border); }
.sv-color:hover { filter: brightness(1.1); }
.sv-color.active { outline: 2px solid var(--accent); outline-offset: 2px; }
/* Settings for the selected edit tool (straighten, crop, light, redact). */
.sv-options { padding: .35rem .75rem; gap: .75rem; background: var(--surface-2); border-bottom: 1px solid var(--border); }
.sv-options > .row { gap: .6rem; }
.sv-slider { display: flex; align-items: center; gap: .5rem; margin: 0; font-size: .85rem; font-weight: 400; }
.sv-slider input { width: 150px; padding: 0; }
/* While editing: only the edit tools, and nothing that would leave the snapshot. */
#snap-viewer.editing .sv-view-only { display: none; }
#snap-viewer.editing .sv-rail { pointer-events: none; opacity: .4; }
#snap-viewer.editing .sv-stage { cursor: default; }
#snap-viewer.editing #sv-image { visibility: hidden; }
.sv-edit-canvas { position: absolute; touch-action: none; }
.sv-edit-canvas.drawing { cursor: crosshair; }
.sv-edit-canvas:focus { outline: none; } /* takes focus only so keys like Delete reach the editor */
/* Over the preview: the crop box, or a straightening grid. */
.sv-edit-overlay { position: absolute; overflow: hidden; touch-action: none; cursor: crosshair; }
.sv-edit-overlay.grid {
  pointer-events: none;
  background-image: linear-gradient(to right, rgb(255 255 255 / 35%) 1px, transparent 1px), linear-gradient(to bottom, rgb(255 255 255 / 35%) 1px, transparent 1px);
  background-size: calc(100% / 6) calc(100% / 6);
}
.sv-crop-box { position: absolute; outline: 2px solid #fff; box-shadow: 0 0 0 9999px rgb(0 0 0 / 55%); cursor: move; }
.sv-crop-box [data-handle] { position: absolute; width: 14px; height: 14px; margin: -7px 0 0 -7px; background: #fff; border: 1px solid #000; border-radius: 2px; }
.sv-crop-box [data-handle="nw"] { left: 0; top: 0; cursor: nwse-resize; }
.sv-crop-box [data-handle="n"] { left: 50%; top: 0; cursor: ns-resize; }
.sv-crop-box [data-handle="ne"] { left: 100%; top: 0; cursor: nesw-resize; }
.sv-crop-box [data-handle="e"] { left: 100%; top: 50%; cursor: ew-resize; }
.sv-crop-box [data-handle="se"] { left: 100%; top: 100%; cursor: nwse-resize; }
.sv-crop-box [data-handle="s"] { left: 50%; top: 100%; cursor: ns-resize; }
.sv-crop-box [data-handle="sw"] { left: 0; top: 100%; cursor: nesw-resize; }
.sv-crop-box [data-handle="w"] { left: 0; top: 50%; cursor: ew-resize; }
/* Text tool: clicks pass through to the picture; only the text box takes them. */
.sv-edit-overlay.passive { pointer-events: none; cursor: auto; }
.sv-text-select { position: absolute; pointer-events: none; outline: 2px dashed #fff; outline-offset: 3px; box-shadow: 0 0 0 4px rgb(0 0 0 / 45%); border-radius: 2px; }
.sv-text-editor {
  position: absolute; pointer-events: auto; box-sizing: content-box; min-width: 2ch;
  margin: 0; padding: 0; border: none; border-radius: 2px; outline: 1px dashed rgb(255 255 255 / 80%); outline-offset: 2px;
  resize: none; overflow: hidden; white-space: pre; caret-color: currentColor; box-shadow: none;
}
.sv-text-editor:focus { outline: 1px dashed rgb(255 255 255 / 80%); outline-offset: 2px; }
.sv-seg { display: inline-flex; }
.sv-seg > button { border-radius: 0; }
.sv-seg > button:first-child { border-radius: 8px 0 0 8px; }
.sv-seg > button:last-child { border-radius: 0 8px 8px 0; }
.sv-seg > button + button { margin-left: -1px; }
.sv-slider select { width: auto; padding: .2rem .4rem; font-size: .85rem; }
/* Perspective: an outline between 4 corner handles placed on the document. */
.sv-warp { position: absolute; inset: 0; }
.sv-warp svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.sv-warp polygon { fill: rgb(59 130 246 / 15%); stroke: #fff; stroke-width: 2; vector-effect: non-scaling-stroke; stroke-dasharray: 6 4; }
.sv-warp [data-corner] { position: absolute; width: 18px; height: 18px; margin: -9px 0 0 -9px; border-radius: 50%; background: #fff; border: 2px solid var(--accent); box-shadow: 0 0 0 1px #000; cursor: move; touch-action: none; }
@media (pointer: coarse) {
  .sv-crop-box [data-handle] { width: 22px; height: 22px; margin: -11px 0 0 -11px; }
  .sv-warp [data-corner] { width: 28px; height: 28px; margin: -14px 0 0 -14px; }
}
.sv-stage { position: relative; flex: 1; min-height: 0; overflow: hidden; background: #000; cursor: zoom-in; touch-action: none; }
.sv-stage.zoomed { cursor: grab; }
.sv-stage.panning { cursor: grabbing; }
.sv-stage img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; transform-origin: 0 0; user-select: none; }
@media (max-width: 760px) {
  #snap-viewer[open] { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
  .sv-rail { order: 2; flex-direction: row; overflow: auto hidden; border-right: none; border-top: 1px solid var(--border); }
  .sv-thumb { width: 96px; }
}

/* ---------- onsite */
.onsite { height: 100dvh; display: flex; flex-direction: column; background: #000; color: #fff; }
.onsite .stage { flex: 1; }
/* Sharing their screen: the preview of it sits small in the lower-left quarter (setPreviewSmall). */
.stage.preview-small video {
  inset: auto auto .75rem .75rem; width: 50%; height: 50%;
  border: 1px solid #2c3846; border-radius: 8px; box-shadow: 0 4px 16px rgb(0 0 0 / 50%);
}
.preview-size {
  position: absolute; left: .75rem; bottom: .75rem; z-index: 2;
  width: 36px; height: 36px; padding: 0; min-width: 0;
  background: rgb(15 20 25 / 75%); border-color: rgb(255 255 255 / 25%); color: #fff; backdrop-filter: blur(6px);
}
.preview-size:hover { background: rgb(15 20 25 / 90%); }
/* In the small preview's top-right corner. */
.stage.preview-small .preview-size { left: calc(50% + .75rem - 36px - .4rem); bottom: calc(50% + .75rem - 36px - .4rem); }
.onsite-bar {
  display: flex; align-items: center; gap: .5rem; padding: .6rem .75rem;
  padding-bottom: max(.6rem, env(safe-area-inset-bottom));
  background: #111820;
}
.onsite-bar button { background: #1f2a36; border-color: #2c3846; color: #fff; padding: .7rem; min-width: 48px; }
.onsite-bar button.off { background: #4a1d1d; border-color: #6b2525; }
.onsite-bar button.active { background: #b45309; border-color: #b45309; }
.onsite-request {
  display: flex; align-items: center; gap: .5rem; flex-wrap: wrap;
  padding: .6rem .9rem; background: #1f2a36; border-top: 1px solid #2c3846; font-size: .9rem;
}
.onsite-request span { flex: 1; min-width: 12rem; }
.scan-banner { border-left: 3px solid var(--ok); }
.onsite-request button:not(.btn-primary) { background: transparent; border-color: #2c3846; color: #fff; }
.onsite-status { flex: 1; font-size: .85rem; color: #cfd8e3; display: flex; align-items: center; gap: .45rem; min-width: 0; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--warn); flex: none; }
.dot.live { background: #ef4444; box-shadow: 0 0 0 3px rgb(239 68 68 / 30%); }
.icon { width: 20px; height: 20px; flex: none; }
.btn-icon { padding: .4rem .55rem; }
.btn-icon .icon { width: 18px; height: 18px; }

/* ---------- onsite chat drawer */
.chat-tab {
  /* Same row and height as the drawer's close button (.chat-drawer padding + .chat-drawer-head button). */
  position: absolute; right: 0; top: .75rem; z-index: 5;
  padding: .45rem .4rem .45rem .5rem; min-width: 0; border-radius: 10px 0 0 10px; border-right: none;
  background: rgb(15 20 25 / 75%); border-color: rgb(255 255 255 / 25%); color: #fff;
  backdrop-filter: blur(6px);
}
.chat-tab:hover { background: rgb(15 20 25 / 90%); }
.chat-tab-count {
  position: absolute; top: -.5rem; left: -.5rem; min-width: 1.3rem; height: 1.3rem; padding: 0 .3rem;
  border-radius: 999px; background: #ef4444; color: #fff; font-size: .75rem; font-weight: 700;
  display: grid; place-items: center;
}
.chat-drawer {
  position: absolute; top: 0; right: 0; bottom: 0; z-index: 6;
  width: min(360px, 88vw); display: flex; flex-direction: column; gap: .5rem; padding: .75rem;
  background: #111820; border-left: 1px solid #2c3846;
  transform: translateX(100%); transition: transform .2s ease, visibility .2s; visibility: hidden;
  --surface: #1f2a36; --surface-2: #0b1015; --border: #2c3846; --text: #e6ebf1; --muted: #9aa7b5;
  color: var(--text);
}
.chat-drawer.open { transform: none; visibility: visible; }
.chat-drawer-head { display: flex; align-items: center; justify-content: space-between; }
.chat-drawer .chat-log { flex: 1; height: auto; }
.chat-drawer .chat-form { margin-top: 0; }
.chat-drawer button:not(.btn-primary) { background: #1f2a36; border-color: #2c3846; color: #fff; }
.chat-drawer-head button { padding: .45rem; }

/* Sign-in page: SSO and passkey buttons above "or" and the email form. One button fills the row; two share it and stack on narrow screens. */
.signin-buttons { display: flex; flex-wrap: wrap; gap: .6rem; }
.signin-buttons > * { flex: 1 1 9rem; }
.divider-or { display: flex; align-items: center; gap: .75rem; margin: 1rem 0; color: var(--muted); font-size: .85rem; }
.divider-or::before, .divider-or::after { content: ""; flex: 1; border-top: 1px solid var(--border); }

/* Admin settings panels (Authentication page): one bordered box per area, with a tinted header and status badge. */
.settings-panel { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.stack > .settings-panel + .settings-panel { margin-top: 1.25rem; }
.settings-panel > header { display: flex; align-items: flex-start; gap: .75rem; padding: .8rem 1rem; background: var(--surface-2); border-bottom: 1px solid var(--border); }
.settings-panel > header h3 { margin: 0; font-size: 1.02rem; }
.settings-panel > header p { margin: .2rem 0 0; }
.settings-panel > header .badge { margin-left: auto; flex: none; }
.settings-panel-body { padding: 1rem; }
.settings-panel-body .subhead { margin-top: 1.1rem; padding-top: .9rem; border-top: 1px dashed var(--border); }
/* Authentication page while locked to single sign-on (SSO_ONLY variable). */
.lock-banner { margin-bottom: 1rem; padding: .75rem 1rem; background: var(--surface-2); border-radius: 0 var(--radius) var(--radius) 0; font-size: .9rem; }
.settings-panel.locked, .locked-setting { opacity: .55; }
