/* ==========================================================================
   TRACCAR LIVE TELEMETRY - CORE STYLES & DESIGN SYSTEM
   ========================================================================== */

:root {
  /* Color Palette - Cyber Dark & Automotive Neon */
  --bg-primary: #0a0d14;
  --bg-secondary: #101522;
  --bg-card: rgba(18, 24, 38, 0.75);
  --bg-card-hover: rgba(24, 32, 50, 0.85);
  --bg-glass: rgba(15, 21, 34, 0.75);
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-glow: rgba(0, 229, 255, 0.3);
  --border-focus: #00e5ff;

  /* Accent Colors */
  --accent-cyan: #00e5ff;
  --accent-cyan-glow: rgba(0, 229, 255, 0.35);
  --accent-blue: #2979ff;
  --accent-green: #00e676;
  --accent-green-glow: rgba(0, 230, 118, 0.3);
  --accent-yellow: #ffd600;
  --accent-orange: #ff9100;
  --accent-red: #ff1744;
  --accent-purple: #d500f9;

  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-display: 'Orbitron', monospace;
  --font-mono: 'JetBrains Mono', monospace;

  /* Text Colors */
  --text-primary: #f0f4f8;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --text-inverse: #0a0d14;

  /* Elevation & Shadows */
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.6);
  --shadow-glow-cyan: 0 0 20px rgba(0, 229, 255, 0.25);
  --shadow-glow-green: 0 0 20px rgba(0, 230, 118, 0.25);

  /* Layout Constants */
  --header-height: 70px;
  --sidebar-width: 440px;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;

  /* Transitions */
  --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Reset & Base Setup */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.2);
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* App Container Layout */
.app-layout {
  display: flex;
  flex-direction: column;
  width: 100vw;
  height: 100vh;
  position: relative;
  background: radial-gradient(circle at 10% 20%, rgba(0, 229, 255, 0.03) 0%, transparent 40%),
              radial-gradient(circle at 90% 80%, rgba(41, 121, 255, 0.03) 0%, transparent 40%),
              var(--bg-primary);
}

/* ==========================================================================
   HEADER / NAVBAR
   ========================================================================== */

.app-header {
  height: var(--header-height);
  min-height: var(--header-height);
  background: var(--bg-glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 100;
  position: relative;
}

/* Logo */
.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.logo-container {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: default;
}

.spray-logo-box {
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius-md);
  padding: 4px 8px;
  backdrop-filter: blur(8px);
  transition: var(--transition-normal);
}

.spray-logo-box:hover {
  border-color: var(--accent-cyan);
  box-shadow: 0 0 15px rgba(0, 229, 255, 0.3);
}

.spray-team-img-logo {
  height: 38px;
  width: auto;
  max-width: 90px;
  object-fit: contain;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.6));
}

.logo-text h1 {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 900;
  letter-spacing: 1.5px;
  color: #ffffff;
  line-height: 1.1;
}

.logo-text h1 span {
  color: var(--accent-cyan);
  text-shadow: 0 0 12px var(--accent-cyan-glow);
}

.app-tagline {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  font-weight: 500;
}

/* Header Center: Device Selector & Mode Badge */
.header-center {
  display: flex;
  align-items: center;
  gap: 16px;
}

.device-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  padding: 6px 14px;
  transition: var(--transition-normal);
  cursor: pointer;
}

.device-pill:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.2);
}

.status-indicator {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent-green);
  box-shadow: 0 0 10px var(--accent-green);
  animation: blink-soft 2s infinite;
}

.status-indicator.offline {
  background: var(--accent-red);
  box-shadow: 0 0 10px var(--accent-red);
}

.device-info-compact {
  display: flex;
  flex-direction: column;
}

.device-label {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text-primary);
  max-width: 180px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.device-sub {
  font-size: 0.68rem;
  color: var(--text-muted);
}

.icon-btn-small {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn-small svg {
  width: 16px;
  height: 16px;
}

/* Badge Mode */
.badge-mode {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--radius-full);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.badge-mode.live {
  background: rgba(0, 230, 118, 0.12);
  border: 1px solid rgba(0, 230, 118, 0.35);
  color: var(--accent-green);
}

.badge-mode.public {
  background: rgba(0, 229, 255, 0.12);
  border: 1px solid var(--border-glow);
  color: var(--accent-cyan);
}

.badge-mode svg {
  width: 14px;
  height: 14px;
}

/* Header Right: Connection status & Actions */
.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.connection-status {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 6px 14px;
}

.live-pulse {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-red);
  box-shadow: 0 0 8px var(--accent-red);
  position: relative;
}

.live-pulse.connected {
  background: var(--accent-cyan);
  box-shadow: 0 0 8px var(--accent-cyan);
}

.live-pulse.connected::after {
  content: '';
  position: absolute;
  top: -4px;
  left: -4px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid var(--accent-cyan);
  opacity: 0.7;
  animation: radar-pulse 2s infinite ease-out;
}

.conn-text {
  display: flex;
  flex-direction: column;
}

.conn-state {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.live-pulse.connected + .conn-text .conn-state {
  color: var(--accent-cyan);
}

.conn-time {
  font-size: 0.65rem;
  color: var(--text-muted);
}

.header-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: 0.82rem;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  cursor: pointer;
  transition: var(--transition-normal);
}

.header-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.2);
  transform: translateY(-1px);
}

.header-btn[data-active="true"] {
  background: rgba(0, 229, 255, 0.15);
  border-color: var(--accent-cyan);
  color: var(--accent-cyan);
  box-shadow: 0 0 12px rgba(0, 229, 255, 0.2);
}

.header-btn.secondary-btn {
  background: rgba(0, 229, 255, 0.08);
  border: 1px solid var(--border-glow);
  color: var(--accent-cyan);
}

.header-btn.secondary-btn:hover {
  background: rgba(0, 229, 255, 0.18);
  box-shadow: 0 0 14px rgba(0, 229, 255, 0.25);
}

.header-btn.primary {
  background: linear-gradient(135deg, #00b4d8, #0077b6);
  border: 1px solid rgba(0, 229, 255, 0.4);
  color: #ffffff;
  box-shadow: 0 4px 15px rgba(0, 180, 216, 0.3);
}

.header-btn.primary:hover {
  background: linear-gradient(135deg, #00c6eb, #0088cc);
  box-shadow: 0 6px 20px rgba(0, 180, 216, 0.45);
}

.header-btn svg {
  width: 16px;
  height: 16px;
}

/* ==========================================================================
   DASHBOARD BODY (SIDEBAR + MAP)
   ========================================================================== */

.dashboard-body {
  display: flex;
  flex: 1;
  width: 100%;
  height: calc(100vh - var(--header-height));
  overflow: hidden;
  position: relative;
}

/* Sidebar: Telemetry & Stats */
.telemetry-panel {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  height: 100%;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-subtle);
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  z-index: 10;
  box-shadow: var(--shadow-lg);
}

/* Cards Base */
.card {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  transition: var(--transition-normal);
}

.card:hover {
  border-color: rgba(255, 255, 255, 0.14);
}

.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-display);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.6px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.section-title svg {
  width: 14px;
  height: 14px;
  color: var(--accent-cyan);
}

/* ==========================================================================
   MAP SECTION
   ========================================================================== */

.map-view-container, .map-section {
  flex: 1;
  height: 100%;
  position: relative;
  background: #0d1117;
  overflow: hidden;
}

#map, .map-canvas, .leaflet-map-canvas {
  width: 100%;
  height: 100%;
  min-height: 100%;
  background: #0d1117;
  z-index: 1;
}

/* Floating Elements on Map */
.map-floating-panel.top-left {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 800;
  pointer-events: auto;
}

.location-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(16, 21, 34, 0.88);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 10px 16px;
  box-shadow: var(--shadow-md);
  max-width: 420px;
}

.loc-icon-pin {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: rgba(0, 229, 255, 0.12);
  border: 1px solid var(--border-glow);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-cyan);
  flex-shrink: 0;
}

.loc-icon-pin svg {
  width: 18px;
  height: 18px;
}

.loc-title {
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.loc-subtitle {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.map-floating-controls.top-right {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 800;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: auto;
}

.control-group {
  display: flex;
  background: rgba(16, 21, 34, 0.88);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 4px;
  gap: 4px;
  box-shadow: var(--shadow-md);
}

.map-ctrl-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: none;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition-fast);
}

.map-ctrl-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
}

.map-ctrl-btn.active {
  background: rgba(0, 229, 255, 0.2);
  color: var(--accent-cyan);
  border: 1px solid var(--border-glow);
}

.map-ctrl-btn[data-active="true"] {
  background: rgba(0, 229, 255, 0.2);
  color: var(--accent-cyan);
}

.map-ctrl-btn svg {
  width: 18px;
  height: 18px;
}

.map-floating-legend.bottom-center {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 800;
  display: flex;
  align-items: center;
  gap: 14px;
  background: rgba(16, 21, 34, 0.88);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  padding: 8px 18px;
  font-size: 0.72rem;
  color: var(--text-secondary);
  box-shadow: var(--shadow-md);
  pointer-events: auto;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.legend-dot.green { background: var(--accent-green); box-shadow: 0 0 6px var(--accent-green); }
.legend-dot.yellow { background: var(--accent-yellow); box-shadow: 0 0 6px var(--accent-yellow); }
.legend-dot.red { background: var(--accent-red); box-shadow: 0 0 6px var(--accent-red); }

.legend-separator {
  width: 1px;
  height: 14px;
  background: var(--border-subtle);
}

.legend-counter span {
  font-weight: 700;
  color: var(--accent-cyan);
}

/* Not Connected Overlay Prompt */
.not-connected-banner {
  position: absolute;
  inset: 0;
  background: rgba(10, 13, 20, 0.75);
  backdrop-filter: blur(6px);
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: center;
}

.not-connected-content {
  background: #111726;
  border: 1px solid var(--border-glow);
  border-radius: var(--radius-lg);
  padding: 32px 40px;
  text-align: center;
  max-width: 440px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.not-connected-icon {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: rgba(0, 229, 255, 0.12);
  border: 1px solid var(--border-glow);
  color: var(--accent-cyan);
  display: flex;
  align-items: center;
  justify-content: center;
}

.not-connected-icon svg {
  width: 28px;
  height: 28px;
}

.not-connected-text h3 {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.not-connected-text p {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* ==========================================================================
   ANIMATIONS & KEYFRAMES
   ========================================================================== */

@keyframes pulse-glow {
  0%, 100% {
    box-shadow: 0 0 15px rgba(0, 229, 255, 0.25);
  }
  50% {
    box-shadow: 0 0 25px rgba(0, 229, 255, 0.55);
  }
}

@keyframes radar-pulse {
  0% {
    transform: scale(0.6);
    opacity: 1;
  }
  100% {
    transform: scale(2.2);
    opacity: 0;
  }
}

@keyframes blink-soft {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ==========================================================================
   RESPONSIVE DESIGN
   ========================================================================== */

@media (max-width: 1024px) {
  :root {
    --sidebar-width: 380px;
  }
}

@media (max-width: 768px) {
  .dashboard-body {
    flex-direction: column-reverse;
    overflow-y: auto;
  }

  .telemetry-panel {
    width: 100%;
    min-width: 100%;
    height: auto;
    max-height: 52vh;
    border-right: none;
    border-top: 1px solid var(--border-subtle);
    overflow-y: auto;
  }

  .map-view-container {
    height: 48vh;
    min-height: 280px;
    width: 100%;
  }

  .app-header {
    padding: 0 10px;
    height: 56px;
    min-height: 56px;
  }

  .spray-team-img-logo {
    height: 28px;
    max-width: 65px;
  }

  .logo-text h1 {
    font-size: 0.95rem;
  }

  .app-tagline {
    display: none;
  }

  .header-btn .btn-text {
    display: none;
  }

  .device-info-compact .device-sub {
    display: none;
  }

  .device-pill {
    padding: 4px 8px;
  }

  .date-selector-group .date-pill-btn span {
    font-size: 0.75rem;
  }
}

@media (max-width: 480px) {
  .header-center {
    gap: 6px;
  }

  .date-selector-group {
    padding: 2px 4px;
  }

  .date-pill-btn {
    padding: 4px 8px;
    font-size: 0.7rem;
  }

  .connection-status {
    display: none;
  }
}
