/* Shared components. The CSP forbids inline styles: use these classes (and element.style via JS only for
   computed geometry such as chart bars). Every interactive target is >= 44px on touch layouts. */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--page); color: var(--text); font: 400 var(--fs-m)/var(--lh) var(--font-body); min-height: 100vh; overflow-x: hidden; }
h1, h2, h3, h4 { font-family: var(--font-display); line-height: var(--lh-tight); margin: 0; letter-spacing: -0.01em; }
h1 { font-size: var(--fs-2xl); font-weight: 650; } h2 { font-size: var(--fs-xl); font-weight: 600; } h3 { font-size: var(--fs-l); font-weight: 600; } h4 { font-size: var(--fs-m); font-weight: 600; }
p { margin: 0 0 var(--sp-3); } a { color: var(--accent-text); text-underline-offset: 2px; }
small, .small { font-size: var(--fs-s); } .muted { color: var(--text-2); } .mono { font-family: var(--font-mono); font-size: var(--fs-s); }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; left: 8px; top: -60px; background: var(--card); color: var(--text); padding: 10px 14px; border-radius: var(--radius-s); z-index: 100; }
.skip-link:focus { top: 8px; }
[hidden] { display: none !important; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; scroll-behavior: auto !important; } }

/* ---- layout utilities ---- */
.stack { display: flex; flex-direction: column; gap: var(--sp-4); } .stack-s { display: flex; flex-direction: column; gap: var(--sp-2); } .stack-l { display: flex; flex-direction: column; gap: var(--sp-8); }
.row { display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; } .row-tight { display: flex; align-items: center; gap: var(--sp-2); } .row-top { align-items: flex-start; }
.between { justify-content: space-between; } .end { justify-content: flex-end; } .grow { flex: 1 1 0; min-width: 0; } .nowrap { white-space: nowrap; } .wrap-anywhere { overflow-wrap: anywhere; }
.grid { display: grid; gap: var(--sp-4); } .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)); }
.grid-auto { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); } .grid-main { grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); }
.mt-2 { margin-top: var(--sp-2);} .mt-4 { margin-top: var(--sp-4);} .mt-6 { margin-top: var(--sp-6);} .mb-0 { margin-bottom: 0; } .mb-4 { margin-bottom: var(--sp-4);} .p-0 { padding: 0 !important; }
.text-center { text-align: center; } .w-full { width: 100%; } .max-prose { max-width: 68ch; } .max-form { max-width: 560px; }
@media (max-width: 1024px) { .grid-4 { grid-template-columns: repeat(2, minmax(0,1fr)); } .grid-main { grid-template-columns: minmax(0,1fr); } }
@media (max-width: 720px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: minmax(0,1fr); } .hide-mobile { display: none !important; } }
@media (min-width: 721px) { .only-mobile { display: none !important; } }

/* ---- app shell ---- */
.shell { display: grid; grid-template-columns: var(--sidebar-w) minmax(0,1fr); min-height: 100vh; }
.sidebar { background: var(--sidebar-bg); color: var(--sidebar-text); border-right: 1px solid var(--sidebar-border); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.sidebar .brand { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-5) var(--sp-5) var(--sp-4); color: var(--sidebar-text-strong); font: 650 var(--fs-l)/1.1 var(--font-display); text-decoration: none; }
.sidebar .brand small { display: block; font: 500 var(--fs-xs)/1.3 var(--font-body); color: var(--sidebar-text); letter-spacing: .08em; text-transform: uppercase; }
.brand-mark { width: 34px; height: 34px; border-radius: 9px; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 700; flex: none; }
.nav-group { padding: var(--sp-3) var(--sp-3) 0; } .nav-group h2 { font: 600 var(--fs-xs)/1 var(--font-body); letter-spacing: .1em; text-transform: uppercase; color: var(--sidebar-text); opacity: .75; padding: var(--sp-2) var(--sp-3); }
.nav-link { display: flex; align-items: center; gap: var(--sp-3); min-height: 40px; padding: 6px var(--sp-3); border-radius: var(--radius-s); color: var(--sidebar-text); text-decoration: none; font-weight: 500; font-size: var(--fs-m); border-left: 3px solid transparent; }
.nav-link:hover { color: var(--sidebar-text-strong); background: rgba(255,255,255,.06); }
.nav-link[aria-current="page"] { color: var(--sidebar-text-strong); background: var(--sidebar-active-bg); border-left-color: var(--accent); }
.nav-link svg { width: 18px; height: 18px; flex: none; } .nav-link .count { margin-left: auto; font-size: var(--fs-xs); background: rgba(255,255,255,.12); border-radius: var(--radius-pill); padding: 1px 8px; }
.sidebar-foot { margin-top: auto; padding: var(--sp-4) var(--sp-5); font-size: var(--fs-xs); border-top: 1px solid var(--sidebar-border); }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { height: var(--topbar-h); display: flex; align-items: center; gap: var(--sp-3); padding: 0 var(--sp-6); background: var(--card); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.topbar .search { flex: 1 1 auto; max-width: 460px; position: relative; }
.content { padding: var(--sp-6); max-width: 1480px; width: 100%; margin: 0 auto; flex: 1; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--sp-4); flex-wrap: wrap; margin-bottom: var(--sp-5); }
.page-head p { margin: 4px 0 0; color: var(--text-2); max-width: 70ch; }
.footer { padding: var(--sp-4) var(--sp-6); color: var(--text-2); font-size: var(--fs-xs); border-top: 1px solid var(--border); display: flex; gap: var(--sp-4); flex-wrap: wrap; justify-content: space-between; }
.btn.menu-btn { display: none; }
@media (max-width: 960px) {
  .shell { grid-template-columns: minmax(0,1fr); }
  .sidebar { position: fixed; z-index: 60; left: 0; top: 0; width: min(86vw, 300px); transform: translateX(-102%); transition: transform var(--dur) var(--ease); }
  .sidebar[data-open="true"] { transform: none; box-shadow: var(--shadow); }
  .scrim { position: fixed; inset: 0; background: var(--overlay); z-index: 55; }
  .btn.menu-btn { display: inline-flex; } .topbar { padding: 0 var(--sp-3); } .content { padding: var(--sp-4); }
  .nav-link { min-height: var(--touch); }
}

/* ---- buttons ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2); min-height: 38px; padding: 0 var(--sp-4); border-radius: var(--radius-s); border: 1px solid var(--border-strong); background: var(--card); color: var(--text); font: 600 var(--fs-s)/1 var(--font-body); cursor: pointer; text-decoration: none; transition: background var(--dur), border-color var(--dur); white-space: nowrap; }
.btn:hover { background: var(--card-2); } .btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent-fill); border-color: var(--accent-fill); color: var(--text-on-accent); } .btn-primary:hover { background: var(--accent-fill-hover); }
.btn-danger { background: var(--error); border-color: var(--error); color: #fff; } [data-theme="dark"] .btn-danger { color: #1a0508; }
.btn-ghost { border-color: transparent; background: transparent; } .btn-s { min-height: 30px; padding: 0 var(--sp-3); font-size: var(--fs-xs); }
.btn-icon { width: 38px; padding: 0; } .btn svg { width: 16px; height: 16px; }
@media (pointer: coarse) { .btn { min-height: var(--touch); } .btn-icon { width: var(--touch); } .btn-s { min-height: 40px; } }

/* ---- forms ---- */
.field { display: flex; flex-direction: column; gap: 6px; } .field label, .label { font: 600 var(--fs-s)/1.3 var(--font-body); }
.field .hint { font-size: var(--fs-xs); color: var(--text-2); } .field .err { font-size: var(--fs-xs); color: var(--error); font-weight: 600; }
.input, select.input, textarea.input { width: 100%; min-height: 40px; padding: 8px 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-s); background: var(--card); color: var(--text); font: 400 var(--fs-m)/1.4 var(--font-body); }
textarea.input { min-height: 96px; resize: vertical; } .input[aria-invalid="true"] { border-color: var(--error); } .input::placeholder { color: var(--text-2); opacity: .8; }
@media (pointer: coarse) { .input, select.input { min-height: var(--touch); font-size: 1rem; } }
.check { display: flex; gap: var(--sp-3); align-items: flex-start; min-height: 32px; } .check input { width: 20px; height: 20px; margin-top: 2px; accent-color: var(--accent-fill); flex: none; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius-m); padding: var(--sp-4); margin: 0; } legend { font-weight: 600; padding: 0 var(--sp-2); }
.form-actions { display: flex; gap: var(--sp-3); justify-content: flex-end; flex-wrap: wrap; margin-top: var(--sp-4); }

/* ---- surfaces ---- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-m); padding: var(--sp-5); box-shadow: var(--shadow); }
.card-flat { box-shadow: none; } .card h3 { margin-bottom: var(--sp-3); } .card-head { display: flex; justify-content: space-between; align-items: center; gap: var(--sp-3); margin-bottom: var(--sp-4); flex-wrap: wrap; }
.stat { display: flex; flex-direction: column; gap: 4px; text-decoration: none; color: inherit; } .stat .k { font-size: var(--fs-s); color: var(--text-2); font-weight: 500; } .stat .v { font: 650 var(--fs-2xl)/1.1 var(--font-display); font-variant-numeric: tabular-nums; } .stat .d { font-size: var(--fs-xs); color: var(--text-2); }
a.stat:hover .v { color: var(--accent-text); }
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: var(--radius-pill); font: 600 var(--fs-xs)/1.6 var(--font-body); background: var(--card-2); color: var(--text-2); border: 1px solid var(--border); white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-positive { background: var(--positive-soft); color: var(--positive); border-color: transparent; } .badge-warning { background: var(--warning-soft); color: var(--warning); border-color: transparent; }
.badge-error { background: var(--error-soft); color: var(--error); border-color: transparent; } .badge-info { background: var(--info-soft); color: var(--info); border-color: transparent; } .badge-accent { background: var(--accent-soft); color: var(--accent-text); border-color: transparent; }
.badge-plain::before { display: none; }
.banner { display: flex; gap: var(--sp-3); align-items: flex-start; padding: var(--sp-3) var(--sp-4); border-radius: var(--radius-m); border: 1px solid var(--border); background: var(--card-2); font-size: var(--fs-s); }
.banner-warning { background: var(--warning-soft); border-color: transparent; color: var(--text); } .banner-error { background: var(--error-soft); border-color: transparent; } .banner-info { background: var(--info-soft); border-color: transparent; } .banner-demo { background: var(--accent-soft); border-color: transparent; }
.kv { display: grid; grid-template-columns: minmax(120px, 34%) minmax(0,1fr); gap: 6px var(--sp-4); font-size: var(--fs-s); margin: 0; } .kv dt { color: var(--text-2); } .kv dd { margin: 0; overflow-wrap: anywhere; }
.divider { border: 0; border-top: 1px solid var(--border); margin: var(--sp-4) 0; }
.list { list-style: none; margin: 0; padding: 0; } .list > li { padding: var(--sp-3) 0; border-bottom: 1px solid var(--border); } .list > li:last-child { border-bottom: 0; }

/* ---- tables ---- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-m); background: var(--card); }
table.table { width: 100%; border-collapse: collapse; font-size: var(--fs-s); }
.table th { text-align: left; font: 600 var(--fs-xs)/1.3 var(--font-body); letter-spacing: .04em; text-transform: uppercase; color: var(--text-2); padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--card-2); white-space: nowrap; position: sticky; top: 0; }
.table th button { all: unset; cursor: pointer; display: inline-flex; gap: 4px; align-items: center; } .table th button:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.table td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; } .table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--card-2); } .table tr[data-href] { cursor: pointer; } .table .num { text-align: right; }
.table-tools { display: flex; gap: var(--sp-3); flex-wrap: wrap; align-items: center; margin-bottom: var(--sp-3); } .table-tools .input { width: auto; min-width: 160px; }
.pager { display: flex; justify-content: space-between; align-items: center; gap: var(--sp-3); padding: var(--sp-3) 0; font-size: var(--fs-s); color: var(--text-2); flex-wrap: wrap; }
@media (max-width: 720px) { /* tables become cards */
  .table-cards thead { display: none; } .table-cards, .table-cards tbody, .table-cards tr, .table-cards td { display: block; width: 100%; }
  .table-cards tr { border-bottom: 1px solid var(--border); padding: var(--sp-3) 0; } .table-cards td { border: 0; padding: 4px 14px; display: flex; justify-content: space-between; gap: var(--sp-3); text-align: right; }
  .table-cards td::before { content: attr(data-label); color: var(--text-2); font-weight: 600; font-size: var(--fs-xs); text-align: left; text-transform: uppercase; letter-spacing: .04em; }
}

/* ---- tabs, drawer, dialog, toast ---- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); overflow-x: auto; margin-bottom: var(--sp-5); }
.tab { border: 0; background: none; padding: 10px var(--sp-4); min-height: var(--touch); font: 600 var(--fs-s)/1 var(--font-body); color: var(--text-2); cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
dialog.drawer { margin: 0 0 0 auto; height: 100vh; max-height: 100vh; width: min(var(--drawer-w), 100vw); max-width: 100vw; border: 0; border-left: 1px solid var(--border); background: var(--card); color: var(--text); padding: 0; box-shadow: var(--shadow); }
dialog.modal { border: 1px solid var(--border); border-radius: var(--radius-l); background: var(--card); color: var(--text); padding: 0; width: min(560px, calc(100vw - 24px)); box-shadow: var(--shadow); }
dialog::backdrop { background: var(--overlay); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; gap: var(--sp-3); padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--card); z-index: 1; }
.dialog-body { padding: var(--sp-5); overflow-y: auto; } .dialog-foot { padding: var(--sp-4) var(--sp-5); border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: var(--sp-3); flex-wrap: wrap; }
.toasts { position: fixed; right: var(--sp-4); bottom: var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-2); z-index: 200; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--text); color: var(--page); padding: var(--sp-3) var(--sp-4); border-radius: var(--radius-m); font-size: var(--fs-s); box-shadow: var(--shadow); } .toast-error { background: var(--error); color: #fff; }
[data-theme="dark"] .toast-error { color: #1a0508; }

/* ---- states ---- */
.state { text-align: center; padding: var(--sp-10) var(--sp-5); color: var(--text-2); } .state h3 { color: var(--text); margin-bottom: var(--sp-2); } .state svg { width: 36px; height: 36px; margin-bottom: var(--sp-3); opacity: .7; } .state .btn { margin-top: var(--sp-3); }
.skeleton { background: linear-gradient(90deg, var(--card-2), var(--border), var(--card-2)); background-size: 200% 100%; animation: sk 1.2s linear infinite; border-radius: var(--radius-s); min-height: 16px; } .skeleton-row { height: 44px; margin-bottom: 8px; } .skeleton-card { height: 120px; }
@keyframes sk { to { background-position: -200% 0; } }
.offline-bar { background: var(--warning-soft); color: var(--text); text-align: center; padding: 6px; font-size: var(--fs-s); font-weight: 600; }
.demo-bar { background: var(--accent-soft); color: var(--accent-text); text-align: center; padding: 6px var(--sp-4); font-size: var(--fs-xs); font-weight: 600; letter-spacing: .02em; }

/* ---- small charts (bars sized from JS via style.width / style.height) ---- */
.bar-track { background: var(--card-2); border-radius: var(--radius-pill); height: 8px; overflow: hidden; } .bar-fill { background: var(--accent-fill); height: 100%; border-radius: inherit; }
.bar-fill.positive { background: var(--positive); } .bar-fill.warning { background: var(--warning); } .bar-fill.info { background: var(--info); }
.timeline { position: relative; padding-left: var(--sp-5); border-left: 2px solid var(--border); } .timeline > li { position: relative; padding: 0 0 var(--sp-4) var(--sp-3); list-style: none; }
.timeline > li::before { content: ""; position: absolute; left: calc(-1 * var(--sp-5) - 6px); top: 5px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); border: 2px solid var(--card); }
.steps { display: flex; gap: var(--sp-2); flex-wrap: wrap; list-style: none; padding: 0; margin: 0 0 var(--sp-5); counter-reset: step; }
.steps li { counter-increment: step; display: flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-s); color: var(--text-2); padding: 6px 12px; border-radius: var(--radius-pill); border: 1px solid var(--border); }
.steps li::before { content: counter(step); font-weight: 700; } .steps li[aria-current="step"] { color: var(--accent-text); border-color: var(--accent); background: var(--accent-soft); font-weight: 600; } .steps li[data-done="true"] { color: var(--positive); }

/* ---- search popover, auth, public ---- */
.search-results { position: absolute; top: calc(100% + 6px); left: 0; right: 0; padding: var(--sp-2); max-height: 60vh; overflow-y: auto; z-index: 40; }
.search-hit { display: flex; gap: var(--sp-3); align-items: center; padding: 8px 10px; border-radius: var(--radius-s); color: var(--text); text-decoration: none; min-height: 40px; } .search-hit:hover, .search-hit:focus { background: var(--card-2); } .search-none { padding: var(--sp-3); }
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: var(--sp-5); } .auth-card { width: min(440px, 100%); }
.auth-card .brand-row { display: flex; gap: var(--sp-3); align-items: center; margin-bottom: var(--sp-5); }
.code-box { font: 600 var(--fs-l)/1.6 var(--font-mono); letter-spacing: .08em; background: var(--card-2); border: 1px dashed var(--border-strong); border-radius: var(--radius-s); padding: var(--sp-3); overflow-wrap: anywhere; }
.banner > svg { width: 18px; height: 18px; flex: none; margin-top: 2px; }

/* focus ring stays >= 3:1 on the dark sidebar */
.sidebar :focus-visible { outline-color: var(--focus-on-dark, var(--focus)); }
/* Sep 29: HQ / Desk guard page when the session is inside a client console */
.guard-page { max-width: 640px; margin: 0 auto; } .guard-actions { justify-content: center; }

/* Oct 22, 2026 — HQ sweep fixes. On a phone, action rows wrap and long badges break onto a second line instead of running off the screen
   (found on Pipeline, Board, Rules and the 3D map's filters); selects never grow wider than the screen; a whole-page state keeps its h1 small. */
@media (max-width: 640px) {
  .row-tight { flex-wrap: wrap; }
  .badge { white-space: normal; max-width: 100%; }
  select.input, .input { max-width: 100%; }
}
.state .state-title { font-size: var(--fs-lg, 1.15rem); margin: 0; }
