:root {
  color-scheme: light dark;
  --blue: #0B409C;
  --blue-dark: #0D226B;
  --link: #0B409C;
  --yellow: #FDBE34;
  --bg: #F2F7FF;
  --surface: #ffffff;
  --surface-2: #eaf1fc;
  --text: #14213d;
  --muted: #5b6785;
  --border: #d9e2f2;
  --danger: #b3261e;
  --sidebar-bg: #0D226B;
  --sidebar-text: #dbe4ff;
  --sidebar-active: rgba(255, 255, 255, 0.12);
  --shadow: 0 1px 2px rgba(13, 34, 107, 0.06), 0 4px 16px rgba(13, 34, 107, 0.06);
  --radius: 12px;
  --sidebar-w: 240px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1526;
    --link: #8fb3ff;
    --surface: #171f36;
    --surface-2: #1e2846;
    --text: #e8edf8;
    --muted: #9aa6c4;
    --border: #2a355a;
    --danger: #ff8a80;
    --sidebar-bg: #0a1230;
    --sidebar-text: #c9d4f5;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 16px rgba(0, 0, 0, 0.3);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
    --bg: #0f1526;
    --link: #8fb3ff;
    --surface: #171f36;
    --surface-2: #1e2846;
    --text: #e8edf8;
    --muted: #9aa6c4;
    --border: #2a355a;
    --danger: #ff8a80;
    --sidebar-bg: #0a1230;
    --sidebar-text: #c9d4f5;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 16px rgba(0, 0, 0, 0.3);
}
:root[data-theme="light"] { color-scheme: light; }

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
a { color: var(--link); }
.h1 { font-size: 22px; font-weight: 700; margin: 0; }
.h2 { font-size: 17px; font-weight: 650; margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; word-break: break-all; }
.error { color: var(--danger); font-size: 14px; margin: 12px 0 0; }
.row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }

.view.center {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.login-card { width: 100%; max-width: 380px; text-align: center; }
.login-card .brand { justify-content: center; margin-bottom: 8px; }
.login-card .row { justify-content: center; }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: inherit; }
.brand-lg { font-size: 22px; color: var(--text); }
.brand-mark {
  width: 28px; height: 28px; border-radius: 8px; flex: none;
  background: radial-gradient(circle at 50% 50%, var(--yellow) 0 38%, var(--blue) 40%);
}
.brand-name { letter-spacing: -0.01em; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600;
  cursor: pointer; transition: background .15s, transform .05s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-dark); }
.btn-block { width: 100%; margin-top: 16px; }
.icon { width: 18px; height: 18px; flex: none; }

.spinner {
  width: 36px; height: 36px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--blue);
  animation: spin .8s linear infinite; margin-bottom: 14px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* App shell */
.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100dvh; }
.sidebar {
  background: var(--sidebar-bg); color: var(--sidebar-text);
  display: flex; flex-direction: column; padding: 20px 14px;
  position: sticky; top: 0; height: 100dvh;
}
.sidebar .brand { color: #fff; padding: 4px 8px 18px; font-size: 18px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: 10px;
  color: var(--sidebar-text); text-decoration: none; font-weight: 500;
}
.nav a:hover { background: var(--sidebar-active); color: #fff; }
.nav a.active { background: var(--sidebar-active); color: #fff; box-shadow: inset 3px 0 0 var(--yellow); }
.sidebar-footer { margin-top: auto; border-top: 1px solid rgba(255,255,255,.12); padding-top: 14px; }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 4px 6px; min-width: 0; }
.avatar { width: 34px; height: 34px; border-radius: 50%; flex: none; object-fit: cover; }
.avatar-fallback { display: inline-flex; align-items: center; justify-content: center; background: var(--yellow); color: var(--blue-dark); font-weight: 700; font-size: 14px; }
.user-meta { min-width: 0; }
.user-name { font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-email { font-size: 12px; opacity: .75; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-footer .btn { margin-top: 12px; background: transparent; color: #fff; border-color: rgba(255,255,255,.25); }
.sidebar-footer .btn:hover { background: var(--sidebar-active); }

.main { padding: 24px 28px 48px; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.badge { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; padding: 3px 8px; border-radius: 999px; background: var(--yellow); color: var(--blue-dark); }
.page { display: flex; flex-direction: column; gap: 16px; }
.grid.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
.stat-label { color: var(--muted); font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat-value { font-size: 30px; font-weight: 700; margin-top: 4px; }
.placeholder p:last-child { margin-bottom: 0; }
.kv { display: grid; grid-template-columns: fit-content(45%) minmax(0, 1fr); gap: 6px 18px; margin: 0; }
.kv dd { min-width: 0; overflow-wrap: anywhere; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow);
  font-size: 14px; max-width: calc(100% - 32px); z-index: 10;
}


/* ---------------------------------------------------------------------------
   Data views
   --------------------------------------------------------------------------- */
.h3 { font-size: 15px; font-weight: 650; margin: 0 0 8px; }
.h4 { font-size: 14px; font-weight: 650; margin: 14px 0 6px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
.card-head .h2, .card-head .h3 { margin: 0; }
.grid.two { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.stat-link { text-decoration: none; color: inherit; display: block; transition: transform .08s, box-shadow .15s; }
.stat-link:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(13, 34, 107, 0.12); }
.stat-sub { margin-top: 2px; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 240px; }
.prewrap { white-space: pre-wrap; margin-top: 6px; }
ul.plain { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-direction: column; gap: 4px; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }

.badge-neutral { background: var(--surface-2); color: var(--muted); }
.badge-muted { background: var(--surface-2); color: var(--muted); font-weight: 600; }
.badge-ok { background: #dcf5e6; color: #14663a; }
.badge-warn { background: #fff1d6; color: #8a5a00; }
.badge-danger { background: #fde3e1; color: #9a1f17; }
.badge-info { background: #dde8ff; color: var(--blue-dark); }
.badge-accent { background: var(--yellow); color: var(--blue-dark); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .badge-ok { background: #123f2a; color: #8fe3b4; }
  :root:not([data-theme="light"]) .badge-warn { background: #4a3608; color: #ffd27a; }
  :root:not([data-theme="light"]) .badge-danger { background: #4d1c19; color: #ffa39e; }
  :root:not([data-theme="light"]) .badge-info { background: #1b2b5c; color: #b8caff; }
}
:root[data-theme="dark"] .badge-ok { background: #123f2a; color: #8fe3b4; }
:root[data-theme="dark"] .badge-warn { background: #4a3608; color: #ffd27a; }
:root[data-theme="dark"] .badge-danger { background: #4d1c19; color: #ffa39e; }
:root[data-theme="dark"] .badge-info { background: #1b2b5c; color: #b8caff; }

.badge + .badge { margin-left: 4px; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 4px; }
.input { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 9px 12px; min-width: 0; }
.input:focus { outline: 2px solid var(--blue); outline-offset: 1px; border-color: var(--blue); }
.input.search { flex: 1 1 260px; }
select.input { padding-right: 28px; max-width: 260px; }
.btn-sm { padding: 6px 11px; font-size: 13px; border-radius: 8px; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(.92); background: var(--danger); }
.field { display: flex; flex-direction: column; gap: 6px; margin-top: 14px; font-size: 14px; }
.field textarea, .field input { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { text-align: left; padding: 10px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { font-size: 11px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 650; white-space: nowrap; background: var(--surface-2); position: sticky; top: 0; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: var(--surface-2); }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table td .cell { display: block; min-width: 0; }
.table td.wide { min-width: 220px; }
.table td .cell > a, .table td .cell .muted > a { white-space: nowrap; max-width: 140px; overflow: hidden; text-overflow: ellipsis; display: inline-block; vertical-align: bottom; }
.table td .cell > .muted:not(:has(a)) { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell-main { font-weight: 600; }
.cell-avatar { display: flex; align-items: center; gap: 10px; }
.avatar-sm { width: 28px; height: 28px; border-radius: 8px; object-fit: cover; flex: none; display: inline-flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; }
.avatar-sm.avatar-fallback { background: var(--surface-2); color: var(--muted); }
.empty { padding: 28px; text-align: center; border: 1px dashed var(--border); border-radius: var(--radius); }
.loading { display: flex; align-items: center; gap: 12px; padding: 24px 4px; }
.loading .spinner { width: 22px; height: 22px; border-width: 2px; margin: 0; }
.error-box { display: flex; align-items: center; justify-content: space-between; gap: 12px; border-color: var(--danger); }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 2px; }
.pager-btns { display: flex; gap: 6px; }

.back { display: inline-block; margin-bottom: 12px; font-weight: 600; text-decoration: none; }
.detail-body { display: flex; flex-direction: column; gap: 16px; }
.detail-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 14px; }
.detail-title { display: flex; align-items: center; gap: 14px; min-width: 0; }
.detail-title .avatar { width: 56px; height: 56px; font-size: 20px; }
.detail-title .avatar-sm { width: 56px; height: 56px; font-size: 18px; border-radius: 14px; }
.detail-title .h2 { margin: 0 0 2px; }
.actions { margin: 0; }

.activity { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.activity li { display: flex; align-items: center; gap: 12px; padding: 9px 0; border-top: 1px solid var(--border); }
.activity li:first-child { border-top: 0; }
.activity-icon { width: 30px; height: 30px; border-radius: 8px; background: var(--surface-2); display: inline-flex; align-items: center; justify-content: center; flex: none; font-size: 15px; }
.activity-main { flex: 1; min-width: 0; }
.activity-main a { font-weight: 600; text-decoration: none; }
.activity-main a:hover { text-decoration: underline; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.tabs a { padding: 8px 14px; text-decoration: none; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.active { color: var(--link); border-bottom-color: var(--link); }
.tab-body { display: flex; flex-direction: column; gap: 12px; }

.message-frame { width: 100%; min-height: 96px; border: 1px solid var(--border); border-radius: 10px; background: #fff; resize: vertical; }
.message-text { white-space: pre-wrap; font: 14px/1.5 inherit; margin: 0; padding: 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); max-height: 360px; overflow: auto; }
details.small summary { cursor: pointer; }

.modal { position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-scrim { position: absolute; inset: 0; background: rgba(8, 14, 40, .55); }
.modal-card { position: relative; background: var(--surface); color: var(--text); border-radius: 14px; box-shadow: var(--shadow); padding: 22px; width: 100%; max-width: 460px; }
.modal-body p { margin: 6px 0; }
.modal-actions { justify-content: flex-end; }

/* Theme control (Settings → Appearance) */
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--surface); }
.segmented button { font: inherit; font-weight: 600; padding: 8px 14px; border: 0; background: transparent; color: var(--muted); cursor: pointer; }
.segmented button + button { border-left: 1px solid var(--border); }
.segmented button[aria-pressed="true"] { background: var(--blue); color: #fff; }

.form { margin-top: 10px; display: flex; flex-direction: column; gap: 2px; }
.form .field { margin-top: 8px; }
.form .row { margin-top: 12px; }

/* ---------------------------------------------------------------------------
   Charts (palette validated: series 1-3 pass CVD + contrast gates on both surfaces)
   --------------------------------------------------------------------------- */
:root {
  --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a;
  --series-1-wash: rgba(42, 120, 214, 0.10);
  --deemph: #a8adbd;
  --grid: #e6ebf5; --axis-line: #c9d2e6; --axis-text: #7b869e;
  --meter-track: #cde2fb;
  --heat-0: var(--surface-2);
  --heat-1: #b7d3f6; --heat-2: #86b6ef; --heat-3: #5598e7; --heat-4: #2a78d6; --heat-5: #1c5cab; --heat-6: #0d366b;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70;
    --series-1-wash: rgba(57, 135, 229, 0.14);
    --deemph: #5c6784;
    --grid: #232d4d; --axis-line: #34406a; --axis-text: #8d98b8;
    --meter-track: #1b3766;
    --heat-1: #184f95; --heat-2: #256abf; --heat-3: #3987e5; --heat-4: #6da7ec; --heat-5: #9ec5f4; --heat-6: #cde2fb;
  }
}
:root[data-theme="dark"] {
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70;
  --series-1-wash: rgba(57, 135, 229, 0.14);
  --deemph: #5c6784;
  --grid: #232d4d; --axis-line: #34406a; --axis-text: #8d98b8;
  --meter-track: #1b3766;
  --heat-1: #184f95; --heat-2: #256abf; --heat-3: #3987e5; --heat-4: #6da7ec; --heat-5: #9ec5f4; --heat-6: #cde2fb;
}

.chart-card .chart-body { margin-top: 6px; }
.chart-table { margin-top: 12px; max-height: 320px; overflow: auto; }
svg.chart { display: block; max-width: 100%; overflow: visible; font: 11px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
svg.chart .grid { stroke: var(--grid); stroke-width: 1; }
svg.chart .baseline { stroke: var(--axis-line); stroke-width: 1; }
svg.chart .axis { fill: var(--axis-text); font-variant-numeric: tabular-nums; }
svg.chart .value { fill: var(--text); font-weight: 600; font-size: 11px; }
svg.chart .bar { fill: var(--series-1); transition: opacity .12s; }
svg.chart .hit { fill: transparent; }
svg.chart .bar-g:hover .bar, svg.chart .bar-g:focus .bar { opacity: .75; }
svg.chart .bar-g:focus, svg.chart .pt-g:focus { outline: none; }
svg.chart .line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
svg.chart .area-fill { fill: var(--series-1-wash); }
svg.chart .dot { fill: var(--series-1); stroke: var(--surface); stroke-width: 2; opacity: 0; transition: opacity .12s; }
svg.chart .pt-g:hover .dot, svg.chart .pt-g:focus .dot, svg.chart .pt-g:last-of-type .dot { opacity: 1; }

.spark { display: block; overflow: visible; }
.spark-line { fill: none; stroke: var(--deemph); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.spark-accent { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linecap: round; }
.spark-dot { fill: var(--series-1); stroke: var(--surface); stroke-width: 2; }
.stat .spark { margin-top: 8px; }
.stat-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 10px; }

.hbars { display: flex; flex-direction: column; gap: 6px; }
.hbar-row { display: grid; grid-template-columns: minmax(90px, 160px) 1fr 48px; align-items: center; gap: 10px; font-size: 13px; }
.hbar-row:hover .hbar-fill { opacity: .8; }
.hbar-label a { text-decoration: none; }
.hbar-track { height: 18px; background: transparent; }
.hbar-fill { height: 100%; background: var(--series-1); border-radius: 0 4px 4px 0; min-width: 2px; transition: opacity .12s; }
.hbar-value { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }

.stack { display: flex; gap: 2px; height: 22px; border-radius: 6px; overflow: hidden; }
.stack-seg { display: flex; align-items: center; justify-content: center; color: #fff; font-size: 11px; font-weight: 600; min-width: 2px; }
.stack-seg.s1, .swatch.s1 { background: var(--series-1); }
.stack-seg.s2, .swatch.s2 { background: var(--series-2); }
.stack-seg.s3, .swatch.s3 { background: var(--series-3); }
.stack-seg.s3 span { color: #0b2a1c; }
.legend { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13px; color: var(--muted); }
.legend strong { color: var(--text); }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: 0; }

.heat-grid { display: grid; gap: 2px; align-items: stretch; }
.heat-row, .heat-col { font-size: 11px; color: var(--axis-text); display: flex; align-items: center; }
.heat-col { justify-content: flex-start; height: 16px; }
.heat-cell { aspect-ratio: 1 / 1; border-radius: 3px; background: var(--heat-0); min-width: 0; }
.heat-cell.l1 { background: var(--heat-1); } .heat-cell.l2 { background: var(--heat-2); } .heat-cell.l3 { background: var(--heat-3); }
.heat-cell.l4 { background: var(--heat-4); } .heat-cell.l5 { background: var(--heat-5); } .heat-cell.l6 { background: var(--heat-6); }
.heat-cell:hover, .heat-cell:focus { outline: 2px solid var(--text); outline-offset: -2px; }
.heat-scale { display: flex; align-items: center; gap: 4px; margin-top: 10px; justify-content: flex-end; }
.heat-scale .heat-cell { width: 14px; height: 14px; aspect-ratio: auto; }

.meter { display: inline-flex; align-items: center; gap: 8px; min-width: 90px; }
.meter-track { flex: 1; height: 6px; border-radius: 3px; background: var(--meter-track); overflow: hidden; }
.meter-fill { display: block; height: 100%; background: var(--series-1); border-radius: 3px; }
.cell-meter { display: flex; align-items: center; gap: 8px; }
.cell-meter .meter { min-width: 48px; width: 48px; }

.chart-tip { position: absolute; z-index: 30; pointer-events: none; background: var(--text); color: var(--bg); font-size: 12px; font-weight: 600; padding: 6px 9px; border-radius: 7px; box-shadow: var(--shadow); white-space: nowrap; }
.spark-cell { width: 76px; }

/* Dashboard filter row */
.filter-row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.filter-spacer { flex: 1; }
#dash-body { display: flex; flex-direction: column; gap: 16px; transition: opacity .15s; }
#dash-body.is-loading { opacity: .45; pointer-events: none; }

.btn-group { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.report-details { max-width: 320px; margin-top: 4px; }

/* Sidebar badges */
.nav a { position: relative; }
.nav-badge { margin-left: auto; min-width: 22px; height: 20px; padding: 0 7px; border-radius: 999px; display: inline-flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; background: rgba(255, 255, 255, 0.16); color: #fff; font-variant-numeric: tabular-nums; }
.nav-badge.is-new { background: var(--danger); color: #fff; box-shadow: 0 0 0 2px var(--sidebar-bg); animation: badge-pop .35s ease-out; }
@keyframes badge-pop { from { transform: scale(.6); } to { transform: scale(1); } }
@media (max-width: 760px) { .nav-badge { margin-left: 6px; } }

/* ---------------------------------------------------------------------------
   Responsive refinements
   --------------------------------------------------------------------------- */
.table td time, .table td .nowrap { white-space: nowrap; }
.table .cell-main, .table .cell-avatar > div { max-width: 320px; }
.table .cell-main { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table .cell-main .badge { vertical-align: 1px; }
.detail-title .h2, .detail-head .h2 { overflow-wrap: anywhere; }
.hbar-label { min-width: 0; }
.nav-label { white-space: nowrap; }

/* Tablet: icon rail so content keeps its width */
@media (min-width: 761px) and (max-width: 1080px) {
  :root { --sidebar-w: 72px; }
  .sidebar { padding: 16px 10px; align-items: center; }
  .sidebar .brand { padding: 4px 0 16px; justify-content: center; }
  .brand-name, .nav-label, .user-meta, .sidebar-footer .btn { display: none; }
  .nav { width: 100%; }
  .nav a { justify-content: center; padding: 12px 0; position: relative; }
  .nav a.active { box-shadow: inset 3px 0 0 var(--yellow); }
  .nav-badge { position: absolute; top: 4px; right: 6px; margin: 0; min-width: 18px; height: 18px; padding: 0 5px; font-size: 10px; }
  .sidebar-footer { width: 100%; display: flex; justify-content: center; padding-top: 10px; }
  .user-chip { padding: 0; }
  .main { padding: 22px 22px 44px; }
}

/* Phone: compact sticky header, card-style tables, two-up tiles */
@media (max-width: 760px) {
  .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
  .sidebar, .main { min-width: 0; }
  .sidebar {
    position: sticky; top: 0; z-index: 15; height: auto;
    padding: calc(8px + env(safe-area-inset-top, 0px)) 12px 0;
    box-shadow: 0 2px 10px rgba(0, 0, 0, .25);
  }
  .sidebar .brand { padding: 4px 4px 8px; font-size: 16px; }
  .sidebar .brand-mark { width: 22px; height: 22px; border-radius: 6px; }
  .nav { flex-direction: row; flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; gap: 0; margin: 0 -12px; padding: 0 8px; }
  .nav::-webkit-scrollbar { display: none; }
  .nav a { flex: none; flex-direction: column; gap: 3px; padding: 6px 12px 9px; border-radius: 0; font-size: 11px; font-weight: 600; }
  .nav a .icon { width: 20px; height: 20px; }
  .nav a:hover { background: transparent; }
  .nav a.active { background: transparent; box-shadow: inset 0 -3px 0 var(--yellow); }
  .nav-badge { position: absolute; top: 0; left: calc(50% + 6px); margin: 0; min-width: 16px; height: 16px; padding: 0 4px; font-size: 10px; }
  .sidebar-footer { display: none; }
  .sidebar::after { content: ''; position: absolute; right: 0; bottom: 0; width: 40px; height: 56px; background: linear-gradient(90deg, transparent, var(--sidebar-bg)); pointer-events: none; }
  .table td .cell > a, .table td .cell .muted > a { white-space: normal; max-width: none; display: inline; }
  .main { padding: 16px 16px 40px; }
  .topbar { margin-bottom: 14px; }
  .h1 { font-size: 20px; }

  .grid.stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .card.stat { padding: 14px; min-width: 0; }
  .stat-label { font-size: 11px; }
  .stat-value { font-size: 24px; }
  .stat-sub { font-size: 12px; line-height: 1.35; }
  .stat .spark { width: 100%; height: 26px; }
  .card { padding: 16px; }
  .grid.two { gap: 12px; }
  .page, .detail-body { gap: 12px; }

  .filter-row .segmented { display: flex; width: 100%; }
  .filter-row .segmented button { flex: 1; padding: 8px 4px; font-size: 13px; }
  .filter-spacer { display: none; }
  .toolbar .input.search { flex-basis: 100%; }
  .toolbar select.input { flex: 1 1 36%; max-width: none; }
  .detail-head .actions .btn { width: 100%; }
  .kv { gap: 6px 12px; font-size: 14px; }

  /* Tables become stacked cards; each cell shows its column label */
  .table-wrap { border: 0; background: transparent; overflow: visible; }
  .table, .table tbody, .table tr, .table td { display: block; }
  .table thead { display: none; }
  .table tr { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 6px 12px; margin-bottom: 10px; box-shadow: var(--shadow); }
  .table td { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; border: 0; padding: 7px 0; font-size: 14px; min-width: 0; }
  .table td + td { border-top: 1px solid var(--border); }
  .table td::before { content: attr(data-label); flex: 0 0 34%; max-width: 120px; color: var(--muted); font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: .04em; padding-top: 2px; text-align: left; }
  .table td .cell { flex: 1 1 auto; min-width: 0; text-align: right; overflow-wrap: anywhere; }
  .table td.wide .cell, .table td .cell:has(.cell-main), .table td .cell:has(details), .table td .cell:has(.report-details) { text-align: left; }
  .table td .cell .cell-avatar { justify-content: flex-start; }
  .table td .cell .cell-meter { justify-content: flex-end; }
  .table td .cell .btn-group { justify-content: flex-end; }
  .table td.no-label::before { display: none; }
  .table td.no-label { justify-content: flex-end; }
  .table td > * { min-width: 0; }
  .table td.num { text-align: right; }
  .table td.num, .table td.wide { min-width: 0; }
  .table .cell-main, .table td .cell > .muted, .table td .cell > .muted:not(:has(a)) { white-space: normal; max-width: none; overflow-wrap: anywhere; }
  .table .cell-avatar > div { max-width: none; }
  .table .truncate { white-space: normal; max-width: none; }
  .table tr.clickable:hover td { background: transparent; }
  .table tr.clickable:active { background: var(--surface-2); }
  .cell-meter { justify-content: flex-end; }
  .report-details { max-width: none; }
  .chart-table .table tr { padding: 0 12px; }
  .pager { flex-wrap: wrap; }
  .message-frame { max-height: 60vh; }
  .heat-grid { gap: 1px; }
  .heat-row, .heat-col { font-size: 9px; }
  .modal-card { padding: 18px; }
}

/* Reports summary block spacing (matches .page) */
#reports-summary, #reports-list { display: flex; flex-direction: column; gap: 16px; }
#reports-summary:empty { display: none; }
@media (max-width: 760px) { #reports-summary, #reports-list { gap: 12px; } }

.avatar-slot { display: inline-flex; flex: none; }
.avatar-slot img.avatar-sm { display: block; }
.detail-title .avatar-slot .avatar-sm { width: 56px; height: 56px; border-radius: 14px; }
