/* ═══════════════════════════════════════════════════════════════
   Mobile & Tablet Responsive Styles - App-Like Experience
   ═══════════════════════════════════════════════════════════════ */

/* ═══════════════════════════════════════════════════════════════
   MOBILE-FIRST BASE STYLES
   ═══════════════════════════════════════════════════════════════ */

/* Smooth scrolling for better mobile experience */
html {
  scroll-behavior: smooth;
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
  -webkit-touch-callout: none;
}

body {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overscroll-behavior-y: contain;
}

/* Better touch targets - minimum 44x44px for mobile */
button, a, input, select, textarea {
  min-height: 44px;
  touch-action: manipulation;
}

/* ═══════════════════════════════════════════════════════════════
   MOBILE NAVBAR - Collapsible & Touch-Friendly
   ═══════════════════════════════════════════════════════════════ */

@media (max-width: 767px) {
  /* Mobile Navbar */
  .navbar {
    padding: 0.5rem 1rem;
  }

  .navbar-brand {
    font-size: 1.4rem;
  }

  /* Mobile Menu Toggle Button */
  .navbar-toggler {
    border: 2px solid rgba(255, 255, 255, 0.5);
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
  }

  .navbar-toggler:focus {
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.25);
    outline: none;
  }

  /* Mobile Dropdown Menu - Full Width */
  .navbar-collapse {
    background: linear-gradient(135deg, var(--primary-light) 0%, var(--primary-dark) 100%);
    margin: 0.5rem -1rem -0.5rem -1rem;
    padding: 1rem;
    border-radius: 0 0 12px 12px;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
  }

  .navbar-nav {
    gap: 0.5rem;
  }

  .navbar-nav .nav-link {
    padding: 0.75rem 1rem !important;
    margin: 0;
    font-size: 1rem;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.1);
  }

  .navbar-nav .nav-link:active {
    background: rgba(255, 255, 255, 0.25);
  }

  /* Mobile Dropdown Items */
  .dropdown-menu {
    background: rgba(255, 255, 255, 0.98);
    border: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    margin-top: 0.5rem;
    width: 100%;
  }

  .dropdown-item {
    padding: 0.875rem 1rem;
    font-size: 0.95rem;
    min-height: 48px;
    display: flex;
    align-items: center;
  }
}

/* ═══════════════════════════════════════════════════════════════
   TABLET OPTIMIZATION (768px - 1024px)
   ═══════════════════════════════════════════════════════════════ */

@media (min-width: 768px) and (max-width: 1024px) {
  .navbar-brand {
    font-size: 1.4rem;
  }

  .navbar-nav .nav-link {
    font-size: 0.95rem;
    padding: 0.5rem 0.85rem !important;
  }

  .container {
    max-width: 100%;
    padding: 0 1.5rem;
  }
}

/* ═══════════════════════════════════════════════════════════════
   MOBILE CARDS & TABLES
   ═══════════════════════════════════════════════════════════════ */

@media (max-width: 767px) {
  /* Cards - Stack vertically with proper spacing */
  .card {
    margin-bottom: 1rem;
    border-radius: 12px;
  }

  .card-header {
    padding: 1rem;
    font-size: 1rem;
  }

  .card-body {
    padding: 1rem;
  }

  /* Tables - Horizontal scroll with shadow indicators */
  .table-responsive {
    border-radius: 12px;
    box-shadow: inset -10px 0 10px -10px rgba(0, 0, 0, 0.1);
    margin-bottom: 1rem;
  }

  .table {
    font-size: 0.875rem;
    margin-bottom: 0;
  }

  .table thead th {
    padding: 0.75rem 0.5rem;
    font-size: 0.8rem;
    white-space: nowrap;
  }

  .table tbody td {
    padding: 0.75rem 0.5rem;
    white-space: nowrap;
  }

  /* Mobile-friendly table alternative - Card view */
  .mobile-card-view {
    display: block;
  }

  .mobile-card-view .card {
    margin-bottom: 0.75rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  }
}

/* ═══════════════════════════════════════════════════════════════
   MOBILE FORMS - Touch-Optimized
   ═══════════════════════════════════════════════════════════════ */

@media (max-width: 767px) {
  .form-control, .form-select {
    font-size: 16px; /* Prevents zoom on iOS */
    padding: 0.75rem 1rem;
    min-height: 48px;
    border-radius: 10px;
  }

  .form-label {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
  }

  /* Form groups spacing */
  .mb-3 {
    margin-bottom: 1.25rem !important;
  }

  /* Buttons - Full width on mobile for easier tapping */
  .btn {
    min-height: 48px;
    font-size: 1rem;
    padding: 0.75rem 1.5rem;
    border-radius: 10px;
    font-weight: 600;
  }

  .btn-block-mobile {
    width: 100%;
    display: block;
  }

  /* Button groups - Stack vertically */
  .btn-group-mobile {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
  }

  .btn-group-mobile .btn {
    width: 100%;
  }
}

/* ═══════════════════════════════════════════════════════════════
   MOBILE MODALS - Full Screen on Small Devices
   ═══════════════════════════════════════════════════════════════ */

@media (max-width: 767px) {
  .modal-dialog {
    margin: 0;
    max-width: 100%;
    height: 100vh;
  }

  .modal-content {
    height: 100%;
    border-radius: 0;
    border: none;
  }

  .modal-header {
    padding: 1rem 1.25rem;
    border-radius: 0;
  }

  .modal-body {
    padding: 1.25rem;
    overflow-y: auto;
  }

  .modal-footer {
    padding: 1rem 1.25rem;
    border-radius: 0;
  }
}

/* ═══════════════════════════════════════════════════════════════
   MOBILE FOOTER - Sticky & Compact
   ═══════════════════════════════════════════════════════════════ */

@media (max-width: 767px) {
  .footer {
    padding: 1rem 0;
    font-size: 0.85rem;
    text-align: center;
  }
}

/* ═══════════════════════════════════════════════════════════════
   TOUCH GESTURES & INTERACTIONS
   ═══════════════════════════════════════════════════════════════ */

/* Active state for touch feedback */
@media (max-width: 767px) {
  .btn:active,
  .nav-link:active,
  .dropdown-item:active {
    transform: scale(0.98);
    opacity: 0.9;
  }

  /* Swipe indicators for horizontal scroll */
  .table-responsive::after {
    content: '← Swipe →';
    position: absolute;
    bottom: 0.5rem;
    right: 0.5rem;
    font-size: 0.75rem;
    color: var(--gray-400);
    pointer-events: none;
    opacity: 0.6;
  }
}

/* ═══════════════════════════════════════════════════════════════
   LANDSCAPE MODE OPTIMIZATION
   ═══════════════════════════════════════════════════════════════ */

@media (max-width: 767px) and (orientation: landscape) {
  .navbar {
    padding: 0.35rem 1rem;
  }

  .navbar-brand {
    font-size: 1.1rem;
  }

  .navbar-nav .nav-link {
    padding: 0.5rem 0.75rem !important;
    font-size: 0.9rem;
  }
}

/* ═══════════════════════════════════════════════════════════════
   TABLET LANDSCAPE (1024px+)
   ═══════════════════════════════════════════════════════════════ */

@media (min-width: 1024px) {
  .container {
    max-width: 1200px;
  }
}

/* ═══════════════════════════════════════════════════════════════
   ACCESSIBILITY - Better Focus States for Touch
   ═══════════════════════════════════════════════════════════════ */

@media (max-width: 767px) {
  *:focus-visible {
    outline: 3px solid rgba(65, 105, 225, 0.5);
    outline-offset: 2px;
  }

  /* Remove outline for mouse users */
  *:focus:not(:focus-visible) {
    outline: none;
  }
}

/* ═══════════════════════════════════════════════════════════════
   LOADING STATES - Mobile Optimized
   ═══════════════════════════════════════════════════════════════ */

@media (max-width: 767px) {
  .spinner-border {
    width: 2rem;
    height: 2rem;
  }

  .loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
  }
}

/* ═══════════════════════════════════════════════════════════════
   TOAST NOTIFICATIONS - Mobile Position
   ═══════════════════════════════════════════════════════════════ */

@media (max-width: 767px) {
  #toastContainer {
    top: auto !important;
    bottom: 16px !important;
    right: 16px !important;
    left: 16px !important;
    max-width: calc(100vw - 32px);
  }

  #toastContainer > div {
    width: 100%;
    max-width: 100%;
  }
}

/* ═══════════════════════════════════════════════════════════════
   SAFE AREA INSETS - For Notched Devices (iPhone X+)
   ═══════════════════════════════════════════════════════════════ */

@supports (padding: max(0px)) {
  body {
    padding-left: max(0px, env(safe-area-inset-left));
    padding-right: max(0px, env(safe-area-inset-right));
  }

  .navbar {
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
  }

  .footer {
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
  }
}

/* ═══════════════════════════════════════════════════════════════
   PRINT STYLES - Hide unnecessary elements
   ═══════════════════════════════════════════════════════════════ */

@media print {
  .navbar,
  .footer,
  .btn,
  #toastContainer {
    display: none !important;
  }

  body {
    background: white;
  }

  .card {
    box-shadow: none;
    border: 1px solid #ddd;
  }
}
