/* =========================================================================
   1. Design tokens. The only fonts, sizes, colors and motion used anywhere.
   ========================================================================= */
:root {
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --fs-12: 12px;
  --fs-14: 14px;
  --fs-16: 16px;
  --fs-20: 20px;
  --fs-28: 28px;
  --fs-36: 36px;                         /* landing headline only */
  --fw-regular: 400;
  --fw-medium: 500;
  --fw-semibold: 600;
  --lh-body: 1.5;
  --lh-heading: 1.25;

  --bg: #F5F7FA;
  --surface: #FFFFFF;
  --border: #E2E8F0;
  --text: #0F172A;
  --text-muted: #64748B;
  --stage: #0F172A;                      /* dark viewer behind the images */
  --glass: rgba(15, 23, 42, .66);        /* overlays on the stage */
  --primary: #1D4ED8;
  --primary-hover: #1E40AF;
  --primary-soft: #DBEAFE;
  --success: #15803D;
  --success-soft: #DCFCE7;
  --danger: #B91C1C;
  --danger-soft: #FEE2E2;
  --warning: #B45309;
  --warning-soft: #FEF3C7;
  --defect: #EF4444;                     /* same as DEFECT_BGR in backend/config.py */

  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-6: 24px;
  --s-8: 32px;
  --s-12: 48px;
  --radius-control: 6px;
  --radius-card: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, .14);
  --ease: cubic-bezier(.2, .8, .2, 1);
  --ease-pop: cubic-bezier(.2, .9, .3, 1.25);
}

/* =========================================================================
   2. Base
   ========================================================================= */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  display: flex; flex-direction: column; min-height: 100vh; margin: 0;
  font-family: var(--font); font-size: var(--fs-16); font-weight: var(--fw-regular); line-height: var(--lh-body);
  color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p, figure, dl, dd { margin: 0; }
h1, h2, h3 { font-weight: var(--fw-semibold); line-height: var(--lh-heading); }
img { display: block; max-width: 100%; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
[hidden] { display: none !important; }

/* Every animation and transition is off when the user asks for reduced motion.
   Entrance animations only use `from` keyframes, so the resting state stays visible. */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* =========================================================================
   3. Layout
   ========================================================================= */
.container { width: 100%; max-width: 1240px; margin: 0 auto; padding-left: var(--s-4); padding-right: var(--s-4); }
.main { flex: 1; display: flex; flex-direction: column; gap: var(--s-8); padding-top: var(--s-6); padding-bottom: var(--s-12); }

.app-header { position: sticky; top: 0; z-index: 20; background: rgba(255, 255, 255, .92); border-bottom: 1px solid var(--border); backdrop-filter: blur(8px); }
.header-inner { display: flex; align-items: center; justify-content: space-between; gap: var(--s-4); min-height: 64px; }
.brand { display: flex; align-items: center; gap: var(--s-3); min-width: 0; }
.logo-slot { display: grid; place-items: center; flex-shrink: 0; width: 40px; height: 40px; border-radius: var(--radius-card); background: var(--primary); color: #fff; }
.app-title { font-size: var(--fs-16); }
.app-subtitle { font-size: var(--fs-12); color: var(--text-muted); }

.section-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: var(--s-2) var(--s-4); margin-bottom: var(--s-4); }
.section-title { font-size: var(--fs-20); }
.section-sub { font-size: var(--fs-14); color: var(--text-muted); }

.card { min-width: 0; padding: var(--s-6); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow); }
.card-title { font-size: var(--fs-16); }
.card-sub { margin-top: var(--s-1); font-size: var(--fs-14); color: var(--text-muted); }
.card-eyebrow { display: flex; align-items: center; gap: var(--s-2); font-size: var(--fs-12); font-weight: var(--fw-semibold); letter-spacing: .06em; text-transform: uppercase; color: var(--text-muted); }

.footer { border-top: 1px solid var(--border); background: var(--surface); }
.footer-inner { display: flex; flex-wrap: wrap; justify-content: space-between; gap: var(--s-2) var(--s-4); padding-top: var(--s-4); padding-bottom: var(--s-4); font-size: var(--fs-12); color: var(--text-muted); }
.footer-inner span { display: inline-flex; align-items: center; gap: var(--s-2); }

@media (min-width: 768px) {
  .container { padding-left: var(--s-6); padding-right: var(--s-6); }
}

/* =========================================================================
   4. Components
   ========================================================================= */

/* Header status */
.status { display: inline-flex; align-items: center; gap: var(--s-2); padding: var(--s-1) var(--s-3); border-radius: 999px; background: var(--bg); font-size: var(--fs-12); font-weight: var(--fw-semibold); color: var(--text-muted); white-space: nowrap; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); }
.status[data-state="ready"] { background: var(--success-soft); color: var(--success); }
.status[data-state="ready"] .status-dot { background: var(--success); animation: breathe 2.4s ease-in-out infinite; }
.status[data-state="error"] { background: var(--danger-soft); color: var(--danger); }
.status[data-state="error"] .status-dot { background: var(--danger); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  min-height: 40px; padding: 0 var(--s-4); border: 1px solid transparent; border-radius: var(--radius-card);
  font-size: var(--fs-14); font-weight: var(--fw-semibold); white-space: nowrap; cursor: pointer;
  transition: background-color .15s, border-color .15s, transform .15s var(--ease);
}
.btn:active:not(:disabled) { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-secondary:hover:not(:disabled) { background: var(--bg); }

/* ---------- Landing ---------- */
.idle { display: flex; flex-direction: column; gap: var(--s-12); }
.hero { display: grid; gap: var(--s-8); align-items: center; }
.hero-copy { display: flex; flex-direction: column; gap: var(--s-4); animation: rise .6s var(--ease) backwards; }
.eyebrow { display: inline-flex; align-items: center; gap: var(--s-2); align-self: flex-start; padding: var(--s-1) var(--s-3); border-radius: 999px; background: var(--primary-soft); color: var(--primary-hover); font-size: var(--fs-12); font-weight: var(--fw-semibold); }
.hero-title { max-width: 560px; font-size: var(--fs-28); letter-spacing: -.01em; }
.hero-text { max-width: 560px; font-size: var(--fs-16); color: var(--text-muted); }

.features { display: grid; gap: var(--s-3); margin: var(--s-2) 0 0; padding: 0; list-style: none; }
.feature { display: flex; align-items: flex-start; gap: var(--s-3); animation: rise .5s var(--ease) backwards; animation-delay: calc(var(--i) * 90ms + 200ms); }
.feature-icon { display: grid; place-items: center; flex-shrink: 0; width: 40px; height: 40px; border-radius: var(--radius-card); background: var(--surface); border: 1px solid var(--border); color: var(--primary); box-shadow: var(--shadow); }
.feature-title { font-size: var(--fs-14); font-weight: var(--fw-semibold); }
.feature-text { font-size: var(--fs-14); color: var(--text-muted); }

.engine { margin-top: var(--s-2); padding: var(--s-4); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow); }
.engine-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--success); animation: breathe 2.4s ease-in-out infinite; }
.engine-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-3) var(--s-4); margin-top: var(--s-3); }
.engine-grid dt { font-size: var(--fs-12); color: var(--text-muted); }
.engine-grid dd { font-size: var(--fs-14); font-weight: var(--fw-medium); overflow-wrap: anywhere; }

.hero-upload { display: flex; flex-direction: column; gap: var(--s-4); animation: rise .6s .1s var(--ease) backwards; }
.dropzone {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--s-2);
  min-height: 320px; padding: var(--s-8); text-align: center; cursor: pointer; overflow: hidden;
  background: var(--surface); border: 2px dashed var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  transition: border-color .2s, transform .25s var(--ease);
}
.dropzone::before {                     /* slow ambient glow behind the orb */
  content: ""; position: absolute; width: 360px; height: 360px; border-radius: 50%;
  background: radial-gradient(circle, rgba(219, 234, 254, .9), rgba(219, 234, 254, 0) 70%);
  animation: drift 8s ease-in-out infinite; pointer-events: none;
}
.dropzone > * { position: relative; }
.dropzone > * { position: relative; }
.dropzone:hover { border-color: var(--primary); transform: translateY(-3px); }
.dz-orb { display: grid; place-items: center; width: 80px; height: 80px; margin-bottom: var(--s-3); border-radius: 50%; background: var(--primary); color: #fff; animation: float 3s ease-in-out infinite; }
.dz-orb::after { content: ""; position: absolute; inset: 0; border-radius: 50%; border: 2px solid var(--primary); animation: ripple 2.4s ease-out infinite; }
.dz-title { font-size: var(--fs-20); font-weight: var(--fw-semibold); }
.dz-hint { font-size: var(--fs-14); color: var(--text-muted); }
.dz-formats { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--s-2); margin-top: var(--s-3); }
.dz-formats span { padding: 2px var(--s-2); border-radius: var(--radius-control); background: var(--bg); border: 1px solid var(--border); font-size: var(--fs-12); font-weight: var(--fw-medium); color: var(--text); }

.samples { display: flex; flex-direction: column; gap: var(--s-3); }
.sample-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: var(--s-2); margin: 0; padding: 0; list-style: none; }
.sample {
  position: relative; display: block; width: 100%; aspect-ratio: 1 / 1; padding: 0; overflow: hidden; cursor: pointer;
  background: var(--stage); border: 2px solid transparent; border-radius: var(--radius-card);
  animation: pop .4s var(--ease-pop) backwards; animation-delay: calc(var(--i) * 60ms + 300ms);
  transition: border-color .2s, transform .2s var(--ease);
}
.sample img { width: 100%; height: 100%; object-fit: cover; transition: transform .35s var(--ease); }
.sample:hover { border-color: var(--primary); transform: translateY(-2px); }
.sample:hover img { transform: scale(1.08); }

.how { animation: rise .6s .2s var(--ease) backwards; }
.pipeline { position: relative; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-4); margin: 0; padding: 0; list-style: none; }
.pipe-step {
  position: relative; display: flex; flex-direction: column; gap: var(--s-1); padding: var(--s-4);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow);
  animation: rise .5s var(--ease) backwards; animation-delay: calc(var(--i) * 80ms + 300ms);
  transition: transform .25s var(--ease), border-color .2s;
}
.pipe-step:hover { transform: translateY(-3px); border-color: var(--primary-soft); }
.pipe-node { position: relative; z-index: 1; display: grid; place-items: center; width: 48px; height: 48px; margin-bottom: var(--s-2); border-radius: 50%; background: var(--primary-soft); color: var(--primary); }
.pipe-num { font-size: var(--fs-12); font-weight: var(--fw-semibold); letter-spacing: .06em; text-transform: uppercase; color: var(--primary); }
.pipe-title { font-size: var(--fs-16); font-weight: var(--fw-semibold); }
.pipe-text { font-size: var(--fs-14); color: var(--text-muted); }

@media (min-width: 768px) { .pipeline { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 1024px) {
  .hero { grid-template-columns: minmax(0, 1fr) minmax(0, 520px); gap: var(--s-12); }
  .hero-title { font-size: var(--fs-36); }
  .pipeline { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  /* Chevron connectors in the gaps, pulsing one after another to show the flow */
  .pipe-step:not(:last-child)::after {
    content: ""; position: absolute; top: 33px; right: -16px; z-index: 2; width: 16px; height: 16px; border-radius: 50%;
    background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%231D4ED8' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M9 6l6 6-6 6'/%3E%3C/svg%3E") center / 10px no-repeat;
    border: 1px solid var(--primary-soft);
    animation: flow 3.6s ease-in-out infinite; animation-delay: calc(var(--i) * .6s);
  }
}
@media (max-width: 1023px) { .hero-upload { order: -1; } }

/* Whole-page drop overlay */
body.is-dragging::after {
  content: "Drop to inspect"; position: fixed; inset: var(--s-4); z-index: 70; display: grid; place-items: center;
  font-size: var(--fs-20); font-weight: var(--fw-semibold); color: var(--primary);
  background: rgba(219, 234, 254, .9); border: 2px dashed var(--primary); border-radius: var(--radius-lg);
  pointer-events: none; animation: fade .15s ease backwards;
}

/* ---------- Results ---------- */
.workspace-wrap { display: flex; flex-direction: column; gap: var(--s-6); animation: rise .45s var(--ease) backwards; }
.stage, .insights, .recent { scroll-margin-top: 88px; }   /* clear the sticky header */
.result-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s-3) var(--s-4); }
.result-meta { min-width: 0; }
.result-name { font-size: var(--fs-20); font-weight: var(--fw-semibold); overflow-wrap: anywhere; }
.result-info { font-size: var(--fs-14); color: var(--text-muted); }
.result-actions { display: flex; flex-wrap: wrap; gap: var(--s-2); }

.workspace { display: grid; gap: var(--s-6); }
.viewer { display: flex; flex-direction: column; gap: var(--s-3); width: min(100%, max(320px, 100vh - 360px)); justify-self: center; min-width: 0; }
.panel, .panel-result, .panel-loading { display: flex; flex-direction: column; gap: var(--s-4); min-width: 0; }
@media (min-width: 1024px) { .workspace { grid-template-columns: minmax(0, 1fr) 360px; align-items: start; } }

/* Stage */
.stage { position: relative; width: 100%; aspect-ratio: 1 / 1; overflow: hidden; background: var(--stage); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); }
.stage-canvas { position: absolute; inset: 0; transform-origin: 0 0; transition: transform .6s var(--ease); }
.stage[data-phase="playing"] { cursor: pointer; }
.stage.is-zoomed { cursor: zoom-out; }
.stage:fullscreen { border-radius: 0; }
.stage:fullscreen .stage-canvas { inset: 0; margin: auto; width: min(100vw, 100vh); height: min(100vw, 100vh); }

.layer { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; opacity: 0; transform: scale(1.03); transition: opacity .5s ease, transform .7s var(--ease); }
.layer.is-active { opacity: 1; transform: none; }
#stage-preview { transform: none; transition: opacity .5s ease, filter .6s ease; }
.stage[data-phase="analyzing"] #stage-preview { filter: brightness(.7) saturate(.6); }
.layer[data-key="plate_mask"].is-active { animation: iris .9s var(--ease) backwards; }
.layer[data-key="plate_extracted"].is-active { animation: focus-in .8s ease backwards; }
.layer[data-key="defect_mask"].is-active { animation: wipe .9s var(--ease) backwards; }
.layer[data-key="final"].is-active { animation: settle .7s var(--ease) backwards; }

.scan { position: absolute; inset: 0; overflow: hidden; pointer-events: none; opacity: 0; transition: opacity .3s; }
.scan::before {
  content: ""; position: absolute; left: 0; right: 0; top: -35%; height: 35%;
  background: linear-gradient(to bottom, rgba(29, 78, 216, 0), rgba(29, 78, 216, .45));
  border-bottom: 2px solid var(--primary-soft); box-shadow: 0 6px 18px rgba(219, 234, 254, .5);
  animation: scan 1.8s cubic-bezier(.45, 0, .25, 1) infinite;
}
.stage[data-phase="analyzing"] .scan { opacity: 1; }

/* Step description card (outside the image) */
.step-caption {
  display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s-3); min-height: 104px;
  padding: var(--s-3) var(--s-4); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); box-shadow: var(--shadow);
}
.step-caption.is-changing .cap-body { animation: caption-in .45s var(--ease) backwards; }
.cap-body { min-width: 0; }
.cap-step { display: flex; align-items: center; gap: var(--s-2); font-size: var(--fs-12); font-weight: var(--fw-semibold); letter-spacing: .06em; text-transform: uppercase; color: var(--primary); }
.cap-title { margin-top: 2px; font-size: var(--fs-16); font-weight: var(--fw-semibold); }
.cap-text { margin-top: 2px; font-size: var(--fs-14); color: var(--text-muted); }
.cap-metric { flex-shrink: 0; padding: 2px var(--s-2); border-radius: var(--radius-control); background: var(--primary-soft); color: var(--primary-hover); font-size: var(--fs-12); font-weight: var(--fw-semibold); white-space: nowrap; font-variant-numeric: tabular-nums; }
.step-caption.is-analyzing .cap-step::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--primary); animation: breathe 1.2s ease-in-out infinite; }

.stage-tools { position: absolute; top: var(--s-3); right: var(--s-3); display: flex; gap: var(--s-2); }
.stage[data-phase="analyzing"] .stage-tools { display: none; }
.stage:not([data-phase="done"]) #replay-btn { display: none; }
.tool { display: grid; place-items: center; width: 36px; height: 36px; padding: 0; border: 0; border-radius: 50%; background: var(--glass); color: #fff; cursor: pointer; backdrop-filter: blur(6px); transition: transform .15s var(--ease); }
.tool:hover { transform: scale(1.08); }

.stage[data-phase="done"][data-verdict="DEFECTIVE"] { animation: glow-danger 1.4s ease-out backwards; }
.stage[data-phase="done"][data-verdict="OK"] { animation: glow-success 1.4s ease-out backwards; }
.stage[data-phase="done"][data-verdict="NO_PLATE"] { animation: shake .5s ease backwards, glow-warning 1.4s ease-out backwards; }

.markers { position: absolute; inset: 0; pointer-events: none; }
.stage[data-step="original"] .markers, .stage.is-zoomed .markers { display: none; }
.marker { position: absolute; border-radius: var(--s-1); pointer-events: auto; transition: box-shadow .2s ease; }
.marker::after { content: ""; position: absolute; inset: -4px; border: 2px solid var(--defect); border-radius: var(--radius-control); opacity: 0; }
.markers.flash .marker::after { animation: ping 1s ease-out backwards; animation-delay: calc(var(--i, 0) * 90ms); }
.markers.has-active .marker.active { box-shadow: 0 0 0 3px #fff, 0 0 0 9999px rgba(15, 23, 42, .55); }

/* Timeline */
.tl-track { height: 3px; overflow: hidden; border-radius: 999px; background: var(--border); }
.tl-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--primary); transition: width .6s var(--ease); }
.timeline { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: var(--s-2); margin: 0; padding: 0; list-style: none; }
.tl-btn { display: flex; flex-direction: column; align-items: center; gap: var(--s-1); width: 100%; padding: 0; background: none; border: 0; cursor: pointer; }
.tl-btn:disabled { cursor: default; }
.tl-thumb {
  display: block; width: 100%; aspect-ratio: 4 / 3; overflow: hidden; border-radius: var(--radius-card); background: var(--stage); border: 2px solid transparent;
  opacity: .3; filter: grayscale(1); transform: scale(.92); transition: opacity .4s ease, filter .4s ease, transform .4s var(--ease-pop), border-color .2s;
}
.tl-thumb img { width: 100%; height: 100%; object-fit: cover; }
.tl-label { font-size: var(--fs-12); font-weight: var(--fw-medium); color: var(--text-muted); text-align: center; line-height: var(--lh-heading); }
.tl-item.is-reached .tl-thumb { opacity: 1; filter: none; transform: none; }
.tl-item.is-current .tl-thumb { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.tl-item.is-current .tl-label { color: var(--primary); font-weight: var(--fw-semibold); }
.tl-item.is-skipped .tl-thumb { opacity: .15; }
.tl-btn:hover:not(:disabled) .tl-thumb { transform: translateY(-2px); }
.tl-item.is-loading .tl-thumb { opacity: 1; filter: none; transform: none; }
.tl-text { display: flex; flex-direction: column; align-items: center; min-width: 0; }
.tl-step, .tl-item .sk-line { display: none; }
@media (max-width: 639px) { .tl-label { display: none; } }

/* Wide screens: image on the left, step description + vertical step list on the right */
@media (min-width: 1200px) {
  .viewer {
    display: grid; width: 100%; justify-content: center; align-content: start; column-gap: var(--s-4); row-gap: var(--s-3);
    grid-template-columns: minmax(0, clamp(320px, 100vh - 190px, 560px)) 240px;
    grid-template-rows: auto 1fr;
    grid-template-areas: "stage caption" "stage timeline";
  }
  .stage { grid-area: stage; }
  .step-caption { grid-area: caption; flex-direction: column; align-items: flex-start; gap: var(--s-2); min-height: 168px; }
  .tl-track { display: none; }
  .timeline { grid-area: timeline; grid-template-columns: minmax(0, 1fr); align-content: start; gap: var(--s-1); }
  .tl-btn { flex-direction: row; gap: var(--s-3); padding: var(--s-1); border-radius: var(--radius-card); transition: background-color .2s, box-shadow .2s; }
  .tl-btn:hover:not(:disabled) { background: var(--surface); }
  .tl-btn:hover:not(:disabled) .tl-thumb { transform: none; }
  .tl-item.is-current .tl-btn { background: var(--surface); box-shadow: 0 0 0 1px var(--primary-soft), var(--shadow); }
  .tl-thumb { flex-shrink: 0; width: 48px; }
  .tl-item.is-current .tl-thumb { box-shadow: none; }
  .tl-text { align-items: flex-start; }
  .tl-step { display: block; font-size: var(--fs-12); color: var(--text-muted); line-height: var(--lh-heading); }
  .tl-label { font-size: var(--fs-14); color: var(--text); text-align: left; }
  .tl-item.is-skipped .tl-label { color: var(--text-muted); }
  .tl-item .sk-line { display: block; width: 96px; height: 12px; }
}

/* Verdict */
.verdict { display: flex; align-items: center; gap: var(--s-4); padding: var(--s-6); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); }
.verdict.tone-success { background: var(--success-soft); border-color: transparent; color: var(--success); }
.verdict.tone-danger { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
.verdict.tone-warning { background: var(--warning-soft); border-color: transparent; color: var(--warning); }
.panel-result .verdict { animation: pop .55s var(--ease-pop) backwards; }
.v-icon { display: grid; place-items: center; flex-shrink: 0; width: 56px; height: 56px; border-radius: 50%; background: currentColor; }
.v-icon svg { color: #fff; }
.v-icon path { stroke-dasharray: 40; animation: draw .5s .3s ease backwards; }
.panel-result .v-icon { animation: pop .5s .1s var(--ease-pop) backwards; }
.v-label { font-size: var(--fs-28); font-weight: var(--fw-semibold); line-height: var(--lh-heading); }
.v-sub { margin-top: var(--s-1); font-size: var(--fs-14); color: var(--text); }

/* KPI stat tiles */
.kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-2); }
.kpi { padding: var(--s-3) var(--s-4); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); animation: rise .45s var(--ease) backwards; animation-delay: calc(var(--i) * 70ms + 150ms); }
.kpi dt { font-size: var(--fs-12); font-weight: var(--fw-medium); color: var(--text-muted); }
.kpi dd { margin-top: 2px; font-size: var(--fs-28); font-weight: var(--fw-semibold); line-height: var(--lh-heading); }
.kpi .unit { margin-left: 2px; font-size: var(--fs-14); font-weight: var(--fw-medium); color: var(--text-muted); }
.kpi .meter { margin-top: var(--s-2); }
.kpi-sk { height: 78px; border-radius: var(--radius-card); }

/* Meters: blue fill on a lighter step of the same ramp */
.meter { display: block; height: 6px; overflow: hidden; border-radius: 999px; background: var(--primary-soft); }
.meter > span { display: block; width: calc(var(--v) * 100%); height: 100%; border-radius: inherit; background: var(--primary); animation: grow .9s var(--ease) backwards; animation-delay: var(--d, 0ms); }

/* Defect tiles */
.defects-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s-2); margin-bottom: var(--s-2); }
.defects-title { font-size: var(--fs-14); font-weight: var(--fw-semibold); }
.hint { font-size: var(--fs-12); color: var(--text-muted); }
.defect-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--s-2); max-height: 260px; overflow-y: auto; padding: 2px; }
.defect-tile {
  position: relative; aspect-ratio: 1 / 1; padding: 0; overflow: hidden; cursor: zoom-in; background: var(--stage); border: 0; border-radius: var(--radius-card);
  animation: pop .45s var(--ease-pop) backwards; animation-delay: calc(var(--i, 0) * 60ms + 250ms); transition: box-shadow .2s ease;
}
.defect-tile img { width: 100%; height: 100%; object-fit: cover; transition: transform .35s var(--ease); }
.defect-tile:hover img, .defect-tile.active img { transform: scale(1.1); }
.defect-tile.active, .defect-tile.is-zoomed { box-shadow: 0 0 0 2px var(--defect); }
.tile-id { position: absolute; top: var(--s-1); left: var(--s-1); padding: 0 6px; border-radius: var(--s-1); background: var(--danger); color: #fff; font-size: var(--fs-12); font-weight: var(--fw-semibold); line-height: 18px; }

.empty-note { display: flex; gap: var(--s-3); padding: var(--s-4); border-radius: var(--radius-card); background: var(--surface); border: 1px solid var(--border); font-size: var(--fs-14); }
.empty-note svg { flex-shrink: 0; color: var(--success); }

/* Selected defect / summary card */
.detail-card { padding: var(--s-4); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); animation: rise .45s .4s var(--ease) backwards; }
.detail-card:empty { display: none; }
.detail-head { display: flex; align-items: center; gap: var(--s-2); margin-bottom: var(--s-3); }
.detail-head .grow { flex: 1; min-width: 0; font-size: var(--fs-14); font-weight: var(--fw-semibold); }
.detail-head .num { font-size: var(--fs-14); font-weight: var(--fw-semibold); }
.detail-card.is-changing { animation: fade .25s ease backwards; }
.id-badge { display: inline-block; padding: 0 var(--s-2); border-radius: var(--s-1); background: var(--danger); color: #fff; font-size: var(--fs-12); font-weight: var(--fw-semibold); line-height: 20px; }

.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: var(--s-2) var(--s-4); font-size: var(--fs-14); }
.kv dt { color: var(--text-muted); }
.kv dd { overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.detail-card .kv { margin-top: var(--s-3); }

/* Insights below the stage */
.insights { display: grid; gap: var(--s-6); animation: rise .5s var(--ease) backwards; }
.insight-side { display: flex; flex-direction: column; gap: var(--s-6); min-width: 0; }
@media (min-width: 1024px) { .insights { grid-template-columns: minmax(0, 1fr) 360px; align-items: start; } }

.table-wrap { margin-top: var(--s-4); overflow-x: auto; }
.defect-table { width: 100%; border-collapse: collapse; font-size: var(--fs-14); }
.defect-table th { padding: var(--s-2) var(--s-3); font-size: var(--fs-12); font-weight: var(--fw-semibold); color: var(--text-muted); text-align: left; white-space: nowrap; border-bottom: 1px solid var(--border); }
.defect-table td { padding: var(--s-2) var(--s-3); border-bottom: 1px solid var(--border); white-space: nowrap; font-variant-numeric: tabular-nums; }
.defect-table tbody tr { cursor: pointer; transition: background-color .15s; animation: rise .4s var(--ease) backwards; animation-delay: calc(var(--i) * 40ms + 200ms); }
.defect-table tbody tr:hover, .defect-table tbody tr.active { background: var(--bg); }
.defect-table tbody tr.active td:first-child { box-shadow: inset 3px 0 0 var(--defect); }
.defect-table .num-col { text-align: right; }
.row-thumb { width: 40px; height: 40px; border-radius: var(--radius-control); object-fit: cover; background: var(--stage); }
.conf-cell { display: flex; align-items: center; gap: var(--s-2); min-width: 140px; }
.conf-cell .meter { flex: 1; }
.conf-cell span:last-child { width: 40px; text-align: right; }

.tips { display: grid; gap: var(--s-3); margin: var(--s-4) 0 0; padding: 0; list-style: none; }
.tips li { display: flex; gap: var(--s-3); font-size: var(--fs-14); }
.tips svg { flex-shrink: 0; color: var(--warning); }
.state-banner { display: flex; align-items: center; gap: var(--s-3); margin-top: var(--s-4); padding: var(--s-4); border-radius: var(--radius-card); font-size: var(--fs-14); }
.state-banner.tone-success { background: var(--success-soft); color: var(--success); }
.state-banner strong { font-weight: var(--fw-semibold); }

.meter-list { display: grid; gap: var(--s-3); margin: var(--s-4) 0 0; padding: 0; list-style: none; }
.meter-row { display: grid; grid-template-columns: 120px minmax(0, 1fr) 56px; align-items: center; gap: var(--s-3); padding: 2px 0; border-radius: var(--radius-control); font-size: var(--fs-14); }
.meter-row:hover .meter > span { background: var(--primary-hover); }
.meter-row .meter { height: 8px; }
.meter-value { text-align: right; font-weight: var(--fw-medium); font-variant-numeric: tabular-nums; }
#details { margin-top: var(--s-4); }

/* Skeleton */
.skeleton { display: block; border-radius: var(--radius-control); background: linear-gradient(90deg, var(--border) 25%, var(--bg) 50%, var(--border) 75%); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; }
.sk-verdict .v-icon { background-color: transparent; }
.sk-lines { display: flex; flex: 1; flex-direction: column; gap: var(--s-2); }
.sk-lines .skeleton { height: 20px; }
.sk-lines .skeleton.short { width: 60%; height: 14px; }
.skeleton.tile { aspect-ratio: 1 / 1; border-radius: var(--radius-card); }
.tl-item.is-loading .tl-thumb { background: linear-gradient(90deg, var(--border) 25%, var(--bg) 50%, var(--border) 75%); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; }

/* Recent inspections */
.recent { animation: fade .4s ease backwards; }
.recent-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: var(--s-3); margin: 0; padding: 0; list-style: none; }
.recent-card {
  display: flex; align-items: center; gap: var(--s-3); width: 100%; padding: var(--s-2); text-align: left; cursor: pointer;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow);
  transition: transform .2s var(--ease), border-color .2s;
}
.recent-card:hover { transform: translateY(-2px); border-color: var(--primary-soft); }
.recent-card.is-current { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
.recent-card img { flex-shrink: 0; width: 56px; height: 56px; border-radius: var(--radius-card); object-fit: cover; background: var(--stage); }
.recent-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.recent-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--fs-14); font-weight: var(--fw-semibold); }
.recent-info { font-size: var(--fs-12); color: var(--text-muted); }
.pill { display: inline-flex; align-items: center; gap: 6px; align-self: flex-start; padding: 0 var(--s-2); border-radius: 999px; font-size: var(--fs-12); font-weight: var(--fw-semibold); line-height: 20px; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.tone-success.pill { background: var(--success-soft); color: var(--success); }
.tone-danger.pill { background: var(--danger-soft); color: var(--danger); }
.tone-warning.pill { background: var(--warning-soft); color: var(--warning); }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: var(--s-6); z-index: 60; transform: translateX(-50%);
  display: flex; align-items: center; gap: var(--s-3); width: max-content; max-width: calc(100vw - 32px);
  padding: var(--s-3) var(--s-4); border-radius: var(--radius-card); background: var(--text); color: #fff;
  font-size: var(--fs-14); box-shadow: var(--shadow-lg); animation: toast-in .35s var(--ease) backwards;
}
.toast::before { content: ""; flex-shrink: 0; width: 8px; height: 8px; border-radius: 50%; background: var(--defect); }

.print-only { display: none; }

/* =========================================================================
   5. Motion
   ========================================================================= */
@keyframes rise { from { opacity: 0; transform: translateY(12px); } }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: scale(.85); } }
@keyframes grow { from { width: 0; } }
@keyframes float { 50% { transform: translateY(-6px); } }
@keyframes ripple { from { opacity: .6; transform: scale(1); } to { opacity: 0; transform: scale(1.7); } }
@keyframes drift { 50% { transform: translate(40px, 20px) scale(1.1); } }
@keyframes flow { 0%, 30%, 100% { transform: none; border-color: var(--primary-soft); } 15% { transform: translateX(3px) scale(1.15); border-color: var(--primary); } }
@keyframes breathe { 50% { opacity: .35; } }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@keyframes scan { to { top: 100%; } }
@keyframes iris { from { clip-path: circle(0% at 50% 50%); } to { clip-path: circle(75% at 50% 50%); } }
@keyframes focus-in { from { filter: blur(10px) brightness(1.4); } }
@keyframes wipe { from { clip-path: inset(0 0 100% 0); } to { clip-path: inset(0 0 0 0); } }
@keyframes settle { from { transform: scale(1.08); } }
@keyframes caption-in { from { opacity: 0; transform: translateY(6px); } }
@keyframes draw { from { stroke-dashoffset: 40; } }
@keyframes ping { 0% { opacity: 0; transform: scale(2.4); } 35% { opacity: 1; } 100% { opacity: 0; transform: scale(1); } }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 16px); } }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
@keyframes glow-danger { from { box-shadow: 0 0 0 0 rgba(185, 28, 28, .55), var(--shadow-lg); } to { box-shadow: 0 0 0 24px rgba(185, 28, 28, 0), var(--shadow-lg); } }
@keyframes glow-success { from { box-shadow: 0 0 0 0 rgba(21, 128, 61, .55), var(--shadow-lg); } to { box-shadow: 0 0 0 24px rgba(21, 128, 61, 0), var(--shadow-lg); } }
@keyframes glow-warning { from { box-shadow: 0 0 0 0 rgba(180, 83, 9, .55), var(--shadow-lg); } to { box-shadow: 0 0 0 24px rgba(180, 83, 9, 0), var(--shadow-lg); } }

/* =========================================================================
   6. Print: a full report on paper
   ========================================================================= */
@media print {
  @page { margin: 12mm; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; animation: none !important; transition: none !important; }
  body { background: #fff; }
  .app-header { position: static; border-bottom: 2px solid var(--text); }
  .status, .idle, .viewer, .step-caption, .result-actions, .recent, .toast, .panel-loading, #defects, .detail-card, .footer { display: none !important; }
  .container { max-width: none; padding: 0; }
  .main { gap: var(--s-4); padding-top: var(--s-4); }
  .workspace, .insights { display: block; }
  .insight-side { margin-top: var(--s-4); }
  .card, .verdict, .kpi { box-shadow: none; break-inside: avoid; }
  .kpis { grid-template-columns: repeat(4, 1fr); margin-top: var(--s-4); }
  .table-card { margin-top: var(--s-4); }
  .print-only { display: block; break-before: page; }
  .print-only h2 { margin-bottom: var(--s-3); font-size: var(--fs-16); }
  .print-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s-3); }
  .print-grid figure { break-inside: avoid; }
  .print-grid img { width: 100%; aspect-ratio: 1 / 1; object-fit: contain; background: var(--stage); border-radius: var(--radius-control); }
  .print-grid figcaption { margin-top: var(--s-1); font-size: var(--fs-12); font-weight: var(--fw-medium); }
}
