/* SPK-OS design system. Flat, neutral, one accent. Colour means something (status) or marks the primary action. */
:root {
  /* neutrals */
  --bg: #f5f6f8; --surface: #ffffff; --surface-2: #f8f9fb; --border: #e3e6eb; --border-strong: #cbd1d9;
  --text: #1c2430; --text-2: #4e5a6b; --text-3: #5f6b7c;
  /* the one accent: primary actions, links, focus, the selected menu item */
  --accent: #0f6b5a; --accent-hover: #0b5748; --accent-bg: #e5f1ee;
  /* status */
  --ok: #17794a; --ok-bg: #e5f3ea; --warn: #9a5b00; --warn-bg: #fdf0d5; --bad: #c0362c; --bad-bg: #fbe9e7; --neutral-bg: #eceff3;
  /* compatibility names used across the modules */
  --brand: var(--accent); --brand-2: var(--accent); --gold: var(--accent); --info-bg: var(--neutral-bg);
  --radius: 6px; --shadow: none; --shadow-pop: 0 8px 24px rgba(16, 24, 40, .16);
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: var(--font);
  /* type scale */
  --t-title: 20px; --t-section: 15px; --t-body: 14px; --t-table: 13.5px; --t-meta: 12.5px;
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 400 var(--t-body)/1.45 var(--font); -webkit-font-smoothing: antialiased; }
h1, h2, h3 { margin: 0; font-weight: 600; font-family: var(--font); }
h1 { font-size: var(--t-title); line-height: 1.25; } h2 { font-size: var(--t-section); } h3 { font-size: var(--t-body); }
a { color: var(--accent); text-decoration: none; } a:hover { text-decoration: underline; }
[hidden] { display: none !important; }
.sub { color: var(--text-2); font-size: var(--t-meta); }
.boot { padding: 40px; color: var(--text-2); text-align: center; }
#demo-banner { background: var(--warn-bg); color: var(--warn); text-align: center; padding: 5px 12px; font-weight: 500; font-size: 12px; position: sticky; top: 0; z-index: 50; border-bottom: 1px solid #f0dcae; }
.mono, td.num { font-variant-numeric: tabular-nums; }
.mono { font-size: inherit; } td.mono { white-space: nowrap; }

/* ---- layout ---- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--border); padding: 14px 10px; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { padding: 4px 10px 14px; }
.brand b { font-size: 16px; font-weight: 700; letter-spacing: .01em; color: var(--text); }
.brand small { display: block; color: var(--text-3); font-size: 12px; margin-top: 2px; }
.nav { display: flex; flex-direction: column; gap: 14px; }
.nav-group { display: flex; flex-direction: column; gap: 1px; }
.nav-label { padding: 0 10px 4px; font-size: 12px; font-weight: 600; color: var(--text-3); }
.nav a { display: flex; align-items: center; gap: 10px; padding: 0 10px; height: 34px; border-radius: var(--radius); color: var(--text-2); font-weight: 500; }
.nav a .ico, .nav-sheet a .ico, .nav-more .ico { flex: none; color: var(--text-3); }
.nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.nav a.active { background: var(--accent-bg); color: var(--accent); }
.nav a.active .ico { color: var(--accent); }
.me { margin-top: auto; padding: 10px 6px 0; border-top: 1px solid var(--border); display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; align-items: center; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--neutral-bg); color: var(--text-2); display: inline-flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 600; }
.me-text { min-width: 0; display: flex; flex-direction: column; line-height: 1.25; } .me-text b { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } .me-text span { color: var(--text-3); font-size: 12px; }
.me .btn { grid-column: 1 / -1; justify-self: start; }
.main { padding: 20px 24px 32px; min-width: 0; max-width: 1320px; width: 100%; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px 16px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head > div:first-child { min-width: 0; }
.page-head .sub { margin-top: 2px; font-size: 13px; }

body:has(#demo-banner:not([hidden])) .side { top: 28px; height: calc(100vh - 28px); }   /* the demo banner sits above the sidebar */

/* ---- controls ---- */
.btn { font: inherit; font-weight: 500; font-size: 13.5px; height: 34px; padding: 0 14px; border-radius: var(--radius); border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; }
a.btn { line-height: 1; } a.btn:hover { text-decoration: none; }
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; } .btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { color: var(--bad); border-color: #e7b9b4; } .btn-danger:hover { background: var(--bad-bg); }
.btn-quiet { border-color: transparent; background: transparent; color: var(--text-2); } .btn-quiet:hover { background: var(--neutral-bg); }
.btn-sm { height: 28px; padding: 0 10px; font-size: 12.5px; }
.icon-btn { border: 0; background: transparent; font-size: 22px; line-height: 1; cursor: pointer; color: var(--text-2); width: 32px; height: 32px; border-radius: var(--radius); } .icon-btn:hover { background: var(--neutral-bg); }
input, select, textarea { font: inherit; width: 100%; height: 34px; padding: 0 10px; border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--surface); color: var(--text); }
textarea { height: auto; min-height: 76px; padding: 8px 10px; resize: vertical; }
select { padding-right: 6px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-bg); }
.btn:focus-visible, a:focus-visible, .icon-btn:focus-visible, .tabs button:focus-visible, [data-drill]:focus-visible, tr[data-open]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input[type=checkbox], input[type=radio] { width: 16px; height: 16px; accent-color: var(--accent); }
label { display: block; font-weight: 500; font-size: 13px; color: var(--text-2); margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.field .hint { font-size: var(--t-meta); color: var(--text-3); font-weight: 400; margin-top: 3px; }
.grid { display: grid; gap: 0 16px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.span-2 { grid-column: span 2; } @media (max-width: 560px) { .span-2 { grid-column: auto; } }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; } .row.end { justify-content: flex-end; } .row.between { justify-content: space-between; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 400; font-size: var(--t-body); color: var(--text); }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px 4px; margin: 0 0 14px; }
legend { font-weight: 600; color: var(--text-2); padding: 0 6px; font-size: 13px; }

/* ---- surfaces ---- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.card > h2:first-child, .card .row.between > h2 { margin-bottom: 8px; }
.cards { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.kpi .n { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.2; } .kpi .l { color: var(--text-2); font-size: var(--t-meta); margin-top: 2px; }
.kpi.bad .n { color: var(--bad); }
[data-drill] { cursor: pointer; } [data-drill]:hover { border-color: var(--border-strong); background: var(--surface-2); }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-size: var(--t-table); font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12.5px; font-weight: 600; color: var(--text-2); background: var(--surface-2); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tbody tr[data-open], tbody tr[data-matter], tbody tr[data-bill], tbody tr[data-inv], tbody tr[data-doc] { cursor: pointer; }
tbody tr[data-open]:hover, tbody tr[data-matter]:hover, tbody tr[data-bill]:hover, tbody tr[data-inv]:hover, tbody tr[data-doc]:hover { background: var(--surface-2); }
.chip { display: inline-block; padding: 1px 8px; border-radius: 4px; font-size: 12px; font-weight: 500; line-height: 20px; background: var(--neutral-bg); color: var(--text-2); margin: 0 4px 2px 0; white-space: nowrap; }
.chip.ok { background: var(--ok-bg); color: var(--ok); } .chip.warn { background: var(--warn-bg); color: var(--warn); } .chip.bad { background: var(--bad-bg); color: var(--bad); } .chip.info { background: var(--neutral-bg); color: var(--text-2); }
.ftype { display: inline-block; min-width: 34px; text-align: center; padding: 0 4px; border: 1px solid var(--border-strong); border-radius: 3px; color: var(--text-2); font-size: 10.5px; font-weight: 600; line-height: 16px; margin-right: 6px; }
.late { color: var(--bad); font-weight: 500; }
.plain { color: var(--text-2); white-space: nowrap; }
table b, table strong, .kv b { font-weight: 500; }
table:not(.stack) .num { text-align: right; font-variant-numeric: tabular-nums; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; align-items: center; }
.filters input[type=search] { max-width: 300px; } .filters select { width: auto; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 14px; flex-wrap: wrap; }
.tabs button { font: inherit; font-weight: 500; background: none; border: 0; padding: 8px 12px; color: var(--text-2); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button:hover { color: var(--text); } .tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }
.kv { display: grid; grid-template-columns: 160px 1fr; gap: 6px 12px; } .kv dt { color: var(--text-2); font-size: 13px; } .kv dd { margin: 0; }
.err-list { background: var(--bad-bg); color: var(--bad); padding: 8px 12px; border-radius: var(--radius); margin-bottom: 10px; }
.note { background: var(--neutral-bg); color: var(--text-2); padding: 8px 12px; border-radius: var(--radius); margin-bottom: 12px; font-size: 13px; }
.timeline { list-style: none; margin: 8px 0 0; padding: 0; }
.timeline li { padding: 6px 0; border-bottom: 1px solid var(--border); } .timeline li:last-child { border-bottom: 0; }

/* ---- loading, empty, failed ---- */
.state, .empty { padding: 32px 16px; text-align: center; color: var(--text-2); }
.state-title { font-weight: 600; color: var(--text); } .state-hint { margin-top: 4px; font-size: 13px; color: var(--text-2); } .state .btn { margin-top: 12px; }
.state-err .state-title { color: var(--bad); }
.spinner { display: inline-block; width: 14px; height: 14px; margin-right: 8px; vertical-align: -2px; border: 2px solid var(--border-strong); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } } @media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }

/* ---- dialogs and messages ---- */
.modal-wrap { position: fixed; inset: 0; background: rgba(16, 24, 40, .45); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 12px; overflow-y: auto; z-index: 100; }
.modal { background: var(--surface); border-radius: 8px; width: 100%; max-width: 640px; box-shadow: var(--shadow-pop); }
.modal-wide { max-width: 920px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px 10px 18px; border-bottom: 1px solid var(--border); }
.modal-head h3 { font-size: var(--t-section); }
.modal-body { padding: 18px; }
#toasts { position: fixed; bottom: 16px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { padding: 10px 14px; border-radius: var(--radius); color: #fff; box-shadow: var(--shadow-pop); max-width: 340px; font-size: 13.5px; }
.toast-ok { background: #1c2430; } .toast-err { background: var(--bad); } .toast-info { background: #1c2430; }

/* ---- sign in ---- */
.login { max-width: 400px; margin: 10vh auto 0; padding: 0 16px; }
.login .card { padding: 28px 26px 22px; }
.login .login-mark { margin-bottom: 18px; } .login .wordmark { font-weight: 700; font-size: 13px; color: var(--accent); letter-spacing: .02em; margin-bottom: 8px; }
.login .login-mark h1 { font-size: 19px; } .login .login-mark .sub { margin-top: 2px; font-size: 13px; }
.demo-list { margin-top: 14px; font-size: 12.5px; color: var(--text-2); } .demo-list button { margin: 2px 4px 2px 0; }

/* ---- reports ---- */
.grid2 { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.delta-good { color: var(--ok); font-weight: 500; } .delta-bad { color: var(--bad); font-weight: 500; }
.bar-row { display: grid; grid-template-columns: 150px 1fr auto; gap: 8px; align-items: center; margin: 4px 0; font-size: 13px; }
.bar { background: var(--neutral-bg); border-radius: 3px; height: 8px; } .bar i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }

/* ---- phones ---- */
.nav-more, .nav-sheet { display: none; }
@media (max-width: 800px) {
  .shell { grid-template-columns: 1fr; }
  body:has(#demo-banner:not([hidden])) .side { top: auto; height: auto; }
  .side { position: fixed; bottom: 0; left: 0; right: 0; top: auto; height: auto; flex-direction: row; padding: 2px 4px calc(2px + env(safe-area-inset-bottom)); z-index: 40; border-right: 0; border-top: 1px solid var(--border); overflow: visible; }
  .brand, .me, .nav-label { display: none; }
  .nav { flex-direction: row; gap: 0; width: 100%; } .nav-group { display: contents; }
  .nav a, .nav-more { flex: 1 1 0; min-width: 0; flex-direction: column; justify-content: center; gap: 2px; height: 52px; padding: 4px 2px; font-size: 11.5px; text-align: center; border-radius: var(--radius); }
  .nav-more { display: flex; align-items: center; font: inherit; font-size: 11.5px; font-weight: 500; color: var(--text-2); background: none; border: 0; cursor: pointer; }
  .nav a.active, .nav-more.active, .nav-more[aria-expanded="true"] { background: var(--accent-bg); color: var(--accent); } .nav-more.active .ico, .nav-more[aria-expanded="true"] .ico { color: var(--accent); }
  .n-extra { display: none !important; }
  .nav-sheet { position: fixed; left: 8px; right: 8px; bottom: calc(58px + env(safe-area-inset-bottom)); z-index: 45; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 6px; display: grid; grid-template-columns: repeat(2, 1fr); gap: 2px; box-shadow: var(--shadow-pop); }
  .nav-sheet[hidden] { display: none; }
  .nav-sheet a { display: flex; align-items: center; gap: 10px; color: var(--text); padding: 12px 10px; border-radius: var(--radius); font-weight: 500; }
  .nav-sheet a:hover, .nav-sheet a.active { background: var(--accent-bg); color: var(--accent); text-decoration: none; }
  .main { padding: 14px 12px calc(84px + env(safe-area-inset-bottom)); }
  #toasts { left: 12px; right: 12px; bottom: calc(70px + env(safe-area-inset-bottom)); } .toast { max-width: none; }
}
@media (max-width: 640px) {
  input, select, textarea { font-size: 16px; }            /* stops phones zooming in when a field is tapped */
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .kpi { padding: 10px 12px; } .kpi .n { font-size: 19px; overflow-wrap: anywhere; } .kpi .l { font-size: 12px; }
  .page-head > .row, .page-head > .btn, .page-head > div.no-print { width: 100%; } .page-head .btn { flex: 1 1 auto; }
  .filters input[type=search], .filters select { max-width: none; width: 100%; }
  .tabs button { padding: 8px 10px; }
  .bar-row { grid-template-columns: 96px 1fr auto; }
  .row.between { align-items: flex-start; }
  .modal-wrap { padding: 0; } .modal { border-radius: 0; min-height: 100vh; }
  .modal-head { position: sticky; top: 0; background: var(--surface); z-index: 2; }
  .kv { grid-template-columns: 1fr; gap: 2px 0; } .kv dd { margin-bottom: 6px; }
  .grid2 { grid-template-columns: minmax(0, 1fr); }
  /* list tables become cards */
  .table-wrap { border: 0; background: transparent; overflow: visible; }
  table.stack, table.stack tbody, table.stack tr, table.stack td { display: block; width: 100%; }
  table.stack thead, table.stack .stack-head { display: none; }
  table.stack tr { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 8px; padding: 4px 12px; }
  table.stack td { position: relative; border: 0; padding: 5px 0 5px 38%; min-height: 24px; text-align: left; overflow-wrap: anywhere; }
  table.stack td::before { content: attr(data-label); position: absolute; left: 0; top: 6px; width: 34%; color: var(--text-3); font-size: 12px; font-weight: 500; }
  table.stack td[data-label=""]::before { content: none; } table.stack td[data-label=""] { padding-left: 0; }
  table.stack td[data-empty] { display: none; }
  table.stack td .btn { margin: 2px 4px 2px 0; }
}
@media (max-width: 380px) { .cards { gap: 6px; } .kpi .n { font-size: 17px; } }
@media print { .no-print, .side, #demo-banner, .nav-sheet { display: none !important; } .card, .kpi { break-inside: avoid; } body { background: #fff; } .shell { display: block; } }

/* ---- Phase 2: work queue, matter header, key facts, inline editing */
tbody tr.clickable { cursor: pointer; } tbody tr.clickable:hover { background: var(--surface-2); } tr.clickable:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.count { color: var(--text-2); font-weight: 400; font-size: 12px; margin-left: 2px; font-variant-numeric: tabular-nums; }
.queue { margin-bottom: 20px; } .queue h2 { margin: 0 0 8px; }
.mhead { margin-bottom: 14px; } .mhead h1 { margin: 4px 0 2px; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px 20px; padding: 12px 0; margin-bottom: 12px; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.facts dt { color: var(--text-2); font-size: 12px; } .facts dd { margin: 2px 0 0; font-weight: 500; }
.facts select, .inline-edit { font: inherit; font-size: 13.5px; padding: 3px 6px; border: 1px solid transparent; background: transparent; border-radius: var(--radius); max-width: 100%; margin-left: -7px; cursor: pointer; }
.facts select:hover, .inline-edit:hover { border-color: var(--border-strong); background: var(--surface); } .facts select:focus-visible, .inline-edit:focus-visible { outline: 2px solid var(--accent); }
.banner { border: 1px solid var(--border-strong); background: var(--warn-bg); padding: 8px 12px; border-radius: var(--radius); margin-bottom: 10px; display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.banner.bad { background: var(--bad-bg); }
td .inline-edit { max-width: 150px; }
@media (max-width: 640px) { .facts { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 641px) { .queue table { table-layout: fixed; } .queue th:nth-child(1) { width: 110px; } .queue th:nth-child(2) { width: 150px; } .queue th:nth-child(4) { width: 90px; } .queue th:nth-child(5) { width: 130px; } }
.th-sort { font: inherit; font-weight: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; text-align: inherit; } .th-sort:hover { color: var(--accent); } .th-sort:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.pager { display: flex; align-items: center; justify-content: flex-end; gap: 8px; margin-top: 10px; }
.views { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.results { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.results li + li { border-top: 1px solid var(--border); }
.results a { display: flex; flex-direction: column; gap: 1px; padding: 9px 14px; color: var(--text); text-decoration: none; } .results a:hover, .results a:focus-visible { background: var(--surface-2); outline: none; }
.content { min-width: 0; }
.topbar { padding: 14px 24px 0; max-width: 1320px; } .topbar input { width: 100%; max-width: 360px; }
@media (max-width: 800px) { .topbar { padding: 12px 12px 0; } .topbar input { max-width: none; } .topbar + .main { padding-top: 10px; } }
.sub a, td a, p a, li a, dd a { text-decoration: underline; text-underline-offset: 2px; } .results a { text-decoration: none; } .nav a, .btn, .topbar a { text-decoration: none; }
.table-wrap a:not(.btn), .card a:not(.btn) { text-decoration: underline; text-underline-offset: 2px; }
td .mono { white-space: nowrap; }
