/* ============================================================================
   Dark Mode Stylesheet for Grain Aeration Controller
   ============================================================================ */

:root {
  --bg-primary: #1a1a1a;
  --bg-secondary: #2d2d2d;
  --bg-card: #242424;
  --text-primary: #e0e0e0;
  --text-secondary: #b0b0b0;
  --accent-primary: #4a9eff;
  --accent-secondary: #3a8fdf;
  --border-color: #404040;
  --success-color: #4caf50;
  --error-color: #f44336;
  --warning-color: #ff9800;
  --shadow: rgba(0, 0, 0, 0.5);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  display: inline-block;
  text-align: center;
  background-color: var(--bg-primary);
  color: var(--text-primary);
}

body {
  margin: 0 auto;
  max-width: 800px;
  min-height: 100vh;
  background-color: var(--bg-primary);
}

h1 {
  font-size: 2.6rem;
  font-weight: bold;
  color: var(--text-primary);
  background-color: transparent;
  margin: 1rem 0;
}

h2 {
  font-size: 1.4rem;
  color: var(--bg-secondary);
  margin: 0.8rem 0;
}

p {
  font-size: 1.4rem;
  color: var(--text-primary);
}

p1 {
  font-size: 1rem;
  color: var(--text-secondary);
}

/* ============================================================================
   HEADER & CONTAINER
   ============================================================================ */

.topnav {
  /* overflow: hidden;
  background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
  box-shadow: 0 2px 10px var(--shadow); */

  /*css from RH*/
  overflow: hidden;
  /* background-color: var(--bg-secondary); */
  background-color: white;
  padding: 10px;
  border-radius: 8px;
  margin-bottom: 20px;
}

.w3-container {
  padding: 0;
}

img {
  border-radius: 5px 5px 0 0;
  max-width: 100%;
  height: auto;
}

.content {
  padding: 30px 20px;
  max-width: 800px;
  margin: 0 auto;
}

.ssid-display {
  color: var(--accent-primary);
  font-size: 1.4rem;
  font-weight: bold;
  margin: 10px 0 0 0;
  padding: 0;
  border: none;
}

/* ============================================================================
   CARDS
   ============================================================================ */

.card-grid {
  max-width: 800px;
  margin: 0 auto;
  display: grid;
  grid-gap: 2rem;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

.card {
  background-color: var(--bg-card);
  box-shadow: 0 4px 14px var(--shadow);
  transition: all 0.3s ease;
  border-radius: 15px;
  border: 1px solid var(--border-color);
  padding: 20px;
}

.card:hover {
  box-shadow: 0 8px 20px var(--shadow);
  transform: translateY(-2px);
}

.card-title {
  font-size: 1.5rem;
  font-weight: bold;
  color: var(--accent-primary);
  margin-bottom: 1rem;
}

/* ============================================================================
   TABLES
   ============================================================================ */

table {
  margin: 20px auto;
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background-color: var(--bg-card);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 2px 8px var(--shadow);
}

th,
td {
  text-align: center;
  padding: 12px;
  color: var(--text-primary);
}

/* ============================================================================
   STATUS DASHBOARD GRID
   Replaces the old colspan-juggling <table>. A 2-column grid by default; rows
   that need a different column count use a nested sub-grid (.sg-subgrid for the
   3-up Fan Groups, .sg-subgrid-2 for the 2-up WP/RH pairs). Full-width items
   span both columns with .sg-full.
   ============================================================================ */
.status-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px; /* thin divider lines via the card background showing through */
  margin: 20px auto;
  width: 100%;
  background-color: var(--bg-card);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 2px 8px var(--shadow);
}

/* Span both columns of the parent grid */
.status-grid .sg-full {
  grid-column: 1 / -1;
}

/* Nested sub-grids for rows with their own column count */
.status-grid .sg-subgrid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
}
.status-grid .sg-subgrid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
}

/* Data cell — mirrors old <td> */
.status-grid .sg-cell {
  background-color: var(--bg-card);
  text-align: center;
  padding: 12px;
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.status-grid .sg-cell:hover {
  background-color: var(--bg-secondary);
}

/* Header cell — mirrors old <th> */
.status-grid .sg-head {
  background: linear-gradient(135deg, #021b79 0%, #0575e6 100%);
  color: white;
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.9rem;
  letter-spacing: 0.5px;
  text-align: center;
  padding: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

th {
  /* background: linear-gradient(135deg, #4a9eff 0%, #3a8fdf 100%); */
  background: linear-gradient(135deg, #021b79 0%, #0575e6 100%);
  color: white;
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.9rem;
  letter-spacing: 0.5px;
}

tr:hover td {
  background-color: var(--bg-secondary);
}

/* ============================================================================
   TEMPERATURE & STATUS DISPLAYS
   ============================================================================ */

.temps {
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--accent-primary);
}

.units {
  font-size: 1.6rem;
  color: var(--text-secondary);
}

.motor {
  font-size: 2rem;
  font-weight: 600;
  color: var(--accent-primary);
}

.faults {
  font-size: 2rem;
  font-weight: 700;
  color: #ffeb3b;
  background-color: var(--error-color);
  padding: 10px;
  border-radius: 8px;
  animation: pulse 1.5s infinite;
}

.probe-warning {
  font-size: 1.2rem;
  font-weight: 600;
  color: #000;
  background-color: #ff9800;
  padding: 8px 15px;
  border-radius: 6px;
  display: inline-block;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.7;
  }
}

.contentON {
  background-color: var(--success-color);
  color: white;
  padding: 8px 15px;
  border-radius: 6px;
  display: inline-block;
  font-weight: 600;
}

.contentOFF {
  background-color: var(--error-color);
  color: white;
  padding: 8px 15px;
  border-radius: 6px;
  display: inline-block;
  font-weight: 600;
}

.update-time {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 15px;
  font-style: italic;
}

/* ============================================================================
   FORMS & INPUTS
   ============================================================================ */

input[type="text"],
input[type="number"],
input[type="password"] {
  width: 100%;
  max-width: 300px;
  padding: 10px 15px;
  margin: 8px 0;
  border: 2px solid var(--border-color);
  border-radius: 6px;
  background-color: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 1rem;
  transition: all 0.3s ease;
}

input[type="text"]:focus,
input[type="number"]:focus,
input[type="password"]:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(74, 158, 255, 0.2);
}

input[type="submit"],
button[type="submit"] {
  /* background: linear-gradient(
    135deg,
    var(--accent-primary) 0%,
    var(--accent-secondary) 100%
  ); */
  background: linear-gradient(135deg, #021b79 0%, #0575e6 100%);
  color: white;
  padding: 10px 25px;
  margin: 10px 5px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 600;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px var(--shadow);
}

input[type="submit"]:hover,
button[type="submit"]:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px var(--shadow);
}

input[type="submit"]:active,
button[type="submit"]:active {
  transform: translateY(0);
  box-shadow: 0 2px 6px var(--shadow);
}

/* ============================================================================
   COLLAPSIBLE SECTIONS
   ============================================================================ */

.collapsible {
  /* background: linear-gradient(135deg, #4a9eff 0%, #3a8fdf 100%); */
  background: linear-gradient(135deg, #021b79 0%, #0575e6 100%);
  color: white;
  cursor: pointer;
  padding: 15px;
  width: 100%;
  max-width: 600px;
  border: none;
  text-align: center;
  outline: none;
  font-size: 1rem;
  font-weight: 600;
  margin: 10px auto;
  border-radius: 8px;
  transition: all 0.3s ease;
  display: block;
  box-shadow: 0 2px 8px var(--shadow);
}

.collapsible:hover {
  /* background: linear-gradient(135deg, #5aaaff 0%, #4a9fef 100%); */
  background: linear-gradient(135deg, #021b79 0%, #0575e6 80%);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px var(--shadow);
}

.collapsible:active {
  transform: translateY(0);
  box-shadow: 0 2px 6px var(--shadow);
}

.collapsible.active {
  /* background: linear-gradient(135deg, #3a8fdf 0%, #2a7fcf 100%); */
  background: linear-gradient(135deg, #0575e6 0%, #00f2fe 100%);
}

.content1 {
  padding: 0 18px;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease-out;
  background-color: var(--bg-card);
  border-radius: 0 0 8px 8px;
  margin-bottom: 20px;
}

/* ============================================================================
   TOGGLE SWITCH
   ============================================================================ */

.switch {
  position: relative;
  display: inline-block;
  width: 120px;
  height: 50px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #555;
  transition: 0.4s;
  border-radius: 34px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 42px;
  width: 42px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  transition: 0.4s;
  border-radius: 50%;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

input:checked + .slider {
  background: linear-gradient(
    135deg,
    var(--accent-primary) 0%,
    var(--accent-secondary) 100%
  );
}

input:focus + .slider {
  box-shadow: 0 0 8px var(--accent-primary);
}

input:checked + .slider:before {
  transform: translateX(69px);
}

/* ============================================================================
   BUTTONS
   ============================================================================ */

.resetbtn {
  border: 2px solid var(--error-color);
  background-color: transparent;
  color: var(--error-color);
  padding: 12px 28px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-block;
  border-radius: 6px;
  transition: all 0.3s ease;
  margin: 10px;
}

.resetbtn:hover {
  background-color: var(--error-color);
  color: white;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(244, 67, 54, 0.3);
}

.resetbtn:active {
  transform: translateY(0);
}

/* ============================================================================
   RESPONSIVE DESIGN
   ============================================================================ */

@media screen and (max-width: 600px) {
  .content {
    padding: 20px 10px;
  }

  .temps {
    font-size: 2rem;
  }

  .card-title {
    font-size: 1.2rem;
  }

  .collapsible {
    font-size: 0.9rem;
    padding: 12px;
  }

  table {
    font-size: 0.9rem;
  }

  th,
  td {
    padding: 8px 4px;
  }

  .status-grid {
    font-size: 0.9rem;
  }

  .status-grid .sg-cell,
  .status-grid .sg-head {
    padding: 8px 4px;
  }

  .status-grid .motor {
    font-size: 1.5rem;
  }
}

/* ============================================================================
   UTILITY CLASSES
   ============================================================================ */

.text-center {
  text-align: center;
}

.mb-1 {
  margin-bottom: 1rem;
}

.mb-2 {
  margin-bottom: 2rem;
}

.mt-1 {
  margin-top: 1rem;
}

.mt-2 {
  margin-top: 2rem;
}

/* ============================================================================
   LoRa Probe Cards
   ============================================================================ */

/* Probe grid layout */
.probe-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 15px;
  margin-top: 15px;
  text-align: left;
}

/* Probe card styling */
.probe-card {
  border-radius: 12px;
  padding: 0;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  box-shadow: 0 2px 8px var(--shadow);
  transition:
    transform 0.2s,
    box-shadow 0.2s;
  overflow: hidden;
}

.probe-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px var(--shadow);
}

/* Timed out probe styling */
.probe-card.probe-timeout {
  border: 2px solid var(--error-color);
  background: linear-gradient(
    135deg,
    rgba(244, 67, 54, 0.1) 0%,
    var(--bg-card) 100%
  );
  animation: pulse-border 2s infinite;
}

@keyframes pulse-border {
  0%,
  100% {
    border-color: var(--error-color);
  }
  50% {
    border-color: rgba(244, 67, 54, 0.4);
  }
}

/* Card header with DeviceID and type badge */
.probe-card-header {
  background: var(--bg-secondary);
  padding: 12px 15px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-color);
}

.probe-id {
  font-family: "Courier New", monospace;
  font-size: 0.95rem;
  color: var(--text-primary);
  font-weight: 600;
  letter-spacing: 0.5px;
}

.probe-type-badge {
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Probe alias row */
.probe-alias-row {
  padding: 8px 15px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
}

.probe-alias-input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 0.95rem;
  font-weight: 600;
  text-align: center;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.probe-alias-input:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 2px rgba(76, 175, 80, 0.2);
}

.probe-alias-input::placeholder {
  color: var(--text-secondary);
  font-weight: 400;
  font-style: italic;
}

/* Card data rows */
.probe-card-data {
  padding: 15px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.probe-data-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
}

.probe-data-row .label {
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
}

.probe-data-row .value {
  color: var(--text-primary);
  font-size: 0.95rem;
  font-weight: 600;
  text-align: right;
}

/* Card actions (buttons) */
.probe-card-actions {
  padding: 12px 15px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  display: flex;
  gap: 10px;
  justify-content: stretch;
}

.probe-card-actions button {
  flex: 1;
  padding: 10px 16px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  transition: all 0.2s;
}

.btn-toggle {
  background-color: var(--accent-primary);
  color: white;
}

.btn-toggle:hover {
  background-color: var(--accent-secondary);
  transform: translateY(-1px);
}

.btn-remove {
  background-color: var(--error-color);
  color: white;
}

.btn-remove:hover {
  background-color: #d32f2f;
  transform: translateY(-1px);
}

.probe-card-actions button:active {
  transform: scale(0.98);
}

/* Battery color coding */
.low-battery {
  color: var(--error-color) !important;
  font-weight: bold;
}

.medium-battery {
  color: var(--warning-color) !important;
  font-weight: bold;
}

.good-battery {
  color: var(--success-color) !important;
  font-weight: bold;
}

/* Pairing button styling */
.button {
  display: inline-block;
  padding: 12px 30px;
  font-size: 16px;
  cursor: pointer;
  text-align: center;
  color: white;
  /* background-color: var(--accent-primary); */
  background: linear-gradient(135deg, #021b79 0%, #0575e6 100%);
  border: none;
  border-radius: 8px;
  box-shadow: 0 4px 8px var(--shadow);
  margin-top: 5px;
  font-weight: 600;
  transition: all 0.2s;
}

.button:hover {
  /* background-color: var(--accent-secondary); */
  background: linear-gradient(135deg, #021b79 0%, #0575e6 80%);
  transform: translateY(-1px);
  box-shadow: 0 6px 12px var(--shadow);
}

.button:active {
  transform: translateY(0);
  box-shadow: 0 2px 4px var(--shadow);
}

/* Probe type indicators */
.probe-type-grain {
  color: var(--warning-color);
  font-weight: bold;
}

.probe-type-ambient {
  color: var(--info-color);
  font-weight: bold;
}

.probe-type-rh {
  color: #9c27b0; /* Purple color for RH sensors */
  font-weight: bold;
}

.probe-type-rr {
  color: #00897b; /* Teal for DTC3-WRR Wireless Remote Relay boards */
  font-weight: bold;
}

/* ============================================================================
   PROTOCOL 2.1 — AMBIENT RH & CO2 THRESHOLDS
   ============================================================================
   Applied by buildProbeCards() (per-probe rows) and the dashboard JS
   (averaged tiles) to highlight readings that have crossed advisory or
   alert thresholds. Mirrors the low-/medium-/good-battery pattern so the
   colour language is consistent.

   RH thresholds (grain headspace):
     >= 75%   warn  (condensation/mould risk in stored grain)
     >= 85%   alert (active condensation risk)
   CO2 thresholds (grain headspace):
     >= 1000 ppm  warn  (early respiration / insect activity)
     >= 5000 ppm  alert (high microbial / occupational concern)
   These are advisory only — adjust in buildProbeCards() AND script.js
   (updateWirelessAggregateTiles) if your crop / region differs.

   The classes attach to either .value (probe cards) or a free span
   (dashboard tiles), so the colour rules are intentionally not scoped
   to a parent selector.
*/
.rh-warn,
.co2-warn {
  color: var(--warning-color) !important;
  font-weight: bold;
}

.rh-alert,
.co2-alert {
  color: var(--error-color) !important;
  font-weight: bold;
}

/* New label colour so per-probe ambient/CO2 rows are visually grouped */
.probe-data-row .label.ambient-label {
  color: var(--info-color);
}

.probe-data-row .label.co2-label {
  color: #00897b;  /* teal — distinguishes from grain/ambient/RH colours */
}

/* Dashboard aggregate tiles for ambient-RH and CO2 — small "from N probes"
   helper text under the main value, in the same style as the existing
   .update-time hint at the bottom of the dashboard. */
.probe-count-note {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* ============================================================================
   CENTERED INPUTS
   ============================================================================ */
.centered-input {
  text-align: center;
}

/* ============================================================================
   TOAST NOTIFICATIONS
   ============================================================================ */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
}

.toast {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-left: 4px solid var(--success-color);
  border-radius: 8px;
  box-shadow: 0 4px 12px var(--shadow);
  min-width: 300px;
  max-width: 400px;
  transform: translateX(400px);
  opacity: 0;
  transition: all 0.3s ease-in-out;
}

.toast.show {
  transform: translateX(0);
  opacity: 1;
}

.toast-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 15px;
  background-color: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  border-radius: 8px 8px 0 0;
}

.toast-title {
  color: var(--text-primary);
  font-size: 1rem;
  font-weight: 600;
}

.toast-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0;
  width: 25px;
  height: 25px;
  line-height: 1;
}

.toast-close:hover {
  color: var(--text-primary);
}

.toast-body {
  padding: 15px;
  color: var(--text-primary);
  font-size: 0.95rem;
}

.toast.success {
  border-left-color: var(--success-color);
}

.toast.error {
  border-left-color: var(--error-color);
}

.toast.warning {
  border-left-color: var(--warning-color);
}

/* ============================================================================
   PULSATING STATUS INDICATORS
   ============================================================================ */
.status-on-yellow {
  color: #ffeb3b !important;
  font-weight: bold;
  animation: pulse-yellow 1.5s infinite;
}

.status-on-green {
  color: #4caf50 !important;
  font-weight: bold;
  animation: pulse-green 1.5s infinite;
}

@keyframes pulse-yellow {
  0%,
  100% {
    opacity: 1;
    text-shadow: 0 0 10px #ffeb3b;
  }
  50% {
    opacity: 0.7;
    text-shadow: 0 0 5px #ffeb3b;
  }
}

@keyframes pulse-green {
  0%,
  100% {
    opacity: 1;
    text-shadow: 0 0 10px #4caf50;
  }
  50% {
    opacity: 0.7;
    text-shadow: 0 0 5px #4caf50;
  }
}

/* ============================================================================
   CONNECTION STATUS INDICATOR
   ============================================================================ */
.connection-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
  background-color: var(--success-color);
  animation: pulse-dot 1.5s ease-in-out infinite;
}

.connection-dot.disconnected {
  background-color: #888;
  animation: none;
}

@keyframes pulse-dot {
  0%,
  100% {
    opacity: 1;
    box-shadow: 0 0 4px var(--success-color);
  }
  50% {
    opacity: 0.5;
    box-shadow: 0 0 8px var(--success-color);
  }
}

/* ===== SecureOTA card ===== */
.ota-card {
  padding: 0.8em;
  border: 1px solid var(--accent-primary);
  border-radius: 6px;
  margin-top: 1em;
}
.ota-title {
  margin: 0 0 0.4em 0;
  font-size: 1.05em;
  color: var(--accent-primary);
}
.ota-button {
  margin: 0.6em 0;
  padding: 0.6em 1em;
  width: 100%;
  background: var(--accent-primary);
  color: #fff;
  border: none;
  border-radius: 4px;
  font: inherit;
  cursor: pointer;
}
.ota-button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.ota-bar {
  width: 100%;
  height: 8px;
  background: rgba(128, 128, 128, 0.25);
  border-radius: 4px;
  overflow: hidden;
  margin-top: 0.4em;
}
.ota-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--accent-primary);
  transition: width 0.2s ease;
}
.ota-status {
  margin-top: 0.4em;
  font-size: 0.9em;
  min-height: 1.2em;
}
.ota-status.ok   { color: var(--success-color, #4caf50); }
.ota-status.warn { color: #e9a700; }
.ota-status.fail { color: #e35454; }

/* ============================================================================
   PWA SHELL — login, device picker, header, banners, sync pill
   Styled to match the DTC3 controller palette (blue accent + gradient bands).
   Appended on top of the controller's own stylesheet (above).
   ============================================================================ */

:root {
  --grad-blue: linear-gradient(135deg, #021b79 0%, #0575e6 100%);
}

/* Make the body a flex column app-shell instead of the controller's
   centered inline-block document. */
html { display: block; text-align: left; }
body {
  max-width: 100%;
  display: flex;
  flex-direction: column;
}
#app {
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* App header */
.app-header {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  display: flex;
  align-items: center;
  gap: 8px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.app-header .back-btn {
  background: none;
  border: none;
  color: var(--accent-primary);
  font-size: 1.4rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  line-height: 1;
}
.app-header .back-btn:active { background: var(--bg-card); }
.header-actions { display: flex; gap: 8px; align-items: center; }

.main-content {
  flex: 1;
  padding: 16px 14px calc(72px + env(safe-area-inset-bottom));
  overflow-y: auto;
}

/* Screens */
.screen { display: none; }
.screen.active { display: block; }
#screen-login.active { display: flex; }

/* Login */
#screen-login {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
  background: var(--bg-primary);
  overflow: hidden;
  text-align: center;
}
.login-stripe {
  position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: var(--grad-blue);
}
.login-wrap {
  position: relative; z-index: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  flex: 1; padding: 32px 28px 40px;
}
.login-logo-wrap {
  display: flex; flex-direction: column; align-items: center;
  margin-bottom: 32px; gap: 8px;
}
.title-product-logo { max-height: 90px; object-fit: contain; }
.login-wordmark {
  font-weight: 800; letter-spacing: 0.01em;
  color: var(--accent-primary); text-align: center; line-height: 1.05;
}
.login-sub-tag {
  font-size: 1rem; color: var(--text-secondary);
  text-align: center; margin-top: 2px;
}
.login-divider {
  width: 100%; max-width: 320px; height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent-primary), transparent);
  opacity: 0.5; margin-bottom: 28px;
}
.login-form { width: 100%; max-width: 320px; text-align: left; }
.form-group { margin-bottom: 14px; }
.form-group label {
  display: block; font-size: 0.75rem; font-weight: 600;
  letter-spacing: 0.05em; text-transform: uppercase;
  color: var(--text-secondary); margin-bottom: 6px;
}
.form-group input { width: 100%; max-width: 100%; margin: 0; }
.btn-primary {
  width: 100%; padding: 14px; margin-top: 8px;
  background: var(--grad-blue); color: #fff; border: none;
  border-radius: 6px; font-size: 1rem; font-weight: 700;
  cursor: pointer; box-shadow: 0 2px 8px var(--shadow);
  transition: transform 0.2s, box-shadow 0.2s;
}
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.login-error {
  margin-top: 12px; padding: 10px 14px;
  background: rgba(244, 67, 54, 0.12);
  border: 1px solid var(--error-color); border-radius: 6px;
  color: var(--error-color); font-size: 0.9rem;
  text-align: center; display: none;
}

/* Device picker cards */
.devices-grid { display: flex; flex-direction: column; gap: 14px; }
.device-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  box-shadow: 0 2px 8px var(--shadow);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
  text-align: left;
}
.device-card:hover { transform: translateY(-2px); box-shadow: 0 6px 16px var(--shadow); }
.device-card:active { border-color: var(--accent-primary); }
.device-card-head {
  background: var(--grad-blue);
  color: #fff;
  padding: 12px 16px;
  display: flex; align-items: center; gap: 10px;
}
.device-card-head .dc-name {
  flex: 1; font-size: 1.2rem; font-weight: 700;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.device-card-head .dc-rename, .device-card-head .dc-chevron {
  background: none; border: none; color: #fff; cursor: pointer;
  font-size: 1.1rem; padding: 2px 4px; opacity: 0.9;
}
.device-card-body { padding: 14px 16px; }
.dc-status {
  display: flex; align-items: center; gap: 8px;
  font-size: 0.9rem; color: var(--text-secondary); margin-bottom: 12px;
}
.dc-readings { display: flex; gap: 24px; }
.dc-reading { display: flex; flex-direction: column; }
.dc-reading .dc-val { font-size: 1.8rem; font-weight: 700; color: var(--accent-primary); line-height: 1; }
.dc-reading .dc-lbl { font-size: 0.78rem; color: var(--text-secondary); margin-top: 4px; text-transform: uppercase; letter-spacing: 0.5px; }
.dc-fault {
  margin-top: 12px; padding: 8px 12px;
  background: var(--error-color); color: #fff;
  border-radius: 6px; font-size: 0.9rem; font-weight: 600;
  display: flex; align-items: center; gap: 8px;
}

/* Detail screen extras (reuses controller .status-grid / .temps / .motor / .faults) */
.detail-titlebar {
  background: var(--grad-blue); color: #fff;
  border-radius: 10px; padding: 14px 16px; margin-bottom: 8px;
  display: flex; align-items: center; gap: 10px;
  box-shadow: 0 2px 8px var(--shadow);
}
.detail-titlebar .dt-name { flex: 1; font-size: 1.3rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.detail-titlebar .dt-rename { background: none; border: none; color: #fff; font-size: 1.1rem; cursor: pointer; padding: 2px 6px; }
.detail-substatus {
  text-align: center; font-size: 0.85rem; color: var(--text-secondary);
  margin-bottom: 8px;
}

/* Local/remote card — text above the switch, stacked in a centered column */
.remote-card {
  background: var(--bg-card); border: 1px solid var(--border-color);
  border-radius: 10px; padding: 20px 16px; margin: 20px auto;
  box-shadow: 0 2px 8px var(--shadow);
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  text-align: center;
}
.remote-card .switch { flex-shrink: 0; }
.remote-card .rc-text { text-align: center; }
.remote-card .rc-title { font-size: 1.2rem; font-weight: 700; color: var(--accent-primary); }
.remote-card .rc-state { font-size: 0.95rem; color: var(--text-secondary); margin-top: 4px; }
.remote-card .rc-state.on { color: var(--success-color); font-weight: 600; }

/* Header hamburger menu */
.notif-menu-wrap { position: relative; }
.notif-menu {
  position: absolute; top: calc(100% + 6px); right: 0;
  min-width: 220px; background: var(--bg-card);
  border: 1px solid var(--border-color); border-radius: 10px;
  box-shadow: 0 8px 24px var(--shadow); padding: 6px;
  display: none; z-index: 1000;
}
.notif-menu.open { display: block; }
.notif-menu-header {
  padding: 8px 10px; font-size: 0.72rem; color: var(--text-secondary);
  letter-spacing: 0.05em; text-transform: uppercase;
  border-bottom: 1px solid var(--border-color); margin-bottom: 4px;
}
.notif-menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 10px; background: transparent; border: none;
  color: var(--text-primary); font-size: 0.9rem; text-align: left;
  border-radius: 6px; cursor: pointer;
}
.notif-menu-item:hover { background: var(--bg-secondary); }
.notif-menu-item .notif-item-label { flex: 1; }
.notif-menu-version {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px 4px; font-size: 0.7rem; color: var(--text-secondary);
  border-top: 1px solid var(--border-color); margin-top: 4px;
}

/* Banners */
.offline-banner, .stale-banner {
  padding: 8px 14px; font-size: 0.85rem; text-align: center; display: none;
}
.offline-banner {
  background: rgba(255, 152, 0, 0.15);
  border-bottom: 1px solid var(--warning-color); color: var(--warning-color);
}
.stale-banner {
  background: rgba(244, 67, 54, 0.16);
  border-bottom: 1px solid var(--error-color); color: var(--error-color);
}
.offline-banner.show, .stale-banner.show { display: block; }

/* Spinner / empty state */
.spinner-wrap { display: flex; align-items: center; justify-content: center; padding: 48px; }
.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border-color); border-top-color: var(--accent-primary);
  border-radius: 50%; animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.empty-state { text-align: center; padding: 48px 24px; color: var(--text-secondary); }
.empty-state-icon { font-size: 3rem; margin-bottom: 12px; opacity: 0.5; color: var(--accent-primary); }
.empty-state h3 { font-size: 1.1rem; margin-bottom: 6px; color: var(--text-primary); }

/* Sync pill / pull-to-refresh */
.sync-pill {
  position: fixed; bottom: 12px; left: 50%; transform: translateX(-50%);
  display: inline-flex; align-items: center; gap: 8px;
  background: rgba(36, 36, 36, 0.92);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  border: 1px solid var(--border-color); border-radius: 999px;
  padding: 5px 6px 5px 12px; font-size: 0.75rem; color: var(--text-secondary);
  z-index: 850; user-select: none;
}
.sync-pill .sync-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--success-color); box-shadow: 0 0 6px var(--success-color); }
.sync-pill.stale .sync-dot { background: var(--warning-color); box-shadow: 0 0 6px var(--warning-color); }
.sync-pill.offline .sync-dot { background: var(--error-color); box-shadow: 0 0 6px var(--error-color); }
#sync-pill-refresh {
  background: transparent; border: 1px solid var(--border-color);
  color: var(--accent-primary); border-radius: 50%;
  width: 24px; height: 24px; display: inline-flex; align-items: center;
  justify-content: center; cursor: pointer; padding: 0; font-size: 0.85rem;
}
#sync-pill-refresh.spinning i { animation: spin 0.8s linear infinite; }

.ptr-indicator {
  position: fixed; top: 0; left: 50%;
  transform: translate(-50%, -100%);
  background: var(--bg-card); border: 1px solid var(--border-color);
  border-radius: 0 0 14px 14px; padding: 8px 14px;
  font-size: 0.8rem; color: var(--text-secondary);
  display: flex; align-items: center; gap: 8px;
  z-index: 900; pointer-events: none; transition: transform 0.18s ease;
}
.ptr-indicator.visible { transform: translate(-50%, 0); }
.ptr-indicator.refreshing #ptr-icon { animation: spin 0.8s linear infinite; }

/* ── Wireless probe cards (ported from Store Guardian PWA) ─────────────────── */
/* Multi-probe → responsive column grid; single probe sits on its own row. */
.probe-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  margin-top: 12px;
  text-align: left;
}

.temp-stat-card {
  background: linear-gradient(135deg, #2f2f2f 0%, #242424 100%);
  border-radius: 10px;
  padding: 15px;
  border: 1px solid var(--border-color);
  box-shadow: 0 2px 8px var(--shadow);
  transition: all 0.3s;
}
.temp-stat-card.probe-offline { opacity: 0.55; border-color: var(--error-color); }
.temp-stat-content { text-align: left; }

.temp-stat-icon {
  width: 36px; height: 36px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem; flex-shrink: 0; color: #fff;
}
.temp-stat-icon.avg { background: linear-gradient(135deg, #021b79 0%, #0575e6 100%); }

.temp-stat-label {
  font-size: 0.85rem; color: var(--text-secondary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 110px;
}
.temp-stat-value {
  font-size: 1.7rem; font-weight: bold; color: var(--accent-primary); line-height: 1.2;
}
.temp-stat-value.hot  { color: #f44336; }
.temp-stat-value.warm { color: #ff9800; }
.temp-stat-value.cool { color: var(--accent-primary); }
.temp-stat-value.cold { color: #7ecfff; }

/* ONLINE / OFFLINE badge */
.probe-badge {
  font-size: 0.65rem; font-weight: 700; padding: 2px 8px; border-radius: 12px;
  text-transform: uppercase; letter-spacing: 0.5px; white-space: nowrap;
}
.probe-badge.online  { background: var(--success-color); color: #fff; }
.probe-badge.offline { background: #555; color: #ddd; }

/* SVG battery (matches SG dashboard) */
.battery-container { display: inline-flex; align-items: center; gap: 4px; vertical-align: middle; }
.batteryIcon { width: 35px; height: auto; flex-shrink: 0; }
.batteryLevel { transition: width 0.8s ease-in-out, fill 0.4s ease; }
.batteryText { font-size: 0.82rem; min-width: 32px; color: var(--text-primary); }

.probe-extras { font-size: 0.72rem; color: var(--text-secondary); margin-top: 6px; }
.probe-updated-time { font-size: 0.65rem; color: var(--text-secondary); margin-top: 4px; }

/* Section label between blocks */
.section-header {
  font-size: 0.78rem; font-weight: 700; color: var(--text-secondary);
  text-transform: uppercase; letter-spacing: 0.8px; margin: 20px 0 8px;
}
