/* ==========================================================================
   LSPD / SASP Panel - Elite Responsive & Aesthetic Design System
   Optimized for Desktop (1280px+), Tablet (768px - 1023px), and Mobile (< 768px)
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800;900&family=JetBrains+Mono:wght@400;500;600;700&display=swap');

/* --- Root & Global Resets --- */
:root {
  --lspd-blue-primary: #2563eb;
  --lspd-blue-glow: rgba(37, 99, 235, 0.4);
  --lspd-navy-dark: #070b14;
  --lspd-navy-card: #0d1527;
  --lspd-navy-surface: #131d35;
  --lspd-border-subtle: rgba(59, 130, 246, 0.18);
  --lspd-border-strong: rgba(59, 130, 246, 0.35);
  --sidebar-w: 16rem;
  --header-h: 4rem;
}

html, body {
  font-family: 'Plus Jakarta Sans', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif !important;
  background-color: var(--lspd-navy-dark) !important;
  color: #e2e8f0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
  max-width: 100vw;
  scroll-behavior: smooth;
}

/* Custom Sleek Dark Scrollbars */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: rgba(15, 23, 42, 0.6);
}
::-webkit-scrollbar-thumb {
  background: rgba(71, 85, 105, 0.6);
  border-radius: 9999px;
  transition: background 0.2s;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(59, 130, 246, 0.6);
}
* {
  scrollbar-width: thin;
  scrollbar-color: rgba(71, 85, 105, 0.6) rgba(15, 23, 42, 0.6);
}

/* ==========================================================================
   1. CORE RESPONSIVE LAYOUT (Desktop vs Tablet vs Mobile)
   ========================================================================== */

/* Main layout wrapper */
#root > div {
  min-height: 100vh;
  background: radial-gradient(circle at 15% 15%, rgba(37, 99, 235, 0.08) 0%, transparent 40%),
              radial-gradient(circle at 85% 85%, rgba(14, 165, 233, 0.05) 0%, transparent 40%),
              #070b14 !important;
  display: flex !important;
  width: 100% !important;
  max-width: 100vw !important;
  overflow-x: hidden !important;
}

/* Main Content Area */
main {
  width: 100% !important;
  max-width: 100vw !important;
  min-width: 0 !important;
  box-sizing: border-box !important;
}

/* Header Enhancements */
header {
  position: sticky !important;
  top: 0 !important;
  z-index: 45 !important;
  backdrop-filter: blur(12px) !important;
  -webkit-backdrop-filter: blur(12px) !important;
  background: rgba(15, 23, 42, 0.92) !important;
  border-bottom: 1px solid var(--lspd-border-subtle) !important;
  box-shadow: 0 4px 20px -2px rgba(0, 0, 0, 0.5) !important;
  transition: all 0.2s ease !important;
}

/* ==========================================================================
   2. MOBILE & TABLET OFF-CANVAS SIDEBAR (< 1024px)
   ========================================================================== */

@media (max-width: 1023px) {
  /* Content margin reset */
  .ml-64,
  div[class*="ml-64"] {
    margin-left: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
  }

  /* Aside turns into off-canvas drawer */
  aside {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    bottom: 0 !important;
    height: 100vh !important;
    height: 100dvh !important;
    width: 290px !important;
    max-width: 86vw !important;
    transform: translateX(-105%) !important;
    transition: transform 0.32s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.32s ease !important;
    z-index: 1000 !important;
    background: rgba(11, 17, 33, 0.97) !important;
    backdrop-filter: blur(20px) !important;
    -webkit-backdrop-filter: blur(20px) !important;
    border-right: 1px solid var(--lspd-border-strong) !important;
    box-shadow: none !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
  }

  /* Open state */
  body.sidebar-open aside {
    transform: translateX(0) !important;
    box-shadow: 0 0 60px rgba(0, 0, 0, 0.95), 10px 0 35px rgba(37, 99, 235, 0.3) !important;
  }

  body.sidebar-open {
    overflow: hidden !important;
    touch-action: none !important;
  }

  /* Header adjustments on mobile/tablet */
  header {
    padding-left: 0.875rem !important;
    padding-right: 0.875rem !important;
    gap: 0.5rem !important;
  }

  header h2 {
    font-size: 1.05rem !important;
    line-height: 1.3 !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    max-width: 190px !important;
  }

  /* Page padding adjustments on mobile/tablet */
  main {
    padding: 0.875rem !important;
  }
}

@media (min-width: 640px) and (max-width: 1023px) {
  header h2 {
    max-width: 320px !important;
    font-size: 1.2rem !important;
  }
  main {
    padding: 1.25rem !important;
  }
}

/* Desktop layout (>= 1024px) */
@media (min-width: 1024px) {
  aside {
    transform: none !important;
    width: 16rem !important;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.3) !important;
  }
  .ml-64,
  div[class*="ml-64"] {
    margin-left: 16rem !important;
  }
  #sidebar-backdrop,
  #mobile-menu-btn,
  #mobile-sidebar-close {
    display: none !important;
  }
}

/* ==========================================================================
   3. HAMBURGER MENU BUTTON & MOBILE DRAWER CONTROLS
   ========================================================================== */

#mobile-menu-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: rgba(30, 41, 59, 0.8);
  border: 1px solid var(--lspd-border-subtle);
  color: #93c5fd;
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
  outline: none;
  touch-action: manipulation;
}

#mobile-menu-btn:hover,
#mobile-menu-btn:active {
  background: rgba(37, 99, 235, 0.2);
  border-color: rgba(59, 130, 246, 0.5);
  color: #ffffff;
  transform: scale(0.96);
}

#sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 8, 18, 0.82);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 990;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

body.sidebar-open #sidebar-backdrop {
  opacity: 1 !important;
  pointer-events: auto !important;
}

#mobile-sidebar-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #f87171;
  cursor: pointer;
  transition: all 0.2s;
  outline: none;
}
#mobile-sidebar-close:active {
  transform: scale(0.92);
  background: rgba(239, 68, 68, 0.25);
}

/* ==========================================================================
   4. DEFCON COMPONENT RESPONSIVE FIXES
   ========================================================================== */

/* Prevent DEFCON card numbers from overflowing or clipping */
div[class*="DEFCON"],
div:has(> div:contains("DEFCON")),
.defcon-container {
  overflow: visible !important;
}

/* Fix flex containers wrapping in DEFCON and Status banners */
.bg-gradient-to-r,
div[class*="from-blue-950"],
div[class*="from-rose-950"] {
  max-width: 100% !important;
  box-sizing: border-box !important;
}

@media (max-width: 767px) {
  /* DEFCON banner: stack vertically on mobile */
  div:has(> span:contains("DEFCON")) {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 0.75rem !important;
  }
}

/* ==========================================================================
   5. GRID SYSTEMS RESPONSIVENESS (Stat Cards, Action Hubs)
   ========================================================================== */

/* Automatically adapt grids for mobile and tablet */
@media (max-width: 639px) {
  /* 4-column & 3-column grids become 1-column on small phones */
  .grid-cols-4,
  .grid-cols-3,
  .grid-cols-2 {
    grid-template-columns: repeat(1, minmax(0, 1fr)) !important;
    gap: 0.75rem !important;
  }

  /* Specific mini-stats can be 2 columns if compact */
  .mini-stat-grid,
  .grid-cols-2.compact {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 0.5rem !important;
  }

  /* Action buttons flex row -> column */
  .flex-row-mobile-col {
    flex-direction: column !important;
  }
}

@media (min-width: 640px) and (max-width: 1023px) {
  /* 4-column & 3-column grids become 2-column on tablets */
  .grid-cols-4,
  .grid-cols-3 {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 1rem !important;
  }
}

/* Stat Cards Aesthetics */
div[class*="bg-slate-900"]:hover,
div[class*="bg-slate-800\/50"]:hover {
  border-color: rgba(59, 130, 246, 0.4) !important;
  box-shadow: 0 8px 30px -4px rgba(0, 0, 0, 0.5), 0 0 20px -2px rgba(37, 99, 235, 0.15) !important;
}

/* ==========================================================================
   6. DISPATCH SYSTEM RESPONSIVE POLISH (/dispatch)
   ========================================================================== */

/* Station Tabs (Dashboard, MRPD, LSPD Little Seoul) */
.dispatch-tabs-container,
div:has(> button:contains("MRPD")),
div:has(> button:contains("LSPD")) {
  max-width: 100% !important;
  overflow-x: auto !important;
  -webkit-overflow-scrolling: touch !important;
  scrollbar-width: none;
}
.dispatch-tabs-container::-webkit-scrollbar {
  display: none;
}

@media (max-width: 767px) {
  /* Dispatch unit cards stack cleanly */
  .dispatch-column {
    min-width: 100% !important;
    width: 100% !important;
  }
  
  /* Status selection buttons */
  .dispatch-status-btn {
    padding: 0.5rem !important;
    font-size: 0.75rem !important;
  }
}

/* ==========================================================================
   7. TABLE SCROLL WRAPPERS & DATA GRIDS
   ========================================================================== */

/* All tables with overflow-x-auto */
.overflow-x-auto {
  position: relative !important;
  max-width: 100% !important;
  width: 100% !important;
  -webkit-overflow-scrolling: touch !important;
  border-radius: 0.75rem !important;
}

/* Table scroll visual cues */
.table-scroll-hint {
  display: none;
}
@media (max-width: 1023px) {
  .overflow-x-auto {
    border: 1px solid rgba(51, 65, 85, 0.6) !important;
    box-shadow: inset -10px 0 10px -10px rgba(0, 0, 0, 0.5) !important;
  }
}

/* Tables inside modals or pages */
table {
  border-collapse: separate !important;
  border-spacing: 0 !important;
}
th, td {
  white-space: normal !important;
}
th {
  position: sticky !important;
  top: 0 !important;
  z-index: 10 !important;
  background-color: #0b1120 !important;
}

/* ==========================================================================
   8. MODALS & POPUPS RESPONSIVENESS
   ========================================================================== */

.fixed.inset-0 {
  padding: 0.75rem !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
}

.fixed.inset-0 > div:not(#sidebar-backdrop) {
  max-width: calc(100vw - 1.5rem) !important;
  max-height: calc(100vh - 2rem) !important;
  max-height: calc(100dvh - 2rem) !important;
  overflow-y: auto !important;
  -webkit-overflow-scrolling: touch !important;
  box-shadow: 0 25px 60px -15px rgba(0, 0, 0, 0.9), 0 0 40px rgba(37, 99, 235, 0.25) !important;
  border: 1px solid var(--lspd-border-strong) !important;
}

@media (max-width: 639px) {
  /* Forms inside modals */
  .fixed.inset-0 .grid-cols-2,
  .fixed.inset-0 .grid-cols-3 {
    grid-template-columns: 1fr !important;
    gap: 0.75rem !important;
  }
  
  /* Modal action buttons stack or stretch */
  .fixed.inset-0 .modal-footer,
  .fixed.inset-0 .flex.justify-end {
    flex-direction: column-reverse !important;
    width: 100% !important;
    gap: 0.5rem !important;
  }
  .fixed.inset-0 .flex.justify-end > button {
    width: 100% !important;
    justify-content: center !important;
  }
}

/* ==========================================================================
   9. FORMS, SEARCH BARS & FILTER TOOLBARS
   ========================================================================== */

@media (max-width: 767px) {
  /* Search & Filter bars stack */
  div:has(> input[type="text"]):has(> button),
  .search-filter-bar {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 0.625rem !important;
  }

  /* Full width search input */
  input[type="text"],
  input[type="search"],
  select {
    width: 100% !important;
    font-size: 16px !important; /* Prevents auto-zoom on iOS Safari */
    min-height: 44px !important;
  }

  /* Buttons touch size */
  button {
    min-height: 42px !important;
  }
}

/* Input Fields Premium Glow */
input, select, textarea {
  transition: all 0.2s ease !important;
}
input:focus, select:focus, textarea:focus {
  border-color: #3b82f6 !important;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25) !important;
  outline: none !important;
}

/* ==========================================================================
   10. AESTHETICS & MICRO-INTERACTIONS (WOW FACTOR)
   ========================================================================== */

/* Badges & Pills */
.badge-police {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.25rem 0.625rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

/* Card glassmorphism & hover effects */
.panel-card {
  background: rgba(13, 21, 39, 0.85) !important;
  backdrop-filter: blur(12px) !important;
  -webkit-backdrop-filter: blur(12px) !important;
  border: 1px solid var(--lspd-border-subtle) !important;
  border-radius: 0.875rem !important;
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), border-color 0.2s ease, box-shadow 0.2s ease !important;
}

.panel-card:hover {
  border-color: var(--lspd-border-strong) !important;
  transform: translateY(-2px);
  box-shadow: 0 10px 30px -5px rgba(0, 0, 0, 0.6), 0 0 25px rgba(37, 99, 235, 0.15) !important;
}

/* Status Indicators */
.pulse-available {
  position: relative;
}
.pulse-available::before {
  content: "";
  position: absolute;
  inset: -2px;
  border-radius: 9999px;
  background: rgba(34, 197, 94, 0.4);
  animation: pulse-ring 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
  z-index: -1;
}

@keyframes pulse-ring {
  0% { transform: scale(0.95); opacity: 0.8; }
  50% { transform: scale(1.3); opacity: 0.2; }
  100% { transform: scale(1.5); opacity: 0; }
}

/* Login Page Watermark Fix */
img[alt="LSPD Watermark"] {
  max-width: 80vw !important;
  max-height: 80vh !important;
  pointer-events: none !important;
}

/* Print Optimization for Factures / Reports */
@media print {
  aside, header, #mobile-menu-btn, #sidebar-backdrop {
    display: none !important;
  }
  .ml-64, div[class*="ml-64"] {
    margin-left: 0 !important;
  }
  main {
    padding: 0 !important;
  }
}
