:root {
  --bg: #070b16;
  --bg-2: #0b1222;
  --card: rgba(20, 29, 51, 0.72);
  --card-brd: rgba(120, 150, 220, 0.14);
  --ink: #eaf0ff;
  --muted: #8a97b8;
  --pv: #ffb020;
  --pv-2: #ff7a45;
  --load: #38e0c8;
  --grid: #6c8cff;
  --battery: #4ade80;
  --danger: #ff5c72;
  --radius: 20px;
  --shadow: 0 18px 50px -24px rgba(0, 0, 0, 0.8);
  font-synthesis: none;
}

* { box-sizing: border-box; margin: 0; }
[hidden] { display: none !important; }

body {
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1100px 700px at 80% -10%, rgba(255, 176, 32, 0.10), transparent 55%),
    radial-gradient(900px 700px at -10% 20%, rgba(108, 140, 255, 0.12), transparent 55%),
    var(--bg);
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  letter-spacing: -0.01em;
}

h1, h2, .hero-value, .kpi-value, .brand h1 {
  font-family: 'Space Grotesk', 'Inter', system-ui, sans-serif;
  letter-spacing: -0.02em;
}

.muted { color: var(--muted); }
.small { font-size: 0.8rem; }
.unit { font-size: 0.5em; color: var(--muted); font-weight: 500; margin-left: 0.25em; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px clamp(14px, 4vw, 28px);
  position: sticky; top: 0; z-index: 20;
  background: linear-gradient(180deg, rgba(7, 11, 22, 0.92), rgba(7, 11, 22, 0.55));
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--card-brd);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  display: grid; place-items: center;
  width: 42px; height: 42px; border-radius: 13px;
  font-size: 22px;
  background: linear-gradient(145deg, var(--pv), var(--pv-2));
  color: #1a1000; box-shadow: 0 8px 24px -8px rgba(255, 140, 40, 0.7);
}
.brand-mark.big { width: 64px; height: 64px; font-size: 34px; border-radius: 20px; }
.brand h1 { font-size: 1.15rem; font-weight: 700; line-height: 1; }
.topbar-sub { display: flex; align-items: center; gap: 7px; margin-top: 4px; font-size: 0.78rem; color: var(--muted); }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.5); }
.status-dot.live { background: var(--battery); animation: pulse 2s infinite; }
.status-dot.stale { background: var(--pv); }
.status-dot.offline { background: var(--danger); }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.55); }
  70% { box-shadow: 0 0 0 8px rgba(74, 222, 128, 0); }
  100% { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0); }
}

.ghost-btn {
  background: rgba(255, 255, 255, 0.04); color: var(--ink);
  border: 1px solid var(--card-brd); border-radius: 12px;
  padding: 9px 14px; font: inherit; font-size: 0.85rem; cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.ghost-btn:hover { background: rgba(255, 255, 255, 0.09); border-color: rgba(120, 150, 220, 0.3); }

/* ---------- Layout ---------- */
.wrap {
  max-width: 1080px; margin: 0 auto;
  padding: 18px clamp(14px, 4vw, 28px) 60px;
  display: grid; gap: 16px;
}
@media (min-width: 780px) {
  .wrap { grid-template-columns: 1fr 1fr; align-items: start; }
  .hero, .chart-card { grid-column: 1 / -1; }
}

.card {
  background: var(--card);
  border: 1px solid var(--card-brd);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.card-head h2 { font-size: 1rem; font-weight: 600; }
.eyebrow { text-transform: uppercase; letter-spacing: 0.14em; font-size: 0.68rem; color: var(--muted); font-weight: 600; }

/* ---------- Hero ---------- */
.hero-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; }
.hero-value { font-size: clamp(2.8rem, 12vw, 4.2rem); font-weight: 700; line-height: 0.95; margin-top: 4px;
  background: linear-gradient(120deg, var(--pv), var(--pv-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero-today { text-align: right; }
.hero-today-value { font-size: 1.3rem; font-weight: 600; font-family: 'Space Grotesk', sans-serif; margin-top: 4px; }
.flow { margin-top: 6px; }
.flow svg { width: 100%; height: auto; display: block; }

/* flow node labels */
.flow-label { font: 600 13px 'Inter', sans-serif; fill: var(--ink); }
.flow-sub { font: 500 11px 'Inter', sans-serif; fill: var(--muted); }

/* ---------- KPI grid ---------- */
.kpi-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (min-width: 780px) { .kpi-grid { grid-template-columns: repeat(4, 1fr); grid-column: 1 / -1; } }
.kpi { position: relative; overflow: hidden; }
.kpi::before { content: ''; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--muted); }
.kpi[data-accent="pv"]::before { background: linear-gradient(var(--pv), var(--pv-2)); }
.kpi[data-accent="load"]::before { background: var(--load); }
.kpi[data-accent="grid"]::before { background: var(--grid); }
.kpi[data-accent="battery"]::before { background: var(--battery); }
.kpi-label { font-size: 0.82rem; color: var(--muted); font-weight: 500; }
.kpi-value { font-size: 1.9rem; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; }
.kpi-battery { grid-column: span 2; }
@media (min-width: 780px) { .kpi-battery { grid-column: span 1; } }
.battery-row { display: flex; align-items: center; gap: 16px; margin-top: 8px; }
.battery-meta p { font-size: 0.95rem; font-weight: 600; }

/* SOC ring */
.soc-ring {
  --pct: 0; --ring: var(--battery);
  width: 74px; height: 74px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  background: conic-gradient(var(--ring) calc(var(--pct) * 1%), rgba(255,255,255,0.08) 0);
  position: relative; font-weight: 700; font-family: 'Space Grotesk', sans-serif;
}
.soc-ring::after { content: ''; position: absolute; inset: 8px; border-radius: 50%; background: var(--bg-2); }
.soc-ring span, .soc-ring small { position: relative; z-index: 1; }
.soc-ring small { color: var(--muted); font-size: 0.7rem; }

/* ---------- Segmented control ---------- */
.seg { display: inline-flex; background: rgba(9, 14, 28, 0.7); border: 1px solid var(--card-brd); border-radius: 11px; padding: 3px; }
.seg button {
  font: inherit; font-size: 0.8rem; font-weight: 500; color: var(--muted);
  background: none; border: none; border-radius: 8px; padding: 6px 14px; cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.seg button.active { background: rgba(74, 222, 128, 0.16); color: var(--battery); }

/* ---------- SOC section ---------- */
.soc-stats { display: flex; align-items: center; gap: 22px; margin-bottom: 16px; }
.soc-ring-lg { width: 92px; height: 92px; font-size: 1.4rem; --ring: var(--battery); }
.soc-figures { display: flex; gap: 24px; flex-wrap: wrap; }
.soc-figures p:first-child { font-size: 0.76rem; }
.soc-figures b { font-size: 1.35rem; font-weight: 700; font-family: 'Space Grotesk', sans-serif; }

/* ---------- Chart ---------- */
.chart { width: 100%; }
.chart svg { width: 100%; height: auto; display: block; }
.legend { display: flex; gap: 12px; font-size: 0.76rem; color: var(--muted); }
.lg { display: inline-flex; align-items: center; gap: 6px; }
.lg::before { content: ''; width: 10px; height: 10px; border-radius: 3px; }
.lg-pv::before { background: var(--pv); }
.lg-load::before { background: var(--load); }
.lg-batt::before { background: var(--battery); }

/* ---------- Energy + detail grids ---------- */
.energy-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 18px; }
@media (min-width: 560px) { .energy-grid { grid-template-columns: repeat(3, 1fr); } }
.energy-item p:first-child { font-size: 0.8rem; }
.energy-item b { font-size: 1.35rem; font-weight: 700; font-family: 'Space Grotesk', sans-serif; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 18px; }
@media (min-width: 560px) { .detail-grid { grid-template-columns: repeat(3, 1fr); } }
.detail p:first-child { font-size: 0.78rem; }
.detail b { font-size: 1.15rem; font-weight: 600; }
.updated { margin-top: 16px; font-size: 0.78rem; }

/* ---------- Empty state ---------- */
.empty { display: grid; place-items: center; min-height: 62vh; padding: 30px; text-align: center; }
.empty-inner { max-width: 380px; display: grid; gap: 12px; justify-items: center; }
.empty-inner h2 { font-size: 1.3rem; }
.empty code { background: rgba(255,255,255,0.08); padding: 2px 7px; border-radius: 6px; font-size: 0.85em; }

/* ---------- Login ---------- */
.login-body { display: grid; place-items: center; padding: 24px; position: relative; overflow: hidden; }
.login-aurora {
  position: fixed; inset: -30%; z-index: 0; pointer-events: none;
  background:
    radial-gradient(500px 400px at 25% 30%, rgba(255, 176, 32, 0.22), transparent 60%),
    radial-gradient(500px 500px at 78% 70%, rgba(108, 140, 255, 0.22), transparent 60%);
  filter: blur(20px);
  animation: drift 16s ease-in-out infinite alternate;
}
@keyframes drift { to { transform: translate3d(0, -24px, 0) scale(1.05); } }
.login-card {
  position: relative; z-index: 1; width: 100%; max-width: 380px;
  background: var(--card); border: 1px solid var(--card-brd);
  border-radius: 24px; padding: 28px; box-shadow: var(--shadow); backdrop-filter: blur(16px);
}
.login-card .brand { margin-bottom: 22px; }
.login-card .brand p { font-size: 0.82rem; color: var(--muted); margin-top: 3px; }
#loginForm { display: grid; gap: 14px; }
#loginForm label { display: grid; gap: 6px; font-size: 0.82rem; color: var(--muted); }
#loginForm input {
  background: rgba(9, 14, 28, 0.8); border: 1px solid var(--card-brd); color: var(--ink);
  border-radius: 12px; padding: 12px 14px; font: inherit; font-size: 1rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}
#loginForm input:focus { outline: none; border-color: var(--pv); box-shadow: 0 0 0 3px rgba(255, 176, 32, 0.18); }
#loginBtn {
  margin-top: 4px; padding: 13px; border: none; border-radius: 12px; cursor: pointer;
  font: inherit; font-weight: 600; font-size: 1rem; color: #1a1000;
  background: linear-gradient(135deg, var(--pv), var(--pv-2));
  box-shadow: 0 12px 30px -12px rgba(255, 140, 40, 0.8);
  transition: transform 0.1s, filter 0.15s;
}
#loginBtn:hover { filter: brightness(1.05); }
#loginBtn:active { transform: translateY(1px); }
#loginBtn:disabled { opacity: 0.7; cursor: default; }
.login-error { color: var(--danger); font-size: 0.85rem; text-align: center; }
.login-foot { margin-top: 18px; text-align: center; font-size: 0.75rem; color: var(--muted); }

@media (prefers-reduced-motion: reduce) {
  .status-dot.live, .login-aurora, .flow-dot { animation: none !important; }
}
