/* ==========================================================================
   builder.css — BUILDER / ADMIN CONSOLE workbench skin.

   Loaded LAST, after css/console.css and css/kits.css. Takes every colour
   from the national kit tokens css/kits.css sets on html[data-edition] —
   --bg, --bg-elevated, --panel, --border, --text, --text-muted, --accent,
   --accent-2, --accent-strong, --accent-contrast, --glow-rgb,
   --kit-accent-grad, --kit-rim, --kit-page-glow-a/b — plus console.css's own
   --bg-sunken, --border-strong, --text-faint, --font-mono. No colour in this
   file is hard-coded: the SAME palette as the user-facing app, per edition,
   in both themes. What still marks this as the builder side is structure,
   never colour: near-black-relative graphite tiers (via --bg-sunken/--bg/
   --bg-elevated), a fine blueprint grid, monospace wherever data lives, thin
   hairline rules, square-ish panels with a top-edge hairline and corner
   ticks, a status rail of build-style chips, a file-tree nav, and an
   IDE-style Code room with a bottom status strip.

   Additive only: no selectors are removed from console.css, nothing here
   reaches outside this stylesheet's cascade. Every rule is scoped so it
   only ever tightens or re-skins what console.css and kits.css already draw.
   ========================================================================== */

:root {
  /* Workbench-only tokens, entirely DERIVED from the active kit/theme — no
     literal colour is introduced here. The three "graphite" tiers are just
     this edition's own sunken/base/elevated surfaces, reused so the
     workbench chrome (rails, code room, gutters) always sits one or two
     steps darker than the room content, whatever the kit. */
  --bw-graphite-0: var(--bg-sunken);
  --bw-graphite-1: var(--bg);
  --bw-graphite-2: var(--bg-elevated);
  --bw-hair: rgba(var(--glow-rgb), 0.5);
  --bw-hair-dim: rgba(var(--glow-rgb), 0.22);
  --bw-tick: rgba(var(--glow-rgb), 0.65);
  --bw-grid-major: rgba(var(--glow-rgb), 0.07);
  --bw-grid-minor: rgba(var(--glow-rgb), 0.035);
  --bw-radius: 3px;
  --bw-radius-sm: 2px;
}

/* Blueprint grid over the kit's own page ground — same background colours
   the front end uses for this edition/theme (kits.css already painted
   --kit-page-glow-a/b under body via html[data-edition] body), this layer
   only adds the fine graph-paper lines in the kit's own glow colour. */
html[data-edition] body {
  background-image:
    linear-gradient(var(--bw-grid-major) 1px, transparent 1px) 0 0 / 64px 64px,
    linear-gradient(90deg, var(--bw-grid-major) 1px, transparent 1px) 0 0 / 64px 64px,
    linear-gradient(var(--bw-grid-minor) 1px, transparent 1px) 0 0 / 16px 16px,
    linear-gradient(90deg, var(--bw-grid-minor) 1px, transparent 1px) 0 0 / 16px 16px,
    radial-gradient(1100px 560px at 100% -10%, var(--kit-page-glow-a), transparent 60%),
    radial-gradient(900px 520px at -10% 110%, var(--kit-page-glow-b), transparent 60%),
    var(--bg);
  background-attachment: fixed;
}

@media (prefers-reduced-motion: no-preference) {
  html[data-edition] body { transition: background-color .2s ease; }
}

/* ---------- monospace, everywhere data lives ---------- */

#app,
.room-title,
.nav-item,
.nav-group-label,
.data-table,
.cell-mono,
.tile-value,
.tile-label,
.chip,
.status-pill,
.code-explorer-item,
.code-tab,
.brand-word,
.field-label,
.user-name,
.history-row,
.audit-table-wrap,
input,
select,
textarea {
  font-family: var(--font-mono);
}

/* Prose stays legible in its own face; only the workbench chrome and data
   surfaces above take the mono treatment. */
.card-desc,
.hint,
.view-sub,
.help-body p,
.help-body ul,
.modal-card p,
.review-item {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
}

.room-title,
.nav-item,
.brand-word,
.data-table th {
  letter-spacing: 0;
}

.brand-word { white-space: nowrap; }
.brand { flex-wrap: nowrap; min-width: 0; }

@media (max-width: 480px) {
  .brand-word { font-size: 15px; }
}

/* ---------- BUILDER identity mark, beside the wordmark ---------- */

.admin-pill {
  height: auto;
  min-height: 22px;
  padding: 3px 10px;
  border-radius: var(--bw-radius-sm);
  background: transparent;
  border: 1px solid var(--bw-tick);
  color: var(--accent);
  box-shadow: none;
  position: relative;
  font-family: var(--font-mono);
  white-space: nowrap;
  font-size: 9.5px;
}
.admin-pill::before {
  content: "BUILDER";
  margin-right: 6px;
  padding-right: 6px;
  border-right: 1px solid var(--bw-hair-dim);
  color: var(--text-faint);
  font-weight: 800;
  white-space: nowrap;
}
.admin-pill-sm {
  min-height: 18px;
  padding: 2px 7px;
  font-size: 8.5px;
}

.brand-mark { filter: none; }
.brand::after {
  content: "";
  width: 1px;
  align-self: stretch;
  min-height: 18px;
  background: var(--bw-hair-dim);
  margin: 0 2px;
}
.brand-centered::after { display: none; }

/* ---------- status rail — build-style chips along the top ---------- */

.topbar {
  border-bottom: 1px solid var(--bw-hair-dim);
  position: relative;
}
.topbar::before {
  content: "";
  position: absolute; left: 0; right: 0; top: 0; height: 2px;
  background: linear-gradient(90deg, var(--accent), transparent 55%, transparent 70%, var(--accent-2));
  opacity: .55;
}

.status-pill {
  border-radius: var(--bw-radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-sunken);
  position: relative;
  padding-left: 20px;
}
.status-pill::before {
  content: "";
  position: absolute; left: 8px; top: 50%; width: 6px; height: 6px;
  transform: translateY(-50%);
  background: var(--text-faint);
  border-radius: 1px;
}
.status-pill-on { border-color: rgba(var(--glow-rgb), 0.4); }
.status-pill-on::before { background: var(--accent); box-shadow: 0 0 6px rgba(var(--glow-rgb), 0.8); }
.status-pill-danger::before { background: var(--danger); box-shadow: 0 0 6px rgba(255, 107, 94, 0.7); }

@media (prefers-reduced-motion: no-preference) {
  .status-pill-on::before { animation: bw-blink 2.4s ease-in-out infinite; }
}
@keyframes bw-blink { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

/* ---------- square-ish panels: top hairline + corner ticks ---------- */

.card,
.tile,
.login-card,
.modal-card,
.review-item,
.code-editor-wrap,
.code-body,
.diff-block,
.compile-error-item,
.compile-ok {
  border-radius: var(--bw-radius);
}

.card,
.login-card {
  border-color: var(--border);
  background: var(--bw-graphite-2);
  position: relative;
}
.card::after,
.login-card::after {
  background: linear-gradient(90deg, transparent, var(--bw-hair), transparent);
  left: 0; right: 0;
}
.card::before,
.login-card::before,
.tile::before,
.modal-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; width: 7px; height: 7px;
  border-top: 1px solid var(--bw-tick);
  border-left: 1px solid var(--bw-tick);
  pointer-events: none;
  opacity: .8;
}
.card, .login-card, .tile, .modal-card { overflow: visible; }
.card > *, .login-card > * { position: relative; }

.tile {
  border-radius: var(--bw-radius);
  background: var(--bw-graphite-2);
  position: relative;
}
.tile-label { letter-spacing: .08em; }
.tile-value { text-shadow: none; }

/* ---------- flat outline buttons, the seal fill only for primary ---------- */

.btn {
  border-radius: var(--bw-radius-sm);
  font-weight: 700;
  letter-spacing: .01em;
  transition: background .12s linear, border-color .12s linear, color .12s linear;
}
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: none;
}
.btn-primary:hover { filter: none; background: var(--accent-strong); }
.btn-secondary,
.btn-danger,
.btn-ghost {
  background: transparent;
}
.btn-secondary { border-color: var(--border-strong); color: var(--text); }
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: var(--danger-soft); }

.switch::before { border-radius: var(--bw-radius-sm); }
.switch-thumb { border-radius: var(--bw-radius-sm); }

@media (prefers-reduced-motion: reduce) {
  .btn, .switch::before, .switch-thumb, .nav-item { transition: none !important; }
}

/* ---------- nav: file-tree / command list, leading glyph column ---------- */

.sidebar {
  background: var(--bw-graphite-1);
  border-right: 1px solid var(--bw-hair-dim);
  /* Clip own content to own bounds: console.css translates a closed drawer
     off-screen (translateX(-100%)) but never clips it, so on a mono-width
     brand word the sidebar's own text/pill can paint past its right edge
     and bleed under the topbar while "closed". Overflow hidden here is a
     pure containment fix, scoped to this file's own skin. */
  overflow: hidden;
}
.sidebar-top { border-bottom: 1px solid var(--border); }

.nav-group-label {
  font-size: 10px;
  letter-spacing: .08em;
  position: relative;
  padding-left: 22px;
}
.nav-group-label::before { content: "//"; position: absolute; left: 10px; color: var(--bw-hair-dim); }

.nav-item {
  border-radius: var(--bw-radius-sm);
  font-size: 13px;
  padding-left: 8px;
  display: grid;
  grid-template-columns: 18px 1fr;
  align-items: center;
  gap: 8px;
}
.nav-item svg { grid-column: 1; width: 16px; height: 16px; opacity: .75; }
.nav-item.is-active {
  background: rgba(var(--glow-rgb), 0.08);
  box-shadow: inset 2px 0 0 var(--accent);
  color: var(--accent);
}
.nav-item.is-active svg { opacity: 1; }
.nav-item::before {
  content: "";
  display: none;
}

.sidebar-user { border-top: 1px solid var(--bw-hair-dim); }

/* ---------- tables: compact, sticky headers, mono data ---------- */

.data-table { font-size: 12px; }
.data-table th {
  position: sticky; top: 0; z-index: 1;
  background: var(--bw-graphite-2);
  border-bottom: 1px solid var(--bw-hair-dim);
  font-size: 10px;
  letter-spacing: .06em;
}
.data-table td { padding: 6px 6px; border-bottom: 1px solid var(--border); }
.data-table tr:hover td { background: rgba(var(--glow-rgb), 0.04); }
.cell-mono { color: var(--accent-strong); }

.audit-table-wrap { border: 1px solid var(--border); border-radius: var(--bw-radius); }
.audit-table-wrap .data-table th { top: 0; }

/* ---------- Code room: pro-IDE finish ---------- */

.code-body {
  border-color: var(--bw-hair-dim);
  background: var(--bw-graphite-0);
}
.code-explorer {
  background: var(--bw-graphite-1);
  border-right: 1px solid var(--bw-hair-dim);
}
.code-explorer-item { font-size: 11.5px; border-radius: var(--bw-radius-sm); }
.code-explorer-item.is-active {
  background: rgba(var(--glow-rgb), 0.1);
  box-shadow: inset 2px 0 0 var(--accent);
}
.code-explorer-dir::before { content: "▸ "; color: var(--bw-hair); }

.code-tabs {
  background: var(--bw-graphite-1);
  border-bottom: 1px solid var(--bw-hair-dim);
}
.code-tab {
  border-right: 1px solid var(--border);
  font-size: 11.5px;
}
.code-tab.is-active {
  background: var(--bw-graphite-2);
  box-shadow: inset 0 -2px 0 var(--accent);
}

.code-editor-wrap { border-color: var(--bw-hair-dim); background: var(--bw-graphite-0); }
.code-editor-gutter {
  background: var(--bw-graphite-1);
  border-right: 1px solid var(--bw-hair-dim);
  color: var(--text-faint);
}
.code-editor-textarea { background: var(--bw-graphite-0); }

.code-panels { border-top: 1px solid var(--bw-hair-dim); }
.code-panel-tabs { background: var(--bw-graphite-1); }
.code-panel-tab { border-radius: var(--bw-radius-sm); font-size: 11px; }
.code-panel-tab.is-active { background: rgba(var(--glow-rgb), 0.12); }
.code-panel-body { background: var(--bw-graphite-0); }

/* Bottom status bar strip for the Code room, in the IDE's own idiom.
   Structural only — content, if any, is supplied by js/rooms/code.js;
   this file adds no script and reads no state. Safe to leave empty. */
.code-room { position: relative; padding-bottom: 26px; }
.code-room::after {
  content: "BUILDER — GOVERNANCE WORKBENCH";
  position: absolute; left: 0; right: 0; bottom: 0; height: 22px;
  display: flex; align-items: center; padding: 0 10px;
  font-size: 10px; letter-spacing: .06em;
  background: var(--accent);
  color: var(--accent-contrast);
  border-radius: 0 0 var(--bw-radius) var(--bw-radius);
}

.compile-error-item, .compile-ok { border-radius: var(--bw-radius-sm); }
.diff-block { border-color: var(--bw-hair-dim); background: var(--bw-graphite-0); }

/* ---------- chips: square, hairline, mono ---------- */

.chip { border-radius: var(--bw-radius-sm); border: 1px solid var(--border); background: transparent; }
.chip-ok { border-color: rgba(var(--glow-rgb), 0.4); }
.chip-danger { border-color: rgba(255, 107, 94, 0.4); }
.chip-amber { border-color: rgba(240, 180, 76, 0.4); }
.chip-role-owner { border-color: rgba(var(--glow-rgb), 0.4); }

.ledger-badge { border-radius: var(--bw-radius-sm); border: 1px solid rgba(var(--glow-rgb), 0.4); background: transparent; box-shadow: none; }
.ledger-badge.is-broken { border-color: rgba(255, 107, 94, 0.4); }

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

.field-input,
.field-row input,
.field-row select,
.field-row textarea {
  border-radius: var(--bw-radius-sm);
  background: var(--bw-graphite-1);
}
.field-input:focus,
.field-row input:focus,
.field-row select:focus,
.field-row textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(var(--glow-rgb), 0.35);
}

/* ---------- focus rings — always visible, AA ---------- */

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

/* ==========================================================================
   RESPONSIVE — measured at 375, 768, 1280
   ========================================================================== */

/* 1280 and up: full workbench, wide nav rail already handled by console.css
   at 900px; nothing further required here beyond the chrome above. */

/* 768: tablet — keep 44px targets, tighten the status rail wrap. */
@media (max-width: 900px) {
  .topbar-controls, .topbar-actions { gap: 6px; }
  .status-pill { height: 26px; }
}

/* 375: phone — touch targets stay >= 44px; nav items and code explorer rows
   grow back to a comfortable thumb target even though the desk skin tightens
   their font size. */
@media (max-width: 480px) {
  .nav-item { min-height: 44px; }
  .code-explorer-item { min-height: 34px; display: flex; align-items: center; }
  .btn, .btn-sm { min-height: 44px; }
  .code-room::after { font-size: 9px; padding: 0 8px; }
  .admin-pill::before { margin-right: 4px; padding-right: 4px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}
