/* =========================================================================
   contour.css — RT Contour trainer. Mirrors the RT3D / Image Match RT theme.
   ========================================================================= */

:root {
  --bg: #0e141c;
  --surface: #161f2b;
  --surface-2: #1e2937;
  --border: #263241;
  --border-strong: #3a4759;
  --text: #e8edf2;
  --text-muted: #9aa7b5;
  --text-faint: #6b7888;
  --accent: #0d9488;
  --accent-hover: #14b8a6;
  --accent-dim: #0891b2;
  --grad: linear-gradient(135deg, #0d9488, #0891b2);
  --danger: #dc2626;
  --warn: #d97706;
  --good: #16a34a;
  --radius: 12px;
  --radius-sm: 8px;
  --panel-w: 420px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text",
          "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
}

html[data-theme="light"] {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-2: #eceef1;
  --border: #e3e6ea;
  --border-strong: #cfd4dc;
  --text: #1d1d1f;
  --text-muted: #55606e;
  --text-faint: #8a929e;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0; height: 100vh;
  background: var(--bg); color: var(--text);
  font-family: var(--font); letter-spacing: -0.011em;
  -webkit-font-smoothing: antialiased;
  overflow: hidden; display: flex; flex-direction: column;
}

/* ---- Top bar ---- */
.topbar {
  flex: 0 0 auto; height: 52px; display: flex; align-items: center; gap: 10px;
  padding: 0 14px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 15px; display: flex; align-items: center; gap: 7px; }
.brand .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); }
.brand .rt { color: var(--accent); }
.brand-mode { color: var(--text-muted); font-weight: 500; font-size: 13px; }
.topbar .spacer { flex: 1; }

.btn {
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); padding: 7px 12px; font: inherit; font-size: 13px;
  cursor: pointer; white-space: nowrap; text-decoration: none; display: inline-flex;
  align-items: center; gap: 6px;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.sm { padding: 5px 9px; font-size: 12px; }
.btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* ---- Case bar ---- */
.casebar {
  flex: 0 0 auto; display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 9px 14px; background: var(--surface-2); border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.casebar label { color: var(--text-muted); font-size: 11px; text-transform: uppercase;
  letter-spacing: .06em; font-weight: 700; }
select, input[type=text] {
  background: var(--surface); color: var(--text); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); padding: 6px 9px; font: inherit; font-size: 13px;
}
/* ---- Main toolbar ---- */
.toolbar {
  flex: 0 0 auto; display: flex; align-items: center; gap: 4px; flex-wrap: wrap;
  padding: 7px 12px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.tbgroup { display: flex; align-items: center; gap: 3px; }
.tbsep { width: 1px; height: 22px; background: var(--border-strong); margin: 0 7px; flex: none; }
.tbspacer { flex: 1 1 auto; }
.tb {
  background: transparent; color: var(--text-muted); border: 1px solid transparent;
  border-radius: var(--radius-sm); padding: 6px 11px; font: inherit; font-size: 12.5px;
  cursor: pointer; white-space: nowrap; line-height: 1.1;
}
.tb:hover { background: var(--surface-2); color: var(--text); }
.tb.active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.tb.danger:hover { background: var(--danger); color: #fff; border-color: var(--danger); }
.tbval { font-size: 12px; color: var(--text-muted); min-width: 46px; text-align: center;
  font-variant-numeric: tabular-nums; }
.tbchk { display: flex; align-items: center; gap: 6px; font-size: 12.5px;
  color: var(--text-muted); cursor: pointer; white-space: nowrap; }
.tbchk input { accent-color: var(--accent); width: 14px; height: 14px; }
.tbslice { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-muted); }
.tbslice input[type=range] { width: 190px; accent-color: var(--accent); }
@media (max-width: 1100px) { .tbslice input[type=range] { width: 110px; } }

.status-line {
  flex: 0 0 auto; padding: 7px 14px; font-size: 12.5px; color: var(--text-muted);
  background: var(--bg); border-bottom: 1px solid var(--border);
}
.status-line.err { color: #fca5a5; }

/* ---- Workspace ---- */
.workspace { flex: 1 1 auto; display: flex; min-height: 0; }
.viewer { flex: 1 1 auto; position: relative; background: #000; min-width: 0;
  display: grid; gap: 3px; }

/* Layouts. "hero" is the 3-up the planning systems use: one large pane with the
   other two stacked beside it. NiiVue's own multiplanar always redraws all three
   panes alongside the hero, giving a duplicate, so we lay the panes out here. */
.viewer[data-layout="single"] { grid-template-columns: 1fr; grid-template-rows: 1fr; }
.viewer[data-layout="single"] .pane-b,
.viewer[data-layout="single"] .pane-c { display: none; }

.viewer[data-layout="hero"] {
  grid-template-columns: 2fr 1fr;
  grid-template-rows: 1fr 1fr;
}
.viewer[data-layout="hero"] .pane-main { grid-area: 1 / 1 / 3 / 2; }
.viewer[data-layout="hero"] .pane-b    { grid-area: 1 / 2 / 2 / 3; }
.viewer[data-layout="hero"] .pane-c    { grid-area: 2 / 2 / 3 / 3; }

.viewer[data-layout="grid"] { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.viewer[data-layout="grid"] .pane-main { grid-area: 1 / 1 / 2 / 2; }
.viewer[data-layout="grid"] .pane-b    { grid-area: 1 / 2 / 2 / 3; }
.viewer[data-layout="grid"] .pane-c    { grid-area: 2 / 1 / 3 / 2; }

.viewer[data-layout="row"] { grid-template-columns: repeat(3, 1fr); grid-template-rows: 1fr; }

.pane { position: relative; background: #000; overflow: hidden; min-width: 0; min-height: 0; }
.pane canvas.gl { width: 100%; height: 100%; display: block; }
.pane .overlay { position: absolute; inset: 0; width: 100%; height: 100%;
  pointer-events: none; }
.pane-tag {
  position: absolute; left: 8px; top: 6px; font-size: 11px; letter-spacing: .06em;
  text-transform: uppercase; font-weight: 700; color: rgba(232,237,242,.55);
  pointer-events: none; user-select: none;
}
.pane.active-pane { outline: 1px solid rgba(13,148,136,.6); outline-offset: -1px; }

.viewer-empty {
  position: absolute; inset: 0; display: grid; place-items: center; text-align: center;
  padding: 30px; color: var(--text-muted); pointer-events: none;
}
.viewer-empty .card {
  background: rgba(22,31,43,.92); border: 1px solid var(--border-strong);
  border-radius: var(--radius); padding: 26px 30px; max-width: 380px;
}
.viewer-empty h3 { margin: 10px 0 8px; color: var(--text); font-size: 17px; }
.viewer-empty p { margin: 0; font-size: 13.5px; line-height: 1.55; }

/* ---- Side panel ---- */
.panel {
  flex: 0 0 var(--panel-w); width: var(--panel-w); background: var(--surface);
  border-left: 1px solid var(--border); overflow-y: auto; padding: 18px 20px;
}
.panel .group + .group { border-top: 1px solid var(--border); padding-top: 18px; }
.seg { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.seg .btn { justify-content: center; }
.panel h3 {
  margin: 0 0 10px; font-size: 11px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--text-muted); font-weight: 700;
}
.group { margin-bottom: 20px; }
.toolrow { display: flex; flex-wrap: wrap; gap: 6px; }
.slider-row { display: flex; align-items: center; gap: 9px; margin-top: 9px; }
.slider-row input[type=range] { flex: 1; accent-color: var(--accent); }
.slider-row .val { font-size: 12px; color: var(--text-muted); min-width: 42px;
  text-align: right; font-variant-numeric: tabular-nums; }

.hint { font-size: 11.5px; color: var(--text-faint); margin-top: 8px; line-height: 1.5; }

/* ---- Guidance panel ---- */
.guide { background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px; }
.guide h4 { margin: 0 0 6px; font-size: 14px; color: var(--text); }
.guide .cat {
  display: inline-block; font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .05em; padding: 2px 7px; border-radius: 100px; margin-bottom: 8px;
  background: rgba(13,148,136,.16); color: var(--accent-hover);
}
.guide .cat.target { background: rgba(217,119,6,.16); color: #fbbf24; }
.guide p { margin: 0 0 9px; font-size: 12.5px; line-height: 1.55; color: var(--text-muted); }
.guide ul { margin: 0 0 9px; padding-left: 17px; }
.guide li { font-size: 12.5px; line-height: 1.5; color: var(--text-muted); margin-bottom: 5px; }
.guide .sub { font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .05em; color: var(--text-faint); margin: 11px 0 5px; }
.guide a.eviq {
  display: inline-flex; align-items: center; gap: 5px; font-size: 12px;
  color: var(--accent-hover); text-decoration: none; margin-top: 4px;
}
.guide a.eviq:hover { text-decoration: underline; }
.guide .disclaimer { font-size: 10.5px; color: var(--text-faint); margin-top: 10px;
  padding-top: 9px; border-top: 1px solid var(--border); line-height: 1.5; }

/* ---- Results ---- */
.results { display: none; }
.score-hero {
  text-align: center; padding: 16px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 12px;
}
.score-hero .n { font-size: 40px; font-weight: 800; letter-spacing: -.03em; line-height: 1; }
.score-hero .n.good { color: var(--good); }
.score-hero .n.mid  { color: var(--warn); }
.score-hero .n.low  { color: var(--danger); }
.score-hero .l { font-size: 11px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--text-muted); margin-top: 6px; font-weight: 700; }
.score-hero .best { font-size: 11.5px; color: var(--text-faint); margin-top: 5px; }

.metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.metric { background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 9px 11px; }
.metric .v { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }
.metric .k { font-size: 10px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-faint); margin-top: 3px; font-weight: 700; }

.feedback { background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 11px; margin-bottom: 12px; }
.feedback li { font-size: 12.5px; line-height: 1.5; color: var(--text-muted); margin-bottom: 6px; }
.feedback ul { margin: 0; padding-left: 17px; }

.legend { display: flex; flex-direction: column; gap: 5px; margin-top: 9px; }
.legend .row { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-muted); }
.legend .sw { width: 13px; height: 13px; border-radius: 3px; flex: none; }

/* ---- Login gate ---- */
.gate { position: fixed; inset: 0; background: var(--bg); display: grid;
  place-items: center; z-index: 900; padding: 20px; }
.gate-card { background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 30px; max-width: 380px; text-align: center; }
.gate-card h2 { margin: 0 0 8px; font-size: 20px; }
.gate-card p { color: var(--text-muted); font-size: 13.5px; line-height: 1.55; margin: 0 0 16px; }

/* ---- Toast ---- */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--surface); border: 1px solid var(--border-strong); color: var(--text);
  padding: 11px 18px; border-radius: var(--radius); font-size: 13.5px; opacity: 0;
  transition: .25s; pointer-events: none; z-index: 1000; max-width: 80vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { border-color: var(--danger); }
.toast.ok { border-color: var(--accent); }

/* ---- Checkbox rows ---- */
.chk { display: flex; align-items: center; gap: 8px; margin-top: 10px;
  font-size: 12.5px; color: var(--text-muted); cursor: pointer; }
.chk input { accent-color: var(--accent); width: 15px; height: 15px; flex: none; }

/* ---- Brush mode radios (planning-system style) ---- */
.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 11px 13px; }
.mode-col { display: flex; flex-direction: column; gap: 7px; }
.rad { display: flex; align-items: center; gap: 7px; font-size: 12.5px;
  color: var(--text-muted); cursor: pointer; }
.rad input { accent-color: var(--accent); width: 14px; height: 14px; flex: none; }
.rad input:checked + span { color: var(--text); font-weight: 600; }

/* ---- Inline readouts (tool hint, W/L range, measurements) ---- */
.readout {
  margin-top: 10px; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 8px 11px; font-size: 12px;
  color: var(--text-muted); font-variant-numeric: tabular-nums; line-height: 1.5;
}
.readout strong { color: var(--accent-hover); font-weight: 700; }

/* ---- Tool-specific settings panels ---- */
.tpanel[hidden] { display: none; }
.slab { font-size: 12px; color: var(--text-muted); min-width: 62px; }

/* ---- Measurement list ---- */
.meas-list { margin-top: 9px; display: flex; flex-direction: column; gap: 5px; }
.meas-row {
  display: flex; align-items: center; gap: 9px; font-size: 12.5px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 6px 10px; color: var(--text);
  font-variant-numeric: tabular-nums;
}
.meas-row .n { color: var(--text-faint); font-size: 11px; min-width: 16px; }
.meas-row .mm { font-weight: 700; color: var(--accent-hover); }
.meas-empty { font-size: 12px; color: var(--text-faint); }

/* ---- Upload modal ---- */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); display: none;
  align-items: center; justify-content: center; z-index: 950; padding: 20px;
}
.modal.open { display: flex; }
.modal-card {
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius); padding: 26px; width: 100%; max-width: 520px;
  max-height: 88vh; overflow-y: auto;
}
.modal-card h2 { margin: 0 0 8px; font-size: 19px; }
.modal-sub { color: var(--text-muted); font-size: 13px; line-height: 1.55; margin: 0 0 18px; }
.modal-card code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: 12px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 11px; text-transform: uppercase;
  letter-spacing: .06em; color: var(--text-muted); font-weight: 700; margin-bottom: 5px; }
.field input[type=text], .field input[type=file] {
  width: 100%; background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: 8px 10px; font: inherit; font-size: 13px;
}
.field .req { color: var(--accent-hover); text-transform: none; letter-spacing: 0; font-weight: 600; }
.field .opt { color: var(--text-faint); text-transform: none; letter-spacing: 0; font-weight: 500; }
.struct-list { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 5px; }
.struct-list .chip {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 100px; padding: 3px 10px; font-size: 11.5px; color: var(--text-muted);
}
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }
.upload-progress { margin-top: 12px; font-size: 12.5px; color: var(--text-muted); }
.auth-error { color: #fca5a5; font-size: 12.5px; margin-top: 8px; min-height: 16px; }

/* ---- Busy overlay ---- */
.busy {
  position: absolute; inset: 0; background: rgba(0,0,0,.55); display: none;
  place-items: center; z-index: 60; color: #fff; font-size: 14px;
}
.busy.show { display: grid; }

@media (max-width: 900px) {
  .workspace { flex-direction: column; }
  .panel { flex: 0 0 auto; width: 100%; border-left: none; border-top: 1px solid var(--border); }
  .viewer { min-height: 46vh; }
}
