:root {
    --bg: #f6f7f5;
    --panel: #ffffff;
    --ink: #1c2321;
    --muted: #66706d;
    --line: #e2e6e3;
    --accent: #0f5257;
    --accent-ink: #ffffff;
    --accent-soft: #e3eff0;
    --ok: #1d7a46;
    --ok-soft: #e3f4ea;
    --warn: #9a6200;
    --warn-soft: #fbf0d9;
    --bad: #b42318;
    --bad-soft: #fde8e6;
    --radius: 8px;
    --shadow: 0 1px 2px rgba(16, 24, 22, .06), 0 1px 1px rgba(16, 24, 22, .03);
    --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 14px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; display: flex; align-items: center; gap: 10px; }
h2 { font-size: 15px; margin: 0 0 12px; }
h2.section { margin: 28px 0 10px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
code { font-family: var(--mono); font-size: 12.5px; background: var(--accent-soft); padding: 1px 5px; border-radius: 4px; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.strong { font-weight: 600; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.neg { color: var(--bad); }
.warn-text { color: var(--warn); font-weight: 500; }
.bad { color: var(--bad); }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar { background: #10201f; color: #c9d6d3; display: flex; flex-direction: column; padding: 18px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 650; font-size: 16px; padding: 4px 8px 18px; }
.brand:hover { text-decoration: none; }
.brand img { width: 28px; height: 28px; }
.sidebar nav { display: flex; flex-direction: column; gap: 1px; flex: 1; }
.sidebar nav a { color: #c9d6d3; padding: 7px 10px; border-radius: 6px; font-size: 13.5px; }
.sidebar nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; color: #fff; }
.sidebar nav a.active { background: rgba(126, 203, 196, .16); color: #fff; font-weight: 550; }
.nav-group { font-size: 10.5px; text-transform: uppercase; letter-spacing: .09em; color: #7f9692; padding: 16px 10px 5px; }
.whoami { display: flex; justify-content: space-between; align-items: center; border-top: 1px solid rgba(255,255,255,.08); padding: 12px 8px 0; font-size: 13px; }
.whoami .link { background: none; border: 0; color: #9fc5c0; cursor: pointer; font: inherit; padding: 0; }
.content { padding: 26px 32px 80px; max-width: 1280px; width: 100%; }

.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.back { font-size: 12.5px; display: inline-block; margin-bottom: 4px; }

/* ---------- controls ---------- */
input, select, textarea { font: inherit; color: inherit; background: #fff; border: 1px solid #cfd6d3; border-radius: 6px; padding: 7px 9px; width: 100%; min-width: 0; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(15, 82, 87, .25); border-color: var(--accent); }
input[type=checkbox], input[type=radio] { width: auto; accent-color: var(--accent); }
input[type=file] { border-style: dashed; padding: 10px; background: #fafbfa; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; font-weight: 550; color: #3c4643; }
label.check { flex-direction: row; align-items: center; gap: 7px; font-weight: 500; white-space: nowrap; }
.inline { padding: 4px 6px; border-color: transparent; background: transparent; }
.inline:hover, .inline:focus { border-color: #cfd6d3; background: #fff; }
.empty-sel { color: var(--warn); font-weight: 500; }
.search { max-width: 260px; }

.btn { display: inline-flex; align-items: center; gap: 6px; font: inherit; font-weight: 550; font-size: 13.5px; padding: 7px 14px; border-radius: 6px; border: 1px solid #cfd6d3; background: #fff; color: var(--ink); cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f1f4f2; text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #0b4246; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: #eef1ef; }
.btn.danger { color: var(--bad); }
.btn.small { padding: 4px 9px; font-size: 12.5px; }
.btn.wide { width: 100%; justify-content: center; padding: 10px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.icon-btn { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 14px; padding: 4px 6px; border-radius: 5px; }
.icon-btn:hover { background: #eef1ef; color: var(--ink); }

.row { display: flex; }
.row.gap { gap: 10px; }
.row.center { align-items: center; }
.row.wrap { flex-wrap: wrap; }

.grid-2, .grid-3, .grid-4 { display: grid; gap: 12px 16px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.span-2 { grid-column: span 2; }
.span-3 { grid-column: span 3; }
.align-end { align-items: end; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 16px; }
.card > p:first-child { margin-top: 0; }
.card.help summary { cursor: pointer; font-weight: 550; }
.filters { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.filters select, .filters input[type=date] { width: auto; }

.alert { padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; border: 1px solid; }
.alert.error { background: var(--bad-soft); border-color: #f5c2bc; color: #7a1a12; }
.alert.success { background: var(--ok-soft); border-color: #b9e2c9; color: #14532d; }
.alert.info { background: var(--accent-soft); border-color: #c4dcde; color: #0d3c40; }
.alert ul { margin: 6px 0 0; padding-left: 20px; }
.field-warn { color: var(--warn); font-size: 12.5px; margin: 8px 0 0; }

.segmented { display: inline-flex; border: 1px solid #cfd6d3; border-radius: 7px; overflow: hidden; margin-bottom: 14px; }
.segmented button { border: 0; background: #fff; padding: 7px 14px; font: inherit; font-weight: 550; cursor: pointer; color: var(--muted); }
.segmented button.on { background: var(--accent); color: #fff; }

/* ---------- tables ---------- */
.table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.table th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; padding: 9px 12px; background: #fafbfa; border-bottom: 1px solid var(--line); }
.table td { padding: 9px 12px; border-bottom: 1px solid #edf0ee; vertical-align: top; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tfoot td { border-top: 1px solid var(--line); background: #fafbfa; font-weight: 500; }
.table th.right, .table td.right { text-align: right; }
.table.compact td { padding: 7px 10px; }
.table .clickable { cursor: pointer; }
.table .clickable:hover td { background: #f6f9f8; }
.table tr.selected td { background: var(--accent-soft); }
.table tr.dim td { opacity: .5; }
.table tr.group td { background: #f3f6f5; font-weight: 650; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.table tr.net td { font-weight: 700; }
.table-scroll { overflow-x: auto; }
.table.pivot td, .table.pivot th { white-space: nowrap; }
.table.bank td.narr { max-width: 420px; word-break: break-word; font-size: 13px; }
.table.bank td.credit { color: var(--ok); }
.table.bank tr.untagged td:first-child { box-shadow: inset 3px 0 0 #e8b44a; }
.table.lines td { padding: 6px 6px; vertical-align: middle; }
.table.lines textarea { min-height: 38px; }
.w-sac { width: 86px; } .w-qty { width: 72px; } .w-unit { width: 64px; } .w-rate { width: 110px; } .w-gst { width: 70px; }
.note { min-width: 140px; }

.pill { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 2px 9px; border-radius: 999px; font-family: var(--font); letter-spacing: 0; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.neutral { background: #eef1ef; color: #47524f; }
.pill.muted { background: #eef1ef; color: #8a9491; text-decoration: line-through; }
.tag { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 4px; background: var(--accent-soft); color: var(--accent); margin-left: 6px; }
.tag.link { margin: 0 4px 2px 0; font-family: var(--mono); }

.empty { text-align: center; padding: 48px 20px; background: var(--panel); border: 1px dashed #cfd6d3; border-radius: var(--radius); }
.empty p { color: var(--muted); margin-top: 0; }

.summary-bar { display: flex; gap: 22px; flex-wrap: wrap; padding: 8px 2px 12px; font-size: 13px; color: var(--muted); }
.summary-bar strong { color: var(--ink); }

/* ---------- invoice editor ---------- */
.taxline { margin-top: 14px; padding: 9px 12px; background: var(--accent-soft); border-radius: 6px; font-size: 13px; }
.totals { margin: 16px 0 0 auto; width: 320px; display: flex; flex-direction: column; gap: 6px; }
.totals > div { display: flex; justify-content: space-between; }
.totals .grand { border-top: 1px solid var(--ink); padding-top: 8px; font-size: 17px; font-weight: 700; }
.service-pick { width: auto; }
.sticky-actions { position: sticky; bottom: 0; background: linear-gradient(transparent, var(--bg) 30%); padding: 18px 0 8px; display: flex; justify-content: flex-end; gap: 10px; }

/* ---------- invoice view ---------- */
.split { display: grid; grid-template-columns: 1fr 330px; gap: 18px; align-items: start; }
.pdf-frame { background: #525659; border-radius: var(--radius); overflow: hidden; height: calc(100vh - 170px); min-height: 560px; }
.pdf-frame iframe { width: 100%; height: 100%; border: 0; }
.side .card { padding: 16px; }
.payment { display: flex; justify-content: space-between; gap: 8px; padding: 8px 0; border-bottom: 1px solid #edf0ee; }
.kv { display: flex; justify-content: space-between; gap: 10px; padding: 5px 0; font-size: 13px; }
.kv > span:first-child { color: var(--muted); }

/* ---------- dashboard ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 16px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; display: flex; flex-direction: column; gap: 4px; box-shadow: var(--shadow); }
.kpi .label { font-size: 12px; color: var(--muted); font-weight: 550; }
.kpi .value { font-size: 23px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.kpi .value.sm { font-size: 17px; }
.kpi .hint { font-size: 12px; color: var(--muted); }
.two-col { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; }
.bars { display: flex; align-items: flex-end; gap: 8px; height: 190px; padding-top: 6px; }
.bar-group { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; }
.bar-group span { font-size: 11px; color: var(--muted); }
.bar-pair { flex: 1; display: flex; align-items: flex-end; gap: 3px; width: 100%; justify-content: center; }
.bar { width: 42%; max-width: 18px; border-radius: 3px 3px 0 0; min-height: 1px; }
.bar.inc, .sw.inc { background: #2a9d8f; }
.bar.exp, .sw.exp { background: #e09f3e; }
.legend { font-size: 12px; color: var(--muted); margin-top: 10px; display: flex; align-items: center; gap: 6px; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-left: 8px; }
.hbar { margin-bottom: 10px; }
.hbar-label { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 3px; }
.hbar-track { background: #eef1ef; border-radius: 3px; height: 7px; }
.hbar-fill { background: #e09f3e; height: 100%; border-radius: 3px; }

/* ---------- import ---------- */
.steps { padding-left: 20px; margin: 0 0 14px; }
.steps li { margin-bottom: 4px; }
.dropzone { max-width: 520px; }
.stats { display: flex; gap: 34px; margin-bottom: 10px; }
.stats div { display: flex; flex-direction: column; }
.stats .big { font-size: 28px; font-weight: 700; }
.stats span:last-child { color: var(--muted); font-size: 12.5px; }
.checklist { padding-left: 20px; }
.checklist li { margin-bottom: 4px; }
.logo-preview { max-height: 56px; max-width: 220px; border: 1px solid var(--line); border-radius: 6px; padding: 6px; background: #fff; }

/* ---------- modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(16, 24, 22, .4); z-index: 40; }
.modal { position: fixed; z-index: 41; top: 6vh; left: 50%; transform: translateX(-50%); width: calc(100% - 32px); max-width: 560px; max-height: 88vh; display: flex; flex-direction: column; background: #fff; border-radius: 10px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal header { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px 10px; }
.modal header h2 { margin: 0; font-size: 16px; }
.modal-body { padding: 4px 20px 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.modal footer { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- auth ---------- */
.blank { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(circle at 30% 20%, #e3efee, var(--bg) 60%); }
.auth-card { width: 100%; max-width: 380px; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 30px 28px; box-shadow: 0 10px 30px rgba(16, 24, 22, .08); }
.auth-card h1 { margin: 10px 0 2px; }
.auth-card form { display: flex; flex-direction: column; gap: 14px; margin-top: 18px; }
.auth-logo { width: 40px; height: 40px; }

#blazor-error-ui { display: none; position: fixed; bottom: 0; left: 0; right: 0; padding: 10px 20px; background: #fff4e5; border-top: 1px solid #f0c27b; z-index: 100; }
#blazor-error-ui .reload { margin-left: 10px; }

@media (max-width: 1000px) {
    .shell { grid-template-columns: 1fr; }
    .sidebar { position: static; height: auto; }
    .sidebar nav { flex-direction: row; flex-wrap: wrap; }
    .nav-group { display: none; }
    .content { padding: 18px 16px 60px; }
    .kpis { grid-template-columns: repeat(2, 1fr); }
    .two-col, .split { grid-template-columns: 1fr; }
    .grid-3, .grid-4 { grid-template-columns: repeat(2, 1fr); }
    .pdf-frame { height: 70vh; }
}
@media (max-width: 600px) {
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
    .span-2, .span-3 { grid-column: auto; }
    .kpis { grid-template-columns: 1fr; }
}

/* ---------- 2FA ---------- */
.auth-card.wide { max-width: 480px; }
.otp { font-family: var(--mono); font-size: 22px; letter-spacing: .3em; text-align: center; padding: 10px; }
.enroll-steps { padding-left: 18px; margin: 18px 0 0; display: flex; flex-direction: column; gap: 18px; }
.enroll-steps form { margin-top: 8px; gap: 10px; }
.qr-wrap { display: flex; gap: 14px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.qr { width: 168px; height: 168px; image-rendering: pixelated; border: 1px solid var(--line); border-radius: 8px; }
.secret { display: inline-block; margin-top: 4px; font-size: 13px; color: var(--ink); word-break: break-all; }
.codes { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px 14px; margin-top: 8px; padding: 12px; background: #f6f8f7; border: 1px dashed #cfd6d3; border-radius: 8px; font-size: 14px; }
.tag.muted-tag { background: #eef1ef; color: #66706d; }
.modal h3.sub { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 6px 0 0; }
.export-acc { border: 1px solid var(--line); border-radius: 8px; padding: 12px; margin-bottom: 12px; display: flex; flex-direction: column; gap: 10px; }
.color-input { width: 46px; height: 36px; padding: 2px; cursor: pointer; }
.accent-preview { border: 1px solid; border-radius: 8px; padding: 10px; width: 280px; background: #fff; display: flex; flex-direction: column; gap: 6px; font-size: 12px; }
.accent-preview .ap-name { font-weight: 700; font-size: 15px; }
.accent-preview .ap-head { display: flex; justify-content: space-between; padding: 4px 6px; font-weight: 600; }
.accent-preview .ap-band { padding: 4px 6px; color: #66706d; }
