:root {
  --bg-gradient: radial-gradient(circle at 10% 20%, #111827 0%, #0a0e17 90%);
  --card-bg: rgba(17, 24, 39, 0.72);
  --card-border: rgba(255, 255, 255, 0.08);
  --card-hover-border: rgba(56, 189, 248, 0.3);
  --text-main: #f9fafb;
  --text-muted: #9ca3af;
  --text-dim: #6b7280;
  --accent-blue: #38bdf8;
  --accent-cyan: #06b6d4;
  --accent-orange: #fb923c;
  --accent-green: #34d399;
  --accent-purple: #c084fc;
  --accent-red: #f87171;
  --status-cooling: #0ea5e9;
  --status-heating: #f97316;
  --status-idle: #64748b;
  --status-fan: #10b981;
}

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

body {
  font-family: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg-gradient);
  background-color: #0a0e17;
  color: var(--text-main);
  min-height: 100vh;
  padding: 24px;
  line-height: 1.5;
}

.container { max-width: 1680px; margin: 0 auto; }

/* Header */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--card-border);
}

.brand { display: flex; align-items: center; gap: 14px; }

.brand-icon {
  width: 48px;
  height: 48px;
  background: linear-gradient(135deg, #0284c7, #06b6d4);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(14, 165, 233, 0.4);
  font-size: 24px;
}

h1 { font-size: 24px; font-weight: 700; letter-spacing: -0.5px; }
.subtitle { font-size: 13px; color: var(--text-muted); }

.header-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

.btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--card-border);
  color: var(--text-main);
  padding: 8px 16px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s ease;
  font-family: inherit;
  text-decoration: none;
}

.btn:hover { background: rgba(255, 255, 255, 0.12); transform: translateY(-1px); }

.btn-primary {
  background: linear-gradient(135deg, #0284c7, #2563eb);
  border-color: #38bdf8;
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.35);
}
.btn-primary:hover { background: linear-gradient(135deg, #0369a1, #1d4ed8); }

.range-picker {
  display: inline-flex;
  background: rgba(0, 0, 0, 0.3);
  padding: 3px;
  border-radius: 10px;
  border: 1px solid var(--card-border);
}

.range-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 7px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.range-btn:hover { color: var(--text-main); }
.range-btn.active {
  background: #0284c7;
  color: #fff;
  box-shadow: 0 2px 8px rgba(2, 132, 199, 0.4);
}

.pulse {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #34d399;
  display: inline-block;
  animation: pulse-glow 2s infinite;
}

@keyframes pulse-glow {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(52, 211, 153, 0.7); }
  70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(52, 211, 153, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(52, 211, 153, 0); }
}

.last-updated { font-size: 12px; color: var(--text-muted); display: inline-flex; align-items: center; gap: 6px; }

/* Auto-Refresh Toggle Switch */
.auto-refresh-wrap {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-size: 13px;
  color: var(--text-muted);
  user-select: none;
  cursor: pointer;
}

.switch {
  position: relative;
  display: inline-block;
  width: 38px;
  height: 20px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: rgba(255, 255, 255, 0.12);
  transition: .25s ease;
  border-radius: 20px;
  border: 1px solid var(--card-border);
}

.slider:before {
  position: absolute;
  content: "";
  height: 14px;
  width: 14px;
  left: 2px;
  bottom: 2px;
  background-color: #cbd5e1;
  transition: .25s ease;
  border-radius: 50%;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}

input:checked + .slider {
  background-color: #0284c7;
  border-color: #38bdf8;
}

input:checked + .slider:before {
  transform: translateX(18px);
  background-color: #fff;
}

/* Diagnostic Grid */
.section-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--accent-blue);
  margin: 28px 0 14px 2px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.refresh-badge {
  font-size: 11px;
  font-weight: 500;
  text-transform: none;
  letter-spacing: normal;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--card-border);
  padding: 3px 9px;
  border-radius: 6px;
  margin-left: auto;
  transition: all 0.2s ease;
}

.refresh-badge.updating {
  color: var(--accent-blue);
  border-color: rgba(56, 189, 248, 0.4);
  background: rgba(56, 189, 248, 0.1);
}

.grid-summary {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-radius: 14px;
  padding: 16px 14px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  position: relative;
  overflow: hidden;
  transition: border-color 0.2s ease, transform 0.2s ease;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.card:hover { border-color: var(--card-hover-border); }

.card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; height: 3px;
  background: linear-gradient(90deg, transparent, rgba(56, 189, 248, 0.4), transparent);
}

.card-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.temp-hero {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin: 2px 0 6px 0;
}

.temp-val {
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -1.5px;
  line-height: 1;
}

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

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 20px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.3px;
}

.badge-cooling { background: rgba(14, 165, 233, 0.2); color: #38bdf8; border: 1px solid rgba(14, 165, 233, 0.4); }
.badge-heating { background: rgba(249, 115, 22, 0.2); color: #fb923c; border: 1px solid rgba(249, 115, 22, 0.4); }
.badge-idle { background: rgba(100, 116, 139, 0.2); color: #94a3b8; border: 1px solid rgba(100, 116, 139, 0.4); }
.badge-fan { background: rgba(16, 185, 129, 0.2); color: #34d399; border: 1px solid rgba(16, 185, 129, 0.4); }
.badge-diag { background: rgba(192, 132, 252, 0.15); color: #c084fc; border: 1px solid rgba(192, 132, 252, 0.3); }

.metrics-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 6px;
  margin-top: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--card-border);
  flex: 1;
}

.metric-item { display: flex; flex-direction: column; justify-content: center; }
.metric-label { font-size: 9.5px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.metric-val { font-size: 13px; font-weight: 600; color: var(--text-main); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.metric-sub { font-size: 10px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Charts */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(460px, 1fr));
  gap: 20px;
  margin-top: 16px;
}

.chart-card { height: 360px; display: flex; flex-direction: column; }
.chart-container { flex: 1; position: relative; width: 100%; min-height: 270px; }

/* Table */
.table-card { margin-top: 24px; margin-bottom: 28px; overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 12px; }
th {
  text-align: left;
  padding: 10px 12px;
  color: var(--text-muted);
  font-weight: 500;
  border-bottom: 1px solid var(--card-border);
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.5px;
  background: rgba(0, 0, 0, 0.2);
}
td {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
}
tr:hover td { background: rgba(255, 255, 255, 0.03); }

/* Footer */
footer {
  text-align: center;
  font-size: 12px;
  color: var(--text-dim);
  padding: 20px 0;
  border-top: 1px solid var(--card-border);
}

/* Navigation Tabs */
.nav-tabs {
  display: inline-flex;
  gap: 8px;
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 6px;
  margin: 18px 0 24px 0;
  backdrop-filter: blur(12px);
}

.tab-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  font-family: 'Outfit', sans-serif;
  font-size: 14px;
  font-weight: 500;
  padding: 10px 22px;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  user-select: none;
}

.tab-btn:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.05);
}

.tab-btn.active {
  color: #ffffff;
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.18), rgba(59, 130, 246, 0.25));
  border-color: rgba(56, 189, 248, 0.45);
  box-shadow: 0 0 16px rgba(56, 189, 248, 0.2);
}

.tab-icon {
  font-size: 16px;
}

/* Daily Header & Controls */
.daily-header-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 22px;
  padding: 18px 22px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 12px;
}

.daily-title-group h2 {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-main);
  margin: 0 0 4px 0;
}

.daily-subtitle {
  font-size: 13px;
  color: var(--text-muted);
}

.daily-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.rate-input-wrap {
  display: flex;
  align-items: center;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  padding: 5px 12px;
  font-size: 13px;
  color: var(--text-muted);
}

.rate-input-wrap input {
  width: 58px;
  background: transparent;
  border: none;
  color: #34d399;
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  outline: none;
}

.rate-unit {
  font-size: 11px;
  color: var(--text-dim);
  margin-left: 2px;
}

.daily-range-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: 'Outfit', sans-serif;
  font-size: 12px;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.daily-range-btn:hover {
  color: var(--text-main);
}

.daily-range-btn.active {
  background: rgba(56, 189, 248, 0.2);
  color: #38bdf8;
  font-weight: 600;
}

@media (max-width: 1380px) {
  .grid-summary { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 900px) {
  .grid-summary { grid-template-columns: repeat(2, 1fr); }
  .charts-grid { grid-template-columns: 1fr; }
  .daily-header-bar { flex-direction: column; align-items: flex-start; }
}

@media (max-width: 580px) {
  .grid-summary { grid-template-columns: 1fr; }
  .nav-tabs { width: 100%; display: flex; }
  .tab-btn { flex: 1; justify-content: center; padding: 10px 12px; font-size: 12px; }
}
