/* ============================================================
   Agent Advance & Balance — design system
   Flat, professional, accessible (WCAG AA). No gradients, no heavy shadows.
   Color always comes with text or an icon.
   ============================================================ */

:root {
  --font: 'Inter', 'Noto Sans Sinhala', 'Iskoola Pota', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --fs-xs: 0.75rem; --fs-sm: 0.8125rem; --fs-base: 0.9375rem; --fs-md: 1rem; --fs-lg: 1.125rem; --fs-xl: 1.375rem; --fs-2xl: 1.75rem;
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 20px; --sp-6: 24px; --sp-8: 32px;
  --r-sm: 6px; --r: 10px; --r-lg: 14px;
  --tap: 44px; --sidebar-w: 264px; --topbar-h: 64px;

  --bg: #f4f6fa; --surface: #ffffff; --surface-2: #f8fafc; --surface-3: #eef2f7;
  --border: #e3e8ef; --border-strong: #cbd3df;
  --text: #0f172a; --text-2: #334155; --muted: #5b6577;
  --primary: #1d4ed8; --primary-hover: #1e40af; --primary-soft: #e8efff; --primary-text: #ffffff;
  --focus: #2563eb;
  --navy: #0b1f3a; --navy-2: #12294a; --navy-3: #1b3660; --navy-text: #c9d4e5; --navy-muted: #8798b3;
  --green: #15803d; --green-bg: #e9f7ef; --green-text: #14532d; --green-line: #86d4a5;
  --blue: #1d4ed8; --blue-bg: #e8efff; --blue-text: #1e3a8a; --blue-line: #a7bff7;
  --amber: #b45309; --amber-bg: #fff6e0; --amber-text: #78350f; --amber-line: #f2c26b;
  --red: #b91c1c; --red-bg: #fdecec; --red-text: #7f1d1d; --red-line: #f0a3a3;
  --gray: #64748b; --gray-bg: #f1f4f8; --gray-text: #334155; --gray-line: #cdd5e0;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a0f17; --surface: #111823; --surface-2: #151d2a; --surface-3: #1b2533;
    --border: #232f40; --border-strong: #33415a;
    --text: #e6ebf2; --text-2: #c3cddb; --muted: #94a1b5;
    --primary: #4f86f7; --primary-hover: #6d9bff; --primary-soft: #16264a; --primary-text: #071021;
    --focus: #8fb3ff;
    --navy: #070d17; --navy-2: #0e1726; --navy-3: #182640; --navy-text: #c4cfdf; --navy-muted: #7f8ea7;
    --green: #4ade80; --green-bg: #0f2a1b; --green-text: #bbf7d0; --green-line: #1f6b3d;
    --blue: #8fb3ff; --blue-bg: #13213f; --blue-text: #dbe6ff; --blue-line: #2c4a86;
    --amber: #fbbf24; --amber-bg: #2c2108; --amber-text: #fde68a; --amber-line: #7a5a12;
    --red: #f87171; --red-bg: #321313; --red-text: #fecaca; --red-line: #7c2a2a;
    --gray: #94a3b8; --gray-bg: #1a2230; --gray-text: #cbd5e1; --gray-line: #36435a;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  }
}
:root[data-theme="dark"] {
    --bg: #0a0f17; --surface: #111823; --surface-2: #151d2a; --surface-3: #1b2533;
    --border: #232f40; --border-strong: #33415a;
    --text: #e6ebf2; --text-2: #c3cddb; --muted: #94a1b5;
    --primary: #4f86f7; --primary-hover: #6d9bff; --primary-soft: #16264a; --primary-text: #071021;
    --focus: #8fb3ff;
    --navy: #070d17; --navy-2: #0e1726; --navy-3: #182640; --navy-text: #c4cfdf; --navy-muted: #7f8ea7;
    --green: #4ade80; --green-bg: #0f2a1b; --green-text: #bbf7d0; --green-line: #1f6b3d;
    --blue: #8fb3ff; --blue-bg: #13213f; --blue-text: #dbe6ff; --blue-line: #2c4a86;
    --amber: #fbbf24; --amber-bg: #2c2108; --amber-text: #fde68a; --amber-line: #7a5a12;
    --red: #f87171; --red-bg: #321313; --red-text: #fecaca; --red-line: #7c2a2a;
    --gray: #94a3b8; --gray-bg: #1a2230; --gray-text: #cbd5e1; --gray-line: #36435a;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  }
:root[data-theme="dark"] { color-scheme: dark; }
:root[data-theme="light"] { color-scheme: light; }

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); font-size: var(--fs-base); line-height: 1.55; color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
body.no-scroll { overflow: hidden; }
h1 { font-size: var(--fs-2xl); font-weight: 700; letter-spacing: -0.02em; line-height: 1.2; margin: 0 0 var(--sp-2); display: flex; align-items: center; flex-wrap: wrap; gap: var(--sp-3); }
h2 { font-size: var(--fs-lg); font-weight: 650; letter-spacing: -0.01em; margin: var(--sp-8) 0 var(--sp-3); }
h3 { font-size: var(--fs-md); font-weight: 600; margin: var(--sp-5) 0 var(--sp-2); }
p { margin: 0 0 var(--sp-3); }
a { color: var(--primary); text-underline-offset: 2px; }
a:hover { color: var(--primary-hover); }
code { font-family: ui-monospace, 'Cascadia Mono', Consolas, monospace; font-size: 0.85em; background: var(--surface-3); padding: 1px 6px; border-radius: 4px; overflow-wrap: anywhere; }
ul { padding-left: 1.25em; }
.muted { color: var(--muted); }
.small { font-size: var(--fs-sm); }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.neg { color: var(--red); font-weight: 600; }
.pos { color: var(--green); font-weight: 600; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.icon { width: 18px; height: 18px; flex: 0 0 auto; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.skip-link { position: absolute; left: -9999px; top: 8px; background: var(--surface); color: var(--text); padding: var(--sp-2) var(--sp-4); border-radius: var(--r-sm); z-index: 100; }
.skip-link:focus { left: var(--sp-2); }

/* ---------- shell ---------- */
.app-shell { min-height: 100vh; }
.app-main { min-width: 0; }
.container { max-width: 1200px; margin: 0 auto; padding: var(--sp-6) var(--sp-4) 64px; }
main:focus { outline: none; }
.app-shell.is-public .container { max-width: none; padding: 0; }
.sidebar { position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); background: var(--navy); color: var(--navy-text); display: flex; flex-direction: column; z-index: 40; transform: translateX(-100%); transition: transform 0.2s ease; overflow-y: auto; }
.sidebar.open { transform: none; }
.scrim { position: fixed; inset: 0; background: rgba(5, 12, 24, 0.55); z-index: 35; }
.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: var(--sp-4) var(--sp-4) var(--sp-3); }
.brand { display: flex; align-items: center; gap: var(--sp-3); color: #fff; text-decoration: none; min-height: var(--tap); }
.brand:hover { color: #fff; }
.brand-mark { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 9px; background: var(--primary); color: #fff; font-weight: 700; font-size: 0.8125rem; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-size: var(--fs-base); }
.brand-text small { color: var(--navy-muted); font-size: var(--fs-xs); }
.side-nav { padding: var(--sp-2) var(--sp-3); flex: 1; }
.nav-label { text-transform: uppercase; letter-spacing: 0.08em; font-size: 0.6875rem; font-weight: 600; color: var(--navy-muted); margin: var(--sp-4) var(--sp-3) var(--sp-2); }
.side-nav ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.side-nav a { display: flex; align-items: center; gap: var(--sp-3); min-height: 42px; padding: 0 var(--sp-3); border-radius: var(--r-sm); color: var(--navy-text); text-decoration: none; font-weight: 500; position: relative; }
.side-nav a:hover { background: var(--navy-2); color: #fff; }
.side-nav a[aria-current="page"] { background: var(--navy-3); color: #fff; font-weight: 600; }
.side-nav a[aria-current="page"]::before { content: ''; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: #6d9bff; }
.sidebar a:focus-visible, .sidebar button:focus-visible { outline-color: #8fb3ff; }
.sidebar-foot { border-top: 1px solid var(--navy-3); padding: var(--sp-3); display: grid; gap: var(--sp-1); }
.user-card { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-2); border-radius: var(--r-sm); color: #fff; text-decoration: none; min-height: var(--tap); }
.user-card:hover, .user-card[aria-current="page"] { background: var(--navy-2); color: #fff; }
.user-meta { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.user-meta strong { font-size: var(--fs-sm); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-meta small { color: var(--navy-muted); font-size: var(--fs-xs); }
.side-logout { display: flex; align-items: center; gap: var(--sp-3); min-height: 40px; padding: 0 var(--sp-3); border: 0; background: transparent; color: var(--navy-text); font: inherit; font-weight: 500; border-radius: var(--r-sm); cursor: pointer; text-align: left; }
.side-logout:hover { background: var(--navy-2); color: #fff; }
.avatar { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; background: #2d4f86; color: #fff; font-weight: 600; font-size: var(--fs-sm); flex: 0 0 auto; text-decoration: none; }
.avatar-sm { background: var(--primary); color: var(--primary-text); }
.avatar-sm:hover { color: var(--primary-text); background: var(--primary-hover); }
.topbar { position: sticky; top: 0; z-index: 20; height: var(--topbar-h); background: var(--surface); border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: var(--sp-3); padding: 0 var(--sp-4); }
.topbar-title { flex: 1; min-width: 0; display: flex; align-items: center; gap: var(--sp-2); white-space: nowrap; overflow: hidden; }
.topbar-title strong { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.crumb { color: var(--muted); font-size: var(--fs-sm); }
.crumb-sep { color: var(--border-strong); }
.topbar-actions { display: flex; align-items: center; gap: var(--sp-2); }
.icon-btn { display: inline-grid; place-items: center; width: var(--tap); height: var(--tap); border: 1px solid transparent; border-radius: var(--r-sm); background: transparent; color: inherit; cursor: pointer; }
.icon-btn:hover { background: var(--surface-3); }
.sidebar .icon-btn:hover { background: var(--navy-2); }
.icon-btn .icon { width: 22px; height: 22px; }
@media (max-width: 560px) {
  .crumb, .crumb-sep, .hide-sm { display: none; }
  .topbar-actions .btn span { display: none; }
  .container { padding-top: var(--sp-5); }
}
@media (min-width: 1024px) {
  .sidebar { transform: none; }
  .sidebar[hidden] { display: none; }
  .app-shell:not(.is-public) .app-main { margin-left: var(--sidebar-w); }
  .menu-btn, .sidebar-close, .scrim { display: none !important; }
  .topbar { padding: 0 var(--sp-8); }
  .container { padding: var(--sp-8) var(--sp-8) 72px; }
}

/* ---------- page header ---------- */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: var(--sp-3); margin-bottom: var(--sp-2); }
.page-head h1 { margin: 0; }
.page-head + p.muted, h1 + p.muted { margin-top: var(--sp-1); margin-bottom: var(--sp-6); }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2); min-height: 40px; padding: 0 var(--sp-4); border: 1px solid var(--border-strong); border-radius: var(--r-sm); background: var(--surface); color: var(--text); font: inherit; font-weight: 600; font-size: var(--fs-sm); text-decoration: none; cursor: pointer; white-space: nowrap; transition: background-color 0.12s, border-color 0.12s; box-shadow: var(--shadow); }
.btn:hover { background: var(--surface-3); color: var(--text); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); color: var(--primary-text); }
.btn-danger { color: var(--red); border-color: var(--red-line); background: var(--surface); }
.btn-danger:hover { background: var(--red-bg); color: var(--red); }
.btn-ghost { border-color: transparent; background: transparent; box-shadow: none; }
.btn-ghost:hover { background: var(--surface-3); }
.btn-small { min-height: 36px; padding: 0 var(--sp-3); }
@media (pointer: coarse) { .btn, .btn-small { min-height: var(--tap); } }
.btn[disabled] { opacity: 0.65; cursor: progress; }
.btn .icon { width: 16px; height: 16px; }
.actions { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin-top: var(--sp-5); }
@media (max-width: 480px) { form .actions .btn, .card .actions .btn { flex: 1 1 100%; } }
.linklike { background: none; border: 0; padding: 0; font: inherit; color: var(--primary); cursor: pointer; }

/* ---------- cards & stats ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); padding: var(--sp-5); margin-bottom: var(--sp-4); box-shadow: var(--shadow); }
@media (min-width: 768px) { .card { padding: var(--sp-6); } }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.card h2 { font-size: var(--fs-md); }
.grid { display: grid; gap: var(--sp-4); grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); margin-bottom: var(--sp-2); }
.stat { position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); padding: var(--sp-5); box-shadow: var(--shadow); overflow: hidden; }
.stat::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--gray-line); }
.stat .label { color: var(--muted); font-size: var(--fs-sm); font-weight: 500; margin: 0; display: flex; align-items: center; gap: var(--sp-2); }
.stat .value { font-size: 1.625rem; font-weight: 700; letter-spacing: -0.02em; margin: var(--sp-2) 0 0; font-variant-numeric: tabular-nums; line-height: 1.2; }
.stat .small { margin: var(--sp-2) 0 0; }
.stat-green::before { background: var(--green); }
.stat-red::before { background: var(--red); }
.stat-blue::before { background: var(--blue); }
.stat-amber::before { background: var(--amber); }
.stat-ico { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 8px; background: var(--surface-3); color: var(--text-2); }
.stat-green .stat-ico { background: var(--green-bg); color: var(--green); }
.stat-red .stat-ico { background: var(--red-bg); color: var(--red); }
.stat-blue .stat-ico { background: var(--blue-bg); color: var(--blue); }
.stat-amber .stat-ico { background: var(--amber-bg); color: var(--amber); }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: var(--sp-2) var(--sp-6); margin: 0; }
dl.kv dt { color: var(--muted); font-size: var(--fs-sm); }
dl.kv dd { margin: 0; font-weight: 500; }
@media (max-width: 480px) { dl.kv { grid-template-columns: 1fr; gap: 0; } dl.kv dd { margin-bottom: var(--sp-3); } }

/* ---------- badges / alerts ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 10px; border-radius: 999px; font-size: var(--fs-xs); font-weight: 600; white-space: nowrap; border: 1px solid transparent; line-height: 1.6; vertical-align: middle; }
h1 .badge { font-size: var(--fs-sm); padding: 3px 12px; }
.badge-green { background: var(--green-bg); color: var(--green-text); border-color: var(--green-line); }
.badge-blue { background: var(--blue-bg); color: var(--blue-text); border-color: var(--blue-line); }
.badge-amber { background: var(--amber-bg); color: var(--amber-text); border-color: var(--amber-line); }
.badge-red { background: var(--red-bg); color: var(--red-text); border-color: var(--red-line); }
.badge-gray { background: var(--gray-bg); color: var(--gray-text); border-color: var(--gray-line); }
.alert { display: block; padding: var(--sp-3) var(--sp-4); border-radius: var(--r-sm); border: 1px solid; border-left-width: 4px; margin-bottom: var(--sp-4); font-size: var(--fs-sm); }
.alert-green { background: var(--green-bg); color: var(--green-text); border-color: var(--green-line); border-left-color: var(--green); }
.alert-blue { background: var(--blue-bg); color: var(--blue-text); border-color: var(--blue-line); border-left-color: var(--blue); }
.alert-amber { background: var(--amber-bg); color: var(--amber-text); border-color: var(--amber-line); border-left-color: var(--amber); }
.alert-red { background: var(--red-bg); color: var(--red-text); border-color: var(--red-line); border-left-color: var(--red); }
.empty { text-align: center; padding: var(--sp-8) var(--sp-5); border: 1px dashed var(--border-strong); border-radius: var(--r); background: var(--surface); }
.empty p { color: var(--muted); margin-bottom: var(--sp-4); }
.loading { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-8) 0; color: var(--muted); }
.spinner { width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; display: inline-block; animation: spin 0.75s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.5s; } .sidebar { transition: none; } }

/* ---------- forms ---------- */
.field { margin-bottom: var(--sp-5); }
.field label { display: block; font-weight: 600; font-size: var(--fs-sm); color: var(--text-2); margin-bottom: 6px; }
.req { color: var(--red); margin-left: 2px; }
input, select, textarea { width: 100%; min-height: var(--tap); padding: 10px var(--sp-3); font: inherit; font-size: var(--fs-base); color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-sm); transition: border-color 0.12s, box-shadow 0.12s; }
input:hover, select:hover, textarea:hover { border-color: var(--muted); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
input[readonly] { background: var(--surface-2); color: var(--text-2); }
textarea { min-height: 96px; resize: vertical; }
input[type="checkbox"], input[type="radio"] { width: 18px; height: 18px; min-height: 0; padding: 0; accent-color: var(--primary); box-shadow: none; }
input[type="file"] { padding: 8px; background: var(--surface-2); border-style: dashed; cursor: pointer; }
input[type="file"]::file-selector-button { font: inherit; font-weight: 600; font-size: var(--fs-sm); border: 1px solid var(--border-strong); background: var(--surface); border-radius: var(--r-sm); padding: 6px 12px; margin-right: 12px; cursor: pointer; color: var(--text); }
::placeholder { color: var(--muted); opacity: 0.8; }
[aria-invalid="true"] { border-color: var(--red) !important; box-shadow: 0 0 0 3px var(--red-bg) !important; }
.help { color: var(--muted); font-size: var(--fs-sm); margin: 6px 0 0; }
.field-error { color: var(--red); font-size: var(--fs-sm); font-weight: 600; margin: 6px 0 0; }
.form-error { margin-bottom: var(--sp-4); }
.form-row { display: grid; gap: 0 var(--sp-5); grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.check { display: inline-flex; align-items: center; gap: var(--sp-2); min-height: 40px; margin-right: var(--sp-4); }
.check label { font-weight: 500; margin: 0; font-size: var(--fs-base); color: var(--text); }
.filters { display: grid; gap: var(--sp-4); grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); align-items: end; }
.filters .field { margin: 0; }
form.filters:not(.card) { margin-bottom: var(--sp-5); max-width: 320px; }
.switch { display: inline-flex; align-items: center; gap: var(--sp-3); min-height: var(--tap); cursor: pointer; }
.switch input { appearance: none; -webkit-appearance: none; width: 44px; height: 24px; border-radius: 999px; background: var(--gray-line); border: 0; position: relative; cursor: pointer; margin: 0; padding: 0; min-height: 0; transition: background-color 0.15s; }
.switch input::after { content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: left 0.15s; box-shadow: 0 1px 2px rgba(0,0,0,.25); }
.switch input:checked { background: var(--green); }
.switch input:checked::after { left: 23px; }
.switch input:focus { box-shadow: 0 0 0 3px var(--primary-soft); }
.switch .state { font-weight: 700; font-size: var(--fs-sm); min-width: 3ch; }

/* ---------- tables ---------- */
.table-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); overflow: hidden; margin-bottom: var(--sp-5); box-shadow: var(--shadow); }
.table { width: 100%; border-collapse: collapse; background: var(--surface); font-size: var(--fs-sm); }
.table th, .table td { padding: 12px var(--sp-4); border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.table th { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 600; background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--surface-2); }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table tfoot td { font-weight: 700; background: var(--surface-2); border-top: 1px solid var(--border-strong); border-bottom: 0; }
.table td a { font-weight: 600; text-decoration: none; }
.table td a:hover { text-decoration: underline; }
.table .actions-cell { text-align: right; white-space: nowrap; }
.table .actions-cell .btn { margin-left: 4px; }
@media (max-width: 720px) {
  .table.stack thead { position: absolute; left: -9999px; }
  .table.stack tr { display: block; border-bottom: 1px solid var(--border); padding: var(--sp-3) 0; }
  .table.stack tbody tr:last-child { border-bottom: 0; }
  .table.stack tbody tr:hover td { background: transparent; }
  .table.stack td { display: flex; justify-content: space-between; align-items: baseline; gap: var(--sp-3); border: 0; padding: 4px var(--sp-4); text-align: right; }
  .table.stack td::before { content: attr(data-label); color: var(--muted); font-size: var(--fs-xs); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; text-align: left; flex: 0 0 auto; max-width: 50%; }
  .table.stack td.actions-cell { justify-content: flex-end; flex-wrap: wrap; gap: var(--sp-2); padding-top: var(--sp-2); white-space: normal; }
  .table.stack td.actions-cell::before { content: none; }
  .table.stack tfoot tr { display: flex; flex-wrap: wrap; justify-content: space-between; padding: var(--sp-2) 0; }
  .table.stack tfoot td { display: block; border: 0; }
  .table.stack tfoot td:empty { display: none; }
}
.calc-table { font-size: var(--fs-base); }
.calc-table td { padding: 10px var(--sp-3); }
.calc-table td:first-child { width: 2.5em; color: var(--muted); font-weight: 700; text-align: center; }
.calc-table tbody tr:hover td { background: transparent; }
.calc-table tr.result td, .calc-table tr.result:hover td { background: var(--surface-3); font-weight: 700; border-top: 1px solid var(--border-strong); }
.calc { font-variant-numeric: tabular-nums; margin: var(--sp-3) 0 0; color: var(--text-2); }
.calc .op { color: var(--muted); font-weight: 700; padding: 0 2px; }

/* ---------- stepper ---------- */
.stepper { position: relative; margin: var(--sp-5) 0 var(--sp-4); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); padding: 20px 0 var(--sp-4); box-shadow: var(--shadow); }
.stepper ol { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(6, 1fr); position: relative; z-index: 1; }
.stepper-track { position: absolute; top: 40px; left: calc(100% / 12); right: calc(100% / 12); height: 4px; background: var(--gray-line); border-radius: 2px; }
.stepper-fill { height: 100%; background: var(--green); border-radius: 2px; }
.step { display: flex; flex-direction: column; align-items: center; text-align: center; min-width: 0; padding: 0 2px; }
.step-dot { width: var(--tap); height: var(--tap); padding: 0; border: 0; background: transparent; cursor: pointer; display: grid; place-items: center; border-radius: 50%; }
.dot { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: var(--fs-sm); background: var(--surface); border: 2px solid var(--gray-line); color: var(--muted); transition: transform 0.12s; }
.step-dot:hover .dot { transform: scale(1.06); }
.step-name { font-size: var(--fs-xs); font-weight: 600; margin-top: 6px; line-height: 1.25; overflow-wrap: break-word; hyphens: auto; color: var(--text); }
.step-state { font-size: var(--fs-xs); color: var(--muted); line-height: 1.3; margin-top: 2px; }
.step-date { display: inline-block; color: var(--muted); font-weight: 400; }
.step-done .dot { background: var(--green); border-color: var(--green); color: var(--surface); font-size: var(--fs-md); }
.step-done .step-state { color: var(--green); font-weight: 600; }
.step-current .dot { background: var(--surface); border: 3px solid var(--blue); color: var(--blue); box-shadow: 0 0 0 4px var(--blue-bg); }
.step-current .step-state { color: var(--blue); font-weight: 700; }
.step-rejected .dot { background: var(--red); border-color: var(--red); color: var(--surface); box-shadow: 0 0 0 4px var(--red-bg); }
.step-rejected .step-state, .step-rejected .step-name { color: var(--red); font-weight: 700; }
.step-stopped .dot { border-style: dashed; color: var(--gray); }
.step-dot[aria-expanded="true"] .dot { outline: 3px solid var(--focus); outline-offset: 2px; }
.step-detail { border-left: 4px solid var(--blue); }
.step-detail h3 { margin-top: 0; }
.step-detail:focus { outline: none; }
@media (min-width: 640px) { .step-name, .step-state { font-size: var(--fs-sm); } .step-date { white-space: nowrap; } .stepper { padding: 24px 0 20px; } .stepper-track { top: 44px; } }
@media (max-width: 400px) { .step-name, .step-state { font-size: 0.6875rem; letter-spacing: -0.01em; } }

/* ---------- dialogs / toasts ---------- */
.dialog { border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--sp-6); max-width: min(480px, calc(100vw - 32px)); width: 100%; background: var(--surface); color: var(--text); box-shadow: 0 12px 32px rgba(15, 23, 42, 0.18); }
.dialog::backdrop { background: rgba(5, 12, 24, 0.55); }
.dialog h2 { margin-top: 0; font-size: var(--fs-lg); }
.dialog p { color: var(--text-2); }
.toasts { position: fixed; bottom: var(--sp-5); right: var(--sp-5); width: min(420px, calc(100vw - 32px)); z-index: 60; display: grid; gap: var(--sp-2); }
.toast { margin: 0; box-shadow: 0 6px 18px rgba(15, 23, 42, 0.14); font-weight: 500; }
@media (max-width: 560px) { .toasts { left: 16px; right: 16px; width: auto; bottom: 16px; } }

/* ---------- login ---------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1fr; }
.auth-panel { display: none; background: var(--navy); color: var(--navy-text); padding: 48px; flex-direction: column; justify-content: space-between; }
.auth-panel h2 { color: #fff; font-size: 2rem; letter-spacing: -0.02em; line-height: 1.2; margin: 0 0 var(--sp-4); max-width: 18ch; }
.auth-panel p { max-width: 44ch; }
.auth-points { list-style: none; padding: 0; margin: var(--sp-8) 0 0; display: grid; gap: var(--sp-5); }
.auth-points li { display: flex; gap: var(--sp-3); align-items: flex-start; }
.auth-points .icon { color: #6d9bff; margin-top: 3px; }
.auth-points strong { color: #fff; display: block; }
.auth-foot { color: var(--navy-muted); font-size: var(--fs-sm); }
.auth-form { background: var(--surface); display: flex; align-items: center; justify-content: center; padding: var(--sp-8) var(--sp-4); }
.auth-box { width: 100%; max-width: 400px; }
.auth-box .brand { color: var(--text); margin-bottom: var(--sp-8); }
.auth-box .brand:hover { color: var(--text); }
.auth-box .brand-text small { color: var(--muted); }
.auth-box h1 { font-size: 1.625rem; }
.auth-box .btn-primary { width: 100%; min-height: var(--tap); font-size: var(--fs-base); }
.auth-lang { display: flex; justify-content: center; margin-top: var(--sp-6); }
@media (min-width: 960px) { .auth { grid-template-columns: 1.05fr 1fr; } .auth-panel { display: flex; } }

/* ---------- settings ---------- */
details.group { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); margin-bottom: var(--sp-3); box-shadow: var(--shadow); overflow: hidden; }
details.group > summary { cursor: pointer; padding: var(--sp-4) var(--sp-5); font-weight: 650; font-size: var(--fs-md); min-height: var(--tap); list-style: none; display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); }
details.group > summary::-webkit-details-marker { display: none; }
details.group > summary::after { content: ''; width: 9px; height: 9px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); transition: transform 0.15s; margin-right: 4px; flex: 0 0 auto; }
details.group[open] > summary::after { transform: rotate(-135deg); }
details.group[open] > summary { border-bottom: 1px solid var(--border); background: var(--surface-2); }
details.group > summary:hover { background: var(--surface-2); }
details.group > .group-body { padding: 0 var(--sp-5); }
.setting { padding: var(--sp-5) 0; border-bottom: 1px solid var(--border); }
.setting:last-child { border-bottom: 0; }
.setting-label { font-weight: 600; display: block; color: var(--text); }
.setting .help { margin: 2px 0 var(--sp-3); }
.setting-save { display: flex; gap: var(--sp-2); align-items: center; flex-wrap: wrap; max-width: 560px; }
.setting-save > :first-child { flex: 1 1 220px; }
.setting .actions { margin-top: var(--sp-3); }

@media print {
  .sidebar, .topbar, .scrim, .actions, .no-print, .filters, .toasts, .skip-link, button { display: none !important; }
  .app-shell:not(.is-public) .app-main { margin: 0 !important; }
  body { background: #fff; color: #000; }
  .card, .table-card, .stat, .stepper { border-color: #bbb; box-shadow: none; break-inside: avoid; }
  .container { max-width: none; padding: 0; }
}
