/* OverflowEV — unified design system */

:root {
    --sidebar-w: 240px;
    --bg: #f3f6f9;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --border: #e2e8f0;
    --text: #0b1a2a;
    --muted: #6b7a8a;
    --accent: #2ab7ca;
    --accent-soft: rgba(42, 183, 202, 0.12);
    --accent-hover: #2299aa;
    --solar: #e8b84a;
    --solar-soft: #fef6e4;
    --home: #3a7bd5;
    --home-soft: #e8f1fb;
    --ev: #2ab7ca;
    --ev-soft: rgba(42, 183, 202, 0.12);
    --ok: #6bc44a;
    --ok-soft: rgba(126, 217, 87, 0.14);
    --warn: #ca8a04;
    --warn-soft: #fef9c3;
    --err: #dc2626;
    --err-soft: #fee2e2;
    --ok-text: #4a9e32;
    --ok-border: rgba(126, 217, 87, 0.45);
    --warn-text: #a16207;
    --warn-border: #fde047;
    --home-text: #2563eb;
    --home-border: #93c5fd;
    --err-text: #b91c1c;
    --err-border: #fecaca;
    --accent-border: rgba(42, 183, 202, 0.35);
    --switch-track: #d1d5db;
    --radius: 12px;
    --radius-lg: 16px;
    --shadow-sm: 0 1px 2px rgba(11, 26, 42, 0.04);
    --shadow: 0 1px 3px rgba(11, 26, 42, 0.06), 0 4px 12px rgba(11, 26, 42, 0.05);
    --font: 'Montserrat', 'Segoe UI', system-ui, sans-serif;
    --font-display: 'Montserrat', 'Segoe UI', system-ui, sans-serif;
    --brand-ink: #0b1a2a;
    --brand-green: #7ed957;
    --brand-teal: #2ab7ca;
    --brand-gradient: linear-gradient(135deg, #7ed957 0%, #2ab7ca 100%);
}

/* ── Dark theme ── */
:root[data-theme="dark"] {
    --bg: #0b1a2a;
    --surface: #122232;
    --surface-2: #1a2d42;
    --border: #243548;
    --text: #eef2f6;
    --muted: #94a3b8;
    --accent: #7ed957;
    --accent-soft: rgba(126, 217, 87, 0.12);
    --accent-hover: #9ee878;
    --solar: #fbbf24;
    --solar-soft: #40320d;
    --home: #60a5fa;
    --home-soft: #17304f;
    --ev: #5eead4;
    --ev-soft: rgba(42, 183, 202, 0.15);
    --ok: #7ed957;
    --ok-soft: rgba(126, 217, 87, 0.12);
    --warn: #facc15;
    --warn-soft: #3a2f0a;
    --err: #f87171;
    --err-soft: #3a1717;
    --ok-text: #9ee878;
    --ok-border: rgba(126, 217, 87, 0.35);
    --warn-text: #fde047;
    --warn-border: #52440f;
    --home-text: #93c5fd;
    --home-border: #1f3f66;
    --err-text: #fca5a5;
    --err-border: #5c2323;
    --accent-border: rgba(126, 217, 87, 0.3);
    --switch-track: #3a4f63;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.3);
    --shadow: 0 1px 3px rgba(0,0,0,.4), 0 4px 14px rgba(0,0,0,.35);
}

:root[data-theme="dark"] .mfa-qr-wrap {
    background: #fff;
}

:root[data-theme="dark"] body.login-page {
    background: linear-gradient(160deg, #0b1a2a 0%, #0e2030 45%, #0a1824 100%);
}

:root[data-theme="dark"] .mfa-backup-box {
    background: var(--warn-soft);
    border-color: var(--warn-border);
}

:root[data-theme="dark"] .node-battery .flow-node-icon,
:root[data-theme="dark"] .node-battery.is-charging .flow-node-icon {
    background: var(--accent-soft);
}

:root[data-theme="dark"] .node-battery.is-discharging .flow-node-icon {
    background: var(--ok-soft);
}

:root[data-theme="dark"] .node-battery.is-grid-charge .flow-node-icon {
    background: #3a2413;
}

:root[data-theme="dark"] ::-webkit-scrollbar-thumb {
    background: #3a3f4c;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* Keep form controls / buttons on the same face as body copy */
button,
input,
textarea,
select,
optgroup {
    font-family: inherit;
    font-size: inherit;
    letter-spacing: inherit;
}

/* Brand + page titles share one face so the whole app lines up */
.brand-name,
.login-brand h1,
.home-header h1.home-brand,
.page-header h1,
.wizard-card h2,
.wizard-subhead,
.card-title {
    font-family: var(--font);
}

.brand-name,
.login-brand h1,
.home-header h1.home-brand {
    font-weight: 800;
    letter-spacing: -0.04em;
    line-height: 1.15;
    color: var(--brand-ink);
}

.brand-ev {
    background: var(--brand-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    -webkit-text-fill-color: transparent;
}

:root[data-theme="dark"] .brand-name,
:root[data-theme="dark"] .login-brand h1,
:root[data-theme="dark"] .home-header h1.home-brand {
    color: var(--text);
}

/* Form controls — always pair text + background (browsers skip color in dark mode) */
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]),
textarea,
select {
    color: var(--text);
    background-color: var(--surface);
    border-color: var(--border);
    color-scheme: light;
}
:root[data-theme="dark"] input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]),
:root[data-theme="dark"] textarea,
:root[data-theme="dark"] select {
    color-scheme: dark;
    background-color: var(--surface-2);
    color: var(--text);
}
:root[data-theme="dark"] input::placeholder,
:root[data-theme="dark"] textarea::placeholder {
    color: var(--muted);
    opacity: 1;
}
:root[data-theme="dark"] input:-webkit-autofill,
:root[data-theme="dark"] input:-webkit-autofill:hover,
:root[data-theme="dark"] input:-webkit-autofill:focus,
:root[data-theme="dark"] textarea:-webkit-autofill,
:root[data-theme="dark"] select:-webkit-autofill {
    -webkit-text-fill-color: var(--text);
    caret-color: var(--text);
    box-shadow: 0 0 0 1000px var(--surface-2) inset;
    transition: background-color 99999s ease-in-out 0s;
}

/* ── Layout ── */
.layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 50;
    padding: 20px 16px;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px 24px;
    text-decoration: none;
    color: var(--text);
}

.brand-mark {
    width: 36px; height: 36px;
    background: var(--accent);
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    color: white;
    flex-shrink: 0;
}

.brand-logo {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    object-fit: cover;
    flex-shrink: 0;
    display: block;
}

.brand-logo-lg {
    width: 72px;
    height: 72px;
    border-radius: 16px;
}

.brand-name {
    font-size: 1.05rem;
}

.brand-mark svg { width: 20px; height: 20px; }

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 14px;
    border-radius: 10px;
    text-decoration: none;
    color: var(--muted);
    font-weight: 500;
    font-size: 0.9375rem;
    transition: background .15s, color .15s;
}

.nav-item:hover {
    background: var(--surface-2);
    color: var(--text);
}

.nav-item.active {
    background: var(--accent-soft);
    color: var(--brand-teal);
    font-weight: 600;
}

:root[data-theme="dark"] .nav-item.active {
    color: var(--brand-green);
}

.nav-item svg {
    width: 20px; height: 20px;
    flex-shrink: 0;
    opacity: 0.85;
}

.nav-item.active svg { opacity: 1; }

.sidebar-foot {
    padding: 16px 12px 8px;
    border-top: 1px solid var(--border);
    margin-top: auto;
}

.live-pill {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8125rem;
    color: var(--muted);
    font-weight: 500;
}

.live-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--ok);
    flex-shrink: 0;
}

.live-dot.off { background: var(--err); }

.sidebar-polling {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 0 12px;
}

.sidebar-polling-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.sidebar-polling-text strong {
    font-size: 0.8125rem;
    font-weight: 600;
}

.sidebar-polling-text span {
    font-size: 0.75rem;
    color: var(--muted);
    line-height: 1.3;
}

.sidebar-user {
    margin-top: 10px;
    padding: 8px 10px;
    border-radius: 8px;
    background: var(--surface-2);
    border: 1px solid var(--border);
}

.sidebar-user-label {
    display: block;
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    margin-bottom: 2px;
}

.sidebar-user-name {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text);
    line-height: 1.3;
    word-break: break-word;
}

.theme-toggle {
    width: 100%;
    margin-top: 10px;
    padding: 8px 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-2);
    color: var(--muted);
    cursor: pointer;
    transition: background .15s, color .15s, border-color .15s;
}

.theme-toggle svg { width: 17px; height: 17px; }

.theme-toggle:hover {
    background: var(--accent-soft);
    color: var(--accent-hover);
    border-color: var(--accent-border);
}

.sidebar-logout {
    width: 100%;
    margin-top: 8px;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-2);
    color: var(--muted);
    font-size: 0.8125rem;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s, color .15s;
}

.sidebar-logout:hover {
    background: var(--err-soft);
    color: var(--err);
    border-color: var(--err-border);
}

/* Login page */
body.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(ellipse 80% 60% at 15% 10%, rgba(126, 217, 87, 0.12), transparent 55%),
        radial-gradient(ellipse 70% 55% at 85% 90%, rgba(42, 183, 202, 0.1), transparent 55%),
        linear-gradient(160deg, #f8fbf9 0%, var(--bg) 45%, #eef6f8 100%);
    padding: 24px;
}

.login-wrap {
    width: 100%;
    max-width: 400px;
}

.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 32px 28px;
}

.login-brand {
    text-align: center;
    margin-bottom: 28px;
}

.login-brand .brand-mark,
.login-brand .brand-logo {
    margin: 0 auto 14px;
}

.login-brand h1 {
    font-size: 1.5rem;
    margin-bottom: 6px;
}

.login-brand p {
    color: var(--muted);
    font-size: 0.9375rem;
}

.login-form .form-field {
    margin-bottom: 16px;
}

.login-form label {
    display: block;
    font-size: 0.8125rem;
    font-weight: 600;
    margin-bottom: 6px;
}

.login-form input {
    width: 100%;
    padding: 11px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    font: inherit;
    color: var(--text);
    background: var(--surface-2);
}

.login-form input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.login-form .btn {
    width: 100%;
    margin-top: 8px;
}

.login-error {
    margin-top: 12px;
    font-size: 0.875rem;
    color: var(--err);
    text-align: center;
}

.login-mfa-hint {
    font-size: 0.875rem;
    color: var(--muted);
    margin-bottom: 16px;
    line-height: 1.5;
}

/* ── Time-of-use window editor ── */
.tou-rates {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin: 4px 0 18px;
}
.tou-rate-card {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 12px 12px 10px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface-2);
}
.tou-rate-card.tier-peak { border-color: color-mix(in srgb, var(--err) 35%, var(--border)); background: var(--err-soft); }
.tou-rate-card.tier-off { border-color: color-mix(in srgb, var(--home) 35%, var(--border)); background: var(--home-soft); }
.tou-rate-card.tier-super { border-color: color-mix(in srgb, var(--ok) 35%, var(--border)); background: var(--ok-soft); }
.tou-rate-label {
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: var(--muted);
}
.tou-rate-card.tier-peak .tou-rate-label { color: var(--err-text); }
.tou-rate-card.tier-off .tou-rate-label { color: var(--home-text); }
.tou-rate-card.tier-super .tou-rate-label { color: var(--ok-text); }
.tou-rate-card input {
    width: 100%;
    font-size: 1.125rem;
    font-weight: 600;
    border: none;
    background: transparent;
    color: var(--text);
    padding: 0;
}
.tou-rate-card input:focus { outline: none; }
.tou-rate-unit { font-size: 0.7rem; color: var(--muted); }

.tou-windows-field { margin-top: 4px; }
.tou-windows-head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}
.tou-windows-head label { display: block; margin-bottom: 2px; }
.tou-windows-head small { display: block; color: var(--muted); line-height: 1.35; }
.tou-windows-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.tou-windows {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.tou-empty {
    text-align: center;
    padding: 28px 16px;
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    background: var(--surface-2);
}
.tou-empty p { margin: 0 0 12px; color: var(--muted); }

.tou-card {
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface);
    padding: 14px 14px 12px;
    box-shadow: var(--shadow-sm);
    border-left: 4px solid var(--border);
    transition: border-color .15s ease, box-shadow .15s ease;
}
.tou-card.tier-peak { border-left-color: var(--err); }
.tou-card.tier-off { border-left-color: var(--home); }
.tou-card.tier-super { border-left-color: var(--ok); }

.tou-card-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 12px;
}
.tou-tier-pills {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 3px;
    border-radius: 999px;
    background: var(--bg);
    border: 1px solid var(--border);
}
.tou-tier {
    border: none;
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-size: 0.8125rem;
    font-weight: 600;
    padding: 6px 12px;
    border-radius: 999px;
    cursor: pointer;
}
.tou-tier:hover { color: var(--text); }
.tou-card.tier-peak .tou-tier.active { background: var(--err); color: #fff; }
.tou-card.tier-off .tou-tier.active { background: var(--home); color: #fff; }
.tou-card.tier-super .tou-tier.active { background: var(--ok); color: #fff; }
.tou-remove {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--muted);
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
}
.tou-remove:hover { border-color: var(--err-border); color: var(--err); background: var(--err-soft); }

.tou-times {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 10px 12px;
    margin-bottom: 10px;
}
.tou-time {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}
.tou-time span {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
}
.tou-time input[type="time"] {
    font-size: 1.05rem;
    font-weight: 600;
    padding: 8px 10px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    min-width: 7.5rem;
}
.tou-arrow {
    color: var(--muted);
    font-size: 1.1rem;
    padding-bottom: 10px;
}
.tou-overnight {
    display: none;
    align-self: center;
    margin-bottom: 2px;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--warn-text);
    background: var(--warn-soft);
    border: 1px solid var(--warn-border);
    padding: 4px 8px;
    border-radius: 999px;
}
.tou-overnight.show { display: inline-flex; }

.tou-timeline { margin: 0 0 12px; }
.tou-timeline-track {
    display: grid;
    grid-template-columns: repeat(24, 1fr);
    gap: 2px;
    height: 10px;
}
.tou-timeline-track i {
    display: block;
    border-radius: 2px;
    background: var(--border);
}
.tou-card.tier-peak .tou-timeline-track i.on { background: var(--err); }
.tou-card.tier-off .tou-timeline-track i.on { background: var(--home); }
.tou-card.tier-super .tou-timeline-track i.on { background: var(--ok); }
.tou-timeline-labels {
    display: flex;
    justify-content: space-between;
    margin-top: 4px;
    font-size: 0.65rem;
    color: var(--muted);
}

.tou-days-block { display: flex; flex-direction: column; gap: 8px; }
.tou-day-pills {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 6px;
}
.tou-day {
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--muted);
    font: inherit;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 8px 0;
    border-radius: 10px;
    cursor: pointer;
    transition: background .12s ease, border-color .12s ease, color .12s ease;
}
.tou-day:hover { border-color: var(--accent-border); color: var(--text); }
.tou-day.on {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}
.tou-day-presets {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.tou-preset {
    border: 1px solid var(--border);
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 5px 10px;
    border-radius: 999px;
    cursor: pointer;
}
.tou-preset:hover { border-color: var(--accent); color: var(--accent-hover); }
.tou-preset.active {
    background: var(--accent-soft);
    border-color: var(--accent);
    color: var(--accent-hover);
}

@media (max-width: 640px) {
    .tou-rates { grid-template-columns: 1fr; }
    .tou-windows-head { flex-direction: column; }
    .tou-time input[type="time"] { min-width: 0; width: 100%; }
    .tou-times { display: grid; grid-template-columns: 1fr auto 1fr; align-items: end; }
    .tou-overnight { grid-column: 1 / -1; justify-self: start; }
}

.mfa-status-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.mfa-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 16px;
}

.mfa-qr-wrap {
    display: flex;
    justify-content: center;
    margin: 20px 0;
    padding: 16px;
    background: #fff;
    border-radius: 12px;
    border: 1px solid var(--border);
    width: fit-content;
}

.mfa-qr {
    width: 200px;
    height: 200px;
    image-rendering: pixelated;
}

.mfa-manual-secret {
    margin-bottom: 16px;
    font-size: 0.875rem;
}

.mfa-manual-secret code {
    display: block;
    margin-top: 8px;
    padding: 10px 12px;
    background: var(--surface-2);
    border-radius: 8px;
    font-size: 0.8125rem;
    word-break: break-all;
}

.mfa-backup-box {
    margin-top: 20px;
    padding: 16px;
    border-radius: 12px;
    background: #fffbeb;
    border: 1px solid #f59e0b;
}

.mfa-backup-list {
    list-style: none;
    padding: 0;
    margin: 12px 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 8px;
    font-family: ui-monospace, monospace;
    font-size: 0.875rem;
}

.mfa-disable-form {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}


.main {
    flex: 1;
    margin-left: var(--sidebar-w);
    padding: 28px 40px 28px;
    max-width: 1100px;
}

body[data-page="dashboard"] .main {
    padding: 20px 32px 16px;
    padding-bottom: 16px;
}

/* ── Page header ── */
.page-header {
    margin-bottom: 20px;
}

body[data-page="dashboard"] .page-header {
    margin-bottom: 12px;
}

/* Dashboard: tighten cards / rings so less empty vertical space. */
body[data-page="dashboard"] .flow-panel {
    padding: 12px 14px 8px;
    margin-bottom: 10px;
}

body[data-page="dashboard"] .grid-2 {
    gap: 14px;
}

body[data-page="dashboard"] .card {
    padding: 16px 18px;
}

body[data-page="dashboard"] .card-title {
    margin-bottom: 12px;
}

body[data-page="dashboard"] .vehicle-card-head,
body[data-page="dashboard"] .vehicle-card-head.card-title {
    margin-bottom: 12px;
}

body[data-page="dashboard"] .ring-wrap {
    width: 112px;
    height: 112px;
    margin: 0 auto 12px;
}

body[data-page="dashboard"] .ring-pct {
    font-size: 1.4rem;
}

body[data-page="dashboard"] .stat-mini-row {
    gap: 18px;
}

body[data-page="dashboard"] .vehicle-refresh-row {
    margin-top: 10px;
    padding-top: 10px;
}

body[data-page="dashboard"] .session-panel {
    gap: 12px;
}

body[data-page="dashboard"] .mode-intent {
    margin: 0 0 10px;
    min-height: 0;
}

body[data-page="dashboard"] .mode-chip {
    padding: 10px 12px;
}

body[data-page="dashboard"] .stat-row {
    margin-bottom: 12px;
    gap: 12px;
}

body[data-page="dashboard"] .stat-card {
    padding: 14px 16px;
}

body[data-page="dashboard"] .stat-card-top {
    margin-bottom: 8px;
}

body[data-page="dashboard"] .stat-value {
    font-size: 1.55rem;
    margin-bottom: 6px;
}

.page-header h1 {
    font-family: var(--font);
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.2;
    margin-bottom: 4px;
}

.page-header p {
    color: var(--muted);
    font-size: 0.9375rem;
}

.page-header-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    flex-wrap: wrap;
}

.header-meta {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.meta-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--muted);
}

.meta-chip-toggle {
    cursor: pointer;
    user-select: none;
    gap: 10px;
}

.meta-chip-label {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--muted);
    white-space: nowrap;
}

.switch-sm {
    width: 40px;
    height: 22px;
}

.switch-sm .switch-track::after {
    width: 16px;
    height: 16px;
}

.switch-sm input:checked + .switch-track::after {
    transform: translateX(18px);
}

.btn-sm {
    padding: 6px 14px;
    font-size: 0.8125rem;
    min-height: 34px;
}

.meta-chip.on {
    background: var(--ok-soft);
    border-color: var(--ok-border);
    color: var(--ok-text);
}

.meta-chip .live-dot { width: 6px; height: 6px; }

/* ── Energy stats ── */
.stat-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 22px 24px;
    box-shadow: var(--shadow-sm);
}

.stat-card-top {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
}

.stat-icon {
    width: 40px; height: 40px;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
}

.stat-icon svg { width: 20px; height: 20px; }

.stat-icon.solar { background: var(--solar-soft); color: var(--solar); }
.stat-icon.home { background: var(--home-soft); color: var(--home); }
.stat-icon.excess { background: var(--ok-soft); color: var(--ok); }

.stat-label {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    line-height: 1.1;
    margin-bottom: 10px;
}

.stat-bar {
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    overflow: hidden;
}

.stat-bar-fill {
    height: 100%;
    border-radius: 2px;
    width: 0%;
    transition: width .5s ease;
}

.stat-bar-fill.solar { background: var(--solar); }
.stat-bar-fill.home { background: var(--home); }
.stat-bar-fill.excess { background: var(--ok); }

/* ── Live energy flow ── */
.flow-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px 18px 12px;
    box-shadow: var(--shadow-sm);
    margin-bottom: 12px;
    --solar-flow: #f59e0b;
    --evsolar-flow: #16a34a;
    --home-flow: #2563eb;
    --export-flow: #2ab7ca;
    --import-flow: #ea580c;
    --batt-charge-flow: #2ab7ca;
    --batt-discharge-flow: #059669;
    --muted-flow: #cbd5e1;
}

.flow-headline {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text);
    margin-bottom: 6px;
    min-height: 24px;
}

.flow-headline-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--muted);
    flex-shrink: 0;
    transition: background .4s, box-shadow .4s;
}

.flow-headline.is-free .flow-headline-dot { background: var(--evsolar-flow); box-shadow: 0 0 0 4px rgba(22,163,74,.15); }
.flow-headline.is-import .flow-headline-dot { background: var(--import-flow); }
.flow-headline.is-export .flow-headline-dot { background: var(--export-flow); }
.flow-headline.is-idle .flow-headline-dot { background: var(--muted); }
.flow-headline.is-error .flow-headline-dot { background: var(--err); }

.flow-stage {
    position: relative;
    width: 100%;
    aspect-ratio: 1000 / 520;
    max-height: 420px;
    margin: 0 auto;
}

/* No home battery → don't reserve a empty bottom band. */
.flow-stage.no-battery {
    aspect-ratio: 1000 / 400;
    max-height: 340px;
}

.flow-stage.is-multi-ev {
    aspect-ratio: 1000 / 540;
    max-height: 440px;
}

.flow-stage.is-multi-ev.no-battery {
    aspect-ratio: 1000 / 430;
    max-height: 360px;
}

.flow-stage.is-multi-ev.has-battery {
    aspect-ratio: 1000 / 620;
    max-height: 500px;
}

.flow-stage .node-ev-fleet {
    width: clamp(120px, 16%, 168px);
    padding: 8px 10px;
}

.flow-stage .node-ev-fleet .flow-node-head {
    margin-bottom: 4px;
    gap: 6px;
}

.flow-stage .node-ev-fleet .flow-node-icon {
    width: 26px;
    height: 26px;
    border-radius: 7px;
}

.flow-stage .node-ev-fleet .flow-node-title {
    font-size: 0.78rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 7.5rem;
}

.flow-stage .node-ev-fleet .flow-node-value {
    font-size: 0.95rem;
}

.flow-stage .node-ev-fleet .flow-node-status {
    font-size: 0.62rem;
    line-height: 1.25;
    max-width: 9rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.vehicle-key-warn {
    width: 100%;
    margin: 0;
    font-size: 0.8125rem;
    color: var(--warn, #b45309);
}

.virtual-key-banner {
    margin: 12px 0 0;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid #fcd34d;
    background: #fffbeb;
    color: #92400e;
}

.virtual-key-banner p {
    margin: 0 0 8px;
    font-size: 0.8125rem;
    line-height: 1.4;
}

.virtual-key-banner-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

:root[data-theme="dark"] .virtual-key-banner {
    background: rgba(180, 83, 9, 0.18);
    border-color: rgba(251, 191, 36, 0.35);
    color: #fcd34d;
}

.flow-svg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    overflow: visible;
    pointer-events: none;
}

.flow-line {
    fill: none;
    stroke-width: 2.5;
    stroke-linecap: round;
    stroke-linejoin: round;
    opacity: 0;
    transition: opacity .4s ease, stroke .4s ease, stroke-width .4s ease;
}

.flow-line.active { opacity: 1; }

.flow-line[data-edge^="solar"] { stroke: var(--solar-flow); marker-end: url(#arrowSolar); }
.flow-line[data-edge^="grid"] { stroke: var(--home-flow); marker-end: url(#arrowGrid); }
.flow-line[data-edge^="battery"] { stroke: var(--batt-discharge-flow); marker-end: url(#arrowBattery); }

/* Labels — small pills sitting mid-way along a connector line, matching the
   "2.1 kW · To Grid" callouts on the reference design. */
.flow-label {
    position: absolute;
    transform: translate(-50%, -50%);
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 3px 9px;
    border-radius: 999px;
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    font-size: .72rem;
    line-height: 1.3;
    white-space: nowrap;
    opacity: 0;
    transition: opacity .35s ease, left .35s ease, top .35s ease;
    pointer-events: none;
}

.flow-label.active { opacity: 1; }

.flow-label-val { font-weight: 700; color: var(--text); }
.flow-label-dir { color: var(--muted); font-weight: 500; }

.flow-label[data-tone="solar"] .flow-label-val { color: var(--solar-flow); }
.flow-label[data-tone="grid"] .flow-label-val { color: var(--home-flow); }
.flow-label[data-tone="battery"] .flow-label-val { color: var(--batt-discharge-flow); }

.flow-node {
    position: absolute;
    transform: translate(-50%, -50%);
    width: clamp(140px, 19%, 200px);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 12px 14px;
    text-align: left;
    box-shadow: var(--shadow);
    transition: opacity .4s, border-color .4s, box-shadow .4s;
    z-index: 2;
}

.flow-node-head {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.flow-node-icon {
    width: 32px;
    height: 32px;
    border-radius: 9px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface-2);
    color: var(--muted);
}

.flow-node-icon svg { width: 18px; height: 18px; }

.flow-node-title {
    font-size: .74rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.flow-node-value {
    font-size: clamp(1.05rem, 2vw, 1.4rem);
    font-weight: 700;
    letter-spacing: -.02em;
    line-height: 1.15;
}

.flow-node-status {
    font-size: .74rem;
    color: var(--muted);
    line-height: 1.3;
    margin-top: 1px;
}

.node-solar .flow-node-icon { background: var(--solar-soft); color: var(--solar); }
.node-home .flow-node-icon { background: var(--home-soft); color: var(--home); }
.node-ev .flow-node-icon { background: var(--ev-soft); color: var(--ev); }
.node-grid .flow-node-icon { background: var(--surface-2); color: var(--muted); }
.node-battery .flow-node-icon { background: var(--accent-soft); color: var(--batt-charge-flow); }
.node-battery.is-charging .flow-node-icon { background: var(--accent-soft); color: var(--batt-charge-flow); }
.node-battery.is-discharging .flow-node-icon { background: var(--ok-soft); color: var(--batt-discharge-flow); }
.node-battery.is-grid-charge .flow-node-icon { background: #ffedd5; color: var(--import-flow); }

.flow-node.is-hidden, .flow-line.is-hidden, .flow-label.is-hidden { display: none; }

.flow-node.node-ev.is-free {
    border-color: var(--ok-border);
    box-shadow: 0 0 0 3px rgba(22,163,74,.12), var(--shadow);
}
.flow-node.node-ev.is-free .flow-node-icon { background: var(--ok-soft); color: var(--ok); }
.flow-node.is-dim { opacity: .55; }
.flow-node.is-offline { opacity: .6; border-style: dashed; }

.flow-legend {
    display: flex;
    justify-content: center;
    gap: 22px;
    padding-top: 10px;
    margin-top: 2px;
    border-top: 1px solid var(--border);
    flex-wrap: wrap;
}

.flow-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-size: .78rem;
    color: var(--muted);
    font-weight: 500;
}

.flow-legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}

.flow-legend-dot.solar { background: var(--solar-flow); }
.flow-legend-dot.grid { background: var(--home-flow); }
.flow-legend-dot.battery { background: var(--batt-discharge-flow); }

@media (max-width: 620px) {
    .flow-stage {
        aspect-ratio: 360 / 520;
        max-height: none;
    }
    .flow-stage.no-battery {
        aspect-ratio: 360 / 380;
    }
    .flow-stage.is-multi-ev.no-battery {
        aspect-ratio: 360 / 420;
    }
    .flow-node {
        width: clamp(104px, 32%, 140px);
        padding: 8px 8px;
        border-radius: 12px;
    }
    .flow-node-head { gap: 5px; margin-bottom: 5px; }
    .flow-node-icon { width: 22px; height: 22px; border-radius: 6px; }
    .flow-node-icon svg { width: 13px; height: 13px; }
    .flow-node-title {
        font-size: .6rem;
        white-space: normal;
        line-height: 1.15;
        overflow: visible;
        text-overflow: clip;
    }
    .flow-node-value { font-size: .88rem; }
    .flow-node-status { font-size: .6rem; }
    .flow-label { font-size: .62rem; padding: 2px 6px; }
    .flow-legend { gap: 14px; }
    .flow-legend-item { font-size: .7rem; }
}

/* ── Setup cards ── */
.section-label {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    margin-bottom: 12px;
}

.setup-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 28px;
}

.setup-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
    display: flex;
    gap: 14px;
    align-items: flex-start;
    transition: border-color .2s;
}

.setup-card.ok { border-color: var(--ok-border); }
.setup-card.warn { border-color: var(--warn-border); }
.setup-card.info { border-color: var(--home-border); }

.setup-card-icon {
    width: 44px; height: 44px;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}

.setup-card-icon svg { width: 22px; height: 22px; }

.setup-card-icon.solar { background: var(--solar-soft); color: var(--solar); }
.setup-card-icon.home { background: var(--home-soft); color: var(--home); }
.setup-card-icon.ev { background: var(--ev-soft); color: var(--ev); }

.setup-card-body { flex: 1; min-width: 0; }

.setup-card-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    margin-bottom: 2px;
}

.setup-card-head h3 {
    font-size: 0.9375rem;
    font-weight: 600;
}

.setup-card-body p {
    font-size: 0.8125rem;
    color: var(--muted);
    line-height: 1.4;
}

.badge {
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 3px 8px;
    border-radius: 6px;
    white-space: nowrap;
    flex-shrink: 0;
}

.badge.ok { background: var(--ok-soft); color: var(--ok-text); }
.badge.warn { background: var(--warn-soft); color: var(--warn-text); }
.badge.info { background: var(--home-soft); color: var(--home-text); }
.badge:not(.ok):not(.warn):not(.info) { background: var(--surface-2); color: var(--muted); }

.text-link {
    color: var(--accent);
    font-weight: 600;
    font-size: 0.875rem;
    text-decoration: none;
}

.text-link:hover { text-decoration: underline; }

/* ── Two column ── */
.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-sm);
}

.card-title {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.card-title svg { width: 18px; height: 18px; color: var(--muted); }

.card-title > span { display: inline-flex; align-items: center; color: var(--muted); }

/* Vehicle ring */
.ring-wrap {
    position: relative;
    width: 140px; height: 140px;
    margin: 0 auto 20px;
}

.ring-wrap svg { width: 100%; height: 100%; display: block; }

.ring-center {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.ring-pct {
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.03em;
}

.ring-label {
    font-size: 0.6875rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 600;
}

.stat-mini-row {
    display: flex;
    justify-content: center;
    gap: 28px;
}

.vehicle-refresh-row {
    display: flex;
    justify-content: center;
    margin-top: 16px;
    padding-top: 14px;
    border-top: 1px solid var(--border);
}

.vehicle-refresh-row .btn {
    min-width: 7rem;
}

.vehicle-card {
    position: relative;
}

.vehicle-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 20px;
}

.vehicle-card-head.card-title {
    margin-bottom: 20px;
}

.vehicle-card-head-title {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.vehicle-solar-slot:empty,
.vehicle-solar-slot[hidden] {
    display: none;
}

.session-vehicles {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.vehicle-share-line {
    margin: 10px 0 0;
    font-size: 0.8125rem;
    color: var(--muted);
}

.vehicle-fleet-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 16px;
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
}

.vehicle-mode-picker {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    margin-left: auto;
}

.vehicle-mode-caption {
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--muted);
    text-transform: uppercase;
}

.vehicle-mode-picker select {
    min-width: 8.5rem;
    padding: 6px 10px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-size: 0.8125rem;
    font-weight: 600;
}

.fleet-alloc {
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.fleet-alloc-chips {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 8px;
}

.fleet-alloc-chip {
    text-align: left;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--surface);
    cursor: pointer;
    color: inherit;
}

.fleet-alloc-chip strong {
    display: block;
    font-size: 0.875rem;
}

.fleet-alloc-chip span {
    display: block;
    margin-top: 2px;
    font-size: 0.75rem;
    color: var(--muted);
}

.fleet-alloc-chip.is-active {
    border-color: var(--accent-border, var(--accent));
    background: var(--accent-soft, rgba(42, 183, 202, 0.12));
}

.fleet-site-hint {
    margin-top: 8px;
}

.flow-stage .node-ev[data-fleet-ev] .flow-node-status {
    max-width: 9.5rem;
}

.vehicle-solar-radio {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    margin-left: auto;
}

.vehicle-solar-radio-caption {
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--muted);
    text-transform: uppercase;
}

.vehicle-solar-radio-track {
    display: inline-flex;
    padding: 3px;
    border-radius: 999px;
    background: var(--surface-2, rgba(0, 0, 0, 0.04));
    border: 1px solid var(--border);
    gap: 2px;
}

.vehicle-solar-radio-opt {
    position: relative;
    cursor: pointer;
    margin: 0;
}

.vehicle-solar-radio-opt input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.vehicle-solar-radio-opt span {
    display: block;
    min-width: 2.4rem;
    padding: 5px 11px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1.2;
    text-align: center;
    color: var(--muted);
    transition: background .15s ease, color .15s ease, box-shadow .15s ease;
}

.vehicle-solar-radio-opt input[value="1"]:checked + span {
    background: var(--ok, #16a34a);
    color: #fff;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
}

.vehicle-solar-radio-opt input[value="0"]:checked + span {
    background: var(--text);
    color: var(--surface);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.vehicle-solar-radio-opt input:focus-visible + span {
    outline: 2px solid var(--accent, #2ab7ca);
    outline-offset: 2px;
}

.vehicle-priority-btns {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.tesla-vehicle-actions {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.tesla-vehicles-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin: 12px 0;
}

.tesla-multi-list {
    display: grid;
    gap: 8px;
    margin: 0 0 12px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface-2, rgba(0, 0, 0, 0.03));
}

.tesla-multi-item {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.95rem;
    cursor: pointer;
}

.tesla-multi-item input {
    width: auto;
    accent-color: var(--accent, #2ab7ca);
}

.tesla-vehicle-row {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px;
}

.tesla-vehicle-row-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 8px;
}

.tesla-vehicle-row-fields {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.tesla-vehicle-row-fields label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 0.8125rem;
    color: var(--muted);
}

.tesla-vehicle-row-fields input {
    width: 100%;
}

.tesla-enable {
    display: flex;
    align-items: center;
    gap: 8px;
}

.vehicle-card-body {
    transition: opacity 0.25s ease, filter 0.25s ease;
}

.vehicle-card.is-stale .vehicle-card-body {
    opacity: 0.5;
    filter: grayscale(0.35) saturate(0.7);
}

.stat-mini {
    text-align: center;
}

.stat-mini-label {
    font-size: 0.6875rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
    margin-bottom: 2px;
}

.stat-mini-val {
    font-size: 0.9375rem;
    font-weight: 600;
}

.stat-mini-val.ok { color: var(--ok); }
.stat-mini-val.warn { color: var(--err); }
.stat-mini-val.muted { color: var(--muted); }

/* Controls */
.toggle-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px;
    background: var(--surface-2);
    border-radius: var(--radius);
    margin-bottom: 16px;
}

.toggle-row strong {
    display: block;
    font-size: 0.9375rem;
    margin-bottom: 1px;
}

.toggle-row span {
    font-size: 0.8125rem;
    color: var(--muted);
}

.btn-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 20px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 20px;
    border: none;
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 0.9375rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity .15s, transform .1s;
}

.btn svg { width: 16px; height: 16px; }

.btn:active:not(:disabled) { transform: scale(.98); }
.btn:disabled { opacity: .4; cursor: not-allowed; }

.btn-start { background: var(--ok); color: white; }
.btn-stop { background: var(--err); color: white; }
.btn-accent {
    background: var(--brand-gradient);
    color: white;
    box-shadow: 0 4px 14px rgba(42, 183, 202, 0.22);
}

.btn-accent:hover:not(:disabled) {
    filter: brightness(1.05);
    box-shadow: 0 6px 18px rgba(42, 183, 202, 0.28);
}
.btn-ghost {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
}

.btn-lg { padding: 14px 28px; font-size: 1rem; }

.field-label {
    display: block;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--muted);
    margin-bottom: 8px;
}

.field-row {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
}

.field-row input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 0.9375rem;
    color: var(--text);
    background: var(--surface-2);
}

.field-row input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(13,148,136,.12);
}

.chips {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.chip {
    padding: 6px 14px;
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: 999px;
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
    color: var(--text);
    transition: border-color .15s, background .15s;
}

.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-hover); }

.schedule-days {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 6px;
}
.schedule-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.schedule-card {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
    background: var(--surface-2, rgba(255,255,255,0.02));
}
.schedule-card-head {
    display: flex;
    align-items: center;
    gap: 12px;
}
.schedule-card-head .schedule-name {
    flex: 1;
    min-width: 0;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 12px;
    background: transparent;
    color: inherit;
}
.activity-log {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 320px;
    overflow-y: auto;
}
.activity-log-tall { max-height: 480px; }
.activity-item {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 14px;
    background: var(--surface-2);
}
.activity-item.tone-ok { border-left: 3px solid var(--ok); }
.activity-item.tone-err { border-left: 3px solid var(--err); }
.activity-item.tone-warn { border-left: 3px solid var(--warn); }
.activity-item.tone-muted { border-left: 3px solid var(--border); }
.activity-item-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    font-size: 0.875rem;
}
.activity-item-title {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}
.activity-source {
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--muted);
}
.activity-source.source-manual { color: var(--home-text); border-color: var(--home-border); background: var(--home-soft); }
.activity-source.source-solar { color: var(--ok-text); border-color: var(--ok-border); background: var(--ok-soft); }
.activity-source.source-schedule { color: var(--warn-text); border-color: var(--warn-border); background: var(--warn-soft); }
.activity-when { white-space: nowrap; font-size: 0.75rem; }
.activity-item-msg {
    margin-top: 4px;
    color: var(--muted);
    font-size: 0.875rem;
}
.chip-check {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 0.8125rem;
    cursor: pointer;
    user-select: none;
}
.chip-check:has(input:checked) {
    background: var(--accent-soft);
    border-color: var(--accent);
    color: var(--accent-hover);
}
.chip-check input { margin: 0; }

/* Switch */
.switch {
    position: relative;
    width: 48px; height: 26px;
    flex-shrink: 0;
}

.switch input { opacity: 0; width: 0; height: 0; position: absolute; }

.switch-track {
    position: absolute;
    inset: 0;
    background: var(--switch-track);
    border-radius: 999px;
    cursor: pointer;
    transition: background .2s;
}

.switch-track::after {
    content: '';
    position: absolute;
    width: 20px; height: 20px;
    left: 3px; top: 3px;
    background: white;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0,0,0,.15);
    transition: transform .2s;
}

.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(22px); }

/* Toast */
.toast {
    position: fixed;
    bottom: 24px; left: 50%;
    transform: translateX(-50%);
    padding: 12px 20px;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 500;
    z-index: 200;
    box-shadow: var(--shadow);
    max-width: 90vw;
}

.toast.ok { background: var(--ok-soft); color: var(--ok-text); border: 1px solid var(--ok-border); }
.toast.warn { background: var(--warn-soft); color: var(--warn-text); border: 1px solid var(--warn-border); }
.toast.err { background: var(--err-soft); color: var(--err-text); border: 1px solid var(--err-border); }

.toast-inline {
    position: static;
    transform: none;
    margin-bottom: 16px;
}

/* ── Settings ── */
.setup-progress {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 28px;
}

@media (max-width: 960px) {
    .setup-progress { grid-template-columns: 1fr; }
}

.progress-step {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.progress-step .badge { margin-left: auto; }

.step-num {
    width: 32px; height: 32px;
    background: var(--accent);
    color: white;
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700;
    font-size: 0.875rem;
    flex-shrink: 0;
}

.step-body { flex: 1; min-width: 0; }
.step-body small {
    display: block;
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    margin-bottom: 2px;
}
.step-body strong {
    font-size: 0.9375rem;
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tabs {
    display: flex;
    gap: 4px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 4px;
    margin-bottom: 24px;
}

.tab {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 16px;
    border: none;
    background: none;
    border-radius: 8px;
    font-family: inherit;
    font-weight: 500;
    font-size: 0.875rem;
    color: var(--muted);
    cursor: pointer;
    transition: all .15s;
}

.tab svg { width: 16px; height: 16px; }
.tab:hover { color: var(--text); background: var(--surface-2); }
.tab.active { background: var(--accent); color: white; font-weight: 600; }

.panel { display: none; }
.panel.open { display: block; }

.integ-list { display: flex; flex-direction: column; gap: 16px; }

.integ-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-sm);
    transition: border-color .2s, box-shadow .2s;
}

.integ-item.integ-saved {
    border-color: var(--accent-border);
    box-shadow: 0 0 0 1px rgba(13,148,136,.08);
}

.integ-item.integ-saved .integ-head h3::after {
    content: ' · Connected';
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--accent);
}

/* ── Locked credentials ── */
.cred-locked {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.cred-locked-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 18px;
    background: linear-gradient(135deg, var(--accent-soft) 0%, var(--surface) 100%);
    border-bottom: 1px solid var(--border);
}

.cred-locked-status {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.cred-lock-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: var(--accent);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.cred-lock-icon svg { width: 18px; height: 18px; }

.cred-locked-status strong {
    display: block;
    font-size: 0.9375rem;
    margin-bottom: 2px;
}

.cred-locked-status span {
    display: block;
    font-size: 0.8125rem;
    color: var(--muted);
}

.cred-locked-rows {
    padding: 4px 18px;
}

.cred-locked-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.875rem;
}

.cred-locked-row:last-child { border-bottom: none; }

.cred-locked-label {
    color: var(--muted);
    font-weight: 500;
    flex-shrink: 0;
}

.cred-locked-value {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.8125rem;
    color: var(--text);
    text-align: right;
    word-break: break-all;
}

.cred-locked-foot {
    padding: 12px 18px 16px;
    border-top: 1px solid var(--border);
}

.cred-edit-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 14px;
    margin-bottom: 14px;
    background: var(--warn-soft);
    border: 1px solid var(--warn-border);
    border-radius: var(--radius);
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--warn);
}

.cred-none-box {
    padding: 16px 18px;
    background: var(--surface-2);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
}

.cred-none-box p {
    margin: 0 0 10px;
    font-size: 0.875rem;
    color: var(--muted);
}

.cred-guide-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--accent);
    text-decoration: none;
}

.cred-guide-link:hover { text-decoration: underline; }

.tesla-oauth-row { margin-top: 12px; }

.tesla-oauth-row .cred-locked { margin-bottom: 12px; }

.tesla-oauth-form {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
}

.help-intro {
    font-size: 0.9375rem;
    color: var(--muted);
    margin-bottom: 20px;
    line-height: 1.5;
}

.integ-head {
    display: flex;
    gap: 16px;
    margin-bottom: 20px;
    align-items: flex-start;
}

.integ-icon {
    width: 48px; height: 48px;
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}

.integ-icon svg { width: 24px; height: 24px; }

.integ-icon.solar { background: var(--solar-soft); color: var(--solar); }
.integ-icon.home { background: var(--home-soft); color: var(--home); }
.integ-icon.tariff { background: var(--warn-soft, #fff4e5); color: var(--warn, #c47a00); }
.integ-icon.ev { background: var(--ev-soft); color: var(--ev); }

.integ-step-tag {
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--accent);
    margin-bottom: 2px;
}

.integ-head h3 { font-size: 1.0625rem; font-weight: 700; margin-bottom: 2px; }
.integ-head p { font-size: 0.8125rem; color: var(--muted); }

.form-field { margin-bottom: 14px; }

.form-field label {
    display: block;
    font-size: 0.8125rem;
    font-weight: 600;
    margin-bottom: 6px;
}

.form-field input,
.form-field textarea,
.field-select {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 0.9375rem;
    color: var(--text);
    background: var(--surface-2);
}

.form-field textarea {
    min-height: 7.5rem;
    resize: vertical;
}

.form-field input:focus,
.form-field textarea:focus,
.field-select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(13,148,136,.12);
}

.form-field input.field-highlight {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(13,148,136,.2);
}

.form-field small {
    display: block;
    margin-top: 4px;
    font-size: 0.8125rem;
    color: var(--muted);
}

.field-hint {
    font-size: 0.8125rem;
    color: var(--muted);
    padding: 12px;
    background: var(--surface-2);
    border-radius: var(--radius);
}

.btn-test {
    margin-top: 8px;
    padding: 10px 18px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-family: inherit;
    font-weight: 600;
    font-size: 0.875rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--text);
    transition: all .15s;
}

.btn-test svg { width: 14px; height: 14px; }
.btn-test:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}

.field-unit {
    display: flex;
    align-items: center;
    gap: 8px;
}

.field-unit input { flex: 1; }
.field-unit span { font-weight: 600; color: var(--muted); font-size: 0.875rem; }

.save-bar {
    position: sticky;
    bottom: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 0;
    margin-top: 32px;
    border-top: 1px solid var(--border);
    background: linear-gradient(to top, var(--bg) 80%, transparent);
}

.save-bar p { font-size: 0.8125rem; color: var(--muted); }

.help-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 24px;
}

.help-tile {
    display: flex;
    gap: 14px;
    padding: 18px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    text-decoration: none;
    color: inherit;
    transition: border-color .15s, box-shadow .15s;
}

.help-tile:hover {
    border-color: var(--accent);
    box-shadow: var(--shadow);
}

.help-tile-icon {
    width: 40px; height: 40px;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}

.help-tile-icon svg { width: 20px; height: 20px; }

.help-tile h4 { font-size: 0.9375rem; font-weight: 600; margin-bottom: 2px; }
.help-tile p { font-size: 0.8125rem; color: var(--muted); }

.help-banner {
    text-align: center;
    padding: 28px;
    background: var(--accent-soft);
    border-radius: var(--radius-lg);
    border: 1px solid var(--accent-border);
}

.help-banner p { color: var(--accent-hover); margin-bottom: 14px; font-size: 0.9375rem; }

/* ── Guide ── */
.guide-toc {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 28px;
    padding: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    position: sticky;
    top: 12px;
    z-index: 10;
}

.guide-toc a {
    padding: 6px 14px;
    border-radius: 8px;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--muted);
    text-decoration: none;
    transition: all .15s;
}

.guide-toc a:hover { background: var(--accent-soft); color: var(--accent-hover); }

.guide-block {
    display: flex;
    gap: 20px;
    padding: 24px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    margin-bottom: 16px;
    scroll-margin-top: 80px;
}

.guide-block-icon {
    width: 48px; height: 48px;
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}

.guide-block-icon svg { width: 24px; height: 24px; }

.guide-block-icon.solar { background: var(--solar-soft); color: var(--solar); }
.guide-block-icon.home { background: var(--home-soft); color: var(--home); }
.guide-block-icon.ev { background: var(--ev-soft); color: var(--ev); }
.guide-block-icon.plug { background: var(--accent-soft); color: var(--accent); }
.guide-block-icon.warn { background: var(--warn-soft); color: var(--warn); }

.help-tile-icon.solar { background: var(--solar-soft); color: var(--solar); }
.help-tile-icon.home { background: var(--home-soft); color: var(--home); }
.help-tile-icon.ev { background: var(--ev-soft); color: var(--ev); }
.help-tile-icon.plug { background: var(--accent-soft); color: var(--accent); }

.tesla-oauth-row {
    margin: 16px 0;
    padding: 16px;
    background: var(--accent-soft);
    border: 1px solid var(--accent-border);
    border-radius: var(--radius);
}

.tesla-oauth-row .field-hint { margin-top: 10px; margin-bottom: 0; }

.tesla-vehicle-panel {
    margin: 16px 0;
    padding: 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.tesla-vehicle-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

.tesla-vehicle-head h4 {
    font-size: 0.9375rem;
    font-weight: 600;
    margin: 0;
}

.tesla-vehicle-details {
    display: grid;
    gap: 8px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.tesla-detail-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    font-size: 0.875rem;
}

.tesla-detail-row span { color: var(--muted); }

.tesla-selected-cars {
    display: grid;
    gap: 12px;
    margin: 12px 0;
}

.tesla-selected-car {
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface-2, rgba(0, 0, 0, 0.03));
}

.tesla-selected-car-head {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.tesla-selected-car .btn {
    margin-top: 10px;
}

#chargeAmpsSlider { flex: 1; min-width: 0; }

.field-row input[type="range"] {
    flex: 1;
    min-width: 80px;
}

.guide-block-body h2 {
    font-size: 1.125rem;
    font-weight: 700;
    margin-bottom: 10px;
    letter-spacing: -0.02em;
}

.guide-block-body p {
    color: var(--muted);
    font-size: 0.9375rem;
    margin-bottom: 12px;
    line-height: 1.6;
}

.guide-box {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
    margin-bottom: 12px;
}

.guide-box.tip {
    background: var(--warn-soft);
    border-color: var(--warn-border);
}

.guide-box h4 { font-weight: 700; font-size: 0.875rem; margin-bottom: 8px; }
.guide-box ul { padding-left: 18px; color: var(--muted); font-size: 0.875rem; line-height: 1.7; }
.guide-box a { color: var(--accent); font-weight: 600; }

.guide-table-wrap {
    overflow-x: auto;
    margin: 4px -4px 0;
}

.guide-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8125rem;
    line-height: 1.45;
}

.guide-table th,
.guide-table td {
    text-align: left;
    vertical-align: top;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
}

.guide-table th {
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    white-space: nowrap;
}

.guide-table td:first-child {
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
}

.guide-table td:nth-child(3) {
    font-weight: 600;
    color: var(--accent-hover);
    white-space: nowrap;
}

.guide-table tbody tr:last-child th,
.guide-table tbody tr:last-child td {
    border-bottom: none;
}

@media (max-width: 720px) {
    .guide-table th:nth-child(2),
    .guide-table td:nth-child(2) {
        min-width: 12rem;
    }
}

.guide-docs {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.guide-docs h4 {
    font-weight: 700;
    font-size: 0.8125rem;
    margin-bottom: 8px;
    color: var(--text);
}

.guide-docs ul {
    padding-left: 18px;
    margin: 0;
    font-size: 0.8125rem;
    line-height: 1.7;
}

.guide-steps {
    padding-left: 18px;
    color: var(--muted);
    line-height: 1.8;
    font-size: 0.9375rem;
    margin: 0;
}

.guide-steps li { margin-bottom: 6px; }

.guide-box code {
    background: rgba(0,0,0,.06);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.8125rem;
}

.guide-cols {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

.guide-col {
    padding: 16px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.guide-col h4 { font-weight: 700; font-size: 0.875rem; margin: 8px 0 4px; }
.guide-col p { font-size: 0.8125rem; color: var(--muted); line-height: 1.5; }

.guide-faq details {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 8px;
    overflow: hidden;
}

.guide-faq summary {
    padding: 12px 16px;
    font-weight: 600;
    font-size: 0.9375rem;
    cursor: pointer;
    background: var(--surface-2);
    list-style: none;
}

.guide-faq summary::-webkit-details-marker { display: none; }

.guide-faq details p {
    padding: 12px 16px;
    font-size: 0.875rem;
    color: var(--muted);
    line-height: 1.6;
}

.guide-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
    padding: 32px 0 16px;
}

/* ── Responsive ── */
@media (max-width: 768px) {
    .sidebar {
        width: 64px;
        padding: 16px 10px;
    }
    .brand-name, .nav-item span, .sidebar-foot .live-pill span:last-child { display: none; }
    .nav-item { justify-content: center; padding: 12px; }
    .main { margin-left: 64px; padding: 16px 16px 20px; }
    .grid-2, .setup-progress, .form-grid, .help-grid, .guide-cols { grid-template-columns: 1fr; }
    .tabs { flex-direction: column; }
    .page-header-row { flex-direction: column; }
}

@media (max-width: 560px) {
    .stat-row, .setup-row { grid-template-columns: 1fr; }
    .stat-value { font-size: 1.625rem; }
}

/* ── Analytics ── */
.analytics-header-row {
    align-items: flex-start;
    gap: 16px;
}

.analytics-hero {
    display: grid;
    grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
    gap: 16px 20px;
    margin-bottom: 20px;
    padding: 22px 24px;
    background:
        linear-gradient(145deg, color-mix(in srgb, var(--ok) 10%, var(--surface)) 0%, var(--surface) 55%),
        var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}

.analytics-hero-main {
    grid-column: 1;
    grid-row: 1;
    min-width: 0;
}

.analytics-hero-kicker {
    display: block;
    font-size: 0.8125rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--muted);
    margin-bottom: 6px;
}

.analytics-hero-value {
    font-size: clamp(2rem, 4vw, 2.75rem);
    font-weight: 750;
    line-height: 1.1;
    letter-spacing: -0.02em;
    color: var(--text);
}

.analytics-hero-main.has-savings .analytics-hero-value {
    color: var(--ok-text, var(--ok));
}

.analytics-hero-sub {
    margin: 10px 0 0;
    font-size: 0.9375rem;
    color: var(--muted);
    max-width: 28rem;
    line-height: 1.4;
}

.analytics-hero-side {
    grid-column: 2;
    grid-row: 1;
    display: grid;
    gap: 10px;
    align-content: start;
}

.analytics-focus {
    padding: 12px 14px;
    border-radius: var(--radius);
    background: var(--surface-2, color-mix(in srgb, var(--border) 35%, transparent));
    border: 1px solid transparent;
}

.analytics-focus-label {
    display: block;
    font-size: 0.75rem;
    color: var(--muted);
    margin-bottom: 2px;
}

.analytics-focus-value {
    font-size: 1.125rem;
    font-weight: 700;
}

.solar-text { color: var(--ok-text, #15803d); }
.home-text { color: var(--home, #2563eb); }
.ev-text { color: var(--ev, #2ab7ca); }

.analytics-split {
    grid-column: 1 / -1;
    grid-row: 2;
    padding-top: 4px;
}

.analytics-split-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    font-size: 0.8125rem;
    color: var(--muted);
    margin-bottom: 8px;
}

.analytics-split-head span:last-child {
    font-weight: 650;
    color: var(--text);
}

.analytics-split-bar {
    display: flex;
    height: 12px;
    border-radius: 999px;
    overflow: hidden;
    background: color-mix(in srgb, var(--border) 80%, transparent);
}

.analytics-split-solar {
    background: var(--ok, #16a34a);
    transition: width 0.35s ease;
    min-width: 0;
}

.analytics-split-grid {
    background: #94a3b8;
    transition: width 0.35s ease;
    min-width: 0;
}

.analytics-split-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    margin-top: 10px;
    font-size: 0.8125rem;
    color: var(--muted);
}

.analytics-split-legend .dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 6px;
    vertical-align: middle;
}

.analytics-split-legend .dot.solar { background: var(--ok, #16a34a); }
.analytics-split-legend .dot.grid { background: #94a3b8; }

.analytics-split-legend strong {
    color: var(--text);
    font-weight: 650;
    margin-left: 4px;
}

.analytics-detail {
    margin: 8px 0 20px;
}

.analytics-detail-title {
    font-size: 0.9375rem;
    font-weight: 650;
    margin: 0 0 12px;
    color: var(--text);
}

.analytics-detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 10px 14px;
}

.analytics-detail-item {
    padding: 12px 14px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface);
}

.analytics-detail-item.detail-wide {
    grid-column: 1 / -1;
}

.analytics-detail-label {
    display: block;
    font-size: 0.75rem;
    color: var(--muted);
    margin-bottom: 4px;
}

.analytics-detail-value {
    font-size: 1.0625rem;
    font-weight: 700;
}

.analytics-detail-sub {
    display: block;
    margin-top: 4px;
    font-size: 0.75rem;
    color: var(--muted);
    line-height: 1.35;
}

/* Legacy summary tiles (profile / other pages) */
.analytics-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.analytics-stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
}

.analytics-stat-label {
    display: block;
    font-size: 0.8125rem;
    color: var(--muted);
    margin-bottom: 4px;
}

.analytics-stat-value {
    font-size: 1.25rem;
    font-weight: 700;
}

.analytics-stat-sub {
    display: block;
    margin-top: 4px;
    font-size: 0.75rem;
    color: var(--muted);
    font-weight: 400;
}

.savings-summary {
    margin-top: 0;
}

.analytics-card { margin-bottom: 16px; }

.analytics-card .chart-wrap-tall {
    height: 360px;
}

.chart-wrap {
    position: relative;
    height: 220px;
    margin-top: 8px;
}

.chart-wrap-tall { height: 280px; }

.analytics-date-input {
    width: auto;
    min-width: 10rem;
    padding: 8px 12px;
}

@media (max-width: 720px) {
    .analytics-hero {
        grid-template-columns: 1fr;
        padding: 18px;
    }
    .analytics-hero-main,
    .analytics-hero-side,
    .analytics-split {
        grid-column: 1;
        grid-row: auto;
    }
    .analytics-hero-side {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (max-width: 520px) {
    .analytics-hero-side {
        grid-template-columns: 1fr;
    }
}

/* ── Admin ── */
.admin-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}

.poll-stats-grid {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    margin-bottom: 0;
}

.card-title-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 4px;
}

.card-title-row .card-title {
    margin: 0;
}

.card-title-row .chips {
    margin: 0;
}

.poll-source-row {
    font-size: 0.8125rem;
    color: var(--muted);
}

.stat-card.compact {
    padding: 16px 18px;
}

.stat-card.compact .stat-value {
    font-size: 1.5rem;
    margin-top: 4px;
}

.admin-table-wrap { overflow-x: auto; }

.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.admin-table th,
.admin-table td {
    padding: 12px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.admin-table th {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
}

.admin-actions {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
}

.admin-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-2);
    color: var(--muted);
    cursor: pointer;
    transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease, transform 0.12s ease;
}

.admin-icon-btn:hover {
    color: var(--text);
    border-color: var(--accent, #2ab7ca);
    background: var(--accent-soft, rgba(42, 183, 202, 0.12));
}

.admin-icon-btn:active {
    transform: scale(0.96);
}

.admin-icon-btn.is-ok:hover {
    color: var(--ok-text, #2f6b2f);
    border-color: var(--ok-border, rgba(126, 217, 87, 0.45));
    background: var(--ok-soft, rgba(126, 217, 87, 0.14));
}

.admin-icon-btn.is-warn:hover {
    color: var(--warn-text, #8a5a00);
    border-color: var(--warn-border, rgba(200, 140, 40, 0.45));
    background: var(--warn-soft, rgba(200, 140, 40, 0.12));
}

.admin-icon-btn.is-danger:hover {
    color: var(--err, #c0392b);
    border-color: rgba(192, 57, 43, 0.4);
    background: rgba(192, 57, 43, 0.1);
}

.admin-icon-btn svg {
    width: 15px;
    height: 15px;
    display: block;
}

.admin-form { margin-top: 8px; }

@media (max-width: 768px) {
    .analytics-summary, .admin-stats { grid-template-columns: 1fr; }
}

/* ── Admin polling sections ── */
.polling-sections {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-bottom: 20px;
}

.polling-section {
    padding: 18px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.polling-section-head {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 4px;
}

.polling-section-head > div {
    flex: 1;
    min-width: 0;
}

.polling-section-head strong {
    display: block;
    font-size: 0.9375rem;
}

.polling-section-head span {
    display: block;
    font-size: 0.8125rem;
    color: var(--muted);
}

.polling-section-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.polling-section-icon svg { width: 20px; height: 20px; }
.polling-section-icon.solar { background: var(--solar-soft); color: var(--solar); }
.polling-section-icon.home { background: var(--home-soft); color: var(--home); }
.polling-section-icon.ev { background: var(--ev-soft); color: var(--ev); }

.integ-allowlist {
    display: flex;
    flex-direction: column;
    gap: 20px;
}
.integ-allow-group h4 {
    margin: 0 0 10px;
    font-size: 0.8125rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
}
.integ-allow-rows {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 8px;
}
.integ-allow-row {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    cursor: pointer;
}
.integ-allow-row:has(input:checked) {
    border-color: var(--accent);
    background: var(--surface);
}
.integ-allow-row input { margin-top: 3px; flex-shrink: 0; }
.integ-allow-body {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}
.integ-allow-body strong {
    font-size: 0.875rem;
}
.integ-allow-body small {
    color: var(--muted);
    font-size: 0.75rem;
    line-height: 1.35;
}

.polling-form-foot {
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

/* ── Admin API call log ── */
.log-filters {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
    margin-bottom: 8px;
}

.log-filter-group label {
    display: block;
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    font-weight: 600;
    margin-bottom: 4px;
}

.log-filter-search {
    grid-column: span 2;
    min-width: 180px;
}

.log-meta {
    font-size: 0.8125rem;
    color: var(--muted);
}

.log-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin-top: 14px;
}

.log-detail {
    max-width: 420px;
    white-space: normal;
    overflow-wrap: anywhere;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.75rem;
    color: var(--muted);
    line-height: 1.35;
}

.log-target {
    color: var(--muted);
}

.log-error {
    margin-top: 4px;
    color: var(--err-text);
    font-weight: 600;
}

.admin-table tr.log-row-fail td {
    background: color-mix(in srgb, var(--err) 8%, transparent);
}

.admin-table tr.log-row-fail td:first-child {
    box-shadow: inset 3px 0 0 var(--err);
}

.badge.err { background: var(--err-soft); color: var(--err-text); }

.log-type-solar { color: var(--solar); }
.log-type-home { color: var(--home); }
.log-type-ev { color: var(--ev); }

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 16px;
}

.modal-overlay[hidden] {
    display: none;
}

.modal-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 24px;
    max-width: 440px;
    width: 100%;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 8px;
}

@media (max-width: 768px) {
    .log-filter-search { grid-column: span 1; }
}

/* ── Home / customer session UX ── */
.home-header h1.home-brand {
    font-size: 1.75rem;
    margin: 0 0 4px;
}
.home-brand-row {
    display: flex;
    align-items: center;
    gap: 12px;
}
.home-brand-row .brand-logo {
    width: 40px;
    height: 40px;
    border-radius: 12px;
}
.home-status-line {
    margin: 0;
    color: var(--muted);
    font-size: 0.95rem;
    max-width: 36rem;
    line-height: 1.4;
}

.schedule-banner {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    margin-bottom: 16px;
    border-radius: var(--radius);
    background: var(--home-soft);
    border: 1px solid var(--home-border);
    color: var(--home-text);
}

.view-as-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 10px 20px;
    background: #0f2744;
    color: #e8eef7;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
    position: sticky;
    top: 0;
    z-index: 200;
}
.view-as-banner-body {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}
.view-as-banner-body strong {
    font-size: 0.875rem;
}
.view-as-banner-body span {
    font-size: 0.8125rem;
    opacity: 0.85;
}
.view-as-banner-body code {
    font-size: 0.8125rem;
    background: rgba(255, 255, 255, 0.1);
    padding: 1px 6px;
    border-radius: 4px;
}
.view-as-banner .btn {
    flex-shrink: 0;
    background: #fff;
    color: #0f2744;
    border: none;
}
.view-as-banner .btn:hover {
    background: #e8eef7;
}
body.viewing-as .layout {
    min-height: calc(100vh - 56px);
}
.schedule-banner-icon {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
    color: var(--home);
}
.schedule-banner-icon svg { width: 100%; height: 100%; }
.schedule-banner-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}
.schedule-banner-body strong { font-size: 0.875rem; }
.schedule-banner-body span { font-size: 0.8125rem; opacity: 0.9; }

.session-panel {
    display: grid;
    grid-template-columns: 1fr 1.15fr;
    gap: 16px;
    margin-top: 0;
}
@media (max-width: 820px) {
    .session-panel { grid-template-columns: 1fr; }
}

.mode-chips {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 12px;
}
.mode-chip {
    text-align: left;
    padding: 12px 14px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg);
    cursor: pointer;
    transition: border-color .15s ease, background .15s ease, box-shadow .15s ease;
}
.mode-chip strong {
    display: block;
    font-size: 0.9rem;
    color: var(--text);
    margin-bottom: 2px;
}
.mode-chip span {
    display: block;
    font-size: 0.75rem;
    color: var(--muted);
    line-height: 1.3;
}
.mode-chip:hover { border-color: var(--accent-border); }
.mode-chip.is-active {
    border-color: var(--accent);
    background: var(--accent-soft);
    box-shadow: inset 0 0 0 1px var(--accent);
}
.mode-chip.is-active strong { color: var(--accent-hover); }
.mode-chip:disabled { opacity: 0.55; cursor: wait; }

.mode-intent {
    margin: 0 0 14px;
    font-size: 0.875rem;
    color: var(--text);
    min-height: 1.35em;
}

.amp-stepper { margin-bottom: 12px; }
.amp-stepper .field-label {
    display: block;
    font-size: 0.75rem;
    color: var(--muted);
    margin-bottom: 8px;
}
.amp-stepper-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
}
.amp-btn {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--surface);
    font-size: 1.4rem;
    line-height: 1;
    color: var(--text);
    cursor: pointer;
}
.amp-btn:hover { border-color: var(--accent); color: var(--accent); }
.amp-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.amp-display {
    display: flex;
    align-items: baseline;
    gap: 4px;
    min-width: 4.5rem;
    justify-content: center;
}
.amp-display span {
    font-size: 2rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--accent);
}
.amp-display small { font-size: 0.9rem; color: var(--muted); font-weight: 600; }
.amp-range {
    width: 100%;
    margin-top: 12px;
    accent-color: var(--accent);
}
.amp-stepper.is-solar .amp-display span { color: var(--solar); }

.session-actions { margin-top: 4px; }

.connections-details {
    margin-top: 24px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    padding: 0;
}
.connections-details > summary {
    list-style: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    font-weight: 600;
    font-size: 0.875rem;
}
.connections-details > summary::-webkit-details-marker { display: none; }
.connections-details > summary::before {
    content: '▸';
    color: var(--muted);
    font-size: 0.75rem;
}
.connections-details[open] > summary::before { content: '▾'; }
.connections-summary-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    flex: 1;
}
.connections-details .setup-row {
    padding: 0 16px 16px;
    margin: 0;
}
.connections-details.is-needs-setup {
    border-color: var(--warn-border);
    background: var(--warn-soft);
}
.connections-details.is-needs-setup > summary { color: var(--warn-text); }

.flow-line.active {
    stroke-dasharray: 10 8;
    animation: flowDash var(--flow-dur, 1.6s) linear infinite;
}
@keyframes flowDash {
    to { stroke-dashoffset: -36; }
}
@media (prefers-reduced-motion: reduce) {
    .flow-line.active { animation: none; stroke-dasharray: none; }
}

/* ── Guided setup wizard ── */
.setup-main { max-width: 720px; }
.wizard-steps {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 20px;
}
.wizard-step {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface);
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--muted);
    cursor: pointer;
}
.wizard-step span {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--bg);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
}
.wizard-step.is-active {
    border-color: var(--accent);
    color: var(--accent-hover);
    background: var(--accent-soft);
}
.wizard-step.is-done {
    border-color: var(--ok-border);
    color: var(--ok-text);
}
.wizard-step.is-done span {
    background: var(--ok);
    color: #fff;
}
.wizard-panel { display: none; }
.wizard-panel.open { display: block; }
.wizard-card h2 {
    font-family: var(--font);
    margin: 0 0 8px;
    font-size: 1.375rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.2;
}
.wizard-lead {
    color: var(--muted);
    margin: 0 0 20px;
    line-height: 1.45;
}
.wizard-subhead {
    font-family: var(--font);
    font-size: 1.0625rem;
    font-weight: 600;
    margin: 0 0 8px;
    letter-spacing: -0.01em;
    line-height: 1.3;
}
.enphase-oauth-row .cred-locked-row,
.tesla-oauth-row .cred-locked-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.wizard-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 24px;
}
.wizard-advanced {
    border: 1px solid var(--border, #e2e8f0);
    border-radius: 10px;
    padding: 10px 14px;
    background: var(--surface-2, rgba(0, 0, 0, 0.02));
}
.wizard-advanced > summary {
    cursor: pointer;
    font-weight: 600;
    font-size: 0.95rem;
    list-style: none;
}
.wizard-advanced > summary::-webkit-details-marker { display: none; }
.wizard-advanced > summary::after {
    content: " ▾";
    opacity: 0.55;
    font-weight: 400;
}
.wizard-advanced[open] > summary::after { content: " ▴"; }
.choice-cards {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.choice-card {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    cursor: pointer;
}
.choice-card input { margin-top: 3px; }
.choice-card strong { display: block; font-size: 0.9375rem; margin-bottom: 2px; }
.choice-card span { display: block; font-size: 0.8125rem; color: var(--muted); line-height: 1.35; }
.choice-card.is-selected {
    border-color: var(--accent);
    background: var(--accent-soft);
    box-shadow: inset 0 0 0 1px var(--accent);
}

/* ── Admin server health ── */
.health-status-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    border-radius: 999px;
    font-size: 0.8125rem;
    font-weight: 600;
    border: 1px solid var(--border);
    background: var(--surface);
}
.health-status-pill.status-ok {
    color: var(--ok-text, #15803d);
    background: var(--ok-soft, #dcfce7);
    border-color: var(--ok-border, #86efac);
}
.health-status-pill.status-degraded {
    color: #a16207;
    background: #fef9c3;
    border-color: #fde047;
}
.health-status-pill.status-critical {
    color: var(--err-text);
    background: var(--err-soft);
    border-color: var(--err-border);
}
.chip-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
}
.chip-toggle input { margin: 0; }
.health-meters {
    display: grid;
    gap: 16px;
}
.health-meter-head {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 6px;
    font-size: 0.875rem;
}
.health-meter-track {
    height: 8px;
    border-radius: 999px;
    background: var(--border);
    overflow: hidden;
}
.health-meter-fill {
    height: 100%;
    border-radius: inherit;
    background: var(--accent);
    transition: width .35s ease;
}
.health-meter-fill.ok { background: #16a34a; }
.health-meter-fill.warn { background: #ca8a04; }
.health-meter-fill.crit { background: #dc2626; }
.health-meter-detail { font-size: 0.8125rem; margin-top: 6px; }
.health-kv { display: grid; gap: 10px; }
.health-kv-row {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    font-size: 0.875rem;
}
.health-kv-row strong { font-weight: 600; text-align: right; }
