:root {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-alt: #f7f8fb;
  --line: #e2e6ee;
  --ink: #18202f;
  --ink-muted: #5d6779;
  --ink-faint: #98a1b2;
  --accent: #1f5fd1;
  --accent-soft: #e8effc;
  --positive: #18794e;
  --positive-soft: #e6f4ec;
  --warning: #9a5b00;
  --warning-soft: #fdf3e1;
  --danger: #c0352b;
  --danger-soft: #fdecea;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f131a;
    --surface: #171c25;
    --surface-alt: #1d2330;
    --line: #2a3242;
    --ink: #e8ecf3;
    --ink-muted: #a3adbf;
    --ink-faint: #6b7588;
    --accent: #6f9ef2;
    --accent-soft: #1d2a44;
    --positive: #4cc48b;
    --positive-soft: #15302a;
    --warning: #f0b24f;
    --warning-soft: #33280f;
    --danger: #f07a70;
    --danger-soft: #3a1c1a;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 'Segoe UI', system-ui, -apple-system, sans-serif;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 600; }
h2 { font-size: 16px; font-weight: 600; }
.muted { color: var(--ink-muted); }
.faint { color: var(--ink-faint); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }
.mono { font-family: Consolas, 'Courier New', monospace; font-size: 13px; }
.hidden { display: none !important; }
.spacer { flex: 1; }

/* ---------------------------------------------------------------- shell */
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 0 24px; height: 56px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: -0.01em; color: var(--ink); }
.brand:hover { text-decoration: none; }
.login img { display: block; margin-bottom: 12px; }
.brand span { font-weight: 400; color: var(--ink-muted); margin-left: 6px; }
.topbar .spacer { flex: 1; }
main { max-width: 1180px; margin: 0 auto; padding: 24px; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .spacer { flex: 1; }

/* ---------------------------------------------------------------- parts */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card.pad { padding: 20px; }
.card + .card { margin-top: 16px; }
.card-head { display: flex; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.card-head .spacer { flex: 1; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: 6px;
  border: 1px solid var(--line); background: var(--surface); cursor: pointer;
  font-weight: 500; white-space: nowrap;
}
.btn:hover { background: var(--surface-alt); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.small { height: 30px; padding: 0 10px; font-size: 13px; }

.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 13px; font-weight: 500; color: var(--ink-muted); }
.field .error { color: var(--danger); font-size: 13px; }
.field .hint { color: var(--ink-faint); font-size: 12px; }
input[type='text'], input[type='email'], input[type='password'], input[type='number'], input[type='date'], input[type='search'], select, textarea {
  height: 38px; padding: 0 10px; border-radius: 6px;
  border: 1px solid var(--line); background: var(--surface); width: 100%;
}
textarea { height: auto; min-height: 76px; padding: 8px 10px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.grid { display: grid; gap: 14px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 720px) { .grid.two, .grid.three { grid-template-columns: 1fr; } }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { padding: 14px 16px; }
.stat .label { font-size: 13px; color: var(--ink-muted); }
.stat .value { font-size: 24px; font-weight: 600; margin-top: 2px; }

.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tab { height: 32px; padding: 0 12px; border-radius: 6px; border: 1px solid transparent; background: none; cursor: pointer; color: var(--ink-muted); }
.tab.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.toolbar { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.toolbar input[type='search'] { max-width: 300px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 16px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-muted); background: var(--surface-alt); }
tr:last-child td { border-bottom: none; }
tbody tr.link { cursor: pointer; }
tbody tr.link:hover td { background: var(--surface-alt); }
td.right, th.right { text-align: right; }
.table-wrap { overflow-x: auto; }
.empty { padding: 40px 20px; text-align: center; color: var(--ink-muted); }

.badge { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.active { background: var(--positive-soft); color: var(--positive); }
.badge.due { background: var(--warning-soft); color: var(--warning); }
.badge.lapsed, .badge.suspended { background: var(--danger-soft); color: var(--danger); }
.badge.neutral { background: var(--surface-alt); color: var(--ink-muted); }

.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px 24px; }
.facts .label { font-size: 12px; color: var(--ink-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.facts .value { margin-top: 2px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.notice { padding: 12px 14px; border-radius: 6px; margin-bottom: 16px; }
.notice.danger { background: var(--danger-soft); color: var(--danger); }
.notice.warning { background: var(--warning-soft); color: var(--warning); }

.secret {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 6px;
  background: var(--surface-alt); border: 1px dashed var(--line); word-break: break-all;
}
.secret code { flex: 1; font-family: Consolas, 'Courier New', monospace; font-size: 15px; }

.history li { padding: 10px 0; border-bottom: 1px solid var(--line); display: flex; gap: 12px; }
.history li:last-child { border-bottom: none; }
.history { list-style: none; margin: 0; padding: 0 20px; }
.history .when { width: 150px; flex-shrink: 0; color: var(--ink-muted); font-size: 13px; }

.login { max-width: 380px; margin: 12vh auto 0; }
.login h1 { margin-bottom: 4px; }

dialog { border: none; border-radius: 10px; padding: 0; width: min(520px, calc(100vw - 32px)); background: var(--surface); color: var(--ink); box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25); }
dialog::backdrop { background: rgba(15, 20, 30, 0.45); }
dialog .head { padding: 16px 20px; border-bottom: 1px solid var(--line); }
dialog .body { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
dialog .foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--surface); padding: 10px 16px; border-radius: 8px; z-index: 50;
}

/* ---------------------------------------------------------------- insights */
.topnav { margin-left: 16px; }
.topnav .tab { display: inline-flex; align-items: center; text-decoration: none; }
.section-title { margin: 8px 0 10px; font-size: 14px; color: var(--ink-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.card-body { padding: 16px 20px; }
.chart { width: 100%; height: auto; display: block; margin-top: 8px; }
.chart .bar { fill: var(--accent); }
.chart .bar:hover { fill: var(--positive); }
.chart .axis { fill: var(--ink-faint); font-size: 11px; }
.services { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 10px; margin-top: 10px; }
.service { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--line); border-radius: 6px; cursor: pointer; }
.service span { display: flex; flex-direction: column; }
.grid.two > .card { margin-top: 16px; }
/* Cards side by side line up; the gap between stacked cards is only for stacks. */
.stats > .card + .card, .grid > .card + .card, .services > .service { margin-top: 0; }
.chart { max-height: 220px; }

/* Narrow windows: the top bar stays one line, the tabs scroll sideways. */
.brand, .topnav .tab { white-space: nowrap; flex-shrink: 0; }
.topnav { flex-wrap: nowrap; overflow-x: auto; min-width: 0; }
@media (max-width: 760px) {
  .topbar { padding: 0 12px; gap: 8px; }
  .topnav { margin-left: 0; }
  .brand span, #who { display: none; }
  main { padding: 16px; }
}
