:root {
  --bg: #0b1017;
  --bg-soft: #0f1721;
  --panel: #141d28;
  --panel-2: #1a2532;
  --panel-3: #223040;
  --line: #263546;
  --line-soft: #1d2a39;
  --text: #e9f0f7;
  --muted: #8fa2b7;
  --faint: #66788c;
  --accent: #5aa9ff;
  --accent-soft: rgba(90, 169, 255, 0.14);
  --ok: #3ecf7a;
  --warn: #f0b429;
  --err: #ff6b61;
  --fast: #2fbf71;
  --fast-dark: #0d2a1c;
  --slow: #f0a72e;
  --slow-dark: #2d210a;
  --uncertain: #7c8ea3;
  --uncertain-dark: #202b38;
  --skip: #2a3644;
  --radius: 14px;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.32);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  background:
    radial-gradient(1200px 600px at 15% -10%, rgba(90, 169, 255, 0.08), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, rgba(62, 207, 122, 0.05), transparent 55%),
    var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: var(--panel-3); padding: 1px 6px; border-radius: 5px; font-size: 0.9em; }

kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-bottom-width: 2px;
  border-radius: 6px;
  font-size: 0.72em;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.82);
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.84em; }
.spacer { flex: 1; }
.eyebrow {
  display: block;
  color: var(--faint);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

/* ---------------------------------------------------------------- chrome --- */
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 24px;
  background: rgba(15, 23, 33, 0.85);
  border-bottom: 1px solid var(--line-soft);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 30;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 750;
  letter-spacing: 0.2px;
}
.brand-mark {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  background: linear-gradient(135deg, var(--accent), var(--fast));
  box-shadow: 0 0 18px rgba(90, 169, 255, 0.5);
}
.topbar nav { display: flex; gap: 4px; margin-left: auto; }
.topbar nav a {
  color: var(--muted);
  padding: 7px 13px;
  border-radius: 8px;
  font-weight: 550;
}
.topbar nav a:hover { background: var(--panel-2); color: var(--text); text-decoration: none; }
.topbar nav a.active { background: var(--accent-soft); color: var(--accent); }

/* ---------------------------------------------------------------- admin ---- */
.page { max-width: 1180px; margin: 24px auto 70px; padding: 0 20px; }

.card {
  background: var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 18px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
}
.card h2 { margin: 0 0 15px; font-size: 1.06rem; letter-spacing: 0.1px; }

.alert { padding: 11px 15px; border-radius: 10px; margin-bottom: 16px; }
.alert.error { background: rgba(255, 107, 97, 0.12); border: 1px solid rgba(255, 107, 97, 0.45); color: #ffb9b3; }

.grid.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(152px, 1fr)); gap: 10px; }
.grid.stats > div {
  background: var(--panel-2);
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  padding: 11px 13px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.grid.stats .num { font-size: 1.55rem; font-weight: 750; letter-spacing: -0.02em; }
.grid.stats .lbl { color: var(--muted); font-size: 0.78rem; }

.button, button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 14px;
  font: inherit;
  font-weight: 550;
  cursor: pointer;
  transition: border-color 0.12s ease, background 0.12s ease, transform 0.06s ease;
}
.button:hover, button:hover { border-color: #3c5470; background: var(--panel-3); text-decoration: none; }
.button:active, button:active { transform: translateY(1px); }
.button.primary, button.primary { background: var(--accent); border-color: var(--accent); color: #06121f; font-weight: 700; }
.button.primary:hover, button.primary:hover { background: #7abaff; border-color: #7abaff; }
.button.small { padding: 5px 10px; font-size: 0.84rem; }
button:disabled { opacity: 0.4; cursor: not-allowed; }

.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
.table th { color: var(--faint); font-weight: 700; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; }
.table .actions { display: flex; flex-wrap: wrap; gap: 5px; }
.export-row td { border-bottom: 2px solid var(--line); background: rgba(255, 255, 255, 0.014); }
.inline { display: inline; }
.inline-form { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.inline-form label { color: var(--muted); }

.form { display: flex; flex-direction: column; gap: 12px; }
.form label { display: flex; flex-direction: column; gap: 5px; color: var(--muted); font-size: 0.9rem; }
.form input, .form select, fieldset input {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  padding: 9px 11px;
  font: inherit;
}
fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 13px; }
legend { color: var(--muted); padding: 0 6px; }
.row3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; }
.presets { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.presets li { display: flex; align-items: center; gap: 14px; background: var(--panel-2); padding: 11px 13px; border-radius: 10px; }

/* ---------------------------------------------------------------- login ---- */
.login-body { display: grid; place-items: center; min-height: 100vh; }
.login-card {
  width: min(430px, 92vw);
  background: var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: 18px;
  padding: 34px;
  box-shadow: var(--shadow);
}
.login-card h1 { margin: 0 0 6px; font-size: 1.45rem; }
.login-card form { display: flex; flex-direction: column; gap: 10px; margin-top: 22px; }
.login-card label { color: var(--muted); font-size: 0.9rem; }
.login-card input {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--text);
  padding: 11px 13px;
  font: inherit;
}

/* -------------------------------------------------------------- annotate ---- */
.workspace {
  max-width: 1520px;
  margin: 18px auto 44px;
  padding: 0 18px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 352px;
  gap: 18px;
  align-items: start;
}

.stage-card {
  background: var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: 16px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: calc(100vh - 118px);
  box-shadow: var(--shadow);
}

.stage-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.sample-block { display: flex; align-items: baseline; gap: 9px; }
.sample-id {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 1.05rem;
  font-weight: 750;
  letter-spacing: 0.02em;
}
.badges { display: flex; gap: 6px; flex-wrap: wrap; }
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 0.76rem;
  font-weight: 650;
}
.badge.dir.up { color: #7ee2a8; border-color: rgba(62, 207, 122, 0.4); background: rgba(62, 207, 122, 0.1); }
.badge.dir.down { color: #ff9c94; border-color: rgba(255, 107, 97, 0.4); background: rgba(255, 107, 97, 0.1); }
.badge.warn { color: #f6cf74; border-color: rgba(240, 180, 41, 0.55); background: rgba(240, 180, 41, 0.12); }

.zoom { display: flex; gap: 3px; background: var(--panel-2); border: 1px solid var(--line-soft); border-radius: 9px; padding: 3px; }
.zoom-btn { padding: 4px 10px; font-size: 0.78rem; background: transparent; border: 1px solid transparent; border-radius: 6px; }
.zoom-btn:hover { background: var(--panel-3); border-color: transparent; }
.zoom-btn.active { background: var(--accent-soft); color: var(--accent); border-color: rgba(90, 169, 255, 0.35); }

.image-viewport {
  position: relative;
  display: grid;
  place-items: center;
  flex: 1 1 auto;
  min-height: 360px;
  overflow: auto;
  background-color: #070b10;
  background-image:
    linear-gradient(45deg, #0d141c 25%, transparent 25%),
    linear-gradient(-45deg, #0d141c 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #0d141c 75%),
    linear-gradient(-45deg, transparent 75%, #0d141c 75%);
  background-size: 22px 22px;
  background-position: 0 0, 0 11px, 11px -11px, -11px 0;
  border: 1px solid var(--line-soft);
  border-radius: 12px;
  padding: 16px;
}
.image-viewport img {
  display: block;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 2px;
}
.empty { color: var(--muted); text-align: center; padding: 50px 20px; }
.empty-icon {
  width: 46px; height: 46px; margin: 0 auto 10px;
  display: grid; place-items: center;
  border-radius: 50%; background: var(--panel-2);
  color: var(--faint); font-size: 1.4rem; font-weight: 700;
}
.empty p { margin: 4px 0; }

.stage-foot { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-height: 22px; }
.meta-chip {
  color: var(--muted);
  background: var(--panel-2);
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 0.76rem;
  font-weight: 550;
}
.position-text { color: var(--faint); font-size: 0.8rem; font-variant-numeric: tabular-nums; }

.side-panel { display: flex; flex-direction: column; gap: 12px; position: sticky; top: 76px; }
.panel-card {
  background: var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 14px 15px;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.16);
}
.setup-card { display: flex; flex-direction: column; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label { color: var(--faint); font-size: 0.7rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }
.field input, .field select {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  padding: 8px 10px;
  font: inherit;
  min-width: 0;
}
.field input:focus, .field select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field-row { display: grid; grid-template-columns: 1fr 108px; gap: 10px; }

.progress-card { display: flex; flex-direction: column; gap: 9px; }
.progress-top { display: flex; align-items: flex-end; justify-content: space-between; gap: 10px; }
.progress-big { font-size: 1.22rem; font-weight: 750; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.percent { color: var(--accent); font-size: 1.22rem; font-weight: 750; font-variant-numeric: tabular-nums; }
.progress-track { height: 8px; background: var(--panel-3); border-radius: 999px; overflow: hidden; }
.progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--fast));
  transition: width 0.25s ease;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--panel-2);
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  padding: 3px 9px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
}
.chip b { color: var(--text); font-variant-numeric: tabular-nums; }
.chip.fast b { color: var(--fast); }
.chip.slow b { color: var(--slow); }
.chip.uncertain b { color: #aebccb; }
.chip.warn b { color: var(--warn); }

.actions-card { display: flex; flex-direction: column; gap: 10px; }
.label-stack { display: flex; flex-direction: column; gap: 8px; }
.label-btn {
  position: relative;
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  align-items: center;
  justify-items: start;
  gap: 0 10px;
  padding: 12px 14px;
  border: 1px solid transparent;
  border-radius: 11px;
  font: inherit;
  cursor: pointer;
  transition: transform 0.06s ease, filter 0.12s ease, box-shadow 0.12s ease;
}
.label-btn:hover { filter: brightness(1.08); }
.label-btn:active { transform: translateY(1px); }
.label-btn .label-main { font-size: 1.06rem; font-weight: 750; line-height: 1.2; }
.label-btn .label-sub { font-size: 0.72rem; opacity: 0.7; grid-row: 2; }
.label-btn kbd { grid-row: 1 / span 2; grid-column: 2; align-self: center; }
.label-btn.fast { background: linear-gradient(180deg, #35cf7d, var(--fast)); color: #04150c; }
.label-btn.slow { background: linear-gradient(180deg, #ffc25a, var(--slow)); color: #1c1302; }
.label-btn.uncertain { background: linear-gradient(180deg, #93a6bb, var(--uncertain)); color: #0a1420; }
.label-btn.skip { background: var(--skip); color: var(--text); font-weight: 650; padding: 10px 13px; grid-template-rows: auto; font-size: 0.9rem; }
.label-btn.skip kbd { grid-row: auto; }
.label-btn.selected { box-shadow: 0 0 0 2px #fff, 0 0 0 5px rgba(90, 169, 255, 0.35); }
.label-btn:disabled { filter: grayscale(0.6); }

.secondary-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; align-items: end; }
.confidence-field select { padding: 9px 10px; }

.nav-card { display: flex; flex-direction: column; gap: 9px; }
.nav-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.nav-btn { width: 100%; }
.save-status { min-height: 1.35em; font-size: 0.82rem; font-weight: 650; text-align: center; }
.save-status.ok { color: var(--ok); }
.save-status.error { color: var(--err); }
.save-status.muted { color: var(--muted); font-weight: 500; }
.key-hint { margin: 0; text-align: center; line-height: 2; }
.key-hint kbd { margin: 0 1px; }

/* ------------------------------------------------------ desktop / mobile --- */
@media (max-width: 1080px) {
  .workspace { grid-template-columns: 1fr; }
  .side-panel { position: static; display: grid; grid-template-columns: 1fr 1fr; }
  .setup-card { grid-column: 1 / -1; }
  .actions-card { grid-column: 1 / -1; }
  .label-stack { display: grid; grid-template-columns: repeat(3, 1fr); }
  .label-btn { grid-template-columns: 1fr; justify-items: center; text-align: center; padding: 13px 8px; }
  .label-btn kbd { position: absolute; top: 6px; right: 6px; grid-row: auto; grid-column: auto; }
  .label-btn .label-sub { display: none; }
  .stage-card { min-height: 62vh; }
  .image-viewport { min-height: 320px; }
}

@media (max-width: 700px) {
  .topbar { padding: 10px 14px; gap: 10px; flex-wrap: wrap; }
  .topbar nav a { padding: 6px 9px; font-size: 0.85rem; }
  .workspace { padding: 0 10px; margin-top: 10px; gap: 0; display: flex; flex-direction: column; align-items: stretch; }
  /* Flatten the side panel so the label buttons can sit directly under the image card. */
  .side-panel { display: contents; }
  .stage-card { padding: 12px; padding-bottom: 8px; min-height: 0; order: 1; border-bottom: none; border-bottom-left-radius: 0; border-bottom-right-radius: 0; margin-bottom: 0; }
  .actions-card { order: 2; margin-top: 0; padding-top: 8px; border-top-left-radius: 0; border-top-right-radius: 0; }
  .setup-card { order: 3; margin-top: 12px; }
  .progress-card { order: 4; margin-top: 12px; }
  .nav-card { order: 5; margin-top: 12px; }
  .field-row { grid-template-columns: 1fr 1fr; }
  .label-stack { grid-template-columns: 1fr; }
  .label-btn { grid-template-columns: 1fr auto; justify-items: start; text-align: left; }
  .label-btn kbd { position: static; }
  .secondary-row { grid-template-columns: 1fr; }
  .image-viewport { min-height: 240px; }
  .nav-row { grid-template-columns: 1fr 1fr; }
}
