/* ─── Reset & Base ──────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #1a2030;
  --bg1:       #242c3e;
  --bg2:       #2e3850;
  --bg3:       #3d4865;
  --border:    #4a5677;
  --text:      #e4ebf5;
  --text-dim:  #a8b4cc;
  --text-muted:#6b7694;
  --white:     #ffffff;
  --green:     #3fb950;
  --green-bg:  #1e4a2a;
  --red:       #f85149;
  --red-bg:    #5a2020;
  --yellow:    #f0b030;
  --yellow-bg: #4d3810;
  --blue:      #58a6ff;
  --orange:    #e3b341;

  --sidebar-w: 220px;
  --header-h:  52px;
  --client-bar-h: 22px;
}

/* ── Theme: Kontrast Dunkel (Default Alternative) ───────────────────────── */
html[data-theme="contrast-dark"] {
  --bg:        #1d2638;
  --bg1:       #2a3550;
  --bg2:       #35446a;
  --bg3:       #455680;
  --border:    #556796;
  --text:      #f2f6fc;
  --text-dim:  #c0cce0;
  --text-muted:#8695b2;
  --white:     #ffffff;
  --green:     #2ee86b;
  --green-bg:  #1a5030;
  --red:       #ff4747;
  --red-bg:    #5a1c1c;
  --yellow:    #ffd500;
  --yellow-bg: #5a4200;
  --blue:      #4aa8ff;
  --orange:    #ff8c2b;
}

/* ── Theme: Racing Orange (Emsland-Akzent) ──────────────────────────────── */
html[data-theme="racing-orange"] {
  --bg:        #2a2418;
  --bg1:       #3a3222;
  --bg2:       #4a4030;
  --bg3:       #5e5240;
  --border:    #786850;
  --text:      #fbf0dc;
  --text-dim:  #d2c2a4;
  --text-muted:#8f8166;
  --white:     #ffffff;
  --green:     #4edc73;
  --green-bg:  #1d4a2c;
  --red:       #ff4d3d;
  --red-bg:    #5a1f18;
  --yellow:    #ffc83d;
  --yellow-bg: #5a4200;
  --blue:      #ffb057;
  --orange:    #ff7a18;
}

/* ── Theme: Pit-Wall Schwarz/Gelb ────────────────────────────────────────── */
html[data-theme="pitwall"] {
  --bg:        #242424;
  --bg1:       #303030;
  --bg2:       #3d3d3d;
  --bg3:       #4d4d4d;
  --border:    #626262;
  --text:      #f5f5f5;
  --text-dim:  #c2c2c2;
  --text-muted:#858585;
  --white:     #ffffff;
  --green:     #39ff6e;
  --green-bg:  #1a4a28;
  --red:       #ff3838;
  --red-bg:    #5a1818;
  --yellow:    #ffdd00;
  --yellow-bg: #524300;
  --blue:      #58a6ff;
  --orange:    #ffaa00;
}

/* ── Theme: Racing Rot (RennKart) ───────────────────────────────────────── */
html[data-theme="racing-red"] {
  --bg:        #2d1818;
  --bg1:       #3d2020;
  --bg2:       #4f2a2a;
  --bg3:       #653636;
  --border:    #804545;
  --text:      #fbe8e8;
  --text-dim:  #d4adad;
  --text-muted:#8a6868;
  --white:     #ffffff;
  --green:     #3fff7a;
  --green-bg:  #1a4a2a;
  --red:       #ff1e2d;
  --red-bg:    #6a1818;
  --yellow:    #ffce3a;
  --yellow-bg: #5a4200;
  --blue:      #ff9eb4;
  --orange:    #ff5a3c;
}

/* ── Theme: Hell Klar ────────────────────────────────────────────────────── */
html[data-theme="light"] {
  --bg:        #ffffff;
  --bg1:       #f4f6f9;
  --bg2:       #e6ebf0;
  --bg3:       #cfd7e0;
  --border:    #b6c0cc;
  --text:      #0d1320;
  --text-dim:  #3d4a63;
  --text-muted:#6b7890;
  --white:     #000000;
  --green:     #058c2c;
  --green-bg:  #c7f2d3;
  --red:       #d11a22;
  --red-bg:    #ffd5d7;
  --yellow:    #a86b00;
  --yellow-bg: #ffeaa8;
  --blue:      #0357c9;
  --orange:    #c9460e;
}

html, body { height: 100%; overflow: hidden; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  line-height: 1.5;
}

/* ─── Layout ────────────────────────────────────────────────────────────── */
#app { display: flex; flex-direction: column; height: calc(100vh - var(--client-bar-h)); }

#header {
  height: var(--header-h);
  background: var(--bg1);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  flex-shrink: 0;
  z-index: 10;
}

#header .brand {
  font-weight: 700;
  font-size: 15px;
  color: var(--white);
  letter-spacing: 0.03em;
  white-space: nowrap;
}

#decoder-status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: 12px;
  padding: 4px 10px;
  background: var(--bg2);
  border-radius: 6px;
  border: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
}

#decoder-status .dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: background 0.3s;
}
#decoder-status.connected .dot { background: var(--green); }
#decoder-status.connected { color: var(--text); }

.header-spacer { flex: 1; }

#nav-tabs { display: flex; gap: 4px; }
#nav-tabs button {
  background: none;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 5px 12px;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 12px;
  transition: all 0.15s;
}
#nav-tabs button:hover { color: var(--text); background: var(--bg2); }
#nav-tabs button.active {
  color: var(--white);
  background: var(--bg2);
  border-color: var(--border);
}

/* ─── Main Content ──────────────────────────────────────────────────────── */
#content { flex: 1; display: flex; overflow: hidden; }

/* ─── Views ─────────────────────────────────────────────────────────────── */
.view { display: none; width: 100%; }
.view.active { display: flex; }

/* ── Timing View ── */
#view-timing { flex-direction: row; overflow: hidden; }

/* ─── Sidebar ───────────────────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg1);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#sidebar-header {
  padding: 10px 12px 8px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 6px;
}

#day-prev, #day-next {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-dim);
  cursor: pointer;
  padding: 2px 6px;
  font-size: 12px;
  line-height: 1.4;
}
#day-prev:hover, #day-next:hover { color: var(--text); background: var(--bg2); }

#day-picker {
  flex: 1;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-dim);
  font-size: 11px;
  padding: 2px 4px;
  min-width: 0;
  cursor: pointer;
}
#day-picker:focus { outline: none; border-color: var(--blue); }
#day-picker::-webkit-calendar-picker-indicator { filter: invert(0.5); cursor: pointer; }

#run-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px 0;
}

#run-list::-webkit-scrollbar { width: 4px; }
#run-list::-webkit-scrollbar-track { background: transparent; }
#run-list::-webkit-scrollbar-thumb { background: var(--bg3); border-radius: 2px; }

.run-item {
  position: relative;
  padding: 9px 12px 9px 17px;
  cursor: pointer;
  border-left: 3px solid transparent;
  display: flex;
  align-items: center;
  gap: 8px;
  user-select: none;
  transition: background 0.1s;
}
.run-item:hover { background: var(--bg2); }
.run-item.selected { background: var(--bg2); }

.run-item.training { border-left-color: var(--bg3); }
.run-item.gp_time, .run-item.gp_laps { border-left-color: var(--red); }

/* Klassen-Kategorie-Streifen an der linken Seite (überschreibt mode-Border) */
.run-item.cat-kinder      { border-left: 5px solid #1565c0 !important; }
.run-item.cat-erwachsene  { border-left: 5px solid var(--red) !important; }
.run-item.cat-mixed       { border-left: 5px solid var(--bg3) !important; }

.run-item-icon {
  width: 28px; height: 28px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 800;
}
.run-item .status-done,
.run-item .status-armed,
.run-item .status-running,
.run-item .status-paused,
.run-item .status-finishing {
  font-size: 22px;
  font-weight: 800;
  text-shadow: 0 0 6px currentColor;
}

.run-item-name {
  flex: 1;
  font-size: 15px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.run-item-badge {
  font-size: 11px;
  padding: 2px 5px;
  border-radius: 3px;
  background: var(--red-bg);
  color: var(--red);
  font-weight: 600;
  letter-spacing: 0.03em;
  flex-shrink: 0;
}

.run-item-time {
  font-size: 12px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  min-width: 42px;
  text-align: right;
  flex-shrink: 0;
}

.run-item-arm {
  flex-shrink: 0;
  background: #196c2e;
  border: 1px solid var(--green);
  border-radius: 5px;
  color: var(--green);
  cursor: pointer;
  font-size: 13px;
  padding: 4px 9px;
  line-height: 1.3;
  opacity: 0.9;
  transition: opacity 0.15s, background 0.15s;
}
.run-item-arm:hover { opacity: 1; }
.run-item-arm.disabled, .run-item-arm:disabled { opacity: 0.3; cursor: not-allowed; }
.run-item-arm.disarm {
  background: #6e5c14;
  border-color: var(--yellow);
  color: var(--yellow);
}
.run-item-arm.disarm:hover { background: #8a7320; }

/* Status indicators */
.run-item .status-done   { color: var(--text-muted); }
.run-item .status-armed  { color: var(--yellow); }
.run-item .status-running { color: var(--green); }
.run-item .status-paused { color: var(--orange); }
.run-item .status-finishing { color: var(--blue); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.3; }
}
.pulse { animation: pulse 1.2s ease-in-out infinite; }

#run-list-footer {
  padding: 6px 10px;
  border-top: 1px solid var(--border);
}

#btn-add-run {
  width: 100%;
  background: none;
  border: 1px dashed var(--border);
  border-radius: 5px;
  color: var(--text-dim);
  padding: 5px;
  cursor: pointer;
  font-size: 11px;
  transition: all 0.15s;
}
#btn-add-run:hover { color: var(--text); border-color: var(--text-dim); }

/* ─── Main Panel ────────────────────────────────────────────────────────── */
#main-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#run-header {
  padding: 10px 16px 8px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  background: var(--bg1);
}

#run-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--white);
}

#run-mode-badge {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 700;
  letter-spacing: 0.05em;
  display: none;
}
#run-mode-badge.gp { display: inline; background: var(--red-bg); color: var(--red); }

#run-timer {
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  color: var(--white);
  min-width: 72px;
  text-align: right;
}
#run-timer.warn { color: var(--yellow); }
#run-timer.crit { color: var(--red); }

#run-status-text {
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
}

#run-controls { display: flex; gap: 6px; flex-wrap: wrap; }

.btn {
  padding: 5px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg2);
  color: var(--text);
  cursor: pointer;
  font-size: 12px;
  white-space: nowrap;
  transition: all 0.15s;
}
.btn:hover { background: var(--bg3); color: var(--white); }
.btn:disabled { opacity: 0.35; cursor: not-allowed; }
.btn-green  { background: var(--green);  border-color: var(--green);  color: #fff; font-weight: 600; }
.btn-green:hover  { filter: brightness(1.12); color: #fff; }
.btn-red    { background: var(--red);    border-color: var(--red);    color: #fff; font-weight: 600; }
.btn-red:hover    { filter: brightness(1.12); color: #fff; }
.btn-yellow { background: var(--yellow); border-color: var(--yellow); color: #1a1200; font-weight: 700; }
.btn-yellow:hover { filter: brightness(1.12); color: #1a1200; }
.btn-green:disabled, .btn-red:disabled, .btn-yellow:disabled { filter: none; }

/* ─── Kart Table ─────────────────────────────────────────────────────────── */
#kart-table-container {
  flex: 1;
  overflow-y: auto;
  padding: 0;
}

#kart-table-container::-webkit-scrollbar { width: 5px; }
#kart-table-container::-webkit-scrollbar-track { background: transparent; }
#kart-table-container::-webkit-scrollbar-thumb { background: var(--bg3); border-radius: 2px; }

table#kart-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

table#kart-table thead th {
  padding: 8px 10px;
  text-align: left;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 1;
}
th.num { text-align: left; }

table#kart-table tbody tr.kart-row {
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
}
table#kart-table tbody tr.kart-row:hover { background: var(--bg2); }
table#kart-table tbody tr.kart-row.flash { background: #1a3a1a; }
table#kart-table tbody tr.kart-row.finished { background: #0d2d1a; }
table#kart-table tbody tr.kart-row.finished td.kart-name { color: var(--green); }

/* Light Theme: Cyan für Nachläufer nach Zeitablauf */
html[data-theme="light"] table#kart-table tbody tr.kart-row.finished { background: #00FFFF; }
html[data-theme="light"] table#kart-table tbody tr.kart-row.finished td.kart-name { color: #005d66; }

/* Kontrast Dunkel: das Standard-Dunkelgrün ist im Kontrast-Theme zu dunkel –
   Cyan liefert deutlich mehr Kontrast und macht die durchgefahrenen Karts
   sofort erkennbar. */
html[data-theme="contrast-dark"] table#kart-table tbody tr.kart-row.finished { background: #0d4a4a; }
html[data-theme="contrast-dark"] table#kart-table tbody tr.kart-row.finished td.kart-name { color: #00ffff; font-weight: 700; }

table#kart-table td {
  padding: 9px 10px;
  vertical-align: middle;
  white-space: nowrap;
}
td.num { text-align: left; font-variant-numeric: tabular-nums; }
td.pos {
  font-weight: 700;
  font-size: 14px;
  color: var(--text-dim);
  width: 36px;
}
td.pos-1 { color: #ffd700; }
td.pos-2 { color: #c0c0c0; }
td.pos-3 { color: #cd7f32; }

td.kart-name {
  font-weight: 600;
  color: var(--white);
  overflow: hidden;
  text-overflow: ellipsis;
}
td.time { color: var(--text); font-variant-numeric: tabular-nums; }
td.best-time { color: var(--green); font-variant-numeric: tabular-nums; }

.trend-up   { color: var(--green); }
.trend-down { color: var(--red); }
.trend-stable { color: var(--text-dim); }

td.prog-cell { width: 80px; padding: 9px 6px; }
.prog-bar-bg {
  height: 6px;
  background: var(--bg3);
  border-radius: 3px;
  overflow: hidden;
}
.prog-bar-fill {
  height: 100%;
  border-radius: 3px;
  background: var(--green);
  width: 0%;
  transition: background 0.3s;
}
.prog-bar-fill.warn { background: var(--yellow); }
.prog-bar-fill.over { background: var(--red); }

td.sig-cell { width: 48px; text-align: right; font-variant-numeric: tabular-nums; }
.sig-good { color: var(--green); }
.sig-ok   { color: var(--yellow); }
.sig-bad  { color: var(--red); }

/* ─── Lap Detail Row ─────────────────────────────────────────────────────── */
/* Trick: TR und TD auf display:block setzen damit die Lap-Detail-Zeile
   das table-layout der Spalten nicht mehr beeinflusst (in Safari +
   Chrome verursacht ein Colspan-TR über alle Spalten sonst, dass die
   Spalten beim Aufklappen auf ihre deklarierten Pixel-Breiten
   zurückspringen). Mit display:block ist die Zeile aus dem Tabellen-
   Layout raus und nimmt einfach die TBODY-Breite ein. */
tr.lap-detail { display: block; width: 100%; }
tr.lap-detail td {
  display: block;
  width: 100%;
  box-sizing: border-box;
  padding: 0;
  background: var(--bg);
}
.lap-detail-inner {
  width: 100%;
  box-sizing: border-box;
  padding: 6px 16px 10px 52px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
}
.lap-chip {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 8px;
}
.lap-chip.best { color: var(--green); border-color: var(--green); background: var(--green-bg); }

/* Chips im Transponder-Detail (letzte 50 Runden) */
.lap-chip-td {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 2px 6px;
}
.lap-chip-td.lap-slow { color: var(--red);    border-color: var(--red);    background: var(--red-bg); }
.lap-chip-td.lap-fast { color: var(--green);  border-color: var(--green);  background: var(--green-bg); }

/* Defekt-Warndreieck in Transponder-Tabelle */
.defect-warn {
  display: inline-block;
  margin-right: 6px;
  color: var(--red);
  font-size: 14px;
  line-height: 1;
  text-shadow: 0 0 6px rgba(229, 57, 53, 0.5);
  animation: defect-pulse 1.6s ease-in-out infinite;
}
@keyframes defect-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.45; }
}
tr.has-defect td:nth-child(2) { color: var(--red); font-weight: 600; }

/* ─── Empty State ────────────────────────────────────────────────────────── */
#empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  gap: 8px;
}
#empty-state .empty-icon { font-size: 36px; }
#empty-state p { font-size: 13px; }

/* ─── Floating Timer ─────────────────────────────────────────────────────── */
#float-timer {
  position: fixed;
  bottom: calc(var(--client-bar-h) + 18px);
  right: 18px;
  background: var(--bg1);
  border-radius: 14px;
  padding: 4px;
  z-index: 200;
  text-align: center;
  min-width: 170px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.6);
  cursor: pointer;
  user-select: none;
  transition: transform 0.15s, box-shadow 0.15s;
  --ring-angle: 360deg;
  --ring-color: var(--border);
}
#float-timer:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 48px rgba(0,0,0,0.7);
}
/* Ring/Rahmen: conic-gradient gegen den Uhrzeigersinn (from 360deg, via 0deg) */
#float-timer-ring {
  position: absolute;
  inset: 0;
  border-radius: 14px;
  padding: 5px;
  background: conic-gradient(
    from 0deg,
    var(--ring-color) 0 var(--ring-angle),
    var(--border) var(--ring-angle) 360deg
  );
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
          mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
          mask-composite: exclude;
  pointer-events: none;
  transition: background 0.3s;
}
#float-timer-inner {
  position: relative;
  padding: 12px 22px;
}
/* Status-abhängige Ring-Farben */
#float-timer.state-armed   { --ring-color: var(--green); --ring-angle: 360deg; }
#float-timer.state-running { --ring-color: var(--green); }
#float-timer.state-finishing { --ring-color: var(--yellow); --ring-angle: 360deg; }
#float-timer-label {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 6px;
  font-weight: 600;
}
#float-timer-value {
  font-size: 48px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  color: var(--white);
  line-height: 1;
  text-shadow: 0 2px 8px rgba(0,0,0,0.4);
}
#float-timer-value.warn {
  color: var(--orange);
  text-shadow: 0 0 14px color-mix(in srgb, var(--orange) 50%, transparent);
  animation: pulse-last 1.4s ease-in-out infinite;
}
#float-timer-value.crit {
  color: var(--red);
  text-shadow: 0 0 20px color-mix(in srgb, var(--red) 60%, transparent);
  animation: pulse-last 0.9s ease-in-out infinite;
}
@keyframes pulse-last {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.65; }
}
#float-timer-status {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 6px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
}

/* ─── Laufzeit-Fortschrittsbalken ─────────────────────────────────────────── */
#run-progress-wrap {
  height: 12px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  position: relative;
  flex-shrink: 0;
}
#run-progress-bar {
  height: 100%;
  width: 0%;
  background: var(--green);
  transition: width 0.5s linear;
}
#run-progress-bar.finishing {
  background: var(--yellow);
  animation: pulse 1.2s ease-in-out infinite;
}

/* Readonly hardware */
.hw-locked input, .hw-locked select {
  pointer-events: none;
  opacity: 0.55;
  background: var(--bg) !important;
}

/* ─── Finish-Countdown ───────────────────────────────────────────────────── */
#run-finish-timer {
  display: flex; align-items: center; gap: 6px;
  background: #2d1e00;
  color: var(--yellow);
  padding: 3px 10px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  margin-right: 8px;
  border: 1px solid var(--yellow);
}
#run-finish-timer #run-finish-value {
  font-family: monospace;
  font-variant-numeric: tabular-nums;
  font-size: 14px;
}

/* ─── Print-Options Buttons ──────────────────────────────────────────────── */
#print-options button {
  background: var(--bg2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
  min-width: 80px;
}
#print-options button.gesamt {
  background: var(--green-bg);
  border-color: var(--green);
  color: var(--green);
  font-weight: 600;
}
#print-options button:hover { background: var(--bg3); }

/* ─── Client Bar ─────────────────────────────────────────────────────────── */
#client-bar {
  height: var(--client-bar-h);
  background: var(--bg1);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  flex-shrink: 0;
}
#client-bar-text {
  font-size: 10px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
#ampel-bar-indicators {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 5px;
}
.ampel-bar-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1px solid;
  transition: background 0.3s, box-shadow 0.3s;
}
.ampel-bar-dot-red {
  background: #3a0000;
  border-color: #600;
  box-shadow: none;
}
.ampel-bar-dot-red.lit {
  background: #e53935;
  border-color: #ff6659;
  box-shadow: 0 0 6px #e53935;
}
.ampel-bar-dot-green {
  background: #003a00;
  border-color: #060;
  box-shadow: none;
}
.ampel-bar-dot-green.lit {
  background: #43a047;
  border-color: #76d275;
  box-shadow: 0 0 6px #43a047;
}

/* ─── Context Menu ───────────────────────────────────────────────────────── */
#ctx-menu {
  position: fixed;
  background: var(--bg1);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  z-index: 1000;
  padding: 4px 0;
  min-width: 180px;
  display: none;
}
#ctx-menu.visible { display: block; }
.ctx-item {
  padding: 7px 14px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}
.ctx-item:hover { background: var(--bg2); }
.ctx-separator { height: 1px; background: var(--border); margin: 3px 0; }

/* ─── Modal ──────────────────────────────────────────────────────────────── */
#modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 500;
  display: none;
  align-items: center;
  justify-content: center;
}
#modal-overlay.visible { display: flex; }

.modal {
  background: var(--bg1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px 24px;
  min-width: 340px;
  max-width: 480px;
  width: 90%;
  box-shadow: 0 16px 48px rgba(0,0,0,0.6);
}
.modal h2 {
  font-size: 14px;
  font-weight: 600;
  color: var(--white);
  margin-bottom: 16px;
}
.form-group { margin-bottom: 12px; }
.form-group label {
  display: block;
  font-size: 11px;
  color: var(--text-dim);
  margin-bottom: 4px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.form-group input, .form-group select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 10px;
  color: var(--text);
  font-size: 13px;
}
.form-group input:focus, .form-group select:focus {
  outline: none;
  border-color: var(--blue);
}
.form-row { display: flex; gap: 8px; }
.form-row .form-group { flex: 1; }

/* Spinner rows for +/- increment buttons */
.spinner-row {
  display: flex;
  align-items: stretch;
  gap: 0;
}
.spinner-row input {
  border-radius: 0;
  text-align: center;
  flex: 1;
  min-width: 0;
}
.spinner-btn {
  background: var(--bg2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  cursor: pointer;
  padding: 0 8px;
  font-size: 14px;
  line-height: 1;
  transition: all 0.1s;
  flex-shrink: 0;
  width: 28px;
}
.spinner-btn:first-child { border-radius: 6px 0 0 6px; border-right: none; }
.spinner-btn:last-child  { border-radius: 0 6px 6px 0; border-left: none; }
.spinner-btn:hover { background: var(--bg3); color: var(--white); }

.modal-footer {
  margin-top: 16px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.btn-sm { padding: 5px 12px; font-size: 12px; }

/* ─── Settings View ──────────────────────────────────────────────────────── */
#view-settings {
  flex-direction: column;
  padding: 20px;
  overflow-y: auto;
  width: 100%;
}

.settings-section {
  background: var(--bg1);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px 20px;
  margin-bottom: 16px;
}
.settings-section h3 {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin-bottom: 14px;
}

.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 500px) { .settings-grid { grid-template-columns: 1fr; } }

/* ─── Transponder View ───────────────────────────────────────────────────── */
#view-transponders {
  flex-direction: column;
  overflow: hidden;
  width: 100%;
}

#transponder-table { width: 100%; border-collapse: collapse; }
#transponder-table th {
  text-align: left;
  padding: 6px 10px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 1;
}
#transponder-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}
#transponder-table tr:hover td { background: var(--bg2); cursor: pointer; }

/* Class color swatches - using CSS custom property set per-row from JS */
.class-badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.03em;
}

.sparkline { display: block; }

/* ─── Range Pills ─────────────────────────────────────────────────────────── */
.range-pills { display: flex; gap: 4px; flex-wrap: wrap; }
.range-pill {
  background: none;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2px 9px;
  font-size: 10px;
  color: var(--text-dim);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.range-pill:hover { color: var(--text); border-color: var(--text-dim); }
.range-pill.active { background: var(--bg2); border-color: var(--blue); color: var(--blue); }

/* ─── Chart Tooltip ─────────────────────────────────────────────────────── */
.chart-tooltip {
  position: absolute;
  background: rgba(22,27,34,0.95);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 9px;
  font-size: 11px;
  color: var(--white);
  pointer-events: none;
  white-space: nowrap;
  z-index: 10;
  transform: translate(-50%, -110%);
}

/* ─── Class Management List ──────────────────────────────────────────────── */
.class-list-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  margin-bottom: 6px;
  background: var(--bg);
}
.class-list-item .class-color-dot {
  width: 14px; height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
}
.class-list-item .class-name-input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 12px;
  padding: 0;
  min-width: 0;
}
.class-list-item .class-name-input:focus { outline: none; }
.class-list-item .class-color-input {
  width: 36px; height: 24px;
  padding: 1px;
  border-radius: 3px;
  border: 1px solid var(--border);
  background: var(--bg2);
  cursor: pointer;
}
.class-list-item .cls-delete {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13px;
  padding: 2px 4px;
  border-radius: 3px;
}
.class-list-item .cls-delete:hover { color: var(--red); background: var(--red-bg); }
.class-list-item .cls-save {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  cursor: pointer;
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 3px;
}
.class-list-item .cls-save:hover { color: var(--green); border-color: var(--green); }

/* ─── Debug View ─────────────────────────────────────────────────────────── */
#view-debug { flex-direction: column; overflow: hidden; width: 100%; }

.debug-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}
.debug-panel-header {
  padding: 6px 12px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  background: var(--bg1);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.debug-log {
  flex: 1;
  overflow-y: auto;
  font-family: "SFMono-Regular", "Consolas", "Liberation Mono", monospace;
  font-size: 11px;
  line-height: 1.6;
  padding: 6px 10px;
  background: var(--bg);
}
.debug-log::-webkit-scrollbar { width: 4px; }
.debug-log::-webkit-scrollbar-thumb { background: var(--bg3); border-radius: 2px; }

.debug-entry {
  display: flex;
  gap: 8px;
  padding: 2px 0;
  border-bottom: 1px solid rgba(255,255,255,0.03);
}
.debug-entry:hover { background: var(--bg1); }
.debug-ts { color: var(--text-muted); flex-shrink: 0; min-width: 68px; }
.debug-body { color: var(--text); word-break: break-all; }
.debug-body .hi { color: var(--green); }
.debug-body .hi-emu { color: var(--blue); }
.debug-body .dim { color: var(--text-dim); }

/* ─── Scrollbar global ───────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg3); border-radius: 3px; }

/* ─── Toasts ──────────────────────────────────────────────────────────────── */
#toast-host {
  position: fixed; top: 16px; right: 16px; z-index: 9999;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--bg1); color: var(--text);
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 13px; font-weight: 600;
  box-shadow: 0 6px 24px rgba(0,0,0,0.4);
  min-width: 220px;
  transition: opacity 0.5s, transform 0.5s;
}
.toast.toast-ok  { border-color: var(--green); color: var(--green); }
.toast.toast-err { border-color: var(--red);   color: var(--red); }
.toast.fade      { opacity: 0; transform: translateX(20px); }
