/* ═══════ ApiTronik Dashboard — Redesigned ═══════ */

:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --border: #e8e8e8;
  --border-hover: #d0d0d0;
  --accent: #c48a1a;
  --accent-light: #fdf4e3;
  --accent2: #0d9488;
  --accent2-light: #ecfdf5;
  --danger: #dc4a42;
  --danger-light: #fef2f2;
  --text: #1a1a1a;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --online: #22c55e;
  --radius: 12px;
  --radius-lg: 16px;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
}

/* ── Header ─────────────────────────────────── */

header {
  padding: 24px 0 8px;
  margin-bottom: 24px;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--accent-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}

.logo-text {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--text);
}

.logo-text span { color: var(--accent); }

.logo-subtitle {
  margin-top: 2px;
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 400;
}

.header-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
}

.pulse {
  width: 8px;
  height: 8px;
  background: var(--online);
  border-radius: 50%;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ── Alert Banner ────────────────────────────── */

.alert-banner {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  border-radius: var(--radius);
  margin-bottom: 20px;
  font-size: 13px;
  font-weight: 600;
  border: 1px solid transparent;
}

.alert-banner.show {
  display: flex;
  background: #fffbeb;
  border-color: #fcd34d;
  color: #92400e;
}

.alert-banner.show.danger {
  background: var(--danger-light);
  border-color: #fca5a5;
  color: #991b1b;
  animation: alertPulse 1.5s ease infinite;
}

@keyframes alertPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.75; }
}

/* ── Stats Row ───────────────────────────────── */

.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}

.stats-row[hidden] {
  display: none;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  animation: fadeIn 0.4s ease both;
}

.stat-card:nth-child(1) { animation-delay: 0.05s; }
.stat-card:nth-child(2) { animation-delay: 0.1s; }
.stat-card:nth-child(3) { animation-delay: 0.15s; }
.stat-card:nth-child(4) { animation-delay: 0.2s; }

.stat-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.stat-unit {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
}

/* ── Tab Navigation ──────────────────────────── */

.tabs {
  display: flex;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px;
  margin-bottom: 24px;
  overflow-x: auto;
}

.tab {
  flex: 1;
  padding: 10px 16px;
  border: none;
  background: transparent;
  border-radius: 8px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.tab:hover {
  color: var(--text-secondary);
  background: var(--bg);
}

.tab.active {
  background: var(--accent2);
  color: #fff;
  box-shadow: 0 1px 3px rgba(13,148,136,0.3);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
  animation: fadeIn 0.3s ease;
}

/* ── Section Elements ────────────────────────── */

.section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 16px;
}

.section-subtitle {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}

/* ── Hive Grid & Cards ───────────────────────── */

.hive-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.hive-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
}
.hive-card.fade-enter {
  animation: fadeIn 0.4s ease both;
}

.hive-card:hover {
  border-color: var(--border-hover);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.04);
}

.hive-card.selected {
  box-shadow: 0 0 0 2px var(--accent2);
  border-color: var(--accent2);
}

.hive-card.offline { opacity: 0.6; }

.hive-card.danger-heat {
  border-color: var(--danger);
  animation: cardDanger 1.2s ease infinite;
}

@keyframes cardDanger {
  0%, 100% { box-shadow: 0 0 0 0 rgba(220,74,66,0); }
  50% { box-shadow: 0 0 0 4px rgba(220,74,66,0.18); }
}

.hive-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 16px;
  gap: 8px;
}

.hive-name {
  font-size: 16px;
  font-weight: 700;
}

.hive-ago {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.hive-ago.stale {
  color: #b45309;
  font-weight: 600;
}

.hive-header-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.hive-badge {
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}

.badge-online  { background: #ecfdf5; color: #16a34a; }
.badge-offline { background: #fef2f2; color: #dc2626; }
.badge-heating { background: var(--accent-light); color: var(--accent); }
.badge-danger  { background: #fef2f2; color: #dc2626; }
.badge-warn    { background: #fffbeb; color: #b45309; }

.hive-alert {
  font-size: 14px;
  cursor: help;
  animation: alertPulse 1.5s ease infinite;
}

.btn-ctrl {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-ctrl:hover {
  background: var(--accent2-light);
  color: var(--accent2);
  border-color: var(--accent2);
}

/* ── Hive Metrics ────────────────────────────── */

.hive-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

.metric {
  background: var(--bg);
  border-radius: 10px;
  padding: 12px;
  text-align: center;
}

.metric-value {
  font-size: 22px;
  font-weight: 700;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}

.metric-value.temp     { color: var(--accent); }
.metric-value.hum      { color: var(--accent2); }
.metric-value.sound    { color: #2563eb; }
.metric-value.temp-bot { color: #e11d48; }
.metric-value.temp-out { color: #0284c7; }

.metric-unit {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
}

.metric-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-top: 4px;
}

.metric-sub {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 2px;
}

.metric-sub.danger {
  color: var(--danger);
  font-weight: 700;
}

.metric-stale {
  font-size: 9px;
  color: #f59e0b;
  margin-top: 2px;
  font-weight: 600;
}
.stale-val { /* no dimming — user preference */ }

.metric-extra {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 3px;
  line-height: 1.4;
}

.temp-tag {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
  margin-top: 4px;
}

.temp-tag.heating   { background: #fdf4e3; color: var(--accent); }
.temp-tag.on-target { background: #ecfdf5; color: #16a34a; }
.temp-tag.cooling   { background: #eff6ff; color: #2563eb; }
.temp-tag.overheat  { background: #fef2f2; color: #dc2626; font-weight: 700; }
.temp-tag.warn-heat { background: #fffbeb; color: #b45309; }

/* ── Heater Bar (Card) ──────────────────────── */

.heater-bar-wrap { margin-top: 2px; }

.hive-card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-muted);
}

.heater-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 5px;
  font-weight: 500;
}

.heater-pct {
  font-weight: 700;
  color: var(--text-secondary);
}

.heater-bar {
  height: 5px;
  background: #f0f0f0;
  border-radius: 999px;
  overflow: hidden;
}

.heater-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent2) 0%, var(--accent) 100%);
  transition: width 0.5s ease;
}
.heater-fill.manual {
  background: linear-gradient(90deg, #7c3aed 0%, #a855f7 100%);
}

.heater-mode-tag {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: #fff;
  background: #7c3aed;
  padding: 1px 6px;
  border-radius: 4px;
  vertical-align: middle;
  margin-left: 4px;
}

.pending-tag {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--accent2);
  animation: pendingPulse 2s ease-in-out infinite;
}
@keyframes pendingPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* v2.3: FW version tag on hive card */
.fw-tag {
  font-size: 0.65rem;
  font-weight: 500;
  color: var(--text2);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  margin-left: 4px;
}

/* v2.3: Sensor error value (I2C bus error, phantom spike) */
.sensor-error { color: #e74c3c !important; }
.diag-tag {
  font-size: 0.6rem;
  font-weight: 600;
  color: #e74c3c;
  background: rgba(231,76,60,0.12);
  border-radius: 3px;
  padding: 1px 4px;
  margin-left: 3px;
}

/* ── Common Buttons ──────────────────────────── */

.btn-add {
  padding: 7px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-add:hover {
  border-color: var(--accent2);
  color: var(--accent2);
}

.pill-btn {
  padding: 6px 14px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.pill-btn:hover { color: var(--text); }

.pill-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

/* ── Hive Selector ───────────────────────────── */

.hive-selector {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.hive-btn {
  padding: 6px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.hive-btn:hover {
  border-color: var(--border-hover);
  color: var(--text);
}

.hive-btn.active {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Chart Section ───────────────────────────── */

.chart-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  gap: 12px;
}

.chart-title {
  font-size: 18px;
  font-weight: 700;
}

.chart-controls {
  display: flex;
  gap: 2px;
  background: var(--bg);
  border-radius: 10px;
  padding: 3px;
}

canvas {
  max-height: 340px;
}

/* ── Toggle Switches (Chart datasets) ────────── */

.chart-toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  margin-bottom: 18px;
  padding: 12px 14px;
  background: var(--bg);
  border-radius: var(--radius);
}

.toggle-switch {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  user-select: none;
  transition: color 0.15s;
}

.toggle-switch input { display: none; }

.toggle-track {
  width: 34px;
  height: 18px;
  background: #ddd;
  border-radius: 18px;
  position: relative;
  transition: background 0.2s;
  flex-shrink: 0;
}

.toggle-track::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  background: white;
  border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

.toggle-switch input:checked + .toggle-track {
  background: var(--tc, var(--accent2));
}

.toggle-switch input:checked + .toggle-track::after {
  transform: translateX(16px);
}

.toggle-switch input:checked ~ .toggle-label {
  color: var(--text);
}

/* ── Events ──────────────────────────────────── */

.events-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.events-header .section-title { margin-bottom: 0; }

.event-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.event-type-pill {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 20px;
  white-space: nowrap;
  background: #f3f4f6;
  color: #4b5563;
}

.event-date  { font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.event-hive  { font-size: 12px; color: var(--text-secondary); }
.event-notes { flex: 1; font-size: 13px; color: var(--text); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.event-del-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  padding: 2px 6px;
  border-radius: 4px;
  transition: color 0.15s;
}

.event-del-btn:hover { color: var(--danger); }

.events-empty {
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
  padding: 24px;
}

/* ── Journal (Stats + Diagnostics) ───────────── */

.journal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 8px;
}

.journal-header .section-title { margin-bottom: 0; }

.journal-actions {
  display: flex;
  gap: 8px;
}

.diag-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
  gap: 10px;
  margin-bottom: 20px;
}

.diag-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
}

.diag-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 4px;
}

.diag-value {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.diag-unit {
  font-size: 11px;
  color: var(--text-secondary);
  font-weight: 500;
}

.diag-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.diag-value.temp     { color: var(--accent); }
.diag-value.temp-bot { color: #e11d48; }
.diag-value.temp-out { color: #0284c7; }
.diag-value.hum      { color: var(--accent2); }
.diag-value.heater   { color: #ea580c; }
.diag-value.sound    { color: #2563eb; }
.diag-value.config   { color: #7c3aed; }
.diag-value.ok       { color: #16a34a; }
.diag-value.warn     { color: #b45309; }
.diag-value.danger   { color: #dc2626; }

.stats-text-block {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  font-family: 'Courier New', monospace;
  font-size: 12px;
  line-height: 1.6;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 300px;
  overflow-y: auto;
}

/* ── Modal ───────────────────────────────────── */

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-overlay.open { display: flex; }

.ctrl-modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px 24px 20px;
  width: 90%;
  max-width: 440px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.15);
}

.ctrl-modal h2 {
  margin: 0 0 2px;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
}

.ctrl-modal-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 20px;
  min-height: 16px;
}

.ctrl-divider {
  height: 1px;
  background: var(--border);
  margin: 16px 0;
}

.ctrl-section { margin-bottom: 4px; }

.ctrl-section-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 10px;
  font-weight: 600;
}

.ctrl-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.ctrl-input {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 1rem;
  font-family: inherit;
  width: 90px;
  outline: none;
}

.ctrl-input:focus {
  border-color: var(--accent2);
  box-shadow: 0 0 0 3px rgba(13,148,136,0.1);
}

/* ── Radio Group (Heater Mode) ───────────────── */

.radio-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.radio-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.15s;
}

.radio-option:hover {
  border-color: var(--border-hover);
  background: var(--bg);
}

.radio-option:has(input:checked) {
  border-color: var(--accent2);
  background: var(--accent2-light);
}

.radio-option input[type="radio"] {
  accent-color: var(--accent2);
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.radio-label {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}

.radio-desc {
  font-size: 11px;
  color: var(--text-muted);
  margin-left: auto;
}

/* ── Slider (Modal) ──────────────────────────── */

.ctrl-slider-wrap {
  margin: 0 0 14px;
  padding: 14px;
  background: var(--bg);
  border-radius: 10px;
}

.ctrl-slider-top {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.ctrl-slider-top strong {
  color: var(--accent2);
  font-size: 14px;
}

.ctrl-slider {
  width: 100%;
  accent-color: var(--accent2);
  cursor: pointer;
}

.ctrl-slider-labels {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ── Collapsible Advanced Settings ───────────── */

.ctrl-advanced {
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 4px;
}

.ctrl-advanced summary {
  padding: 12px 16px;
  cursor: pointer;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  font-weight: 600;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.ctrl-advanced summary::-webkit-details-marker { display: none; }
.ctrl-advanced summary::after { content: '▸'; transition: transform 0.2s; }
.ctrl-advanced[open] summary::after { transform: rotate(90deg); }
.ctrl-advanced[open] summary { border-bottom: 1px solid var(--border); }

.ctrl-advanced-body { padding: 16px; }

.cfg-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.cfg-label {
  font-size: 12px;
  color: var(--text-secondary);
  width: 130px;
  flex-shrink: 0;
}

.cfg-unit {
  font-size: 11px;
  color: var(--text-muted);
  width: 30px;
}

.cfg-input {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 0.9rem;
  font-family: inherit;
  width: 70px;
  outline: none;
}

.cfg-input:focus { border-color: var(--accent2); }

.ctrl-fw {
  margin-top: 10px;
  font-size: 11px;
  color: var(--text-muted);
}

/* ── Modal Buttons ───────────────────────────── */

.cbtn {
  padding: 8px 14px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 0.84rem;
  font-weight: 600;
  font-family: inherit;
  transition: opacity 0.15s;
  white-space: nowrap;
}

.cbtn:hover { opacity: 0.82; }
.cbtn:disabled { opacity: 0.4; cursor: default; }

.cbtn-primary { background: var(--accent2); color: #fff; }
.cbtn-danger  { background: var(--danger); color: #fff; }
.cbtn-neutral { background: var(--bg); color: var(--text-secondary); border: 1px solid var(--border); }
.cbtn-purple  { background: #7c3aed; color: #fff; }

.cbtn-close {
  background: var(--bg);
  color: var(--text-muted);
  width: 100%;
  margin-top: 12px;
  border: 1px solid var(--border);
}

.cmd-status {
  margin-top: 12px;
  font-size: 0.82rem;
  min-height: 18px;
  color: var(--accent2);
  font-weight: 500;
  display: none;
}

.cmd-status.error { color: var(--danger); }

/* Toast notification inside modal */
.ctrl-toast {
  position: sticky;
  top: 0;
  z-index: 10;
  margin: -28px -24px 16px;
  padding: 10px 16px;
  font-size: 0.82rem;
  font-weight: 600;
  text-align: center;
  border-radius: 16px 16px 0 0;
  transform: translateY(-100%);
  opacity: 0;
  transition: transform 0.3s ease, opacity 0.3s ease;
  pointer-events: none;
}
.ctrl-toast.show {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
}
.ctrl-toast.success {
  background: var(--accent2);
  color: #fff;
}
.ctrl-toast.error {
  background: var(--danger);
  color: #fff;
}
.ctrl-toast.pending {
  background: var(--text-muted);
  color: #fff;
}

/* Command Log */
.cmd-log { max-height: 220px; overflow-y: auto; }
.cmd-log-row {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 0; border-bottom: 1px solid var(--border);
  font-size: 0.78rem;
}
.cmd-log-row:last-child { border-bottom: none; }
.cmd-badge {
  display: inline-block; padding: 2px 7px; border-radius: 6px;
  font-size: 0.7rem; font-weight: 600; white-space: nowrap;
}
.cmd-badge.pending  { background: #f59e0b22; color: #f59e0b; }
.cmd-badge.sent     { background: #3b82f622; color: #3b82f6; }
.cmd-badge.applied  { background: #10b98122; color: #10b981; }
.cmd-badge.failed   { background: #ef444422; color: #ef4444; }
.cmd-log-type { font-weight: 600; flex: 1; }
.cmd-log-time { color: var(--text-muted); font-size: 0.72rem; }

/* ── Event Modal ─────────────────────────────── */

.evt-field {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.95rem;
  font-family: inherit;
  width: 100%;
  box-sizing: border-box;
  outline: none;
  margin-top: 6px;
}

.evt-field:focus {
  border-color: var(--accent2);
  box-shadow: 0 0 0 3px rgba(13,148,136,0.1);
}

textarea.evt-field {
  resize: vertical;
  min-height: 60px;
}

.evt-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 12px;
  display: block;
}

.evt-label:first-of-type { margin-top: 0; }

.evt-status {
  font-size: 0.82rem;
  min-height: 18px;
  color: var(--accent2);
  font-weight: 500;
  margin-top: 10px;
}

.evt-status.error { color: var(--danger); }

/* ── Footer ──────────────────────────────────── */

.ota-empty {
  padding: 16px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  color: var(--text-muted);
}

.btn-add:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.flash-panel,
.flash-history-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

.flash-head {
  margin-bottom: 10px;
}

.flash-device-toggle {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  margin-bottom: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}

.flash-device {
  min-width: 96px;
  padding: 8px 12px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.flash-device.active {
  color: #fff;
  background: var(--accent2);
}

.flash-form {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.flash-form input[type="text"] {
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 13px;
}

#btnOneClickFlash {
  background: #f3f4f6;
  border-color: var(--border);
  color: var(--text-muted);
  font-weight: 800;
  min-height: 38px;
}

#btnOneClickFlash.is-ready {
  background: var(--online);
  border-color: var(--online);
  color: #fff;
}

#btnOneClickFlash.is-ready:hover {
  background: #16a34a;
  border-color: #16a34a;
  color: #fff;
}

#btnOneClickFlash:disabled {
  cursor: not-allowed;
  opacity: 1;
}

#btnOneClickFlash.is-flashing {
  background: #f59e0b;
  border-color: #f59e0b;
  color: #111827;
}

.flash-file-hint {
  margin-bottom: 8px;
  font-size: 12px;
  color: var(--text-muted);
  font-family: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
}

.flash-flow-status {
  display: none;
}

.flash-main-progress {
  margin-top: 12px;
}

.flash-main-progress-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
  font-size: 13px;
  color: var(--text-secondary);
}

.flash-main-progress-head strong {
  color: var(--text-primary);
}

.flash-main-progress-track {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--border);
}

.flash-main-progress-track > div {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--accent2);
  transition: width 0.35s ease, background-color 0.2s ease;
}

.flash-main-progress.ok .flash-main-progress-track > div {
  background: #22c55e;
}

.flash-main-progress.fail .flash-main-progress-track > div {
  background: var(--danger);
}

.flash-ok { color: #166534; font-weight: 700; }
.flash-error { color: var(--danger); font-weight: 700; }

.flash-history {
  margin-top: 12px;
  display: grid;
  gap: 8px;
}

.flash-history-row {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) 2fr;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-radius: 8px;
  background: var(--bg);
  font-size: 12px;
}

.flash-history-row.ok { border-left-color: var(--online); }
.flash-history-row.active { border-left-color: #f59e0b; }
.flash-history-row.fail { border-left-color: var(--danger); }
.flash-history-row.muted { border-left-color: var(--border-hover); }

.flash-history-row > div {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.flash-history-row strong {
  color: var(--text);
}

.flash-history-row span {
  color: var(--text-secondary);
}

.flash-history-status {
  font-weight: 700;
  text-transform: uppercase;
}

.flash-history-error {
  color: var(--danger) !important;
}

.last-update {
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  padding: 12px 0 32px;
}

/* ── Loading ─────────────────────────────────── */

.loading {
  text-align: center;
  padding: 40px 24px;
  color: var(--text-muted);
  font-size: 14px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

/* ── Animations ──────────────────────────────── */

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Responsive ──────────────────────────────── */

@media (max-width: 980px) {
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .header-inner { flex-direction: column; align-items: flex-start; }
}

@media (max-width: 768px) {
  .container { padding: 0 16px; }
  header { padding-top: 16px; }
  .logo-text { font-size: 20px; }
  .hive-grid { grid-template-columns: 1fr; }
  .chart-header { flex-direction: column; align-items: flex-start; }
  .chart-section { padding: 16px; }
  .stat-value { font-size: 24px; }
  .tabs { gap: 2px; }
  .tab { padding: 8px 10px; font-size: 12px; }
  .diag-grid { grid-template-columns: repeat(2, 1fr); }
  .journal-header { flex-direction: column; align-items: flex-start; }
  .flash-head { flex-direction: column; }
  .flash-form { grid-template-columns: 1fr; }
  .flash-history-row { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .stats-row { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat-card { padding: 12px; }
  .stat-value { font-size: 22px; }
  .metric-value { font-size: 18px; }
  .diag-grid { grid-template-columns: 1fr 1fr; }
  .chart-toggles { gap: 6px 10px; padding: 10px; }
}

/* ═══ Raw Log Table (Дневник) ═══ */
.raw-log-controls {
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--text-secondary);
}
.raw-log-controls label { cursor: pointer; }
.raw-log-controls input[type="checkbox"] { margin-right: 4px; vertical-align: middle; }

.raw-log-wrap {
  max-height: 500px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.raw-log-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  font-family: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
}
.raw-log-table thead { position: sticky; top: 0; z-index: 1; }
.raw-log-table th {
  background: var(--bg);
  padding: 6px 8px;
  text-align: left;
  font-weight: 600;
  font-size: 11px;
  color: var(--text-secondary);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}
.raw-log-table td {
  padding: 4px 8px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.raw-log-table tr:hover { background: var(--accent-light); }
.raw-log-table .ghost-row { background: #f9fafb; color: var(--text-muted); }
.raw-log-table .ghost-row:hover { background: #f3f4f6; }
.raw-log-table .cutoff-row { background: var(--danger-light); }
.raw-log-table .fail-row { background: #fffbeb; }
.raw-log-table .sensor-ok { color: var(--online); font-weight: 600; }
.raw-log-table .sensor-fail { color: var(--danger); font-weight: 600; }
.raw-log-table .safety-bad { color: var(--danger); font-weight: 600; }
.raw-log-table .null-val { color: var(--text-muted); }
