/* MacroLens design system — sober, dense, data-first. Mobile-first; print-friendly (TS 2.14). */
:root {
  --c-bg: #f4f6f9;
  --c-surface: #ffffff;
  --c-surface-2: #f8fafc;
  --c-border: #dde3ea;
  --c-border-strong: #c3ccd7;
  --c-text: #1b2430;
  --c-text-2: #4a5666;
  --c-muted: #5b6778; /* ≥ 4.5:1 on every surface colour (WCAG 2.1 AA 1.4.3; #6b7788 was 4.2:1 on --c-bg) */
  --c-primary: #16365c;
  --c-primary-2: #1f4e79;
  --c-primary-soft: #e6eef7;
  --c-accent: #0f8b8d;
  --c-ok: #17803d;
  --c-warn: #b25e09;
  --c-error: #b42318;
  --c-focus: #2f7bd8;
  --radius: 6px;
  --radius-lg: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow-lg: 0 8px 24px rgba(16, 24, 40, .14);
  --font: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "Cascadia Mono", "Segoe UI Mono", Consolas, monospace;
  --topbar-h: 52px;
  --sidebar-w: 216px;
  /* chart palette (colour-blind safe, used by charts.js default) */
  --chart-1: #1f4e79; --chart-2: #e07b00; --chart-3: #2a9d8f; --chart-4: #c1121f;
  --chart-5: #6a4c93; --chart-6: #8a6d3b; --chart-7: #d63a8b; --chart-8: #5c677d;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 14px/1.45 var(--font); color: var(--c-text); background: var(--c-bg); }
[x-cloak] { display: none !important; }
a { color: var(--c-primary-2); text-decoration: none; }
a:hover { text-decoration: underline; }
/* links inside running text are underlined, not told apart by colour alone (WCAG 1.4.1, axe link-in-text-block) */
p a:not(.btn), dd a:not(.btn), .prose a:not(.btn), .md a { text-decoration: underline; text-underline-offset: 2px; }
:focus-visible { outline: 2px solid var(--c-focus); outline-offset: 2px; }
h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 .5em; color: var(--c-text); }
h1 { font-size: 1.45rem; font-weight: 650; }
h2 { font-size: 1.15rem; font-weight: 650; }
h3 { font-size: 1rem; font-weight: 650; }
p { margin: 0 0 .8em; }
code, kbd, .mono { font-family: var(--font-mono); font-size: .92em; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; left: -999px; top: 4px; background: #fff; padding: 6px 10px; z-index: 100; }
.skip-link:focus { left: 8px; }

/* ---------- top bar ---------- */
.topbar { position: sticky; top: 0; z-index: 30; height: var(--topbar-h); display: flex; align-items: center; gap: 12px;
  padding: 0 12px; background: var(--c-primary); color: #fff; }
.brand { display: flex; align-items: center; gap: 8px; color: #fff; font-weight: 700; font-size: 1.05rem; letter-spacing: .2px; }
.brand:hover { text-decoration: none; }
.topsearch { flex: 1; max-width: 560px; }
.topsearch input { width: 100%; height: 34px; border-radius: var(--radius); border: 0; padding: 0 12px; font: inherit; }
.topsearch input:focus { outline: 2px solid #93c5fd; outline-offset: 1px; } /* visible on the dark top bar */
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.lang-switch { display: flex; gap: 2px; }
.lang-switch a { color: #cfe0f3; padding: 4px 7px; border-radius: 4px; font-size: .85rem; font-weight: 600; }
.lang-switch a[aria-current] { background: rgba(255,255,255,.18); color: #fff; }
.icon-btn { background: none; border: 0; color: inherit; padding: 6px; border-radius: var(--radius); cursor: pointer; display: inline-flex; }
.icon-btn:hover { background: rgba(255,255,255,.12); }
.nav-toggle { display: none; }
.user-menu { position: relative; }
.user-btn { display: flex; align-items: center; gap: 8px; background: none; border: 0; color: #fff; cursor: pointer; font: inherit; padding: 4px; }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--c-accent); display: grid; place-items: center; font-weight: 700; }
.user-name { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu { position: absolute; right: 0; top: calc(100% + 6px); min-width: 200px; background: var(--c-surface); color: var(--c-text);
  border: 1px solid var(--c-border); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 4px; z-index: 40; }
.menu a, .menu button { display: block; width: 100%; text-align: left; padding: 8px 10px; color: var(--c-text); background: none; border: 0; font: inherit; cursor: pointer; border-radius: 4px; }
.menu a:hover, .menu button:hover { background: var(--c-surface-2); text-decoration: none; }

/* ---------- shell ---------- */
.shell { display: flex; min-height: calc(100vh - var(--topbar-h)); }
.sidebar { width: var(--sidebar-w); flex: 0 0 var(--sidebar-w); background: var(--c-surface); border-right: 1px solid var(--c-border);
  position: sticky; top: var(--topbar-h); height: calc(100vh - var(--topbar-h)); overflow-y: auto; padding: 10px 8px; }
.sidebar ul { list-style: none; margin: 0; padding: 0; }
.sidebar a { display: block; padding: 7px 10px; border-radius: var(--radius); color: var(--c-text-2); font-weight: 500; }
.sidebar a:hover { background: var(--c-surface-2); text-decoration: none; color: var(--c-text); }
.sidebar a[aria-current] { background: var(--c-primary-soft); color: var(--c-primary); font-weight: 650; }
.nav-sep { height: 1px; background: var(--c-border); margin: 8px 6px; }
.scrim { display: none; }
.main { flex: 1; min-width: 0; padding: 18px 22px 40px; }
.main.full-bleed { padding: 0; }

/* ---------- banners, toasts, flash ---------- */
.banner { display: flex; flex-wrap: wrap; gap: 10px; align-items: baseline; padding: 8px 16px; font-size: .92rem; border-bottom: 1px solid; }
.banner-maintenance { background: #fff7e6; border-color: #f3d19c; color: #6b4000; }
.banner-notice { background: #e8f1fb; border-color: #b8d0ec; color: #173d66; }
.banner-incident { background: #fdecec; border-color: #f2b8b5; color: #7a1a13; }
.toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 60; }
.toast { background: var(--c-text); color: #fff; padding: 10px 14px; border-radius: var(--radius); box-shadow: var(--shadow-lg); max-width: 380px; }
.toast.error { background: var(--c-error); }
.toast.ok { background: var(--c-ok); }
.alert { padding: 10px 12px; border-radius: var(--radius); border: 1px solid; margin-bottom: 12px; }
.alert-error { background: #fdecec; border-color: #f2b8b5; color: #7a1a13; }
.alert-ok { background: #e9f7ef; border-color: #b7e1c6; color: #0f5a2a; }
.alert-info { background: #e8f1fb; border-color: #b8d0ec; color: #173d66; }
.alert-warn { background: #fff7e6; border-color: #f3d19c; color: #6b4000; }

/* ---------- page furniture ---------- */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; margin-bottom: 14px; }
.page-head h1 { margin: 0; }
.page-head .actions { margin-left: auto; display: flex; flex-wrap: wrap; gap: 8px; }
.crumbs { font-size: .85rem; color: var(--c-muted); margin-bottom: 6px; }
.crumbs a { color: var(--c-muted); }
.card { background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--radius-lg); box-shadow: var(--shadow); }
.card-body { padding: 14px 16px; }
.card-head { padding: 10px 16px; border-bottom: 1px solid var(--c-border); display: flex; align-items: center; gap: 8px; }
.card-head h2, .card-head h3 { margin: 0; }
.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stack > * + * { margin-top: 12px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.muted { color: var(--c-muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.empty { padding: 28px; text-align: center; color: var(--c-muted); }

/* ---------- buttons & forms ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 34px; padding: 0 14px; border-radius: var(--radius);
  border: 1px solid var(--c-border-strong); background: var(--c-surface); color: var(--c-text); font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--c-surface-2); text-decoration: none; }
.btn-primary { background: var(--c-primary-2); border-color: var(--c-primary-2); color: #fff; }
.btn-primary:hover { background: var(--c-primary); }
.btn-danger { color: var(--c-error); border-color: #f0b4ae; }
.btn-sm { height: 28px; padding: 0 10px; font-size: .88rem; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
label { font-weight: 550; font-size: .9rem; }
.field { display: grid; gap: 4px; margin-bottom: 12px; }
.field .hint { font-size: .82rem; color: var(--c-muted); font-weight: 400; }
input[type=text], input[type=search], input[type=email], input[type=password], input[type=number], input[type=date], input[type=color],
select, textarea { font: inherit; color: var(--c-text); background: #fff; border: 1px solid var(--c-border-strong); border-radius: var(--radius);
  height: 34px; padding: 0 10px; min-width: 0; }
input[type=color] { padding: 2px; width: 44px; }
textarea { height: auto; padding: 8px 10px; min-height: 90px; }
input:focus, select:focus, textarea:focus { border-color: var(--c-focus); outline: 2px solid rgba(47,123,216,.2); outline-offset: 0; }
.checkbox { display: inline-flex; gap: 6px; align-items: center; font-weight: 450; }
fieldset { border: 1px solid var(--c-border); border-radius: var(--radius); padding: 10px 12px; margin: 0 0 12px; }
legend { font-weight: 650; padding: 0 4px; }

/* ---------- chips, badges, tabs ---------- */
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px; background: var(--c-surface-2);
  border: 1px solid var(--c-border); font-size: .82rem; color: var(--c-text-2); }
.chip[aria-pressed=true], .chip.active { background: var(--c-primary-soft); border-color: #a9c3e2; color: var(--c-primary); font-weight: 600; }
.badge { display: inline-block; padding: 1px 7px; border-radius: 4px; font-size: .76rem; font-weight: 650; background: var(--c-surface-2); color: var(--c-text-2); border: 1px solid var(--c-border); }
.badge-freq { background: #eef4ff; color: #274b8f; border-color: #cbd9f5; }
.badge-src { background: #eefaf7; color: #0e625f; border-color: #bfe6df; }
.badge-ok { background: #e9f7ef; color: #0f5a2a; border-color: #b7e1c6; }
.badge-warn { background: #fff7e6; color: #6b4000; border-color: #f3d19c; }
.badge-error { background: #fdecec; color: #7a1a13; border-color: #f2b8b5; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--c-border); margin-bottom: 12px; overflow-x: auto; }
.tabs button, .tabs a { background: none; border: 0; border-bottom: 2px solid transparent; padding: 8px 12px; font: inherit; font-weight: 550; color: var(--c-text-2); cursor: pointer; white-space: nowrap; }
.tabs [aria-selected=true], .tabs [aria-current] { color: var(--c-primary); border-bottom-color: var(--c-primary-2); }

/* ---------- data tables ---------- */
.table-wrap { overflow-x: auto; }
table.data { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
table.data th, table.data td { padding: 6px 10px; border-bottom: 1px solid var(--c-border); text-align: left; vertical-align: top; }
table.data th { background: var(--c-surface-2); font-weight: 650; font-size: .85rem; color: var(--c-text-2); position: sticky; top: 0; }
table.data td.num, table.data th.num { text-align: right; white-space: nowrap; }
table.data tr:hover td { background: #fafcff; }

/* ---------- search results ---------- */
.result { padding: 10px 12px; border-bottom: 1px solid var(--c-border); display: grid; gap: 3px; }
.result:hover { background: #fafcff; }
.result-title { font-weight: 600; }
.result-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: .82rem; color: var(--c-muted); }
.facets { display: grid; gap: 12px; align-content: start; }
.facet h3 { font-size: .85rem; text-transform: uppercase; letter-spacing: .04em; color: var(--c-muted); margin-bottom: 6px; }
.facet label { display: flex; gap: 6px; align-items: center; font-weight: 450; padding: 2px 0; }
.facet .count { margin-left: auto; color: var(--c-muted); font-size: .8rem; }

/* ---------- workspace layout ---------- */
.workspace { display: grid; grid-template-columns: minmax(280px, 360px) minmax(0, 1fr); gap: 14px; align-items: start; }
.panel { background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--radius-lg); }
.panel-head { padding: 8px 12px; border-bottom: 1px solid var(--c-border); display: flex; align-items: center; gap: 8px; font-weight: 650; }
.panel-body { padding: 10px 12px; }
.series-item { border: 1px solid var(--c-border); border-radius: var(--radius); padding: 8px; margin-bottom: 8px; background: var(--c-surface-2); }
.series-item .swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; flex: 0 0 12px; }
.op-chain { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.chart-box { width: 100%; min-height: 360px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 6px 0; }

/* ---------- modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 50; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--c-surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); width: min(640px, 100%); max-height: calc(100vh - 32px); overflow: auto; }
.modal-head { padding: 12px 16px; border-bottom: 1px solid var(--c-border); display: flex; align-items: center; }
.modal-head h2 { margin: 0; }
.modal-body { padding: 14px 16px; }
.modal-foot { padding: 10px 16px; border-top: 1px solid var(--c-border); display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- auth pages ---------- */
.auth-wrap { min-height: calc(100vh - var(--topbar-h)); display: grid; place-items: center; padding: 20px; width: 100%; }
.auth-card { width: min(420px, 100%); }

/* ---------- help / prose ---------- */
.prose { max-width: 820px; }
.prose h2 { margin-top: 1.4em; }
.prose pre { background: #0f172a; color: #e2e8f0; padding: 10px 12px; border-radius: var(--radius); overflow-x: auto; }
.prose table { border-collapse: collapse; }
.prose th, .prose td { border: 1px solid var(--c-border); padding: 4px 8px; }

/* ---------- htmx ---------- */
.htmx-indicator { opacity: 0; transition: opacity .2s; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }
.spinner { width: 16px; height: 16px; border: 2px solid var(--c-border-strong); border-top-color: var(--c-primary-2); border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .workspace { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .nav-toggle { display: inline-flex; }
  .sidebar { position: fixed; left: 0; top: var(--topbar-h); bottom: 0; height: auto; z-index: 35; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: none; }
  .scrim { display: block; position: fixed; inset: var(--topbar-h) 0 0 0; background: rgba(15,23,42,.35); z-index: 34; }
  .main { padding: 14px 12px 32px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .user-name { display: none; }
}
@media (max-width: 560px) {
  .topsearch { display: none; }
  .page-head .actions { margin-left: 0; width: 100%; }
}

/* site footer: its inline colour (partials/footer.html) is below 4.5:1 on the page background */
.site-footer { color: var(--c-muted) !important; }

/* ---------- print (TS 2.14) ---------- */
@media print {
  @page { margin: 14mm; }
  body { background: #fff; font-size: 11pt; }
  .topbar, .sidebar, .scrim, .banner, .toasts, .no-print, .toolbar, .page-head .actions, .skip-link { display: none !important; }
  .site-footer nav { display: none !important; } /* site links are no content of a printed series, report or deck */
  .main { padding: 0; }
  .card, .panel { box-shadow: none; border-color: #bbb; break-inside: avoid; }
  .workspace { display: block; }
  a { color: inherit; text-decoration: none; }
  table.data th { position: static; }
  .print-only { display: block !important; }
}
.print-only { display: none; }
