/* ==========================================================================
   Work Instruction Operations — tokens from the design handoff
   ========================================================================== */

:root {
  --bg:        #f6f7f8;
  --surface:   #ffffff;
  --ink:       #1a1d21;
  --ink-2:     #404750;
  --muted:     #6b7480;
  --line:      #e4e7eb;
  --line-2:    #eef0f3;

  --accent:      #3b6bf5;
  --accent-soft: oklch(0.95 0.04 260);
  --accent-ink:  oklch(0.40 0.12 260);

  --amber:       oklch(0.78 0.13 75);
  --amber-soft:  oklch(0.96 0.04 80);
  --amber-ink:   oklch(0.45 0.11 60);

  --red:         oklch(0.62 0.18 25);
  --red-soft:    oklch(0.96 0.03 25);
  --red-ink:     oklch(0.42 0.15 25);

  --green:       oklch(0.65 0.13 150);
  --green-soft:  oklch(0.95 0.04 150);
  --green-ink:   oklch(0.42 0.10 150);

  --radius-card: 14px;
  --row-py: 16px;
}

*, *::before, *::after { box-sizing: border-box; }

/* Class-level display rules outrank the UA rule for [hidden], so restate it. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

body {
  font-family: 'Geist', ui-sans-serif, system-ui, -apple-system, sans-serif;
  font-feature-settings: 'cv11', 'ss01';
  -webkit-font-smoothing: antialiased;
  font-size: 13.5px;
  line-height: 1.5;
}

h1, h2, h3, p, ul { margin: 0; }
ul { list-style: none; padding: 0; }
button { font: inherit; }

.mono { font-family: 'Geist Mono', ui-monospace, 'SF Mono', Menlo, monospace; }

.small-caps {
  text-transform: uppercase;
  font-size: 11.5px;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 500;
}

.dot-sep { margin: 0 6px; color: var(--muted); }

.code-chip {
  display: inline-flex;
  align-items: center;
  font-family: 'Geist Mono', ui-monospace, monospace;
  font-size: 11.5px;
  padding: 2px 7px;
  border-radius: 6px;
  background: #f3f5f7;
  border: 1px solid var(--line);
  color: var(--ink-2);
}

/* Icons ------------------------------------------------------------------ */
.ico-14 { width: 14px; height: 14px; flex: none; }
.ico-16 { width: 16px; height: 16px; flex: none; }
.ico-20 { width: 20px; height: 20px; flex: none; }
.ico-24 { width: 24px; height: 24px; flex: none; }

/* Surfaces --------------------------------------------------------------- */
.surface {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
}

.page {
  max-width: 1480px;
  margin: 0 auto;
  padding: 32px clamp(24px, 3vw, 40px);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ── Header ─────────────────────────────────────────────────────────────── */
.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  padding-bottom: 4px;
}

.breadcrumb {
  font-family: 'Geist Mono', ui-monospace, monospace;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}

.page-head h1 {
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.head-metrics { display: flex; align-items: center; gap: 28px; }
.metric { display: flex; align-items: center; gap: 10px; }
.metric-text { display: flex; flex-direction: column; gap: 2px; }
.metric-sub { font-size: 12px; color: var(--ink-2); }

.metric-value {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 15px;
  color: var(--ink);
}

.metric-ring { position: relative; }
.ring { width: 44px; height: 44px; transform: rotate(-90deg); }
.ring-track { fill: none; stroke: var(--line); stroke-width: 4; }
.ring-value {
  fill: none;
  stroke: var(--accent);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-dasharray: 0 999;
  transition: stroke-dasharray .35s ease, stroke .2s;
}
.ring-label {
  position: absolute;
  left: 0;
  width: 44px;
  top: 50%;
  transform: translateY(-50%);
  text-align: center;
  font-size: 11px;
  color: var(--ink-2);
}

/* ── Source bar ─────────────────────────────────────────────────────────── */
.source-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
}

.bar-label {
  display: flex;
  align-items: center;
  gap: 7px;
  padding-right: 14px;
  border-right: 1px solid var(--line);
  color: var(--muted);
}

.source-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.demo-buttons { display: flex; gap: 8px; }
.field-wrap { position: relative; }
.field-wrap.grow { flex: 1; min-width: 140px; }

.field {
  height: 38px;
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0 34px 0 36px;
  font-size: 13.5px;
  color: var(--ink);
  transition: border-color .12s, box-shadow .12s;
}
.field.no-left-icon { padding-left: 14px; }
.field:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in oklch, var(--accent) 18%, transparent);
}

.model-chip {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11.5px;
  color: var(--muted);
  padding-left: 14px;
  border-left: 1px solid var(--line);
  white-space: nowrap;
}
.model-chip .dot {
  width: 7px; height: 7px; border-radius: 999px;
  background: #99a1ab;
}
.model-chip.is-ready .dot { background: var(--green); }
.model-chip.is-error .dot { background: var(--red); }
.model-chip.is-error { color: var(--red-ink); }

/* ── Buttons ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 40px;
  padding: 0 16px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 500;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-2);
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s, border-color .12s, transform .04s;
}
.btn:hover:not(:disabled) { background: #fafbfc; }
.btn:active:not(:disabled) { transform: translateY(0.5px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn-sm { height: 32px; padding: 0 12px; font-size: 12.5px; }

.btn-primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn-primary:hover:not(:disabled) { background: #2a2f36; }

.btn-danger {
  background: var(--red-soft); color: var(--red-ink);
  border-color: color-mix(in oklch, var(--red) 25%, transparent);
}
.btn-danger:hover:not(:disabled) { background: color-mix(in oklch, var(--red) 12%, white); }

.btn-warn {
  background: var(--amber-soft); color: var(--amber-ink);
  border-color: color-mix(in oklch, var(--amber) 30%, transparent);
}
.btn-warn:hover:not(:disabled) { background: color-mix(in oklch, var(--amber) 18%, white); }

.icon-btn {
  width: 32px; height: 32px;
  display: inline-flex; align-items: center; justify-content: center;
  border: none; border-radius: 6px;
  background: transparent; color: var(--muted);
  cursor: pointer;
}
.icon-btn:hover { background: var(--line-2); }

/* ── Pills ──────────────────────────────────────────────────────────────── */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 22px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 500;
  border: 1px solid transparent;
  white-space: nowrap;
}
.pill .dot { width: 6px; height: 6px; border-radius: 999px; flex: none; }

.pill-pending { background: #f1f3f5; color: #565d66; border-color: var(--line); }
.pill-pending .dot { background: #99a1ab; }

.pill-active {
  background: var(--accent-soft); color: var(--accent-ink);
  border-color: color-mix(in oklch, var(--accent) 25%, transparent);
}
.pill-active .dot { background: var(--accent); animation: pulse 1.8s ease-in-out infinite; }

.pill-done {
  background: var(--green-soft); color: var(--green-ink);
  border-color: color-mix(in oklch, var(--green) 25%, transparent);
}
.pill-done .dot { background: var(--green); }

.pill-bad {
  background: var(--red-soft); color: var(--red-ink);
  border-color: color-mix(in oklch, var(--red) 25%, transparent);
}
.pill-bad .dot { background: var(--red); }

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 3px color-mix(in oklch, var(--accent) 25%, transparent); }
  50%      { box-shadow: 0 0 0 6px color-mix(in oklch, var(--accent) 10%, transparent); }
}

/* ── Main grid ──────────────────────────────────────────────────────────── */
.grid {
  display: grid;
  grid-template-columns: 7fr 5fr;
  gap: 16px;
  align-items: stretch;
}

/* Two operations is a short list, so the card stretches to the detail card's
   height and the list takes up the slack rather than leaving a hole. */
.ops { display: flex; flex-direction: column; }
.ops-list { flex: 1; }

/* Detail card */
.detail-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line-2);
}

.step-num {
  width: 28px; height: 28px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 8px;
  font-family: 'Geist Mono', ui-monospace, monospace;
  font-size: 12px;
  background: #f1f3f5;
  color: var(--ink-2);
  border: 1px solid var(--line);
  flex: none;
  transition: background .15s, color .15s, border-color .15s;
}
.step-num.is-active { background: var(--accent); color: #fff; border-color: var(--accent); }
.step-num.is-done   { background: var(--green-soft); color: var(--green-ink); border-color: color-mix(in oklch, var(--green) 25%, transparent); }
.step-num.is-bad    { background: var(--red-soft); color: var(--red-ink); border-color: color-mix(in oklch, var(--red) 25%, transparent); }

.detail-titles { flex: 1; min-width: 0; }
.eyebrow {
  text-transform: uppercase;
  font-size: 11.5px;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 2px;
}
.eyebrow .mono { text-transform: none; }

.detail-head h2 {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.detail-body {
  display: grid;
  grid-template-columns: 3fr 2fr;
  gap: 20px;
  padding: 20px;
}

.video-frame {
  position: relative;
  aspect-ratio: 16 / 9;
  border-radius: 12px;
  overflow: hidden;
  background: #10131a;
  border: 1px solid var(--line);
}
.video-frame canvas { width: 100%; height: 100%; display: block; object-fit: contain; }

.video-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: #8b94a2;
  font-size: 13px;
  background:
    repeating-linear-gradient(45deg, #171b24 0 10px, #141821 10px 20px);
}
.video-empty strong { color: #d4dae4; font-weight: 500; }

.video-tag {
  position: absolute;
  top: 10px; left: 10px;
  background: rgba(255,255,255,.92);
  color: var(--ink-2);
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
}

.video-scrub {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 3px;
  background: rgba(255,255,255,.16);
}
.video-scrub-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width .1s linear;
}

.hint {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  margin-top: 10px;
  font-size: 12px;
  color: var(--muted);
}
.hint svg { margin-top: 2px; }

.section-label { margin-bottom: 6px; }
.section-label + .body-text { margin-bottom: 16px; }

.body-text { font-size: 13.5px; line-height: 1.6; color: var(--ink-2); }

.criteria { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.criteria li { display: flex; align-items: flex-start; gap: 9px; font-size: 13px; color: var(--ink-2); }
.criteria li::before {
  content: '';
  width: 16px; height: 16px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: radial-gradient(circle, var(--accent) 0 3px, transparent 3px);
  flex: none;
  margin-top: 1px;
}

.live-read {
  border: 1px solid var(--line-2);
  background: #fbfcfd;
  border-radius: 10px;
  padding: 12px;
}
.live-task {
  font-size: 14px;
  font-weight: 500;
  color: var(--ink);
  margin: 4px 0 8px;
  min-height: 21px;
}
.conf-bar { height: 4px; border-radius: 999px; background: var(--line); overflow: hidden; }
.conf-fill {
  height: 100%; width: 0;
  background: var(--accent);
  transition: width .2s ease, background .2s;
}
.live-note { font-size: 11.5px; color: var(--muted); margin-top: 8px; }

.detail-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 20px;
  border-top: 1px solid var(--line-2);
  background: #fbfcfd;
  border-radius: 0 0 var(--radius-card) var(--radius-card);
}
.foot-actions { display: flex; gap: 8px; }
.foot-stat { font-size: 11.5px; color: var(--muted); text-align: right; }

/* ── Operations list ────────────────────────────────────────────────────── */
.ops-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line-2);
}
.ops-head h2 { font-size: 14px; font-weight: 600; letter-spacing: -0.01em; }
.ops-sub { font-size: 11.5px; color: var(--muted); margin-top: 2px; }

.ops-list li {
  position: relative;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: var(--row-py) 16px;
  border-bottom: 1px solid var(--line-2);
  transition: background .1s;
}
.ops-list li.is-active { background: color-mix(in oklch, var(--accent) 4%, white); }
.ops-list li.is-active::before {
  content: '';
  position: absolute;
  left: 0; top: 8px; bottom: 8px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
}
.ops-list li.is-done { opacity: .75; }
.ops-list li.is-bad::before {
  content: '';
  position: absolute;
  left: 0; top: 8px; bottom: 8px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--red);
}

.op-text { flex: 1; min-width: 0; }
.op-title {
  font-size: 13.5px;
  font-weight: 500;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.op-meta {
  font-family: 'Geist Mono', ui-monospace, monospace;
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ops-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-top: 1px solid var(--line-2);
  background: #fbfcfd;
  border-radius: 0 0 var(--radius-card) var(--radius-card);
  font-size: 12px;
  color: var(--muted);
}

/* ── Verdict ────────────────────────────────────────────────────────────── */
.verdict {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
  padding: 16px 20px;
  border-radius: var(--radius-card);
  border: 1px solid var(--line);
  background: var(--surface);
  transition: background .2s, border-color .2s;
}
.verdict-main { display: flex; align-items: center; gap: 14px; min-width: 0; }

.verdict-icon {
  width: 38px; height: 38px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 10px;
  background: #f1f3f5;
  color: var(--muted);
  flex: none;
}
.verdict-title { font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
.verdict-reason { font-size: 12.5px; color: var(--muted); margin-top: 2px; }

.verdict.is-good {
  background: var(--green-soft);
  border-color: color-mix(in oklch, var(--green) 30%, transparent);
}
.verdict.is-good .verdict-icon { background: color-mix(in oklch, var(--green) 22%, white); color: var(--green-ink); }
.verdict.is-good .verdict-title { color: var(--green-ink); }
.verdict.is-good .verdict-reason { color: color-mix(in oklch, var(--green-ink) 78%, white); }

.verdict.is-bad {
  background: var(--red-soft);
  border-color: color-mix(in oklch, var(--red) 35%, transparent);
  animation: flag 1.4s ease-out 1;
}
.verdict.is-bad .verdict-icon { background: color-mix(in oklch, var(--red) 22%, white); color: var(--red-ink); }
.verdict.is-bad .verdict-title { color: var(--red-ink); }
.verdict.is-bad .verdict-reason { color: color-mix(in oklch, var(--red-ink) 78%, white); }

.verdict.is-incomplete {
  background: var(--amber-soft);
  border-color: color-mix(in oklch, var(--amber) 35%, transparent);
}
.verdict.is-incomplete .verdict-icon { background: color-mix(in oklch, var(--amber) 22%, white); color: var(--amber-ink); }
.verdict.is-incomplete .verdict-title { color: var(--amber-ink); }

@keyframes flag {
  0%   { box-shadow: 0 0 0 0 color-mix(in oklch, var(--red) 45%, transparent); }
  100% { box-shadow: 0 0 0 18px transparent; }
}
@media (prefers-reduced-motion: reduce) {
  .verdict.is-bad { animation: none; }
  .pill-active .dot { animation: none; }
}

/* Signature: required order vs observed order */
.ribbon { display: flex; flex-direction: column; gap: 6px; }
.ribbon-row { display: flex; align-items: center; gap: 12px; }
.ribbon-row > .small-caps { width: 62px; text-align: right; flex: none; }
.ribbon-track { display: flex; align-items: center; gap: 6px; min-height: 26px; }

.ribbon-step {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 26px;
  padding: 0 10px 0 6px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 12px;
  color: var(--ink-2);
}
.ribbon-step .num {
  font-family: 'Geist Mono', ui-monospace, monospace;
  font-size: 11px;
  color: var(--muted);
  background: #f1f3f5;
  border-radius: 999px;
  padding: 1px 6px;
}
.ribbon-step.is-hit { border-color: color-mix(in oklch, var(--green) 35%, transparent); }
.ribbon-step.is-hit .num { background: var(--green-soft); color: var(--green-ink); }
.ribbon-step.is-miss { border-color: color-mix(in oklch, var(--red) 40%, transparent); }
.ribbon-step.is-miss .num { background: var(--red-soft); color: var(--red-ink); }
.ribbon-step.is-miss .label { text-decoration: line-through; text-decoration-color: var(--red); }

.ribbon-arrow { color: var(--muted); font-size: 12px; }
.ribbon-empty { font-size: 11.5px; color: var(--muted); }

/* ── Detection log ──────────────────────────────────────────────────────── */
.log-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line-2);
}
.log-head h2 { font-size: 15px; font-weight: 600; }
.log-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.log-head-right { display: flex; align-items: center; gap: 10px; }

.log-table { width: 100%; border-collapse: collapse; }
.log-table th {
  text-align: left;
  text-transform: uppercase;
  font-size: 11.5px;
  letter-spacing: 0.05em;
  font-weight: 500;
  color: var(--muted);
  background: #fafbfc;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
}
.log-table td {
  padding: 13px 16px;
  font-size: 13px;
  border-bottom: 1px solid var(--line-2);
  color: var(--ink);
}
.log-table tbody tr:last-child td { border-bottom: none; }
.log-table tr.is-step td { background: color-mix(in oklch, var(--accent) 4%, white); }
.log-table tr.is-violation td { background: var(--red-soft); }
.col-conf { width: 16%; }
.col-time { width: 16%; }
.log-table td.mono { font-family: 'Geist Mono', ui-monospace, monospace; color: var(--ink-2); }
.log-empty td { text-align: center; color: var(--muted); padding: 56px 16px; }

.log-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.log-badge .num {
  font-family: 'Geist Mono', ui-monospace, monospace;
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent-ink);
}

/* ── History drawer ─────────────────────────────────────────────────────── */
.drawer-backdrop {
  position: fixed; inset: 0;
  background: rgba(16, 19, 26, .35);
  z-index: 40;
}
.drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(460px, 92vw);
  background: var(--surface);
  border-left: 1px solid var(--line);
  z-index: 41;
  display: flex;
  flex-direction: column;
}
.drawer-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 20px;
  border-bottom: 1px solid var(--line-2);
}
.drawer-head h2 { font-size: 15px; font-weight: 600; }
.drawer-body { overflow-y: auto; padding: 8px 0; }

.history-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line-2);
}
.history-row .grow { flex: 1; min-width: 0; }
.history-part { font-size: 13px; font-weight: 500; }
.history-meta { font-family: 'Geist Mono', ui-monospace, monospace; font-size: 11.5px; color: var(--muted); }

/* ── Toast ──────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  font-size: 13px;
  padding: 11px 16px;
  border-radius: 10px;
  z-index: 60;
  max-width: 560px;
}
.toast.is-error { background: var(--red-ink); }

/* ── Narrow workstation screens ─────────────────────────────────────────── */
@media (max-width: 1180px) {
  .grid { grid-template-columns: 1fr; }
  .detail-body { grid-template-columns: 1fr; }
  .source-bar { flex-wrap: wrap; }
  .model-chip { border-left: none; padding-left: 0; }
}
