:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #f0eee9;
  --text: #1d1c1a;
  --muted: #6b6760;
  --line: #e2dfd8;
  --accent: #b5541c;
  --accent-text: #ffffff;
  --green: #1f7a4a;
  --green-bg: #e3f3ea;
  --amber: #8a5a00;
  --amber-bg: #fdf0d2;
  --red: #b42318;
  --red-bg: #fde7e4;
  --grey-bg: #ecebe8;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #151412;
    --surface: #1f1d1a;
    --surface-2: #2a2723;
    --text: #f1eee8;
    --muted: #a39d93;
    --line: #36322d;
    --accent: #e07a3c;
    --accent-text: #1a0e05;
    --green: #6fd39c;
    --green-bg: #173326;
    --amber: #f2c25b;
    --amber-bg: #3a2e12;
    --red: #ff8a7a;
    --red-bg: #3d1a16;
    --grey-bg: #2d2a26;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}
.mono { font-family: ui-monospace, 'Cascadia Mono', Consolas, monospace; font-size: 13px; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 19px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; margin-bottom: 10px; }

.logo { font-size: 26px; }
.sub { display: block; margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.badge { white-space: nowrap; font: 12px ui-monospace, Consolas, monospace; padding: 4px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.badge.dev { background: var(--amber-bg); color: var(--amber); }

.banner { padding: 10px 16px; font-size: 14px; }
.banner.warn { background: var(--amber-bg); color: var(--amber); border-bottom: 1px solid var(--line); }

main { max-width: 1200px; padding: 16px 20px 32px; display: grid; gap: 16px; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.stat {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 12px 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  color: var(--muted); font: inherit; cursor: pointer; text-align: left;
}
.stat:hover { border-color: var(--accent); }
.stat .n { font-size: 26px; font-weight: 700; color: var(--text); }
.stat.amber .n { color: var(--amber); }
.stat.red .n { color: var(--red); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tabs button {
  background: none; border: 0; border-bottom: 2px solid transparent; padding: 10px 12px;
  font: inherit; color: var(--muted); cursor: pointer; white-space: nowrap;
}
.tabs button[aria-selected='true'] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.toolbar input[type='search'] { flex: 1 1 260px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  padding: 6px 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface);
  color: var(--text); font: inherit; font-size: 13px; cursor: pointer;
}
.chip[aria-pressed='true'] { background: var(--text); color: var(--surface); border-color: var(--text); }

input, select, textarea {
  width: 100%; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--text); font: inherit;
}
textarea.mono, input.mono { font-size: 13px; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: block; font-size: 13px; color: var(--muted); }
label > input, label > select, label > textarea { margin-top: 4px; color: var(--text); font-size: 15px; }
label.check { display: flex; gap: 8px; align-items: flex-start; color: var(--text); font-size: 14px; }
label.check input { width: auto; margin-top: 3px; }

.form { display: grid; gap: 14px; }
.form fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px 14px; margin: 0; display: grid; gap: 12px; }
.form legend { padding: 0 6px; font-weight: 600; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row { display: flex; gap: 10px; }
.grow { flex: 1; }
.boxed { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-top: 16px; background: var(--surface-2); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface);
  color: var(--text); font: inherit; font-weight: 500; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: 0.55; cursor: progress; }
.actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.actions.left { justify-content: flex-start; }
.icon { background: none; border: 0; font-size: 18px; color: var(--muted); cursor: pointer; padding: 4px 8px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 600; }
th, td { padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:hover { background: var(--surface-2); }
td .secondary { display: block; color: var(--muted); font-size: 12px; }
td.nowrap { white-space: nowrap; }

.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill.active { background: var(--green-bg); color: var(--green); }
.pill.expiring { background: var(--amber-bg); color: var(--amber); }
.pill.expired { background: var(--red-bg); color: var(--red); }
.pill.superseded { background: var(--grey-bg); color: var(--muted); }

.empty { color: var(--muted); text-align: center; padding: 24px 0 8px; margin: 0; }
.hint { margin: 0; color: var(--muted); font-size: 13px; }
.hint.ok { color: var(--green); }
.hint.bad { color: var(--red); }
.error { margin: 0; padding: 9px 12px; border-radius: 8px; background: var(--red-bg); color: var(--red); font-size: 14px; }
.link { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; text-decoration: underline; }

dialog {
  width: min(680px, calc(100vw - 32px)); max-height: calc(100vh - 32px); padding: 0;
  border: 1px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--text);
}
dialog::backdrop { background: rgb(0 0 0 / 0.45); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); }
.dialog-body { padding: 16px; display: grid; gap: 14px; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0; font-size: 14px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; word-break: break-word; }
.history { font-size: 13px; color: var(--muted); display: grid; gap: 4px; }

.result { margin-top: 14px; padding: 12px 14px; border-radius: var(--radius); border: 1px solid var(--line); display: grid; gap: 10px; }
.result.ok { border-color: var(--green); }
.result.bad { border-color: var(--red); }

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%);
  background: var(--text); color: var(--surface); padding: 10px 16px; border-radius: 999px; font-size: 14px;
  box-shadow: 0 6px 20px rgb(0 0 0 / 0.25); max-width: calc(100vw - 32px);
}

/* ---- sign in ---- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(circle at 20% 10%, color-mix(in srgb, var(--accent) 18%, transparent), transparent 55%), var(--bg); }
.auth-card { width: min(400px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 28px 24px; box-shadow: 0 12px 40px rgb(0 0 0 / 0.08); }
.auth-brand { text-align: center; margin-bottom: 22px; }
.auth-brand .wordmark { display: block; width: 190px; height: auto; margin: 0 auto 10px; }
.dark-only { display: none !important; }
@media (prefers-color-scheme: dark) {
  .auth-brand .light-only { display: none !important; }
  .auth-brand .dark-only { display: block !important; }
}
.auth-brand h1 { font-size: 22px; }
.btn.block { width: 100%; padding: 11px 14px; }

/* ---- console layout ---- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--line); padding: 16px 12px; display: flex; flex-direction: column; gap: 18px; position: sticky; top: 0; height: 100vh; }
.side .brand { display: flex; gap: 10px; align-items: center; padding: 0 6px; }
.side .brand strong { display: block; font-size: 16px; }
.side .brand .logo { width: 36px; height: 36px; border-radius: 9px; flex: none; background: #fff; box-shadow: 0 0 0 1px rgb(0 0 0 / 0.1); }
.nav { display: grid; gap: 2px; }
.nav button { display: flex; gap: 10px; align-items: center; width: 100%; text-align: left; padding: 9px 10px; border: 0; border-radius: 8px; background: none; color: var(--muted); font: inherit; cursor: pointer; }
.nav button span { width: 20px; text-align: center; }
.nav button:hover { background: var(--surface-2); color: var(--text); }
.nav button[aria-current='page'] { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); font-weight: 600; }
.side-foot { margin-top: auto; padding: 0 6px; }
.side-foot .badge { white-space: normal; overflow-wrap: anywhere; display: inline-block; max-width: 100%; }
.content { min-width: 0; }
.bar { display: flex; gap: 12px; align-items: center; justify-content: space-between; padding: 14px 20px; border-bottom: 1px solid var(--line); background: var(--surface); position: sticky; top: 0; z-index: 2; }
.bar-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.panel-group { display: grid; gap: 16px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; gap: 10px; align-items: center; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.list li:last-child { border-bottom: 0; }
.list .secondary { color: var(--muted); font-size: 12px; display: block; }
.money-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.money-row div { padding: 4px 0; }
.money-row .n { display: block; font-size: 20px; font-weight: 700; }
.money-row span:not(.n) { color: var(--muted); font-size: 13px; }

.btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn.danger.ghost { background: transparent; color: var(--red); border-color: transparent; }
.actions.spread { justify-content: space-between; }
details.danger { border: 1px solid var(--red-bg); border-radius: var(--radius); padding: 10px 14px; }
details.danger summary { cursor: pointer; color: var(--red); font-weight: 600; }
details.danger[open] { display: grid; gap: 10px; }
details.danger .row input { flex: 1; }
.you { font-size: 12px; color: var(--muted); }

@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px 12px; gap: 10px; border-right: 0; border-bottom: 1px solid var(--line); }
  .side { min-width: 0; }
  .nav { display: flex; overflow-x: auto; width: 100%; min-width: 0; order: 3; }
  .nav button { width: auto; white-space: nowrap; }
  .side-foot { margin: 0 0 0 auto; }
  .two { grid-template-columns: 1fr; }
  .bar { position: static; padding: 12px 16px; }
  main { padding: 16px; }
}
@media (max-width: 720px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .grid2 { grid-template-columns: 1fr; }
  .money-row { grid-template-columns: 1fr; }
  .hide-sm { display: none; }
  .bar h1 { font-size: 17px; }
}
