:root {
  --bg-primary: #000000;
  --bg-secondary: #1C1C1E;
  --bg-tertiary: #2C2C2E;
  --bg-card: #1C1C1E;
  --text-primary: #FFFFFF;
  --text-secondary: #8E8E93;
  --text-tertiary: #636366;
  --accent-blue: #3478F6;
  --accent-green: #30D158;
  --accent-red: #FF453A;
  --accent-orange: #FF9F0A;
  --accent-teal: #64D2FF;
  --border-color: #38383A;
  --icon-color: #8A8B8B;
  --icon-active: #FFFFFF;
  --quickaction-bg: #1C1C1E;
  --overlay-bg: rgba(0,0,0,0.5);
  --transition: 0.25s ease;
  --radius: 14px;
  --radius-sm: 10px;
}

@font-face {
  font-family: 'TeslaUniversal';
  src: url('../fonts/UniversalSansText-Medium-540.ttf') format('truetype');
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'TeslaUniversal';
  src: url('../fonts/UniversalSans-710.otf') format('opentype');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'RobotoMedium';
  src: url('../fonts/Roboto-Medium.ttf') format('truetype');
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  font-family: 'TeslaUniversal', -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

body {
  max-width: 430px;
  margin: 0 auto;
  padding-bottom: env(safe-area-inset-bottom, 20px);
}

/* Status bar */
.status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 20px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
}

/* Header */
.header {
  padding: 4px 20px 0;
}
.header h1 {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.5px;
}
.header .subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* Car visual */
.car-section {
  position: relative;
  width: 100%;
  padding: 10px 0 5px;
  text-align: center;
}
.car-canvas {
  width: 100%;
  height: 260px;
  display: block;
  touch-action: pan-y;
  background: linear-gradient(180deg, transparent 0%, rgba(20,20,20,0.4) 100%);
}
.car-image {
  width: 280px;
  height: auto;
  margin: 0 auto;
  display: block;
  filter: brightness(1.1);
  transition: filter var(--transition);
}

/* Battery bar */
.battery-section {
  padding: 0 20px;
  margin-bottom: 12px;
}
.battery-bar-container {
  display: flex;
  align-items: center;
  gap: 8px;
}
.battery-bar {
  flex: 1;
  height: 6px;
  background: var(--bg-tertiary);
  border-radius: 3px;
  overflow: hidden;
}
.battery-fill {
  height: 100%;
  border-radius: 3px;
  background: var(--accent-green);
  transition: width 1s ease;
  position: relative;
}
.battery-fill.low { background: var(--accent-red); }
.battery-fill.medium { background: var(--accent-orange); }
.battery-text {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  min-width: 40px;
  text-align: right;
}
.battery-info {
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
  font-size: 12px;
  color: var(--text-secondary);
}
.charge-limit-marker {
  position: absolute;
  top: -3px;
  width: 2px;
  height: 12px;
  background: var(--text-secondary);
  border-radius: 1px;
}

/* Quick actions */
.quick-actions {
  display: flex;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  margin-bottom: 8px;
}
.quick-action {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 16px;
  background: var(--quickaction-bg);
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  min-width: 76px;
  transition: background var(--transition), transform 0.1s ease;
  -webkit-user-select: none;
  user-select: none;
}
.quick-action:active {
  transform: scale(0.95);
  background: var(--bg-tertiary);
}
.quick-action.active {
  background: var(--accent-blue);
}
.quick-action.active .qa-label { color: #fff; }
.quick-action.active .qa-icon svg path { fill: #fff; stroke: #fff; }
.qa-icon {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.qa-icon svg {
  width: 24px;
  height: 24px;
}
.qa-icon svg path {
  transition: fill var(--transition), stroke var(--transition);
}
.qa-label {
  font-size: 11px;
  color: var(--text-secondary);
  font-weight: 500;
  white-space: nowrap;
  transition: color var(--transition);
}
.quick-action.loading .qa-icon {
  animation: spin 1s linear infinite;
}
@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* Menu sections */
.menu-section {
  padding: 0 16px;
}
.menu-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 10px;
}
.menu-item {
  display: flex;
  align-items: center;
  padding: 14px 16px;
  cursor: pointer;
  transition: background var(--transition);
  text-decoration: none;
  color: inherit;
  border: none;
  background: transparent;
  width: 100%;
}
.menu-item:active { background: var(--bg-tertiary); }
.menu-item + .menu-item {
  border-top: 0.5px solid var(--border-color);
}
.menu-icon {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 14px;
  flex-shrink: 0;
}
.menu-icon svg {
  width: 22px;
  height: 22px;
}
.menu-icon img {
  width: 22px;
  height: 22px;
}
.menu-text {
  flex: 1;
  text-align: left;
}
.menu-title {
  font-size: 16px;
  font-weight: 400;
  color: var(--text-primary);
}
.menu-subtitle {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 1px;
}
.menu-arrow {
  color: var(--text-tertiary);
  font-size: 16px;
  margin-left: 8px;
}
.menu-badge {
  background: var(--accent-blue);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  margin-left: auto;
  margin-right: 8px;
}

/* Panel / Detail views */
.panel {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg-primary);
  z-index: 100;
  max-width: 430px;
  margin: 0 auto;
  overflow-y: auto;
  animation: slideIn 0.3s ease forwards;
}
.panel.active { display: block; }
@keyframes slideIn {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}
@keyframes slideOut {
  from { transform: translateX(0); }
  to { transform: translateX(100%); }
}
.panel-header {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  position: sticky;
  top: 0;
  background: rgba(0,0,0,0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  z-index: 10;
}
.panel-back {
  font-size: 16px;
  color: var(--accent-blue);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  padding: 8px 0;
  font-weight: 400;
}
.panel-back svg { width: 20px; height: 20px; }
.panel-title {
  font-size: 17px;
  font-weight: 600;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}
.panel-content {
  padding: 8px 16px 40px;
}

/* Control grid */
.control-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}
.control-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 20px 12px;
  background: var(--bg-card);
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  transition: background var(--transition), transform 0.1s;
}
.control-btn:active {
  transform: scale(0.96);
  background: var(--bg-tertiary);
}
.control-btn .ctrl-icon {
  width: 32px;
  height: 32px;
}
.control-btn .ctrl-icon svg {
  width: 32px;
  height: 32px;
}
.control-btn .ctrl-label {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
}
.control-btn.active {
  background: var(--accent-blue);
}
.control-btn.active .ctrl-label { color: #fff; }

/* Toggle row */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--bg-card);
  border-radius: var(--radius);
  margin-bottom: 10px;
}
.toggle-row + .toggle-row {
  margin-top: -5px;
  border-radius: 0 0 var(--radius) var(--radius);
}
.toggle-label {
  font-size: 16px;
  color: var(--text-primary);
}
.toggle-switch {
  width: 50px;
  height: 30px;
  background: var(--bg-tertiary);
  border-radius: 15px;
  position: relative;
  cursor: pointer;
  transition: background var(--transition);
  border: none;
  -webkit-appearance: none;
  appearance: none;
}
.toggle-switch.on {
  background: var(--accent-green);
}
.toggle-switch::after {
  content: '';
  position: absolute;
  width: 26px;
  height: 26px;
  background: #fff;
  border-radius: 50%;
  top: 2px;
  left: 2px;
  transition: transform var(--transition);
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
.toggle-switch.on::after {
  transform: translateX(20px);
}

/* Temperature slider */
.temp-control {
  text-align: center;
  padding: 24px 16px;
  background: var(--bg-card);
  border-radius: var(--radius);
  margin-bottom: 10px;
}
.temp-value {
  font-size: 56px;
  font-weight: 200;
  letter-spacing: -2px;
  color: var(--text-primary);
  margin-bottom: 4px;
}
.temp-unit {
  font-size: 20px;
  font-weight: 300;
  vertical-align: super;
}
.temp-label {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 16px;
}
.temp-buttons {
  display: flex;
  justify-content: center;
  gap: 40px;
}
.temp-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  border: none;
  color: var(--text-primary);
  font-size: 24px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), transform 0.1s;
}
.temp-btn:active {
  transform: scale(0.9);
  background: var(--border-color);
}

/* Slider control */
.slider-row {
  padding: 14px 16px;
  background: var(--bg-card);
  border-radius: var(--radius);
  margin-bottom: 10px;
}
.slider-row label {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  color: var(--text-primary);
  margin-bottom: 10px;
}
.slider-row label span {
  color: var(--text-secondary);
}
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  background: var(--bg-tertiary);
  border-radius: 2px;
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 24px;
  height: 24px;
  background: #fff;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

/* Charge panel */
.charge-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}
.charge-stat {
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  padding: 14px;
  text-align: center;
}
.charge-stat-value {
  font-size: 22px;
  font-weight: 600;
  color: var(--text-primary);
}
.charge-stat-label {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* Location panel */
.map-container {
  width: 100%;
  height: 220px;
  background: var(--bg-card);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 16px;
}
.map-container iframe {
  width: 100%;
  height: 100%;
  border: 0;
  filter: invert(1) hue-rotate(180deg) contrast(0.9);
}

/* Toast notifications */
.toast {
  position: fixed;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  padding: 10px 24px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 500;
  z-index: 1000;
  opacity: 0;
  transition: all 0.3s ease;
  backdrop-filter: blur(20px);
  max-width: 90%;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.success { border-left: 3px solid var(--accent-green); }
.toast.error { border-left: 3px solid var(--accent-red); }

/* Loading overlay */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
}
.loading-overlay.show { display: flex; }
.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--bg-tertiary);
  border-top-color: var(--accent-blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* Section header */
.section-header {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 16px 16px 8px;
}

/* Status pill */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 12px;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
}
.status-pill.online {
  background: rgba(48,209,88,0.15);
  color: var(--accent-green);
}
.status-pill.online::before {
  content: '';
  width: 6px;
  height: 6px;
  background: var(--accent-green);
  border-radius: 50%;
}
.status-pill.offline {
  background: rgba(142,142,147,0.15);
}
.status-pill.charging {
  background: rgba(48,209,88,0.15);
  color: var(--accent-green);
}

/* Footer spacer */
.footer-spacer {
  height: 30px;
}

/* Scrollbar */
::-webkit-scrollbar { width: 0; background: transparent; }

/* Animation for button press feedback */
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(52,120,246,0.4); }
  70% { box-shadow: 0 0 0 10px rgba(52,120,246,0); }
  100% { box-shadow: 0 0 0 0 rgba(52,120,246,0); }
}
.pulse { animation: pulse 0.6s ease; }
