/* Ovòcits — dark lab UI. The work happens on photos shot down an eyepiece,
   so the chrome stays dark and out of the way and the image carries the colour. */

:root {
  --bg: #0b1016;
  --bg2: #121a24;
  --bg3: #18222e;
  --line: #243141;
  --line2: #304155;
  --fg: #e8eef6;
  --muted: #8ba0b8;
  --accent: #4da3ff;
  --accent2: #2d7fd6;
  --ok: #3ddc97;
  --warn: #ffb547;
  --danger: #ff6b6b;
  --inner: #4da3ff;
  --outer: #3ddc97;
  --fov: #ffd23f;
  --radius: 12px;
  --sh: 0 8px 28px rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--fg);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

.hidden { display: none !important; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.muted { color: var(--muted); }
.tiny { font-size: 12px; }
.spacer { flex: 1; }
.sep { width: 1px; height: 22px; background: var(--line); flex: none; }

/* ── Login ─────────────────────────────────────────────────────────────── */
.login {
  position: fixed; inset: 0; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1200px 700px at 50% -10%, #1b2838, var(--bg));
}
.login-card {
  width: min(380px, 100%); background: var(--bg2); border: 1px solid var(--line);
  border-radius: 18px; padding: 28px; box-shadow: var(--sh); text-align: center;
}
.brand { font-size: 24px; font-weight: 650; letter-spacing: -.3px; }
.brand.small { font-size: 16px; font-weight: 600; white-space: nowrap; }
.login-card p { margin: 8px 0 20px; font-size: 14px; }
.login-card input {
  width: 100%; padding: 12px 14px; border-radius: 10px; margin-bottom: 10px;
  border: 1px solid var(--line2); background: var(--bg3); color: var(--fg); font-size: 16px;
}
.login-card button {
  width: 100%; padding: 12px; border: 0; border-radius: 10px; cursor: pointer;
  background: var(--accent); color: #04121f; font-weight: 650; font-size: 15px;
}
.error { color: var(--danger); font-size: 14px; margin-top: 10px; }

/* ── Shell ─────────────────────────────────────────────────────────────── */
#app { display: flex; flex-direction: column; height: 100%; }

.topbar {
  display: flex; align-items: center; gap: 12px; flex: none;
  padding: 10px 14px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--bg2); border-bottom: 1px solid var(--line);
}
.viewnav { display: flex; gap: 4px; margin-left: 8px; }
.vtab {
  background: transparent; border: 0; color: var(--muted); cursor: pointer;
  padding: 7px 14px; border-radius: 9px; font-size: 14px; font-weight: 550;
}
.vtab.active { background: var(--bg3); color: var(--fg); }
.topbar .actions { margin-left: auto; display: flex; gap: 6px; }

.iconbtn {
  background: transparent; border: 1px solid transparent; color: var(--muted);
  width: 34px; height: 34px; border-radius: 9px; cursor: pointer; font-size: 17px;
  display: grid; place-items: center; flex: none;
}
.iconbtn:hover { background: var(--bg3); color: var(--fg); }

.btn {
  background: var(--bg3); border: 1px solid var(--line2); color: var(--fg);
  padding: 8px 14px; border-radius: 9px; cursor: pointer; font-size: 14px;
  font-weight: 550; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #04121f; }
.btn.primary:hover { background: var(--accent2); }
.btn.ghost { background: transparent; border-color: var(--line); }
.btn.danger { background: transparent; border-color: #6a2b2b; color: var(--danger); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.view { flex: 1; overflow: auto; padding: 18px; }
.view.mark { padding: 0; display: flex; overflow: hidden; }

.toolbar {
  display: flex; align-items: center; gap: 14px; margin-bottom: 16px; flex-wrap: wrap;
}
.row-actions { display: flex; gap: 8px; margin-left: auto; }
.stats { display: flex; gap: 16px; font-size: 13px; color: var(--muted); flex-wrap: wrap; }
.stats b { color: var(--fg); font-size: 15px; }

.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty h3 { margin: 0 0 6px; color: var(--fg); font-size: 17px; }
.empty p { margin: 0; font-size: 14px; max-width: 460px; margin-inline: auto; }

/* ── Lots ──────────────────────────────────────────────────────────────── */
.lots { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.lot {
  background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; cursor: pointer; transition: border-color .12s, transform .12s;
}
.lot:hover { border-color: var(--accent); transform: translateY(-1px); }
.lot h3 { margin: 0 0 2px; font-size: 17px; }
.lot .meta { font-size: 13px; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; }
.lot .counts { margin-top: 10px; display: flex; gap: 8px; flex-wrap: wrap; }
.tag {
  font-size: 11.5px; padding: 3px 8px; border-radius: 20px; background: var(--bg3);
  border: 1px solid var(--line2); color: var(--muted); white-space: nowrap;
}
.tag.m { border-color: #2f5c8a; color: #9ccdff; }
.tag.ok { border-color: #2a6b52; color: var(--ok); }
.tag.todo { border-color: #6b5520; color: var(--warn); }

/* ── Lot detail ────────────────────────────────────────────────────────── */
.lot-head { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.lot-title h2 { margin: 0; font-size: 22px; }
.lot-sub { color: var(--muted); font-size: 13.5px; margin-top: 3px; }
.lot-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

.photos { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.photo {
  background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; cursor: pointer; position: relative;
}
.photo:hover { border-color: var(--accent); }
.photo img { width: 100%; aspect-ratio: 3/4; object-fit: cover; display: block; background: #000; }
.photo .cap {
  padding: 8px 10px; font-size: 13px; display: flex; justify-content: space-between;
  align-items: center; gap: 6px;
}
.photo .num { font-weight: 650; }
.photo .badge {
  position: absolute; top: 8px; right: 8px; background: rgba(8,14,20,.82);
  border: 1px solid var(--line2); border-radius: 20px; padding: 2px 9px; font-size: 12px;
}
.photo .badge.has { border-color: #2a6b52; color: var(--ok); }

.progress { margin-bottom: 14px; }
.progress .bar { height: 6px; background: var(--bg3); border-radius: 4px; overflow: hidden; }
.progress .bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.progress-label { font-size: 13px; color: var(--muted); margin-top: 6px; }

.unlinked {
  margin-top: 22px; padding: 14px 16px; background: var(--bg2);
  border: 1px solid var(--line); border-radius: var(--radius);
}
.unlinked h4 { margin: 0 0 6px; font-size: 15px; }

/* ── Marking view ──────────────────────────────────────────────────────── */
.mark-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.mark-bar {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px; flex: none;
  background: var(--bg2); border-bottom: 1px solid var(--line); overflow-x: auto;
}
.m-title { font-weight: 600; font-size: 14px; white-space: nowrap; }
.modes { display: flex; gap: 4px; }
.chip {
  background: var(--bg3); border: 1px solid var(--line2); color: var(--muted);
  padding: 6px 12px; border-radius: 20px; cursor: pointer; font-size: 13px; white-space: nowrap;
}
.chip.active { background: var(--accent); border-color: var(--accent); color: #04121f; font-weight: 600; }
.hint { font-size: 12.5px; color: var(--muted); white-space: nowrap; }

.canvas-wrap { flex: 1; position: relative; overflow: hidden; background: #05080c; touch-action: none; }
#canvas { display: block; width: 100%; height: 100%; cursor: crosshair; }
.canvas-badge {
  position: absolute; left: 12px; bottom: 12px; background: rgba(8,14,20,.88);
  border: 1px solid var(--line2); border-radius: 9px; padding: 7px 11px;
  font-size: 12.5px; pointer-events: none; max-width: 70%;
}

.mark-side {
  width: 340px; flex: none; background: var(--bg2); border-left: 1px solid var(--line);
  overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 12px;
}
.side-head { display: flex; align-items: center; gap: 8px; }
.side-head h3 { margin: 0; font-size: 15px; }
.pill {
  background: var(--bg3); border: 1px solid var(--line2); border-radius: 20px;
  padding: 1px 9px; font-size: 12px; color: var(--muted);
}
.side-head .btn { margin-left: auto; }

.ovo-list { display: flex; flex-wrap: wrap; gap: 6px; }
.ovo-chip {
  width: 34px; height: 34px; border-radius: 9px; border: 1px solid var(--line2);
  background: var(--bg3); color: var(--muted); cursor: pointer; font-size: 13px;
  font-weight: 600; display: grid; place-items: center; position: relative;
}
.ovo-chip.sel { border-color: var(--accent); background: var(--accent); color: #04121f; }
.ovo-chip.valid::after {
  content: ''; position: absolute; top: 3px; right: 3px; width: 6px; height: 6px;
  border-radius: 50%; background: var(--ok);
}

.ovo-editor {
  border-top: 1px solid var(--line); padding-top: 12px; display: flex;
  flex-direction: column; gap: 8px;
}
.editor-head { display: flex; align-items: center; }
.editor-head h4 { margin: 0; font-size: 15px; }
.editor-head .btn { margin-left: auto; }

.field-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.seg { display: flex; gap: 4px; }
.seg button {
  flex: 1; padding: 8px; border-radius: 8px; border: 1px solid var(--line2);
  background: var(--bg3); color: var(--muted); cursor: pointer; font-size: 13px; font-weight: 600;
}
.seg button.on { background: var(--accent); border-color: var(--accent); color: #04121f; }
.seg button.auto.on { background: var(--bg3); border-color: var(--accent); color: var(--accent); }

.chips { display: flex; gap: 4px; flex-wrap: wrap; }
.chips button {
  padding: 4px 9px; border-radius: 20px; border: 1px solid var(--line2);
  background: var(--bg3); color: var(--muted); cursor: pointer; font-size: 12px;
}
.chips button.on { border-color: var(--accent); color: var(--accent); }

input[type=range] { width: 100%; accent-color: var(--accent); }
textarea, input[type=text], input[type=date], input[type=number], select {
  width: 100%; padding: 9px 11px; border-radius: 9px; border: 1px solid var(--line2);
  background: var(--bg3); color: var(--fg); font-size: 14px; font-family: inherit; resize: vertical;
}
.readout {
  padding: 8px 11px; border-radius: 9px; background: var(--bg3);
  border: 1px solid var(--line); font-size: 13px;
}

.measures { border-top: 1px solid var(--line); padding-top: 10px; }
.measures-head {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 12px; color: var(--muted); text-transform: uppercase;
  letter-spacing: .4px; margin-bottom: 6px;
}
.mtable { width: 100%; border-collapse: collapse; font-size: 13px; }
.mtable td { padding: 4px 0; border-bottom: 1px solid var(--line); }
.mtable td:last-child { text-align: right; color: var(--fg); }
.mtable tr.strong td { font-weight: 650; }
.mtable tr:last-child td { border-bottom: 0; }
.rotate-row { margin-top: 10px; }
.warn {
  margin-top: 8px; padding: 7px 10px; border-radius: 8px; font-size: 12.5px;
  background: rgba(255, 181, 71, .1); border: 1px solid #6b5520; color: var(--warn);
}

/* ── Data table ────────────────────────────────────────────────────────── */
.tablewrap {
  overflow: auto; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--bg2); max-height: calc(100vh - 220px);
}
.dtable { border-collapse: collapse; width: 100%; font-size: 12.5px; white-space: nowrap; }
.dtable th {
  position: sticky; top: 0; background: var(--bg3); text-align: left;
  padding: 9px 11px; font-size: 11px; letter-spacing: .3px; color: var(--muted);
  border-bottom: 1px solid var(--line2); z-index: 1;
}
.dtable td { padding: 7px 11px; border-bottom: 1px solid var(--line); }
.dtable tbody tr:hover { background: var(--bg3); }
.dtable td.n { text-align: right; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.dtable td.si { color: var(--ok); font-weight: 600; }

.exports { margin-top: 16px; display: flex; flex-direction: column; gap: 6px; }
.exports a { color: var(--accent); text-decoration: none; font-size: 13px; }
.exports a:hover { text-decoration: underline; }

/* ── Modal ─────────────────────────────────────────────────────────────── */
.modal {
  position: fixed; inset: 0; background: rgba(4, 8, 12, .72); display: grid;
  place-items: center; padding: 20px; z-index: 50; backdrop-filter: blur(3px);
}
.modal-card {
  width: min(440px, 100%); background: var(--bg2); border: 1px solid var(--line2);
  border-radius: 16px; padding: 22px; box-shadow: var(--sh);
  max-height: 88vh; overflow-y: auto;
}
.modal-card h3 { margin: 0 0 14px; font-size: 18px; }
.modal-card .row { margin-bottom: 12px; }
.modal-card .row label {
  display: block; font-size: 12px; color: var(--muted);
  text-transform: uppercase; letter-spacing: .4px; margin-bottom: 5px;
}
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }

/* ── Toast ─────────────────────────────────────────────────────────────── */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: var(--bg3); border: 1px solid var(--line2); color: var(--fg);
  padding: 11px 18px; border-radius: 10px; box-shadow: var(--sh); z-index: 80;
  font-size: 14px; max-width: 90vw; text-align: center;
}
.toast.err { border-color: #6a2b2b; color: #ffbcbc; }

/* ── Mobile ────────────────────────────────────────────────────────────── */
@media (max-width: 860px) {
  .view.mark { flex-direction: column; }
  .mark-side {
    width: 100%; border-left: 0; border-top: 1px solid var(--line);
    max-height: 48vh; padding-bottom: max(14px, env(safe-area-inset-bottom));
  }
  .mark-main { min-height: 42vh; }
  .brand.small { display: none; }
  .view { padding: 14px; }
  .lot-actions { width: 100%; }
  .lot-actions .btn { flex: 1; }
}
