  :root {
    --navy-900: #0b1a3a;
    --navy-800: #13264f;
    --navy-700: #1e3a6f;
    --navy-600: #2b4c8a;
    --cream: #f7f3e8;
    --bg: #f3f5f9;
    --surface: #ffffff;
    --surface2: #fafbfd;
    --border: #e2e8f0;
    --text: #111827;
    --fg: #111827;
    --card-alt-bg: #f8fafc;
    --muted: #5b6472;
    --muted-dim: #94a3b8;
    --green: #16a34a;
    --yellow: #d97706;
    --red: #dc2626;
    --blue: #2563eb;
    --gold: #f0b429;
    /* Text-on-white variants (>=4.5:1 on #fff). --gold/--amber/#22c55e are for
       fills and dark backgrounds; use these for TEXT. Dark theme restores the bright ones. */
    --gold-text: #8a5a00;
    --warn-text: #b45309;
    --green-text: #15803d;
    --red-text: #b91c1c;
    --accent: var(--navy-900);
    --accent-soft: #93c5fd;
    --card-bg: var(--surface);
    /* Solid ("filled") button pair. Several buttons were hand-rolled as
       `background:var(--fg); color:#fff`, which is correct in light mode and
       ILLEGIBLE in dark: --fg flips to #f1f5f9 there, putting white on white.
       Reported 2026-08-18 on the "Find a Panel Cleaner" button. These resolve
       at use time, so one definition covers both themes and the pair can never
       drift apart again. Same anti-pattern family as the --accent and --amber
       notes below. */
    --btn-solid-bg: var(--fg);
    --btn-solid-fg: var(--surface);
    --tooltip-bg: var(--navy-900);
    --tooltip-fg: #ffffff;
    /* Amber palette (used by shortfall-detected teaser card + similar warning panes).
       Defined here so inline `var(--amber, ...)` / `var(--amber-bg, ...)` references
       resolve correctly in BOTH themes — inline styles always beat external CSS rules,
       so the only reliable way to dark-mode the inline-styled teaser card is via the
       custom property, not via a `[data-theme="dark"] #claim-teaser-card { ... }` rule. */
    --amber: #f59e0b;
    --amber-bg: #fffbeb;
    --amber-fg: #78350f;
    /* Subtle surface tint — used by `.nudge-soft` informational callouts
       (Support tab "we typically reply within 72 hours" pane and similar).
       Same inline-style-vs-theme reasoning as --amber above: defined as a
       custom property so inline `var(--surface-subtle, ...)` references
       resolve correctly in both themes. */
    --surface-subtle: #f5f7fa;
    --font: -apple-system, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
    --mono: "SF Mono", "JetBrains Mono", "Fira Code", monospace;
  }

  /* ── Dark mode override (2026-04-20) ──
     Default theme is light. Adding [data-theme="dark"] on <html>
     flips the surface/text palette while keeping brand navy + gold intact. */
  [data-theme="dark"] {
    --gold-text: #f0b429;
    --warn-text: #f59e0b;
    --green-text: #22c55e;
    --red-text: #f87171;
    --bg: #0f172a;
    --surface: #1e293b;
    --surface2: #111c30;
    --card-alt-bg: #162238;
    --border: #334155;
    --text: #f1f5f9;
    --fg: #f1f5f9;
    --muted: #94a3b8;
    --muted-dim: #64748b;
    --card-bg: #1e293b;
    --tooltip-bg: #020617;
    --tooltip-fg: #f1f5f9;
    /* Amber teaser card — translucent amber over dark navy reads well; border stays
       saturated so the warning framing survives the theme flip. */
    --amber: #b45309;
    --amber-bg: rgba(245,158,11,0.10);
    --amber-fg: #fde68a;
    /* Accent — :root default is var(--navy-900) (#0b1a3a) which is near-invisible
       on dark surfaces. Same anti-pattern that hit .stat-value.navy and the
       --amber gap. Override proactively to a light blue matching the dark-mode
       link color so any element using var(--accent) stays legible. */
    --accent: #93c5fd;
    --accent-soft: #1e3a5f;  /* Deeper navy-blue for soft-tinted backgrounds; stays legible against dark surfaces */
    /* Subtle surface — translucent blue tint over dark page bg reads as a
       gentle informational callout (vs the saturated --amber warning stripe). */
    --surface-subtle: rgba(147, 197, 253, 0.08);
    /* Raised card surface + red claim background — :root leaves these undefined so
       inline `var(--surface-raised, #f8fafc)` / `var(--red-bg, #fef2f2)` fall back to
       LIGHT hexes, leaving the guarantee-claim year rows + dollar row white-on-dark.
       Define dark equivalents so those surfaces flip with the theme. */
    --surface-raised: #111c30;
    --red-bg: rgba(239, 68, 68, 0.12);
    /* Muted text on the two lighter dark surfaces: --muted (#94a3b8) reads 3.4:1 on
       the upload zone and 4.15:1 inside the pending-outcome pill; both need 4.5. */
    --upload-sub-fg: #cbd5e1;
    --badge-pending-fg: #cbd5e1;
    /* Citation ref ("p.1 ¶3") sits on the amber-tinted cite box: --muted measures 4.48:1 there. */
    --cite-ref-fg: #b0c0d0;
  }
  [data-theme="dark"] a { color: #93c5fd; }
  /* `.nudge` defaults to amber warning treatment in dark mode (see rule below).
     `.nudge-soft` is the informational variant — neutralise the warning text
     color so it reads correctly against the subtle blue background. */
  [data-theme="dark"] .nudge.nudge-soft { color: var(--text); }
  [data-theme="dark"] .bill-glance-compare.below { background: rgba(34,197,94,0.2); color: #4ade80; }
  [data-theme="dark"] .bill-glance-compare.above { background: rgba(239,68,68,0.2); color: #f87171; }
  [data-theme="dark"] .nudge { background: #422006; border-color: #92400e; color: #fed7aa; }
  [data-theme="dark"] .nudge a { color: #fdba74; }
  [data-theme="dark"] .usage-anomaly-callout { background: #422006; color: #fed7aa; }
  /* Form fields — swap hardcoded #fff background so Settings inputs are readable */
  [data-theme="dark"] .form-grid input,
  [data-theme="dark"] .form-grid select,
  [data-theme="dark"] .form-grid textarea { background: var(--surface2); color: var(--text); }
  [data-theme="dark"] .form-grid input:disabled { background: #0b1220; color: var(--muted); }
  /* Grid banner + card (was light pastel #eef2f7 / #fef2f2 / #ecfdf5).
     The teaser card's outer wrapper is themed primarily via the --amber / --amber-bg
     custom properties above (so inline `var(--amber-bg, #fffbeb)` resolves to dark);
     this rule is a redundant safety net if anything ever sets the inline background
     to a literal hex. !important is needed because inline styles outrank external CSS. */
  [data-theme="dark"] #claim-teaser-card { background: var(--amber-bg) !important; border-color: var(--amber) !important; }
  /* Contract start-date confirm + confirmed boxes — inline styles used hardcoded
     light-palette colors; dark mode needs explicit overrides. !important because
     the targets carry inline styles. */
  [data-theme="dark"] #contract-start-confirm-box,
  [data-theme="dark"] #contract-start-confirm-box-fb { background: rgba(245,158,11,0.1) !important; border-color: #b45309 !important; color: #fde68a !important; }
  [data-theme="dark"] #contract-start-status-text,
  [data-theme="dark"] #contract-start-status-text-fb { color: #fcd34d !important; }
  [data-theme="dark"] #contract-start-confirmed-box,
  [data-theme="dark"] #contract-start-confirmed-box-fb { background: rgba(5,150,105,0.12) !important; border-color: #065f46 !important; color: #bbf7d0 !important; }
  /* Inline "Change" buttons inside the confirmed boxes carry hardcoded color:#059669
     (saturated green) which loses contrast on the dark green-tinted background.
     Force a light-green link color so the button reads as a clear secondary action. */
  [data-theme="dark"] #contract-start-confirmed-box button,
  [data-theme="dark"] #contract-start-confirmed-box-fb button { color: #6ee7b7 !important; }
  [data-theme="dark"] #collector-offline-banner { background: rgba(245,158,11,0.12); color: #fcd34d; border-color: #92400e; }
  /* Contract-year performance cards — inline var(--surface-raised, #f8fafc) fallback
     was cream in every theme (the var is never defined anywhere). Same for the
     COMPLETE / IN PROGRESS pills which carry hardcoded light-palette colors. */
  [data-theme="dark"] #perf-contract-years > div { background: var(--surface2) !important; border-color: var(--border) !important; color: var(--fg) !important; }
  [data-theme="dark"] #perf-contract-years span[style*="background:#dcfce7"] { background: rgba(34,197,94,0.2) !important; color: #86efac !important; }
  [data-theme="dark"] #perf-contract-years span[style*="background:#fef9c3"] { background: rgba(250,204,21,0.2) !important; color: #fde047 !important; }
  [data-theme="dark"] #banner { background: var(--surface2); color: var(--muted); border-color: var(--border); }
  [data-theme="dark"] #banner.exporting { background: rgba(34,197,94,0.18); color: #4ade80; border-color: rgba(34,197,94,0.45); }
  [data-theme="dark"] #banner.importing { background: rgba(239,68,68,0.18); color: #f87171; border-color: rgba(239,68,68,0.45); }
  [data-theme="dark"] #grid-card { background: var(--surface2); border-color: var(--border); }
  [data-theme="dark"] #grid-card.exporting { background: rgba(34,197,94,0.18); border-color: rgba(34,197,94,0.45); }
  [data-theme="dark"] #grid-card.importing { background: rgba(239,68,68,0.18); border-color: rgba(239,68,68,0.45); }
  /* Panel orientation cards (was #f8fafc background + confidence pastels) */
  [data-theme="dark"] .orient-array { background: var(--surface2); }
  [data-theme="dark"] .orient-array .orient-title { color: var(--text); }
  [data-theme="dark"] .orient-confidence.high { background: rgba(34,197,94,0.2); color: #4ade80; }
  [data-theme="dark"] .orient-confidence.medium { background: rgba(245,158,11,0.22); color: #fcd34d; }
  [data-theme="dark"] .orient-confidence.low { background: rgba(239,68,68,0.2); color: #f87171; }
  /* Settings tabs — active tab color was hardcoded var(--navy-900) = invisible on dark surface */
  [data-theme="dark"] .settings-tab.active { color: var(--text); background: var(--surface); }
  [data-theme="dark"] .settings-tab:hover { background: rgba(255,255,255,0.04); }
  /* Bill-glance pastel compares — light rgba on light bg looks fine but blends on dark */
  [data-theme="dark"] .bill-glance-compare.below { color: #4ade80; }
  [data-theme="dark"] .bill-glance-compare.above { color: #f87171; }
  [data-theme="dark"] .bill-glance-compare.at { color: var(--muted); }
  /* Performance gauge arc background — hardcoded #e5e7eb bleeds on dark */
  [data-theme="dark"] #perf-analysis-content svg path[stroke="#e5e7eb"] { stroke: var(--border); }
  /* Bill coverage nudge fallback colors */
  [data-theme="dark"] #bill-coverage-nudge { background: rgba(245,158,11,0.12); color: #fcd34d; }
  /* Perf-gauge center value (inline color var(--fg) isn't defined here; force readable) */
  [data-theme="dark"] #perf-gauge-value { color: var(--text); }
  /* Dark-mode contrast fixes (audit 2026-10-01): navy-700 / light-theme hex
     literals that vanish on --surface (#1e293b). Text targets >= 4.5:1. */
  [data-theme="dark"] .finding-category { color: var(--muted); }
  [data-theme="dark"] .upload-link { color: var(--accent); }
  [data-theme="dark"] .nudge .nudge-close { color: #fed7aa; }
  [data-theme="dark"] .nudge .nudge-close:hover { color: #fff7ed; }
  [data-theme="dark"] #soiling-level-badge { background: var(--surface2) !important; }
  [data-theme="dark"] #soiling-level-badge.soil-clean { color: #4ade80 !important; }
  [data-theme="dark"] #soiling-level-badge.soil-mild { color: #fbbf24 !important; }
  [data-theme="dark"] #soiling-level-badge.soil-moderate { color: #fb923c !important; }
  [data-theme="dark"] #soiling-level-badge.soil-heavy { color: #f87171 !important; }
  [data-theme="dark"] #soiling-level-badge.soil-insufficient_evidence { color: var(--muted) !important; }
  [data-theme="dark"] #ref-not-affiliated-section { background: rgba(59,130,246,0.12) !important; border-color: #1e40af !important; color: #bfdbfe !important; }
  [data-theme="dark"] #ref-not-affiliated-section p { color: #cbd5e1 !important; }
  [data-theme="dark"] #equipment-correction-details { border-color: var(--border) !important; }
  [data-theme="dark"] #equipment-correction-details summary { color: var(--muted) !important; }
  [data-theme="dark"] #equipment-correction-details p { color: var(--muted) !important; }
  /* Bug 3: stat-value.navy uses --navy-700 (#1e3a6f) which is invisible on dark backgrounds */
  [data-theme="dark"] .stat-value.navy { color: #93c5fd; }
  /* Bug 2: claim-teaser inner stat boxes use var(--surface, #fff) which stays white in dark mode */
  [data-theme="dark"] #claim-teaser-card .claim-teaser-stat-box { background: var(--surface2); border-color: var(--border); }
  /* Generate Claim Report buttons — inline `background:var(--fg)` flips to a near-white
     bg in dark mode, making the white-on-white button invisible. Force a navy bg so
     the CTA stays readable. !important because the bg is set inline. */
  [data-theme="dark"] #btn-claim-report,
  [data-theme="dark"] #btn-claim-report-fb,
  /* Per-contract-year PDF report buttons in the guarantee-claim card
     (JS-created, see dashboard.html #guarantee-claim-years) -- same
     inline `background:var(--fg)` white-on-white bug as the buttons above. */
  [data-theme="dark"] .guarantee-report-btn { background: var(--navy-700) !important; color: #fff !important; }
  /* Guarantee-claim card: the "verification needed" pending row hardcodes light
     amber (#fffbeb / #78350f / #92400e) inline, so it renders as a light box on the
     dark dashboard. Force the dark amber palette + readable text. The attestation
     wrappers/buttons inside already use var(--surface)/var(--fg) and flip correctly. */
  [data-theme="dark"] #guarantee-claim-pending-row { background: var(--amber-bg) !important; border-color: var(--amber) !important; }
  [data-theme="dark"] #guarantee-claim-pending-row > div:first-child,
  [data-theme="dark"] #guarantee-claim-pending-text { color: var(--amber-fg) !important; }
  /* Contract-start input + Confirm Start Date button (lines 393-394, 418-419) carry
     hardcoded `background:#fff` / `background:#d97706;color:#fff`. The amber button is
     fine on dark; the date input is unreadable (white-on-amber-on-dark). */
  [data-theme="dark"] #contract-start-date-input,
  [data-theme="dark"] #contract-start-date-input-fb { background: var(--surface2) !important; color: var(--text) !important; border-color: var(--amber) !important; color-scheme: dark; }

  /* Devices tab — rename + location inputs inherit card surface; force legible text. */
  [data-theme="dark"] .device-rename-input,
  [data-theme="dark"] .device-loc-input,
  [data-theme="dark"] .device-card input { color: var(--text); background: transparent; }
  [data-theme="dark"] .device-card input.device-loc-input { background: var(--surface2); border-color: var(--border); }
  [data-theme="dark"] .device-rename-input::placeholder,
  [data-theme="dark"] .device-loc-input::placeholder { color: var(--muted); }

  /* Notifications matrix — category group rows + mandatory badge use custom
     properties so dark mode overrides cleanly. */
  :root {
    --notif-cat-bg: #fafafa;
    --notif-req-bg: #fef3c7;
    --notif-req-fg: #92400e;
  }
  [data-theme="dark"] {
    --notif-cat-bg: var(--surface2);
    --notif-req-bg: rgba(245,158,11,0.22);
    --notif-req-fg: #fcd34d;
  }
  [data-theme="dark"] select { background: var(--surface2); color: var(--text); color-scheme: dark; }
  [data-theme="dark"] .notif-matrix-table select,
  [data-theme="dark"] .notif-matrix-table input { color: var(--text); }
  /* Theme toggle button in topbar */
  .theme-toggle-btn {
    background: transparent;
    border: 1px solid rgba(255,255,255,0.25);
    color: var(--cream);
    padding: 5px 10px;
    border-radius: 5px;
    font-size: 14px;
    cursor: pointer;
    line-height: 1;
  }
  .theme-toggle-btn:hover { background: rgba(255,255,255,0.08); }
  * { box-sizing: border-box; margin: 0; padding: 0; }
  body {
    font-family: var(--font);
    font-size: 14px;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
  }
  a { color: var(--navy-700); text-decoration: none; }
  a:hover { text-decoration: underline; }

  /* ── Top bar ── */
  #topbar {
    background: var(--navy-900);
    color: var(--cream);
    padding: 10px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 3px solid var(--gold);
    flex-shrink: 0;
  }
  /* min-width: 0 lets these flex children shrink below their content's
     intrinsic (min-content) size instead of forcing #topbar to overflow the
     viewport -- the classic flexbox-overflow trap on narrow phones (~390px,
     iPhone standard width) where an unbreakable string (e.g. an email
     address with no wrap points) would otherwise push the row wider than
     the screen. Paired with text-overflow: ellipsis below so any content
     that does get squeezed truncates gracefully instead of clipping/overflowing. */
  .brand-wrap { display: flex; align-items: center; gap: 10px; min-width: 0; }
  .brand-logo { display: flex; align-items: center; flex-shrink: 0; }
  .brand-logo img { height: 26px; vertical-align: middle; }
  .owl-logo { filter: drop-shadow(0 1px 3px rgba(11,35,64,0.35)); }
  .brand-name {
    font-size: 18px; font-weight: 700; letter-spacing: 0.4px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .top-right { display: flex; align-items: center; gap: 14px; font-size: 13px; min-width: 0; }
  .top-right .email {
    color: var(--muted-dim); font-size: 12px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 160px;
  }
  .theme-toggle-btn, .logout-btn { flex-shrink: 0; }
  .logout-btn {
    background: transparent;
    border: 1px solid rgba(255,255,255,0.25);
    color: var(--cream);
    padding: 5px 12px;
    border-radius: 5px;
    font-size: 12px;
    cursor: pointer;
  }
  .logout-btn:hover { background: rgba(255,255,255,0.08); }

  /* ── Layout ── */
  #layout {
    flex: 1;
    display: flex;
    overflow: hidden;
  }
  #sidebar {
    width: 250px;
    background: var(--navy-800);
    color: var(--cream);
    padding: 16px 0;
    flex-shrink: 0;
    overflow-y: auto;
  }
  #sidebar .nav-item {
    padding: 10px 18px;
    font-size: 13px;
    cursor: pointer;
    color: rgba(255,255,255,0.72);
    border-left: 3px solid transparent;
    transition: background 0.1s, color 0.1s, border-color 0.1s;
    display: flex;
    align-items: center;
    gap: 10px;
    white-space: nowrap;
  }
  #sidebar .nav-item:hover { background: rgba(255,255,255,0.05); color: var(--cream); }
  #sidebar .nav-item.active {
    background: rgba(255,255,255,0.08);
    color: var(--cream);
    border-left-color: var(--gold);
    font-weight: 600;
  }
  .nav-icon {
    width: 20px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .nav-icon svg {
    display: block;
    width: 18px;
    height: 18px;
    flex-shrink: 0;
  }

  #main {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
  }
  .page { display: none; max-width: 1400px; margin: 0 auto; }
  .page.active { display: block; }

  /* ── Cards / common ── */
  .card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px;
    margin-bottom: 12px;
  }
  .card-label {
    font-size: 11px;
    color: var(--muted);
    letter-spacing: 0.8px;
    text-transform: uppercase;
    margin-bottom: 8px;
    font-weight: 600;
  }
  /* A floated .card-help inside the label (inline float:right) used to escape the
     label and squeeze the overflow:auto wrapper below it to 0px on mobile
     (Notifications matrix). Contain the float; stack the help text under 600px. */
  .card-label::after { content: ""; display: table; clear: both; }
  @media (max-width: 600px) {
    .card-label > .card-help { float: none !important; display: block; margin-top: 4px; }
  }

  .stat-row { display: flex; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
  .stat-card {
    flex: 1;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px;
    text-align: center;
    min-width: 120px;
  }
  .stat-label {
    font-size: 10px;
    color: var(--muted);
    letter-spacing: 1px;
    margin-bottom: 6px;
    text-transform: uppercase;
    font-weight: 600;
  }
  .stat-value { font-size: 28px; font-weight: 700; color: var(--text); line-height: 1; font-family: var(--mono); }
  .stat-value.big { font-size: 36px; }
  .stat-value.sm  { font-size: 18px; }
  .stat-value.green { color: var(--green-text); }
  .stat-value.red { color: var(--red-text); }
  .stat-value.navy { color: var(--navy-700); }
  .stat-value.gold { color: var(--gold-text); }
  .stat-unit { font-size: 11px; color: var(--muted); margin-top: 3px; }

  /* ── Onboarding nudges (dismissible banners above the main banner) ── */
  .nudge {
    background: #fff7ed;
    border: 1px solid #fdba74;
    color: #7c2d12;
    border-radius: 8px;
    padding: 10px 14px;
    margin-bottom: 10px;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 10px;
  }
  .nudge a { color: #9a3412; text-decoration: underline; font-weight: 600; }
  .nudge .nudge-close {
    background: transparent;
    border: 0;
    color: #7c2d12;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    padding: 2px 6px;
    margin-left: auto;
  }
  .nudge .nudge-close:hover { color: #431407; }

  /* ── Banner ── */
  #banner {
    border-radius: 10px;
    padding: 12px 16px;
    text-align: center;
    margin-bottom: 12px;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 1.5px;
    background: #eef2f7;
    color: var(--muted);
    border: 2px solid var(--border);
  }
  #banner.exporting { background: #ecfdf5; color: #166534; border-color: #22c55e; }
  #banner.importing { background: #fef2f2; color: #991b1b; border-color: #ef4444; }

  /* ── Grid card ── */
  #grid-card {
    border-radius: 10px;
    padding: 14px;
    text-align: center;
    margin-bottom: 12px;
    border: 2px solid var(--border);
    background: #eef2f7;
  }
  #grid-card.exporting { background: #ecfdf5; border-color: #22c55e; }
  #grid-card.importing { background: #fef2f2; border-color: #ef4444; }

  /* ── Sun arc SVG ──
     The viewBox is 1200x200 with preserveAspectRatio="none", so setting
     an explicit pixel height (and width:100%) is what gives us the wide,
     polished proportions matching the homelab dashboard. Without this,
     some browsers collapse the SVG to a 150px default square. */
  #sun-arc-card svg {
    display: block;
    width: 100%;
    height: 200px;
    min-height: 180px;
  }
  @media (max-width: 720px) {
    #sun-arc-card svg { height: 160px; min-height: 140px; }
  }

  /* ── Chart / history ── */
  .history-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
  .range-btns { display: flex; gap: 4px; }
  .range-btn {
    background: var(--surface2);
    color: var(--muted);
    border: 1px solid var(--border);
    border-radius: 5px;
    padding: 4px 12px;
    font-size: 12px;
    cursor: pointer;
    font-family: var(--mono);
    transition: all 0.1s;
  }
  .range-btn:hover { background: var(--border); color: var(--text); }
  .range-btn.active { background: var(--navy-900); color: var(--cream); border-color: var(--navy-900); }

  .legend-row { display: flex; gap: 14px; font-size: 11px; color: var(--muted); margin-bottom: 6px; font-family: var(--mono); }

  /* ── Microinverters grid ── */
  #inverter-grid, #inverter-offline-grid {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    gap: 6px;
  }
  .inv-tile {
    background: #f3f5f9;
    color: var(--muted);
    border: 1px solid var(--border);
    border-radius: 5px;
    padding: 5px 4px 4px;
    text-align: center;
    font-family: var(--mono);
    min-width: 0;
    font-size: 11px;
    cursor: help;
    position: relative;
    line-height: 1.2;
  }
  .inv-tile.ok      { background: #ecfdf5; color: #166534; border-color: #bbf7d0; }
  .inv-tile.medium  { background: #fefce8; color: #92400e; border-color: #fde68a; }
  .inv-tile.low     { background: #f3f5f9; color: var(--muted); }
  .inv-tile.dark    { background: #eef2f7; color: #94a3b8; border-color: var(--border); }
  .inv-tile.stale   { background: #fef2f2; color: #991b1b; border-color: #fecaca; }
  .inv-tile .inv-w  { font-size: 12px; font-weight: 700; }
  .inv-tile .inv-s  { font-size: 9px; opacity: 0.65; margin-top: 1px; }
  /* ── Power optimizers (SolarEdge: identity + status only, no wattage
       scale -- see #optimizer-card in _dashboard.html) ── */
  .optimizer-group { margin-bottom: 14px; }
  .optimizer-group-label {
    font-size: 10px; color: var(--muted); letter-spacing: 0.6px;
    text-transform: uppercase; font-weight: 600; margin-bottom: 6px;
  }
  #optimizer-groups .opt-grid {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    gap: 6px;
  }
  .opt-tile {
    background: #f3f5f9;
    color: var(--muted);
    border: 1px solid var(--border);
    border-radius: 5px;
    padding: 5px 4px 4px;
    text-align: center;
    font-family: var(--mono);
    min-width: 0;
    font-size: 10px;
    cursor: help;
    position: relative;
    line-height: 1.2;
  }
  .opt-tile.active   { background: #ecfdf5; color: #166534; border-color: #bbf7d0; }
  .opt-tile.inactive { background: #fef2f2; color: #991b1b; border-color: #fecaca; }
  .opt-tile.duplicate { border-width: 2px; border-style: dashed; border-color: var(--yellow); }
  .opt-tile .opt-pos { font-size: 11px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  @media (max-width: 600px) {
    /* 10 across at 390px truncated labels to "Pan 1.1": fewer, readable columns. */
    #optimizer-groups .opt-grid { grid-template-columns: repeat(4, 1fr); }
  }
  .opt-tile .opt-s   { font-size: 10px; font-weight: 600; margin-top: 1px; }
  #inverter-offline-toggle {
    display: flex; align-items: center; gap: 6px; cursor: pointer;
    margin-top: 10px; margin-bottom: 6px;
    font-size: 11px; color: var(--muted); letter-spacing: 0.8px;
    font-weight: 600; text-transform: uppercase;
    user-select: none;
  }
  #inverter-offline-toggle:hover { color: var(--text); }

  /* ── Orientation estimate card ── */
  .orient-array {
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 14px;
    margin-bottom: 8px;
    font-family: var(--mono);
    font-size: 12px;
    line-height: 1.6;
  }
  .orient-array .orient-title {
    font-weight: 700;
    font-size: 13px;
    color: var(--text);
    margin-bottom: 4px;
  }
  .orient-array .orient-detail {
    color: var(--muted);
    font-size: 11px;
  }
  .orient-array .orient-detail span {
    margin-right: 12px;
  }
  .orient-confidence {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 600;
  }
  .orient-confidence.high { background: #ecfdf5; color: #166534; }
  .orient-confidence.medium { background: #fefce8; color: #92400e; }
  .orient-confidence.low { background: #fef2f2; color: #991b1b; }
  #orient-save-btn {
    margin-top: 10px;
    padding: 8px 18px;
    background: var(--navy-900);
    color: var(--cream);
    border: none;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    font-weight: 600;
  }
  #orient-save-btn:hover { opacity: 0.9; }
  #orient-save-btn:disabled { opacity: 0.5; cursor: default; }

  /* ── Insight card ── */
  .insight-text {
    font-size: 13px;
    color: var(--text);
    line-height: 1.7;
    white-space: pre-line;
  }
  .insight-meta {
    font-size: 11px;
    color: var(--muted);
    margin-top: 10px;
    font-family: var(--mono);
    border-top: 1px solid var(--border);
    padding-top: 8px;
  }

  /* ── Empty state ── */
  .empty-state {
    text-align: center;
    padding: 30px 18px;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.6;
  }
  .empty-state .big { margin-bottom: 8px; }
  .empty-state .sub { font-size: 12px; color: var(--muted); margin-top: 4px; }

  /* ── Upload drag-drop zone (contract + bill tabs) ── */
  .upload-zone {
    margin-top: 14px;
    padding: 32px 18px;
    border: 2px dashed var(--border);
    border-radius: 12px;
    text-align: center;
    background: rgba(228,234,242,0.18);
    cursor: pointer;
    transition: border-color 120ms ease, background 120ms ease;
  }
  .upload-zone:hover { border-color: var(--navy-700); background: rgba(0,64,128,0.05); }
  .upload-zone.dragover { border-color: var(--gold); background: rgba(240,180,41,0.10); }
  .upload-big { font-size: 40px; margin-bottom: 8px; }
  .upload-title { font-size: 14px; margin-bottom: 4px; }
  .upload-link { color: var(--navy-700); text-decoration: underline; }
  .upload-sub { font-size: 12px; color: var(--upload-sub-fg, var(--muted)); margin-top: 4px; }
  .upload-progress { margin-top: 12px; }
  .progress-bar { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; }
  .progress-fill {
    height: 100%; width: 0%;
    background: linear-gradient(90deg, var(--navy-700), var(--gold));
    transition: width 200ms ease;
  }
  .progress-label { font-size: 12px; color: var(--muted); margin-top: 6px; text-align: center; }
  .upload-error {
    margin-top: 12px; padding: 10px 12px;
    background: #fef2f2; color: #991b1b; border-radius: 8px; font-size: 13px;
  }
  .consent-row {
    display: flex; align-items: flex-start; gap: 10px;
    font-size: 13px; color: var(--muted); margin: 10px 0 6px;
  }
  .consent-row input[type="checkbox"] { margin-top: 3px; }

  /* ── Analysis result card ── */
  .analysis-narrative {
    padding: 12px 14px;
    background: rgba(0,64,128,0.04);
    border-left: 3px solid var(--navy-700);
    border-radius: 6px;
    font-size: 13px;
    line-height: 1.6;
    margin: 10px 0 14px;
    white-space: pre-line;
  }
  .analysis-structured {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 8px;
    margin: 8px 0 14px;
  }
  .struct-cell {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 10px;
  }
  .struct-cell .lbl {
    font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em;
  }
  .struct-cell .val {
    font-size: 14px; font-weight: 600; color: var(--text); margin-top: 2px; word-break: break-word;
  }
  /* Materials-discrepancy compact badge (D1/D2: Contract tab + Settings/System
     tab). Reuses the existing gated equipment_finding payload -- never sets
     its own text beyond what the JS caller passes in (server-gated, no
     client-side leak of model names). */
  .equip-finding-badge {
    display: inline-block;
    margin-left: 8px;
    font-size: 11px;
    font-weight: 600;
    color: var(--red-text, #dc2626);
    cursor: pointer;
    white-space: normal;
  }
  .equip-finding-badge:hover { text-decoration: underline; }
  .findings-list { margin: 8px 0; padding: 0; list-style: none; }
  .finding-item {
    padding: 10px 12px; margin-bottom: 8px;
    background: var(--card-bg); border: 1px solid var(--border); border-radius: 8px;
  }
  .finding-head { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
  .finding-label { font-size: 13px; font-weight: 600; color: var(--text); }
  .finding-category {
    font-size: 10px; text-transform: uppercase; letter-spacing: .05em; color: var(--navy-700);
  }
  .finding-value { font-size: 13px; color: var(--muted); margin-top: 3px; }
  .finding-cite {
    margin-top: 6px; padding: 6px 10px;
    background: rgba(240,180,41,0.12); border-left: 2px solid var(--gold);
    font-size: 12px; color: var(--text); border-radius: 4px; cursor: default;
    font-style: italic;
  }
  .finding-cite-ref { font-style: normal; font-weight: 600; color: var(--cite-ref-fg, var(--muted)); margin-right: 6px; }
  .anomaly-item {
    padding: 8px 12px; margin-bottom: 6px;
    background: #fef3c7; border-left: 3px solid #d97706; border-radius: 4px;
    font-size: 13px; color: #78350f;
  }
  .anomaly-item.critical { background: #fee2e2; border-color: #dc2626; color: #7f1d1d; }
  .btn-primary, .btn-secondary {
    padding: 8px 14px; font-size: 13px; border-radius: 6px; cursor: pointer;
    border: 1px solid var(--border); background: var(--card-bg); color: var(--text);
  }
  .btn-primary { background: var(--navy-700); color: #fff; border-color: var(--navy-700); }
  .btn-primary:hover { background: var(--navy-900, #002952); }
  .btn-secondary:hover { background: rgba(0,0,0,0.03); }

  /* ── Modal (auto-fill) ── */
  .modal-backdrop {
    position: fixed; inset: 0;
    background: rgba(15,23,42,0.55);
    display: flex; align-items: center; justify-content: center;
    z-index: 1000;
  }
  .modal-card {
    background: var(--card-bg); color: var(--text);
    max-width: 540px; width: calc(100% - 32px);
    padding: 20px 22px; border-radius: 12px;
    box-shadow: 0 30px 80px rgba(0,0,0,0.4);
  }
  .modal-title { font-size: 16px; font-weight: 700; margin-bottom: 6px; }
  .modal-actions {
    margin-top: 14px; display: flex; gap: 10px; justify-content: flex-end;
  }
  .autofill-field {
    display: flex; align-items: center; gap: 10px;
    padding: 6px 4px; border-bottom: 1px solid var(--border); font-size: 13px;
  }
  .autofill-field:last-child { border-bottom: none; }
  .autofill-field label { flex: 1; }
  .autofill-field .lbl-name { font-weight: 600; }
  .autofill-field .lbl-val { color: var(--muted); margin-left: 6px; }

  /* ── Responsive ── */
  @media (max-width: 720px) {
    #sidebar { width: 62px; }
    #sidebar .nav-item { justify-content: center; padding: 12px 0; font-size: 11px; }
    #sidebar .nav-label { display: none; }
    #main { padding: 14px; }
    .stat-value.big { font-size: 28px; }
    #inverter-grid, #inverter-offline-grid { grid-template-columns: repeat(5, 1fr); }
    .stat-card { min-width: calc(50% - 6px); }
    .stat-row { gap: 8px; }
  }
  @media (max-width: 420px) {
    .brand-name { display: none; }
    .top-right .email { display: none; }
    #inverter-grid, #inverter-offline-grid { grid-template-columns: repeat(4, 1fr); }
  }

  /* ── PWA install banner (non-modal, dismissable) ── */
  #pwa-install-banner {
    display: none;
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    bottom: 16px;
    width: calc(100% - 24px);
    max-width: 480px;
    background: var(--navy-900);
    color: var(--cream);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.25);
    padding: 12px 14px;
    z-index: 9999;
    font-size: 13px;
    line-height: 1.4;
  }
  #pwa-install-banner .row { display: flex; align-items: center; gap: 10px; }
  #pwa-install-banner .icon { flex-shrink: 0; display: flex; align-items: center; }
  #pwa-install-banner .msg { flex: 1; min-width: 0; }
  #pwa-install-banner .msg b { display: block; font-size: 13px; }
  #pwa-install-banner .msg span { color: var(--muted-dim); font-size: 12px; }
  #pwa-install-banner .actions { display: flex; gap: 6px; flex-shrink: 0; }
  #pwa-install-banner button {
    background: var(--gold);
    color: var(--navy-900);
    border: 0;
    padding: 7px 12px;
    border-radius: 7px;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
  }
  #pwa-install-banner button.secondary {
    background: transparent;
    color: var(--muted-dim);
    border: 1px solid rgba(255,255,255,0.12);
  }
  /* Reachability, not full occlusion prevention: the banner is
     position:fixed over #main's own scroll area, so it can still sit on
     top of content mid-scroll. That's a smaller regression than the
     in-flow band cookie-banner.js switched to (see that file's header
     comment) because this banner is dismissable ("Not now"), suppressed
     for 30 days after dismissal, and delayed on first show — it is not
     guaranteed to be up while someone is actively reading. This class is
     toggled alongside banner.style.display in the script below so the
     LAST content in a tab (which would otherwise be permanently
     unreachable, the failure mode #main's baseline padding-bottom does
     not cover) always clears it. */
  body.pwa-banner-open #main {
    padding-bottom: 110px;
  }
  #pwa-ios-hint { display: none; }
  #pwa-ios-hint .share-icon {
    display: inline-block;
    vertical-align: -3px;
    margin: 0 2px;
    font-weight: 700;
  }

  /* ── Settings page ── */
  .settings-tabs {
    display: flex;
    gap: 2px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 18px;
    overflow-x: auto;
    background: var(--surface2);
    border-radius: 10px 10px 0 0;
  }
  .settings-tab {
    background: transparent;
    color: var(--muted);
    border: 0;
    padding: 12px 18px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    border-bottom: 3px solid transparent;
    white-space: nowrap;
    transition: color 0.1s, border-color 0.1s, background 0.1s;
  }
  .settings-tab:hover { color: var(--text); background: rgba(0,0,0,0.02); }
  .settings-tab.active { color: var(--navy-900); border-bottom-color: var(--gold); background: var(--surface); }
  /* Narrow screens: wrap the tab strip so every tab (Notifications, Support)
     is visible and tappable instead of hiding off the right edge. */
  @media (max-width: 600px) {
    .settings-tabs { flex-wrap: wrap; overflow-x: visible; }
    .settings-tab { padding: 10px 12px; }
  }
  .settings-tab-pane { display: none; }
  .settings-tab-pane.active { display: block; }

  .form-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
  }
  .form-grid label {
    display: flex;
    flex-direction: column;
    font-size: 12px;
    color: var(--muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    gap: 5px;
  }
  .form-grid input,
  .form-grid select,
  .form-grid textarea {
    font-family: var(--font);
    font-size: 14px;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #fff;
    color: var(--text);
    text-transform: none;
    font-weight: 400;
    letter-spacing: 0;
  }
  .form-grid input:focus,
  .form-grid select:focus,
  .form-grid textarea:focus {
    outline: 2px solid var(--navy-700);
    outline-offset: -1px;
    border-color: var(--navy-700);
  }
  .form-grid input:disabled { background: #f7f7f9; color: var(--muted); }
  .form-grid textarea { resize: vertical; min-height: 100px; }
  .form-grid-2 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  @media (max-width: 720px) { .form-grid-2 { grid-template-columns: minmax(0, 1fr); } }
  .form-actions {
    display: flex;
    gap: 10px;
    grid-column: 1 / -1;
    justify-content: flex-end;
    margin-top: 4px;
  }
  .btn-primary, .btn-secondary, .btn-danger {
    padding: 8px 16px;
    border-radius: 6px;
    border: 0;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: opacity 0.1s, background 0.1s;
  }
  .btn-primary { background: var(--navy-900); color: var(--cream); }
  .btn-primary:hover { background: var(--navy-700); }
  .btn-primary:disabled { background: #55657b; cursor: not-allowed; }
  .btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
  .btn-secondary:hover { background: var(--border); }
  .btn-danger { background: var(--red); color: #fff; }
  .btn-danger:hover { opacity: 0.85; }

  .card-help { font-size: 12px; color: var(--muted); line-height: 1.5; }

  /* ── Contract hint collapsible ── */
  details[open] > summary span { transform: rotate(90deg); display: inline-block; }

  /* ── Tooltips ──
     Tooltips default to appearing ABOVE the trigger. Parents like #main
     have `overflow-y: auto`, so tooltips near the top of the scroll area
     used to get clipped. Fix (2026-04-20): the `.tooltip-below` variant
     renders the tooltip below the trigger; setTooltipPlacement() on hover/focus
     auto-adds it when the trigger is within 90px of the viewport top. */
  .tooltip-wrap { position: relative; display: inline-flex; align-items: center; gap: 4px; }
  .tooltip-icon {
    display: inline-flex; align-items: center; justify-content: center;
    width: 16px; height: 16px; border-radius: 50%;
    background: var(--border); color: var(--muted); font-size: 10px;
    cursor: help; font-weight: 700; flex-shrink: 0;
  }
  .tooltip-text {
    visibility: hidden; position: absolute; bottom: 125%; top: auto; left: 50%;
    transform: translateX(-50%); background: var(--tooltip-bg, var(--navy-900)); color: var(--tooltip-fg, #fff);
    padding: 8px 12px; border-radius: 6px; font-size: 12px; width: 260px;
    z-index: 100; line-height: 1.4; box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    text-transform: none; letter-spacing: 0; font-weight: 400;
  }
  .tooltip-wrap.tooltip-below .tooltip-text {
    bottom: auto; top: 125%;
  }
  .tooltip-wrap:hover .tooltip-text,
  .tooltip-wrap:focus-within .tooltip-text { visibility: visible; }
  [data-theme="dark"] .tooltip-icon { color: #cbd5e1; }
  .tooltip-icon:focus { outline: 2px solid var(--gold, #f59e0b); outline-offset: 1px; }
  @media (max-width: 600px) {
    .tooltip-text { width: 200px; left: 0; transform: none; }
  }

  /* ── Settings section headings (inside Account tab, 2026-04-20) ── */
  .settings-section-heading {
    font-size: 13px; text-transform: uppercase; letter-spacing: 0.8px;
    color: var(--muted); font-weight: 700;
    margin: 28px 0 10px 2px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
  }

  /* ── Bill at a Glance ── */
  .bill-glance {
    padding: 16px 18px; border-radius: 10px; margin-bottom: 14px;
    background: linear-gradient(135deg, var(--card-bg) 0%, var(--surface2) 100%);
    border: 1px solid var(--border);
  }
  .bill-glance-title {
    font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px;
    color: var(--muted); font-weight: 600; margin-bottom: 10px;
  }
  .bill-glance-big {
    font-size: 28px; font-weight: 700; color: var(--text); line-height: 1.1;
    font-family: var(--mono);
  }
  .bill-glance-row {
    display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-end; margin-top: 8px;
  }
  .bill-glance-stat { font-size: 13px; color: var(--text); }
  .bill-glance-stat .lbl { font-size: 11px; color: var(--muted); margin-bottom: 2px; }
  .bill-glance-stat .val { font-weight: 600; font-family: var(--mono); }
  .bill-glance-compare {
    display: inline-block; padding: 2px 8px; border-radius: 4px;
    font-size: 12px; font-weight: 600;
  }
  .bill-glance-compare.below { background: rgba(34,197,94,0.12); color: var(--green-text); }
  .bill-glance-compare.above { background: rgba(239,68,68,0.12); color: var(--red-text); }
  .bill-glance-compare.at { background: rgba(107,114,128,0.12); color: var(--muted); }

  /* ── Aggregate bill summary ── */
  .bill-agg {
    padding: 14px 16px; border-radius: 10px; margin-bottom: 14px;
    background: var(--card-bg); border: 1px solid var(--border);
  }
  .bill-agg-title {
    font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px;
    color: var(--muted); font-weight: 600; margin-bottom: 10px;
  }
  .bill-agg-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 10px;
  }
  .bill-agg-cell .lbl { font-size: 11px; color: var(--muted); margin-bottom: 2px; }
  .bill-agg-cell .val { font-size: 15px; font-weight: 600; font-family: var(--mono); }
  .bill-agg-cell .sub { font-size: 11px; color: var(--muted); margin-top: 2px; }

  /* ── Next-bill nudge (Bills tab) ── */
  .next-bill-card {
    display: none;          /* JS flips to block when state != none */
    max-width: 900px;
    margin-bottom: 16px;
    padding: 14px 16px;
    border-radius: 8px;
    border-left: 5px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-size: 14px;
    line-height: 1.45;
  }
  .next-bill-card.red {
    border-left-color: var(--red);
    background: rgba(220,38,38,0.08);
  }
  .next-bill-card.amber {
    border-left-color: var(--yellow);
    background: rgba(217,119,6,0.08);
  }
  .next-bill-card .next-bill-title {
    font-weight: 600;
    margin-bottom: 4px;
    font-size: 14px;
  }
  .next-bill-card .next-bill-meta {
    color: var(--muted);
    font-size: 12px;
    margin-top: 4px;
  }
  .next-bill-card .next-bill-actions {
    margin-top: 10px;
  }
  [data-theme="dark"] .next-bill-card.red {
    background: rgba(239,68,68,0.10);
    color: #fecaca;
  }
  [data-theme="dark"] .next-bill-card.amber {
    background: rgba(245,158,11,0.12);
    color: #fcd34d;
  }
  [data-theme="dark"] .next-bill-card .next-bill-meta { color: var(--muted-dim); }

  /* ── Usage-pattern card ── */
  #usage-pattern-card .usage-chart-wrap {
    position: relative;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  #usage-pattern-card .usage-chart-wrap svg { display: block; width: 100%; height: 240px; }
  #usage-pattern-tooltip {
    position: absolute;
    display: none;
    background: var(--navy-900);
    color: var(--cream);
    font-size: 11px;
    font-family: var(--mono);
    padding: 6px 10px;
    border-radius: 6px;
    pointer-events: none;
    white-space: nowrap;
    z-index: 10;
    box-shadow: 0 2px 8px rgba(0,0,0,0.18);
  }
  .usage-anomaly-callout {
    border-left: 4px solid var(--yellow);
    background: #fef9ee;
    color: #78350f;
    padding: 10px 14px;
    border-radius: 0 6px 6px 0;
    font-size: 13px;
    margin-top: 10px;
    line-height: 1.5;
  }
  .usage-summary {
    font-size: 13px;
    color: var(--text);
    margin-top: 10px;
    font-family: var(--mono);
    line-height: 1.6;
  }
  .usage-summary .above { color: var(--red-text); font-weight: 600; }
  .usage-summary .below { color: var(--green-text); font-weight: 600; }
  @media (max-width: 600px) {
    #usage-pattern-card .usage-chart-wrap svg { height: 180px; }
  }
  .alert-warn {
    background: #fef3c7; border: 1px solid #fde68a; color: #92400e;
    padding: 10px 12px; border-radius: 6px; font-size: 13px; margin: 10px 0;
  }
  .codes-list {
    background: #eef2f7; border: 1px solid var(--border);
    padding: 10px 12px; border-radius: 6px; font-family: var(--mono);
    font-size: 13px; line-height: 1.7; white-space: pre; user-select: all;
    margin: 10px 0;
  }

  /* ── Onboarding wizard overlay ── */
  #onboarding-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 5000;
    background: var(--bg);
    overflow-y: auto;
  }
  #onboarding-overlay.active { display: block; }
  .ob-container {
    max-width: 720px;
    margin: 0 auto;
    padding: 24px 20px 60px;
  }
  .ob-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
  }
  .ob-logo { display: inline-flex; align-items: center; }
  .ob-logo img { height: 32px; }
  .ob-title { font-size: 22px; font-weight: 700; color: var(--navy-900); }

  /* Progress bar */
  .ob-progress {
    display: flex;
    align-items: center;
    gap: 0;
    margin-bottom: 32px;
    position: relative;
  }
  .ob-step {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    z-index: 1;
  }
  .ob-step-dot {
    width: 36px; height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700;
    border: 3px solid var(--border);
    background: var(--surface);
    color: var(--muted);
    transition: all 0.3s;
  }
  .ob-step.completed .ob-step-dot {
    background: var(--green);
    border-color: var(--green);
    color: white;
  }
  .ob-step.current .ob-step-dot {
    background: var(--gold);
    border-color: var(--gold);
    color: var(--navy-900);
    animation: ob-pulse 2s infinite;
  }
  @keyframes ob-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(240,180,41,0.4); }
    50% { box-shadow: 0 0 0 8px rgba(240,180,41,0); }
  }
  .ob-step-label {
    font-size: 11px;
    color: var(--muted);
    margin-top: 6px;
    text-align: center;
    font-weight: 600;
  }
  .ob-step.completed .ob-step-label { color: var(--green-text); }
  .ob-step.current .ob-step-label { color: var(--navy-900); font-weight: 700; }
  .ob-connector {
    flex: 1;
    height: 3px;
    background: var(--border);
    margin: 0 -8px;
    position: relative;
    top: -12px;
    z-index: 0;
  }
  .ob-connector.done { background: var(--green); }

  /* Step cards */
  .ob-card {
    display: none;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 28px 24px;
    margin-bottom: 16px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.04);
  }
  .ob-card.active { display: block; }
  .ob-card-title {
    font-size: 20px;
    font-weight: 700;
    color: var(--navy-900);
    margin-bottom: 6px;
  }
  .ob-card-subtitle {
    font-size: 14px;
    color: var(--muted);
    margin-bottom: 20px;
    line-height: 1.5;
  }
  .ob-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 20px;
    flex-wrap: wrap;
  }
  .ob-btn {
    padding: 10px 24px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.15s;
  }
  .ob-btn-primary {
    background: var(--navy-900);
    color: var(--cream);
  }
  .ob-btn-primary:hover { opacity: 0.9; }
  .ob-btn-primary:disabled { opacity: 0.5; cursor: default; }
  .ob-btn-secondary {
    background: transparent;
    color: var(--navy-700);
    border: 1px solid var(--border);
  }
  .ob-btn-secondary:hover { background: var(--surface2); }
  .ob-skip {
    font-size: 13px;
    color: var(--muted);
    cursor: pointer;
    background: none;
    border: none;
    text-decoration: underline;
    margin-left: auto;
  }
  .ob-skip:hover { color: var(--text); }

  /* Collector cards */
  .ob-collector-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    margin-bottom: 16px;
  }
  @media (max-width: 600px) {
    .ob-collector-options { grid-template-columns: 1fr; }
  }
  .ob-collector-card {
    border: 2px solid var(--border);
    border-radius: 12px;
    padding: 20px 16px;
    cursor: pointer;
    transition: all 0.15s;
    text-align: center;
  }
  .ob-collector-card:hover { border-color: var(--navy-700); }
  .ob-collector-card.selected {
    border-color: var(--gold);
    background: #fffbeb;
  }
  .ob-collector-card .ob-cc-icon { font-size: 36px; margin-bottom: 8px; }
  .ob-collector-card .ob-cc-name { font-weight: 700; font-size: 15px; color: var(--navy-900); margin-bottom: 4px; }
  .ob-collector-card .ob-cc-price { font-size: 13px; color: var(--gold); font-weight: 600; margin-bottom: 8px; }
  .ob-collector-card .ob-cc-desc { font-size: 12px; color: var(--muted); line-height: 1.5; }

  /* Device detection banners */
  .ob-detect-banner {
    padding: 14px 18px;
    border-radius: 10px;
    margin-bottom: 14px;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 12px;
  }
  .ob-detect-banner.waiting {
    background: #fef9ee;
    border: 1px solid #fde68a;
    color: #78350f;
  }
  .ob-detect-banner.found {
    background: #ecfdf5;
    border: 1px solid #bbf7d0;
    color: #166534;
  }
  .ob-detect-banner.fallback {
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    color: #1e40af;
  }
  .ob-detect-spinner {
    display: inline-block;
    width: 18px; height: 18px;
    border: 2px solid #fde68a;
    border-top-color: #d97706;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    flex-shrink: 0;
  }
  @keyframes spin { to { transform: rotate(360deg); } }
  @keyframes backfill-progress { from { width: 20%; } to { width: 90%; } }

  .ob-qr-section {
    text-align: center;
    margin: 16px 0;
  }
  .ob-qr-section img, .ob-qr-section svg {
    max-width: 200px;
    margin: 0 auto 12px;
    display: block;
  }
  .ob-pair-manual {
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: center;
    margin-top: 12px;
  }
  .ob-pair-input {
    font-family: var(--mono);
    font-size: 16px;
    font-weight: 700;
    width: 130px;
    padding: 8px 12px;
    border: 2px solid var(--border);
    border-radius: 8px;
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 2px;
  }
  .ob-pair-input:focus { border-color: var(--gold); outline: none; }

  /* Contract analysis result in wizard */
  .ob-contract-result {
    padding: 14px 18px;
    border-radius: 10px;
    margin: 14px 0;
    font-size: 13px;
    line-height: 1.6;
  }
  .ob-contract-result.guarantee {
    background: #ecfdf5;
    border: 1px solid #bbf7d0;
    color: #166534;
  }
  .ob-contract-result.no-guarantee {
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    color: #1e40af;
  }
  .ob-contract-result.wrong-brand {
    background: #fef9ee;
    border: 1px solid #fde68a;
    color: #78350f;
  }

  /* Pricing mock */
  .ob-pricing {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px;
    margin: 14px 0;
  }
  .ob-pricing-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--navy-900);
    margin-bottom: 8px;
  }
  .ob-pricing-row {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    padding: 4px 0;
  }

  /* Post-onboarding banner */
  .ob-post-banner {
    background: #ecfdf5;
    border: 1px solid #bbf7d0;
    color: #166534;
    border-radius: 10px;
    padding: 14px 18px;
    margin-bottom: 12px;
    font-size: 13px;
    line-height: 1.6;
  }
  .ob-post-banner a { color: #166534; font-weight: 600; text-decoration: underline; }
  /* Unconnected cloud-only Enphase customer: only the pinned sign-in card
     shows; every other setup prompt waits until numbers can exist. */
  body.ob-needs-enphase #nudge-zip,
  body.ob-needs-enphase #nudge-solar,
  body.ob-needs-enphase #contract-start-confirm-box,
  body.ob-needs-enphase #contract-start-confirm-box-fb { display: none !important; }
  .ob-post-close {
    float: right;
    background: none;
    border: none;
    color: #166534;
    font-size: 18px;
    cursor: pointer;
    line-height: 1;
  }

  /* Mobile responsive */
  @media (max-width: 768px) {
    .ob-container { padding: 16px 14px 40px; }
    .ob-card { padding: 20px 16px; }
    .ob-step-label { font-size: 9px; }
    .ob-step-dot { width: 30px; height: 30px; font-size: 12px; }
  }

  .toast {
    position: fixed; bottom: 20px; right: 20px;
    background: var(--navy-900); color: var(--cream);
    padding: 12px 18px; border-radius: 8px; font-size: 13px;
    box-shadow: 0 6px 20px rgba(0,0,0,0.18); opacity: 0;
    pointer-events: none; transform: translateY(8px); transition: all 0.18s;
    z-index: 10000; max-width: 360px;
  }
  .toast.show { opacity: 1; transform: translateY(0); }
  .toast.error { background: var(--red); }
  .toast.success { background: var(--green); }

  .modal-backdrop {
    position: fixed; inset: 0; background: rgba(11,26,58,0.4);
    z-index: 9998; display: flex; align-items: center; justify-content: center;
  }
  .modal {
    background: var(--surface); border-radius: 12px; padding: 24px;
    max-width: 440px; width: calc(100% - 40px); box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  }

  .dot { display:inline-block; width:10px; height:10px; border-radius:50%; vertical-align:middle; margin: 0 2px 0 8px; }
  .dot-green { background: var(--green); }
  .dot-yellow { background: var(--yellow); }
  .dot-red { background: var(--red); }

  .device-card {
    border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px;
    margin-bottom: 10px; background: var(--surface);
  }
  .device-card-head { display:flex; align-items:center; gap:10px; margin-bottom: 8px; }
  .device-card-name { font-weight: 700; font-size: 14px; }
  .device-card-meta { font-size: 11px; color: var(--muted); font-family: var(--mono); }
  /* Rename/location inputs double as the card "title" when a nickname is set,
     so their empty-state placeholder must read as an obvious hint (muted,
     normal weight) — not a bold value indistinguishable from a real saved
     nickname. Was previously only overridden for dark theme; light theme
     inherited the UA default, which combined with the inline font-weight:700
     on the input made the placeholder ("Nickname (e.g. Garage)") look like
     the actual device name. */
  .device-rename-input::placeholder,
  .device-loc-input::placeholder { color: var(--muted); font-weight: 400; opacity: 1; }
  .device-card-grid { display:grid; grid-template-columns: repeat(auto-fit,minmax(120px,1fr)); gap: 8px; font-size: 12px; }
  .device-card-actions { display:flex; gap:8px; margin-top:10px; flex-wrap:wrap; }

  .ticket-row {
    display:flex; justify-content:space-between; align-items:center;
    padding: 10px 12px; border-bottom: 1px solid var(--border);
    font-size: 13px;
  }
  .ticket-row:last-child { border-bottom: 0; }
  .ticket-status {
    font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px;
    padding: 3px 8px; border-radius: 10px; font-weight: 700;
  }
  .ticket-status.open { background: #dbeafe; color: #1e40af; }
  .ticket-status.pending { background: #fef3c7; color: #92400e; }
  .ticket-status.resolved { background: #d1fae5; color: #065f46; }
  /* Feature-request status pills (Task #77) */
  .ticket-status.submitted   { background: #e0e7ff; color: #3730a3; }
  .ticket-status.in-review   { background: #fef3c7; color: #92400e; }
  .ticket-status.planned     { background: #e0f2fe; color: #075985; }
  .ticket-status.in-progress { background: #ddd6fe; color: #5b21b6; }
  .ticket-status.shipped     { background: #d1fae5; color: #065f46; }
  .ticket-status.declined    { background: #fecaca; color: #991b1b; }

  /* ── Safe-area insets (viewport-fit=cover + notch / Dynamic Island) ──────
     env() is ignored by browsers that don't support it, so this is safe to
     apply unconditionally.  The top inset is the critical one: it prevents
     #topbar content from sliding under the iOS status bar / Dynamic Island.
     The sidebar and main content inherit the bottom inset so the home
     indicator doesn't obscure the last row of nav items or page content.   */
  #topbar {
    padding-top: calc(10px + env(safe-area-inset-top, 0px));
    padding-left: calc(20px + env(safe-area-inset-left, 0px));
    padding-right: calc(20px + env(safe-area-inset-right, 0px));
  }
  #sidebar {
    padding-top: calc(16px + env(safe-area-inset-top, 0px));
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    padding-left: env(safe-area-inset-left, 0px);
  }
  #main {
    padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    padding-right: calc(20px + env(safe-area-inset-right, 0px));
  }
  /* On narrow screens the sidebar is collapsed; still apply insets */
  @media (max-width: 720px) {
    #main { padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px)); }
  }

  /* ── Native-app overrides ───────────────────────────────────────────────
     Applied by JS (see dashboard.html) when OwlWattNative.getPlatform()
     returns a non-web platform.  Hides UI elements that are irrelevant or
     harmful inside the Capacitor WKWebView wrapper.                        */
  body.ow-native #pwa-install-banner { display: none !important; }
  body.ow-native #owlwatt-cookie-banner { display: none !important; }

/* Contract history table: never clip the Download link on a phone. */
.contract-history-wrap { overflow-x: auto; }
@media (max-width: 480px) {
  .contract-history-table th, .contract-history-table td { padding: 6px 4px !important; font-size: 12px; }
  /* Filename: one line with ellipsis (it used to wrap letter-by-letter at 390px). */
  .contract-history-table td:first-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 120px; max-width: 160px; }
}

/* Notifications matrix: stacked under 480px so channel names sit next to
   their checkboxes and nothing needs horizontal scrolling. */
@media (max-width: 480px) {
  #notif-matrix-wrap { overflow-x: visible !important; }
  .notif-matrix-table, .notif-matrix-table tbody { display: block; width: 100%; }
  .notif-matrix-table thead { display: none; }
  .notif-matrix-table tr.nm-cat-row, .notif-matrix-table tr.nm-cat-row td { display: block; }
  .notif-matrix-table tr.nm-event-row { display: flex; flex-wrap: wrap; padding: 6px 0; }
  .notif-matrix-table tr.nm-event-row > td:first-child { flex: 0 0 100%; min-width: 0 !important; padding: 6px 4px !important; }
  .notif-matrix-table tr.nm-event-row > td:first-child .card-help { max-width: none !important; }
  .notif-matrix-table td.nm-chan-cell { flex: 1 1 0; padding: 4px !important; min-width: 0; }
  .notif-matrix-table td.nm-chan-cell::before {
    content: attr(data-label); display: block; font-size: 10px; font-weight: 700;
    letter-spacing: .4px; text-transform: uppercase; color: var(--muted); margin-bottom: 4px;
  }
}

/* Contract: the "Something missing from the analysis?" disclosure summary
   colour is a theme-aware token (was slate-600, 1.93:1 on the dark card). */
.contract-missing-summary { color: #475569; }
[data-theme="dark"] .contract-missing-summary { color: #cbd5e1; }
