:root {
  --font-display: 'Space Grotesk', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

/* ---------- Dark Theme (Standard) ---------- */
:root,
[data-theme="dark"] {
  --bg: #0a0d11;
  --bg-alt: #0e1218;
  --panel: #121720;
  --panel-border: #1e2530;
  --text: #e7ebf0;
  --text-dim: #8b95a5;
  --text-faint: #4f5868;

  --amber: #ff9f43;
  --cyan: #4fd1c5;
  --green: #5ce0a0;
  --red: #ff5c5c;
  --yellow: #f4c95d;

  --grid-line: rgba(255,255,255,0.025);
  --shadow: 0 1px 0 rgba(255,255,255,0.02) inset;
}

/* ---------- Light Theme ---------- */
[data-theme="light"] {
  --bg: #f3f5f8;
  --bg-alt: #eaedf2;
  --panel: #ffffff;
  --panel-border: #dde2ea;
  --text: #1c232e;
  --text-dim: #5b6675;
  --text-faint: #9aa3b2;

  --amber: #e07a1f;
  --cyan: #1f9d8f;
  --green: #1e9e63;
  --red: #d23d3d;
  --yellow: #b9851b;

  --grid-line: rgba(20,30,45,0.035);
  --shadow: 0 1px 0 rgba(0,0,0,0.02) inset;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-display);
  min-height: 100vh;
  transition: background 0.25s ease, color 0.25s ease;
}

.bg-grid {
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(to right, var(--grid-line) 1px, transparent 1px),
    linear-gradient(to bottom, var(--grid-line) 1px, transparent 1px);
  background-size: 42px 42px;
  pointer-events: none;
  z-index: 0;
  mask-image: radial-gradient(ellipse 80% 60% at 50% 0%, black 40%, transparent 90%);
}

.topbar, .layout { position: relative; z-index: 1; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px 32px;
  border-bottom: 1px solid var(--panel-border);
  flex-wrap: wrap;
  gap: 12px;
}

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

.logo-mark {
  color: var(--cyan);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  background: var(--panel);
}

.topbar-title { display: flex; flex-direction: column; gap: 2px; }

.eyebrow {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.topbar h1 {
  margin: 0;
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
  font-family: var(--font-mono);
  font-size: 12px;
}

.datetime {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.4;
  color: var(--text-dim);
}
.datetime #dateNow { font-size: 11px; color: var(--text-faint); }
.datetime #timeNow { font-size: 13px; font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }

.theme-toggle {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.theme-toggle:hover { color: var(--text); border-color: var(--text-faint); }
.theme-toggle .icon-moon { display: none; }
[data-theme="light"] .theme-toggle .icon-sun { display: none; }
[data-theme="light"] .theme-toggle .icon-moon { display: block; }

.conn-status { display: flex; align-items: center; gap: 7px; color: var(--text-dim); }

.dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text-faint);
}
.dot--pending { background: var(--yellow); animation: blink 1.2s infinite; }
.dot--ok { background: var(--green); }
.dot--error { background: var(--red); }

@keyframes blink { 50% { opacity: 0.3; } }

/* ---------- Layout ---------- */
.layout {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

/* ---------- Hero cards ---------- */
.hero {
  display: grid;
  grid-template-columns: 1.1fr 0.8fr 1.2fr 1fr;
  gap: 18px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 22px 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-label {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.pulse {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 0 0 rgba(79,209,197,0.6);
  animation: pulse-ring 2.2s infinite;
}
@keyframes pulse-ring {
  0% { box-shadow: 0 0 0 0 rgba(79,209,197,0.55); }
  70% { box-shadow: 0 0 0 9px rgba(79,209,197,0); }
  100% { box-shadow: 0 0 0 0 rgba(79,209,197,0); }
}

/* Temp card */
.card--temp { justify-content: flex-start; }

.temp-readout {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-top: 4px;
}
.temp-value {
  font-family: var(--font-mono);
  font-size: 60px;
  font-weight: 600;
  line-height: 1;
  color: var(--cyan);
  font-variant-numeric: tabular-nums;
}
.temp-unit {
  font-family: var(--font-mono);
  font-size: 22px;
  color: var(--text-dim);
}

.card-foot {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-faint);
  margin-top: auto;
}

.error-banner {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  background: rgba(255, 92, 92, 0.08);
  border: 1px solid rgba(255, 92, 92, 0.35);
  color: var(--red);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 12.5px;
  line-height: 1.4;
  font-family: var(--font-mono);
}
.error-banner svg { flex-shrink: 0; margin-top: 1px; }

/* Battery card */
.card--batt { align-items: stretch; }
.batt-volt {
  font-family: var(--font-mono);
  font-size: 14px;
  color: var(--amber);
  font-variant-numeric: tabular-nums;
}

.cell-wrap {
  display: flex;
  justify-content: center;
  align-items: center;
  flex: 1;
  padding: 4px 0;
}

.cell-svg {
  width: 78px;
  height: 156px;
  color: var(--text-faint);
}
.cell-body { color: var(--panel-border); }
.cell-nub { color: var(--panel-border); }
.cell-fill {
  fill: var(--green);
  transition: y 0.6s ease, height 0.6s ease, fill 0.6s ease;
}
.cell-pct {
  font-family: var(--font-mono);
  font-size: 17px;
  font-weight: 600;
  fill: var(--text);
  text-anchor: middle;
  paint-order: stroke;
  stroke: var(--panel);
  stroke-width: 6px;
}

/* Weather card */
.card--weather { gap: 6px; }
.weather-body {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 4px;
}
.weather-icon { color: var(--amber); flex-shrink: 0; }
.weather-temp {
  font-family: var(--font-mono);
  font-size: 38px;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.weather-text {
  font-size: 13px;
  color: var(--text-dim);
}

.weather-forecast {
  display: flex;
  gap: 8px;
  margin-top: 6px;
  padding-top: 12px;
  border-top: 1px dashed var(--panel-border);
}
.forecast-day {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  text-align: center;
}
.forecast-day .fd-label {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.forecast-day .fd-icon {
  color: var(--amber);
  width: 22px;
  height: 22px;
}
.forecast-day .fd-temps {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-dim);
  white-space: nowrap;
}
.forecast-day .fd-temps .fd-max {
  color: var(--text);
  font-weight: 600;
}

/* Stats card */
.stat-list { margin: 4px 0 0; display: flex; flex-direction: column; gap: 12px; }
.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  border-bottom: 1px dashed var(--panel-border);
  padding-bottom: 10px;
}
.stat-row:last-child { border-bottom: none; padding-bottom: 0; }
.stat-row dt {
  font-size: 12.5px;
  color: var(--text-dim);
}
.stat-row dd {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.stat-row--warn dd { color: var(--red); }

/* ---------- Charts ---------- */
.charts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 20px 22px 16px;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  flex-wrap: wrap;
  gap: 10px;
}

.panel-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.range-switch {
  display: flex;
  background: var(--bg-alt);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 3px;
  gap: 2px;
}
.range-switch button {
  font-family: var(--font-mono);
  font-size: 11px;
  border: none;
  background: transparent;
  color: var(--text-faint);
  padding: 5px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.range-switch button:hover { color: var(--text-dim); }
.range-switch button.active {
  background: var(--panel-border);
  color: var(--text);
}

.chart-holder {
  position: relative;
  height: 260px;
}

.panel-note {
  margin: 12px 0 0;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-faint);
}

/* ---------- Footer ---------- */
.footer {
  display: flex;
  justify-content: center;
  gap: 10px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-faint);
  padding: 12px 0 28px;
}

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .hero { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 920px) {
  .hero { grid-template-columns: 1fr; }
  .charts { grid-template-columns: 1fr; }
  .topbar { padding: 18px; }
  .layout { padding: 18px; }
  .topbar-right { width: 100%; justify-content: space-between; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .pulse, .dot--pending { animation: none; }
  .cell-fill { transition: none; }
  html, body { transition: none; }
}
