/* ============================================================
   MOBILE FIXES - COMPREHENSIVE RESPONSIVE OVERRIDES
   Fixes overlapping, overflow, and layout issues on mobile/tablet
   ============================================================ */

/* ============================================================
   GLOBAL MOBILE FIXES
   ============================================================ */

* {
  box-sizing: border-box;
}

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

body {
  overflow-x: hidden;
  width: 100%;
  position: relative;
}

@media (max-width: 768px) {
  /* Prevent horizontal scroll on mobile */
  body, html {
    max-width: 100vw;
    overflow-x: hidden;
  }

  /* Force all containers to stay within viewport */
  .container,
  .max-w-7xl,
  .max-w-6xl,
  .max-w-5xl,
  .max-w-4xl {
    max-width: 100% !important;
    padding-left: 1rem !important;
    padding-right: 1rem !important;
    overflow-x: hidden;
  }

  /* Fix any absolute positioning that causes overflow */
  .absolute {
    max-width: calc(100vw - 2rem);
  }
}

/* ============================================================
   HERO SECTION - FIX OVERLAPPING TEXT
   ============================================================ */

@media (max-width: 768px) {
  .hero-modern {
    padding-top: 6rem !important;
    padding-bottom: 3rem !important;
    padding-left: 1rem !important;
    padding-right: 1rem !important;
  }

  .hero-title {
    font-size: 1.75rem !important;
    line-height: 1.2 !important;
    margin-bottom: 1rem !important;
  }

  .hero-subtitle {
    font-size: 1rem !important;
    line-height: 1.5 !important;
    margin-bottom: 2rem !important;
    padding: 0 0.5rem;
  }

  .cta-button {
    width: 100% !important;
    max-width: 100% !important;
    padding: 1rem 1.5rem !important;
    font-size: 1rem !important;
  }
}

/* ============================================================
   NAVIGATION - FIX MOBILE HEADER
   ============================================================ */

@media (max-width: 768px) {
  .header-sticky {
    width: 100% !important;
    left: 0 !important;
    right: 0 !important;
    top: 0 !important;
    margin: 0 !important;
    border-radius: 0 !important;
  }

  .header-nav {
    padding: 0.75rem 1rem !important;
    min-height: 3.5rem !important;
  }

  .header-logo {
    font-size: 1rem !important;
  }

  /* Hide desktop navigation */
  .hidden.md\\:flex {
    display: none !important;
  }

  /* Mobile menu dropdown fix */
  .md\\:hidden [x-data] > div[x-show] {
    position: fixed !important;
    right: 0.5rem !important;
    top: 4rem !important;
    max-width: calc(100vw - 1rem) !important;
    width: 90vw !important;
    z-index: 9999 !important;
  }
}

/* ============================================================
   PRICING CARDS - FIX LAYOUT
   ============================================================ */

@media (max-width: 768px) {
  /* Force single column on mobile */
  .grid.md\\:grid-cols-2 {
    grid-template-columns: 1fr !important;
    gap: 1.5rem !important;
  }

  .grid.md\\:grid-cols-3 {
    grid-template-columns: 1fr !important;
    gap: 1.5rem !important;
  }

  .grid.md\\:grid-cols-4 {
    grid-template-columns: 1fr !important;
    gap: 1rem !important;
  }

  /* Pricing card specific fixes */
  .grid.md\\:grid-cols-2.gap-8 {
    gap: 1.5rem !important;
  }

  /* Make pricing cards stack nicely */
  .bg-white.rounded-xl.shadow-lg {
    padding: 1.5rem !important;
    margin-bottom: 1rem;
  }

  /* Price display */
  .flex.items-baseline {
    flex-wrap: wrap;
    justify-content: center;
  }

  .text-4xl,
  .text-5xl {
    font-size: 2rem !important;
  }

  .text-3xl {
    font-size: 1.5rem !important;
  }
}

/* ============================================================
   BUTTONS - FIX OVERFLOW AND SPACING
   ============================================================ */

@media (max-width: 768px) {
  /* Stack buttons vertically on mobile */
  .flex.space-x-3,
  .flex.space-x-4,
  .flex.gap-3,
  .flex.gap-4 {
    flex-direction: column !important;
    gap: 0.75rem !important;
  }

  .flex.space-x-3 > *,
  .flex.space-x-4 > *,
  .flex.gap-3 > *,
  .flex.gap-4 > * {
    margin-left: 0 !important;
    margin-right: 0 !important;
    width: 100% !important;
  }

  /* Button sizing */
  button,
  .btn,
  a.btn,
  input[type="button"],
  input[type="submit"] {
    min-height: 44px !important;
    padding: 0.75rem 1rem !important;
    font-size: 1rem !important;
    width: 100%;
    text-align: center;
  }

  /* Small buttons */
  .text-sm.px-3,
  .text-sm.px-4 {
    font-size: 0.875rem !important;
    padding: 0.5rem 0.75rem !important;
  }
}

/* ============================================================
   FORMS - FIX INPUT FIELDS
   ============================================================ */

@media (max-width: 768px) {
  /* Form groups stack vertically */
  form .flex,
  form .grid {
    flex-direction: column !important;
    grid-template-columns: 1fr !important;
  }

  /* Input fields */
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="url"],
  input[type="tel"],
  textarea,
  select {
    width: 100% !important;
    max-width: 100% !important;
    font-size: 16px !important; /* Prevents iOS zoom */
    padding: 0.75rem !important;
    margin-bottom: 0.75rem;
  }

  /* File upload */
  input[type="file"] {
    width: 100% !important;
    padding: 0.75rem !important;
  }

  /* Select dropdowns */
  select {
    min-height: 44px !important;
  }

  /* Label spacing */
  label {
    margin-bottom: 0.5rem;
    display: block;
  }
}

/* ============================================================
   DASHBOARD - FIX PROJECT CARDS
   ============================================================ */

@media (max-width: 768px) {
  /* Project grid */
  .grid.grid-cols-1.md\\:grid-cols-3 {
    grid-template-columns: 1fr !important;
    gap: 1rem !important;
  }

  /* Project card actions */
  .flex.gap-2 {
    flex-wrap: wrap;
    gap: 0.5rem !important;
  }

  .flex.gap-2 > button,
  .flex.gap-2 > a {
    flex: 1 1 calc(50% - 0.25rem);
    min-width: 0;
    font-size: 0.75rem;
    padding: 0.5rem 0.75rem !important;
  }

  /* Stats cards */
  .grid-cols-4 {
    grid-template-columns: repeat(2, 1fr) !important;
  }
}

/* ============================================================
   MODALS - FULL SCREEN ON MOBILE
   ============================================================ */

@media (max-width: 768px) {
  /* Modal backdrop */
  div[style*="position: fixed"],
  .fixed.inset-0 {
    padding: 0 !important;
  }

  /* Modal content */
  .relative.bg-white.rounded-lg,
  .bg-white.rounded-xl.shadow-xl {
    width: 100vw !important;
    max-width: 100vw !important;
    height: auto !important;
    min-height: 100vh !important;
    margin: 0 !important;
    border-radius: 0 !important;
    overflow-y: auto;
  }

  /* Modal padding */
  .relative.bg-white.rounded-lg > div,
  .relative.bg-white.rounded-lg .p-6 {
    padding: 1.5rem !important;
  }

  /* Modal close button */
  .absolute.top-4.right-4 {
    top: 1rem !important;
    right: 1rem !important;
  }
}

/* ============================================================
   UPLOAD SECTION - FIX FILE DROP ZONE
   ============================================================ */

@media (max-width: 768px) {
  /* Upload area */
  .border-2.border-dashed {
    padding: 1.5rem !important;
    min-height: auto !important;
  }

  /* Drop zone text */
  .border-2.border-dashed p {
    font-size: 0.875rem !important;
  }

  /* Template selection */
  .grid.grid-cols-1.md\\:grid-cols-3.gap-4 {
    grid-template-columns: 1fr !important;
    gap: 0.75rem !important;
  }

  /* Template buttons */
  button[class*="border-2"] {
    padding: 0.75rem !important;
    font-size: 0.875rem !important;
  }

  /* Template badge */
  .bg-purple-200,
  .bg-purple-100 {
    font-size: 0.625rem !important;
    padding: 0.125rem 0.375rem !important;
  }
}

/* ============================================================
   FOOTER - FIX LAYOUT
   ============================================================ */

@media (max-width: 768px) {
  footer {
    padding: 2rem 1rem !important;
    margin-top: 3rem !important;
  }

  footer .grid {
    grid-template-columns: 1fr !important;
    gap: 2rem !important;
    text-align: center;
  }

  footer .space-y-2 {
    margin-top: 1rem;
  }

  footer a {
    font-size: 0.875rem;
  }

  /* Footer links */
  footer .flex.items-center {
    justify-content: center !important;
  }
}

/* ============================================================
   TABLE - RESPONSIVE OVERFLOW
   ============================================================ */

@media (max-width: 768px) {
  /* Wrap tables in scrollable container */
  table {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  thead,
  tbody,
  tr {
    display: table;
    width: 100%;
  }

  th,
  td {
    font-size: 0.75rem !important;
    padding: 0.5rem !important;
  }

  /* API Keys table */
  .font-mono.text-xs {
    font-size: 0.625rem !important;
    word-break: break-all;
  }
}

/* ============================================================
   ANALYTICS - FIX CHARTS AND STATS
   ============================================================ */

@media (max-width: 768px) {
  /* Chart containers */
  canvas {
    max-width: 100% !important;
    height: auto !important;
  }

  /* Stat cards */
  .text-2xl.font-bold {
    font-size: 1.25rem !important;
  }

  .text-sm.text-gray-600 {
    font-size: 0.75rem !important;
  }

  /* Icon containers */
  .p-3.rounded-full {
    padding: 0.5rem !important;
  }

  .w-6.h-6 {
    width: 1rem !important;
    height: 1rem !important;
  }
}

/* ============================================================
   API KEYS PAGE - FIX LAYOUT
   ============================================================ */

@media (max-width: 768px) {
  /* API key display */
  .bg-gray-50.rounded-lg.p-4 {
    padding: 0.75rem !important;
    overflow-x: auto;
  }

  /* API key text */
  .font-mono {
    font-size: 0.625rem !important;
    word-break: break-all;
  }

  /* Copy button */
  .absolute.right-2 {
    position: static !important;
    margin-top: 0.5rem;
    width: 100%;
  }
}

/* ============================================================
   TEXT OVERFLOW FIXES
   ============================================================ */

@media (max-width: 768px) {
  /* Prevent text overflow */
  h1, h2, h3, h4, h5, h6 {
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
  }

  p, span, div {
    word-wrap: break-word;
    overflow-wrap: break-word;
  }

  /* Truncate long text */
  .truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
  }

  /* Line clamp */
  .line-clamp-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .line-clamp-3 {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
}

/* ============================================================
   SPACING FIXES - PREVENT OVERLAP
   ============================================================ */

@media (max-width: 768px) {
  /* Section spacing */
  section {
    padding-left: 1rem !important;
    padding-right: 1rem !important;
    padding-top: 2rem !important;
    padding-bottom: 2rem !important;
  }

  /* Reduce massive padding */
  .p-20 {
    padding: 2rem !important;
  }

  .p-16 {
    padding: 1.5rem !important;
  }

  .p-12 {
    padding: 1.25rem !important;
  }

  .py-20 {
    padding-top: 2rem !important;
    padding-bottom: 2rem !important;
  }

  .py-16 {
    padding-top: 1.5rem !important;
    padding-bottom: 1.5rem !important;
  }

  .py-12 {
    padding-top: 1.25rem !important;
    padding-bottom: 1.25rem !important;
  }

  /* Reduce massive margins */
  .my-20 {
    margin-top: 2rem !important;
    margin-bottom: 2rem !important;
  }

  .my-16 {
    margin-top: 1.5rem !important;
    margin-bottom: 1.5rem !important;
  }

  .mb-12 {
    margin-bottom: 1.25rem !important;
  }

  .mt-12 {
    margin-top: 1.25rem !important;
  }
}

/* ============================================================
   TABLET SPECIFIC FIXES (768px - 1024px)
   ============================================================ */

@media (min-width: 768px) and (max-width: 1024px) {
  .max-w-7xl {
    padding-left: 2rem !important;
    padding-right: 2rem !important;
  }

  /* 2 column layout on tablet */
  .grid.md\\:grid-cols-3,
  .grid.md\\:grid-cols-4 {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* Buttons side by side on tablet */
  .flex.space-x-3,
  .flex.gap-3 {
    flex-direction: row !important;
  }

  .flex.space-x-3 > *,
  .flex.gap-3 > * {
    width: auto !important;
  }
}

/* ============================================================
   VERY SMALL DEVICES (< 375px)
   ============================================================ */

@media (max-width: 375px) {
  .header-logo span {
    font-size: 0.875rem !important;
  }

  .p-6 {
    padding: 0.75rem !important;
  }

  .p-4 {
    padding: 0.5rem !important;
  }

  button, .btn {
    font-size: 0.875rem !important;
    padding: 0.625rem 0.75rem !important;
  }

  h1 {
    font-size: 1.5rem !important;
  }

  h2 {
    font-size: 1.25rem !important;
  }

  h3 {
    font-size: 1.125rem !important;
  }
}

/* ============================================================
   LANDSCAPE MODE FIXES
   ============================================================ */

@media (max-width: 768px) and (orientation: landscape) {
  .hero-modern {
    padding-top: 4rem !important;
    padding-bottom: 2rem !important;
  }

  .header-sticky {
    top: 0 !important;
  }

  .header-nav {
    min-height: 3rem !important;
  }
}

/* ============================================================
   TOUCH DEVICE OPTIMIZATIONS
   ============================================================ */

@media (hover: none) and (pointer: coarse) {
  /* Larger touch targets */
  button,
  a,
  input[type="button"],
  input[type="submit"],
  select {
    min-height: 44px !important;
    min-width: 44px !important;
  }

  /* Remove hover states, add active states */
  .hover\\:bg-gray-50:hover {
    background-color: transparent;
  }

  .hover\\:bg-gray-50:active {
    background-color: #F9FAFB;
  }

  /* Card tap feedback */
  .card:active,
  .bg-white.rounded-xl:active {
    transform: scale(0.98);
    transition: transform 0.1s;
  }
}

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

@media (max-width: 768px) {
  /* Focus states */
  button:focus,
  a:focus,
  input:focus,
  select:focus,
  textarea:focus {
    outline: 2px solid #3B82F6;
    outline-offset: 2px;
  }

  /* Skip to content link */
  .sr-only:focus {
    position: static;
    width: auto;
    height: auto;
    padding: 1rem;
    margin: 0;
    overflow: visible;
    clip: auto;
    white-space: normal;
  }
}
