:root {
  --bg: #0f1115;
  --panel: #181b22;
  --panel-2: #1f232c;
  --border: #2a2f3a;
  --text: #e5e7eb;
  --muted: #8b93a7;
  --accent: #6ea8fe;
  --accent-strong: #4f8cff;
  --danger: #f87171;
  --ok: #34d399;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.topbar .brand strong { font-size: 16px; }
.topbar .tag { color: var(--muted); margin-left: 8px; font-size: 12px; }
.topbar nav a { color: var(--muted); margin-left: 14px; text-decoration: none; }
.topbar nav a:hover { color: var(--text); }

.banner {
  background: #2a2410;
  color: #fde68a;
  padding: 8px 18px;
  font-size: 13px;
  border-bottom: 1px solid #443a14;
}
.banner a { color: #fbbf24; }

.layout {
  display: grid;
  grid-template-columns: 280px 1fr 320px;
  grid-template-rows: minmax(0, 1.1fr) minmax(0, 1fr);
  grid-template-areas:
    "files plot analysis"
    "files results results";
  gap: 10px;
  padding: 10px;
  height: calc(100vh - 50px);
  min-height: 720px;
}
body[data-profile="public"] .layout { height: calc(100vh - 80px); }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  overflow: auto;
}
.panel h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 0 0 10px;
}

#file-panel { grid-area: files; }
#analysis-panel { grid-area: analysis; }
.plot-panel { grid-area: plot; }
.results-panel { grid-area: results; }

.quota {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 8px;
}

.uploader { display: flex; gap: 6px; margin-bottom: 10px; flex-wrap: wrap; }
.upload-btn {
  background: var(--accent-strong);
  color: white;
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
  display: inline-block;
  font-size: 13px;
}
.upload-btn input { display: none; }
button {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 13px;
  cursor: pointer;
}
button:hover:not(:disabled) { background: #262b36; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.file-list { list-style: none; padding: 0; margin: 0; }
.file-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
}
.file-list li:hover { background: var(--panel-2); }
.file-list li.active { background: var(--accent-strong); color: white; }
.file-list .size { color: var(--muted); font-size: 11px; margin-left: 8px; }
.file-list .del {
  background: transparent; border: none; color: var(--muted);
  cursor: pointer; padding: 0 4px;
}
.file-list .del:hover { color: var(--danger); }

select, input[type="text"], input[type="number"] {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
  padding: 4px 6px;
  font-size: 13px;
  width: 100%;
}
.param-form { display: grid; grid-template-columns: 1fr; gap: 6px; margin-top: 4px; }
.param-form label { font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 2px; }
.param-form input.changed { border-color: var(--accent); }
.param-group { border: 1px solid var(--border); border-radius: 6px; padding: 4px 8px; }
.param-group[open] { display: grid; gap: 6px; padding-bottom: 8px; }
.param-group summary { cursor: pointer; font-size: 12px; color: var(--text); padding: 2px 0; }
.params-head { display: flex; align-items: center; justify-content: space-between; margin-top: 10px;
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.params-head button.mini { margin-right: 0; text-transform: none; letter-spacing: 0; }
.run-row { display: flex; gap: 6px; margin-top: 12px; }
.run-row button { flex: 1; }
.run-row #run-batch-btn { background: var(--accent-strong); color: white; border-color: var(--accent-strong); }

.job-status {
  margin-top: 12px;
  font-size: 12px;
  color: var(--muted);
  min-height: 18px;
}
.job-status.error { color: var(--danger); }
.job-status.ok { color: var(--ok); }
.progress {
  width: 100%; height: 4px; background: var(--panel-2);
  border-radius: 2px; overflow: hidden; margin-top: 4px;
}
.progress > div { height: 100%; background: var(--accent); width: 0%; transition: width 200ms; }

.plot-controls { display: flex; gap: 12px; margin-bottom: 6px; font-size: 12px; color: var(--muted); }
.plot-panel { display: flex; flex-direction: column; overflow: hidden; }
.plot { width: 100%; flex: 1; min-height: 200px; }
.sweep-picker { font-size: 11px; color: var(--muted); margin-top: 4px; max-height: 48px; overflow: auto; flex: none; }
.sweep-picker label { margin-right: 8px; }

.results-actions { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.results-actions .muted { margin-left: auto; font-size: 12px; }
.results-panel { display: flex; flex-direction: column; }
.results-body { position: relative; flex: 1; min-height: 160px; display: flex; gap: 8px; }
#results-table { flex: 1; min-width: 0; height: 100%; min-height: 160px; }

.sheet-tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 6px; }
.sheet-tabs .tab { padding: 3px 9px; font-size: 12px; border-radius: 4px 4px 0 0; }
.sheet-tabs .tab.active { background: var(--accent-strong); border-color: var(--accent-strong); color: white; }
.sheet-tabs .tab .count { opacity: 0.7; font-size: 11px; margin-left: 3px; }

.job-warnings { font-size: 12px; color: #fbbf24; margin-bottom: 6px; }
.job-warnings ul { margin: 4px 0; padding-left: 18px; max-height: 90px; overflow: auto; color: var(--muted); }

.feature-picker {
  width: 300px; flex: none; background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 6px; padding: 8px; overflow: auto; font-size: 12px;
}
.feature-picker .picker-head { display: flex; gap: 4px; }
.feature-picker .picker-head input { flex: 1; min-width: 0; }
.feature-picker .picker-head button { padding: 3px 7px; font-size: 12px; }
.feature-picker .picker-note { margin: 6px 0; font-size: 11px; }
.feature-picker details { margin: 2px 0; }
.feature-picker summary { cursor: pointer; padding: 2px 0; }
.feature-picker label { display: block; padding: 1px 0 1px 18px; color: var(--text); word-break: break-all; }

.dim { color: var(--muted); font-size: 0.9em; }
.error { color: var(--danger); }
.plot-msg { padding: 20px; }
.file-list .fname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-list li.empty { cursor: default; }
.file-list li.empty:hover { background: transparent; }
.file-list > li { flex-direction: column; align-items: stretch; padding: 0; }
.file-list .file-row { display: flex; align-items: center; justify-content: space-between; padding: 6px 8px; border-radius: 4px; }
.file-list > li.open > .file-row { color: var(--accent); }
.file-list .proto-label { display: block; padding: 0 8px 5px; font-size: 11px; color: var(--muted); }
.file-list > li.active .proto-label { color: #dbe6ff; }
.protocol-list { list-style: none; margin: 0 0 4px; padding: 0 0 0 14px; }
.protocol-list li { padding: 3px 8px; border-left: 2px solid var(--border); font-size: 12px; color: var(--muted); cursor: pointer; }
.protocol-list li:hover { color: var(--text); background: var(--panel-2); }
.protocol-list li.active { color: white; background: var(--accent-strong); border-left-color: var(--accent); border-radius: 0 4px 4px 0; }
.protocol-row { margin-top: 10px; }
.protocol-row label { font-size: 12px; color: var(--muted); }
.trace-title { text-transform: none; letter-spacing: 0; color: var(--text); font-weight: normal; margin-left: 4px; }
button.mini { padding: 1px 6px; font-size: 11px; margin-right: 8px; }
#preset-doc { font-size: 12px; }
#custom-block { margin-top: 8px; }

/* Tabulator dark theme overrides (Tabulator's default theme is light,
   including the frozen-column and header backgrounds). */
.tabulator { background: var(--panel); border-color: var(--border); font-size: 12px; }
.tabulator .tabulator-header,
.tabulator .tabulator-header .tabulator-col,
.tabulator .tabulator-header .tabulator-col.tabulator-frozen {
  background: var(--panel-2) !important; color: var(--text) !important; border-color: var(--border) !important;
}
.tabulator .tabulator-header .tabulator-col .tabulator-col-content .tabulator-col-title { color: var(--text); }
.tabulator .tabulator-tableholder { background: var(--panel); }
.tabulator-row, .tabulator-row .tabulator-cell.tabulator-frozen {
  background: var(--panel) !important; color: var(--text); border-color: var(--border);
}
.tabulator-row.tabulator-row-even,
.tabulator-row.tabulator-row-even .tabulator-cell.tabulator-frozen { background: #1b1f27 !important; }
.tabulator-row .tabulator-cell { border-color: var(--border) !important; }
.tabulator-row .tabulator-cell.tabulator-frozen { font-weight: 600; }
.tabulator-row:hover, .tabulator-row:hover .tabulator-cell.tabulator-frozen { background: #232836 !important; }
.tabulator .tabulator-placeholder span { color: var(--muted) !important; }

.muted { color: var(--muted); }

.prose { max-width: 720px; margin: 30px auto; padding: 0 18px; }
.prose h1, .prose h2 { color: var(--text); }
.prose code { background: var(--panel-2); padding: 1px 4px; border-radius: 3px; font-size: 0.9em; }
.prose pre { background: var(--panel-2); padding: 12px; border-radius: 6px; overflow-x: auto; }
.prose pre code { background: transparent; padding: 0; }
.prose a { color: var(--accent); }

/* DANDI import */
.dandi-form { margin: 0 0 4px; }
.dandi-form label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.dandi-form label a { color: var(--accent); }
.dandi-row { display: flex; gap: 6px; }
.dandi-row input { flex: 1; min-width: 0; }
.dandi-status { font-size: 12px; min-height: 16px; margin-bottom: 6px; word-break: break-word; }
.dandi-status.error { color: var(--danger); }
.dandi-status.ok { color: var(--ok); }
.dandi-browser {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px;
  padding: 8px; margin-bottom: 10px; font-size: 12px;
}
.dandi-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 6px; }
.dandi-head a { color: var(--accent); text-decoration: none; font-weight: 600; word-break: break-word; }
.dandi-head a:hover { text-decoration: underline; }
.dandi-head button.mini { margin-right: 0; flex: none; }
.dandi-meta { margin: 3px 0 6px; font-size: 11px; }
.link-btn { background: none; border: none; padding: 0; color: var(--accent); font-size: 11px; cursor: pointer; }
.link-btn:hover:not(:disabled) { background: none; text-decoration: underline; }
.dandi-browser input[type="search"], .dandi-row input[type="text"] {
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  border-radius: 4px; padding: 4px 6px; font-size: 12px; width: 100%;
}
.dandi-assets { list-style: none; margin: 6px 0; padding: 0; max-height: 260px; overflow: auto; }
.dandi-assets li { display: flex; align-items: center; gap: 6px; padding: 3px 2px; border-bottom: 1px solid var(--border); }
.dandi-assets li:last-child { border-bottom: none; }
.dandi-assets .dname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dandi-assets .size { color: var(--muted); font-size: 11px; flex: none; }
.dandi-assets button.mini { margin-right: 0; flex: none; }
.dandi-assets li.too-large .dname { color: var(--muted); }
.dandi-pager { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.dandi-pager button.mini { margin-right: 0; }
.file-list .src-badge {
  display: inline-block; margin: 0 8px 4px; padding: 0 5px; font-size: 10px;
  color: var(--accent); border: 1px solid var(--accent); border-radius: 3px;
  text-decoration: none; align-self: flex-start;
}
.file-list .src-badge:hover { background: var(--accent-strong); color: white; }
.file-list > li.active .src-badge { color: white; border-color: white; }
