:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e222b;
  --border: #2a2f3a;
  --text: #e6e8ec;
  --dim: #8b93a1;
  --accent: #4f8cff;
  --accent-dim: #2b3650;
  --good: #43c181;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 13px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.dim { color: var(--dim); }
kbd {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 5px;
  font-size: 11px;
  color: var(--dim);
}

/* Topbar */
#topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 600; font-size: 15px; }
.meta { display: flex; gap: 8px; flex: 1; }
.pill {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12px;
  color: var(--dim);
}
.pill:empty { display: none; }
.actions { display: flex; align-items: center; gap: 12px; }
.save-status { font-size: 12px; color: var(--good); }
.save-status.saving { color: var(--dim); }
.save-status.error { color: #ff6b6b; }

button {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 7px 12px;
  font-size: 13px;
  cursor: pointer;
}
button:hover { filter: brightness(1.1); }

/* Tabs */
#tabs { display: flex; gap: 4px; }
.tab-btn {
  background: transparent; color: var(--dim); border: 1px solid transparent;
  border-radius: 6px; padding: 6px 14px; white-space: nowrap;
}
.tab-btn:hover { color: var(--text); background: var(--panel-2); }
.tab-btn.active { color: var(--text); background: var(--accent-dim); border-color: var(--accent); }

/* Narrow screens: reflow the single-row top bar into stacked rows so nothing
   is clipped (brand + actions, a scrollable tab strip, then status pills). */
@media (max-width: 720px) {
  #topbar { flex-wrap: wrap; gap: 8px 10px; padding: 8px 10px; }
  .brand { font-size: 14px; }
  .actions { margin-left: auto; gap: 8px; }
  #tabs { order: 10; flex-basis: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .meta { order: 11; flex-basis: 100%; }
  .tab-btn { padding: 6px 10px; }
}

/* Panels */
.panel-view { display: none; flex: 1; min-height: 0; }
.panel-view.active { display: block; overflow-y: auto; }
#panel-annotate.active { display: flex; overflow: hidden; }

.cols { display: flex; flex-wrap: wrap; gap: 16px; padding: 20px; align-items: flex-start; }
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 18px; width: 360px; max-width: 100%;
}
.card.wide { width: 540px; }
/* Instructions/guide page: stack every card vertically in one readable column */
#panel-guide .cols { flex-direction: column; align-items: stretch; gap: 16px; }
#panel-guide .card, #panel-guide .card.wide { width: 100%; max-width: 820px; }
.card h2 { margin: 0 0 4px; font-size: 15px; }
details.opts { margin-top: 10px; }
details.opts summary { cursor: pointer; color: var(--dim); font-size: 12px; padding: 4px 0; }
details.help { margin: 4px 0 2px; }
details.help summary { cursor: pointer; color: var(--accent); font-size: 12px; padding: 4px 0; }
details.help .help-body { color: var(--dim); font-size: 12px; line-height: 1.5; border-left: 2px solid var(--border); padding: 2px 0 2px 10px; margin-top: 4px; }
details.help .help-body p { margin: 6px 0; }
details.help .help-body ol { margin: 6px 0; padding-left: 18px; }
details.help .help-body ul { margin: 4px 0; padding-left: 18px; }
details.help .help-body li { margin: 5px 0; }
details.help .help-body b { color: var(--text); }
details.help .help-body code { background: var(--panel-2); border: 1px solid var(--border); border-radius: 4px; padding: 0 4px; font-size: 11px; }
details.help .help-body a { color: var(--accent); }
details.help .help-body .refs { font-size: 11px; border-top: 1px solid var(--border); padding-top: 6px; margin-top: 8px; }
.card label { display: block; margin: 10px 0 4px; font-size: 12px; color: var(--dim); }
.card input[type=text], .card input[type=number], .card select, .card textarea {
  width: 100%; background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 6px; color: var(--text); padding: 7px 9px; font: inherit;
}
.card .form-row { display: flex; gap: 8px; }
.card .form-row label { flex: 1; }
.card button { margin-top: 14px; }
/* Class constructor (new-project schema authoring) */
.constructor { margin: 12px 0; border: 1px solid var(--border); border-radius: 8px; padding: 10px; }
.cc-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.cc-head span { font-size: 12px; color: var(--dim); text-transform: uppercase; letter-spacing: .04em; }
.cc-list { list-style: none; margin: 0; padding: 0; }
.cc-row {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  margin-bottom: 6px; padding-bottom: 8px; border-bottom: 1px solid var(--border);
}
.cc-row:last-child { border-bottom: none; }
.cc-row input[type=color] {
  width: 30px; height: 30px; padding: 0; border: 1px solid var(--border);
  border-radius: 6px; background: var(--panel-2); cursor: pointer; flex: none;
}
.cc-row .cc-name { flex: 1 1 100%; order: -1; }
.cc-row .cc-kind { width: 130px; flex: none; }
.cc-row .cc-single { display: flex; align-items: center; gap: 3px; font-size: 11px; color: var(--dim); white-space: nowrap; flex: none; }
.cc-row .cc-single input { margin: 0; }
.cc-hint { margin: 6px 0 0; font-size: 11px; }

.radio-row { display: flex; gap: 16px; margin: 12px 0 6px; }
.radio-row label { display: inline; color: var(--text); margin: 0; }
.hidden { display: none; }

/* Network architecture diagram (its own tab) */
/* `.card.arch-card` (specificity 0,2,0, declared after `.card.wide`) overrides
   the 540px `.card.wide` width so the diagram spans the full panel width. */
.card.arch-card { width: auto; margin: 20px; display: flex; flex-direction: column; }
.arch-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.arch-head h2 { margin: 0; }
.arch-tools { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.arch-tools .arch-scale { display: inline-flex; align-items: center; gap: 5px; margin: 0; font-size: 12px; color: var(--dim); }
.arch-tools select { width: auto; padding: 3px 6px; }
.arch-tools button { margin-top: 0; }
.arch-zoom { display: inline-flex; gap: 4px; }
.arch-zoom button { min-width: 30px; }
.arch-hint { margin: 8px 0; }
.arch-canvas {
  width: 100%; height: min(58vh, 56vw); min-height: 320px;
  overflow: hidden; background: #ffffff; border: 1px solid var(--border);
  border-radius: 8px; cursor: grab; touch-action: none;
}
.arch-canvas.grabbing, #arch-svg.grabbing { cursor: grabbing; }
#arch-svg { display: block; width: 100%; height: 100%; }
.msg { margin-top: 10px; font-size: 12px; color: #ff8a8a; min-height: 16px; }

.project-list { list-style: none; margin: 0; padding: 0; }
.project-list li {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 9px 0; border-bottom: 1px solid var(--border);
}
.project-list li button { margin: 0; padding: 5px 12px; }

.progress-wrap { margin-top: 14px; }
.progress-wrap .bar { height: 8px; background: var(--panel-2); border-radius: 999px; overflow: hidden; }
.progress-wrap .fill { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.progress-wrap span { display: block; margin-top: 6px; }

/* Activity leaderboard */
.leaderboard { list-style: none; margin: 10px 0 0; padding: 0; }
.leaderboard li {
  display: grid; grid-template-columns: 2.5rem 1fr auto; gap: 10px; align-items: center;
  padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13px;
}
.leaderboard li .rk { color: var(--dim); font-variant-numeric: tabular-nums; text-align: right; }
.leaderboard li .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.leaderboard li .tm { color: var(--dim); font-variant-numeric: tabular-nums; }
.leaderboard li.me { color: var(--text); }
.leaderboard li.me .nm { font-weight: 600; }
.leaderboard li.me .tm { color: var(--accent); }
.activity-project-card { width: 320px; }
.activity-project-card h2 { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.activity-project-card h2 .sub { font-size: 12px; font-weight: 400; color: var(--dim); }

/* upload subsection (Data tab) */
.tiny { font-size: 11px; }
button.link { background: none; border: none; color: var(--accent); cursor: pointer; padding: 0; margin: 0; font: inherit; text-decoration: underline; }
.drop-zone { border: 1.5px dashed var(--border); border-radius: 8px; padding: 16px; text-align: center; transition: border-color .15s, background .15s; }
.drop-zone.dragover { border-color: var(--accent); background: var(--panel-2); }
.drop-zone .drop-hint { margin: 0 0 6px; font-size: 13px; }
.drop-zone code { background: var(--panel-2); border: 1px solid var(--border); border-radius: 4px; padding: 0 4px; font-size: 11px; }
.upload-list { list-style: none; margin: 10px 0 0; padding: 0; text-align: left; max-height: 160px; overflow: auto; }
.upload-list li { display: flex; align-items: center; gap: 8px; padding: 3px 0; font-size: 12px; border-top: 1px solid var(--border); }
.upload-list li .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-list li .sz { color: var(--dim); font-variant-numeric: tabular-nums; }
.upload-list li .rm { color: var(--dim); cursor: pointer; border: none; background: none; padding: 0 4px; font: inherit; }
.upload-list li .rm:hover { color: var(--text); }

/* Uploaded-data record (Data tab) */
.section-sep { border: none; border-top: 1px solid var(--border); margin: 20px 0; }
.uploads-record-title { margin: 4px 0 2px; font-size: 14px; }
.uploads-record li .ic { width: 16px; text-align: center; color: var(--dim); flex: none; }
.status-pill { flex: none; font-size: 10px; padding: 1px 8px; border-radius: 999px; text-transform: uppercase; letter-spacing: .04em; }
.status-pill.pending { color: var(--dim); background: var(--panel-2); border: 1px solid var(--border); }
.status-pill.extracted, .status-pill.done { color: #0b1a10; background: #6bd48a; }
.status-pill.approved { color: #0b1226; background: #7cb8ff; }
.status-pill.running { color: #1a1204; background: #f0c060; }
.status-pill.failed, .status-pill.interrupted { color: #2a0d0d; background: #e88; }
.status-pill.rejected, .status-pill.canceled { color: var(--dim); background: var(--panel-2); border: 1px solid var(--border); }

/* Train tab */
.train-runs li { flex-wrap: wrap; }
.train-runs li .nm { flex: 1 1 100%; }
.train-log {
  margin-top: 10px; max-height: 260px; overflow: auto; white-space: pre-wrap;
  word-break: break-word; background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 6px; padding: 8px 10px; font-size: 11px; line-height: 1.45;
}

.empty-hint {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--dim); pointer-events: none;
}
button.ghost {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
}
button.ghost:hover { filter: none; background: #232834; }
button.tiny { padding: 4px 8px; margin: 0; }

/* Keybinding editor */
.keybind-list { list-style: none; margin: 0; padding: 0; }
.keybind-list li {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 4px; border-bottom: 1px solid #20242d;
}
.keybind-list li .grow { flex: 1; }
.keybind-list .swatch { width: 12px; height: 12px; border-radius: 3px; flex: none; }
.key-btn {
  min-width: 64px; text-align: center; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px; padding: 5px 10px; font: inherit; margin: 0;
}
.key-btn:hover { filter: none; background: #232834; }
.key-btn.unset { color: var(--dim); font-style: italic; }
.key-btn.capturing { border-color: var(--accent); background: var(--accent-dim); color: var(--text); }

/* Modal (login) */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.55);
  display: flex; align-items: center; justify-content: center; z-index: 60;
}
.modal.hidden { display: none; }
.modal-box {
  width: 640px; max-width: 92vw; max-height: 80vh; display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px; overflow: hidden;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
}
.modal-head span { font-weight: 600; }

/* Login */
.login-box { width: 360px; }
.login-body { padding: 18px; }
.login-body label { display: block; margin: 0 0 4px; font-size: 12px; color: var(--dim); }
.login-body input {
  width: 100%; background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 6px; color: var(--text); padding: 8px 10px; font: inherit; margin-bottom: 12px;
}
.login-actions { display: flex; gap: 10px; margin-top: 4px; }
.login-actions button { flex: 1; }

#toast {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  padding: 9px 16px; border-radius: 8px; opacity: 0; transition: opacity .2s; z-index: 50;
}
#toast.show { opacity: 1; }
#toast.err { border-color: #ff6b6b; }

/* Layout (annotate tab) */
#layout {
  --sidebar-w: 240px;
  --tools-w: 260px;
  flex: 1;
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr var(--tools-w);
  min-height: 0;
}
#layout.sidebar-collapsed { --sidebar-w: 0px; }
#layout.tools-collapsed { --tools-w: 0px; }
#layout.sidebar-collapsed #sidebar { display: none; }
#layout.tools-collapsed #tools { display: none; }

/* Sidebar */
#sidebar, #tools {
  position: relative;
  background: var(--panel);
  overflow-y: auto;
  border-right: 1px solid var(--border);
}
#tools { border-right: none; border-left: 1px solid var(--border); padding-bottom: 24px; }

/* Column resize handles (sit on the inner edges of the stage) */
.col-resizer {
  position: absolute; top: 0; bottom: 0; width: 7px; z-index: 6;
  cursor: col-resize; user-select: none; touch-action: none;
}
.col-resizer-left { left: 0; }
.col-resizer-right { right: 0; }
.col-resizer:hover, .col-resizer.dragging { background: var(--accent-dim); }
#layout.sidebar-collapsed #resize-sidebar { display: none; }
#layout.tools-collapsed #resize-tools { display: none; }

/* Stage-edge buttons that collapse / expand the side panels */
.col-toggle {
  position: absolute; top: 50%; transform: translateY(-50%); z-index: 7;
  width: 16px; height: 46px; padding: 0; display: flex; align-items: center;
  justify-content: center; font-size: 10px; line-height: 1;
  color: var(--dim); background: rgba(15,17,21,0.82);
  border: 1px solid var(--border); cursor: pointer; margin: 0;
}
.col-toggle:hover { color: var(--text); background: var(--accent-dim); }
.col-toggle-left { left: 0; border-left: none; border-radius: 0 8px 8px 0; }
.col-toggle-right { right: 0; border-right: none; border-radius: 8px 0 0 8px; }
.sidebar-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  position: sticky;
  top: 0;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
#filter {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 4px 8px;
  width: 100%;
}
.task-select {
  flex: 1;
  min-width: 0;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 5px 8px;
  font: inherit;
}
#image-list { list-style: none; margin: 0; padding: 0; }
#image-list li {
  padding: 7px 12px;
  cursor: pointer;
  border-bottom: 1px solid #20242d;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  white-space: nowrap;
}
#image-list li .nm { overflow: hidden; text-overflow: ellipsis; }
#image-list li:hover { background: var(--panel-2); }
#image-list li.active { background: var(--accent-dim); }
#image-list li .dot { color: var(--dim); }
#image-list li.annot .dot { color: var(--good); }

/* Stage */
#stage { position: relative; min-width: 0; background: #0b0d11; }
#canvas-wrap { position: absolute; inset: 0; }
#canvas { width: 100%; height: 100%; display: block; cursor: crosshair; }

/* Floating image-navigation bar (top of the stage) */
#stagebar {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
  z-index: 5; display: flex; align-items: center; gap: 6px;
  background: rgba(15,17,21,0.82); border: 1px solid var(--border);
  border-radius: 8px; padding: 5px 8px;
}
#stagebar .navbtn {
  margin: 0; background: var(--panel-2); border: 1px solid var(--border);
  color: var(--text); border-radius: 6px; padding: 4px 9px; font: inherit;
  font-size: 12px; line-height: 1.2; cursor: pointer;
}
#stagebar .navbtn:hover:not(:disabled) { background: var(--accent-dim); }
#stagebar .navbtn:disabled { opacity: .4; cursor: default; }
#stagebar .navpos { min-width: 70px; text-align: center; font-variant-numeric: tabular-nums; }
#stagebar .navspacer { width: 1px; align-self: stretch; background: var(--border); margin: 0 3px; }
#hud {
  position: absolute;
  left: 10px;
  bottom: 10px;
  display: flex;
  gap: 14px;
  background: rgba(15,17,21,0.7);
  padding: 5px 10px;
  border-radius: 6px;
  pointer-events: none;
  font-size: 12px;
}

/* Tools */
.panel { padding: 12px; border-bottom: 1px solid var(--border); }
.panel h3 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--dim); }
.tool-group { margin-top: 6px; display: flex; flex-direction: column; gap: 4px; }
.tool-group:empty { margin-top: 0; }
.tool {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 7px 9px;
}
.tool:hover { filter: none; background: #232834; }
.tool.active { border-color: var(--accent); background: var(--accent-dim); }
.tool:disabled, .tool.locked { opacity: 0.45; cursor: not-allowed; }
.tool:disabled:hover { background: var(--panel-2); }
.tool .swatch { width: 12px; height: 12px; border-radius: 3px; flex: none; }
.tool .grow { flex: 1; }
.tool kbd { margin-left: auto; }

#shape-list { list-style: none; margin: 0; padding: 0; }
#shape-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 6px;
  border-radius: 5px;
  cursor: pointer;
}
#shape-list li:hover { background: var(--panel-2); }
#shape-list li.sel { background: var(--accent-dim); }
#shape-list .swatch { width: 10px; height: 10px; border-radius: 2px; }
#shape-list .x { margin-left: auto; color: var(--dim); cursor: pointer; }
#shape-list .x:hover { color: #ff6b6b; }

.help .keys { list-style: none; margin: 0 0 8px; padding: 0; }
.help .keys li { padding: 2px 0; color: var(--dim); }
