/* OCTA Vessel Annotator — dark clinical UI.
   Density over decoration: the canvas gets the pixels, chrome stays out of the way. */

:root {
  --bg:        #0b0e13;
  --bg-1:      #11151d;
  --bg-2:      #171d27;
  --bg-3:      #1e2632;
  --line:      #263040;
  --line-soft: #1c2331;
  --fg:        #d8e0ec;
  --fg-dim:    #8794a8;
  --fg-faint:  #5d6a7e;
  --accent:    #35c6e8;
  --accent-dk: #1b7f97;
  --danger:    #ff5a5f;
  --ok:        #35d07f;

  --c-artery:  #ff4d4f;
  --c-vein:    #4d94ff;
  --c-cap:     #35d07f;
  --c-unc:     #f5a524;

  --rail: 52px;
  --panel: 274px;
  --top: 44px;
  --strip: 84px;
  --radius: 5px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; height: 100%;
  background: var(--bg);
  color: var(--fg);
  font: 12.5px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, sans-serif;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-variant-numeric: tabular-nums; }

/* ───────────────────────── topbar ───────────────────────── */

.topbar {
  height: var(--top);
  display: flex; align-items: center; gap: 8px;
  padding: 0 10px;
  background: var(--bg-1);
  border-bottom: 1px solid var(--line);
  position: relative; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 7px; font-size: 12.5px; letter-spacing: .2px; padding-right: 6px; }
.brand b { font-weight: 650; }
.logo { width: 17px; height: 17px; stroke: var(--accent); fill: none; stroke-width: 1.4; }
.logo circle { fill: rgba(53,198,232,.08); }

.spacer { flex: 1; }

.nav-group { display: flex; align-items: center; gap: 2px; margin-left: 6px; }
.filename {
  min-width: 168px; max-width: 240px;
  text-align: center; padding: 3px 9px;
  background: var(--bg-2); border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  font-family: ui-monospace, Menlo, monospace; font-size: 11.5px;
  color: var(--fg-dim);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.btn {
  background: var(--bg-2); color: var(--fg);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 4px 11px; font-size: 12px; cursor: pointer;
  transition: background .12s, border-color .12s;
  white-space: nowrap;
}
.btn:hover { background: var(--bg-3); border-color: #33415a; }
.btn:active { transform: translateY(.5px); }
.btn.primary { background: var(--accent-dk); border-color: #2aa3c2; color: #eafaff; }
.btn.primary:hover { background: #2394b0; }
.btn.icon { padding: 3px 9px; font-size: 15px; line-height: 1; color: var(--fg-dim); }
.btn.icon.svg { padding: 4px 7px; display: flex; align-items: center; }
.btn.icon.svg svg {
  width: 15px; height: 15px; display: block;
  fill: none; stroke: currentColor; stroke-width: 1.7;
  stroke-linecap: round; stroke-linejoin: round;
}
.btn.icon.svg:not(:disabled):hover { color: var(--fg); }
.hist-group { display: flex; align-items: center; gap: 2px; margin-left: 6px; }
.btn.big { padding: 8px 18px; font-size: 13px; margin-top: 6px; }
.btn:disabled { opacity: .4; cursor: default; }

.status-group { display: flex; align-items: center; gap: 5px; }
.chip {
  font-size: 11px; padding: 2.5px 8px; border-radius: 99px;
  background: var(--bg-2); border: 1px solid var(--line-soft); color: var(--fg-dim);
}
.chip.toggle { cursor: pointer; }
.chip.toggle[data-s="todo"]        { color: var(--fg-faint); }
.chip.toggle[data-s="in progress"] { color: var(--c-unc);  border-color: #4a3c1c; background: #241d0d; }
.chip.toggle[data-s="done"]        { color: var(--ok);     border-color: #1d4433; background: #0e2419; }

/* ───────────────────────── layout ───────────────────────── */

.workspace {
  position: absolute; inset: var(--top) 0 var(--strip) 0;
  display: grid; grid-template-columns: var(--rail) 1fr var(--panel);
}

/* ───────────────────────── tool rail ───────────────────────── */

.rail {
  background: var(--bg-1); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: center;
  padding: 6px 0; gap: 2px; overflow-y: auto;
}
.rail::-webkit-scrollbar { width: 0; }
.tool {
  width: 38px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius); border: 1px solid transparent;
  background: none; color: var(--fg-dim); cursor: pointer; position: relative;
}
.tool svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.tool:hover { background: var(--bg-2); color: var(--fg); }
.tool.active { background: rgba(53,198,232,.14); border-color: rgba(53,198,232,.4); color: var(--accent); }
.tool .k {
  position: absolute; right: 2px; bottom: 1px;
  font-size: 8.5px; font-family: ui-monospace, monospace; color: var(--fg-faint);
}
.tool.active .k { color: var(--accent); }
.rail .sep { width: 24px; height: 1px; background: var(--line); margin: 5px 0; }

/* ───────────────────────── stage ───────────────────────── */

.stage { position: relative; background: #070a0e; overflow: hidden; }
#canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: crosshair; }
.stage.panning #canvas { cursor: grabbing; }
.stage.pannable #canvas { cursor: grab; }

.loupe {
  position: absolute; top: 10px; right: 10px;
  width: 176px; height: 176px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: #05070a;
  box-shadow: 0 6px 24px rgba(0,0,0,.55);
  pointer-events: none;          /* never steals a click from the canvas */
  image-rendering: pixelated;
  z-index: 5;
  display: none;                 /* shown by the render loop once there is
                                    an image and a cursor to magnify */
}

.hud {
  position: absolute; left: 10px; bottom: 10px;
  display: flex; gap: 10px; pointer-events: none;
  font-size: 11px; color: var(--fg-faint);
  background: rgba(11,14,19,.78); border: 1px solid var(--line-soft);
  padding: 3px 9px; border-radius: var(--radius);
  backdrop-filter: blur(6px);
}
.hud span:empty { display: none; }

.empty-state {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; gap: 4px; color: var(--fg-dim); padding: 20px;
}
.empty-state h2 { font-size: 17px; font-weight: 550; color: var(--fg); margin: 0 0 2px; }
.empty-state p { margin: 0; max-width: 420px; line-height: 1.6; }
.empty-state code { background: var(--bg-2); padding: 1px 5px; border-radius: 3px; color: var(--accent); font-size: 11.5px; }
.empty-state .hint { color: var(--fg-faint); font-size: 11.5px; margin-top: 10px; }

.toast {
  position: absolute; left: 50%; top: 14px; transform: translateX(-50%) translateY(-8px);
  background: var(--bg-3); border: 1px solid var(--line);
  padding: 5px 14px; border-radius: 99px; font-size: 12px;
  opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s;
  box-shadow: 0 6px 24px rgba(0,0,0,.5);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { border-color: #6b2b2e; color: #ffb4b6; }

/* ───────────────────────── right panel ───────────────────────── */

.panel {
  background: var(--bg-1); border-left: 1px solid var(--line);
  overflow-y: auto; overscroll-behavior: contain;
}
.panel::-webkit-scrollbar { width: 9px; }
.panel::-webkit-scrollbar-thumb { background: #222c3a; border-radius: 9px; border: 3px solid var(--bg-1); }

.pgroup { border-bottom: 1px solid var(--line-soft); padding: 9px 11px 11px; }
.pgroup h3 {
  margin: 0 0 8px; font-size: 10px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .85px; color: var(--fg-faint);
  display: flex; align-items: center; justify-content: space-between;
}
.pgroup h3 .sub { text-transform: none; letter-spacing: 0; color: var(--accent); font-weight: 500; font-size: 11px; }

.row { display: flex; align-items: center; gap: 8px; min-height: 24px; font-size: 12px; color: var(--fg-dim); }
.row + .row { margin-top: 3px; }
.row.switch { cursor: pointer; user-select: none; }
.row.switch span { flex: 1; }
.row.switch:hover span { color: var(--fg); }
.row.slider span { width: 58px; flex: none; }
.row.slider output { width: 40px; text-align: right; font-family: ui-monospace, monospace; font-size: 11px; color: var(--fg); flex: none; }
.row.select span { width: 58px; flex: none; }
.row.op input[type=number] { width: 52px; }
.row.op .unit { color: var(--fg-faint); font-size: 10.5px; width: 22px; }
.row.buttons { margin-top: 7px; }
.row.buttons4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; margin-top: 7px; }

kbd {
  font-family: ui-monospace, monospace; font-size: 9.5px;
  background: var(--bg-3); border: 1px solid var(--line);
  border-bottom-width: 2px; border-radius: 3px;
  padding: 0 4px; color: var(--fg-faint); min-width: 15px; text-align: center;
}

input[type=range] {
  -webkit-appearance: none; appearance: none;
  flex: 1; height: 3px; border-radius: 3px; background: var(--bg-3); outline: none;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 12px; height: 12px; border-radius: 50%;
  background: var(--fg-dim); cursor: pointer; border: none; transition: background .12s;
}
input[type=range]:hover::-webkit-slider-thumb { background: var(--accent); }

input[type=checkbox] {
  -webkit-appearance: none; appearance: none;
  width: 13px; height: 13px; border: 1px solid var(--line); border-radius: 3px;
  background: var(--bg-2); cursor: pointer; position: relative; flex: none;
}
input[type=checkbox]:checked { background: var(--accent-dk); border-color: var(--accent); }
input[type=checkbox]:checked::after {
  content: ''; position: absolute; left: 4px; top: 1px;
  width: 3px; height: 7px; border: solid #eafaff; border-width: 0 1.8px 1.8px 0; transform: rotate(42deg);
}

input[type=number], select {
  background: var(--bg-2); color: var(--fg); border: 1px solid var(--line);
  border-radius: 4px; padding: 2px 5px; font-size: 11.5px; font-family: ui-monospace, monospace;
  flex: 1; min-width: 0;
}
select { font-family: inherit; }

.mini {
  background: var(--bg-2); color: var(--fg-dim); border: 1px solid var(--line);
  border-radius: 4px; padding: 3px 7px; font-size: 11px; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.mini:hover { background: var(--bg-3); color: var(--fg); }
.mini.wide { flex: 1; }
.mini.danger:hover { background: #3a1618; border-color: #6b2b2e; color: #ffb4b6; }

.note { font-size: 10.5px; color: var(--fg-faint); line-height: 1.5; margin: 8px 0 0; }
.note span { color: var(--fg-dim); font-family: ui-monospace, monospace; }

/* class list */
.classlist { display: flex; flex-direction: column; gap: 3px; }
.classrow {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 7px; border-radius: var(--radius);
  border: 1px solid transparent; cursor: pointer; user-select: none;
}
.classrow:hover { background: var(--bg-2); }
.classrow.active { background: var(--bg-3); border-color: var(--line); }
.classrow .sw {
  width: 12px; height: 12px; border-radius: 3px; flex: none;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.15);
  cursor: pointer; position: relative; overflow: hidden;
}
.classrow .sw input[type=color] {
  position: absolute; inset: 0; opacity: 0; cursor: pointer;
  border: none; padding: 0; width: 100%; height: 100%;
}
/* The name is an input styled as text — click to rename, no mode switch. */
.classrow .nm {
  flex: 1; min-width: 0;
  color: var(--fg-dim); font-size: 12px; font-family: inherit;
  background: none; border: 1px solid transparent; border-radius: 3px;
  padding: 1px 4px; margin: 0;
}
.classrow .nm:hover { border-color: var(--line); }
.classrow .nm:focus { background: var(--bg); border-color: var(--accent); color: var(--fg); outline: none; }
.classrow.active .nm { color: var(--fg); font-weight: 550; }
.classrow .del {
  opacity: 0; color: var(--fg-faint); font-size: 15px; line-height: 1;
  cursor: pointer; padding: 0 2px; flex: none;
}
.classrow:hover .del { opacity: .5; }
.classrow .del:hover { opacity: 1; color: var(--danger); }
.classrow kbd.none { opacity: .35; }
.classadd { margin-top: 6px; display: flex; }
.classadd .mini:disabled { opacity: .4; cursor: default; }
.importsel { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line-soft); }
.importsel span { width: auto; flex: none; font-size: 11px; color: var(--fg-faint); }
.classrow .ct { font-family: ui-monospace, monospace; font-size: 10.5px; color: var(--fg-faint); }
.classrow .vis { opacity: .35; }
.classrow .vis:hover { opacity: 1; }
.classrow .vis svg { width: 13px; height: 13px; stroke: currentColor; fill: none; stroke-width: 1.4; display: block; }
.classrow.hidden .nm, .classrow.hidden .sw { opacity: .35; }

/* stats */
.stats { width: 100%; border-collapse: collapse; font-size: 11px; }
.stats td { padding: 2px 0; color: var(--fg-dim); }
.stats td:last-child { text-align: right; font-family: ui-monospace, monospace; color: var(--fg); }
.stats tr.sub td { color: var(--fg-faint); font-size: 10.5px; padding: 1px 0; }
.stats tr.sub td:last-child { color: var(--fg-dim); }
.classrow .rgn { color: var(--fg-faint); font-size: 11px; flex: none; }
.classadd { display: flex; gap: 4px; }
.row.op .lbl { width: 58px; flex: none; }
.stats tr.total td { border-top: 1px solid var(--line-soft); padding-top: 5px; color: var(--fg-faint); }

/* ───────────────────────── filmstrip ───────────────────────── */

.filmstrip {
  position: absolute; left: 0; right: 0; bottom: 0; height: var(--strip);
  background: var(--bg-1); border-top: 1px solid var(--line);
  display: flex; gap: 6px; padding: 8px 10px; overflow-x: auto; overflow-y: hidden;
  align-items: center;
}
.filmstrip::-webkit-scrollbar { height: 7px; }
.filmstrip::-webkit-scrollbar-thumb { background: #222c3a; border-radius: 9px; }
.thumb {
  position: relative; flex: none;
  width: 60px; height: 60px; border-radius: 4px; overflow: hidden;
  border: 1px solid var(--line); cursor: pointer; background: #000;
}
.thumb canvas, .thumb img { width: 100%; height: 100%; display: block; image-rendering: pixelated; }
.thumb.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.thumb .lbl {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: linear-gradient(transparent, rgba(0,0,0,.85));
  font-size: 9px; font-family: ui-monospace, monospace; text-align: center;
  color: #cfd8e6; padding: 6px 0 1px;
}
.thumb .dot { position: absolute; top: 3px; right: 3px; width: 6px; height: 6px; border-radius: 50%; background: var(--fg-faint); }
.thumb[data-s="in progress"] .dot { background: var(--c-unc); }
.thumb[data-s="done"] .dot { background: var(--ok); }

/* ───────────────────────── help overlay ───────────────────────── */

.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(5,7,10,.78); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; padding: 30px;
}
/* An author `display` rule outranks the UA's [hidden] { display: none },
   so the hidden attribute needs restating here or the overlay never closes. */
.overlay[hidden] { display: none; }
.help {
  position: relative; max-width: 900px; max-height: 100%; overflow-y: auto;
  background: var(--bg-1); border: 1px solid var(--line);
  border-radius: 10px; padding: 22px 26px 26px;
  box-shadow: 0 24px 80px rgba(0,0,0,.7);
}
.help h2 { font-size: 12px; text-transform: uppercase; letter-spacing: 1px; color: var(--fg-faint); margin: 0 0 12px; font-weight: 600; }
.help h2 + * { margin-top: 0; }
.helpcols { columns: 3; column-gap: 26px; margin-bottom: 24px; }
.helpcols .hk { break-inside: avoid; display: flex; align-items: baseline; gap: 8px; padding: 2.5px 0; font-size: 11.5px; color: var(--fg-dim); }
.helpcols .hk kbd { flex: none; }
.helpcols .hgroup { break-inside: avoid; font-size: 9.5px; text-transform: uppercase; letter-spacing: .8px; color: var(--accent); margin: 12px 0 4px; }
.helpcols .hgroup:first-child { margin-top: 0; }
.workflow { margin: 0; padding-left: 18px; columns: 2; column-gap: 26px; }
.workflow li { break-inside: avoid; font-size: 11.5px; color: var(--fg-dim); line-height: 1.6; margin-bottom: 9px; padding-left: 2px; }
.workflow b { color: var(--fg); font-weight: 600; }
.close {
  position: absolute; top: 12px; right: 14px;
  background: none; border: none; color: var(--fg-faint); font-size: 22px; cursor: pointer; line-height: 1;
}
.close:hover { color: var(--fg); }

@media (max-width: 1180px) { :root { --panel: 240px; } }
