/* ═══════════════════════════════════════════════════════════════════════════════
 * GoSiteMe Mobile Universal — v1.0
 * ═══════════════════════════════════════════════════════════════════════════════
 * Loaded on EVERY page via site-header.inc.php.
 * Catches all pages that lack their own mobile CSS.
 * Uses standardized breakpoints: 768px (tablet), 480px (phone).
 * Complements page-specific responsive styles — never overrides them.
 * ══════════════════════════════════════════════════════════════════════════════ */

/* ── TABLET (≤768px) ─────────────────────────────────────────────────────────── */
@media (max-width: 768px) {

  /* ── Layout normalization ─────────────────────────────────────────────────── */
  body {
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
  }

  /* Prevent horizontal overflow from any element */
  main, section, .container, .page-content, .content-wrapper,
  .main-content, article, .section-content, .page-wrapper {
    max-width: 100vw;
    overflow-x: hidden;
  }

  /* Stack all generic grid/flex layouts */
  .grid, .card-grid, .features-grid, .stats-grid, .kpi-grid,
  .tools-grid, .pricing-grid, .services-grid, .integration-grid,
  .dashboard-grid, .metric-grid, .team-grid, .agent-grid {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 1rem !important;
  }

  /* Stack 2-3 column layouts */
  .two-col, .three-col, .split-layout, .dual-panel,
  .columns, .col-2, .col-3, .flex-row, .row {
    flex-direction: column !important;
    gap: 1rem !important;
  }

  /* Side-by-side elements stack */
  .sidebar + .main, .aside + .content, .panel-left + .panel-right {
    display: flex;
    flex-direction: column;
  }

  /* ── Typography scaling ─────────────────────────────────────────────────── */
  h1, .h1 { font-size: clamp(1.5rem, 6vw, 2.2rem) !important; }
  h2, .h2 { font-size: clamp(1.25rem, 5vw, 1.75rem) !important; }
  h3, .h3 { font-size: clamp(1.1rem, 4.5vw, 1.4rem) !important; }

  /* Prevent text from overflowing */
  h1, h2, h3, h4, h5, h6, p, li, td, th, span, a, label {
    word-break: break-word;
    overflow-wrap: anywhere;
  }

  /* ── Section spacing ────────────────────────────────────────────────────── */
  section, .section {
    padding-left: 1rem !important;
    padding-right: 1rem !important;
  }

  /* Reduce large section padding */
  .hero, .hero-section, .page-hero, [class*="hero"] {
    padding: 2rem 1rem !important;
    min-height: auto !important;
  }

  /* ── Cards — full width ─────────────────────────────────────────────────── */
  .card, .feature-card, .stat-card, .kpi-card, .pricing-card,
  .tool-card, .service-card, .agent-card, .metric-card,
  [class*="-card"] {
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
  }

  /* ── Tables — horizontal scroll ─────────────────────────────────────────── */
  table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
  }

  /* ── Forms — full width inputs ──────────────────────────────────────────── */
  input[type="text"], input[type="email"], input[type="password"],
  input[type="search"], input[type="url"], input[type="tel"],
  input[type="number"], textarea, select, .form-control {
    width: 100% !important;
    max-width: 100% !important;
    min-height: 44px;
    font-size: 16px !important; /* Prevents iOS zoom */
    box-sizing: border-box;
  }

  /* ── Buttons — touch targets ────────────────────────────────────────────── */
  button, .btn, [class*="btn-"], a.button, input[type="submit"],
  input[type="button"], .action-btn {
    min-height: 44px;
    min-width: 44px;
    padding: 10px 16px;
    font-size: 0.9rem;
  }

  /* Button rows stack on mobile */
  .btn-group, .button-group, .action-buttons, .cta-buttons,
  .btn-row, .button-row, [class*="btn-group"] {
    flex-direction: column !important;
    gap: 0.5rem !important;
    width: 100%;
  }

  .btn-group > *, .button-group > *, .action-buttons > *,
  .cta-buttons > *, .btn-row > *, .button-row > * {
    width: 100%;
  }

  /* ── Images & media — contain ───────────────────────────────────────────── */
  img, video, iframe, canvas, svg {
    max-width: 100%;
    height: auto;
  }

  /* ── Pre/code blocks — scroll ───────────────────────────────────────────── */
  pre, code {
    max-width: 100%;
    overflow-x: auto;
    word-break: break-all;
  }

  /* ── Modals — full screen on mobile ─────────────────────────────────────── */
  .modal-content, .dialog, .popup, [class*="modal-body"] {
    width: 95vw !important;
    max-width: 95vw !important;
    max-height: 90vh;
    margin: 5vh auto !important;
    overflow-y: auto;
  }

  /* ── Dashboard layouts ──────────────────────────────────────────────────── */
  .dashboard-container, .dash-grid, .dashboard-content {
    display: flex !important;
    flex-direction: column !important;
    gap: 1rem;
    padding: 0.5rem !important;
  }

  /* Dashboard sidebars collapse */
  .dashboard-sidebar, .dash-sidebar, .side-panel, .sidebar {
    width: 100% !important;
    position: static !important;
    height: auto !important;
    max-height: none !important;
  }

  /* ── Tabs — scrollable on mobile ────────────────────────────────────────── */
  .tabs, .tab-bar, .tab-nav, [class*="tab-"] {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap !important;
    white-space: nowrap;
  }

  /* ── Fixed/sticky elements — safer on mobile ────────────────────────────── */
  .fixed-bottom, .sticky-bar, .floating-action {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1000;
  }

  /* ── Hide desktop-only elements ─────────────────────────────────────────── */
  .desktop-only, .hide-mobile {
    display: none !important;
  }

  /* ── Show mobile-only elements ──────────────────────────────────────────── */
  .mobile-only, .show-mobile {
    display: block !important;
  }

  /* ── Pricing page fixes ─────────────────────────────────────────────────── */
  .pricing-toggle, .plan-comparison {
    flex-direction: column;
    align-items: center;
  }

  /* ── Feature sections with icons ────────────────────────────────────────── */
  .feature-row, .feature-item, .benefit-row {
    flex-direction: column !important;
    text-align: center;
    gap: 0.75rem;
  }

  /* ── Timeline / step indicators ─────────────────────────────────────────── */
  .timeline, .steps, .process-steps {
    flex-direction: column !important;
  }

  /* ── Charts & visualizations ────────────────────────────────────────────── */
  .chart-container, .graph-container, [class*="chart"] {
    width: 100% !important;
    min-height: 200px;
    overflow-x: auto;
  }

  /* ── Navigation breadcrumbs ─────────────────────────────────────────────── */
  .breadcrumb, .breadcrumbs {
    font-size: 0.8rem;
    overflow-x: auto;
    white-space: nowrap;
  }

  /* ── Stats/metric rows ──────────────────────────────────────────────────── */
  .stats-row, .metrics-row, .kpi-row, .stat-bar {
    flex-direction: column !important;
    gap: 0.75rem;
  }

  /* ── Absolute/floating elements ─────────────────────────────────────────── */
  .floating-card, .absolute-card, [style*="position: absolute"] {
    position: relative !important;
    transform: none !important;
    top: auto !important;
    left: auto !important;
    right: auto !important;
    width: 100% !important;
  }
}

/* ── PHONE (≤480px) ──────────────────────────────────────────────────────────── */
@media (max-width: 480px) {

  /* Even tighter padding */
  section, .section {
    padding-left: 0.75rem !important;
    padding-right: 0.75rem !important;
  }

  /* Smaller headings */
  h1, .h1 { font-size: 1.4rem !important; }
  h2, .h2 { font-size: 1.15rem !important; }

  /* Full-width buttons */
  button, .btn, [class*="btn-"], a.button {
    width: 100%;
    text-align: center;
  }

  /* Hide non-essential decorative elements */
  .decorative, .ornament, .bg-decoration, .glow-orb, .particle,
  [class*="decoration"], [class*="ornament"] {
    display: none !important;
  }

  /* Reduce card padding */
  .card, [class*="-card"] {
    padding: 0.75rem !important;
  }

  /* Modal takes full width */
  .modal-content, .dialog, .popup {
    width: 100vw !important;
    max-width: 100vw !important;
    border-radius: 12px 12px 0 0 !important;
    margin: auto 0 0 0 !important;
    max-height: 85vh;
  }
}

/* ── TOUCH DEVICE OPTIMIZATION ───────────────────────────────────────────────── */
@media (hover: none) and (pointer: coarse) {

  /* Minimum touch targets (WCAG 2.5.5 — 44x44px) */
  button, .btn, a, [role="button"], [tabindex],
  input[type="checkbox"], input[type="radio"],
  .clickable, .tappable, .interactive {
    min-height: 44px;
    min-width: 44px;
  }

  /* Add spacing between adjacent interactive elements */
  button + button, .btn + .btn, a + a {
    margin-top: 4px;
  }

  /* Remove hover effects that don't work on touch */
  .hover-effect, [class*="hover-"] {
    transform: none !important;
  }

  /* Disable tooltip hover — use tap instead */
  [data-tooltip]:hover::after,
  [data-tooltip]:hover::before {
    display: none;
  }

  /* Smoother scrolling */
  * {
    -webkit-overflow-scrolling: touch;
  }

  /* Prevent accidental text selection while scrolling */
  .scrollable, .scroll-container {
    -webkit-user-select: none;
    user-select: none;
  }

  /* Make scrollbars thinner on touch */
  ::-webkit-scrollbar {
    width: 4px;
    height: 4px;
  }

  ::-webkit-scrollbar-track {
    background: transparent;
  }

  ::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 4px;
  }
}

/* ── LANDSCAPE PHONE ─────────────────────────────────────────────────────────── */
@media (max-height: 500px) and (orientation: landscape) {
  .hero, .hero-section, .page-hero, [class*="hero"] {
    min-height: auto !important;
    padding: 1rem !important;
  }

  /* Reduce fixed header height in landscape */
  header, .site-header, .nav-bar {
    padding-top: 4px !important;
    padding-bottom: 4px !important;
  }
}

/* ── UTILITY CLASSES ─────────────────────────────────────────────────────────── */
.mobile-only { display: none; }
.desktop-only { display: block; }

@media (max-width: 768px) {
  .mobile-only { display: block !important; }
  .desktop-only { display: none !important; }
  .mobile-stack { flex-direction: column !important; }
  .mobile-center { text-align: center !important; }
  .mobile-full { width: 100% !important; }
  .mobile-hide { display: none !important; }
  .mobile-p-0 { padding: 0 !important; }
  .mobile-gap-sm { gap: 0.5rem !important; }
}
