* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  background: #0f1115; color: #e6e8ec;
  -webkit-font-smoothing: antialiased;
}
body[data-view="ha"] { background: transparent; }

a { color: #7eb6ff; }

.status-line {
  padding: 10px 14px;
  color: #8a93a3;
  font-size: 0.9rem;
  display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
  border-bottom: 1px solid #1a1d24;
}
.status-line strong { color: #e6e8ec; }
.status-line .mock { background: #5a3a0e; color: #ffd28a; padding: 2px 8px; border-radius: 6px; font-size: 0.8rem; font-weight: 600; }
.status-line .meta {
  color: #6b7382; font-size: 0.8rem;
  margin-left: auto;
  white-space: nowrap;
}
.warn-text {
  color: #ff8d8d;
  font-size: 0.9rem;
  font-weight: 600;
}
.warn-text:empty { display: none; }

.badge {
  display: inline-block; padding: 2px 10px; border-radius: 6px;
  font-size: 0.85rem; font-weight: 600;
  background: #2c313c; color: #e6e8ec;
}
.badge.ok { background: #0d3a25; color: #7ed99c; }
.badge.warn { background: #5a1e1e; color: #ff8d8d; }

.badge.mode {
  font-size: 0.95rem; padding: 4px 14px;
  font-weight: 700;
  letter-spacing: 0.02em;
  background: #2c313c; color: #e6e8ec;
}
.badge.mode-L { background: #16385e; color: #8bbef0; border: 1px solid #2e6db5; }
.badge.mode-B { background: #46164a; color: #f0a8e8; border: 1px solid #a04ca0; }
.badge.mode-F { background: #5a1e1e; color: #ff8d8d; border: 1px solid #a64141; }
.badge.mode-S, .badge.mode-H { background: #2c313c; color: #a8b0c0; }
.badge.mode-P { background: #4a3a0e; color: #ffd28a; border: 1px solid #8a6a1e; }

.tiles {
  display: grid; gap: 12px; padding: 12px;
}
body[data-view="mobile"] .tiles { grid-template-columns: 1fr 1fr; }
body[data-view="desktop"] .tiles { grid-template-columns: repeat(3, 1fr); }
body[data-view="ha"] .tiles { grid-template-columns: repeat(4, 1fr); gap: 8px; padding: 8px; }

.tile {
  background: #1a1d24;
  border: 1px solid #262a33;
  border-radius: 14px;
  padding: 16px 18px;
  display: flex; flex-direction: column; gap: 4px;
  min-width: 0;
}
.tile .label {
  font-size: 0.8rem; color: #8a93a3;
  text-transform: uppercase; letter-spacing: 0.06em;
  font-weight: 600;
}
.tile .value {
  font-size: 2.6rem; font-weight: 700; line-height: 1.05;
  font-variant-numeric: tabular-nums;
  color: #f7f8fa;
}
.tile .value, .tile .unit {
  white-space: nowrap;
}
.tile > div:has(> .value) {
  display: flex; align-items: baseline;
  min-width: 0;
}
body[data-view="mobile"] .tile .value { font-size: clamp(2rem, 10vw, 2.8rem); }
body[data-view="desktop"] .tile .value { font-size: 5.2rem; }
body[data-view="ha"] .tile .value { font-size: 2.4rem; }
.tile .unit {
  font-size: 1rem; color: #8a93a3; margin-left: 6px; font-weight: 500;
}
body[data-view="desktop"] .tile .unit { font-size: 1.4rem; }
.tile .sub {
  font-size: 0.95rem; color: #a8b0c0;
  font-variant-numeric: tabular-nums;
}
body[data-view="mobile"] .tile .sub { font-size: 1.05rem; }

.flow-pos, .tile .flow-pos, .tile .value.flow-pos { color: #7ed99c; font-weight: 700; }
.flow-neg, .tile .flow-neg, .tile .value.flow-neg { color: #ff8d8d; font-weight: 700; }
.flow-zero, .tile .flow-zero, .tile .value.flow-zero { color: #a8b0c0; }

.mode-bar {
  display: flex; flex-direction: column; gap: 12px;
  padding: 14px;
  border-top: 1px solid #1a1d24;
}
.mode-bar .current {
  font-size: 1rem; color: #8a93a3;
}
.mode-bar .current strong {
  font-size: 2rem; font-weight: 700; color: #f7f8fa; display: block;
  font-variant-numeric: tabular-nums;
}
body[data-view="desktop"] .mode-bar .current strong { font-size: 3rem; }

.mode-btn-row {
  display: flex; gap: 10px;
}
.mode-btn-row .mode-btn {
  flex: 1; min-width: 0;
}

/* Mobile mode-tap card */
.mode-tap {
  margin: 12px;
  padding: 18px 20px;
  background: #1a1d24;
  border: 1px solid #262a33;
  border-radius: 14px;
  cursor: pointer;
  text-align: center;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.1s, background 0.1s;
}
.mode-tap:active { background: #20242d; border-color: #4a566e; }
.mode-tap-label {
  font-size: 0.8rem; color: #8a93a3;
  text-transform: uppercase; letter-spacing: 0.06em;
  font-weight: 600;
}
.mode-tap-value {
  font-size: 3.4rem; font-weight: 700; line-height: 1.1;
  color: #f7f8fa;
  font-variant-numeric: tabular-nums;
  margin-top: 4px;
}
.mode-tap-hint {
  font-size: 0.85rem; color: #6b7382;
  margin-top: 4px;
}

/* Picker modal: 3 mode buttons in a row */
.modal.mode-picker .mode-btn-row {
  margin-top: 8px;
}
.modal.mode-picker .mode-btn {
  padding: 16px 0; font-size: 1.3rem;
  min-width: 0;
}
body[data-view="desktop"] .modal.mode-picker .mode-btn {
  padding: 16px 0; font-size: 1.3rem;
  min-width: 0;
}
.modal.mode-picker .picker-cancel {
  margin-top: 16px;
  width: 100%;
  padding: 12px;
  border-radius: 10px;
  background: #1a1d24;
  color: #e6e8ec;
  border: 1px solid #2c313c;
  font-size: 1rem; font-weight: 600;
  cursor: pointer; font-family: inherit;
}

.mode-btn {
  background: #1a1d24; color: #e6e8ec;
  border: 2px solid #2c313c;
  padding: 14px 26px;
  border-radius: 12px;
  font-size: 1.4rem; font-weight: 700;
  cursor: pointer; font-family: inherit;
  min-width: 110px;
  transition: border-color 0.1s, background 0.1s;
}
body[data-view="desktop"] .mode-btn { font-size: 1.8rem; padding: 18px 36px; min-width: 150px; }
body[data-view="ha"] .mode-btn { font-size: 1rem; padding: 8px 16px; min-width: 70px; }

.mode-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.mode-btn:not(:disabled):hover { border-color: #4a566e; }
.mode-btn.active {
  background: #0d3a25; border-color: #2f9d5e; color: #b6f0c8;
}
.mode-btn.active:hover { border-color: #41c47a; }

/* Per-mode colors on picker buttons */
.mode-btn.prio-UTL { border-color: #2e6db5; color: #8bbef0; }
.mode-btn.prio-UTL.active { background: #16385e; color: #cfe2f7; border-color: #4b8fd9; }
.mode-btn.prio-SUB { border-color: #a07020; color: #ffc278; }
.mode-btn.prio-SUB.active { background: #4a330e; color: #ffd9a0; border-color: #d99238; }
.mode-btn.prio-SBU { border-color: #a04ca0; color: #f0a8e8; }
.mode-btn.prio-SBU.active { background: #46164a; color: #ffcaf5; border-color: #c869c8; }

/* Tinting the big mode-tap card by current priority */
.mode-tap.prio-UTL .mode-tap-value { color: #8bbef0; }
.mode-tap.prio-UTL { border-color: #2e6db5; }
.mode-tap.prio-SUB .mode-tap-value { color: #ffc278; }
.mode-tap.prio-SUB { border-color: #a07020; }
.mode-tap.prio-SBU .mode-tap-value { color: #f0a8e8; }
.mode-tap.prio-SBU { border-color: #a04ca0; }

body[data-view="desktop"] .mode-tap {
  padding: 18px 36px;
  margin: 18px auto;
  max-width: 360px;
  text-align: center;
}
body[data-view="desktop"] .mode-tap-value {
  font-size: 3.4rem;
}
body[data-view="desktop"] .mode-tap-label {
  font-size: 0.85rem;
}
body[data-view="desktop"] .mode-tap-hint {
  font-size: 0.9rem;
}

.settings-panel { padding: 12px; border-top: 1px solid #1a1d24; }
.settings-toggle {
  background: none;
  border: 1px solid #2c313c;
  color: #8a93a3;
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer; font-family: inherit;
  font-size: 0.9rem;
}
.settings-body, .device-body { display: none; margin-top: 12px; }
.settings-panel.open .settings-body,
.settings-panel.open .device-body {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 4px 24px;
}
.settings-body div, .device-body div {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 6px 0;
  border-bottom: 1px solid #1a1d24;
  font-size: 0.9rem;
}
.settings-body .k, .device-body .k { color: #8a93a3; }
.settings-body .v, .device-body .v { font-variant-numeric: tabular-nums; color: #e6e8ec; }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.modal {
  background: #1a1d24;
  border: 1px solid #2c313c;
  border-radius: 14px;
  padding: 24px;
  max-width: 420px;
  width: 90%;
}
.modal-text { font-size: 1.25rem; margin-bottom: 22px; line-height: 1.4; }
.modal-buttons { display: flex; gap: 12px; justify-content: flex-end; }
.modal-buttons button {
  padding: 12px 22px;
  border-radius: 10px;
  font-size: 1rem; font-weight: 600;
  cursor: pointer; font-family: inherit;
  border: 1px solid #2c313c;
}
.btn-cancel { background: #1a1d24; color: #e6e8ec; }
.btn-confirm { background: #0d3a25; color: #b6f0c8; border-color: #2f9d5e; }
.btn-confirm:hover { background: #0e4a2c; }

.toast {
  position: fixed; bottom: 24px; left: 50%;
  transform: translateX(-50%);
  background: #0d3a25; color: #b6f0c8;
  padding: 14px 24px; border-radius: 10px;
  font-weight: 700; font-size: 1rem;
  z-index: 200;
  border: 1px solid #2f9d5e;
}
.toast.err { background: #5a1e1e; color: #ffb0b0; border-color: #a64141; }

/* HA-specific (iframe-friendly, 2x3 tiles, no controls) */
body[data-view="ha"] .status-line { padding: 8px 12px; gap: 8px; border-bottom: none; }
body[data-view="ha"] .tiles { grid-template-columns: 1fr 1fr; gap: 10px; padding: 10px; }
body[data-view="ha"] .tile { padding: 14px 16px; border-radius: 12px; gap: 4px; }
body[data-view="ha"] .tile .label { font-size: 0.8rem; }
body[data-view="ha"] .tile .value { font-size: clamp(2.4rem, 9vw, 3.2rem); }
body[data-view="ha"] .tile .unit { font-size: 0.95rem; margin-left: 5px; }
body[data-view="ha"] .tile .sub { font-size: 0.95rem; }
