/* fb-db admin — a quiet, crisp operations UI. */

:root {
  --bg: #f6f6f4;
  --surface: #ffffff;
  --surface-2: #f1f1ee;
  --border: #e4e4df;
  --border-strong: #d2d2cb;
  --text: #1b1b19;
  --text-2: #5d5d57;
  --text-3: #8b8b84;
  --accent: #2f5bea;
  --accent-ink: #ffffff;
  --accent-soft: #e8eefd;
  --ok: #1f8a4c;
  --ok-soft: #e4f4ea;
  --warn: #a86400;
  --warn-soft: #fbf0dc;
  --fail: #c4302b;
  --fail-soft: #fbe6e5;
  --bar: #c9d6fb;
  --shadow: 0 1px 2px rgb(20 20 18 / 0.04), 0 1px 1px rgb(20 20 18 / 0.03);
  --radius: 10px;
  --radius-sm: 7px;
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --font: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111110;
    --surface: #1a1a18;
    --surface-2: #222220;
    --border: #2c2c29;
    --border-strong: #3a3a36;
    --text: #ededea;
    --text-2: #a8a8a1;
    --text-3: #75756f;
    --accent: #6d8cff;
    --accent-ink: #0b0f1f;
    --accent-soft: #1d2542;
    --ok: #4cc27f;
    --ok-soft: #15291d;
    --warn: #e0a24a;
    --warn-soft: #2c2213;
    --fail: #f07068;
    --fail-soft: #331817;
    --bar: #33427a;
    --shadow: none;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
}
a { color: inherit; text-decoration: none; }
a.link { color: var(--accent); }
a.link:hover { text-decoration: underline; text-underline-offset: 3px; }
h1, h2, h3 { margin: 0; letter-spacing: -0.01em; }
h1 { font-size: 22px; font-weight: 650; }
h2 { font-size: 15px; font-weight: 620; }
h3 { font-size: 13px; font-weight: 600; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* ---------- layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1180px; margin: 0 auto; padding: 0 24px;
  display: flex; align-items: center; gap: 28px; height: 56px;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 650; letter-spacing: -0.01em; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 6px; background: var(--text);
  display: grid; place-items: center; color: var(--bg); font-size: 11px; font-weight: 700;
}
.nav { display: flex; gap: 2px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.nav a {
  padding: 6px 11px; border-radius: var(--radius-sm); color: var(--text-2); white-space: nowrap;
  transition: background-color 150ms ease, color 150ms ease;
}
.nav a[aria-current="page"] { color: var(--text); background: var(--surface-2); }
@media (hover: hover) and (pointer: fine) { .nav a:hover { color: var(--text); } }

main { max-width: 1180px; margin: 0 auto; padding: 28px 24px 80px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; }
.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
@media (max-width: 900px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2, .grid-main { grid-template-columns: minmax(0, 1fr); }
}
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* ---------- cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); min-width: 0;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.card-body { padding: 16px 18px; }
.card-foot { padding: 12px 18px; border-top: 1px solid var(--border); }

.stat { padding: 16px 18px; }
.stat-label { color: var(--text-2); font-size: 12.5px; }
.stat-value { font-size: 24px; font-weight: 640; letter-spacing: -0.02em; margin-top: 4px; }
.stat-sub { color: var(--text-3); font-size: 12px; margin-top: 2px; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left; font-weight: 550; font-size: 12px; color: var(--text-3);
  padding: 9px 18px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
td { padding: 11px 18px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr.clickable { cursor: pointer; transition: background-color 120ms ease; }
@media (hover: hover) and (pointer: fine) { tbody tr.clickable:hover { background: var(--surface-2); } }
td.num, th.num { text-align: right; }
.cell-title { font-weight: 560; }
.cell-sub { color: var(--text-3); font-size: 12px; }
.empty { padding: 36px 18px; text-align: center; color: var(--text-2); }

/* ---------- status ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px 2px 7px;
  border-radius: 999px; font-size: 12px; font-weight: 550; white-space: nowrap;
  background: var(--surface-2); color: var(--text-2);
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.ok, .pill.success { background: var(--ok-soft); color: var(--ok); }
.pill.warn, .pill.queued { background: var(--warn-soft); color: var(--warn); }
.pill.fail, .pill.failed { background: var(--fail-soft); color: var(--fail); }
.pill.running { background: var(--accent-soft); color: var(--accent); }
.pill.running::before { animation: pulse 1.2s ease-in-out infinite; }
.pill.inactive { background: var(--surface-2); color: var(--text-3); }
@keyframes pulse { 50% { opacity: 0.25; } }

.checks { list-style: none; margin: 0; padding: 0; }
.checks li { display: grid; grid-template-columns: 18px 1fr; gap: 10px; padding: 12px 18px; border-bottom: 1px solid var(--border); }
.checks li:last-child { border-bottom: 0; }
.dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; background: var(--ok); }
.dot.warn { background: var(--warn); }
.dot.fail { background: var(--fail); }

/* ---------- bars (weekly import volume) ---------- */
.bars { display: flex; align-items: flex-end; gap: 6px; height: 120px; padding: 8px 0 0; }
.bars .bar { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; gap: 6px; min-width: 0; }
.bars .fill { width: 100%; border-radius: 4px 4px 1px 1px; background: var(--bar); min-height: 2px; }
.bars .fill.has-fail { background: var(--fail); opacity: 0.7; }
.bars .bar:last-child .fill { background: var(--accent); }
.bars .lbl { font-size: 10.5px; color: var(--text-3); white-space: nowrap; }

.meter { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--accent); border-radius: 99px; }

/* ---------- forms ---------- */
label { display: block; font-weight: 550; font-size: 13px; margin-bottom: 6px; }
.hint { color: var(--text-3); font-size: 12px; margin-top: 5px; }
.field { margin-bottom: 16px; }
input[type=text], input[type=password], input[type=date], input[type=number], select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: 8px 11px; min-height: 36px;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}
textarea { min-height: 72px; resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.check { display: flex; gap: 8px; align-items: center; font-weight: 500; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.segmented { display: inline-flex; background: var(--surface-2); padding: 3px; border-radius: 9px; gap: 2px; flex-wrap: wrap; }
.segmented label { margin: 0; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { display: block; padding: 5px 11px; border-radius: 6px; font-weight: 500; color: var(--text-2); cursor: pointer; transition: background-color 150ms ease, color 150ms ease; }
.segmented input:checked + span { background: var(--surface); color: var(--text); box-shadow: var(--shadow), 0 0 0 1px var(--border); }
.segmented input:focus-visible + span { box-shadow: 0 0 0 3px var(--accent-soft); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  font: inherit; font-weight: 560; line-height: 1; white-space: nowrap;
  height: 36px; padding: 0 14px; border-radius: var(--radius-sm); cursor: pointer;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  transition: transform 140ms var(--ease-out), background-color 150ms ease, border-color 150ms ease, opacity 150ms ease;
}
.btn:active { transform: scale(0.97); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--fail); border-color: color-mix(in srgb, var(--fail) 40%, var(--border)); }
.btn.danger.solid { background: var(--fail); color: #fff; border-color: var(--fail); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; transform: none; }
@media (hover: hover) and (pointer: fine) {
  .btn:not([disabled]):hover { background: var(--surface-2); }
  .btn.primary:not([disabled]):hover { background: color-mix(in srgb, var(--accent) 88%, var(--text)); }
  .btn.danger.solid:not([disabled]):hover { background: color-mix(in srgb, var(--fail) 88%, var(--text)); }
  .btn.ghost:not([disabled]):hover { color: var(--text); }
}

/* ---------- flash ---------- */
.flash {
  display: flex; gap: 10px; align-items: center; margin-bottom: 20px;
  padding: 10px 14px; border-radius: var(--radius-sm);
  background: var(--ok-soft); color: var(--ok); font-weight: 520;
  transition: opacity 250ms var(--ease-out), transform 250ms var(--ease-out);
  @starting-style { opacity: 0; transform: translateY(-4px); }
}
.flash.error { background: var(--fail-soft); color: var(--fail); }

.notice { padding: 12px 14px; border-radius: var(--radius-sm); background: var(--warn-soft); color: var(--warn); margin-bottom: 20px; }

/* ---------- danger zone ---------- */
.danger-zone { border-color: color-mix(in srgb, var(--fail) 30%, var(--border)); }
.danger-zone .card-head h2 { color: var(--fail); }

details.disclosure summary { cursor: pointer; color: var(--text-2); list-style: none; }
details.disclosure summary::-webkit-details-marker { display: none; }
details.disclosure summary::before { content: "›"; display: inline-block; width: 14px; transition: transform 150ms var(--ease-out); }
details.disclosure[open] summary::before { transform: rotate(90deg); }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 8px 18px; margin: 0; }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

pre.code {
  margin: 0; padding: 12px 14px; background: var(--surface-2); border-radius: var(--radius-sm);
  font-family: var(--mono); font-size: 12.5px; overflow-x: auto; white-space: pre;
}

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: 100%; max-width: 360px; }
.login-card .card-body { padding: 26px 26px 22px; }
.login-card h1 { font-size: 19px; margin: 14px 0 4px; }
.login-card .btn { width: 100%; margin-top: 4px; }

@media (max-width: 640px) {
  .topbar-inner { padding: 0 16px; gap: 14px; }
  main { padding: 20px 16px 60px; }
  th, td { padding-left: 12px; padding-right: 12px; }
  .hide-sm { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0ms !important; animation: none !important; }
}

.text-fail { color: var(--fail); }
.text-ok { color: var(--ok); }
td.run-error { padding-top: 0; font-size: 12px; }
.login-sub { margin: 0 0 20px; }
.chart { width: 100%; height: 132px; display: block; }
.chart .bar { fill: var(--bar); }
.chart .bar.latest { fill: var(--accent); }
.chart .bar.has-fail { fill: var(--fail); }
.chart text { fill: var(--text-3); font-size: 10px; font-family: var(--font); }
.meter-svg { width: 100%; height: 6px; display: block; border-radius: 99px; }
.meter-svg .track { fill: var(--surface-2); }
.meter-svg .val { fill: var(--accent); }
.mt { margin-top: 16px; }
.mb0 { margin-bottom: 0; }
.chart-labels { display: flex; justify-content: space-between; color: var(--text-3); font-size: 11px; margin-top: 6px; }
[hidden] { display: none !important; }
.events td.mono { overflow-wrap: anywhere; font-size: 12px; }
.events td.num { white-space: nowrap; }
.events td, .events th { padding-left: 14px; padding-right: 14px; }
