/* Палитра взята из цеха: холодная нержавейка и кафель под люминесцентным
   светом, а акцент — цвет самого дефекта на тушке. Один и тот же цвет
   носят рамка на видео, счётчик класса и строка в ленте, поэтому глазу
   не нужно сопоставлять их по подписям. */

:root {
  --steel-900: #1b2124;
  --steel-850: #1f272a;
  --steel-800: #262f33;
  --steel-700: #2f3a3f;
  --steel-600: #3e4b51;
  --chalk: #e6edef;
  --chalk-dim: #90a1a8;
  --chalk-faint: #5e6e75;
  --ok: #5e9e7e;

  /* Цвета классов дефектов, по порядку в модели. */
  --c0: #c0446a;
  --c1: #9a5aa8;
  --c2: #d98324;
  --c3: #4fa3a5;
  --c4: #c9a227;
  --c5: #7a8fc7;
  --c6: #5f9ea0;
  --c7: #b8734a;

  --sans: "IBM Plex Sans", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--steel-900);
  color: var(--chalk);
  font: 400 16px/1.5 var(--sans);
  -webkit-text-size-adjust: 100%;
  padding-bottom: env(safe-area-inset-bottom);
}

main { max-width: 720px; margin: 0 auto; }

/* Статусная строка ------------------------------------------------ */

.bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  border-bottom: 1px solid var(--steel-600);
  background: var(--steel-850);
  font-size: 13px;
}

.lamp {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--chalk-faint);
  flex: none;
}
.lamp[data-state="live"] { background: var(--ok); animation: pulse 2.4s ease-in-out infinite; }
.lamp[data-state="error"] { background: var(--c0); }

@keyframes pulse { 50% { opacity: .35; } }

.bar__state { color: var(--chalk-dim); }
.bar__meta {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--chalk-faint);
  font-variant-numeric: tabular-nums;
}

/* Смотровое окно --------------------------------------------------- */

.viewport {
  position: relative;
  width: 100%;
  /* Высота задаётся напрямую, а не через aspect-ratio: счётчики должны
     попадать на экран вместе с видео, а пропорция при этом ужимала бы
     кадр по ширине. Кадрирование берёт на себя object-fit. */
  height: 46vh;
  height: 46svh;
  min-height: 240px;
  background: #000;
  overflow: hidden;
  border-bottom: 1px solid var(--steel-600);
}

.viewport video,
.viewport canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.curtain {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 32px;
  text-align: center;
  background: var(--steel-850);
}
.curtain[hidden] { display: none; }

.curtain__text {
  margin: 0;
  max-width: 34ch;
  color: var(--chalk-dim);
  font-size: 15px;
}

/* Крупное показание ------------------------------------------------ */

.readout {
  display: flex;
  align-items: baseline;
  gap: 14px;
  padding: 20px 16px 18px;
  border-bottom: 1px solid var(--steel-600);
}

.readout__value {
  font-family: var(--mono);
  font-weight: 600;
  font-size: clamp(3rem, 16vw, 4.5rem);
  line-height: .85;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.03em;
}

.readout__label { color: var(--chalk-dim); font-size: 15px; }

/* Счётчики по классам ---------------------------------------------- */

.classes { padding: 4px 0; }

.class {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "name count" "bar bar";
  align-items: center;
  gap: 6px 12px;
  padding: 11px 16px;
}
.class + .class { border-top: 1px solid var(--steel-800); }

.class__name { grid-area: name; font-size: 15px; }

.class__count {
  grid-area: count;
  font-family: var(--mono);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--hue);
}

.class__bar {
  grid-area: bar;
  height: 3px;
  background: var(--steel-800);
  overflow: hidden;
}
.class__bar i {
  display: block;
  height: 100%;
  background: var(--hue);
  transition: width .25s ease-out;
}

/* Лента событий ---------------------------------------------------- */

.feed { border-top: 1px solid var(--steel-600); padding: 8px 0 4px; }

.feed__list { list-style: none; margin: 0; padding: 0; }

.feed__item {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 8px 16px;
  font-size: 14px;
}
.feed__item time {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--chalk-faint);
  font-variant-numeric: tabular-nums;
}
.feed__item b { font-weight: 500; color: var(--hue); }
.feed__item span {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--chalk-faint);
}
.feed__item--fresh { animation: flash .9s ease-out; }
@keyframes flash { from { background: color-mix(in srgb, var(--hue) 22%, transparent); } }

.feed__empty { margin: 0; padding: 10px 16px 14px; color: var(--chalk-faint); font-size: 14px; }
.feed__empty[hidden] { display: none; }

/* Управление ------------------------------------------------------- */

.controls {
  position: sticky;
  bottom: 0;
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  align-items: end;
  gap: 16px;
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--steel-600);
  background: var(--steel-850);
}

.slider { flex: 1; display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; }
.slider__label { font-size: 13px; color: var(--chalk-dim); }
.slider__value {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--chalk);
  font-variant-numeric: tabular-nums;
}
.slider input { grid-column: 1 / -1; width: 100%; accent-color: var(--chalk-dim); margin: 0; }

.button {
  font: 500 15px var(--sans);
  color: var(--chalk);
  background: var(--steel-700);
  border: 1px solid var(--steel-600);
  border-radius: 4px;
  padding: 10px 16px;
  cursor: pointer;
}
.button:active { background: var(--steel-800); }
.button--primary {
  background: var(--chalk);
  color: var(--steel-900);
  border-color: var(--chalk);
  border-radius: 3px;
  padding: 13px 26px;
  font-size: 16px;
}
.button:focus-visible { outline: 2px solid var(--ok); outline-offset: 2px; }

@media (min-width: 640px) {
  .viewport { height: auto; aspect-ratio: 4 / 3; }
}

/* Переключение страниц -------------------------------------------- */

.bar__state { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lamp[data-state="ok"] { background: var(--ok); }

.bar__nav { display: flex; gap: 2px; flex: none; }
.bar__nav a {
  padding: 3px 10px;
  border: 1px solid transparent;
  border-radius: 3px;
  color: var(--chalk-dim);
  text-decoration: none;
}
.bar__nav a:hover { color: var(--chalk); }
.bar__nav a[aria-current="page"] {
  color: var(--chalk);
  background: var(--steel-800);
  border-color: var(--steel-600);
}
.bar__nav a:focus-visible { outline: 2px solid var(--ok); outline-offset: 1px; }

/* Проверка по фото ------------------------------------------------- */

.desk { max-width: 1280px; margin: 0 auto; }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 150px;
  margin: 16px;
  padding: 24px 20px;
  text-align: center;
  cursor: pointer;
  border: 1px dashed var(--steel-600);
  border-radius: 4px;
  background-image: repeating-linear-gradient(
    -45deg, transparent 0 9px, rgb(230 237 239 / .018) 9px 18px);
  transition: border-color .15s, background-color .15s;
}
.drop:hover,
.drop[data-over] { border-color: var(--chalk-dim); background-color: var(--steel-850); }
.drop[data-over] { border-style: solid; }
.drop:focus-within { outline: 2px solid var(--ok); outline-offset: 2px; }
.drop__title { font-weight: 500; font-size: 17px; }
.drop__hint { color: var(--chalk-faint); font-size: 13px; line-height: 1.45; }

.readout--wrap { flex-wrap: wrap; row-gap: 8px; border-top: 1px solid var(--steel-600); }
.readout__sub { flex-basis: 100%; color: var(--chalk-faint); font-size: 13px; }

.shots { border-top: 1px solid var(--steel-600); }
.shots__empty,
.shots__hint { margin: 0; padding: 16px 16px 0; color: var(--chalk-faint); font-size: 14px; }

.shots__list {
  list-style: none;
  margin: 0;
  padding: 16px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr));
  gap: 16px;
  align-items: start;
}

.shot {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--steel-850);
  border: 1px solid var(--steel-700);
  border-radius: 4px;
}

.shot__frame {
  position: relative;
  aspect-ratio: 4 / 3;
  max-width: 100%;
  overflow: hidden;
  background: #000;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.shot__frame img,
.shot__marks {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
.shot__frame img { object-fit: contain; -webkit-user-drag: none; }
.shot:not([data-state="done"]) .shot__frame img { opacity: .4; filter: grayscale(1); }
.shot[data-state="error"] .shot__frame img { visibility: hidden; }   /* без значка битой картинки */

.shot__marks g { transition: opacity .15s; }
.shot__marks g.is-dim { opacity: .12; }
.shot__frame.is-bare .shot__marks { opacity: 0; }

.shot__veil {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  margin: 0;
  padding: 18px 12px 8px;
  font: 500 12px var(--mono);
  color: var(--chalk-dim);
  background: linear-gradient(transparent, rgb(0 0 0 / .75));
}
.shot[data-state="done"] .shot__veil { display: none; }
.shot[data-state="error"] .shot__veil {
  top: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  text-align: center;
  font: 400 14px/1.45 var(--sans);
  color: var(--chalk);
  background: rgb(27 33 36 / .86);
  box-shadow: inset 3px 0 var(--c0);
}

/* Полоса сканирования, пока снимок распознаётся. */
.shot[data-state="pending"] .shot__frame::after {
  content: "";
  position: absolute;
  left: 0; right: 0; top: 0;
  height: 2px;
  background: var(--chalk-dim);
  box-shadow: 0 0 12px var(--chalk-dim);
  opacity: .6;
  animation: scan 1.4s ease-in-out infinite alternate;
}
@keyframes scan { to { top: calc(100% - 2px); } }

/* minmax(0, …) — иначе длинное имя файла распирает колонку шире карточки. */
.shot__info { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; padding: 12px 14px 14px; }

.shot__head { display: flex; align-items: baseline; gap: 12px; }
.shot__name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font: 400 12px var(--mono);
  color: var(--chalk-dim);
}
.shot__total {
  font: 600 30px/1 var(--mono);
  font-variant-numeric: tabular-nums;
  letter-spacing: -.02em;
}

.shot__chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }

.chip {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  padding: 4px 9px;
  font: 400 13px var(--sans);
  color: var(--chalk);
  background: color-mix(in srgb, var(--hue) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--hue) 45%, transparent);
  border-radius: 3px;
  cursor: pointer;
}
.chip b { font: 500 13px var(--mono); color: var(--hue); font-variant-numeric: tabular-nums; }
.chip[aria-pressed="true"] { background: color-mix(in srgb, var(--hue) 30%, transparent); border-color: var(--hue); }
.chip:focus-visible { outline: 2px solid var(--ok); outline-offset: 1px; }
.chip--none { --hue: var(--ok); color: var(--chalk-dim); cursor: default; }

.shot__foot { display: flex; align-items: center; gap: 8px; }
.shot__meta {
  margin-right: auto;
  font: 400 12px var(--mono);
  color: var(--chalk-faint);
  font-variant-numeric: tabular-nums;
}
.shot:not([data-state="error"]) [data-retry] { display: none; }
.shot[data-state="error"] [data-download] { display: none; }

.button--small { padding: 6px 12px; font-size: 13px; }
.button:disabled { opacity: .4; cursor: default; }

.controls--wide { max-width: 1280px; flex-wrap: wrap; align-items: center; }
.controls--wide .slider { flex: 1 1 220px; }
.controls__buttons { display: flex; gap: 8px; }

.switch {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--chalk-dim);
  cursor: pointer;
}
.switch input { width: 18px; height: 18px; margin: 0; accent-color: var(--ok); }

@media (min-width: 1000px) {
  .desk { display: grid; grid-template-columns: 360px minmax(0, 1fr); align-items: start; }
  .desk__side {
    position: sticky;
    top: 0;
    max-height: 100vh;
    overflow-y: auto;
    padding-bottom: 80px;
    border-right: 1px solid var(--steel-600);
  }
  .shots { border-top: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
