*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: #f0f2f5;
  color: #1a1a2e;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Header ── */
header {
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
  color: white;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 8px rgba(0,0,0,.3);
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-left { display: flex; align-items: center; gap: 14px; }
.logo { font-size: 18px; font-weight: 700; letter-spacing: .5px; }
.model-badge {
  background: rgba(255,255,255,.15);
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  letter-spacing: .5px;
}
.header-right { display: flex; align-items: center; gap: 10px; }

/* ── Status badge ── */
.status-badge {
  padding: 5px 14px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .5px;
}
.status-badge.connected    { background: #27ae60; color: white; }
.status-badge.disconnected { background: #e74c3c; color: white; }

/* ── Buttons ── */
.btn {
  padding: 8px 16px;
  border-radius: 6px;
  border: none;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary  { background: #2980b9; color: white; }
.btn-primary:hover:not(:disabled)  { background: #1f6fa1; }
.btn-secondary { background: #ecf0f1; color: #2c3e50; border: 1px solid #bdc3c7; }
.btn-secondary:hover:not(:disabled) { background: #dde1e3; }
.btn-danger   { background: #e74c3c; color: white; }
.btn-danger:hover:not(:disabled)  { background: #c0392b; }
.btn.active-mode { background: #27ae60; color: white; }
.btn-mode { background: #ecf0f1; color: #2c3e50; border: 1px solid #bdc3c7; }
.full-width { width: 100%; margin-top: 8px; }

/* ── Main grid ── */
.main-grid {
  display: grid;
  grid-template-columns: 1fr 280px 320px;
  gap: 16px;
  padding: 16px;
  flex: 1;
  min-height: 0;
}

/* ── Panels ── */
.panel {
  background: white;
  border-radius: 10px;
  padding: 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,.07);
  overflow-y: auto;
}
.panel h2 {
  font-size: 15px;
  font-weight: 700;
  color: #2c3e50;
  border-bottom: 2px solid #3498db;
  padding-bottom: 8px;
  margin-bottom: 14px;
}

/* ── Gauge bars ── */
.gauge-row { display: flex; gap: 10px; margin-bottom: 14px; }
.gauge-card {
  flex: 1;
  background: #f8f9fa;
  border-radius: 8px;
  padding: 10px;
  text-align: center;
}
.gauge-label { font-size: 11px; color: #7f8c8d; margin-bottom: 6px; font-weight: 600; text-transform: uppercase; }
.gauge-bar {
  height: 8px;
  background: #ecf0f1;
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 6px;
}
.gauge-fill {
  height: 100%;
  border-radius: 4px;
  width: 50%;
  transition: width .5s ease;
}
.gauge-fill.travel { background: linear-gradient(90deg, #3498db, #1abc9c); }
.gauge-fill.setpt  { background: linear-gradient(90deg, #e67e22, #f39c12); }
.gauge-fill.drive  { background: linear-gradient(90deg, #9b59b6, #e91e63); }
.gauge-value { font-size: 18px; font-weight: 700; color: #2c3e50; }

/* ── KV grid ── */
.kv-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.kv {
  background: #f8f9fa;
  border-radius: 6px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.kv span { font-size: 11px; color: #7f8c8d; }
.kv strong { font-size: 14px; color: #2c3e50; }

/* ── Chart ── */
.chart-wrap { height: 180px; position: relative; }

/* ── Control cards ── */
.ctrl-card {
  background: #f8f9fa;
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 12px;
}
.ctrl-card h3 { font-size: 13px; font-weight: 700; color: #2c3e50; margin-bottom: 10px; }

.slider-row { display: flex; align-items: center; gap: 10px; }
.slider-row input[type=range] { flex: 1; }
.slider-row span { font-weight: 700; min-width: 54px; text-align: right; }

label { display: block; font-size: 12px; color: #7f8c8d; margin-bottom: 6px; }
.num-input {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid #ddd;
  border-radius: 5px;
  font-size: 13px;
  margin-top: 2px;
}
.num-input.sm { width: 70px; }
.sel {
  width: 100%;
  padding: 7px 8px;
  border: 1px solid #ddd;
  border-radius: 5px;
  font-size: 13px;
  background: white;
}

.toggle-row { display: flex; gap: 8px; }
.toggle-row .btn { flex: 1; }

.diag-btn-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.diag-btn { font-size: 12px; padding: 8px 6px; }

/* ── Progress bar ── */
.progress-bar {
  height: 8px;
  background: #ecf0f1;
  border-radius: 4px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #3498db, #1abc9c);
  border-radius: 4px;
  width: 0%;
  transition: width .3s;
}

/* ── Tabs ── */
.tab-bar {
  display: flex;
  border-bottom: 2px solid #ecf0f1;
  margin-bottom: 12px;
  gap: 4px;
}
.tab {
  padding: 7px 12px;
  background: none;
  border: none;
  font-size: 12px;
  font-weight: 600;
  color: #7f8c8d;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color .15s;
}
.tab.active { color: #2980b9; border-bottom-color: #2980b9; }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ── Alerts ── */
.check-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: #2c3e50;
  margin-bottom: 4px;
  cursor: pointer;
}
.alert-range-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 0 10px 24px;
  font-size: 12px;
  color: #7f8c8d;
}

/* ── Event log ── */
.event-log {
  height: 320px;
  overflow-y: auto;
  background: #1a1a2e;
  border-radius: 6px;
  padding: 10px;
  font-family: 'Courier New', monospace;
  font-size: 11px;
  color: #a8d8ea;
  line-height: 1.6;
}

/* ── Alerts in KV ── */
.alert-active { color: #e74c3c !important; }
.alert-inactive { color: #27ae60 !important; }

@media (max-width: 900px) {
  .main-grid { grid-template-columns: 1fr; }
}
