/* Shared application/admin palette. Public websites keep their own themes. */
html[data-backend-theme][data-theme] a.button{display:inline-flex;align-items:center;justify-content:center;min-height:44px;padding:10px 16px;border:1px solid transparent;border-radius:8px;text-decoration:none}
html[data-backend-theme]{--ui-bg:#f3f6f5;--ui-panel:#ffffff;--ui-raised:#e9f0ec;--ui-text:#203b34;--ui-muted:#4e665b;--ui-label:#365647;--ui-link:#176447;--ui-border:#bdcec4;--ui-input:#ffffff;--ui-button:#216349;--ui-button-text:#ffffff;--ui-warning:#744707;--ui-warning-bg:#fff3d6;--ui-danger:#9b2925;--ui-danger-bg:#ffefed;--ui-good:#205c3e;--ui-good-bg:#e3f2e8;--ui-focus:#176447;--ui-placeholder:#617568}
html[data-backend-theme][data-theme=dark]{--ui-bg:#0b1110;--ui-panel:#14201b;--ui-raised:#24382f;--ui-text:#edf4ee;--ui-muted:#bdcec4;--ui-label:#d5e5dc;--ui-link:#9ce9ca;--ui-border:#526b5e;--ui-input:#0d1713;--ui-button:#96e7c5;--ui-button-text:#10251c;--ui-warning:#ffda8a;--ui-warning-bg:#382b16;--ui-danger:#ffc0b9;--ui-danger-bg:#38201f;--ui-good:#a4edbe;--ui-good-bg:#183b28;--ui-focus:#9ce9ca;--ui-placeholder:#a9bfb2}
html[data-backend-theme][data-theme]{background:var(--ui-bg);color:var(--ui-text);--muted:var(--ui-muted);--border:var(--ui-border);--green:var(--ui-link);--warn:var(--ui-warning);--critical:var(--ui-danger)}
html[data-backend-theme][data-theme] :is(.app-layout,.customer-layout,.admin-layout,.helium-guide){color:var(--ui-text)}
html[data-backend-theme][data-theme] :is(section,article,.app-metric,.app-sensor,.app-account,.app-account-links,.device,.mobile-menu){background:var(--ui-panel);color:var(--ui-text);border-color:var(--ui-border)}
html[data-backend-theme][data-theme] :is(label,legend,.eyebrow,.facts dt,th){color:var(--ui-label)}
html[data-backend-theme][data-theme] :is(.muted,.sidebar-foot,.sidebar-foot p,.bounds,.stamp,.metric-foot,.metric-unit,.metric-time,.app-empty,.app-account p,.app-sensor .model,.app-sensor .last-seen,.app-sensor dt,.app-metric>small,.app-metric .sensor-label,.guide-source,footer){color:var(--ui-muted)}
html[data-backend-theme][data-theme] :is(a,.tabs a,.app-account-links a,.app-auth-link){color:var(--ui-link)}
html[data-backend-theme][data-theme] header a{color:#f6faf6}
html[data-backend-theme][data-theme] :is(input,textarea,select){color:var(--ui-text);background:var(--ui-input);border-color:var(--ui-border)}
html[data-backend-theme][data-theme] :is(input,textarea)::placeholder{color:var(--ui-placeholder);opacity:1}
html[data-backend-theme][data-theme] :is(input[readonly],textarea[readonly],pre,th,.rule,.chart-readout,.stat,.insight,.guide-notice,.guide-flow,.helium-guide nav a,[data-scanner]){background:var(--ui-raised);color:var(--ui-text);border-color:var(--ui-border)}
html[data-backend-theme][data-theme] :is(td,th,.spec-row,.facts dt,.facts dd,.stamp,.dashboard-toggle,.app-tabs,.app-account-links a){border-color:var(--ui-border)}
html[data-backend-theme][data-theme] :is(.stat-value,.summary:last-child strong){color:var(--ui-text)}
html[data-backend-theme][data-theme] :is(.summary,.summary:last-child,.sensor-values span,.mobile-menu nav a,.device.active,aside a,aside a.active){background:var(--ui-raised);color:var(--ui-text)}
html[data-backend-theme][data-theme] :is(.tabs a.active,aside a.active){color:var(--ui-link);border-color:var(--ui-link)}
html[data-backend-theme][data-theme] :is(button,a.app-button,a.button){color:var(--ui-button-text);background:var(--ui-button);border-color:var(--ui-button)}
html[data-backend-theme][data-theme] :is(button.secondary,a.app-button.secondary,a.button.secondary,.app-language button,.card-order-controls button){background:var(--ui-raised);color:var(--ui-text);border-color:var(--ui-border)}
html[data-backend-theme][data-theme] .app-language button[aria-pressed=true]{background:var(--ui-button);color:var(--ui-button-text);border-color:var(--ui-button)}
html[data-backend-theme][data-theme] :is(.drag-handle,.metric-remove){background:transparent;color:var(--ui-muted);border-color:transparent}
html[data-backend-theme][data-theme] .metric-remove:hover{background:var(--ui-raised)}
html[data-backend-theme][data-theme] .app-signout{background:transparent;color:var(--ui-danger);border-color:var(--ui-border)}
html[data-backend-theme][data-theme] :is(.badge.good){color:var(--ui-good);background:var(--ui-good-bg)}
html[data-backend-theme][data-theme] .badge.neutral{color:var(--ui-muted);background:var(--ui-raised)}
html[data-backend-theme][data-theme] :is(.badge.warning,.notice.warning){color:var(--ui-warning);background:var(--ui-warning-bg);border-color:var(--ui-warning)}
html[data-backend-theme][data-theme] :is(.badge.critical,.notice.critical,.app-error){color:var(--ui-danger);background:var(--ui-danger-bg);border-color:var(--ui-danger)}
html[data-backend-theme][data-theme] .app-metric.critical{background:var(--ui-danger-bg);color:var(--ui-text);border-color:var(--ui-danger)}
html[data-backend-theme][data-theme] :is(.device-warning,.distance-notice,.sensor-state.warning,.metric-state.warning){color:var(--ui-warning)}
html[data-backend-theme][data-theme] :is(.sensor-state.critical,.metric-state.critical){color:var(--ui-danger);background:transparent}
html[data-backend-theme][data-theme] :is(.notice,.guide-notice) p{color:inherit}
html[data-backend-theme][data-theme] :is(.notice a,.guide-notice a){color:inherit;text-decoration:underline}
html[data-backend-theme][data-theme] .metric-icon{background:var(--ui-raised);color:var(--ui-label)}
html[data-backend-theme][data-theme] .gaugeValue{fill:var(--ui-text)}
html[data-backend-theme][data-theme] .unit{fill:var(--ui-muted)}
html[data-backend-theme][data-theme] .track{stroke:var(--ui-raised)}
html[data-backend-theme][data-theme] .metric-history polyline{stroke:var(--ui-link)}
html[data-backend-theme][data-theme] :is(button,a,input,select,textarea,summary):focus-visible{outline:3px solid var(--ui-focus);outline-offset:3px}
html[data-backend-theme][data-theme] .dashboard-toggle input{background:var(--ui-border)}
html[data-backend-theme][data-theme] .dashboard-toggle input:checked{background:#28876a}
html[data-backend-theme][data-theme] .theme-control select{color:var(--ui-text);background:var(--ui-panel);border-color:var(--ui-border)}
html[data-backend-theme][data-theme] .theme-control option{color:var(--ui-text);background:var(--ui-panel)}
html[data-backend-theme][data-theme] .fleet-section{background:transparent;border:0}
/* Leaflet uses intentionally light map surfaces, independent of page appearance. */
html[data-backend-theme][data-theme] .leaflet-control a{background:#fff;color:#244a39}
html[data-backend-theme][data-theme] .leaflet-popup-content a{color:#176447}
html[data-backend-theme][data-theme] .sensor-popup.critical .leaflet-popup-content a{color:#fff}
.backend-heading{display:flex;align-items:center;justify-content:space-between;gap:16px;flex-wrap:wrap}.backend-heading .eyebrow{margin:0}.backend-heading .theme-control{font-size:13px}
@media(max-width:600px){.backend-heading{align-items:flex-start}.backend-heading .theme-control{flex-wrap:wrap}.backend-heading .theme-control select{max-width:100%}}

html[data-backend-theme]{--ui-temperature:#a2462d;--ui-humidity:#275f8b}html[data-backend-theme][data-theme=dark]{--ui-temperature:#ffad8f;--ui-humidity:#8ecaf3}
html[data-backend-theme][data-theme] .legend label:first-child{color:var(--ui-temperature)}html[data-backend-theme][data-theme] .legend label:last-child{color:var(--ui-humidity)}

/* Explicit button selectors beat generic button and dark-theme rules. */
html[data-backend-theme][data-theme] .app-metric button.metric-remove{display:grid;place-items:center;width:44px;height:44px;min-height:44px;padding:0;background:var(--ui-danger-bg);color:var(--ui-danger);border:1px solid var(--ui-danger);border-radius:8px;font-size:30px;font-weight:600;line-height:1}
html[data-backend-theme][data-theme] .app-metric button.metric-remove:hover{background:var(--ui-danger);color:var(--ui-danger-bg)}
html[data-backend-theme][data-theme] .app-metric button.drag-handle{background:transparent;color:var(--ui-muted);border-color:transparent}

/* Login errors must remain prominent in both themes; empty alerts stay hidden. */
html[data-backend-theme] .login [role="alert"]:empty{display:none}
html[data-backend-theme] .login [role="alert"]:not(:empty){display:block;margin:18px 0;padding:14px 16px;border:2px solid #b42318;border-radius:10px;background:#fff0ee;color:#8f1d16;font-weight:600;line-height:1.5;overflow-wrap:anywhere}
html[data-backend-theme][data-theme="dark"] .login [role="alert"]:not(:empty){background:#481c20;border-color:#ff8989;color:#ffe2e2}

/* The demo notice is a banner, not the full-height application sidebar. */
html[data-backend-theme] aside.content[aria-label="Demo"]{min-height:0;border:0;padding:10px 0;margin:0}
html[data-backend-theme] aside.content[aria-label="Demo"] + .login{margin:20px auto}
