/**
 * SPS Nearest Vehicle Demo Dashboard - Custom Styles
 * 
 * Custom CSS overrides and enhancements for the Tailwind CSS and Flowbite Pro
 * components used in the vehicle tracking dashboard.
 */

/* =============================================================================
   Global Styles and CSS Variables
   ============================================================================= */

/* Custom CSS variables for SPS branding */
:root {
  --sps-primary: #ff6b35; /* Deep Orange - Power systems, energy */
  --sps-primary-hover: #e55a2b; /* Darker orange for hover states */
  --sps-secondary: #1e3a8a; /* Navy Blue - Professional, trustworthy */
  --sps-secondary-hover: #1e40af; /* Lighter navy for hover */
  --sps-accent: #f59e0b; /* Amber - Status indicators */
  --sps-success: #10b981; /* Emerald Green - Success states */
  --sps-warning: #f59e0b; /* Amber - Warning states */
  --sps-error: #ef4444; /* Red - Error states */
  --sps-info: #1e3a8a; /* Navy - Info states */
  --sps-dark-bg: #1f2937; /* Dark background */
  --sps-dark-surface: #374151; /* Dark surface */
  --sps-light-bg: #f9fafb; /* Light background */
  --sps-light-surface: #ffffff; /* Light surface */
}

/* =============================================================================
   Global Styles and Overrides
   ============================================================================= */

/* Ensure full height layout and prevent horizontal scrollbar */
html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow-x: hidden;
}

/* Custom scrollbar styling for webkit browsers */
::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: #f1f5f9;
}

::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

/* Dark mode scrollbar */
.dark ::-webkit-scrollbar-track {
  background: #374151;
}

.dark ::-webkit-scrollbar-thumb {
  background: #6b7280;
}

.dark ::-webkit-scrollbar-thumb:hover {
  background: #9ca3af;
}

/* =============================================================================
   Map Container Styles
   ============================================================================= */

#map {
  position: relative;
  z-index: 1;
  overflow-x: hidden;
}

/* Map layout with sidebar offset */
.map-with-sidebar {
  margin-left: 320px;
}

/* Map layout when left sidebar is hidden - full width */
.map-no-sidebar {
  margin-left: 0;
}

/* Map layout when right sidebar is closed - full width */
.map-full-width {
  margin-left: 320px;
}

/* Map layout when right sidebar is open - still full width since sidebar overlays */
.map-with-right-sidebar {
  margin-left: 320px;
}

/* Map layout when both left sidebar is hidden and right sidebar is closed */
.map-no-sidebar.map-full-width {
  margin-left: 0;
}

/* Map layout when left sidebar is hidden but right sidebar is open */
.map-no-sidebar.map-with-right-sidebar {
  margin-left: 0;
}

/* Map controls positioning - no longer needed with header integration */

/* Responsive map layout for mobile */
@media (max-width: 640px) {
  .map-with-sidebar,
  .map-no-sidebar,
  .map-full-width,
  .map-with-right-sidebar {
    margin-left: 0;
  }
}

/* Mapbox control customizations */
.mapboxgl-ctrl-group {
  border-radius: 8px !important;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1),
    0 2px 4px -1px rgba(0, 0, 0, 0.06) !important;
}

/* Position navigation controls in bottom-right, responsive to right drawer */
.mapboxgl-ctrl-bottom-right {
  bottom: 20px !important;
  right: 20px !important;
  z-index: 200 !important; /* Very high z-index to ensure visibility above all drawers */
  transition: right 0.3s ease !important;
  position: fixed !important; /* Ensure it's positioned relative to viewport */
}

/* Move controls left when right drawer is open */
.map-with-right-sidebar .mapboxgl-ctrl-bottom-right {
  right: 420px !important; /* 384px drawer width + 36px padding */
}

/* Ensure all Mapbox controls have high z-index */
.mapboxgl-ctrl-top-right,
.mapboxgl-ctrl-top-left,
.mapboxgl-ctrl-bottom-left {
  z-index: 200 !important; /* Match bottom-right controls */
}

/* Position navigation controls to avoid conflict with right drawer toggle */
.mapboxgl-ctrl-top-right {
  top: 70px !important; /* Position below the right drawer toggle button */
  right: 10px !important;
  z-index: 15 !important; /* Higher than drawer toggle (z-10) but lower than overlays */
}

.mapboxgl-ctrl-group button {
  border-radius: 0 !important;
}

.mapboxgl-ctrl-group button:first-child {
  border-top-left-radius: 8px !important;
  border-top-right-radius: 8px !important;
}

.mapboxgl-ctrl-group button:last-child {
  border-bottom-left-radius: 8px !important;
  border-bottom-right-radius: 8px !important;
}

/* Mapbox popup customizations */
.mapboxgl-popup {
  z-index: 1000 !important; /* High z-index to appear above connection status bar */
}

.mapboxgl-popup-content {
  border-radius: 8px !important;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1),
    0 4px 6px -2px rgba(0, 0, 0, 0.05) !important;
  border: 1px solid #e5e7eb !important;
  padding: 0 !important; /* Remove default padding for custom content */
}

.dark .mapboxgl-popup-content {
  background-color: #374151 !important;
  border-color: #4b5563 !important;
  color: #f9fafb !important;
}

/* Vehicle popup specific styling */
.vehicle-popup .mapboxgl-popup-content {
  background-color: transparent !important;
  border: none !important;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.3),
    0 10px 10px -5px rgba(0, 0, 0, 0.2) !important;
}

.vehicle-popup-content {
  background: linear-gradient(135deg, #1f2937, #374151) !important;
  border: 1px solid #4b5563 !important;
  border-radius: 12px !important;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1),
    0 2px 4px -1px rgba(0, 0, 0, 0.06) !important;
  min-width: 300px;
  max-width: 350px;
}

/* Responsive popup sizing */
@media (max-width: 768px) {
  .vehicle-popup-content {
    min-width: 280px;
    max-width: 320px;
  }
}

@media (max-width: 480px) {
  .vehicle-popup-content {
    min-width: 260px;
    max-width: 280px;
  }
}

.mapboxgl-popup-close-button {
  color: #9ca3af !important;
  font-size: 20px !important;
  font-weight: bold !important;
  padding: 6px 10px !important;
  border-radius: 50% !important;
  background-color: rgba(0, 0, 0, 0.5) !important;
  border: 2px solid rgba(255, 255, 255, 0.3) !important;
  transition: all 0.2s ease-in-out !important;
  margin: 4px !important;
  width: 32px !important;
  height: 32px !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  line-height: 1 !important;
}

.mapboxgl-popup-close-button:hover {
  color: #ffffff !important;
  background-color: rgba(239, 68, 68, 0.8) !important;
  border-color: rgba(255, 255, 255, 0.6) !important;
  transform: scale(1.1) !important;
}

.dark .mapboxgl-popup-close-button {
  background-color: rgba(31, 41, 55, 0.8) !important;
  border-color: rgba(255, 255, 255, 0.2) !important;
}

.dark .mapboxgl-popup-close-button:hover {
  color: #ffffff !important;
  background-color: rgba(239, 68, 68, 0.9) !important;
  border-color: rgba(255, 255, 255, 0.6) !important;
}

/* =============================================================================
   Loading Overlay Styles
   ============================================================================= */

#loading-overlay {
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

/* Loading spinner animation enhancement */
@keyframes pulse-glow {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(255, 107, 53, 0.4);
  }
  50% {
    box-shadow: 0 0 0 10px rgba(255, 107, 53, 0);
  }
}

.loading-pulse {
  animation: pulse-glow 2s infinite;
}

/* =============================================================================
   Sidebar Styles (Flowbite Drawer)
   ============================================================================= */

/* Ensure proper z-index for Flowbite drawer */
#sidebar-navigation {
  z-index: 50 !important;
}

/* Right sidebar toggle animations */
#right-sidebar {
  transition: transform 0.3s ease-in-out;
  height: calc(100vh - 4rem); /* Account for header height */
}

#right-sidebar.translate-x-full {
  transform: translateX(100%);
}

/* Custom sidebar scrolling */
.sidebar-scroll {
  scrollbar-width: thin;
  scrollbar-color: #cbd5e1 #f1f5f9;
}

.dark .sidebar-scroll {
  scrollbar-color: #6b7280 #374151;
}

/* Flowbite drawer backdrop enhancement */
[data-drawer-backdrop] {
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

/* Vehicle list item hover effects in sidebar */
.vehicle-item a:hover {
  background-color: rgba(255, 107, 53, 0.05) !important;
}

.dark .vehicle-item a:hover {
  background-color: rgba(255, 107, 53, 0.1) !important;
}

/* Vehicle card hover effects */
.vehicle-card {
  transition: all 0.2s ease-in-out;
}

.vehicle-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);
}

/* Closest vehicle card special styling */
.closest-vehicle-card {
  position: relative;
  overflow: hidden;
}

.closest-vehicle-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, #10b981, #34d399);
}

/* =============================================================================
   Toast Notification Styles
   ============================================================================= */

.toast-enter {
  transform: translateX(100%);
  opacity: 0;
}

.toast-enter-active {
  transform: translateX(0);
  opacity: 1;
  transition: all 0.3s ease-out;
}

.toast-exit {
  transform: translateX(0);
  opacity: 1;
}

.toast-exit-active {
  transform: translateX(100%);
  opacity: 0;
  transition: all 0.3s ease-in;
}

/* =============================================================================
   Status Indicator Styles
   ============================================================================= */

/* Connection status indicator animations */
.status-connecting {
  animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

.status-connected {
  animation: none;
  box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.2);
}

.status-error {
  animation: pulse 1s cubic-bezier(0.4, 0, 0.6, 1) infinite;
  box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.2);
}

/* =============================================================================
   Form Input Enhancements
   ============================================================================= */

/* Address search input focus effects */
#address-search:focus {
  box-shadow: 0 0 0 3px rgba(255, 107, 53, 0.1);
  border-color: var(--sps-primary);
}

.dark #address-search:focus {
  box-shadow: 0 0 0 3px rgba(255, 107, 53, 0.2);
}

/* Search button hover effects */
#search-btn:hover svg {
  color: var(--sps-primary);
  transform: scale(1.1);
  transition: all 0.2s ease-in-out;
}

/* =============================================================================
   Responsive Design Enhancements
   ============================================================================= */

/* Mobile-specific adjustments */
@media (max-width: 768px) {
  /* Flowbite drawer mobile adjustments */
  #sidebar-navigation {
    width: 100% !important;
    max-width: 320px !important;
  }

  /* Right sidebar mobile adjustments */
  #right-sidebar {
    width: 100% !important;
    max-width: 100vw !important;
    position: fixed !important;
    top: 64px !important;
    right: 0 !important;
    bottom: 0 !important;
    z-index: 45 !important;
  }

  /* Ensure mobile toggle button is visible */
  [data-drawer-toggle="sidebar-navigation"] {
    display: inline-flex !important;
  }

  /* Stack layout on mobile */
  .mobile-stack {
    flex-direction: column;
  }

  /* Adjust map controls position on mobile */
  .mapboxgl-ctrl-bottom-right {
    bottom: 10px !important;
    right: 10px !important;
    position: fixed !important;
    z-index: 100 !important;
  }

  /* On mobile, controls stay in same position regardless of drawer state */
  .map-with-right-sidebar .mapboxgl-ctrl-bottom-right {
    right: 10px !important;
  }

  /* Adjust overlay positioning */
  .mobile-overlay {
    position: fixed;
    top: 64px; /* Account for header */
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
  }
}

/* Tablet adjustments */
@media (min-width: 769px) and (max-width: 1024px) {
  /* Adjust sidebar width on tablet */
  .sidebar-tablet {
    width: 320px;
  }
}

/* =============================================================================
   Animation Utilities
   ============================================================================= */

/* Fade in animation */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.fade-in {
  animation: fadeIn 0.3s ease-out;
}

/* Slide in from right */
@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.slide-in-right {
  animation: slideInRight 0.3s ease-out;
}

/* Bounce animation for markers */
@keyframes markerBounce {
  0%,
  20%,
  50%,
  80%,
  100% {
    transform: translateY(0);
  }
  40% {
    transform: translateY(-10px);
  }
  60% {
    transform: translateY(-5px);
  }
}

.marker-bounce {
  animation: markerBounce 1s ease-in-out;
}

/* =============================================================================
   Accessibility Enhancements
   ============================================================================= */

/* Focus indicators for keyboard navigation */
.focus-visible:focus {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .vehicle-card {
    border-width: 2px;
  }

  .closest-vehicle-card {
    border-width: 3px;
    border-color: #059669;
  }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .mapboxgl-map {
    transition: none !important;
  }
}

/* =============================================================================
   Print Styles
   ============================================================================= */

@media print {
  /* Hide interactive elements when printing */
  .no-print {
    display: none !important;
  }

  /* Ensure map is visible in print */
  #map {
    height: 400px !important;
    width: 100% !important;
  }

  /* Adjust sidebar for print */
  .sidebar {
    position: static !important;
    width: 100% !important;
    border: none !important;
    box-shadow: none !important;
  }
}

/* =============================================================================
   Video Player Styles
   ============================================================================= */

/* Video player container */
#video-player-section {
  animation: slideInRight 0.3s ease-out;
  position: relative;
  z-index: 10;
}

/* Video player container responsive sizing */
.video-container {
  position: relative;
  width: 100%;
  max-width: 100%;
  background: #000;
  border-radius: 8px;
  overflow: hidden;
}

/* Video element styling */
#vehicle-video-player {
  width: 100%;
  height: auto;
  min-height: 200px;
  max-height: 300px;
  background: #000;
  border-radius: 8px;
  object-fit: contain;
}

/* Video loading overlay */
#video-loading {
  background: rgba(0, 0, 0, 0.8);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

/* Video error overlay */
#video-error {
  background: rgba(0, 0, 0, 0.9);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

/* Video status indicator animations */
#video-status-indicator.animate-pulse {
  animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

/* Video control buttons */
.video-control-btn {
  transition: all 0.2s ease-in-out;
}

.video-control-btn:hover {
  transform: scale(1.05);
}

/* View Camera button styling */
.view-camera-btn {
  background: linear-gradient(135deg, #10b981, #059669);
  transition: all 0.2s ease-in-out;
}

.view-camera-btn:hover {
  background: linear-gradient(135deg, #059669, #047857);
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(16, 185, 129, 0.3);
}

.view-camera-btn:active {
  transform: translateY(0);
}

/* Video player responsive design */
@media (max-width: 768px) {
  #vehicle-video-player {
    max-height: 200px;
    min-height: 150px;
  }

  #video-player-section {
    margin-top: 1rem;
    padding-top: 1rem;
  }

  .video-container {
    border-radius: 6px;
  }
}

@media (max-width: 480px) {
  #vehicle-video-player {
    max-height: 180px;
    min-height: 120px;
  }

  /* Stack video control buttons on very small screens */
  .video-controls-mobile {
    flex-direction: column;
    gap: 0.5rem;
  }

  .video-controls-mobile button {
    width: 100%;
  }
}

/* Video player dark mode enhancements */
.dark #video-player-section {
  border-color: #4b5563;
}

.dark .video-container {
  border: 1px solid #374151;
}

/* Video status indicator colors */
.video-status-connecting {
  background-color: #fbbf24;
  box-shadow: 0 0 0 2px rgba(251, 191, 36, 0.2);
}

.video-status-connected {
  background-color: #10b981;
  box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.2);
}

.video-status-streaming {
  background-color: #10b981;
  animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
  box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.3);
}

.video-status-buffering {
  background-color: var(--sps-secondary);
  animation: pulse 1.5s cubic-bezier(0.4, 0, 0.6, 1) infinite;
  box-shadow: 0 0 0 2px rgba(30, 58, 138, 0.2);
}

.video-status-error {
  background-color: #ef4444;
  animation: pulse 1s cubic-bezier(0.4, 0, 0.6, 1) infinite;
  box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.2);
}

/* Video player accessibility */
#vehicle-video-player:focus {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}

/* Retry button styling */
#retry-video-stream {
  transition: all 0.2s ease-in-out;
}

#retry-video-stream:hover {
  background-color: var(--sps-secondary-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(30, 64, 175, 0.3);
}

/* Video loading spinner enhancement */
#video-loading .animate-spin {
  filter: drop-shadow(0 0 8px rgba(255, 255, 255, 0.3));
}

/* Video error icon styling */
#video-error svg {
  filter: drop-shadow(0 0 4px rgba(239, 68, 68, 0.3));
}

/* Smooth transitions for video states */
#video-loading,
#video-error {
  transition: opacity 0.3s ease-in-out;
}

/* Video player fullscreen support */
#vehicle-video-player:-webkit-full-screen {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

#vehicle-video-player:-moz-full-screen {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

#vehicle-video-player:fullscreen {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* =============================================================================
   Vehicle Popup Video Styles
   ============================================================================= */

/* Popup video container */
.vehicle-popup-content .video-container {
  position: relative;
  width: 100%;
  background: #000;
  border-radius: 8px;
  overflow: hidden;
}

/* Popup video elements */
.vehicle-popup-content video[id^="popup-video-"] {
  width: 100%;
  height: auto;
  min-height: 150px;
  max-height: 200px;
  background: #000;
  border-radius: 8px;
  object-fit: contain;
}

/* Popup video loading state */
.vehicle-popup-content div[id^="popup-video-loading-"] {
  background: rgba(0, 0, 0, 0.9);
  border-radius: 8px;
  min-height: 150px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Popup video error state */
.vehicle-popup-content div[id^="popup-video-error-"] {
  background: rgba(0, 0, 0, 0.9);
  border-radius: 8px;
  min-height: 150px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Popup video status */
.vehicle-popup-content div[id^="popup-video-status-"] {
  background: rgba(31, 41, 55, 0.8);
  border-radius: 4px;
  padding: 4px 8px;
  margin-top: 8px;
}

/* Popup video retry button */
.vehicle-popup-content button[id^="popup-retry-"] {
  transition: all 0.2s ease-in-out;
}

.vehicle-popup-content button[id^="popup-retry-"]:hover {
  background-color: var(--sps-secondary-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(30, 64, 175, 0.3);
}

/* Mobile responsive adjustments for popup video */
@media (max-width: 768px) {
  .vehicle-popup-content video[id^="popup-video-"] {
    max-height: 160px;
    min-height: 120px;
  }

  .vehicle-popup-content div[id^="popup-video-loading-"],
  .vehicle-popup-content div[id^="popup-video-error-"] {
    min-height: 120px;
  }
}

@media (max-width: 480px) {
  .vehicle-popup-content video[id^="popup-video-"] {
    max-height: 140px;
    min-height: 100px;
  }

  .vehicle-popup-content div[id^="popup-video-loading-"],
  .vehicle-popup-content div[id^="popup-video-error-"] {
    min-height: 100px;
  }
}
