:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dfe3e8;
  --text: #12161c;
  --muted: #626d7d;
  --accent: #2f5bd8;
  --accent-soft: #e8edfc;
  --ok: #1a7f4b;
  --ok-soft: #e2f4ea;
  --warn: #9a6400;
  --warn-soft: #fdf1dc;
  --bad: #b3261e;
  --bad-soft: #fceceb;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --surface: #171b21;
    --surface-2: #1e232b;
    --border: #2b323c;
    --text: #e7eaee;
    --muted: #98a3b3;
    --accent: #7aa0ff;
    --accent-soft: #1c2740;
    --ok: #5fd39b;
    --ok-soft: #12291f;
    --warn: #e5b567;
    --warn-soft: #2b2415;
    --bad: #f08b84;
    --bad-soft: #2e1a19;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- layout ---------- */
header.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.topbar .inner {
  max-width: 1180px; margin: 0 auto; padding: 0 20px;
  display: flex; align-items: center; gap: 16px; min-height: 56px; flex-wrap: wrap;
}
.brand { font-weight: 650; letter-spacing: -.01em; color: var(--text); white-space: nowrap; }
.brand:hover { text-decoration: none; }
nav.main { display: flex; gap: 14px; flex: 1; flex-wrap: wrap; min-width: 0; }
nav.main a { color: var(--muted); font-size: 13.5px; font-weight: 500; white-space: nowrap; }
nav.main a.on, nav.main a:hover { color: var(--text); text-decoration: none; }
.whoami { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 10px; }

main { max-width: 1180px; margin: 0 auto; padding: 26px 20px 80px; }

h1 { font-size: 21px; margin: 0 0 4px; letter-spacing: -.015em; }
h2 { font-size: 15px; margin: 0 0 12px; letter-spacing: -.005em; }
.sub { color: var(--muted); font-size: 13.5px; margin: 0 0 22px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px; margin-bottom: 18px;
}
.card.tight { padding: 0; overflow: hidden; }
.card.tight h2 { padding: 16px 18px 0; }
.grid { display: grid; gap: 18px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid.stats { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }

.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.stat .k { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.stat .v { font-size: 22px; font-weight: 620; margin-top: 4px; letter-spacing: -.02em; }

/* ---------- tables ---------- */
.scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; background: var(--surface-2); white-space: nowrap; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tfoot td { font-weight: 620; background: var(--surface-2); border-top: 2px solid var(--border); }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }

/* ---------- badges ---------- */
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; white-space: nowrap;
}
.badge.draft { background: var(--surface-2); color: var(--muted); }
.badge.submitted { background: var(--warn-soft); color: var(--warn); }
.badge.returned { background: var(--bad-soft); color: var(--bad); }
.badge.approved { background: var(--ok-soft); color: var(--ok); }
.badge.you { background: var(--accent-soft); color: var(--accent); }

/* ---------- forms ---------- */
label { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
/* Every text-ish input, including <input> with no type attribute. */
input:not([type=checkbox]):not([type=radio]):not([type=button]):not([type=submit]),
select, textarea {
  width: 100%; padding: 8px 10px; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
textarea { min-height: 70px; resize: vertical; }
.field { margin-bottom: 12px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.row > .field { flex: 1 1 160px; margin-bottom: 0; }

button, .btn {
  font: inherit; font-weight: 550; font-size: 14px; cursor: pointer;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); white-space: nowrap;
}
button:hover, .btn:hover { background: var(--surface-2); text-decoration: none; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { filter: brightness(1.07); }
button.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
button.danger { color: var(--bad); border-color: var(--border); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.link { border: none; background: none; color: var(--accent); padding: 4px 0; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
form.inline { display: inline; }

/* ---------- notices ---------- */
.notice { padding: 11px 14px; border-radius: 8px; margin-bottom: 16px; font-size: 14px; border: 1px solid transparent; }
.notice.ok { background: var(--ok-soft); color: var(--ok); border-color: var(--ok); }
.notice.err { background: var(--bad-soft); color: var(--bad); border-color: var(--bad); }
.notice.info { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.notice.warn { background: var(--warn-soft); color: var(--warn); border-color: var(--warn); }

/* ---------- allocation editor ---------- */
.factor-input { width: 92px; text-align: right; font-variant-numeric: tabular-nums; }
.totalbar {
  position: sticky; bottom: 0; background: var(--surface);
  border-top: 1px solid var(--border); padding: 12px 18px;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
}
.totalbar .readout { font-size: 15px; font-weight: 620; font-variant-numeric: tabular-nums; }
.totalbar .readout.good { color: var(--ok); }
.totalbar .readout.bad { color: var(--bad); }
.totalbar .spacer { flex: 1; }
.meter { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; width: 160px; }
.meter > i { display: block; height: 100%; background: var(--accent); transition: width .15s ease; }
.meter.good > i { background: var(--ok); }
.meter.bad > i { background: var(--bad); }

/* ---------- login ---------- */
.login-wrap { max-width: 380px; margin: 12vh auto; padding: 0 20px; }
.login-wrap .card { padding: 26px; }
.login-wrap h1 { margin-bottom: 18px; }

.timeline { list-style: none; margin: 0; padding: 0; font-size: 13.5px; }
.timeline li { padding: 9px 0; border-bottom: 1px solid var(--border); }
.timeline li:last-child { border-bottom: none; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px;
       background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }

@media (max-width: 640px) {
  .whoami .email { display: none; }
  main { padding: 18px 14px 60px; }
  .topbar .inner { gap: 10px 14px; padding: 8px 14px; min-height: 0; }
  nav.main { gap: 12px; }
  nav.main a, .whoami { font-size: 13px; }
  .page-head { gap: 10px; }
  .totalbar { padding: 10px 14px; gap: 10px; }
  .meter { width: 90px; }
}
