/* Private Invoice Manager - application styles (light + dark, follows the OS setting). */
:root {
  color-scheme: light;
  --navy: #0f2a4a;
  --navy-600: #163a63;
  --navy-500: #1f4e80;
  --brand: #0f2a4a;
  --brand-hover: #1a3d66;
  --brand-contrast: #ffffff;
  --focus: #2f6fdf;
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --surface-3: #eef2f7;
  --border: #e1e6ee;
  --border-strong: #c9d2de;
  --text: #182231;
  --text-2: #4a5567;
  --muted: #6b7587;
  --sidebar-bg: #0f2a4a;
  --sidebar-text: #c9d6e6;
  --sidebar-active: #ffffff;
  --sidebar-active-bg: rgba(255, 255, 255, 0.12);
  --sidebar-hover-bg: rgba(255, 255, 255, 0.07);
  --success: #0f7b52; --success-bg: #e6f5ee;
  --warning: #9a5b00; --warning-bg: #fff4dc;
  --danger: #b42318;  --danger-bg: #fdeceb;
  --info: #1d4fb8;    --info-bg: #e8f0fd;
  --neutral-bg: #eef1f5;
  --shadow: 0 1px 2px rgba(16, 32, 56, 0.06), 0 2px 8px rgba(16, 32, 56, 0.05);
  --shadow-lg: 0 10px 40px rgba(10, 25, 45, 0.22);
  --radius: 10px;
  --radius-sm: 6px;
  /* chart tokens (dataviz reference palette, validated) */
  --chart-surface: #ffffff;
  --chart-grid: #e7e7e7;
  --chart-axis: #c2c2c2;
  --chart-text: #666666;
  --series-1: #257de0;
  --series-2: #f47230;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --brand: #3d7bd6; --brand-hover: #4f8be0; --brand-contrast: #ffffff; --focus: #6fa3ff;
    --bg: #0e1218; --surface: #161b22; --surface-2: #1b212a; --surface-3: #222a35;
    --border: #2a323e; --border-strong: #3a4554;
    --text: #e6ebf2; --text-2: #b7c1cf; --muted: #8b97a8;
    --sidebar-bg: #0b1f38; --sidebar-text: #b9c7d9;
    --success: #4cc38a; --success-bg: #12301f; --warning: #f2b24c; --warning-bg: #33260d;
    --danger: #f2706a; --danger-bg: #3a1614; --info: #7fa8ff; --info-bg: #15233f; --neutral-bg: #232b36;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4); --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.6);
    --chart-surface: #161b22; --chart-grid: #2b313a; --chart-axis: #474f5a; --chart-text: #9c9c9c;
    --series-1: #338ced; --series-2: #e76624;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --brand: #3d7bd6; --brand-hover: #4f8be0; --brand-contrast: #ffffff; --focus: #6fa3ff;
  --bg: #0e1218; --surface: #161b22; --surface-2: #1b212a; --surface-3: #222a35;
  --border: #2a323e; --border-strong: #3a4554;
  --text: #e6ebf2; --text-2: #b7c1cf; --muted: #8b97a8;
  --sidebar-bg: #0b1f38; --sidebar-text: #b9c7d9;
  --success: #4cc38a; --success-bg: #12301f; --warning: #f2b24c; --warning-bg: #33260d;
  --danger: #f2706a; --danger-bg: #3a1614; --info: #7fa8ff; --info-bg: #15233f; --neutral-bg: #232b36;
  --chart-surface: #161b22; --chart-grid: #2b313a; --chart-axis: #474f5a; --chart-text: #9c9c9c;
  --series-1: #338ced; --series-2: #e76624;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: var(--font); font-size: 14px; line-height: 1.45; color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.noscript { padding: 24px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.right { text-align: right; }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, Menlo, monospace; font-size: 12.5px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.row.between { justify-content: space-between; }
.grow { flex: 1 1 auto; }
.icon { width: 18px; height: 18px; flex: 0 0 auto; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; vertical-align: middle; }

/* Boot & login */
.boot { min-height: 100vh; display: grid; place-items: center; }
.boot-card { color: var(--muted); }
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: linear-gradient(160deg, var(--navy) 0%, #183d68 55%, var(--bg) 55.1%); }
.login-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-lg); padding: 32px; }
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; }
.login-brand .mark { width: 40px; height: 40px; border-radius: 10px; background: var(--navy); color: #fff; display: grid; place-items: center; }
.login-brand h1 { font-size: 19px; }
.login-card form { display: flex; flex-direction: column; gap: 14px; }
.login-foot { margin-top: 18px; font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: flex-start; }

/* App shell */
.shell { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar { background: var(--sidebar-bg); color: var(--sidebar-text); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.sidebar-brand { display: flex; gap: 10px; align-items: center; padding: 20px 18px 16px; color: #fff; }
.sidebar-brand .mark { width: 34px; height: 34px; border-radius: 9px; background: rgba(255,255,255,0.12); display: grid; place-items: center; }
.sidebar-brand .name { font-weight: 700; font-size: 15px; }
.sidebar-brand .sub { font-size: 11.5px; color: var(--sidebar-text); max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav { display: flex; flex-direction: column; padding: 6px 10px 16px; gap: 2px; }
.nav-section { font-size: 10.5px; letter-spacing: 0.08em; text-transform: uppercase; color: rgba(201, 214, 230, 0.6); padding: 14px 10px 6px; }
.nav a, .nav button { display: flex; align-items: center; gap: 11px; padding: 8px 10px; border-radius: 7px; color: var(--sidebar-text); text-decoration: none; border: 0; background: none; cursor: pointer; width: 100%; text-align: left; font-size: 13.5px; }
.nav a:hover, .nav button:hover { background: var(--sidebar-hover-bg); color: #fff; text-decoration: none; }
.nav a.active { background: var(--sidebar-active-bg); color: var(--sidebar-active); font-weight: 600; }
.nav .badge { margin-left: auto; }
.sidebar-foot { margin-top: auto; padding: 14px 18px; font-size: 11.5px; border-top: 1px solid rgba(255,255,255,0.08); }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 16px; padding: 16px 28px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.topbar h1 { font-size: 19px; font-weight: 700; }
.topbar .crumb { color: var(--muted); font-size: 12.5px; }
.topbar-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.user-chip { display: flex; align-items: center; gap: 8px; padding: 4px 10px 4px 4px; border-radius: 99px; background: var(--surface-3); font-size: 12.5px; }
.user-chip .avatar { width: 26px; height: 26px; border-radius: 50%; background: var(--navy); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 12px; }
.content { padding: 24px 28px 48px; display: flex; flex-direction: column; gap: 20px; max-width: 1400px; width: 100%; }
.topbar .menu-toggle { display: none; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.card-head h2 { font-size: 15px; font-weight: 650; }
.card-head .sub { color: var(--muted); font-size: 12.5px; }
.card-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.card-body { padding: 18px 20px; }
.card-body.flush { padding: 0; }
.card-foot { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.grid { display: grid; gap: 20px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.sidebar-right { grid-template-columns: minmax(0, 1fr) 340px; align-items: start; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 36px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); cursor: pointer; font-weight: 550; font-size: 13.5px; white-space: nowrap; text-decoration: none; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-contrast); }
.btn.primary:hover { background: var(--brand-hover); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, var(--border-strong)); }
.btn.danger:hover { background: var(--danger-bg); }
.btn.danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-3); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 12.5px; border-radius: 7px; }
.btn.icon-only { width: 32px; padding: 0; height: 32px; }
.btn .icon { width: 16px; height: 16px; }
.btn.loading { position: relative; color: transparent !important; }
.btn.loading::after { content: ""; position: absolute; width: 16px; height: 16px; border: 2px solid currentColor; border-color: var(--muted) transparent var(--muted) transparent; border-radius: 50%; animation: spin 0.8s linear infinite; }
.btn.primary.loading::after { border-color: #fff transparent #fff transparent; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Forms */
.form-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 14px 16px; }
.span-12 { grid-column: span 12; } .span-8 { grid-column: span 8; } .span-6 { grid-column: span 6; }
.span-4 { grid-column: span 4; } .span-3 { grid-column: span 3; } .span-2 { grid-column: span 2; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label, .field-label { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.field .help { font-size: 12px; color: var(--muted); }
.field .error { font-size: 12px; color: var(--danger); }
.input, select.input, textarea.input { width: 100%; height: 36px; padding: 0 10px; border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface); color: var(--text); }
textarea.input { height: auto; min-height: 64px; padding: 8px 10px; resize: vertical; line-height: 1.45; }
.input:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 22%, transparent); }
.input.invalid { border-color: var(--danger); }
.input[readonly] { background: var(--surface-2); color: var(--text-2); }
.input.num { text-align: right; }
.check { display: inline-flex; gap: 8px; align-items: center; cursor: pointer; font-size: 13.5px; }
.check input { width: 16px; height: 16px; accent-color: var(--brand); }
.input-group { display: flex; }
.input-group .input { border-radius: 8px 0 0 8px; }
.input-group .addon { display: grid; place-items: center; padding: 0 10px; border: 1px solid var(--border-strong); border-left: 0; border-radius: 0 8px 8px 0; background: var(--surface-2); color: var(--muted); font-size: 12.5px; }
.form-section-title { font-size: 12px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); margin: 6px 0 2px; grid-column: span 12; }
.segmented { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 8px; overflow: hidden; }
.segmented button { border: 0; background: var(--surface); padding: 6px 12px; cursor: pointer; font-size: 12.5px; color: var(--text-2); }
.segmented button + button { border-left: 1px solid var(--border-strong); }
.segmented button.active { background: var(--brand); color: var(--brand-contrast); }

/* Tables */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th { text-align: left; font-size: 11.5px; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); font-weight: 650; padding: 10px 14px; background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr.clickable { cursor: pointer; }
.table tbody tr.clickable:hover td { background: var(--surface-2); }
.table th.right, .table td.right { text-align: right; }
.table td .sub { display: block; font-size: 12px; color: var(--muted); }
.table tr.voided td { color: var(--muted); text-decoration: line-through; }
.empty { padding: 36px 20px; text-align: center; color: var(--muted); }
.empty .icon { width: 30px; height: 30px; margin-bottom: 8px; opacity: 0.6; }
.pager { display: flex; align-items: center; gap: 10px; justify-content: flex-end; padding: 12px 16px; border-top: 1px solid var(--border); font-size: 12.5px; color: var(--muted); }

/* Badges & alerts */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 99px; font-size: 11.5px; font-weight: 650; white-space: nowrap; background: var(--neutral-bg); color: var(--text-2); }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.85; }
.badge.plain::before { display: none; }
.badge.draft { background: var(--neutral-bg); color: var(--text-2); }
.badge.unpaid { background: var(--info-bg); color: var(--info); }
.badge.partially_paid { background: var(--warning-bg); color: var(--warning); }
.badge.paid { background: var(--success-bg); color: var(--success); }
.badge.overdue { background: var(--danger-bg); color: var(--danger); }
.badge.cancelled { background: var(--neutral-bg); color: var(--muted); text-decoration: line-through; }
.badge.ok { background: var(--success-bg); color: var(--success); }
.badge.warn { background: var(--warning-bg); color: var(--warning); }
.badge.bad { background: var(--danger-bg); color: var(--danger); }
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 8px; font-size: 13.5px; border: 1px solid transparent; }
.alert .icon { margin-top: 1px; }
.alert.info { background: var(--info-bg); color: var(--info); border-color: color-mix(in srgb, var(--info) 20%, transparent); }
.alert.warning { background: var(--warning-bg); color: var(--warning); border-color: color-mix(in srgb, var(--warning) 22%, transparent); }
.alert.danger { background: var(--danger-bg); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 22%, transparent); }
.alert.success { background: var(--success-bg); color: var(--success); border-color: color-mix(in srgb, var(--success) 22%, transparent); }
.alert .alert-body { color: var(--text); }
.alert strong { color: inherit; }

/* Key/value lists */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 8px 16px; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 550; min-width: 0; overflow-wrap: anywhere; }

/* Stat tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.tile .label { font-size: 12.5px; color: var(--muted); }
.tile .value { font-size: 22px; font-weight: 650; margin-top: 4px; overflow-wrap: anywhere; }
.tile .value .ccy { font-size: 13px; color: var(--muted); font-weight: 600; margin-right: 4px; }
.tile .foot { font-size: 12px; color: var(--muted); margin-top: 4px; }
.currency-block { display: flex; flex-direction: column; gap: 10px; }
.currency-block h3 { font-size: 13px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-2); }

/* Filters */
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.filters .field { min-width: 140px; }
.filters .field.wide { min-width: 240px; flex: 1 1 240px; }

/* Charts */
.chart-card .card-body { position: relative; }
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart .grid-line { stroke: var(--chart-grid); stroke-width: 1; shape-rendering: crispEdges; }
.chart .base-line { stroke: var(--chart-axis); stroke-width: 1; shape-rendering: crispEdges; }
.chart .tick { fill: var(--chart-text); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .bar-1 { fill: var(--series-1); }
.chart .bar-2 { fill: var(--series-2); }
.chart .band { fill: transparent; cursor: default; }
.chart .band:hover, .chart .band:focus { fill: color-mix(in srgb, var(--text) 5%, transparent); outline: none; }
.legend { display: flex; gap: 16px; font-size: 12.5px; color: var(--text-2); margin-bottom: 8px; flex-wrap: wrap; }
.legend .key { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.legend .key.s1 { background: var(--series-1); } .legend .key.s2 { background: var(--series-2); }
.chart-tip { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow-lg); padding: 8px 10px; font-size: 12.5px; min-width: 170px; z-index: 5; }
.chart-tip .t-title { color: var(--muted); font-size: 11.5px; margin-bottom: 4px; }
.chart-tip .t-row { display: flex; align-items: center; gap: 8px; }
.chart-tip .t-row strong { font-variant-numeric: tabular-nums; }
.chart-tip .line-key { width: 12px; height: 2px; border-radius: 1px; }
.chart-tip .line-key.s1 { background: var(--series-1); } .chart-tip .line-key.s2 { background: var(--series-2); }

/* Invoice editor */
.items-table { width: 100%; border-collapse: separate; border-spacing: 0; }
.items-table th { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); text-align: left; padding: 0 6px 6px; font-weight: 650; }
.items-table td { padding: 6px; vertical-align: top; border-top: 1px solid var(--border); }
.items-table tr:first-child td { border-top: 0; }
.items-table .c-qty { width: 84px; } .items-table .c-price { width: 128px; } .items-table .c-total { width: 136px; text-align: right; }
.items-table .c-actions { width: 100px; white-space: nowrap; text-align: right; }
.items-table .c-actions .btn.icon-only { width: 28px; height: 28px; }
.items-table td.c-total { padding-top: 15px; font-weight: 600; }
.items-table textarea.input { min-height: 36px; height: 36px; margin-top: 6px; font-size: 13px; resize: none; overflow: hidden; }
.summary-card { position: sticky; top: 84px; }
.summary-lines { display: flex; flex-direction: column; gap: 8px; font-size: 13.5px; }
.summary-lines .line { display: flex; justify-content: space-between; gap: 12px; }
.summary-lines .line .v { font-variant-numeric: tabular-nums; font-weight: 600; }
.summary-lines .total { margin-top: 4px; padding: 10px 12px; border-radius: 8px; background: var(--navy); color: #fff; font-weight: 700; font-size: 15px; }
.summary-lines .total .v { color: #fff; }
.fx-box { border: 1px solid var(--border); border-radius: 8px; padding: 12px; background: var(--surface-2); display: flex; flex-direction: column; gap: 10px; }
.autocomplete { position: relative; }
.autocomplete-list { position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + 4px); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow-lg); max-height: 280px; overflow-y: auto; }
.autocomplete-list button { display: block; width: 100%; text-align: left; padding: 8px 12px; border: 0; background: none; cursor: pointer; }
.autocomplete-list button:hover, .autocomplete-list button.active { background: var(--surface-3); }
.autocomplete-list .sub { display: block; font-size: 12px; color: var(--muted); }
.dirty-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warning); display: inline-block; }

/* Invoice preview */
.preview-holder { position: relative; width: 100%; overflow: hidden; background: #e9edf2; border-radius: 0 0 var(--radius) var(--radius); }
.preview-holder iframe { position: absolute; left: 0; top: 0; border: 0; transform-origin: 0 0; background: #e9edf2; }
.modal .preview-holder { border-radius: 8px; }
.pay-list { display: flex; flex-direction: column; }
.pay-item { padding: 12px 20px; border-top: 1px solid var(--border); }
.pay-item:first-child { border-top: 0; }
.pay-main { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.pay-item.voided strong { text-decoration: line-through; color: var(--muted); }
.preview-card .card-body { padding: 0; background: #e9edf2; border-radius: 0 0 var(--radius) var(--radius); }

/* Modals */
.modal-backdrop { position: fixed; inset: 0; background: rgba(8, 18, 32, 0.5); display: grid; place-items: center; padding: 24px; z-index: 100; }
.modal { width: 100%; max-width: 560px; max-height: calc(100vh - 48px); overflow: auto; background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg); border: 1px solid var(--border); display: flex; flex-direction: column; }
.modal.wide { max-width: 780px; }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 18px 20px 6px; }
.modal-head h2 { font-size: 17px; }
.modal-head .close { margin-left: auto; }
.modal-body { padding: 12px 20px 8px; display: flex; flex-direction: column; gap: 14px; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 14px 20px 18px; }

/* Toasts */
.toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 200; max-width: 420px; }
.toast { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 10px; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-lg); font-size: 13.5px; animation: toast-in 0.18s ease-out; }
.toast.success { border-left: 4px solid var(--success); }
.toast.error { border-left: 4px solid var(--danger); }
.toast.info { border-left: 4px solid var(--info); }
.toast.warning { border-left: 4px solid var(--warning); }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* Misc */
.steps { display: flex; flex-direction: column; gap: 14px; }
.step { display: grid; grid-template-columns: 28px 1fr; gap: 12px; }
.step .num-dot { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 13px; background: var(--surface-3); color: var(--text-2); }
.step.done .num-dot { background: var(--success-bg); color: var(--success); }
.step h3 { font-size: 14px; margin-bottom: 4px; }
.logo-preview { width: 160px; height: 80px; border: 1px dashed var(--border-strong); border-radius: 8px; display: grid; place-items: center; background: var(--surface-2); overflow: hidden; }
.logo-preview img { max-width: 100%; max-height: 100%; object-fit: contain; }
.fingerprint { font-family: ui-monospace, Consolas, Menlo, monospace; font-size: 12px; word-break: break-all; background: var(--surface-2); padding: 8px 10px; border-radius: 6px; border: 1px solid var(--border); }
.loading-block { padding: 40px; text-align: center; color: var(--muted); }
.refetching { opacity: 0.55; transition: opacity 0.15s; }

@media (max-width: 1180px) {
  .grid.sidebar-right { grid-template-columns: 1fr; }
  .summary-card { position: static; }
  .grid.cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 90; transform: translateX(-100%); transition: transform 0.2s; }
  .shell.nav-open .sidebar { transform: none; box-shadow: var(--shadow-lg); }
  .topbar .menu-toggle { display: inline-flex; }
  .topbar { padding: 12px 16px; }
  .content { padding: 16px; }
  .grid.cols-2, .grid.cols-3 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .span-8, .span-6 { grid-column: span 6; } .span-4, .span-3 { grid-column: span 3; } .span-2 { grid-column: span 3; }
  .items-table .c-price, .items-table .c-total { width: 110px; }
}
@media print {
  .sidebar, .topbar, .toasts { display: none !important; }
}

/* =================================================================== payroll helpers */
.lines-editor { display: flex; flex-direction: column; gap: 8px; }
.lines-list { display: flex; flex-direction: column; gap: 8px; }
.line-row { display: grid; grid-template-columns: minmax(0, 1fr) 140px 34px; gap: 8px; align-items: start; }

/* =================================================================== responsive (tablet & phone) */
.nav-backdrop { display: none; }
.mobile-bar { display: none; }

@media (max-width: 900px) {
  .nav-backdrop { display: block; position: fixed; inset: 0; background: rgba(8, 18, 32, 0.45); z-index: 80; opacity: 0; pointer-events: none; transition: opacity 0.2s; }
  .shell.nav-open .nav-backdrop { opacity: 1; pointer-events: auto; }
  .topbar { flex-wrap: wrap; row-gap: 10px; }
  .topbar > div:nth-child(2) { flex: 1 1 auto; min-width: 0; }
  .topbar h1 { font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .user-chip { order: 2; margin-left: auto; }
  .topbar-actions { order: 3; width: 100%; margin-left: 0; flex-wrap: nowrap; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
  .topbar-actions::-webkit-scrollbar { display: none; }
  .topbar-actions .btn { flex: 0 0 auto; }
  .mobile-bar { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 60; gap: 8px; align-items: center;
    padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--border);
    box-shadow: 0 -4px 16px rgba(10, 25, 45, 0.08); }
  .mobile-bar > div { margin-right: auto; min-width: 0; }
  .mobile-bar strong { font-size: 15px; white-space: nowrap; }
  .content.has-mobile-bar { padding-bottom: 96px; }
  .content.has-mobile-bar .summary-card .card-foot { display: none; }
}

@media (max-width: 700px) {
  /* Tables turn into stacked, labelled cards */
  .table-wrap { overflow-x: visible; }
  table.table thead { display: none; }
  table.table, table.table tbody, table.table tr, table.table td { display: block; width: 100%; }
  table.table tr { padding: 10px 14px; border-bottom: 1px solid var(--border); }
  table.table tbody tr:last-child { border-bottom: 0; }
  table.table td { display: flex; justify-content: space-between; align-items: baseline; gap: 14px; padding: 4px 0; border: 0; text-align: right; }
  table.table td::before { content: attr(data-label); flex: 0 0 auto; font-size: 11px; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); font-weight: 650; text-align: left; }
  table.table td[data-label=""]::before { display: none; }
  table.table td[data-label=""] { justify-content: flex-end; }
  table.table td .sub { text-align: right; }
  /* Invoice items: one card per line */
  .items-table thead { display: none; }
  .items-table, .items-table tbody { display: block; }
  .items-table tr { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; padding: 12px 0; border-top: 1px solid var(--border); }
  .items-table tbody tr:first-child { border-top: 0; }
  .items-table td { display: block; padding: 0; border: 0 !important; width: auto !important; }
  .items-table td:first-child { grid-column: 1 / -1; }
  .items-table td[data-label]::before { content: attr(data-label); display: block; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 650; margin-bottom: 4px; }
  .items-table td.c-total { padding-top: 0; text-align: left; align-self: center; }
  .items-table td.c-actions { text-align: right; align-self: center; }
  .line-row { grid-template-columns: minmax(0, 1fr) 110px 34px; }
}

@media (max-width: 600px) {
  .content { padding: 12px 12px 32px; gap: 14px; }
  .topbar { padding: 10px 12px; }
  .input, select.input, textarea.input { font-size: 16px; }
  .form-grid { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .form-grid > * { grid-column: 1 / -1 !important; }
  .card-head { padding: 14px 16px; flex-wrap: wrap; }
  .card-head .actions { margin-left: 0; width: 100%; }
  .card-body { padding: 14px 16px; }
  .card-foot { padding: 12px 16px; }
  .card-foot .btn { flex: 1 1 auto; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .tile { padding: 12px; }
  .tile .value { font-size: 17px; }
  .filters { flex-direction: column; align-items: stretch; }
  .filters .field, .filters .field.wide { min-width: 0; width: 100%; flex: 1 1 auto; }
  .kv { grid-template-columns: minmax(0, 1fr); gap: 2px 0; }
  .kv dd { margin-bottom: 8px; }
  .modal-backdrop { padding: 0; place-items: stretch; }
  .modal, .modal.wide { max-width: none; max-height: 100vh; height: 100%; border-radius: 0; border: 0; }
  .modal-foot { position: sticky; bottom: 0; background: var(--surface); border-top: 1px solid var(--border); flex-wrap: wrap; }
  .modal-foot .btn { flex: 1 1 auto; }
  .toasts { left: 12px; right: 12px; bottom: 12px; max-width: none; }
  .pager { flex-wrap: wrap; justify-content: center; }
  .login-card { padding: 22px; }
  .row.between { flex-wrap: wrap; }
  .user-chip > span:last-child { display: none; }
  .user-chip { padding: 2px; }
  .legend { gap: 10px; }
  .fingerprint { font-size: 11px; }
}

/* =================================================================== layout fixes (v1.1) */
/* Every column width 1-12 exists (a missing .span-5 made the salary field one column wide). */
.span-1 { grid-column: span 1; } .span-5 { grid-column: span 5; } .span-7 { grid-column: span 7; }
.span-9 { grid-column: span 9; } .span-10 { grid-column: span 10; } .span-11 { grid-column: span 11; }
.form-section-title { grid-column: 1 / -1; }

.line-row { grid-template-columns: minmax(0, 1fr) minmax(150px, 220px) 34px; }
.line-head { font-size: 11px; font-weight: 650; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); align-items: end; }
.line-amount .input-group .input { min-width: 0; }
.input-group .addon { white-space: nowrap; }
/* Itemised salary breakdown (each allowance / deduction by name) */
.summary-lines .line .v { white-space: nowrap; }
.summary-lines .line .k { min-width: 0; overflow-wrap: anywhere; }
.breakdown .line.item .k { color: var(--text-2); }
.breakdown .line.subtotal { border-top: 1px solid var(--border); padding-top: 8px; font-weight: 600; }
.salary-preview { border: 1px solid var(--border); background: var(--surface-2); border-radius: 8px; padding: 12px 14px; }
.salary-preview-title { font-size: 12px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; }

@media (max-width: 900px) {
  /* 6-column form grid on tablets: wide fields take the full row, small ones half. */
  .span-12, .span-11, .span-10, .span-9, .span-8, .span-7, .span-6, .span-5 { grid-column: span 6; }
  .span-4, .span-3, .span-2, .span-1 { grid-column: span 3; }
}

@media (max-width: 600px) {
  /* Allowance / deduction lines: description on one row, amount (with currency) on the next. */
  .line-row { grid-template-columns: minmax(0, 1fr) 36px; grid-template-areas: "label remove" "amount amount"; row-gap: 6px;
    padding-bottom: 10px; border-bottom: 1px dashed var(--border); }
  .line-row .line-label { grid-area: label; }
  .line-row .line-amount { grid-area: amount; }
  .line-row .line-remove { grid-area: remove; }
  .line-head { display: none; }
}
/* Spreadsheet import results */
.import-notes { margin: 0; padding-left: 18px; display: grid; gap: 4px; }
.import-result:empty { display: none; }
