:root {
  /* Premium Dark Theme Palette */
  --bg-dark: #0f172a;
  /* Slate 900 */
  --bg-card: rgba(30, 41, 59, 0.7);
  /* Slate 800 with opacity */
  --text-primary: #f8fafc;
  /* Slate 50 */
  --text-secondary: #94a3b8;
  /* Slate 400 */

  /* Sky 400 */
  --accent-secondary: #818cf8;
  /* Indigo 400 */
  --accent-price: #fb923c;
  /* Orange 400 */
  --accent-success: #4ade80;
  /* Green 400 */
  --accent-danger: #f87171;
  /* Red 400 */

  --glass-border: 1px solid rgba(255, 255, 255, 0.1);
  --glass-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

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

body {
  background-color: var(--bg-dark);
  color: var(--text-primary);
  font-family: var(--font-family);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 0.5rem;
  /* Reduced from 1rem */
}

@media (min-width: 768px) {
  body {
    padding: 1rem;
  }
}

/* Header */
header {
  margin-bottom: 2rem;
  text-align: center;
}

header h1 {
  font-weight: 700;
  font-size: 1.5rem;
  letter-spacing: -0.025em;
  background: linear-gradient(to right, var(--accent-primary), var(--accent-secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

header p {
  color: var(--text-secondary);
  font-size: 0.875rem;
  margin-top: 0.25rem;
}

/* Main Layout */
main {
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  flex: 1;
}

/* Metric Cards Container (Top Row) */
.metrics-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

@media (max-width: 600px) {
  .metrics-grid {
    grid-template-columns: 1fr;
  }
}

/* Status Card (Bottom Row) */
.status-card {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: var(--glass-border);
  border-radius: 1rem;
  box-shadow: var(--glass-shadow);
  padding: 1.5rem;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  /* 3 Columns: Grid, Battery, Price */
  gap: 1rem;
  align-items: center;
  /* Vertically align */
}

@media (max-width: 768px) {
  .status-card {
    grid-template-columns: 1fr;
    gap: 1.5rem;
    text-align: center;
  }

  .status-item {
    align-items: center;
  }
}

.status-item {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
}

/* Glassmorphism Card Style (Standard) */
.card {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: var(--glass-border);
  border-radius: 1rem;
  box-shadow: var(--glass-shadow);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

.card-title {
  font-size: 0.875rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
  font-weight: 600;
  min-height: 2.5em;
  /* Ensure vertical alignment even if text wraps */
  display: flex;
  align-items: flex-end;
  /* Align bottom of text */
}

/* Value & Subtext Styles */
.card-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--text-primary);
}

.card-unit {
  font-size: 0.875rem;
  /* Slightly smaller for status card fit */
  color: var(--text-secondary);
  font-weight: 500;
  margin-left: 0.25rem;
}

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

/* Status Item Specifics (for the bottom card values) */
.status-value {
  font-size: 1.75rem;
  /* Slightly smaller than main cards */
  font-weight: 700;
  color: var(--text-primary);
}

.status-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.25rem;
}

/* Text Colors */
.text-success {
  color: var(--accent-success) !important;
}

.text-danger {
  color: var(--accent-danger) !important;
}

.text-neutral {
  color: var(--text-primary) !important;
}

.text-orange {
  color: var(--accent-price) !important;
}

/* Subtext colors specifically */
.status-subtext {
  font-size: 0.85rem;
  font-weight: 500;
  margin-top: 0.25rem;
}

.status-subtext.charging {
  color: var(--accent-success);
}

.status-subtext.discharging {
  color: var(--accent-price);
}

/* Orange/Warning */
.status-subtext.idle {
  color: var(--text-secondary);
}

/* Graph Container */
.graph-container {
  flex: 1;
  min-height: 400px;
  position: relative;
  width: 100%;
}

/* Specific accent colors for cards */
.card.avg-today .card-value {
  color: var(--accent-price);
}

/* Wallbox Card (New) */
.wallbox-card,
.forecast-card {
  margin-top: 1rem;
  grid-template-columns: 1fr;
  /* Stack title, status, logs */
  gap: 1rem;
}

.wallbox-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 1rem;
  width: 100%;
}

.wallbox-item {
  display: flex;
  flex-direction: column;
}

.wallbox-logs {
  margin-top: 1rem;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 0.5rem;
  padding: 0.75rem;
  max-height: 150px;
  overflow-y: auto;
  font-family: monospace;
  font-size: 0.8rem;
  width: 100%;
}

.log-entry {
  margin-bottom: 0.25rem;
  color: var(--text-secondary);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  padding-bottom: 0.25rem;
}

@media (max-width: 768px) {
  .wallbox-grid {
    grid-template-columns: 1fr;
  }
}

/* Footer */
footer {
  margin-top: 2rem;
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.75rem;
}

/* Tabs Navigation */
.tabs {
  display: flex;
  gap: 10px;
  margin-bottom: 25px;
  background: rgba(30, 41, 59, 0.5);
  padding: 6px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.tab-btn {
  flex: 1;
  padding: 10px;
  border: none;
  background: transparent;
  color: #94a3b8;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.3s;
}

.tab-btn.active {
  background: #3b82f6;
  color: white;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.tab-pane {
  display: none;
  animation: fadeIn 0.4s ease-out;
}

.tab-pane.active {
  display: block;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Charging Mode Selector */
.mode-selector {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.5rem;
  width: 100%;
}

.mode-btn {
  flex: 1;
  min-width: 100px;
  /* Reduced specific min-width for mobile */
  position: relative;
  cursor: pointer;
}

/* Reduced strictness for mobile fitting */
@media (max-width: 400px) {
  .mode-btn span {
    padding: 10px;
    font-size: 0.9rem;
  }
}

/* ... existing code ... */

/* Single Line Telemetry */
.wallbox-line-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1.5rem;
  margin: 1.5rem 0;
  background: rgba(255, 255, 255, 0.02);
  padding: 1.5rem;
  /* Reduced padding */
  border-radius: 1rem;
}

@media (max-width: 600px) {
  .wallbox-line-grid {
    grid-template-columns: repeat(2, 1fr);
    /* 2x2 grid on mobile */
    gap: 1rem;
    padding: 1rem;
  }
}

.mode-btn input {
  position: absolute;
  opacity: 0;
}

.mode-btn span {
  display: block;
  padding: 15px;
  text-align: center;
  background: rgba(30, 41, 59, 1);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  color: #94a3b8;
  font-weight: 600;
  transition: 0.3s;
}

.mode-btn input:checked+span {
  border-color: #3b82f6;
  background: rgba(59, 130, 246, 0.1);
  color: #3b82f6;
  box-shadow: 0 0 15px rgba(59, 130, 246, 0.2);
}

/* Target Mode Dials */
.dial-container {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.dial-item label {
  display: block;
  margin-bottom: 8px;
  color: #94a3b8;
  font-size: 0.9rem;
}

.dial-item input {
  width: 100%;
  padding: 12px;
  background: #1e293b;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  color: white;
  font-size: 1.1rem;
}

/* KPI Styling */
.kpi-value-container {
  display: flex;
  align-items: baseline;
  gap: 0.25rem;
  justify-content: center;
}

.kpi-unit-small {
  font-size: 0.9rem;
  color: var(--text-secondary);
  font-weight: 400;
}

/* Single Line Telemetry */
.wallbox-line-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1.5rem;
  margin: 1.5rem 0;
  background: rgba(255, 255, 255, 0.02);
  padding: 2rem;
  border-radius: 1rem;
}

.wallbox-item {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-items: center;
}

.status-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

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

.unit-small {
  font-size: 1rem;
  color: var(--text-secondary);
  margin-left: 0.25rem;
}

.status-value-small {
  font-size: 1.2rem;
  font-weight: 700;
  margin-left: 0.5rem;
}

.unit-small {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-left: 0.1rem;
}

/* Controls Row Grid (2 Panels: 1/3 Left, 2/3 Right) */
.controls-row-grid-2panel {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 0.5rem;
  margin-top: 0.75rem;
  width: 100%;
}

.settings-panel {
  padding: 0.6rem 0.4rem;
  background: rgba(255, 255, 255, 0.02);
  border-radius: 0.75rem;
  border: 1px solid rgba(255, 255, 255, 0.05);
  transition: all 0.3s ease;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 84px;
}

/* Highlighted Panel (Active mode - blue border, blue glow, blue label) */
.settings-panel.active,
#max-controls.active,
#target-controls.active {
  background: rgba(59, 130, 246, 0.12) !important;
  border: 1.5px solid #3b82f6 !important;
  opacity: 1.0 !important;
  pointer-events: auto !important;
  box-shadow: 0 0 15px rgba(59, 130, 246, 0.3) !important;
  -webkit-box-shadow: 0 0 15px rgba(59, 130, 246, 0.3) !important;
}

.settings-panel.active label,
.settings-panel.active .toggle-item label,
.settings-panel.active .dial-item label,
#max-controls.active label,
#target-controls.active label {
  color: #3b82f6 !important;
  font-weight: 600 !important;
}

/* Dimmed Inactive Panel (Fully interactive, no glow) */
.settings-panel.disabled,
#max-controls.disabled,
#target-controls.disabled {
  background: rgba(255, 255, 255, 0.02) !important;
  border: 1px solid rgba(255, 255, 255, 0.05) !important;
  opacity: 0.45 !important;
  pointer-events: auto !important;
  box-shadow: none !important;
  -webkit-box-shadow: none !important;
}

.settings-panel.disabled label,
.settings-panel.disabled .toggle-item label,
.settings-panel.disabled .dial-item label,
#max-controls.disabled label,
#target-controls.disabled label {
  color: var(--text-secondary) !important;
  font-weight: 400 !important;
}

.target-dials-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  width: 100%;
}

.max-settings-row {
  display: flex;
  align-items: center;
  justify-content: center;
}

.toggle-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
}

.toggle-item label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

/* Toggle Switch Styling */
.switch {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 26px;
}

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

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(255, 255, 255, 0.1);
  transition: .3s;
  border-radius: 26px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: #94a3b8;
  transition: .3s;
  border-radius: 50%;
}

input:checked + .slider {
  background-color: rgba(59, 130, 246, 0.2);
  border-color: #3b82f6;
}

input:checked + .slider:before {
  transform: translateX(22px);
  background-color: #3b82f6;
}

.target-settings-row {
  display: flex;
  gap: 1.5rem;
}


.dial-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
}

.dial-item label,
.toggle-item label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  text-align: center;
  line-height: 1.15;
}

.dial-item input[type="time"],
.dial-item select {
  width: 100%;
  height: 38px;
  padding: 0.4rem 0.2rem;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 0.5rem;
  color: var(--text-primary);
  font-size: 1rem;
  font-weight: 600;
  text-align: center;
  text-align-last: center;
  box-sizing: border-box;
  -webkit-appearance: none;
  appearance: none;
}

.dial-item select option {
  background: #1e293b;
  color: white;
}

/* Standardize box heights */
.car-status-card,
.wallbox-card {
  min-height: 120px;
}

.car-status-card {
  margin-bottom: 1.5rem;
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.1), rgba(37, 99, 235, 0.05));
  padding: 1.5rem;
}

.car-status-grid {
  display: flex;
  justify-content: space-around;
  gap: 2rem;
  padding: 1rem 0;
}

.car-status-item {
  text-align: center;
  flex: 1;
}

.car-status-item .status-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  margin-bottom: 0.5rem;
  display: block;
}

.car-status-item .status-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--text-primary);
}

.text-blue {
  color: #3b82f6 !important;
}

.text-yellow {
  color: #facc15 !important;
}

.hidden {
  display: none !important;
}