/* Tax ID Resolver — administration styling.
 *
 * Replaces Tailwind 4, which needed a Vite plugin and so kept the whole npm build alive for what
 * amounts to tables, forms and cards. The tokens are the ones the React UI used, so the screens
 * look the same. No web fonts: a CDN request is the one thing this layer is not allowed to make,
 * and the previous stylesheet named Inter without ever loading it — every browser was already
 * falling back to the system stack below.
 */

:root {
  --canvas: #fafafa;
  --surface: #ffffff;
  --line: #ebebeb;
  --line-strong: #e2e2e2;
  --ink: #171717;
  --sub: #525252;
  --muted: #737373;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --ok: #059669;
  --danger: #dc2626;
  --warn: #b45309;
  --tint-0: #2563eb;
  --tint-1: #10b981;
  --tint-2: #f59e0b;
  --tint-3: #8b5cf6;
  --tint-4: #f43f5e;
  --tint-5: #06b6d4;
  --tint-6: #9ca3af;
  --radius: 12px;
  --radius-sm: 8px;
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, 'JetBrains Mono', Menlo, monospace;
}

*, *::before, *::after { box-sizing: border-box; }

/* 🔴 The browser's own `[hidden] { display: none }` loses to any class that sets `display`, and
   several here do — `.btn` most of all. Without this, `<button hidden>` and `el.hidden = true`
   are silently inert, which is how the Stop and CSV buttons on the lookup screen were visible
   before a batch had ever run. Every `hidden` in the templates and in batch.js depends on it. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  background: var(--canvas);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

h1, h2 { margin: 0; font-weight: 600; }
h1 { font-size: 18px; }
h2 { font-size: 15px; }
p { margin: 0; }
a { color: inherit; }

.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.xsmall { font-size: 12px; }
.right { text-align: right; }
.ok { color: var(--ok); }
.danger { color: var(--danger); }
.mt { margin-top: 16px; }
.mb { margin-bottom: 8px; }
.narrow { max-width: 420px; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scroll-x { overflow-x: auto; }

/* ── Shell ─────────────────────────────────────────────────────────────────────────────────── */
.shell { min-height: 100vh; display: grid; grid-template-columns: 220px 1fr; }

.sidebar {
  border-right: 1px solid var(--line);
  background: var(--surface);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.brand { padding: 12px 8px; font-weight: 600; font-size: 15px; }
.brand span { display: block; font-weight: 400; font-size: 11px; color: var(--muted); }
.sidebar nav { display: flex; flex-direction: column; gap: 4px; }
.nav-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--sub);
  text-decoration: none;
}
.nav-link:hover { background: var(--canvas); }
.nav-link.is-active { background: var(--accent); color: #fff; }
.sidebar-foot { margin-top: auto; font-size: 11px; color: var(--muted); padding: 0 8px; }
.sidebar-foot form { margin-top: 8px; }

main { padding: 24px; max-width: 1024px; width: 100%; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
/* Pushes the action button to the right edge. On the heading rather than on the last child: a
 * screen with no action makes the heading itself the last child, and it would float right. */
.page-head h1 { margin-right: auto; }

.centre-screen { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; }
.brand-line { font-weight: 600; font-size: 15px; }
.gsi-slot { display: flex; justify-content: center; margin-top: 16px; }

/* ── Surfaces ──────────────────────────────────────────────────────────────────────────────── */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.pad { padding: 16px; }
.pad-lg { padding: 24px; }
.panel-title { font-weight: 500; font-size: 13px; margin-bottom: 8px; }
.empty { text-align: center; color: var(--muted); font-size: 13px; padding: 40px 0; }

.grid { display: grid; gap: 12px; }
.grid-stats { grid-template-columns: repeat(2, 1fr); }
.grid-2 { grid-template-columns: 1fr; }
@media (min-width: 768px) {
  .grid-stats { grid-template-columns: repeat(3, 1fr); }
  .grid-2 { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 1024px) { .grid-stats { grid-template-columns: repeat(6, 1fr); } }

.stat-value { font-size: 24px; font-weight: 600; margin-top: 4px; }

/* ── Tables ────────────────────────────────────────────────────────────────────────────────── */
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  text-align: left;
  font-weight: 400;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  padding: 6px 8px 6px 0;
}
.table td { padding: 6px 8px 6px 0; border-bottom: 1px solid var(--line); }
.table tbody tr:last-child td { border-bottom: 0; }
.table-padded th, .table-padded td { padding: 8px 16px; }

/* ── Breakdown bars ────────────────────────────────────────────────────────────────────────── */
.bars { display: flex; flex-direction: column; gap: 8px; }
.bar-head { display: flex; justify-content: space-between; font-size: 12px; margin-bottom: 2px; }
.bar-head > :first-child { color: var(--sub); }
.bar-track { height: 8px; border-radius: 999px; background: var(--canvas); overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); }
.tint-0 { background: var(--tint-0); }
.tint-1 { background: var(--tint-1); }
.tint-2 { background: var(--tint-2); }
.tint-3 { background: var(--tint-3); }
.tint-4 { background: var(--tint-4); }
.tint-5 { background: var(--tint-5); }
.tint-6 { background: var(--tint-6); }

/* ── Tags and badges ───────────────────────────────────────────────────────────────────────── */
.code-cell { display: inline-flex; align-items: center; gap: 6px; }
.tag { font-size: 10px; padding: 2px 6px; border-radius: 4px; text-transform: uppercase; }
.tag-bti { background: #eff6ff; color: #1d4ed8; }
.tag-pti { background: #fffbeb; color: #b45309; }

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 999px;
  margin: 0 4px 4px 0;
  background: #f3f4f6;
  color: #4b5563;
}
.badge-admin { background: #fef2f2; color: #b91c1c; }
.badge-lookup-bti { background: #eff6ff; color: #1d4ed8; }
.badge-lookup-pti { background: #f5f3ff; color: #6d28d9; }
.badge-pii { background: #fffbeb; color: #b45309; }

/* ── Forms and buttons ─────────────────────────────────────────────────────────────────────── */
.stack { display: flex; flex-direction: column; gap: 12px; }
.field { display: block; }
.field-label { font-weight: 500; font-size: 13px; color: var(--sub); }
.field input, .field select {
  width: 100%;
  margin-top: 4px;
  padding: 8px 12px;
  font: inherit;
  font-size: 13px;
  background: var(--canvas);
  color: inherit;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
}
.field input:focus, .field select:focus {
  background: var(--surface);
  border-color: var(--accent);
  outline: 2px solid rgba(37, 99, 235, 0.15);
}

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  font-size: 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  color: var(--sub);
  cursor: pointer;
}
/* The checkbox stays visible and focusable — hiding it, as the React version did, left the chips
   unreachable by keyboard and invisible to a screen reader. */
.chip:has(input:checked) { border-color: var(--accent); color: var(--accent); }
.chip:focus-within { outline: 2px solid rgba(37, 99, 235, 0.3); }

.btn {
  display: inline-block;
  padding: 8px 16px;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  cursor: pointer;
}
.btn:hover { background: var(--accent-hover); }
.btn-ghost { background: var(--surface); border-color: var(--line-strong); color: var(--sub); }
.btn-ghost:hover { background: var(--canvas); }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #b91c1c; }

.linkish {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  font-size: 12px;
  color: var(--danger);
  text-decoration: none;
  cursor: pointer;
}
.linkish:hover { text-decoration: underline; }

/* ── Alerts ────────────────────────────────────────────────────────────────────────────────── */
.alert { padding: 8px 12px; border-radius: var(--radius-sm); font-size: 13px; }
.alert-error { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.alert-ok { background: #ecfdf5; color: #047857; border: 1px solid #a7f3d0; }
.alert-warn { background: #fffbeb; color: var(--warn); border: 1px solid #fde68a; }
.login-card .alert { margin-bottom: 12px; }

/* ── Dialogs ───────────────────────────────────────────────────────────────────────────────── */
/* Opened by rendering `<dialog open>`, never by script, so the screens work without JavaScript.
 * A plain `open` dialog is non-modal, which is exactly what the show-once key needs: there is no
 * backdrop to click through and no Esc dismissal, so the one copy of a key cannot be lost by a
 * stray click. The overlay below is appearance only. */
.modal[open] {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: block;
  width: 100%;
  max-width: 440px;
  height: fit-content;
  margin: auto;
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}
/* The scrim. A non-modal dialog has no ::backdrop, and drawing it as a pseudo-element rather than
 * a real overlay keeps it exactly that: appearance, with nothing to click through. */
.modal[open]::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  background: rgba(0, 0, 0, 0.4);
}
.modal header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
}
.modal-x { margin-left: auto; color: var(--muted); text-decoration: none; }
.modal-body { padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.modal footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 0 20px 20px;
}
.key-box {
  padding: 12px;
  font-size: 12px;
  word-break: break-all;
  background: var(--canvas);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}

@media (max-width: 640px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
  main { padding: 16px; }
}

/* ── Batch lookup screen ─────────────────────────────────────────────────────────────────────── */
.batch-actions { display: flex; gap: .5rem; align-items: center; }

/* The paste box. Monospace because what goes in it is columns of digits, and a proportional font
   makes a mistyped code much harder to spot. */
#codes {
  width: 100%;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .9rem;
  line-height: 1.5;
  resize: vertical;
}

/* Rows are drawn before any answer exists, so the table's height is settled from the start and the
   page does not jump as results land. */
#results tbody td { vertical-align: top; }
#results tbody tr:target { background: var(--tint-ok, rgba(0, 0, 0, .03)); }

/* ── Statistics: period control and server-rendered charts ──────────────────────────────────── */
.range-row { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; }
.range-presets, .range-export { display: flex; gap: 6px; }
.range-custom { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.range-custom input[type="date"], .range-custom select { padding: 6px 8px; font: inherit; }
.btn.is-active { background: var(--accent); color: #fff; border-color: var(--accent); }
.mt-sm { margin-top: 8px; }

/* The chart is one <svg> scaled to the card's width. `height` is fixed and the viewBox is not
   preserved on the x axis, so the bars stretch to fill whatever width is available instead of
   leaving the card half empty on a wide screen. */
.chart { margin: 0; }
.chart svg { width: 100%; height: 210px; display: block; overflow: visible; }
.chart-baseline { stroke: var(--line-strong); stroke-width: 1; }
.chart-bar { fill: var(--accent); opacity: .28; }
.chart-bar-hit { fill: var(--accent); opacity: .85; }
.chart-tick { fill: var(--muted); font-size: 11px; font-family: var(--mono); }
/* A swatch, so the caption can name a colour without a legend component. The colour itself is set
   inline from the same --tint-N the shape uses; a second copy here would be one to keep in step. */
.chart-key {
  display: inline-block; width: 10px; height: 10px; border-radius: 2px;
  margin: 0 4px 0 8px; vertical-align: baseline;
}
.chart-key-total { background: var(--accent); opacity: .28; }
.chart-key-hit { background: var(--accent); opacity: .85; }
