/* theme.css -- the shared design system for the sz_sqlrunner_ws pages.
 *
 * Extracted rather than duplicated: /, /features and /tester are three pages that
 * must look like one product, and three copies of a palette drift apart the moment
 * one of them is touched. Everything here is chrome they share -- tokens, layout,
 * typography, buttons, fields, the copy affordance, code and table surfaces. What a
 * page needs beyond this goes in that page's own <style>.
 *
 * Still no build step and no external origin: one extra local request, and the
 * pages work offline exactly as before.
 */

:root {
  color-scheme: dark;

  --bg: #0e1116;
  --bg-elev: #151a21;
  --panel: #171d25;
  --panel-2: #1c232c;
  --line: #2b3542;
  --line-soft: #232c37;

  /* Contrast is measured, not eyeballed -- every pair below clears WCAG AA, and
     most clear AAA. The descriptive text (-muted) is the one that matters: it
     carries the field labels and the hints, so at the old #77839a it sat at
     4.15:1 on a panel and read as washed out. Ratios against the panel bg are
     noted so a future change can be checked rather than guessed at. */
  --text: #eef1f6;        /* 15.0:1 on body, 13.4:1 on panel */
  --text-dim: #bcc5d3;    /* 10.4:1 on body,  9.1:1 on panel */
  --muted: #9aa5b6;       /*  7.6:1 on body,  6.4:1 on panel */

  --accent: #7fb4ff;      /*  9.2:1 on body,  7.9:1 on panel */
  --accent-dim: #35548a;
  --ok: #5cd79a;          /* 11.4:1 on the code bg */
  --ok-dim: #235c40;
  --warn: #f0c060;        /* 10.9:1 on panel */
  --bad: #ff8b8e;         /*  8.3:1 on the code bg */
  --bad-dim: #6b3336;

  --radius: 10px;
  --radius-sm: 7px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }
body {
  margin: 0;
  padding: 2rem 2rem 4rem;
  background:
    radial-gradient(1200px 500px at 15% -10%, #18222f 0%, transparent 60%),
    var(--bg);
  color: var(--text);
  font: 15px/1.55 var(--sans);
  /* No -webkit-font-smoothing: antialiased. On macOS it thins the glyphs, which
     on a dark background makes body text look faint and washed out. The default
     (subpixel) rendering is heavier and noticeably easier to read here. */
  text-rendering: optimizeLegibility;
}

.wrap { max-width: 1180px; margin: 0 auto; }
.wrap.narrow { max-width: 900px; }

/* ------------------------------------------------------------------ header */

header { margin-bottom: 1.5rem; }
.title-row { display: flex; align-items: center; gap: .65rem; flex-wrap: wrap; }
h1 { margin: 0; font-size: 1.6rem; font-weight: 680; letter-spacing: -.02em; }
/* The technical name sits beside the title rather than replacing it, so the
   project is still identifiable without making the page read like a directory. */
.badge {
  padding: .18rem .55rem; border: 1px solid var(--line); border-radius: 6px;
  background: #12171e; color: var(--muted);
  font: 500 .78rem var(--mono); letter-spacing: .01em;
}

.health {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .2rem .6rem .2rem .5rem;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--panel); color: var(--text-dim);
  font-size: .76rem; font-family: var(--mono);
}
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 3px rgba(78,201,138,.14); }
.dot.bad { background: var(--bad); box-shadow: 0 0 0 3px rgba(242,119,122,.14); }

p.sub { margin: .6rem 0 0; color: var(--text-dim); max-width: 82ch; font-size: .94rem; }

/* ------------------------------------------------------------------- cards */

.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1.15rem 1.25rem 1.25rem;
}
.card-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem;
}
h2 { margin: 0; font-size: 1rem; font-weight: 600; }
h2 .path { font-family: var(--mono); color: var(--accent); }
h3 { margin: 1.25rem 0 .5rem; font-size: .88rem; font-weight: 600; color: var(--text); }

/* ------------------------------------------------------------------ fields */

.label { display: block; margin: .75rem 0; font-size: .84rem; color: var(--muted); }
.label > span { display: block; margin-bottom: .3rem; }
.label > span em { font-style: normal; color: var(--muted); }
.label > span .req { color: var(--warn); font-style: normal; }

input[type=text], input[type=number], textarea, select {
  width: 100%; padding: .5rem .6rem;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: #0b0e13; color: var(--text);
  font: inherit; font-size: .9rem;
  transition: border-color .12s, box-shadow .12s;
}
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--accent-dim);
  box-shadow: 0 0 0 3px rgba(110,168,254,.13);
}
textarea { font-family: var(--mono); font-size: .86rem; line-height: 1.5; resize: vertical; }
::placeholder { color: #7d8899; }

.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 0 1rem; }

/* A copy affordance pinned inside the top-right of a field, like a notebook cell.
   The wrapper is what gets positioned -- an <input> cannot contain a button, and a
   <label> may only contain phrasing content, so the field sits in a div and the
   caption uses label[for] instead. */
.field { position: relative; display: block; }
.field > input, .field > textarea, .field > select { display: block; }

/* Room for the button to sit over the field rather than on the last character. */
.field[data-copy] > input,
.field[data-copy] > textarea { padding-right: 2.5rem; }

/* The result blocks take a button too -- the run command and the three text
   outputs are exactly the things people copy out of a notebook cell. */
.field[data-copy] > pre,
.field[data-copy] > .cmd { padding-right: 2.7rem; }

.copy-btn {
  position: absolute; top: .32rem; right: .32rem;
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; padding: 0; margin: 0;
  border: 1px solid var(--line); border-radius: 6px;
  background: #1b222c; color: var(--text-dim);
  /* .75 rather than something fainter: the icon must be findable without hunting
     for it, and the contrast audit put .55 at only 3.8:1 on the button's own bg. */
  cursor: pointer; opacity: .75;
  transition: opacity .12s, color .12s, border-color .12s, background .12s;
}
/* Dim until the field is in play, so a form of six fields does not read as six
   buttons -- but always reachable by keyboard. */
.field:hover .copy-btn, .field:focus-within .copy-btn { opacity: 1; }
.copy-btn:hover { background: #232c37; border-color: var(--accent-dim); color: var(--text); }
.copy-btn:focus-visible { opacity: 1; outline: 2px solid var(--accent); outline-offset: 1px; }
.copy-btn.done { color: var(--ok); border-color: var(--ok-dim); opacity: 1; }
.copy-btn svg { width: 14px; height: 14px; display: block; }

/* --------------------------------------------------------------- checkboxes */

.checks { display: flex; flex-wrap: wrap; gap: .45rem; margin: .9rem 0 .2rem; }
label.check {
  display: inline-flex; align-items: center; gap: .5rem;
  margin: 0; padding: .4rem .75rem;
  border: 1px solid var(--line); border-radius: 999px;
  background: #12171e; color: var(--text-dim);
  font-size: .82rem; font-family: var(--mono);
  cursor: pointer; user-select: none;
  transition: border-color .12s, background .12s, color .12s;
}
label.check:hover { border-color: #38414f; color: var(--text); }
label.check:has(input:checked) {
  border-color: var(--accent-dim); background: rgba(110,168,254,.1); color: var(--text);
}

/* A native unchecked checkbox is a bright white square on macOS, which fights
   the whole dark theme -- so it is drawn from scratch. */
label.check input[type=checkbox] {
  appearance: none; -webkit-appearance: none;
  width: 15px; height: 15px; flex: none; margin: 0;
  border: 1.5px solid #3b4553; border-radius: 4px;
  background: #0b0e13; cursor: pointer;
  display: grid; place-content: center;
  transition: background .12s, border-color .12s;
}
label.check input[type=checkbox]:hover { border-color: #4d5a6b; }
label.check input[type=checkbox]:checked {
  background: var(--accent); border-color: var(--accent);
}
label.check input[type=checkbox]:checked::after {
  content: ""; width: 7px; height: 3.5px;
  border-left: 2px solid #0b0e13; border-bottom: 2px solid #0b0e13;
  transform: rotate(-45deg) translate(0, -1px);
}
label.check input[type=checkbox]:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

/* ---------------------------------------------------------------- controls */

.actions { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; margin-top: 1rem; }

button {
  padding: .5rem .95rem; cursor: pointer;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--panel-2); color: var(--text);
  font: inherit; font-size: .88rem;
  transition: background .12s, border-color .12s, transform .06s;
}
button:hover { background: #232c37; border-color: var(--accent-dim); }
button:active { transform: translateY(1px); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.primary {
  background: linear-gradient(#3163b4, #2a4f8f);
  border-color: #3d6cbe; font-weight: 550;
}
button.primary:hover { background: linear-gradient(#3a6fc6, #31599c); }
button.ghost { background: transparent; color: var(--text-dim); }
button.ghost:hover { background: var(--panel-2); }
button:disabled { opacity: .5; cursor: not-allowed; transform: none; }

/* A link that looks like a button, for cross-page navigation. */
a.btn {
  display: inline-flex; align-items: center; gap: .45rem;
  padding: .5rem .95rem; text-decoration: none;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--panel-2); color: var(--text);
  font-size: .88rem;
  transition: background .12s, border-color .12s, transform .06s;
}
a.btn:hover { background: #232c37; border-color: var(--accent-dim); }
a.btn:active { transform: translateY(1px); }
a.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
a.btn.primary {
  background: linear-gradient(#3163b4, #2a4f8f);
  border-color: #3d6cbe; font-weight: 550;
}
a.btn.primary:hover { background: linear-gradient(#3a6fc6, #31599c); }
a.btn.ghost { background: transparent; color: var(--text-dim); }
a.btn.ghost:hover { background: var(--panel-2); }

kbd {
  font: 600 .72rem/1 var(--mono);
  padding: .22rem .38rem; border-radius: 5px;
  background: #0b0e13; border: 1px solid var(--line);
  border-bottom-width: 2px; color: var(--text-dim);
}

.hint { margin: .85rem 0 0; font-size: .82rem; color: var(--muted); max-width: 88ch; line-height: 1.6; }
.hint code { background: #10151c; padding: .1em .38em; border-radius: 4px; font-size: .92em; color: var(--text-dim); }
.hint a { color: var(--accent); }

code {
  background: #10151c; padding: .1em .38em; border-radius: 4px;
  font-family: var(--mono); font-size: .88em; color: var(--text-dim);
}
a { color: var(--accent); }

/* ------------------------------------------------------- code & data surfaces */

pre {
  margin: 0; padding: .8rem .9rem;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: #0a0d12; color: #d3dbe6;
  font-family: var(--mono); font-size: .84rem; line-height: 1.6;
  white-space: pre-wrap; word-break: break-word;
  overflow: auto; max-height: 26rem;
}
pre:empty::before { content: "(empty)"; color: #8b95a6; }
pre.ok { color: #cfe6d9; }
pre.err { color: #f0c9c9; }

.pill {
  display: inline-block;
  padding: .2rem .55rem; border-radius: 999px;
  border: 1px solid var(--line); color: var(--text-dim);
  font-family: var(--mono); font-size: .82rem;
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.pill.ok { color: var(--ok); border-color: var(--ok-dim); background: rgba(78,201,138,.07); }
.pill.bad { color: var(--bad); border-color: var(--bad-dim); background: rgba(242,119,122,.07); }
.pill.info { color: var(--accent); border-color: var(--accent-dim); background: rgba(110,168,254,.07); }
.pill.warn { color: var(--warn); border-color: #6b571f; background: rgba(240,192,96,.07); }

.tablewrap {
  display: inline-block; max-width: 100%;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: #0a0d12; overflow: auto; max-height: 26rem;
}
table { border-collapse: collapse; width: auto; font-family: var(--mono); font-size: .84rem; }
th, td {
  text-align: left; padding: .42rem .7rem;
  border-bottom: 1px solid var(--line-soft);
  white-space: nowrap; max-width: 52ch; overflow: hidden; text-overflow: ellipsis;
}
thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--panel-2); color: var(--text);
  font-weight: 600; border-bottom: 1px solid var(--line);
}
tbody tr:hover { background: rgba(110,168,254,.06); }
tbody tr:nth-child(even) { background: rgba(255,255,255,.017); }
tbody tr:nth-child(even):hover { background: rgba(110,168,254,.07); }
tbody tr:last-child td { border-bottom: none; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
th.num { text-align: right; }
td.null { color: #8b95a6; font-style: italic; }

.empty { padding: 1rem; color: var(--muted); font-size: .85rem; text-align: center; }
.spacer { flex: 1 1 auto; }

/* ------------------------------------------------------------------- extras */

details { margin-top: 1rem; }
summary { cursor: pointer; color: var(--muted); font-size: .82rem; }
summary:hover { color: var(--text-dim); }

.toast {
  position: fixed; left: 50%; bottom: 1.5rem; transform: translateX(-50%) translateY(1rem);
  padding: .5rem .9rem; border-radius: 999px;
  background: var(--panel-2); border: 1px solid var(--line);
  color: var(--text); font-size: .82rem;
  opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s;
  z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.spin {
  display: inline-block; width: 11px; height: 11px; vertical-align: -1px;
  border: 2px solid var(--accent-dim); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* scrollbars */
* { scrollbar-width: thin; scrollbar-color: #3a4552 transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #3a4552; border-radius: 6px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: #4b5766; }

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

/* ------------------------------------------------------------- account chip */

/* Who is signed in, and the way out. Populated by JS from GET /whoami, and hidden
   until that succeeds -- so a page that is not signed in shows nothing rather than
   an empty shell, and a page served without JS degrades to no chip instead of a
   broken one. */
.account { position: relative; margin-left: auto; display: none; }
.account.ready { display: block; }

.account-chip {
  display: inline-flex; align-items: center; gap: .5rem;
  padding: .25rem .6rem .25rem .3rem;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--panel); color: var(--text-dim);
  font: 500 .8rem var(--sans);
  cursor: pointer;
  transition: border-color .12s, background .12s, color .12s;
}
.account-chip:hover { border-color: var(--accent-dim); background: var(--panel-2); color: var(--text); }
.account-chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* The avatar: initials by default, the Google picture when there is one. Both are
   present, and whichever has no value is hidden by the caller. */
.avatar {
  width: 22px; height: 22px; border-radius: 50%; flex: none;
  display: grid; place-content: center;
  background: var(--accent-dim); color: var(--text);
  font: 600 .68rem/1 var(--mono); letter-spacing: .02em;
  overflow: hidden;
}
img.avatar { object-fit: cover; background: none; }
.account-chip .who { max-width: 15ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-chip .caret { color: var(--muted); font-size: .6rem; margin-left: -.1rem; }

.account-menu {
  position: absolute; top: calc(100% + .4rem); right: 0; z-index: 60;
  min-width: 15rem; padding: .35rem;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--panel-2);
  box-shadow: 0 16px 40px -18px rgba(0,0,0,.85);
  display: none;
}
.account.open .account-menu { display: block; }

.account-menu .ident { padding: .55rem .7rem .6rem; border-bottom: 1px solid var(--line-soft); margin-bottom: .3rem; }
.account-menu .ident b { display: block; font-size: .86rem; font-weight: 600; color: var(--text); }
.account-menu .ident span { display: block; margin-top: .15rem; font-family: var(--mono); font-size: .76rem; color: var(--muted); word-break: break-all; }

.account-menu a {
  display: flex; align-items: center; gap: .5rem;
  padding: .45rem .7rem; border-radius: 5px;
  color: var(--text-dim); text-decoration: none; font-size: .86rem;
}
.account-menu a:hover { background: var(--panel); color: var(--text); }
.account-menu .sep { height: 1px; background: var(--line-soft); margin: .3rem 0; }
