/* Modern EMS Dashboard Styles */

:root {
  /* === Brand colors === */
  --primary:        #3b82f6;
  --primary-hover:  #2563eb;
  --primary-light:  #dbeafe;
  --primary-soft:   rgba(59, 130, 246, 0.12);
  --primary-border: rgba(59, 130, 246, 0.28);
  --primary-dim:    rgba(59, 130, 246, 0.12); /* alias for primary-soft */

  --accent:        #10b981;
  --accent-hover:  #059669;
  --accent-soft:   rgba(16, 185, 129, 0.12);
  --accent-border: rgba(16, 185, 129, 0.28);

  /* === Backgrounds === */
  --bg-page:      #0d1420;
  --bg-shell:     #111827;
  --bg-surface:   #162234;
  --bg-card:      #1e293b;
  --bg-card-soft: #192030;
  --bg-elevated:  #334155;
  --bg-overlay:   rgba(15, 23, 42, 0.88);
  --bg-main:  #111827; /* alias for bg-shell */
  --bg-input: #0f172a;

  /* === Borders === */
  --border-subtle: rgba(148, 163, 184, 0.16);
  --border:        rgba(51, 65, 85, 0.82);
  --border-strong: #334155;
  --border-focus:  #3b82f6;

  /* === Text === */
  --text-primary:   #f1f5f9;
  --text-secondary: #cbd5e1;
  --text-muted:     #94a3b8;
  --text-disabled:  #64748b;

  /* === Semantic colors === */
  --success:        #10b981;
  --success-soft:   rgba(16, 185, 129, 0.12);
  --success-border: rgba(16, 185, 129, 0.28);
  --color-success:     #10b981; /* alias */
  --color-success-dim: rgba(16, 185, 129, 0.12); /* alias */

  --warning:        #f59e0b;
  --warning-soft:   rgba(245, 158, 11, 0.12);
  --warning-border: rgba(245, 158, 11, 0.28);
  --color-warning:     #FFB000; /* alias */
  --color-warning-dim: rgba(255, 176, 0, 0.12); /* alias */

  --danger:        #ef4444;
  --danger-soft:   rgba(239, 68, 68, 0.12);
  --danger-border: rgba(239, 68, 68, 0.28);
  --color-danger:     #E63946; /* alias */
  --color-danger-dim: rgba(230, 57, 70, 0.12); /* alias */

  --color-info:     #38bdf8;
  --color-info-dim: rgba(56, 189, 248, 0.12);

  /* === Energy flow colors === */
  --flow-pv:      #10b981;
  --flow-battery: #f59e0b;
  --flow-grid:    #3b82f6;
  --flow-export:  #38bdf8;
  --flow-import:  #E63946;
  --flow-soc:     #a855f7;
  --flow-load:    #38bdf8;

  /* === Border radius === */
  --radius-xs:   6px;
  --radius-sm:   10px;
  --radius:      12px;
  --radius-md:   14px;
  --radius-lg:   16px;
  --radius-xl:   24px;
  --radius-pill: 999px;

  /* === Shadows === */
  --shadow-soft: 0 1px 4px rgba(0,0,0,0.28);
  --shadow-card: 0 2px 8px rgba(0,0,0,0.38);
  --shadow-sm:   0 1px 3px rgba(0,0,0,0.4);
  --shadow-md:   0 4px 12px rgba(0,0,0,0.45);
  --shadow-lg:   0 10px 28px rgba(0,0,0,0.55);
  --shadow-xl:   0 20px 48px rgba(0,0,0,0.65);

  /* === Spacing scale === */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 32px;
  --space-8: 48px;

  /* === Transitions === */
  --transition-fast: 0.1s ease;
  --transition-base: 0.18s ease;

  /* === Typography === */
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: ui-monospace, 'JetBrains Mono', SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: linear-gradient(180deg, #111827 0%, #162234 100%);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
}

.page {
  min-height: 100vh;
  display: flex;
  flex-direction: row;
  align-items: stretch;
}

/* Sidebar */
.sidebar {
  width: 244px;
  min-height: 100vh;
  background: rgba(15, 23, 42, 0.98);
  border-right: 1px solid var(--border);
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.4);
  padding: 1.5rem 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  position: sticky;
  top: 0;
  align-self: flex-start;
}

.sidebar-header {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 1rem;
}

.sidebar-toggle-wrap {
  padding: 0 0.4rem 0.25rem;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.brand-logo {
  height: 38px;
  width: 38px;
  object-fit: contain;
  display: block;
}

.brand-name {
  font-weight: 700;
  letter-spacing: 0.06em;
  font-size: 1.1rem;
  color: var(--text-primary);
  line-height: 1.05;
}

.brand-name span {
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.7rem;
  letter-spacing: 0.04em;
}

.view-toggle {
  padding: 0.25rem;
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid var(--border);
  border-radius: 999px;
  display: flex;
}

.mode-pill {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font: 600 0.8rem var(--font-sans);
  padding: 0.4rem 0.6rem;
  border-radius: 999px;
  cursor: pointer;
  transition: background-color 0.12s ease, color 0.12s ease, box-shadow 0.12s ease;
}

.mode-pill[aria-pressed="true"] {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.4);
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  margin-top: 0.5rem;
}

.nav a {
  color: var(--text-secondary);
  text-decoration: none;
  padding: 0.55rem 0.8rem;
  border-radius: var(--radius);
  transition: background-color 0.12s ease, color 0.12s ease;
  font-weight: 500;
  font-size: 0.92rem;
  display: flex;
  align-items: center;
  gap: 0.7rem;
}

.nav a:hover {
  color: var(--text-primary);
  background: var(--bg-elevated);
}

.nav a[data-nav].active {
  background: var(--primary-dim);
  box-shadow: inset 3px 0 0 var(--primary);
  color: var(--text-primary);
}

.nav-icon {
  display: inline-flex;
  width: 18px;
  height: 18px;
  justify-content: center;
  align-items: center;
  flex-shrink: 0;
}

.nav-icon svg {
  width: 100%;
  height: 100%;
}

.nav-text {
  white-space: nowrap;
}

.nav-group {
  display: flex;
  flex-direction: column;
}

.chev {
  margin-left: auto;
  opacity: 0.6;
  transition: transform 0.18s ease;
}

.nav-group.open > a .chev {
  transform: rotate(90deg);
}

.nav-sub {
  display: none;
  flex-direction: column;
  gap: 0.05rem;
  padding: 0.15rem 0 0.25rem 2.4rem;
  border-left: 1px dashed var(--border-subtle);
  margin: 0.1rem 0 0.1rem 1.45rem;
}

.nav-group.open .nav-sub {
  display: flex;
}

.nav-sub-link {
  font-size: 0.82rem;
  padding: 0.3rem 0.6rem;
  color: var(--text-muted);
}

.nav-sub-link:hover {
  color: var(--text-primary);
  background: transparent;
}

.sidebar-foot {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  padding-top: 0.5rem;
}

.logout-btn {
  width: 100%;
  padding: 0.55rem 0.8rem;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: var(--radius);
  cursor: pointer;
  font: 500 0.9rem var(--font-sans);
  display: flex;
  align-items: center;
  gap: 0.7rem;
  transition: background-color 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}

.logout-btn:hover {
  background: rgba(230, 57, 70, 0.08);
  color: #ff8a93;
  border-color: rgba(230, 57, 70, 0.3);
}

.sidebar.collapsed {
  width: 72px;
  padding: 1rem 0.5rem;
  align-items: center;
}

.sidebar.collapsed .sidebar-header {
  width: 100%;
}

.sidebar.collapsed .brand-name,
.sidebar.collapsed .view-toggle,
.sidebar.collapsed .sidebar-build {
  display: none;
}

.sidebar.collapsed .nav {
  align-items: center;
}

.sidebar.collapsed .nav a {
  justify-content: center;
}

.sidebar.collapsed .nav-group > a {
  justify-content: center;
}

.sidebar.collapsed .chev,
.sidebar.collapsed .nav-sub {
  display: none;
}

.sidebar.collapsed .nav-text {
  display: none;
}

.sidebar.collapsed [data-logout] .nav-text {
  display: none;
}

.sidebar-build {
  padding: 0 0.4rem;
}

.sidebar-build-id {
  color: var(--text-disabled);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 0.7rem;
  line-height: 1.4;
  letter-spacing: 0.01em;
  overflow-wrap: anywhere;
}

.sidebar.collapsed .sidebar-build {
  display: none;
}

/* Content */
.content {
  flex: 1;
  padding: 2rem;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
}

/* EMS Page */
.ems-hero {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 2rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.ems-title {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 0.35rem;
}

.ems-subtitle {
  color: var(--text-secondary);
  margin-bottom: 1rem;
}

.ems-meta {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
  color: var(--text-secondary);
  font-size: 0.95rem;
}

.ems-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.ems-metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.metric-card {
  padding: 1.25rem;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--bg-card);
  box-shadow: var(--shadow-sm);
}

.metric-title {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

.metric-value {
  font-size: 1.6rem;
  font-weight: 700;
}

.metric-sub {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-top: 0.25rem;
}

.panel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

.panel {
  padding: 1.75rem;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.details-block {
  background: rgba(15, 23, 42, 0.4);
  border-radius: var(--radius);
  border: 1px solid rgba(51, 65, 85, 0.5);
  padding: 0.75rem 1rem;
}

.details-block summary {
  cursor: pointer;
  color: var(--text-secondary);
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.details-block pre {
  margin-top: 0.5rem;
  white-space: pre-wrap;
  color: var(--text-muted);
}

.device-list {
  display: grid;
  gap: 0.75rem;
  margin-top: 1rem;
}

.device {
  padding: 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.45);
  display: grid;
  gap: 0.25rem;
  grid-template-columns: 1fr auto;
}

.device small {
  color: var(--text-muted);
}

.device .actions {
  justify-content: flex-end;
  gap: 0.5rem;
}

.btn.tiny {
  padding: 0.35rem 0.7rem;
  font-size: 0.8rem;
}

.device-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.35rem;
  justify-self: end;
  grid-column: 2;
  grid-row: 1;
}

.icon-btn {
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
}

.device-debug {
  display: none;
  grid-column: 1 / -1;
  margin-top: 0.5rem;
  padding: 0.85rem;
  border-radius: calc(var(--radius) - 4px);
  border: 1px solid rgba(148, 163, 184, 0.25);
  background: rgba(2, 6, 23, 0.55);
  gap: 0.65rem;
}

.device-debug.is-visible {
  display: grid;
}

.device-debug-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.device-debug pre {
  margin: 0;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text-muted);
  font-size: 0.84rem;
  line-height: 1.45;
}

.price-curve-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 1rem;
}

.price-curve {
  display: grid;
  grid-template-columns: repeat(24, 1fr);
  gap: 6px;
  height: 180px;
  background: rgba(15, 23, 42, 0.4);
  border: 1px solid rgba(51, 65, 85, 0.6);
  border-radius: var(--radius);
  padding: 0.75rem;
}

.price-bar {
  background: linear-gradient(180deg, rgba(0, 168, 232, 0.78), rgba(0, 119, 182, 0.62));
  border-radius: 6px;
  align-self: end;
  min-height: 6px;
  cursor: ns-resize;
  position: relative;
  transition: height 0.08s ease;
}

.price-curve.readonly .price-bar {
  cursor: default;
}

.price-bar::after {
  content: attr(data-value);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.7rem;
  color: var(--text-muted);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
}

.price-bar:hover::after {
  opacity: 1;
}

.price-curve-labels {
  display: grid;
  grid-template-columns: repeat(24, 1fr);
  gap: 6px;
  font-size: 0.65rem;
  color: var(--text-muted);
  text-align: center;
}

.price-mode {
  display: flex;
  gap: 0.5rem;
}

.price-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 1rem;
}

.price-table th,
.price-table td {
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  font-size: 0.9rem;
}

.price-table th {
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.75rem;
}

.price-table input {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  padding: 0.35rem 0.5rem;
}

.debug-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.kv-grid {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.4rem 1rem;
  font-size: 0.92rem;
}

.kv-grid .k {
  color: var(--text-secondary);
}

.kv-grid .v {
  color: var(--text-primary);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  text-align: right;
}

.compare-table {
  width: 100%;
  border-collapse: collapse;
}

.compare-table th,
.compare-table td {
  padding: 0.55rem 0.65rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  font-size: 0.92rem;
}

.compare-table th {
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.74rem;
}

.pack-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.pack-card {
  padding: 1rem;
  border-radius: var(--radius);
  border: 1px solid rgba(148, 163, 184, 0.2);
  background: rgba(15, 23, 42, 0.45);
}

.pack-card h3 {
  font-size: 1rem;
  margin-bottom: 0.75rem;
}

.cell-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.cell {
  padding: 0.55rem 0.6rem;
  border-radius: 10px;
  background: rgba(2, 6, 23, 0.55);
  border: 1px solid rgba(148, 163, 184, 0.16);
}

.cell .idx {
  color: var(--text-muted);
  font-size: 0.78rem;
}

.cell .val {
  display: block;
  margin-top: 0.15rem;
  font-weight: 700;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}

.battery-glance {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.summary-stat {
  padding: 1rem 1.1rem;
  border-radius: var(--radius-lg);
  border: 1px solid rgba(148, 163, 184, 0.2);
  background: rgba(15, 23, 42, 0.5);
  box-shadow: var(--shadow-sm);
}

.summary-stat.info {
  border-color: rgba(59, 130, 246, 0.35);
}

.summary-stat.primary {
  border-color: rgba(16, 185, 129, 0.35);
}

.summary-stat.accent {
  border-color: rgba(245, 158, 11, 0.35);
}

.summary-stat.ok {
  border-color: rgba(16, 185, 129, 0.35);
}

.summary-stat.caution,
.summary-stat.warn {
  border-color: rgba(245, 158, 11, 0.45);
}

.summary-stat.danger {
  border-color: rgba(239, 68, 68, 0.45);
}

.summary-label {
  color: var(--text-muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.summary-value {
  margin-top: 0.45rem;
  font-size: 1.2rem;
  font-weight: 700;
}

.summary-note {
  margin-top: 0.35rem;
  color: var(--text-secondary);
  font-size: 0.84rem;
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.chip-list.compact {
  gap: 0.35rem;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.28rem 0.62rem;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.25);
  background: rgba(15, 23, 42, 0.55);
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1.2;
}

.chip.ok {
  border-color: rgba(46, 196, 182, 0.4);
  background: rgba(46, 196, 182, 0.12);
  color: #9ee8e2;
}

.chip.info {
  border-color: rgba(0, 119, 182, 0.4);
  background: rgba(0, 119, 182, 0.14);
  color: #99d4f0;
}

.chip.primary {
  border-color: rgba(46, 196, 182, 0.4);
  background: rgba(46, 196, 182, 0.12);
  color: #9ee8e2;
}

.chip.caution,
.chip.warn {
  border-color: rgba(255, 176, 0, 0.45);
  background: rgba(255, 176, 0, 0.12);
  color: #ffe099;
}

.chip.danger {
  border-color: rgba(230, 57, 70, 0.45);
  background: rgba(230, 57, 70, 0.12);
  color: #f5b0b5;
}

.chip.muted {
  border-color: rgba(30, 75, 107, 0.4);
  background: rgba(6, 20, 38, 0.42);
  color: var(--text-muted);
}

.compare-row.indirect {
  opacity: 0.82;
}

.compare-note {
  color: var(--text-muted);
  font-size: 0.82rem;
}

.protocol-note {
  display: grid;
  gap: 0.8rem;
  padding: 1rem;
  border-radius: var(--radius);
  border: 1px solid rgba(148, 163, 184, 0.18);
  background: rgba(15, 23, 42, 0.45);
}

.protocol-note-title {
  font-size: 1rem;
  font-weight: 700;
}

.protocol-note-body {
  color: var(--text-secondary);
  max-width: 70ch;
}

.battery-card {
  margin-top: 1rem;
  padding: 1rem;
  border-radius: var(--radius-lg);
  border: 1px solid rgba(148, 163, 184, 0.2);
  background: rgba(15, 23, 42, 0.4);
  box-shadow: var(--shadow-sm);
}

.battery-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.compact-grid {
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  margin-bottom: 1rem;
}

.inner-panel {
  background: rgba(2, 6, 23, 0.36);
  box-shadow: none;
}

.card-title.small {
  font-size: 0.95rem;
  margin-bottom: 0.8rem;
}

.kv-grid.compact {
  font-size: 0.88rem;
}

.flag-group + .flag-group {
  margin-top: 0.9rem;
}

.flag-group-title {
  color: var(--text-muted);
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.45rem;
}

.protocol-inline-note {
  margin-top: 0.95rem;
  color: var(--text-muted);
  font-size: 0.8rem;
  line-height: 1.45;
}

.pack-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.cell.is-low {
  border-color: rgba(230, 57, 70, 0.35);
  background: rgba(100, 20, 25, 0.28);
}

.cell.is-mid {
  border-color: rgba(0, 119, 182, 0.18);
  background: rgba(6, 20, 38, 0.6);
}

.cell.is-high {
  border-color: rgba(46, 196, 182, 0.35);
  background: rgba(15, 80, 75, 0.28);
}

@media (max-width: 900px) {
  .battery-card-header {
    flex-direction: column;
  }

  .cell-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* Cards */
.card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow-card);
  border: 1px solid var(--border);
  transition: border-color var(--transition-base), box-shadow var(--transition-base);
}

.card:hover {
  border-color: var(--primary-border);
  box-shadow: var(--shadow-md);
}

.card-label {
  font-size: 0.7rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.topology-card {
  padding: 2.5rem;
}

/* Hero Section */
.hero {
  text-align: center;
  margin-bottom: 2rem;
}

.hero h1 {
  font-size: 2.5rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
  color: var(--text-primary);
}

.hero p {
  color: var(--text-secondary);
  font-size: 1.1rem;
}

/* Topology */
.topology-title {
  margin-bottom: 2rem;
}

.topology-title h1 {
  font-size: 1.875rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  color: var(--text-primary);
}

.topology-title span {
  color: var(--text-muted);
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.topology-title span::before {
  content: "";
  width: 8px;
  height: 8px;
  background: var(--accent);
  border-radius: 50%;
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.topology-wrap {
  background: rgba(6, 20, 38, 0.5);
  border-radius: var(--radius);
  padding: 2rem;
  margin-bottom: 1.5rem;
  border: 1px solid rgba(30, 75, 107, 0.5);
}

/* SVG Nodes */
.node {
  fill: var(--bg-elevated);
  stroke: var(--border);
  stroke-width: 2;
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.3));
  transition: fill 0.12s ease, stroke 0.12s ease;
}

.node:hover {
  fill: #1E4B6B;
  stroke: var(--primary);
}

.node-accent {
  fill: #1E4B6B;
  stroke: var(--primary);
  stroke-width: 2.5;
}

.value {
  fill: var(--text-primary);
  font-size: 16px;
  font-weight: 700;
}

.topology-wrap .label {
  fill: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
}

/* Flow lines */
.flow {
  stroke: var(--primary);
  stroke-width: 3;
  fill: none;
  opacity: 0.3;
  marker-end: url(#arrow);
}

.flow.animate {
  opacity: 1;
  stroke-dasharray: 10 5;
  animation: flowAnimation 1.5s linear infinite;
}

.flow.reverse {
  animation-direction: reverse;
}

@keyframes flowAnimation {
  to { stroke-dashoffset: -15; }
}

.soft {
  stroke: var(--border);
  stroke-width: 1;
  fill: none;
  opacity: 0.3;
}

/* Legend */
.topology-legend {
  display: flex;
  gap: 2rem;
  flex-wrap: wrap;
  padding: 1rem;
  background: rgba(15, 23, 42, 0.3);
  border-radius: var(--radius);
  border: 1px solid rgba(51, 65, 85, 0.3);
}

.topology-legend span {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  box-shadow: 0 0 8px currentColor;
}

.dot-grid { background: #FFB000; }
.dot-pv { background: #2EC4B6; }
.dot-battery { background: #0077B6; }
.dot-load { background: #E63946; }
.dot-gridline { background: var(--primary); }

/* Form Elements */
.form-grid {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.split {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

body:is(.settings-page, [data-page="settings"]) .panel {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1.5rem;
}

body:is(.settings-page, [data-page="settings"]) .panel-header {
  margin-bottom: 0;
}

body:is(.settings-page, [data-page="settings"]) .panel .device-list {
  margin-top: 0;
}

body:is(.settings-page, [data-page="settings"]) .panel .split {
  align-items: start;
  gap: 1rem;
}

body:is(.settings-page, [data-page="settings"]) .panel .form-row {
  min-width: 0;
}

body:is(.settings-page, [data-page="settings"]) #service-panels-grid,
body:is(.settings-page, [data-page="settings"]) #service-access-grid {
  align-items: start;
}

body:is(.settings-page, [data-page="settings"]) #service-panels-grid > .panel,
body:is(.settings-page, [data-page="settings"]) #service-access-grid > .panel {
  align-self: start;
}

body:is(.settings-page, [data-page="settings"]) #service-panels-grid > .service-card-compact {
  justify-self: start;
  width: min(100%, 420px);
}

body:is(.settings-page, [data-page="settings"]) #service-panels-grid > .service-card-wide {
  grid-column: span 2;
}

body:is(.settings-page, [data-page="settings"]) #service-panels-grid > .service-card-full {
  grid-column: 1 / -1;
}

@media (max-width: 900px) {
  body:is(.settings-page, [data-page="settings"]) #service-panels-grid > .service-card-compact {
    width: 100%;
  }

  body:is(.settings-page, [data-page="settings"]) #service-panels-grid > .service-card-wide {
    grid-column: span 1;
  }

  body:is(.settings-page, [data-page="settings"]) #service-panels-grid > .service-card-full {
    grid-column: span 1;
  }
}

.form-row {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: 48px;
  color: var(--text-secondary);
}

.toggle-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
}

.progress-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.progress-wrap progress {
  width: 100%;
  height: 12px;
}

.code-block {
  margin: 0;
  padding: 0.85rem 1rem;
  border-radius: var(--radius);
  border: 1px solid rgba(148, 163, 184, 0.22);
  background: rgba(2, 6, 23, 0.55);
  color: var(--text-muted);
  font-size: 0.84rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  min-height: 7.5rem;
}

body[data-page="login"] .grid {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  max-width: 400px;
  margin: 0 auto;
}

body[data-page="login"] .row {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.label {
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.input {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.85rem;
  color: var(--text-primary);
  font-size: 0.925rem;
  font-family: var(--font-sans);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.input::placeholder {
  color: var(--text-muted);
}

.input:disabled,
.input[readonly] {
  background: rgba(15, 23, 42, 0.55);
  border-color: rgba(148, 163, 184, 0.22);
  color: var(--text-muted);
  box-shadow: none;
  cursor: not-allowed;
}

select.input:disabled {
  opacity: 1;
  -webkit-text-fill-color: var(--text-muted);
}

.input:disabled::placeholder,
.input[readonly]::placeholder {
  color: rgba(148, 163, 184, 0.7);
}

/* Buttons */
.btn {
  padding: 0.5rem 1.2rem;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.9rem;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: background-color var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast);
  border: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  text-decoration: none;
  line-height: 1.4;
  white-space: nowrap;
}

.btn.primary {
  background: linear-gradient(180deg, rgba(59, 130, 246, 0.92), rgba(37, 99, 235, 0.92));
  color: white;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.28);
}

.btn.primary:hover {
  box-shadow: 0 5px 16px rgba(37, 99, 235, 0.34);
}

.btn.primary:active {
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.28);
}

.btn.ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 2px solid var(--border);
}

.btn.ghost:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border-color: var(--primary);
}

.actions {
  display: flex;
  gap: 1rem;
  margin-top: 0.5rem;
}

.actions .btn {
  flex: 1;
}

/* ===== Utility classes ===== */
.hidden { display: none !important; }
body.no-pv-site a[data-nav="solar-layout.html"] { display: none !important; }

.stack-sm { display: flex; flex-direction: column; gap: var(--space-2); }
.stack-md { display: flex; flex-direction: column; gap: var(--space-4); }
.stack-lg { display: flex; flex-direction: column; gap: var(--space-6); }

.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.row-center  { display: flex; align-items: center; gap: var(--space-3); }

.grid-2    { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--space-4); }
.grid-3    { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-4); }
.grid-auto { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: var(--space-4); }

.text-muted     { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-primary   { color: var(--text-primary); }
.text-sm        { font-size: 0.8rem; }
.text-xs        { font-size: 0.72rem; }
.font-mono      { font-family: var(--font-mono); }

.warning-box {
  background: var(--warning-soft);
  border: 1px solid var(--warning-border);
  border-radius: var(--radius-sm);
  padding: var(--space-3) var(--space-4);
  color: var(--warning);
  font-size: 0.875rem;
}

.danger-box {
  background: var(--danger-soft);
  border: 1px solid var(--danger-border);
  border-radius: var(--radius-sm);
  padding: var(--space-3) var(--space-4);
  color: var(--danger);
  font-size: 0.875rem;
}

.info-box {
  background: var(--color-info-dim);
  border: 1px solid rgba(56, 189, 248, 0.28);
  border-radius: var(--radius-sm);
  padding: var(--space-3) var(--space-4);
  color: var(--color-info);
  font-size: 0.875rem;
}

.success-box {
  background: var(--success-soft);
  border: 1px solid var(--success-border);
  border-radius: var(--radius-sm);
  padding: var(--space-3) var(--space-4);
  color: var(--success);
  font-size: 0.875rem;
}

/* Status */
.status {
  padding: 0.875rem 1rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  text-align: center;
  display: none;
  animation: slideIn 0.3s ease;
}

.status:not(:empty) {
  display: block;
}

.status.error {
  background: rgba(230, 57, 70, 0.1);
  color: #f5b0b5;
  border: 1px solid rgba(230, 57, 70, 0.3);
}

.status.success {
  background: rgba(46, 196, 182, 0.1);
  color: #9ee8e2;
  border: 1px solid rgba(46, 196, 182, 0.3);
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Footer */
.footer {
  background: rgba(30, 41, 59, 0.6);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
  padding: 1.25rem 2rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.footer-brand {
  color: var(--primary);
  font-weight: 600;
}

.footer-build {
  margin-top: 0.35rem;
  color: var(--text-muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 0.8rem;
  overflow-wrap: anywhere;
}

.nav-hamburger-icon { display: none; }
.nav-close-icon     { display: none; }

.brand[data-nav-toggle] { cursor: pointer; }

/* Responsive */
@media (max-width: 768px) {
  .page {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    min-height: auto;
    position: relative;
    padding: 1rem;
  }

  .sidebar-header {
    gap: 0.75rem;
  }

  .sidebar.collapsed {
    width: 100%;
    padding: 1rem;
  }

  .sidebar.collapsed .brand-name,
  .sidebar.collapsed .view-toggle,
  .sidebar.collapsed .sidebar-build {
    display: revert;
  }

  .sidebar.collapsed .nav-text {
    display: inline;
  }

  .sidebar.collapsed .chev {
    display: inline-flex;
  }

  .nav {
    margin-top: 0;
  }

  .content {
    padding: 1rem;
  }

  .card {
    padding: 1.25rem;
  }

  .topology-card {
    padding: 1.25rem;
  }

  .topology-wrap {
    padding: 1rem;
  }

  .topology-legend {
    gap: 0.75rem;
  }

  .hero h1 {
    font-size: 1.75rem;
  }

  .actions {
    flex-direction: column;
  }

  /* Single-column forms on mobile */
  .split {
    grid-template-columns: 1fr;
  }

  .panel-grid {
    grid-template-columns: 1fr;
  }

  /* EMS page hero stacks vertically */
  .ems-hero {
    flex-direction: column;
    gap: 1rem;
    align-items: flex-start;
  }

  /* Danger zone inner actions */
  .danger-zone-header {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* Additional polish */
::selection {
  background: var(--primary);
  color: white;
}

input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus {
  -webkit-box-shadow: 0 0 0 1000px var(--bg-elevated) inset;
  -webkit-text-fill-color: var(--text-primary);
  border-color: var(--primary);
}

/* Battery Debug OEM Layout */
.battery-debug-page {
  max-width: 1680px;
}

.battery-debug-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1.5rem;
  margin-bottom: 1rem;
}

.battery-debug-meta {
  display: grid;
  gap: 0.2rem;
  min-width: 280px;
  color: var(--text-secondary);
  font-size: 0.92rem;
}

.battery-debug-statusbar {
  margin-bottom: 1rem;
}

.oem-workbench {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
}

.oem-side-rail,
.oem-main-area {
  display: grid;
  gap: 1rem;
}

.oem-group {
  border: 1px solid rgba(96, 165, 250, 0.18);
  border-radius: 10px;
  background: rgba(8, 15, 27, 0.88);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.02), var(--shadow-sm);
  padding: 0.95rem 1rem 1rem;
  min-width: 0;
}

.oem-group legend {
  padding: 0 0.45rem;
  color: #cfe5ff;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.battery-selector-rail {
  display: grid;
  gap: 0.65rem;
}

.battery-select-card {
  width: 100%;
  display: grid;
  gap: 0.45rem;
  padding: 0.75rem 0.8rem;
  border-radius: 8px;
  border: 1px solid rgba(148, 163, 184, 0.18);
  background: rgba(15, 23, 42, 0.66);
  color: var(--text-primary);
  text-align: left;
  cursor: pointer;
  transition: border-color 0.12s ease, background-color 0.12s ease;
}

.battery-select-card:hover {
  border-color: rgba(96, 165, 250, 0.45);
  background: rgba(30, 41, 59, 0.88);
}

.battery-select-card.active {
  border-color: rgba(59, 130, 246, 0.7);
  background: rgba(26, 45, 68, 0.92);
  box-shadow: inset 0 0 0 1px rgba(147, 197, 253, 0.18);
}

.battery-select-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.battery-select-id {
  font-weight: 700;
  letter-spacing: 0.02em;
}

.battery-select-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  color: var(--text-secondary);
  font-size: 0.82rem;
}

.oem-main-grid,
.oem-secondary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.oem-readout-table {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.45rem 1rem;
}

.oem-readout-table.compact {
  grid-template-columns: minmax(0, 1fr);
}

.oem-readout-row {
  display: grid;
  grid-template-columns: minmax(120px, 0.95fr) minmax(0, 1.05fr);
  gap: 0.65rem;
  align-items: center;
  min-width: 0;
}

.oem-readout-label {
  color: var(--text-muted);
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.oem-readout-value {
  min-height: 34px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 0.45rem 0.65rem;
  border-radius: 6px;
  border: 1px solid rgba(148, 163, 184, 0.16);
  background: rgba(2, 6, 23, 0.7);
  color: #f8fafc;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 0.92rem;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.oem-signal-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.65rem;
}

.signal-indicator {
  display: grid;
  gap: 0.18rem;
  padding: 0.7rem 0.8rem;
  border-radius: 8px;
  border: 1px solid rgba(148, 163, 184, 0.16);
  background: rgba(2, 6, 23, 0.64);
}

.signal-label {
  color: var(--text-muted);
  font-size: 0.72rem;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.signal-value {
  font-size: 1rem;
  font-weight: 700;
}

.signal-note {
  color: var(--text-secondary);
  font-size: 0.76rem;
}

.signal-indicator.ok {
  border-color: rgba(16, 185, 129, 0.28);
  box-shadow: inset 0 0 0 1px rgba(16, 185, 129, 0.08);
}

.signal-indicator.info {
  border-color: rgba(59, 130, 246, 0.28);
  box-shadow: inset 0 0 0 1px rgba(59, 130, 246, 0.08);
}

.signal-indicator.caution,
.signal-indicator.warn {
  border-color: rgba(245, 158, 11, 0.32);
  box-shadow: inset 0 0 0 1px rgba(245, 158, 11, 0.08);
}

.signal-indicator.danger {
  border-color: rgba(239, 68, 68, 0.32);
  box-shadow: inset 0 0 0 1px rgba(239, 68, 68, 0.08);
}

.signal-indicator.muted {
  opacity: 0.82;
}

.oem-issue-stack {
  display: grid;
  gap: 0.65rem;
  margin-top: 0.8rem;
}

.issue-block {
  padding: 0.7rem 0.8rem;
  border-radius: 8px;
  border: 1px solid rgba(148, 163, 184, 0.16);
  background: rgba(2, 6, 23, 0.55);
}

.issue-title {
  margin-bottom: 0.45rem;
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.issue-values {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.issue-empty {
  color: var(--text-muted);
  font-size: 0.82rem;
}

.oem-pack-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.8rem;
}

.oem-cell-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.55rem;
}

.oem-cell {
  display: grid;
  gap: 0.16rem;
  padding: 0.62rem 0.7rem;
  border-radius: 8px;
  border: 1px solid rgba(59, 130, 246, 0.14);
  background: rgba(8, 15, 27, 0.9);
  min-height: 70px;
}

.oem-cell-name {
  color: var(--text-muted);
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.oem-cell-value {
  color: var(--text-primary);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 1rem;
  font-weight: 700;
}

.oem-cell.is-low {
  border-color: rgba(239, 68, 68, 0.45);
  background: rgba(58, 18, 22, 0.9);
}

.oem-cell.is-mid {
  border-color: rgba(59, 130, 246, 0.24);
}

.oem-cell.is-high {
  border-color: rgba(16, 185, 129, 0.45);
  background: rgba(10, 52, 44, 0.9);
}

.oem-temp-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem;
  margin-top: 0.75rem;
}

.oem-temp-grid .temp-card {
  border-radius: 8px;
  border: 1px solid rgba(148, 163, 184, 0.14);
  background: rgba(2, 6, 23, 0.68);
}

.oem-compare-table {
  margin-top: 0.15rem;
}

.oem-compare-table th {
  background: rgba(2, 6, 23, 0.66);
}

.oem-protocol-note {
  background: rgba(2, 6, 23, 0.58);
}

@media (max-width: 1280px) {
  .oem-workbench {
    grid-template-columns: minmax(0, 1fr);
  }

  .oem-side-rail {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 980px) {
  .battery-debug-header {
    flex-direction: column;
  }

  .oem-main-grid,
  .oem-secondary-grid,
  .oem-side-rail {
    grid-template-columns: minmax(0, 1fr);
  }

  .oem-readout-table {
    grid-template-columns: minmax(0, 1fr);
  }

  .oem-signal-grid,
  .oem-temp-grid,
  .oem-cell-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .oem-cell-grid,
  .oem-signal-grid,
  .oem-temp-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .oem-pack-head {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* Generic device debug tables */
.debug-table-layout {
  display: grid;
  gap: 1rem;
}

.debug-section {
  padding: 1.35rem;
}

.diag-subtitle {
  margin-bottom: 0.55rem;
  color: var(--text-secondary);
  font-size: 0.86rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.diag-table-wrap {
  overflow-x: auto;
  border: 1px solid rgba(148, 163, 184, 0.14);
  border-radius: 10px;
  background: rgba(2, 6, 23, 0.55);
}

.diag-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  line-height: 1.45;
}

.diag-table th,
.diag-table td {
  padding: 0.75rem 0.85rem;
  border-bottom: 1px solid rgba(148, 163, 184, 0.1);
  text-align: left;
  vertical-align: top;
  white-space: normal;
  overflow-wrap: anywhere;
}

.diag-table thead th {
  position: sticky;
  top: 0;
  background: rgba(15, 23, 42, 0.96);
  color: var(--text-secondary);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  z-index: 1;
}

.diag-table tbody th {
  width: 28%;
  background: rgba(15, 23, 42, 0.55);
  color: var(--text-secondary);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  line-height: 1.35;
}

.diag-table tbody tr:last-child th,
.diag-table tbody tr:last-child td {
  border-bottom: 0;
}

.diag-table-compact tbody th {
  width: 40%;
}

.diag-table code {
  white-space: normal;
  overflow-wrap: anywhere;
}

.diag-empty,
.diag-empty-inline {
  color: var(--text-muted);
}

.diag-empty {
  padding: 1rem;
}

.device-poll-sections,
.battery-detail-sections {
  display: grid;
  gap: 1rem;
}

.device-debug-card {
  display: grid;
  gap: 0.85rem;
  padding: 1.15rem;
  border-radius: var(--radius);
  border: 1px solid rgba(148, 163, 184, 0.16);
  background: rgba(2, 6, 23, 0.34);
}

.device-debug-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.debug-two-col {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.diag-state-block {
  display: grid;
  gap: 0.95rem;
  padding: 1rem;
  border-radius: 10px;
  border: 1px solid rgba(148, 163, 184, 0.14);
  background: rgba(15, 23, 42, 0.45);
  line-height: 1.45;
}

.diag-state-block strong {
  display: inline-block;
  margin-bottom: 0.35rem;
}

.diag-value-stack {
  display: grid;
  gap: 0.28rem;
}

.diag-value-item {
  min-width: 0;
}

.diag-value-pair {
  display: grid;
  grid-template-columns: minmax(100px, 0.9fr) auto minmax(0, 1.1fr);
  gap: 0.4rem;
  align-items: start;
}

.diag-value-key {
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.diag-value-sep {
  color: var(--text-muted);
}

.diag-value-text {
  color: var(--text-primary);
}

.diag-inline-json {
  margin: 0;
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  border: 1px solid rgba(148, 163, 184, 0.12);
  background: rgba(15, 23, 42, 0.42);
  color: var(--text-secondary);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 0.82rem;
  line-height: 1.45;
}

.cell-table td.diag-low,
.cell-table th.diag-low {
  background: rgba(127, 29, 29, 0.36);
  color: #fecaca;
}

.cell-table td.diag-high,
.cell-table th.diag-high {
  background: rgba(6, 78, 59, 0.36);
  color: #bbf7d0;
}

@media (max-width: 980px) {
  .debug-two-col {
    grid-template-columns: minmax(0, 1fr);
  }

  .device-debug-card-head,
  .battery-debug-header {
    flex-direction: column;
  }

  .diag-value-pair {
    grid-template-columns: minmax(0, 1fr);
    gap: 0.15rem;
  }

  .diag-value-sep {
    display: none;
  }
}

/* ================================================================
   REDESIGN ADDITIONS
   ================================================================ */

/* --- Badges --- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 0.2rem 0.55rem;
  border-radius: var(--radius-pill);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  white-space: nowrap;
}
.badge::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}
.badge-success { color: var(--color-success); background: var(--color-success-dim); }
.badge-warning { color: var(--color-warning); background: var(--color-warning-dim); }
.badge-danger  { color: var(--color-danger);  background: var(--color-danger-dim);  }
.badge-info    { color: var(--color-info);    background: var(--color-info-dim);    }
.badge-muted   { color: var(--text-muted);    background: rgba(100,116,139,0.1);    }

/* --- Skeleton Loader --- */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--bg-elevated) 25%,
    var(--bg-card) 50%,
    var(--bg-elevated) 75%
  );
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.4s ease infinite;
  border-radius: var(--radius-sm);
  display: inline-block;
}
@keyframes skeleton-shimmer {
  from { background-position: 200% 0; }
  to   { background-position: -200% 0; }
}


/* --- Mode Toggle (Simple / Advanced) --- */
.mode-toggle {
  padding: 0.75rem;
  border-top: 1px solid var(--border-subtle);
  margin-top: auto;
}
.mode-toggle-label {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}
.mode-toggle-pills {
  display: flex;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 3px;
  gap: 2px;
}
.mode-pill {
  flex: 1;
  padding: 0.28rem 0.5rem;
  font-size: 0.74rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--transition-fast);
  text-align: center;
}
.mode-pill[aria-pressed="true"] {
  background: var(--bg-card);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}
.sidebar.collapsed .mode-toggle-label { display: none; }
.sidebar.collapsed .mode-toggle { padding: 0.5rem; }

/* --- UI Mode Gating --- */
[data-ui-mode="simple"] [data-advanced] { display: none !important; }
[data-simple] { display: none; }
[data-ui-mode="simple"] [data-simple] { display: flex; }
[data-ui-mode="simple"] #tab-general { display: block !important; }
[data-ui-mode="simple"] .device-row { cursor: default; pointer-events: none; }
[data-ui-mode="simple"] .device-row:hover { background: transparent; border-color: var(--border-subtle); }

/* --- Mode Notice Banner --- */
.mode-notice {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0.9rem;
  background: var(--color-info-dim);
  border: 1px solid rgba(56, 189, 248, 0.2);
  border-radius: var(--radius);
  font-size: 0.82rem;
  color: var(--color-info);
  margin-bottom: 1rem;
}
[data-ui-mode="advanced"] .mode-notice[data-simple] { display: none; }

/* --- Nav Advanced Badge --- */
.nav-adv-badge {
  margin-left: auto;
  font-size: 0.62rem;
  font-weight: 700;
  padding: 0.1rem 0.32rem;
  border-radius: var(--radius-pill);
  background: var(--primary-dim);
  color: var(--primary);
  line-height: 1.4;
}
[data-ui-mode="advanced"] .nav-adv-badge { display: none; }
.sidebar.collapsed .nav-adv-badge { display: none; }

/* --- Nav Sub-menu --- */
.nav-submenu {
  display: none;
  flex-direction: column;
  gap: 0.1rem;
  padding-bottom: 0.25rem;
}

[data-ui-mode="advanced"] .nav a[data-nav="settings.html"].active ~ .nav-submenu {
  display: flex;
}

.nav-sub-link {
  display: block;
  color: var(--text-muted);
  text-decoration: none;
  padding: 0.32rem 0.9rem 0.32rem 2.6rem;
  border-radius: var(--radius);
  font-size: 0.8rem;
  font-weight: 500;
  transition: background-color var(--transition-fast), color var(--transition-fast);
}

.nav-sub-link:hover {
  color: var(--text-primary);
  background: var(--bg-elevated);
}

.sidebar.collapsed .nav-submenu { display: none !important; }

/* --- Advanced Collapsible Section --- */
.advanced-section { margin-top: 1.5rem; }
.advanced-section > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  cursor: pointer;
  list-style: none;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-secondary);
  transition: var(--transition-fast);
  user-select: none;
}
.advanced-section > summary::-webkit-details-marker { display: none; }
.advanced-section > summary:hover { color: var(--text-primary); border-color: var(--border); }
.advanced-section-chevron { transition: transform var(--transition-fast); }
details[open].advanced-section .advanced-section-chevron { transform: rotate(180deg); }
.advanced-section-body {
  padding: 1rem 0;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* --- Danger Zone --- */
.danger-zone {
  border: 1px solid rgba(239, 68, 68, 0.25);
  border-radius: var(--radius-xl);
  padding: 1.25rem 1.5rem;
  margin-top: 1.5rem;
  background: rgba(239, 68, 68, 0.04);
}
.danger-zone-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid rgba(239, 68, 68, 0.15);
  flex-wrap: wrap;
}
.danger-zone-title {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--color-danger);
}
.danger-zone-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-left: auto;
}

/* --- Button Danger Variant --- */
.btn.danger {
  background: var(--color-danger);
  color: #fff;
  border: none;
}
.btn.danger:hover { background: #dc2626; }

/* --- Topology Legend --- */
.topo-legend {
  display: flex;
  gap: 1.25rem;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 0.75rem;
  padding: 0.45rem 0.75rem;
  background: rgba(8, 13, 24, 0.5);
  border: 1px solid rgba(51, 65, 85, 0.35);
  border-radius: var(--radius);
}
.topo-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-secondary);
}
.topo-legend-item::before {
  content: '';
  width: 22px;
  height: 4px;
  border-radius: 999px;
  background: currentColor;
  flex-shrink: 0;
  box-shadow: 0 0 6px currentColor;
}
/* Items with inline SVG icons don't need the ::before dash indicator */
.topo-legend-item.flow-pv::before,
.topo-legend-item.flow-battery::before,
.topo-legend-item.flow-grid::before,
.topo-legend-item.flow-load::before { display: none; }
.topo-legend-item svg { flex-shrink: 0; filter: drop-shadow(0 0 3px currentColor); }
.topo-legend-item.flow-pv      { color: var(--flow-pv); }
.topo-legend-item.flow-battery { color: var(--flow-battery); }
.topo-legend-item.flow-grid    { color: var(--flow-grid); }
.topo-legend-item.flow-load    { color: var(--flow-load); }

/* --- Accessibility Focus Rings --- */
:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

/* ================================================================
   DASHBOARD — index.html
   All classes unique to the standalone dashboard page.
   ================================================================ */

/* --- Dashboard grid --- */
.dashboard-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 1rem; margin-bottom: 1.5rem; }
@media (max-width: 1280px) { .dashboard-grid { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 720px)  { .dashboard-grid { grid-template-columns: repeat(2, 1fr); } }

/* --- Live indicator bar --- */
.live-indicator-bar { display: flex; align-items: center; gap: 0.4rem; margin-bottom: 0.75rem; font-size: 0.78rem; color: var(--text-muted); }
.live-indicator-bar .live-dot { width: 7px; height: 7px; flex-shrink: 0; }
.live-indicator-bar .live-text { font-weight: 700; color: var(--accent); font-size: 0.8rem; }
.live-indicator-sep { opacity: 0.4; }

/* --- Stat cards --- */
.stat-card {
  position: relative; background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 1.1rem 1.2rem 0; box-shadow: var(--shadow-md);
  transition: border-color 0.15s; overflow: hidden; min-height: 168px;
  display: flex; flex-direction: column;
}
.stat-card:hover { border-color: rgba(96, 165, 250, 0.28); }
.stat-card::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--accent-color, transparent);
}
.stat-card[data-stat="solar"]       { --accent-color: var(--flow-pv); }
.stat-card[data-stat="grid"]        { --accent-color: var(--flow-grid); }
.stat-card[data-stat="battery"]     { --accent-color: var(--flow-battery); }
.stat-card[data-stat="consumption"] { --accent-color: var(--flow-load); }
.stat-card[data-stat="weather"]     { --accent-color: #6c8aa4; }
.stat-card-header { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; margin-bottom: 0.45rem; }
.stat-card-label { font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-muted); }
.stat-card-icon { width: 20px; height: 20px; color: var(--accent-color, var(--text-muted)); opacity: 0.9; flex-shrink: 0; }
.stat-card-icon svg { width: 100%; height: 100%; }
.stat-card-value { font-size: 2rem; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; margin-top: 0.5rem; font-variant-numeric: tabular-nums; }
.stat-card-value .unit { font-size: 0.95rem; color: var(--text-secondary); font-weight: 500; margin-left: 0.2rem; }

/* --- Stat sub-row and delta badge --- */
.stat-sub { display: flex; align-items: center; gap: 0.45rem; margin-top: 0.2rem; margin-bottom: 0.35rem; font-size: 0.78rem; color: var(--text-muted); }
.delta { display: inline-flex; align-items: center; gap: 0.15rem; padding: 0.06rem 0.38rem; border-radius: var(--radius-pill); font-weight: 600; font-variant-numeric: tabular-nums; font-size: 0.72rem; }
.delta.up   { color: #5fdfa0; background: rgba(46, 196, 137, 0.1); }
.delta.down { color: #ff8a93; background: rgba(230, 57, 70, 0.1); }
.delta.neut { color: var(--text-muted); background: rgba(255, 255, 255, 0.04); }

/* --- Sparkline canvas — bleed to card edges --- */
.stat-sparkline {
  display: block; pointer-events: none; height: 44px; margin-top: auto;
  margin-left: -1.2rem; margin-right: -1.2rem; width: calc(100% + 2.4rem);
}

/* --- Battery meta --- */
.battery-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 0.22rem 0.75rem; font-size: 0.78rem; color: var(--text-muted); margin-top: 0.4rem; margin-bottom: 0.35rem; }
.battery-meta > div { display: flex; flex-direction: column; gap: 0.05rem; }
.battery-meta-label { font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); }
.battery-meta > div > span:last-child { color: var(--text-primary); font-weight: 600; font-size: 0.82rem; font-variant-numeric: tabular-nums; }

/* --- Weather extras (redesign — replaces old .weather-meta) --- */
.weather-extras { display: flex; flex-direction: column; gap: 0.2rem; margin-top: 0.4rem; padding-top: 0.5rem; border-top: 1px dashed var(--border-subtle); font-size: 0.78rem; color: var(--text-muted); }
.weather-extras b { color: var(--text-primary); font-weight: 600; font-variant-numeric: tabular-nums; }

/* --- Charts grid and card header --- */
.charts-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(400px, 1fr)); gap: 1.5rem; margin-bottom: 1.5rem; }
.chart-card { grid-column: span 1; }
.chart-card.wide { grid-column: 1 / -1; }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.card-actions { display: flex; align-items: center; gap: 0.5rem; }
.mini-btn { border: 1px solid var(--border); background: transparent; color: var(--text-secondary); padding: 0.25rem 0.6rem; border-radius: var(--radius-pill); font-size: 0.75rem; cursor: pointer; transition: background var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast); }
.mini-btn:hover { color: var(--text-primary); border-color: var(--primary); }
.mini-btn.active { background: var(--bg-elevated); color: var(--text-primary); border-color: var(--primary); }

/* --- Segmented range control (pill style) --- */
.segmented-control { display: inline-flex; background: var(--bg-input); border: 1px solid var(--border-subtle); border-radius: var(--radius-pill); padding: 3px; }
.seg-btn { border: 0; background: transparent; color: var(--text-secondary); padding: 0.32rem 0.85rem; font: 600 0.78rem var(--font-sans); border-radius: var(--radius-pill); cursor: pointer; transition: background var(--transition-fast), color var(--transition-fast); font-variant-numeric: tabular-nums; }
.seg-btn:hover { color: var(--text-primary); }
.seg-btn.active { background: var(--primary); color: #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.5); }

/* --- Chart legend chips --- */
.legend { display: flex; flex-wrap: wrap; gap: 0.45rem; margin: 0.75rem 0 0.5rem; }
.legend-chip { display: inline-flex; align-items: center; gap: 0.45rem; padding: 0.32rem 0.7rem; border-radius: var(--radius-pill); background: var(--bg-input); border: 1px solid var(--border-subtle); color: var(--text-secondary); font: 500 0.8rem var(--font-sans); cursor: pointer; user-select: none; transition: border-color var(--transition-fast), background var(--transition-fast), color var(--transition-fast); }
.legend-chip:hover { color: var(--text-primary); border-color: rgba(96, 165, 250, 0.35); }
.legend-chip.off { opacity: 0.45; }
.legend-chip.off .swatch-row { filter: grayscale(0.9); }
.swatch-row { display: inline-flex; align-items: center; gap: 3px; }
.swatch { width: 12px; height: 3px; border-radius: 2px; background: var(--c, #fff); }
.swatch.dashed { background: repeating-linear-gradient(to right, var(--c, #fff) 0 4px, transparent 4px 7px); }
.legend-meta { margin-left: auto; color: var(--text-muted); font-size: 0.74rem; display: flex; align-items: center; gap: 0.4rem; }

/* --- Pill tag (forecast badge) --- */
.pill-tag { display: inline-flex; align-items: center; padding: 0.18rem 0.55rem; border-radius: var(--radius-pill); background: rgba(168, 85, 247, 0.1); border: 1px solid rgba(168, 85, 247, 0.3); color: #c4a4f6; font-size: 0.7rem; font-weight: 600; letter-spacing: 0.02em; }

/* --- Chart container and uPlot --- */
.chart-container {
  min-height: 410px;
  margin-top: 0.75rem;
  position: relative;
  overflow: hidden;
  min-width: 0;
  padding: 0.85rem 0.85rem 0.55rem;
  border-radius: calc(var(--radius-xl) + 2px);
  border: 1px solid rgba(148, 163, 184, 0.12);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.03), rgba(255, 255, 255, 0.01)),
    radial-gradient(120% 100% at 0% 0%, rgba(0, 168, 232, 0.08), transparent 44%),
    radial-gradient(110% 90% at 100% 0%, rgba(46, 196, 182, 0.08), transparent 40%),
    rgba(6, 20, 38, 0.74);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.04),
    inset 0 0 0 1px rgba(6, 20, 38, 0.35);
}
.chart-toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.75rem; margin-top: 0.75rem; }
.chart-pills, .series-toggles { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.chart-meta { color: var(--text-muted); font-size: 0.8rem; font-variant-numeric: tabular-nums; }
.series-toggle { display: inline-flex; align-items: center; gap: 0.35rem; color: var(--text-secondary); font-size: 0.8rem; padding: 0.2rem 0.45rem; border: 1px solid var(--border); border-radius: var(--radius-pill); background: rgba(6, 20, 38, 0.4); }
.series-toggle input { accent-color: var(--primary); }
.uplot-host { width: 100%; height: 390px; min-width: 0; }
.uplot {
  font-family: inherit;
  max-width: 100%;
  overflow: hidden;
  border-radius: calc(var(--radius-lg) + 2px);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.02), rgba(255, 255, 255, 0)),
    rgba(6, 20, 38, 0.18);
}
.uplot canvas,
.uplot .u-wrap,
.uplot .u-under,
.uplot .u-over { border-radius: inherit; }
.uplot, .uplot .u-title, .uplot .u-label, .uplot .u-value { color: var(--text-secondary); }
.uplot .u-legend { display: none; }
.uplot .u-select {
  background: rgba(59, 130, 246, 0.14);
  border: 1px solid rgba(96, 165, 250, 0.35);
  border-radius: 8px;
}
.uplot .u-cursor-x,
.uplot .u-cursor-y { border-color: rgba(184, 199, 214, 0.16) !important; }
.chart-tooltip { position: absolute; z-index: 20; pointer-events: none; min-width: 180px; max-width: min(320px, calc(100% - 16px)); padding: 0.75rem 0.9rem; border-radius: var(--radius-lg); border: 1px solid rgba(148, 163, 184, 0.28); background: rgba(6, 20, 38, 0.96); box-shadow: 0 14px 30px rgba(0, 0, 0, 0.45); color: var(--text-primary); opacity: 0; transition: opacity 0.12s ease; }
.chart-tooltip.visible { opacity: 1; }
.chart-tooltip-time { font-size: 0.78rem; color: var(--text-muted); margin-bottom: 0.5rem; }
.chart-tooltip-grid { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0.25rem 0.75rem; font-size: 0.83rem; }
.chart-tooltip-label { display: inline-flex; align-items: center; gap: 0.45rem; color: var(--text-secondary); }
.chart-tooltip-swatch { width: 0.6rem; height: 0.6rem; border-radius: var(--radius-pill); flex: 0 0 auto; }
.chart-tooltip-value { color: var(--text-primary); font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
.chart-card.collapsed .chart-container { display: none; }
.chart-card.collapsed { padding-bottom: 1rem; }

/* --- SVG utility --- */
.icon-stroke { fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

/* --- Topology (dashboard-specific X6 layout) --- */
.topology-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 1.25rem; padding-bottom: 1rem; border-bottom: 1px solid rgba(148, 163, 184, 0.1); gap: 1rem; }
/* Override topology-title for dashboard (smaller h1) */
.topology-card .topology-title h1 { font-size: 1.35rem; font-weight: 700; margin-bottom: 0.25rem; letter-spacing: -0.3px; }
.topology-card .topology-title span { color: var(--text-muted); font-size: 0.85rem; display: flex; align-items: center; gap: 0.5rem; }
.topology-status { margin-top: 0.5rem; color: var(--text-muted); font-size: 0.85rem; line-height: 1.45; }
.topology-status.is-stale { color: #fbbf24; }
.topology-controls { display: flex; align-items: center; justify-content: flex-end; gap: 0.75rem; flex-shrink: 0; }
.topology-debug-toggle { display: inline-flex; align-items: center; gap: 0.45rem; color: var(--text-muted); font-size: 0.82rem; border: 1px solid rgba(148, 163, 184, 0.18); border-radius: var(--radius-pill); padding: 0.3rem 0.6rem; background: rgba(10, 15, 26, 0.5); user-select: none; cursor: pointer; }
.topology-debug-toggle:hover { color: var(--text-secondary); border-color: rgba(148, 163, 184, 0.32); }
.topology-debug-toggle input { accent-color: var(--primary); }
.topo-toggle { display: inline-flex; align-items: center; gap: 0.45rem; color: var(--text-muted); font-size: 0.82rem; border: 1px solid rgba(148, 163, 184, 0.18); border-radius: var(--radius-pill); padding: 0.3rem 0.6rem; background: rgba(10, 15, 26, 0.5); user-select: none; cursor: pointer; }
.topo-toggle:hover { color: var(--text-secondary); border-color: rgba(148, 163, 184, 0.32); }
.topo-toggle input { accent-color: var(--primary); margin: 0; }
.topo-title-row { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.topology-heading { font-size: 1.1rem; font-weight: 700; margin: 0; color: var(--text-primary); }
.topo-live-pill { display: inline-flex; align-items: center; gap: 0.35rem; font-size: 0.72rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: #4ade80; opacity: 0.85; }
.topo-live-pill .live-dot { width: 6px; height: 6px; border-radius: 50%; background: #4ade80; flex-shrink: 0; animation: topoLivePulse 1.8s ease-in-out infinite; }
@keyframes topoLivePulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }
/* Dashboard topology wrap */
.topology-card .topology-wrap { margin-bottom: 1rem; }
.topology-scroll { overflow-x: auto; overflow-y: hidden; display: flex; justify-content: center; }
.topo-title-row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.7rem 0.9rem; }
.topology-heading { font-size: 1.35rem; font-weight: 700; color: var(--text-primary); letter-spacing: -0.02em; }
.topo-live-pill { display: inline-flex; align-items: center; gap: 0.45rem; padding: 0.28rem 0.65rem; border-radius: var(--radius-pill); border: 1px solid rgba(16, 185, 129, 0.28); background: rgba(16, 185, 129, 0.12); color: #d1fae5; font-size: 0.74rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; }
.topo-live-pill .live-dot { width: 0.55rem; height: 0.55rem; border-radius: 999px; background: #34d399; box-shadow: 0 0 0 0.28rem rgba(16, 185, 129, 0.14); }
.topo-toggle { display: inline-flex; align-items: center; gap: 0.55rem; padding: 0.36rem 0.72rem; border-radius: var(--radius-pill); border: 1px solid rgba(148, 163, 184, 0.18); background: rgba(10, 15, 26, 0.5); color: var(--text-secondary); font-size: 0.82rem; user-select: none; cursor: pointer; }
.topo-toggle:hover { border-color: rgba(148, 163, 184, 0.32); color: var(--text-primary); }
.topo-toggle input { accent-color: var(--primary); }
.topo-canvas { position: relative; margin-top: 0.75rem; border-radius: var(--radius-lg); background: radial-gradient(circle, rgba(100, 116, 139, 0.12) 1px, transparent 1px) 0 0 / 24px 24px, rgba(8, 13, 24, 0.6); border: 1px solid var(--border-subtle); overflow: auto; }
.topo-canvas { position: relative; width: 1260px; min-width: 1260px; min-height: 560px; margin: 0 auto; }
.topo-stage { position: relative; width: 1260px; height: 560px; margin: 0 auto; }
.topo-edges-svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; z-index: 0; }
.topology-graph-host { width: 1120px; min-width: 1120px; height: 500px; margin: 0 auto; }
.topology-graph-host .x6-graph, .topology-graph-host .x6-graph-svg { background: transparent !important; }
.topology-graph-host .x6-node rect { vector-effect: non-scaling-stroke; }
.topology-canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 0; overflow: visible; }
.topology-link-base, .topology-link-active { fill: none; stroke-linecap: round; stroke-linejoin: round; transition: opacity 0.18s ease, stroke 0.18s ease; }
.topology-link-base { stroke: rgba(100, 116, 139, 0.42); stroke-width: 4; }
.topology-link-active { stroke-width: 5; opacity: 0; stroke-dasharray: 12 8; animation: topologyFlowDash 1.4s linear infinite; filter: drop-shadow(0 0 10px rgba(96, 165, 250, 0.25)); }
.topology-link-group.is-visible .topology-link-base { opacity: 1; }
.topology-link-group.is-structural .topology-link-active, .topology-link-group.is-structural .topology-link-indicator { display: none; }
.topology-link-group.is-structural .topology-link-base { stroke: rgba(148, 163, 184, 0.32); stroke-dasharray: 4 6; }
.topology-link-group:not(.is-visible) .topology-link-base, .topology-link-group:not(.is-visible) .topology-link-active { opacity: 0; }
.topology-link-group.is-active .topology-link-active { opacity: 0.92; }
.topology-link-group.is-reverse .topology-link-active { animation-direction: reverse; }
.topology-link-indicator { opacity: 0; transition: opacity 0.18s ease; }
.topology-link-group.is-active .topology-link-indicator { opacity: 1; }
.topology-arrow { fill: none; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; animation: topologyArrowPulse 1.4s ease-in-out infinite; }
.topology-link-group.flow-pv .topology-link-active, .topology-link-group.flow-pv .topology-arrow { stroke: rgba(255, 176, 0, 0.95); }
.topology-link-group.flow-grid .topology-link-active, .topology-link-group.flow-grid .topology-arrow { stroke: rgba(0, 119, 182, 0.95); }
.topology-link-group.flow-battery .topology-link-active, .topology-link-group.flow-battery .topology-arrow { stroke: rgba(46, 196, 182, 0.95); }
.topology-link-group.flow-load .topology-link-active, .topology-link-group.flow-load .topology-arrow { stroke: rgba(184, 199, 214, 0.95); }
.topology-link-group.flow-grid-port .topology-link-active, .topology-link-group.flow-grid-port .topology-arrow { stroke: rgba(0, 168, 232, 0.95); }
@keyframes topologyFlowDash { from { stroke-dashoffset: 0; } to { stroke-dashoffset: -40; } }
@keyframes topologyArrowPulse { 0%, 100% { opacity: 0.72; transform: scale(0.96); } 50% { opacity: 1; transform: scale(1.04); } }
.topo-node { position: absolute; background: var(--bg-elevated); border: 2px solid var(--border); border-radius: 16px; padding: 1.25rem; min-width: 160px; transition: border-color 0.12s ease, box-shadow 0.12s ease; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3); z-index: 1; }
.topo-node.compact { min-width: 136px; padding: 0.9rem 1rem; }
.topo-node:hover { border-color: var(--primary); box-shadow: 0 6px 18px rgba(0, 0, 0, 0.42); }
.topo-node.is-inactive { opacity: 0.58; filter: saturate(0.78); }
.topo-node header { display: flex; align-items: center; gap: 0.7rem; margin-bottom: 0.85rem; font-weight: 700; color: var(--text-primary); }
.topo-node header span:last-child { font-size: 0.96rem; line-height: 1.2; white-space: nowrap; }
.n-icon { display: inline-flex; align-items: center; justify-content: center; width: 1.9rem; height: 1.9rem; flex: 0 0 1.9rem; border-radius: 999px; background: rgba(96, 165, 250, 0.12); color: #dbeafe; font-size: 1rem; }
.n-pv .n-icon { background: rgba(245, 158, 11, 0.18); color: #fde68a; }
.n-battery .n-icon { background: rgba(20, 184, 166, 0.16); color: #ccfbf1; }
.n-grid .n-icon, .n-meter .n-icon { background: rgba(59, 130, 246, 0.16); color: #dbeafe; }
.n-load .n-icon, .n-eps .n-icon { background: rgba(148, 163, 184, 0.14); color: #e2e8f0; }
.n-generator .n-icon { background: rgba(168, 85, 247, 0.16); color: #f3e8ff; }
.topo-node dl { margin: 0; display: grid; gap: 0.45rem; }
.topo-node dl + dl { margin-top: 0.7rem; padding-top: 0.7rem; border-top: 1px solid rgba(148, 163, 184, 0.14); }
.topo-node dl > div { display: flex; align-items: baseline; justify-content: space-between; gap: 0.75rem; }
.topo-node dt { color: var(--text-muted); font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.06em; }
.topo-node dd { margin: 0; color: var(--text-primary); font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
#pv-mppt-list dt, #meter-lines dt { text-transform: none; letter-spacing: 0; font-size: 0.78rem; }
#pv-mppt-list dd, #meter-lines dd { font-size: 0.84rem; }
.topo-legend { display: flex; align-items: center; flex-wrap: wrap; gap: 0.8rem 1.1rem; color: var(--text-muted); font-size: 0.8rem; }
.topo-legend-item { display: inline-flex; align-items: center; gap: 0.45rem; }
.topo-legend-item .dot { width: 0.68rem; height: 0.68rem; border-radius: 999px; box-shadow: 0 0 0 0.24rem rgba(15, 23, 42, 0.42); }
.topo-legend-key { margin-left: auto; white-space: nowrap; }
.topo-node-header { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 0.75rem; }
.topo-icon { font-size: 28px; line-height: 1; }
.topo-node-title { font-weight: 700; font-size: 1rem; color: var(--text-primary); }
.topo-stat { font-size: 0.85rem; color: var(--text-secondary); margin-top: 0.25rem; }
.topo-value { font-weight: 600; color: var(--text-primary); }
.topo-data-grid { margin-top: 0.6rem; display: grid; grid-template-columns: auto 1fr; gap: 0.25rem 0.6rem; font-size: 0.8rem; color: var(--text-muted); }
.topo-data-grid span { color: var(--text-primary); font-weight: 600; }
.topo-terminal-grid { margin-top: 0.85rem; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.45rem; }
.topo-terminal { display: inline-flex; align-items: center; justify-content: center; padding: 0.22rem 0.45rem; border-radius: var(--radius-pill); border: 1px solid rgba(148, 163, 184, 0.18); background: rgba(6, 20, 38, 0.58); color: var(--text-secondary); font-size: 0.72rem; letter-spacing: 0.06em; text-transform: uppercase; }
.node-pv        { top: 80px;  left: 56px;                             min-width: 170px; }
.node-battery   { top: 280px; left: 56px;                             min-width: 190px; }
.node-inverter  { top: 188px; left: 50%; transform: translateX(-50%); min-width: 228px; background: #223549; border-color: rgba(96, 165, 250, 0.42); }
.node-meter     { top: 78px;  left: calc(50% + 174px);                min-width: 150px; }
.node-grid      { top: 92px;  right: 32px;                            min-width: 142px; }
.node-load      { top: 262px; right: 32px;                            min-width: 184px; }
.node-eps       { top: 472px; left: 50%; transform: translateX(-50%); min-width: 184px; }
.node-generator { top: 476px; left: 56px;                             min-width: 160px; }

/* --- Footer and canvas (dashboard overrides) --- */
.footer { background: rgba(30, 41, 59, 0.6); border-top: 1px solid var(--border); padding: 1.25rem 2rem; text-align: center; color: var(--text-muted); font-size: 0.9rem; margin-top: 1.5rem; }
.footer-brand { color: var(--text-primary); font-weight: 600; }
.footer-build { margin-top: 0.35rem; color: var(--text-muted); font-family: var(--font-mono); font-size: 0.8rem; overflow-wrap: anywhere; }
canvas { max-width: 100%; }

/* --- Dashboard responsive breakpoints --- */
@media (max-width: 768px) {
  .dashboard-grid     { grid-template-columns: 1fr; }
  .charts-grid        { grid-template-columns: 1fr; }
  .topo-canvas        { width: 100%; min-width: 0; min-height: 0; }
  .topo-stage         { width: 100%; height: auto; display: flex; flex-direction: column; gap: 1rem; }
  .topo-edges-svg     { display: none; }
  .topo-node          { position: static; margin-bottom: 1rem; transform: none !important; min-width: 0; width: 100%; }
  .topology-card .topology-wrap { padding: 1rem; min-height: auto; }
  .topology-header    { flex-direction: column; align-items: flex-start; gap: 0.75rem; }
  .topo-toggle        { align-self: stretch; justify-content: center; }
  .topo-legend        { flex-direction: column; align-items: flex-start; }
  .topo-legend-key    { margin-left: 0; }
  .chart-container    { min-height: 260px; padding: 0.65rem 0.65rem 0.45rem; }
  .uplot-host         { height: 240px; }
  .stat-card-value    { font-size: 1.8rem; }
  .topo-terminal-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .chart-toolbar      { flex-direction: column; align-items: flex-start; }
  .segmented-control  { flex-wrap: wrap; }
}

/* ================================================================
   LOGIN PAGE — login.html
   All classes scoped to body[data-page="login"].
   ================================================================ */

body[data-page="login"] {
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(59, 130, 246, 0.18), transparent 32rem),
    radial-gradient(circle at bottom right, rgba(34, 197, 94, 0.12), transparent 28rem),
    var(--bg-page);
}

body[data-page="login"] .login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: var(--space-6);
}

body[data-page="login"] .login-card {
  width: min(100%, 440px);
  padding: var(--space-8);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  background: var(--bg-card);
  border: 1px solid var(--border);
}

body[data-page="login"] .login-brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-6);
}

body[data-page="login"] .login-logo {
  width: 44px;
  height: 44px;
  object-fit: contain;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

body[data-page="login"] .login-brand-title {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1.2;
}

body[data-page="login"] .login-brand-subtitle {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 1px;
}

body[data-page="login"] .login-hero {
  margin-bottom: var(--space-6);
}

body[data-page="login"] .login-hero h1 {
  margin: 0;
  font-size: 1.8rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text-primary);
}

body[data-page="login"] .login-hero p {
  margin: 0.5rem 0 0;
  color: var(--text-secondary);
  font-size: 0.95rem;
  line-height: 1.5;
}

body[data-page="login"] .login-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  margin-top: var(--space-5);
}

body[data-page="login"] .login-form .form-row {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

body[data-page="login"] .login-form .input {
  width: 100%;
  padding: 0.6rem 0.85rem;
}

body[data-page="login"] .login-submit {
  width: 100%;
  padding: 0.65rem 1rem;
  font-size: 0.95rem;
  margin-top: var(--space-1);
}

body[data-page="login"] .login-status {
  text-align: center;
  font-size: 0.875rem;
  min-height: 1.5em;
}

body[data-page="login"] .login-footer {
  margin-top: var(--space-5);
  color: var(--text-muted);
  font-size: 0.78rem;
  text-align: center;
}

body[data-page="login"] .login-footer .footer-brand {
  color: var(--text-secondary);
  font-weight: 500;
}

body[data-page="login"] .login-footer .footer-build {
  margin-top: 0.25rem;
  font-family: var(--font-mono);
  font-size: 0.72rem;
}

/* Password toggle button */
.text-button {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  transition: color var(--transition-fast);
  font-family: var(--font-sans);
}
.text-button:hover { color: var(--primary-hover); }

@media (max-width: 520px) {
  body[data-page="login"] .login-shell {
    padding: var(--space-4);
  }

  body[data-page="login"] .login-card {
    padding: var(--space-5);
  }

  body[data-page="login"] .login-hero h1 {
    font-size: 1.5rem;
  }
}
