/* Swordfish design system v2 — dark, minimal, elegant, modern.
   Intent documented in DESIGN.md. Fonts: Inter (UI), Fraunces (display only). */

:root {
  --bg: oklch(0.13 0.004 140);
  --surface: oklch(0.165 0.005 140);
  --raised: oklch(0.205 0.006 140);
  --line: rgba(255, 255, 255, .08);
  --line-strong: rgba(255, 255, 255, .14);
  --text: oklch(0.93 0.005 140);
  --text-2: oklch(0.72 0.008 140);
  --text-3: oklch(0.55 0.008 140);
  --brand: oklch(0.75 0.09 140);
  --brand-ink: oklch(0.17 0.02 140);
  --good: oklch(0.75 0.09 140);
  --warn: oklch(0.80 0.10 85);
  --bad: oklch(0.65 0.17 25);
  --r-ctl: 10px;
  --r-card: 14px;
  --font-ui: 'Inter', system-ui, sans-serif;
  --font-display: 'Fraunces', Georgia, serif;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  /* Back-compat aliases (v1 names still referenced by shared JS/pages) */
  --paper: var(--bg);
  --ink: var(--bg);
  --card: var(--surface);
  --card-2: var(--raised);
  --acc: var(--brand);
  --on: var(--brand-ink);
  --muted: var(--text-2);
  --line-soft: var(--line);
  --radius: var(--r-card);
  --radius-sm: var(--r-ctl);
  --font-head: var(--font-ui);
  --font-body: var(--font-ui);
  --font-mono: var(--font-ui);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 76px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1, h2, h3, h4 { font-family: var(--font-ui); font-weight: 600; line-height: 1.15; margin: 0 0 .5em; letter-spacing: -0.015em; text-wrap: balance; }
h1 { font-size: clamp(28px, 4vw, 38px); }
h2 { font-size: 24px; }
h3 { font-size: 16px; }
p { margin: 0 0 1em; max-width: 68ch; text-wrap: pretty; }
a { color: var(--text); text-decoration-color: var(--line-strong); text-underline-offset: 3px; }
a:hover { text-decoration-color: var(--text-2); }
img, svg { max-width: 100%; }
::selection { background: var(--brand); color: var(--brand-ink); }
:focus-visible { outline: 2px solid color-mix(in oklab, var(--brand) 65%, transparent); outline-offset: 2px; border-radius: 4px; }

.display { font-family: var(--font-display); font-weight: 400; letter-spacing: 0; line-height: 1.06; }
.eyebrow { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 8px; }
.acc { color: var(--brand); }
.muted { color: var(--text-2); }
.mono { font-size: 12.5px; color: var(--text-2); font-variant-numeric: tabular-nums; letter-spacing: .01em; }
.num { font-weight: 600; font-size: 28px; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: 500 14px/1 var(--font-ui); letter-spacing: 0;
  height: 40px; padding: 0 18px; border-radius: var(--r-ctl);
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background .18s var(--ease), border-color .18s var(--ease), transform .12s var(--ease), opacity .18s var(--ease);
}
.btn:hover { background: var(--raised); border-color: var(--line-strong); }
.btn:active { transform: translateY(0.5px); }
.btn-acc { background: var(--brand); color: var(--brand-ink); border-color: transparent; font-weight: 600; }
.btn-acc:hover { background: color-mix(in oklab, var(--brand) 92%, white); border-color: transparent; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface); color: var(--text); border-color: transparent; }
.btn-danger { background: transparent; border-color: transparent; color: var(--bad); }
.btn-danger:hover { background: color-mix(in oklab, var(--bad) 12%, transparent); border-color: transparent; }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; }
.btn[disabled] { opacity: .45; cursor: not-allowed; transform: none; }
.btn-block { width: 100%; }

/* ---- Cards ---- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-card); padding: 24px; }
.card-t { border-top: 1px solid var(--line); }

/* ---- KPI tiles ---- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-card); padding: 16px 18px; }
.kpi .num { display: block; margin: 4px 0 0; font-size: 26px; }
.kpi .lbl { font-size: 12.5px; color: var(--text-2); letter-spacing: 0; text-transform: none; }
.kpi .sub { font-size: 12px; color: var(--text-3); }

/* ---- Forms ---- */
.lbl { display: block; font-size: 13px; font-weight: 500; color: var(--text-2); margin: 0 0 6px; letter-spacing: 0; text-transform: none; }
.field {
  width: 100%; height: 40px; background: var(--surface); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--r-ctl);
  padding: 0 12px; font: 400 14px/1.4 var(--font-ui);
  transition: border-color .18s var(--ease);
}
.field:focus { outline: none; border-color: var(--brand); }
.field::placeholder { color: var(--text-3); }
textarea.field { min-height: 96px; height: auto; padding: 10px 12px; resize: vertical; }
select.field { appearance: none; }
.frow { display: grid; gap: 14px; margin-bottom: 14px; }
.frow-2 { grid-template-columns: 1fr 1fr; }
@media (max-width: 560px) { .frow-2 { grid-template-columns: 1fr; } }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 13.5px; color: var(--text-2); cursor: pointer; line-height: 1.5; }
.check input { margin-top: 2px; accent-color: var(--brand); width: 15px; height: 15px; flex: none; }
.check b { color: var(--text); font-weight: 500; }

/* ---- Tables ---- */
.tblwrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; min-width: 560px; }
.tbl th {
  text-align: left; font-size: 12.5px; font-weight: 500; color: var(--text-2);
  letter-spacing: 0; text-transform: none;
  padding: 10px 12px; border-bottom: 1px solid var(--line-strong);
}
.tbl td { padding: 12px; border-bottom: 1px solid var(--line); vertical-align: middle; font-variant-numeric: tabular-nums; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr.rowlink { cursor: pointer; }
.tbl tr.rowlink:hover td { background: var(--surface); }

/* ---- Status (dot + word; quiet) ---- */
.badge {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 12.5px; font-weight: 500; letter-spacing: 0; text-transform: none;
  padding: 0; border: 0; border-radius: 0; background: none;
  color: var(--text-2); white-space: nowrap;
}
.badge-acc { color: var(--brand); }
.badge-bad { color: var(--bad); }
.badge-warn { color: var(--warn); }
.dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; display: inline-block; flex: none; }
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.badge .dot { display: none; }

/* ---- App shell ---- */
.shell { display: grid; grid-template-columns: 224px 1fr; min-height: 100vh; }
.side {
  border-right: 1px solid var(--line); background: var(--bg);
  padding: 20px 14px; display: flex; flex-direction: column; gap: 2px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.side .brand { display: flex; align-items: center; gap: 9px; padding: 4px 10px 20px; text-decoration: none; }
.navlink {
  display: flex; align-items: center; gap: 10px; height: 34px; padding: 0 10px;
  border-radius: 8px; color: var(--text-2); text-decoration: none;
  font-size: 13.5px; font-weight: 500;
  transition: background .15s var(--ease), color .15s var(--ease);
}
.navlink svg { width: 15px; height: 15px; flex: none; opacity: .8; }
.navlink:hover { color: var(--text); background: var(--surface); }
.navlink.on { color: var(--text); background: var(--surface); }
.navlink.on svg { color: var(--brand); opacity: 1; }
.main { padding: 28px clamp(16px, 3vw, 36px) 64px; min-width: 0; max-width: 1240px; }
.pagehead { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.pagehead h1 { font-size: 20px; margin: 0; }
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 248px; z-index: 40; transform: translateX(-100%); transition: transform .22s var(--ease); background: var(--bg); }
  .side.open { transform: none; box-shadow: 24px 0 64px rgba(0,0,0,.5); }
}
.burger { display: none; }
@media (max-width: 860px) { .burger { display: inline-flex; } }

/* ---- Topbar (public) ---- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  background: color-mix(in oklab, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
  height: 60px; padding: 0 clamp(16px, 4vw, 40px);
}

/* ---- Overlay + sheet ---- */
.overlay {
  position: fixed; inset: 0; z-index: 60; background: rgba(0, 0, 0, .55);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade-in .18s var(--ease);
}
@media (min-width: 640px) { .overlay { align-items: center; padding: 24px; } }
@keyframes fade-in { from { opacity: 0; } }
.sheet {
  background: var(--raised); border: 1px solid var(--line); border-radius: 16px 16px 0 0;
  width: 100%; max-width: 440px; max-height: 92vh; overflow-y: auto; padding: 24px;
  animation: sheet-up .24s var(--ease);
}
@media (min-width: 640px) { .sheet { border-radius: 16px; } }
@keyframes sheet-up { from { transform: translateY(14px); opacity: 0; } }

/* ---- Toast ---- */
.toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 80; display: flex; flex-direction: column; gap: 8px; width: min(400px, calc(100vw - 32px)); }
.toast {
  background: var(--raised); border: 1px solid var(--line);
  border-radius: var(--r-ctl); padding: 11px 14px; font-size: 13.5px;
  animation: toast-in .22s var(--ease); box-shadow: 0 12px 40px rgba(0,0,0,.4);
}
.toast.bad { color: var(--bad); }
@keyframes toast-in { from { opacity: 0; translate: 0 6px; } }

/* ---- Funnel bars ---- */
.funnel { display: flex; flex-direction: column; gap: 12px; }
.fstep .frow-top { display: flex; justify-content: space-between; align-items: baseline; font-size: 13px; margin-bottom: 6px; }
.fstep .frow-top b { font-weight: 600; font-variant-numeric: tabular-nums; }
.fbar { height: 24px; border-radius: 6px; background: var(--surface); overflow: hidden; }
.fbar i { display: block; height: 100%; background: var(--brand); border-radius: 6px; transition: width 1s var(--ease); }
.fstep .drop { color: var(--text-2); font-size: 12px; font-variant-numeric: tabular-nums; }

/* ---- Pixel console: floating panel, bottom-right ---- */
.pxc {
  position: fixed; z-index: 50; right: 16px; bottom: 16px; left: auto; top: auto;
  width: auto; max-width: calc(100vw - 32px);
  background: var(--raised); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 16px 56px rgba(0,0,0,.45);
  transform: none; transition: none; max-height: none;
  display: flex; flex-direction: column; overflow: hidden;
}
.pxc-head {
  display: flex; align-items: center; gap: 8px; padding: 10px 14px; cursor: pointer;
  font-size: 13px; font-weight: 500; color: var(--text); letter-spacing: 0; text-transform: none;
  flex: none; user-select: none; white-space: nowrap;
}
.pxc-body { display: none; }
.pxc.open { width: 380px; }
.pxc.open .pxc-body { display: block; overflow-y: auto; max-height: min(48vh, 420px); padding: 0 10px 10px; }
.pxrow { border-top: 1px solid var(--line); padding: 10px 4px; margin: 0; background: none; border-radius: 0; font-size: 12.5px; }
.pxrow .pxname { color: var(--text); font-weight: 600; font-size: 13px; }
.pxrow pre { margin: 8px 0 0; white-space: pre-wrap; word-break: break-all; color: var(--text-2); font: 11px/1.5 ui-monospace, monospace; max-height: 150px; overflow-y: auto; }

/* ---- Utility ---- */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
@media (max-width: 860px) { .grid2, .grid3 { grid-template-columns: 1fr; } }
.row { display: flex; align-items: center; gap: 10px; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.wrap { max-width: 1160px; margin: 0 auto; padding: 0 clamp(16px, 4vw, 40px); }
.hr { border: 0; border-top: 1px solid var(--line); margin: 24px 0; }
.hidden { display: none !important; }
.skel { background: linear-gradient(90deg, var(--surface), var(--raised), var(--surface)); background-size: 200% 100%; animation: skel 1.2s linear infinite; border-radius: var(--r-ctl); color: transparent !important; }
@keyframes skel { to { background-position: -200% 0; } }

/* ---- Footer ---- */
.foot {
  border-top: 1px solid var(--line); margin-top: 72px;
  padding: 28px clamp(16px, 4vw, 40px); display: flex; flex-wrap: wrap; gap: 14px;
  align-items: center; justify-content: space-between; font-size: 13px; color: var(--text-3);
}
.foot a { color: var(--text-3); text-decoration: none; }
.foot a:hover { color: var(--text-2); }
.foot .legal { display: flex; gap: 20px; }

/* ---- Reveal (enhance-only; content visible without JS) ---- */
.reveal { opacity: 1; translate: none; }
.js-reveal .reveal { opacity: 0; translate: 0 10px; transition: opacity .5s var(--ease), translate .5s var(--ease); }
.js-reveal .reveal.in { opacity: 1; translate: 0 0; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
  .js-reveal .reveal { opacity: 1; translate: none; }
}
