/* Phase 4 Mobile-First Audit Fixes - 2026-03-05 */
/* Comprehensive responsive fixes for ALL pages */

/* ============================================
   1. RESPONSIVE LAYOUT - BASE FIXES
   ============================================ */

/* Prevent horizontal scroll at all breakpoints */
* {
  max-width: 100%;
  box-sizing: border-box;
}

html, body {
  overflow-x: hidden;
  width: 100%;
}

/* Ensure images and media scale correctly */
img, video, iframe {
  max-width: 100%;
  height: auto;
}

/* ============================================
   2. TOUCH TARGETS - 44×44px MINIMUM
   ============================================ */

/* All interactive elements */
button,
a,
input[type="submit"],
input[type="button"],
select,
.btn,
.button,
.card-button {
  min-height: 44px;
  min-width: 44px;
  padding: 12px 24px;
  cursor: pointer;
}

/* Icon-only buttons need extra padding wrapper */
.icon-button,
button.icon-only {
  min-width: 44px;
  min-height: 44px;
  padding: 12px;
}

/* Table action buttons */
table button,
table a.button {
  min-height: 44px;
  padding: 10px 16px;
}

/* Navigation links */
nav a,
.nav-link {
  min-height: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  padding: 12px 16px;
  box-sizing: border-box;
}

/* ============================================
   3. FORM USABILITY - MOBILE OPTIMIZATION
   ============================================ */

/* Prevent zoom on iOS - 16px minimum */
input,
select,
textarea {
  font-size: 16px !important;
  min-height: 44px;
  padding: 12px 16px;
  border-radius: 8px;
}

/* Labels must be clearly associated */
label {
  display: block;
  margin-bottom: 8px;
  font-size: 14px;
  font-weight: 500;
}

/* Spacing between form fields */
.form-group,
.form-field {
  margin-bottom: 24px;
}

/* ============================================
   4. MOBILE BREAKPOINT - 375px (iPhone SE)
   ============================================ */

@media (max-width: 375px) {
  /* Reduce padding on mobile */
  .container,
  .page-container {
    padding-left: 16px;
    padding-right: 16px;
  }
  
  /* Stack cards */
  .card-grid,
  .grid {
    grid-template-columns: 1fr !important;
    gap: 16px;
  }
  
  /* Full-width buttons on mobile */
  .btn-primary,
  .btn-secondary,
  button:not(.icon-button) {
    width: 100%;
    justify-content: center;
  }
  
  /* Typography adjustments */
  h1 { font-size: 28px; line-height: 1.2; }
  h2 { font-size: 24px; line-height: 1.3; }
  h3 { font-size: 20px; line-height: 1.4; }
  
  /* Tables - force scroll container */
  table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }
}

/* ============================================
   5. TABLET BREAKPOINT - 768px (iPad)
   ============================================ */

@media (min-width: 768px) and (max-width: 1023px) {
  .container {
    padding-left: 24px;
    padding-right: 24px;
  }
  
  /* 2-column grid for cards */
  .card-grid,
  .grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 24px;
  }
}

/* ============================================
   6. DESKTOP BREAKPOINT - 1024px+
   ============================================ */

@media (min-width: 1024px) {
  .container {
    max-width: 1200px;
    margin: 0 auto;
    padding-left: 32px;
    padding-right: 32px;
  }
  
  /* 3-column grid for cards */
  .card-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 32px;
  }
}

/* ============================================
   7. PORTAL - BOTTOM NAVIGATION (MOBILE ONLY)
   ============================================ */

/* Show bottom nav on mobile for portal pages */
@media (max-width: 767px) {
  /* Hide desktop sidebar on mobile */
  .portal-sidebar,
  .sidebar {
    display: none !important;
  }
  
  /* Bottom navigation bar */
  .mobile-bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 72px;
    background: #ffffff;
    border-top: 1px solid #e5e7eb;
    display: flex;
    justify-content: space-around;
    align-items: center;
    z-index: 999;
    box-shadow: 0 -2px 8px rgba(0,0,0,0.1);
  }
  
  .mobile-bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    min-height: 72px;
    padding: 8px;
    text-decoration: none;
    color: #64748b;
    transition: color 0.2s;
  }
  
  .mobile-bottom-nav-item:hover,
  .mobile-bottom-nav-item.active {
    color: #2AA198;
  }
  
  .mobile-bottom-nav-icon {
    font-size: 24px;
    margin-bottom: 4px;
  }
  
  .mobile-bottom-nav-label {
    font-size: 12px;
    font-weight: 500;
  }
  
  /* Add padding to page content to account for bottom nav */
  body.portal-page {
    padding-bottom: 88px;
  }
}

/* Desktop - show sidebar, hide bottom nav */
@media (min-width: 768px) {
  .mobile-bottom-nav {
    display: none !important;
  }
}

/* ============================================
   8. HORIZONTAL SCROLL FIXES
   ============================================ */

/* Tables must scroll horizontally, not overflow */
.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 24px;
}

.table-wrapper table {
  min-width: 600px; /* Ensure minimum width for table */
}

/* Long URLs in content */
.content-text,
.article-body {
  word-wrap: break-word;
  overflow-wrap: break-word;
  word-break: break-word;
}

/* Code blocks */
pre, code {
  max-width: 100%;
  overflow-x: auto;
  word-wrap: normal;
}

/* ============================================
   9. CALCULATOR MOBILE UX
   ============================================ */

@media (max-width: 767px) {
  /* Calculator inputs in vertical layout */
  .calculator-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
  }
  
  .calculator-row {
    display: flex;
    flex-direction: column;
    gap: 16px;
  }
  
  /* Results section as bottom sheet style */
  .calculator-results {
    position: sticky;
    bottom: 88px; /* Above bottom nav */
    background: #ffffff;
    padding: 24px;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -4px 12px rgba(0,0,0,0.1);
  }
}

/* ============================================
   10. ANIMATION PERFORMANCE & ACCESSIBILITY
   ============================================ */

/* All animations max 0.5s */
* {
  transition-duration: 0.3s !important;
  max-transition-duration: 0.5s;
}

/* Respect prefers-reduced-motion */
@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;
  }
}

/* ============================================
   11. MOBILE NAVIGATION FIXES
   ============================================ */

@media (max-width: 767px) {
  /* Mobile menu spacing */
  .mobile-menu {
    padding: 16px;
  }
  
  .mobile-menu-item {
    padding: 16px;
    min-height: 56px;
    display: flex;
    align-items: center;
  }
  
  /* Hamburger must be 44×44px */
  .hamburger,
  .mobile-hamburger {
    min-width: 44px;
    min-height: 44px;
    padding: 10px;
  }
}

/* ============================================
   12. SPACING FIXES - 8px GRID
   ============================================ */

/* Section spacing */
section,
.section {
  padding: 48px 16px;
}

@media (min-width: 768px) {
  section,
  .section {
    padding: 64px 24px;
  }
}

@media (min-width: 1024px) {
  section,
  .section {
    padding: 80px 32px;
  }
}

/* Card spacing */
.card {
  padding: 16px;
  margin-bottom: 16px;
}

@media (min-width: 768px) {
  .card {
    padding: 24px;
    margin-bottom: 24px;
  }
}

/* ============================================
   13. FOCUS STATES - ACCESSIBILITY
   ============================================ */

/* Ensure all focusable elements have visible focus */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid #2AA198;
  outline-offset: 2px;
  border-radius: 4px;
}

/* ============================================
   14. BLOG POST RESPONSIVE
   ============================================ */

@media (max-width: 767px) {
  .blog-post-header {
    padding: 24px 16px;
  }
  
  .blog-post-content {
    padding: 16px;
    font-size: 16px;
    line-height: 1.6;
  }
  
  .blog-post-image {
    width: 100%;
    height: auto;
    margin-bottom: 24px;
  }
}

/* ============================================
   15. FOOTER RESPONSIVE
   ============================================ */

@media (max-width: 767px) {
  footer {
    padding: 32px 16px;
  }
  
  .footer-columns {
    display: flex;
    flex-direction: column;
    gap: 32px;
  }
  
  .footer-column {
    width: 100%;
  }
}

/* ============================================
   16. BLOG CATEGORY BADGES - PREVENT WRAPPING
   ============================================ */

/* Blog category badges — prevent wrapping */
.category-badge,
.blog-card-meta .category-badge,
span.category-badge {
  white-space: nowrap !important;
  flex-shrink: 0 !important;
  display: inline-block !important;
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
  box-sizing: border-box;
}
