:root {
  --bg: #0f1216;
  --panel: #171b21;
  --panel-2: #1d222a;
  --line: #2a313b;
  --text: #e6eaf0;
  --muted: #98a2b3;
  --accent: #4da3ff;
  --accent-2: #7c5cff;
  --ok: #38b26a;
  --warn: #e0a33a;
  --bad: #e5484d;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); }

header.top {
  display: flex; align-items: center; gap: 16px;
  padding: 14px 22px; border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #171c24, #12161b);
  position: sticky; top: 0; z-index: 50;
}
header.top h1 { font-size: 17px; margin: 0; letter-spacing: .2px; line-height: 1.15; }
header.top .brand { display: flex; align-items: center; gap: 12px; }
header.top .tagline { font-size: 11.5px; color: var(--muted); letter-spacing: .1px; }
header.top .mark {
  width: 30px; height: 30px; border-radius: 8px; flex: none;
  background: linear-gradient(145deg, var(--accent), var(--accent-2));
  position: relative; box-shadow: 0 2px 10px #4da3ff33;
}
header.top .mark::before, header.top .mark::after {
  content: ""; position: absolute; background: #0b1017cc; border-radius: 1px;
}
header.top .mark::before { left: 7px; right: 7px; top: 10px; height: 2px; }
header.top .mark::after { top: 7px; bottom: 7px; left: 14px; width: 2px; }
header.top .badge {
  font-size: 11px; padding: 3px 9px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--muted); background: #12161b;
}
header.top .spacer { flex: 1; }
header.top .sys { font-family: var(--mono); font-size: 11.5px; color: var(--muted); text-align: right; }

main { padding: 20px 22px 60px; max-width: 1680px; margin: 0 auto; }

section.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); margin-bottom: 20px; overflow: hidden;
}
section.card > h2 {
  margin: 0; padding: 13px 18px; font-size: 14px; font-weight: 600;
  border-bottom: 1px solid var(--line); background: var(--panel-2);
  display: flex; align-items: center; gap: 10px;
}
section.card > h2 .step {
  width: 22px; height: 22px; border-radius: 6px; display: grid; place-items: center;
  background: var(--accent); color: #06101c; font-size: 12px; font-weight: 700;
}
section.card > h2 .sub { font-weight: 400; color: var(--muted); font-size: 12px; }
.card-body { padding: 16px 18px; }

.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
input[type=text], input[type=number], select {
  background: #0e1116; border: 1px solid var(--line); color: var(--text);
  border-radius: 7px; padding: 8px 10px; font-size: 13px; min-width: 150px;
}
input:focus, select:focus { outline: 1px solid var(--accent); border-color: var(--accent); }

button {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  padding: 8px 14px; border-radius: 7px; font-size: 13px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 7px;
}
button:hover:not(:disabled) { border-color: #3d4753; background: #232933; }
button:disabled { opacity: .42; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: #06101c; font-weight: 600; }
button.primary:hover:not(:disabled) { background: #6bb4ff; }
button.danger { border-color: #58272a; color: #ff9ea1; }
button.ghost { background: transparent; }
button.sm { padding: 5px 9px; font-size: 12px; }

.hint { color: var(--muted); font-size: 12.5px; margin: 10px 0 0; }

.note {
  border-radius: 8px; padding: 10px 12px; font-size: 12.5px; margin: 12px 0 0;
  border: 1px solid; line-height: 1.5;
}
.note.info { background: #10202f; border-color: #1d3a55; color: #a9d2f7; }
.note.warn { background: #2a2110; border-color: #4a3a17; color: #f0c98a; }
.note.bad  { background: #2b1516; border-color: #522326; color: #ffaeb0; }
.note.ok   { background: #12241a; border-color: #1f4630; color: #9fe0bb; }
.note ul { margin: 6px 0 0 16px; padding: 0; }

.thumbs { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 14px; }
.thumb {
  width: 190px; border: 1px solid var(--line); border-radius: 9px;
  overflow: hidden; background: #0d1015; position: relative;
}
.thumb.golden { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.thumb img { width: 100%; height: 118px; object-fit: cover; display: block; background: #000; }
.thumb .meta { padding: 7px 9px; font-size: 11.5px; }
.thumb .meta .nm {
  font-weight: 600; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; margin-bottom: 2px;
}
.thumb .meta .dim { color: var(--muted); font-family: var(--mono); font-size: 10.5px; }
.thumb .acts { display: flex; gap: 5px; padding: 0 9px 9px; }
.thumb .tag {
  position: absolute; top: 6px; left: 6px; font-size: 10px; font-weight: 700;
  background: var(--accent); color: #06101c; padding: 2px 7px; border-radius: 999px;
}
.thumb .wtag {
  position: absolute; top: 6px; right: 6px; font-size: 10px;
  background: var(--warn); color: #221802; padding: 2px 6px; border-radius: 999px;
  cursor: help;
}

.progress { margin-top: 14px; display: none; }
.progress.on { display: block; }
.bar { height: 7px; background: #0d1015; border-radius: 999px; overflow: hidden; border: 1px solid var(--line); }
.bar > i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .25s; }
.stages { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.stages span {
  font-size: 11px; padding: 3px 9px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--muted);
}
.stages span.active { border-color: var(--accent); color: var(--accent); }
.stages span.done { border-color: #235c3c; color: var(--ok); }
.progress .detail { margin-top: 8px; font-size: 12px; color: var(--muted); font-family: var(--mono); }

/* ---- viewer ---- */
.viewer-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 1100px) { .viewer-grid { grid-template-columns: 1fr; } }

.pane { border: 1px solid var(--line); border-radius: 9px; overflow: hidden; background: #07090c; }
.pane .pane-head {
  padding: 7px 11px; font-size: 12px; border-bottom: 1px solid var(--line);
  background: var(--panel-2); display: flex; justify-content: space-between; align-items: center;
}
.pane .pane-head b { font-weight: 600; }
.pane .pane-head span { color: var(--muted); font-family: var(--mono); font-size: 11px; }
.stage-wrap { position: relative; height: 460px; overflow: hidden; cursor: grab; background: #07090c; }
.stage-wrap.dragging { cursor: grabbing; }
.stage { position: absolute; top: 0; left: 0; transform-origin: 0 0; }
.stage img { position: absolute; top: 0; left: 0; display: block; image-rendering: auto; }
.stage img.layer { pointer-events: none; }
.stage svg { position: absolute; top: 0; left: 0; overflow: visible; pointer-events: none; }
.stage svg rect { fill: none; stroke: #ff3b40; vector-effect: non-scaling-stroke; stroke-width: 2; }
.stage svg rect.sel { stroke: #ffd400; stroke-width: 3; }
.stage svg text { fill: #fff; font: 700 11px system-ui; paint-order: stroke; stroke: #b3272b; stroke-width: 3px; }

.viewer-toolbar {
  display: flex; gap: 14px; align-items: center; flex-wrap: wrap;
  padding: 11px 0 14px; border-bottom: 1px solid var(--line); margin-bottom: 14px;
}
.viewer-toolbar .grp { display: flex; gap: 8px; align-items: center; }
.viewer-toolbar label { font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
input[type=range] { width: 130px; accent-color: var(--accent); }

.controls { display: flex; gap: 18px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 14px; }
.controls .field { min-width: 190px; }
.controls .val { font-family: var(--mono); font-size: 12px; color: var(--accent); }

table.kv { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.kv td { padding: 5px 8px; border-bottom: 1px solid #232a33; vertical-align: top; }
table.kv td:first-child { color: var(--muted); width: 190px; white-space: nowrap; }
table.kv td.mono, .mono { font-family: var(--mono); font-size: 11.5px; }

.regions { margin-top: 16px; display: flex; flex-direction: column; gap: 10px; max-height: 620px; overflow-y: auto; padding-right: 4px; }
.region {
  display: flex; gap: 12px; padding: 10px; border: 1px solid var(--line);
  border-radius: 9px; background: var(--panel-2); align-items: center; cursor: pointer;
}
.region:hover { border-color: #3d4753; }
.region.sel { border-color: #ffd400; }
.region .idx {
  width: 26px; height: 26px; border-radius: 6px; background: #b3272b; color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 12px; flex: none;
}
.region .crops { display: flex; gap: 8px; }
.region .crops figure { margin: 0; }
.region .crops figcaption { font-size: 10px; color: var(--muted); text-align: center; margin-top: 3px; }
.region .crops img {
  width: 108px; height: 88px; object-fit: contain; background: #000;
  border: 1px solid var(--line); border-radius: 6px; display: block;
}
.region .info { flex: 1; font-size: 12px; }
.region .info .sc { font-family: var(--mono); color: var(--muted); }

.verdict { padding: 12px 14px; border-radius: 9px; font-weight: 600; margin-bottom: 14px; border: 1px solid; }
.verdict.suspected { background: #2b1516; border-color: #522326; color: #ffb4b6; }
.verdict.suspected_low { background: #2a2110; border-color: #4a3a17; color: #f0c98a; }
.verdict.no_anomaly { background: #12241a; border-color: #1f4630; color: #9fe0bb; }
.verdict.unable { background: #1c1f26; border-color: #333b46; color: var(--muted); }
.verdict .small { display: block; font-weight: 400; font-size: 12px; margin-top: 4px; opacity: .85; }

.empty { color: var(--muted); font-size: 13px; padding: 26px; text-align: center; border: 1px dashed var(--line); border-radius: 9px; }

.roi-editor { position: relative; display: inline-block; margin-top: 12px; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.roi-editor img { display: block; max-width: 100%; }
.roi-editor svg { position: absolute; inset: 0; width: 100%; height: 100%; cursor: crosshair; }
.roi-editor svg rect.roi { fill: rgba(77,163,255,.14); stroke: #4da3ff; stroke-width: 2; }
.roi-editor svg rect.ign { fill: rgba(229,72,77,.22); stroke: #e5484d; stroke-width: 2; }

.filedrop {
  border: 1px dashed var(--line); border-radius: 9px; padding: 18px;
  text-align: center; color: var(--muted); font-size: 13px; cursor: pointer;
}
.filedrop:hover, .filedrop.over { border-color: var(--accent); color: var(--accent); }
.filedrop input { display: none; }

.split { display: grid; grid-template-columns: 1.6fr 1fr; gap: 18px; }
@media (max-width: 1280px) { .split { grid-template-columns: 1fr; } }

.tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.tabs button.active { border-color: var(--accent); color: var(--accent); }
details { border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; margin-top: 12px; }
details summary { cursor: pointer; font-size: 12.5px; color: var(--muted); }
.toast {
  position: fixed; right: 18px; bottom: 18px; z-index: 200; max-width: 460px;
  display: flex; flex-direction: column; gap: 8px;
}
.toast > div {
  padding: 11px 14px; border-radius: 9px; font-size: 13px;
  border: 1px solid var(--line); background: var(--panel-2); box-shadow: 0 8px 28px #0008;
}
.toast > div.bad { border-color: #522326; background: #2b1516; color: #ffb4b6; }
.toast > div.ok { border-color: #1f4630; background: #12241a; color: #9fe0bb; }


/* ---- verdict header + status chips ---- */
.vhead { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.vhead .vtext { flex: 1; min-width: 240px; }
.chip {
  font-size: 10.5px; font-weight: 600; letter-spacing: .3px; text-transform: uppercase;
  padding: 3px 9px; border-radius: 999px; border: 1px solid; white-space: nowrap;
}
.chip.ok { border-color: #1f4630; background: #12241a; color: #9fe0bb; }
.chip.warn { border-color: #4a3a17; background: #2a2110; color: #f0c98a; }

/* ---- capture guide / operating notes ---- */
details.opnotes { background: var(--panel); }
details.opnotes summary { color: var(--text); font-weight: 600; }
.opnotes-body {
  display: grid; grid-template-columns: 1fr 1fr; gap: 22px;
  font-size: 12.5px; line-height: 1.6; padding: 12px 2px 4px;
}
@media (max-width: 900px) { .opnotes-body { grid-template-columns: 1fr; } }
.opnotes-body ul { margin: 6px 0 0 16px; padding: 0; color: var(--muted); }
.opnotes-body li { margin-bottom: 4px; }
.opnotes-body b { color: var(--text); }
