/* Inspection-line demo: a full-screen control-panel layout. System fonts only, so it runs offline. */
:root {
  --bg: #061619;
  --surface: #0a2227;
  --surface-2: #0f2e34;
  --surface-3: #153b42;
  --border: rgba(199, 216, 209, .14);
  --text: #e9efea;
  --muted: #93aca8;
  --faint: #6c8784;
  --accent: #e07a55;
  --good: #74c28c;
  --warn: #edba65;
  --reject: #ef6f5a;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Consolas, "Liberation Mono", monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 var(--sans); }
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: not-allowed; }
a { color: inherit; text-decoration: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.app { min-height: 100vh; display: grid; grid-template-rows: auto 1fr; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* ---------- App bar ---------- */
.appbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: .75rem 1.5rem;
  padding: .6rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border);
}
.appbar-id { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem .85rem; min-width: 0; }
.brand { font-weight: 800; font-size: 1.05rem; letter-spacing: -.06em; }
.brand i { font-style: normal; color: var(--accent); padding-inline: .12em; }
.appbar h1 { margin: 0; font-size: .95rem; font-weight: 650; white-space: nowrap; }
.appbar-status { display: flex; align-items: center; gap: .75rem; font: 500 .72rem var(--mono); }
.line-pill {
  display: inline-flex; align-items: center; gap: .45rem; padding: .3rem .6rem;
  border-radius: 999px; background: rgba(116, 194, 140, .12); color: var(--good); letter-spacing: .05em;
}
.line-pill b { font-weight: 600; }
.live-dot { width: .5rem; height: .5rem; border-radius: 50%; background: currentColor; }
.line-pill[data-state="run"] .live-dot { animation: blink 1.6s ease-in-out infinite; }
.line-pill[data-state="paused"] { background: rgba(237, 186, 101, .12); color: var(--warn); }
.line-pill[data-state="hold"] { background: rgba(239, 111, 90, .16); color: var(--reject); }
.line-pill[data-state="hold"] .live-dot { animation: blink .7s ease-in-out infinite; }
.clock { color: var(--muted); font-variant-numeric: tabular-nums; }
.tally { display: inline-flex; align-items: center; gap: .4rem; padding: .3rem .6rem; border: 1px solid var(--border); border-radius: 6px; color: var(--muted); }
.tally i { width: .5rem; height: .5rem; border-radius: 2px; }
.tally.main i { background: var(--good); }
.tally.reject i { background: var(--reject); }
.tally b { min-width: 1.6ch; color: var(--text); font-size: .85rem; font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }

.appbar-controls { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin-left: auto; }
.segmented { display: flex; margin: 0; padding: 2px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); }
.segmented legend { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.segmented label { position: relative; }
.segmented input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.segmented span { display: block; padding: .32rem .7rem; border-radius: 4px; color: var(--muted); font-size: .78rem; font-weight: 600; }
.segmented input:checked + span { background: var(--surface-3); color: var(--text); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }
.run-button {
  min-width: 7.5rem; padding: .42rem .9rem; border: 0; border-radius: 6px;
  background: var(--text); color: var(--bg); font-size: .78rem; font-weight: 700;
}
.run-button[aria-pressed="false"] { background: var(--good); }
.run-button:disabled { opacity: .35; }
.icon-button {
  width: 2rem; height: 2rem; border: 1px solid var(--border); border-radius: 50%;
  background: transparent; color: var(--muted); font-weight: 700;
}
.icon-button:hover { color: var(--text); border-color: var(--muted); }

/* ---------- Workspace ---------- */
.workspace {
  display: grid; gap: 1px; background: var(--border);
  grid-template-columns: minmax(0, 1fr) minmax(19rem, 23rem);
  grid-template-rows: 1fr auto;
}
.line-view, .operator-panel, .policy-panel { background: var(--surface); min-width: 0; }
.line-view { display: flex; flex-direction: column; }
.operator-panel { grid-row: 1 / span 2; grid-column: 2; display: flex; flex-direction: column; }
.policy-panel { grid-column: 1; }

.pane-head {
  display: flex; justify-content: space-between; align-items: baseline; gap: 1rem;
  padding: .55rem 1rem; border-bottom: 1px solid var(--border);
  color: var(--muted); font: 500 .68rem var(--mono); letter-spacing: .06em; text-transform: uppercase;
}
.pane-head strong { color: var(--text); font-weight: 600; }

/* ---------- Conveyor ---------- */
/* A faint grid fills any space around the fixed-ratio conveyor, so it reads as part of the camera view. */
.line-view {
  background-color: #071c20;
  background-image: linear-gradient(rgba(233, 239, 234, .035) 1px, transparent 1px), linear-gradient(90deg, rgba(233, 239, 234, .035) 1px, transparent 1px);
  background-size: 32px 32px;
}
.conveyor {
  position: relative; width: 100%; margin-block: auto; aspect-ratio: 2.15 / 1; overflow: hidden;
  background: linear-gradient(180deg, #0b2a2f 0 62%, #05181b 62%);
}
.track {
  position: absolute; left: 0; right: 0; display: flex; align-items: center;
  color: var(--faint); font: 500 .62rem var(--mono); letter-spacing: .06em; text-transform: uppercase;
}
.track::before {
  content: ""; position: absolute; left: 0; right: 0; top: 50%; height: 1px;
  background: repeating-linear-gradient(90deg, rgba(233, 239, 234, .16) 0 14px, transparent 14px 28px);
}
.track span { position: relative; z-index: 1; margin-left: 1rem; padding: .15rem .35rem; background: #0b2a2f; }
.reject-track span { background: #05181b; color: var(--reject); opacity: .8; }
.main-track { top: 47%; height: 28%; }
.reject-track { top: 73%; height: 18%; }

.camera-zone {
  position: absolute; z-index: 4; top: 0; bottom: 0; left: 46%; width: 9%;
  display: flex; flex-direction: column; align-items: center;
  border-inline: 1px solid rgba(233, 239, 234, .3); background: rgba(233, 239, 234, .035); pointer-events: none;
}
.camera-label { margin-top: .8rem; padding: .2rem .35rem; background: #d4e2da; color: var(--bg); font: 600 .58rem var(--mono); letter-spacing: .06em; }
.camera-icon {
  display: grid; place-items: center; width: 2.2rem; height: 2.2rem; margin-top: .6rem;
  border: 1px solid #c7d8d1; border-radius: 50%; color: #c7d8d1; font-size: 1rem;
}
.scan-beam { position: absolute; top: 5rem; bottom: 0; width: 2px; background: linear-gradient(var(--accent), transparent); opacity: 0; }
.camera-zone.is-scanning .scan-beam { animation: scan .9s ease-out; }

/* Diverter: a cylinder above the main line drives a pusher plate that shoves the board into the reject lane.
   Positions are % of conveyor height; the pusher's travel matches the board's move from top 39% to 61%. */
.diverter { position: absolute; z-index: 3; top: 0; bottom: 0; left: 13%; width: 17%; pointer-events: none; }
.cylinder {
  position: absolute; top: 8%; left: 32%; width: 36%; height: 17%; border-radius: 5px;
  background: linear-gradient(90deg, #5d7470, #b9c9c4 45%, #7d938e);
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, .25), 0 6px 14px rgba(0, 0, 0, .4);
  display: grid; place-items: center;
}
.cylinder::before { content: ""; position: absolute; left: -12%; right: -12%; top: -12%; height: 22%; border-radius: 3px; background: #42564f; }
.cylinder span { color: #0b2226; font: 700 .52rem var(--mono); letter-spacing: .08em; }
.rod {
  position: absolute; top: 25%; left: calc(50% - 4px); width: 8px; height: 10.5%;
  background: linear-gradient(90deg, #8ea39e, #eef3f0, #8ea39e); transition: height .3s ease;
}
.pusher {
  position: absolute; top: 35.5%; left: 0; right: 0; height: 3.2%; border-radius: 3px;
  background: linear-gradient(#f0b257, #d9892f); box-shadow: 0 3px 8px rgba(0, 0, 0, .45);
  transition: top .3s ease, background .3s ease;
}
.pusher::after { content: ""; position: absolute; inset: 0; border-radius: inherit; background: repeating-linear-gradient(135deg, transparent 0 7px, rgba(0, 0, 0, .28) 7px 13px); }
.diverter.is-active .rod { height: 32.5%; }
.diverter.is-active .pusher { top: 57.5%; background: linear-gradient(#ff8a6e, var(--reject)); }

.board { position: absolute; z-index: 2; top: 39%; left: 110%; width: 42%; transition: top .3s ease; }
.board.is-diverted { top: 61%; }
.board-frame { position: relative; overflow: hidden; aspect-ratio: 1200 / 439; background: #204a50; box-shadow: 0 12px 28px rgba(0, 0, 0, .45); }
.board-frame > img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: fill; }
.board-frame .mask { opacity: 0; mix-blend-mode: screen; transition: opacity .25s ease; }
.board.is-scanned .mask { opacity: .42; }
.boxes, .markers { position: absolute; inset: 0; pointer-events: none; }
.feature-box { position: absolute; border: 2px solid var(--feature); }
.feature-marker {
  position: absolute; display: grid; place-items: center; min-width: 1.2rem; height: 1.2rem; padding: 0 .15rem;
  background: var(--feature); color: var(--bg); font: 600 .6rem var(--mono); transform: translate(-20%, -20%);
}
.board-meta { display: flex; justify-content: space-between; gap: .5rem; padding: .35rem .55rem; background: #04130f; color: #c7d8d1; font: 500 .6rem var(--mono); letter-spacing: .04em; }

/* ---------- Operator panel ---------- */
.operator-body { flex: 1; display: flex; flex-direction: column; padding: 1rem 1.1rem 1.1rem; }
.kicker { margin: 0 0 .2rem; color: var(--faint); font: 500 .66rem var(--mono); letter-spacing: .06em; text-transform: uppercase; }
.operator-panel h2 { margin: 0 0 1rem; font-size: 2.4rem; line-height: 1.1; letter-spacing: -.02em; }
.operator-panel h2[data-tone="good"] { color: var(--good); }
.operator-panel h2[data-tone="reject"] { color: var(--reject); }
.feature-list { display: grid; gap: .1rem; min-height: 3rem; margin: 0; padding: 0; list-style: none; }
.feature-list li { display: flex; align-items: center; gap: .55rem; padding: .35rem .5rem; border-radius: 4px; color: var(--muted); font-size: .82rem; }
.feature-list li.is-over { background: rgba(239, 111, 90, .1); }
.feature-list li.is-over span { color: var(--text); font-weight: 650; }
.feature-list i { width: .65rem; height: .65rem; flex: none; background: var(--feature); }
.feature-list em { margin-left: auto; color: var(--faint); font: 500 .72rem var(--mono); font-style: normal; }
.feature-list li.is-over em { color: var(--reject); }
.operator-actions { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; margin-top: auto; padding-top: 1rem; }
.operator-actions button {
  min-height: 4rem; padding: .6rem; border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface-2); font-size: 1rem; font-weight: 700;
}
.operator-actions button.divert:not(:disabled) { border-color: var(--reject); background: rgba(239, 111, 90, .16); color: #ffd9d1; }
.operator-actions button:not(:disabled):hover { filter: brightness(1.2); }
.operator-actions button:disabled { opacity: .3; }
.operator-note { margin: .75rem 0 0; color: var(--faint); font-size: .78rem; }

/* ---------- Policy panel ---------- */
.policy-note { text-transform: none; letter-spacing: 0; color: var(--faint); text-align: right; }
.threshold-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: .75rem 1.25rem; padding: .8rem 1rem 1rem; }
.threshold { display: grid; gap: .3rem; }
.threshold-name { display: flex; align-items: center; gap: .45rem; font-size: .82rem; font-weight: 650; }
.threshold-name i { width: .65rem; height: .65rem; background: var(--feature); }
.threshold input { width: 100%; margin: 0; accent-color: var(--feature); }
.threshold output { color: var(--muted); font: 500 .72rem var(--mono); }


/* ---------- About dialog ---------- */
.about {
  width: min(36rem, calc(100vw - 2rem)); padding: 1.5rem; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text);
}
.about::backdrop { background: rgba(2, 10, 12, .7); }
.about h2 { margin: 0 0 .75rem; font-size: 1.25rem; }
.about h3 { margin: 1.25rem 0 .5rem; font-size: .9rem; }
.about p, .about li { color: var(--muted); }
.about ol { margin: 0; padding-left: 1.2rem; display: grid; gap: .35rem; }
.about-warning { padding: .6rem .75rem; border-left: 3px solid var(--warn); background: rgba(237, 186, 101, .08); color: var(--warn) !important; }
.about-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 1rem; margin-top: 1.5rem; }
.about-actions a { color: var(--accent); font-weight: 600; font-size: .85rem; }
.about-actions button { margin-left: auto; padding: .5rem 1rem; border: 0; border-radius: 6px; background: var(--text); color: var(--bg); font-weight: 700; }

@keyframes scan { 0% { opacity: 0; transform: translateY(-1rem); } 20% { opacity: 1; } 100% { opacity: 0; transform: translateY(12rem); } }
@keyframes blink { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---------- Smaller screens ---------- */
@media (max-width: 1100px) {
  .workspace { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto; align-content: start; }
  .operator-panel, .policy-panel { grid-row: auto; grid-column: auto; }
  .threshold-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  .appbar-controls { margin-left: 0; }
  .pane-head { flex-direction: column; gap: .2rem; }
  .policy-note { text-align: left; }
  .camera-zone { width: 11%; }
  .tally { padding: .25rem .45rem; }
  .cylinder span { display: none; }
  .threshold-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .operator-actions { grid-template-columns: 1fr; }
}
