/* ============================================================================
   Piping QC Tool — Dark theme overrides
   ----------------------------------------------------------------------------
   Mirrors the existing `html.theme-light .X { … }` rules in index.html
   for `html.theme-dark` so the dark theme actually styles the app instead of
   leaving it half-painted.

   Load order
   ──────────
   tokens.css  →  index.html inline <style>  →  theme-dark.css
   (Dark must come AFTER the inline style so it can override the
    light-leaning rules that were written without a dark counterpart.)

   Most surfaces in index.html already use var(--pc-*) tokens, which
   tokens.css re-binds for dark. This file only patches the places
   where the inline CSS hardcoded a colour or scoped a rule under
   `html.theme-light` without a dark twin.
   ========================================================================= */

/* ── Selection / active colour token (dark mirror) ───────────────────────
   SPEC-2.70 introduced the token; SPEC-2.81 re-pointed its value from the legacy
   pink-red (#e94560) to the brand blue (#2563eb). Theme-stable: identical to the
   tokens.css light value. The CAD canvas/world layer is always dark regardless of
   app theme, so the selection colour must NOT flip per theme. Mirror of tokens.css :root. */
html.theme-dark,
html[data-theme="dark"] { --pc-selected: #2563eb; }

/* ── Body / page chrome ──────────────────────────────────────────────── */
html.theme-dark body { background: var(--pc-body); color: var(--pc-text); }

html.theme-dark .view-hdr {
  background: var(--pc-surface);
  border-bottom-color: var(--pc-border);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}
html.theme-dark .view-hdr h2 { color: var(--pc-text); }
html.theme-dark .view-body { background: var(--pc-body); }

html.theme-dark #view-jobs,
html.theme-dark #view-dashboard { background: var(--pc-body); }

/* ── CAD chrome (was hardcoded dark; now token-driven) ───────────────── */
html.theme-dark #toolbar         { background: var(--pc-surface); border-bottom-color: var(--pc-border); }
html.theme-dark #sidebar-left,
html.theme-dark #sidebar-right   { background: var(--pc-surface); border-color: var(--pc-border); }
html.theme-dark #canvas-container { background: var(--pc-canvas); }  /* SPEC-2.61: follow canvas token (slate), not page body */
html.theme-dark #status-bar      {
  background: var(--pc-sunken);
  color: var(--pc-text-mu);
  border-top: 1px solid var(--pc-border);
}
html.theme-dark .sep             { background: var(--pc-border); }

/* ── Buttons ─────────────────────────────────────────────────────────── */
html.theme-dark .view-hdr .btn,
html.theme-dark .view-body .btn,
html.theme-dark #view-jobs .btn,
html.theme-dark #view-dashboard .btn,
html.theme-dark #view-setup .view-body .btn,
html.theme-dark .modal-actions .btn {
  background: var(--pc-sunken);
  border-color: var(--pc-border-st);   /* SPEC-2.65 (3B) — match light: resting chip edge = --pc-border-st (was --pc-border) */
  color: var(--pc-text);
  box-shadow: none;
}
html.theme-dark .view-hdr .btn:hover,
html.theme-dark .view-body .btn:hover,
html.theme-dark #view-jobs .btn:hover,
html.theme-dark #view-dashboard .btn:hover,
html.theme-dark .modal-actions .btn:hover {
  background: var(--pc-hover);          /* SPEC-2.65 (F8) — hover lifts (was full --accent fill that read as primary) */
  border-color: var(--accent);          /* SPEC-2.65 (F8) — accent edge only, mirroring light-mode hover intent */
  color: var(--pc-text);
}
/* SPEC-2.65 (F8) — active reads as accent-selected (was --danger: semantically wrong + contradicted light). Mirrors light .btn.active. */
html.theme-dark .btn.active        { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-hi); }
html.theme-dark .btn-sm            { background: var(--pc-sunken); border-color: var(--pc-border); color: var(--pc-text-mu); }
html.theme-dark .btn-sm:hover      { background: var(--accent); border-color: var(--accent); color: #fff; }
html.theme-dark .mdr-generate-btn  { background: var(--success); color: #fff; }

/* SPEC-2.83: rail .tool-btn.active override deleted — the §6.4 active style
   (accent-soft bg + accent-hi text, both themes) lives in index.html's
   #sidebar-left block, the single rail styling location. */

/* ── Cards ───────────────────────────────────────────────────────────── */
html.theme-dark .job-card,
html.theme-dark .dash-card,
html.theme-dark .mdr-readiness-bar,
html.theme-dark .portfolio-panel-bar,
html.theme-dark .ndt-stat {
  background: var(--pc-surface);
  border-color: var(--pc-border);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}
html.theme-dark .job-card:hover,
html.theme-dark .dash-card:hover {
  border-color: var(--accent);
  box-shadow: 0 4px 16px rgba(var(--accent-rgb), 0.25);
}
html.theme-dark .job-card h3,
html.theme-dark .dc-title { color: var(--pc-text); }
html.theme-dark .job-meta,
html.theme-dark .dc-detail { color: var(--pc-text-di); }
html.theme-dark .dc-head    { border-bottom-color: var(--pc-border-s); }
html.theme-dark .dc-stat    { color: var(--accent); }
html.theme-dark .dc-action  { color: var(--accent); border-top-color: var(--pc-border-s); }
html.theme-dark .dash-card.soon .dc-action { color: var(--pc-text-di); }

/* ── View tabs ───────────────────────────────────────────────────────── */
html.theme-dark .view-tabs        { border-bottom-color: var(--pc-border); }
html.theme-dark .view-tab         { color: var(--pc-text-di); }
html.theme-dark .view-tab:hover   { color: var(--pc-text-mu); }
html.theme-dark .view-tab.active  { color: var(--pc-text); border-bottom-color: var(--accent); }
html.theme-dark .expiry-banner.has-expired  { background: var(--danger-soft); border-bottom-color: rgba(239,68,68,0.32); color: var(--danger-text); }
html.theme-dark .expiry-banner.has-expiring { background: var(--warning-soft); border-bottom-color: rgba(245,158,11,0.32); color: var(--warning-text); }

/* ── Tables (mirrors the long light-mode table override list) ────────── */
/* SPEC-2.64 — in-job register header band (dark): 7 in-scope tables -> --pc-table-header
   (a step lighter than dark --pc-sunken), keeping the header distinct from the rows. */
html.theme-dark #weld-reg-table th,
html.theme-dark #wps-table th,
html.theme-dark #ndt-lines-table th,
html.theme-dark #tp-table th,
html.theme-dark #calib-table th,
html.theme-dark #lines-table th,
html.theme-dark .bom-table th,
html.theme-dark .lc-table th,
html.theme-dark .pecpr-eq-table th {
  background: var(--pc-table-header);
  color: var(--pc-text);   /* SPEC-2.66 (C2) — header authority: full-strength text (was --pc-text-mu) */
  border-color: var(--pc-border);
}
/* SPEC-2.68 — ITP matrix removed from the dark register-table overrides. The Concept 2 grid
   self-themes via .itp-table + var(--itp-*) (rebound on html.theme-dark in tokens.css); an
   #itp-table ID rule here would outrank the class CSS and leak --pc-* into the grid. */
html.theme-dark #weld-reg-table td,
html.theme-dark #wps-table td,
html.theme-dark #ndt-lines-table td,
html.theme-dark #tp-table td,
html.theme-dark #calib-table td,
html.theme-dark #lines-table td,
html.theme-dark .bom-table td,
html.theme-dark .lc-table td,
html.theme-dark .pecpr-eq-table td {
  color: var(--pc-text);
  border-color: var(--pc-border-s);
  background: var(--pc-surface);
}
html.theme-dark #weld-reg-table tr:hover td,
html.theme-dark #wps-table tr:hover td,
html.theme-dark #ndt-lines-table tr:hover td { background: var(--pc-hover); }

/* Replace the legacy bright-red active row tint with the safety stripe */
html.theme-dark #weld-reg-table tr.wr-active td,
html.theme-light #weld-reg-table tr.wr-active td {
  background: var(--pc-hover);
}
html.theme-dark #weld-reg-table tr.wr-active td:first-child,
html.theme-light #weld-reg-table tr.wr-active td:first-child {
  box-shadow: inset 3px 0 0 var(--pc-safety);
}

/* Even-row striping (was hardcoded rgba(15,52,96,.3)).
   SPEC-2.86 — dark-only now: the light half was dropped so the unified light zebra rule in
   index.html (--pc-table-zebra) isn't beaten by source order. Dark value unchanged. */
html.theme-dark .bom-table tr:nth-child(even) td {
  background: var(--pc-sunken);
}

/* Inline inputs inside tables */
html.theme-dark #weld-reg-table input,
html.theme-dark #weld-reg-table select,
html.theme-dark #wps-table input,
html.theme-dark #wps-table select,
html.theme-dark #lines-table input,
html.theme-dark .bom-table input {
  background: transparent;
  color: var(--pc-text);
}
html.theme-dark #weld-reg-table input:focus,
html.theme-dark #weld-reg-table select:focus,
html.theme-dark #wps-table input:focus,
html.theme-dark #wps-table select:focus,
html.theme-dark #lines-table input:focus,
html.theme-dark .bom-table input:focus {
  background: var(--pc-sunken);
  border-color: var(--accent);
  outline: 0;
  box-shadow: 0 0 0 2px var(--pc-focus);
}

/* ── Modals ──────────────────────────────────────────────────────────── */
html.theme-dark .modal-overlay { background: rgba(0, 0, 0, 0.65); }
html.theme-dark .modal {
  background: var(--pc-surface);
  border-color: var(--pc-border);
  box-shadow: var(--sh-3);
}
html.theme-dark .modal h2 { color: var(--pc-text); border-bottom-color: var(--pc-border-s); }

/* ── Inputs (generic) ────────────────────────────────────────────────── */
/* Cohesion drift-fix F1 — .prop-row input/select removed from this boxed dark
   override. The canvas Properties panel is now a frameless edit surface; its
   index.html base rule (transparent rest → --pc-field-hint underline → bg +
   --accent on hover/focus) is theme-agnostic and resolves correctly in dark via
   the token rebinds, so no dark-specific box is wanted here anymore. */
html.theme-dark .modal-row input,
html.theme-dark .modal-row select,
html.theme-dark #toolbar input[type="text"] {
  background: var(--pc-sunken);
  border-color: var(--pc-border);
  color: var(--pc-text);
}
html.theme-dark .modal-row input:focus,
html.theme-dark .modal-row select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--pc-focus);
  outline: 0;
}

/* ── Sidebar app-shell patches deleted (SPEC-2.83) — the single sidebar
   ruleset lives in theme.css §SIDEBAR; dark mode comes free via the
   --pc-navy* / --pc-pack-blue token rebinds in tokens.css. ─────────────── */

/* ── Status bar at the bottom of CAD chrome (was rgba navy) ──────────── */
html.theme-dark #status-bar,
html.theme-light #status-bar {
  background: var(--pc-sunken);
  color: var(--pc-text-mu);
  border-top: 1px solid var(--pc-border);
}

/* ── Weld map side panel ─────────────────────────────────────────────── */
html.theme-dark #wm-side-panel {
  background: var(--pc-surface);
  border-left-color: var(--pc-border);
}
html.theme-dark #wm-side-panel .wm-panel-field label { color: var(--pc-text-di); }
html.theme-dark #wm-side-panel input,
html.theme-dark #wm-side-panel select {
  background: var(--pc-sunken); border-color: var(--pc-border); color: var(--pc-text);
}

/* ── Toast (pre-existing rules use --success/danger/warning so they work
       in dark already; just bump the readability of the warning variant) */
html.theme-dark .toast.warning { color: #1a1a1a; }
