:root {
    color-scheme: dark;
    --bg: #0b1220;
    --surface: #131c2e;
    --surface-2: #1c2840;
    --line: #243049;
    --text: #e6edf7;
    --muted: #8696b4;
    --amber: #f59e0b;
    --emerald: #10b981;
    --violet: #8b5cf6;
    --rose: #f43f5e;
    --slate: #64748b;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", system-ui, sans-serif;
}

code { font-family: ui-monospace, "JetBrains Mono", Menlo, Consolas, monospace; font-size: 0.92em; }

.dash {
    width: 100%;
    margin: 0 auto;
    padding: 1.5rem 1.5rem 4rem;
}

.dash-header {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.dash-header h1 {
    margin: 0;
    font-size: 1.6rem;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 0.75rem;
    color: var(--muted);
    font-size: 0.9rem;
    flex: 1 1 auto;
    min-width: 0;
}

.refresh {
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 0.35rem 0.7rem;
    font-size: 0.85rem;
    cursor: pointer;
}
.refresh:hover { background: var(--line); }
.refresh:disabled { opacity: 0.5; cursor: not-allowed; }

.tuya-toggle {
    border-radius: 6px;
    padding: 0.35rem 0.8rem;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
}
.tuya-toggle:disabled { opacity: 0.5; cursor: not-allowed; }
.tuya-toggle-on  { background: rgba(16, 185, 129, 0.18); color: #6ee7b7; border-color: rgba(16, 185, 129, 0.4); }
.tuya-toggle-on:hover  { background: rgba(16, 185, 129, 0.32); }
.tuya-toggle-off { background: rgba(244, 63, 94, 0.18); color: #fda4af; border-color: rgba(244, 63, 94, 0.4); }
.tuya-toggle-off:hover { background: rgba(244, 63, 94, 0.32); }

.auto { display: inline-flex; align-items: center; gap: 0.3rem; font-size: 0.85rem; }

.meta-right {
    margin-left: auto;
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.4rem 0.5rem;
}

.tiles {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.metrics-h { font-size: 0.78rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; margin: 0.6rem 0 0.4rem; }
.sensors-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.sensor-card { padding: 0.9rem 1.1rem; border-top: 3px solid var(--slate); }
.sensor-card-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 0.6rem; }
.sensor-card-name { font-size: 0.95rem; font-weight: 600; color: var(--text); }
.sensor-card-id { font-size: 0.7rem; color: var(--muted); }
.sensor-metric { padding: 0.5rem 0; border-top: 1px solid var(--line); }
.sensor-metric:first-of-type { border-top: none; padding-top: 0.1rem; }
.sensor-metric-head { display: flex; justify-content: space-between; align-items: baseline; }
.sensor-metric-label { font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.sensor-metric-value { font-size: 1.05rem; font-weight: 600; color: var(--text); }
.sensor-metric-sub { font-size: 0.7rem; color: var(--muted); margin-top: 0.1rem; }
.sensor-spark { width: 100%; height: 36px; display: block; }
.sensor-spark-wrap { position: relative; width: 100%; height: 36px; margin-top: 0.25rem; }
.spark-tip {
    position: absolute;
    top: -2px;
    transform: translateY(-100%);
    pointer-events: none;
    background: rgba(11,18,32,0.92);
    border: 1px solid rgba(148,163,184,0.25);
    color: #e6edf7;
    font-size: 0.7rem;
    font-weight: 500;
    padding: 0.15rem 0.45rem;
    border-radius: 4px;
    white-space: nowrap;
    line-height: 1.2;
    z-index: 5;
}
.batt-pill { display: inline-block; font-size: 0.65rem; font-weight: 600; padding: 0.05rem 0.45rem; border-radius: 999px; margin-left: 0.4rem; vertical-align: 0.1em; }
.batt-pill-good { background: rgba(16, 185, 129, 0.18); color: #6ee7b7; }
.batt-pill-warn { background: rgba(245, 158, 11, 0.20); color: #fcd34d; }
.batt-pill-bad  { background: rgba(244, 63, 94, 0.20);  color: #fda4af; }

.tank-pill {
    display: inline-block; font-size: 0.65rem; font-weight: 600;
    padding: 0.05rem 0.45rem; border-radius: 999px; margin-left: 0.4rem;
    vertical-align: 0.1em;
    background: rgba(14, 165, 233, 0.18); color: #7dd3fc;
}
.tank-pill.tank-low  { background: rgba(245, 158, 11, 0.20); color: #fcd34d; }
.tank-pill.tank-crit { background: rgba(244, 63, 94, 0.20);  color: #fda4af; }
.tank-pill.tank-pill-big {
    font-size: 1.05rem; padding: 0.15rem 0.65rem; margin-left: 0;
    border-radius: 8px;
}
.tank-fill-row { border-top: 1px dashed rgba(148, 163, 184, 0.18); padding-top: 0.5rem; margin-top: 0.4rem; }
.placeholder-row .sensor-metric-label { color: #86efac; }
.placeholder-row .sensor-metric-value { color: #86efac; font-variant-numeric: tabular-nums; }
.sensor-metric-hint { font-weight: 400; opacity: 0.55; font-size: 0.75em; margin-left: 0.3rem; }
.tank-usage { display: flex; gap: 0.4rem; align-items: baseline; flex-wrap: wrap; }
.tank-usage-used strong { color: #f5a3a3; font-weight: 600; }
.tank-usage-refilled { opacity: 0.85; }
.tank-usage-refilled strong { color: #6ee7b7; font-weight: 600; }
.tank-usage-rate strong { color: #7dd3fc; font-weight: 600; }
.tank-usage-left strong { color: #fcd34d; font-weight: 600; }
.tank-usage-aux { opacity: 0.55; font-weight: 400; }

.tank-cfg {
    display: flex; gap: 0.75rem; align-items: center;
    margin-top: 0.35rem; font-size: 0.7rem; color: var(--muted);
}
.tank-cfg label { display: inline-flex; align-items: center; gap: 0.3rem; }
.tank-cfg input {
    width: 4.5rem; padding: 0.1rem 0.35rem;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid rgba(148, 163, 184, 0.25);
    border-radius: 4px; color: #e6edf7;
    font-size: 0.7rem; font-family: inherit;
}
.tank-cfg input:focus { outline: none; border-color: rgba(14, 165, 233, 0.6); }
.tank-cfg-unit { color: var(--muted); opacity: 0.7; }

.gauges {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.gauge {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 0.9rem 1rem 0.6rem;
    border-top: 3px solid var(--slate);
    position: relative;
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto auto;
    column-gap: 0.5rem;
    row-gap: 0.4rem;
}
.gauge.tile-amber   { border-top-color: var(--amber); }
.gauge.tile-emerald { border-top-color: var(--emerald); }
.gauge.tile-violet  { border-top-color: var(--violet); }
.gauge.tile-rose    { border-top-color: var(--rose); }

.gauge-svg {
    grid-column: 1 / -1;
    grid-row: 2;
    width: 100%;
    height: auto;
    max-height: 200px;
}
.gauge-svg .gauge-value { fill: var(--text); font-size: 32px; font-weight: 600; }
.gauge-svg .gauge-unit  { fill: var(--muted); font-size: 16px; font-weight: 500; }
.gauge-svg .gauge-label { fill: var(--muted); font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; }

.gauge-corner {
    font-size: 0.78rem;
    line-height: 1.25;
    color: var(--muted);
}
.gauge-corner .v { color: var(--text); font-weight: 600; font-size: 0.92rem; }
.gauge-corner .l { display: block; font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.eflow-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-top: 3px solid var(--amber);
    border-radius: 12px;
    padding: 0.9rem 1rem 0.6rem;
}
.card.dash-sankey-card {
    padding: 0.9rem 1rem 0.6rem;
    margin-bottom: 0;
    border-top: 3px solid var(--amber);
    display: flex;
    flex-direction: column;
}
.card.dash-amsankey-card {
    padding: 0.9rem 1rem 0.6rem;
    margin-bottom: 0;
    border-top: 3px solid var(--amber);
    display: flex;
    flex-direction: column;
}
.card.dash-amsankey-card h2 { margin: 0 0 0.4rem 0; font-size: 0.85rem; }
.dash-amsankey-host { position: relative; flex: 1 1 auto; min-height: 240px; width: 100%; }

.card.dash-grid3-card {
    padding: 0.9rem 1rem 0.6rem;
    margin-bottom: 0;
    border-top: 3px solid var(--slate);
    display: flex;
    flex-direction: column;
}
.card.dash-grid3-card h2 { margin: 0 0 0.4rem 0; font-size: 0.85rem; }
.grid-3x3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 0.5rem;
    flex: 1 1 auto;
    min-height: 240px;
    width: 100%;
    position: relative;
}
.g3-arrow {
    position: absolute;
    background: var(--surface);
    font-size: 1.05rem;
    line-height: 1;
    padding: 0.25rem 0.45rem;
    border-radius: 6px;
    pointer-events: none;
    transform: translate(-50%, -50%);
    z-index: 2;
}
.g3a-amber   { color: var(--amber);   }
.g3a-rose    { color: var(--rose);    }
.g3a-emerald { color: var(--emerald); }
.g3a-violet  { color: var(--violet);  }
.g3a-muted   { color: var(--muted);   }
.g3-arrow-solar   { top: 33.33%; left: 50%; }
.g3-arrow-grid    { top: 50%;    left: 33.33%; }
.g3-arrow-battery { top: 50%;    left: 66.66%; }
.g3-arrow-house   { top: 66.66%; left: 50%; }
.grid-3x3 > div { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 0.4rem; }
.g3-cell {
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 10px;
}
.g3-cell.g3-solar    { border-color: var(--amber);   }
.g3-cell.g3-grid     { border-color: var(--rose);    }
.g3-cell.g3-inverter { border-color: var(--slate);   }
.g3-cell.g3-battery  { border-color: var(--emerald); }
.g3-cell.g3-house    { border-color: var(--violet);  }
.g3-cell.g3-geyser   { border-color: #ef4444;        }
.g3-cell .g3-sub     { font-size: 0.62rem; color: var(--muted); text-align: center; margin-top: 0.15rem; line-height: 1.2; }
.g3-label { font-size: 0.7rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; text-align: center; }
.g3-value { font-size: 1.2rem; font-weight: 600; color: var(--text); margin-top: 0.2rem; }
.dash-sankey-card h2 { margin: 0 0 0.4rem 0; font-size: 0.85rem; }
.dash-sankey-host { position: relative; flex: 1 1 auto; min-height: 240px; width: 100%; }
.eflow-svg { width: 100%; height: auto; max-height: 260px; display: block; }
.eflow-node rect { fill: var(--surface-2); stroke: var(--line); stroke-width: 1; }
.eflow-node-label { fill: var(--muted); font-size: 11px; letter-spacing: 0.08em; font-weight: 500; }
.eflow-node-value { fill: var(--text); font-size: 14px; font-weight: 600; }
.eflow-node.node-solar   rect { stroke: var(--amber);   }
.eflow-node.node-grid    rect { stroke: var(--rose);    }
.eflow-node.node-battery rect { stroke: var(--emerald); }
.eflow-node.node-house   rect { stroke: var(--violet);  }
.eflow-node.node-inverter rect { stroke: var(--slate);  }
.eflow-arm-label { fill: var(--text); font-size: 11px; font-weight: 600; }

@media (max-width: 720px) {
    .gauges > .eflow-card { padding: 0.6rem 0.7rem 0.4rem; grid-column: 1 / -1; }
    .eflow-svg { max-height: 320px; }
    .gauges > .dash-grid3-card { grid-column: 1 / -1 !important; width: 100%; }
    .gauges > .dash-amsankey-card { grid-column: 1 / -1 !important; width: 100%; }
    .eflow-node-label { font-size: 10px; }
    .eflow-node-value { font-size: 12px; }
    .eflow-arm-label  { font-size: 10px; }
}

.gauge-tl { grid-column: 1; grid-row: 1; text-align: left; }
.gauge-tr { grid-column: 2; grid-row: 1; text-align: right; }
.gauge-bl { grid-column: 1; grid-row: 3; text-align: left; }
.gauge-br { grid-column: 2; grid-row: 3; text-align: right; }
.gauge-caption {
    grid-column: 1 / -1;
    grid-row: 4;
    text-align: center;
    padding-top: 0.25rem;
    border-top: 1px solid var(--line);
    margin-top: 0.25rem;
    font-size: 0.78rem;
    color: var(--muted);
}
.gauge-caption .v { color: var(--text); font-weight: 600; font-size: 0.95rem; }
.gauge-caption .l { display: block; font-size: 0.6rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }

.tile {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 1.1rem 1.25rem;
    border-top: 3px solid var(--slate);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 110px;
}

.tile-amber   { border-top-color: var(--amber); }
.tile-emerald { border-top-color: var(--emerald); }
.tile-violet  { border-top-color: var(--violet); }
.tile-rose    { border-top-color: var(--rose); }
.tile-slate   { border-top-color: var(--slate); }

.tile-label {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
}
.tile-value {
    font-size: 2rem;
    font-weight: 600;
    margin-top: 0.35rem;
}
.tile-sub {
    font-size: 0.85rem;
    color: var(--muted);
    margin-top: 0.2rem;
}

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 1.1rem 1.25rem;
    margin-bottom: 1.5rem;
}
.card h2 {
    margin: 0 0 0.9rem 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--muted);
    letter-spacing: 0.02em;
    text-transform: uppercase;
}
.card h2 code {
    text-transform: none;
    color: var(--text);
    font-weight: 500;
    margin-left: 0.5rem;
}

table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th { text-align: left; color: var(--muted); font-weight: 500; padding: 0.4rem 0.6rem; border-bottom: 1px solid var(--line); }
td { padding: 0.55rem 0.6rem; border-bottom: 1px solid var(--line); }
tr:last-child td { border-bottom: none; }

.badge {
    display: inline-block;
    font-size: 0.75rem;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    background: var(--surface-2);
}
.badge-online  { background: rgba(16, 185, 129, 0.18); color: #6ee7b7; }
.badge-offline { background: rgba(244, 63, 94, 0.18); color: #fda4af; }
.badge-alert   { background: rgba(245, 158, 11, 0.18); color: #fcd34d; }

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 0.6rem;
}
.kv {
    background: var(--surface-2);
    border-radius: 8px;
    padding: 0.55rem 0.75rem;
    border-left: 3px solid transparent;
}
.k { font-size: 0.75rem; color: var(--muted); }
.v { font-size: 1rem; margin-top: 0.15rem; }
.u { color: var(--muted); font-size: 0.85rem; margin-left: 0.2rem; }

.kv-pv        { border-left-color: #f59e0b; }
.kv-ac        { border-left-color: #06b6d4; }
.kv-grid      { border-left-color: #f43f5e; }
.kv-house     { border-left-color: #8b5cf6; }
.kv-battery   { border-left-color: #10b981; }
.kv-temp      { border-left-color: #f97316; }
.kv-daily     { border-left-color: #14b8a6; }
.kv-lifetime  { border-left-color: #64748b; }
.kv-generator { border-left-color: #475569; }
.kv-static    { border-left-color: #1c2840; }

.kv-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-bottom: 0.8rem;
}
.kv-chip {
    font-size: 0.7rem;
    color: var(--muted);
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    background: var(--surface-2);
    border-left: 3px solid transparent;
}

.error {
    background: rgba(244, 63, 94, 0.1);
    border: 1px solid rgba(244, 63, 94, 0.4);
    color: #fda4af;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    font-family: ui-monospace, Menlo, Consolas, monospace;
    font-size: 0.85rem;
}

.loading { color: var(--muted); }

/* Slim custom reconnect indicator — replaces Blazor's default white modal.
   Hidden by default; Blazor toggles the components-reconnect-* classes. */
#components-reconnect-modal {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0;
    padding: 0.45rem 1rem;
    text-align: center;
    z-index: 9999;
    font-size: 0.85rem;
    color: #fff;
    background: rgba(245, 158, 11, 0.92);
    pointer-events: auto;
}
#components-reconnect-modal a { color: #fff; text-decoration: underline; font-weight: 600; }
#components-reconnect-modal.components-reconnect-show { display: none; }
#components-reconnect-modal.components-reconnect-failed,
#components-reconnect-modal.components-reconnect-rejected {
    display: block;
    background: rgba(244, 63, 94, 0.94);
}

.topnav {
    background: var(--surface);
    border-bottom: 1px solid var(--line);
}
.topnav-inner {
    width: 100%;
    margin: 0 auto;
    padding: 0.8rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 1.5rem;
}
.navlinks {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    flex-wrap: wrap;
}
.nav-toggle {
    display: none;
    background: none;
    border: 0;
    color: var(--text);
    font-size: 1.5rem;
    line-height: 1;
    padding: 0.1rem 0.4rem;
    margin-left: auto;
    cursor: pointer;
    border-radius: 6px;
}
.nav-toggle:hover { background: var(--surface-2); }
.brand {
    font-weight: 600;
    color: var(--amber);
    letter-spacing: 0.02em;
}
.navlink {
    color: var(--muted);
    text-decoration: none;
    font-size: 0.92rem;
    padding: 0.25rem 0;
    border-bottom: 2px solid transparent;
}
.navlink:hover { color: var(--text); }
.navlink.active {
    color: var(--text);
    border-bottom-color: var(--amber);
}

.chart-host {
    position: relative;
    height: 420px;
    width: 100%;
}

.status-banner {
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    padding: 0.5rem 1.5rem;
    display: flex;
    flex-wrap: wrap;
    gap: 1rem 1.5rem;
    align-items: center;
    color: var(--text);
    font-size: 0.85rem;
}
.status-banner.sb-warn { color: #fda4af; background: rgba(244, 63, 94, 0.06); }
.sb-section { display: inline-flex; align-items: baseline; gap: 0.4rem; }
.sb-emoji { font-size: 1.05rem; }
.sb-label { color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; font-size: 0.72rem; }
.sb-val { font-weight: 600; }
.sb-sub { color: var(--muted); font-size: 0.8rem; }
.sb-link { margin-left: auto; color: var(--amber); text-decoration: none; font-size: 0.8rem; }
.sb-link:hover { text-decoration: underline; }
.chart-card h2 { margin-bottom: 0.5rem; }

.muted { color: var(--muted); font-size: 0.82rem; }

.gap-pill {
    background: rgba(139, 92, 246, 0.2);
    color: #c4b5fd;
    padding: 0.15rem 0.6rem;
    border-radius: 999px;
    font-size: 0.8rem;
}

.rule-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 0.7rem 1rem;
}
.rule-input {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}
.rule-input span {
    font-size: 0.78rem;
    color: var(--muted);
}
.rule-input input {
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 0.4rem 0.6rem;
    font-size: 0.95rem;
}

pre.raw {
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 0.8rem 1rem;
    overflow: auto;
    max-height: 480px;
    color: var(--muted);
    font-size: 0.82rem;
    margin: 0;
}

@media (max-width: 720px) {
    .dash { padding: 1rem 0.85rem 3rem; }
    .dash-header { gap: 0.5rem; margin-bottom: 1rem; }
    .dash-header h1 { font-size: 1.25rem; }

    .meta { font-size: 0.8rem; gap: 0.35rem 0.55rem; }
    .meta-right { margin-left: 0; width: 100%; justify-content: flex-start; }

    .refresh, .tuya-toggle { padding: 0.3rem 0.55rem; font-size: 0.8rem; }

    .topnav-inner {
        padding: 0.55rem 0.85rem;
        gap: 0.6rem;
        flex-wrap: wrap;
        align-items: center;
    }
    .nav-toggle { display: inline-block; }
    .navlinks {
        display: none;
        width: 100%;
        flex-direction: column;
        align-items: stretch;
        gap: 0;
        margin-top: 0.4rem;
        border-top: 1px solid var(--line);
        padding-top: 0.3rem;
    }
    .topnav-inner.nav-open .navlinks { display: flex; }
    .navlinks .navlink {
        padding: 0.6rem 0.4rem;
        border-bottom: 1px solid var(--line);
        border-radius: 0;
        font-size: 0.95rem;
    }
    .navlinks .navlink:last-child { border-bottom: none; }
    .navlinks .navlink.active { border-bottom-color: var(--amber); }

    .status-banner {
        padding: 0.45rem 0.7rem;
        gap: 0.4rem 0.7rem;
        font-size: 0.72rem;
        flex-wrap: nowrap;
        white-space: nowrap;
        overflow-x: auto;
    }
    .status-banner .sb-section { gap: 0.3rem; min-width: 0; }
    .status-banner .sb-optional { display: none; }
    .status-banner .sb-today-label,
    .status-banner .sb-tomorrow-label { font-size: 0.62rem; text-transform: uppercase; letter-spacing: 0.04em; }
    .sb-link { margin-left: 0; }

    .tiles {
        grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
        gap: 0.55rem;
        margin-bottom: 1rem;
    }
    .gauges {
        grid-template-columns: 1fr 1fr;
        gap: 0.6rem;
        margin-bottom: 1rem;
    }
    /* Override desktop's row-2 placement rules so all gauges flow uniformly half-width. */
    .gauges > :nth-child(n) { grid-column: auto; grid-area: auto; }
    .gauge { padding: 0.6rem 0.7rem 0.4rem; }
    .gauge-svg { max-height: 150px; }
    .gauge-svg .gauge-value { font-size: 26px; }
    .gauge-svg .gauge-unit  { font-size: 13px; }
    .gauge-corner { font-size: 0.7rem; }
    .gauge-corner .v { font-size: 0.82rem; }
    .gauge-corner .l { font-size: 0.6rem; }
    .tile { padding: 0.75rem 0.85rem; }
    .tile-value { font-size: 1.35rem; }
    .tile-label { font-size: 0.68rem; }
    .tile-sub { font-size: 0.72rem; }

    .card {
        padding: 0.85rem 0.9rem;
        margin-bottom: 1rem;
        border-radius: 10px;
    }
    .card h2 { font-size: 0.85rem; margin-bottom: 0.65rem; }

    .chart-host { height: 340px; }

    .grid, .rule-grid {
        grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
        gap: 0.5rem;
    }

    table { font-size: 0.82rem; }
    th, td { padding: 0.35rem 0.4rem; }

    /* Wide tables (devices, peak demand) scroll horizontally rather than overflowing the card. */
    .card { overflow-x: auto; }
    table { white-space: nowrap; }

    /* Devices table: hide the Type column and the date portion of last-seen so it fits without scrolling. */
    .devices-table .col-type { display: none; }
    .devices-table .ls-date { display: none; }
    .devices-table { white-space: normal; }
    .devices-table code { font-size: 0.78rem; }

    /* Efficiency analysis (PV strings): drop the two least-essential columns and allow headers to wrap. */
    .efficiency-table .col-secondary { display: none; }
    .efficiency-table { white-space: normal; font-size: 0.78rem; }
    .efficiency-table th, .efficiency-table td { padding: 0.3rem 0.3rem; }

    /* Tuya devices: drop Product column, allow Name/State to wrap, hide low-value sub-line (IP/category/id). */
    .tuya-table .tuya-col-secondary { display: none; }
    .tuya-table { white-space: normal; font-size: 0.82rem; }
    .tuya-table th, .tuya-table td { padding: 0.4rem 0.35rem; vertical-align: top; }
    .tuya-table .tuya-meta { display: none; }
    .tuya-toggle { padding: 0.3rem 0.55rem; font-size: 0.78rem; }
}
