/* ==========================================================================
   INTELLIBRIDGE AI - COMPREHENSIVE RESPONSIVE STYLESHEET
   Mobile First & Progressive Enhancement for All Devices & Screen Sizes
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. GLOBAL MOBILE DEFENSIVE STYLES & OVERFLOW PREVENTION
   -------------------------------------------------------------------------- */
html, body {
  overflow-x: hidden;
  max-width: 100vw;
  -webkit-text-size-adjust: 100%;
}

*, *::before, *::after {
  box-sizing: border-box;
}

img, picture, video, canvas, svg, iframe {
  max-width: 100%;
}

/* Ensure flex & grid items don't blow out containers */
.hero-content,
.hero-visual,
.hero-media,
.card,
.feature-box,
.stat-item,
.consultation-wrapper > div {
  min-width: 0;
}

/* Safe area for modern notched devices */
:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

/* --------------------------------------------------------------------------
   2. DESKTOP VIEWPORT SAFEGUARDS (min-width: 1025px)
   -------------------------------------------------------------------------- */
@media (min-width: 1025px) {
  .mobile-drawer,
  .mobile-drawer-overlay,
  .hamburger-btn {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
  }
}

/* --------------------------------------------------------------------------
   2b. LAPTOP & MID-SIZED DESKTOP BREAKPOINTS (1025px - 1366px)
   -------------------------------------------------------------------------- */
/* Standard & Compact Laptops (1025px to 1200px) */
@media (min-width: 1025px) and (max-width: 1200px) {
  .header-inner {
    gap: 0.75rem;
  }

  .brand-logo img {
    height: 32px;
    max-width: 145px;
  }

  .desktop-nav {
    gap: 0.15rem;
  }

  .nav-link {
    padding-inline: 0.4rem;
    font-size: 0.85rem;
    gap: 0.2rem;
  }

  .nav-link svg {
    width: 12px;
    height: 12px;
  }

  /* Compact header buttons: hide secondary button on compact laptop screens (present in top utility bar) */
  .header-actions {
    gap: 0.5rem;
  }

  .header-actions .btn-secondary {
    display: none;
  }

  .header-actions .btn-primary {
    padding: 0 16px;
    font-size: 0.875rem;
    height: 42px;
    min-height: 42px;
  }

  /* Mega menu edge alignment: items 4-8 expand inwards from the right to avoid edge collision */
  .nav-item:nth-child(n+4) .mega-menu {
    left: auto;
    right: 0;
  }

  .mega-menu {
    max-width: calc(100vw - 48px);
    padding: 1.5rem;
  }

  /* Footer grid: 4 columns prevents title wrapping on laptop screens */
  .footer-grid {
    grid-template-columns: repeat(4, 1fr) !important;
    gap: var(--space-6) var(--space-5) !important;
  }

  /* 4-Column Card Grids on Laptops */
  .ai-toolkit-grid .card,
  .grid-4 .card {
    padding: var(--space-5);
  }

  /* Consultation section */
  .consultation-wrapper {
    gap: var(--space-6);
  }

  .consultation-form-card {
    padding: 32px;
  }

  /* Hero section on compact laptops */
  .hero-grid {
    gap: var(--space-6);
  }

  .hero-headline,
  .hero-title {
    font-size: clamp(2.2rem, 3.6vw, 3rem) !important;
  }
}

/* Wide Laptops & Standard Displays (1201px to 1366px) */
@media (min-width: 1201px) and (max-width: 1366px) {
  .header-inner {
    gap: 1rem;
  }

  .nav-link {
    padding-inline: 0.55rem;
    font-size: 0.9rem;
    gap: 0.25rem;
  }

  .header-actions .btn {
    padding: 0 18px;
    font-size: 0.9rem;
    height: 44px;
    min-height: 44px;
  }

  .nav-item:nth-child(n+5) .mega-menu {
    left: auto;
    right: 0;
  }
}

/* --------------------------------------------------------------------------
   3. TABLET & SMALL LAPTOP BREAKPOINT (max-width: 1024px)
   -------------------------------------------------------------------------- */
@media (max-width: 1024px) {
  /* Navigation switches to mobile mode */
  .desktop-nav {
    display: none !important;
  }

  .hamburger-btn {
    display: flex !important;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    padding: 0.5rem;
    border-radius: var(--radius-md);
    cursor: pointer;
  }

  .hamburger-btn:hover {
    background-color: var(--color-background-soft);
  }

  /* Container bounds */
  .container {
    width: min(100% - 3rem, 100%);
  }

  /* Header proportions */
  .header-inner {
    height: 70px;
    gap: 1rem;
  }

  /* Grid layouts */
  .hero-grid {
    grid-template-columns: 1fr !important;
    gap: var(--space-7);
  }

  .hero-content {
    max-width: 100%;
  }

  .feature-split-layout {
    grid-template-columns: 1fr !important;
    gap: var(--space-7);
  }

  .consultation-wrapper {
    grid-template-columns: 1fr !important;
    gap: var(--space-7);
  }

  .grid-3,
  .grid.grid-3 {
    grid-template-columns: repeat(2, 1fr);
  }

  .grid-4,
  .grid.grid-4 {
    grid-template-columns: repeat(2, 1fr);
  }

  .ai-toolkit-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .footer-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-6);
  }
}

/* --------------------------------------------------------------------------
   4. SMARTPHONE & PORTRAIT TABLET BREAKPOINT (max-width: 768px)
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
  /* Hide top utility bar to preserve critical vertical space */
  .utility-bar {
    display: none !important;
  }

  /* Container padding */
  .container {
    width: min(100% - 2rem, 100%);
  }

  /* Compact sticky header */
  .site-header {
    height: 64px;
    min-height: 64px;
  }

  .header-inner {
    height: 64px;
    gap: 0.75rem;
  }

  .brand-logo img {
    height: 30px !important;
    max-width: 135px !important;
    width: auto !important;
  }

  /* In header actions: hide secondary login button (accessible in drawer) */
  .header-actions {
    gap: 0.5rem;
    flex-shrink: 0;
  }

  .header-actions .btn-secondary {
    display: none !important;
  }

  .header-actions .btn-primary {
    height: 38px !important;
    min-height: 38px !important;
    padding: 0 14px !important;
    font-size: 0.85rem !important;
    white-space: nowrap;
    flex-shrink: 0;
  }

  .hamburger-btn {
    flex-shrink: 0 !important;
  }

  /* Fluid Typography Scale */
  h1,
  .hero-headline,
  .hero-title {
    font-size: clamp(1.85rem, 5.5vw, 2.5rem) !important;
    line-height: 1.18 !important;
    letter-spacing: -0.02em;
    margin-bottom: var(--space-3);
  }

  h2,
  .section-title {
    font-size: clamp(1.5rem, 4.5vw, 2rem) !important;
    line-height: 1.25 !important;
    margin-bottom: var(--space-3);
  }

  h3,
  .card-title {
    font-size: 1.2rem;
    line-height: 1.35;
    margin-bottom: var(--space-2);
  }

  h4 {
    font-size: 1.05rem;
  }

  p,
  .hero-description,
  .section-header p,
  .card-description,
  .card-text {
    font-size: 0.98rem;
    line-height: 1.6;
  }

  .eyebrow,
  .section-tag {
    font-size: 0.75rem;
    padding: 0.35rem 0.8rem;
    margin-bottom: var(--space-3);
    white-space: normal;
    text-align: center;
  }

  /* Suppress hard breaks inside headings on mobile */
  h1 br,
  h2 br,
  .hero-headline br,
  .hero-title br {
    display: none;
  }

  /* Text overflow protection */
  h1, h2, h3, h4, p, span, a {
    overflow-wrap: break-word;
    word-wrap: break-word;
  }

  /* Spacing Scale Reductions */
  .section {
    padding-block: var(--space-7);
  }

  .hero-section {
    padding-block: var(--space-6);
  }

  .section-header {
    margin-bottom: var(--space-5);
  }

  /* Hero Section Components */
  .hero-actions {
    flex-direction: column;
    width: 100%;
    gap: 0.75rem;
  }

  .hero-actions .btn {
    width: 100%;
    justify-content: center;
  }

  /* Handle inline centered hero action wrappers across service pages */
  .hero-section div[style*="justify-content:center"],
  .hero-section div[style*="justify-content: center"] {
    flex-direction: column !important;
    width: 100% !important;
    gap: 0.75rem !important;
  }

  .hero-section div[style*="justify-content:center"] .btn,
  .hero-section div[style*="justify-content: center"] .btn {
    width: 100% !important;
    justify-content: center !important;
  }

  .hero-interface-card {
    border-radius: var(--radius-lg);
  }

  .trust-bar-slim {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.65rem;
    margin-top: var(--space-5);
    padding-top: var(--space-5);
  }

  .trust-pill {
    font-size: 0.875rem;
  }

  /* Grids Stack to 1 Column */
  .grid-2,
  .grid.grid-2,
  .grid-3,
  .grid.grid-3,
  .grid-4,
  .grid.grid-4,
  .ai-toolkit-grid {
    grid-template-columns: 1fr !important;
    gap: var(--space-5);
  }

  /* Cards */
  .card,
  .ai-tool-card,
  .feature-box {
    padding: var(--space-5);
    border-radius: var(--radius-md);
  }

  .card-icon {
    width: 46px;
    height: 46px;
    margin-bottom: var(--space-3);
  }

  .card-icon svg {
    width: 22px;
    height: 22px;
  }

  /* Expert Links Grid */
  .team-links-grid {
    grid-template-columns: 1fr;
    gap: var(--space-3);
  }

  /* Statistics Grid */
  .stats-grid-container {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-4);
  }

  .stat-item {
    padding: var(--space-4);
    border-radius: var(--radius-md);
  }

  .stat-number {
    font-size: 2rem;
  }

  .stat-text {
    font-size: 0.85rem;
  }

  /* Testimonial Card */
  .testimonial-featured-card {
    padding: var(--space-5);
    border-radius: var(--radius-lg);
  }

  .testimonial-quote-text {
    font-size: 1.05rem;
    margin-bottom: var(--space-4);
  }

  /* FAQ Accordion Component */
  .faq-question {
    padding: 1.15rem 0;
    font-size: 1.05rem;
    gap: 0.75rem;
  }

  .faq-item.active .faq-answer {
    padding-bottom: 1.25rem;
  }

  /* Consultation Form */
  .consultation-form-card {
    padding: 1.5rem 1.25rem;
    border-radius: var(--radius-lg);
  }

  .form-row {
    grid-template-columns: 1fr;
    gap: var(--space-4);
  }

  /* CRITICAL FOR MOBILE: 16px font-size prevents iOS Safari auto-zoom */
  .form-input,
  .form-select,
  .form-textarea {
    font-size: 16px !important;
    height: 48px;
    padding: 0 14px;
    border-radius: var(--radius-md);
  }

  .form-textarea {
    height: auto !important;
    min-height: 110px;
    padding: 12px 14px;
  }

  /* Footer on Mobile */
  .site-footer {
    padding-top: var(--space-7);
    padding-bottom: var(--space-6);
  }

  .footer-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-6) var(--space-4);
    padding-bottom: var(--space-6);
  }

  .footer-col-title {
    font-size: 0.75rem;
    margin-bottom: var(--space-3);
  }

  .footer-links-list {
    gap: 0.65rem;
  }

  .footer-links-list a {
    font-size: 0.85rem;
    padding-block: 0.15rem;
    display: inline-block;
  }

  .footer-bottom-bar {
    padding-top: var(--space-5);
    flex-direction: column;
    text-align: center;
    gap: 1rem;
    align-items: center;
  }

  .footer-brand-info {
    flex-direction: column;
    gap: 0.4rem;
  }

  /* Domain Search & Tools (find-domain.html, etc.) */
  div[style*="flex-direction:column"] form input#domain-input {
    min-width: 100% !important;
  }

  #search-result > div {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 1rem !important;
    text-align: center !important;
  }

  #search-result .btn {
    width: 100% !important;
  }
}

/* --------------------------------------------------------------------------
   5. COMPACT MOBILE SCREENS (max-width: 480px)
   -------------------------------------------------------------------------- */
@media (max-width: 480px) {
  .container {
    width: calc(100% - 24px);
  }

  /* Header compact mode */
  .site-header {
    height: 58px;
    min-height: 58px;
  }

  .header-inner {
    height: 58px;
    gap: 0.5rem;
  }

  .brand-logo img {
    height: 26px !important;
    max-width: 120px !important;
    width: auto !important;
  }

  .header-actions {
    gap: 0.35rem;
  }

  .header-actions .btn-primary {
    height: 34px !important;
    min-height: 34px !important;
    padding: 0 10px !important;
    font-size: 0.775rem !important;
    border-radius: var(--radius-sm);
    white-space: nowrap;
  }

  .hamburger-btn {
    min-width: 36px !important;
    min-height: 36px !important;
    width: 36px !important;
    height: 36px !important;
    padding: 0.3rem !important;
    flex-shrink: 0 !important;
  }

  .hamburger-btn svg {
    width: 20px !important;
    height: 20px !important;
  }

  /* Typography */
  h1,
  .hero-headline,
  .hero-title {
    font-size: 1.75rem !important;
  }

  h2,
  .section-title {
    font-size: 1.4rem !important;
  }

  /* Buttons */
  .btn {
    height: 46px;
    min-height: 46px;
    padding: 0 18px;
    font-size: 0.9rem;
  }

  .btn-lg {
    height: 48px;
    min-height: 48px;
    padding: 0 20px;
    font-size: 0.9375rem;
  }

  /* Stats grid stacks to 1 column on very narrow screens */
  .stats-grid-container {
    grid-template-columns: 1fr;
    gap: var(--space-3);
  }

  .stat-item {
    padding: var(--space-4) var(--space-3);
  }

  /* Footer stacks single column for clean readability */
  .footer-grid {
    grid-template-columns: 1fr;
    gap: var(--space-5);
  }

  .footer-col-title {
    padding-bottom: 0.35rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  }

  /* Mobile Drawer takes full width on very small phones */
  .mobile-drawer {
    max-width: 100vw;
  }

  .mobile-drawer-header {
    padding: 1rem;
  }

  .mobile-drawer-body {
    padding: 1rem;
  }

  /* Domain tags & badges wrapping */
  div[style*="justify-content:center"][style*="flex-wrap:wrap"] {
    gap: 0.35rem !important;
  }
}

/* --------------------------------------------------------------------------
   5b. ULTRA-COMPACT MOBILE BREAKPOINT (max-width: 360px)
   -------------------------------------------------------------------------- */
@media (max-width: 360px) {
  .container {
    width: calc(100% - 16px);
  }

  .brand-logo img {
    max-width: 105px !important;
    height: 24px !important;
    width: auto !important;
  }

  .header-actions {
    gap: 0.25rem;
  }

  .header-actions .btn-primary {
    padding: 0 8px !important;
    font-size: 0.725rem !important;
    height: 32px !important;
    min-height: 32px !important;
  }

  .hamburger-btn {
    min-width: 32px !important;
    min-height: 32px !important;
    width: 32px !important;
    height: 32px !important;
    padding: 0.2rem !important;
    flex-shrink: 0 !important;
  }

  .hamburger-btn svg {
    width: 18px !important;
    height: 18px !important;
  }

  h1,
  .hero-headline,
  .hero-title {
    font-size: 1.55rem !important;
  }

  h2,
  .section-title {
    font-size: 1.3rem !important;
  }

  .consultation-form-card {
    padding: 1.25rem 0.85rem;
  }
}

/* --------------------------------------------------------------------------
   6. MOBILE DRAWER INTERACTION & ANIMATION REFINEMENTS
   -------------------------------------------------------------------------- */
.mobile-drawer {
  width: 100%;
  max-width: min(360px, 88vw);
  height: 100vh;
  height: 100dvh;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
  -webkit-overflow-scrolling: touch;
  transition: right 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.mobile-drawer-body {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.mobile-nav-title {
  min-height: 48px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: color var(--transition-fast);
}

.mobile-nav-title:active {
  color: var(--color-primary);
}

.mobile-nav-title svg {
  transition: transform 0.25s ease;
  flex-shrink: 0;
}

.mobile-nav-subitems {
  transition: all var(--transition-normal);
}

.mobile-nav-subitem {
  display: block;
  min-height: 42px;
  line-height: 42px;
  padding-left: 0.5rem;
  border-radius: var(--radius-sm);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.mobile-nav-subitem:active {
  background-color: var(--color-background-soft);
  color: var(--color-primary);
}

/* --------------------------------------------------------------------------
   7. FORM VALIDATION & INTERACTIVE STATE POLISH ON TOUCH
   -------------------------------------------------------------------------- */
button,
a,
input,
select,
textarea {
  touch-action: manipulation;
}

:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}
