/* ==============================================================================
   Mobile-First Responsive Styles
   ==============================================================================
   This file contains mobile-first responsive styles to ensure HassleFreebooks
   looks great and functions perfectly on all device sizes. It follows a
   mobile-first approach with progressive enhancement for larger screens.

   Breakpoints:
   - Base: 0-575px (Mobile)
   - Small: 576px-767px (Large Mobile)
   - Medium: 768px-991px (Tablet)
   - Large: 992px-1199px (Desktop)
   - Extra Large: 1200px+ (Wide Desktop)
   ============================================================================== */

/* ==============================================================================
   Base Mobile Styles (0-575px)
   ============================================================================== */

/* Improved mobile typography */
@media (max-width: 575px) {
  /* Better font sizes for mobile readability */
  body {
    font-size: 16px; /* Prevent zoom on iOS */
    line-height: 1.6;
  }

  h1 {
    font-size: 1.75rem;
    line-height: 1.2;
    margin-bottom: 1rem;
  }

  h2 {
    font-size: 1.5rem;
    line-height: 1.3;
  }

  h3 {
    font-size: 1.25rem;
    line-height: 1.4;
  }

  /* Improved mobile spacing */
  .container {
    padding-left: 1rem;
    padding-right: 1rem;
    max-width: 100%;
  }

  /* Stack elements on mobile */
  .row {
    flex-direction: column;
  }

  .col {
    width: 100%;
    margin-bottom: 1rem;
  }

  /* Better button sizing for touch */
  .btn {
    min-height: 48px;
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    width: 100%;
    display: block;
    text-align: center;
  }

  /* Stack button groups */
  .btn-group {
    flex-direction: column;
    gap: 0.5rem;
  }

  .btn-group .btn {
    margin: 0;
    width: 100%;
  }

  /* Full-width forms on mobile */
  .form-control,
  .form-select,
  .form-textarea {
    min-height: 48px;
    font-size: 16px; /* Prevent zoom on iOS */
    width: 100%;
  }

  /* Mobile-friendly cards */
  .card {
    margin-bottom: 1rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  }

  /* Responsive tables */
  .table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 1rem;
  }

  .table {
    min-width: 100%;
    font-size: 0.875rem;
  }

  /* Mobile navigation adjustments */
  .navbar {
    padding: 0.5rem 1rem;
  }

  .navbar-brand {
    font-size: 1.125rem;
  }

  /* Hide desktop navigation, show mobile toggle */
  .navbar-nav-desktop {
    display: none;
  }

  .navbar-toggle {
    display: block;
  }

  /* Mobile menu styles */
  .mobile-menu {
    position: fixed;
    top: 60px;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--bg-color);
    z-index: 1000;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .mobile-menu.active {
    transform: translateX(0);
  }

  .mobile-menu-nav {
    padding: 1rem;
  }

  .mobile-menu-link {
    display: block;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
    text-decoration: none;
    color: var(--text-color);
  }

  /* Modals on mobile */
  .modal-content {
    margin: 1rem;
    max-height: calc(100vh - 2rem);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .modal-header,
  .modal-footer {
    position: sticky;
    background-color: var(--bg-color);
    z-index: 1;
  }

  .modal-header {
    top: 0;
  }

  .modal-footer {
    bottom: 0;
  }

  /* Mobile-friendly spacing utilities */
  .p-mobile-2 { padding: 0.5rem !important; }
  .p-mobile-3 { padding: 0.75rem !important; }
  .p-mobile-4 { padding: 1rem !important; }

  .m-mobile-0 { margin: 0 !important; }
  .m-mobile-2 { margin: 0.5rem !important; }
  .m-mobile-3 { margin: 0.75rem !important; }
}

/* ==============================================================================
   Large Mobile Styles (576px-767px)
   ============================================================================== */

@media (min-width: 576px) and (max-width: 767px) {
  /* Slightly larger container padding */
  .container {
    padding-left: 1.25rem;
    padding-right: 1.25rem;
  }

  /* Two-column layout for some elements */
  .grid-mobile-2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
  }

  /* Inline buttons where appropriate */
  .btn-inline-mobile {
    width: auto;
    display: inline-block;
  }

  /* Better card layout */
  .card-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
  }
}

/* ==============================================================================
   Tablet Styles (768px-991px)
   ============================================================================== */

@media (min-width: 768px) {
  /* Show desktop navigation */
  .navbar-nav-desktop {
    display: flex;
  }

  .navbar-toggle {
    display: none;
  }

  .mobile-menu {
    display: none;
  }

  /* Three-column grid for tablets */
  .grid-tablet-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
  }

  /* Side-by-side forms */
  .form-row {
    display: flex;
    gap: 1rem;
  }

  .form-row > * {
    flex: 1;
  }

  /* Inline buttons */
  .btn {
    width: auto;
    display: inline-block;
  }

  /* Better modal sizing */
  .modal-content {
    max-width: 600px;
    margin: 3rem auto;
  }

  /* Improved table display */
  .table {
    font-size: 1rem;
  }

  /* Two-column layout utilities */
  .row-tablet {
    display: flex;
    flex-wrap: wrap;
  }

  .col-tablet-6 {
    flex: 0 0 50%;
    max-width: 50%;
  }

  .col-tablet-4 {
    flex: 0 0 33.333%;
    max-width: 33.333%;
  }
}

/* ==============================================================================
   Desktop Styles (992px+)
   ============================================================================== */

@media (min-width: 992px) {
  /* Desktop container */
  .container {
    max-width: 960px;
  }

  /* Four-column grid for desktop */
  .grid-desktop-4 {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 2rem;
  }

  /* Hover effects enabled on desktop */
  .card-hoverable:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
  }

  /* Better spacing on desktop */
  section {
    padding: 4rem 0;
  }

  /* Side navigation layout */
  .layout-sidebar {
    display: grid;
    grid-template-columns: 250px 1fr;
    gap: 2rem;
  }

  /* Desktop-specific utilities */
  .desktop-only {
    display: block;
  }

  .mobile-only {
    display: none;
  }
}

/* ==============================================================================
   Wide Desktop Styles (1200px+)
   ============================================================================== */

@media (min-width: 1200px) {
  .container {
    max-width: 1140px;
  }

  /* Five-column grid for wide displays */
  .grid-wide-5 {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 2rem;
  }

  /* Larger modals on wide screens */
  .modal-content-large {
    max-width: 800px;
  }

  .modal-content-xlarge {
    max-width: 1000px;
  }
}

/* ==============================================================================
   Touch Device Enhancements
   ============================================================================== */

/* Improve touch targets */
@media (hover: none) and (pointer: coarse) {
  /* Larger click/tap areas */
  a,
  button,
  .clickable {
    min-height: 44px;
    min-width: 44px;
  }

  /* Remove hover effects on touch devices */
  .hover-effect:hover {
    transform: none;
    box-shadow: none;
  }

  /* Better form inputs for touch */
  input,
  textarea,
  select {
    min-height: 48px;
  }

  /* Disable hover menus on touch */
  .dropdown:hover .dropdown-menu {
    display: none;
  }

  /* Require tap to open dropdowns */
  .dropdown.active .dropdown-menu {
    display: block;
  }
}

/* ==============================================================================
   Landscape Mobile Adjustments
   ============================================================================== */

@media (max-width: 767px) and (orientation: landscape) {
  /* Reduce vertical spacing in landscape */
  .hero-section {
    padding: 2rem 0;
  }

  h1 {
    font-size: 1.5rem;
  }

  /* Horizontal layout for forms */
  .form-landscape {
    display: flex;
    gap: 1rem;
  }

  /* Side-by-side buttons */
  .btn-group-landscape {
    flex-direction: row;
  }

  /* Reduce modal height */
  .modal-content {
    max-height: calc(100vh - 4rem);
  }
}

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

@media print {
  /* Hide unnecessary elements */
  .no-print,
  .navbar,
  .footer,
  .btn,
  .modal,
  .mobile-menu {
    display: none !important;
  }

  /* Expand content for print */
  .container {
    max-width: 100%;
    padding: 0;
  }

  /* Better print colors */
  * {
    color: black !important;
    background: white !important;
  }

  /* Show link URLs */
  a[href]:after {
    content: " (" attr(href) ")";
  }

  /* Page breaks */
  h1, h2, h3 {
    page-break-after: avoid;
  }

  .page-break {
    page-break-after: always;
  }
}

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

/* Focus visible for keyboard navigation */
@media (min-width: 768px) {
  *:focus-visible {
    outline: 3px solid var(--color-primary);
    outline-offset: 3px;
  }
}

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

  .btn,
  .card,
  .form-control {
    border: 2px solid currentColor !important;
  }
}

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