/* DBWeaver static styles ("paperfox" aesthetic).
   No external fonts, no CDN — CSP forbids inline CSS and remote hosts, so all
   styling lives here and the Geist fonts are served from /static/fonts/.
   Design tokens live in :root below as CSS custom properties — change the look
   from one place. */

/* ---- Fonts (vendored, never fetched over the network) ------------------- */
@font-face {
  font-family: "Geist";
  src: url("fonts/Geist-Variable.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Geist Mono";
  src: url("fonts/GeistMono-Variable.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

/* ---- Design tokens ------------------------------------------------------- */
:root {
  --font-sans: "Geist", -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --bg:        #ffffff;   /* page background */
  --bg-subtle: #fafafa;   /* alternating sections, auth page, table heads */
  --text:      #09090b;   /* near-black body */
  --muted:     #52525b;   /* secondary text (>=4.5:1 on white) */
  --border:    #e4e4e7;   /* hairline borders everywhere */

  --accent:       #2f6bff; /* vivid blue */
  --accent-hover: #1e5ae8;
  --accent-weak:  #eef4ff; /* soft blue wash for selected / info chips */

  --pass: #16a34a;  --pass-bg: #f0fdf4;
  --fail: #dc2626;  --fail-bg: #fef2f2;
  --warn: #b45309;  --warn-bg: #fffbeb;

  --radius-ctl:  6px;    /* buttons, inputs, chips */
  --radius-card: 12px;   /* panels, cards, tables' outer frame */
  --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
  --shadow-card: 0 1px 3px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.04);

  /* Back-compat aliases: older selectors referenced these names. */
  --panel: var(--bg);
  --ink:   var(--text);
  --line:  var(--border);
  --brand: var(--accent);
  --warn-bg-legacy: var(--warn-bg);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- Typography --------------------------------------------------------- */
h1 {
  font-size: 27px;
  line-height: 1.2;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 0.7rem;
}
h2 {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 1.3rem 0 0.6rem;
}
h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  text-transform: none;
  margin: 1.1rem 0 0.5rem;
}
.muted { color: var(--muted); }
code { font-family: var(--font-mono); font-size: 0.92em; }

/* Eyebrow label — the small category pill above a page title. */
.eyebrow {
  display: inline-block;
  margin: 0 0 0.5rem;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.01em;
}

/* Page header: eyebrow + title on the left, primary action on the right. */
.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.1rem;
}
.page-head > .page-head-titles { min-width: 0; }
.page-head h1 { margin-bottom: 0; }
.page-head .eyebrow { margin-bottom: 0.4rem; }

/* ---- Top nav ------------------------------------------------------------ */
.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  min-height: 56px;
  padding: 0 1.2rem;
  background: var(--bg);
  color: var(--text);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.topbar a { color: var(--muted); }
.topbar a:hover { color: var(--text); text-decoration: none; }
.brand {
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 17px;
  letter-spacing: -0.02em;
  color: var(--text);
}
.brand:hover { color: var(--text); }
.brand-db { color: var(--accent); }
.topnav {
  display: flex;
  align-items: center;
  gap: 1.1rem;
  margin-left: auto;
  flex-wrap: wrap;
  font-size: 14px;
}
.topnav a { color: var(--muted); }
.topnav a:hover { color: var(--text); }
.topnav a[aria-current="page"] { color: var(--text); font-weight: 600; }
.topnav .who { color: var(--text); font-weight: 500; }
.inline-form { display: inline; margin: 0; }
.linklike {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  padding: 0;
}
.linklike:hover { color: var(--text); text-decoration: underline; }

/* ---- Layout ------------------------------------------------------------- */
.container { max-width: 1100px; margin: 1.8rem auto; padding: 0 1.2rem; }
/* The workspace page opts into a wider container (see the container_class
   block in base.html): on big external monitors the editor and result tables
   get real room, while laptop-width viewports render essentially as before
   and every other page keeps the 1100px reading width. */
.container.wide { max-width: 1680px; }

/* ---- Cards / panels ----------------------------------------------------- */
.card,
.panel {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 20px;
  margin-bottom: 1.1rem;
  box-shadow: var(--shadow-card);
}
.card > :first-child,
.panel > :first-child { margin-top: 0; }
.card > :last-child,
.panel > :last-child { margin-bottom: 0; }
.card.narrow { max-width: 640px; }

/* Forms live in a single-column card, capped narrow for readability. */
.form-card { max-width: 640px; }

/* ---- Buttons ------------------------------------------------------------ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  padding: 8px 16px;
  border-radius: var(--radius-ctl);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 500;
  line-height: 1.2;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}
.btn:hover { text-decoration: none; background: var(--bg-subtle); }
.btn.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  box-shadow: var(--shadow-sm);
}
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
/* Destructive-ish secondary: white button with red text (deactivate, retire,
   regenerate code). Keeps the light weight of a secondary control. */
.btn.danger { background: var(--bg); color: var(--fail); border-color: var(--border); }
.btn.danger:hover { background: var(--fail-bg); border-color: var(--fail); }
.btn.small { padding: 4px 10px; font-size: 13px; }

/* Export ↓ affordance without touching the label wording. */
.btn.export::before { content: "\2193"; font-weight: 600; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---- Tiles (admin dashboard shortcuts) ---------------------------------- */
ul.tiles {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.9rem;
}
ul.tiles li a {
  display: block;
  padding: 18px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--bg);
  color: var(--text);
  font-weight: 600;
  box-shadow: var(--shadow-card);
  transition: border-color 0.12s ease, background 0.12s ease;
}
ul.tiles li a:hover { text-decoration: none; background: var(--bg-subtle); border-color: #d4d4d8; }

/* ---- Chips / badges ----------------------------------------------------- */
.badge,
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3em;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.4;
  border: 1px solid transparent;
  white-space: nowrap;
}
/* Difficulty */
.badge.easy   { background: var(--pass-bg); color: var(--pass); }
.badge.medium { background: var(--warn-bg); color: var(--warn); }
.badge.hard   { background: var(--fail-bg); color: var(--fail); }
/* Status pairs reused across the app */
.badge.published,
.badge.active,
.chip.pass    { background: var(--pass-bg); color: var(--pass); }
.badge.draft  { background: var(--accent-weak); color: var(--accent); }
.badge.stale,
.badge.failed_probe,
.chip.fail    { background: var(--fail-bg); color: var(--fail); }
.badge.inactive { background: var(--bg-subtle); color: var(--muted); border-color: var(--border); }
.chip.info    { background: var(--accent-weak); color: var(--accent); }
.chip.due     { background: var(--bg-subtle); color: var(--muted); border-color: var(--border); }

/* ---- Flash messages (reuse banner language) ----------------------------- */
.flashes { margin-bottom: 1.1rem; }
.flash {
  padding: 10px 12px 10px 14px;
  border-radius: var(--radius-ctl);
  margin-bottom: 0.5rem;
  border: 1px solid var(--border);
  font-size: 14px;
}
.flash-error   { background: var(--fail-bg); color: var(--fail); border-color: var(--fail); }
.flash-success { background: var(--pass-bg); color: var(--pass); border-color: var(--pass); }
.flash-info    { background: var(--accent-weak); color: var(--accent); border-color: var(--accent); }

/* ---- Tables ------------------------------------------------------------- */
/* Every table sits in a hairline-framed scroll box (the "card" outer frame /
   framed product shot). Standalone list tables get a soft card shadow; result
   tables nested in a panel stay flat hairline frames. */
.table-scroll {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  margin-bottom: 1.1rem;
  background: var(--bg);
}

table.grid {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg);
  font-size: 14px;
}
table.grid th,
table.grid td {
  padding: 10px 14px;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--border);
}
table.grid thead th {
  background: var(--bg-subtle);
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
}
table.grid tbody tr:last-child td { border-bottom: none; }
table.grid tbody tr:hover td { background: var(--bg-subtle); }

/* ---- Forms -------------------------------------------------------------- */
label {
  display: block;
  margin: 0.9rem 0 0.2rem;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
}
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=datetime-local], select, textarea {
  display: block;
  width: 100%;
  margin-top: 0.3rem;
  padding: 8px 10px;
  font-family: var(--font-sans);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-ctl);
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-weak);
}
textarea { font-family: var(--font-mono); line-height: 1.5; }
select { -webkit-appearance: none; appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
                    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 55%, calc(100% - 13px) 55%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 34px;
}
label.checkbox { display: flex; align-items: center; gap: 0.45rem; font-weight: 400; color: var(--text); font-size: 14px; }
label.checkbox input { width: auto; margin: 0; display: inline-block; }
.w-points { width: 5rem; }
.errors, .error, .field-error { color: var(--fail); font-size: 13px; margin-top: 0.25rem; }

/* ---- Prompt / code blocks ----------------------------------------------- */
/* Task prompt reads as prose, not a gray slab — but line breaks are kept. */
.prompt-body {
  white-space: pre-wrap;
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  margin: 0 0 0.8rem;
}
/* SQL / code shown in drill-downs and history stays mono in a hairline frame. */
pre {
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.5;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  padding: 12px 14px;
  border-radius: var(--radius-ctl);
  overflow-x: auto;
  white-space: pre-wrap;
}

/* ---- Banners ------------------------------------------------------------ */
.banner {
  position: relative;
  padding: 10px 12px 10px 34px;
  border-radius: var(--radius-ctl);
  margin: 0.7rem 0;
  border: 1px solid var(--border);
  font-size: 14px;
}
.banner::before {
  position: absolute;
  left: 12px;
  top: 10px;
  font-weight: 700;
  line-height: 1.4;
}
.banner.pass {
  background: var(--pass-bg);
  color: var(--pass);
  border-color: var(--pass);
  border-left-width: 2px;
}
.banner.pass::before { content: "\2713"; color: var(--pass); }
.banner.fail { background: var(--fail-bg); color: var(--fail); border-color: var(--fail); }
.banner.fail::before { content: "\2715"; color: var(--fail); }
.banner.warn { background: var(--warn-bg); color: var(--warn); border-color: var(--warn); }
.banner.warn::before { content: "!"; color: var(--warn); }

/* Signature moment: on a pass the check pops in. Motion only when welcome. */
@media (prefers-reduced-motion: no-preference) {
  .banner.pass::before {
    animation: pop-check 200ms ease-out both;
    transform-origin: center;
  }
}
@keyframes pop-check {
  0%   { transform: scale(0.4); opacity: 0; }
  70%  { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

/* ---- Workspace ---------------------------------------------------------- */
/* Narrow screens: single-column stack, divider hidden. From 900px up: a
   three-track grid (Task | divider | SQL). --ws-left is set by app.js when
   the user drags the divider (or uses arrow keys); without it the split
   defaults to 50/50. The ratio persists in localStorage. */
.workspace { display: grid; grid-template-columns: 1fr; gap: 1.1rem; }
.workspace-divider { display: none; }
@media (min-width: 900px) {
  .workspace {
    grid-template-columns: minmax(300px, var(--ws-left, 1fr)) 12px minmax(340px, 1fr);
    column-gap: 0.5rem;
  }
  .workspace-divider {
    display: block;
    position: relative;
    cursor: col-resize;
    touch-action: none;      /* let pointer events drive the drag on touch */
    border-radius: 999px;
  }
  .workspace-divider::before {
    content: "";
    position: absolute;
    top: 0; bottom: 0;
    left: 50%;
    width: 2px;
    margin-left: -1px;
    border-radius: 999px;
    background: var(--border);
    transition: background 0.12s ease;
  }
  .workspace-divider:hover::before,
  .workspace-divider:focus-visible::before { background: var(--accent); }
}
/* min-width: 0 stops wide content (ERD image, result tables) from blowing a
   grid column open and squeezing the other panel. */
.workspace > .panel { min-width: 0; }

.editor { width: 100%; min-height: 220px; font-size: 14px; }

.result-tables { display: flex; gap: 1rem; flex-wrap: wrap; }
.result-tables > div { flex: 1 1 320px; min-width: 0; }

/* Result tables (run/submit/expected) read as framed product shots: mono
   cells inside a nested hairline frame (flat, no shadow). */
#result-box .table-scroll,
.expected-sample .table-scroll,
#validate-result .table-scroll {
  box-shadow: none;
  margin: 0.5rem 0 0.8rem;
}
#result-box table.grid td,
.expected-sample table.grid td,
#validate-result table.grid td {
  font-family: var(--font-mono);
  font-size: 13px;
}

/* Countdown shown as a small chip near the title. */
.countdown {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--accent-weak);
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
}

/* Wide ERDs scroll inside their panel at natural size (shrinking would make
   column names unreadable). Framed like a paperfox product shot. */
.erd-panel {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--bg-subtle);
  padding: 10px;
  margin: 0.5rem 0;
}
.erd-panel img, .erd-panel svg { display: block; max-width: none; height: auto; }
details.erd, details.expected-sample { margin: 0.6rem 0; }
details.erd summary, details.expected-sample summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  padding: 4px 0;
}
details.erd ul { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.5rem 0 0; }
details.erd ul li code {
  display: inline-block;
  padding: 2px 8px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-ctl);
}

.actions { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; margin: 0.8rem 0; }

/* Hints + history lists. #history-box keeps ul.hintlist so app.js can prepend
   new attempts into the same list. */
.hintlist { list-style: none; padding: 0; margin: 0.4rem 0; }
.hintlist li { margin: 0.45rem 0; }
.history-list li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.history-list li:last-child { border-bottom: none; }
.history-list .ts { margin-left: auto; }

/* ---- Auth pages --------------------------------------------------------- */
body:has(.auth-card) { background: var(--bg-subtle); }
.auth-wrap {
  max-width: 400px;
  margin: 3rem auto 0;
  text-align: center;
}
.auth-brand {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0 0 1.1rem;
}
.auth-card {
  max-width: 400px;
  margin: 0 auto;
  text-align: left;
  background: var(--bg);
}
.auth-card h1 { font-size: 22px; font-weight: 700; }
.auth-card .btn.primary { width: 100%; justify-content: center; margin-top: 0.6rem; }

/* ---- Utilities ---------------------------------------------------------- */
.hidden { display: none; }

@media (max-width: 560px) {
  .container { margin: 1.1rem auto; }
  h1 { font-size: 23px; }
  .page-head { align-items: flex-start; }
}
