/* Mobile-First Responsive Optimization for KORIX Learn
   Prioritizes 375px mobile phones through responsive breakpoints */

/* ============================================
   ULTRA-MOBILE BREAKPOINT: 375px - 480px
   Primary target for 90% of users on phones
   ============================================ */

@media (max-width: 480px) {
  /* Typography: Larger, more readable on small screens */
  body {
    font-size: 15px;
    line-height: 1.6;
  }

  header {
    padding: 0.75rem 1rem;
    gap: 0.5rem;
  }

  header h1 {
    font-size: 1.1rem;
  }

  header .tag {
    font-size: 0.6rem;
    padding: 0.15rem 0.4rem;
  }

  .site-nav {
    gap: 0.3rem;
  }

  .site-nav a,
  .practice-btn {
    font-size: 0.7rem;
    padding: 0.3rem 0.6rem;
  }

  /* Menu toggle: Larger tap target */
  .menu-toggle {
    width: 2.4rem;
    height: 2.4rem;
    font-size: 1.1rem;
  }

  /* Layout: Full-width content on mobile */
  .layout {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  body.sidebar-collapsed .layout {
    grid-template-columns: 1fr;
  }

  /* Sidebar: Stack above content on mobile */
  .sidebar {
    max-height: none;
    display: none;
    position: absolute;
    top: 60px;
    left: 0;
    right: 0;
    background: var(--surface);
    border-right: none;
    border-bottom: 1px solid var(--border);
    z-index: 99;
    max-width: 100%;
    width: 100%;
    overflow-y: auto;
    max-height: 50vh;
  }

  body.sidebar-open .sidebar {
    display: block;
  }

  /* Content area: Reduce padding on mobile */
  .main-content {
    padding: 1rem;
  }

  /* Buttons: Full width, large tap targets (min 44px) */
  button,
  .btn,
  a.btn,
  input[type="button"],
  input[type="submit"] {
    min-height: 44px;
    width: 100%;
    font-size: 0.95rem;
    padding: 0.75rem 1rem;
  }

  .btn-small {
    width: auto;
    min-height: 40px;
    padding: 0.6rem 0.8rem;
  }

  /* Form fields: Full width, larger on mobile */
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="search"],
  textarea,
  select {
    width: 100%;
    min-height: 44px;
    font-size: 1rem;
    padding: 0.75rem;
    border-radius: 8px;
  }

  textarea {
    min-height: 100px;
  }

  /* Video: Responsive aspect ratio (16:9) */
  .video-wrapper {
    position: relative;
    width: 100%;
    padding-bottom: 56.25%; /* 16:9 */
    height: 0;
    overflow: hidden;
    margin-bottom: 1rem;
  }

  .video-wrapper iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: none;
  }

  /* Grid layouts: Single column on mobile */
  .course-grid,
  .grid-2,
  .drop-zones {
    display: flex;
    flex-direction: column;
    gap: 1rem;
  }

  .course-grid > *,
  .grid-2 > *,
  .drop-zones > * {
    width: 100%;
  }

  /* Cards: Full width with proper spacing */
  .card {
    width: 100%;
    margin-bottom: 1rem;
    padding: 1rem;
    border-radius: 8px;
  }

  /* Tables: Horizontal scroll on mobile */
  table {
    font-size: 0.9rem;
    overflow-x: auto;
    display: block;
    width: 100%;
  }

  tbody {
    display: block;
  }

  tr {
    display: block;
    margin-bottom: 1rem;
    border: 1px solid var(--border);
    border-radius: 4px;
  }

  td,
  th {
    display: block;
    padding: 0.5rem;
    text-align: left;
  }

  th {
    background: var(--surface-2);
    font-weight: 600;
  }

  /* Lists: Better mobile spacing */
  ul,
  ol {
    padding-left: 1.5rem;
  }

  li {
    margin-bottom: 0.75rem;
  }

  /* Modals/Overlays: Full screen on mobile */
  .modal,
  .dialog {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    max-width: none;
    border-radius: 0;
  }

  .modal-content,
  .dialog-content {
    width: 100%;
    max-width: 100%;
    padding: 1.5rem 1rem;
  }

  /* Floating action buttons: Larger on mobile */
  .fab {
    width: 52px;
    height: 52px;
    min-width: 44px;
    min-height: 44px;
  }

  /* Navigation: Stacked on mobile */
  .breadcrumb {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .breadcrumb-item {
    font-size: 0.85rem;
  }

  /* Spacing utilities for mobile */
  .mt-sm { margin-top: 0.5rem; }
  .mb-sm { margin-bottom: 0.5rem; }
  .px-sm { padding-left: 0.5rem; padding-right: 0.5rem; }

  /* Hide desktop-only elements */
  .desktop-only {
    display: none !important;
  }

  /* Show mobile-only elements */
  .mobile-only {
    display: block !important;
  }
}

/* ============================================
   SMALL TABLET BREAKPOINT: 481px - 768px
   Intermediate sizing
   ============================================ */

@media (min-width: 481px) and (max-width: 768px) {
  header {
    padding: 0.9rem 1.5rem;
  }

  header h1 {
    font-size: 1.2rem;
  }

  .main-content {
    padding: 1.5rem;
  }

  button,
  .btn,
  a.btn,
  input[type="submit"] {
    min-height: 42px;
  }

  input[type="text"],
  input[type="email"],
  input[type="password"],
  textarea,
  select {
    min-height: 42px;
    font-size: 1rem;
  }

  /* 2-column layout for tablet */
  .grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
  }

  .course-grid {
    grid-template-columns: 1fr;
  }
}

/* ============================================
   DESKTOP BREAKPOINT: 769px+
   Original desktop styles apply
   ============================================ */

@media (min-width: 769px) {
  .layout {
    grid-template-columns: 320px 1fr;
  }

  .sidebar {
    max-height: auto;
    display: block;
    position: static;
  }

  .grid-2,
  .course-grid {
    grid-template-columns: 1fr 1fr;
  }

  button,
  .btn,
  a.btn {
    width: auto;
    min-height: auto;
  }

  .mobile-only {
    display: none !important;
  }

  .desktop-only {
    display: block !important;
  }
}

/* ============================================
   TOUCH-FRIENDLY INTERACTIONS
   ============================================ */

/* Ensure all interactive elements are 44px minimum */
button,
a[role="button"],
input[type="button"],
input[type="submit"],
input[type="checkbox"],
input[type="radio"],
select,
textarea,
input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"] {
  min-width: 44px;
  min-height: 44px;
}

/* Better touch feedback */
@media (hover: none) and (pointer: coarse) {
  /* Mobile devices */
  button,
  a,
  input[type="submit"],
  .clickable {
    padding: 0.75rem;
  }

  button:active,
  a:active,
  .clickable:active {
    opacity: 0.7;
  }

  /* Disable hover states on touch devices */
  button:hover,
  a:hover {
    opacity: 1;
  }
}

/* ============================================
   RESPONSIVE IMAGES & MEDIA
   ============================================ */

img {
  max-width: 100%;
  height: auto;
  display: block;
}

picture {
  display: block;
  width: 100%;
}

/* Aspect ratio containers for images/videos */
.aspect-video {
  position: relative;
  padding-bottom: 56.25%; /* 16:9 */
  height: 0;
  overflow: hidden;
}

.aspect-video > * {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.aspect-square {
  position: relative;
  padding-bottom: 100%;
  height: 0;
  overflow: hidden;
}

.aspect-square > * {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

/* ============================================
   ACCESSIBILITY
   ============================================ */

/* Focus indicators visible on mobile */
*:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* Better contrast for touch targets */
button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  box-shadow: 0 0 0 3px var(--primary-soft);
}

/* ============================================
   PERFORMANCE: Optimized for mobile networks
   ============================================ */

/* Reduce animations on slow connections */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Optimize for slow 3G networks */
@media (max-width: 480px) {
  img {
    loading: lazy;
  }

  iframe {
    loading: lazy;
  }

  /* Reduce box shadows on mobile for performance */
  .shadow,
  .shadow-md {
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
  }
}
