/* Dunkles Lab-Theme – modernisierte Fassung.
   Farbwelt wie zuvor (keysight_reader/ui/theme.py), aber mit ruhigerer
   Typografie, klareren Fokus-Zuständen, Tabellen mit Tabellenziffern und
   einer gruppierten Tab-Leiste. Die Chart-Serienfarben liegen separat in
   charts.js und sind gegen die dunkle Zeichenfläche validiert. */
:root {
  --bg: #10141b;
  --surface: #1b212b;
  --surface-2: #232b37;
  --surface-3: #2a3342;
  --border: #2c3543;
  --border-soft: #262f3d;
  --text: #dfe5ee;
  --text-dim: #8a93a3;
  --accent: #4da3ff;     /* Primärakzent (Bedienung, aktive Zustände) */
  --accent-2: #ff9d4d;   /* Sekundärakzent */
  --accent-3: #b388ff;
  --green: #3ec98a;
  --red: #ef5a6f;
  --amber: #e0b341;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.28);
  --shadow-modal: 0 12px 40px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI Variable Text", "Segoe UI", "Inter", system-ui, sans-serif;
  font-size: 13px;
  scrollbar-color: var(--surface-3) var(--bg);
}

#app {
  display: flex;
  flex-direction: column;
  gap: 10px;
  height: 100vh;
  padding: 12px 14px 6px;
}

/* ----------------------------------------------------------------- Bars */
.bar {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 10px 16px;
  box-shadow: var(--shadow-card);
}
.header { display: flex; flex-direction: column; gap: 8px; }
.header-row { display: flex; align-items: center; gap: 10px; }
.header-row.sub { color: var(--text-dim); font-size: 12px; }
.header-title { font-size: 16px; font-weight: 700; color: var(--text); letter-spacing: 0.2px; }
.spacer-16 { width: 16px; } .spacer-20 { width: 20px; }
.chk { display: flex; align-items: flex-start; gap: 6px; color: var(--text-dim); white-space: normal; cursor: pointer; line-height: 1.4; }
.chk input { margin-top: 2px; flex: 0 0 auto; }
.flex-grow { flex: 1 1 auto; }

/* Verbindungsstatus in der Kopfzeile: Punkt + Beschreibung je Gerät. */
.conn { display: inline-flex; align-items: center; gap: 6px; }
.conn-dot { color: var(--surface-3); font-size: 11px; transition: color 0.2s; }
.conn-dot.on { color: var(--green); text-shadow: 0 0 7px rgba(62, 201, 138, 0.55); }

/* ----------------------------------------------------------- Inputs/Buttons */
label { color: var(--text-dim); white-space: nowrap; }

input[type="text"], input[type="number"], input[type="search"], input[type="password"] {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 8px;
  color: var(--text);
  font: inherit;
  transition: border-color 0.12s, box-shadow 0.12s;
}
input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(77, 163, 255, 0.22);
}
input.full { width: 100%; }
input::placeholder { color: var(--text-dim); opacity: 0.6; }

.btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 16px;
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn:disabled { color: var(--text-dim); background: var(--surface); cursor: default; }

.btn.start { background: var(--green); color: #06231a; border: none; min-width: 120px; }
.btn.start:hover:not(:disabled) { background: #4ad99a; }
.btn.start:disabled { background: #234034; color: #5d7a6c; }
.btn.stop { background: var(--red); color: #2a0a10; border: none; min-width: 120px; }
.btn.stop:hover:not(:disabled) { background: #ff6e82; }
.btn.stop:disabled { background: #402128; color: #7a5d62; }
.btn.reset { min-width: 120px; }
.btn.reset:hover:not(:disabled) { border-color: var(--amber); }
.btn.capture { background: var(--accent); color: #06121f; border: none; width: 100%; }
.btn.capture:hover:not(:disabled) { background: #6cb6ff; }
.btn.capture:disabled { background: #213243; color: #5d7186; }
.btn.grow { flex: 1 1 auto; }

/* ---------------------------------------------------------------- Content */
.content {
  flex: 1 1 auto;
  display: flex;
  gap: 12px;
  min-height: 0;
}

.sidebar {
  width: 338px;
  flex: 0 0 338px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  padding-right: 4px;
}

/* Darstellung: die Auswahl-Liste trägt Datum + Spule + Pos + Besonderheit und
   braucht daher spürbar mehr Breite als die Eingabe-Seitenleisten. */
#displayView .sidebar { width: 470px; flex: 0 0 470px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 12px 16px 14px;
  box-shadow: var(--shadow-card);
}

.card-title, .section-title {
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.2px;
}
.section-title { margin-bottom: 8px; }

.card-value { font-weight: 700; user-select: text; font-variant-numeric: tabular-nums; }
.card-value.small { font-size: 24px; }
.card-value.big { font-size: 34px; }
.accent { color: var(--accent); }
.green { color: var(--green); }

/* Protokoll-Felder */
.field-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 10px;
  align-items: center;
  margin-bottom: 10px;
}
.field-grid input { width: 100%; }
.button-row { display: flex; gap: 8px; margin-top: 8px; }
.path-label {
  color: var(--text-dim);
  font-size: 11px;
  margin-top: 8px;
  word-break: break-all;
  user-select: text;
}

/* Statistik-Tabelle */
.stat-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 7px 14px;
  align-items: baseline;
}
.stat-label { color: var(--text-dim); }
.stat-value {
  color: var(--text); font-weight: 600; text-align: right; user-select: text;
  font-variant-numeric: tabular-nums;
}
.stat-value.verdict { text-align: left; font-weight: 600; }

/* ------------------------------------------------------------------ Plots */
.plots {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}
.plot-card { display: flex; flex-direction: column; padding: 10px 12px 12px; min-height: 0; }
.plot-card.hist { flex: 3 1 0; }
.plot-bottom { flex: 2 1 0; display: flex; gap: 12px; min-height: 0; }
.plot-bottom .plot-card { flex: 1 1 0; }
.plot-title {
  color: var(--text); font-size: 13px; font-weight: 600;
  text-align: left; padding: 2px 0 6px;
}
.plot-card canvas { flex: 1 1 auto; width: 100%; min-height: 0; display: block; }

/* ---------------------------------------------------------------- Controls */
.controls { display: flex; align-items: center; gap: 10px; }
.progress {
  flex: 0 0 280px;
  height: 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.progress-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, #3e95f0, #6cb6ff);
  border-radius: 7px;
  transition: width 0.12s linear;
}
.progress-count {
  min-width: 120px; text-align: right;
  font-variant-numeric: tabular-nums;
  font-family: Consolas, "Courier New", monospace;
}

/* --------------------------------------------------------------- Statusbar */
.statusbar {
  display: flex; align-items: center; gap: 8px;
  color: var(--text-dim);
  padding: 2px 4px 4px;
  font-size: 12px;
}
.status-dot { color: var(--text-dim); }

.dim { color: var(--text-dim); }

/* ------------------------------------------------------------------ Modals */
.modal {
  position: fixed; inset: 0;
  background: rgba(4, 6, 10, 0.6);
  backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.modal.hidden { display: none; }
.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
  width: 900px; max-width: 92vw;
  max-height: 86vh;
  display: flex; flex-direction: column; gap: 12px;
  box-shadow: var(--shadow-modal);
}
.modal-box.small { width: 560px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; }
.modal-title { font-size: 15px; font-weight: 700; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; }
.alert-text { white-space: pre-wrap; line-height: 1.5; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }

.table-wrap { overflow: auto; border: 1px solid var(--border-soft); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; font-size: 12px; }
th, td {
  padding: 6px 10px; text-align: left;
  border-right: 1px solid var(--border-soft);
  border-bottom: 1px solid var(--border-soft);
  white-space: nowrap;
}
th {
  background: var(--surface-2); color: var(--text-dim);
  font-weight: 600; position: sticky; top: 0; z-index: 1;
}
tbody tr:nth-child(even) { background: rgba(35, 43, 55, 0.55); }
tbody tr:hover td { background: rgba(77, 163, 255, 0.07); }
td.num { text-align: right; font-variant-numeric: tabular-nums; }

/* --------------------------------------------------------------- Ansicht-Tabs
   Gruppierte Leiste: Einzelerfassung | „Messreihe" Assistent/Automatik/Extern/
   Darstellung | ⚙ Einstellungen (rechts). Aktiver Tab als Pille mit Akzent. */
.tabs {
  display: flex; align-items: center; gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 5px 8px;
  box-shadow: var(--shadow-card);
}
.tab {
  background: transparent; border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 6px 14px; color: var(--text-dim); font: inherit; font-weight: 600;
  cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.tab:hover { color: var(--text); background: var(--surface-2); }
.tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.tab.active {
  background: var(--surface-2); color: var(--accent);
  border-color: rgba(77, 163, 255, 0.45);
}
.tab-kicker {
  color: var(--text-dim); font-size: 10px; font-weight: 700;
  letter-spacing: 1.2px; text-transform: uppercase;
  margin: 0 2px 0 6px; user-select: none;
}
.tab-sep { width: 1px; height: 22px; background: var(--border); margin: 0 6px; }

/* Views füllen den restlichen Platz wie zuvor die .content/.controls. */
.view { flex: 1 1 auto; display: flex; flex-direction: column; gap: 12px; min-height: 0; }
.view.hidden { display: none; }

/* Wizard-Hilfselemente */
.sub-title { color: var(--text-dim); font-size: 11px; font-weight: 700; letter-spacing: 1.2px; margin: 10px 0 6px; }
.band-checks { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.band-checks label { display: flex; align-items: center; gap: 7px; color: var(--text); white-space: normal; cursor: pointer; }
.band-checks .swatch { width: 12px; height: 12px; border-radius: 3px; flex: 0 0 12px; }
.mode-row { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.series-hint {
  background: rgba(224, 179, 65, 0.12);
  border: 1px solid rgba(224, 179, 65, 0.65);
  border-radius: 6px;
  padding: 7px 10px;
  margin-bottom: 10px;
  color: var(--amber);
  font-size: 12px;
}
.series-hint.hidden { display: none; }
.measure-row { display: flex; align-items: center; gap: 8px; margin: 2px 0 12px; }
.measure-btn { min-width: 0; padding: 6px 14px; flex: 0 0 auto; }
.measure-row .progress-count { min-width: 0; margin-left: auto; }
.radio { display: flex; align-items: center; gap: 7px; color: var(--text); cursor: pointer; white-space: nowrap; }

/* Setup-Dialog: zweispaltig (Nennstrom-Punkte | Kalibrator-Befehle) */
.setup-grid { display: flex; gap: 20px; min-height: 0; overflow: auto; }
.setup-col { flex: 1 1 0; min-width: 0; }
.radio-row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.setup-note { font-size: 11px; line-height: 1.5; margin-top: 10px; }
.setup-note b { color: var(--amber); }
@media (max-width: 760px) { .setup-grid { flex-direction: column; } }

/* Generisches Verstecken (Utility) */
.hidden { display: none !important; }

/* Live-Werte in der Kopfzeile */
.live-readout { display: flex; align-items: center; gap: 18px; }
.live-item { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.1; }
.live-label { font-size: 10px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.6px; }
.live-val { font-weight: 700; font-size: 15px; font-variant-numeric: tabular-nums; }

/* Fehler-Modal (Kalibrator-HTTP-Fehler im Rohformat) */
.modal-box.error { border-color: var(--red); }
.error-title { color: var(--red); }
.raw-error {
  white-space: pre-wrap; word-break: break-word;
  font-family: "Consolas", "Courier New", monospace; font-size: 12px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px;
  padding: 10px; margin: 0; max-height: 50vh; overflow: auto; color: var(--text);
}

/* Geteilte Serien-Karte (wird zwischen Assistent/Automatisch verschoben) */
.shared-block { display: flex; flex-direction: column; gap: 12px; }

/* Manueller Achsenbereich pro Diagramm */
.range-ctrl { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 11px; }
.btn-mini {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-dim);
  border-radius: 5px; padding: 2px 8px; font: inherit; font-size: 11px; cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.btn-mini:hover { color: var(--text); }
.btn-mini:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn-mini.on { color: var(--accent); border-color: var(--accent); }
.range-fields { display: inline-flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.range-fields .dim { font-weight: 700; }
.range-fields input {
  width: 62px; padding: 2px 4px; font-size: 11px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text); border-radius: 4px;
}

/* Detailansicht eines Messpunkts (Darstellung → Klick auf Punkt) */
.detail-grid { display: flex; gap: 16px; min-height: 0; }
.detail-stats { flex: 0 0 210px; }
/* Anklickbare Messpunkt-Zeilen (Darstellung → Detailansicht) */
#comparePointsTable tbody tr.clickable { cursor: pointer; }
#comparePointsTable tbody tr.clickable:hover td { background: rgba(77, 163, 255, 0.1); color: var(--accent); }

/* Filter-/Sortier-Tabelle der gespeicherten Messreihen (Sidebar „Darstellung") */
.mr-list-wrap { max-height: 62vh; overflow: auto; margin-bottom: 10px; border: 1px solid var(--border-soft); border-radius: 8px; }
table.mr-list { font-size: 12px; color: var(--text); }
table.mr-list th, table.mr-list td { padding: 4px 6px; }
table.mr-list th.sortable { cursor: pointer; user-select: none; color: var(--text-dim); }
table.mr-list th.sortable:hover { color: var(--text); }
table.mr-list .sort-ind { color: var(--accent); }
table.mr-list th.mr-check, table.mr-list td.mr-check { text-align: center; padding: 4px; }
table.mr-list tr.filter-row th { top: 25px; padding: 3px 5px; }
table.mr-list tr.filter-row input, table.mr-list tr.filter-row select {
  width: 100%; min-width: 0; box-sizing: border-box; padding: 2px 4px; font-size: 11px;
}
table.mr-list tbody tr { cursor: pointer; }
table.mr-list tbody tr:hover td { color: var(--accent); }
.detail-charts { flex: 1 1 auto; display: flex; flex-direction: column; gap: 12px; height: 62vh; min-height: 360px; }
@media (max-width: 820px) { .detail-grid { flex-direction: column; } .detail-charts { height: 460px; } }

/* Einstellungen-Tab */
.settings-content { overflow: auto; align-items: flex-start; }
.settings-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 12px; align-content: start; width: 100%; max-width: 1120px;
}
.settings-grid .card { align-self: start; }
.settings-grid .points-edit td:nth-child(2) { color: var(--accent); text-align: right; padding-right: 8px; font-variant-numeric: tabular-nums; }
.settings-actions { grid-column: 1 / -1; display: flex; align-items: center; gap: 14px; }
.settings-actions .btn { width: auto; }
.stat-value.calc { text-align: left; color: var(--accent); font-size: 15px; }
select, select.full {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 6px; padding: 5px 8px; color: var(--text); font: inherit;
  transition: border-color 0.12s, box-shadow 0.12s;
}
select.full { width: 100%; }
select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px rgba(77, 163, 255, 0.22); }

/* Diagramm-Kopf mit Achsen-Umschaltern */
.plot-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 2px 2px 6px; flex-wrap: wrap; }
.plot-head .plot-title { padding: 0; text-align: left; }
.axis-controls { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; font-size: 12px; }
.xaxis-toggle, .yaxis-toggle { display: flex; align-items: center; gap: 10px; }
.xaxis-toggle .radio, .yaxis-toggle .radio { gap: 5px; }
.yaxis-toggle input[type="number"] { width: 56px; padding: 3px 6px; text-align: right; }
.yaxis-toggle input[type="number"]:disabled { opacity: 0.45; }

/* Band-Editor (Modal) */
.band-editor { display: flex; gap: 16px; min-height: 0; }
.band-list { flex: 0 0 240px; }
.band-form { flex: 1 1 auto; min-width: 0; }
.points-edit { width: 100%; }
.points-edit input { width: 100%; }
.points-edit input:disabled { opacity: 0.45; cursor: not-allowed; }
.points-edit.disabled { opacity: 0.85; }
.points-edit td { border: none; padding: 3px 4px; }
.points-edit th { background: transparent; position: static; padding: 2px 4px; }
.points-edit .del { color: var(--red); cursor: pointer; font-weight: 700; padding: 0 6px; }
input[type="color"] { width: 48px; height: 28px; padding: 1px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; }

/* Scrollbars (WebKit) */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }
