:root {
  --navy: #0b1640; --blue: #1d3fae; --blue-2: #3d6bff; --gold: #c8921a; --gold-2: #f6d77c;
  --bg: #f4f6fb; --card: #ffffff; --line: #e2e6ef; --text: #0b1640; --muted: #5b6478;
  --green: #0f7a43; --red: #b42318; --amber: #a15c00; --chip: #eef2ff;
  --radius: 12px; --shadow: 0 1px 2px rgba(11,22,64,.06), 0 4px 16px rgba(11,22,64,.05);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text); font-size: 15px;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--blue); }
h1 { font-size: 24px; margin: 0 0 4px; } h2 { font-size: 18px; margin: 0 0 12px; } h3 { font-size: 15px; margin: 0 0 8px; }
.muted { color: var(--muted); } .small { font-size: 13px; } .center { text-align: center; padding: 48px 16px; }
.pos { color: var(--green); } .neg { color: var(--red); } .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Top bar */
.top { background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.top-in { max-width: 1180px; margin: 0 auto; display: flex; align-items: center; gap: 16px; padding: 10px 16px; }
.top img { height: 34px; }
.top nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.top nav a { text-decoration: none; color: var(--muted); padding: 8px 12px; border-radius: 8px; font-weight: 600; }
.top nav a.on, .top nav a:hover { color: var(--blue); background: var(--chip); }
.top .right { display: flex; gap: 8px; align-items: center; }
main { max-width: 1180px; margin: 0 auto; padding: 24px 16px 64px; }

/* Cards and layout */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 16px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.grid { display: grid; gap: 16px; margin-bottom: 16px; }
.grid > .card { margin-bottom: 0; }
.g2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.g4 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }

/* Buttons and inputs */
button, .btn { font: inherit; font-weight: 600; border: 1px solid var(--line); background: var(--card); color: var(--text); padding: 8px 14px; border-radius: 8px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
button:hover, .btn:hover { border-color: var(--blue-2); }
button.primary, .btn.primary { background: var(--blue); color: #fff; border-color: var(--blue); }
button.primary:hover { background: #17338f; }
button.gold { background: var(--gold); border-color: var(--gold); color: #fff; }
button.danger { color: var(--red); }
button.link { border: 0; background: none; color: var(--blue); padding: 4px 6px; }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { font: inherit; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #fff; color: var(--text); min-width: 0; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--blue-2); outline-offset: 1px; }
textarea { width: 100%; min-height: 90px; }
label { display: grid; gap: 4px; font-size: 13px; font-weight: 600; color: var(--muted); }
form.stack { display: grid; gap: 12px; }
.form-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 10px 14px; text-decoration: none; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.on { color: var(--blue); border-bottom-color: var(--blue); }
.badge { display: inline-block; min-width: 20px; padding: 1px 7px; border-radius: 99px; background: var(--gold); color: #fff; font-size: 12px; font-weight: 700; text-align: center; }
.pill { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--chip); color: var(--blue); }
.pill.ok { background: #e7f6ee; color: var(--green); } .pill.warn { background: #fff4e0; color: var(--amber); } .pill.bad { background: #fdecea; color: var(--red); }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 8px; border-bottom: 1px solid var(--line); }
td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr.sub td { font-weight: 700; } tr.total td { font-weight: 800; font-size: 16px; border-top: 2px solid var(--navy); }
tr.sec td { color: var(--blue); font-weight: 700; padding-top: 16px; border-bottom: 0; }
td.indent { padding-left: 24px; }
.desc { max-width: 420px; overflow: hidden; text-overflow: ellipsis; }
.conf { font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 6px; }
.conf.hi { background: #e7f6ee; color: var(--green); } .conf.mid { background: #fff4e0; color: var(--amber); } .conf.lo { background: #fdecea; color: var(--red); } .conf.rule { background: var(--chip); color: var(--blue); }

/* KPI tiles */
.kpi { padding: 18px; }
.kpi .label { font-size: 13px; color: var(--muted); font-weight: 600; }
.kpi .value { font-size: 28px; font-weight: 800; margin: 4px 0; font-variant-numeric: tabular-nums; }
.kpi .delta { font-size: 13px; font-weight: 600; }
.summary { border-left: 4px solid var(--gold); background: #fffbef; }
.summary p { margin: 0; line-height: 1.55; font-size: 16px; }

/* Bars */
.hbar { display: grid; grid-template-columns: minmax(120px, 1fr) 2fr auto; gap: 10px; align-items: center; margin: 8px 0; font-size: 14px; }
.hbar .track { background: var(--chip); border-radius: 6px; height: 14px; overflow: hidden; }
.hbar .fill { height: 100%; background: linear-gradient(90deg, var(--blue), var(--blue-2)); border-radius: 6px; }
.chart svg { width: 100%; height: auto; display: block; }
.legend { display: flex; gap: 16px; font-size: 13px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

/* Auth screens */
.auth { max-width: 420px; margin: 8vh auto; padding: 0 16px; }
.auth .logo { display: block; margin: 0 auto 24px; height: 56px; }
.drop { border: 2px dashed var(--line); border-radius: var(--radius); padding: 28px; text-align: center; color: var(--muted); cursor: pointer; }
.drop.over { border-color: var(--blue-2); background: var(--chip); }
.notice { padding: 12px 14px; border-radius: 8px; background: var(--chip); color: var(--navy); margin-bottom: 12px; }
.notice.warn { background: #fff4e0; } .notice.bad { background: #fdecea; color: var(--red); }
.secret { font-family: ui-monospace, Menlo, monospace; font-size: 16px; background: #fffbef; border: 1px solid var(--gold-2); padding: 10px; border-radius: 8px; user-select: all; }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--navy); color: #fff; padding: 10px 18px; border-radius: 10px; opacity: 0; transition: opacity .2s; pointer-events: none; max-width: calc(100% - 32px); z-index: 50; }
#toast.show { opacity: 1; } #toast.err { background: var(--red); }

@media (max-width: 640px) {
  .top-in { flex-wrap: wrap; } .top img { height: 28px; }
  .kpi .value { font-size: 22px; } main { padding: 16px 12px 48px; }
  .hbar { grid-template-columns: 1fr auto; } .hbar .track { grid-column: 1 / -1; grid-row: 2; }
  .hide-sm { display: none; }
  .top nav { order: 3; flex-basis: 100%; flex-wrap: nowrap; overflow-x: auto; } .top nav a { white-space: nowrap; padding: 6px 10px; }
  .top .right { margin-left: auto; }
  table.lines thead { display: none; }
  table.lines tr.ln { display: grid; grid-template-columns: 1fr 1fr auto; gap: 6px; padding: 10px 0; border-bottom: 1px solid var(--line); }
  table.lines tr.ln td { padding: 0; border: 0; width: auto !important; align-self: center; }
  table.lines tr.ln td:first-child { grid-column: 1 / -1; }
  table.lines tr.ln td.amt { grid-column: 1 / 3; text-align: left; font-weight: 700; }
}
@media print {
  .top, .noprint, .tabs, .cmp, .delta { display: none !important; } body { background: #fff; } .card { box-shadow: none; border: 0; }
  @page { size: letter; margin: 0.5in; }
  table { page-break-inside: auto; } tr { page-break-inside: avoid; }
}
.print-only { display: none; }
@media print { .print-only { display: flex !important; } }
.stamp-row { gap: 24px; justify-content: space-between; align-items: stretch; margin-top: 28px; page-break-inside: avoid; color: #000; }
.stamp-row .sign { flex: 1; display: flex; flex-direction: column; justify-content: space-between; max-width: 260px; }
.stamp-row .sign .ln { border-bottom: 1px solid #000; margin-top: 36px; } .stamp-row .sign .ln.short { width: 60%; }
.stamp { border: 1.5px solid #000; border-radius: 10px; padding: 10px 14px; width: 300px; text-align: center; color: #000; font-family: Arial, Helvetica, sans-serif; text-transform: uppercase; }
.stamp img { height: 46px; max-width: 100%; display: block; margin: 0 auto 6px; filter: grayscale(1) contrast(10); }
.stamp .p { font-weight: 800; font-size: 16px; } .stamp .s { font-size: 9.5px; } .stamp .l { font-weight: 700; font-size: 11px; }
.stamp hr { border: 0; border-top: 1px solid #000; margin: 6px 0; }
tr.click { cursor: pointer; } tr.click:hover td { background: var(--chip); }
table.lines td { padding: 6px 4px; } table.lines input { padding: 7px 8px; }
a.pill { text-decoration: none; }
button.usem { white-space: nowrap; }
table.lines { table-layout: fixed; width: 100%; }
table.lines input:not([type=checkbox]) { width: 100%; box-sizing: border-box; min-width: 0; }
[hidden] { display: none !important; }
.stamp-preview .stamp-row { display: flex; margin-top: 8px; }
/* Printed reports fit on one page: tighter rows and spacing on paper. */
@media print {
  html, body { font-size: 11px; } main { padding: 0 !important; max-width: none !important; }
  .card { padding: 6px 0 !important; margin: 0 0 6px !important; } .head { margin-bottom: 6px !important; } h1 { font-size: 18px !important; margin: 0 !important; }
  table td, table th { padding-top: 2px !important; padding-bottom: 2px !important; }
  .summary p { margin: 2px 0 !important; } .stamp-row { margin-top: 14px; }
}
