/* Technician pages (console, CG Admin, start-from-Core): app shell, light and dark themes.
   Loaded after style.css on pages with <body class="console">; customer pages are untouched.
   Colours are CG brand: red #E93E3F, blue #066AB5, charcoal #333333, grey #EBECF0. */

body.console {
  --bg: #f4f5f8;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --border: #e3e5ea;
  --border-strong: #d5d7de;
  --text: #333333;
  --charcoal: #333333;
  --muted: #6b6f7a;
  --grey: #ebecf0;
  --grey-2: #d5d7de;
  --accent: #e93e3f;
  --accent-hover: #c9302f;
  --accent-soft: #fdecec;
  --blue: #066ab5;
  --blue-hover: #05589a;
  --blue-soft: #e6f0fa;
  --ok: #1f8a4c;
  --ok-soft: #e3f5ea;
  --warn: #9a6514;
  --warn-soft: #fff4e0;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 1px 3px rgba(16, 24, 40, 0.06);
  --input-bg: #ffffff;
  color-scheme: light;
}

/* Dark: chosen explicitly, or following the system unless light was chosen. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) body.console {
    --bg: #111216;
    --surface: #1a1b20;
    --surface-2: #212228;
    --border: #2b2d34;
    --border-strong: #3a3c44;
    --text: #e6e7eb;
    --charcoal: #f1f2f5;
    --muted: #9b9eaa;
    --grey: #2b2d34;
    --grey-2: #3a3c44;
    --accent: #f05455;
    --accent-hover: #f46b6c;
    --accent-soft: #3a1d1f;
    --blue: #3d8fd6;
    --blue-hover: #5aa3e2;
    --blue-soft: #16273a;
    --ok: #4cc27f;
    --ok-soft: #15301f;
    --warn: #e0a64a;
    --warn-soft: #33270f;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    --input-bg: #15161a;
    color-scheme: dark;
  }
}
:root[data-theme='dark'] body.console {
  --bg: #111216;
  --surface: #1a1b20;
  --surface-2: #212228;
  --border: #2b2d34;
  --border-strong: #3a3c44;
  --text: #e6e7eb;
  --charcoal: #f1f2f5;
  --muted: #9b9eaa;
  --grey: #2b2d34;
  --grey-2: #3a3c44;
  --accent: #f05455;
  --accent-hover: #f46b6c;
  --accent-soft: #3a1d1f;
  --blue: #3d8fd6;
  --blue-hover: #5aa3e2;
  --blue-soft: #16273a;
  --ok: #4cc27f;
  --ok-soft: #15301f;
  --warn: #e0a64a;
  --warn-soft: #33270f;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  --input-bg: #15161a;
  color-scheme: dark;
}

body.console { background: var(--bg); color: var(--text); }
.console a { color: var(--blue); }
.console h1, .console h2, .console h3 { color: var(--charcoal); }
.console .muted { color: var(--muted); }

/* ---- Top bar ---- */
.console .topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 20px;
  height: 60px; padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: inset 0 3px 0 var(--accent);
}
.console .topbar .brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--charcoal); }
.console .topbar .brand img { height: 30px; }
.console .topbar .brand b { font-size: 1.02rem; }
.console .topbar .brand span { color: var(--muted); font-weight: 600; font-size: 0.9rem; padding-left: 10px; border-left: 1px solid var(--border-strong); }
.console .nav { display: flex; gap: 4px; }
.console .nav a { color: var(--muted); text-decoration: none; font-weight: 600; font-size: 0.9rem; padding: 7px 12px; border-radius: 8px; }
.console .nav a:hover { color: var(--text); background: var(--surface-2); }
.console .nav a[aria-current='page'] { color: var(--text); background: var(--surface-2); }
.console .topbar .spacer { flex: 1; }
.console .user { display: flex; align-items: center; gap: 10px; font-size: 0.9rem; }
.console .avatar {
  width: 32px; height: 32px; border-radius: 50%; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 0.8rem;
}
.console .icon-btn {
  width: 34px; height: 34px; padding: 0; border-radius: 8px;
  background: transparent; color: var(--muted); border: 1px solid var(--border);
  font-size: 1rem; line-height: 1;
}
.console .icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* ---- Layout & surfaces ---- */
.console .page { max-width: 1160px; margin: 0 auto; padding: 28px 24px 48px; }
.console .page-head { display: flex; align-items: flex-end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.console .page-head h1 { font-size: 1.5rem; margin: 0; }
.console .page-head p { margin: 4px 0 0; }
.console .card { background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); border-radius: 12px; }
.console .card + .card { margin-top: 20px; }
.console .stats .card + .card { margin-top: 0; }
.console .card-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.console .card-head h2 { font-size: 1.05rem; margin: 0; }

/* ---- Controls ---- */
.console input[type='text'], .console input[type='email'], .console input[type='password'],
.console input[type='search'], .console textarea, .console select.select {
  background: var(--input-bg); color: var(--text); border-color: var(--border-strong);
}
.console input::placeholder { color: var(--muted); }
.console button, .console .btn { background: var(--accent); }
.console button:hover, .console .btn:hover { background: var(--accent-hover); }
.console .btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border-strong); }
.console .btn-secondary:hover { background: var(--surface-2); }
.console .btn-blue { background: var(--blue); }
.console .btn-blue:hover { background: var(--blue-hover); }
.console .btn-sm { padding: 6px 12px; font-size: 0.85rem; border-radius: 7px; }
.console .btn-ghost { background: transparent; color: var(--muted); border: 1px solid transparent; }
.console .btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.console .error { color: var(--accent); }
.console details summary { cursor: pointer; }

/* ---- Start a session ---- */
.console .start-form { display: flex; gap: 10px; margin-top: 14px; }
.console .start-form input { flex: 1; font-size: 1rem; padding: 12px 14px; }
.console .start-form button { padding: 12px 22px; font-size: 1rem; }
.console .new-result {
  margin-top: 18px; padding: 18px 20px; border-radius: 10px;
  background: var(--surface-2); border: 1px solid var(--border);
  display: grid; grid-template-columns: auto 1fr; gap: 6px 28px; align-items: center;
}
.console .new-result .code {
  grid-row: span 2; font-size: 2.6rem; font-weight: 700; letter-spacing: 0.18em;
  font-variant-numeric: tabular-nums; color: var(--charcoal);
}
.console .new-result .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.console .countdown { font-variant-numeric: tabular-nums; }
.console .countdown.low { color: var(--warn); font-weight: 600; }

/* ---- At a glance ---- */
.console .stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin: 20px 0; }
.console .stat { padding: 16px 18px; }
.console .stat .n { font-size: 1.7rem; font-weight: 700; color: var(--charcoal); font-variant-numeric: tabular-nums; }
.console .stat .l { font-size: 0.85rem; color: var(--muted); font-weight: 600; display: flex; align-items: center; gap: 6px; }

/* ---- Status ---- */
.console .status { display: inline-flex; align-items: center; gap: 7px; font-size: 0.85rem; font-weight: 600; white-space: nowrap; }
.console .status::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.console .status.active { color: var(--ok); }
.console .status.active::before { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.console .status.joined { color: var(--blue); }
.console .status.joined::before { background: var(--blue); }
.console .status.waiting { color: var(--warn); }
.console .status.waiting::before { background: var(--warn); }
.console .status.ended, .console .status.expired, .console .status.denied { color: var(--muted); }
.console .dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.console .dot.ok { background: var(--ok); }
.console .dot.warn { background: var(--warn); }
.console .dot.muted { background: var(--muted); }

/* ---- Session list ---- */
.console .segmented { display: inline-flex; padding: 3px; border-radius: 9px; background: var(--surface-2); border: 1px solid var(--border); }
.console .segmented button { background: transparent; color: var(--muted); padding: 5px 12px; font-size: 0.85rem; border-radius: 6px; }
.console .segmented button:hover { background: transparent; color: var(--text); }
.console .segmented button[aria-pressed='true'] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.console .toggle { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; font-size: 0.85rem; color: var(--muted); margin: 0; }
.console table.sessions { margin-top: 12px; }
.console table.sessions th { color: var(--muted); font-size: 0.75rem; border-bottom: 1px solid var(--border); padding: 10px 12px; }
.console table.sessions td { border-bottom: 1px solid var(--border); padding: 12px; font-size: 0.92rem; }
.console table.sessions tr:last-child td { border-bottom: 0; }
.console table.sessions tbody tr:hover td { background: var(--surface-2); }
.console table.sessions .ref { font-weight: 600; color: var(--charcoal); }
.console table.sessions .sub { font-size: 0.82rem; color: var(--muted); margin-top: 2px; }
.console table.sessions .mono { font-variant-numeric: tabular-nums; letter-spacing: 0.08em; font-weight: 600; }
.console table.sessions .when { white-space: nowrap; color: var(--muted); }
.console table.sessions td.actions { display: table-cell; text-align: right; white-space: nowrap; }
.console table.sessions .actions > * + * { margin-left: 6px; }
.console .empty { text-align: center; padding: 36px 16px; color: var(--muted); }
.console .empty b { display: block; color: var(--text); margin-bottom: 4px; }

/* ---- Sign in ---- */
.console .signin { max-width: 440px; margin: 64px auto; padding: 0 16px; }
.console .signin .card { padding: 28px; }

/* Older pages (CG Admin, start-from-Core) keep their markup; only colours and the bar change. */
.console .brandbar { background: var(--surface); border-bottom-color: var(--accent); }
.console .wordmark { color: var(--charcoal); }
.console .wordmark span { color: var(--accent); }
.console table th, .console table td { border-bottom-color: var(--border); }
.console .pill { background: var(--surface-2); color: var(--muted); }
.console .pill.active { background: var(--ok-soft); color: var(--ok); }
.console .pill.waiting { background: var(--warn-soft); color: var(--warn); }
.console .pill.joined { background: var(--blue-soft); color: var(--blue); }
.console hr.sep { border-top-color: var(--border); }
.console .code-display { color: var(--charcoal); }

@media (max-width: 760px) {
  .console .topbar { gap: 10px; padding: 0 14px; }
  .console .topbar .brand span, .console .topbar .brand b, .console .user .name { display: none; }
  .console .nav { overflow-x: auto; min-width: 0; flex: 1; }
  .console .nav a { white-space: nowrap; padding: 7px 9px; }
  .console .topbar .spacer { display: none; }
  .console .start-form { flex-direction: column; }
  .console .stats { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .console .stat { padding: 12px; }
  .console .new-result { grid-template-columns: 1fr; }
  .console .new-result .code { grid-row: auto; font-size: 2.1rem; }
  .console table.sessions th:nth-child(3), .console table.sessions td:nth-child(3),
  .console table.sessions th:nth-child(4), .console table.sessions td:nth-child(4),
  .console table.sessions th:nth-child(5), .console table.sessions td:nth-child(5) { display: none; }
  .console table.sessions td, .console table.sessions th { padding-left: 8px; padding-right: 8px; }
  .console .page { padding: 18px 14px 40px; }
}
.console .scope-note { margin: 18px 0 -8px; min-height: 0; }
.console .scope-note:empty { display: none; }

/* ---- Customer pages (join, help, privacy) ---- */
.console.customer .wrap { margin: 48px auto; }
.console.customer .card { padding: 32px; }
.console.customer .card h1 { font-size: 1.55rem; }
.console.customer .code-input input { background: var(--input-bg); color: var(--charcoal); border-color: var(--border-strong); }
.console.customer .code-input input:focus { border-color: var(--blue); }
.console.customer .download-steps li::marker { color: var(--accent); font-weight: 700; }
.console.customer .site-footer, .console.customer .site-footer a { color: var(--muted); }
.console.customer .chat-log { background: var(--surface-2); }
@media (max-width: 640px) {
  .console.customer .wrap { margin: 20px auto; }
  .console.customer .card { padding: 22px; }
}

/* ---- Session viewer ---- */
body.console.viewer { --stage: #e2e4e9; --stage-text: #4a4e59; background: var(--bg); color: var(--text); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) body.console.viewer { --stage: #0b0c0f; --stage-text: #b4b7c2; }
}
:root[data-theme='dark'] body.console.viewer { --stage: #0b0c0f; --stage-text: #b4b7c2; }

.console.viewer .viewer-bar {
  height: 56px; gap: 6px; padding: 0 12px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  box-shadow: inset 0 3px 0 var(--accent);
}
.console.viewer .vb-logo { display: flex; padding: 4px; border-radius: 8px; }
.console.viewer .vb-logo:hover { background: var(--surface-2); }
.console.viewer .vb-logo img { height: 26px; }
.console.viewer .vb-title { display: flex; align-items: center; gap: 8px; min-width: 0; margin-right: 4px; }
.console.viewer .vb-title .title { font-weight: 700; color: var(--charcoal); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 260px; margin: 0; }
.console.viewer .vb-sep { width: 1px; height: 24px; background: var(--border); margin: 0 4px; flex: none; }
.console.viewer .viewer-bar button, .console.viewer .viewer-bar select {
  background: var(--surface); color: var(--text); border: 1px solid var(--border-strong);
  padding: 6px 11px; font-size: 0.84rem; font-weight: 600; border-radius: 7px; height: 34px;
}
.console.viewer .viewer-bar button:hover:not(:disabled), .console.viewer .viewer-bar select:hover:not(:disabled) { background: var(--surface-2); }
.console.viewer .viewer-bar button:disabled, .console.viewer .viewer-bar select:disabled { opacity: 0.45; }
.console.viewer .viewer-bar label { color: var(--muted); font-weight: 600; margin: 0; gap: 5px; }
/* Control is the main action: outlined in blue when available, filled when on. */
.console.viewer #control-btn:not(:disabled) { border-color: var(--blue); color: var(--blue); }
.console.viewer .viewer-bar button.on, .console.viewer #control-btn.on { background: var(--blue); border-color: var(--blue); color: #fff; }
.console.viewer .viewer-bar button.danger { background: var(--accent); border-color: var(--accent); color: #fff; }
.console.viewer .viewer-bar button.danger:hover { background: var(--accent-hover); }
.console.viewer .viewer-bar .icon-btn { width: 34px; padding: 0; color: var(--muted); }
.console.viewer .viewer-bar .stats { color: var(--muted); font-size: 0.75rem; margin-right: 4px; white-space: nowrap; }

.console.viewer .viewer-main { height: calc(100vh - 56px); }
.console.viewer .stage { background: var(--stage); }
.console.viewer .stage video { background: #000; box-shadow: 0 4px 24px rgba(0, 0, 0, 0.25); }
.console.viewer .stage .overlay { color: var(--stage-text); }
.console.viewer .spinner { border-color: var(--border-strong); border-top-color: var(--accent); }

.console.viewer .side { width: 320px; background: var(--surface); border-left: 1px solid var(--border); padding: 16px; gap: 10px; }
.console.viewer .side h3 { color: var(--muted); font-size: 0.72rem; letter-spacing: 0.06em; margin: 8px 0 0; }
.console.viewer .side h3:first-child { margin-top: 0; }
.console.viewer .kv { font-size: 0.86rem; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.console.viewer .kv dt { color: var(--muted); }
.console.viewer .kv dd { color: var(--text); }
.console.viewer .side button { background: var(--surface); color: var(--text); border: 1px solid var(--border-strong); padding: 8px 10px; font-size: 0.85rem; }
.console.viewer .side button:hover:not(:disabled) { background: var(--surface-2); }
.console.viewer .side .chat-log { background: var(--surface-2); border: 1px solid var(--border); color: var(--text); }
.console.viewer .side input { background: var(--input-bg); color: var(--text); border-color: var(--border-strong); }
.console.viewer .side .muted { color: var(--muted); }
.console.viewer .transfer { background: var(--surface-2); border: 1px solid var(--border); color: var(--text); border-radius: 8px; }
.console.viewer .transfer-status { color: var(--muted); }

/* In the All screens grid the viewer is a bare screen. */
.console.viewer.tile .viewer-main { height: 100vh; }

/* ---- All screens grid ---- */
body.console.wall { background: var(--bg); color: var(--text); }
.console.wall .wall-bar { height: 56px; background: var(--surface); border-bottom: 1px solid var(--border); box-shadow: inset 0 3px 0 var(--accent); }
.console.wall .wall-bar .title { color: var(--charcoal); }
.console.wall .wall-bar a { color: var(--blue); }
.console.wall .wall-bar .icon-btn { width: 34px; height: 34px; padding: 0; background: transparent; color: var(--muted); border: 1px solid var(--border); }
.console.wall .wall-tile { background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); border-radius: 12px; }
.console.wall .wall-tile-head .name { color: var(--charcoal); }
.console.wall .wall-tile-head .muted { color: var(--muted); }
.console.wall .wall-tile iframe { background: var(--bg); }
.console.wall .wall-empty { color: var(--muted); }
.console.viewer .code-display { color: var(--charcoal); }
.console.viewer .side .link-btn { border: 0 !important; color: var(--blue) !important; }
.console.viewer .viewer-bar > * { flex-shrink: 0; }
.console.viewer .viewer-bar button, .console.viewer .viewer-bar select, .console.viewer .viewer-bar label { white-space: nowrap; }
.console.viewer .viewer-bar .vb-title { flex-shrink: 0; }
.console.viewer .viewer-bar #keys-select { max-width: 150px; }
.console.viewer .viewer-bar .grow { flex: 1 1 0; min-width: 0; }
.console.viewer .viewer-bar .stats { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 1280px) {
  .console.viewer .vb-title .title { max-width: 160px; }
  .console.viewer .side { width: 280px; }
}
.console.viewer .conn { font-size: 0.8rem; color: var(--muted); background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; font-variant-numeric: tabular-nums; }

/* ---- Technician pages on phones and small tablets ---- */
.console.viewer #panel-btn { display: none; }
.console .card:has(> table), .console .card:has(> .table-scroll) { overflow-x: auto; }
.console.wall .wall-grid { grid-template-columns: repeat(auto-fill, minmax(min(100%, 380px), 1fr)); }

@media (max-width: 900px) {
  /* Viewer: one scrolling toolbar row, the screen fills what's left, details in a sheet. */
  .console.viewer .viewer-bar { overflow-x: auto; scrollbar-width: none; padding: 0 8px; }
  .console.viewer .viewer-bar::-webkit-scrollbar { display: none; }
  .console.viewer .viewer-bar .grow { display: none; }
  .console.viewer .vb-title .title { max-width: 130px; }
  .console.viewer #panel-btn { display: inline-flex; }
  /* Keep the essentials in view; the rest of the toolbar scrolls after them. */
  .console.viewer .viewer-bar > * { order: 5; }
  .console.viewer .viewer-bar .vb-logo { order: 0; }
  .console.viewer .viewer-bar .vb-title { order: 1; }
  .console.viewer .viewer-bar #panel-btn { order: 2; }
  .console.viewer .viewer-bar #end-btn { order: 3; }
  .console.viewer .viewer-bar .vb-sep:first-of-type { order: 4; }
  .console.viewer .viewer-main { height: calc(100dvh - 56px); }
  .console.viewer .side {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    width: auto; height: min(62dvh, 560px);
    border-left: 0; border-top: 1px solid var(--border); border-radius: 16px 16px 0 0;
    box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.25);
    transform: translateY(105%); transition: transform 0.22s ease;
  }
  .console.viewer.panel-open .side { transform: none; }
  .console.viewer .side .chat-log { min-height: 120px; }
}
@media (prefers-reduced-motion: reduce) {
  .console.viewer .side { transition: none; }
}

@media (max-width: 640px) {
  .console.wall .wall-bar { gap: 8px; padding: 0 10px; }
  .console.wall .wall-bar .small.muted { display: none; }
  .console.wall .wall-grid { padding: 10px; gap: 10px; }
  .console .wrap.wide { padding: 0 10px; }
  .console form.row > input, .console form.row > select, .console form.row > button { flex: 1 1 100%; }
  .console.wall .wall-tile-head .muted { display: none; }
}
