/* common.css — shared chrome across flow / details / control pages.
   Rules here are the header, page nav, connection pill, base card
   hull, and the shared mobile overrides for those elements. Anything
   page-specific (flow diagram, detail rows, control tabs, etc.) stays
   in each page's inline <style> block so the per-page views can
   override as needed. Loaded via <link> BEFORE the inline <style>,
   so inline rules win on tie-breaks. */

:root {
  --bg: #05070d; --bg-2: #0b0f1a;
  --card: rgba(20, 26, 42, 0.6);
  --card-edge: rgba(255, 255, 255, 0.05);
  --border: rgba(255,255,255,0.055);
  --text: #f1f4fb; --text-dim: #8892a8; --text-muted: #4e5770;
  /* Tesla-adjacent palette: warmer solar, cleaner home blue, neutral grid */
  --solar: #f59e0b; --solar-soft: #fcd34d;
  --grid:  #94a3b8; --grid-soft: #cbd5e1;
  --batt:  #10b981; --batt-soft: #6ee7b7;
  --home:  #3b82f6; --home-soft: #93c5fd;
  --red: #f87171; --red-soft: #fecaca;
}
* { box-sizing: border-box; }

/* Auth-gated UI defaults: hidden until JS proves we have a token. Reveal-
   on-evidence beats hide-on-evidence — without these rules the auth tabs
   and Edit buttons render visible until `_bootstrapApiToken` finishes
   (up to 2 s on cold launch), giving anyone reaching the URL via Funnel
   a window to navigate into write pages they can't actually use.
   `_applyAuthGatedUI` adds .auth-ok / .pywebview-ok once the token
   resolves; the :not() form lets each element's own CSS (inline-flex on
   tabs, etc.) take over without us hardcoding a per-element display
   value here. */
[data-auth-required]:not(.auth-ok) { display: none; }
[data-pywebview-only]:not(.pywebview-ok) { display: none; }
html { font-feature-settings: "cv11","ss01"; font-variant-numeric: tabular-nums; }
body {
  margin: 0; padding: 0;
  background:
    radial-gradient(1200px 600px at 20% -5%, rgba(129, 140, 248, 0.10), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, rgba(56, 189, 248, 0.06), transparent 55%),
    radial-gradient(1000px 800px at 50% 120%, rgba(52, 211, 153, 0.05), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, system-ui, sans-serif; font-size: 14px;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
/* No max-width: content expands to fill the viewport. Horizontal padding
   uses clamp() so the gutter grows with viewport width — readable on a
   phone (16 px), comfortable on a laptop (32 px), airy on a 4K display
   (up to 80 px). */
.wrap { margin: 0 auto; padding: 28px clamp(16px, 3vw, 80px) 64px; }

/* ================== meter-protection banner ==================
   Driven by /api/meter-state, rendered by common.js across every page.
   Sticky at the top of the viewport so it can't be missed when the
   user scrolls. The 5 severity variants map from the 12 alert states:
     safe     → routine zone (rows 1-4)
     warning  → other-meter-at-risk standby (rows 5-6)
     urgent   → active meter at risk / stranded / last-stand-flip (rows 7-9, 15)
     lost     → at least one meter has crossed 200u (rows 10-14)
     worst    → both lost (row 16)
   When in safe state with no banner text, the element has the .hidden
   class and is not displayed. */
.meter-banner {
  position: sticky;
  top: 0;
  z-index: 100;
  margin: -28px clamp(-80px, -3vw, -16px) 16px;   /* pull out into the wrap padding */
  padding: 10px clamp(16px, 3vw, 80px);
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  text-align: center;
  letter-spacing: 0.01em;
  box-shadow: 0 2px 12px rgba(0,0,0,0.35);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.meter-banner.hidden { display: none; }
.meter-banner.severity-safe    { background: rgba(16,185,129,0.85);  color: #04140d; }
.meter-banner.severity-warning { background: rgba(245,158,11,0.90);  color: #1a0e00; }
.meter-banner.severity-urgent  { background: rgba(239,68,68,0.92);   color: #fff; }
.meter-banner.severity-lost    { background: rgba(220,38,38,0.95);   color: #fff; }
.meter-banner.severity-worst   { background: rgba(0,0,0,0.92);       color: #fca5a5; }

.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 12px;
  background: linear-gradient(135deg, rgba(52, 211, 153, 0.18), rgba(56, 189, 248, 0.18));
  border: 1px solid rgba(110, 231, 183, 0.25);
  display: grid; place-items: center;
  box-shadow: 0 0 24px rgba(52, 211, 153, 0.15);
}
.brand-mark svg { width: 22px; height: 22px; stroke: var(--batt-soft); }
.title { font-size: 22px; font-weight: 700; letter-spacing: -0.015em; line-height: 1.15; }
.subtitle { font-size: 12px; color: var(--text-dim); margin-top: 3px; letter-spacing: 0.01em; }
.back-link {
  font-size: 13px; font-weight: 600; color: var(--text); text-decoration: none;
  padding: 9px 16px; border-radius: 10px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--card-edge);
  transition: all 160ms ease;
  display: inline-flex; align-items: center; gap: 6px;
}
.back-link:hover { background: rgba(255,255,255,0.08); border-color: rgba(255,255,255,0.18); }

.card {
  background: var(--card);
  border: 1px solid var(--card-edge);
  border-radius: 18px; padding: 24px;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: 0 1px 0 0 rgba(255,255,255,0.04) inset, 0 14px 40px rgba(0,0,0,0.35);
}
.card-head {
  font-size: 10.5px; font-weight: 700; letter-spacing: 0.18em;
  color: var(--text-dim); text-transform: uppercase; margin-bottom: 18px;
}

/* Icon power button — red=connected (click disconnects), green=disconnected
   (click connects). Same visual as the details view. */
.icon-btn {
  width: 40px; height: 40px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 10px; padding: 0;
  background: rgba(248, 113, 113, 0.08);
  border: 1px solid rgba(248, 113, 113, 0.35);
  color: #fca5a5; cursor: pointer;
  transition: all 140ms ease;
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn:hover { background: rgba(248, 113, 113, 0.18); border-color: rgba(248, 113, 113, 0.6); }
.icon-btn:active { transform: translateY(1px); }
.icon-btn.disconnected {
  background: rgba(52, 211, 153, 0.08);
  border-color: rgba(52, 211, 153, 0.35);
  color: #6ee7b7;
}
.icon-btn.disconnected:hover { background: rgba(52, 211, 153, 0.18); border-color: rgba(52, 211, 153, 0.6); }
.icon-btn:disabled { opacity: 0.55; cursor: not-allowed; }
.header-actions { display: inline-flex; gap: 10px; align-items: center; }

/* ---------- Unified connection pill ----------
   Same widget on flow + details + control so the connection status reads
   identically across pages. Combines the status indicator (dot + text)
   with the connect/disconnect action (click toggles). Replaces the old
   mix of "red power icon when connected" + "green status dot" which
   encoded the same state twice with opposite colors. */
.conn-pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px; border-radius: 10px;
  background: rgba(52, 211, 153, 0.1);
  border: 1px solid rgba(52, 211, 153, 0.3);
  color: #6ee7b7;
  font-size: 12px; font-weight: 600;
  cursor: pointer; transition: all 160ms ease;
  font-family: inherit; letter-spacing: 0.02em;
  white-space: nowrap;
}
.conn-pill:hover:not(:disabled) {
  background: rgba(52, 211, 153, 0.18);
  border-color: rgba(52, 211, 153, 0.55);
}
.conn-pill:active { transform: translateY(1px); }
.conn-pill:disabled { cursor: wait; }
.conn-pill .conn-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 10px currentColor;
  flex-shrink: 0;
}
.conn-pill.connecting, .conn-pill.disconnecting {
  background: rgba(251, 191, 36, 0.1);
  border-color: rgba(251, 191, 36, 0.35);
  color: #fcd34d;
}
.conn-pill.connecting .conn-dot,
.conn-pill.disconnecting .conn-dot {
  animation: conn-pulse 1s ease-in-out infinite;
}
@keyframes conn-pulse {
  0%, 100% { box-shadow: 0 0 8px currentColor; }
  50%      { box-shadow: 0 0 18px currentColor; }
}
.conn-pill.disconnected {
  background: rgba(136, 146, 168, 0.08);
  border-color: rgba(136, 146, 168, 0.24);
  color: #94a3b8;
}
.conn-pill.error {
  background: rgba(248, 113, 113, 0.08);
  border-color: rgba(248, 113, 113, 0.3);
  color: #fca5a5;
}

/* ---------- Page nav (segmented tabs) ----------
   Shared pattern across flow / details / control so the three pages read
   as one app. Each page marks its own tab `.active`. Visually mirrors
   control.html's in-page `.tabs` so the user learns one idiom. */
.page-nav {
  display: flex; gap: 4px; margin-bottom: 22px;
  padding: 4px; border-radius: 14px;
  background: rgba(20, 26, 42, 0.4);
  border: 1px solid var(--card-edge);
  backdrop-filter: blur(8px);
}
.page-tab {
  flex: 1; text-align: center;
  padding: 9px 12px; border-radius: 10px;
  text-decoration: none; font-weight: 600; font-size: 13px;
  color: var(--text-dim);
  border: 1px solid transparent;
  transition: all 180ms ease;
}
.page-tab:hover:not(.active) { color: var(--text); background: rgba(255,255,255,0.03); }
.page-tab.active {
  background: linear-gradient(135deg, rgba(52, 211, 153, 0.18), rgba(56, 189, 248, 0.12));
  border-color: rgba(110, 231, 183, 0.28);
  color: var(--text);
  box-shadow: 0 0 14px rgba(52, 211, 153, 0.12);
}

/* ---------- Mobile overrides ----------
   Shared mobile adjustments for the chrome above. Each page may add its
   own `@media (max-width: 640px)` block with page-specific overrides;
   those inline rules come later in cascade and still win on ties. */
@media (max-width: 640px) {
  .wrap { padding: 20px 14px 48px; }
  .title { font-size: 20px; }
  .brand-mark { width: 38px; height: 38px; }
  .brand-mark svg { width: 20px; height: 20px; }
  .page-nav { margin-bottom: 18px; }
  .page-tab { font-size: 12.5px; padding: 8px 6px; }
  .conn-pill { padding: 7px 11px; font-size: 11.5px; gap: 7px; }
}
