/* Modern Dark Glassmorphism Styling System for Deye Inverter Dashboard */
:root {
  --bg-dark: #0f172a;
  --bg-card: rgba(30, 41, 59, 0.7);
  --bg-card-hover: rgba(51, 65, 85, 0.8);
  --border-card: rgba(255, 255, 255, 0.1);
  --primary-accent: #38bdf8;
  --solar-gold: #fbbf24;
  --battery-green: #34d399;
  --inverter-purple: #c084fc;
  --grid-cyan: #22d3ee;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --danger: #f87171;
  --success: #4ade80;
  --color-red: #ef4444;
  --color-light-gray: #f8fafc;
  --color-purple: #a855f7;
  --color-gold: #eab308;
  --color-green: #22c55e;
  --color-dark-gray: #94a3b8;
  /* EV teal (#800, Design C's dark-theme EV colour): the EV node, its line and its stats rows. */
  --color-ev: #2dd4bf;
  --font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

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

body {
  background: radial-gradient(circle at top left, #1e1b4b 0%, #0f172a 50%, #020617 100%);
  color: var(--text-main);
  font-family: var(--font-family);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header & Navigation Bar */
.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.2rem 2rem;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-card);
  position: sticky;
  top: 0;
  z-index: 100;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text-main);
  text-decoration: none;
  letter-spacing: -0.5px;
}

/* The Sunkeep mark (_sunkeep_mark.html): ink is the text colour, the sun the on-dark amber. */
.brand .sk-mark {
  flex: none;
  width: 28px;
  height: 28px;
}

.brand .sk-sun { color: #f5b32e; }

.nav-links {
  display: flex;
  gap: 0.5rem;
  list-style: none;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1.2rem;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.95rem;
  font-weight: 500;
  border-radius: 8px;
  transition: all 0.2s ease-in-out;
}

.nav-item:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.05);
}

.nav-item.active {
  color: var(--primary-accent);
  background: rgba(56, 189, 248, 0.12);
  border: 1px solid rgba(56, 189, 248, 0.25);
}

/* Navigation Dropdown Menu (Settings Cog) */
.nav-dropdown {
  position: relative;
}

.dropdown-toggle {
  background: transparent;
  border: none;
  cursor: pointer;
  font-family: inherit;
}

.dropdown-menu {
  position: absolute;
  top: calc(100% + 0.5rem);
  right: 0;
  background: rgba(15, 23, 42, 0.95);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-card);
  border-radius: 10px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
  display: none;
  flex-direction: column;
  min-width: 160px;
  padding: 0.5rem;
  z-index: 200;
}

.nav-dropdown:hover .dropdown-menu,
.nav-dropdown.is-open .dropdown-menu {
  display: flex;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 1rem;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  border-radius: 6px;
  transition: all 0.2s ease;
}

.dropdown-item:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.08);
}

.dropdown-item.active {
  color: var(--primary-accent);
  background: rgba(56, 189, 248, 0.12);
}


/* Main Container Layout */
.container {
  max-width: 1350px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
  width: 100%;
  flex: 1;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 2rem;
}

.page-title {
  font-size: 1.8rem;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.page-subtitle {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-top: 0.3rem;
}

.timestamp-badge {
  font-size: 0.85rem;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-card);
  padding: 0.4rem 0.9rem;
  border-radius: 6px;
}

.timestamp-badge.online {
  color: var(--success);
  border-color: var(--success);
  background-color: rgba(74, 222, 128, 0.15);
}

.timestamp-badge.offline {
  color: var(--danger);
  border-color: var(--danger);
  background-color: rgba(248, 113, 113, 0.15);
}

/* Card Grid Layout */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2.5rem;
}

.stat-card {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-card);
  border-radius: 14px;
  padding: 1.5rem;
  transition: transform 0.2s ease, border-color 0.2s ease;
  position: relative;
  overflow: hidden;
}

.stat-card:hover {
  transform: translateY(-3px);
  border-color: rgba(255, 255, 255, 0.2);
}

.card-label {
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 0.75rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-value {
  font-size: 2.2rem;
  font-weight: 700;
  letter-spacing: -1px;
  color: var(--text-main);
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
}

.card-unit {
  font-size: 1rem;
  font-weight: 500;
  color: var(--text-muted);
}

.card-subtext {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 0.75rem;
}

/* Specific Accent Colors for Stat Cards */
.solar-card { border-top: 3px solid var(--solar-gold); }
.battery-card { border-top: 3px solid var(--battery-green); }
.inverter-card { border-top: 3px solid var(--inverter-purple); }
.grid-card { border-top: 3px solid var(--grid-cyan); }

/* Table Container */
.table-container {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-card);
  border-radius: 14px;
  padding: 1.5rem;
  margin-bottom: 2rem;
}

.table-title {
  font-size: 1.15rem;
  font-weight: 600;
  margin-bottom: 1rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

th, td {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

th {
  color: var(--text-muted);
  font-size: 0.85rem;
  text-transform: uppercase;
  font-weight: 600;
}

td {
  font-size: 0.95rem;
}

tr:last-child td {
  border-bottom: none;
}

.controls-bar {
  display: flex;
  gap: 1rem;
  align-items: center;
  margin-bottom: 1.5rem;
}

.select-input, .btn {
  background: rgba(30, 41, 59, 0.9);
  border: 1px solid var(--border-card);
  color: var(--text-main);
  padding: 0.55rem 1rem;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.9rem;
  outline: none;
  cursor: pointer;
}

.btn:hover {
  background: rgba(51, 65, 85, 1);
}

/* Log Container */
.log-box {
  background: #020617;
  border: 1px solid var(--border-card);
  border-radius: 10px;
  padding: 1.25rem;
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 0.85rem;
  line-height: 1.6;
  color: #e2e8f0;
  max-height: 600px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

.log-line {
  padding: 0.15rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.02);
}

.log-line.info { color: #38bdf8; }
.log-line.warning { color: #fbbf24; }
.log-line.error { color: #f87171; }
.log-line.debug { color: #94a3b8; }

/* ----------------------------------------------------
   Power Flow Diagram Layout & Circular Nodes (Responsive)
   ---------------------------------------------------- */
:root {
  /* Node diameters scale with #dashboard-container's own width (140px/100px
     at its 900px max-width, i.e. 15.56%/11.11%) so the diagram can never
     overlap itself, with a floor so text stays legible on small phones. */
  --node-size-lg-max: 140px;
  --node-size-lg-min: 68px;
  --node-size-sm-max: 100px;
  --node-size-sm-min: 52px;
}

#dashboard-container {
    position: relative;
    width: 100%;
    max-width: 900px;
    aspect-ratio: 900 / 650;
    margin: 1rem auto 2rem auto;
}

.node {
    position: absolute;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background-color: #16213e;
    border: 4px solid;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.5), 0 4px 6px -2px rgba(0, 0, 0, 0.3);
    transition: transform 0.3s ease, border-color 0.3s ease, color 0.3s ease, opacity 0.3s ease;
    z-index: 10;
}

.node:hover {
    transform: translate(-50%, -50%) scale(1.05);
}

.node-title {
    font-size: 1.05rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: -0.3px;
    margin-bottom: 0.2rem;
}

.node-value {
    font-size: 1.05rem;
    font-weight: 700;
    margin-top: 0.15rem;
}

.node-subtext {
    font-size: 0.75rem;
    opacity: 0.75;
    /* A subtext of more than one line (A2's grid charger, the EV's mode and session)
       stays centred and inside the circle. */
    text-align: center;
    max-width: 80%;
}

.node-grid {
    border-color: var(--color-red);
    color: var(--color-red);
    width: clamp(var(--node-size-lg-min), 15.56%, var(--node-size-lg-max));
    aspect-ratio: 1;
}

.node-charger {
    border-color: var(--color-dark-gray);
    color: var(--color-dark-gray);
    width: clamp(var(--node-size-sm-min), 11.11%, var(--node-size-sm-max));
    aspect-ratio: 1;
    opacity: 0.5;
}

.node-charger.is-online {
    border-color: var(--color-red);
    color: var(--color-red);
    opacity: 1;
}

/* Charger/Generator are the small nodes -- their text needs to run smaller
   than the default .node-title/.node-value/.node-subtext sizing at every
   breakpoint, not just on mobile, so it fits the smaller circle. */
.node-charger .node-title,
.node-generator .node-title,
.node-ev .node-title {
    font-size: 0.7rem;
    margin-bottom: 0;
}

.node-charger .node-value,
.node-generator .node-value,
.node-ev .node-value {
    font-size: 0.9rem;
    margin-top: 0;
}

.node-charger .node-subtext,
.node-generator .node-subtext,
.node-ev .node-subtext {
    font-size: 0.7rem;
}

.node-battery {
    border-color: var(--color-purple);
    color: var(--color-purple);
    width: clamp(var(--node-size-lg-min), 15.56%, var(--node-size-lg-max));
    aspect-ratio: 1;
}

.node-inverter {
    border-color: var(--color-light-gray);
    color: var(--color-light-gray);
    width: clamp(var(--node-size-lg-min), 15.56%, var(--node-size-lg-max));
    aspect-ratio: 1;
}

.node-solar {
    border-color: var(--color-gold);
    color: var(--color-gold);
    width: clamp(var(--node-size-lg-min), 15.56%, var(--node-size-lg-max));
    aspect-ratio: 1;
}

.node-generator {
    border-color: var(--color-dark-gray);
    color: var(--color-dark-gray);
    width: clamp(var(--node-size-sm-min), 11.11%, var(--node-size-sm-max));
    aspect-ratio: 1;
    opacity: 0.5;
}

.node-generator.is-online {
    border-color: var(--color-red);
    color: var(--color-red);
    opacity: 1;
}

.node-house {
    border-color: var(--color-green);
    color: var(--color-green);
    width: clamp(var(--node-size-lg-min), 15.56%, var(--node-size-lg-max));
    aspect-ratio: 1;
}

.node-ev {
    border-color: var(--color-ev);
    color: var(--color-ev);
    width: clamp(var(--node-size-sm-min), 11.11%, var(--node-size-sm-max));
    aspect-ratio: 1;
}

/* Two or more EV chargers: one line per charger in the node (#829), never wrapped, so
   the circle keeps its shape. A phone drops each line's word (.node-subtext-more). */
.node-ev .node-subtext.ev-node-lines {
    max-width: none;
}

.ev-node-line {
    white-space: nowrap;
    line-height: 1.1;
    font-size: 0.62rem;
}

#flow-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    pointer-events: none;
}

.line-grid { stroke: var(--color-red); }
.line-solar { stroke: var(--color-gold); }
.line-charger { stroke: var(--color-red); }
.line-battery { stroke: var(--color-purple); }
.line-inverter-house { stroke: var(--color-green); }
.line-generator { stroke: var(--color-red); }
.line-ev { stroke: var(--color-ev); }

.dial-container {
    position: absolute;
    top: -10px;
    left: -10px;
    width: calc(100% + 20px);
    height: calc(100% + 20px);
    pointer-events: none;
    z-index: 5;
}

.dial-track {
    fill: none;
    stroke: #334155;
    stroke-width: 6;
}

.dial-progress {
    fill: none;
    stroke-width: 6;
    stroke-linecap: round;
    transform-box: fill-box;
    transform-origin: center;
    transform: rotate(-90deg);
    transition: stroke-dasharray 0.5s ease-out;
}

.dial-solar .dial-progress { stroke: #f59e0b; }
.dial-inverter .dial-progress { stroke: #3b82f6; }
.dial-battery .dial-progress { stroke: #c084fc; }

.node-has-dial {
    border: none;
    background-color: #1e293b;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.5);
    overflow: visible;
}

.flow-line {
  stroke-dasharray: 4, 4;
  animation: flow-dash 1.2s linear infinite;
}

/* A wire that exists but carries nothing measured: same colour, held still and dimmed.
   drawPath drops the arrowhead too -- see its isIdle argument. */
.flow-line--idle {
  animation: none;
  stroke-dasharray: none;
  opacity: 0.35;
}

@keyframes flow-dash {
  from { stroke-dashoffset: 24; }
  to { stroke-dashoffset: 0; }
}

/* Today's Stats Table Container */
.todays-stats-wrapper {
  display: flex;
  justify-content: center;
  margin-top: 1rem;
}

/* The EV panel (#800): opened from the EV node, one .ev-unit block per charger, filled
   by renderEvChargers in main.js. Anchored under the node: `top` is the node's centre
   (85% of the diagram's height) and the margin its radius plus a gap -- a margin's
   percentage is of the container's WIDTH, which is what the node's diameter is sized
   from (.node-ev). Above the nodes, and never wider than the viewport. */
.ev-panel {
  position: absolute;
  top: 85%;
  left: 50%;
  margin-top: calc(clamp(var(--node-size-sm-min), 11.11%, var(--node-size-sm-max)) / 2 + 0.75rem);
  transform: translateX(-50%);
  width: min(380px, calc(100vw - 2rem));
  z-index: 20;
  padding: 1rem 1.25rem;
  background: #1e293b;
  border: 1px solid var(--color-ev);
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.ev-panel[hidden] {
  display: none;
}

.ev-panel-close {
  position: absolute;
  top: 0.4rem;
  right: 0.6rem;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
}

.ev-panel-body {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.ev-unit + .ev-unit {
  border-top: 1px solid var(--border-card);
  padding-top: 1rem;
}

.ev-unit-name {
  font-weight: 700;
  margin-right: 1.5rem;
}

.ev-unit-stats {
  margin-top: 0.25rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.ev-unit-mode {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.75rem;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.ev-mode-select {
  padding: 0.35rem 0.6rem;
}

.ev-unit-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  margin-top: 0.75rem;
}

.ev-stop-btn {
  margin-top: 0;
}

.ev-unit-note {
  margin-top: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.todays-stats-container {
  max-width: 550px;
  width: 100%;
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-card);
  border-radius: 16px;
  padding: 1.75rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.todays-stats-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}

.todays-stats-header .table-title {
  flex: 1;
  text-align: center;
  margin-bottom: 0;
}

.stats-nav-btn {
  background: rgba(30, 41, 59, 0.9);
  border: 1px solid var(--border-card);
  color: var(--text-main);
  width: 2rem;
  height: 2rem;
  border-radius: 8px;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
}

.stats-nav-btn:hover:not(:disabled) {
  background: rgba(51, 65, 85, 1);
}

.stats-nav-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.todays-stats-table td {
  padding: 1rem 1.25rem;
  font-size: 1.05rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.stat-highlight {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.5px;
}

/* A Today's Stats row that expands to its breakdown (#757-#759, #831): the whole label is
   the button, so it is an easy tap on a phone. */
.stats-expander {
  background: none;
  border: none;
  padding: 0;
  color: inherit;
  font: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  text-align: left;
}

.stats-caret {
  display: inline-block;
  color: var(--text-muted);
  transition: transform 0.15s ease;
}

.stats-expander[aria-expanded="true"] .stats-caret {
  transform: rotate(90deg);
}

.todays-stats-table tr.stats-sub td {
  padding-top: 0.5rem;
  padding-bottom: 0.5rem;
  font-size: 0.95rem;
  color: var(--text-muted);
}

.todays-stats-table tr.stats-sub td:first-child {
  padding-left: 2.5rem;
}

/* Each stat in its node's colour (.node-solar, .node-house, .node-battery, ...), so a
   figure reads as belonging to its node. */
.solar-txt { color: var(--color-gold); }
.house-txt { color: var(--color-green); }
.battery-txt { color: var(--color-purple); }
.grid-txt { color: var(--color-red); }
.generator-txt { color: var(--color-red); }
.ev-txt { color: var(--color-ev); }

/* ----------------------------------------------------
   Mobile Responsiveness Media Queries
   ---------------------------------------------------- */
@media (max-width: 640px) {
  .navbar {
    padding: 0.8rem 1rem;
    flex-direction: column;
    gap: 0.75rem;
    align-items: flex-start;
  }

  .nav-links {
    width: 100%;
    justify-content: space-between;
  }

  .nav-item {
    padding: 0.4rem 0.6rem;
    font-size: 0.85rem;
  }

  .container {
    padding: 1rem 0.6rem;
  }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
    margin-bottom: 1.25rem;
  }

  .page-title {
    font-size: 1.4rem;
  }

  .chart-wrapper {
    height: 200px;
  }

  .node-title {
    font-size: 0.76rem;
    margin-bottom: 0.1rem;
  }

  .node-value {
    font-size: 0.85rem;
    margin-top: 0.1rem;
  }

  .node-subtext {
    font-size: 0.65rem;
  }

  .node-subtext-more {
    display: none;
  }

  /* A node is its label and value only (#834, VOCABULARY.md §6): the line animation and
     the node's colour carry direction and state. The multi-charger EV lines are values,
     so they stay, each without its word (.node-subtext-more above). */
  .node-words:not(.ev-node-lines) {
    display: none;
  }

  .node-charger .node-title,
  .node-generator .node-title,
  .node-ev .node-title {
    font-size: 0.6rem;
  }

  .node-charger .node-value,
  .node-generator .node-value,
  .node-ev .node-value {
    font-size: 0.72rem;
  }

  .node-charger .node-subtext,
  .node-generator .node-subtext,
  .node-ev .node-subtext {
    font-size: 0.58rem;
  }

  /* "CHARGER" and a kW figure are the widest text in the smallest circle (#834). */
  .node-charger .node-title {
    font-size: 0.5rem;
  }

  /* "GENERATOR" is wider still. */
  .node-generator .node-title {
    font-size: 0.44rem;
  }

  .node-charger .node-value {
    font-size: 0.62rem;
    white-space: nowrap;
  }

  .ev-node-line {
    font-size: 0.5rem;
  }

  .todays-stats-container {
    padding: 1rem;
  }

  .todays-stats-table td {
    padding: 0.75rem 0.6rem;
    font-size: 0.9rem;
  }

  .todays-stats-table tr.stats-sub td {
    font-size: 0.85rem;
  }

  .todays-stats-table tr.stats-sub td:first-child {
    padding-left: 1.75rem;
  }

  /* On a phone the EV panel is a sheet across the bottom of the screen: the diagram is
     too narrow to hang a panel off one node without covering the rest. */
  .ev-panel {
    position: fixed;
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    margin-top: 0;
    transform: none;
    width: auto;
    max-height: 70vh;
    overflow-y: auto;
    z-index: 1000;
    border-radius: 16px 16px 0 0;
    border-bottom: none;
  }

  .stat-highlight {
    font-size: 1rem;
  }
}

@media (max-width: 380px) {
  .node-title {
    font-size: 0.68rem;
  }

  .node-value {
    font-size: 0.75rem;
  }

  .node-subtext {
    font-size: 0.58rem;
  }

  /* Not the charger's or the generator's: their sizes from the 640 px rules are already
     the sizes that fit. */
  .node-ev .node-title {
    font-size: 0.52rem;
  }

  .node-charger .node-value,
  .node-generator .node-value,
  .node-ev .node-value {
    font-size: 0.62rem;
  }

  /* Charger's extra "(DC Output)" line is the tightest fit -- drop it at
     the smallest breakpoint so the node stays circular instead of stretching. The
     multi-charger EV lines are values, so they stay, as at 640 px (#834). */
  .node-charger .node-subtext,
  .node-generator .node-subtext,
  .node-ev .node-subtext:not(.ev-node-lines) {
    display: none;
  }
}

/* Footer */
footer {
  text-align: center;
  padding: 1.5rem;
  color: var(--text-muted);
  font-size: 0.85rem;
  border-top: 1px solid var(--border-card);
  margin-top: auto;
}

/* The running-version line (#391): muted by default -- it is a reference, not news --
   and amber only when web and backend disagree, which is the one case worth noticing. */
.version-line {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.78rem;
}

.version-line.version-mismatch {
  color: var(--solar-gold);
}

.version-line.version-mismatch::before {
  content: "⚠ ";
}

/* ==========================================================================
   Devices Page Styles
   ========================================================================== */
.devices-container {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.devices-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 1.5rem;
  align-items: start;
}

@media (max-width: 900px) {
  .devices-layout {
    grid-template-columns: 1fr;
  }
}

.sidebar-card {
  padding: 1rem;
}

.devices-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-top: 0.75rem;
}

.device-group-header {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 700;
  margin-bottom: 0.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  padding-bottom: 0.25rem;
}

.device-item-card {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem;
  border-radius: var(--border-radius-sm, 8px);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  cursor: pointer;
  transition: all 0.2s ease;
}

.device-item-card:hover {
  background: rgba(255, 255, 255, 0.07);
  border-color: rgba(255, 255, 255, 0.2);
  transform: translateY(-1px);
}

.active-device-card {
  background: rgba(59, 130, 246, 0.15) !important;
  border-color: var(--accent-blue, #3b82f6) !important;
  box-shadow: 0 0 12px rgba(59, 130, 246, 0.25);
}

.device-item-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.category-inverter { background: rgba(245, 158, 11, 0.2); color: #f59e0b; }
.category-controller { background: rgba(59, 130, 246, 0.2); color: #3b82f6; }
.category-sensor { background: rgba(16, 185, 129, 0.2); color: #10b981; }

.device-item-name {
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--text-primary, #f8fafc);
}

.device-item-sub {
  font-size: 0.75rem;
  color: var(--text-muted, #94a3b8);
  margin-top: 2px;
}

.active-device-header-card {
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.25rem;
}

.active-device-title {
  font-size: 1.35rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.active-device-meta {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.badge-category {
  padding: 0.2rem 0.6rem;
  font-size: 0.72rem;
  border-radius: 4px;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.category-badge-inverter { background: rgba(245, 158, 11, 0.25); color: #fbbf24; border: 1px solid rgba(245, 158, 11, 0.4); }
.category-badge-controller { background: rgba(59, 130, 246, 0.25); color: #60a5fa; border: 1px solid rgba(59, 130, 246, 0.4); }
.category-badge-sensor { background: rgba(16, 185, 129, 0.25); color: #34d399; border: 1px solid rgba(16, 185, 129, 0.4); }

/* Which device a resolved battery value came from (#211). Sized off .badge-category
   above but deliberately quieter -- it sits inside a status row, next to the number
   it annotates, and must not compete with it. */
.source-badge {
  padding: 0.1rem 0.4rem;
  margin-left: 0.4rem;
  font-size: 0.68rem;
  border-radius: 4px;
  letter-spacing: 0.02em;
  background: rgba(148, 163, 184, 0.18);
  color: var(--text-muted);
  border: 1px solid rgba(148, 163, 184, 0.3);
  white-space: nowrap;
}

/* Every source stale: the number is still the best available, so it is shown -- but
   amber, matching the warning vocabulary the divergence banner uses. */
.source-badge.stale {
  background: rgba(245, 158, 11, 0.2);
  color: #fbbf24;
  border-color: rgba(245, 158, 11, 0.4);
}

.divergence-banner {
  margin: 0 0 0.75rem;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  font-size: 0.85rem;
  background: rgba(245, 158, 11, 0.12);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.35);
}

/* Home-page site alerts (#258). Same shape as the divergence banner deliberately -- a
   warning should look like a warning wherever it appears -- but a shade heavier, since
   these carry a deadline rather than a discrepancy. Two severities: `warning` reuses the
   amber vocabulary above, `error` is red for the one that means the site goes dark. */
.site-alert {
  margin: 0 auto 0.75rem;
  padding: 0.6rem 0.9rem;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 600;
  text-align: center;
  max-width: 900px;
}

.site-alert-warning {
  background: rgba(245, 158, 11, 0.12);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.35);
}

.site-alert-error {
  background: rgba(239, 68, 68, 0.12);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.4);
}

/* Info (#791): something the system did on the user's behalf, not a fault -- the blue of
   the diagnostics page's `.finding-info`, so one severity looks the same on both pages. */
.site-alert-info {
  background: rgba(96, 165, 250, 0.12);
  color: #93c5fd;
  border: 1px solid rgba(96, 165, 250, 0.35);
}

/* A row's plain-language second line (#791), under the bold title. */
.site-alert-detail {
  margin-top: 0.25rem;
  font-weight: 400;
}

.site-alert-actions {
  margin-top: 0.4rem;
}

/* The notice's local Dismiss, dressed like the emergency event's. */
.site-alert-dismiss {
  background: transparent;
  border: 1px solid currentColor;
  color: inherit;
  padding: 0.2rem 0.6rem;
  font-size: 0.8rem;
}

/* Generator run advice card (#297, rendered #306). Deliberately the site-alert amber --
   it is the same warning as the banner above it, in structured form -- but left-aligned
   fields rather than a centred sentence, because this is the copy someone acts on. */
.generator-advice {
  margin: 0 auto 0.75rem;
  padding: 0.6rem 0.9rem;
  border-radius: 6px;
  font-size: 0.9rem;
  max-width: 900px;
  background: rgba(245, 158, 11, 0.12);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.35);
}

.generator-advice-title {
  font-weight: 700;
  margin-bottom: 0.35rem;
}

.generator-advice-fields {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1.5rem;
}

.generator-advice-label {
  font-weight: 700;
  margin-right: 0.4rem;
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  opacity: 0.8;
}

.generator-advice-shortfall {
  margin-top: 0.35rem;
  color: #f87171;
  font-weight: 600;
}

/* How old the advice above is, when nothing is recomputing it (#330). Muted: it
   qualifies the card rather than competing with the deadline on it. */
.generator-advice-stale {
  margin-top: 0.35rem;
  font-size: 0.85rem;
  opacity: 0.75;
}

.generator-advice-cleared {
  margin: 0 auto 0.75rem;
  padding: 0.6rem 0.9rem;
  border-radius: 6px;
  font-size: 0.9rem;
  text-align: center;
  max-width: 900px;
  background: rgba(59, 130, 246, 0.10);
  color: #93c5fd;
  border: 1px solid rgba(59, 130, 246, 0.3);
}

/* Storm prep (#344). Mirrors .generator-advice's shape -- active is the same amber
   warning, structured; the armed-but-idle line below is quiet, like .generator-advice-
   cleared, because "nothing is happening yet" is not a warning. */
.emergency-mode-active {
  margin: 0 auto 0.75rem;
  padding: 0.6rem 0.9rem;
  border-radius: 6px;
  font-size: 0.9rem;
  max-width: 900px;
  background: rgba(245, 158, 11, 0.12);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.35);
}

/* Blue, not amber, and it now carries the same structured body as the active card:
   "armed for Tuesday's outage, nothing being held yet" is a real state with real
   details to show, and #551 made it a paragraph rather than the one centred line it
   used to be. The colour is the whole distinction the operator reads at a glance. */
.emergency-mode-armed {
  margin: 0 auto 0.75rem;
  padding: 0.6rem 0.9rem;
  border-radius: 6px;
  font-size: 0.9rem;
  max-width: 900px;
  background: rgba(59, 130, 246, 0.10);
  color: #93c5fd;
  border: 1px solid rgba(59, 130, 246, 0.3);
}

.emergency-mode-title {
  font-weight: 700;
  margin-bottom: 0.35rem;
}

.emergency-mode-fields {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1.5rem;
  margin-bottom: 0.35rem;
}

.emergency-mode-label {
  font-weight: 700;
  margin-right: 0.4rem;
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  opacity: 0.8;
}

/* One trigger, boxed, so several of them read as several events rather than as one
   run-on paragraph -- the card's job since #551 is to let the event be inspected and
   judged, and "which of these lines belongs to which outage" is the first thing that
   has to be obvious. currentColor keeps it inside whichever palette (armed or active)
   the surrounding card chose. */
.emergency-mode-trigger {
  margin-top: 0.5rem;
  padding: 0.45rem 0.6rem;
  border-radius: 5px;
  border: 1px solid currentColor;
  background: rgba(0, 0, 0, 0.15);
}

.emergency-mode-trigger-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.15rem;
}

.emergency-mode-trigger-kind {
  font-weight: 700;
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.05em;
}

/* Who says so -- the utility for an outage, the agency for a warning, AEMO for grid
   stress. Quieter than the kind: it qualifies the claim rather than making it. */
.emergency-mode-trigger-origin {
  font-size: 0.8rem;
  opacity: 0.8;
}

.emergency-mode-trigger-detail {
  margin-bottom: 0.25rem;
}

.emergency-mode-trigger-link a {
  color: inherit;
}

.emergency-mode-trigger-time {
  opacity: 0.75;
}

.emergency-mode-note {
  margin-top: 0.35rem;
  font-size: 0.85rem;
  opacity: 0.85;
}

.emergency-mode-actions {
  margin-top: 0.5rem;
}

/* The consolidated card's distinct reasons (#690): one line each, with the number of
   triggers behind it, so four re-issues of one warning read as one reason. */
.emergency-mode-reasons {
  margin: 0.25rem 0 0;
  padding-left: 1.1rem;
}

.emergency-mode-count {
  font-weight: 700;
  opacity: 0.85;
}

.emergency-mode-link {
  color: inherit;
  font-weight: 600;
}

/* The alerts page (#690): the card's events, one boxed event each, in three lists. The
   events keep the armed card's blue palette; this page is detail, not an alarm. */
.emergency-alerts-page {
  max-width: 900px;
  margin: 0 auto;
}

.emergency-alerts-section {
  margin-bottom: 1.25rem;
  padding: 0.6rem 0.9rem;
  border-radius: 6px;
  font-size: 0.9rem;
  background: rgba(59, 130, 246, 0.10);
  color: #93c5fd;
  border: 1px solid rgba(59, 130, 246, 0.3);
}

.emergency-alerts-heading {
  font-size: 1rem;
  margin: 0 0 0.25rem;
}

.emergency-alerts-empty {
  opacity: 0.8;
}

/* The per-event Dismiss (#551). Deliberately quiet and outlined rather than a filled
   button: it lowers protection, so it must be findable without inviting the click. In
   currentColor like everything else in a trigger block, so it stays inside whichever
   palette (armed or active) the card chose. */
.emergency-mode-dismiss {
  background: transparent;
  border: 1px solid currentColor;
  color: inherit;
  padding: 0.2rem 0.6rem;
  font-size: 0.8rem;
  opacity: 0.85;
}

.emergency-mode-dismiss:hover:not(:disabled) {
  opacity: 1;
  background: rgba(255, 255, 255, 0.08);
}

/* The manual override at the bottom of the page (#551), wearing the charge override's
   clothes: it is `.manual-override-container` plus a top margin separating the two, so
   the two controls that override automatic behaviour read as one pair rather than as
   two unrelated widgets that happen to be near each other. */
.emergency-mode-manual {
  margin-top: 1rem;
}


.config-table-wrapper, .history-table-wrapper {
  overflow-x: auto;
  max-height: 480px;
}

.config-table td.config-key {
  font-weight: 600;
  color: var(--text-secondary, #cbd5e1);
  width: 35%;
  font-family: monospace;
}

.config-table td.config-val {
  font-family: monospace;
  color: #38bdf8;
  white-space: pre-wrap;
  word-break: break-all;
}

.search-input {
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #f8fafc;
  padding: 0.4rem 0.8rem;
  border-radius: 6px;
  font-size: 0.85rem;
  width: 220px;
}

.search-input:focus {
  outline: none;
  border-color: #3b82f6;
}

.records-count {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-left: 0.75rem;
}

.param-name {
  font-weight: 600;
  color: #f1f5f9;
}

.numeric-val {
  font-family: monospace;
  color: #a7f3d0;
}

.nowrap-col {
  white-space: nowrap;
}

.empty-select-card {
  padding: 4rem 2rem;
  text-align: center;
}

.empty-prompt-body svg {
  margin-bottom: 1rem;
  color: var(--text-muted);
}

.empty-prompt-body h3 {
  font-size: 1.2rem;
  margin-bottom: 0.5rem;
}

.empty-prompt-body p {
  color: var(--text-muted);
  max-width: 420px;
  margin: 0 auto;
  font-size: 0.9rem;
}

/* Manual Charger Override -- placed at the very bottom of the home page by
   design, so a stray click can't accidentally force the charger on. */
.manual-override-wrapper {
  margin-top: 2.5rem;
  margin-bottom: 1rem;
}

.manual-override-container {
  border-color: rgba(248, 113, 113, 0.25);
}

.manual-override-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
}

.manual-override-label {
  font-weight: 600;
  color: var(--text-main);
}

.manual-override-sublabel {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: 0.25rem;
}

/* The right-hand end of an override row: the hours box and the toggle, one gap apart.
   Shared by BOTH rows -- the charge override's markup (Web/templates/home.html) and the
   Emergency Mode override's, which main.js builds -- so the pair cannot drift into two
   layouts saying the same thing differently. */
.manual-override-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}

.manual-override-hours {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.manual-override-hours input {
  width: 4.5rem;
  text-align: right;
}

.manual-override-hours input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.manual-override-countdown {
  margin-top: 1rem;
  font-size: 0.9rem;
  color: var(--danger);
  font-weight: 600;
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 52px;
  height: 28px;
  flex-shrink: 0;
}

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

.toggle-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: rgba(255, 255, 255, 0.15);
  border: 1px solid var(--border-card);
  border-radius: 28px;
  transition: background-color 0.2s ease;
}

.toggle-slider::before {
  content: "";
  position: absolute;
  height: 20px;
  width: 20px;
  left: 3px;
  bottom: 3px;
  background-color: var(--text-main);
  border-radius: 50%;
  transition: transform 0.2s ease;
}

.toggle-switch input:checked + .toggle-slider {
  background-color: var(--danger);
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(24px);
}

.toggle-switch input:disabled + .toggle-slider {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Node Detail Page (click-through from a home-page node) */
.node-clickable {
  cursor: pointer;
}

.node-detail-subheading {
  font-size: 0.95rem;
  font-weight: 600;
  margin: 1.25rem 0 0.5rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.node-detail-subheading:first-child {
  margin-top: 0;
}

/* Confines the status table's overflow to the table itself (#270). A table's
   min-content width is set by its longest unbreakable cell, and .node-detail-table
   had nothing between it and .container -- so one long timestamp made the whole page
   wider than a 390px viewport and scrolled the charts off the right edge. min-width: 0
   is what lets this box actually shrink inside a flex/grid ancestor rather than
   inheriting the auto minimum it is trying to contain. */
.node-detail-table-wrapper {
  overflow-x: auto;
  max-width: 100%;
  min-width: 0;
}

.node-detail-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.node-detail-table td, .node-detail-table th {
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  text-align: left;
}

.node-detail-table tbody {
  max-height: 240px;
}

.calibration-age,
.basis-note {
  color: var(--text-muted);
  font-size: 0.8em;
}

/* The history range chips under a ranged node chart (#800): the same four everywhere. */
.range-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0 0 0.25rem;
}

.range-chip {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 999px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.8rem;
  padding: 0.15rem 0.7rem;
}

.range-chip:hover {
  color: var(--text-main);
}

.range-chip.active {
  background: rgba(56, 189, 248, 0.15);
  border-color: #38bdf8;
  color: var(--text-main);
}

/* A group of tables and charts on one node page: A2's grid charger section (#828). */
.node-detail-section {
  margin-top: 2rem;
}

.node-detail-section-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 0 0 0.75rem;
}

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

.node-detail-page .page-header {
  justify-content: flex-start;
  align-items: center;
  gap: 1rem;
}

.back-link {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.95rem;
  white-space: nowrap;
}

.back-link:hover {
  color: var(--text-main);
}

/* max-width/min-width belt-and-braces for #270: Chart.js sizes the canvas to this
   container, so the container must never be wider than the column it sits in no
   matter what a sibling does. */
.chart-wrapper {
  position: relative;
  height: 260px;
  margin: 0.5rem 0 1.5rem;
  max-width: 100%;
  min-width: 0;
}


/* ----------------------------------------------------
   Diagnostics page (#273): a list of findings, nothing else
   ---------------------------------------------------- */
.finding {
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  /* The severity stripe is the only colour that carries meaning here, so it gets a
     whole edge rather than competing with a coloured background: a page of amber
     panels reads as decoration, and the reader stops seeing it. */
  border-left: 3px solid #fbbf24;
  border-radius: 10px;
  padding: 0.85rem 1rem;
  margin-bottom: 0.75rem;
}

.finding-error { border-left-color: #f87171; }

.finding-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  flex-wrap: wrap;
}

.finding-title {
  color: var(--text-main);
  font-size: 0.95rem;
  font-weight: 600;
  /* Log lines arrive as one long unbroken string; without this they force the whole
     page into a horizontal scroll on a phone. */
  overflow-wrap: anywhere;
}

.finding-since {
  color: var(--text-muted);
  font-size: 0.8rem;
  white-space: nowrap;
}

.finding-evidence {
  margin: 0.6rem 0 0;
  display: grid;
  /* Labels size to the longest of them, values take the rest; below 480px the pairs
     stack instead of squeezing a value into a two-word column. */
  grid-template-columns: max-content 1fr;
  gap: 0.25rem 0.75rem;
  font-size: 0.85rem;
}

/* 640px is the page-level breakpoint the rest of this stylesheet already turns on;
   a new one just for these rows would restack them at a width nothing else changes at. */

.finding-eviRow { display: contents; }

.finding-evidence dt { color: var(--text-muted); }

.finding-evidence dd {
  margin: 0;
  color: var(--text-main);
  overflow-wrap: anywhere;
}

.finding-expand {
  margin-top: 0.75rem;
  padding: 0.35rem 0.7rem;
  background: transparent;
  border: 1px solid var(--border-card);
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 0.8rem;
  cursor: pointer;
}

.finding-expand:hover {
  background: var(--bg-card-hover);
  color: var(--text-main);
}

.finding-detail { margin-top: 0.5rem; }

/* #414: a failure *rate* that is worth knowing about but is not yet a fault. Its stripe
   is deliberately the quietest of the three -- a row the reader is meant to note, not
   act on, must not look like the row above it that they do have to act on. */
.finding-info { border-left-color: #60a5fa; }

/* The raw log, one click from the plain-language summaries that replaced it (#414). */
.finding-technical,
.diagnostics-raw {
  margin-top: 0.6rem;
  font-size: 0.85rem;
}

.finding-technical > summary,
.diagnostics-raw > summary {
  color: var(--text-muted);
  cursor: pointer;
}

.diagnostics-raw { margin-top: 1.5rem; }

.raw-event-list {
  list-style: none;
  margin: 0.6rem 0 0;
  padding: 0;
}

.raw-event {
  border-left: 3px solid #fbbf24;
  padding: 0.3rem 0 0.3rem 0.6rem;
  margin-bottom: 0.4rem;
}

.raw-event-error { border-left-color: #f87171; }

.raw-event code {
  display: block;
  color: var(--text-muted);
  word-break: break-word;
}

/* How many times this one message has repeated, and over what span -- the count is the
   reason the block is short enough to read. */
.raw-event-count {
  display: block;
  color: var(--text-muted);
  font-size: 0.78rem;
  margin-bottom: 0.1rem;
}

.diagnostics-ok {
  color: var(--text-main);
  font-size: 1.1rem;
  font-weight: 600;
  text-align: center;
  margin: 2.5rem 0 0.4rem;
}

.diagnostics-ok-sub {
  color: var(--text-muted);
  font-size: 0.9rem;
  text-align: center;
  margin: 0;
}

@media (max-width: 640px) {
  .finding-evidence { grid-template-columns: 1fr; gap: 0.1rem; }
  .finding-eviRow { display: block; margin-bottom: 0.35rem; }
}

/* Inline explanatory note on a node-detail page (#259: the battery page's
   "no charging mechanism" caveat beside the projected trajectory). */
.detail-note {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin: 0.4rem 0 0.8rem;
}

/* --- First-run setup wizard (#386, /setup) ---------------------------------------
   Its own block rather than the dashboard's card vocabulary, because the page is a
   form: dense rows of labelled inputs, no nav bar (every destination redirects back
   here while the backend has no config) and one save at the bottom. */
.setup-body {
  padding-bottom: 4rem;
}

.setup-header {
  padding: 1.5rem 2rem;
  border-bottom: 1px solid var(--border-card);
  background: rgba(15, 23, 42, 0.6);
}

.setup-header-inner {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  max-width: 1100px;
  margin: 0 auto;
}

.setup-title {
  font-size: 1.5rem;
  font-weight: 700;
}

.setup-subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 0.2rem;
}

.setup-container {
  max-width: 1100px;
}

.setup-section {
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: 12px;
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.25rem;
}

.setup-section .card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.5rem;
}

.setup-section .card-title {
  font-size: 1.1rem;
  font-weight: 600;
}

.setup-help {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 0.9rem;
  line-height: 1.5;
}

/* Two or three columns on a laptop, one on the phone an electrician actually holds. */
.setup-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.75rem 1rem;
}

.setup-field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.setup-input {
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid var(--border-card);
  color: var(--text-main);
  border-radius: 8px;
  padding: 0.5rem 0.7rem;
  font-family: inherit;
  font-size: 0.9rem;
  outline: none;
  width: 100%;
}

.setup-input:focus {
  border-color: var(--primary-accent);
}

/* Read-only settings (#386): outside setup mode the Gateway refuses the write, so every
   control on the page is disabled. Dimmed rather than hidden -- the point of the page in
   running mode is to show what is configured. */
.setup-input:disabled,
.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* The raw-YAML editor: a plain textarea, monospaced, tall enough to hold a section at a
   time. No syntax-highlighting library -- this is served to an SBC-class browser. */
.yaml-editor {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.82rem;
  line-height: 1.45;
  min-height: 60vh;
  white-space: pre;
  resize: vertical;
}

/* One device, array or charger part. */
.setup-row {
  border: 1px solid var(--border-card);
  border-radius: 10px;
  padding: 0.9rem 1rem;
  margin-bottom: 0.85rem;
  background: rgba(15, 23, 42, 0.35);
}

.setup-row-head {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.7rem;
}

.setup-row-head .setup-remove {
  margin-left: auto;
}

.setup-row-foot {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  margin-top: 0.8rem;
}

/* The one decision on a card, given the weight of one (#548). A full-width panel with a
   large box and a live on/off/not-answered line, rather than a checkbox in the header --
   the state line is what carries the tri-state, since a checkbox cannot show "unknown". */
.setup-toggle {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.85rem 1rem;
  margin-bottom: 0.9rem;
  border: 1px solid var(--border-card);
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.55);
  cursor: pointer;
}

.setup-toggle-box {
  width: 1.4rem;
  height: 1.4rem;
  flex: none;
  accent-color: var(--primary-accent);
  cursor: pointer;
}

.setup-toggle-text {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.setup-toggle-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-main);
}

.setup-toggle-state {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.setup-toggle-box:checked ~ .setup-toggle-text .setup-toggle-state {
  color: var(--success);
}

.setup-inline-check {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  cursor: pointer;
}

.setup-test-result {
  margin-top: 0.7rem;
  padding: 0.5rem 0.7rem;
  border-radius: 6px;
  font-size: 0.85rem;
}

.setup-test-ok {
  background: rgba(34, 197, 94, 0.12);
  color: var(--success);
  border: 1px solid rgba(34, 197, 94, 0.35);
}

.setup-test-fail {
  background: rgba(239, 68, 68, 0.12);
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.4);
}

.setup-savebar {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  align-items: stretch;
}

/* The errors the backend returned, left-aligned as a list: this is the copy someone
   works through, not a banner they glance at. */
.setup-savebar .site-alert,
#setup-boot-errors {
  text-align: left;
  max-width: none;
  /* Not `margin: 0 auto`: an auto side margin on a flex item shrinks it to its content
     and centres it, which turned this list into a narrow column mid-page. */
  margin: 0 0 0.75rem;
  font-weight: 500;
}

.setup-savebar .site-alert ul,
#setup-boot-errors ul {
  margin: 0.4rem 0 0 1.1rem;
}

.setup-save-btn {
  background: var(--primary-accent);
  border-color: var(--primary-accent);
  color: #0f172a;
  font-weight: 700;
  padding: 0.75rem 1rem;
  font-size: 1rem;
}

.setup-save-btn:hover {
  background: #7dd3fc;
}

.setup-save-btn:disabled {
  opacity: 0.6;
  cursor: default;
}

/* The save is answered before the write happens, and the backend then exits and is
   restarted -- so the page has to hold still through a real outage. */
.setup-overlay {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.setup-overlay-box {
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: 12px;
  padding: 2rem 2.5rem;
  text-align: center;
}

.setup-overlay-box p {
  color: var(--text-muted);
  margin-top: 0.6rem;
}

/* ----------------------------------------------------
   Relay offline (#519, design docs/design/PUBLIC_RELAY.md section 8)
   ----------------------------------------------------
   Only ever reachable on a relay-served page: the banner element exists only under
   public_mode, and main.js puts .relay-offline on <body> only after a served document
   reported `_relay.online: false`. Nothing here can fire on the device. */

/* The amber warning vocabulary the divergence banner and site alerts already use --
   this is a caveat about the data, not a fault in the site. It IS a site alert, so
   base.html renders it as `site-alert site-alert-warning relay-banner` and every one of
   those properties comes from there; all this adds is the wider gap below, because the
   banner heads the whole page rather than sitting in the alert stack. */
.relay-banner {
  margin-bottom: 1rem;
}

/* Greyed/stale tiles while the relay cannot reach the site: every surface here shows a
   live value, and a live value nobody is refreshing should not read as current.
   Enumerated per surface rather than as one blanket rule on the page, because
   .chart-wrapper must stay untouched -- charts stay drawn at full contrast (history is
   history, and the now-line makes the gap visible). The backend-status badge is left
   alone too: it reports the DEVICE's own view, which is a different question the relay
   outage does not answer, and greyscaling it would destroy the colour that is its
   entire meaning. */
.relay-offline .node,
.relay-offline .todays-stats-container,
.relay-offline .node-detail-table-wrapper {
  opacity: 0.5;
  filter: grayscale(1);
}

/* Carries the "why is this disabled" tooltip for a control that cannot carry its own:
   a disabled button or checkbox takes no pointer events, so a title on it never shows.
   inline-block so it wraps the control without changing the row's layout. */
.control-reason {
  display: inline-block;
}

/* A settled command failure -- the relay's own 409 wording, or the device's ack detail
   ("Storm prep is not enabled in config"). Red rather than amber: unlike the banner
   above, this is something that did not happen. */
.command-error {
  margin-top: 0.5rem;
  font-size: 0.85rem;
  color: var(--danger);
}
