/* forge — one stylesheet, custom-property tokens, no framework.
 *
 * THEMING RULE (house convention, copy it exactly): the complete LIGHT palette
 * is defined on bare :root. Dark redefines only the tokens, twice — once under
 * prefers-color-scheme for the "system" setting, and once under
 * [data-theme="dark"] so an explicit choice wins in both directions. No colour
 * anywhere has its ONLY definition inside a media query; a token that exists
 * only in the dark block renders as nothing in light mode and the failure is
 * invisible until someone switches.
 *
 * The CSP is script-src 'self' / style-src 'self' with no 'unsafe-inline', so
 * there are no <style> blocks and no style="" attributes anywhere in this app.
 * Anything dynamic goes through the CSSOM (el.style.setProperty), which CSP
 * does not restrict.
 */

:root {
  color-scheme: light;

  --paper: #f4f2ee;
  --surface: #fbfaf8;
  --sunken: #e9e6e0;
  --chrome: #ffffff;

  --ink: #1d1b18;
  --ink-2: #3d3a35;
  --muted: #6b665e;
  --faint: #98928a;

  --rule: #d9d4cb;
  --rule-2: #c3bcb0;

  /* Hot metal. The accent is the one saturated colour in the palette, so it
     reads as "this is the action" without any other cue. */
  --accent: #b4531b;
  --accent-ink: #ffffff;
  --accent-soft: #f3e3d8;

  --good: #2f6a44;
  --warn: #8a6212;
  --bad: #a33125;
  --bad-soft: #f7e2df;

  --btn-face: #b4531b;
  --btn-face-ink: #ffffff;
  --btn-quiet: #e6e2da;
  --btn-quiet-ink: #2b2825;

  --focus: #1f6fb2;

  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  --top-h: 56px;
  --pad: 16px;
  --r: 10px;
  --r-sm: 6px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --paper: #16171a;
    --surface: #1d1f23;
    --sunken: #121316;
    --chrome: #23262b;
    --ink: #eceae6;
    --ink-2: #cbc7c0;
    --muted: #97928a;
    --faint: #6d6862;
    --rule: #33373d;
    --rule-2: #454a52;
    --accent: #e07437;
    --accent-ink: #1a1206;
    --accent-soft: #38251a;
    --good: #6cc08a;
    --warn: #d8ac4c;
    --bad: #e8776a;
    --bad-soft: #3a201d;
    --btn-face: #e07437;
    --btn-face-ink: #1a1206;
    --btn-quiet: #2e3238;
    --btn-quiet-ink: #e4e1dc;
    --focus: #6fb2ee;
  }
}

[data-theme="dark"] {
  color-scheme: dark;
  --paper: #16171a;
  --surface: #1d1f23;
  --sunken: #121316;
  --chrome: #23262b;
  --ink: #eceae6;
  --ink-2: #cbc7c0;
  --muted: #97928a;
  --faint: #6d6862;
  --rule: #33373d;
  --rule-2: #454a52;
  --accent: #e07437;
  --accent-ink: #1a1206;
  --accent-soft: #38251a;
  --good: #6cc08a;
  --warn: #d8ac4c;
  --bad: #e8776a;
  --bad-soft: #3a201d;
  --btn-face: #e07437;
  --btn-face-ink: #1a1206;
  --btn-quiet: #2e3238;
  --btn-quiet-ink: #e4e1dc;
  --focus: #6fb2ee;
}

/* Load-bearing. #login is display:grid; without this the hidden attribute does
   not hide it and it becomes an invisible overlay eating every click. */
[hidden] { display: none !important; }

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--accent); }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

.muted { color: var(--muted); }
.faint { color: var(--faint); }
.mono { font-family: var(--mono); }
.error { color: var(--bad); }

/* ── Buttons ───────────────────────────────────────────────────────────────
   EVERY interactive control wears these. A Cancel or Back is a button with a
   quieter fill, never a bare underlined word next to a filled primary — same
   box, same height, same padding, so a dialog reads as two halves of one
   decision rather than a button with a footnote beside it. */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  padding: 8px 16px;
  border: 1px solid var(--rule-2);
  border-radius: var(--r-sm);
  background: var(--btn-quiet);
  color: var(--btn-quiet-ink);
  font: inherit;
  font-weight: 550;
  text-decoration: none;
  cursor: pointer;
  transition: filter .12s ease, border-color .12s ease;
}
.btn:hover:not(:disabled) { filter: brightness(0.96); border-color: var(--faint); }
.btn:active:not(:disabled) { filter: brightness(0.92); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary { background: var(--btn-face); color: var(--btn-face-ink); border-color: transparent; }
.btn-primary:hover:not(:disabled) { filter: brightness(1.07); }

.btn-quiet { background: var(--btn-quiet); color: var(--btn-quiet-ink); }

.btn-danger { background: var(--bad-soft); color: var(--bad); border-color: var(--bad); }

.btn-sm { min-height: 30px; padding: 4px 10px; font-size: 13px; }

/* ── Gates ─────────────────────────────────────────────────────────────────── */
.gate {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: var(--pad);
}

.login-card { width: min(380px, 100%); display: grid; gap: 10px; }
.login-card h1 { margin: 0; }
.login-card label { font-size: 13px; color: var(--muted); margin-top: 6px; }
.login-card .btn { margin-top: 14px; }

input, select, textarea {
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--rule-2);
  border-radius: var(--r-sm);
  padding: 9px 11px;
  width: 100%;
}
textarea { resize: vertical; min-height: 78px; }

.card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r);
  padding: 18px;
}

.brand {
  font-weight: 700;
  letter-spacing: .11em;
  text-transform: uppercase;
  font-size: 16px;
  color: var(--ink);
  text-decoration: none;
}

/* ── Chrome ────────────────────────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 18px;
  height: var(--top-h);
  padding: 0 var(--pad);
  background: var(--chrome);
  border-bottom: 1px solid var(--rule);
}
.topbar-right { margin-left: auto; display: flex; gap: 8px; }
.tabs { display: flex; gap: 4px; }
.tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 13px;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  color: var(--ink-2);
  text-decoration: none;
  font-weight: 550;
}
.tab:hover { background: var(--sunken); }
.tab[aria-current="page"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.badge {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 12px;
  font-weight: 700;
}

.view { padding: var(--pad); max-width: 1180px; margin: 0 auto; }

.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.between { justify-content: space-between; }
.stack { display: grid; gap: 14px; }

h2 { margin: 0 0 4px; font-size: 20px; }
h3 { margin: 0 0 6px; font-size: 15px; }

/* ── Piece grid ────────────────────────────────────────────────────────────── */
.grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
}
.piece-card { display: grid; gap: 0; padding: 0; overflow: hidden; }
.piece-thumb {
  aspect-ratio: 1 / 1;
  width: 100%;
  object-fit: cover;
  background: var(--sunken);
  display: block;
  border-bottom: 1px solid var(--rule);
}
.piece-thumb-empty {
  aspect-ratio: 1 / 1;
  display: grid;
  place-items: center;
  background: var(--sunken);
  color: var(--faint);
  border-bottom: 1px solid var(--rule);
}
.piece-body { padding: 12px 14px 14px; display: grid; gap: 6px; }
.piece-body a { color: var(--ink); text-decoration: none; font-weight: 600; }
.piece-body a:hover { color: var(--accent); }

/* ── Pills ─────────────────────────────────────────────────────────────────── */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: 999px;
  border: 1px solid var(--rule-2);
  background: var(--sunken);
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.pill-good { background: color-mix(in srgb, var(--good) 14%, transparent); border-color: var(--good); color: var(--good); }
.pill-bad { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }
.pill-warn { background: color-mix(in srgb, var(--warn) 16%, transparent); border-color: var(--warn); color: var(--warn); }
.pill-run { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* ── Tables ────────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; border: 1px solid var(--rule); border-radius: var(--r); }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--rule); white-space: nowrap; }
th { background: var(--sunken); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
tr:last-child td { border-bottom: none; }
td.num { font-family: var(--mono); }

/* ── Progress ──────────────────────────────────────────────────────────────── */
.bar { height: 6px; border-radius: 999px; background: var(--sunken); overflow: hidden; min-width: 110px; }
.bar > i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .3s ease; }

/* ── Viewer ────────────────────────────────────────────────────────────────── */
.viewer-wrap {
  position: relative;
  border: 1px solid var(--rule);
  border-radius: var(--r);
  overflow: hidden;
  background: var(--sunken);
  aspect-ratio: 4 / 3;
}
.viewer-wrap canvas { display: block; width: 100%; height: 100%; }
.viewer-hud {
  position: absolute;
  left: 10px;
  bottom: 10px;
  padding: 5px 10px;
  border-radius: var(--r-sm);
  background: color-mix(in srgb, var(--chrome) 86%, transparent);
  border: 1px solid var(--rule);
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-2);
}
.viewer-msg { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); }

.split { display: grid; gap: 16px; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); align-items: start; }
@media (max-width: 900px) { .split { grid-template-columns: minmax(0, 1fr); } }

.checks { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; }
.check { display: grid; grid-template-columns: 22px 1fr; gap: 8px; align-items: start; padding: 7px 0; border-bottom: 1px solid var(--rule); }
.check:last-child { border-bottom: none; }
.check-mark { font-weight: 700; }
.check-pass .check-mark { color: var(--good); }
.check-fail .check-mark { color: var(--bad); }
.check-soft .check-mark { color: var(--warn); }
.check-detail { color: var(--muted); font-size: 13px; font-family: var(--mono); }

.version-rail { display: grid; gap: 6px; max-height: 420px; overflow-y: auto; }
.version-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 9px 11px;
  border: 1px solid var(--rule);
  border-radius: var(--r-sm);
  background: var(--surface);
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: var(--ink);
  width: 100%;
}
.version-row:hover { border-color: var(--faint); }
.version-row[aria-selected="true"] { border-color: var(--accent); background: var(--accent-soft); }

.sheet { width: 100%; border: 1px solid var(--rule); border-radius: var(--r); display: block; }

/* Spans every column: inside .grid it would otherwise sit in the first
   250px track and read as a very narrow first card. */
.empty { grid-column: 1 / -1; display: grid; gap: 12px; place-items: center; padding: 54px 20px; color: var(--muted); text-align: center; }

.form-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.field { display: grid; gap: 5px; }
.field label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }

/* ── Brief and notes ────────────────────────────────────────────────────────
   The brief is the ask in the owner's own words and the notes are the
   back-and-forth about it. Both are prose, so they get prose treatment rather
   than the mono/pill styling the measurements use. */
.brief { margin: 0; white-space: pre-wrap; }
.brief-snip {
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-size: 13px;
}
.notes { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.note {
  border: 1px solid var(--rule);
  border-left: 3px solid var(--accent);
  border-radius: var(--r-sm);
  background: var(--surface);
  padding: 10px 12px;
  display: grid;
  gap: 6px;
}
.note p { margin: 0; }
.note-addressed { border-left-color: var(--good); opacity: .72; }
.note-wontfix { border-left-color: var(--faint); opacity: .6; }
