
:root {
  --page: #131820; --surface: #1b222c; --raised: #232c38; --field: #171d26;
  --line: #303b48; --input-line: #455160; --ink: #eaf0f6; --muted: #a4afbe;
  --accent: #ff9351; --action: #f5873e; --action-hover: #ffa76b; --on-action: #211307;
  --primary-soft: #33271f; --positive: #8ed3aa; --positive-bg: #223b31;
  --warning: #ffda84; --warning-bg: #473618;
  --negative: #ffc0bc; --negative-bg: #442829; --focus: #92beff;
  --avatar-bg: #d9e3ed; --avatar-ink: #263648;
  --control-h: 2.45rem;
  --bulma-family-primary: system-ui, -apple-system, "Segoe UI", sans-serif;
  --bulma-body-size: 15px;
  --bulma-radius: .42rem;
}

:root[data-theme="light"] {
  --page: #f5f6f8; --surface: #fff; --raised: #eef1f5; --field: #fff;
  --line: #dce1e8; --input-line: #c9d1da; --ink: #1b2431; --muted: #556171;
  --accent: #ad4215; --action: #be4b17; --action-hover: #a54013; --on-action: #fff;
  --primary-soft: #fff0e6; --positive: #206344; --positive-bg: #e7f6ed;
  --warning: #714800; --warning-bg: #ffedbf;
  --negative: #a3312c; --negative-bg: #fff0ef; --focus: #3168ad;
  --avatar-bg: #29394c; --avatar-ink: #fff;
}

html { min-height: 100%; background: var(--page); }
body { color: var(--ink); min-width: 0; }
a { color: inherit; }
a:hover { color: var(--ink); }
h1, h2, p, dl, dd { margin: 0; }
h1 { font-size: clamp(1.35rem, 3vw, 1.7rem); font-weight: 720; line-height: 1.18; letter-spacing: -.025em; }
h2 { font-size: 1.02rem; font-weight: 680; }
.muted { color: var(--muted); }
.meta { font-size: .79rem; }
.icon { flex-shrink: 0; width: 1.1rem; height: 1.1rem; vertical-align: middle; }
.icon svg { display: block; width: 100%; height: 100%; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }

.button, .input, .select select {
  min-height: var(--control-h); height: var(--control-h); font-size: .875rem;
  border-radius: .45rem; border-color: var(--input-line); box-shadow: none;
  background-color: var(--field); color: var(--ink);
}
.button { font-weight: 625; }
.button.is-small { --control-h: 1.95rem; font-size: .77rem; }
.button:hover { background-color: var(--raised); border-color: var(--input-line); color: var(--ink); }
.button.is-primary { background-color: var(--action); color: var(--on-action); border-color: transparent; }
.button.is-primary:hover { background-color: var(--action-hover); color: var(--on-action); border-color: transparent; }
.button.is-danger { background-color: var(--negative-bg); color: var(--negative); border-color: transparent; }
.button.is-danger:hover { color: var(--negative); border-color: var(--negative); }
.button:focus-visible, .input:focus-visible, .select select:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.button[disabled], .menu-command[disabled] { opacity: .48; cursor: not-allowed; }
.select:not(.is-multiple) { height: var(--control-h); }
.select:not(.is-multiple):not(.is-loading)::after { border-color: var(--muted); }
select, input, textarea { min-width: 0; }
.card, .sidebar {
  min-width: 0; color: var(--ink); border: 1px solid var(--line); background: var(--surface);
  border-radius: .72rem; box-shadow: 0 1px 2px rgb(9 15 24 / 5%);
}
body .card:not(:last-child) { margin-bottom: 0; }

.topbar { position: sticky; top: 0; z-index: 4; background: var(--surface); border-bottom: 1px solid var(--line); }
.top-inner, .page { max-width: 1440px; margin-inline: auto; padding-inline: clamp(1rem, 3vw, 2.25rem); }
.top-inner { min-height: 3.85rem; display: flex; align-items: center; justify-content: space-between; gap: .75rem; }
.top-inner.login-top { justify-content: flex-end; }
.brand { display: inline-flex; align-items: center; gap: .47rem; color: var(--ink);
  font: 800 1.55rem/1 Arial, Helvetica, sans-serif; letter-spacing: -.045em; }
.brand .icon { width: 1.36rem; height: 1.36rem; color: #f97316; }
.brand strong { color: #f97316; }
.toolbar, .preferences { display: flex; align-items: center; gap: .55rem; }
.toolbar-actions { display: flex; align-items: center; gap: .14rem; }
.toolbar-actions::before { content: ""; height: 1.18rem; border-inline-start: 1px solid var(--line); margin-inline-end: .38rem; }
.icon-button { position: relative; width: var(--control-h); padding: 0; }
.icon-button .icon:first-child:last-child { margin: 0; }
.language { font-size: .76rem; letter-spacing: .03em; }
.theme-toggle { position: relative; display: inline-grid; grid-template-columns: repeat(2, 1.55rem); justify-items: center; align-items: center;
  height: 2.02rem; padding: 0 .23rem; border: 1px solid var(--line); border-radius: 999px;
  background: var(--raised); color: var(--muted); cursor: pointer; }
.theme-toggle .icon { z-index: 1; width: .9rem; height: .9rem; }
.theme-toggle .theme-thumb { position: absolute; width: 1.42rem; height: 1.42rem; left: .28rem;
  border-radius: 50%; background: var(--surface); box-shadow: 0 1px 2px rgb(0 0 0 / 16%); transition: transform 160ms ease; }
.theme-toggle[aria-checked="true"] .theme-thumb { transform: translateX(1.55rem); }
.theme-toggle[aria-checked="false"] .icon:nth-child(2), .theme-toggle[aria-checked="true"] .icon:nth-child(3) { color: var(--accent); }

.panel-menu { position: relative; }
.panel-menu > summary { cursor: pointer; list-style: none; }
.panel-menu > summary::-webkit-details-marker { display: none; }
.panel-menu[open] > .dropdown-menu { display: block; }
.panel-menu[open] > summary { background: var(--raised); }
.panel-menu .dropdown-menu { min-width: 12.5rem; }
.panel-menu .dropdown-content { background: var(--surface); color: var(--ink); border: 1px solid var(--line);
  border-radius: .6rem; padding: .3rem; box-shadow: 0 .7rem 2rem rgb(0 0 0 / 16%); }
.alerts-menu .dropdown-menu { width: min(22rem, calc(100vw - 5.2rem)); }
.toolbar-trigger { display: flex; align-items: center; justify-content: center; min-height: 2.75rem; min-width: 2.75rem;
  border-radius: .45rem; color: var(--ink); }
.toolbar-trigger:hover { background-color: var(--raised); }
.alert-trigger { position: relative; }
.alert-trigger .icon { width: 1.2rem; height: 1.2rem; }
.account-trigger { gap: .42rem; padding-inline: .32rem; font-size: .85rem; font-weight: 615; }
.account-trigger > .icon:last-child { width: .73rem; height: .73rem; color: var(--muted); }
.avatar { display: grid; place-items: center; width: 1.96rem; height: 1.96rem; border-radius: 50%;
  color: var(--avatar-ink); background: var(--avatar-bg); }
.avatar .icon { width: 1.08rem; height: 1.08rem; }
.username { max-width: 7rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-identity { display: grid; gap: .08rem; padding: .38rem .55rem .52rem;
  border-bottom: 1px solid var(--line); margin-bottom: .23rem; overflow-wrap: anywhere; }
.account-identity strong { font-size: .88rem; }
.alert-dot { position: absolute; top: .59rem; right: .58rem; width: .38rem; height: .38rem; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 0 2px var(--surface); }
.menu-heading { padding: .42rem .55rem; font-size: .86rem; }
.panel-menu .menu-command { display: flex; align-items: center; gap: .45rem; text-align: left; width: 100%;
  box-sizing: border-box; padding: .53rem .58rem;
  border: 0; border-radius: .3rem; background: transparent; color: var(--ink); cursor: pointer; }
.panel-menu .menu-command:hover { color: var(--ink); background: var(--raised); }
.alerts { list-style: none; max-height: min(50dvh, 23rem); overflow: auto; }
.alerts li { display: grid; gap: .12rem; padding: .46rem .58rem; border-top: 1px solid var(--line); overflow-wrap: anywhere; }
.alerts strong { font-size: .86rem; }
.alerts summary { font-size: .76rem; color: var(--muted); cursor: pointer; }
.alert-empty { padding: .4rem .55rem .6rem; font-size: .88rem; }

.page { padding-block: clamp(1rem, 3vw, 1.85rem) 2rem; }
.dashboard { display: grid; grid-template-columns: minmax(14rem, 17rem) minmax(0, 1fr); align-items: start; gap: 1.4rem; }
.sidebar { padding: .85rem; position: sticky; top: 5rem; }
.sidebar h2 { margin: .1rem .25rem .65rem; }
.device-filter { margin-bottom: .45rem; }
.device-filter-empty { padding: .5rem .25rem; }
.device-list, .detail { display: grid; min-width: 0; gap: .95rem; }
.device-list { gap: .28rem; }
.device-row { display: grid; grid-template-columns: auto minmax(0,1fr) auto; gap: .5rem; align-items: center;
  min-height: 3.15rem; padding: .52rem; border: 1px solid transparent; border-radius: .47rem; }
.device-row[hidden] { display: none; }
.device-row:hover { background: var(--raised); }
.device-row.selected { border-color: var(--line); background: var(--primary-soft); }
.device-text { min-width: 0; display: grid; }
.device-text strong, .device-text .meta { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.device-text strong { font-size: .88rem; }
.device-text .meta { font-size: .74rem; }
.device-dot { width: .43rem; height: .43rem; border-radius: 50%; background: var(--muted); flex: none; }
.device-dot.online { background: var(--positive); }
.device-dot.offline { background: var(--muted); opacity: .6; }
.broker-line { display: flex; align-items: center; gap: .4rem; border-top: 1px solid var(--line); margin-top: .65rem; padding: .52rem .25rem .1rem; }
.radiator { width: 1rem; height: .85rem; border: 1.4px solid currentColor; border-radius: .18rem; color: var(--accent); position: relative; }
.radiator::before { content: ""; position: absolute; inset: .15rem .17rem;
  background: repeating-linear-gradient(90deg, transparent 0 17%, currentColor 17% 27%, transparent 27% 33.333%); }
.empty { padding: 1.25rem; }
.device-heading { display: flex; align-items: center; flex-wrap: wrap; gap: .55rem; min-width: 0; }
.device-header { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: start; gap: .65rem; }
.device-header p { margin-top: .23rem; overflow-wrap: anywhere; }
.device-tools { display: flex; gap: .4rem; }
.badge { display: inline-flex; gap: .35rem; align-items: center; justify-self: start; white-space: nowrap; border-radius: 999px;
  padding: .18rem .49rem; font-size: .73rem; font-weight: 660; }
.badge i { width: .36rem; height: .36rem; background: currentColor; border-radius: 50%; }
.positive { color: var(--positive); background: var(--positive-bg); }
.neutral { color: var(--muted); background: var(--raised); }
.boiler-control { display: inline-flex; min-width: 0; }
.boiler-toggle { display: inline-flex; max-width: 100%; padding: 0; background: none; border: 0; border-radius: .42rem; cursor: pointer; }
.boiler-badge { min-height: 1.8rem; border: 1px solid var(--line); border-radius: .42rem; white-space: normal; text-align: start; }
.boiler-badge.warning { background: var(--warning-bg); color: var(--warning); }
.boiler-badge .icon { width: .87rem; height: .87rem; }
.hot { color: var(--accent); }
.overview-grid, .sensor-workspace { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .95rem; }
.sensor-workspace { align-items: start; }
.temperature-card, .settings, .related, .discovery { padding: clamp(.85rem, 2vw, 1.22rem); }
.temperature-card { display: grid; align-content: space-between; gap: .78rem; }
.temperature-card h2 { color: var(--muted); font-weight: 610; }
.stats, .reading-values { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: .45rem; }
.stats { row-gap: .63rem; }
.stats dt, .reading-values dt { color: var(--muted); font-size: .75rem; }
.stats dd, .reading-values dd { font-weight: 650; overflow-wrap: anywhere; }
.temperature-reading { grid-column: 1 / -1; padding-bottom: .63rem; border-bottom: 1px solid var(--line); }
.stats .temperature-value { font-size: clamp(3rem, 5.5vw, 4.35rem); line-height: 1.04; letter-spacing: -.064em;
  font-variant-numeric: tabular-nums; font-weight: 710; white-space: nowrap; }
.temperature-value span { color: var(--accent); font-size: .45em; letter-spacing: -.035em; }
.settings h2 { margin-bottom: .65rem; }
.form-stack, .login-form { display: grid; gap: .6rem; }
.setting-fields, .discovery-fields { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, .85fr); gap: .62rem; align-items: end; }
label { display: grid; gap: .25rem; min-width: 0; font-size: .83rem; color: var(--muted); font-weight: 570; }
label.inline { grid-template-columns: 1fr minmax(5rem, 1fr); align-items: center; }
.select select { width: 100%; }
.input-with-unit { display: flex; height: var(--control-h); gap: .45rem; align-items: center; }
.input-with-unit span { white-space: nowrap; }
.override > summary, .scanner-section > summary { color: var(--muted); cursor: pointer; font-size: .84rem; }
.override > div { padding-top: .44rem; }
.notification { font-size: .87rem; padding: .58rem .75rem; margin-bottom: 0 !important; }
#reboot-feedback:empty { display: none; }

.section-title { display: flex; align-items: center; gap: .55rem; }
.section-title .icon { color: var(--accent); }
.related, .discovery, .discovery [data-discovery-content] { display: grid; gap: .72rem; }
#sensors, #configured-sensors, #device-config { scroll-margin-top: 5rem; }
.readings { list-style: none; }
.reading { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: .45rem .7rem; align-items: start;
  border-top: 1px solid var(--line); padding: .56rem 0; }
.reading:first-child { border-top: 0; padding-top: .15rem; }
.reading:last-child { padding-bottom: 0; }
.reading-name { min-width: 0; display: grid; gap: .08rem; overflow-wrap: anywhere; }
.reading-values { grid-column: 1 / -1; grid-row: 2; grid-template-columns: repeat(4,minmax(0,1fr));
  font-size: .82rem; font-variant-numeric: tabular-nums; }
.reading-actions { display: flex; gap: .38rem; flex-wrap: wrap; align-items: center; justify-content: end; grid-column: 2; grid-row: 1; }
.control-sensor { max-width: 10rem; text-align: right; font-size: .78rem; }
.button.is-danger.remove-sensor { background-color: var(--field); border-color: var(--line); color: var(--muted); }
.button.is-danger.remove-sensor:hover { background-color: var(--negative-bg); border-color: var(--negative); color: var(--negative); }
.scanner-section { border-top: 1px solid var(--line); padding-top: .6rem; }
.scanner-section ul { padding-top: .45rem; }
.reading > .badge { grid-row: 1; grid-column: 2; }
.action-row { display: flex; flex-wrap: wrap; gap: .55rem; align-items: center; }
.discovery [hidden] { display: none; }
.discovery-state { display: grid; gap: .38rem; padding: .5rem .62rem; border: 1px solid var(--line); border-radius: .5rem; }
.discovery-state-line { display: flex; flex-wrap: wrap; align-items: center; gap: .38rem .63rem; }
.discovery-progress { display: grid; grid-template-columns: minmax(0,1fr) max-content; align-items: center; gap: .56rem;
  font-variant-numeric: tabular-nums; }
.discovery .progress:not(:last-child) { height: .45rem; margin: 0; --bulma-progress-value-background-color: var(--action);
  --bulma-progress-bar-background-color: var(--raised); }
.table-scroll { overflow-x: auto; }
.discovery .table { margin: 0; font-size: .83rem; --bulma-table-background-color: var(--surface); }
.discovery table th, .discovery table td { padding: .44rem .3rem; vertical-align: middle; }
.discovery table thead th { font-size: .73rem; color: var(--muted); }
.discovery table td { white-space: nowrap; }
.discovery table tbody th { overflow-wrap: anywhere; }
.sensor-room { display: block; font-size: .76rem; font-weight: normal; }

.disclosures { display: grid; gap: .37rem; }
.disclosures > details { border: 1px solid var(--line); border-radius: .52rem; background: var(--surface); }
.disclosures > details:target { border-color: var(--accent); }
.disclosures summary { font-weight: 630; font-size: .85rem; padding: .54rem .75rem; cursor: pointer; }
.disclosures > details > div { padding: .12rem .75rem .65rem; }
.state-rows > div { display: flex; justify-content: space-between; gap: .6rem; border-top: 1px solid var(--line); padding-block: .3rem; }
.state-rows dd { text-align: right; overflow-wrap: anywhere; }
.yes { color: var(--positive); }
pre, textarea { font-family: ui-monospace, Consolas, monospace; }
pre { overflow: auto; max-height: 18rem; background: var(--raised); border-radius: .4rem; padding: .5rem; font-size: .76rem; }

.login-layout { display: grid; place-items: start center; padding: clamp(2.6rem, 12vh, 7rem) 1rem 2rem; }
.login-stack { width: min(100%, 24rem); }
.login-brand { display: grid; justify-items: center; margin-bottom: 1.65rem; }
.login-brand .brand { display: grid; justify-items: center; gap: .6rem; font-size: 3.4rem; }
.login-brand .icon { width: 2.9rem; height: 2.9rem; }
.login-card { width: min(100%, 24rem); padding: 1.42rem; }
.login-card h1 { font-size: 1.29rem; }
.login-card p { margin: .24rem 0 .95rem; font-size: .89rem; }
.login-card .notification { margin-bottom: .7rem !important; }
.login-form { gap: .78rem; }
.login-form .button { margin-top: .18rem; }
dialog { width: min(28rem, calc(100vw - 2rem)); margin: auto; padding: 1.2rem; border: 1px solid var(--line);
  border-radius: .72rem; background: var(--surface); color: var(--ink); }
dialog p { color: var(--muted); margin: .55rem 0 1rem; }
dialog .action-row { justify-content: flex-end; }
dialog::backdrop { background: rgb(0 0 0 / 57%); }
#output-dialog { width: min(23rem, calc(100vw - 2rem)); }
#output-dialog [hidden] { display: none; }
.output-options { display: grid; gap: .38rem; border: 0; margin: .7rem 0 .85rem; padding: 0; }
.output-choice { display: flex; align-items: center; gap: .55rem; min-height: 2.75rem; padding: .4rem .65rem;
  border: 1px solid var(--line); border-radius: .45rem; background: var(--field); cursor: pointer; }
.output-choice:has(input:checked) { border-color: var(--focus); }
.output-choice input { accent-color: var(--action); }

@media (pointer: coarse) {
  .boiler-toggle .boiler-badge { min-height: 2.75rem; }
}

@media (max-width: 1180px) {
  .dashboard { grid-template-columns: minmax(13rem, 15rem) minmax(0, 1fr); gap: 1rem; }
  .overview-grid, .sensor-workspace { grid-template-columns: minmax(0, 1fr); }
}
@media (min-width: 771px) {
  .device-text .meta { white-space: normal; overflow-wrap: anywhere; }
}
@media (max-width: 770px) {
  .dashboard { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: static; }
  .broker-line { margin-top: .4rem; }
}
@media (max-width: 550px) {
  .top-inner { gap: .5rem; padding-inline: .75rem; }
  .toolbar, .preferences { gap: .33rem; }
  .top-inner .brand { font-size: 1.25rem; gap: .25rem; }
  .top-inner .brand .icon { width: 1.08rem; height: 1.08rem; }
  .toolbar-actions::before { margin-inline-end: .18rem; }
  .account-trigger { padding-inline: .2rem; }
  .account-trigger .username { display: none; }
  .alerts-menu > .dropdown-menu { position: fixed; top: 3.65rem; right: .75rem; width: min(22rem, calc(100vw - 1.5rem)); }
  .page { padding-inline: .73rem; }
  .stats { grid-template-columns: minmax(0, 1.15fr) minmax(0, .85fr); }
  .temperature-reading { grid-column: 1; padding-bottom: 0; border-bottom: 0; }
  .stats .temperature-value { font-size: clamp(2.5rem, 12vw, 3rem); }
  .temperature-target { align-self: center; }
  .temperature-target ~ div { border-top: 1px solid var(--line); padding-top: .52rem; }
  .setting-fields, .discovery-fields { grid-template-columns: minmax(0,1fr); }
  .reading-actions { max-width: 9.5rem; }
  .discovery table, .discovery tbody { display: block; }
  .discovery thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .discovery tbody tr { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: .35rem .5rem;
    border-bottom: 1px solid var(--line); padding: .47rem 0; }
  .discovery tbody th { grid-row: 1; grid-column: 1 / 3; min-width: 0; }
  .discovery tbody th, .discovery tbody td { border: 0; padding: 0; }
  .discovery tbody td { white-space: normal; overflow-wrap: anywhere; }
  .discovery tbody td:last-child { grid-row: 1; grid-column: 3; justify-self: end; align-self: start; }
  .discovery td[data-reading-label]::before { content: attr(data-reading-label); display: block; color: var(--muted); font-size: .74rem; }
}
@media (prefers-reduced-motion: reduce) { .theme-toggle .theme-thumb { transition: none; } }
