/* Layer 1.5 theme base — consumes var() only, NO hex literals (spec §13).
 * Scope = Q3=a (consumer-driven): typography, layout, links, tables, forms,
 * buttons, status pills, focus, + sidebar nav & device sub-tabs (Layer 1.9
 * consumers). NO modals/drawers/progress/log-console (no consumer yet).
 * Loaded AFTER tokens.css. */

/* ── Layout + typography ──────────────────────────────────────────── */
/* Reserve the vertical-scrollbar gutter so a list-length change (e.g. live
 * search re-rendering per keystroke) does NOT toggle the scrollbar on/off —
 * that toggles viewport width ~15px, recentering the `.page` + header (both
 * margin:0 auto) and reflowing the whole page horizontally (operator-reported,
 * chunk-layout-stable). Degrades to the old behavior on pre-2022 browsers. */
html { scrollbar-gutter: stable; }

body {
  margin: 0;
  background: var(--deep-space);
  color: var(--starlight);
  font-family: var(--font-body);
  font-size: var(--fs-body);
  line-height: 20px;
  -webkit-font-smoothing: antialiased;
}

.page {
  padding: 24px 28px;
  max-width: 1200px;
  margin: 0 auto;
}

/* Form column cap (Layer 1.7) — child combinator scopes to a page-level form
 * (customer_new) ONLY; the customers table's inline display:inline button-forms
 * are nested in <td>, never direct children of .page, so they stay untouched.
 * Checkbox/radio excluded so is_business / is_beta_tester don't stretch. */
.page > form { max-width: 520px; }
.page > form input:not([type="checkbox"]):not([type="radio"]),
.page > form textarea,
.page > form select {
  width: 100%;
  box-sizing: border-box;
}

/* §17.A readability fix (2026-06-26): Inter, not Orbitron — the wide geometric
 * display face bled/merged at h1/h2 sizes on the dark base. Orbitron stays on
 * .wordmark + hero only. No text-shadow on headings (none was ever set; the
 * perceived "glow" was Orbitron's anti-alias bloom). Weight 600 + starlight
 * (inherited from body) per the directive. */
h1, h2, h3 {
  font-family: var(--font-heading);
  font-weight: 600;
  line-height: 1.2;
  margin: 0 0 0.5em;
}
h1 { font-size: var(--fs-h1); }
h2 { font-size: var(--fs-h2); }
h3 { font-size: var(--fs-h3); }

a {
  color: var(--accent-primary);
  text-decoration: none;
}
a:hover { text-decoration: underline; }

/* ── Tables ───────────────────────────────────────────────────────── */
table {
  border-collapse: collapse;
  width: 100%;
}
th {
  font-size: var(--fs-small);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted-comm);
  text-align: left;
  font-weight: 600;
}
th, td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--gunmetal);
}

/* ── Forms ────────────────────────────────────────────────────────── */
label {
  display: block;
  font-size: var(--fs-small);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted-comm);
  margin-bottom: 4px;
}
input, textarea, select {
  background: var(--hull-grey);
  border: 1px solid var(--gunmetal);
  color: var(--starlight);
  font-family: var(--font-body);
  font-size: var(--fs-body);
  padding: 8px 10px;
  border-radius: 4px;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent-primary);
}

.field-error {
  color: var(--rocket-rust);
  font-size: var(--fs-small);
}

/* ── Buttons (§9.1) ───────────────────────────────────────────────── */
button {
  font-family: var(--font-body);
  font-size: var(--fs-body);
  color: var(--starlight);
  background: transparent;
  border: 1px solid var(--accent-primary);
  border-radius: 4px;
  padding: 6px 14px;
  cursor: pointer;
  transition: background 0.15s ease, box-shadow 0.15s ease, transform 0.1s ease;
}
button:hover {
  background: var(--accent-primary);
  color: var(--deep-space);
  box-shadow: 0 0 4px var(--accent-primary);
  transform: translateY(-2px);
}
button:active { transform: scale(0.98); }
button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
  background: transparent;
}

/* ── Status pills (color + icon + text) ───────────────────────────── */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  padding: 0.15em 0.6em;
  border-radius: 999px;
  border: 1px solid;
  font-size: var(--fs-small);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.pill svg { width: 14px; height: 14px; }

.pill-info {
  color: var(--plasma-cyan);
  border-color: var(--plasma-cyan);
  background: color-mix(in srgb, var(--plasma-cyan) 15%, transparent);
}
.pill-success {
  color: var(--groot-bioluminescent);
  border-color: var(--groot-bioluminescent);
  background: color-mix(in srgb, var(--groot-bioluminescent) 15%, transparent);
}
.pill-warn {
  color: var(--quill-amber);
  border-color: var(--quill-amber);
  background: color-mix(in srgb, var(--quill-amber) 15%, transparent);
}
.pill-danger {
  color: var(--rocket-rust);
  border-color: var(--rocket-rust);
  background: color-mix(in srgb, var(--rocket-rust) 15%, transparent);
}
.pill-neutral {
  color: var(--muted-comm);
  border-color: var(--muted-comm);
  background: color-mix(in srgb, var(--muted-comm) 15%, transparent);
}

/* ── Focus (§10.4) + reduced motion (§10.3) ───────────────────────── */
:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}
@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
  button:hover { transform: none; }
}

/* ── Identity strip + wordmark (Layer 1.6) ───────────────────────── */
.identity-strip {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 3px;
  background: var(--accent-primary);
  z-index: 100;
}
.identity-header {
  display: flex;
  align-items: center;
  gap: 0.5em;
  padding: 16px 28px 0;
  max-width: 1200px;
  margin: 0 auto;
}
.wordmark-glyph {
  color: var(--accent-primary);
  display: inline-flex;
}
.wordmark-glyph svg { width: 24px; height: 24px; }
.wordmark {
  font-family: var(--font-display);
  font-size: 28px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent-primary);
  text-shadow: 0 0 1px var(--accent-primary);
}

/* ── Sidebar nav (Layer 1.9 §9.4) ─────────────────────────────────── */
/* 2-column layout engages ONLY on authed pages with nav (body.has-nav set by
 * base.html); every other render stays single-column (byte-identical). */
body.has-nav {
  display: grid;
  grid-template-columns: 200px minmax(0, 1fr);
}
body.has-nav .identity-header { grid-column: 1 / -1; }
/* The content column shrinks to its content when it's a grid item (body.has-nav)
 * with auto side-margins — a grid item with `margin:0 auto` uses its max-content
 * width, not the column width. So `.page` tracked the table's content width
 * (narrower with fewer/shorter rows) and recentered on every filter → whole-frame
 * shift (operator-reported, chunk-page-width-stable; the table is already
 * width:100%, so .page is the sole cause). An explicit width:100% gives the grid
 * item the column width (content-independent); box-sizing keeps the 28px padding
 * from overflowing. Single-column (login, no has-nav) renders untouched. */
body.has-nav .page { width: 100%; box-sizing: border-box; }

.sidenav {
  padding: 16px 0 16px 16px;
}
.sidenav a {
  display: flex;
  align-items: center;
  gap: 0.5em;
  padding: 8px 12px;
  color: var(--muted-comm);
  border-left: 3px solid transparent;  /* reserved so .current's bar doesn't shift text */
}
.sidenav a:hover { color: var(--starlight); text-decoration: none; }
.sidenav a.current {
  color: var(--starlight);
  border-left-color: var(--accent-primary);
}
.sidenav a.current svg { color: var(--accent-primary); }  /* two-tone: starlight text + accent icon */
.sidenav svg { width: 16px; height: 16px; }  /* CSS pin over intrinsic attrs (1.8 defense-in-depth) */

/* ── Device sub-tabs (Layer 1.9 §9.4/§5.4) ────────────────────────── */
.tabs {
  display: flex;
  gap: 1.25em;
  margin: 12px 0;
  border-bottom: 1px solid var(--gunmetal);
}
.tab {
  color: var(--muted-comm);
  text-decoration: none;
  padding: 6px 2px;
  border-bottom: 2px solid transparent;  /* reserved so .current's underline doesn't shift */
}
a.tab:hover {  /* override global a:hover underline (theme-base.css a:hover) */
  color: var(--starlight);
  text-decoration: none;
  border-bottom-color: color-mix(in srgb, var(--accent-primary) 40%, transparent);
}
.tab.current {
  color: var(--starlight);
  border-bottom-color: var(--accent-primary);
  box-shadow: 0 4px 8px -4px var(--accent-primary);  /* soft accent glow beneath */
}

/* ── Fleet metric strip (M08-metrics Phase 2) — per-status counts + total ── */
/* Clickable overview cards = status-filter shortcuts; counts are whole-fleet
 * (unfiltered). Modeled on .pill / .fleet-filters (var()-only, §13). */
.fleet-metrics { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.metric-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 88px;
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid var(--hull-grey);
  background: transparent;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.metric-card:hover { border-color: var(--accent-primary); }
.metric-card-current {
  border-color: var(--accent-primary);
  background: color-mix(in srgb, var(--accent-primary) 12%, transparent);
}
.metric-count { font-weight: 600; font-size: var(--fs-h2); }
.metric-label { font-size: var(--fs-small); text-transform: uppercase; letter-spacing: 0.04em; }

/* ── Fleet filter bar (M08-2 Phase 2a) — first filter convention ─────── */
/* Wrapped in <section class="fleet-filters"> so the form is NOT a direct
 * child of .page → escapes the L1.7 data-entry-form cap (.page > form). */
.fleet-filters { margin-bottom: 16px; }
.fleet-filters form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.fleet-filters input[type="text"] { flex: 1 1 220px; }

/* ── Row actions kebab (chunk-customers-actions-menu) ──────────────── */
/* Per-row Actions collapse into a JS-free <details> popover (Edit + the
 * state-valid lifecycle forms). Absolute popover anchored to .row-actions
 * (the <details>), NOT the <td> (table-cell positioning is quirky); the
 * ancestor chain is overflow-visible (verified) so it won't clip. Opaque
 * bg overlays the row beneath. var()-only per §13. */
.row-actions { position: relative; display: inline-block; }
.row-actions > summary {
  list-style: none;
  cursor: pointer;
  padding: 2px 10px;
  font-size: var(--fs-h3);
  line-height: 1;
  border-radius: 6px;
}
.row-actions > summary::-webkit-details-marker { display: none; }
.row-actions > summary:hover { background: var(--gunmetal); }
.row-actions-menu {
  position: absolute;
  right: 0;
  z-index: 10;
  min-width: 160px;
  margin-top: 4px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--panel-grey);
  border: 1px solid var(--hull-grey);
  border-radius: 8px;
  box-shadow: 0 6px 16px -6px rgba(0, 0, 0, 0.6);
}
.row-actions-menu a,
.row-actions-menu button,
.row-actions-menu form {
  display: block;
  width: 100%;
  text-align: left;
  white-space: nowrap;
}

/* ── Mobile breakpoint (Layer 1.7 + 1.9) — tighten padding; nav collapses ── */
@media (max-width: 640px) {
  .page { padding: 24px 16px; }
  .identity-header { padding: 16px 16px 0; }
  body.has-nav { display: block; }
  .sidenav {
    display: flex;
    gap: 1em;
    padding: 8px 16px 0;
  }
  .sidenav a {
    border-left: none;
    border-bottom: 3px solid transparent;  /* left-bar rotates to underline, coherent with tabs */
  }
  .sidenav a.current {
    border-left-color: transparent;
    border-bottom-color: var(--accent-primary);
  }
}
