/* Palettes from razorair_godot/autoloads/AppTheme.gd. Keep in sync with
   THEMES in js/settings.js. */
:root,
[data-theme="dark"] {
  --bg: #101218;
  --card: #232832;
  --border: #323842;
  --input: #1e232c;
  --hover: #2a313c;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #1f6fee;
  --accent-hover: #3d81f4;
  --accent-text: #f5f7fc;
  --dialog: #2a2f3a;
  color-scheme: dark;
}

[data-theme="light"] {
  --bg: #f0f2f7;
  --card: #ffffff;
  --border: #ccd4de;
  --input: #f5f7fa;
  --hover: #e6edf5;
  --text: #212933;
  --muted: #616b7a;
  --accent: #1f66db;
  --accent-hover: #337aeb;
  --accent-text: #fafaff;
  --dialog: #ffffff;
  color-scheme: light;
}

[data-theme="spring"] {
  --bg: #edf5e8;
  --card: #f7fcf5;
  --border: #b8ccb3;
  --input: #f0f7eb;
  --hover: #dbebd6;
  --text: #293d29;
  --muted: #617a61;
  --accent: #458c52;
  --accent-hover: #549e61;
  --accent-text: #f7fcf5;
  --dialog: #f7fcf5;
  color-scheme: light;
}

[data-theme="summer"] {
  --bg: #f7f0db;
  --card: #fffaed;
  --border: #d1b885;
  --input: #fcf5e0;
  --hover: #f0e0bd;
  --text: #47331a;
  --muted: #7a6647;
  --accent: #d99414;
  --accent-hover: #eba81f;
  --accent-text: #38240a;
  --accent-strong: #b0720a;
  --dialog: #fffaf0;
  color-scheme: light;
}

[data-theme="fall"] {
  --bg: #2b1c14;
  --card: #3d291c;
  --border: #66472e;
  --input: #332117;
  --hover: #523826;
  --text: #f7ebd6;
  --muted: #bd9e7a;
  --accent: #cc6129;
  --accent-hover: #e07a38;
  --accent-text: #fcf2e6;
  --dialog: #472e21;
  color-scheme: dark;
}

[data-theme="winter"] {
  --bg: #1c242e;
  --card: #293342;
  --border: #52667a;
  --input: #212b38;
  --hover: #38475c;
  --text: #e6f0f7;
  --muted: #9eb3c7;
  --accent: #8cc7e6;
  --accent-hover: #add9f2;
  --accent-text: #142433;
  --dialog: #2e3b4d;
  color-scheme: dark;
}

:root {
  --ok: #56c856;
  --err: #e64c4c;
  --warn: #ffbf33;
  --cold: #80ccff;
  --info: #8cd9a6;
  --plug-on: #287532;
  --plug-on-border: #349841;
  --on-text: #f2faf2;

  --radius: 12px;
  --gap: 12px;
  --tap: 48px;
}

/* Darker status colors so they stay readable on the light palettes. */
[data-theme="light"],
[data-theme="spring"],
[data-theme="summer"] {
  --ok: #2e8b3e;
  --err: #c93030;
  --warn: #a8670f;
  --cold: #2b74b8;
  --info: #2f8a57;
}

:root {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.4;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

body {
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
    env(safe-area-inset-bottom) env(safe-area-inset-left);
  -webkit-tap-highlight-color: transparent;
}

h1,
h2,
p {
  margin: 0;
}

/* ── Top bar ─────────────────────────────────────────────────────────────── */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: var(--gap);
  max-width: 560px;
  margin: 0 auto;
  padding: 10px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.brand {
  font-size: 1.15rem;
  font-weight: 600;
}

.status {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  font-size: 0.85rem;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

[data-role="muted"] { color: var(--muted); }
[data-role="ok"] { color: var(--ok); }
[data-role="err"] { color: var(--err); }
[data-role="warn"] { color: var(--warn); }
[data-role="cold"] { color: var(--cold); }
[data-role="info"] { color: var(--info); }

/* ── Buttons & inputs ────────────────────────────────────────────────────── */

.btn,
.icon-btn {
  min-height: 40px;
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--input);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

.btn:hover,
.icon-btn:hover {
  background: var(--hover);
}

.btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.btn.primary {
  min-height: var(--tap);
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

.btn.primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.icon-btn {
  width: 44px;
  min-height: 44px;
  padding: 0;
  font-size: 1.3rem;
  line-height: 1;
}

input {
  width: 100%;
  min-height: var(--tap);
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--input);
  color: var(--text);
  font: inherit;
}

input:focus-visible,
.btn:focus-visible,
.icon-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ── Cards ───────────────────────────────────────────────────────────────── */

.cards {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  max-width: 560px;
  margin: 0 auto;
  padding: 16px;
}

.card {
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
}

.card-title {
  font-size: 1rem;
  font-weight: 600;
}

.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--gap);
  margin-bottom: 12px;
}

.card-status {
  min-width: 0;
  overflow: hidden;
  font-size: 0.85rem;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.label {
  color: var(--muted);
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.sub {
  color: var(--muted);
  font-size: 0.85rem;
}

.empty {
  color: var(--muted);
  font-size: 0.9rem;
}

.kv {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 16px;
  margin: 0;
}

.kv dt {
  color: var(--muted);
}

.kv dd {
  margin: 0;
  text-align: right;
  overflow-wrap: anywhere;
}

.flash-err {
  animation: flash-err 1.5s ease-out;
}

@keyframes flash-err {
  0%,
  60% {
    outline: 2px solid var(--err);
    outline-offset: 2px;
    border-radius: 8px;
  }
  100% {
    outline: 2px solid transparent;
  }
}

/* ── Steppers, switches, selects ─────────────────────────────────────────── */

.stepper {
  display: flex;
  align-items: center;
  gap: 10px;
}

.step-btn {
  width: var(--tap);
  min-height: var(--tap);
  padding: 0;
  font-size: 1.5rem;
  line-height: 1;
}

.step-label {
  min-width: 5.5em;
  text-align: center;
}

.select {
  min-height: var(--tap);
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--input);
  color: var(--text);
  font: inherit;
}

.select:disabled,
.step-btn:disabled {
  opacity: 0.45;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  min-height: var(--tap);
  cursor: pointer;
}

.toggle-row.disabled {
  cursor: default;
  opacity: 0.6;
}

.switch {
  position: relative;
  flex: none;
  width: 52px;
  height: 30px;
  min-height: 0;
  padding: 0;
  margin: 0;
  border-radius: 15px;
  background: var(--input);
  border: 1px solid var(--border);
  appearance: none;
  cursor: inherit;
  transition: background 0.15s;
}

.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform 0.15s, background 0.15s;
}

.switch:checked {
  background: var(--accent);
  border-color: var(--accent);
}

.switch:checked::after {
  background: var(--accent-text);
  transform: translateX(22px);
}

.switch:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ── Thermostat ──────────────────────────────────────────────────────────── */

.thermo-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--gap);
}

.thermo-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  text-align: center;
}

.thermo-col + .thermo-col {
  border-left: 1px solid var(--border);
}

.big-value {
  font-size: 2.2rem;
  font-weight: 600;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}

.big-value.accent {
  color: var(--accent-strong, var(--accent-hover));
}

.boost-btn {
  width: 100%;
  min-height: var(--tap);
  font-weight: 600;
}

.boost-btn[data-active="true"] {
  border-color: var(--warn);
  background: color-mix(in srgb, var(--warn) 22%, var(--input));
  font-variant-numeric: tabular-nums;
}

.boost-btn[data-active="true"]:hover:not(:disabled) {
  background: color-mix(in srgb, var(--warn) 32%, var(--input));
}

/* ── HVAC unit ───────────────────────────────────────────────────────────── */

.vent-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
}

.vent-ctrl .select {
  min-width: 9em;
}

/* ── Plugs & sensors ─────────────────────────────────────────────────────── */

.rows {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.plug-row,
.sensor-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.plug-btn {
  flex: 1;
  min-width: 0;
  min-height: 56px;
  padding: 0 14px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--input);
  color: var(--muted);
  font: inherit;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}

.plug-btn[data-state="on"] {
  border-color: var(--plug-on-border);
  background: var(--plug-on);
  color: var(--on-text);
}

.plug-btn[data-state="unknown"] {
  background: var(--bg);
}

.plug-btn:disabled {
  cursor: default;
}

.plug-btn:not(:disabled):hover {
  filter: brightness(1.15);
}

.metric {
  flex: none;
  min-width: 3.6em;
  color: var(--text);
  font-size: 0.9rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.plug-row .metric {
  color: var(--muted);
}

.sensor-name {
  flex: 1;
  min-width: 0;
  padding: 14px 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--input);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sensor-row[data-stale="true"] .sensor-name {
  background: var(--bg);
}

.sensor-row[data-stale="true"] > :not([data-role="warn"]) {
  color: var(--muted);
}

/* ── Alerts ──────────────────────────────────────────────────────────────── */

.alerts {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.power-alert {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
}

.power-alert-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

/* ── Settings sheet ──────────────────────────────────────────────────────── */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgb(0 0 0 / 0.55);
}

.sheet-panel {
  width: 100%;
  max-width: 560px;
  max-height: 100dvh;
  overflow-y: auto;
  padding: 16px 16px calc(24px + env(safe-area-inset-bottom));
  border-radius: var(--radius) var(--radius) 0 0;
  background: var(--dialog);
}

@media (min-width: 600px) {
  .sheet {
    align-items: center;
  }

  .sheet-panel {
    border-radius: var(--radius);
  }
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-label {
  color: var(--muted);
  font-size: 0.9rem;
}

.pw-row {
  display: flex;
  gap: 8px;
}

.pw-row .btn {
  min-height: var(--tap);
}

.form-msg {
  color: var(--err);
}

.account {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.prefs {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.prefs h3 {
  margin: 0;
}

.field .select {
  width: 100%;
}

/* ── Full-screen overlays (admin, radar) ───────────────────────────────────────────────────────── */

.full-panel {
  height: 100dvh;
  padding-top: 0;
  border-radius: 0;
}

@media (min-width: 600px) {
  .full-panel {
    height: 90dvh;
    border-radius: var(--radius);
  }
}

.full-head {
  position: sticky;
  top: 0;
  z-index: 1;
  margin: 0 -16px 4px;
  padding: 16px 16px 4px;
  background: var(--dialog);
  border-bottom: 1px solid var(--border);
}

.full-head .sheet-head {
  margin-bottom: 12px;
}

.tabs {
  display: flex;
  gap: 6px;
  margin: 0 -16px;
  padding: 0 16px 2px;
  overflow-x: auto;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tab {
  flex: none;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--input);
  color: var(--muted);
  font: inherit;
  font-size: 0.95rem;
  cursor: pointer;
}

.tab[aria-selected="true"] {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-text);
}

.tab:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.admin-status {
  min-height: 1.5em;
  margin: 6px 0 0;
  font-size: 0.85rem;
  overflow-wrap: anywhere;
}

.admin-body,
.admin-list {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

.admin-body {
  padding-top: 8px;
}

.form-row {
  display: flex;
  align-items: stretch;
  gap: 8px;
}

.form-row > input {
  flex: 1;
  min-width: 0;
}

.form-row > .btn {
  flex: none;
  min-height: var(--tap);
}

.form-row > input[type="time"] {
  flex: 1.8;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.btn-row .btn {
  min-height: 44px;
}

.btn.danger {
  color: var(--err);
}

.seg {
  display: flex;
  gap: 8px;
}

.seg .btn {
  flex: 1;
  min-height: var(--tap);
}

.seg .btn[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

.subitem {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.subitem[data-stale="true"] .subitem-head {
  color: var(--muted);
}

.subitem-head {
  display: flex;
  align-items: center;
  gap: 10px;
}

.subitem-head .grow {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.subitem-head .btn {
  flex: none;
}

/* ── Radar ───────────────────────────────────────────────────────────────── */

.radar-body {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  padding-top: 12px;
}

.radar-frame {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 240px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--input);
}

.radar-frame img {
  display: block;
  width: 100%;
  height: auto;
}

.radar-body > .btn {
  min-height: var(--tap);
}

/* ── Thermostat heat sources ─────────────────────────────────────────────── */

.heat-sources {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: -8px;
}

.source-name {
  min-width: 0;
}

.source-detail {
  margin: -6px 0 6px;
  white-space: pre-line;
}

.source-detail[data-role="warn"] {
  color: var(--warn);
}

.heat-source-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.heat-source-form:last-child {
  padding-bottom: 0;
  border-bottom: none;
}

.diag-msg {
  flex: 1;
  margin: 0;
  font-size: 0.9rem;
}
