@import url("section-colors.css");

[hidden] { display: none !important; }

:root {
  color-scheme: light;
  --plane: #e9edf0;
  --surface-1: #ffffff;
  --surface-2: #f2f4f5;
  --surface-strong: #182127;
  --text-primary: #172027;
  --text-secondary: #46545d;
  --text-muted: #66737b;
  --grid: #dfe4e7;
  --axis: #aeb8be;
  --border: #cbd3d8;
  --shadow: 0 2px 0 rgba(23, 32, 39, .08), 0 8px 24px rgba(23, 32, 39, .06);
  --focus-ring: 0 0 0 4px color-mix(in srgb, var(--accent) 28%, transparent);
  --good-wash: #e2f3e7;
  --warning-wash: #fff3d1;
  --field-h: 48px;
  --series-1: #156fa8;
  --series-2: #b6502c;
  --good: #08733f;
  --warning: #d78b00;
  --critical: #b9292f;
  --critical-wash: #fde9e9;
  --accent: #156fa8;
  --radius: 4px;
  --font: "Inter", "Geist Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "Geist Mono", "Roboto Mono", ui-monospace, SFMono-Regular, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --plane: #0e1013;
    --surface-1: #191c20;
    --surface-2: #1f2329;
    --text-primary: #f2f4f7;
    --text-secondary: #c3c8d0;
    --text-muted: #8b93a1;
    --grid: #282d34;
    --axis: #3a4048;
    --border: #2a2f36;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.40);
    --focus-ring: 0 0 0 4px rgba(57, 135, 229, 0.22);
    --good-wash: #10231a;
    --warning-wash: #2a2113;
    --series-1: #3987e5;
    --series-2: #d95926;
    --good: #63d995;
    --warning: #ffd36b;
    --critical: #ff8589;
    --warning-text: #ffd980;
    --good-text: #6ee7a0;
    --critical-wash: #3a1e1e;
    --accent: #3987e5;
    --ok-bg: #10231a;
    --ok-text: #9be7b8;
    --ok-border: #1f5134;
    --warn-bg: #3a1e1e;
    --warn-text: #ffb4b4;
    --warn-border: #6b2a2a;
    --link: #7ab3ff;
    --danger: #ff8589;
  }
}
:root[data-theme="dark"] {
    color-scheme: dark;
    --plane: #0e1013;
    --surface-1: #191c20;
    --surface-2: #1f2329;
    --text-primary: #f2f4f7;
    --text-secondary: #c3c8d0;
    --text-muted: #8b93a1;
    --grid: #282d34;
    --axis: #3a4048;
    --border: #2a2f36;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.40);
    --focus-ring: 0 0 0 4px rgba(57, 135, 229, 0.22);
    --good-wash: #10231a;
    --warning-wash: #2a2113;
    --series-1: #3987e5;
    --series-2: #d95926;
    --good: #63d995;
    --warning: #ffd36b;
    --critical: #ff8589;
    --warning-text: #ffd980;
    --good-text: #6ee7a0;
    --critical-wash: #3a1e1e;
    --accent: #3987e5;
    --ok-bg: #10231a;
    --ok-text: #9be7b8;
    --ok-border: #1f5134;
    --warn-bg: #3a1e1e;
    --warn-text: #ffb4b4;
    --warn-border: #6b2a2a;
    --link: #7ab3ff;
    --danger: #ff8589;
  }


* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--plane);
  color: var(--text-primary);
  font-size: 15px;
  line-height: 1.45;
}

/* ---------- shell ---------- */
header.app {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 24px;
  box-shadow: var(--shadow);
  background: var(--surface-1);
  border-bottom: 1px solid #0c1317;
  background: var(--surface-strong);
  color: #f7fafb;
  position: sticky;
  top: 0;
  z-index: 20;
  flex-wrap: wrap;
}
header.app h1 { font-size: 19px; margin: 0; letter-spacing: .01em; text-transform: uppercase; }
header.app .sub { color: #aebbc2; font-size: 12px; letter-spacing: .035em; }
header.app .spacer { flex: 1; }

nav.tabs { display: flex; gap: 2px; flex-wrap: wrap; background: #0f181d; padding: 3px; border: 1px solid #34434b; border-radius: 3px; }
nav.tabs button {
  border: 1px solid transparent;
  background: none;
  font: inherit;
  font-size: 14px;
  color: #bdc8ce;
  padding: 9px 14px;
  border-radius: 2px;
  cursor: pointer;
}
nav.tabs button { font-weight: 500; }
nav.tabs button:not([aria-selected="true"]):hover { background: #27343b; color: #fff; }
nav.tabs button[aria-selected="true"] {
  background: var(--section-accent, var(--accent));
  color: #fff;
  border-color: var(--section-accent, var(--accent));
  font-weight: 600;
  box-shadow: none;
}
nav.tabs .wallboard-nav-link,
nav.tabs .floor-control-nav-link {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--section-accent);
  background: var(--section-wash);
  color: var(--section-accent);
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  padding: 7px 14px;
  border-radius: 2px;
  text-decoration: none;
  white-space: nowrap;
}
nav.tabs .wallboard-nav-link:hover,
nav.tabs .wallboard-nav-link:focus-visible,
nav.tabs .floor-control-nav-link:hover,
nav.tabs .floor-control-nav-link:focus-visible {
  background: var(--section-accent);
  color: #fff;
  outline: none;
}

main { padding: 24px; max-width: 1500px; margin: 0 auto; }
.view[hidden] { display: none; }

/* ---------- cards / forms ---------- */
.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-top: 4px solid color-mix(in srgb, var(--section-accent, var(--accent)) 75%, #172027);
  border-radius: var(--radius);
  padding: 22px 24px 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}
/* The heading is pulled out to the card edges so it reads as a header strip.
   Negative margins do it, so no card needs its content wrapped in a new element. */
.card > h2 {
  margin: 0 0 20px;
  padding: 0;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: .045em;
  text-transform: uppercase;
  color: var(--text-primary);
  background: transparent;
  border-bottom: 0;
  border-radius: 0;
}
/* A second heading inside the same card is a divider, not another strip. */
.card > h2 ~ h2 {
  margin: 26px 0 20px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  border-radius: 0;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px 14px;
}
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--text-primary); }
.field.wide { grid-column: 1 / -1; }

input, select, textarea, button {
  font: inherit;
  font-family: var(--font);
}
input, select, textarea {
  padding: 9px 11px;
  border: 2px solid var(--axis);
  border-radius: var(--radius);
  background: var(--surface-1);
  color: var(--text-primary);
  width: 100%;
  box-shadow: inset 0 1px 2px rgba(16, 24, 40, 0.04);
}
input:not([type="checkbox"]), select { min-height: var(--field-h); }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}
textarea { min-height: 62px; resize: vertical; }

input.reading { font-size: 20px; font-weight: 700; text-align: center; font-variant-numeric: tabular-nums; }

/* out-of-tolerance state — color plus an icon + message, never color alone */
.field.out input { border-color: var(--critical); background: var(--critical-wash); color: var(--critical); font-weight: 700; box-shadow: 0 0 0 4px rgba(208, 59, 59, 0.10); }
.field.out label { color: var(--critical); }
.field.bad input { border-color: var(--critical); }
.msg { font-size: 12px; min-height: 15px; color: var(--critical); font-weight: 600; }
.msg.ok { color: var(--good); }
.msg.hint { color: var(--text-muted); font-weight: 400; }

.limits { font-size: 12px; color: var(--text-muted); font-variant-numeric: tabular-nums; }

.btn {
  padding: 0 18px;
  min-height: var(--field-h);
  border-radius: 3px;
  border: 2px solid var(--axis);
  background: var(--surface-1);
  color: var(--text-primary);
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 2px 0 rgba(23, 32, 39, .12);
}
.btn:hover { border-color: var(--text-muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 800; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--critical); border-color: var(--critical); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.sm { padding: 0 12px; min-height: 32px; font-size: 13px; }

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }

/* ---------- banners ---------- */
.banner {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 14px 16px; border-radius: var(--radius);
  font-size: 14px; margin-bottom: 16px;
  border: 2px solid var(--border);
  border-left-width: 6px;
  font-weight: 650;
}
.banner .ico { font-size: 16px; line-height: 1.2; }
.banner.good { background: color-mix(in srgb, var(--good) 12%, var(--surface-1)); border-color: var(--good); }
.banner.bad { background: var(--critical-wash); border-color: var(--critical); }
.banner.warn { background: color-mix(in srgb, var(--warning) 18%, var(--surface-1)); border-color: var(--warning); }
.banner[hidden] { display: none; }

/* ---------- table ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-1); }
table { border-collapse: collapse; width: 100%; font-size: 13.5px; white-space: nowrap; }
th, td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--grid); }
th {
  position: sticky; top: 0; background: var(--surface-2); z-index: 1;
  font-size: 11.5px; font-weight: 800; letter-spacing: 0.055em;
  text-transform: uppercase; color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
}
tbody tr:hover { background: var(--plane); }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
td.flagged {
  color: var(--critical); font-weight: 700; background: var(--critical-wash);
}
td.notes { white-space: normal; min-width: 220px; max-width: 380px; }
.empty { padding: 30px; text-align: center; color: var(--text-muted); }

.pill {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11.5px; font-weight: 800; padding: 4px 9px; border-radius: 2px;
  border: 1px solid currentColor; background: var(--critical-wash); color: var(--critical);
}

/* ---------- stat tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 18px; }
.tile {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 20px;
  box-shadow: var(--shadow);
  position: relative; overflow: hidden;
}
/* Thin accent keyed to what the tile says. :has() keeps this in CSS, so the code
   that renders the tiles does not need to grow status classes. */
.tile::before { content: none; }
.tile:has(.value.bad)::before { background: var(--critical); }
.tile .label { font-size: 13px; font-weight: 500; color: var(--text-secondary); }
.tile .value { font-size: 34px; font-weight: 700; letter-spacing: -0.02em; margin-top: 6px; font-variant-numeric: tabular-nums; }
.tile .value.bad { color: var(--critical); }
.tile .foot { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }

/* ---------- charts ---------- */
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(420px, 100%), 1fr)); gap: 16px; }
.chart-card { background: var(--surface-1); border: 1px solid var(--border); border-radius: 14px; padding: 20px; box-shadow: var(--shadow); }
.chart-card h3 { margin: 0 0 2px; font-size: 14px; }
.chart-card .caption { margin: 0 0 10px; font-size: 12px; color: var(--text-muted); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--text-secondary); margin-bottom: 6px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
svg { display: block; width: 100%; height: auto; overflow: visible; }
svg text { font-family: var(--font); font-size: 11px; fill: var(--text-muted); }
svg .grid-line { stroke: var(--grid); stroke-width: 1; }
svg .axis-line { stroke: var(--axis); stroke-width: 1; }
svg .hit { fill: transparent; cursor: pointer; }

.tooltip {
  position: fixed; pointer-events: none; z-index: 100;
  background: var(--surface-1); border: 1px solid var(--border);
  box-shadow: 0 6px 20px rgba(0,0,0,0.18);
  border-radius: var(--radius); padding: 8px 11px; font-size: 12px;
  color: var(--text-primary); max-width: 260px;
}
.tooltip[hidden] { display: none; }
.tooltip b { display: block; margin-bottom: 3px; }

/* ---------- modal ---------- */
dialog {
  border: 2px solid var(--border); border-top: 5px solid var(--accent); border-radius: var(--radius); padding: 20px;
  background: var(--surface-1); color: var(--text-primary);
  max-width: 900px; width: 92vw;
}
dialog::backdrop { background: rgba(0,0,0,0.45); }

.identity { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.identity select { width: auto; min-width: 150px; }

/* ---------- supervisor alert ---------- */
/* Deliberately loud: this is the one dialog on the shop floor that must not be
   skimmed past. Colour is backed by an icon and the heading text, never alone. */
dialog.supervisor {
  max-width: 520px;
  border: 3px solid var(--critical);
  border-radius: 14px;
  padding: 24px 26px;
}
dialog.supervisor::backdrop { background: rgba(120, 0, 0, 0.55); }
.sv-head { display: flex; align-items: center; gap: 12px; }
.sv-head h2 { margin: 0; font-size: 24px; color: var(--critical); letter-spacing: -0.01em; }
.sv-ico { font-size: 32px; line-height: 1; color: var(--critical); }
.sv-lead { margin: 14px 0 8px; color: var(--text-secondary); font-size: 14px; }
dialog.supervisor ul { margin: 0; padding-left: 22px; }
dialog.supervisor li { margin-bottom: 6px; font-weight: 600; }
.sv-ack {
  display: flex; align-items: center; gap: 10px;
  margin-top: 20px; padding: 12px 14px;
  border: 1px solid var(--axis); border-radius: var(--radius);
  background: var(--plane); cursor: pointer; font-weight: 600;
}
.sv-ack input { width: 20px; height: 20px; cursor: pointer; }
.sv-ack:has(input:checked) { border-color: var(--good); color: var(--good); }
.quality-hold-facts { display: grid; gap: 8px; margin: 16px 0; }
.quality-hold-facts > div {
  display: grid; grid-template-columns: 130px 1fr; gap: 12px;
  padding-bottom: 8px; border-bottom: 1px solid var(--border);
}
.quality-hold-facts dt {
  color: var(--text-muted); font-size: 11px; font-weight: 800;
  letter-spacing: .06em; text-transform: uppercase;
}
.quality-hold-facts dd { margin: 0; font-weight: 700; overflow-wrap: anywhere; }
.quality-hold-next { margin: 14px 0 0; font-weight: 700; }

/* Sample colour check on a non-bronze: present but visibly not in play. */
.field.not-applicable { opacity: .5; }
.field.not-applicable select { background: var(--plane); cursor: not-allowed; }

/* The instructions, shown inside the app. */
#help-frame { display: block; width: 100%; height: 78vh; border: 0; background: var(--surface); }

/* A reading that was never taken — amber outline, hollow. */
.field.missing input { border-color: var(--warning); background: color-mix(in srgb, var(--warning) 12%, var(--surface-1)); }

/* In tolerance but in the upper half of the band. Solid amber fill and a bold
   value, so it never reads as the hollow "no reading taken" state above. */
.field.watch input {
  border-color: var(--warning); border-width: 2px;
  background: color-mix(in srgb, var(--warning) 26%, var(--surface-1));
  color: #6b4b00; font-weight: 700;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .field.watch input { color: #ffd980; }
}
:root[data-theme="dark"] .field.watch input { color: #ffd980; }

.msg.watch { color: #8a6100; font-weight: 700; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .msg.watch { color: var(--warning); }
}
:root[data-theme="dark"] .msg.watch { color: var(--warning); }

td.watch { background: color-mix(in srgb, var(--warning) 20%, transparent); font-weight: 700; }
.msg.warn { color: #8a6100; font-weight: 600; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .msg.warn { color: var(--warning); }
}
:root[data-theme="dark"] .msg.warn { color: var(--warning); }


/* Seal test failed — same red language as an out-of-tolerance reading. */
.field.out select { border-color: var(--critical); background: var(--critical-wash); color: var(--critical); font-weight: 700; }

/* ---------- brand mark ---------- */
header.app .brand { display: flex; align-items: center; gap: 12px; }
header.app .mark {
  width: 38px; height: 38px; flex: none;
  border-radius: 2px;
  display: grid; place-items: center;
  background: var(--section-accent, var(--accent));
  color: #fff; font-weight: 800; font-size: 13px; letter-spacing: -0.02em;
}

/* ---------- admin sub-tabs ---------- */
.admin-head {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-bottom: 16px;
}
.admin-head-spacer { flex: 1; }

nav.subtabs {
  display: flex; gap: 2px; flex-wrap: wrap;
  background: var(--plane); padding: 4px; border-radius: var(--radius);
  border: 1px solid var(--border);
}
nav.subtabs button {
  font: inherit; font-size: 14px; font-weight: 500; cursor: pointer;
  border: 1px solid transparent; background: none; color: var(--text-secondary);
  padding: 8px 15px; border-radius: 2px;
}
nav.subtabs button:not([aria-selected="true"]):hover { background: var(--surface-1); }
nav.subtabs button[aria-selected="true"] {
  background: var(--surface-2); border-color: var(--axis); color: var(--text-primary);
  font-weight: 600; box-shadow: none;
}

.subview[hidden] { display: none; }

/* Collapsed sections inside a card (e.g. the backup file list). */
summary.disclosure {
  cursor: pointer; font-size: 13px; font-weight: 600;
  color: var(--text-secondary); padding: 8px 0;
  list-style: none;
}
summary.disclosure::-webkit-details-marker { display: none; }
summary.disclosure::before { content: "▸ "; color: var(--text-muted); }
details[open] > summary.disclosure::before { content: "▾ "; }
summary.disclosure:hover { color: var(--text-primary); }

/* A long managed list (customers can run to hundreds) scrolls inside the card
   rather than turning the admin page into a mile of table. The sticky header
   keeps the column labels visible, and the Find box searches every row, not
   just the ones on screen. */
.table-wrap.tall { max-height: 60vh; overflow-y: auto; }

/* Factory-floor interaction and accessibility */
button:focus-visible,
a:focus-visible,
summary:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.identity label {
  color: #bdc8ce;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .05em;
  text-transform: uppercase;
}
.identity input,
.identity select {
  min-height: 40px;
  border-color: var(--axis);
  background: var(--surface-1);
}

@media (max-width: 760px) {
  header.app { padding: 10px 12px; gap: 10px; }
  main { padding: 14px 12px; }
  .card { padding: 18px 14px; }
  nav.tabs { order: 3; width: 100%; }
  nav.tabs button, nav.tabs a { flex: 1 1 auto; justify-content: center; }
  .btn { min-height: 48px; }
}

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