/* ═══════════════════════════════════════════════════════════
   Tally design system v3 — paper, deep green, brass
   ═══════════════════════════════════════════════════════════ */
:root {
  --paper: #F4F1EA;
  --surface: #FFFFFF;
  --surface-2: #FAF8F2;
  --ink: #0E1F18;
  --text: #16201A;
  --text-body: #222B25;
  --text-muted: #6B756E;
  --text-faint: #8A938C;
  --border: #EAE4D6;
  --border-soft: #F3EFE4;
  --green: #0F6B4F;
  --green-deep: #0C5A42;
  --green-tint: #E4F2EA;
  --gold: #C2A24E;
  --gold-tint: #FBEEDD;
  --positive: #0F6B4F;
  --warning: #9A6A12;
  --negative: #C24E4E;
  --sh: 0 1px 2px rgba(20,30,24,0.03);
  --r: 16px;
  --rs: 10px;
  --rpill: 999px;
  --focus: #0F6B4F;
  font-size: 14px;
}
:root.big { font-size: 17px; }
:root.hc {
  --paper: #fff;
  --text-muted: #333;
  --text-faint: #555;
  --border: #999;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: 'Hanken Grotesk', system-ui, sans-serif;
  color: var(--text-body);
  background: var(--paper);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
::selection { background: var(--green); color: #fff; }
.mono { font-family: ui-monospace, 'Cascadia Code', monospace; }
h1, h2, h3 {
  font-family: 'Newsreader', Georgia, serif;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.02em;
  line-height: 1.15;
  color: var(--text);
}
.num { font-variant-numeric: tabular-nums; }
button { font-family: inherit; cursor: pointer; font-size: inherit; border: none; background: none; }
a { color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
.skip {
  position: absolute; left: -999px; top: 8px;
  background: #fff; border: 2px solid var(--focus);
  padding: 10px 16px; border-radius: 8px; z-index: 50;
}
.skip:focus { left: 12px; }

/* ── Shell ────────────────────────────────────────────────── */
#app { display: grid; grid-template-columns: 264px 1fr; min-height: 100vh; }

.sidebar {
  background: var(--ink);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  border-right: 1px solid #0A1812;
}

.brand {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 26px 24px 22px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.brand-tile {
  width: 42px; height: 42px;
  border-radius: 12px;
  background: linear-gradient(160deg,#1A3A2C,#0B1A13);
  display: flex; align-items: center; justify-content: center;
  border: 1px solid rgba(212,175,95,0.35);
  box-shadow: 0 4px 14px rgba(0,0,0,0.35);
  flex: 0 0 auto;
}
.brand-name {
  font-family: 'Newsreader', serif;
  font-size: 22px; font-weight: 600;
  color: #FBF7EC; letter-spacing: 0.2px; line-height: 1;
}
.brand-sub {
  font-size: 10.5px; letter-spacing: 2.5px;
  color: #6E857A; font-weight: 600; margin-top: 3px;
}

.nav-h {
  font-size: 10.5px; letter-spacing: 2.2px;
  text-transform: uppercase; color: #5C7268;
  font-weight: 700; padding: 18px 10px 8px 24px;
}
.nav { padding: 0 14px 24px; }
.nav a {
  display: flex; align-items: center; gap: 12px;
  min-height: 40px; padding: 9px 12px;
  border-radius: var(--rs); margin-bottom: 2px;
  color: #AFC0B6; text-decoration: none;
  font-size: 13.5px; font-weight: 500;
  transition: background .15s, color .15s;
}
.nav a:hover { background: rgba(255,255,255,0.05); color: #EAF1ED; }
.nav a[aria-current="page"] {
  background: linear-gradient(100deg,#0F6B4F,#0C5A42);
  color: #FBF7EC; font-weight: 700;
}
.nav a .ic {
  width: 17px; height: 17px;
  display: inline-flex; align-items: center; justify-content: center;
  flex: 0 0 auto;
}

.side-foot {
  margin-top: auto;
  padding: 14px 18px;
  border-top: 1px solid rgba(255,255,255,0.06);
  display: flex; align-items: center; gap: 11px;
  color: #647A70; font-size: 11px; line-height: 1.5;
}
.side-foot-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: #234636; color: #CFE6DB;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; flex: 0 0 auto;
}

/* ── Main ─────────────────────────────────────────────────── */
.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: rgba(244,241,234,0.88);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding: 22px 40px 18px;
  display: flex; align-items: flex-end;
  justify-content: space-between; gap: 24px; flex-wrap: wrap;
}
.topbar-eyebrow {
  font-size: 11.5px; letter-spacing: 1.8px;
  color: var(--green); font-weight: 700;
  text-transform: uppercase; margin-bottom: 5px;
}
.topbar h1 { font-size: 28px; letter-spacing: -0.3px; }
.topbar .sub { font-size: 13px; color: var(--text-muted); margin-top: 4px; }
.toptools { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; flex: 0 0 auto; }
.tbtn {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 34px; padding: 5px 12px;
  border: 1px solid var(--border); background: var(--surface);
  border-radius: var(--rs); font-size: 12.5px; font-weight: 500;
  color: var(--text-body); text-decoration: none;
  transition: background .15s;
}
.tbtn:hover { background: var(--surface-2); }
.acct { display: flex; align-items: center; gap: 10px; padding-left: 8px; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: #234636; color: #CFE6DB;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 12px;
}
.acct .nm { font-size: 12.5px; font-weight: 600; line-height: 1.3; color: var(--text); }
.acct .rl { font-size: 11px; color: var(--text-muted); }
select {
  font-family: inherit; font-size: 12.5px; min-height: 32px;
  border: 1px solid var(--border); border-radius: var(--rs);
  padding: 4px 10px; background: var(--surface); color: var(--text-body); font-weight: 500;
}
/* Text-like inputs match the select look (rounded, same height). Placed before
   the login/daterange/chipsel rules so those more-specific styles still win. */
input[type="text"], input[type="password"], input[type="number"],
input[type="email"], input[type="search"] {
  font-family: inherit; font-size: 12.5px; min-height: 32px;
  border: 1px solid var(--border); border-radius: var(--rs);
  padding: 4px 10px; background: var(--surface); color: var(--text-body); font-weight: 500;
  box-sizing: border-box;
}
input[type="text"]:focus, input[type="password"]:focus, input[type="number"]:focus,
input[type="email"]:focus, input[type="search"]:focus {
  border-color: var(--green); outline: none; box-shadow: 0 0 0 3px rgba(15,107,79,0.14);
}
.content { padding: 30px 40px 56px; }

/* ── Sync banner ──────────────────────────────────────────── */
.sync {
  display: flex; align-items: center; gap: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--green);
  border-radius: var(--r);
  padding: 14px 20px; margin-bottom: 24px;
  flex-wrap: wrap; box-shadow: var(--sh);
}
.sync.stale { border-left-color: var(--negative); }
.sync .badge {
  width: 38px; height: 38px; border-radius: 50%; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
  background: var(--green-tint); color: var(--green);
}
.sync.stale .badge { background: #FEF0F0; color: var(--negative); }
.sync .lead { font-size: 14px; font-weight: 600; color: var(--text); }
.sync .meta { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }
.sync .meta .when { font-weight: 600; color: var(--text); }
.sync .right { margin-left: auto; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.sync .next { font-size: 11.5px; color: var(--text-muted); text-align: right; }
.sync .next b { display: block; color: var(--text); font-size: 13px; }

/* ── Filters bar ───────────────────────────────────────────── */
.filters {
  display: flex; gap: 8px; flex-wrap: wrap;
  align-items: center; margin-bottom: 24px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r); padding: 10px 16px; box-shadow: var(--sh);
}

/* Period toggle */
.seg {
  display: flex; flex-wrap: wrap; gap: 2px;
  background: #EBE6D9; border-radius: var(--rs); padding: 3px;
}
.seg button {
  min-height: 30px; padding: 4px 12px; border: none; background: transparent;
  font-size: 12px; font-weight: 600; color: var(--text-muted);
  border-radius: 8px; transition: all .15s; white-space: nowrap;
}
.seg button:hover { color: var(--text); }
.seg button[aria-pressed="true"] {
  background: var(--surface); color: var(--ink);
  box-shadow: 0 1px 3px rgba(20,30,24,0.12);
}
/* Custom date range inputs */
.daterange {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 34px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--rs); padding: 3px 10px;
}
.daterange .lbl { color: var(--text-faint); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.8px; }
.daterange input[type=date] {
  border: none; background: transparent; font-size: 12.5px;
  color: var(--ink); font-family: inherit; padding: 2px 4px;
  cursor: pointer;
}
.daterange input[type=date]:focus { outline: 2px solid var(--focus); border-radius: 4px; }
.chipsel {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 34px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--rs); padding: 3px 10px;
}
.chipsel .lbl { color: var(--text-faint); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.8px; }
.chipsel select { border: none; min-height: 26px; padding: 2px 6px; background: transparent; font-size: 12.5px; }

/* Multi-select dropdown (terminals) — <details> with a checkbox panel */
.multisel {
  position: relative; display: inline-flex; align-items: center;
  min-height: 34px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--rs); padding: 3px 10px;
}
.multisel > summary { list-style: none; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; font-size: 12.5px; }
.multisel > summary::-webkit-details-marker { display: none; }
.multisel > summary::after { content: "▾"; color: var(--text-faint); font-size: 10px; }
.multisel .lbl { color: var(--text-faint); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.8px; }
.multisel .ms-val { font-weight: 600; color: var(--text-body); }
.multisel[open] > summary::after { content: "▴"; }
.ms-panel {
  position: absolute; top: calc(100% + 4px); left: 0; z-index: 30;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--rs);
  box-shadow: var(--sh); padding: 8px; min-width: 190px; max-height: 280px; overflow: auto;
  display: flex; flex-direction: column; gap: 3px;
}
.ms-panel label { display: flex; align-items: center; gap: 8px; font-size: 12.5px; white-space: nowrap; padding: 3px 4px; cursor: pointer; }
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  min-height: 34px; border: 1px solid var(--border);
  background: var(--surface); border-radius: var(--rs);
  padding: 5px 14px; font-size: 12.5px; font-weight: 600;
  color: var(--text-body); text-decoration: none; transition: background .15s;
}
.btn:hover { background: var(--surface-2); }
.btn-accent { background: var(--green); border-color: var(--green); color: #fff; }
.btn-accent:hover { background: var(--green-deep); border-color: var(--green-deep); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .4; cursor: not-allowed; pointer-events: none; }
.actions { margin-left: auto; display: flex; gap: 8px; }
/* Dim content while HTMX is fetching */
#report-body.htmx-request { opacity: 0.45; pointer-events: none; transition: opacity 0.1s; }

/* ── KPI cards ─────────────────────────────────────────────── */
.kpis { display: grid; grid-template-columns: repeat(auto-fit,minmax(200px,1fr)); gap: 18px; margin-bottom: 18px; }
.kpi {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r); padding: 20px 20px 18px;
  position: relative; overflow: hidden; box-shadow: var(--sh);
}
.kpi-accent {
  position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: linear-gradient(90deg,#0F6B4F,#2E8B6B);
}
.kpi:nth-child(2) .kpi-accent { background: linear-gradient(90deg,#2E8B6B,#3F7A8C); }
.kpi:nth-child(3) .kpi-accent { background: linear-gradient(90deg,#3F7A8C,#7C6BAE); }
.kpi:nth-child(4) .kpi-accent { background: linear-gradient(90deg,#C2A24E,#A8814A); }
.kpi .k-lbl {
  font-size: 10.5px; letter-spacing: 1.4px; color: var(--text-faint);
  font-weight: 700; text-transform: uppercase; margin-bottom: 13px;
}
.kpi .k-val {
  font-family: 'Newsreader', serif;
  font-size: 33px; font-weight: 600; letter-spacing: -0.5px;
  line-height: 1; color: var(--text);
}
.kpi .k-sub { font-size: 12.5px; margin-top: 8px; color: var(--text-muted); }
.up { color: var(--positive); }
.down { color: var(--negative); }
.flat { color: var(--text-muted); }

/* ── Content cards ─────────────────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r); box-shadow: var(--sh);
  padding: 22px 24px; margin-bottom: 18px;
}
.card h2 { font-size: 19px; margin-bottom: 3px; }
.card .csub { color: var(--text-muted); font-size: 12.5px; margin-bottom: 18px; }
.row2 { display: grid; grid-template-columns: 1.62fr 1fr; gap: 18px; }
@media (max-width: 980px) { .row2 { grid-template-columns: 1fr; } }

/* ── Bar charts ─────────────────────────────────────────────── */
.bar-row {
  display: grid;
  grid-template-columns: 118px 1fr 92px;
  align-items: center; gap: 14px; padding: 8px 0; font-size: 13px;
}
.bar-row .nm { color: var(--text-body); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { display: block; height: 10px; background: #F1EDE2; border-radius: var(--rpill); overflow: hidden; }
.bar-fill { display: block; height: 100%; border-radius: var(--rpill); min-width: 4px; background: var(--green); }
.bar-row .val { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--text); }

/* ── Table ───────────────────────────────────────────────────── */
table { width: 100%; border-collapse: collapse; }
caption { text-align: left; color: var(--text-muted); font-size: 12px; padding-bottom: 12px; }
th {
  text-align: left; color: var(--text-faint); font-weight: 700;
  font-size: 10.5px; letter-spacing: 1.1px; text-transform: uppercase;
  padding: 11px 26px; background: var(--surface-2);
  border-top: 1px solid #EEE9DC; border-bottom: 1px solid #EEE9DC; white-space: nowrap;
}
td {
  padding: 13px 26px; border-bottom: 1px solid var(--border-soft);
  font-size: 13px; color: var(--text-body); font-weight: 500;
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
tbody tr:hover { background: #FBFAF5; }
td.r, th.r { text-align: right; }
tfoot td {
  font-weight: 700; color: #15201A;
  background: var(--surface-2); border-top: 2px solid #D4CFC2;
  border-bottom: none;
}
tfoot tr:hover { background: var(--surface-2); }
.tag {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; padding: 3px 9px; border-radius: var(--rpill); font-weight: 600;
}
.tag.ok { background: var(--green-tint); color: var(--positive); }
.tag.warn { background: var(--gold-tint); color: var(--warning); }
.tag.bad { background: #F4E7E7; color: var(--negative); }
.pill { font-size: 12px; border: 1px solid var(--border); border-radius: var(--rpill); padding: 3px 12px; color: var(--text-muted); font-weight: 500; }
.callout {
  background: var(--gold-tint); border: 1px solid #F0D8A8;
  border-radius: var(--rs); padding: 14px 16px; font-size: 13px;
  color: #5C3B0A; display: flex; gap: 12px; align-items: flex-start; margin-top: 18px;
}
.callout .ic { flex: 0 0 auto; }

/* ── Empty / loading ─────────────────────────────────────────── */
.empty { text-align: center; padding: 52px 20px; }
.empty h2 { font-size: 19px; margin-bottom: 10px; }
.empty p { color: var(--text-muted); max-width: 40ch; margin: 0 auto; font-size: 13px; }
.skel {
  background: linear-gradient(90deg,#EAE4D6 25%,#F4F1EA 37%,#EAE4D6 63%);
  background-size: 400% 100%; border-radius: 6px; height: 14px; margin: 12px 0;
}
@media (prefers-reduced-motion: no-preference) { .skel { animation: sk 1.3s ease infinite; } }
@keyframes sk { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: block; }
.htmx-request.report-body > :not(.htmx-indicator) { display: none; }

/* ── Login ───────────────────────────────────────────────────── */
.login { min-height: 100vh; display: grid; grid-template-columns: 1fr 1.15fr; }
@media (max-width: 880px) { .login { grid-template-columns: 1fr; } .login .art { display: none; } }
.login .art {
  background: var(--ink); color: #AFC0B6;
  padding: 60px 56px; display: flex; flex-direction: column;
  justify-content: space-between; order: 2;
}
.login .art h2 { color: #FBF7EC; font-size: 34px; line-height: 1.2; margin-bottom: 16px; }
.login .art p { color: #5C7268; max-width: 36ch; font-size: 14px; line-height: 1.7; }
.login .art .stamp { font-size: 12px; color: #3A5447; border-top: 1px solid rgba(255,255,255,0.07); padding-top: 18px; }
.login .form { display: flex; align-items: center; justify-content: center; padding: 48px 44px; order: 1; }
.login .box { width: 100%; max-width: 380px; }
.login .box h1 { font-size: 28px; margin-bottom: 6px; }
.login .box > p { color: var(--text-muted); margin: 0 0 28px; font-size: 13.5px; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--text); }
.field input {
  width: 100%; min-height: 46px; padding: 10px 14px;
  border: 1.5px solid var(--border); border-radius: var(--rs);
  font-family: inherit; font-size: 14px; background: var(--surface);
  color: var(--text-body); transition: border-color .15s;
}
.field input:focus { border-color: var(--green); outline: none; box-shadow: 0 0 0 3px rgba(15,107,79,0.14); }
.ms {
  width: 100%; display: flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 46px; border: 1.5px solid var(--border); background: var(--surface);
  border-radius: var(--rs); font-size: 14px; font-weight: 500;
  text-decoration: none; color: var(--text-body);
}
.ms:hover { background: var(--surface-2); }
.sep { display: flex; align-items: center; gap: 12px; color: var(--text-faint); font-size: 12px; margin: 18px 0; }
.sep::before, .sep::after { content: ''; height: 1px; background: var(--border); flex: 1; }
.full { width: 100%; justify-content: center; min-height: 48px; font-size: 14px; }
.mini { font-size: 12px; color: var(--text-faint); text-align: center; margin-top: 20px; line-height: 1.7; }
.err {
  background: #FEF0F0; color: var(--negative);
  border: 1px solid #FECACA; border-radius: var(--rs);
  padding: 10px 14px; font-size: 13px; margin-bottom: 16px;
}

.hidden { display: none !important; }

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 820px) {
  #app { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; flex-direction: row; align-items: center; overflow-x: auto; padding: 8px 12px; gap: 4px; }
  .brand { padding: 6px 10px; border: none; margin: 0; }
  .brand-sub, .nav-h, .side-foot { display: none; }
  .nav { display: flex; gap: 4px; padding: 0; }
  .nav a { min-height: 40px; white-space: nowrap; padding: 8px 12px; margin: 0; }
  .content { padding: 18px 16px 48px; }
  .topbar { padding: 12px 16px; }
}

@media print {
  .sidebar, .topbar, .filters, .sync .right { display: none; }
  .content { padding: 0; max-width: none; }
  .card { box-shadow: none; border: 1px solid #ddd; break-inside: avoid; }
}
