/* ========================================
   TeslaTrip — Global Styles
   ======================================== */

:root {
  --bg: #0f0f0f;
  --card-bg: #1a1a1a;
  --card-border: #2a2a2a;
  --accent: #0088ff;
  --accent-hover: #0077e6;
  --text-primary: #f0f0f0;
  --text-secondary: #888888;
  --text-dim: #555555;

  --battery-good: #00c853;
  --battery-medium: #ffd600;
  --battery-low: #ff1744;

  --live-green: #00e676;
  --charging-blue: #448aff;
  --error-red: #ff5252;
  --warning-yellow: #ffd600;
  --sleep-gray: #666666;

  --radius: 12px;
  --radius-sm: 8px;
}

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

html, body {
  height: 100%;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ========================================
   Login Page
   ======================================== */

.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 20px;
}

.login-container {
  width: 100%;
  max-width: 380px;
}

.login-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 40px 32px;
}

.login-header {
  text-align: center;
  margin-bottom: 32px;
}

.login-title {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.5px;
  margin-bottom: 6px;
}

.login-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
  font-weight: 400;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.password-input {
  width: 100%;
  padding: 14px 16px;
  font-size: 16px; /* Prevents iOS zoom */
  font-family: inherit;
  background: var(--bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.2s;
}

.password-input:focus {
  border-color: var(--accent);
}

.password-input.input-error {
  border-color: var(--error-red);
}

.login-btn {
  width: 100%;
  padding: 14px;
  font-size: 16px;
  font-weight: 600;
  font-family: inherit;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.2s, opacity 0.2s;
}

.login-btn:hover {
  background: var(--accent-hover);
}

.login-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.error-message {
  font-size: 13px;
  color: var(--error-red);
  text-align: center;
}

/* ========================================
   Animations
   ======================================== */

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  10%, 30%, 50%, 70%, 90% { transform: translateX(-4px); }
  20%, 40%, 60%, 80% { transform: translateX(4px); }
}

.shake {
  animation: shake 0.5s ease-in-out;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

@keyframes charge-glow {
  0%, 100% { filter: drop-shadow(0 0 4px var(--charging-blue)); }
  50% { filter: drop-shadow(0 0 12px var(--charging-blue)); }
}

@keyframes fade-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ========================================
   Trip Page — Layout
   ======================================== */

.trip-page {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

/* --- Status Bar --- */

.status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--card-border);
  font-size: 13px;
  z-index: 10;
  flex-shrink: 0;
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--live-green);
  animation: pulse 2s ease-in-out infinite;
}

.status-dot.charging {
  background: var(--charging-blue);
}

.status-dot.reconnecting {
  background: var(--warning-yellow);
}

.status-dot.offline {
  background: var(--error-red);
  animation: none;
}

.status-dot.sleeping {
  background: var(--sleep-gray);
  animation: none;
}

.status-time {
  color: var(--text-secondary);
}

/* --- Map Container --- */

.map-container {
  flex: 1;
  position: relative;
  min-height: 0;
}

#map {
  width: 100%;
  height: 100%;
}

.map-controls {
  position: absolute;
  right: 12px;
  bottom: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 5;
}

.map-btn {
  width: 44px;
  height: 44px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.map-btn:active {
  background: #252525;
}

.map-btn.recenter {
  display: none;
}

.map-btn.recenter.visible {
  display: flex;
}

/* --- State Overlay --- */

.state-overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(26, 26, 26, 0.92);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 24px 32px;
  text-align: center;
  z-index: 5;
  animation: fade-in 0.3s ease;
  display: none;
}

.state-overlay.visible {
  display: block;
}

.state-overlay-icon {
  font-size: 32px;
  margin-bottom: 8px;
}

.state-overlay-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 4px;
}

.state-overlay-subtitle {
  font-size: 13px;
  color: var(--text-secondary);
}

/* --- Traffic Delay Badge (map overlay) --- */

.traffic-delay-badge {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 16px;
  background: rgba(26, 26, 26, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--card-border);
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  z-index: 5;
  display: none;
  white-space: nowrap;
  animation: fade-in 0.3s ease;
}

.traffic-delay-badge.visible {
  display: block;
}

.traffic-delay-badge.severity-low {
  border-color: var(--warning-yellow);
  color: var(--warning-yellow);
}

.traffic-delay-badge.severity-high {
  border-color: var(--battery-low);
  color: var(--battery-low);
}

/* --- Stats Panel --- */

.stats-panel {
  background: var(--card-bg);
  border-top: 1px solid var(--card-border);
  flex-shrink: 0;
  z-index: 10;
  transition: max-height 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  max-height: 120px;
  overflow: hidden;
}

.stats-panel.expanded {
  max-height: 400px;
}

.stats-handle {
  width: 36px;
  height: 4px;
  background: var(--card-border);
  border-radius: 2px;
  margin: 8px auto 4px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.stats-collapsed {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 16px;
  padding: 6px 20px 12px;
}

.stat-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 15px;
  font-weight: 500;
  white-space: nowrap;
}

.stat-item .stat-icon {
  font-size: 14px;
  flex-shrink: 0;
}

.stat-item .stat-value {
  font-variant-numeric: tabular-nums;
}

.stat-item .stat-unit {
  color: var(--text-secondary);
  font-weight: 400;
  font-size: 13px;
}

.stat-item .stat-value.speed {
  font-size: 20px;
  font-weight: 700;
}

/* --- Stats Expanded --- */

.stats-expanded {
  padding: 4px 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  border-top: 1px solid var(--card-border);
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
}

.stat-row .stat-label {
  color: var(--text-secondary);
}

.stat-row .stat-data {
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.battery-bar {
  width: 100%;
  height: 6px;
  background: #2a2a2a;
  border-radius: 3px;
  overflow: hidden;
}

.battery-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.8s cubic-bezier(0.4, 0, 0.2, 1), background-color 0.5s;
  background: var(--battery-good);
}

.traffic-badge {
  display: inline-block;
  padding: 2px 8px;
  background: rgba(255, 214, 0, 0.15);
  color: var(--warning-yellow);
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
}

.charging-section {
  background: rgba(68, 138, 255, 0.08);
  border-radius: var(--radius-sm);
  padding: 12px;
  display: none;
}

.charging-section.visible {
  display: block;
}

.charging-section .stat-row {
  font-size: 13px;
}

.car-state-badge {
  text-align: center;
  padding: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.car-state-badge.driving { color: var(--live-green); }
.car-state-badge.charging { color: var(--charging-blue); }
.car-state-badge.sleeping { color: var(--sleep-gray); }
.car-state-badge.offline { color: var(--error-red); }

/* --- Car Marker --- */

.car-marker {
  width: 24px;
  height: 24px;
  transition: transform 0.3s ease;
}

.car-marker.parked {
  opacity: 0.6;
}

.car-marker.charging {
  animation: charge-glow 2s ease-in-out infinite;
}

.car-marker.sleeping {
  opacity: 0.3;
}

.car-marker.offline {
  opacity: 0.2;
}

/* Destination marker */
.dest-marker {
  width: 24px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.dest-marker-pin {
  width: 24px;
  height: 32px;
}

/* --- Number Counter Animation --- */

.animated-value {
  display: inline-block;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* --- Responsive --- */

@media (max-width: 374px) {
  .stats-collapsed {
    padding: 6px 12px 12px;
    gap: 4px 8px;
  }

  .stat-item {
    font-size: 13px;
  }

  .stat-item .stat-value.speed {
    font-size: 18px;
  }
}

@media (min-width: 768px) {
  .stats-panel {
    max-height: 140px;
  }

  .stats-panel.expanded {
    max-height: 500px;
  }

  .stats-collapsed {
    grid-template-columns: repeat(4, 1fr);
    max-width: 600px;
    margin: 0 auto;
    padding: 8px 24px 14px;
  }

  .stats-expanded {
    max-width: 600px;
    margin: 0 auto;
  }
}
