/* Thermostat: the Pi web page's colours (light) and the Android app's dark set.
   DAY is orange, NIGHT blue, OFF grey, relay ON red and OFF green, the active
   mode button red. --mode-off is the OFF mode; --relay-off the relay open. */

:root {
  color-scheme: light dark;
  --page: #f1f1f1;
  --surface: #ffffff;
  --text: #333333;
  --border: #cccccc;
  --desired: #0000ff;
  --day: #cc6600;
  --night: #0066cc;
  --mode-off: #666666;
  --relay-on: #ff0000;
  --relay-off: #008000;
  --active: #ff0000;
  --accent: #4caf50;
  --on-accent: #ffffff;
  --warning: #b3261e;
  --degraded-background: #fdecea;
  --degraded-border: #f5c2bd;
  --degraded-text: #b3261e;
}

@media (prefers-color-scheme: dark) {
  :root {
    --page: #121212;
    --surface: #1e1e1e;
    --text: #e6e6e6;
    --border: #444444;
    --desired: #7fb2ff;
    --day: #e8902e;
    --night: #4d9bff;
    --mode-off: #9e9e9e;
    --relay-on: #ff5252;
    --relay-off: #5bc95b;
    --active: #ff5252;
    --warning: #f28b82;
    --degraded-background: #3a1f1c;
    --degraded-border: #7a3a33;
    --degraded-text: #f28b82;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--page);
  color: var(--text);
  font-family: -apple-system, system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

button {
  font: inherit;
  color: inherit;
}

.top-bar h1 {
  margin: 0;
  padding: 0.5em 0.75em;
  font-size: 1.4em;
  font-weight: 600;
}

/* --- tabs --- */

.tabs {
  display: flex;
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--page);
  border-bottom: 0.0625em solid var(--border);
}

.tabs button {
  flex: 1;
  padding: 0.8em 0.2em;
  border: none;
  border-bottom: 0.15em solid transparent;
  background: none;
  font-size: 1em;
}

.tabs button[aria-selected="true"] {
  border-bottom-color: var(--text);
  font-weight: 600;
}

.panel {
  background: var(--surface);
  border: 0.0625em solid var(--border);
  border-top: none;
  min-height: 70vh;
  padding: 0.4em 0.75em 1.5em;
}

.heading {
  margin: 0;
  padding: 0.8em 0;
  font-size: 1.4em;
  font-weight: 500;
  text-align: center;
}

.centred {
  text-align: center;
}

.error {
  color: var(--active);
  font-weight: bold;
  text-align: center;
}

.clickable {
  cursor: pointer;
}

/* --- status --- */

.status-block {
  padding: 0.6em 0;
  text-align: center;
}

.status-label {
  font-size: 1.25em;
  font-weight: bold;
}

.status-value {
  font-weight: bold;
  line-height: 1.1;
}

.status-value.huge {
  font-size: 4em;
}

.status-value.large {
  font-size: 2em;
}

.status-value.small {
  font-size: 0.9em;
  font-weight: normal;
}

.desired { color: var(--desired); }
.day { color: var(--day); }
.night { color: var(--night); }
.mode-off { color: var(--mode-off); }
.relay-on { color: var(--relay-on); }
.relay-off { color: var(--relay-off); }

.degraded {
  margin: 0.5em 0 0;
  padding: 0.5em;
  text-align: center;
  font-weight: bold;
  color: var(--degraded-text);
  background: var(--degraded-background);
  border: 0.0625em solid var(--degraded-border);
}

.sensors {
  width: 100%;
  margin-top: 0.75em;
  border-collapse: collapse;
  table-layout: fixed;
}

.sensors th,
.sensors td {
  border: 0.0625em solid var(--border);
  padding: 0.4em 0.2em;
  text-align: center;
}

.sensors th {
  font-size: 0.75em;
  background: var(--page);
}

.sensors td {
  font-size: 1em;
}

.sensors .warn {
  color: var(--relay-on);
  font-weight: bold;
}

/* --- mode --- */

.mode-buttons {
  display: flex;
  flex-direction: column;
  gap: 1.25em;
  max-width: 25em;
  margin: 0 auto;
  padding: 0 0.6em;
}

.mode-button {
  padding: 0.45em 0.6em;
  font-size: 2em;
  background: var(--surface);
  border: 0.03em solid var(--text);
}

.mode-button.active,
.valve-mode.active,
.pairing-toggle.active {
  color: var(--active);
  border-color: var(--active);
  border-width: 0.125rem;
  font-weight: bold;
}

/* --- config --- */

.config-message {
  min-height: 1.4em;
  margin: 0 0 0.6em;
  text-align: center;
  font-weight: bold;
  color: var(--relay-off);
}

.config-message.error {
  color: var(--active);
}

.form-heading {
  margin: 1em 0 0;
  font-size: 1.1em;
  font-weight: 500;
}

.form-row {
  display: flex;
  flex-direction: column;
  gap: 0.25em;
  margin-top: 0.6em;
}

.form-label {
  font-weight: bold;
}

.form-row input {
  width: 100%;
  padding: 0.55em;
  font: inherit;
  font-size: 1.05em;           /* at least 16 px, so iOS does not zoom */
  border: 0.0625em solid var(--border);
  border-radius: 0.3em;
  background: var(--surface);
  color: var(--text);
  min-height: 2.6em;
}

.save-button {
  width: 100%;
  margin-top: 1.25em;
  padding: 0.8em;
  font-size: 1.1em;
  border: none;
  border-radius: 1.5em;
  background: var(--accent);
  color: var(--on-accent);
}

.save-button:disabled {
  opacity: 0.6;
}

/* --- valves --- */

.valves {
  max-width: 25em;
  margin: 0 auto;
}

.valves-offline {
  margin: 0 0 1em;
  text-align: center;
  font-size: 1.75em;
  font-weight: bold;
}

.valve {
  margin-bottom: 1em;
  padding: 0.75em;
  border: 0.0625em solid var(--border);
}

.valve-title-row,
.valve-reading-row,
.valve-figures {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.valve-name {
  padding: 0;
  border: none;
  background: none;
  font-size: 1.25em;
  font-weight: bold;
  text-align: left;
}

.text-button {
  padding: 0.4em 0.6em;
  border: none;
  background: none;
  color: var(--night);
}

.valve-reading-row {
  padding: 0.5em 0;
}

.valve-temperature {
  font-size: 2.5em;
  font-weight: bold;
}

.valve-open {
  font-size: 1.25em;
  font-weight: bold;
}

.valve-setpoint-row {
  display: flex;
  align-items: center;
}

.step-button {
  width: 2.3em;
  padding: 0.1em 0;
  font-size: 1.75em;
  background: var(--surface);
  border: 0.04em solid var(--text);
}

.valve-setpoint {
  flex: 1;
  text-align: center;
  font-size: 1.75em;
  font-weight: bold;
}

.valve-mode-row {
  display: flex;
  gap: 0.5em;
  margin-top: 0.75em;
}

.valve-mode {
  flex: 1;
  padding: 0.5em 0;
  font-size: 1.25em;
  background: var(--surface);
  border: 0.05em solid var(--text);
}

.valve-figures {
  margin-top: 0.75em;
}

.valve-figures .warn {
  color: var(--active);
  font-weight: bold;
}

.joining {
  margin: 0 0 0.75em;
}

.joining.failed {
  color: var(--degraded-text);
}

.pairing-toggle {
  width: 100%;
  margin-bottom: 0.75em;
  padding: 0.6em;
  font-size: 1.25em;
  background: var(--surface);
  border: 0.05em solid var(--text);
}

button:disabled {
  opacity: 0.45;
}
