:root {
  color-scheme: light;
  --bg: #f4f5f2;
  --surface: #ffffff;
  --surface-soft: #f8f8f5;
  --text: #20231f;
  --muted: #6d746a;
  --line: #d9ddd4;
  --ok: #2f7d4f;
  --warn: #b57222;
  --bad: #b94b4b;
  --electricity: #d8a900;
  --heat: #bf3f4a;
  --water: #2f78a8;
  --hotwater: #c65b40;
  --temperature: #3f7f65;
}

* {
  box-sizing: border-box;
}

/* class display rules (e.g. .state-pill { display: inline-flex }) must not override HTML hidden */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-width: 320px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar,
.app-header {
  display: block;
  padding: 24px 28px 12px;
  background: var(--surface);
}

.app-header-main {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  min-width: 0;
}

.app-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px 24px;
  min-width: 0;
}

.app-header-row h1 {
  min-width: 0;
}

.app-tabs {
  display: flex;
  align-items: stretch;
  gap: 4px;
  padding: 0 28px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  overflow-x: auto;
}

.app-tab {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 14px;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 720;
  text-decoration: none;
  white-space: nowrap;
}

.app-tab:hover {
  color: var(--text);
}

.app-tab.active {
  border-bottom-color: #263126;
  color: var(--text);
}

.app-tab-soon {
  opacity: 0.55;
  cursor: default;
}

.app-tab-soon:hover {
  color: var(--muted);
}

.auth-chrome {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.auth-logout-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  min-height: 30px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
}

.auth-logout-button:hover {
  color: var(--text);
  border-color: color-mix(in srgb, var(--text) 25%, var(--line));
}

.auth-logout-button svg {
  width: 16px;
  height: 16px;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.primary-button {
  min-height: 38px;
  padding: 0 14px;
  border: 0;
  border-radius: 8px;
  background: #263126;
  color: #fff;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.primary-button:hover {
  background: #1b231b;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 26px;
  font-weight: 760;
  line-height: 1.1;
}

h2 {
  font-size: 18px;
  font-weight: 720;
}

button {
  min-height: 38px;
  border: 1px solid #263126;
  border-radius: 6px;
  padding: 0 14px;
  background: #263126;
  color: #fff;
  font: inherit;
  font-weight: 680;
  cursor: pointer;
}

.button-link {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  border: 1px solid #263126;
  border-radius: 6px;
  padding: 0 14px;
  background: var(--surface);
  color: #263126;
  font-weight: 680;
  text-decoration: none;
}

button:disabled {
  cursor: wait;
  opacity: 0.68;
}

.icon-button {
  min-width: 38px;
  padding: 0 11px;
  font-size: 20px;
  font-weight: 600;
  line-height: 1;
}

.period-button {
  min-height: 32px;
  padding: 0 11px;
  border-color: var(--line);
  background: var(--surface);
  color: #2f352e;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.period-button-compact {
  min-width: 42px;
  padding: 0 9px;
  font-variant-numeric: tabular-nums;
}

.period-button-compact[data-period="total"] {
  font-size: 15px;
  font-weight: 760;
  line-height: 1;
}

.period-button.active {
  border-color: #263126;
  background: #263126;
  color: #fff;
}

main {
  width: min(1500px, 100%);
  margin: 0 auto;
  padding: 22px 24px 42px;
}

.eyebrow {
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 780;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

.state-pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border-radius: 999px;
  padding: 0 11px;
  border: 1px solid var(--line);
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 13px;
  font-weight: 720;
}

.state-pill.ok {
  border-color: #c6d9cc;
  background: #eef7ef;
  color: var(--ok);
}

button.state-pill {
  cursor: pointer;
  font: inherit;
}

button.state-pill.ok:hover {
  border-color: #b5cdb9;
  background: #e4f2e6;
}

.state-pill.error {
  border-color: #e1c4c4;
  background: #fff1f0;
  color: var(--bad);
}

.summary-grid,
.dashboard-grid,
.heating-grid,
.radio-quality-grid {
  display: grid;
  gap: 12px;
}

.summary-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-top: 28px;
}

.summary-card,
.panel,
.radio-card,
.table-shell {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(26, 31, 24, 0.04);
}

.summary-card {
  min-height: 86px;
  padding: 15px 16px;
}

.label,
.muted,
td {
  color: var(--muted);
}

.label {
  display: block;
  margin-bottom: 10px;
  font-size: 12px;
  font-weight: 720;
  text-transform: uppercase;
}

.summary-card strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: 25px;
  line-height: 1.15;
}

.section-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin: 25px 0 12px;
}

.section-head-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.section-head-meters {
  align-items: center;
  gap: 18px;
}

.section-head-meters .period-row {
  justify-content: flex-end;
  margin-left: auto;
}

.period-controls {
  display: flex;
  align-items: baseline;
  justify-content: flex-start;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin: -4px 0 13px;
}

.period-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  flex-wrap: wrap;
}

.period-divider {
  margin: 0 4px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
  user-select: none;
}

.period-info {
  color: var(--muted);
  font-size: 12px;
}

.dashboard-grid {
  grid-template-columns: repeat(4, minmax(180px, 1fr));
}

.main-col-1 {
  grid-column: 1;
}

.main-col-2 {
  grid-column: 2;
}

.main-col-3 {
  grid-column: 3;
}

.main-col-4 {
  grid-column: 4;
}

.panel {
  min-height: 166px;
  padding: 14px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 14px;
}

.panel.panel-dual {
  min-height: 196px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: start;
}

.panel-title {
  font-size: 14px;
  font-weight: 760;
  line-height: 1.25;
}

.panel-kinds {
  display: flex;
  gap: 4px;
  flex: 0 0 auto;
}

.panel-kind {
  width: 9px;
  height: 28px;
  flex: 0 0 auto;
  border-radius: 99px;
  background: var(--kind-color, #777);
}

.panel-main {
  align-self: start;
}

.panel-main .bar-stack {
  width: 100%;
}

.panel-value {
  display: flex;
  align-items: baseline;
  gap: 6px;
  min-width: 0;
}

.panel-value strong {
  overflow-wrap: anywhere;
  font-size: 28px;
  line-height: 1;
}

.panel-value span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 720;
}

.bar {
  flex: 1 1 auto;
  height: 8px;
  overflow: hidden;
  border-radius: 99px;
  background: #eceee8;
}

.bar > span {
  display: block;
  height: 100%;
  width: var(--pct, 0%);
  min-width: 2px;
  max-width: 100%;
  background: var(--kind-color, #777);
}

.bar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 13px;
}

.bar-row-scale {
  gap: 6px;
}

.bar-scale-min,
.bar-scale-max {
  flex: 0 0 auto;
  min-width: 2.6em;
  color: var(--muted);
  font-size: 11px;
  font-weight: 720;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.bar-scale-min {
  text-align: right;
}

.bar-scale-max {
  text-align: left;
}

.bar-row-scale .bar {
  flex: 1 1 auto;
  min-width: 0;
}

.bar-stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
}

.metric-bar-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.metric-bar-name {
  min-height: 1.2em;
  color: var(--muted);
  font-size: 12px;
  font-weight: 720;
}

.metric-bar-value {
  display: inline-grid;
  grid-template-columns: minmax(5.5ch, auto) 3.6ch;
  align-items: baseline;
  column-gap: 6px;
  font-size: 18px;
  font-weight: 780;
  line-height: 1.1;
  text-align: right;
}

.metric-bar-number {
  overflow-wrap: anywhere;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.metric-bar-unit {
  color: var(--muted);
  font-size: 12px;
  font-weight: 720;
  text-align: left;
  white-space: nowrap;
}

.metric-bar .bar-row {
  margin-top: 6px;
}

.metric-bar-export {
  --kind-color: #d9730d;
}

.bar-label {
  flex: 0 0 54px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 780;
  text-align: right;
  white-space: nowrap;
}

.panel-foot {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
}

.status {
  font-weight: 760;
}

.status.ok {
  color: var(--ok);
}

.status.warn {
  color: var(--warn);
}

.status.bad {
  color: var(--bad);
}

.heating-grid {
  grid-template-columns: repeat(4, minmax(160px, 1fr));
}

.heating-grid .panel {
  grid-column: var(--grid-column, auto);
  grid-row: var(--grid-row, auto);
}

.panel-compact {
  min-height: 142px;
}

.panel-compact .panel-value strong {
  font-size: 24px;
}

.radio-quality-grid {
  grid-template-columns: repeat(4, minmax(220px, 1fr));
}

.radio-card {
  min-height: 196px;
  padding: 14px;
  display: grid;
  gap: 12px;
  align-content: start;
  grid-column: var(--radio-column, auto);
  grid-row: var(--radio-row, auto);
  --radio-color: var(--muted);
}

.radio-good {
  --radio-color: var(--ok);
}

.radio-fair {
  --radio-color: var(--warn);
}

.radio-unstable {
  --radio-color: var(--warn);
}

.radio-weak,
.radio-stale {
  --radio-color: var(--bad);
}

.radio-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.radio-card-head strong {
  display: block;
  font-size: 14px;
  font-weight: 780;
  line-height: 1.2;
}

.radio-card-head span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 640;
}

.radio-status {
  margin-top: 0 !important;
  min-width: 62px;
  border: 1px solid color-mix(in srgb, var(--radio-color) 45%, var(--line));
  border-radius: 99px;
  padding: 4px 8px;
  background: color-mix(in srgb, var(--radio-color) 10%, #fff);
  color: var(--radio-color) !important;
  font-size: 12px !important;
  font-weight: 780 !important;
  text-align: center;
}

.radio-meter {
  height: 8px;
  overflow: hidden;
  border-radius: 99px;
  background: #eceee8;
}

.radio-meter span {
  display: block;
  width: var(--radio-score, 0%);
  min-width: 2px;
  max-width: 100%;
  height: 100%;
  background: var(--radio-color);
}

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

.radio-metrics div {
  min-width: 0;
}

.radio-metrics dt {
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 760;
  text-transform: uppercase;
}

.radio-metrics dd {
  margin: 0;
  overflow-wrap: anywhere;
  color: #2f352e;
  font-size: 13px;
  font-weight: 720;
}

.radio-metrics dd.battery-low {
  color: var(--bad);
}

.radio-metrics dd.battery-warn {
  color: var(--warn);
}

.table-shell {
  overflow-x: auto;
}

.table-shell-scroll,
.table-shell-scroll-5,
.table-shell-scroll-10 {
  overflow: auto;
}

.table-shell-scroll {
  max-height: calc(20 * 41px + 45px);
}

.table-shell-scroll-5 {
  max-height: calc(5 * 41px + 45px);
}

.table-shell-scroll-10 {
  max-height: calc(10 * 41px + 45px);
}

.status-section-pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px 12px;
  min-height: 32px;
  margin: 8px 0 4px;
}

.status-section-pager .muted {
  margin: 0;
}

.status-section-pager .muted:not([hidden]) {
  margin-right: auto;
}

.table-shell-scroll thead th,
.table-shell-scroll-5 thead th,
.table-shell-scroll-10 thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface);
  box-shadow: 0 1px 0 var(--line);
}

table {
  width: 100%;
  min-width: 680px;
  border-collapse: collapse;
  font-size: 14px;
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: #3d453b;
  font-size: 12px;
  font-weight: 780;
  text-transform: uppercase;
}

tbody tr:last-child td {
  border-bottom: 0;
}

.empty {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 22px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.5);
}

@media (max-width: 1180px) {
  .dashboard-grid {
    grid-template-columns: repeat(2, minmax(180px, 1fr));
  }

  .main-col-1,
  .main-col-2,
  .main-col-3,
  .main-col-4 {
    grid-column: auto;
  }

  .heating-grid {
    grid-template-columns: repeat(2, minmax(220px, 1fr));
  }

  .radio-quality-grid {
    grid-template-columns: repeat(2, minmax(220px, 1fr));
  }

  .radio-card {
    grid-column: auto;
    grid-row: auto;
  }

  .heating-grid .panel {
    grid-column: auto;
    grid-row: auto;
  }
}

@media (max-width: 760px) {
  .topbar,
  .app-header {
    padding: 20px 18px 10px;
  }

  .app-header-row {
    flex-wrap: wrap;
    align-items: center;
  }

  .topbar-actions,
  .header-actions {
    width: 100%;
    justify-content: space-between;
  }

  .app-tabs {
    padding: 0 14px;
  }

  main {
    padding: 18px 14px 34px;
  }

  .summary-grid,
  .dashboard-grid,
  .heating-grid,
  .radio-quality-grid {
    grid-template-columns: 1fr;
  }

  .radio-card {
    grid-column: auto;
    grid-row: auto;
  }

  .section-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .section-head-meters .period-row {
    width: 100%;
    justify-content: flex-start;
    margin-left: 0;
  }
}

.security-section {
  margin-top: 28px;
  max-width: 100%;
}

.security-session-card {
  margin-bottom: 18px;
}

.security-session-card strong {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.audit-table-shell {
  max-width: 100%;
}

.audit-filter-panel {
  margin: 0 0 12px;
  border: 0;
}

.audit-filter-panel > summary {
  display: none;
}

.audit-filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 8px 10px;
}

.audit-filters label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.audit-filters input,
.audit-filters select {
  width: 100%;
  min-width: 0;
  min-height: 34px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

table.audit-table {
  min-width: 0;
  width: 100%;
  table-layout: fixed;
}

.audit-table th,
.audit-table td {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.audit-table th:nth-child(1),
.audit-table td:nth-child(1) {
  width: 16%;
}

.audit-table th:nth-child(2),
.audit-table td:nth-child(2),
.audit-table th:nth-child(3),
.audit-table td:nth-child(3) {
  width: 12%;
}

.audit-table th:nth-child(4),
.audit-table td:nth-child(4) {
  width: 16%;
}

.audit-table th:nth-child(5),
.audit-table td:nth-child(5) {
  width: 20%;
}

.audit-table th:nth-child(6),
.audit-table td:nth-child(6) {
  width: 24%;
}

.audit-cards {
  display: none;
}

.audit-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  background: var(--surface);
  max-width: 100%;
}

.audit-card-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
  flex-wrap: wrap;
}

.audit-card-user {
  margin: 8px 0 4px;
  font-weight: 720;
  overflow-wrap: anywhere;
}

.audit-card-meta {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

@media (max-width: 760px) {
  .audit-table-shell {
    display: none;
  }

  .audit-filter-panel {
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 8px 12px 12px;
    background: var(--surface);
  }

  .audit-filter-panel > summary {
    display: list-item;
    cursor: pointer;
    font-weight: 720;
    margin-bottom: 8px;
  }

  .audit-filters {
    grid-template-columns: 1fr 1fr;
  }

  .audit-cards {
    display: grid;
    gap: 10px;
  }
}
