:root {
    --bg: #080b10;
    --surface: #101620;
    --surface-2: #151d2b;
    --border: #243044;
    --text: #e8edf5;
    --muted: #7d8ca3;
    --accent: #ffb020;
    --accent-2: #ff8f00;
    --ok: #22c55e;
    --warn: #f59e0b;
    --crit: #ef4444;
    --info: #38bdf8;
    --shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
    --radius: 14px;
}

* { box-sizing: border-box; }

html {
    overflow-x: clip;
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    min-height: 100vh;
    overflow-x: clip;
    background:
        radial-gradient(1200px 600px at 10% -10%, rgba(255, 176, 32, 0.08), transparent 55%),
        radial-gradient(900px 500px at 100% 0%, rgba(56, 189, 248, 0.06), transparent 50%),
        var(--bg);
    color: var(--text);
    font-family: "Segoe UI", system-ui, sans-serif;
}

.wrap {
    max-width: 1440px;
    margin: 0 auto;
    padding: 20px 24px 40px;
}

.btn-ghost {
    background: transparent;
    border-color: var(--border);
    font-size: 12px;
    font-weight: 600;
    padding: 0 12px;
    color: var(--muted);
}

.btn-ghost:hover {
    color: var(--text);
    border-color: #3d516d;
    background: rgba(255, 255, 255, 0.03);
}

a.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    box-sizing: border-box;
    line-height: 1;
    white-space: nowrap;
}

.topbar-nav {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 3px;
    border-radius: 999px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    flex-shrink: 0;
}

.topbar-nav-item {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 32px;
    padding: 0 14px;
    border-radius: 999px;
    border: none;
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-size: 12px;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
    line-height: 1;
    cursor: pointer;
    transition: color 0.15s, background 0.15s, box-shadow 0.15s;
}

.topbar-nav-item:hover {
    color: var(--text);
    background: rgba(255, 255, 255, 0.04);
}

.topbar-nav-item.active {
    background: linear-gradient(180deg, #ffd166, #ff9f1a);
    color: #111;
    box-shadow: 0 2px 8px rgba(255, 159, 26, 0.22);
}

.topbar-nav-item.active:hover {
    color: #111;
    background: linear-gradient(180deg, #ffd166, #ff9f1a);
}

.user-pill {
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 12px;
    color: var(--muted);
}

.brand-title-row {
    display: flex;
    align-items: baseline;
    gap: 8px;
    flex-wrap: wrap;
}

.app-version {
    font-size: 11px;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: 0.04em;
    padding: 2px 7px;
    border-radius: 4px;
    border: 1px solid rgba(255, 176, 32, 0.35);
    background: rgba(255, 176, 32, 0.08);
    line-height: 1.2;
    white-space: nowrap;
}

.login-card .app-version {
    font-size: 10px;
}

.topbar {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    margin-bottom: 20px;
    padding: 14px 18px;
    background: rgba(16, 22, 32, 0.92);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    backdrop-filter: blur(8px);
}

.topbar-upper {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    width: 100%;
    min-width: 0;
}

.topbar-nav-bottom {
    display: inline-flex;
    align-self: center;
    margin: 0 auto;
}

.topbar-row-tools {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    width: 100%;
    min-height: 38px;
    gap: 8px;
}

.topbar-tools-group {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: nowrap;
    min-width: 0;
}

.topbar-upper .topbar-account-group {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.topbar-header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.topbar-header-actions .topbar-nav {
    height: 38px;
    box-sizing: border-box;
}

.topbar-admin {
    gap: 0;
}

.topbar-upper .topbar-account-group .status-pill {
    height: 38px;
    box-sizing: border-box;
}

.topbar-right {
    display: inline-grid;
    grid-template-rows: auto auto;
    gap: 8px;
    justify-items: end;
    margin-left: auto;
    min-width: 0;
    max-width: 100%;
}

.topbar-row {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: nowrap;
    min-height: 38px;
    max-width: 100%;
}

.topbar-row > .status-pill,
.topbar-row > .btn,
.topbar-row > .select,
.topbar-row > .topbar-nav {
    flex-shrink: 0;
}

.topbar-row-account {
    width: 100%;
    justify-content: flex-end;
    gap: 12px;
}

.topbar-account-group {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.topbar-row .status-pill {
    height: 38px;
    box-sizing: border-box;
}

.topbar-row .topbar-nav {
    height: 38px;
    box-sizing: border-box;
}

.status-pill-error:empty {
    display: none;
}

.status-pill-error:not(:empty) {
    color: #ff8a80;
}

.status-pill-mqtt {
    margin-left: 2px;
}

.topbar-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.topbar-tools {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    flex-wrap: wrap;
    min-width: 0;
}

.topbar-account {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

@media (max-width: 960px) {
    .topbar-upper {
        flex-direction: column;
        align-items: stretch;
    }

    .topbar-upper .topbar-account-group {
        justify-content: flex-end;
    }

    .topbar-header-actions {
        justify-content: flex-end;
        width: 100%;
    }

    .topbar-row-tools {
        justify-content: stretch;
    }

    .topbar-tools-group {
        flex-wrap: wrap;
        justify-content: flex-start;
        width: 100%;
    }

    .topbar-tools-group .select {
        flex: 1 1 180px;
        min-width: 0;
        max-width: 100%;
    }
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-mark {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    background: linear-gradient(135deg, #ffd166, #ff8f00);
    color: #111;
    font-weight: 800;
    display: grid;
    place-items: center;
    font-size: 13px;
}

.brand h1 {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
}

.brand p {
    margin: 2px 0 0;
    color: var(--muted);
    font-size: 12px;
}

.select, .btn {
    height: 38px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    font: inherit;
    font-size: 13px;
}

.select {
    min-width: 220px;
    padding: 0 12px;
}

.btn {
    padding: 0 14px;
    cursor: pointer;
    font-weight: 600;
}

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    padding: 0;
}

.btn-icon svg {
    display: block;
}

.btn:hover { border-color: #3d516d; }
.btn.active {
    background: linear-gradient(180deg, #ffd166, #ff9f1a);
    color: #111;
    border-color: transparent;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 999px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    font-size: 12px;
    color: var(--muted);
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #555;
}
.dot.live { background: var(--ok); box-shadow: 0 0 10px rgba(34, 197, 94, 0.7); }
.dot.off { background: var(--crit); }

.section-title {
    margin: 0 0 12px;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
}

.glb-panel {
    margin-bottom: 18px;
    transition: opacity 0.2s ease, filter 0.2s ease;
}

.panel-title-row {
    display: flex;
    align-items: baseline;
    justify-content: flex-start;
    gap: 14px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.panel-title-row .section-title {
    margin: 0;
}

.panel-title-meta {
    font-size: 12px;
    color: var(--muted);
    white-space: nowrap;
}

.meter-panel {
    margin-bottom: 18px;
    transition: opacity 0.2s ease, filter 0.2s ease;
}

.panel-title-meta.meter-last-update-offline {
    color: #fbbf24;
}

.panel-title-meta.meter-last-update-reconnecting {
    color: #7dd3fc;
}

.meter-live-disconnected {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex: 1 1 auto;
    min-height: 120px;
    padding: 20px 16px;
    text-align: center;
    border-radius: var(--radius);
    border: 1px dashed rgba(251, 191, 36, 0.45);
    background: rgba(251, 191, 36, 0.08);
}

.meter-live-disconnected-badge {
    display: inline-flex;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #fde68a;
    background: rgba(251, 191, 36, 0.16);
    border: 1px solid rgba(251, 191, 36, 0.35);
}

.meter-live-disconnected strong {
    font-size: 14px;
    color: #fde68a;
}

.meter-live-disconnected p {
    margin: 0;
    max-width: 34ch;
    font-size: 12px;
    line-height: 1.45;
    color: var(--muted);
}

.vm-empty .meter-live-disconnected {
    min-height: 0;
    border: none;
    background: transparent;
    padding: 12px 8px;
}

.meter-live-reconnecting {
    border-color: rgba(56, 189, 248, 0.45);
    background: rgba(56, 189, 248, 0.08);
}

.meter-live-reconnecting .meter-live-disconnected-badge {
    color: #bae6fd;
    background: rgba(56, 189, 248, 0.14);
    border-color: rgba(56, 189, 248, 0.35);
}

.meter-live-reconnecting strong {
    color: #bae6fd;
}

.meter-live-loading {
    border-color: rgba(125, 140, 163, 0.45);
    background: rgba(125, 140, 163, 0.08);
}

.meter-live-loading .meter-live-disconnected-badge {
    color: var(--muted);
    background: rgba(125, 140, 163, 0.12);
    border-color: rgba(125, 140, 163, 0.35);
}

.meter-live-loading strong {
    color: var(--text);
}

.meter-live-demo {
    border-color: rgba(34, 197, 94, 0.45);
    background: rgba(34, 197, 94, 0.08);
}

.meter-live-demo .meter-live-disconnected-badge {
    color: #86efac;
    background: rgba(34, 197, 94, 0.16);
    border-color: rgba(34, 197, 94, 0.35);
}

.meter-live-demo strong {
    color: #86efac;
}

.meter-panel .vm-panel {
    margin-bottom: 0;
    margin-top: 14px;
}

.vm-subsection-title {
    margin: 0;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
}

.vm-energies-table-title {
    margin: 0 0 12px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
}

.panel-inline-title {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 8px 12px;
    margin-bottom: 12px;
}

.panel-inline-title .vm-energies-table-title {
    margin: 0;
}

.panel-inline-meta {
    font-size: 12px;
    font-weight: 500;
    letter-spacing: normal;
    text-transform: none;
    color: var(--muted);
}

.glb-panel-inactive {
    opacity: 0.58;
    filter: grayscale(1);
}

.glb-panel-inactive .glb-bar.ok,
.glb-panel-inactive .glb-bar.warn,
.glb-panel-inactive .glb-bar.crit {
    border-color: rgba(120, 130, 145, 0.35);
    background: rgba(90, 100, 115, 0.14);
}

.glb-panel-inactive .section-title {
    color: var(--muted);
}

.glb-panel-inactive .glb-wifi-chip {
    opacity: 0.75;
}

.glb-panel-inactive .io-relay {
    pointer-events: none;
    opacity: 0.65;
}

.glb-bar {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 0;
    padding: 8px 10px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface);
    box-shadow: var(--shadow);
    overflow-x: auto;
}

.glb-bar.ok { border-color: rgba(34, 197, 94, 0.35); background: rgba(34, 197, 94, 0.08); }
.glb-bar.warn { border-color: rgba(245, 158, 11, 0.45); background: rgba(245, 158, 11, 0.1); }
.glb-bar.crit { border-color: rgba(239, 68, 68, 0.45); background: rgba(239, 68, 68, 0.1); }

.glb-seg {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1 1 0;
    min-width: max-content;
    padding: 0 12px;
    border-right: 1px solid rgba(255, 255, 255, 0.06);
}

.glb-seg:last-child {
    border-right: none;
}

.glb-seg-status {
    flex: 1.5 1 0;
    justify-content: space-between;
    gap: 12px;
    min-width: 240px;
}

.glb-status-left {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.glb-seg-title {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    white-space: nowrap;
    flex-shrink: 0;
}

.glb-alarm-text {
    display: flex;
    align-items: baseline;
    gap: 6px;
    flex-wrap: wrap;
    min-width: 0;
}

.glb-seg-alarm strong,
.glb-alarm-text strong {
    font-size: 13px;
    font-weight: 700;
    line-height: 1.2;
}

.glb-alarm-code {
    font-size: 11px;
    color: var(--muted);
    white-space: nowrap;
}

.glb-wifi-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px 4px 8px;
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.35);
    border: 1px solid rgba(56, 189, 248, 0.22);
    color: #bae6fd;
    flex-shrink: 0;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.glb-bar.warn .glb-wifi-chip {
    border-color: rgba(245, 158, 11, 0.25);
    color: #fde68a;
}

.glb-bar.crit .glb-wifi-chip {
    border-color: rgba(239, 68, 68, 0.25);
    color: #fecaca;
}

.glb-wifi-chip.glb-wifi-off {
    opacity: 0.55;
    border-color: rgba(255, 255, 255, 0.08);
    color: var(--muted);
}

.glb-wifi-icon {
    width: 13px;
    height: 13px;
    flex-shrink: 0;
    opacity: 0.9;
}

.glb-conn-val {
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
    letter-spacing: 0.02em;
}

.glb-rssi {
    display: inline-flex;
    align-items: flex-end;
    gap: 2px;
    height: 14px;
    padding-left: 2px;
    border-left: 1px solid rgba(255, 255, 255, 0.1);
    margin-left: 2px;
    padding-left: 6px;
}

.glb-rssi i {
    display: block;
    width: 3px;
    height: var(--bar-h, 3px);
    border-radius: 1px;
    background: rgba(255, 255, 255, 0.12);
    align-self: flex-end;
}

.glb-rssi i.on {
    background: linear-gradient(180deg, #7dd3fc, #38bdf8);
    box-shadow: 0 0 6px rgba(56, 189, 248, 0.35);
}

.glb-rssi-val {
    font-size: 10px;
    font-weight: 600;
    color: rgba(186, 230, 253, 0.75);
    margin-left: 4px;
    align-self: center;
    font-variant-numeric: tabular-nums;
}

.glb-val {
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
}

.glb-val.glb-disconnected {
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
}

.glb-sep {
    color: var(--muted);
    font-size: 12px;
}

.glb-seg-updated {
    margin-left: auto;
    border-right: none;
    padding-left: 12px;
    font-size: 11px;
    color: var(--muted);
    white-space: nowrap;
    flex-shrink: 0;
}

.io-compact {
    gap: 6px;
}

.io-compact .io-led,
.io-compact .io-relay {
    flex: 0 0 auto;
    display: inline-flex;
    flex-direction: row;
    align-items: center;
    gap: 5px;
    padding: 3px 8px;
    border-radius: 8px;
}

.io-compact .io-led .name,
.io-compact .io-relay .name {
    margin: 0;
    font-size: 10px;
}

.io-compact .io-led .state,
.io-compact .io-relay .state {
    margin: 0;
    font-size: 11px;
    font-weight: 800;
}

.glb-seg-relay {
    align-items: flex-start;
}

.glb-relay-col {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.glb-relay-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.glb-relay-hint {
    font-size: 10px;
    line-height: 1.2;
    color: rgba(245, 158, 11, 0.92);
    padding-left: 2px;
    white-space: nowrap;
}

.glb-relay-hint.error {
    color: rgba(248, 113, 113, 0.95);
}

.glb-relay-hint[hidden] {
    display: none;
}

.glb-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
}

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

.card-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    margin-bottom: 8px;
}

.card-value {
    font-size: 22px;
    font-weight: 700;
    line-height: 1.1;
}

.card-sub {
    margin-top: 6px;
    font-size: 12px;
    color: var(--muted);
}

.io-row {
    display: flex;
    gap: 10px;
}

.io-led {
    flex: 1;
    text-align: center;
    padding: 12px 8px;
    border-radius: 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
}

.io-led .name {
    font-size: 11px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.io-led .state {
    margin-top: 8px;
    font-size: 18px;
    font-weight: 800;
}

.io-led.on {
    border-color: rgba(34, 197, 94, 0.5);
    background: rgba(34, 197, 94, 0.12);
    color: var(--ok);
}

.io-led.off { color: #556070; }

.io-relay {
    flex: 1;
    text-align: center;
    padding: 12px 8px;
    border-radius: 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: inherit;
    font: inherit;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s, transform 0.1s;
}

.io-relay .name {
    font-size: 11px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.io-relay .state {
    margin-top: 8px;
    font-size: 18px;
    font-weight: 800;
}

.io-relay.on {
    border-color: rgba(34, 197, 94, 0.5);
    background: rgba(34, 197, 94, 0.12);
    color: var(--ok);
}

.io-relay.off { color: #556070; }

.io-relay:hover:not(:disabled) {
    border-color: rgba(56, 189, 248, 0.55);
    transform: translateY(-1px);
}

.io-relay:focus-visible {
    outline: 2px solid rgba(56, 189, 248, 0.8);
    outline-offset: 2px;
}

.io-relay:disabled {
    cursor: wait;
    opacity: 0.85;
}

.io-relay.pending {
    border-color: rgba(245, 158, 11, 0.45);
}

.io-relay.wait-confirm {
    box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.35);
}

.env-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 8px;
}

.env-metric {
    text-align: center;
    padding: 12px 8px;
    border-radius: 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
}

.env-metric-label {
    display: block;
    font-size: 11px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.env-metric-val {
    display: block;
    margin-top: 8px;
    font-size: 22px;
    font-weight: 800;
    line-height: 1.1;
}

.env-metric.env-disconnected .env-metric-val {
    font-size: 13px;
    font-weight: 700;
    color: var(--muted);
}

.rssi {
    display: flex;
    gap: 4px;
    margin-top: 10px;
}

.rssi i {
    flex: 1;
    height: 8px;
    border-radius: 999px;
    background: #243044;
    display: block;
}

.rssi i.on { background: linear-gradient(90deg, #ffb020, #ff8f00); }

.vm-energies-panel {
    margin-bottom: 0;
    min-width: 0;
}

.meter-hero-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(248px, 340px);
    gap: 16px;
    align-items: stretch;
    margin-bottom: 16px;
}

.meter-hero-row > .install-schema-panel--embedded,
.meter-hero-row > .vm-energies-panel {
    min-height: 0;
    min-width: 0;
    align-self: stretch;
    overflow: hidden;
    container-type: inline-size;
}

.meter-hero-row > .vm-energies-panel .vm-energies-hero--stack {
    min-height: 100%;
    min-width: 0;
}

.meter-hero-row > .vm-energies-panel .vm-energies-grid--stack {
    min-width: 0;
}

.meter-hero-row > .vm-energies-panel .vm-energy-card {
    min-height: 0;
    padding: 12px 12px;
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto auto;
    gap: 2px 0;
}

.meter-hero-row > .vm-energies-panel .vm-energy-code {
    grid-column: 1;
    grid-row: 2;
    align-self: start;
    font-size: 11px;
    line-height: 1.2;
    margin-bottom: 2px;
}

.meter-hero-row > .vm-energies-panel .vm-energy-value {
    grid-column: 1;
    font-size: clamp(1rem, 11cqi, 1.55rem);
    line-height: 1.05;
    max-width: 100%;
    overflow-wrap: anywhere;
    word-break: break-word;
    white-space: normal;
}

.meter-hero-row > .vm-energies-panel .vm-energy-unit {
    font-size: 11px;
}

.meter-hero-row > .vm-energies-panel .vm-energy-label {
    font-size: 10px;
}

.vm-energies-hero--rich {
    gap: 10px;
}

.vm-energies-rich-lead {
    margin: 0;
    font-size: 10px;
    line-height: 1.35;
    color: var(--muted);
    text-align: center;
}

.vm-energies-rich-stack {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 0;
}

.vm-energy-rich {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 16px 14px 12px 18px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: rgba(0, 0, 0, 0.22);
    overflow: hidden;
    min-width: 0;
}

.vm-energy-rich::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
}

.vm-energy-rich--direct {
    border-color: rgba(255, 176, 32, 0.32);
    background:
        linear-gradient(135deg, rgba(255, 176, 32, 0.1), transparent 58%),
        rgba(0, 0, 0, 0.24);
    box-shadow: inset 0 1px 0 rgba(255, 200, 100, 0.08);
}

.vm-energy-rich--direct::before {
    background: linear-gradient(180deg, #fcd34d, #f97316);
}

.vm-energy-rich--inverse {
    border-color: rgba(56, 189, 248, 0.28);
    background:
        linear-gradient(135deg, rgba(56, 189, 248, 0.1), transparent 58%),
        rgba(0, 0, 0, 0.24);
    box-shadow: inset 0 1px 0 rgba(125, 211, 252, 0.08);
}

.vm-energy-rich--inverse::before {
    background: linear-gradient(180deg, #7dd3fc, #2563eb);
}

.vm-energy-rich-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-width: 0;
}

.vm-energy-rich-title {
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
}

.vm-energy-rich-badge {
    flex-shrink: 0;
    padding: 3px 8px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.03em;
}

.vm-energy-rich--direct .vm-energy-rich-badge {
    color: #fcd34d;
    background: rgba(255, 176, 32, 0.16);
    border: 1px solid rgba(255, 176, 32, 0.28);
}

.vm-energy-rich--inverse .vm-energy-rich-badge {
    color: #bae6fd;
    background: rgba(56, 189, 248, 0.14);
    border: 1px solid rgba(56, 189, 248, 0.28);
}

.vm-energy-rich-periods {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.vm-energy-rich-stat {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    align-items: baseline;
    gap: 6px 10px;
    padding: 10px 12px;
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.28);
    min-width: 0;
}

.vm-energy-rich-stat--day {
    border: 1px solid rgba(255, 176, 32, 0.22);
    background: rgba(255, 176, 32, 0.07);
}

.vm-energy-rich--inverse .vm-energy-rich-stat--day {
    border-color: rgba(56, 189, 248, 0.22);
    background: rgba(56, 189, 248, 0.07);
}

.vm-energy-rich-stat--month {
    border: 1px solid rgba(255, 255, 255, 0.06);
}

.vm-energy-rich-stat-label {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--muted);
}

.vm-energy-rich-stat-value {
    font-size: clamp(1.35rem, 14cqi, 2rem);
    font-weight: 800;
    line-height: 1;
    font-variant-numeric: tabular-nums;
    color: var(--text);
    text-align: right;
}

.vm-energy-rich--direct .vm-energy-rich-stat--day .vm-energy-rich-stat-value {
    color: #fde68a;
}

.vm-energy-rich--inverse .vm-energy-rich-stat--day .vm-energy-rich-stat-value {
    color: #bae6fd;
}

.vm-energy-rich-stat-unit {
    font-size: 12px;
    font-weight: 700;
    color: var(--muted);
}

.vm-energy-rich-index {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
    padding-top: 8px;
    border-top: 1px dashed rgba(255, 255, 255, 0.1);
    min-width: 0;
}

.vm-energy-rich-index-label {
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--muted);
    flex-shrink: 0;
}

.vm-energy-rich-index-value {
    font-size: 12px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: rgba(226, 232, 240, 0.88);
    text-align: right;
    overflow-wrap: anywhere;
    word-break: break-word;
}

@media (max-width: 900px) {
    .meter-hero-row {
        grid-template-columns: 1fr;
    }
}

.facturation-panel {
    margin-top: 16px;
}

.facturation-hero-panel {
    margin-top: 0;
    margin-bottom: 16px;
}

#consumptionPeriodPanel.facturation-hero-panel {
    margin-top: 0;
}

.consumption-period-panel {
    padding: 18px 20px 16px;
}

.consumption-period-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px 16px;
    margin-bottom: 12px;
}

.consumption-period-head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 8px;
}

.consumption-period-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
}

.consumption-granularity-group,
.consumption-range-group {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 6px;
}

.consumption-granularity-btn.active,
.consumption-range-btn.active {
    color: var(--accent);
    border-color: rgba(255, 176, 32, 0.45);
    background: rgba(255, 176, 32, 0.12);
}

.consumption-chart-box {
    position: relative;
    height: 260px;
}

.consumption-chart-box canvas {
    width: 100% !important;
    height: 100% !important;
}

.consumption-chart-empty,
.consumption-chart-loading {
    position: absolute;
    inset: 0;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: var(--muted);
    font-size: 13px;
    border-radius: 12px;
    border: 1px dashed rgba(56, 189, 248, 0.2);
    background: rgba(11, 15, 22, 0.72);
    backdrop-filter: blur(2px);
}

.consumption-chart-loading {
    border-style: solid;
    border-color: rgba(56, 189, 248, 0.15);
}

.consumption-chart-loading[hidden] {
    display: none !important;
}

.consumption-chart-spinner {
    animation: chart-spin 0.85s linear infinite;
    color: #ffb020;
}

.consumption-chart-box.is-loading canvas {
    opacity: 0.35;
    pointer-events: none;
}

.consumption-period--loading .consumption-period-controls {
    opacity: 0.65;
    pointer-events: none;
}

@media (max-width: 640px) {
    .consumption-period-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .consumption-chart-box {
        height: 220px;
    }
}

.facturation-hero {
    padding: 22px 24px;
    border-radius: var(--radius);
    border: 1px solid rgba(56, 189, 248, 0.28);
    background:
        radial-gradient(900px 280px at 0% 0%, rgba(56, 189, 248, 0.12), transparent 55%),
        radial-gradient(700px 240px at 100% 100%, rgba(34, 197, 94, 0.08), transparent 50%),
        var(--surface);
    box-shadow: var(--shadow);
}

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

.facturation-hero-kwh {
    border-color: rgba(56, 189, 248, 0.35);
}

.facturation-hero-dh {
    border-color: rgba(34, 197, 94, 0.35);
}

.facturation-hero-dh .vm-energy-value {
    color: #86efac;
}

.facturation-hero-sub,
.facturation-hero-hint {
    margin: 14px 0 0;
    font-size: 12px;
    color: var(--muted);
    text-align: center;
}

.facturation-hero-hint a {
    color: #7dd3fc;
    text-decoration: none;
}

.facturation-hero-hint a:hover {
    text-decoration: underline;
}

.factures-page-panel {
    margin-top: 8px;
}

@media (max-width: 640px) {
    .facturation-hero-grid {
        grid-template-columns: 1fr;
    }
}

.facturation-empty {
    padding: 24px;
    text-align: center;
    color: var(--muted);
    background: var(--surface);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
}

.facturation-card {
    padding: 20px 24px;
    border-radius: var(--radius);
    border: 1px solid rgba(56, 189, 248, 0.22);
    background:
        radial-gradient(900px 280px at 100% 0%, rgba(56, 189, 248, 0.1), transparent 55%),
        var(--surface);
    box-shadow: var(--shadow);
}

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

.facturation-head h3 {
    margin: 0;
    font-size: 16px;
}

.facturation-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 18px;
    margin-bottom: 14px;
    font-size: 12px;
    color: var(--muted);
}

.facturation-meta strong {
    color: #ddd;
}

.facturation-warning {
    margin: 0 0 12px;
    padding: 8px 10px;
    border-radius: 8px;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.25);
    color: #fca5a5;
    font-size: 12px;
}

.facturation-hint {
    margin: 0 0 12px;
    padding: 8px 10px;
    border-radius: 8px;
    background: rgba(251, 191, 36, 0.08);
    border: 1px solid rgba(251, 191, 36, 0.22);
    color: #fcd34d;
    font-size: 12px;
}

.facture-modal-hint {
    margin-top: 0;
    font-size: 12px;
    color: var(--muted);
}

.facturation-comparison-wrap {
    margin: 0 0 14px;
    padding: 10px 12px;
    border-radius: 8px;
    background: rgba(56, 189, 248, 0.06);
    border: 1px solid rgba(56, 189, 248, 0.18);
}

.facturation-delta-plus {
    color: #fcd34d;
}

.facturation-delta-minus {
    color: #7dd3fc;
}

.facturation-meta em {
    font-style: normal;
    color: var(--muted);
    font-size: 11px;
}

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

.facturation-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.facturation-table th,
.facturation-table td {
    padding: 8px 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    text-align: left;
}

.facturation-table th {
    color: var(--muted);
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.facturation-table td.num,
.facturation-table th.num {
    text-align: right;
    white-space: nowrap;
}

.facturation-table tr.total-row td {
    font-weight: 700;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.btn-icon-add {
    width: 34px;
    height: 34px;
    padding: 0;
    font-size: 22px;
    line-height: 1;
    color: #38bdf8;
    border-color: rgba(56, 189, 248, 0.35);
}

.btn-icon-add:hover {
    background: rgba(56, 189, 248, 0.12);
    color: #7dd3fc;
}

.btn-icon-add-lg {
    width: 48px;
    height: 48px;
    font-size: 32px;
    flex-shrink: 0;
}

.period-row-current {
    background: rgba(56, 189, 248, 0.06);
}

.period-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
}

.period-badge-real {
    background: rgba(34, 197, 94, 0.15);
    color: #86efac;
    border: 1px solid rgba(34, 197, 94, 0.35);
}

.period-badge-est {
    background: rgba(251, 191, 36, 0.12);
    color: #fcd34d;
    border: 1px solid rgba(251, 191, 36, 0.3);
}

.period-badge-current {
    background: rgba(56, 189, 248, 0.15);
    color: #7dd3fc;
    border: 1px solid rgba(56, 189, 248, 0.35);
}

.period-box-kwh {
    display: block;
}

.period-partial-hint {
    display: block;
    margin-top: 3px;
    font-size: 10px;
    font-weight: 500;
    line-height: 1.3;
    color: var(--muted);
    white-space: normal;
}

.btn-period-adjust {
    font-size: 11px;
    padding: 0 8px;
    height: 28px;
}

.facturation-periods-table td:last-child,
.facturation-periods-table th:last-child {
    width: 88px;
}

.facturation-factures-wrap {
    margin-top: 16px;
    padding-top: 14px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.facturation-factures-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
}

.facturation-factures-title {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: #ddd;
}

.facturation-factures-table td:last-child,
.facturation-factures-table th:last-child {
    width: 76px;
}

.facturation-control-wrap {
    margin-top: 24px;
}

.facturation-control-table td:last-child,
.facturation-control-table th:last-child {
    width: 76px;
}

.control-gap-cell {
    white-space: nowrap;
}

.control-gap-value {
    display: block;
    font-weight: 600;
    margin-bottom: 4px;
}

.control-gap-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
}

.control-gap-ok {
    background: rgba(34, 197, 94, 0.15);
    color: #86efac;
    border: 1px solid rgba(34, 197, 94, 0.35);
}

.control-gap-warn {
    background: rgba(251, 191, 36, 0.12);
    color: #fcd34d;
    border: 1px solid rgba(251, 191, 36, 0.3);
}

.control-gap-bad {
    background: rgba(248, 113, 113, 0.15);
    color: #fca5a5;
    border: 1px solid rgba(248, 113, 113, 0.35);
}

.control-gap-na {
    background: rgba(148, 163, 184, 0.12);
    color: #cbd5e1;
    border: 1px solid rgba(148, 163, 184, 0.25);
}

.control-gap-muted {
    display: block;
    color: var(--muted, #94a3b8);
    margin-bottom: 4px;
}

.facturation-facture-actions {
    display: flex;
    justify-content: flex-end;
    gap: 4px;
}

.btn-icon-facture-edit {
    width: 30px;
    height: 30px;
    padding: 0;
    color: #38bdf8;
    border-color: rgba(56, 189, 248, 0.25);
}

.btn-icon-facture-edit:hover {
    background: rgba(56, 189, 248, 0.12);
    color: #7dd3fc;
}

.facturation-breakdown-meta {
    margin: 0 0 12px;
    font-size: 12px;
    color: var(--muted);
}

.facturation-ttc-btn {
    appearance: none;
    background: none;
    border: none;
    padding: 0;
    font: inherit;
    color: #7dd3fc;
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.facturation-ttc-btn:hover {
    color: #bae6fd;
}

.facturation-breakdown-table td.num,
.facturation-breakdown-table th.num {
    white-space: nowrap;
}

.breakdown-subtotal-row td {
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    font-weight: 600;
}

.breakdown-total-row td {
    border-top: 1px solid rgba(255, 255, 255, 0.16);
}

.btn-icon-facture-delete {
    width: 30px;
    height: 30px;
    padding: 0;
    color: var(--crit);
    border-color: rgba(239, 68, 68, 0.25);
}

.btn-icon-facture-delete:hover {
    background: rgba(239, 68, 68, 0.12);
    border-color: rgba(239, 68, 68, 0.45);
    color: #fca5a5;
}

.facture-form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px 14px;
    margin: 12px 0 4px;
}

.facture-form-grid .admin-modal-field {
    margin: 0;
}

.facture-form-span {
    grid-column: 1 / -1;
}

.facture-form-grid input {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #333;
    border-radius: 6px;
    background: #111;
    color: #eee;
    font-size: 13px;
}

#factureConsumption {
    color: #7dd3fc;
    font-weight: 600;
}

@media (max-width: 640px) {
    .facture-form-grid {
        grid-template-columns: 1fr;
    }
}

.meter-panel .vm-energies-hero:not(.vm-energies-hero--stack) {
    display: block;
}

.vm-energies-empty {
    padding: 28px 24px;
    text-align: center;
    color: var(--muted);
    background: var(--surface);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
}

.vm-energies-hero {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.6fr);
    gap: 20px;
    align-items: stretch;
    padding: 22px 24px;
    border-radius: var(--radius);
    border: 1px solid rgba(255, 176, 32, 0.28);
    background:
        radial-gradient(900px 280px at 0% 0%, rgba(255, 176, 32, 0.14), transparent 55%),
        radial-gradient(700px 240px at 100% 100%, rgba(56, 189, 248, 0.08), transparent 50%),
        var(--surface);
    box-shadow: var(--shadow);
}

.vm-energies-hero--stack {
    display: flex;
    flex-direction: column;
    gap: 12px;
    height: 100%;
    padding: 18px 20px;
}

@media (max-width: 860px) {
    .vm-energies-hero {
        grid-template-columns: 1fr;
    }
}

.vm-energies-intro {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 8px;
    padding-right: 12px;
}

.vm-energies-badge {
    display: inline-flex;
    align-self: flex-start;
    padding: 5px 10px;
    border-radius: 999px;
    background: rgba(255, 176, 32, 0.14);
    border: 1px solid rgba(255, 176, 32, 0.35);
    color: #ffc861;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.vm-energies-heading {
    margin: 0;
    font-size: clamp(1.5rem, 2.4vw, 2rem);
    font-weight: 800;
    line-height: 1.1;
    letter-spacing: -0.02em;
}

.vm-energies-lead {
    margin: 0;
    font-size: 13px;
    color: var(--muted);
    max-width: 28ch;
}

.vm-energies-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.vm-energies-grid--stack {
    grid-template-columns: 1fr;
    gap: 10px;
}

.vm-energies-grid--stack .vm-energy-card {
    min-height: 0;
    padding: 14px 16px;
}

@media (max-width: 560px) {
    .vm-energies-grid {
        grid-template-columns: 1fr;
    }
}

.vm-energy-card {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto auto;
    gap: 4px 12px;
    padding: 18px 20px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: rgba(0, 0, 0, 0.22);
    min-height: 132px;
}

.vm-energy-direct {
    border-color: rgba(255, 176, 32, 0.35);
    background: linear-gradient(160deg, rgba(255, 176, 32, 0.12), rgba(0, 0, 0, 0.18));
}

.vm-energy-inverse {
    border-color: rgba(56, 189, 248, 0.28);
    background: linear-gradient(160deg, rgba(56, 189, 248, 0.08), rgba(0, 0, 0, 0.18));
}

.vm-energies-empty--compact {
    padding: 16px 12px;
    font-size: 12px;
}

.facturation-inline-sub,
.facturation-inline-hint {
    margin: 0;
    font-size: 10px;
    line-height: 1.35;
    color: var(--muted);
    text-align: center;
}

.facturation-inline-hint a {
    color: #7dd3fc;
    text-decoration: none;
}

.facturation-inline-hint a:hover {
    text-decoration: underline;
}

.vm-energy-day {
    border-color: rgba(74, 222, 128, 0.32);
    background: linear-gradient(160deg, rgba(74, 222, 128, 0.1), rgba(0, 0, 0, 0.18));
}

.vm-energy-day .vm-energy-code {
    color: #86efac;
}

.vm-energy-month {
    border-color: rgba(167, 139, 250, 0.32);
    background: linear-gradient(160deg, rgba(167, 139, 250, 0.1), rgba(0, 0, 0, 0.18));
}

.vm-energy-month .vm-energy-code {
    color: #c4b5fd;
}

.vm-energy-label {
    grid-column: 1;
    font-size: 12px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.vm-energy-code {
    grid-column: 2;
    grid-row: 1 / span 2;
    align-self: start;
    font-size: 13px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: 0.02em;
    text-transform: none;
}

.vm-energy-direct .vm-energy-code {
    color: #fbbf24;
}

.vm-energy-inverse .vm-energy-code {
    color: #7dd3fc;
}

.vm-energy-value {
    grid-column: 1 / -1;
    font-size: clamp(2rem, 4.5vw, 3.2rem);
    font-weight: 800;
    line-height: 1;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.03em;
}

.vm-energy-direct .vm-energy-value {
    color: #ffcc66;
}

.vm-energy-inverse .vm-energy-value {
    color: #7dd3fc;
}

.vm-energy-unit {
    grid-column: 1;
    font-size: 14px;
    font-weight: 700;
    color: var(--muted);
}

.vm-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px 18px;
    box-shadow: var(--shadow);
    margin-bottom: 18px;
}

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

.vm-panel-head .section-title {
    margin: 0;
}

.vm-detail-toggle {
    font-size: 12px;
    padding: 8px 14px;
    flex-shrink: 0;
}

.vm-totals {
    margin-bottom: 14px;
}

.vm-sections {
    margin-top: 4px;
}

.vm-layout {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.vm-row-detail {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    align-items: start;
}

@media (max-width: 1100px) {
    .vm-row-detail {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 640px) {
    .vm-row-detail {
        grid-template-columns: 1fr;
    }
}

.vm-block.common { border-top: 3px solid var(--accent); }

.vm-block {
    border: 1px solid var(--border);
    border-radius: 12px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.02), transparent 48%), var(--surface-2);
    overflow: hidden;
    min-height: 0;
}

.vm-block.open {
    border-color: rgba(56, 189, 248, 0.28);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.vm-block.line-1 { border-top: 3px solid #60a5fa; }
.vm-block.line-2 { border-top: 3px solid #4ade80; }
.vm-block.line-3 { border-top: 3px solid #f97316; }

.vm-block-head {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 10px 12px;
    border: none;
    background: transparent;
    color: inherit;
    text-align: left;
}

.vm-block-titles {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.vm-block-title {
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.vm-block-sub {
    font-size: 11px;
    color: var(--muted);
}

.vm-block-preview {
    font-size: 11px;
    color: var(--info);
    font-variant-numeric: tabular-nums;
    line-height: 1.35;
    word-break: break-word;
}

.vm-block.open .vm-block-preview {
    display: none;
}

.vm-block-body {
    display: none;
    padding: 0 14px 14px;
}

.vm-block.open .vm-block-body {
    display: block;
}

.vm-block-unit {
    display: block;
    font-size: 10px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 8px;
}

.vm-metric-list {
    display: flex;
    flex-direction: column;
    gap: 0;
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.12);
}

.vm-row-metric {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 12px;
    border-bottom: 1px solid rgba(36, 48, 68, 0.85);
}

.vm-row-metric:last-child {
    border-bottom: none;
}

.vm-row-label {
    font-size: 12px;
    color: var(--muted);
}

.vm-row-val {
    font-size: 15px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    text-align: right;
}

.vm-phases {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
}

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

.vm-phase-card.phase-1 { border-top: 3px solid #60a5fa; }
.vm-phase-card.phase-2 { border-top: 3px solid #4ade80; }
.vm-phase-card.phase-3 { border-top: 3px solid #f97316; }

.vm-metric-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin-top: 8px;
}

.vm-metric {
    padding: 8px 10px;
    border-radius: 10px;
    background: var(--surface-2);
    border: 1px solid var(--border);
}

.vm-metric-label {
    display: block;
    font-size: 11px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.vm-metric-val {
    display: block;
    margin-top: 4px;
    font-size: 16px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.vm-empty {
    color: var(--muted);
    font-size: 13px;
}

.chart-panel, .table-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px 18px;
    box-shadow: var(--shadow);
    margin-bottom: 18px;
}

.chart-toolbar {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 0;
}

#historyExportBtn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.range-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 12px;
}

.range-mode-row {
    display: flex;
    justify-content: flex-end;
}

.range-mode-panel {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 8px;
    flex-shrink: 0;
}

.range-mode-group {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.range-presets {
    display: none;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.range-presets.range-presets-visible {
    display: flex;
}

.metric-group {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.range-custom {
    display: none;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.range-custom.range-custom-visible {
    display: flex;
}

.range-custom-label {
    font-size: 0.78rem;
    color: var(--muted);
}

.range-custom-input {
    padding: 6px 8px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: inherit;
    font: inherit;
    font-size: 0.82rem;
}

.range-custom-sep {
    color: var(--muted);
    font-size: 0.85rem;
}

.range-custom .btn-icon {
    flex-shrink: 0;
}

.range-period-error {
    width: 100%;
    margin: 0;
    font-size: 0.78rem;
    color: #ff8a80;
    text-align: right;
}

.range-period-error[hidden] {
    display: none;
}

.metric-custom {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
}

.metric-custom-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.metric-tab {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 10px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: inherit;
    font: inherit;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
}

.metric-tab:hover {
    border-color: rgba(56, 189, 248, 0.35);
}

.metric-tab.active {
    border-color: rgba(56, 189, 248, 0.5);
    background: rgba(56, 189, 248, 0.1);
    color: #bae6fd;
}

.metric-tab-count {
    min-width: 16px;
    padding: 0 4px;
    border-radius: 999px;
    background: rgba(255, 176, 32, 0.2);
    color: #ffdca8;
    font-size: 10px;
    line-height: 16px;
    text-align: center;
}

.metric-custom-body {
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: rgba(0, 0, 0, 0.12);
}

.metric-check-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px 12px;
}

.metric-check {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 6px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    user-select: none;
}

.metric-check:hover {
    background: rgba(255, 255, 255, 0.03);
}

.metric-check.active {
    background: rgba(255, 176, 32, 0.08);
}

.metric-check input {
    accent-color: var(--accent);
    flex-shrink: 0;
}

.metric-check-label {
    line-height: 1.25;
}

@media (max-width: 520px) {
    .metric-check-grid {
        grid-template-columns: 1fr;
    }
}

.chart-views-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.chart-views-left {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    flex: 1 1 auto;
    min-width: 0;
}

.chart-view-buttons {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.chart-view-btn {
    padding: 7px 12px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: inherit;
    font: inherit;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}

.chart-view-btn:hover {
    border-color: rgba(255, 176, 32, 0.35);
}

.chart-view-btn.active {
    border-color: rgba(255, 176, 32, 0.55);
    background: rgba(255, 176, 32, 0.12);
    color: #ffdca8;
}

.chart-custom-toggle {
    flex-shrink: 0;
}

.chart-custom-toggle.active {
    border-color: rgba(56, 189, 248, 0.45);
    background: rgba(56, 189, 248, 0.1);
}

.chart-custom-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 10px;
}

.chart-custom-hint {
    margin: 0;
    font-size: 11px;
    color: var(--muted);
}

.chart-custom-clear {
    flex-shrink: 0;
    padding: 4px 10px;
    font-size: 11px;
    line-height: 1.2;
}

.chart-custom-panel {
    margin-bottom: 12px;
    padding: 12px 14px;
    border-radius: var(--radius);
    border: 1px dashed var(--border);
    background: rgba(0, 0, 0, 0.12);
}

.chart-custom-panel .chart-custom-hint {
    margin: 0;
}

.table-panel-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0;
    border: 0;
    background: none;
    color: inherit;
    font: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-align: left;
}

.table-panel-toggle:hover {
    color: #ffdca8;
}

.table-panel-chevron {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 10px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--accent);
    flex-shrink: 0;
    transition: transform 0.15s, border-color 0.15s, background 0.15s, color 0.15s;
}

.table-panel-chevron svg {
    display: block;
}

.table-panel-toggle:hover .table-panel-chevron {
    border-color: rgba(255, 176, 32, 0.55);
    background: rgba(255, 176, 32, 0.12);
    color: #ffd166;
}

.table-panel-toggle.open .table-panel-chevron {
    transform: rotate(90deg);
}

.table-panel-body {
    margin-top: 14px;
}

.table-panel-body[hidden] {
    display: none;
}

.metric-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 10px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    font-size: 12px;
    cursor: pointer;
    user-select: none;
}

.metric-chip input { accent-color: var(--accent); }

.metric-chip.active {
    border-color: rgba(255, 176, 32, 0.55);
    background: rgba(255, 176, 32, 0.1);
}

.chart-curve-legend {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 14px;
    margin-bottom: 10px;
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: rgba(0, 0, 0, 0.12);
}

.chart-curve-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 600;
    color: #d6deea;
}

.chart-curve-item i {
    width: 10px;
    height: 10px;
    border-radius: 999px;
    flex-shrink: 0;
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.chart-box {
    position: relative;
    height: 380px;
}

.chart-box.is-loading canvas {
    opacity: 0.35;
    pointer-events: none;
}

.chart-empty {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    color: var(--muted);
    font-size: 14px;
}

.chart-loading {
    position: absolute;
    inset: 0;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    color: var(--muted);
    font-size: 14px;
    background: rgba(11, 15, 22, 0.72);
    backdrop-filter: blur(2px);
}

.chart-loading[hidden] {
    display: none !important;
}

.chart-loading-spinner {
    animation: chart-spin 0.85s linear infinite;
    color: #ffb020;
}

@keyframes chart-spin {
    to { transform: rotate(360deg); }
}

.btn-icon.loading {
    pointer-events: none;
    opacity: 0.75;
    cursor: wait;
}

.btn-icon.loading svg {
    animation: chart-spin 0.85s linear infinite;
}

.range-presets.loading {
    opacity: 0.65;
    pointer-events: none;
}

.table-wrap { overflow: auto; max-height: 420px; }

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

th, td {
    padding: 10px 12px;
    border-bottom: 1px solid #1b2433;
    text-align: left;
    white-space: nowrap;
}

th {
    position: sticky;
    top: 0;
    background: #121820;
    color: var(--muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

th .th-energy-role {
    text-transform: none;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.num { font-variant-numeric: tabular-nums; }

@media (max-width: 1100px) {
    .glb-seg-status {
        min-width: 200px;
    }
}

@media (max-width: 640px) {
    .glb-bar {
        flex-wrap: wrap;
        row-gap: 8px;
        overflow-x: visible;
    }

    .glb-seg {
        flex: 1 1 calc(50% - 4px);
        min-width: 0;
        border-right: none;
        padding: 4px 0;
    }

    .glb-seg-status {
        flex: 1 1 100%;
        flex-wrap: wrap;
        border-bottom: 1px solid rgba(255, 255, 255, 0.06);
        padding-bottom: 8px;
    }

    .glb-seg-updated {
        flex: 1 1 100%;
        margin-left: 0;
        padding-top: 4px;
        border-top: 1px solid rgba(255, 255, 255, 0.06);
    }

    .chart-box { height: 280px; }
}

/* Administration */
.admin-tabs {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.admin-tab {
    min-width: 120px;
}

.admin-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px 22px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
}

.admin-panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

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

.admin-filter-group {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: nowrap;
}

.admin-filter-select {
    width: auto;
    min-width: 200px;
    max-width: 280px;
}

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

.admin-form-title {
    margin: 0 0 12px;
    font-size: 14px;
    font-weight: 700;
}

.admin-hint {
    margin: 0 0 10px;
    font-size: 12px;
    color: var(--muted);
    line-height: 1.45;
}

.box-phase-lock-hint {
    display: block;
    margin-top: 6px;
    font-size: 11px;
    font-weight: 500;
    line-height: 1.35;
    color: #fcd34d;
}

.admin-modal-field select:disabled {
    opacity: 0.72;
    cursor: not-allowed;
}

#unassignedWrap {
    margin-bottom: 16px;
}

.admin-form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
    margin-bottom: 14px;
}

.admin-form-grid label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
}

.admin-form-grid input,
.admin-select {
    width: 100%;
    min-width: 0;
    height: 38px;
    padding: 0 12px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 13px;
    text-transform: none;
    letter-spacing: normal;
}

.admin-table-wrap {
    max-height: 480px;
}

.admin-empty {
    text-align: center;
    color: var(--muted);
    padding: 24px !important;
}

.admin-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    align-items: center;
}

.admin-actions .btn-icon {
    width: 32px;
    height: 32px;
    min-width: 32px;
    padding: 0;
}

.admin-actions .btn-icon-danger {
    color: var(--crit);
    border-color: rgba(239, 68, 68, 0.25);
}

.admin-actions .btn-icon-danger:hover {
    background: rgba(239, 68, 68, 0.15);
    border-color: rgba(239, 68, 68, 0.45);
}

.admin-actions .btn-icon-tarif {
    color: #fbbf24;
    border-color: rgba(251, 191, 36, 0.25);
}

.admin-actions .btn-icon-tarif:hover {
    background: rgba(251, 191, 36, 0.12);
    border-color: rgba(251, 191, 36, 0.45);
    color: #fcd34d;
}

.tarif-modal-hint {
    margin-top: 4px;
    font-size: 12px;
    color: #888;
}

.tarif-type-field {
    margin: 8px 0 4px;
    max-width: 280px;
}

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

.tarif-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.tarif-table th,
.tarif-table td {
    padding: 10px 8px;
    border-bottom: 1px solid #2a2a2a;
    vertical-align: middle;
}

.tarif-table th {
    color: #888;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    text-align: left;
}

.tarif-table input {
    width: 100%;
    min-width: 88px;
    padding: 8px 10px;
    background: #111;
    border: 1px solid #333;
    border-radius: 6px;
    color: #eee;
    font-size: 13px;
}

.tarif-last-label {
    display: inline-block;
    padding: 8px 0;
    color: #aaa;
    font-size: 13px;
}

.tarif-extras-wrap {
    margin: 16px 0 4px;
    padding-top: 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.tarif-extras-title {
    margin: 0 0 10px;
    font-size: 13px;
    font-weight: 600;
    color: #ddd;
}

.tarif-extras-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px 14px;
}

.tarif-extras-grid .admin-modal-field {
    margin: 0;
}

.tarif-extras-grid input {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #333;
    border-radius: 6px;
    background: #111;
    color: #eee;
    font-size: 13px;
}

.tarif-tva-field {
    display: flex;
    align-items: center;
    gap: 6px;
}

.tarif-tva-suffix {
    color: #888;
    font-size: 13px;
}

@media (max-width: 640px) {
    .tarif-extras-grid {
        grid-template-columns: 1fr;
    }
}

.btn-sm {
    height: 30px;
    padding: 0 10px;
    font-size: 11px;
}

.btn-danger {
    background: rgba(239, 68, 68, 0.12);
    border: 1px solid rgba(239, 68, 68, 0.35);
    color: var(--crit);
}

.btn-danger:hover {
    background: rgba(239, 68, 68, 0.22);
}

.admin-badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
}

.admin-badge.ok {
    background: rgba(34, 197, 94, 0.15);
    color: var(--ok);
}

.admin-badge.off {
    background: rgba(239, 68, 68, 0.12);
    color: var(--crit);
}

.admin-flash {
    margin-bottom: 14px;
    padding: 10px 14px;
    border-radius: 10px;
    font-size: 13px;
}

.admin-flash.ok {
    background: rgba(34, 197, 94, 0.12);
    border: 1px solid rgba(34, 197, 94, 0.25);
    color: #86efac;
}

.admin-flash.error {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.25);
    color: #fca5a5;
}

.admin-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    display: none;
    z-index: 100;
    padding: 20px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

#confirmModal {
    z-index: 120;
}

#facturationConfirmModal,
#facturationMessageModal {
    z-index: 120;
}

#pwdModal {
    z-index: 110;
}

#deviceModal {
    z-index: 100;
}

#boxIpModal,
#boxMqttModal {
    z-index: 130;
}

.cfg-network-open {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 24px;
}

.cfg-open-block {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

.cfg-ip-open-row .cfg-ip-open {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
}

.cfg-ip-summary {
    font-size: 12px;
    color: var(--muted);
}

.admin-modal-backdrop:not([hidden]) {
    display: flex;
    justify-content: center;
    align-items: center;
}

.admin-modal {
    width: min(400px, 100%);
    max-height: calc(100dvh - 40px);
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 22px;
    box-shadow: var(--shadow);
}

.admin-modal h3 {
    margin: 0 0 6px;
    font-size: 18px;
}

.admin-modal-sub {
    margin: 0 0 16px;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.5;
    white-space: pre-line;
}

.admin-modal-confirm .admin-modal-sub strong {
    color: var(--text);
    font-family: ui-monospace, monospace;
}

.admin-modal-field-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px 14px;
    margin-bottom: 16px;
}

.admin-modal-field-row .admin-modal-field {
    margin-bottom: 0;
}

.admin-modal-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 16px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
}

.admin-modal-field input {
    height: 38px;
    padding: 0 12px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    font: inherit;
    text-transform: none;
    letter-spacing: normal;
}

.admin-modal-field input[readonly] {
    cursor: default;
    opacity: 0.9;
    background: var(--surface);
}

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

code {
    font-family: ui-monospace, Consolas, monospace;
    font-size: 12px;
    color: var(--info);
}

/* ── Device config modal ── */

/* Le hidden attribute doit toujours l'emporter sur display: flex/grid des classes */
[hidden] { display: none !important; }

.admin-modal-wide {
    width: min(520px, 100%);
}

.admin-modal-breakdown {
    width: min(720px, 100%);
}

.admin-modal-section {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 20px 0 14px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
}

.admin-modal-section::before,
.admin-modal-section::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--border);
}

.cfg-status-ok {
    color: var(--ok);
    font-size: 14px;
    line-height: 1;
}

.cfg-status-err {
    color: var(--warn);
    font-size: 14px;
    line-height: 1;
}

.device-cfg-loading {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 0 14px;
    color: var(--muted);
    font-size: 13px;
}

.spinner {
    flex-shrink: 0;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 176, 32, 0.25);
    border-top-color: var(--accent);
    border-radius: 50%;
    display: inline-block;
    animation: spin 0.75s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.device-cfg-error {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 9px 12px;
    border-radius: 10px;
    font-size: 12px;
    background: rgba(239, 68, 68, 0.09);
    border: 1px solid rgba(239, 68, 68, 0.22);
    color: #fca5a5;
    margin-bottom: 12px;
}

.device-cfg-error-msg {
    flex: 1;
    line-height: 1.45;
}

#deviceCfgRetry {
    flex-shrink: 0;
    height: 30px;
    color: #fca5a5;
    border-color: rgba(239, 68, 68, 0.35);
}

.cfg-radio-group {
    display: flex;
    gap: 20px;
    padding: 6px 0 2px;
}

.cfg-radio-group label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 500;
    text-transform: none;
    letter-spacing: normal;
    color: var(--text);
    cursor: pointer;
}

.cfg-radio-group input[type="radio"] {
    accent-color: var(--accent);
    width: 15px;
    height: 15px;
    cursor: pointer;
    flex-shrink: 0;
}

.admin-modal-field select {
    height: 38px;
    padding: 0 12px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    font: inherit;
    font-size: 13px;
    text-transform: none;
    letter-spacing: normal;
    width: 100%;
}

.admin-modal-field.field-invalid span:first-child {
    color: #fca5a5;
}

.admin-modal-field.field-invalid input,
.admin-modal-field.field-invalid select,
.admin-modal-field.field-invalid .tarif-tva-field input {
    border-color: rgba(239, 68, 68, 0.65);
    box-shadow: 0 0 0 1px rgba(239, 68, 68, 0.18);
    color: #fca5a5;
}

.admin-modal-field.field-invalid select {
    border-color: rgba(239, 68, 68, 0.65);
    box-shadow: 0 0 0 1px rgba(239, 68, 68, 0.18);
    color: #fca5a5;
}

.field-error-msg {
    display: block;
    margin-top: 5px;
    font-size: 11px;
    font-weight: 500;
    line-height: 1.35;
    color: #fca5a5;
    text-transform: none;
    letter-spacing: normal;
}

.tarif-table td.field-invalid-cell input {
    border-color: rgba(239, 68, 68, 0.65);
    box-shadow: 0 0 0 1px rgba(239, 68, 68, 0.18);
    color: #fca5a5;
}

.tarif-table td.field-invalid-cell .field-error-msg {
    max-width: 220px;
    white-space: normal;
}

.device-modal-actions {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 8px;
}

.device-modal-actions #deviceModalCancel {
    justify-self: start;
}

.device-modal-actions #deviceModalRestart {
    justify-self: center;
}

.device-modal-actions #deviceModalSave {
    justify-self: end;
}

.admin-modal-actions-spread {
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
}

/* ── Mobile (< 640px) ── */
@media (max-width: 640px) {
    .wrap {
        padding: 12px 14px 28px;
    }

    .topbar {
        padding: 12px 14px;
        gap: 12px;
    }

    .brand h1 {
        font-size: 16px;
    }

    .brand p {
        font-size: 11px;
    }

    .topbar-header-actions {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }

    .topbar-nav {
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .topbar-nav::-webkit-scrollbar {
        display: none;
    }

    .topbar-account-group {
        width: 100%;
        justify-content: space-between;
    }

    .user-pill {
        max-width: min(220px, 55vw);
    }

    .topbar-row-tools {
        width: 100%;
    }

    .topbar-tools-group {
        gap: 8px;
    }

    .topbar-tools-group .select {
        flex: 1 1 100%;
        width: 100%;
        min-width: 0;
    }

    .topbar-tools-group .status-pill-mqtt #mqttLabel {
        max-width: 9em;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .panel-title-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
    }

    .panel-title-meta {
        white-space: normal;
    }

    .vm-energies-hero,
    .facturation-hero,
    .facturation-card {
        padding: 16px 14px;
    }

    .vm-energy-card {
        padding: 14px 16px;
        min-height: 0;
    }

    .facturation-head,
    .facturation-factures-head {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }

    .facturation-head .btn,
    .facturation-factures-head .btn-icon-add-lg {
        align-self: flex-start;
    }

    .facturation-meta {
        flex-direction: column;
        gap: 6px;
    }

    .chart-panel,
    .table-panel,
    .admin-panel {
        padding: 14px;
    }

    .chart-views-row {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }

    .chart-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    #historyExportBtn {
        width: 100%;
    }

    .chart-views-left,
    .range-mode-panel {
        width: 100%;
        justify-content: flex-start;
    }

    .range-mode-row {
        justify-content: flex-start;
    }

    .range-custom {
        width: 100%;
    }

    .range-custom-input {
        flex: 1 1 120px;
        min-width: 0;
        max-width: 100%;
    }

    .vm-panel-head {
        flex-wrap: wrap;
        gap: 8px;
    }

    .glb-seg-relay {
        flex: 1 1 100%;
    }

    .glb-seg-updated {
        white-space: normal;
        text-align: right;
    }

    .admin-modal-backdrop {
        padding: 12px;
        align-items: flex-start;
    }

    .admin-modal {
        max-height: calc(100dvh - 24px);
    }

    .admin-modal-field-row {
        grid-template-columns: 1fr;
    }

    .device-modal-actions {
        grid-template-columns: 1fr;
        justify-items: stretch;
    }

    .device-modal-actions #deviceModalCancel,
    .device-modal-actions #deviceModalRestart,
    .device-modal-actions #deviceModalSave {
        justify-self: stretch;
        width: 100%;
    }

    .admin-filter-group {
        flex-wrap: wrap;
        width: 100%;
    }

    .admin-filter-select {
        flex: 1 1 100%;
        max-width: none;
    }
}

@media (max-height: 820px) {
    .admin-modal-backdrop:not([hidden]) {
        align-items: flex-start;
        padding-top: 12px;
        padding-bottom: 12px;
    }

    .admin-modal {
        max-height: calc(100dvh - 24px);
    }
}

@media (max-width: 400px) {
    .topbar-nav-item {
        padding: 0 11px;
        font-size: 11px;
    }

    .glb-seg {
        flex: 1 1 100%;
    }

    .glb-seg-status {
        min-width: 0;
    }

    .btn-ghost {
        padding: 0 10px;
        font-size: 11px;
    }
}

/* —— Schéma d'installation compact (réseau → compteur → local) —— */
.install-schema-panel {
    margin-bottom: 14px;
    max-width: 520px;
}

.install-schema-panel--embedded {
    max-width: none;
    margin-bottom: 0;
    min-height: 100%;
}

.meter-panel .install-schema-panel--embedded.vm-energies-hero--stack {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-bottom: calc(18px + 2.75em);
}

.install-schema-vfill {
    flex: 1 1 0;
    min-height: 0;
    margin-bottom: calc(-2 * 1.375em);
    pointer-events: none;
}

.install-schema-panel--embedded .install-schema-body {
    margin-top: 0;
    flex-shrink: 0;
    width: 100%;
    display: flex;
    justify-content: center;
    padding-bottom: 12px;
    min-height: 0;
}

.install-schema-panel--embedded .install-schema-body > * {
    flex-shrink: 0;
}

.install-schema-panel-inactive {
    opacity: 0.72;
}

.install-schema-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex-wrap: wrap;
}

.install-schema-head .vm-energies-table-title {
    margin: 0;
}

.install-schema-badges {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.install-schema-badge {
    display: inline-flex;
    align-items: center;
    padding: 5px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #ffc861;
    background: rgba(255, 176, 32, 0.14);
    border: 1px solid rgba(255, 176, 32, 0.35);
}

.install-schema-badge-tarif {
    color: #7dd3fc;
    border-color: rgba(56, 189, 248, 0.35);
    background: rgba(56, 189, 248, 0.12);
}

.install-schema-body {
    min-height: 0;
}

.install-schema-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 96px;
    color: var(--muted);
    font-size: 13px;
}

.install-diagram {
    width: 100%;
}

.install-diagram-grid {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-rows: auto auto auto;
    align-items: center;
    column-gap: 0;
    row-gap: 10px;
    width: 100%;
    max-width: 560px;
    margin: 0 auto;
}

.install-grid-pole {
    grid-column: 1;
    grid-row: 2;
    align-self: center;
    justify-self: end;
    padding-right: 2px;
}

.install-grid-power {
    grid-column: 2;
    grid-row: 1;
    justify-self: center;
}

.install-grid-phases {
    grid-column: 2;
    grid-row: 2;
}

.install-grid-meter {
    grid-column: 2;
    grid-row: 3;
    justify-self: center;
}

.install-grid-site {
    grid-column: 3;
    grid-row: 2;
    align-self: center;
    justify-self: start;
    padding-left: 2px;
}

.install-meter-power-top {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
    padding: 4px 10px;
    border-radius: 8px;
    background: rgba(255, 176, 32, 0.12);
    border: 1px solid rgba(255, 176, 32, 0.32);
    white-space: nowrap;
}

.install-meter-power-top.is-injection {
    background: rgba(56, 189, 248, 0.12);
    border-color: rgba(56, 189, 248, 0.32);
}

.install-meter-power-top strong {
    font-size: 16px;
    font-weight: 800;
    line-height: 1.1;
    color: var(--accent);
    font-variant-numeric: tabular-nums;
}

.install-meter-power-top.is-injection strong {
    color: var(--info);
}

.install-tri-phases {
    display: flex;
    flex-direction: column;
    gap: 14px;
    width: 100%;
}

.install-diagram--mono .install-tri-phases {
    gap: 10px;
}

.install-tri-phase-row {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    column-gap: 0;
    width: 100%;
}

.install-tri-bridge {
    display: flex;
    align-items: center;
    width: 100%;
    min-width: 0;
    position: relative;
    z-index: 1;
}

.install-tri-bridge-in {
    margin-right: -10px;
}

.install-tri-bridge-out {
    margin-left: -10px;
}

.install-tri-phase-measure {
    display: flex;
    justify-content: center;
    z-index: 2;
    flex-shrink: 0;
}

.install-tri-phase-measure .install-measure-chip-phase {
    justify-content: center;
    text-align: center;
    padding: 4px 12px;
    border-color: color-mix(in srgb, var(--phase-color, var(--info)) 40%, transparent);
}

.install-tri-phase-row--neutral .install-tri-phase-measure {
    min-height: 0;
}

.install-neutral-tag {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #93c5fd;
    background: rgba(59, 130, 246, 0.12);
    border: 1px solid rgba(59, 130, 246, 0.28);
}

.install-node {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    z-index: 2;
}

.install-meter-zone {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    min-width: 0;
    z-index: 2;
    position: relative;
    padding: 0 2px;
}

.install-node-meter {
    position: relative;
}

.install-node-site {
    position: relative;
}

.install-node-tag {
    display: block;
    max-width: 136px;
    padding: 4px 8px;
    border-radius: 8px;
    font-size: 11px;
    font-weight: 700;
    line-height: 1.25;
    text-align: center;
    color: #bae6fd;
    background: rgba(56, 189, 248, 0.12);
    border: 1px solid rgba(56, 189, 248, 0.28);
}

.install-icon {
    display: block;
    width: auto;
    height: auto;
    max-width: 162px;
    max-height: 162px;
    object-fit: contain;
    filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.35));
}

.install-icon-pole {
    max-width: 150px;
    max-height: 150px;
}

.install-icon-meter {
    max-width: 66px;
    max-height: 72px;
}

.install-icon-house {
    max-width: 156px;
    max-height: 144px;
}

.install-icon-factory {
    max-width: 174px;
    max-height: 156px;
}

.install-bridge {
    display: flex;
    align-items: center;
    align-self: center;
    width: 100%;
    min-width: 0;
    position: relative;
    z-index: 1;
    padding: 10px 0;
}

.install-bridge-in {
    margin-right: -24px;
}

.install-bridge-out {
    margin-left: -24px;
}

.install-wires {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 6px;
    width: 100%;
}

.install-wire-row {
    display: block;
    width: 100%;
}

.install-wires--1 {
    gap: 8px;
}

.install-wire {
    display: block;
    height: 4px;
    width: 100%;
}

.install-wire-dash {
    display: block;
    width: 100%;
}

.install-wire-neutral {
    --wire-color: #3b82f6;
}

.install-wire-dash {
    height: 100%;
    border-radius: 999px;
    background: repeating-linear-gradient(
        90deg,
        color-mix(in srgb, var(--wire-color, #ef4444) 55%, #334155) 0 6px,
        transparent 6px 10px
    );
    opacity: 0.45;
}

.install-wire-neutral .install-wire-dash {
    opacity: 0.35;
}

.install-wire-dash.is-live {
    opacity: 1;
    background: repeating-linear-gradient(
        90deg,
        color-mix(in srgb, var(--wire-color, #ef4444) 92%, white) 0 7px,
        transparent 7px 11px
    );
    background-size: 18px 100%;
    animation: install-dash-flow 0.7s linear infinite;
}

.install-wire-dash.is-injection.is-live {
    background: repeating-linear-gradient(
        90deg,
        color-mix(in srgb, var(--info) 92%, white) 0 7px,
        transparent 7px 11px
    );
    background-size: 18px 100%;
    animation-direction: reverse;
}

@keyframes install-dash-flow {
    from { background-position: 0 0; }
    to { background-position: 18px 0; }
}

.install-node-power {
    position: absolute;
    top: -6px;
    left: 50%;
    transform: translate(-50%, -100%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
    padding: 3px 8px;
    border-radius: 8px;
    background: rgba(255, 176, 32, 0.12);
    border: 1px solid rgba(255, 176, 32, 0.32);
    min-width: 0;
    white-space: nowrap;
}

.install-node-power.is-injection {
    background: rgba(56, 189, 248, 0.12);
    border-color: rgba(56, 189, 248, 0.32);
}

.install-schema-total-label {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
}

.install-node-power strong {
    font-size: 16px;
    font-weight: 800;
    line-height: 1.1;
    color: var(--accent);
    font-variant-numeric: tabular-nums;
}

.install-node-power.is-injection strong {
    color: var(--info);
}

.install-schema-building {
    display: flex;
    align-items: center;
    justify-content: center;
}

.install-schema-building.is-pending {
    width: 72px;
    height: 72px;
    border-radius: 12px;
    background: linear-gradient(90deg, rgba(148, 163, 184, 0.12) 25%, rgba(148, 163, 184, 0.22) 50%, rgba(148, 163, 184, 0.12) 75%);
    background-size: 200% 100%;
    animation: install-tarif-shimmer 1.1s ease-in-out infinite;
}

@keyframes install-tarif-shimmer {
    0% { background-position: 100% 0; }
    100% { background-position: -100% 0; }
}

.install-measures--inline {
    width: 100%;
    max-width: 240px;
    margin-bottom: 1px;
}

.install-measures-strip {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 4px;
}

.install-measures-strip-tri {
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
}

.install-measure-chip {
    display: inline-flex;
    align-items: baseline;
    gap: 4px;
    padding: 4px 10px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--text);
    background: rgba(8, 11, 16, 0.88);
    border: 1px solid rgba(56, 189, 248, 0.28);
    white-space: nowrap;
}

.install-measure-chip em {
    font-style: normal;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--muted);
}

.install-measure-chip-phase {
    justify-content: center;
    font-size: 12px;
    border-color: color-mix(in srgb, var(--phase-color, var(--info)) 35%, transparent);
}

.install-measure-chip-p {
    color: #f9a8d4;
}

.install-measure-chip .is-injection {
    color: var(--info);
}

.install-measures-total-inline {
    margin-top: 4px;
    text-align: center;
    font-size: 11px;
    font-weight: 700;
    color: var(--muted);
}

.install-measures-total-inline em {
    font-style: normal;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    margin-right: 3px;
}

.install-measures-total-inline strong {
    font-size: 15px;
    font-weight: 800;
    color: var(--accent);
    font-variant-numeric: tabular-nums;
}

.install-measures-total-inline strong.is-injection {
    color: var(--info);
}

@media (max-width: 720px) {
    .install-schema-panel {
        max-width: 100%;
    }

    .install-diagram-grid {
        max-width: 100%;
    }

    .install-tri-phase-row {
        grid-template-columns: 1fr auto 1fr;
    }

    .install-tri-phase-measure .install-measure-chip-phase {
        font-size: 11px;
        padding: 3px 10px;
    }

    .install-icon {
        max-width: 108px;
        max-height: 108px;
    }

    .install-icon-pole { max-width: 100px; max-height: 100px; }
    .install-icon-meter { max-width: 44px; max-height: 48px; }
    .install-icon-house { max-width: 104px; max-height: 96px; }
    .install-icon-factory { max-width: 116px; max-height: 104px; }

    .install-node-tag {
        max-width: 108px;
        font-size: 10px;
    }
}

@media (max-width: 480px) {
    .install-node-power strong {
        font-size: 11px;
    }
}
