:root {
  --red: #c8102e;
  --red-dark: #9e0c24;
  --ink: #1d2433;
  --muted: #687082;
  --line: #e2e5ec;
  --bg: #f5f6f9;
  --card: #fff;
  --ok: #17803d;
  --warn: #b45309;
  --bad: #b91c1c;
  --cell: #ddf8fb;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 15px/1.45 var(--font); color: var(--ink); background: var(--bg); }
a { color: var(--red); }
h1 { font-size: 1.5rem; margin: 0 0 .25rem; }
h2 { font-size: 1.15rem; margin: 0 0 .5rem; }
h3 { font-size: 1rem; margin: 1rem 0 .4rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.num, td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.neg { color: var(--bad); }
.hidden { display: none !important; }

/* top bar */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 1rem; padding: .5rem 1.25rem; background: #fff; border-bottom: 3px solid var(--red); }
.brand { display: flex; align-items: center; gap: .6rem; text-decoration: none; color: var(--ink); }
.brand img { width: 34px; height: 35px; }
.brand span { display: flex; flex-direction: column; line-height: 1.1; }
.brand small { color: var(--muted); }
nav { display: flex; gap: .15rem; flex: 1; flex-wrap: wrap; }
nav a { padding: .45rem .7rem; border-radius: 8px; color: var(--ink); text-decoration: none; font-weight: 500; }
nav a:hover { background: var(--bg); }
nav a.active { background: var(--red); color: #fff; }
nav a .badge { margin-left: .3rem; }
.who { font-size: .85rem; color: var(--muted); text-align: right; }
.menu-toggle { display: none; }
@media (max-width: 900px) {
  .topbar { flex-wrap: wrap; }
  .menu-toggle { display: block; margin-left: auto; }
  nav { display: none; flex-basis: 100%; flex-direction: column; }
  body.nav-open nav { display: flex; }
  .who { display: none; }
}

main { max-width: 1200px; margin: 0 auto; padding: 1.5rem 1.25rem 4rem; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-head .actions { margin: 0; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.15rem; margin-bottom: 1rem; }
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.kpi { display: block; text-decoration: none; color: inherit; }
.kpi .label { color: var(--muted); font-size: .85rem; }
.kpi .value { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi.attention { border-color: var(--warn); box-shadow: inset 4px 0 0 var(--warn); }
.kpi.good { box-shadow: inset 4px 0 0 var(--ok); }

/* tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: .45rem .55rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: #fafbfd; }
tfoot td { font-weight: 700; border-top: 2px solid var(--ink); }

.badge { display: inline-block; padding: .05rem .5rem; border-radius: 999px; font-size: .75rem; font-weight: 600; background: var(--line); color: var(--ink); white-space: nowrap; }
.badge.cleared, .badge.sent, .badge.ok { background: #dcfce7; color: var(--ok); }
.badge.outstanding, .badge.awaiting_cosign, .badge.warn { background: #fef3c7; color: var(--warn); }
.badge.planned, .badge.draft { background: #e0e7ff; color: #3730a3; }
.badge.void, .badge.bad { background: #fee2e2; color: var(--bad); }
.badge.count { background: var(--red); color: #fff; }

/* forms */
form .row, .row { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
label { display: flex; flex-direction: column; gap: .2rem; font-size: .85rem; font-weight: 600; color: #3b4252; margin-bottom: .6rem; }
label.check { flex-direction: row; align-items: center; gap: .4rem; font-weight: 500; }
input, select, textarea { font: inherit; padding: .45rem .55rem; border: 1px solid #c9ceda; border-radius: 7px; background: #fff; color: var(--ink); min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid #f4a3b0; border-color: var(--red); }
input.money { text-align: right; font-variant-numeric: tabular-nums; }
input[type=checkbox] { width: 1rem; height: 1rem; }
.hint { font-weight: 400; color: var(--muted); font-size: .8rem; }

button, .button { font: inherit; font-weight: 600; padding: .5rem .95rem; border-radius: 8px; border: 1px solid var(--red); background: var(--red); color: #fff; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: .35rem; }
button:hover, .button:hover { background: var(--red-dark); }
button:disabled { opacity: .55; cursor: progress; }
button.secondary, .button.secondary { background: #fff; color: var(--ink); border-color: #c9ceda; }
button.secondary:hover { background: var(--bg); }
button.danger { background: #fff; color: var(--bad); border-color: #f1b5b5; }
button.small { padding: .25rem .55rem; font-size: .82rem; }
button.link { background: none; border: none; color: var(--red); padding: 0; font-weight: 500; }
button.icon { background: none; border: none; color: var(--ink); font-size: 1.4rem; padding: .1rem .4rem; }
.actions { display: flex; gap: .5rem; justify-content: flex-end; flex-wrap: wrap; margin-top: .75rem; }
.toolbar { display: flex; gap: .6rem; align-items: flex-end; flex-wrap: wrap; margin-bottom: .75rem; }
.toolbar label { margin: 0; }

/* drop zone */
.dropzone { border: 2px dashed #c9ceda; border-radius: var(--radius); padding: 1.1rem; text-align: center; cursor: pointer; background: #fbfcfe; transition: .15s; }
.dropzone:hover, .dropzone.over { border-color: var(--red); background: #fff5f6; }
.dropzone .dz-icon { font-size: 1.4rem; color: var(--red); }

.files { list-style: none; padding: 0; margin: .5rem 0; }
.files li { display: flex; align-items: center; gap: .5rem; padding: .3rem 0; border-bottom: 1px solid var(--line); }
.files li a { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* modal */
dialog.modal { border: none; border-radius: 14px; padding: 0; width: min(560px, 94vw); max-height: 92vh; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog.modal.wide { width: min(900px, 96vw); }
dialog::backdrop { background: rgba(20, 24, 35, .45); }
dialog header { display: flex; justify-content: space-between; align-items: center; padding: .8rem 1.1rem; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: #fff; z-index: 1; }
dialog header h2 { margin: 0; }
.modal-body { padding: 1rem 1.1rem 1.1rem; }

/* signature pad */
.sigwrap { position: relative; border: 1px solid #c9ceda; border-radius: 8px; background: #fff; margin: .5rem 0; }
.sigpad { width: 100%; height: auto; display: block; cursor: crosshair; }
.sig-line { position: absolute; left: 8%; right: 8%; bottom: 22%; border-top: 1px solid #c9ceda; font-size: .7rem; color: var(--muted); padding-top: 2px; pointer-events: none; }
.sigwrap .link { position: absolute; right: .5rem; top: .35rem; }
.sig-preview { max-height: 46px; max-width: 200px; }

/* checks list */
.checks { list-style: none; padding: 0; margin: 0; }
.checks li { padding: .4rem .6rem; border-radius: 7px; margin-bottom: .3rem; display: flex; gap: .5rem; }
.checks li.ok { background: #f0fdf4; color: var(--ok); }
.checks li.fail { background: #fef2f2; color: var(--bad); }
.checks li.warn { background: #fffbeb; color: var(--warn); }

.form-lines td { padding: .25rem .5rem; }
.form-lines td.line { color: var(--muted); width: 3.5rem; }
.form-lines td.val { background: var(--cell); }
.form-lines tr.total td { font-weight: 700; }

.preview-frame { width: 100%; height: 360px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.pill-row { display: flex; gap: .4rem; flex-wrap: wrap; }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 800px) { .split { grid-template-columns: 1fr; } }

#toasts { position: fixed; bottom: 1rem; right: 1rem; display: flex; flex-direction: column; gap: .5rem; z-index: 100; }
.toast { background: var(--ink); color: #fff; padding: .65rem .9rem; border-radius: 8px; max-width: 420px; box-shadow: 0 6px 20px rgba(0,0,0,.2); }
.toast.error { background: var(--bad); }
.toast.warn { background: var(--warn); }

.empty { text-align: center; padding: 2rem 1rem; color: var(--muted); }
.callout { border-left: 4px solid var(--warn); background: #fffbeb; padding: .6rem .8rem; border-radius: 6px; margin: .5rem 0 1rem; }
.callout.info { border-color: #3b82f6; background: #eff6ff; }
.callout.bad { border-color: var(--bad); background: #fef2f2; }

/* sign-in pages */
.auth-page { display: flex; min-height: 100vh; align-items: center; justify-content: center; padding: 1rem; border-top: 4px solid var(--red); }
.auth-card { width: min(420px, 100%); padding: 1.6rem 1.6rem 1.2rem; }
.auth-card h1 { font-size: 1.25rem; margin: 1rem 0 .6rem; }
.auth-brand { display: flex; gap: .7rem; align-items: center; }
.auth-brand img { width: 42px; }
button.wide, .button.wide { width: 100%; justify-content: center; margin-top: .3rem; }
.or { display: flex; align-items: center; gap: .6rem; color: var(--muted); font-size: .85rem; margin: 1rem 0 .6rem; }
.or::before, .or::after { content: ""; flex: 1; border-top: 1px solid var(--line); }
.google { gap: .6rem; }
.foot { margin-top: 1rem; text-align: center; }
.qr { width: 200px; margin: .5rem auto; }
.qr svg { width: 100%; height: auto; }
.secret, .codes { display: block; font: 600 .95rem/1.6 ui-monospace, Consolas, monospace; background: var(--bg); padding: .6rem .8rem; border-radius: 8px; letter-spacing: .05em; }
.codes { columns: 2; }
.who .link { font-size: .8rem; }
