/* =====================================================
   TCP - Universal Mobile Responsiveness
   Ensures compatibility with ALL phone resolutions
   Tested on: iPhone SE to Pro Max, Android, Foldables
   ===================================================== */

/* ==============================================
   VIEWPORT & SAFE AREAS
   ============================================== */

/* Viewport meta tag requirements (add to HTML):
   <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, user-scalable=yes"> */

/* Safe area support for iPhone notch and home indicator */
@supports (padding: max(0px)) {
  .modern-header,
  .fixed-header {
    padding-top: max(0px, env(safe-area-inset-top));
  }
  
  .bottom-nav,
  .fixed-bottom {
    padding-bottom: max(16px, env(safe-area-inset-bottom));
  }
  
  body {
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }
}

/* ==============================================
   BASE MOBILE STYLES (All Phones)
   ============================================== */

/* Prevent horizontal scroll and text size issues */
html {
  -webkit-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  overflow-x: hidden !important;
  width: 100vw !important;
  position: relative;
}

/* Prevent iOS tap highlight */
* {
  -webkit-tap-highlight-color: transparent;
}

/* Ensure all containers respect viewport */
.container,
.wrapper,
.content,
main,
section {
  max-width: 100% !important;
  overflow-x: hidden !important;
}

/* ==============================================
   ULTRA-SMALL PHONES (Galaxy Fold Closed: 280px)
   ============================================== */
@media (max-width: 320px) {
  /* Typography scaling */
  html {
    font-size: 14px !important;
  }
  
  body {
    font-size: 0.875rem !important;
    line-height: 1.5 !important;
  }
  
  h1 { font-size: 1.5rem !important; }
  h2 { font-size: 1.25rem !important; }
  h3 { font-size: 1.1rem !important; }
  h4 { font-size: 1rem !important; }
  
  /* Ultra-compact header */
  .modern-header {
    padding: 0.5rem !important;
  }
  
  .header-container {
    padding: 0 0.5rem !important;
    height: 56px !important;
  }
  
  /* Hide non-essential elements */
  .header-search {
    display: none !important;
  }
  
  /* Hide language selector except on home page */
  .header-language-select {
    display: none !important;
  }
  
  /* Show language selector on home page even on small screens */
  body.home-page .header-language-select {
    display: flex !important;
  }
  
  /* Simplified navigation */
  .header-nav {
    display: none !important;
  }
  
  .mobile-menu-btn {
    display: flex !important;
  }
  
  /* Form adjustments */
  input, select, textarea, button {
    width: 100% !important;
    min-height: 44px !important;
    font-size: 16px !important;
  }
  
  /* Single column everything */
  .grid,
  .flex-row,
  .columns {
    display: block !important;
  }
  
  /* Padding reductions */
  .card, .panel, .section {
    padding: 0.75rem !important;
    margin: 0.5rem !important;
  }
}

/* ==============================================
   SMALL PHONES (iPhone SE, Mini: 375px)
   ============================================== */
@media (max-width: 375px) {
  /* Typography */
  body {
    font-size: 15px !important;
  }
  
  h1 { font-size: 1.75rem !important; }
  h2 { font-size: 1.5rem !important; }
  h3 { font-size: 1.25rem !important; }
  
  /* Header adjustments */
  .header-container {
    height: 60px !important;
    padding: 0 0.75rem !important;
  }
  
  .header-brand span {
    font-size: 1.25rem !important;
  }
  
  /* Search bar responsive */
  .header-search {
    display: none !important;
  }
  
  .mobile-search {
    display: block !important;
    width: 100% !important;
    padding: 0.75rem !important;
  }
  
  /* Navigation */
  .header-nav {
    display: none !important;
  }
  
  /* Buttons and CTAs */
  .btn, .button, button {
    padding: 0.75rem 1rem !important;
    font-size: 0.95rem !important;
    min-height: 44px !important;
  }
  
  /* Cards and content */
  .card {
    padding: 1rem !important;
    margin-bottom: 1rem !important;
  }
}

/* ==============================================
   STANDARD PHONES (iPhone 12/13/14, Most Android: 390-414px)
   ============================================== */
@media (max-width: 414px) {
  /* Header optimization */
  .header-container {
    flex-wrap: wrap;
    height: auto !important;
    min-height: 64px;
  }
  
  .header-search {
    order: 3;
    width: 100%;
    margin-top: 0.5rem;
  }
  
  .header-search input {
    width: 100%;
    height: 40px;
  }
  
  /* Mobile menu always visible */
  .mobile-menu-btn {
    display: flex !important;
  }
  
  .header-nav {
    display: none !important;
  }
  
  /* Hero section mobile */
  .hero {
    padding: 2rem 1rem !important;
  }
  
  .hero-title {
    font-size: clamp(1.75rem, 5vw, 2.5rem) !important;
  }
  
  .hero-subtitle {
    font-size: clamp(1rem, 3vw, 1.25rem) !important;
  }
  
  /* Feature cards single column */
  .features-grid,
  .grid-3,
  .grid-4 {
    grid-template-columns: 1fr !important;
    gap: 1rem !important;
  }
  
  /* Forms full width */
  .form-group {
    margin-bottom: 1rem !important;
  }
  
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="search"],
  select,
  textarea {
    width: 100% !important;
    padding: 0.875rem !important;
    font-size: 16px !important; /* Prevents zoom on iOS */
    border-radius: 8px !important;
  }
  
  /* OAuth buttons stack */
  .oauth-buttons {
    flex-direction: column !important;
  }
  
  .oauth-button {
    width: 100% !important;
    margin-bottom: 0.75rem !important;
  }
  
  /* Search results mobile */
  .search-tabs {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    scrollbar-width: none !important;
  }
  
  .search-tab {
    white-space: nowrap !important;
    padding: 0.5rem 1rem !important;
  }
  
  .search-result-card {
    padding: 1rem !important;
  }
  
  /* Dashboard mobile */
  .dashboard-sidebar {
    position: fixed !important;
    left: -100% !important;
    top: 0 !important;
    width: 80% !important;
    max-width: 300px !important;
    height: 100vh !important;
    z-index: 999 !important;
    transition: left 0.3s ease !important;
  }
  
  .dashboard-sidebar.active {
    left: 0 !important;
  }
  
  .dashboard-content {
    margin-left: 0 !important;
    width: 100% !important;
  }
  
  /* Tables responsive */
  table {
    display: block !important;
    overflow-x: auto !important;
    white-space: nowrap !important;
  }
  
  /* Modal adjustments */
  .modal {
    width: 95% !important;
    margin: 1rem auto !important;
  }
  
  /* Footer mobile */
  .footer-columns {
    flex-direction: column !important;
  }
  
  .footer-column {
    margin-bottom: 2rem !important;
  }
}

/* ==============================================
   LARGE PHONES (Pro Max, Plus Models: 428-430px)
   ============================================== */
@media (max-width: 480px) {
  /* Similar to standard phones but with more breathing room */
  .container {
    padding: 0 1rem !important;
  }
  
  .hero {
    padding: 3rem 1.5rem !important;
  }
  
  /* Two column grid for larger phones */
  @media (min-width: 415px) {
    .grid-2-mobile {
      display: grid !important;
      grid-template-columns: repeat(2, 1fr) !important;
      gap: 1rem !important;
    }
  }
}

/* ==============================================
   PHABLETS & SMALL TABLETS (up to 768px)
   ============================================== */
@media (max-width: 768px) {
  /* Header adjustments */
  .header-container {
    padding: 0 1rem;
  }
  
  /* Show limited nav items */
  .header-nav {
    display: none;
  }
  
  @media (min-width: 600px) {
    .header-nav-mobile {
      display: flex;
      gap: 0.5rem;
    }
    
    .header-nav-mobile a {
      padding: 0.5rem 0.75rem;
      font-size: 0.9rem;
    }
  }
  
  /* Grid layouts */
  .grid-3 {
    grid-template-columns: repeat(2, 1fr) !important;
  }
  
  .grid-4 {
    grid-template-columns: repeat(2, 1fr) !important;
  }
  
  /* Maintain readability */
  .content-width {
    max-width: 100%;
    padding: 0 1.5rem;
  }
}

/* ==============================================
   TOUCH TARGETS & ACCESSIBILITY
   ============================================== */

/* Ensure all interactive elements meet minimum touch target size */
a,
button,
input,
select,
textarea,
.clickable,
.btn,
.link {
  min-height: 44px !important;
  min-width: 44px !important;
}

/* Spacing between interactive elements */
.btn + .btn,
.link + .link {
  margin-left: 8px !important;
}

/* ==============================================
   LANDSCAPE ORIENTATION
   ============================================== */
@media (orientation: landscape) and (max-height: 500px) {
  /* Reduce vertical spacing in landscape */
  .modern-header {
    position: relative !important;
  }
  
  .hero {
    min-height: auto !important;
    padding: 1rem !important;
  }
  
  /* Hide less important elements */
  .decorative,
  .hero-badge {
    display: none !important;
  }
}

/* ==============================================
   PERFORMANCE OPTIMIZATIONS
   ============================================== */

/* Reduce animations on mobile for better performance */
@media (max-width: 768px) {
  * {
    animation-duration: 0.2s !important;
    transition-duration: 0.2s !important;
  }
  
  /* Disable parallax on mobile */
  .parallax {
    background-attachment: scroll !important;
  }
  
  /* Simplify shadows */
  .card,
  .btn {
    box-shadow: 0 2px 4px rgba(0,0,0,0.1) !important;
  }
}

/* ==============================================
   SPECIFIC COMPONENT FIXES
   ============================================== */

/* Login/Signup Pages */
@media (max-width: 414px) {
  .login-container,
  .signup-container {
    padding: 1rem !important;
    min-height: 100vh !important;
  }
  
  .login-card,
  .signup-card {
    width: 100% !important;
    margin: 0 !important;
    border-radius: 1rem !important;
    padding: 1.5rem !important;
  }
  
  .logo-section {
    margin-bottom: 1.5rem !important;
  }
  
  .logo {
    font-size: 1.5rem !important;
  }
}

/* Search Results Page */
@media (max-width: 414px) {
  .search-container {
    padding: 0.5rem !important;
  }
  
  .search-header {
    padding: 1rem !important;
    border-radius: 0.75rem !important;
  }
  
  .search-input {
    font-size: 16px !important;
    padding: 0.75rem 2.5rem !important;
  }
  
  .search-result-card {
    border-radius: 0.75rem !important;
  }
  
  .result-title {
    font-size: 1.1rem !important;
  }
}

/* Translator Page */
@media (max-width: 414px) {
  .translator-container {
    padding: 0.5rem !important;
  }
  
  .translation-box {
    padding: 1rem !important;
    margin-bottom: 1rem !important;
  }
  
  .voice-button {
    width: 60px !important;
    height: 60px !important;
  }
  
  .language-selector {
    width: 100% !important;
  }
}

/* Dashboard */
@media (max-width: 414px) {
  .dashboard-grid {
    grid-template-columns: 1fr !important;
  }
  
  .dashboard-card {
    padding: 1rem !important;
  }
  
  .stats-number {
    font-size: 1.5rem !important;
  }
}

/* ==============================================
   UTILITIES FOR MOBILE
   ============================================== */

/* Hide on mobile */
@media (max-width: 768px) {
  .desktop-only,
  .hide-mobile {
    display: none !important;
  }
}

/* Show on mobile only */
.mobile-only,
.show-mobile {
  display: none !important;
}

@media (max-width: 768px) {
  .mobile-only,
  .show-mobile {
    display: block !important;
  }
  
  .mobile-only-flex {
    display: flex !important;
  }
}

/* Text alignment on mobile */
@media (max-width: 414px) {
  .text-center-mobile {
    text-align: center !important;
  }
  
  .text-left-mobile {
    text-align: left !important;
  }
}

/* Spacing utilities for mobile */
@media (max-width: 414px) {
  .p-mobile-1 { padding: 0.5rem !important; }
  .p-mobile-2 { padding: 1rem !important; }
  .p-mobile-3 { padding: 1.5rem !important; }
  
  .m-mobile-0 { margin: 0 !important; }
  .m-mobile-1 { margin: 0.5rem !important; }
  .m-mobile-2 { margin: 1rem !important; }
}