:root {
  --bg: #0b0f14;
  --surface: #141a22;
  --surface-2: #1b232d;
  --border: #263140;
  --text: #e6edf3;
  --muted: #7c8b9c;
  --accent: #3ddc84;
  --danger: #ef5a5a;
  --warning: #f0a93c;
  --dev: #a78bfa;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.hidden { display: none !important; }


.brand-logo {
  height: 32px;
  width: 32px;
}


.energyflow-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.stat-label {
  font-size: 0.8rem;
  color: var(--muted);
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
}

.stat-sub {
  font-size: 0.75rem;
  color: var(--warning);
}

.consumer-breakdown {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  margin-top: 0.3rem;
}

.consumer-breakdown-row {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.loadmgmt-banner {
  background: rgba(240, 169, 60, 0.12);
  border: 1px solid var(--warning);
  color: var(--warning);
  border-radius: 8px;
  padding: 0.7rem 1rem;
  margin-bottom: 1.25rem;
  font-size: 0.9rem;
  font-weight: 600;
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.4rem 0.9rem;
  border-radius: 6px;
  cursor: pointer;
}
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn-ghost.small { padding: 0.25rem 0.6rem; font-size: 0.8rem; }
.btn-ghost.danger:hover { border-color: var(--danger); color: var(--danger); }

.btn-primary {
  background: var(--accent);
  border: none;
  border-radius: 6px;
  padding: 0.45rem 1rem;
  font-weight: 600;
  color: #06210f;
  cursor: pointer;
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-primary.small { padding: 0.25rem 0.6rem; font-size: 0.8rem; }
.btn-primary:disabled {
  background: var(--surface-2);
  color: var(--muted);
  cursor: not-allowed;
  filter: none;
}

.dev-card {
  border-color: var(--dev);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 1.25rem;
  max-width: 480px;
}
.dev-card h2 {
  margin: 0;
  font-size: 1.05rem;
  color: var(--dev);
}

.btn-dev {
  background: var(--dev);
  border: none;
  border-radius: 6px;
  padding: 0.45rem 1rem;
  font-weight: 600;
  color: #1c1330;
  cursor: pointer;
}
.btn-dev:hover { filter: brightness(1.08); }

.danger-card {
  border-color: var(--danger);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 1.25rem;
  max-width: 480px;
}
.danger-card h2 {
  margin: 0;
  font-size: 1.05rem;
  color: var(--danger);
}

.btn-danger {
  background: var(--danger);
  border: none;
  border-radius: 6px;
  padding: 0.45rem 1rem;
  font-weight: 600;
  color: #2b0d0d;
  cursor: pointer;
}
.btn-danger:hover { filter: brightness(1.08); }

.loadmgmt-dev-active {
  color: var(--dev);
  font-weight: 600;
}

.device-card-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.8rem;
  padding-top: 0.6rem;
  border-top: 1px solid var(--border);
}

.wallbox-amp-row {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}

.amp-input {
  width: 4.5rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.3rem 0.5rem;
  color: var(--text);
  font-size: 0.85rem;
}
.amp-input:focus { outline: none; border-color: var(--accent); }


.view.hidden { display: none; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.5rem;
}

.login-card {
  max-width: 340px;
  margin: 3rem auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.login-card h1 { margin: 0 0 0.5rem; font-size: 1.3rem; text-align: center; }

.login-logo {
  width: 96px;
  height: 96px;
  margin: 0 auto;
  display: block;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--muted);
}

input,
select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.55rem 0.7rem;
  color: var(--text);
  font-size: 0.95rem;
}
input:focus,
select:focus { outline: none; border-color: var(--accent); }

button[type="submit"] {
  background: var(--accent);
  border: none;
  border-radius: 6px;
  padding: 0.6rem;
  font-weight: 600;
  color: #06210f;
  cursor: pointer;
}
button[type="submit"]:hover { filter: brightness(1.08); }

.error {
  color: var(--danger);
  font-size: 0.85rem;
  margin: 0;
}


.header-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.device-form,
.settings-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 1.25rem;
  max-width: 480px;
}
.device-form h3,
.settings-form h2 { margin: 0; font-size: 1.05rem; }

.device-mgmt-card,
.user-mgmt-card {
  max-width: 640px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.version-card {
  max-width: 480px;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}
.version-card h2 { margin: 0; font-size: 1.05rem; }

.debug-card {
  max-width: 900px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.debug-toolbar {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  flex-wrap: wrap;
}

.debug-section h3 {
  margin: 0 0 0.4rem;
  font-size: 0.95rem;
}

.debug-output {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.7rem 0.85rem;
  font-family: ui-monospace, monospace;
  font-size: 0.78rem;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 420px;
  overflow-y: auto;
  margin: 0;
}

.device-mgmt-list,
.user-mgmt-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.device-mgmt-row,
.user-mgmt-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.6rem 0.7rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.device-mgmt-info,
.user-mgmt-info {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
}

.device-mgmt-name,
.user-mgmt-name {
  font-weight: 600;
  font-size: 0.9rem;
}

.device-mgmt-meta,
.user-mgmt-meta {
  font-size: 0.78rem;
  color: var(--muted);
}

.device-mgmt-actions,
.user-mgmt-actions {
  display: flex;
  gap: 0.4rem;
  flex-shrink: 0;
}

.form-row {
  display: flex;
  gap: 1rem;
}
.form-row label { flex: 1; }

.checkbox-label {
  flex-direction: row !important;
  align-items: center;
  gap: 0.5rem !important;
}
.checkbox-label input { width: auto; }

.device-config-fields {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.config-field-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.config-field-title {
  font-size: 0.85rem;
  color: var(--muted);
}

.list-rows {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.list-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}
.list-row input {
  flex: 1;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem 0.6rem;
  color: var(--text);
  font-size: 0.85rem;
}
.list-row input:focus { outline: none; border-color: var(--accent); }

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

textarea {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.55rem 0.7rem;
  color: var(--text);
  font-family: ui-monospace, monospace;
  font-size: 0.85rem;
  resize: vertical;
}
textarea:focus { outline: none; border-color: var(--accent); }

.form-actions {
  display: flex;
  gap: 0.6rem;
}

.hint {
  font-size: 0.85rem;
  color: var(--accent);
}

.device-card-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.8rem;
  padding-top: 0.6rem;
  border-top: 1px solid var(--border);
}

.entities-card {
  max-width: 640px;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.entities-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.entities-header h2 { margin: 0; font-size: 1.05rem; }

.entities-toolbar {
  display: flex;
  gap: 0.6rem;
  align-items: center;
}

#ha-entity-search {
  flex: 1;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.55rem 0.7rem;
  color: var(--text);
  font-size: 0.9rem;
}
#ha-entity-search:focus { outline: none; border-color: var(--accent); }

.entity-list {
  max-height: 360px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.entity-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.45rem 0.6rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.entity-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.entity-id {
  font-family: ui-monospace, monospace;
  font-size: 0.8rem;
  color: var(--accent);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.entity-name {
  font-size: 0.78rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.entity-state {
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
}

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

.device-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
}

.device-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.1rem;
}

.device-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.6rem;
}

.device-card.collapsed .device-card-head { margin-bottom: 0; }

.device-head-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}

.collapse-toggle {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.75rem;
  padding: 0.1rem 0.2rem;
  line-height: 1;
}
.collapse-toggle:hover { color: var(--accent); }

.device-summary {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-top: 0.3rem;
}

.device-power {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--accent);
}

.device-state-text {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
}

.onoff-badge {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  letter-spacing: 0.02em;
}
.onoff-badge.on { background: rgba(61, 220, 132, 0.15); color: var(--accent); }
.onoff-badge.off { background: rgba(124, 139, 156, 0.15); color: var(--muted); }

.device-card.collapsed .device-card-controls {
  margin-top: 0.6rem;
  padding-top: 0;
  border-top: none;
}

.device-name { font-weight: 600; }

.device-meta {
  color: var(--muted);
  font-size: 0.8rem;
  margin-bottom: 0.6rem;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 0.4rem;
}
.status-dot.online { background: var(--accent); }
.status-dot.offline { background: var(--danger); }

.device-error {
  color: var(--danger);
  font-size: 0.82rem;
}

.detail-list {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.detail-list li {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  border-top: 1px solid var(--border);
  padding-top: 0.25rem;
}
.detail-list li:first-child { border-top: none; padding-top: 0; }
.detail-key { color: var(--muted); }

/* --- KI-Assistent --- */
.assistant-log {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 60vh;
  overflow-y: auto;
  margin: 12px 0;
}
.assistant-bubble {
  max-width: 85%;
  padding: 8px 12px;
  border-radius: 10px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.45;
}
.assistant-user {
  align-self: flex-end;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.assistant-bot {
  align-self: flex-start;
  background: var(--bg);
  border: 1px solid var(--border);
}
.assistant-bot.pending { color: var(--muted); font-style: italic; }
.assistant-bot.error { color: var(--danger); }
.assistant-form textarea {
  width: 100%;
  box-sizing: border-box;
  resize: vertical;
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
}

/* OCPP-Übersicht */
.ocpp-list { list-style: none; padding: 0; margin: 0.25rem 0; font-size: 0.9rem; }
.ocpp-list li { padding: 0.2rem 0; overflow-wrap: anywhere; }
.ocpp-list li.ok::before { content: "● "; color: #2e9e5b; }
.ocpp-list li.warn { color: #c0392b; }

/* --- Octopus --- */
.octopus-small { font-size: 1.1rem; }
.octopus-section { margin: 1.6rem 0 0.4rem; font-size: 1.1rem; }
.octopus-readings { display: flex; flex-direction: column; gap: 0.2rem; font-weight: 600; }
.octopus-readings .muted { font-weight: 400; }
.octopus-list { list-style: none; padding: 0; margin: 0.4rem 0 0; display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.9rem; }
.octopus-list li { display: flex; justify-content: space-between; gap: 1rem; border-bottom: 1px solid var(--border); padding: 0.25rem 0; }
.octopus-device-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.8rem; }
.octopus-tag { display: inline-block; font-size: 0.75rem; padding: 0.1rem 0.5rem; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); }
.octopus-tag.on { border-color: var(--accent); color: var(--accent); }
.octopus-tag.warn { border-color: var(--warning); color: var(--warning); }
.charge-mode-card { display: flex; flex-direction: column; gap: 0.8rem; }
.charge-mode-status { display: flex; flex-direction: column; gap: 0.25rem; }
.charge-mode-status strong { font-size: 1.05rem; }
.charge-mode-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0.6rem 1rem; align-items: end; }
.charge-mode-form .form-actions { margin: 0; }
.octopus-target-form { display: grid; grid-template-columns: 1fr 1fr; gap: 0.4rem 0.6rem; margin-top: 0.8rem; font-size: 0.85rem; }
.octopus-target-form label { display: flex; flex-direction: column; gap: 0.15rem; }
.octopus-target-form input { width: 100%; }
.octopus-target-form .form-actions { grid-column: 1 / -1; margin: 0; }

/* --- Energie-Ansicht (Tag/Monat/Jahr) --- */
:root {
  --c-pv: #25b366;
  --c-battery: #3f95ec;
  --c-export: #c2911a;
  --c-loadpoint: #a07af0;
  --c-grid: #6b7886;
  --c-home: #c3ccd6;
  --c-heatpump: #e5684b;
  --c-water-heater: #e06c9f;
  --c-forecast: #e6edf3;
  --grid-line: #222b37;
}

.energy-header { flex-wrap: wrap; gap: 0.8rem; align-items: center; }
.energy-controls { display: flex; flex-wrap: wrap; gap: 0.8rem; align-items: center; }
.segmented {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 3px;
}
.segmented button {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 0.3rem 0.9rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
}
.segmented button.active { background: var(--surface-2); color: var(--text); }
.energy-datenav { display: flex; align-items: center; gap: 0.5rem; font-size: 0.9rem; }
#energy-date-label { min-width: 9.5rem; text-align: center; font-weight: 600; }

.energy-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.1rem 1.2rem;
  margin-bottom: 1rem;
}
.energy-card h2 { margin: 0; font-size: 1.05rem; }
.energy-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.6rem;
}
.energy-head-stats { display: flex; gap: 1.4rem; flex-wrap: wrap; }
.small-text { font-size: 0.78rem; }

.energy-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 1.2rem 1.6rem;
  align-items: center;
}
.kpi-donut-block { display: flex; gap: 0.9rem; align-items: center; }
.kpi-donut { width: 84px; height: 84px; flex: none; }
.kpi-donut text { fill: var(--text); font-size: 15px; font-weight: 700; }
.kpi-donut .unit { fill: var(--muted); font-size: 9px; font-weight: 400; }
.kpi-label { font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.kpi-big { font-size: 1.3rem; font-weight: 700; margin: 0.1rem 0 0.3rem; }
.kpi-legend { list-style: none; margin: 0; padding: 0; font-size: 0.78rem; display: grid; gap: 0.15rem; }
.kpi-legend li { display: flex; align-items: center; gap: 0.4rem; }
.kpi-legend b { min-width: 2.8rem; text-align: right; font-weight: 600; }
.kpi-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.9rem 1.2rem; }
.kpi-value { font-size: 1.35rem; font-weight: 700; }
.kpi-value.good { color: var(--accent); }
.kpi-value-sm { font-size: 1.05rem; font-weight: 700; }
.kpi-sub { font-size: 0.72rem; color: var(--muted); }

.swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  background: var(--c);
  flex: none;
}
.swatch.line { height: 2px; width: 14px; border-radius: 1px; }
.swatch.line.dashed { background: repeating-linear-gradient(90deg, var(--c) 0 4px, transparent 4px 7px); }

.energy-sankey { width: 100%; height: auto; display: block; }
.energy-sankey .node-label { fill: var(--text); font-size: 12px; font-weight: 600; }
.energy-sankey .node-value { fill: var(--muted); font-size: 11px; }
.energy-sankey .link { mix-blend-mode: screen; transition: opacity 0.15s; }
.energy-sankey .link:hover { opacity: 0.9 !important; }

.energy-chart-wrap { width: 100%; }
.energy-chart { width: 100%; height: auto; display: block; }
.energy-chart .axis text { fill: var(--muted); font-size: 10px; }
.energy-chart .gridline { stroke: var(--grid-line); stroke-width: 1; }
.energy-chart .zero { stroke: var(--border); stroke-width: 1; }
.energy-chart .now-line { stroke: var(--muted); stroke-dasharray: 2 3; }
.energy-chart .hover-col { fill: var(--text); opacity: 0; }
.energy-chart .hover-col.on { opacity: 0.06; }
.energy-chart-sub { font-size: 0.72rem; color: var(--muted); margin-top: 0.4rem; }

.energy-legend {
  list-style: none;
  margin: 0.6rem 0 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.2rem;
  font-size: 0.78rem;
  color: var(--text);
}
.energy-legend li { display: flex; align-items: center; gap: 0.4rem; }

.energy-tooltip {
  position: fixed;
  z-index: 50;
  pointer-events: none;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.65rem;
  font-size: 0.78rem;
  line-height: 1.45;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
  min-width: 140px;
}
.energy-tooltip .tt-title { color: var(--muted); margin-bottom: 0.2rem; }
.energy-tooltip .tt-row { display: flex; align-items: center; gap: 0.4rem; }
.energy-tooltip .tt-row b { margin-left: auto; padding-left: 0.8rem; font-weight: 600; }

.energy-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  flex-wrap: wrap;
  font-size: 0.85rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.7rem 1rem;
  margin-bottom: 1rem;
}

/* =====================================================================
   App-Shell: Kopfzeile, Navigation, Seitenlayout (Desktop + Smartphone)
   ===================================================================== */
:root {
  --c-price: #d7dee6;
  --c-temp: #f0a93c;
  --radius: 12px;
  --content-max: 1440px;
  --nav-h: 64px;
  --good: #3ddc84;
  --good-bg: rgba(61, 220, 132, 0.1);
  --warn-bg: rgba(240, 169, 60, 0.12);
  --bad-bg: rgba(239, 90, 90, 0.12);
}

html { -webkit-text-size-adjust: 100%; }
body { font-size: 15px; line-height: 1.45; }
a { color: var(--accent); }
code { font-size: 0.85em; background: var(--surface-2); padding: 0.05em 0.35em; border-radius: 4px; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  height: var(--nav-h);
  padding: 0 clamp(1rem, 2.5vw, 2rem);
  background: rgba(11, 15, 20, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}
.brand b { color: var(--accent); font-weight: 700; }

.tabs { display: flex; gap: 0.25rem; flex: 1; }
.tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  color: var(--muted);
  text-decoration: none;
  padding: 0.5rem 0.8rem;
  border-radius: 8px;
  font-size: 0.92rem;
  font-weight: 500;
  white-space: nowrap;
}
.tab-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tab-btn:hover { color: var(--text); background: var(--surface); }
.tab-btn.active { color: var(--accent); background: var(--surface-2); }
.tab-btn:focus-visible, .btn-ghost:focus-visible, .btn-primary:focus-visible, .user-menu-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.topbar-right { display: flex; align-items: center; gap: 0.9rem; margin-left: auto; }
.live-indicator { display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.8rem; color: var(--muted); white-space: nowrap; }
.live-indicator::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px rgba(61, 220, 132, 0.18); }
.live-indicator.stale::before { background: var(--warning); box-shadow: 0 0 0 3px rgba(240, 169, 60, 0.18); }
.live-indicator.error::before { background: var(--danger); box-shadow: 0 0 0 3px rgba(239, 90, 90, 0.18); }

.user-menu { position: relative; }
.user-menu-btn {
  display: flex; align-items: center; gap: 0.5rem;
  background: transparent; border: 1px solid var(--border); color: var(--text);
  border-radius: 999px; padding: 0.2rem 0.75rem 0.2rem 0.2rem; cursor: pointer; font: inherit; font-size: 0.88rem;
}
.user-menu-btn:hover { border-color: var(--muted); }
.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--surface-2); color: var(--accent); font-weight: 700; text-transform: uppercase;
}
.user-menu-pop {
  position: absolute; right: 0; top: calc(100% + 8px); min-width: 220px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5); padding: 0.4rem; display: flex; flex-direction: column;
}
.user-menu-head { display: flex; flex-direction: column; padding: 0.5rem 0.7rem 0.6rem; border-bottom: 1px solid var(--border); margin-bottom: 0.3rem; }
.user-menu-item {
  display: block; text-align: left; background: transparent; border: none; color: var(--text);
  font: inherit; font-size: 0.9rem; padding: 0.55rem 0.7rem; border-radius: 6px; cursor: pointer; text-decoration: none;
}
.user-menu-item:hover { background: var(--surface-2); }

main {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 1.75rem clamp(1rem, 2.5vw, 2rem) 3rem;
}

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem 1.2rem;
  flex-wrap: wrap;
  margin-bottom: 1.1rem;
}
.page-head h1 { margin: 0; font-size: 1.5rem; letter-spacing: -0.01em; }
.page-sub { margin: 0.2rem 0 0; }
.small-text { font-size: 0.8rem; }

.card { border-radius: var(--radius); }
.card-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 0.8rem; flex-wrap: wrap;
  margin-bottom: 0.9rem;
}
.card-head h2 { margin: 0; font-size: 1.05rem; }
.link-more { font-size: 0.85rem; text-decoration: none; white-space: nowrap; }
.link-more:hover { text-decoration: underline; }

.btn-ghost, .btn-primary, .btn-danger, .btn-dev { font: inherit; font-size: 0.9rem; min-height: 36px; }
.btn-ghost.small, .btn-primary.small { min-height: 30px; font-size: 0.82rem; }
.icon-btn { min-width: 36px; padding: 0.3rem 0.6rem !important; font-size: 1.1rem !important; line-height: 1; }
.btn-ghost:disabled { opacity: 0.4; cursor: not-allowed; }

/* --- Statusmeldung (Übersicht) --- */
.status-banner {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.4rem 1rem;
  padding: 1rem 1.2rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  margin-bottom: 1.25rem;
}
.status-banner .status-icon { width: 12px; height: 12px; border-radius: 50%; background: var(--muted); }
.status-banner.good { border-color: rgba(61, 220, 132, 0.45); background: linear-gradient(90deg, var(--good-bg), var(--surface) 70%); }
.status-banner.good .status-icon { background: var(--accent); box-shadow: 0 0 0 4px rgba(61, 220, 132, 0.2); }
.status-banner.warn { border-color: rgba(240, 169, 60, 0.5); background: linear-gradient(90deg, var(--warn-bg), var(--surface) 70%); }
.status-banner.warn .status-icon { background: var(--warning); box-shadow: 0 0 0 4px rgba(240, 169, 60, 0.2); }
.status-banner.bad { border-color: rgba(239, 90, 90, 0.5); background: linear-gradient(90deg, var(--bad-bg), var(--surface) 70%); }
.status-banner.bad .status-icon { background: var(--danger); }
.status-body { display: flex; flex-direction: column; gap: 0.15rem; min-width: 0; }
.status-body strong { font-size: 1.08rem; }
.status-body span { color: var(--muted); font-size: 0.92rem; }
.status-chips { display: flex; flex-wrap: wrap; gap: 0.5rem; justify-content: flex-end; }
.chip {
  display: inline-flex; align-items: center; gap: 0.35rem; white-space: nowrap;
  font-size: 0.82rem; padding: 0.3rem 0.7rem; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text); text-decoration: none;
}
.chip b { font-weight: 700; }
.chip.good { border-color: rgba(61, 220, 132, 0.45); color: var(--accent); }
.chip.warn { border-color: rgba(240, 169, 60, 0.5); color: var(--warning); }

/* --- Übersicht: Layout --- */
.ov-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(300px, 1fr);
  gap: 1.25rem;
  margin-bottom: 1.25rem;
}
.ov-side { display: flex; flex-direction: column; gap: 1.25rem; }
.ov-now { display: flex; flex-direction: column; }
.flow-diagram { width: 100%; max-width: 560px; height: auto; margin: 0 auto 1rem; display: block; }
.flow-node circle { fill: var(--surface-2); stroke: var(--border); stroke-width: 2; }
.flow-node.pv circle { stroke: var(--c-pv); }
.flow-node.grid circle { stroke: var(--c-grid); }
.flow-node.battery circle { stroke: var(--c-battery); }
.flow-node.home circle { stroke: var(--c-home); }
.flow-node-label { fill: var(--muted); font-size: 14px; font-weight: 600; }
.flow-node-value { fill: var(--text); font-size: 17px; font-weight: 700; }
.flow-node-sub { fill: var(--muted); font-size: 13px; }
.flow-line { stroke-width: 4; stroke-linecap: round; stroke-dasharray: 8 7; animation: flow-dash 0.9s linear infinite; }
.flow-line.pv { stroke: var(--c-pv); }
.flow-line.grid { stroke: var(--c-grid); }
.flow-line.export { stroke: var(--c-export); }
.flow-line.battery { stroke: var(--c-battery); }
@keyframes flow-dash { to { stroke-dashoffset: -15; } }
@media (prefers-reduced-motion: reduce) { .flow-line { animation: none; stroke-dasharray: none; } }

.ov-tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.75rem; }
.ov-tiles .stat-tile { padding: 0.85rem 1rem; background: var(--surface-2); border-left: 3px solid var(--border); }
.stat-tile.pv { border-left-color: var(--c-pv) !important; }
.stat-tile.grid { border-left-color: var(--c-grid) !important; }
.stat-tile.home { border-left-color: var(--c-home) !important; }
.stat-tile.battery { border-left-color: var(--c-battery) !important; }
.stat-value { font-variant-numeric: tabular-nums; }
.stat-sub { color: var(--muted); }

.kv-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem 1.2rem; margin: 0; }
.kv-grid dt { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.kv-grid dd { margin: 0.15rem 0 0; font-size: 1.4rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.kv-grid dd.good { color: var(--accent); }

.ov-charge { display: flex; flex-direction: column; gap: 0.7rem; }
.ov-charge-row { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
.ov-charge-row .muted { font-size: 0.85rem; }
.ov-charge-big { font-size: 1.25rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.ov-charge-note { font-size: 0.85rem; color: var(--muted); border-top: 1px solid var(--border); padding-top: 0.6rem; }
.ov-charge-sep { border-top: 1px solid var(--border); padding-top: 0.6rem; }
.ov-charge-sub { font-size: 0.8rem; color: var(--muted); margin-top: -0.5rem; text-align: right; }
.ov-charge-state { font-weight: 600; text-align: right; }
.ov-charge-state.good { color: var(--good, var(--accent)); }
.ov-charge-state.warn { color: var(--warning); }
.ov-charge-state.bad { color: var(--danger); }
.cp-pending { font-size: 0.85rem; color: var(--warning); }

.ov-forecast { margin-bottom: 1.25rem; }
.forecast-section { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1.25rem; }
.forecast-card { min-width: 0; }
.forecast-card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 0.6rem; flex-wrap: wrap; margin-bottom: 0.4rem; }
.forecast-card-title { font-weight: 600; }
.forecast-card-values { font-size: 0.82rem; color: var(--muted); }
.forecast-card-values b { color: var(--text); }
.forecast-chart { width: 100%; display: block; }
.forecast-chart .axis text { fill: var(--muted); font-size: 12px; }
.forecast-chart .gridline { stroke: var(--grid-line); }
.forecast-card-source { font-size: 0.75rem; color: var(--muted); margin-top: 0.4rem; }
.forecast-card p.muted { margin: 0.3rem 0 0; }

.info-details { color: var(--muted); font-size: 0.88rem; }
.info-details summary { cursor: pointer; padding: 0.4rem 0; }
.info-details p { margin: 0.3rem 0 0; max-width: 80ch; }

/* --- Energie-Ansicht --- */
.energy-layout { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.25rem; }
.energy-layout .energy-card { margin-bottom: 0; }
.energy-kpis { margin-bottom: 1.25rem; }
.energy-card { border-radius: var(--radius); padding: 1.2rem 1.3rem; }
.energy-chart { width: 100%; display: block; touch-action: pan-y; }
.energy-chart .axis text { font-size: 12px; }
.energy-sankey { width: 100%; display: block; }
.energy-sankey .node-label { font-size: 14px; }
.energy-sankey .node-value { font-size: 13px; }
.energy-chart-sub { font-size: 0.8rem; }
.energy-legend { font-size: 0.85rem; }
.energy-tooltip { font-size: 0.85rem; }
.kpi-legend { font-size: 0.85rem; }
.kpi-label { font-size: 0.75rem; }
.kpi-sub { font-size: 0.78rem; }
.kpi-value-sm { font-size: 1.15rem; }
#energy-date-label { min-width: 10.5rem; }
.energy-status { border-radius: var(--radius); }

/* --- Breakpoints --- */
@media (max-width: 1180px) {
  .ov-grid { grid-template-columns: 1fr; }
  .ov-side { display: grid; grid-template-columns: 1fr 1fr; }
  .energy-layout { grid-template-columns: 1fr; }
  .tab-btn span { display: none; }
  .tab-btn { padding: 0.55rem 0.7rem; }
  .tab-btn.active span { display: inline; }
}

@media (max-width: 760px) {
  body { padding-bottom: calc(68px + env(safe-area-inset-bottom)); }
  .topbar { height: 56px; gap: 0.6rem; }
  .brand-text { font-size: 0.95rem; }
  .user-menu-name { display: none; }
  .user-menu-btn { padding: 0.15rem; }
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 45;
    justify-content: space-around; gap: 0;
    background: rgba(20, 26, 34, 0.97); backdrop-filter: blur(8px);
    border-top: 1px solid var(--border);
    padding: 0.3rem 0.2rem calc(0.3rem + env(safe-area-inset-bottom));
  }
  .tab-btn, .tab-btn.active {
    flex: 1; flex-direction: column; gap: 0.15rem; padding: 0.35rem 0.1rem; min-width: 0;
    font-size: 0.68rem; border-radius: 8px; background: transparent;
  }
  .tab-btn span, .tab-btn.active span { display: block; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  .tab-btn svg { width: 22px; height: 22px; }
  .tab-btn.active { color: var(--accent); }
  main { padding: 1rem 1rem 2rem; }
  .page-head h1 { font-size: 1.3rem; }
  .status-banner { grid-template-columns: auto 1fr; padding: 0.9rem 1rem; }
  .status-chips { grid-column: 1 / -1; justify-content: flex-start; }
  .ov-side { grid-template-columns: 1fr; }
  .ov-tiles { grid-template-columns: 1fr 1fr; }
  .stat-value { font-size: 1.3rem; }
  .card { padding: 1.1rem; }
  .energy-card { padding: 1rem; }
  .energy-kpis { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .energy-controls { width: 100%; justify-content: space-between; }
  #energy-date-label { min-width: 0; }
  .forecast-section { grid-template-columns: 1fr; }
}
@media (max-width: 420px) {
  .brand-text { display: none; }
}
.lbl-short { display: none; }
@media (max-width: 760px) {
  .tab-btn .lbl-long { display: none !important; }
  .tab-btn .lbl-short { display: block !important; }
  .flow-node-label { font-size: 18px; }
  .flow-node-value { font-size: 22px; }
  .flow-node-sub { font-size: 17px; }
  .flow-diagram { margin-bottom: 0.6rem; }
  .ov-charge-row { flex-wrap: wrap; gap: 0.2rem 1rem; }
  .ov-charge-big { font-size: 1.1rem; }
}
@media (min-width: 761px) and (max-width: 1180px) {
  .tab-btn .lbl-short { display: none !important; }
}
@media (max-width: 760px) {
  /* backdrop-filter würde die fixierte Tab-Leiste in der Kopfzeile einschließen */
  .topbar { backdrop-filter: none; background: var(--bg); }
}

/* =====================================================================
   Etappe 2: Geräte, Laden, Einstellungen, Konto, Dialoge
   ===================================================================== */
.hint { color: var(--accent); }
.status-inline { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 0.8rem 1rem; }

/* --- Dialog + Toasts --- */
.dialog {
  border: 1px solid var(--border); border-radius: 14px; background: var(--surface); color: var(--text);
  padding: 1.4rem 1.5rem; width: min(440px, calc(100vw - 2rem)); box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
}
.dialog::backdrop { background: rgba(5, 8, 12, 0.65); }
.dialog h2 { margin: 0 0 0.5rem; font-size: 1.1rem; }
.dialog p { margin: 0 0 1.2rem; font-size: 0.92rem; line-height: 1.5; }
.dialog-actions { justify-content: flex-end; }
.toasts { position: fixed; right: 1rem; bottom: 1rem; z-index: 60; display: flex; flex-direction: column; gap: 0.5rem; max-width: min(420px, calc(100vw - 2rem)); }
.toast {
  background: var(--surface-2); border: 1px solid var(--border); border-left: 4px solid var(--muted);
  border-radius: 10px; padding: 0.75rem 1rem; font-size: 0.9rem; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  transition: opacity 0.35s, transform 0.35s;
}
.toast.success { border-left-color: var(--accent); }
.toast.error { border-left-color: var(--danger); }
.toast.out { opacity: 0; transform: translateY(6px); }
@media (max-width: 760px) { .toasts { left: 1rem; right: 1rem; bottom: calc(76px + env(safe-area-inset-bottom)); max-width: none; } }

/* --- Geräte --- */
.device-toolbar { display: flex; flex-wrap: wrap; gap: 0.7rem; align-items: center; margin-bottom: 0.6rem; }
.device-toolbar input[type="search"] { flex: 1 1 240px; max-width: 360px; }
.device-toolbar .segmented button { padding: 0.4rem 0.9rem; }
.segmented .count { color: var(--muted); font-size: 0.8em; margin-left: 0.2rem; }
.segmented .count.bad { color: var(--danger); font-weight: 700; }
#device-manage-link { margin-left: auto; text-decoration: none; display: inline-flex; align-items: center; }
.device-summary-line { margin: 0 0 1.1rem; font-size: 0.88rem; }
.device-summary-line.has-offline { color: var(--warning); }
.device-groups { display: flex; flex-direction: column; gap: 1.4rem; }
.device-group-title { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 0 0 0.6rem; font-weight: 600; }
.device-grid { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.device-card { border-radius: var(--radius); display: flex; flex-direction: column; }
.device-card.offline { border-color: rgba(239, 90, 90, 0.45); }
.device-card-head { gap: 0.6rem; align-items: flex-start; }
.device-name { font-size: 1rem; }
.device-status { display: inline-flex; align-items: center; white-space: nowrap; font-size: 0.82rem; color: var(--muted); }
.device-status.offline { color: var(--danger); }
.device-summary { flex-wrap: wrap; }
.device-power { font-size: 1.45rem; font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }
.device-state-text { font-size: 1.2rem; }
.device-error { margin-top: 0.4rem; font-size: 0.85rem; }
.device-card-controls { align-items: center; }
.device-card-controls .btn-primary, .device-card-controls .btn-ghost { min-height: 34px; }
.soc-meter { display: inline-flex; align-items: center; gap: 0.5rem; }
.soc-meter b { font-size: 1.2rem; font-variant-numeric: tabular-nums; }
.soc-bar { width: 72px; height: 10px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); overflow: hidden; display: inline-block; }
.soc-bar > span { display: block; height: 100%; background: var(--c-battery); }
.soc-meter-lg { margin: 0.2rem 0 0.6rem; }
.soc-meter-lg .soc-bar { width: 160px; height: 12px; }
.amp-input { width: 4.2rem; }

/* --- Laden --- */
.oct-tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.oct-tiles .stat-tile { border-radius: var(--radius); }
.oct-timeline-card { margin-bottom: 1.25rem; }
.oct-timeline { width: 100%; display: block; }
.oct-timeline .axis text { fill: var(--muted); font-size: 12px; }
.oct-timeline .lane-label { fill: var(--text); font-size: 13px; font-weight: 600; }
.oct-timeline .bar-label { fill: #fff; font-size: 12px; font-weight: 600; }
.oct-timeline .gridline { stroke: var(--grid-line); }
.oct-device-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 1.25rem; margin-bottom: 1.25rem; }
.oct-car .device-card-head { flex-wrap: wrap; }
.oct-sub { margin: 0.9rem 0 0.2rem; font-size: 0.8rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.octopus-target-details { margin-top: 0.8rem; border-top: 1px solid var(--border); padding-top: 0.6rem; }
.octopus-target-details summary { cursor: pointer; color: var(--muted); font-size: 0.88rem; }
.octopus-target-form { grid-template-columns: 1fr 1fr; }
.octopus-target-form .form-actions { justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 0.5rem; }
.charge-mode-card { margin-bottom: 1.25rem; }
.charge-mode-form { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.octopus-section { margin: 0.4rem 0 0.8rem; }
.octopus-list li { padding: 0.4rem 0; }

/* --- Einstellungen --- */
.settings-layout { display: grid; grid-template-columns: 230px minmax(0, 1fr); gap: 1.75rem; align-items: start; }
.settings-nav { position: sticky; top: calc(var(--nav-h) + 1rem); display: flex; flex-direction: column; gap: 0.15rem; }
.settings-nav a {
  display: flex; justify-content: space-between; align-items: center;
  color: var(--muted); text-decoration: none; padding: 0.55rem 0.8rem; border-radius: 8px; font-size: 0.92rem;
}
.settings-nav a:hover { color: var(--text); background: var(--surface); }
.settings-nav a.active { color: var(--accent); background: var(--surface-2); font-weight: 600; }
.nav-badge { background: var(--danger); color: #fff; font-size: 0.72rem; border-radius: 999px; padding: 0 0.45rem; font-weight: 700; }
.settings-nav-select { display: none; }
.settings-section-head { margin-bottom: 1rem; }
.settings-section-head h2 { margin: 0 0 0.25rem; font-size: 1.25rem; }
.settings-section-head p { margin: 0; max-width: 75ch; }
.settings-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(460px, 100%), 1fr)); gap: 1.25rem; align-items: start; }
.settings-cards > .card { max-width: none; margin-bottom: 0; }
.settings-cards > .device-mgmt-card, .settings-cards > .entities-card, .settings-cards > .debug-card, .settings-cards > .user-mgmt-card { grid-column: 1 / -1; }
.settings-form h2, .device-mgmt-card h2, .entities-card h2, .user-mgmt-card h2, .debug-card h2 { font-size: 1.05rem; }
.card.flash { box-shadow: 0 0 0 2px var(--accent); transition: box-shadow 0.3s; }
.integration-overview { grid-column: 1 / -1; margin-bottom: 1.25rem; }
.integration-overview h3 { margin: 0; font-size: 1rem; }
.integration-status { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 0.5rem 1.5rem; }
.integration-row { display: grid; grid-template-columns: auto 1fr auto; grid-template-rows: auto auto; column-gap: 0.7rem; align-items: center; padding: 0.55rem 0; border-bottom: 1px solid var(--border); }
.integration-row .int-dot { grid-row: 1 / 3; width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.integration-row.ok .int-dot { background: var(--accent); }
.integration-row.warn .int-dot { background: var(--warning); }
.integration-row.bad .int-dot { background: var(--danger); }
.integration-row .int-name { font-weight: 600; font-size: 0.92rem; }
.integration-row .int-state { grid-column: 2; font-size: 0.82rem; color: var(--muted); }
.integration-row.bad .int-state { color: var(--danger); }
.integration-row .btn-ghost { grid-column: 3; grid-row: 1 / 3; text-decoration: none; }
.device-mgmt-row { flex-wrap: wrap; }
.device-mgmt-actions { flex-wrap: wrap; }

/* --- Konto --- */
.account-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(380px, 100%), 1fr)); gap: 1.25rem; align-items: start; margin-bottom: 1.25rem; }
.account-grid .settings-form { max-width: none; margin-bottom: 0; }
.account-card { display: flex; flex-direction: column; gap: 1.1rem; }
.account-id { display: flex; align-items: center; gap: 0.9rem; }
.account-id > div { display: flex; flex-direction: column; }
.account-id strong { font-size: 1.15rem; }
.avatar-lg { width: 52px; height: 52px; font-size: 1.4rem; }
.kv-list { margin: 0; display: flex; flex-direction: column; gap: 0.6rem; }
.kv-list > div { display: flex; justify-content: space-between; gap: 1rem; border-top: 1px solid var(--border); padding-top: 0.6rem; }
.kv-list dt { color: var(--muted); font-size: 0.88rem; }
.kv-list dd { margin: 0; text-align: right; font-size: 0.9rem; }
.danger-details { max-width: none; }
.danger-details summary { cursor: pointer; color: var(--danger); font-weight: 600; }
.danger-details:not([open]) { gap: 0; }

@media (max-width: 1180px) {
  .oct-tiles { grid-template-columns: 1fr 1fr 1fr; }
}
@media (max-width: 900px) {
  .settings-layout { grid-template-columns: 1fr; gap: 1rem; }
  .settings-nav { display: none; }
  .settings-nav-select { display: block; width: 100%; font-size: 1rem; padding: 0.7rem; }
}
@media (max-width: 760px) {
  .oct-tiles { grid-template-columns: 1fr; }
  .oct-device-grid { grid-template-columns: 1fr; }
  .device-toolbar input[type="search"] { max-width: none; flex-basis: 100%; }
  #device-manage-link { margin-left: 0; }
  .integration-status { grid-template-columns: 1fr; }
}
.charge-mode-form .form-actions { grid-column: 1 / -1; }
.charge-mode-form .checkbox-label { align-self: end; padding-bottom: 0.6rem; }

/* ===== Etappe 3: KI-Assistent mit mehreren Anbietern ===== */
.assistant-provider-bar { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.provider-badge {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.3rem 0.75rem; border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface); font-size: 0.9rem; white-space: nowrap;
}
.provider-pick { display: inline-flex; flex-direction: row; align-items: center; gap: 0.5rem; margin: 0; }
.provider-pick select { width: auto; min-width: 11rem; margin: 0; }
.provider-dot { display: inline-block; width: 0.6rem; height: 0.6rem; border-radius: 50%; background: var(--muted); flex: none; }
.provider-dot.provider-anthropic { background: #d97757; }
.provider-dot.provider-openai { background: #10a37f; }
.provider-dot.provider-gemini { background: #4f8df5; }
.assistant-card { display: flex; flex-direction: column; }
.assistant-log { min-height: 16rem; max-height: calc(100vh - 22rem); }
.assistant-empty { margin: auto 0; padding: 1rem 0; }
.assistant-empty p { margin: 0 0 0.75rem; }
.assistant-suggestions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1rem; }
.chip-btn {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  border-radius: 999px; padding: 0.45rem 0.9rem; font: inherit; font-size: 0.92rem; cursor: pointer;
}
.chip-btn:hover { border-color: var(--accent); }
.small-print { font-size: 0.85rem; }
.assistant-bubble { max-width: min(85%, 52rem); }
.bubble-meta { margin-top: 0.35rem; font-size: 0.75rem; color: var(--muted); white-space: normal; font-style: normal; }
.assistant-note {
  align-self: center; font-size: 0.82rem; color: var(--muted);
  border: 1px dashed var(--border); border-radius: 999px; padding: 0.2rem 0.8rem;
}
.assistant-settings { grid-column: 1 / -1; }
.provider-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1rem; margin: 0.5rem 0 1rem; }
.provider-card { border: 1px solid var(--border); border-radius: var(--radius, 10px); padding: 0.75rem 1rem 1rem; margin: 0; min-width: 0; }
.provider-card legend { display: flex; align-items: center; gap: 0.45rem; padding: 0 0.4rem; font-weight: 600; flex-wrap: wrap; }
.provider-card label { margin-top: 0.7rem; }
.provider-card input[type="text"], .provider-card input[type="password"] { width: 100%; box-sizing: border-box; }
.provider-card .checkbox-row { flex-direction: row; align-items: center; justify-content: flex-start; gap: 0.5rem; font-size: 0.85rem; margin-top: 0.5rem; }
.provider-card .checkbox-row input { width: auto; margin: 0; }
.provider-test { display: flex; align-items: flex-start; gap: 0.6rem; margin-top: 0.75rem; flex-wrap: wrap; }
.provider-test-result { font-size: 0.88rem; flex: 1 1 12rem; }
.provider-test-result.ok { color: var(--accent); }
.provider-test-result.warn { color: var(--warning); }
.provider-test-result.bad { color: var(--danger); }
@media (max-width: 760px) {
  .assistant-log { max-height: calc(100vh - 20rem); }
  .provider-pick select { min-width: 0; }
}
.key-source { opacity: 0.75; }

/* =====================================================================
   Energieversorger, Ladeplanung, Heizung (30.11.2026)
   ===================================================================== */
.supplier-tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.heating-tiles { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.heating-tiles:empty { display: none; }
.table-scroll { overflow-x: auto; }
.bill-table { width: 100%; border-collapse: collapse; font-size: 0.92rem; font-variant-numeric: tabular-nums; }
.bill-table th, .bill-table td { padding: 0.45rem 0.6rem; border-bottom: 1px solid var(--border); text-align: right; white-space: nowrap; }
.bill-table th:first-child { text-align: left; font-weight: 400; color: var(--muted); }
.bill-table thead th { color: var(--muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; }
.bill-table tr.bill-total td, .bill-table tr.bill-total th { font-weight: 700; color: var(--text); }
#charge-14a { margin-bottom: 1.25rem; }
.charge-wallbox-grid { margin-bottom: 1.25rem; }
.charge-mode-card { margin-bottom: 1.25rem; }
#heating-details { margin-top: 1.25rem; }
#heating-details:empty { display: none; }
.role-suggestions { display: flex; flex-direction: column; gap: 0.6rem; }
.role-suggestion { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: 0.6rem 0; border-bottom: 1px solid var(--border); }
.role-suggestion > div { display: flex; flex-direction: column; gap: 0.15rem; min-width: 0; }
.role-list { display: flex; flex-direction: column; gap: 1rem; }
.role-row { border-bottom: 1px solid var(--border); padding-bottom: 0.8rem; }
.role-row-head { display: flex; justify-content: space-between; align-items: baseline; gap: 0.5rem; }
.role-row-add { display: flex; gap: 0.5rem; margin-top: 0.5rem; }
.role-row-add select { flex: 1; min-width: 0; }
@media (max-width: 1180px) {
  .supplier-tiles { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 760px) {
  .supplier-tiles { grid-template-columns: 1fr; }
  .role-suggestion { flex-direction: column; align-items: stretch; }
}
.settings-content, .settings-cards > * { min-width: 0; }
@media (max-width: 760px) {
  .bill-table { font-size: 0.85rem; }
  .bill-table th, .bill-table td { padding: 0.4rem 0.3rem; }
  .bill-table thead th { white-space: normal; font-size: 0.72rem; }
  .bill-table th:first-child { white-space: normal; }
}
@media (max-width: 760px) {
  .device-mgmt-actions { flex-shrink: 1; min-width: 0; }
}

/* Konto: angemeldete Apps */
#app-sessions-card { margin-top: 16px; margin-bottom: 16px; }
#app-sessions-card h2 { margin-top: 0; }
#app-sessions-list { list-style: none; padding: 0; margin: 12px 0 0; }

/* --- Ladepunkte: Lademodus & Priorität --- */
.cp-list { display: flex; flex-direction: column; gap: 0.9rem; }
.cp-card { border: 1px solid var(--border); border-radius: 10px; padding: 0.8rem 1rem; display: flex; flex-direction: column; gap: 0.6rem; }
.cp-head { display: flex; justify-content: space-between; align-items: baseline; gap: 0.75rem; flex-wrap: wrap; }
.cp-form { grid-template-columns: repeat(auto-fit, minmax(125px, 1fr)); }
.cp-form .form-actions { grid-column: 1 / -1; justify-content: flex-end; }
#grid-limit-form .form-actions { display: flex; justify-content: space-between; align-items: center; gap: 0.75rem; }

/* --- Datenalter / veraltete Werte ------------------------------------------ */
.status-dot.stale { background: var(--warning); }
.device-status.stale { color: var(--warning); }
.device-card.stale:not(.offline) { border-color: rgba(240, 169, 60, 0.45); }
.device-card.stale .device-summary,
.device-card.offline .device-summary { opacity: 0.6; }
.stale-text { color: var(--warning); }
.flow-stale .ov-now,
.flow-stale .flow-diagram,
#dashboard-view.data-stale .device-summary { opacity: 0.55; transition: opacity 0.3s; }

/* --- Laufzeit-Diagnose ------------------------------------------------------ */
.diag-grid { display: grid; gap: 0.75rem; }
.diag-kpis { display: flex; flex-wrap: wrap; gap: 0.5rem 1.25rem; font-size: 0.9rem; }
.diag-kpis b { font-variant-numeric: tabular-nums; }
.diag-table-wrap { overflow-x: auto; }
.diag-table { width: 100%; border-collapse: collapse; font-size: 0.82rem; font-variant-numeric: tabular-nums; }
.diag-table th, .diag-table td { text-align: left; padding: 0.3rem 0.5rem; border-bottom: 1px solid var(--border); white-space: nowrap; }
.diag-table td.wrap { white-space: normal; min-width: 12rem; }
.diag-table th { color: var(--muted); font-weight: 600; }
.diag-ok { color: var(--accent); }
.diag-warn { color: var(--warning); }
.diag-bad { color: var(--danger); }
.diag-actions { display: inline-flex; align-items: center; gap: 0.6rem; }
#runtime-diag-card h3 { font-size: 0.9rem; margin: 0.6rem 0 0.2rem; }

/* Historie im Geräteformular */
.device-history-box { margin-top: 1rem; }
.device-history-box h4 { margin: 0 0 0.25rem; }

/* Heizung: Temperatur-Quellen (Einstellungen) und Sollwert-Steuerung */
.heat-source-row { display: grid; grid-template-columns: minmax(120px, 1fr) minmax(0, 2fr) 90px; gap: 0.5rem; align-items: center; margin: 0.35rem 0; }
.heat-source-row select, .heat-source-row input { min-width: 0; width: 100%; }
.heat-hyst { display: flex; gap: 0.5rem; grid-column: span 2; }
.heat-control { display: flex; align-items: flex-end; gap: 0.5rem; margin: 0.5rem 0; flex-wrap: wrap; }
.heat-control label { display: flex; flex-direction: column; gap: 0.2rem; font-size: 0.85rem; }
.heat-control input { width: 110px; }
@media (max-width: 600px) {
  .heat-source-row { grid-template-columns: 1fr; }
  .heat-hyst { grid-column: auto; }
}
/* --- Geräte nach Funktion + Stromkreise (circuits.js) --- */
.device-section-title { font-size: 1rem; margin: 0.4rem 0 -0.6rem; color: var(--text); font-weight: 600; }
.circuit-chip {
  display: inline-block; margin-left: 0.4rem; padding: 0.05rem 0.45rem; border-radius: 999px;
  border: 1px solid var(--border); color: var(--muted); font-size: 0.72rem; white-space: nowrap;
  max-width: 14rem; overflow: hidden; text-overflow: ellipsis; vertical-align: middle;
}
.circuit-view { display: flex; flex-direction: column; gap: 0.8rem; }
.circuit-events ul { margin: 0.4rem 0 0; padding-left: 1.1rem; color: var(--muted); font-size: 0.85rem; }
.ctree { display: flex; flex-direction: column; gap: 0.6rem; }
.cnode {
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--border);
  border-radius: 10px; padding: 0.65rem 0.8rem; display: flex; flex-direction: column; gap: 0.35rem; min-width: 0;
}
.cnode.state-ok { border-left-color: var(--accent); }
.cnode.state-warn { border-left-color: var(--warning); }
.cnode.state-over { border-left-color: var(--danger); }
.cnode .cnode { background: var(--surface-2); }
.cnode-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.3rem 0.6rem; }
.cnode-name { font-weight: 600; }
.cnode-kind, .cnode-state { color: var(--muted); font-size: 0.78rem; }
.cnode.state-warn .cnode-state { color: var(--warning); }
.cnode.state-over .cnode-state { color: var(--danger); font-weight: 600; }
.cnode-load { margin-left: auto; font-variant-numeric: tabular-nums; }
.cbar { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.cnode .cnode .cbar { background: var(--bg); }
.cbar span { display: block; height: 100%; background: var(--accent); }
.state-warn > .cbar span { background: var(--warning); }
.state-over > .cbar span { background: var(--danger); }
.cphases { display: flex; flex-wrap: wrap; gap: 0.3rem 0.8rem; font-size: 0.8rem; font-variant-numeric: tabular-nums; }
.cphase.warn { color: var(--warning); }
.cphase.bad { color: var(--danger); font-weight: 600; }
.cmeta { color: var(--muted); font-size: 0.78rem; }
.cdevices { list-style: none; margin: 0.2rem 0 0; padding: 0; display: flex; flex-direction: column; gap: 0.2rem; }
.cdevices li { display: flex; align-items: center; gap: 0.4rem; font-size: 0.85rem; min-width: 0; }
.cdev-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cdev-power { margin-left: auto; font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap; }
.ctag { font-size: 0.68rem; padding: 0.02rem 0.35rem; border-radius: 4px; border: 1px solid var(--border); color: var(--muted); white-space: nowrap; }
.ctag.ctrl { border-color: var(--accent); color: var(--accent); }
.ctag.warn { border-color: var(--warning); color: var(--warning); }
.cchildren { display: flex; flex-direction: column; gap: 0.5rem; padding-left: 0.6rem; margin-top: 0.2rem; }
.ceditor-row {
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 0.4rem;
  padding: 0.5rem 0 0.5rem calc(var(--depth, 0) * 1.1rem); border-top: 1px solid var(--border);
}
.ceditor-actions { display: flex; gap: 0.3rem; flex-wrap: wrap; }
.btn-ghost.danger:hover { border-color: var(--danger); color: var(--danger); }
.circuit-device-picks { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0.2rem 0.8rem; margin: 0.3rem 0 0.6rem; }
.device-circuit-fields { border: 1px solid var(--border); border-radius: 8px; padding: 0.6rem 0.8rem; margin: 0.4rem 0; }
.device-circuit-fields legend { color: var(--muted); font-size: 0.85rem; padding: 0 0.3rem; }
@media (max-width: 600px) {
  .cchildren { padding-left: 0.3rem; }
  .ceditor-row { padding-left: calc(var(--depth, 0) * 0.6rem); }
}
.settings-cards > .circuit-editor-card { grid-column: 1 / -1; }
.circuit-editor-card h2 { font-size: 1.05rem; }
.circuit-editor-card .form-row { flex-wrap: wrap; }
.circuit-editor-card .form-row label { min-width: 160px; }
.device-circuit-fields .form-row { flex-wrap: wrap; }
.device-circuit-fields .form-row label { min-width: 160px; }
.device-circuit-line { color: var(--muted); font-size: 0.75rem; margin: -0.2rem 0 0.2rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.circuit-device-picks .checkbox-label { flex-wrap: wrap; gap: 0 0.35rem; }
@media (max-width: 600px) { .cdevices li { flex-wrap: wrap; } .cdev-name { white-space: normal; } }
