/* ==========================================================================
   ThreadSync — Mobile Enterprise Polish
   Version: 1.0.0 | 2026-03-05
   Layered on top of existing base bundle + page CSS.
   ========================================================================== */

/* --------------------------------------------------------------------------
   0. GLOBAL MOBILE FOUNDATIONS
   -------------------------------------------------------------------------- */

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

  /* Anchored headings: offset for sticky header */
  [id] {
    scroll-margin-top: 80px;
  }

  /* Container padding reduction on very small screens */
  .container,
  .ts-container {
    padding-left: 16px !important;
    padding-right: 16px !important;
  }
}

@media (max-width: 360px) {
  .container,
  .ts-container {
    padding-left: 12px !important;
    padding-right: 12px !important;
  }
}

/* --------------------------------------------------------------------------
   1. MOBILE NAVIGATION — Overlay & Focus Trap
   -------------------------------------------------------------------------- */

@media (max-width: 768px) {
  /* Full-height mobile menu overlay */
  .ts-mobile-nav {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    height: 100dvh !important;
    z-index: 9999 !important;
    background: rgba(8, 8, 10, 0.97) !important;
    -webkit-backdrop-filter: blur(20px) !important;
    backdrop-filter: blur(20px) !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    padding-top: 80px !important;
  }

  .ts-mobile-nav[hidden] {
    display: none !important;
  }

  /* Ensure close/toggle button is large enough */
  .ts-mobile-toggle {
    min-width: 44px !important;
    min-height: 44px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
  }

  /* Mobile nav links: large tap targets */
  .ts-mobile-nav a {
    display: block !important;
    padding: 14px 24px !important;
    font-size: 1rem !important;
    min-height: 44px !important;
    line-height: 1.4 !important;
  }

  /* Body scroll lock when menu open */
  body.ts-menu-open {
    overflow: hidden !important;
    position: fixed !important;
    width: 100% !important;
  }

  /* Hide desktop nav on mobile (accessibility: not just visual) */
  .ts-nav {
    display: none !important;
  }
}


/* --------------------------------------------------------------------------
   2. P0: RESPONSIVE TABLES — Pricing Compare & API Docs Tiers
   -------------------------------------------------------------------------- */

/* --- Pricing: Comparison Table → Mobile Scroll Container --- */
@media (max-width: 768px) {
  .comparison-wrapper {
    display: block !important;
    max-width: calc(100vw - 32px) !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    margin: 0 auto !important;
    border-radius: 12px !important;
    /* Scroll hint gradient */
    background:
      linear-gradient(to right, rgba(8,8,10,1) 0%, transparent 2%),
      linear-gradient(to left, rgba(8,8,10,1) 0%, transparent 2%);
    background-size: 40px 100%;
    background-position: left, right;
    background-repeat: no-repeat;
    background-attachment: local, local;
  }

  .comparison-table {
    min-width: 600px !important;
    font-size: 0.8rem !important;
  }

  .comparison-table th,
  .comparison-table td {
    padding: 8px 10px !important;
    white-space: nowrap !important;
  }

  /* First column (Feature) should not wrap */
  .comparison-table th:first-child,
  .comparison-table td:first-child {
    position: sticky !important;
    left: 0 !important;
    z-index: 2 !important;
    background: rgba(8, 8, 10, 0.95) !important;
    -webkit-backdrop-filter: blur(8px) !important;
    backdrop-filter: blur(8px) !important;
  }
}

/* --- API Docs: Rate Limits Table → Mobile Scroll Container --- */
@media (max-width: 768px) {
  .rate-table {
    display: block !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    max-width: 100% !important;
  }

  .rate-table th,
  .rate-table td {
    white-space: nowrap !important;
    padding: 10px 12px !important;
    font-size: 0.85rem !important;
  }

  /* Sticky tier column */
  .rate-table td:first-child,
  .rate-table th:first-child {
    position: sticky !important;
    left: 0 !important;
    z-index: 2 !important;
    background: rgba(8, 8, 10, 0.95) !important;
  }
}


/* --------------------------------------------------------------------------
   3. P0: API DOCS — Language Selector & Code Blocks
   -------------------------------------------------------------------------- */

@media (max-width: 768px) {
  /* Language selector: horizontally scrollable single-line pills */
  .ts-codeTabs__tablist {
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    gap: 6px !important;
    padding: 8px 4px !important;
    scrollbar-width: none !important;        /* Firefox */
    position: static !important;
    width: 100% !important;
    min-width: 0 !important;
    border-right: none !important;
    border-bottom: 1px solid rgba(255,255,255,0.08) !important;
  }

  .ts-codeTabs__tablist::-webkit-scrollbar {
    display: none !important;                /* Chrome/Safari */
  }

  /* Hide helper text on mobile */
  .ts-codeTabs__tablist-label,
  .ts-codeTabs__tablist-note {
    display: none !important;
  }

  /* Tab pills: compact for mobile */
  .ts-codeTabs__tablist .ts-tab {
    flex-shrink: 0 !important;
    font-size: 0.75rem !important;
    padding: 6px 12px !important;
    border-radius: 999px !important;
    white-space: nowrap !important;
    min-height: 36px !important;
  }

  /* Code tabs layout: stack vertically */
  .ts-codeTabs {
    flex-direction: column !important;
  }

  /* Panels: full width */
  .ts-codeTabs__panels {
    width: 100% !important;
    min-width: 0 !important;
  }

  /* Code blocks: contained scrolling */
  .ts-code {
    overflow-x: auto !important;
    max-width: 100% !important;
    -webkit-overflow-scrolling: touch !important;
    font-size: clamp(11px, 2.8vw, 14px) !important;
    padding: 12px !important;
    border-radius: 8px !important;
    white-space: pre !important;
    word-break: normal !important;
  }

  /* Install command bar: wrap on mobile */
  .ts-install {
    flex-wrap: wrap !important;
    gap: 8px !important;
  }

  .ts-install__cmd {
    font-size: clamp(10px, 2.5vw, 13px) !important;
    word-break: break-all !important;
    min-width: 0 !important;
    flex: 1 1 100% !important;
  }

  /* SDK cards grid: 2 cols on small screens, 1 on very small */
  .sdk-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 12px !important;
  }

  .sdk-card {
    padding: 12px !important;
  }

  .sdk-card code {
    font-size: 0.6rem !important;
    word-break: break-all !important;
  }
}

@media (max-width: 400px) {
  .sdk-grid {
    grid-template-columns: 1fr !important;
  }
}

/* Copy button for code blocks (injected via JS) */
.ts-code-copy {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 6px;
  color: rgba(255,255,255,0.5);
  font-size: 12px;
  padding: 4px 10px;
  cursor: pointer;
  z-index: 3;
  min-height: 32px;
  min-width: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.ts-code-copy:hover,
.ts-code-copy:active {
  background: rgba(59, 130, 246, 0.15);
  border-color: rgba(59, 130, 246, 0.3);
  color: #93c5fd;
}

.ts-code-copy.copied {
  background: rgba(34, 197, 94, 0.15);
  border-color: rgba(34, 197, 94, 0.3);
  color: #86efac;
}

/* Code block wrapper needs relative positioning for copy button */
.ts-code {
  position: relative;
}


/* --------------------------------------------------------------------------
   4. P0: FORMS — Demo & Contact (Thumb-First)
   -------------------------------------------------------------------------- */

@media (max-width: 768px) {
  /* Form rows: always single column on mobile */
  .form-row,
  .ts-form-row {
    grid-template-columns: 1fr !important;
    gap: 0 !important;
  }

  /* Form inputs: full width, proper sizing */
  .form-input,
  .ts-input,
  input[class*="form"],
  select[class*="form"],
  textarea[class*="form"] {
    width: 100% !important;
    min-height: 44px !important;
    font-size: 16px !important;    /* Prevents iOS auto-zoom */
    padding: 12px 14px !important;
    border-radius: 10px !important;
  }

  /* Labels: consistent spacing */
  .form-label,
  .ts-label {
    font-size: 0.875rem !important;
    margin-bottom: 6px !important;
    display: block !important;
  }

  /* Form groups: breathing room */
  .form-group,
  .ts-form-group {
    margin-bottom: 16px !important;
  }

  /* Form card: reduce padding on mobile */
  .form-card {
    padding: 1.25rem !important;
    border-radius: 16px !important;
  }

  /* Submit buttons: full width */
  .form-card .ts-btn,
  .form-card button[type="submit"],
  #demo-form button[type="submit"],
  #contact-form button[type="submit"] {
    width: 100% !important;
    min-height: 48px !important;
    font-size: 1rem !important;
    border-radius: 12px !important;
    margin-top: 8px !important;
  }

  /* Select arrows: larger tap area */
  select.form-input,
  select.ts-input {
    background-position: right 12px center !important;
    padding-right: 40px !important;
    -webkit-appearance: none !important;
  }

  /* Checkbox/consent rows */
  .ts-checkbox-label,
  label[class*="checkbox"] {
    font-size: 0.8rem !important;
    line-height: 1.5 !important;
    padding: 8px 0 !important;
    display: flex !important;
    align-items: flex-start !important;
    gap: 10px !important;
  }

  .ts-checkbox-label input[type="checkbox"],
  label[class*="checkbox"] input[type="checkbox"] {
    width: 20px !important;
    height: 20px !important;
    min-width: 20px !important;
    margin-top: 2px !important;
  }

  /* Contact page: stack layout columns */
  .contact-grid,
  .contact-layout {
    grid-template-columns: 1fr !important;
    gap: 24px !important;
  }
}

/* Autocomplete attributes (CSS can't set these, but style the filled state) */
input:-webkit-autofill {
  -webkit-box-shadow: 0 0 0 30px rgba(8,8,10,1) inset !important;
  -webkit-text-fill-color: #e7e9ea !important;
  caret-color: #e7e9ea !important;
}


/* --------------------------------------------------------------------------
   5. P1: TRUST CENTER — "On This Page" Sidebar → Mobile Dropdown
   -------------------------------------------------------------------------- */

@media (max-width: 1024px) {
  .content-grid {
    grid-template-columns: 1fr !important;
    gap: 24px !important;
  }

  /* Don't hide trust-nav on mobile; convert to collapsible dropdown */
  .trust-nav {
    display: block !important;
    position: static !important;
    background: rgba(255,255,255,0.04) !important;
    border: 1px solid rgba(255,255,255,0.08) !important;
    border-radius: 12px !important;
    padding: 0 !important;
    overflow: hidden !important;
  }

  .trust-nav h4 {
    padding: 14px 16px !important;
    margin-bottom: 0 !important;
    cursor: pointer !important;
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    min-height: 44px !important;
    font-size: 13px !important;
  }

  /* Chevron indicator */
  .trust-nav h4::after {
    content: "\25BC" !important;  /* ▼ */
    font-size: 10px !important;
    color: rgba(255,255,255,0.3) !important;
    transition: transform 0.2s !important;
  }

  .trust-nav.expanded h4::after {
    transform: rotate(180deg) !important;
  }

  /* Hidden by default on mobile; JS toggles .expanded */
  .trust-nav ul {
    max-height: 0 !important;
    overflow: hidden !important;
    transition: max-height 0.3s ease !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  .trust-nav.expanded ul {
    max-height: 500px !important;
    padding-bottom: 8px !important;
  }

  .trust-nav a {
    padding: 10px 16px !important;
    min-height: 40px !important;
    font-size: 0.875rem !important;
  }
}


/* --------------------------------------------------------------------------
   6. P1: ROI CALCULATOR — Modal & Sliders (Mobile)
   -------------------------------------------------------------------------- */

@media (max-width: 768px) {
  /* Modal: full-screen on mobile */
  .modal-overlay {
    align-items: flex-end !important;  /* Slide up from bottom */
  }

  .modal-content {
    max-width: 100% !important;
    width: 100% !important;
    max-height: 90dvh !important;
    border-radius: 20px 20px 0 0 !important;
    padding: 24px 20px !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
  }

  /* Close button: prominent and tappable */
  .modal-content button[data-ts-click*="closeModal"],
  .modal-content .modal-close {
    min-height: 44px !important;
    font-size: 0.95rem !important;
    padding: 12px !important;
    margin-top: 12px !important;
  }

  /* Modal inputs */
  .modal-input {
    min-height: 44px !important;
    font-size: 16px !important;
    padding: 12px 14px !important;
  }

  /* Sliders: larger thumb for touch */
  .slider::-webkit-slider-thumb {
    width: 28px !important;
    height: 28px !important;
  }

  .slider::-moz-range-thumb {
    width: 28px !important;
    height: 28px !important;
  }

  /* Slider track: taller for easier grab */
  .slider {
    height: 8px !important;
  }

  /* ROI glass cards: stack on mobile */
  .lg\\:grid-cols-2 {
    grid-template-columns: 1fr !important;
  }

  /* Metric cards: 2-col grid on mobile */
  .lg\\:grid-cols-4 {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* Glass cards: reduce padding */
  .glass-card.p-8 {
    padding: 1.25rem !important;
  }
}

/* Body scroll lock when modal is open */
body.modal-open {
  overflow: hidden !important;
  position: fixed !important;
  width: 100% !important;
}


/* --------------------------------------------------------------------------
   7. P2: GLASS EFFECTS — Mobile Performance
   -------------------------------------------------------------------------- */

/* Reduce blur on mobile for GPU performance */
@media (max-width: 768px) {
  .glass-surface,
  .glass--panel,
  .glass--card {
    -webkit-backdrop-filter: blur(8px) !important;
    backdrop-filter: blur(8px) !important;
  }

  .glass-surface--strong {
    -webkit-backdrop-filter: blur(12px) !important;
    backdrop-filter: blur(12px) !important;
  }

  .glass-surface--soft {
    -webkit-backdrop-filter: blur(6px) !important;
    backdrop-filter: blur(6px) !important;
  }

  /* Pricing cards: reduce blur */
  .pricing-card {
    -webkit-backdrop-filter: blur(10px) !important;
    backdrop-filter: blur(10px) !important;
  }

  /* Disable heavy radial gradients on small screens */
  body::before {
    opacity: 0.3 !important;
  }
}

/* Fallback for no backdrop-filter support */
@supports not (backdrop-filter: blur(1px)) {
  .glass-surface,
  .glass--panel,
  .glass--card,
  .glass-surface--strong,
  .glass-surface--soft {
    background: rgba(15, 20, 25, 0.92) !important;
  }
}

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .glass-surface,
  .glass--panel,
  .glass--card {
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
    background: rgba(15, 20, 25, 0.95) !important;
  }
}


/* --------------------------------------------------------------------------
   8. STAT CARDS — Hero Stats Mobile
   -------------------------------------------------------------------------- */

@media (max-width: 600px) {
  .hero-stats,
  [class*="stat-card"] + [class*="stat-card"] {
    /* Ensure stats wrap to 2x2 grid */
  }

  .stat-value {
    font-size: clamp(1.5rem, 6vw, 2.5rem) !important;
  }

  .stat-label {
    font-size: clamp(0.65rem, 2.5vw, 0.8rem) !important;
  }
}


/* --------------------------------------------------------------------------
   9. CTA BUTTONS — Stack on Mobile
   -------------------------------------------------------------------------- */

@media (max-width: 480px) {
  .cta-buttons {
    flex-direction: column !important;
    gap: 12px !important;
    width: 100% !important;
  }

  .cta-buttons .ts-btn,
  .cta-buttons a {
    width: 100% !important;
    text-align: center !important;
    justify-content: center !important;
  }
}


/* --------------------------------------------------------------------------
   10. PRICING CARDS — Mobile Grid
   -------------------------------------------------------------------------- */

@media (max-width: 900px) {
  .pricing-grid {
    grid-template-columns: 1fr !important;
    max-width: 480px !important;
    margin: 0 auto !important;
  }

  .pricing-card {
    padding: 1.5rem !important;
  }
}
