/*
 * Wait In Central — admin dashboard styles.
 * No framework: design tokens on :root, light and dark schemes, CSP-safe (no inline styles needed).
 */

:root {
  color-scheme: light dark;
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #d9dee7;
  --text: #172033;
  --muted: #5b6577;
  --primary: #0b3d91;
  --primary-hover: #0a347c;
  --primary-contrast: #ffffff;
  --accent: #f2a900;
  --nav-bg: #071b3f;
  --nav-text: #c9d4ea;
  --nav-active: #ffffff;
  --ok: #117a3e;
  --ok-bg: #e5f5ec;
  --warn: #8a5a00;
  --warn-bg: #fff4d6;
  --bad: #b3261e;
  --bad-bg: #fdecea;
  --info: #0b57d0;
  --info-bg: #e8f0fe;
  --focus: #0b57d0;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 1px 3px rgb(16 24 40 / 8%);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "Segoe UI Mono", Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1422;
    --surface: #141d2e;
    --surface-2: #192338;
    --border: #2a3650;
    --text: #e6ebf5;
    --muted: #9aa6bd;
    --primary: #5b8def;
    --primary-hover: #7aa3f2;
    --primary-contrast: #0b1220;
    --nav-bg: #0a1224;
    --ok: #5fd08e;
    --ok-bg: #12301f;
    --warn: #f0c35a;
    --warn-bg: #332709;
    --bad: #ff8a80;
    --bad-bg: #3a1614;
    --info: #8ab4f8;
    --info-bg: #15264a;
    --focus: #8ab4f8;
    --shadow: none;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 400 1rem/1.5 var(--font); color: var(--text); background: var(--bg); accent-color: var(--primary); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .75rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; margin-top: .5rem; }
p { margin: 0 0 .75rem; }
a { color: var(--primary); }
a:hover { color: var(--primary-hover); }
code, .mono { font-family: var(--mono); font-size: .92em; }
.upper { text-transform: uppercase; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.nowrap { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.skip-link { position: absolute; left: -999px; top: 0; background: var(--surface); padding: .5rem 1rem; z-index: 100; }
.skip-link:focus { left: 1rem; top: 1rem; }

/* ── shell ── */
.shell { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100vh; }
.sidebar { background: var(--nav-bg); color: var(--nav-text); padding: 1rem .75rem; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: .6rem; padding: .25rem .5rem 1rem; }
.brand strong { display: block; color: #fff; font-size: 1.05rem; }
.brand span { display: block; font-size: .8rem; color: var(--nav-text); }
.brand-lg strong { color: var(--text); font-size: 1.3rem; }
.brand-lg span { color: var(--muted); }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.nav-label { text-transform: uppercase; letter-spacing: .06em; font-size: .7rem; margin: 1rem .6rem .3rem; color: #7f8fb0; }
.sidebar nav a { display: flex; align-items: center; gap: .6rem; color: var(--nav-text); text-decoration: none; padding: .55rem .6rem; border-radius: 8px; min-height: 40px; }
.sidebar nav a:hover { background: rgb(255 255 255 / 7%); color: #fff; }
.sidebar nav a[aria-current="page"] { background: rgb(255 255 255 / 12%); color: var(--nav-active); box-shadow: inset 3px 0 0 var(--accent); }
.ico { width: 1.25rem; text-align: center; opacity: .9; }

.main-col { display: flex; flex-direction: column; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 1rem; padding: .75rem 1.5rem; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.page-title { font-size: 1.25rem; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-right { display: flex; align-items: center; gap: .75rem; }
.nav-toggle { display: none; }
main { padding: 1.5rem; flex: 1; display: flex; flex-direction: column; gap: 1.25rem; max-width: 1400px; width: 100%; }
main:focus { outline: none; }
.footer { padding: 1rem 1.5rem; color: var(--muted); font-size: .8rem; }

/* live indicator */
.live-pill { display: inline-flex; align-items: center; gap: .4rem; font-size: .8rem; padding: .25rem .6rem; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); }
.live-pill .dot { width: .55rem; height: .55rem; border-radius: 50%; background: var(--muted); }
.live-pill[data-state="live"] { color: var(--ok); }
.live-pill[data-state="live"] .dot { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-bg); }
.live-pill[data-state="offline"] { color: var(--warn); }
.live-pill[data-state="offline"] .dot { background: var(--warn); }
.live-pill[data-state="stopped"] { color: var(--muted); }

/* user menu (native <details>) */
.user-menu { position: relative; }
.user-menu summary { display: flex; align-items: center; gap: .5rem; cursor: pointer; list-style: none; padding: .25rem .4rem; border-radius: 8px; }
.user-menu summary::-webkit-details-marker { display: none; }
.user-menu summary::after { content: "▾"; color: var(--muted); font-size: .8rem; }
.avatar { width: 2rem; height: 2rem; border-radius: 50%; background: var(--primary); color: var(--primary-contrast); display: grid; place-items: center; font-weight: 600; }
.user-menu .menu { position: absolute; right: 0; top: calc(100% + .4rem); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 220px; padding: .5rem; display: flex; flex-direction: column; z-index: 20; }
.user-menu .menu a, .user-menu .menu .linklike { padding: .5rem .6rem; border-radius: 6px; text-decoration: none; color: var(--text); text-align: left; }
.user-menu .menu a:hover, .user-menu .menu .linklike:hover { background: var(--surface-2); }
.menu-meta { font-size: .8rem; color: var(--muted); padding: .25rem .6rem; margin: 0; border-bottom: 1px solid var(--border); margin-bottom: .25rem; }
.linklike { background: none; border: 0; font: inherit; cursor: pointer; width: 100%; }

/* ── building blocks ── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem 1.25rem; box-shadow: var(--shadow); }
.card > h2:first-child { margin-top: 0; }
.stack { display: flex; flex-direction: column; gap: .9rem; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem 1.25rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; }
.grid-sidebar { display: grid; grid-template-columns: minmax(0, 1fr) minmax(300px, 380px); gap: 1.25rem; align-items: start; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: .5rem; }
.section-head h2 { margin: 0; }
.form-card { max-width: 900px; }
fieldset.plain { border: 0; padding: 0; margin: 0; min-width: 0; }
.actions { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.actions form { margin: 0; }
.sticky-actions { position: sticky; bottom: 0; display: flex; justify-content: flex-end; padding: .9rem 0; margin-top: 1rem; background: linear-gradient(to top, var(--bg) 70%, transparent); }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1rem; }
.kpis-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1.1rem; display: flex; flex-direction: column; gap: .15rem; box-shadow: var(--shadow); text-decoration: none; color: inherit; }
a.kpi:hover { border-color: var(--primary); }
.kpi-label { color: var(--muted); font-size: .85rem; }
.kpi-value { font-size: 1.75rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.kpi-value.flash { animation: flash 1.2s ease-out; }
@keyframes flash { from { color: var(--accent); } to { color: inherit; } }
@media (prefers-reduced-motion: reduce) { .kpi-value.flash { animation: none; } }

/* tables */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th, .table td { text-align: left; padding: .6rem .7rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.table thead th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: var(--surface-2); position: sticky; top: 0; }
.table tbody th { font-weight: 500; }
.table tbody tr:hover { background: var(--surface-2); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.row-selected, .table tr.row-selected { background: var(--info-bg) !important; }
.empty { text-align: center; color: var(--muted); padding: 2rem !important; }
.meta-cell { max-width: 420px; overflow-wrap: anywhere; }
.table tr.updated { animation: rowflash 1.5s ease-out; }
@keyframes rowflash { from { background: var(--warn-bg); } to { background: transparent; } }
@media (prefers-reduced-motion: reduce) { .table tr.updated { animation: none; } }

/* badges and chips */
.badge { display: inline-block; font-size: .75rem; font-weight: 600; padding: .15rem .55rem; border-radius: 999px; text-transform: capitalize; white-space: nowrap; }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-bad { background: var(--bad-bg); color: var(--bad); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-muted { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.chip { display: inline-block; font-size: .8rem; padding: .1rem .5rem; margin: 0 .25rem .25rem 0; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--border); }

/* alerts */
.alert { padding: .8rem 1rem; border-radius: var(--radius); border: 1px solid transparent; }
.alert p:last-child { margin: 0; }
.alert-ok { background: var(--ok-bg); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 25%, transparent); }
.alert-bad { background: var(--bad-bg); color: var(--bad); border-color: color-mix(in srgb, var(--bad) 25%, transparent); }
.alert-warn { background: var(--warn-bg); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 25%, transparent); }
.alert-secret { background: var(--warn-bg); border-color: var(--accent); color: var(--text); }
.secret-row { display: flex; gap: .5rem; }
.secret-row input { flex: 1; }

/* forms */
.field { display: flex; flex-direction: column; gap: .3rem; min-width: 0; margin: 0; border: 0; padding: 0; }
.field > span, .field > legend { font-weight: 550; font-size: .9rem; }
fieldset.field legend { padding: 0; margin-bottom: .3rem; }
input, select, textarea { font: inherit; font-size: 1rem; color: var(--text); background: var(--surface); border: 1px solid #8a94a6; border-radius: 8px; padding: .55rem .7rem; min-height: 44px; width: 100%; }
textarea { resize: vertical; min-height: 4.5rem; }
input[type="checkbox"], input[type="radio"] { width: 1.1rem; height: 1.1rem; min-height: 0; padding: 0; margin: 0; flex: none; }
input[type="color"] { width: 3rem; padding: .2rem; flex: none; }
input[readonly] { background: var(--surface-2); }
input:user-invalid, select:user-invalid, textarea:user-invalid, [aria-invalid="true"] { border-color: var(--bad); box-shadow: 0 0 0 1px var(--bad); }
.field-error { color: var(--bad); font-size: .85rem; margin: 0; }
.field-error::before { content: "⚠ "; }
.check { display: flex; align-items: center; gap: .55rem; cursor: pointer; min-height: 32px; }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: .25rem 1rem; }
.checks-inline { display: flex; flex-wrap: wrap; gap: .25rem 1rem; }
fieldset:disabled .check { cursor: default; opacity: .75; }
.filters { display: flex; flex-wrap: wrap; gap: .75rem 1rem; align-items: flex-end; }
.filters .field { flex: 1 1 160px; }
.filter-actions { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.quick-ranges { display: flex; gap: .35rem; }
.color-row { display: flex; gap: .5rem; align-items: center; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; font: inherit; font-weight: 550; font-size: .95rem; padding: .5rem 1rem; min-height: 44px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--surface-2); color: var(--text); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-contrast); }
.btn-primary:hover { background: var(--primary-hover); color: var(--primary-contrast); }
.btn-danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--border)); }
.btn-danger:hover { background: var(--bad-bg); color: var(--bad); }
.btn-sm { min-height: 34px; padding: .3rem .7rem; font-size: .85rem; }
.btn-block { width: 100%; }
.btn[aria-busy="true"] { opacity: .7; cursor: progress; }
.icon-btn { font: inherit; background: none; border: 1px solid var(--border); border-radius: 8px; min-width: 36px; min-height: 36px; cursor: pointer; color: var(--text); }
.icon-btn:disabled { opacity: .4; cursor: default; }

/* branch page */
.branch-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; }
.crumbs { margin: 0 0 .25rem; font-size: .9rem; color: var(--muted); }
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tabs a { padding: .6rem .9rem; text-decoration: none; color: var(--muted); border-bottom: 3px solid transparent; white-space: nowrap; font-weight: 550; }
.tabs a:hover { color: var(--text); }
.tabs a[aria-current="page"] { color: var(--primary); border-bottom-color: var(--primary); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .45rem 1rem; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.code { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: .75rem; overflow-x: auto; font-family: var(--mono); font-size: .85rem; white-space: pre; margin: 0 0 .75rem; }
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .5rem; }
.list li { display: flex; flex-direction: column; }
.ticker-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: .5rem; }
.ticker-list li { display: flex; gap: 1rem; justify-content: space-between; align-items: flex-start; border: 1px solid var(--border); border-radius: 8px; padding: .75rem; }
.ticker-text p { margin: 0 0 .25rem; }
.row-actions { display: flex; gap: .35rem; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.row-actions form { margin: 0; }
.logo-preview { max-height: 64px; max-width: 220px; object-fit: contain; background: repeating-conic-gradient(#ddd 0 25%, #fff 0 50%) 0 0 / 12px 12px; border-radius: 6px; padding: 4px; }

/* branding preview */
.display-preview { --p-primary: #0b3d91; --p-secondary: #fff; --p-accent: #f2a900; --p-bg: #071b3f; --p-text: #fff; background: var(--p-bg); color: var(--p-text); border-radius: 10px; padding: 1rem; display: flex; flex-direction: column; gap: .75rem; }
.pv-title { font-weight: 700; letter-spacing: .08em; }
.pv-cards { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.pv-card { background: var(--p-primary); color: var(--p-secondary); border-radius: 8px; padding: .75rem; display: flex; flex-direction: column; }
.pv-card span { font-size: 1.6rem; font-weight: 800; }
.pv-hl { box-shadow: 0 0 0 3px var(--p-accent); }
.pv-ticker { font-size: .85rem; border-top: 1px solid color-mix(in srgb, var(--p-text) 25%, transparent); padding-top: .5rem; }

/* services handled (checkbox cards) */
.service-options { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: .6rem; }
.service-option { display: flex; gap: .7rem; align-items: flex-start; border: 1px solid var(--border); border-radius: 8px; padding: .7rem .8rem; cursor: pointer; min-height: 48px; }
.service-option input { margin-top: .2rem; }
.service-option > span { display: flex; flex-direction: column; gap: .1rem; }
.service-option:has(input:checked) { border-color: var(--primary); background: var(--info-bg); }
.service-option:has(input:disabled) { opacity: .6; cursor: default; }
fieldset:disabled .service-option { cursor: default; }

/* display pairing code */
.pairing-code { font-size: 2.4rem; font-weight: 700; letter-spacing: .15em; margin: .25rem 0; }

/* roles */
.role-card summary { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; cursor: pointer; }
.role-card[open] summary { margin-bottom: 1rem; }
.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; }
.perm-group { border: 1px solid var(--border); border-radius: 8px; padding: .6rem .8rem; margin: 0; }
.perm-group legend { font-weight: 600; padding: 0 .3rem; }

/* feed */
.feed { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .4rem; max-height: 340px; overflow-y: auto; }
.feed li { display: flex; gap: .6rem; align-items: baseline; font-size: .9rem; border-bottom: 1px dashed var(--border); padding-bottom: .4rem; }
.feed time { color: var(--muted); font-size: .8rem; font-variant-numeric: tabular-nums; flex: none; }

/* charts (drawn by reports.js as inline SVG) */
.chart { min-height: 220px; }
.chart svg { width: 100%; height: 240px; display: block; }
.chart .bar-a { fill: var(--primary); }
.chart .bar-b { fill: var(--accent); }
.chart .axis { stroke: var(--border); }
.chart text { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart-legend { display: flex; gap: 1rem; font-size: .8rem; color: var(--muted); margin-top: .4rem; }
.chart-legend span::before { content: ""; display: inline-block; width: .7rem; height: .7rem; border-radius: 2px; margin-right: .35rem; vertical-align: -1px; background: var(--primary); }
.chart-legend span.b::before { background: var(--accent); }

.pager { display: flex; gap: 1rem; justify-content: center; align-items: center; margin-top: 1rem; }

/* confirm dialog (native <dialog>) */
dialog.confirm { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); padding: 1.25rem; max-width: 420px; width: calc(100% - 2rem); box-shadow: 0 20px 40px rgb(0 0 0 / 25%); }
dialog.confirm::backdrop { background: rgb(7 27 63 / 55%); }
dialog.confirm p { margin-bottom: 1.25rem; }

/* auth */
.auth-body { display: grid; place-items: center; min-height: 100vh; padding: 1rem; background: radial-gradient(circle at top, #0b3d91 0, #071b3f 55%); }
.auth-card { background: var(--surface); border-radius: 14px; padding: 2rem; width: 100%; max-width: 400px; box-shadow: 0 25px 50px rgb(0 0 0 / 35%); display: flex; flex-direction: column; gap: 1rem; }

/* responsive */
@media (max-width: 1100px) {
  .grid-sidebar { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 50; transform: translateX(-100%); transition: transform .2s ease; }
  .sidebar.open { transform: none; box-shadow: 0 0 0 100vmax rgb(0 0 0 / 40%); }
  .nav-toggle { display: inline-grid; place-items: center; }
  .grid-2, .grid-3, .kpis-3 { grid-template-columns: minmax(0, 1fr); }
  main { padding: 1rem; }
  .topbar { padding: .6rem 1rem; }
  .user-name { display: none; }
}
@media (prefers-reduced-motion: reduce) { .sidebar { transition: none; } }
@media print {
  .sidebar, .topbar, .filters, .btn, .footer { display: none !important; }
  .shell { display: block; }
  .card { box-shadow: none; break-inside: avoid; }
}
.perm-group .perm { align-items: flex-start; }
.perm-group .perm > span { display: flex; flex-direction: column; }
.perm-desc { line-height: 1.3; }
.stale-note { color: var(--warn); font-weight: 600; }
.total-row th, .total-row td { border-top: 2px solid var(--border); font-weight: 600; }
