/* 
 * Responsive Enhancements for CODED:UK
 * Mobile-first approach with progressive enhancement
 * Uses existing design tokens for consistency
 */

/* ================================
   ENHANCED RESPONSIVE UTILITIES
   ================================ */

/* Enhanced container with fluid padding */
.container {
  max-width: min(1200px, 92vw);
  margin: 0 auto;
  padding-inline: clamp(1rem, 4vw, 2rem);
}

/* Responsive container variations */
.container-sm { max-width: min(640px, 92vw); }
.container-md { max-width: min(768px, 92vw); }
.container-lg { max-width: min(1024px, 92vw); }
.container-xl { max-width: min(1280px, 92vw); }

/* ================================
   ENHANCED GRID SYSTEM
   ================================ */

/* More granular responsive grids */
.grid-cols-1 { grid-template-columns: 1fr; }
.grid-cols-2 { grid-template-columns: 1fr; }
.grid-cols-3 { grid-template-columns: 1fr; }
.grid-cols-4 { grid-template-columns: 1fr; }

/* Small devices (≥480px) */
@media (min-width: 480px) {
  .grid-cols-2 { grid-template-columns: repeat(2, 1fr); }
}

/* Medium devices (≥768px) */
@media (min-width: 768px) {
  .grid-cols-3 { grid-template-columns: repeat(2, 1fr); }
  .grid-cols-4 { grid-template-columns: repeat(2, 1fr); }
}

/* Large devices (≥1024px) */
@media (min-width: 1024px) {
  .grid-cols-3 { grid-template-columns: repeat(3, 1fr); }
  .grid-cols-4 { grid-template-columns: repeat(3, 1fr); }
}

/* Extra large devices (≥1280px) */
@media (min-width: 1280px) {
  .grid-cols-4 { grid-template-columns: repeat(4, 1fr); }
}

/* Responsive grid gaps */
.gap-responsive {
  gap: clamp(1rem, 3vw, 2rem);
}

/* ================================
   ENHANCED NAVIGATION
   ================================ */

/* Hide navigation links on mobile by default */
@media (max-width: 767px) {
  .nav {
    padding: 1rem 0;
  }
  
  .nav-links {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    background: rgba(14, 20, 38, 0.98);
    backdrop-filter: blur(20px);
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 2rem;
    transform: translateX(-100%);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1000;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    /* Ensure the menu breaks out of any container constraints */
    margin: 0;
    padding: 2rem;
    box-sizing: border-box;
    /* Ensure visibility */
    list-style: none;
  }
  
  .nav-links.show {
    display: flex;
    transform: translateX(0);
    opacity: 1;
  }
  
  .nav-link {
    font-size: 1.25rem;
    padding: 1rem 2rem;
    border-radius: 12px;
    min-height: 44px;
    min-width: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: #ffffff !important;
    text-decoration: none;
    transition: all 0.2s ease;
    /* Ensure proper spacing and layout */
    width: auto;
    max-width: 280px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
  }
  
  .nav-link:hover {
    background: rgba(99, 91, 255, 0.2) !important;
    color: #ffffff !important;
    transform: translateY(-2px);
    border-color: rgba(99, 91, 255, 0.4);
  }
  
  /* Ensure list items are visible */
  .nav-links li {
    list-style: none;
    margin: 0;
    padding: 0;
  }
  
  .mobile-menu-button {
    display: flex;
    padding: 0.75rem;
    border-radius: 12px;
    z-index: 1001;
    position: relative;
    min-width: 44px;
    min-height: 44px;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
    background: rgba(255,255,255,0.04);
    border: 1px solid var(--border);
    color: var(--text);
  }
  
  .mobile-menu-button:focus {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
  }
  
  .mobile-menu-button:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
  }
}

/* Mobile navigation overlay */
.mobile-nav-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh;
  background: rgba(0, 0, 0, 0.5);
  z-index: 999;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  touch-action: none;
}

.mobile-nav-overlay.show {
  opacity: 1;
  visibility: visible;
}

/* Enhanced focus states for mobile */
@media (hover: none) and (pointer: coarse) {
  .btn:focus,
  .nav-link:focus,
  .mobile-menu-button:focus,
  .theme-option:focus,
  input:focus,
  textarea:focus,
  select:focus {
    outline: 3px solid var(--color-primary);
    outline-offset: 2px;
  }
}

/* ================================
   RESPONSIVE BUTTONS & FORMS
   ================================ */

/* Enhanced button touch targets */
.btn {
  min-height: 44px;
  min-width: 44px;
  padding: clamp(0.75rem, 2vw, 1rem) clamp(1rem, 3vw, 1.5rem);
}

.btn-sm {
  min-height: 40px;
  padding: clamp(0.5rem, 1.5vw, 0.75rem) clamp(0.75rem, 2vw, 1rem);
}

.btn-lg {
  min-height: 48px;
  padding: clamp(1rem, 2.5vw, 1.25rem) clamp(1.5rem, 4vw, 2rem);
}

/* Responsive form layouts */
.form-grid-2 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

@media (min-width: 640px) {
  .form-grid-2 {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Enhanced form inputs */
input, textarea, select {
  min-height: 44px;
  width: 100%;
  font-size: max(16px, 1rem); /* Prevent zoom on iOS */
}

/* ================================
   RESPONSIVE SECTIONS & SPACING
   ================================ */

/* Fluid section padding */
.section {
  padding: clamp(3rem, 8vw, 4.5rem) 0;
}

.section-sm {
  padding: clamp(2rem, 5vw, 3rem) 0;
}

/* Hero responsive padding */
.hero {
  padding: clamp(4rem, 12vw, 7.5rem) 0 clamp(2rem, 6vw, 5rem);
}

/* ================================
   RESPONSIVE TYPOGRAPHY
   ================================ */

/* Ensure readable line lengths */
.text-content {
  max-width: 65ch;
}

.text-content-wide {
  max-width: 75ch;
}

/* Responsive heading adjustments */
@media (max-width: 767px) {
  h1 {
    font-size: clamp(2rem, 8vw, 2.5rem);
    line-height: 1.2;
  }
  
  h2 {
    font-size: clamp(1.75rem, 6vw, 2rem);
    line-height: 1.3;
  }
  
  h3 {
    font-size: clamp(1.5rem, 5vw, 1.75rem);
    line-height: 1.4;
  }
}

/* ================================
   RESPONSIVE CARDS & COMPONENTS
   ================================ */

/* Enhanced responsive cards */
.card {
  padding: clamp(1rem, 4vw, 1.5rem);
}

.card-padding-lg {
  padding: clamp(1.5rem, 5vw, 2.5rem);
}

/* Stats cards responsive layout */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

@media (min-width: 480px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 768px) {
  .stats-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* ================================
   RESPONSIVE UTILITIES
   ================================ */

/* Hide/show at different breakpoints */
.hidden-mobile {
  display: none;
}

@media (min-width: 768px) {
  .hidden-mobile {
    display: initial;
  }
  
  .hidden-desktop {
    display: none;
  }
}

/* Responsive text alignment */
.text-center-mobile {
  text-align: center;
}

@media (min-width: 768px) {
  .text-center-mobile {
    text-align: initial;
  }
}

/* Responsive flex direction */
.flex-col-mobile {
  flex-direction: column;
}

@media (min-width: 768px) {
  .flex-col-mobile {
    flex-direction: row;
  }
}

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

/* Responsive images */
img {
  max-width: 100%;
  height: auto;
}

/* Responsive video embeds */
.video-responsive {
  position: relative;
  padding-bottom: 56.25%; /* 16:9 aspect ratio */
  height: 0;
  overflow: hidden;
}

.video-responsive iframe,
.video-responsive video {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

/* ================================
   OVERFLOW PREVENTION
   ================================ */

/* Prevent horizontal scroll */
* {
  box-sizing: border-box;
}

html, body {
  overflow-x: hidden;
  max-width: 100vw;
  position: relative;
}

/* Word breaking for long content */
.break-words {
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* Ensure all major containers don't overflow */
.container,
.section,
.hero,
.card,
.platform-layout,
.platform-main,
.platform-content {
  max-width: 100%;
  overflow-x: hidden;
}

/* ================================
   RESPONSIVE TABLES
   ================================ */

/* Responsive table wrapper */
.table-responsive {
  overflow-x: auto;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.table-responsive table {
  min-width: 600px;
  width: 100%;
}

/* Mobile-first table alternative (stacked cards) */
@media (max-width: 767px) {
  .table-mobile-cards {
    display: block;
  }
  
  .table-mobile-cards thead {
    display: none;
  }
  
  .table-mobile-cards tbody,
  .table-mobile-cards tr,
  .table-mobile-cards td {
    display: block;
    width: 100%;
  }
  
  .table-mobile-cards tr {
    background: var(--surface-elevated);
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-bottom: 1rem;
    padding: 1rem;
  }
  
  .table-mobile-cards td {
    padding: 0.5rem 0;
    border: none;
  }
  
  .table-mobile-cards td::before {
    content: attr(data-label) ": ";
    font-weight: 600;
    color: var(--text-muted);
  }
}

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

/* Respect user motion preferences */
@media (prefers-reduced-motion: reduce) {
  .nav-links {
    transition: none;
  }
  
  .mobile-menu-button,
  .btn {
    transition: none;
  }
}

/* ================================
   MOBILE VIEWPORT OPTIMIZATIONS
   ================================ */

/* Ensure proper viewport behavior on mobile */
@media (max-width: 767px) {
  /* Fix viewport width */
  html {
    width: 100vw;
    overflow-x: hidden;
  }
  
  /* Ensure main content areas are properly constrained */
  .hero,
  .section,
  .footer {
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
  }
  
  /* Fix potential overflow from padding */
  .container {
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
  }
  
  /* Ensure cards don't cause overflow */
  .card,
  .card-premium {
    max-width: 100%;
    word-wrap: break-word;
    overflow-wrap: break-word;
  }
  
  /* Fix table overflow on mobile */
  .table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  
  /* Ensure buttons scale properly */
  .btn-full-width {
    width: 100%;
  }
  
  /* Fix potential grid overflow */
  .grid {
    width: 100%;
    max-width: 100%;
  }
  
  /* Platform specific fixes */
  .platform-layout {
    width: 100%;
    max-width: 100vw;
  }
  
  .platform-content {
    width: 100%;
    max-width: 100%;
    /* padding: var(--space-4, 1rem); */
  }
}