:root {
  --bg: #08101f;
  --bg-soft: #0f172a;
  --card: rgba(15, 23, 42, 0.9);
  --border: rgba(148, 163, 184, 0.18);
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #60a5fa;
  --accent-2: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
}

[data-theme="light"] {
  --bg: #f1f5f9;
  --bg-soft: #e2e8f0;
  --card: rgba(255, 255, 255, 0.92);
  --border: rgba(100, 116, 139, 0.22);
  --text: #1e293b;
  --muted: #64748b;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f1f5f9;
    --bg-soft: #e2e8f0;
    --card: rgba(255, 255, 255, 0.92);
    --border: rgba(100, 116, 139, 0.22);
    --text: #1e293b;
    --muted: #64748b;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(37, 99, 235, 0.2), transparent 0, transparent 35%),
    radial-gradient(circle at top right, rgba(34, 197, 94, 0.16), transparent 0, transparent 30%),
    var(--bg);
}

.page {
  max-width: 1180px;
  margin: 0 auto;
  padding: 16px 18px 48px;
}

/* ── Top bar ── */

.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
}

.topbar-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 10px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  min-width: 0;
}

.topbar-icon {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
}

.topbar-title {
  margin: 0;
  font-size: 1.15rem;
  white-space: nowrap;
}

.topbar-sync {
  margin: 0;
  font-size: 0.78rem;
}

.burger {
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 8px;
  flex-shrink: 0;
}

.burger span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: transform 0.2s, opacity 0.2s;
}

.burger.open span:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}

.burger.open span:nth-child(2) {
  opacity: 0;
}

.burger.open span:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

/* ── Drawer ── */

.drawer {
  position: fixed;
  top: 0;
  right: -320px;
  width: 300px;
  max-width: 85vw;
  height: 100vh;
  z-index: 200;
  background: var(--card);
  border-left: 1px solid var(--border);
  padding: 60px 20px 20px;
  overflow-y: auto;
  transition: right 0.25s ease;
  display: flex;
  flex-direction: column;
}

.drawer.open {
  right: 0;
}

.drawer-overlay {
  position: fixed;
  inset: 0;
  z-index: 150;
  background: rgba(0, 0, 0, 0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}

.drawer-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.drawer-section {
  margin-bottom: 20px;
}

.drawer-heading {
  margin: 0 0 8px;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  font-weight: 700;
}

.drawer-footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.78rem;
}

.drawer-footer-actions {
  display: flex;
  gap: 6px;
}

.update-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 0.78rem;
  color: var(--accent);
  cursor: pointer;
  transition: background 0.15s;
}

.update-btn:hover {
  background: rgba(96, 165, 250, 0.12);
}

.update-btn svg {
  flex-shrink: 0;
}

.update-btn.spinning svg {
  animation: spin 0.8s linear infinite;
}

.update-btn.has-update {
  color: var(--accent-2);
  border-color: var(--accent-2);
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.toggle-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.toggle-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 0.85rem;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  user-select: none;
}

.toggle-item .drag-handle {
  cursor: grab;
  font-size: 1rem;
  line-height: 1;
  opacity: 0.4;
  touch-action: none;
}

.toggle-item .drag-handle:active {
  cursor: grabbing;
}

.toggle-item.dragging {
  opacity: 0.35;
}

.toggle-item.dragging-touch {
  background: var(--card);
  border: 1px solid var(--border);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  border-radius: 10px;
}

.toggle-placeholder {
  border: 2px dashed var(--border);
  border-radius: 10px;
}

.toggle-item:has(input:checked) {
  background: rgba(96, 165, 250, 0.14);
  color: var(--text);
}

.toggle-item input[type="checkbox"] {
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

/* ── Login modal ── */

.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(6px);
  padding: 20px;
}

.login-overlay.hidden {
  display: none;
}

.login-modal {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 32px 28px;
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}

.login-icon {
  width: 48px;
  height: 48px;
  align-self: center;
}

.login-modal h2 {
  margin: 0;
  text-align: center;
  font-size: 1.25rem;
}

.login-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  color: var(--muted);
}

.login-field input {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-soft);
  color: var(--text);
  font-size: 1rem;
  outline: none;
  transition: border-color 0.15s;
}

.login-field input:focus {
  border-color: var(--accent);
}

.login-error {
  margin: 0;
  font-size: 0.85rem;
  color: var(--danger);
  text-align: center;
}

.login-submit {
  padding: 10px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}

.login-submit:hover {
  opacity: 0.85;
}

.login-submit:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.status-pill {
  border-radius: 999px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  font-size: 0.9rem;
  font-weight: 600;
}

.status-pill.info {
  background: rgba(96, 165, 250, 0.16);
}

.status-pill.success {
  background: rgba(34, 197, 94, 0.16);
}

.status-pill.warning {
  background: rgba(245, 158, 11, 0.16);
}

.status-pill.error {
  background: rgba(239, 68, 68, 0.16);
}

.muted {
  color: var(--muted);
}

/* ── Period selector ── */

.period-bar {
  max-width: 1180px;
  margin: 0 auto 12px;
  padding: 0 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.period-buttons {
  display: flex;
  gap: 4px;
}

.period-btn {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: background 0.15s, border-color 0.15s;
}

.period-btn:hover {
  border-color: var(--accent);
}

.period-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.period-custom {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.period-custom.hidden {
  display: none;
}

.period-custom label {
  font-size: 0.85rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 4px;
}

.period-custom input[type="date"] {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 5px 8px;
  border-radius: 6px;
  font-size: 0.85rem;
}

.period-apply {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 6px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
}

.period-apply:hover {
  opacity: 0.85;
}

.card-grid {
  display: grid;
  gap: 16px;
}

.metrics {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 16px;
}

.panels {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 16px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.2);
  overflow: hidden;
}

.metric-card {
  padding: 18px;
}

.metric-card .label {
  margin: 0 0 8px;
  font-size: 0.9rem;
  color: var(--muted);
}

.metric-card h2 {
  margin: 0 0 8px;
  font-size: clamp(1.5rem, 2vw, 2rem);
}

.panel {
  padding: 18px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
}

.panel-header h3 {
  margin: 0 0 4px;
}

/* ── Chart wrapper with Y-axis ── */

.chart-wrapper {
  display: flex;
  position: relative;
}

.y-axis {
  width: 42px;
  min-width: 42px;
  flex-shrink: 0;
  position: relative;
  align-self: flex-end;
  pointer-events: none;
}

.y-tick {
  position: absolute;
  right: 4px;
  font-size: 0.6rem;
  color: var(--muted);
  line-height: 1;
  transform: translateY(50%);
  white-space: nowrap;
  text-align: right;
}

.y-unit {
  position: absolute;
  right: 4px;
  font-size: 0.5rem;
  color: var(--muted);
  opacity: 0.7;
  white-space: nowrap;
  text-align: right;
}

.grid-overlay {
  position: absolute;
  left: 42px;
  right: 0;
  bottom: 0;
  top: 0;
  pointer-events: none;
  z-index: 1;
}

.grid-line {
  position: absolute;
  left: 0;
  right: 0;
  height: 0;
  border-top: 1px solid var(--muted);
  opacity: 0.25;
  pointer-events: none;
}

.avg-line {
  position: absolute;
  left: 0;
  right: 0;
  height: 0;
  border-top: 1.5px dashed var(--warning);
  pointer-events: none;
  z-index: 1;
}

.avg-label {
  position: absolute;
  right: 4px;
  bottom: 2px;
  font-size: 0.6rem;
  color: var(--warning);
  white-space: nowrap;
  font-weight: 600;
  background: var(--card);
  padding: 0 4px;
  border-radius: 2px;
}

.bar-chart {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(12px, 28px);
  gap: 8px;
  align-items: end;
  min-height: 196px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 0 14px;
  flex: 1;
  min-width: 0;
  position: relative;
}

.bar-item {
  display: grid;
  gap: 6px;
  min-width: 12px;
  justify-items: center;
  position: relative;
}

.bar-item span {
  font-size: 0.68rem;
  color: var(--muted);
  writing-mode: vertical-rl;
  transform: rotate(180deg);
}

.bar-item .bar-date {
  position: absolute;
  top: calc(100% + 2px);
  left: 50%;
  transform: translateX(-50%);
  writing-mode: horizontal-tb;
  font-size: 0.58rem;
  font-weight: 600;
  color: var(--accent);
  white-space: nowrap;
  line-height: 1;
}

.bar-item .bar-date-empty {
  display: none;
}

/* Midnight marker for simple bar charts */
.bar-item.bar-midnight::before,
.bar-col.bar-midnight::before {
  content: "";
  position: absolute;
  left: -5px;
  bottom: 0;
  height: 300px;
  width: 2px;
  background: var(--accent);
  opacity: 0.4;
  pointer-events: none;
  z-index: 1;
}

.bar-col .bar-date {
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.58rem;
  font-weight: 600;
  color: var(--accent);
  line-height: 1;
  white-space: nowrap;
  margin-top: 2px;
  height: 10px;
}

.bar-col .bar-date-empty {
  visibility: hidden;
}

.bar {
  width: 100%;
  min-height: 10px;
  border-radius: 10px 10px 4px 4px;
}

.bar-price {
  background: linear-gradient(180deg, #93c5fd, #2563eb);
}

.bar-consumption {
  background: linear-gradient(180deg, #6ee7b7, #059669);
}

.bar-homey {
  background: linear-gradient(180deg, #c4b5fd, #7c3aed);
}

.bar-ex-ev {
  background: linear-gradient(180deg, #a7f3d0, #10b981);
}

.bar-ev {
  background: linear-gradient(180deg, #fda4af, #e11d48);
}

.bar-cost {
  background: linear-gradient(180deg, #fcd34d, #d97706);
}

.bar-negative {
  border-radius: 4px 4px 10px 10px;
  opacity: 0.7;
}

.bar-col {
  position: relative;
  min-width: 12px;
}

.bar-col .bar-zero {
  position: absolute;
  left: -1px;
  right: -1px;
  height: 1px;
  background: var(--muted);
  opacity: 0.5;
  pointer-events: none;
}

.bar-col-label {
  position: absolute;
  bottom: 2px;
  left: 50%;
  transform: translateX(-50%) rotate(180deg);
  writing-mode: vertical-rl;
  font-size: 0.68rem;
  color: var(--muted);
  line-height: 1;
  white-space: nowrap;
}

.bar-now-highlight {
  position: relative;
}

.bar-now-highlight::before {
  content: "";
  position: absolute;
  top: -2px;
  bottom: -2px;
  left: -2px;
  right: -2px;
  border: 2px solid var(--accent);
  border-radius: 12px;
  pointer-events: none;
  opacity: 0.7;
}

.col-now {
  position: relative;
}

.col-now::before {
  content: "";
  position: absolute;
  top: -2px;
  bottom: 0;
  left: -2px;
  right: -2px;
  border: 2px solid var(--accent);
  border-radius: 8px;
  pointer-events: none;
  opacity: 0.7;
}

.stacked-col-v.col-now::before {
  top: 0;
  bottom: 0;
}

.panel-full {
  grid-column: 1 / -1;
}

.metric-inline {
  text-align: right;
  white-space: nowrap;
}

.metric-inline .value {
  font-size: 1.25rem;
  font-weight: 700;
}

.metric-inline .sub {
  font-size: 0.8rem;
  color: var(--muted);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  margin-bottom: 10px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--muted);
}

.legend-swatch {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  flex-shrink: 0;
}

.stacked-chart {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(18px, 1fr);
  gap: 4px;
  align-items: end;
  min-height: 220px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 0 32px;
  flex: 1;
  min-width: 0;
}

.stacked-col {
  display: flex;
  flex-direction: column-reverse;
  align-items: stretch;
  min-width: 18px;
  position: relative;
}

.stacked-col .col-label {
  text-align: center;
  font-size: 0.58rem;
  color: var(--muted);
  margin-top: 4px;
  white-space: nowrap;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  margin-left: auto;
  margin-right: auto;
  line-height: 1;
}

.stacked-col .col-total {
  text-align: center;
  font-size: 0.58rem;
  color: var(--text);
  margin-bottom: 2px;
  opacity: 0;
  transition: opacity 0.15s;
}

.stacked-col:hover .col-total {
  opacity: 1;
}

.stacked-col-v {
  position: relative;
  min-width: 18px;
}

.stacked-col-v .seg-stack {
  position: absolute;
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column-reverse;
  align-items: stretch;
}

.stacked-col-v .chart-zero {
  position: absolute;
  left: -1px;
  right: -1px;
  height: 1px;
  background: var(--muted);
  opacity: 0.6;
  pointer-events: none;
}

.stacked-col-v .col-total-v {
  position: absolute;
  top: 2px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 0.58rem;
  color: var(--text);
  opacity: 0;
  transition: opacity 0.15s;
}

.stacked-col-v:hover .col-total-v {
  opacity: 1;
}

.stacked-col-v .col-label-v {
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%) rotate(180deg);
  writing-mode: vertical-rl;
  font-size: 0.58rem;
  color: var(--muted);
  line-height: 1;
  white-space: nowrap;
  margin-top: 4px;
}

/* Midnight marker and date label for stacked charts */
.stacked-col.col-midnight::before,
.stacked-col-v.col-midnight::before {
  content: "";
  position: absolute;
  left: -3px;
  bottom: 0;
  height: 300px;
  width: 2px;
  background: var(--accent);
  opacity: 0.4;
  pointer-events: none;
  z-index: 1;
}

.stacked-col .col-date {
  font-size: 0.58rem;
  font-weight: 600;
  color: var(--accent);
  white-space: nowrap;
  line-height: 1;
  text-align: center;
  height: 10px;
}

.stacked-col .col-date-empty {
  visibility: hidden;
}

.stacked-col-v .col-date {
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.58rem;
  font-weight: 600;
  color: var(--accent);
  line-height: 1;
  white-space: nowrap;
  margin-top: 2px;
  height: 10px;
}

.stacked-col-v .col-date-empty {
  visibility: hidden;
}

.stacked-seg {
  width: 100%;
  min-height: 1px;
}

.stacked-seg.seg-top {
  border-radius: 6px 6px 0 0;
}

.stacked-seg.seg-bottom {
  border-radius: 0 0 4px 4px;
}

.cheapest-list {
  display: grid;
  gap: 10px;
}

.cheapest-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(148, 163, 184, 0.08);
}

.cheapest-row strong {
  display: block;
}

.empty {
  color: var(--muted);
}

.footer {
  padding-top: 8px;
  text-align: center;
  font-size: 0.92rem;
}

.theme-switch {
  display: inline-flex;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  overflow: hidden;
}

.theme-switch button {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.78rem;
  padding: 6px 12px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.theme-switch button:hover {
  color: var(--text);
}

.theme-switch button.active {
  background: var(--accent);
  color: #fff;
}

@media (max-width: 920px) {
  .metrics,
  .panels {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 640px) {
  .page {
    padding: 12px 10px 28px;
  }

  .topbar-inner {
    padding: 8px 10px;
  }

  .topbar-title {
    font-size: 1rem;
  }

  .topbar-sync {
    display: none;
  }

  .metrics {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .metrics .metric-card:last-child:nth-child(odd) {
    grid-column: 1 / -1;
  }

  .panels {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .metric-card {
    padding: 12px;
  }

  .metric-card .label {
    font-size: 0.78rem;
    margin-bottom: 4px;
  }

  .metric-card h2 {
    font-size: 1.15rem;
    margin-bottom: 4px;
    word-break: break-word;
  }

  .metric-card .muted {
    font-size: 0.72rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .panel {
    padding: 14px 10px;
  }

  .panel-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  .panel-header h3 {
    font-size: 0.95rem;
  }

  .panel-header .muted {
    font-size: 0.75rem;
  }

  .metric-inline {
    text-align: left;
  }

  .bar-chart {
    grid-auto-columns: 22px;
    gap: 3px;
    min-height: 140px;
  }

  .y-axis {
    width: 36px;
    min-width: 36px;
  }

  .y-tick {
    font-size: 0.5rem;
  }

  .y-unit {
    font-size: 0.42rem;
  }

  .bar-item span {
    font-size: 0.56rem;
  }

  .stacked-chart {
    grid-auto-columns: 22px;
    gap: 2px;
    min-height: 160px;
  }

  .stacked-col .col-label {
    font-size: 0.5rem;
  }

  .legend {
    gap: 6px 12px;
  }

  .legend-item {
    font-size: 0.7rem;
  }

  .cheapest-row {
    padding: 10px 12px;
    font-size: 0.88rem;
  }

  .status-pill {
    font-size: 0.78rem;
    padding: 6px 10px;
  }

  .footer {
    font-size: 0.8rem;
  }
}

/* ══ Main tabs ══ */

[hidden] {
  display: none !important;
}

.main-tabs {
  display: flex;
  gap: 4px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 3px;
}

.main-tab {
  border: none;
  background: none;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  padding: 8px 14px;
  min-height: 40px;
  border-radius: 9px;
  cursor: pointer;
  white-space: nowrap;
}

.main-tab.active {
  background: var(--accent);
  color: #fff;
}

body:not([data-tab="energy"]) .topbar-energy {
  display: none;
}

/* ══ Charging view ══ */

.ch-page {
  display: flex;
  flex-direction: column;
  gap: 16px;
  --charge: #22c55e;
  --release: #60a5fa;
  --pause: rgba(148, 163, 184, 0.45);
}

.ch-automation {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px dashed rgba(245, 158, 11, 0.6);
  background: rgba(245, 158, 11, 0.1);
  font-size: 0.92rem;
  line-height: 1.4;
}

.ch-automation[data-state="on"] {
  border-style: solid;
  border-color: rgba(34, 197, 94, 0.6);
  background: rgba(34, 197, 94, 0.1);
}

.ch-automation[data-state="error"] {
  border-style: solid;
  border-color: rgba(239, 68, 68, 0.6);
  background: rgba(239, 68, 68, 0.1);
}

.ch-alerts {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ch-alerts:empty {
  display: none;
}

.ch-alert {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--card);
  font-size: 0.92rem;
}

.ch-alert[data-tone="warn"] { border-color: rgba(245, 158, 11, 0.55); background: rgba(245, 158, 11, 0.1); }
.ch-alert[data-tone="error"] { border-color: rgba(239, 68, 68, 0.55); background: rgba(239, 68, 68, 0.1); }
.ch-alert[data-tone="ok"] { border-color: rgba(34, 197, 94, 0.55); background: rgba(34, 197, 94, 0.1); }

/* Buttons */

.ch-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 48px;
  padding: 10px 18px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
}

.ch-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.ch-btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.ch-btn.danger { color: var(--danger); border-color: rgba(239, 68, 68, 0.5); }
.ch-btn.ghost { background: none; }
.ch-btn.small { min-height: 38px; padding: 6px 12px; font-size: 0.85rem; border-radius: 10px; }

.ch-icon-btn {
  margin-left: auto;
  width: 48px;
  height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
  cursor: pointer;
}

.ch-icon-btn.spinning svg { animation: spin 0.8s linear infinite; }

/* Hero */

.ch-hero {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
  gap: 20px;
  padding: 22px;
}

.ch-hero-main {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

.ch-vehicle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.ch-vehicle-row h2 {
  margin: 0;
  font-size: clamp(1.4rem, 2.6vw, 2rem);
}

.ch-chip {
  font-size: 0.78rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(34, 197, 94, 0.14);
}

.ch-chip[data-tone="warn"] { background: rgba(245, 158, 11, 0.16); }

.ch-picker p { margin: 0 0 8px; }
.ch-picker-buttons { display: flex; flex-wrap: wrap; gap: 8px; }

.ch-battery-bar {
  position: relative;
  height: 44px;
  border-radius: 14px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  overflow: hidden;
}

.ch-battery-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #16a34a, #22c55e);
  transition: width 0.5s ease;
}

.ch-battery-fill[data-tone="low"] { background: linear-gradient(90deg, #dc2626, #f97316); }

.ch-battery-target {
  position: absolute;
  top: -2px;
  bottom: -2px;
  width: 3px;
  margin-left: -1.5px;
  background: var(--text);
  border-radius: 2px;
}

.ch-battery-labels {
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.ch-soc {
  font-size: clamp(2rem, 4vw, 2.8rem);
  font-weight: 800;
  line-height: 1;
}

.ch-state {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
}

.ch-state-badge {
  font-weight: 700;
  font-size: 0.95rem;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
}

.ch-state-badge[data-tone="charge"] { background: rgba(34, 197, 94, 0.2); border-color: rgba(34, 197, 94, 0.6); }
.ch-state-badge[data-tone="wait"] { background: rgba(96, 165, 250, 0.16); border-color: rgba(96, 165, 250, 0.5); }
.ch-state-badge[data-tone="release"],
.ch-state-badge[data-tone="done"] { background: rgba(96, 165, 250, 0.2); }
.ch-state-badge[data-tone="warn"] { background: rgba(245, 158, 11, 0.2); border-color: rgba(245, 158, 11, 0.6); }
.ch-state-badge[data-tone="danger"] { background: rgba(239, 68, 68, 0.2); border-color: rgba(239, 68, 68, 0.6); }

.ch-reason {
  margin: 0;
  font-size: 1.05rem;
  line-height: 1.45;
}

.ch-modes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 5px;
  border-radius: 16px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
}

.ch-modes button {
  min-height: 56px;
  border: none;
  border-radius: 12px;
  background: none;
  color: var(--text);
  font: inherit;
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}

.ch-modes button.active { background: var(--accent); color: #fff; }
.ch-modes button[data-mode="charge_now"].active { background: var(--accent-2); }
.ch-modes button[data-mode="pause"].active { background: var(--warning); color: #111; }
.ch-modes button:disabled { opacity: 0.45; cursor: not-allowed; }

.ch-facts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  align-content: start;
}

.ch-fact {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px;
  border-radius: 14px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  min-width: 0;
}

.ch-fact.wide { grid-column: 1 / -1; }
.ch-fact.wide .ch-btn { align-self: flex-start; margin-top: 6px; }
.ch-fact[data-tone="warn"] { border-color: rgba(245, 158, 11, 0.6); }
.ch-fact[data-tone="ok"] .ch-fact-value { color: var(--accent-2); }
.ch-fact-label { font-size: 0.8rem; color: var(--muted); }
.ch-fact-value { font-size: 1.2rem; font-weight: 700; overflow-wrap: anywhere; }
.ch-fact-sub { font-size: 0.8rem; color: var(--muted); }
.ch-fact-sub:empty { display: none; }

/* Plan */

.ch-plan,
.ch-settings {
  padding: 20px;
}

.ch-section-head h3 { margin: 0 0 4px; }
.ch-section-head p { margin: 0 0 14px; }

.ch-timeline {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 4px;
}

.ch-timeline-inner {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  min-width: min-content;
  height: 170px;
  position: relative;
}

.ch-slot {
  flex: 0 0 22px;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.ch-slot.midnight { border-left: 1px dashed var(--border); padding-left: 2px; }

.ch-bar-wrap {
  flex: 1;
  display: flex;
  align-items: flex-end;
}

.ch-bar {
  width: 100%;
  border-radius: 5px 5px 2px 2px;
  background: var(--pause);
}

.ch-bar.charge { background: var(--charge); }
.ch-bar.release { background: var(--release); opacity: 0.6; }
.ch-bar.estimate {
  background-image: repeating-linear-gradient(135deg, transparent 0 4px, rgba(255, 255, 255, 0.25) 4px 7px);
  outline: 1px dashed var(--muted);
  outline-offset: -1px;
}

.ch-slot.now .ch-bar { box-shadow: 0 0 0 2px var(--text); }

.ch-slot-label {
  height: 18px;
  font-size: 0.7rem;
  color: var(--muted);
  text-align: center;
  white-space: nowrap;
}

.ch-departure-mark {
  align-self: stretch;
  border-left: 3px solid var(--warning);
  padding-left: 4px;
  font-size: 0.8rem;
  font-weight: 700;
  white-space: nowrap;
}

.ch-timeline-more { margin: 6px 0 0; font-size: 0.85rem; }

.ch-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin: 12px 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.ch-legend span { display: inline-flex; align-items: center; gap: 6px; }

.ch-swatch {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  display: inline-block;
  background: var(--pause);
}

.ch-swatch.charge { background: var(--charge); }
.ch-swatch.release { background: var(--release); opacity: 0.6; }
.ch-swatch.estimate {
  background-image: repeating-linear-gradient(135deg, transparent 0 3px, rgba(255, 255, 255, 0.35) 3px 5px);
  outline: 1px dashed var(--muted);
}

.ch-intervals,
.ch-list,
.ch-log {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ch-intervals li {
  display: grid;
  grid-template-columns: minmax(120px, auto) 80px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--bg-soft);
  border-left: 4px solid var(--pause);
  font-size: 0.92rem;
}

.ch-intervals li[data-int-action="CHARGE"] { border-left-color: var(--charge); }
.ch-intervals li[data-int-action="RELEASE"] { border-left-color: var(--release); }
.ch-int-time { font-variant-numeric: tabular-nums; font-weight: 600; }
.ch-int-action { font-weight: 700; }
.ch-int-reason,
.ch-int-hours { color: var(--muted); }

/* Settings */

.ch-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 4px;
  margin-bottom: 12px;
}

.ch-tabs button,
.ch-chip-btn {
  flex: 0 0 auto;
  min-height: 44px;
  padding: 8px 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.ch-tabs button.active,
.ch-chip-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.ch-vehicle-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.ch-vehicle-chips:empty { display: none; }
.ch-chip-btn { min-height: 40px; border-radius: 999px; }

.ch-panel > p.muted:first-child { margin-top: 0; }
.ch-error { color: var(--danger); }
.small { font-size: 0.8rem; }

.ch-week { display: flex; flex-direction: column; gap: 8px; }

.ch-day {
  display: grid;
  grid-template-columns: auto minmax(90px, 1fr) auto auto;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
}

.ch-day.off .ch-day-name,
.ch-day.off input[type="time"],
.ch-day.off .ch-stepper { opacity: 0.4; }
.ch-day-name { font-weight: 600; }

.ch-page input[type="time"],
.ch-page input[type="date"],
.ch-page input[type="text"],
.ch-page input[type="number"],
.ch-dialog input[type="time"],
.ch-dialog input[type="date"] {
  min-height: 48px;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font: inherit;
  font-size: 1.05rem;
  color-scheme: light dark;
}

.ch-stepper {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: var(--card);
}

.ch-stepper button {
  width: 48px;
  height: 48px;
  border: none;
  background: none;
  color: var(--text);
  font-size: 1.5rem;
  cursor: pointer;
  touch-action: manipulation;
}

.ch-stepper output {
  min-width: 72px;
  text-align: center;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.ch-switch { position: relative; display: inline-block; width: 56px; height: 32px; flex-shrink: 0; }
.ch-switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.ch-switch span {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: var(--pause);
  cursor: pointer;
  transition: background 0.2s;
}
.ch-switch span::after {
  content: "";
  position: absolute;
  top: 4px;
  left: 4px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s;
}
.ch-switch input:checked + span { background: var(--accent-2); }
.ch-switch input:checked + span::after { transform: translateX(24px); }
.ch-switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.ch-form {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  padding: 14px;
  border-radius: 14px;
  background: var(--bg-soft);
  margin-bottom: 14px;
}

.ch-form label,
.ch-settings-form label,
.ch-dialog-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  color: var(--muted);
}

.ch-form label.ch-check {
  flex-direction: row;
  align-items: center;
  min-height: 48px;
  gap: 8px;
  color: var(--text);
  font-size: 0.95rem;
}

.ch-check input { width: 22px; height: 22px; accent-color: var(--accent); }

.ch-form-label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 4px; }

.ch-list li {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--bg-soft);
}

.ch-tesla-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  padding: 14px;
  border-radius: 14px;
  background: var(--bg-soft);
  margin-bottom: 14px;
}

.ch-tesla-card p { margin: 4px 0 0; }
.ch-row-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.ch-vehicle-form {
  padding: 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  margin-bottom: 12px;
}

.ch-vehicle-head { display: flex; align-items: center; gap: 12px; }
.ch-name-input { flex: 1; font-weight: 700; }

.ch-grid-fields {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
  margin: 12px 0;
}

.ch-settings-form { display: flex; flex-direction: column; gap: 14px; }

.ch-settings-form fieldset {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
  margin: 0;
}

.ch-settings-form legend { font-weight: 700; padding: 0 6px; }
.ch-settings-form fieldset > p,
.ch-settings-form fieldset > .ch-row-actions { grid-column: 1 / -1; margin: 0; }
.ch-settings-form > .ch-btn { align-self: flex-start; }

.ch-log li {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--bg-soft);
  border-left: 4px solid var(--border);
  font-size: 0.9rem;
}

.ch-log li[data-kind="ACTION"] { border-left-color: var(--accent-2); }
.ch-log li[data-kind="PLAN"] { border-left-color: var(--accent); }
.ch-log li[data-kind="ERROR"] { border-left-color: var(--danger); }
.ch-log time { color: var(--muted); font-variant-numeric: tabular-nums; }

/* Dialog + toast */

.ch-dialog {
  width: min(520px, calc(100vw - 24px));
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.ch-dialog::backdrop { background: rgba(0, 0, 0, 0.55); backdrop-filter: blur(4px); }

.ch-dialog-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 22px;
}

.ch-dialog-form h3,
.ch-dialog-form p { margin: 0; }
.ch-dialog-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.ch-toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 600;
  padding: 12px 20px;
  border-radius: 12px;
  background: #0f172a;
  color: #fff;
  font-weight: 600;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  max-width: calc(100vw - 32px);
  pointer-events: none;
}

.ch-toast[data-tone="error"] { background: #b91c1c; }

@media (max-width: 920px) {
  .ch-hero { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .main-tab { padding: 8px 10px; font-size: 0.88rem; }
  .ch-hero, .ch-plan, .ch-settings { padding: 14px; }
  .ch-page { gap: 12px; }
  .ch-facts { grid-template-columns: 1fr 1fr; gap: 8px; }
  .ch-fact { padding: 10px; }
  .ch-fact-value { font-size: 1.02rem; }
  .ch-modes button { min-height: 52px; font-size: 1rem; }
  .ch-intervals li { grid-template-columns: 1fr auto; gap: 4px 10px; }
  .ch-int-reason { grid-column: 1 / -1; font-size: 0.82rem; }
  .ch-int-hours { grid-row: 1; grid-column: 2; }
  .ch-day { grid-template-columns: auto 1fr; gap: 8px 12px; }
  .ch-day input[type="time"] { grid-column: 1 / 2; }
  .ch-day .ch-stepper { justify-self: end; }
  .ch-list li { grid-template-columns: 1fr auto; }
  .ch-list li > span:nth-child(2) { grid-column: 1; grid-row: 2; }
  .ch-list li > button { grid-row: 1 / span 2; grid-column: 2; }
  .ch-log li { grid-template-columns: 1fr; gap: 2px; }
  .ch-dialog-actions { grid-template-columns: 1fr; }
}

/* ══ Easee tab + automation note ══ */

.ch-automation-note {
  margin: 0;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px dashed rgba(245, 158, 11, 0.6);
  background: rgba(245, 158, 11, 0.1);
  font-size: 0.9rem;
}

.ch-automation-note[data-state="on"] { border-style: solid; border-color: rgba(34, 197, 94, 0.6); background: rgba(34, 197, 94, 0.1); }
.ch-automation-note[data-state="error"] { border-style: solid; border-color: rgba(239, 68, 68, 0.6); background: rgba(239, 68, 68, 0.1); }
.ch-automation-note a,
.ch-automation a { color: var(--accent); font-weight: 600; }

.ez-status,
.ez-controls,
.ez-log { padding: 20px; }

.ez-controls h3,
.ez-log h3 { margin: 0 0 12px; }

.ez-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.ez-control-list { display: flex; flex-direction: column; gap: 10px; }

.ez-control {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px;
  border-radius: 14px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
}

.ez-control p { margin: 4px 0 0; }
.ez-control .ch-btn { flex-shrink: 0; }

@media (max-width: 920px) {
  .ez-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
  .ez-status, .ez-controls, .ez-log { padding: 14px; }
  .ez-grid { gap: 8px; }
  .main-tabs { width: 100%; }
  .main-tab { flex: 1; padding: 8px 6px; }
}
/* ══ Drawer accordion ══ */

.drawer-accordion {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.drawer-acc-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-soft);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

.drawer-acc-toggle .drawer-heading { margin: 0; }

.drawer-acc-chevron {
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(45deg);
  transition: transform 0.2s;
  margin-right: 4px;
}

.drawer-acc-toggle[aria-expanded="true"] .drawer-acc-chevron { transform: rotate(-135deg); }
.drawer-acc-panel { padding: 6px 0 10px; }

/* ══ Unknown car ══ */

.ch-battery-scale {
  display: none;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 4px;
}

.ch-battery[data-kind="unknown"] .ch-battery-scale { display: flex; }
.ch-battery[data-kind="unknown"] .ch-battery-fill { background: linear-gradient(90deg, #2563eb, #60a5fa); }
#ch-soc-meta .ch-btn { margin-left: 8px; }
.ch-reason:empty { display: none; }
.no-target .ch-target-field,
.ch-week.no-target .ch-stepper { display: none; }
.ch-reason-note { display: block; margin-bottom: 10px; }
.ch-reason-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.main-tab-icon { font-size: 1.1rem; padding: 8px 12px; }
@media (max-width: 640px) {
  .main-tab-icon { flex: 0 0 auto; }
}
/* ══ Settings accordion ══ */

.ch-accordion {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ch-acc-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 56px;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--bg-soft);
  color: var(--text);
  font: inherit;
  font-size: 1.05rem;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
}

.ch-acc-toggle[aria-expanded="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.ch-acc-toggle[aria-expanded="true"] .drawer-acc-chevron {
  transform: rotate(-135deg);
  border-color: #fff;
}

.ch-acc-body { padding: 6px 2px 12px; }
/* Easee section inside the settings accordion */
.ez-body { display: flex; flex-direction: column; gap: 12px; }
.ez-body[hidden] { display: none; }
.ez-status, .ez-controls, .ez-log { padding: 0; }
.ez-block { padding-top: 12px; border-top: 1px solid var(--border); }
.ez-block h3 { margin: 0 0 10px; }
.ez-status .ch-vehicle-row h3 { margin: 0; }