/* ==========================================================================
   SkyLogs Mobile-First Responsive Styles
   Comprehensive mobile optimizations for the entire application
   ========================================================================== */

/* ==========================================================================
   1. Base Mobile Overrides
   ========================================================================== */

/* Ensure proper box-sizing everywhere */
*, *::before, *::after {
  box-sizing: border-box;
}

/* Prevent horizontal scroll on mobile */
html, body {
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

/* Smoother touch scrolling */
body {
  -webkit-overflow-scrolling: touch;
}

/* Better tap targets (minimum 44x44px as per Apple HIG) */
button, 
a, 
input[type="submit"], 
input[type="button"],
.btn,
.nav-link,
.clickable {
  min-height: 44px;
  min-width: 44px;
}

/* Prevent zoom on input focus for iOS */
@media screen and (max-width: 768px) {
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="number"],
  input[type="tel"],
  input[type="url"],
  input[type="search"],
  input[type="date"],
  input[type="time"],
  input[type="datetime-local"],
  select,
  textarea {
    font-size: 16px !important;
  }
}


/* ==========================================================================
   2. Typography Mobile Adjustments
   ========================================================================== */

@media (max-width: 640px) {
  :root {
    /* Slightly smaller base sizes on very small screens */
    --font-size-base: 0.9375rem;  /* 15px */
    --font-size-lg: 1rem;          /* 16px */
    --font-size-xl: 1.125rem;      /* 18px */
    --font-size-2xl: 1.375rem;     /* 22px */
    --font-size-3xl: 1.625rem;     /* 26px */
    --font-size-4xl: 2rem;         /* 32px */
    
    /* Tighter spacing on mobile */
    --space-6: 1.25rem;    /* 20px instead of 24px */
    --space-8: 1.5rem;     /* 24px instead of 32px */
    --container-padding: var(--space-4);
  }
}


/* ==========================================================================
   3. Layout - Page Container Mobile
   ========================================================================== */

@media (max-width: 768px) {
  .page-container {
    padding-bottom: var(--space-8);
  }
  
  .page-content {
    padding: var(--space-4) var(--space-3);
  }
  
  .page-content-narrow,
  .page-content-wide {
    max-width: 100%;
    padding-left: var(--space-3);
    padding-right: var(--space-3);
  }
}

@media (max-width: 480px) {
  .page-content {
    padding: var(--space-3) var(--space-2);
  }
}


/* ==========================================================================
   4. Page Headers Mobile
   ========================================================================== */

@media (max-width: 768px) {
  .page-header-card {
    padding: var(--space-4);
    border-radius: var(--radius-lg);
  }
  
  .page-header-top {
    flex-direction: column;
    gap: var(--space-3);
  }
  
  .page-title {
    font-size: var(--font-size-xl);
    line-height: 1.3;
  }
  
  .page-subtitle {
    font-size: var(--font-size-sm);
  }
  
  .page-header-actions {
    width: 100%;
    flex-direction: column;
  }
  
  .page-header-actions .btn {
    width: 100%;
    justify-content: center;
  }
  
  .page-stats-row {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-2);
  }
  
  .page-stat-card {
    padding: var(--space-3);
  }
  
  .page-stat-value {
    font-size: var(--font-size-xl);
  }
}

@media (max-width: 480px) {
  .page-header-card {
    padding: var(--space-3);
    margin-left: calc(-1 * var(--space-2));
    margin-right: calc(-1 * var(--space-2));
    border-radius: 0;
  }
  
  .page-title {
    font-size: var(--font-size-lg);
  }
  
  .page-stats-row {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .page-stat-value {
    font-size: var(--font-size-lg);
  }
  
  .page-stat-label {
    font-size: 0.625rem;
  }
}


/* ==========================================================================
   5. Buttons Mobile
   ========================================================================== */

@media (max-width: 768px) {
  .btn {
    padding: var(--space-3) var(--space-4);
    font-size: var(--font-size-sm);
    width: auto;
  }
  
  .btn-lg {
    padding: var(--space-4) var(--space-6);
    font-size: var(--font-size-base);
  }
  
  /* Stack buttons vertically on mobile when in a group */
  .btn-group-mobile {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    width: 100%;
  }
  
  .btn-group-mobile .btn {
    width: 100%;
    justify-content: center;
  }
}


/* ==========================================================================
   6. Forms Mobile
   ========================================================================== */

@media (max-width: 768px) {
  .form-container {
    padding: var(--space-4);
    border-radius: var(--radius-lg);
  }
  
  .form-row {
    grid-template-columns: 1fr;
    gap: var(--space-3);
  }
  
  .form-group {
    margin-bottom: var(--space-4);
  }
  
  .form-label {
    margin-bottom: var(--space-1);
  }
  
  .form-input,
  .form-select,
  .form-textarea {
    padding: var(--space-3);
    font-size: 16px; /* Prevents iOS zoom */
  }
  
  .form-actions {
    flex-direction: column;
    gap: var(--space-3);
    margin-top: var(--space-6);
  }
  
  .form-actions .btn {
    width: 100%;
  }
  
  /* Filter forms */
  .filter-form {
    flex-direction: column;
    gap: var(--space-3);
  }
  
  .filter-input,
  .filter-select {
    width: 100%;
    min-width: unset;
  }
}

@media (max-width: 480px) {
  .form-container {
    padding: var(--space-3);
    margin-left: calc(-1 * var(--space-2));
    margin-right: calc(-1 * var(--space-2));
    border-radius: 0;
  }
}


/* ==========================================================================
   7. Cards Mobile
   ========================================================================== */

@media (max-width: 768px) {
  .content-card,
  .list-card,
  .legend-card {
    border-radius: var(--radius-lg);
    padding: var(--space-4);
  }
  
  .content-card-body {
    padding: var(--space-4);
  }
  
  .content-card-header {
    padding: var(--space-3) var(--space-4);
  }
  
  /* Flight cards specific */
  .flight-card {
    padding: var(--space-4);
  }
  
  .flight-card-header {
    flex-direction: column;
    gap: var(--space-3);
  }
  
  .flight-title {
    font-size: var(--font-size-lg);
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-2);
  }
  
  .flight-meta-row {
    flex-wrap: wrap;
    gap: var(--space-2);
  }
  
  .flight-actions {
    width: 100%;
    justify-content: flex-start;
    gap: var(--space-2);
  }
  
  .flight-details {
    gap: var(--space-2);
  }
  
  .detail-badge {
    font-size: var(--font-size-xs);
    padding: var(--space-1) var(--space-2);
  }
}

@media (max-width: 480px) {
  .content-card,
  .list-card {
    margin-left: calc(-1 * var(--space-2));
    margin-right: calc(-1 * var(--space-2));
    border-radius: 0;
  }
}


/* ==========================================================================
   8. Grids Mobile
   ========================================================================== */

@media (max-width: 768px) {
  .page-grid,
  .page-grid-2,
  .page-grid-3,
  .page-grid-4 {
    grid-template-columns: 1fr;
    gap: var(--space-3);
  }
  
  .page-grid-span-2 {
    grid-column: span 1;
  }
  
  .features-grid {
    grid-template-columns: 1fr;
    gap: var(--space-4);
  }
}


/* ==========================================================================
   9. Tables Mobile (Card Layout)
   ========================================================================== */

@media (max-width: 768px) {
  /* Convert tables to card layout on mobile */
  .table-responsive {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  
  /* Alternative: Stack table rows as cards */
  .table-stack-mobile thead {
    display: none;
  }
  
  .table-stack-mobile tbody tr {
    display: block;
    padding: var(--space-3);
    margin-bottom: var(--space-2);
    background: var(--color-bg-surface);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-xs);
  }
  
  .table-stack-mobile tbody td {
    display: flex;
    justify-content: space-between;
    padding: var(--space-2) 0;
    border-bottom: 1px solid var(--color-border-muted);
  }
  
  .table-stack-mobile tbody td:last-child {
    border-bottom: none;
  }
  
  .table-stack-mobile tbody td::before {
    content: attr(data-label);
    font-weight: var(--font-weight-medium);
    color: var(--color-text-muted);
  }
}


/* ==========================================================================
   10. Navigation Mobile Enhancements
   ========================================================================== */

@media (max-width: 768px) {
  .navbar-content {
    height: 56px;
    padding: 0 var(--space-3);
  }
  
  .brand-logo {
    height: 28px;
  }
  
  .brand-name {
    font-size: 1.125rem;
  }
  
  /* Mobile menu improvements */
  .mobile-menu {
    padding: var(--space-3);
    max-height: calc(100vh - 56px);
    overflow-y: auto;
  }
  
  .mobile-menu .nav-link {
    padding: var(--space-3);
    font-size: var(--font-size-base);
    border-radius: var(--radius-md);
  }
  
  .mobile-menu .nav-dropdown-menu {
    margin-top: var(--space-2);
  }
}


/* ==========================================================================
   11. Hero & Landing Page Mobile
   ========================================================================== */

@media (max-width: 768px) {
  .hero {
    padding: var(--space-10) 0 var(--space-8);
  }
  
  .hero-content {
    padding: 0 var(--space-4);
  }
  
  .hero-headline {
    font-size: clamp(1.75rem, 8vw, 2.5rem);
    margin-bottom: var(--space-4);
  }
  
  .hero-subhead {
    font-size: var(--font-size-base);
    margin-bottom: var(--space-6);
  }
  
  .hero-cta {
    flex-direction: column;
    gap: var(--space-3);
    width: 100%;
    max-width: 300px;
    margin-left: auto;
    margin-right: auto;
  }
  
  .hero-cta .btn-primary,
  .hero-cta .btn-secondary {
    width: 100%;
    padding: var(--space-4);
  }
  
  .hero-pills {
    gap: var(--space-2);
  }
  
  .hero-pill {
    font-size: var(--font-size-xs);
    padding: var(--space-1) var(--space-3);
  }
  
  /* Stats row in hero */
  .stats-row {
    gap: var(--space-4);
    padding: var(--space-4);
  }
  
  .stats-row-hero {
    margin-top: var(--space-6);
    padding: var(--space-4);
  }
  
  .stat-item {
    min-width: 80px;
  }
  
  .stat-value {
    font-size: var(--font-size-2xl);
  }
}

@media (max-width: 480px) {
  .hero {
    padding: var(--space-8) 0 var(--space-6);
  }
  
  .hero-content {
    padding: 0 var(--space-3);
  }
  
  .hero-headline {
    font-size: 1.5rem;
  }
  
  .stats-row {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
  }
  
  .stat-item {
    flex: 1 1 40%;
    min-width: 70px;
  }
}


/* ==========================================================================
   12. Feature Sections Mobile
   ========================================================================== */

@media (max-width: 768px) {
  .features-section {
    padding: var(--space-10) 0;
  }
  
  .features-header {
    margin-bottom: var(--space-8);
    padding: 0 var(--space-4);
  }
  
  .feature-card {
    padding: var(--space-6);
  }
  
  .feature-icon {
    width: 40px;
    height: 40px;
    font-size: 1.25rem;
  }
  
  .feature-title {
    font-size: var(--font-size-lg);
  }
  
  /* Comparison section */
  .comparison-grid {
    grid-template-columns: 1fr;
    gap: var(--space-4);
  }
  
  .comparison-column {
    padding: var(--space-4);
  }
}


/* ==========================================================================
   13. Modal & Overlay Mobile
   ========================================================================== */

@media (max-width: 768px) {
  .modal {
    width: 100%;
    max-width: 100%;
    margin: 0;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    max-height: 90vh;
    position: fixed;
    bottom: 0;
  }
  
  .modal-content {
    padding: var(--space-4);
  }
  
  .modal-header {
    padding: var(--space-3) var(--space-4);
  }
  
  .modal-footer {
    padding: var(--space-3) var(--space-4);
    flex-direction: column;
    gap: var(--space-2);
  }
  
  .modal-footer .btn {
    width: 100%;
  }
}


/* ==========================================================================
   14. Notices & Alerts Mobile
   ========================================================================== */

@media (max-width: 768px) {
  .notice {
    left: var(--space-3);
    right: var(--space-3);
    transform: none;
    width: auto;
    max-width: none;
    padding: var(--space-3);
    font-size: var(--font-size-sm);
  }
}


/* ==========================================================================
   15. Empty States Mobile
   ========================================================================== */

@media (max-width: 768px) {
  .empty-state-card,
  .empty-state {
    padding: var(--space-8) var(--space-4);
  }
  
  .empty-state-icon {
    font-size: 3rem;
  }
  
  .empty-state-title {
    font-size: var(--font-size-lg);
  }
  
  .empty-state-text {
    font-size: var(--font-size-sm);
  }
}


/* ==========================================================================
   16. Date Badge Mobile
   ========================================================================== */

@media (max-width: 768px) {
  .date-badge {
    min-width: 55px;
    padding: var(--space-2);
  }
  
  .date-badge-day {
    font-size: var(--font-size-xl);
  }
  
  .date-badge-month {
    font-size: 0.625rem;
  }
}


/* ==========================================================================
   17. Maps Mobile
   ========================================================================== */

@media (max-width: 768px) {
  /* Ensure maps are usable on mobile */
  .leaflet-container {
    height: 300px !important;
    min-height: 250px;
  }
  
  /* Larger touch targets for map controls */
  .leaflet-control-zoom a,
  .leaflet-control-layers-toggle {
    width: 36px !important;
    height: 36px !important;
    line-height: 36px !important;
    font-size: 18px !important;
  }
  
  .leaflet-popup-content {
    font-size: var(--font-size-sm);
    max-width: 200px;
  }
}


/* ==========================================================================
   18. Utility Classes Mobile
   ========================================================================== */

@media (max-width: 768px) {
  /* Mobile-specific visibility */
  .mobile-only {
    display: block !important;
  }
  
  .desktop-only {
    display: none !important;
  }
  
  /* Full width on mobile */
  .mobile-full-width {
    width: 100% !important;
  }
  
  /* Stack flex items on mobile */
  .mobile-stack {
    flex-direction: column !important;
  }
  
  /* Remove padding on mobile */
  .mobile-no-padding {
    padding: 0 !important;
  }
  
  /* Center text on mobile */
  .mobile-text-center {
    text-align: center !important;
  }
  
  /* Smaller gaps on mobile */
  .gap-responsive {
    gap: var(--space-2) !important;
  }
}

@media (min-width: 769px) {
  .mobile-only {
    display: none !important;
  }
  
  .desktop-only {
    display: block !important;
  }
}


/* ==========================================================================
   19. Scroll & Touch Improvements
   ========================================================================== */

/* Horizontal scroll containers with snap */
.scroll-snap-x {
  display: flex;
  gap: var(--space-3);
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  padding: var(--space-2);
  margin: calc(-1 * var(--space-2));
}

.scroll-snap-x > * {
  scroll-snap-align: start;
  flex-shrink: 0;
}

/* Hide scrollbar but keep functionality */
.scroll-hide-bar {
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.scroll-hide-bar::-webkit-scrollbar {
  display: none;
}


/* ==========================================================================
   20. Safe Area Insets (for notched devices)
   ========================================================================== */

@supports (padding: max(0px)) {
  .safe-area-inset-top {
    padding-top: max(var(--space-4), env(safe-area-inset-top));
  }
  
  .safe-area-inset-bottom {
    padding-bottom: max(var(--space-4), env(safe-area-inset-bottom));
  }
  
  .safe-area-inset-left {
    padding-left: max(var(--space-4), env(safe-area-inset-left));
  }
  
  .safe-area-inset-right {
    padding-right: max(var(--space-4), env(safe-area-inset-right));
  }
}


/* ==========================================================================
   21. Print Styles
   ========================================================================== */

@media print {
  .navbar,
  .mobile-menu,
  .mobile-menu-toggle,
  .btn,
  .flight-actions,
  .page-header-actions {
    display: none !important;
  }
  
  .page-container {
    background: white;
    padding: 0;
  }
  
  .page-content {
    max-width: 100%;
    padding: 0;
  }
  
  .content-card,
  .list-card {
    box-shadow: none;
    border: 1px solid #ddd;
  }
}
