:root {
  color-scheme: dark;
  --bg: #0f1419;
  --card: #1a222d;
  --border: #2a3544;
  --text: #e8eef5;
  --muted: #8b9bb0;
  --accent: #3dd68c;
  --warn: #ffb020;
  --danger: #ff6b6b;
  --pv: #f5c842;
  --grid-import: #ff8a65;
  --grid-export: #64b5f6;
  --battery: #81c784;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: radial-gradient(circle at top, #1b2838 0%, var(--bg) 55%);
  color: var(--text);
  padding:
    env(safe-area-inset-top, 0)
    env(safe-area-inset-right, 0)
    env(safe-area-inset-bottom, 0)
    env(safe-area-inset-left, 0);
}

.offline-banner {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: 0.55rem 1rem;
  text-align: center;
  font-size: 0.85rem;
  background: rgba(255, 176, 32, 0.15);
  border-bottom: 1px solid rgba(255, 176, 32, 0.35);
  color: #ffd166;
}

.header, .footer, main {
  max-width: 960px;
  margin: 0 auto;
  padding: 1rem 1.25rem;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}

h1 { margin: 0; font-size: 1.5rem; }
h2 { margin: 0 0 1rem; font-size: 1rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }

.subtitle { margin: 0.25rem 0 0; color: var(--muted); font-size: 0.9rem; }

.meta { text-align: right; font-size: 0.85rem; color: var(--muted); display: flex; align-items: center; gap: 0.5rem; }

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}
.dot-ok { background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.dot-warn { background: var(--warn); }
.dot-unknown { background: #555; }

.grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

@media (min-width: 720px) {
  .grid { grid-template-columns: 1.2fr 0.8fr; }
  .card-wide { grid-column: 1 / -1; }
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1.25rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}

.metrics {
  display: grid;
  gap: 0.75rem;
}
.metrics-4 { grid-template-columns: repeat(2, 1fr); }
.metrics-2 { grid-template-columns: repeat(2, 1fr); margin-top: 1rem; }

@media (min-width: 520px) {
  .metrics-4 { grid-template-columns: repeat(4, 1fr); }
}

.metric {
  background: rgba(255, 255, 255, 0.03);
  border-radius: 12px;
  padding: 0.75rem;
  border: 1px solid transparent;
  transition: border-color 0.3s, background 0.3s;
}

.status-badge {
  display: block;
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.2rem;
  min-height: 0.85rem;
  color: var(--muted);
}

.metric.status-neutral { border-color: rgba(139, 155, 176, 0.25); }
.metric.status-red {
  border-color: rgba(255, 107, 107, 0.45);
  background: rgba(255, 107, 107, 0.08);
}
.metric.status-red .status-badge { color: #ff9a9a; }
.metric.status-yellow {
  border-color: rgba(255, 176, 32, 0.45);
  background: rgba(255, 176, 32, 0.08);
}
.metric.status-yellow .status-badge { color: #ffd166; }
.metric.status-green {
  border-color: rgba(61, 214, 140, 0.45);
  background: rgba(61, 214, 140, 0.08);
}
.metric.status-green .status-badge { color: #7dffb8; }

.label { display: block; font-size: 0.75rem; color: var(--muted); margin-bottom: 0.25rem; }
.value { font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; }

.hint { margin: 1rem 0 0; font-size: 0.8rem; color: var(--muted); }
.hint a { color: var(--grid-export); }

.error {
  margin-top: 0.75rem;
  color: var(--danger);
  font-size: 0.85rem;
}

.soc-ring {
  position: relative;
  width: 140px;
  height: 140px;
  margin: 0 auto 0.5rem;
}

.soc-ring svg { transform: rotate(-90deg); width: 100%; height: 100%; }
.soc-bg { fill: none; stroke: #2a3544; stroke-width: 10; }
.soc-fg {
  fill: none;
  stroke: var(--accent);
  stroke-width: 10;
  stroke-linecap: round;
  stroke-dasharray: 327;
  stroke-dashoffset: 327;
  transition: stroke-dashoffset 0.6s ease, stroke 0.3s;
}

.soc-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  font-weight: 700;
}
.soc-label small { font-size: 1rem; color: var(--muted); margin-left: 2px; }

.metrics-1 { grid-template-columns: 1fr; margin-top: 0.75rem; }

.charge-source {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin-top: 1rem;
  padding: 0.85rem 1rem;
  border-radius: 12px;
  font-weight: 600;
  border: 1px solid transparent;
}
.charge-source small {
  display: block;
  font-weight: 400;
  font-size: 0.75rem;
  opacity: 0.85;
  margin-top: 0.15rem;
}
.charge-source-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
}
.charge-source-text { line-height: 1.3; }
.charge-source-green {
  background: rgba(61, 214, 140, 0.12);
  border-color: rgba(61, 214, 140, 0.35);
  color: #7dffb8;
}
.charge-source-green .charge-source-dot { background: #3dd68c; box-shadow: 0 0 10px #3dd68c; }
.charge-source-yellow {
  background: rgba(255, 176, 32, 0.12);
  border-color: rgba(255, 176, 32, 0.35);
  color: #ffd166;
}
.charge-source-yellow .charge-source-dot { background: #ffb020; box-shadow: 0 0 10px #ffb020; }
.charge-source-red {
  background: rgba(255, 107, 107, 0.12);
  border-color: rgba(255, 107, 107, 0.35);
  color: #ff9a9a;
}
.charge-source-red .charge-source-dot { background: #ff6b6b; box-shadow: 0 0 10px #ff6b6b; }
.charge-source-gray {
  background: rgba(139, 155, 176, 0.1);
  border-color: rgba(139, 155, 176, 0.25);
  color: var(--muted);
}
.charge-source-gray .charge-source-dot { background: #6b7785; }

.footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.75rem;
  padding-bottom: 2rem;
}

.import { color: var(--grid-import); }
.export { color: var(--grid-export); }
.pv { color: var(--pv); }
.battery { color: var(--battery); }
