:root {
  --bg: #0b0e13;
  --panel: #12161d;
  --panel-2: #181d26;
  --line: #242b36;
  --text: #e6e9ef;
  --muted: #8a94a6;
  --accent: #3b82f6;
  --accent-2: #60a5fa;
  --ok: #22c55e;
  --danger: #ef4444;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 13px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  display: flex; flex-direction: column; overflow: hidden;
}
button, input, select { font: inherit; color: inherit; }
.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.small { font-size: 11px; }
.count { background: #222a35; padding: 0 6px; border-radius: 999px; font-size: 11px; }

/* ------------------------------------------------------------- top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 14px; border-bottom: 1px solid var(--line); background: var(--panel);
}
.brand span { color: var(--muted); margin-left: 6px; }
.pill { margin-left: 10px; padding: 2px 8px; border-radius: 999px; background: #222a35; color: var(--muted); font-size: 11px; }
.pill.ok { color: var(--ok); }
.pill.err { color: var(--danger); }
.topbar-actions { display: flex; gap: 10px; align-items: center; }
.btn {
  display: inline-block; padding: 6px 12px; border-radius: 6px; cursor: pointer;
  border: 1px solid var(--line); background: #1f252e; color: var(--text);
}
.btn:hover { background: #262e39; }
.link { background: none; border: 0; color: var(--accent-2); cursor: pointer; font-size: 12px; padding: 0 4px; }

/* -------------------------------------------------------------- layout */
.layout {
  flex: 1; display: grid; grid-template-columns: 300px minmax(0, 1fr) 380px; min-height: 0; min-width: 0;
}
.panel { min-height: 0; min-width: 0; display: flex; flex-direction: column; }
.panel.left { border-right: 1px solid var(--line); background: var(--panel); padding: 10px; gap: 10px; }
.panel.right { border-left: 1px solid var(--line); background: var(--panel); }
.panel.viewer { background: #000; position: relative; }

input[type="search"] {
  width: 100%; padding: 6px 8px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
}

/* ------------------------------------------------------ study browser */
.browser { flex: 1; overflow: auto; min-height: 0; }
.patient { margin-bottom: 8px; }
.patient > .hdr {
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px; cursor: pointer;
  padding: 6px 8px; border-radius: 6px; background: var(--panel-2);
}
.patient > .hdr:hover { background: #1f252e; }
.patient > .hdr .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.patient > .hdr .sub { color: var(--muted); font-size: 11px; white-space: nowrap; }
.patient.collapsed .studies { display: none; }
.study { margin: 6px 0 0 6px; padding-left: 8px; border-left: 1px solid var(--line); }
.study > .hdr { color: var(--muted); font-size: 11px; padding: 2px 4px; text-transform: uppercase; letter-spacing: .04em; }
.series {
  display: grid; grid-template-columns: 38px 1fr; gap: 8px; align-items: center;
  padding: 5px 6px; margin: 2px 0; border-radius: 6px; cursor: pointer; border: 1px solid transparent;
}
.series:hover { background: #1f252e; }
.series.active { border-color: var(--accent); background: rgba(59,130,246,.12); }
.series.rt { opacity: .9; }
.badge {
  display: inline-block; text-align: center; font-family: var(--mono); font-size: 10px; font-weight: 700;
  padding: 3px 0; border-radius: 4px; background: #2a3340; color: #cbd5e1;
}
.badge.CT { background: #1e3a5f; } .badge.MR { background: #3b2a5f; } .badge.PT, .badge.NM { background: #5f3b1e; }
.badge.US { background: #1e5f4a; } .badge.CR, .badge.DX, .badge.RG { background: #4a4a1e; }
.badge.RTSTRUCT { background: #5f1e3a; } .badge.RTDOSE { background: #5f4a1e; } .badge.RTPLAN { background: #3a3a3a; }
.badge.SEG { background: #1e5f5f; }
.series .t { font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.series .s { font-size: 11px; color: var(--muted); }
.dropzone {
  border: 1px dashed #3a4350; border-radius: 8px; padding: 10px; text-align: center; color: var(--muted); font-size: 12px;
  transition: border-color .15s, background .15s;
}
.dropzone.over { border-color: var(--accent); background: rgba(59,130,246,.08); color: var(--text); }

/* ------------------------------------------------------------- toolbar */
.toolbar {
  display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; padding: 4px 8px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.toolbar .group { display: flex; gap: 3px; align-items: center; }
.tool {
  padding: 3px 8px; border-radius: 6px; border: 1px solid var(--line); background: #1a2029; color: var(--text); cursor: pointer; font-size: 11.5px;
}
.tool:hover { background: #232b36; }
.tool.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.tool.overlay-toggle.active { background: #7c3aed; border-color: #7c3aed; }
.tool:disabled { opacity: .4; cursor: not-allowed; }
.toolbar select, .toolbar input[type="number"] {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 3px 6px; color: var(--text); font-size: 12px;
}
.toolbar input[type="number"] { width: 62px; }
.toolbar label.num { display: flex; gap: 4px; align-items: center; color: var(--muted); font-size: 12px; }

/* --------------------------------------------------------------- stage */
.stage {
  position: relative; flex: 1; min-height: 0; overflow: hidden; background: #000; outline: none;
  display: grid; gap: 2px; padding: 2px;
}
.stage.layout-1 { grid-template-columns: 1fr; grid-template-rows: 1fr; }
.stage.layout-2 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr; }
.stage.layout-1\+2 { grid-template-columns: 2fr 1fr; grid-template-rows: 1fr 1fr; }
.stage.layout-1\+2 .vp[data-id="0"] { grid-row: 1 / span 2; }
.stage.layout-2x2 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.vp {
  --vp-color: #ef4444;
  position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0;
  border: 1px solid #1c232d; border-radius: 4px; overflow: hidden; background: #000;
}
.vp.active { border-color: var(--vp-color); }
.vp-header {
  display: flex; align-items: center; gap: 6px; padding: 2px 6px; background: #0f131a; border-bottom: 1px solid #1c232d;
  font-size: 11px; color: var(--muted); flex: none;
}
.vp-header::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--vp-color); }
.vp-header select, .vp-header input { background: var(--panel-2); border: 1px solid var(--line); border-radius: 4px; padding: 1px 4px; color: var(--text); font-size: 11px; }
.vp-header input.vp-slab { width: 44px; }
.vp-sep { flex: 1; }
.vp-lab { display: inline-flex; gap: 4px; align-items: center; }
.stage.layout-1 .vp-header { display: none; }
.vp-stage { position: relative; flex: 1; min-height: 0; overflow: hidden; outline: none; cursor: crosshair; }
.vp-stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.vp-msg { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--muted); pointer-events: none; text-align: center; padding: 20px; }
.vp-msg:empty { display: none; }
.vp-tag { font-weight: 700; letter-spacing: .04em; }
.stage.tool-pan .vp-stage, .vp-stage.dragging-pan { cursor: grab; }
.stage.tool-zoom .vp-stage { cursor: ns-resize; }
.stage.tool-cross .vp-stage { cursor: cell; }
.vp-stage.dragging-wl { cursor: ew-resize; }
.overlay {
  position: absolute; margin: 8px; font-family: var(--mono); font-size: 11.5px; line-height: 1.4; pointer-events: none;
  color: #dbe4f0; text-shadow: 0 0 3px #000, 0 0 3px #000; white-space: pre;
}
.overlay.tl { top: 0; left: 0; }
.overlay.tr { top: 0; right: 0; text-align: right; }
.overlay.bl { bottom: 0; left: 0; }
.overlay.br { bottom: 0; right: 0; text-align: right; }
.empty {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center;
  color: var(--muted); pointer-events: none; padding: 20px; z-index: 2;
}
.progress { z-index: 3; }
.empty small { display: block; margin-top: 8px; font-size: 11.5px; }
.progress {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: 260px;
  background: rgba(18,22,29,.85); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; font-size: 12px;
}
.progress div { height: 4px; background: var(--accent); border-radius: 2px; width: 0; transition: width .1s; margin-bottom: 6px; }
.slicebar {
  display: flex; align-items: center; gap: 8px; padding: 6px 10px; background: var(--panel); border-top: 1px solid var(--line);
}
.slicebar input[type="range"] { flex: 1; }
.slicebar .mini { width: 26px; height: 24px; border-radius: 6px; border: 1px solid var(--line); background: #1a2029; color: var(--text); cursor: pointer; }
.slicebar .mono { font-size: 11.5px; color: var(--muted); min-width: 90px; text-align: right; }
.message {
  position: absolute; left: 50%; bottom: 46px; transform: translateX(-50%); max-width: 80%;
  padding: 6px 12px; border-radius: 6px; background: rgba(239,68,68,.15); border: 1px solid var(--danger); color: #fecaca; font-size: 12px;
}
.message.ok { background: rgba(34,197,94,.12); border-color: var(--ok); color: #bbf7d0; }

/* ----------------------------------------------------------- right tabs */
.tabs { display: flex; border-bottom: 1px solid var(--line); background: var(--panel); }
.tab {
  flex: 1; padding: 9px 2px; border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 11.5px; border-bottom: 2px solid transparent;
  white-space: nowrap; min-width: 0; overflow: hidden; text-overflow: ellipsis;
}
.tab .count { padding: 0 4px; font-size: 10px; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.tabpane { display: none; flex: 1; min-height: 0; overflow: auto; padding: 10px 12px; flex-direction: column; gap: 8px; }
.tabpane.active { display: flex; }

.meta { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 3px 10px; margin: 0; font-size: 12px; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; overflow-wrap: anywhere; font-family: var(--mono); font-size: 11.5px; }
.meta dt.section { grid-column: 1 / -1; margin-top: 8px; color: var(--accent-2); text-transform: uppercase; font-size: 10.5px; letter-spacing: .05em; }

.tags-wrap { flex: 1; overflow: auto; min-height: 0; border: 1px solid var(--line); border-radius: 6px; }
.tags { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: 11px; table-layout: fixed; }
.tags col.c-tag { width: 88px; } .tags col.c-vr { width: 28px; } .tags col.c-name { width: 34%; }
.tags th { text-align: left; color: var(--muted); font-weight: 500; position: sticky; top: 0; background: var(--panel); padding: 4px 6px; border-bottom: 1px solid var(--line); }
.tags td { padding: 3px 6px; border-bottom: 1px solid #1a1f28; vertical-align: top; overflow-wrap: anywhere; }
.tags tr.seq td { color: #b7c7e0; }
.tags tr.seq[data-path] { cursor: pointer; }
.tags tr.seq[data-path]:hover td { background: #1f252e; }
.tags td.muted { color: var(--muted); font-style: italic; }
.tags td.indent-1 { padding-left: 16px; } .tags td.indent-2 { padding-left: 26px; } .tags td.indent-3 { padding-left: 36px; }

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row select, #dose-tools select { flex: 1; min-width: 0; background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 3px 6px; color: var(--text); font-size: 12px; }
.check { display: inline-flex; gap: 4px; align-items: center; color: var(--muted); }
.rois { list-style: none; margin: 0; padding: 0; }
.rois li { display: flex; align-items: center; gap: 8px; padding: 3px 4px; border-radius: 4px; cursor: pointer; font-size: 12px; }
.rois li:hover { background: #1f252e; }
.rois li .sw { width: 12px; height: 12px; border-radius: 3px; border: 1px solid rgba(255,255,255,.25); flex: none; }
.rois li .n { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rois li .c { color: var(--muted); font-size: 11px; }
.rois li.off { opacity: .45; }
.slider { display: grid; grid-template-columns: 70px 1fr 48px; gap: 8px; align-items: center; color: var(--muted); font-size: 12px; }
.slider input[type="number"] { width: 100%; background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 3px 6px; color: var(--text); }
#dose-tools { display: flex; flex-direction: column; gap: 8px; }
#dose-legend { width: 100%; height: 14px; border-radius: 3px; }
.legend-labels { display: flex; justify-content: space-between; font-family: var(--mono); font-size: 10.5px; color: var(--muted); }

.rois li .v { color: var(--muted); font-size: 11px; font-family: var(--mono); }
.rois li .go { border: 0; background: none; color: var(--accent-2); cursor: pointer; padding: 0 4px; font-size: 13px; opacity: .6; }
.rois li .go:hover { opacity: 1; }
.rois li.hover { background: #1f252e; }
.slider input[type="text"] { width: 100%; background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 3px 6px; color: var(--text); font-family: var(--mono); font-size: 11.5px; }
#dvh-chart { width: 100%; border: 1px solid var(--line); border-radius: 6px; flex: none; }
#dvh-wrap, #measures-wrap { flex: 1; }
.dvh td .del { border: 0; background: none; color: var(--danger); cursor: pointer; padding: 0 4px; }
.dvh tr.link { cursor: pointer; }
.dvh tr.link:hover td { background: #1f252e; }
.dvh { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: 11px; }
.dvh th { text-align: right; color: var(--muted); font-weight: 500; padding: 3px 4px; border-bottom: 1px solid var(--line); }
.dvh th:nth-child(2) { text-align: left; }
.dvh td { padding: 3px 4px; text-align: right; border-bottom: 1px solid #1a1f28; white-space: nowrap; }
.dvh td:nth-child(2) { text-align: left; overflow: hidden; text-overflow: ellipsis; max-width: 120px; }
.dvh .sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; }

dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 16px 20px; }
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog h3 { margin: 0 0 10px; }
.keys td { padding: 3px 12px 3px 0; font-size: 12.5px; }
.keys td:first-child { font-family: var(--mono); color: var(--accent-2); }
