/* SPK design system. Calm, neutral surfaces with one accent; colour means status or the primary action.
   Light and dark themes follow the device. Font: Inter, self-hosted (the site's CSP does not allow Google Fonts). */
@font-face { font-family: 'Inter'; font-style: normal; font-weight: 100 900; font-display: swap; src: url('../assets/fonts/Inter-latin-variable.woff2') format('woff2'); }

:root {
  color-scheme: light dark;
  --bg: #f3f5f7; --surface: #ffffff; --surface-2: #f7f8fa; --border: #e3e7ec; --border-strong: #c9d0d8;
  --text: #17202b; --text-2: #475467; --text-3: #5d6a7b;
  --accent: #0b6b5b; --accent-hover: #095649; --accent-bg: #e2f1ed; --on-accent: #ffffff;
  --ok: #146c43; --ok-bg: #e3f3ea; --warn: #8f5200; --warn-bg: #fdf0d3; --bad: #b42318; --bad-bg: #fce9e7; --neutral-bg: #eceff3;
  --radius: 8px; --radius-lg: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .04);
  --shadow-pop: 0 12px 32px rgba(16, 24, 40, .18);
  --logo-filter: none;
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --side-w: 244px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1319; --surface: #161c24; --surface-2: #1b222c; --border: #28313d; --border-strong: #3a4554;
    --text: #e9edf2; --text-2: #b0bac7; --text-3: #94a0b0;
    --accent: #34c3a5; --accent-hover: #5fd3ba; --accent-bg: #12332d; --on-accent: #04201a;
    --ok: #5bd694; --ok-bg: #12301f; --warn: #f0b95a; --warn-bg: #36280d; --bad: #ff8f84; --bad-bg: #3b1a17; --neutral-bg: #232c38;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4); --shadow-pop: 0 12px 32px rgba(0, 0, 0, .55);
    --logo-filter: invert(1);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 400 14px/1.5 var(--font); color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; font-feature-settings: 'cv11', 'ss01'; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -.01em; color: var(--text); }
h2 { font-size: 20px; line-height: 1.3; } h3 { font-size: 15px; line-height: 1.35; margin-bottom: 8px; }
p { margin: 0 0 10px; }
a { color: var(--accent); text-decoration: none; } a:hover { text-decoration: underline; text-underline-offset: 2px; }
/* a link inside a sentence or table is underlined, so it does not rely on colour alone */
main p a, main li a, main td a, main dd a, main .sub a, main .muted a, main summary a, .card a:not(.btn):not(:has(> button)) { text-decoration: underline; text-underline-offset: 2px; }
.group .list li a, .tabs a, .results a { text-decoration: none; } .group .list li a:hover { text-decoration: underline; }
.muted, .sub { color: var(--text-2); } .sub { font-size: 13px; }
.error, .form-error { color: var(--bad); } .form-error { font-size: 13px; }
.late { color: var(--bad); font-weight: 600; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.ico { flex: none; vertical-align: middle; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 16px 12px 12px; background: var(--surface); border-right: 1px solid var(--border); overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 2px 8px 18px; }
.brand img { width: 34px; height: 34px; object-fit: contain; filter: var(--logo-filter); }
.brand b { display: block; font-size: 14px; line-height: 1.25; font-weight: 700; }
.brand small { display: block; color: var(--text-3); font-size: 12px; }
#nav { display: flex; flex-direction: column; gap: 2px; }
#nav a { display: flex; align-items: center; gap: 11px; height: 38px; padding: 0 10px; border-radius: var(--radius); color: var(--text-2); font-weight: 500; }
#nav a .ico { color: var(--text-3); }
#nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
#nav a[aria-current="page"] { background: var(--accent-bg); color: var(--accent); font-weight: 600; }
#nav a[aria-current="page"] .ico { color: var(--accent); }
.nav-more, .nav-sheet { display: none; }
.me { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border); display: grid; grid-template-columns: auto 1fr; gap: 8px 10px; align-items: center; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--accent-bg); color: var(--accent); display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; }
.me-text { min-width: 0; line-height: 1.3; } .me-text b { display: block; font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } .me-text span { display: block; color: var(--text-3); font-size: 12px; text-transform: capitalize; }
.me-actions { grid-column: 1 / -1; display: flex; gap: 6px; }
.content { min-width: 0; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 14px 28px 0; max-width: 1280px; }
.topbar .crest { display: none; }
.searchbox { position: relative; flex: 1; max-width: 440px; }
.searchbox .ico { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
.searchbox input { padding-left: 36px; padding-right: 34px; background: var(--surface); }
.searchbox kbd { position: absolute; right: 9px; top: 50%; transform: translateY(-50%); font: 500 11px var(--font); color: var(--text-3); border: 1px solid var(--border-strong); border-radius: 4px; padding: 0 5px; line-height: 18px; pointer-events: none; }
main { max-width: 1280px; padding: 18px 28px 40px; }
body.signed-out .side, body.signed-out .topbar { display: none; }
body.signed-out .shell { display: block; }
body.signed-out main { max-width: none; padding: 0; }

/* ---------- page heading ---------- */
.actions { display: flex; align-items: center; gap: 8px 10px; flex-wrap: wrap; margin: 0 0 14px; }
.actions h2, .actions h3 { margin: 0; }
.grow { flex: 1 1 260px; min-width: 0; margin: 0; overflow-wrap: anywhere; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px 16px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head .sub { margin-top: 2px; }

/* ---------- controls ---------- */
button, .btn { font: inherit; font-weight: 500; font-size: 13.5px; min-height: 36px; padding: 0 14px; border-radius: var(--radius); border: 1px solid var(--accent); background: var(--accent); color: var(--on-accent); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 7px; text-decoration: none; transition: background-color .12s, border-color .12s, box-shadow .12s; }
button:hover, .btn:hover { background: var(--accent-hover); border-color: var(--accent-hover); text-decoration: none; }
button.secondary, .btn.secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
button.secondary:hover, .btn.secondary:hover { background: var(--surface-2); border-color: var(--border-strong); }
button:disabled { opacity: .55; cursor: not-allowed; }
a:has(> button) { text-decoration: none; }
a:has(> button):hover { text-decoration: none; }
a:has(> button):focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--radius); }
.btn-sm, button.small { min-height: 30px; padding: 0 10px; font-size: 12.5px; }
.btn-quiet { background: transparent; border-color: transparent; color: var(--text-2); } .btn-quiet:hover { background: var(--neutral-bg); border-color: transparent; }
input, select, textarea { font: inherit; width: 100%; min-height: 36px; padding: 0 10px; border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--surface); color: var(--text); }
textarea { min-height: 80px; padding: 8px 10px; resize: vertical; }
select { padding-right: 8px; }
input::placeholder, textarea::placeholder { color: var(--text-3); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-bg); }
input[type=checkbox], input[type=radio] { width: 16px; min-height: 0; height: 16px; accent-color: var(--accent); }
input[type=search] { -webkit-appearance: none; appearance: none; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 0 0 14px; }
.inline-form > input, .inline-form > select { width: auto; flex: 1 1 160px; max-width: 320px; }
.inline-form > input[type=checkbox] { flex: none; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px 16px; align-items: start; }
.grid label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 500; color: var(--text-2); }
.grid label.span-2 { grid-column: span 2; }
.grid label.check, label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; font-size: 14px; color: var(--text); }
.spacer { flex: 1; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); margin: 0 0 14px; padding: 10px 14px 14px; background: var(--surface); }
legend { font-weight: 600; padding: 0 6px; font-size: 13px; color: var(--text-2); }
details { margin: 8px 0; } summary { cursor: pointer; font-weight: 500; padding: 4px 0; color: var(--text-2); } summary:hover { color: var(--text); }
details.card > summary { color: var(--text); }

/* ---------- surfaces ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 16px 18px; margin-bottom: 16px; box-shadow: var(--shadow); }
.card > h3:first-child { margin-top: 0; }
.banner { border-radius: var(--radius); padding: 10px 14px; margin-bottom: 14px; border: 1px solid transparent; background: var(--bad-bg); color: var(--bad); font-weight: 500; }
.banner.warn, .banner.ok { background: var(--warn-bg); color: var(--warn); } .banner.ok { background: var(--ok-bg); color: var(--ok); }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin: 0 0 16px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 14px 16px; min-width: 0; box-shadow: var(--shadow); }
button.tile { display: block; font-weight: 400; text-align: left; color: var(--text); }
button.tile:hover { background: var(--surface-2); border-color: var(--border-strong); }
.tile-value { font-size: 24px; line-height: 1.2; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -.02em; overflow-wrap: anywhere; }
.tile-label { color: var(--text-2); font-size: 12.5px; margin-top: 4px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; margin: 0; } .kv dt { color: var(--text-2); font-size: 13px; } .kv dd { margin: 0; overflow-wrap: anywhere; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 9px 0; border-bottom: 1px solid var(--border); display: flex; flex-wrap: wrap; gap: 2px 10px; align-items: baseline; } .list li:last-child { border-bottom: 0; }
.quick-links { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; } .quick-links a { padding: 8px 14px; border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--surface); }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 0 9px; border-radius: 999px; font-size: 12px; font-weight: 500; line-height: 22px; background: var(--neutral-bg); color: var(--text-2); white-space: nowrap; vertical-align: middle; }
.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); }
h2 .chip, h3 .chip { font-size: 11.5px; transform: translateY(-1px); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow); margin-bottom: 16px; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; font-weight: 600; color: var(--text-2); background: var(--surface-2); white-space: nowrap; letter-spacing: .01em; }
tr:last-child td { border-bottom: 0; }
th.num, td.num { text-align: right; }
th button.th-sort, .th-sort { background: none; border: 0; padding: 0; min-height: 0; color: inherit; font: inherit; font-weight: 600; cursor: pointer; } .th-sort:hover { background: none; color: var(--accent); }
tr[data-open], tbody tr.clickable { cursor: pointer; } tr[data-open]:hover, tbody tr.clickable:hover, tbody tr:hover td { background-color: var(--surface-2); }
.card table { margin: 0; }
.pager { display: flex; align-items: center; justify-content: flex-end; gap: 10px; padding: 10px 14px; color: var(--text-2); }

/* ---------- list toolbar ---------- */
.listbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 0 0 12px; }
.listbar .searchbox { flex: 1 1 240px; max-width: 360px; }
.listbar select { width: auto; max-width: 100%; flex: 0 1 auto; }
.listbar .count { margin-left: auto; white-space: nowrap; }
@media (max-width: 640px) { .listbar .searchbox { flex-basis: 100%; max-width: none; } .listbar select { flex: 1 1 calc(50% - 8px); } .listbar .count { margin: 0; flex-basis: 100%; } }

.picked { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--surface-2); }
.picklist { margin-top: 6px; } .picklist li { padding: 3px 0; border: 0; } .picklist button { width: 100%; justify-content: flex-start; flex-wrap: wrap; text-align: left; min-height: 44px; gap: 4px 8px; font-weight: 400; } .picklist .sub { margin-left: auto; }
fieldset.plain { border: 0; box-shadow: none; padding: 0; margin: 0 0 12px; background: none; overflow: visible; } fieldset.plain > :not(legend) { margin-left: 0; margin-right: 0; }

.crumbs { margin: 0 0 8px; font-size: 13px; color: var(--text-2); }
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px 22px; margin: 0; }
.facts dt { font-size: 12px; font-weight: 500; color: var(--text-2); margin: 0 0 3px; } .facts dd { margin: 0; font-weight: 500; overflow-wrap: anywhere; }
.facts select { min-height: 34px; width: 100%; max-width: 100%; } .facts dd .muted { font-weight: 400; font-size: 12.5px; display: block; margin-top: 2px; } .facts dd button { margin-top: 6px; }
.tabs.jump { position: sticky; top: 0; z-index: 8; background: var(--bg); margin-top: 0; }
.task .inline-form { margin-bottom: 8px; } .task .inline-form label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--text-2); font-weight: 500; flex: 1 1 150px; } .task .inline-form select, .task .inline-form input { min-height: 34px; }
.task > .actions { margin-bottom: 8px; } .task details { margin: 4px 0 0; }
button.quiet { background: transparent; border-color: transparent; color: var(--text-2); } button.quiet:hover { background: var(--bad-bg); color: var(--bad); border-color: transparent; }
.timeline li { align-items: flex-start; gap: 10px; } .timeline .grow { flex: 1 1 0; }
@media (max-width: 640px) { .facts { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; } }

/* ---------- filters and tabs ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin: 0 0 16px; overflow-x: auto; scrollbar-width: none; }
.tabs button { background: none; border: 0; border-bottom: 2px solid transparent; border-radius: 0; margin-bottom: -1px; min-height: 40px; padding: 0 14px; color: var(--text-2); font-weight: 500; white-space: nowrap; }
.tabs button:hover { background: none; color: var(--text); } .tabs button[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.tabs a { display: inline-flex; align-items: center; min-height: 40px; padding: 0 14px; border-bottom: 2px solid transparent; margin-bottom: -1px; color: var(--text-2); font-weight: 500; white-space: nowrap; text-decoration: none; }
.tabs a:hover { color: var(--text); text-decoration: none; } .tabs a[aria-current="page"] { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.tabs .count { margin-left: 6px; font-size: 12px; color: var(--text-3); font-weight: 500; font-variant-numeric: tabular-nums; } .tabs [aria-selected="true"] .count { color: var(--accent); }

/* ---------- loading, empty ---------- */
.state { padding: 48px 16px; text-align: center; color: var(--text-2); }
.state .ico-wrap { width: 52px; height: 52px; margin: 0 auto 12px; border-radius: 50%; display: flex; align-items: center; justify-content: center; background: var(--accent-bg); color: var(--accent); }
.state-title { font-weight: 600; font-size: 15px; color: var(--text); } .state-hint { margin-top: 4px; font-size: 13px; }
.state-err .ico-wrap { background: var(--bad-bg); color: var(--bad); }
.spinner { display: inline-block; width: 15px; height: 15px; margin-right: 9px; vertical-align: -3px; 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; } * { transition: none !important; } }

/* ---------- Today ---------- */
.card.group { padding: 0; overflow: hidden; }
.group > h3 { display: flex; align-items: center; gap: 8px; margin: 0; padding: 12px 18px; background: var(--surface-2); border-bottom: 1px solid var(--border); font-size: 13.5px; }
.group .list li { padding: 11px 18px; flex-wrap: wrap; gap: 4px 12px; align-items: center; }
.group .list li a { flex: 1 1 160px; min-width: 0; font-weight: 500; color: var(--text); overflow-wrap: anywhere; }
.group .list li .grow { flex: 2 1 220px; } .group .list li a:hover { color: var(--accent); }
.q-kind { flex: none; font-size: 12px; font-weight: 500; color: var(--text-2); background: var(--neutral-bg); padding: 0 8px; border-radius: 999px; line-height: 22px; }
.q-date { flex: none; font-size: 12.5px; color: var(--text-2); font-variant-numeric: tabular-nums; }
#search-results .card { margin-top: 0; }

.money-strip { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 12px; margin-bottom: 16px; text-decoration: none; color: var(--text); } .money-strip:hover { text-decoration: none; background: var(--surface-2); }
.money-strip .tile-value { font-size: 22px; } .money-strip .tile-label { margin: 0; }

/* ---------- sign in ---------- */
.login-box { max-width: 400px; margin: 9vh auto 0; background: var(--surface); padding: 30px 28px 26px; border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-pop); }
.login-box .login-mark { text-align: center; margin-bottom: 20px; } .login-box .login-mark img { width: 64px; height: 64px; object-fit: contain; filter: var(--logo-filter); }
.login-box .login-mark b { display: block; margin-top: 8px; font-size: 16px; font-weight: 700; } .login-box .login-mark span { color: var(--text-2); font-size: 13px; }
.login-box h2 { font-size: 18px; margin-bottom: 4px; }
.login-box form { display: flex; flex-direction: column; gap: 10px; margin: 14px 0 0; }
.login-box button[type=submit] { min-height: 40px; font-size: 14px; margin-top: 2px; }
.login-wrap { padding: 0 16px; }

/* ---------- portal (client upload page) ---------- */
.portal-head { display: flex; align-items: center; gap: 10px; padding: 12px 20px; background: var(--surface); border-bottom: 1px solid var(--border); }
.portal-head img { width: 30px; height: 30px; filter: var(--logo-filter); } .portal-head .brand-text { font-weight: 600; }
body.portal main { margin: 0 auto; max-width: 760px; }

/* ---------- phones ---------- */
@media (max-width: 800px) {
  .shell { display: block; }
  .side { position: fixed; z-index: 40; left: 0; right: 0; bottom: 0; top: auto; height: auto; flex-direction: row; padding: 4px 6px calc(4px + env(safe-area-inset-bottom)); border-right: 0; border-top: 1px solid var(--border); overflow: visible; box-shadow: 0 -4px 16px rgba(16, 24, 40, .06); }
  .brand, .me { display: none; }
  #nav { flex-direction: row; gap: 0; width: 100%; }
  #nav a, .nav-more { flex: 1 1 0; min-width: 0; flex-direction: column; justify-content: center; gap: 3px; height: 54px; padding: 4px 2px; font-size: 11.5px; text-align: center; border-radius: var(--radius); }
  .nav-more { display: flex; align-items: center; background: none; border: 0; color: var(--text-2); font-weight: 500; flex: 1 1 0; min-height: 54px; padding: 4px 2px; } .nav-more:hover { background: var(--surface-2); }
  .nav-more .ico { color: var(--text-3); } .nav-more[aria-expanded="true"] { background: var(--accent-bg); color: var(--accent); } .nav-more[aria-expanded="true"] .ico { color: var(--accent); }
  #nav a.n-extra { display: none; }
  .nav-sheet { display: block; position: fixed; z-index: 45; left: 8px; right: 8px; bottom: calc(66px + env(safe-area-inset-bottom)); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 8px; box-shadow: var(--shadow-pop); }
  .nav-sheet[hidden] { display: none; }
  .nav-sheet .who { display: flex; align-items: center; gap: 10px; padding: 6px 8px 10px; margin-bottom: 6px; border-bottom: 1px solid var(--border); }
  .nav-sheet .who .me-text b { font-size: 14px; }
  .nav-sheet .grid2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 4px; }
  .nav-sheet a, .nav-sheet button { display: flex; align-items: center; justify-content: flex-start; gap: 10px; min-height: 46px; padding: 0 12px; border-radius: var(--radius); color: var(--text); font-weight: 500; background: none; border: 0; font-size: 14px; }
  .nav-sheet a .ico, .nav-sheet button .ico { color: var(--text-3); }
  .nav-sheet a:hover, .nav-sheet button:hover, .nav-sheet a[aria-current="page"] { background: var(--accent-bg); color: var(--accent); text-decoration: none; } .nav-sheet a[aria-current="page"] .ico { color: var(--accent); }
  .nav-sheet .foot { margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--border); display: grid; grid-template-columns: repeat(2, 1fr); gap: 4px; }
  .topbar { padding: 12px 14px 0; gap: 10px; } .topbar .crest { display: block; width: 32px; height: 32px; object-fit: contain; filter: var(--logo-filter); } .searchbox { max-width: none; } .searchbox kbd { display: none; }
  main { padding: 14px 14px calc(88px + env(safe-area-inset-bottom)); }
  body.signed-out main { padding: 0; }
}
@media (max-width: 640px) {
  input, select, textarea { font-size: 16px; }                  /* stops phones zooming in when a field is tapped */
  h2 { font-size: 19px; }
  .actions > a:has(> button), .actions > button:only-of-type { flex: 0 0 auto; }
  .grid label.span-2 { grid-column: span 1; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; } .tile { padding: 12px; } .tile-value { font-size: 20px; }
  .card { padding: 14px; border-radius: 10px; } .group > h3, .group .list li { padding-left: 14px; padding-right: 14px; }
  .inline-form > input, .inline-form > select { max-width: none; flex-basis: 100%; }
  .kv { grid-template-columns: 1fr; gap: 1px 0; } .kv dd { margin-bottom: 8px; }
  .login-box { margin-top: 5vh; padding: 24px 20px; }
  /* tables become one card per row */
  .table-wrap { border: 0; background: transparent; box-shadow: none; overflow: visible; }
  table.stack, table.stack tbody, table.stack tr, table.stack td { display: block; width: 100%; }
  table.stack thead { display: none; }
  table.stack tr { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; margin-bottom: 8px; padding: 6px 14px; box-shadow: var(--shadow); }
  table.stack td { position: relative; border: 0; padding: 5px 0 5px 40%; min-height: 26px; text-align: left; overflow-wrap: anywhere; }
  table.stack td::before { content: attr(data-label); position: absolute; left: 0; top: 6px; width: 36%; color: var(--text-3); font-size: 12px; font-weight: 500; }
  table.stack td[data-label=""] { padding-left: 0; } table.stack td[data-label=""]::before { content: none; }
  table.stack td.num { text-align: left; }
  table.stack td:empty { display: none; }
  table.stack td button, table.stack td .btn { margin: 2px 4px 2px 0; }
  .pager { justify-content: space-between; padding: 8px 2px; }
}

/* ---------- dialogs and toasts ---------- */
.modal-wrap { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(12, 18, 26, .5); backdrop-filter: blur(2px); animation: fade .12s ease-out; }
.modal { width: 100%; max-width: 460px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-pop); animation: pop .14s ease-out; }
.modal-body { padding: 20px 20px 8px; } .modal-body h3 { font-size: 17px; margin: 0 0 6px; }
.modal-msg { color: var(--text-2); margin: 0 0 10px; }
.modal-fields label { display: block; font-size: 13px; font-weight: 500; color: var(--text-2); margin: 10px 0 5px; }
.modal-fields textarea, .modal-fields input { margin-bottom: 2px; }
.modal .form-error { min-height: 18px; margin: 4px 0 0; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 10px 20px 18px; }
button.danger { background: var(--bad); border-color: var(--bad); color: #fff; } button.danger:hover { background: var(--bad); filter: brightness(.92); }
body.modal-open { overflow: hidden; }
#toasts { position: fixed; z-index: 200; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; pointer-events: none; }
.toast { display: flex; align-items: center; gap: 10px; max-width: 380px; padding: 11px 16px 11px 13px; border-radius: 10px; background: #17202b; color: #fff; font-size: 13.5px; font-weight: 500; box-shadow: var(--shadow-pop); animation: pop .16s ease-out; pointer-events: auto; }
.toast .ico { color: #5bd694; } .toast-err { background: #7a1d14; } .toast-err .ico { color: #ffb4ab; }
@media (prefers-color-scheme: dark) { .toast { background: #e9edf2; color: #17202b; } .toast .ico { color: #146c43; } .toast-err { background: #ffdad5; color: #5a0f08; } .toast-err .ico { color: #b42318; } }
@keyframes fade { from { background-color: rgba(12, 18, 26, 0); } } @keyframes pop { from { transform: translateY(6px) scale(.98); } }
@media (max-width: 640px) {
  .modal-wrap { align-items: flex-end; padding: 0; }
  .modal { max-width: none; border-radius: 16px 16px 0 0; border-bottom: 0; padding-bottom: env(safe-area-inset-bottom); animation: sheet .18s ease-out; }
  .modal-foot { flex-direction: column-reverse; } .modal-foot button { width: 100%; min-height: 44px; }
  #toasts { left: 12px; right: 12px; bottom: calc(76px + env(safe-area-inset-bottom)); align-items: stretch; } .toast { max-width: none; }
}
@keyframes sheet { from { transform: translateY(40px); } }
@media (prefers-reduced-motion: reduce) { .modal-wrap, .modal, .toast { animation: none; } }

/* ---------- forms: each fieldset is a section card ---------- */
fieldset { padding: 0 0 18px; overflow: hidden; box-shadow: var(--shadow); border-radius: var(--radius-lg); }
fieldset > legend { float: left; width: 100%; padding: 12px 18px; margin: 0 0 16px; font-size: 14px; font-weight: 600; color: var(--text); background: var(--surface-2); border-bottom: 1px solid var(--border); }
fieldset > legend + * { clear: both; }
fieldset > :not(legend) { margin-left: 18px; margin-right: 18px; } fieldset { padding-bottom: 18px; }
form > .actions:last-child { padding-top: 4px; }
label .req, .grid label:has(input[required]) > :first-child::after { content: ''; }

/* ---------- tablet: icon rail instead of a full sidebar ---------- */
@media (min-width: 801px) and (max-width: 1100px) {
  :root { --side-w: 72px; }
  .side { padding: 12px 8px; align-items: center; }
  .brand { padding: 2px 0 14px; } .brand div { display: none; }
  #nav { width: 100%; } #nav a { justify-content: center; padding: 0; height: 42px; } #nav a span { display: none; }
  .me { grid-template-columns: 1fr; justify-items: center; gap: 8px; } .me-text { display: none; }
  .me-actions { flex-direction: column; } .me-actions .btn, .me-actions button { padding: 0; width: 38px; } .me-actions span { display: none; }
  main, .topbar { padding-left: 22px; padding-right: 22px; }
}

/* ---------- phone refinements ---------- */
@media (max-width: 640px) {
  .grow { flex-basis: 100%; }
  .actions { gap: 8px; }
  form > .actions:last-child { position: sticky; z-index: 6; bottom: calc(64px + env(safe-area-inset-bottom)); margin: 8px -14px 0; padding: 10px 14px; background: var(--surface); border-top: 1px solid var(--border); box-shadow: 0 -6px 16px rgba(16, 24, 40, .06); }
  form > .actions:last-child button { flex: 1 1 auto; min-height: 44px; }
  table.stack td[data-primary] { padding: 4px 0 6px; font-size: 15px; font-weight: 600; min-height: 0; } table.stack td[data-primary]::before { content: none; }
  table.stack td[data-empty] { display: none; }
  table.stack tr { padding-top: 8px; padding-bottom: 8px; }
}
@media print { .side, .topbar, .nav-sheet, .actions button, .no-print { display: none !important; } .shell { display: block; } body { background: #fff; } .card, .tile { box-shadow: none; break-inside: avoid; } main { padding: 0; max-width: none; } }
