/* Design system (UI UX Pro Max: "Banking/Traditional Finance" palette + Minimalism/Swiss + Data-Dense Dashboard,
   typography "Financial Trust" = IBM Plex Sans, density 8-32px). Semantic tokens only; no raw hex in components. */
:root {
  --primary: #0f172a; --on-primary: #fff;
  --secondary: #1e3a8a; --on-secondary: #fff;
  --accent: #a16207; --on-accent: #fff;
  --bg: #f8fafc; --fg: #020617;
  --card: #fff; --muted: #e8ecf1; --muted-fg: #475569; --border: #e2e8f0;
  --destructive: #dc2626; --on-destructive: #fff;
  --success: #15803d; --warning: #b45309; --info: #1d4ed8;
  --success-bg: #ecfdf3; --warning-bg: #fffbeb; --danger-bg: #fef2f2; --info-bg: #eff6ff;
  --ring: #1e3a8a;
  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px; --space-5: 24px; --space-6: 32px;
  --radius: 8px; --radius-sm: 6px;
  --shadow: 0 1px 2px rgb(15 23 42 / .06), 0 1px 3px rgb(15 23 42 / .08);
  --font: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, Menlo, Consolas, monospace;
  --sidebar-w: 248px;
}
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 14px/1.5 var(--font); color: var(--fg); background: var(--bg); }
h1, h2, h3 { margin: 0; line-height: 1.25; letter-spacing: -0.01em; }
h1 { font-size: 20px; font-weight: 600; } h2 { font-size: 16px; font-weight: 600; } h3 { font-size: 14px; font-weight: 600; }
a { color: var(--secondary); }
.num, td.money, .kpi .value { font-variant-numeric: tabular-nums; }
:focus-visible { outline: 2px solid var(--ring); 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: -999px; top: 8px; background: var(--card); padding: 8px 12px; z-index: 100; }
.skip-link:focus { left: 8px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* Layout */
.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }
.sidebar { background: var(--primary); color: #cbd5e1; padding: var(--space-4) var(--space-3); position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: var(--space-2); color: #fff; padding: var(--space-2) var(--space-2) var(--space-4); }
.brand .logo { width: 32px; height: 32px; border-radius: 8px; background: var(--accent); display: grid; place-items: center; font-weight: 700; color: #fff; font-size: 13px; }
.brand b { display: block; font-size: 14px; } .brand small { color: #94a3b8; font-size: 12px; }
.nav-group { margin-top: var(--space-3); }
.nav-group > span { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #94a3b8; padding: var(--space-2); }
.nav a { display: flex; align-items: center; gap: var(--space-2); min-height: 36px; padding: 6px var(--space-2); border-radius: var(--radius-sm); color: #e2e8f0; text-decoration: none; font-size: 13.5px; }
.nav a:hover { background: rgb(255 255 255 / .07); }
.nav a[aria-current='page'] { background: var(--secondary); color: #fff; }
.nav a .badge { margin-left: auto; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-5); border-bottom: 1px solid var(--border); background: var(--card); position: sticky; top: 0; z-index: 5; }
.topbar .spacer { flex: 1; }
.menu-btn { display: none; }
.content { padding: var(--space-5); display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-4); max-width: 1600px; width: 100%; }
.content > *, .grid > * { min-width: 0; }
.page-head { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: flex-end; justify-content: space-between; }
.page-head > div:first-child { flex: 1 1 420px; }
.page-head p { margin: 4px 0 0; color: var(--muted-fg); max-width: 900px; }
.actions { display: flex; gap: var(--space-2); flex-wrap: wrap; }

/* Cards & KPIs */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card > header { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--border); }
.card .body { padding: var(--space-4); }
.grid { display: grid; gap: var(--space-4); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: var(--space-3); }
.kpi { padding: var(--space-4); }
.kpi .label { color: var(--muted-fg); font-size: 12.5px; }
.kpi .value { font-size: 22px; font-weight: 600; margin-top: 2px; }
.kpi .sub { font-size: 12px; color: var(--muted-fg); margin-top: 2px; }
.two-col { display: grid; grid-template-columns: 1.4fr 1fr; gap: var(--space-4); }

/* Buttons & inputs */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 36px; padding: 0 14px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--card); color: var(--fg); font: inherit; font-weight: 500; cursor: pointer; transition: background-color .15s, border-color .15s; white-space: nowrap; }
.btn:hover { background: var(--muted); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--secondary); border-color: var(--secondary); color: var(--on-secondary); }
.btn.primary:hover { background: #1e40af; }
.btn.danger { color: var(--destructive); border-color: #fecaca; }
.btn.danger:hover { background: var(--danger-bg); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { min-height: 30px; padding: 0 10px; font-size: 13px; }
.btn svg, .nav svg { width: 16px; height: 16px; flex: none; }
label.field { display: grid; gap: 4px; font-size: 12.5px; color: var(--muted-fg); font-weight: 500; }
label.field.req > span:first-child::after { content: ' *'; color: var(--destructive); }
input, select, textarea { font: inherit; color: var(--fg); background: var(--card); border: 1px solid #cbd5e1; border-radius: var(--radius-sm); min-height: 36px; padding: 6px 10px; width: 100%; }
textarea { min-height: 72px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--ring); outline-offset: 0; border-color: var(--ring); }
input[aria-invalid='true'] { border-color: var(--destructive); }
.help { font-size: 12px; color: var(--muted-fg); font-weight: 400; }
.field-error { display: flex; align-items: center; gap: 4px; color: var(--destructive); font-weight: 500; }
.field-error svg { width: 12px; height: 12px; flex: none; }
.viewer { display: block; width: 100%; height: min(75vh, 1000px); border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--muted); overflow: auto; }
.viewer img { display: block; max-width: 100%; height: auto; margin: 0 auto; }
a.btn { text-decoration: none; }
.file-picker { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.toolbar { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--border); }
.toolbar input[type='search'] { max-width: 280px; }
.toolbar select { width: auto; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted-fg); cursor: pointer; min-height: 36px; }
.check input { width: 16px; height: 16px; min-height: 0; }

/* Tables */
.table-wrap { overflow: auto; max-height: calc(100vh - 260px); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 7px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { position: sticky; top: 0; background: #f1f5f9; font-weight: 600; color: #334155; font-size: 12px; z-index: 1; white-space: nowrap; }
th button { all: unset; cursor: pointer; display: inline-flex; gap: 4px; align-items: center; }
td.money, th.money { text-align: right; white-space: nowrap; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: #f8fafc; }
tbody tr.deleted { opacity: .55; text-decoration: line-through; }
tfoot td { font-weight: 600; background: #f8fafc; position: sticky; bottom: 0; }
td.trunc { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.report td, .report th { cursor: default; }
.report tbody tr { cursor: default; }
.report tr.total td { font-weight: 600; background: #f8fafc; }
.empty { padding: var(--space-6); text-align: center; color: var(--muted-fg); }

/* Badges / alerts */
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--muted); color: #334155; white-space: nowrap; }
.badge.error { background: var(--danger-bg); color: var(--destructive); }
.badge.warn { background: var(--warning-bg); color: var(--warning); }
.badge.info { background: var(--info-bg); color: var(--info); }
.badge.ok { background: var(--success-bg); color: var(--success); }
.badge svg { width: 12px; height: 12px; }
.alert { display: flex; gap: var(--space-2); padding: var(--space-3); border-radius: var(--radius-sm); font-size: 13px; border: 1px solid; }
.alert svg { width: 16px; height: 16px; flex: none; margin-top: 2px; }
.alert.error { background: var(--danger-bg); border-color: #fecaca; color: #991b1b; }
.alert.warn { background: var(--warning-bg); border-color: #fde68a; color: #92400e; }
.alert.info { background: var(--info-bg); border-color: #bfdbfe; color: #1e3a8a; }
.alert.ok { background: var(--success-bg); border-color: #bbf7d0; color: #166534; }
.list { display: grid; gap: var(--space-2); margin: 0; padding: 0; list-style: none; }

/* Modal */
dialog { border: none; border-radius: 12px; padding: 0; width: min(980px, 96vw); max-height: 92vh; box-shadow: 0 20px 50px rgb(2 6 23 / .3); color: var(--fg); }
dialog::backdrop { background: rgb(2 6 23 / .45); }
dialog > form, dialog > .dlg { display: flex; flex-direction: column; max-height: 92vh; }
.dlg-head { display: flex; align-items: center; justify-content: space-between; padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--border); }
.dlg-body { padding: var(--space-4) var(--space-5); overflow: auto; display: grid; gap: var(--space-4); }
.dlg-foot { display: flex; gap: var(--space-2); justify-content: flex-end; padding: var(--space-3) var(--space-5); border-top: 1px solid var(--border); background: #f8fafc; }
.dlg-foot .left { margin-right: auto; display: flex; gap: var(--space-2); }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-3) var(--space-4) var(--space-4); margin: 0; }
legend { font-weight: 600; font-size: 13px; padding: 0 6px; color: var(--secondary); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: var(--space-3); }
.form-grid .wide { grid-column: 1 / -1; }
/* Align label / input / help rows across each form row (labels and helps vary in length). */
.form-grid > label.field { grid-row: span 3; grid-template-rows: subgrid; row-gap: 4px; align-content: start; }
.form-grid > label.field > span:first-child { align-self: end; }
.form-grid > label.field > .help { align-self: start; }
details summary { cursor: pointer; font-weight: 600; font-size: 13px; padding: var(--space-2) 0; }

/* Toast */
.toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 1000; pointer-events: none; }
/* Inside a modal the bottom-right corner holds the Save button: show toasts top-centre instead. */
dialog .toasts { top: 16px; bottom: auto; right: 50%; transform: translateX(50%); justify-items: center; }
.toast { background: var(--primary); color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); max-width: 420px; font-size: 13px; }
.toast.error { background: var(--destructive); }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: var(--space-4); background: linear-gradient(160deg, #0f172a 0%, #1e3a8a 100%); }
.login .card { width: min(400px, 100%); padding: var(--space-6); display: grid; gap: var(--space-4); }
.login .brand { color: var(--fg); padding: 0; } .login .brand small { color: var(--muted-fg); }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); padding: 0 var(--space-4); overflow-x: auto; }
.tabs button { all: unset; cursor: pointer; padding: 10px 12px; font-size: 13px; font-weight: 500; color: var(--muted-fg); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button[aria-selected='true'] { color: var(--secondary); border-color: var(--secondary); }
.tabs button:focus-visible { outline: 2px solid var(--ring); }

@media (max-width: 1100px) { .two-col { grid-template-columns: 1fr; } }
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; z-index: 50; width: var(--sidebar-w); transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; }
  .menu-btn { display: inline-flex; }
  .content { padding: var(--space-3); }
}
@media print { .sidebar, .topbar, .toolbar, .actions, .btn { display: none !important; } .app { display: block; } .table-wrap { max-height: none; overflow: visible; } }
