/* Western Mega Project · Invoice Tracker */

:root {
  --brand: #9b3a2e;
  --brand-700: #7f2f25;
  --brand-50: #fbf2f0;
  --brand-100: #f4ddd8;

  --ink: #1c1917;
  --ink-2: #44403c;
  --muted: #6b6560;
  --faint: #a29b95;
  --line: #e7e4e1;
  --line-2: #f1efed;
  --bg: #f6f5f3;
  --surface: #ffffff;
  --surface-2: #fafaf9;

  --blue: #2a64a6;   --blue-bg: #e9f1fb;
  --green: #1c7547;  --green-bg: #e5f3eb;
  --red: #c4352b;    --red-bg: #fdeceb;
  --purple: #6447c4; --purple-bg: #efebfb;
  --slate: #57534e;  --slate-bg: #ecebe9;
  --amber: #b06a00;

  --age-0: #8aa1b8;
  --age-1: #e7a83e;
  --age-2: #df7a35;
  --age-3: #cc4630;
  --age-4: #8e2a21;
  --age-rev: #8e7ad6;

  --radius: 14px;
  --radius-sm: 9px;
  --shadow-sm: 0 1px 2px rgba(28, 25, 23, .05);
  --shadow: 0 1px 2px rgba(28, 25, 23, .04), 0 6px 20px -10px rgba(28, 25, 23, .14);
  --shadow-lg: 0 30px 70px -20px rgba(28, 25, 23, .45);
  --font: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", Arial, sans-serif;
  --ring: 0 0 0 3px rgba(155, 58, 46, .22);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 14.5px/1.5 var(--font);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; }
[hidden] { display: none !important; }
.num, .tnum { font-variant-numeric: tabular-nums; }

.i { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.i-sm { width: 15px; height: 15px; }

/* ── Buttons ───────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px;
  border: 1px solid transparent; border-radius: 10px;
  font-weight: 600; font-size: 14px; white-space: nowrap;
  cursor: pointer; text-decoration: none;
  transition: background .15s, border-color .15s, color .15s, box-shadow .15s, transform .05s;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn[disabled] { opacity: .6; cursor: progress; }
.btn-primary { background: var(--brand); color: #fff; box-shadow: 0 1px 0 rgba(255,255,255,.15) inset, 0 1px 2px rgba(127,47,37,.35); }
.btn-primary:hover { background: var(--brand-700); }
.btn-success { background: var(--green); color: #fff; }
.btn-success:hover { background: #155c37; }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { background: #a62a21; }
.btn-ghost { background: var(--surface); border-color: var(--line); color: var(--ink-2); }
.btn-ghost:hover { border-color: #d6d1cc; background: var(--surface-2); }
.btn-icon { width: 40px; padding: 0; background: transparent; color: var(--muted); }
.btn-icon:hover { background: var(--line-2); color: var(--ink); }
.btn-link { height: auto; padding: 6px 4px; background: none; color: var(--brand); font-weight: 600; }
.btn-link:hover { text-decoration: underline; }
.btn-text-danger { background: none; color: var(--red); padding: 0 10px; }
.btn-text-danger:hover { background: var(--red-bg); }
.btn-block { width: 100%; height: 44px; }
.btn .spinner { width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Top bar ───────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 30;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1320px; margin: 0 auto; padding: 10px 24px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.brand { display: flex; align-items: center; gap: 14px; text-decoration: none; color: inherit; min-width: 0; }
.brand img { height: 46px; width: auto; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; padding-left: 14px; border-left: 1px solid var(--line); min-width: 0; }
.brand-title { font-weight: 700; font-size: 16px; letter-spacing: -.01em; }
.brand-sub { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.logout-form { margin: 0; }

/* ── Page ──────────────────────────────────────────────── */
.page { max-width: 1320px; margin: 0 auto; padding: 22px 24px 60px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.asat { margin: 0; color: var(--muted); font-size: 13px; }

.seg { display: inline-flex; padding: 3px; gap: 2px; background: #ebe8e5; border-radius: 11px; }
.seg button {
  border: 0; background: transparent; padding: 7px 14px; border-radius: 8px;
  font-weight: 600; font-size: 13.5px; color: var(--muted); cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
}
.seg button:hover { color: var(--ink); }
.seg button[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08), 0 1px 1px rgba(0,0,0,.04); }
.seg button:focus-visible { outline: none; box-shadow: var(--ring); }
.seg .dot { width: 8px; height: 8px; border-radius: 50%; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); }

/* ── KPI cards ─────────────────────────────────────────── */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 14px; }
.kpi {
  position: relative; text-align: left;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px 15px; box-shadow: var(--shadow-sm);
  display: flex; flex-direction: column; gap: 4px; min-width: 0;
}
button.kpi { cursor: pointer; transition: border-color .15s, box-shadow .15s, transform .15s; }
button.kpi:hover { border-color: #d8d2cc; box-shadow: var(--shadow); }
button.kpi:focus-visible { outline: none; box-shadow: var(--ring); }
.kpi.is-active { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand) inset; }
.kpi-label { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--muted); }
.kpi-label .badge-ic { width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; }
.kpi-label .badge-ic .i { width: 15px; height: 15px; }
.kpi-value { font-size: 26px; font-weight: 700; letter-spacing: -.02em; line-height: 1.2; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.kpi-value .cents { font-size: 15px; font-weight: 600; color: var(--faint); letter-spacing: 0; }
.kpi-value .unit { font-size: 15px; font-weight: 600; color: var(--muted); margin-left: 2px; letter-spacing: 0; }
.kpi-sub { font-size: 12.5px; color: var(--muted); line-height: 1.45; }
.kpi-sub b { color: var(--ink-2); font-weight: 600; }
.kpi--owed .badge-ic { background: var(--brand-50); color: var(--brand); }
.kpi--overdue .badge-ic { background: var(--red-bg); color: var(--red); }
.kpi--overdue.has-overdue .kpi-value { color: var(--red); }
.kpi--paid .badge-ic { background: var(--green-bg); color: var(--green); }
.kpi--speed .badge-ic { background: var(--blue-bg); color: var(--blue); }
.kpi-ok { color: var(--green); font-weight: 600; }

/* ── Ageing ────────────────────────────────────────────── */
.ageing { padding: 16px 18px; margin-bottom: 14px; }
.ageing-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.ageing-head h2 { margin: 0; font-size: 14px; font-weight: 700; }
.ageing-head p { margin: 0; font-size: 12.5px; color: var(--muted); }
.ageing-bar { display: flex; height: 12px; border-radius: 99px; overflow: hidden; background: var(--line-2); gap: 2px; }
.ageing-bar span { display: block; height: 100%; min-width: 4px; transition: flex-grow .3s ease; }
.ageing-legend { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; margin-top: 12px; }
.age-item {
  border: 1px solid transparent; background: none; text-align: left; cursor: pointer;
  padding: 8px 10px; border-radius: 10px; display: flex; flex-direction: column; gap: 2px; min-width: 0;
}
.age-item:hover { background: var(--surface-2); border-color: var(--line); }
.age-item:focus-visible { outline: none; box-shadow: var(--ring); }
.age-item.is-active { background: var(--brand-50); border-color: var(--brand-100); }
.age-item[disabled] { cursor: default; opacity: .55; }
.age-item[disabled]:hover { background: none; border-color: transparent; }
.age-name { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--muted); font-weight: 600; white-space: nowrap; }
.age-name i { width: 9px; height: 9px; border-radius: 3px; flex: none; }
.age-amt { font-weight: 700; font-size: 14.5px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.age-count { font-size: 12px; color: var(--faint); }
.ageing-empty { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13.5px; }
.ageing-empty .i { color: var(--green); }

/* ── Tabs & filters ────────────────────────────────────── */
.table-card { overflow: hidden; }
.tabs { display: flex; gap: 2px; padding: 0 12px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  position: relative; border: 0; background: none; cursor: pointer;
  padding: 14px 12px 13px; font-weight: 600; font-size: 13.5px; color: var(--muted);
  display: inline-flex; align-items: center; gap: 7px; white-space: nowrap;
}
.tab:hover { color: var(--ink); }
.tab:focus-visible { outline: none; box-shadow: var(--ring); border-radius: 8px; }
.tab[aria-selected="true"] { color: var(--ink); }
.tab[aria-selected="true"]::after { content: ""; position: absolute; left: 10px; right: 10px; bottom: -1px; height: 2px; background: var(--brand); border-radius: 2px; }
.tab .count { font-size: 11.5px; font-weight: 700; padding: 1px 7px; border-radius: 99px; background: var(--line-2); color: var(--muted); font-variant-numeric: tabular-nums; }
.tab[aria-selected="true"] .count { background: var(--brand-50); color: var(--brand); }
.tab.tab-overdue .count.hot { background: var(--red-bg); color: var(--red); }

.filters { display: flex; align-items: flex-end; gap: 12px; padding: 14px 16px 10px; flex-wrap: wrap; }
.search {
  flex: 1 1 280px; position: relative; display: flex; align-items: center;
  height: 40px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
  padding: 0 10px 0 12px; gap: 8px; color: var(--faint);
  transition: border-color .15s, box-shadow .15s;
}
.search:focus-within { border-color: var(--brand); box-shadow: var(--ring); }
.search input { flex: 1; border: 0; outline: none; background: none; height: 100%; color: var(--ink); min-width: 0; }
.search input::placeholder { color: var(--faint); }
.search input:not(:placeholder-shown) ~ kbd, .search input:focus ~ kbd { display: none; }
.search kbd { font: 600 11px var(--font); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; padding: 0 6px; color: var(--faint); }
.date-range { display: flex; gap: 8px; align-items: flex-end; }
.mini-field { display: flex; flex-direction: column; gap: 3px; font-size: 11.5px; font-weight: 600; color: var(--muted); }
.mini-field input { height: 40px; border: 1px solid var(--line); border-radius: 10px; padding: 0 10px; background: var(--surface); }
.mini-field input:focus { outline: none; border-color: var(--brand); box-shadow: var(--ring); }
.active-chips { display: flex; gap: 8px; padding: 0 16px; flex-wrap: wrap; }
.active-chips:not(:empty) { padding-bottom: 10px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 6px 4px 11px; border-radius: 99px; background: var(--brand-50); color: var(--brand-700); font-size: 12.5px; font-weight: 600; border: 1px solid var(--brand-100); }
.chip button { border: 0; background: none; color: inherit; width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; cursor: pointer; padding: 0; }
.chip button:hover { background: var(--brand-100); }

/* ── Table ─────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table.inv { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13.5px; }
.inv th {
  position: sticky; top: 0; background: var(--surface-2);
  text-align: left; font-size: 11.5px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .04em;
  padding: 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); white-space: nowrap;
}
.inv th .th { display: flex; align-items: center; gap: 4px; padding: 10px 12px; }
.inv th button.th { width: 100%; border: 0; background: none; cursor: pointer; font: inherit; color: inherit; text-transform: inherit; letter-spacing: inherit; }
.inv th button.th:hover { color: var(--ink); }
.inv th button.th:focus-visible { outline: none; box-shadow: inset var(--ring); }
.inv th.num .th { justify-content: flex-end; }
.inv th .arrow { opacity: 0; font-size: 10px; }
.inv th[aria-sort] .arrow { opacity: 1; color: var(--brand); }
.inv td { padding: 12px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
.inv tbody tr { cursor: pointer; transition: background .1s; }
.inv tbody tr:hover { background: #fbfaf9; }
.inv tbody tr.flash { animation: flash 1.6s ease; }
@keyframes flash { 0%, 30% { background: #fff4d6; } 100% { background: transparent; } }
.inv td.num { text-align: right; white-space: nowrap; font-weight: 600; font-variant-numeric: tabular-nums; }
.inv .c-no { white-space: nowrap; font-weight: 600; }
.inv .c-date { white-space: nowrap; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.inv .c-desc { min-width: 220px; max-width: 380px; }
.desc { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.row-note { margin-top: 4px; font-size: 12.5px; color: var(--muted); display: flex; gap: 5px; align-items: flex-start; }
.row-note .i { width: 13px; height: 13px; margin-top: 3px; }
.row-note.n-revision { color: var(--purple); }
.row-note.n-rejected { color: var(--slate); }
.muted { color: var(--faint); }
.inv .c-due { white-space: nowrap; }
.due-meta { font-size: 12px; margin-top: 2px; font-weight: 600; }
.due-meta.late { color: var(--red); }
.due-meta.soon { color: var(--amber); }
.due-meta.ok { color: var(--muted); font-weight: 500; }
.due-meta.paid { color: var(--green); }
.due-meta.paid-late { color: var(--amber); }
.inv .c-act { width: 1%; white-space: nowrap; text-align: right; }
.inv td.c-file { width: 1%; text-align: center; }

.grant {
  display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 6px;
  font-size: 12px; font-weight: 700; letter-spacing: .02em; white-space: nowrap;
}
.grant-0 { background: var(--brand-50); color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand-100); }
.grant-1 { background: #eeeeee; color: #555; box-shadow: inset 0 0 0 1px #e0e0e0; }
.grant-2 { background: var(--blue-bg); color: var(--blue); }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 8px 4px 9px; border-radius: 99px; border: 0;
  font-size: 12.5px; font-weight: 600; white-space: nowrap; cursor: pointer;
  transition: filter .15s, box-shadow .15s;
}
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill .chev { width: 14px; height: 14px; opacity: .6; }
.pill:hover { filter: brightness(.96); box-shadow: inset 0 0 0 1px currentColor; }
.pill:focus-visible { outline: none; box-shadow: var(--ring); }
.s-submitted { background: var(--blue-bg); color: var(--blue); }
.s-overdue { background: var(--red-bg); color: var(--red); }
.s-paid { background: var(--green-bg); color: var(--green); }
.s-revision { background: var(--purple-bg); color: var(--purple); }
.s-rejected { background: var(--slate-bg); color: var(--slate); }

.icon-btn {
  display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 9px;
  border: 1px solid transparent; background: none; color: var(--muted); cursor: pointer; text-decoration: none;
}
.icon-btn:hover { background: var(--line-2); color: var(--ink); }
.icon-btn:focus-visible { outline: none; box-shadow: var(--ring); }
.icon-btn.file { color: var(--brand); border-color: var(--brand-100); background: var(--brand-50); }
.icon-btn.file:hover { background: var(--brand-100); }

.table-foot {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 16px; font-size: 13px; color: var(--muted); background: var(--surface-2); border-top: 1px solid var(--line);
}
.table-foot b { color: var(--ink); font-variant-numeric: tabular-nums; }
.foot-totals { display: flex; gap: 18px; flex-wrap: wrap; }

.empty { text-align: center; padding: 56px 20px 60px; }
.empty-ic { width: 56px; height: 56px; border-radius: 16px; margin: 0 auto 14px; display: grid; place-items: center; background: var(--brand-50); color: var(--brand); }
.empty-ic .i { width: 26px; height: 26px; }
.empty h3 { margin: 0 0 4px; font-size: 16px; }
.empty p { margin: 0 auto 16px; color: var(--muted); max-width: 380px; }

.skeleton { padding: 18px 16px; display: grid; gap: 12px; }
.skeleton div { height: 16px; border-radius: 6px; background: linear-gradient(90deg, var(--line-2), #f8f7f6, var(--line-2)); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ── Status menu (popover) ─────────────────────────────── */
.status-menu {
  position: fixed; z-index: 60; min-width: 250px; padding: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-lg);
  animation: pop .12s ease-out;
}
@keyframes pop { from { opacity: 0; transform: translateY(-4px) scale(.98); } }
.status-menu .menu-title { font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--faint); padding: 6px 10px 4px; }
.menu-item {
  display: flex; align-items: flex-start; gap: 10px; width: 100%; text-align: left;
  border: 0; background: none; padding: 9px 10px; border-radius: 8px; cursor: pointer;
}
.menu-item:hover, .menu-item:focus-visible { background: var(--surface-2); outline: none; }
.menu-item .dot { width: 9px; height: 9px; border-radius: 50%; margin-top: 6px; flex: none; }
.menu-item b { display: block; font-size: 13.5px; }
.menu-item small { display: block; color: var(--muted); font-size: 12px; }
.menu-item.is-current { opacity: .5; cursor: default; }
.menu-item.is-current:hover { background: none; }
.dot-submitted { background: var(--blue); }
.dot-paid { background: var(--green); }
.dot-revision { background: var(--purple); }
.dot-rejected { background: var(--slate); }

/* ── Modals ────────────────────────────────────────────── */
dialog.modal {
  width: min(480px, calc(100vw - 24px)); max-height: calc(100dvh - 32px);
  padding: 0; border: 0; border-radius: 18px; background: var(--surface); color: var(--ink);
  box-shadow: var(--shadow-lg); overflow: hidden;
}
dialog.modal-lg { width: min(760px, calc(100vw - 24px)); }
dialog.modal[open] { display: flex; flex-direction: column; animation: modalIn .18s ease-out; }
dialog.modal::backdrop { background: rgba(28, 25, 23, .45); backdrop-filter: blur(2px); animation: fadeIn .18s ease-out; }
@keyframes modalIn { from { opacity: 0; transform: translateY(10px) scale(.985); } }
@keyframes fadeIn { from { opacity: 0; } }
.modal form { display: flex; flex-direction: column; min-height: 0; flex: 1; margin: 0; }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 20px 22px 8px; }
.modal-head h2 { margin: 0; font-size: 18px; letter-spacing: -.01em; }
.modal-head p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
.modal-head .icon-btn { margin: -6px -8px 0 0; }
.modal-body { padding: 10px 22px 18px; overflow-y: auto; }
.modal-foot {
  display: flex; align-items: center; gap: 10px; padding: 14px 22px;
  border-top: 1px solid var(--line); background: var(--surface-2);
}
.modal-foot .spacer { flex: 1; }
.modal-hero { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; margin-bottom: 12px; }
.modal-hero .i { width: 22px; height: 22px; }
.hero-paid { background: var(--green-bg); color: var(--green); }
.hero-revision { background: var(--purple-bg); color: var(--purple); }
.hero-rejected { background: var(--slate-bg); color: var(--slate); }
.hero-submitted { background: var(--blue-bg); color: var(--blue); }
.hero-danger { background: var(--red-bg); color: var(--red); }

.summary { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin: 4px 0 16px; background: var(--surface-2); }
.summary-top { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.summary-top b { font-size: 14px; }
.summary-top .amt { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.summary p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.lead { margin: 0 0 14px; color: var(--ink-2); }
.hint-live { margin: 8px 0 0; font-size: 12.5px; color: var(--muted); min-height: 18px; }
.hint-live.warn { color: var(--amber); }

/* ── Form fields ───────────────────────────────────────── */
.grid { display: grid; gap: 14px 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.span-all { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-label { font-size: 13px; font-weight: 600; color: var(--ink-2); display: flex; justify-content: space-between; gap: 8px; }
.field-label .opt { font-weight: 500; color: var(--faint); }
.field input, .field select, .field textarea {
  width: 100%; min-height: 42px; padding: 9px 12px;
  border: 1px solid #ddd8d3; border-radius: 10px; background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
}
.field textarea { resize: vertical; min-height: 76px; line-height: 1.45; }
.field input:hover, .field select:hover, .field textarea:hover { border-color: #cbc4bd; }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--brand); box-shadow: var(--ring); }
.field .help { font-size: 12px; color: var(--muted); }
.field .help.auto { color: var(--blue); }
.money { position: relative; }
.money span { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); font-weight: 600; pointer-events: none; }
.money input { padding-left: 28px; font-weight: 600; font-variant-numeric: tabular-nums; }
.form-stack { display: grid; gap: 16px; }
.check-row { display: flex; align-items: center; gap: 9px; margin: 0 0 12px; font-size: 13.5px; font-weight: 600; color: var(--ink-2); cursor: pointer; }
.check-row input, input[type="checkbox"] { width: 17px; height: 17px; accent-color: var(--brand); }
.help .btn-link { padding: 0; font-size: 12px; }
[data-dates] { transition: opacity .15s; }

.grant-choice { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.grant-opt { position: relative; }
.grant-opt input { position: absolute; opacity: 0; pointer-events: none; }
.grant-opt label {
  display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; height: 100%;
  border: 1px solid #ddd8d3; border-radius: 10px; cursor: pointer; transition: border-color .15s, background .15s, box-shadow .15s;
}
.grant-opt label b { font-size: 14px; }
.grant-opt label small { color: var(--muted); font-size: 12px; line-height: 1.35; }
.grant-opt label:hover { border-color: #cbc4bd; }
.grant-opt input:checked + label { border-color: var(--brand); background: var(--brand-50); box-shadow: 0 0 0 1px var(--brand) inset; }
.grant-opt input:focus-visible + label { box-shadow: var(--ring); }

.drop {
  display: flex; align-items: center; gap: 14px; padding: 14px; border: 1.5px dashed #d3ccc5; border-radius: 12px;
  background: var(--surface-2); cursor: pointer; transition: border-color .15s, background .15s;
}
.drop:hover, .drop.drag { border-color: var(--brand); background: var(--brand-50); }
.drop input { display: none; }
.drop-ic { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; background: var(--surface); border: 1px solid var(--line); color: var(--brand); flex: none; }
.drop-text { display: flex; flex-direction: column; min-width: 0; }
.drop-text b { font-size: 13.5px; }
.drop-text small { color: var(--muted); font-size: 12px; }
.file-card { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; }
.file-card .drop-ic { width: 36px; height: 36px; }
.file-card .drop-text { flex: 1; }
.file-card .drop-text b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-card .acts { display: flex; gap: 4px; }

.form-error, .alert {
  margin: 0 0 14px; padding: 10px 12px; border-radius: 10px; font-size: 13.5px;
  background: var(--red-bg); color: #9a271f; border: 1px solid #f6cfcb;
}
.alert-warn { background: #fff7e6; color: #7a4a00; border-color: #f5ddb0; }
.alert code { background: rgba(0,0,0,.06); padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }

.section-title { margin: 22px 0 10px; font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.timeline li { position: relative; padding: 0 0 12px 22px; font-size: 13px; }
.timeline li::before { content: ""; position: absolute; left: 4px; top: 14px; bottom: -2px; width: 1.5px; background: var(--line); }
.timeline li:last-child::before { display: none; }
.timeline .tdot { position: absolute; left: 0; top: 5px; width: 10px; height: 10px; border-radius: 50%; background: var(--faint); box-shadow: 0 0 0 3px var(--surface); }
.timeline .t-paid .tdot { background: var(--green); }
.timeline .t-revision .tdot { background: var(--purple); }
.timeline .t-rejected .tdot { background: var(--slate); }
.timeline .t-created .tdot { background: var(--brand); }
.timeline .t-reopened .tdot { background: var(--blue); }
.timeline time { display: block; font-size: 11.5px; color: var(--faint); }

/* ── Toasts ────────────────────────────────────────────── */
.toasts { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 10px;
  background: #22201e; color: #fff; padding: 11px 14px 11px 12px; border-radius: 12px;
  box-shadow: var(--shadow-lg); font-size: 13.5px; font-weight: 500; animation: toastIn .2s ease-out;
  max-width: calc(100vw - 32px);
}
.toast .i { width: 18px; height: 18px; color: #6fd39a; }
.toast.err .i { color: #ff9b91; }
.toast.out { animation: toastOut .2s ease-in forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(8px); } }

/* ── Login ─────────────────────────────────────────────── */
.login-page {
  min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px 16px;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(155, 58, 46, .10), transparent 60%),
    radial-gradient(900px 500px at 110% 110%, rgba(107, 107, 107, .12), transparent 60%),
    var(--bg);
}
.login-card { width: min(400px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 30px 28px 28px; box-shadow: var(--shadow); text-align: center; }
.login-logo { height: 92px; width: auto; margin: 0 auto 6px; display: block; }
.login-card h1 { margin: 0; font-size: 21px; letter-spacing: -.01em; }
.login-sub { margin: 4px 0 22px; color: var(--muted); }
.login-form { text-align: left; display: grid; gap: 14px; }
.login-form .form-error { margin: 0; }
.login-card .alert { text-align: left; }
.pw-wrap { position: relative; display: block; }
.pw-wrap input { padding-right: 64px; }
.pw-toggle { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); border: 0; background: none; color: var(--brand); font-weight: 600; font-size: 12.5px; padding: 6px 8px; border-radius: 6px; cursor: pointer; }
.pw-toggle:hover { background: var(--brand-50); }
.login-foot { color: var(--faint); font-size: 12px; margin-top: 18px; }

/* ── Responsive ────────────────────────────────────────── */
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ageing-legend { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  body { font-size: 14px; }
  .topbar-inner { padding: 8px 16px; }
  .brand img { height: 38px; }
  .brand-text { display: none; }
  .hide-sm { display: none; }
  .topbar .btn-ghost { width: 40px; padding: 0; }
  .page { padding: 16px 16px 48px; }
  .seg { width: 100%; }
  .seg button { flex: 1; justify-content: center; padding: 8px 6px; }
  .kpis { gap: 10px; }
  .kpi { padding: 13px 14px; }
  .kpi-value { font-size: 20px; }
  .kpi-value .cents { display: none; }
  .ageing-legend { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filters { padding: 12px; }
  .date-range { width: 100%; }
  .date-range .mini-field { flex: 1; }
  .date-range input { width: 100%; }

  /* Table → cards */
  table.inv, .inv tbody, .inv tr, .inv td { display: block; }
  .inv thead { display: none; }
  .inv tbody { padding: 4px 12px 8px; }
  .inv tbody tr {
    display: grid; grid-template-columns: 1fr auto; gap: 2px 12px;
    padding: 14px; margin: 10px 0; border: 1px solid var(--line); border-radius: 14px; background: var(--surface);
  }
  .inv td { padding: 0; border: 0; }
  .inv td[data-label]::before { content: attr(data-label); display: block; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--faint); }
  .inv .c-no { grid-column: 1; grid-row: 1; }
  .inv .c-no::before { display: none !important; }
  .inv td.num { grid-column: 2; grid-row: 1; font-size: 16px; }
  .inv td.num::before { display: none !important; }
  .inv .c-desc { grid-column: 1 / -1; grid-row: 2; max-width: none; min-width: 0; margin: 4px 0 8px; }
  .inv .c-desc::before { display: none !important; }
  .inv .c-grant { grid-column: 1 / -1; grid-row: 3; margin-bottom: 8px; }
  .inv .c-grant::before { display: none !important; }
  .inv .c-date { grid-column: auto; font-size: 13px; }
  .inv .c-due { grid-column: 1 / -1; margin-top: 8px; }
  .inv td.c-file .muted { display: none; }
  .inv .c-status { grid-column: 1; margin-top: 10px; }
  .inv .c-status::before { display: none !important; }
  .inv td.c-file { grid-column: 2; margin-top: 10px; width: auto; text-align: right; }
  .inv .c-file::before { display: none !important; }
  .inv .c-act { display: none; }
  .table-foot { flex-direction: column; align-items: flex-start; }

  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .grant-choice { grid-template-columns: 1fr; }
  dialog.modal { width: 100vw; max-width: 100vw; max-height: 94dvh; margin: auto 0 0; border-radius: 18px 18px 0 0; }
  .modal-head { padding: 18px 16px 6px; }
  .modal-body { padding: 8px 16px 16px; }
  .modal-foot { padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

@media print {
  .topbar, .filters, .tabs, .c-act, .c-file, .active-chips, .ageing-legend button { display: none !important; }
  body { background: #fff; }
  .card, .kpi { box-shadow: none; }
}
