/* ==========================================================================
   Mailguard console: tokens, base, shell and shared components.
   Page-specific styling lives in views.css.
   Rules of the house: colours only through tokens; 4/8-based spacing scale;
   status colours are reserved for verdicts and health.
   ========================================================================== */

/* ---------- 1. Tokens ---------- */
:root {
  color-scheme: light;
  /* surfaces and text */
  --bg: #f1f4f8;
  --surface: #ffffff;
  --surface-2: #f6f8fb;
  --surface-3: #eaeff5;
  --text: #0e1b2d;
  --muted: #516074;
  --border: #dce2ea;
  --border-strong: #c3cdda;
  --row-hover: rgba(10, 124, 135, 0.06);
  --row-selected: rgba(10, 124, 135, 0.11);
  --scrim: rgba(7, 18, 34, 0.5);
  --shadow-pop: 0 10px 28px rgba(11, 31, 58, 0.18), 0 2px 6px rgba(11, 31, 58, 0.08);
  --shadow-drawer: -12px 0 40px rgba(11, 31, 58, 0.22);
  /* accent: --accent is a fill (white text passes 4.5:1), --accent-text is for text on surfaces */
  --accent: #0a7c87;
  --accent-hover: #086872;
  --on-accent: #ffffff;
  --accent-text: #06646e;
  --accent-bg: #e0f3f5;
  --accent-bd: #aadce1;
  --focus: #0a7c87;
  /* status: fg is text/icon on bg, solid is for chart fills and dots */
  --ok-fg: #0f6a43;      --ok-bg: #e4f5ec;      --ok-bd: #b4e0c8;      --ok-solid: #1f9d63;
  --warn-fg: #8a5200;    --warn-bg: #fdf1d8;    --warn-bd: #efd08c;    --warn-solid: #c98400;
  --danger-fg: #b01f2b;  --danger-bg: #fdebec;  --danger-bd: #f2bbc0;  --danger-solid: #d1343f;
  --info-fg: #1b5aa6;    --info-bg: #e7f0fb;    --info-bd: #b9d3f1;    --info-solid: #3b82d0;
  --neutral-fg: #46536a; --neutral-bg: #edf0f4; --neutral-bd: #d3dae4; --neutral-solid: #8793a6;
  /* sidebar stays navy in both themes */
  --nav-bg: #0b1f3a;
  --nav-bg-2: #0e2748;
  --nav-text: #c9d6e6;
  --nav-muted: #93a7c0;
  --nav-hover: rgba(255, 255, 255, 0.06);
  --nav-active: rgba(255, 255, 255, 0.1);
  --nav-accent: #34cbd8;
  --nav-border: rgba(255, 255, 255, 0.09);
  /* chart series */
  --c-delivered: var(--ok-solid);
  --c-quarantined: var(--warn-solid);
  --c-rejected: var(--danger-solid);
  --c-processed: var(--info-solid);
  --c-grid: #e3e8ef;
  /* type */
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  /* spacing scale (4px base, 8px rhythm) */
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 24px; --sp-6: 32px; --sp-7: 48px;
  /* radii: controls < panels < dialogs */
  --r-ctl: 6px; --r-panel: 8px; --r-dialog: 12px;
  --topbar-h: 56px;
  --sidebar-w: 248px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #09131f; --surface: #101e30; --surface-2: #0c192a; --surface-3: #16283d;
    --text: #e6edf5; --muted: #9db0c5; --border: #1f3249; --border-strong: #2d4562;
    --row-hover: rgba(255, 255, 255, 0.045); --row-selected: rgba(52, 203, 216, 0.14);
    --scrim: rgba(2, 8, 16, 0.66);
    --shadow-pop: 0 10px 28px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.04);
    --shadow-drawer: -12px 0 40px rgba(0, 0, 0, 0.55);
    --accent: #27b3c1; --accent-hover: #3cc4d1; --on-accent: #032029; --accent-text: #5fd8e4;
    --accent-bg: #0f3640; --accent-bd: #1c5662; --focus: #5fd8e4;
    --ok-fg: #70dca5;      --ok-bg: #0f3326;      --ok-bd: #1c5a40;      --ok-solid: #3cc183;
    --warn-fg: #f3c56d;    --warn-bg: #392a09;    --warn-bd: #6b4d12;    --warn-solid: #e3a73a;
    --danger-fg: #ff9ca4;  --danger-bg: #3c1519;  --danger-bd: #70262d;  --danger-solid: #ee6a74;
    --info-fg: #8fc2ff;    --info-bg: #12294a;    --info-bd: #234a7e;    --info-solid: #5ea4f0;
    --neutral-fg: #b6c2d2; --neutral-bg: #1a2a3d; --neutral-bd: #2b3f57; --neutral-solid: #7d8da3;
    --nav-bg: #071729; --nav-bg-2: #0a2036;
    --c-grid: #1b2d43;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #09131f; --surface: #101e30; --surface-2: #0c192a; --surface-3: #16283d;
  --text: #e6edf5; --muted: #9db0c5; --border: #1f3249; --border-strong: #2d4562;
  --row-hover: rgba(255, 255, 255, 0.045); --row-selected: rgba(52, 203, 216, 0.14);
  --scrim: rgba(2, 8, 16, 0.66);
  --shadow-pop: 0 10px 28px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.04);
  --shadow-drawer: -12px 0 40px rgba(0, 0, 0, 0.55);
  --accent: #27b3c1; --accent-hover: #3cc4d1; --on-accent: #032029; --accent-text: #5fd8e4;
  --accent-bg: #0f3640; --accent-bd: #1c5662; --focus: #5fd8e4;
  --ok-fg: #70dca5;      --ok-bg: #0f3326;      --ok-bd: #1c5a40;      --ok-solid: #3cc183;
  --warn-fg: #f3c56d;    --warn-bg: #392a09;    --warn-bd: #6b4d12;    --warn-solid: #e3a73a;
  --danger-fg: #ff9ca4;  --danger-bg: #3c1519;  --danger-bd: #70262d;  --danger-solid: #ee6a74;
  --info-fg: #8fc2ff;    --info-bg: #12294a;    --info-bd: #234a7e;    --info-solid: #5ea4f0;
  --neutral-fg: #b6c2d2; --neutral-bg: #1a2a3d; --neutral-bd: #2b3f57; --neutral-solid: #7d8da3;
  --nav-bg: #071729; --nav-bg-2: #0a2036;
  --c-grid: #1b2d43;
}

/* ---------- 2. Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 400 14px/1.5 var(--font); font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
h1, h2, h3, h4, p, ul, ol, dl, dd, figure { margin: 0; }
ul, ol { padding: 0; list-style: none; }
h1 { font-size: 22px; line-height: 1.25; font-weight: 650; letter-spacing: -0.012em; }
h2 { font-size: 15px; line-height: 1.3; font-weight: 650; letter-spacing: -0.005em; }
h3 { font-size: 14px; line-height: 1.35; font-weight: 650; }
a { color: var(--accent-text); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }
code, kbd, .mono { font-family: var(--mono); font-size: 0.92em; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 3px; }
[hidden] { display: none !important; }
::selection { background: var(--accent-bg); color: var(--text); }

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.icon-sm { width: 14px; height: 14px; stroke-width: 2; }
.icon-lg { width: 22px; height: 22px; }
.icon-xl { width: 40px; height: 40px; }
.lg-shield { fill: var(--logo-fill, currentColor); stroke: none; }
.lg-check { fill: none; stroke: var(--logo-check, #fff); stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }

.visually-hidden { position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.small { font-size: 12.5px; }
.strong { font-weight: 600; }
.break { overflow-wrap: anywhere; }

.skip-link { position: fixed; left: var(--sp-3); top: -64px; z-index: 200; background: var(--accent); color: var(--on-accent); padding: var(--sp-2) var(--sp-4); border-radius: var(--r-ctl); font-weight: 600; text-decoration: none; transition: top 0.15s; }
.skip-link:focus { top: var(--sp-3); }

.boot { min-height: 100dvh; display: grid; place-content: center; justify-items: center; gap: var(--sp-3); color: var(--muted); }
.boot-logo { color: var(--accent); width: 48px; height: 48px; animation: pulse 1.4s ease-in-out infinite; }
.noscript { padding: var(--sp-5); }
@keyframes pulse { 50% { opacity: 0.45; } }

/* ---------- 3. Shell ---------- */
.shell { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100dvh; }
.sidebar {
  --focus: #7be4ee;
  background: var(--nav-bg); color: var(--nav-text);
  position: sticky; top: 0; height: 100dvh; display: flex; flex-direction: column; z-index: 60;
  border-right: 1px solid var(--nav-border);
}
.sb-brand { display: flex; align-items: center; gap: var(--sp-3); height: var(--topbar-h); padding: 0 var(--sp-4) 0 var(--sp-5); border-bottom: 1px solid var(--nav-border); color: #fff; text-decoration: none; flex: none; }
.sb-brand .icon { width: 28px; height: 28px; --logo-fill: var(--nav-accent); --logo-check: var(--nav-bg); }
.sb-word { font-size: 17px; font-weight: 700; letter-spacing: -0.01em; }
.sb-role { margin-left: auto; font-size: 11.5px; color: var(--nav-muted); border: 1px solid var(--nav-border); border-radius: 999px; padding: 1px 8px; }
.sb-nav { flex: 1; overflow-y: auto; padding: var(--sp-3) var(--sp-3) var(--sp-4); }
.sb-group { margin-top: var(--sp-4); }
.sb-group:first-child { margin-top: var(--sp-1); }
.sb-group-label { padding: 0 var(--sp-3); margin-bottom: var(--sp-1); font-size: 12px; color: var(--nav-muted); font-weight: 600; letter-spacing: 0.02em; }
.nav-link {
  position: relative; display: flex; align-items: center; gap: var(--sp-3); min-height: 38px; padding: 0 var(--sp-3);
  border-radius: var(--r-ctl); color: var(--nav-text); text-decoration: none; font-weight: 500; transition: background 0.12s, color 0.12s;
}
.nav-link .icon { color: var(--nav-muted); transition: color 0.12s; }
.nav-link:hover { background: var(--nav-hover); color: #fff; }
.nav-link[aria-current="page"] { background: var(--nav-active); color: #fff; }
.nav-link[aria-current="page"]::before { content: ""; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: var(--nav-accent); }
.nav-link[aria-current="page"] .icon, .nav-link:hover .icon { color: var(--nav-accent); }
.nav-badge { margin-left: auto; min-width: 22px; padding: 0 7px; height: 20px; border-radius: 999px; font-size: 12px; font-weight: 700; line-height: 20px; text-align: center; background: rgba(255, 255, 255, 0.14); color: #fff; }
.nav-badge.warn { background: #f3c56d; color: #3a2800; }
.sb-foot { flex: none; padding: var(--sp-3) var(--sp-5) var(--sp-4); border-top: 1px solid var(--nav-border); font-size: 12px; color: var(--nav-muted); }

.main-col { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 40; height: var(--topbar-h); display: flex; align-items: center; gap: var(--sp-3);
  padding: 0 var(--sp-5); background: var(--surface); border-bottom: 1px solid var(--border);
}
.tb-menu { display: none; }
.tb-brand { display: none; color: var(--accent); }
.tb-brand .icon { width: 30px; height: 30px; --logo-fill: var(--accent); --logo-check: var(--surface); }
.tb-title { min-width: 0; display: flex; flex-direction: column; justify-content: center; line-height: 1.2; }
.tb-crumb { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tb-page { font-size: 15px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tb-spacer { flex: 1; }
.tb-search { position: relative; width: min(340px, 34vw); }
.tb-search .icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.tb-search input { width: 100%; height: 36px; padding: 0 44px 0 34px; border: 1px solid var(--border-strong); border-radius: var(--r-ctl); background: var(--surface-2); }
.tb-search input::placeholder { color: var(--muted); }
.tb-search kbd { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); font-size: 11px; border: 1px solid var(--border-strong); border-radius: 4px; padding: 0 5px; color: var(--muted); background: var(--surface); pointer-events: none; }

.content { flex: 1; padding: var(--sp-5); outline: none; }
.page { max-width: 1360px; margin: 0 auto; display: grid; gap: var(--sp-5); align-content: start; }
.page-narrow { max-width: 880px; }
.page-head { display: flex; align-items: flex-start; flex-wrap: wrap; gap: var(--sp-3) var(--sp-4); }
.page-head > div:first-child { min-width: 0; flex: 1 1 320px; }
.page-head h1:focus { outline: none; }
.page-lede { color: var(--muted); margin-top: var(--sp-1); max-width: 72ch; }
.page-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); }

.scrim { position: fixed; inset: 0; background: var(--scrim); z-index: 55; opacity: 0; transition: opacity 0.2s; }
.scrim.on { opacity: 1; }

/* ---------- 4. Controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2); min-height: 36px; padding: 0 var(--sp-4);
  border: 1px solid var(--border-strong); border-radius: var(--r-ctl); background: var(--surface); color: var(--text);
  font-weight: 600; text-decoration: none; white-space: nowrap; transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: translateY(0.5px); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { background: var(--danger-bg); border-color: var(--danger-bd); color: var(--danger-fg); }
.btn-danger:hover { background: var(--danger-bd); }
.btn-solid-danger { background: var(--danger-solid); border-color: var(--danger-solid); color: #fff; }
.btn-solid-danger:hover { filter: brightness(0.92); background: var(--danger-solid); }
.btn-ok { background: var(--ok-bg); border-color: var(--ok-bd); color: var(--ok-fg); }
.btn-ok:hover { background: var(--ok-bd); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--accent-text); }
.btn-ghost:hover { background: var(--accent-bg); }
.btn-sm { min-height: 30px; padding: 0 var(--sp-3); font-size: 13px; }
.btn-block { width: 100%; }
.btn.loading { position: relative; color: transparent !important; pointer-events: none; }
.btn.loading::after { content: ""; position: absolute; width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--on-accent); border-right-color: transparent; animation: spin 0.7s linear infinite; }
.btn:not(.btn-primary).loading::after { border-color: var(--text); border-right-color: transparent; }
@keyframes spin { to { transform: rotate(360deg); } }
.icon-btn { display: inline-grid; place-items: center; width: 36px; height: 36px; border: 1px solid transparent; border-radius: var(--r-ctl); background: transparent; color: var(--muted); }
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn.bordered { border-color: var(--border-strong); }
.icon-btn-sm { width: 30px; height: 30px; }

.field { display: grid; gap: var(--sp-1); min-width: 0; }
.field > label, .field > .label, .fieldset > legend { font-weight: 600; font-size: 13px; padding: 0; }
.hint { color: var(--muted); font-size: 12.5px; }
.field-error { color: var(--danger-fg); font-size: 12.5px; display: flex; gap: var(--sp-1); align-items: flex-start; }
.input, .select, .textarea {
  width: 100%; min-height: 36px; padding: 0 var(--sp-3); border: 1px solid var(--border-strong); border-radius: var(--r-ctl);
  background: var(--surface); color: var(--text); transition: border-color 0.12s, box-shadow 0.12s;
}
.textarea { padding: var(--sp-2) var(--sp-3); min-height: 96px; resize: vertical; line-height: 1.45; }
.select { appearance: none; padding-right: 32px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a97a8' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 8px center; background-size: 16px; }
.input:hover, .select:hover, .textarea:hover { border-color: var(--muted); }
.input:focus-visible, .select:focus-visible, .textarea:focus-visible { outline: 2px solid var(--focus); outline-offset: 0; border-color: var(--focus); }
.input[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--danger-solid); }
.input[readonly] { background: var(--surface-2); }
.input-wrap { position: relative; }
.input-wrap .input { padding-right: 44px; }
.input-wrap .icon-btn { position: absolute; right: 2px; top: 2px; width: 32px; height: 32px; }
.input-lg { min-height: 44px; font-size: 15px; }
.input-code { font-family: var(--mono); font-size: 22px; letter-spacing: 0.35em; text-align: center; min-height: 52px; padding-left: 0.35em; }
.fieldset { border: 0; padding: 0; margin: 0; display: grid; gap: var(--sp-2); min-width: 0; }
.form-grid { display: grid; gap: var(--sp-4); }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: var(--sp-4); }
.form-actions { display: flex; flex-wrap: wrap; gap: var(--sp-2); align-items: center; }

.check { display: flex; gap: var(--sp-2); align-items: flex-start; cursor: pointer; line-height: 1.35; }
.check input { width: 18px; height: 18px; margin: 1px 0 0; accent-color: var(--accent); flex: none; cursor: pointer; }
.check .check-text { display: grid; gap: 1px; }
.check .hint { font-weight: 400; }
.choice { display: flex; gap: var(--sp-3); align-items: flex-start; padding: var(--sp-3); border: 1px solid var(--border-strong); border-radius: var(--r-ctl); background: var(--surface); cursor: pointer; }
.choice:hover { border-color: var(--muted); }
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-bg); }
.choice:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }
.choice input { margin: 2px 0 0; accent-color: var(--accent); width: 16px; height: 16px; flex: none; }
.choice b { display: block; }

.seg { width: fit-content; max-width: 100%; display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--r-ctl); background: var(--surface); padding: 2px; gap: 2px; flex-wrap: wrap; }
.seg button { min-height: 30px; padding: 0 var(--sp-3); border: 0; border-radius: 4px; background: transparent; color: var(--muted); font-weight: 600; font-size: 13px; }
.seg button:hover { color: var(--text); background: var(--surface-3); }
.seg button[aria-pressed="true"], .seg button[aria-selected="true"] { background: var(--accent); color: var(--on-accent); }
.seg button .count { opacity: 0.8; font-weight: 500; margin-left: 4px; }

/* ---------- 5. Panels, chips, banners ---------- */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-panel); min-width: 0; }
.panel-head { display: flex; align-items: center; flex-wrap: wrap; gap: var(--sp-2) var(--sp-4); padding: var(--sp-4) var(--sp-4) 0; }
.panel-head > :first-child { min-width: 0; }
.panel-head .panel-sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.panel-actions { margin-left: auto; display: flex; gap: var(--sp-2); align-items: center; flex-wrap: wrap; }
.panel-body { padding: var(--sp-4); }
.panel-flush { padding: 0; }
.panel-foot { padding: var(--sp-3) var(--sp-4); border-top: 1px solid var(--border); }
.stack { display: grid; gap: var(--sp-4); align-content: start; }
.stack-sm { display: grid; gap: var(--sp-2); align-content: start; }
.row { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-4); }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--sp-4); }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--sp-4); }
.grid-auto { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: var(--sp-4); }
.divider { height: 1px; background: var(--border); border: 0; margin: 0; }

.chip {
  display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 9px 0 7px; border-radius: 999px; border: 1px solid var(--neutral-bd);
  background: var(--neutral-bg); color: var(--neutral-fg); font-size: 12px; font-weight: 600; white-space: nowrap; line-height: 1;
}
.chip .icon { width: 13px; height: 13px; stroke-width: 2.2; }
.chip-ok { background: var(--ok-bg); border-color: var(--ok-bd); color: var(--ok-fg); }
.chip-warn { background: var(--warn-bg); border-color: var(--warn-bd); color: var(--warn-fg); }
.chip-danger { background: var(--danger-bg); border-color: var(--danger-bd); color: var(--danger-fg); }
.chip-info { background: var(--info-bg); border-color: var(--info-bd); color: var(--info-fg); }
.chip-accent { background: var(--accent-bg); border-color: var(--accent-bd); color: var(--accent-text); }
.chip-plain { padding-left: 9px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--neutral-solid); flex: none; display: inline-block; }
.dot-ok { background: var(--ok-solid); } .dot-warn { background: var(--warn-solid); } .dot-danger { background: var(--danger-solid); } .dot-info { background: var(--info-solid); }

.pill { display: inline-flex; align-items: center; gap: var(--sp-2); height: 30px; padding: 0 var(--sp-3); border-radius: 999px; font-size: 13px; font-weight: 600; border: 1px solid var(--neutral-bd); background: var(--neutral-bg); color: var(--neutral-fg); white-space: nowrap; text-decoration: none; }
.pill.ok { background: var(--ok-bg); border-color: var(--ok-bd); color: var(--ok-fg); }
.pill.danger { background: var(--danger-bg); border-color: var(--danger-bd); color: var(--danger-fg); }
.pill.warn { background: var(--warn-bg); border-color: var(--warn-bd); color: var(--warn-fg); }


.banner { display: flex; gap: var(--sp-3); align-items: flex-start; padding: var(--sp-3) var(--sp-4); border: 1px solid var(--neutral-bd); border-radius: var(--r-panel); background: var(--neutral-bg); color: var(--text); }
.banner > .icon { margin-top: 1px; color: var(--neutral-fg); }
.banner-body { min-width: 0; flex: 1; display: grid; gap: 2px; }
.banner-title { font-weight: 650; }
.banner-actions { display: flex; gap: var(--sp-2); flex-wrap: wrap; margin-top: var(--sp-2); }
.banner-ok { background: var(--ok-bg); border-color: var(--ok-bd); } .banner-ok > .icon { color: var(--ok-fg); }
.banner-warn { background: var(--warn-bg); border-color: var(--warn-bd); } .banner-warn > .icon { color: var(--warn-fg); }
.banner-danger { background: var(--danger-bg); border-color: var(--danger-bd); } .banner-danger > .icon { color: var(--danger-fg); }
.banner-info { background: var(--info-bg); border-color: var(--info-bd); } .banner-info > .icon { color: var(--info-fg); }

.empty { display: grid; justify-items: center; text-align: center; gap: var(--sp-2); padding: var(--sp-7) var(--sp-4); color: var(--muted); }
.empty .empty-mark { width: 56px; height: 56px; display: grid; place-items: center; border-radius: 50%; background: var(--surface-3); color: var(--muted); margin-bottom: var(--sp-2); }
.empty .empty-mark .icon { width: 26px; height: 26px; }
.empty h3 { color: var(--text); font-size: 15px; }
.empty p { max-width: 46ch; }
.empty .btn { margin-top: var(--sp-2); }

.skeleton { display: block; border-radius: 4px; background: linear-gradient(90deg, var(--surface-3) 25%, var(--surface-2) 50%, var(--surface-3) 75%); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; min-height: 12px; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- 6. Tables ---------- */
.table-wrap { overflow: auto; max-width: 100%; border-radius: inherit; }
.table-wrap.tall { max-height: calc(100dvh - 330px); min-height: 160px; }
table.data { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13.5px; }
table.data caption { text-align: left; }
table.data th {
  position: sticky; top: 0; z-index: 2; background: var(--surface-2); color: var(--muted); font-weight: 600; font-size: 12.5px; text-align: left;
  padding: 9px var(--sp-3); border-bottom: 1px solid var(--border-strong); white-space: nowrap;
}
table.data th.num { text-align: right; }
table.data td { padding: 9px var(--sp-3); border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover td { background: var(--row-hover); }
table.data tbody tr.selected td { background: var(--row-selected); }
table.data tbody tr.clickable { cursor: pointer; }
table.data tbody tr.is-gone td { opacity: 0.62; }
table.data td.num, table.data th.num { text-align: right; }
table.data .col-check { width: 40px; padding-right: 0; }
table.data .col-check input { width: 17px; height: 17px; accent-color: var(--accent); cursor: pointer; vertical-align: middle; }
table.data .cell-main { font-weight: 600; }
table.data .cell-sub { color: var(--muted); font-size: 12.5px; }
.row-link { appearance: none; background: none; border: 0; padding: 0; margin: 0; color: var(--text); font-weight: 600; text-align: left; cursor: pointer; border-radius: 3px; }
.row-link:hover { color: var(--accent-text); text-decoration: underline; text-underline-offset: 2px; }
.cell-clip { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell-clip-sm { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table-note { padding: var(--sp-3) var(--sp-4); border-top: 1px solid var(--border); color: var(--muted); font-size: 12.5px; }

.pager { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); border-top: 1px solid var(--border); color: var(--muted); font-size: 13px; }
.pager .row { gap: var(--sp-2); }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--border); }
.toolbar .search { position: relative; flex: 1 1 260px; max-width: 420px; min-width: 200px; }
.toolbar .search .icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.toolbar .search .input { padding-left: 34px; }
.toolbar .select { width: auto; min-width: 140px; }
.bulkbar { display: flex; align-items: center; flex-wrap: wrap; gap: var(--sp-3); padding: var(--sp-2) var(--sp-4); background: var(--accent-bg); border-bottom: 1px solid var(--accent-bd); position: sticky; top: 0; z-index: 3; }
.bulkbar .spacer { flex: 1; }

/* ---------- 7. Tabs, menus, tooltips, toasts ---------- */
.tabs { display: flex; gap: var(--sp-1); border-bottom: 1px solid var(--border); overflow-x: auto; overflow-y: hidden; }
.tabs button { position: relative; padding: var(--sp-2) var(--sp-4); min-height: 40px; background: none; border: 0; color: var(--muted); font-weight: 600; white-space: nowrap; border-radius: var(--r-ctl) var(--r-ctl) 0 0; }
.tabs button:hover { color: var(--text); background: var(--surface-3); }
.tabs button[aria-selected="true"] { color: var(--accent-text); }
.tabs button[aria-selected="true"]::after { content: ""; position: absolute; left: var(--sp-2); right: var(--sp-2); bottom: 0; height: 2px; background: var(--accent); border-radius: 2px; }

.menu-wrap { position: relative; }
.menu { position: absolute; right: 0; top: calc(100% + 6px); min-width: 230px; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-panel); box-shadow: var(--shadow-pop); padding: var(--sp-1); z-index: 90; }
.menu-head { padding: var(--sp-2) var(--sp-3) var(--sp-3); border-bottom: 1px solid var(--border); margin-bottom: var(--sp-1); }
.menu-head b { display: block; }
.menu [role="menuitem"] { display: flex; align-items: center; gap: var(--sp-3); width: 100%; min-height: 36px; padding: 0 var(--sp-3); border: 0; border-radius: var(--r-ctl); background: none; color: var(--text); text-align: left; text-decoration: none; }
.menu [role="menuitem"]:hover, .menu [role="menuitem"]:focus-visible { background: var(--surface-3); outline-offset: -2px; }
.menu [role="menuitem"] .icon { color: var(--muted); }
.user-btn { display: inline-flex; align-items: center; gap: var(--sp-2); height: 36px; padding: 0 var(--sp-2) 0 var(--sp-1); border: 1px solid transparent; border-radius: 999px; background: none; }
.user-btn:hover { background: var(--surface-3); }
.avatar { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: var(--accent-bg); color: var(--accent-text); font-weight: 700; font-size: 12px; border: 1px solid var(--accent-bd); flex: none; }
.user-btn .uname { font-weight: 600; max-width: 140px; }

.tooltip { position: fixed; z-index: 150; pointer-events: none; background: #0b1f3a; color: #eef3f9; border: 1px solid rgba(255, 255, 255, 0.14); border-radius: var(--r-ctl); padding: var(--sp-2) var(--sp-3); font-size: 12.5px; box-shadow: var(--shadow-pop); max-width: 260px; line-height: 1.4; }
.tooltip b { display: block; margin-bottom: 2px; }
.tooltip .tt-row { display: flex; align-items: center; gap: var(--sp-2); justify-content: space-between; }
.tooltip .tt-row span:first-child { display: inline-flex; align-items: center; gap: 6px; }
.tooltip .sw { width: 9px; height: 9px; border-radius: 2px; display: inline-block; }

.toasts { position: fixed; z-index: 300; right: var(--sp-4); bottom: var(--sp-4); display: grid; gap: var(--sp-2); width: min(380px, calc(100vw - 32px)); pointer-events: none; }
.toast { pointer-events: auto; display: flex; align-items: flex-start; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); border-radius: var(--r-panel); background: #0b1f3a; color: #eef3f9; box-shadow: var(--shadow-pop); border: 1px solid rgba(255, 255, 255, 0.12); animation: toast-in 0.18s ease-out; }
.toast .icon { color: #5fd6a0; margin-top: 1px; }
.toast.error .icon { color: #ff9ca4; }
.toast .toast-msg { flex: 1; min-width: 0; }
.toast button { background: none; border: 0; color: #7be4ee; font-weight: 700; padding: 0 var(--sp-1); }
.toast button:hover { text-decoration: underline; }
.toast button:focus-visible { outline-color: #7be4ee; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- 8. Dialog and drawer (native <dialog>: modal, focus trapped, Esc closes) ---------- */
dialog { color: var(--text); padding: 0; border: 1px solid var(--border-strong); background: var(--surface); }
dialog::backdrop { background: var(--scrim); }
.dialog { width: min(520px, calc(100vw - 24px)); max-height: calc(100dvh - 32px); border-radius: var(--r-dialog); box-shadow: var(--shadow-pop); overflow: hidden; }
.dialog[open] { display: flex; flex-direction: column; animation: dlg-in 0.16s ease-out; }
.dialog-wide { width: min(680px, calc(100vw - 24px)); }
.dlg-head { display: flex; align-items: flex-start; gap: var(--sp-3); padding: var(--sp-5) var(--sp-5) var(--sp-2); }
.dlg-head h2 { font-size: 17px; flex: 1; }
.dlg-body { padding: var(--sp-2) var(--sp-5) var(--sp-4); overflow: auto; display: grid; gap: var(--sp-4); }
.dlg-foot { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: var(--sp-2); padding: var(--sp-3) var(--sp-5) var(--sp-4); border-top: 1px solid var(--border); background: var(--surface-2); }
@keyframes dlg-in { from { opacity: 0; transform: translateY(6px) scale(0.99); } }

.drawer { margin: 0 0 0 auto; width: min(640px, 100vw); max-width: 100vw; height: 100dvh; max-height: 100dvh; border: 0; border-left: 1px solid var(--border-strong); box-shadow: var(--shadow-drawer); }
.drawer-wide { width: min(860px, 100vw); }
.drawer[open] { display: flex; flex-direction: column; animation: drawer-in 0.2s ease-out; }
.drawer-head { display: flex; align-items: flex-start; gap: var(--sp-3); padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--border); background: var(--surface); flex: none; }
.drawer-head .dh-text { flex: 1; min-width: 0; }
.drawer-head h2 { font-size: 17px; line-height: 1.3; overflow-wrap: anywhere; }
.drawer-head .dh-sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.drawer-body { flex: 1; overflow: auto; padding: var(--sp-5); display: grid; gap: var(--sp-5); align-content: start; background: var(--bg); }
.drawer-foot { flex: none; display: flex; flex-wrap: wrap; gap: var(--sp-2); padding: var(--sp-3) var(--sp-5); border-top: 1px solid var(--border); background: var(--surface); }
@keyframes drawer-in { from { transform: translateX(32px); opacity: 0.4; } }

/* ---------- 9. Key/value lists, code ---------- */
.kv { display: grid; grid-template-columns: minmax(110px, 160px) minmax(0, 1fr); gap: var(--sp-2) var(--sp-4); }
.kv dt { color: var(--muted); font-size: 13px; }
.kv dd { min-width: 0; overflow-wrap: anywhere; }
.code { font-family: var(--mono); font-size: 12.5px; line-height: 1.55; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-ctl); padding: var(--sp-3); overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; }
.copy-row { display: flex; gap: var(--sp-2); align-items: stretch; }
.copy-row .code { flex: 1; min-width: 0; }

/* ---------- 10. Responsive ---------- */
@media (max-width: 1100px) {
  .tb-search { width: min(260px, 30vw); }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 960px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(300px, 86vw); transform: translateX(-102%); transition: transform 0.22s ease-out; box-shadow: none; }
  .sidebar.open { transform: none; box-shadow: 8px 0 32px rgba(0, 0, 0, 0.4); }
  .tb-menu { display: inline-grid; }
  .tb-brand { display: inline-flex; }
  .topbar { padding: 0 var(--sp-3); gap: var(--sp-2); }
  .content { padding: var(--sp-4) var(--sp-3) var(--sp-6); }
  .tb-search { display: none; }
  .tb-search.mobile-open { display: block; position: absolute; left: var(--sp-3); right: var(--sp-3); top: 10px; width: auto; z-index: 5; }
  .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
  .user-btn .uname { display: none; }
  .tb-crumb { display: none; }
}
@media (min-width: 961px) { .tb-search-btn { display: none; } }
@media (max-width: 640px) {
  body { font-size: 15px; }
  h1 { font-size: 20px; }
  .input, .select, .textarea { font-size: 16px; min-height: 44px; }
  .btn { min-height: 44px; }
  .btn-sm { min-height: 40px; }
  .icon-btn { width: 44px; height: 44px; }
  .icon-btn-sm { width: 40px; height: 40px; }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-3); }
  .kv { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .kv dt { margin-top: var(--sp-3); }
  .kv dd { margin-bottom: 0; }
  .drawer-head, .drawer-body, .drawer-foot { padding-left: var(--sp-4); padding-right: var(--sp-4); }
  .dlg-head, .dlg-body, .dlg-foot { padding-left: var(--sp-4); padding-right: var(--sp-4); }
  .toasts { right: var(--sp-3); bottom: var(--sp-3); }
  .page-actions { width: 100%; }
  .pill .pill-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .pill { padding: 0; width: 36px; height: 36px; justify-content: center; }
  .tb-title { display: none; }
  .toolbar .select { flex: 1; }
  .seg button { min-height: 38px; }
  .tabs button { min-height: 44px; }
  .menu { right: -8px; }
}

/* Stacked cards: a table opted in with .cards becomes a list of cards on narrow screens
   (subject first, outcome and time on one line, the rest labelled). */
@media (max-width: 760px) {
  table.data.cards, table.data.cards tbody, table.data.cards td { display: block; }
  table.data.cards thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  table.data.cards tbody tr { position: relative; display: flex; flex-wrap: wrap; align-items: center; gap: 4px var(--sp-3); padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--border); }
  table.data.cards tbody tr:last-child { border-bottom: 0; }
  table.data.cards td { border: 0; padding: 0; max-width: none; white-space: normal; flex: 0 1 auto; }
  table.data.cards tbody tr:hover td { background: none; }
  table.data.cards tbody tr:hover { background: var(--row-hover); }
  table.data.cards td.primary { order: -2; flex: 1 1 100%; font-size: 15px; padding-right: 32px; }
  table.data.cards td.primary .cell-clip { max-width: 100%; white-space: normal; }
  table.data.cards td[data-label="Received"], table.data.cards td[data-label="Outcome"], table.data.cards td[data-label="Status"] { order: -1; }
  table.data.cards td[data-label="From"], table.data.cards td[data-label="To"], table.data.cards td[data-label="Why held"], table.data.cards td[data-label="Why"], table.data.cards td[data-label="What happened"], table.data.cards td[data-label="Why it is waiting"], table.data.cards td[data-label="Details"] { flex: 1 1 100%; }
  table.data.cards td[data-label]:not([data-label=""])::before { content: attr(data-label); display: inline-block; min-width: 64px; margin-right: var(--sp-2); color: var(--muted); font-size: 12px; }
  table.data.cards td[data-label="Received"]::before, table.data.cards td[data-label="Outcome"]::before, table.data.cards td[data-label="Status"]::before, table.data.cards td.primary::before { display: none; }
  table.data.cards td.col-check { position: absolute; right: var(--sp-3); top: var(--sp-3); width: auto; }
  table.data.cards td.num { text-align: left; }
  table.data.cards .cell-clip, table.data.cards .cell-clip-sm { max-width: 100%; white-space: normal; overflow-wrap: anywhere; }
  .table-wrap.tall { max-height: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; scroll-behavior: auto !important; }
  .skeleton { animation: none; }
  .boot-logo { animation: none; }
}
