:root {
  --bg: #0b0e14;
  --panel: #141922;
  --panel-2: #1a2130;
  --text: #e4e8ef;
  --muted: #8892a6;
  --primary: #3b82f6;
  --danger: #ef4444;
  --ok: #22c55e;
  --warn: #f59e0b;
  --border: #283042;
  --sidebar-w: 260px;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); height: 100vh; overflow: hidden; }

/* header */
header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 20px; border-bottom: 1px solid var(--border);
  background: var(--panel); height: 48px;
}
header h1 { margin: 0; font-size: 16px; font-weight: 600; }
.status { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); cursor: help; }
.status-detail { font-variant-numeric: tabular-nums; font-family: ui-monospace, monospace; font-size: 12px; opacity: 0.8; }
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status.live    .dot { background: var(--ok);     box-shadow: 0 0 8px var(--ok); }
.status.stale   .dot { background: var(--warn); }
.status.offline .dot { background: var(--danger); }

/* layout */
.layout {
  display: flex;
  height: calc(100vh - 48px);
}
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 12px 0;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
#sessions-list {
  display: flex;
  flex-direction: column;
}
.main {
  flex: 1;
  min-width: 0;
  padding: 12px 16px;
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 12px;
}

/* sidebar items */
.sidebar-header {
  padding: 14px 16px 6px;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
}
.sidebar-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  padding: 10px 16px;
  background: transparent;
  border: 0;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  border-left: 3px solid transparent;
  transition: background 0.1s, border-color 0.1s;
  font-family: inherit;
  font-size: inherit;
  box-sizing: border-box;
}
.sidebar-item:hover { background: rgba(255,255,255,0.03); }
.sidebar-item.active { background: rgba(59,130,246,0.1); border-left-color: var(--primary); }
.sidebar-item.live-item.active { border-left-color: var(--ok); background: rgba(34,197,94,0.08); }
.sidebar-item .item-body { flex: 1; min-width: 0; }
.sidebar-item .item-name {
  font-size: 13px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-item .item-sub {
  font-size: 11px; color: var(--muted); margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}
.sidebar-item.recording .item-name::after {
  content: "● REC"; color: var(--danger); font-size: 10px; margin-left: 8px;
  animation: pulse 1.5s infinite;
}
.live-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--ok); box-shadow: 0 0 6px var(--ok);
  flex-shrink: 0;
}
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }

/* panels */
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
}
.panel h2 { margin: 0; font-size: 13px; font-weight: 500; color: var(--muted); }

/* control panel */
#control-panel .idle-row, #control-panel .active-row {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
#control-panel input {
  flex: 1; min-width: 160px;
  padding: 8px 10px;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px; font-size: 13px;
  font-family: inherit;
}
#control-panel button {
  padding: 8px 16px; border: 0; border-radius: 6px; cursor: pointer;
  font-size: 13px; font-weight: 600;
}
.primary { background: var(--primary); color: white; }
.danger  { background: var(--danger);  color: white; }
.primary:hover, .danger:hover { filter: brightness(1.1); }
.rec-dot {
  width: 10px; height: 10px; border-radius: 50%; background: var(--danger);
  animation: pulse 1.5s infinite;
}
.sep { color: var(--muted); }

/* context banner */
.context-banner {
  display: flex; flex-direction: column; gap: 10px;
  background: rgba(59,130,246,0.08);
  border-color: rgba(59,130,246,0.3);
}
.context-banner .view-head { display: flex; align-items: center; gap: 14px; }
.context-banner .view-actions { margin-left: auto; display: flex; gap: 6px; }
.context-banner .muted { color: var(--muted); font-size: 12px; margin-left: 6px; }

/* playback controls */
.playback-row {
  display: flex; align-items: center; gap: 10px;
}
.pb-btn {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--primary); color: white; border: 0; cursor: pointer;
  font-size: 14px; font-family: inherit;
  display: flex; align-items: center; justify-content: center;
  transition: filter 0.1s;
}
.pb-btn:hover { filter: brightness(1.1); }
.pb-time {
  font-variant-numeric: tabular-nums; font-size: 12px; min-width: 45px;
  font-family: ui-monospace, monospace;
}
.pb-time.muted { color: var(--muted); }
.pb-slider {
  flex: 1; height: 4px; cursor: pointer;
  -webkit-appearance: none; appearance: none;
  background: var(--border); border-radius: 2px; outline: none;
}
.pb-slider::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--primary); cursor: pointer;
}
.pb-slider::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--primary); cursor: pointer; border: 0;
}
.pb-speed {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 4px; padding: 3px 6px; font-size: 12px; cursor: pointer;
  font-family: inherit;
}
.csv-btn, .back-btn, .delete-btn, .rename-btn, .btn-secondary {
  background: transparent; border-radius: 4px; padding: 4px 12px; cursor: pointer; font-size: 12px;
  font-weight: 500; font-family: inherit;
}
.csv-btn, .back-btn { color: var(--primary); border: 1px solid var(--primary); }
.csv-btn:hover, .back-btn:hover { background: var(--primary); color: white; }
.rename-btn { color: var(--text); border: 1px solid var(--border); }
.rename-btn:hover { background: var(--border); }
.delete-btn { color: var(--danger); border: 1px solid var(--danger); }
.delete-btn:hover { background: var(--danger); color: white; }
.btn-secondary { color: var(--muted); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); color: var(--text); }

/* rename dialog input */
.dialog input[type="text"] {
  width: 100%; margin-top: 4px; margin-bottom: 4px;
  padding: 8px 10px; font-size: 14px; font-family: inherit;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px; outline: none;
}
.dialog input[type="text"]:focus { border-color: var(--primary); }

/* delete "x" in sidebar */
.item-delete {
  background: transparent; border: 0; color: var(--muted);
  padding: 2px 6px; border-radius: 4px; cursor: pointer;
  font-size: 14px; line-height: 1; opacity: 0;
  transition: opacity 0.1s, background 0.1s, color 0.1s;
  font-family: inherit;
}
.sidebar-item:hover .item-delete { opacity: 1; }
.item-delete:hover { background: var(--danger); color: white; }

/* modal overlay */
.overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; backdrop-filter: blur(3px);
}
.overlay[hidden] { display: none; }
.dialog {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px 24px;
  min-width: 320px; max-width: 420px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}
.dialog h3 { margin: 0 0 10px; font-size: 16px; }
.dialog p { margin: 0 0 8px; font-size: 13px; color: var(--text); }
.dialog p.muted { color: var(--muted); font-size: 12px; }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.dialog-actions button { padding: 7px 14px; border-radius: 6px; font-size: 13px; border: 0; cursor: pointer; font-weight: 600; }

/* chart controls panel (shared at top) */
#chart-controls-panel { flex: 0 0 auto; }
.chart-head {
  display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 10px;
}

/* level charts grid */
#level-charts {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  flex: 1 1 auto;
  min-height: 0;
}
.level-chart {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  display: flex; flex-direction: column;
  min-height: 220px;
}
.level-chart .level-head {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 6px;
  font-size: 13px; font-weight: 600;
}
.level-chart .level-badge {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--badge-color);
}
.level-chart .level-sub {
  color: var(--muted); font-size: 11px; font-weight: 400;
}
.level-chart .level-warn-badge {
  margin-left: auto;
  display: inline-flex; align-items: center; justify-content: center;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: rgba(255, 184, 0, 0.15);
  border: 1px solid rgba(255, 184, 0, 0.5);
  color: #ffb800;
  font-size: 12px; line-height: 1;
  cursor: help;
}
.level-chart canvas { flex: 1; min-height: 0; }

/* single-column on narrow screens */
@media (max-width: 900px) {
  #level-charts { grid-template-columns: 1fr; }
}

/* chart panel (legacy: hidden now) */
.chart-panel { display: flex; flex-direction: column; }
.chart-controls { font-size: 12px; color: var(--muted); display: inline-flex; align-items: center; gap: 10px; }
.chart-controls select {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 4px; padding: 3px 8px; font-size: 12px;
}
.refresh-btn {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 4px; padding: 3px 10px; font-size: 12px; cursor: pointer;
  font-family: inherit; transition: background 0.1s, border-color 0.1s;
}
.refresh-btn:hover { background: var(--primary); border-color: var(--primary); color: white; }
.refresh-btn:active { transform: scale(0.97); }

/* group filter chips */
.group-filters {
  display: flex; gap: 8px; margin: 4px 0 6px; flex-wrap: wrap;
}
.group-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 14px; cursor: pointer;
  font-size: 12px; font-weight: 500;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--muted);
  font-family: inherit;
  transition: all 0.1s;
}
.group-chip .swatch {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--chip-color, var(--muted));
}
.group-chip.active {
  color: var(--text);
  background: rgba(255,255,255,0.05);
  border-color: var(--chip-color, var(--primary));
}
.group-chip.inactive { opacity: 0.45; }
.group-chip:hover { filter: brightness(1.15); }
.group-chip.all-btn { font-weight: 600; }

/* baseline row */
.baseline-row {
  display: flex; align-items: center; gap: 10px;
  margin-top: 8px; font-size: 12px;
  flex-wrap: wrap;
}
.baseline-label { color: var(--muted); font-weight: 500; }
.baseline-status { font-family: ui-monospace, monospace; font-variant-numeric: tabular-nums; color: var(--text); cursor: help; }
.baseline-status.muted { color: var(--muted); }
.pill-btn {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 4px; padding: 3px 10px; font-size: 12px; cursor: pointer;
  font-family: inherit;
}
.pill-btn:hover { background: var(--primary); border-color: var(--primary); color: white; }
.baseline-toggle { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; color: var(--muted); }
.baseline-toggle input { margin: 0; cursor: pointer; }
#chart { flex: 1; max-height: calc(100vh - 250px); }

/* responsive */
@media (max-width: 720px) {
  :root { --sidebar-w: 200px; }
  #control-panel input { min-width: 120px; }
}
