/*
 * FluxCybers Mobile Responsiveness — Global overrides for all pages
 * Handles: touch targets, typography, forms, navigation, grids, overflow
 * Breakpoints: 768px (tablet), 480px (phone), 375px (standard), 320px (small)
 *
 * Does NOT own: page-specific layout (that stays in each page's inline CSS)
 * DOES own: universal mobile patterns that apply across the whole site
 */

/* ── Body scroll lock when mobile nav is open ──────────────── */
body.mobile-nav-open {
  overflow: hidden;
  position: fixed;
  width: 100%;
  touch-action: none;
}

/* ── Global: prevent horizontal overflow on all screens ────── */
html {
  overflow-x: hidden;
}
body {
  overflow-x: hidden;
  min-width: 0;
}
img, video, iframe, svg, canvas {
  max-width: 100%;
  height: auto;
}
pre, code {
  overflow-x: auto;
  max-width: 100%;
  word-break: break-word;
}
table {
  display: block;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}
/* Restore table for design-system tables that need proper layout */
.table-wrap table {
  display: table;
}

/* ── 768px: Tablet ─────────────────────────────────────────── */
@media (max-width: 768px) {
  /* Touch targets — all clickable elements get min 44px */
  button, .btn, .btn-primary, .btn-secondary, .btn-cta, .btn-ghost,
  a.btn, a.btn-primary, a.btn-secondary, a.btn-cta,
  input[type="submit"], input[type="button"] {
    min-height: 44px;
    min-width: 44px;
  }

  /* Forms — full width on mobile */
  input[type="text"], input[type="email"], input[type="password"],
  input[type="tel"], input[type="url"], input[type="number"],
  input[type="search"], input[type="date"], textarea, select {
    font-size: 16px !important; /* Prevents iOS zoom on focus */
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }

  /* Auth pages — ensure card fits viewport */
  .auth-page {
    padding: 20px 16px !important;
    min-height: auto !important;
  }
  .auth-card {
    max-width: 100% !important;
    width: 100% !important;
    padding: 28px 20px !important;
    margin: 0 auto;
    box-sizing: border-box;
  }
  .auth-card h2 {
    font-size: 22px !important;
  }
  .auth-card .form-group {
    margin-bottom: 14px;
  }
  .auth-card input {
    padding: 12px 14px !important;
  }
  .auth-card .btn-primary,
  .auth-card .btn-secondary,
  .auth-card .auth-alt-btn {
    width: 100% !important;
    padding: 14px 20px !important;
    font-size: 15px !important;
  }

  /* Landing page header nav buttons */
  header .btn-cta,
  header .btn-secondary {
    padding: 10px 16px !important;
    font-size: 13px !important;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  /* Modals must fit viewport */
  .modal, [class*="modal"] {
    max-width: calc(100vw - 24px) !important;
    max-height: calc(100vh - 40px) !important;
    margin: 12px !important;
    overflow-y: auto;
  }

  /* Footer: stack vertically */
  footer {
    padding: 24px 16px !important;
  }
  .footer-links {
    flex-wrap: wrap !important;
    justify-content: center !important;
    gap: 8px 16px !important;
  }

  /* Cards / grids: ensure they don't overflow */
  .card, .panel, .stat-card, .chart-card, .health-card, .arch-card {
    max-width: 100%;
    box-sizing: border-box;
  }
}

/* ── 640px: Large Phone ────────────────────────────────────── */
@media (max-width: 640px) {
  /* Hero actions: stack vertically */
  .hero-actions, .cta-actions {
    flex-direction: column !important;
    gap: 12px !important;
  }
  .hero-actions a, .hero-actions button,
  .cta-actions a, .cta-actions button {
    width: 100% !important;
    justify-content: center !important;
    text-align: center;
  }

  /* Section padding reduction */
  section, .section {
    padding-left: 16px !important;
    padding-right: 16px !important;
  }
}

/* ── 480px: Standard Phone ─────────────────────────────────── */
@media (max-width: 480px) {
  /* Typography — ensure readability */
  h1 {
    font-size: clamp(26px, 7vw, 38px) !important;
    line-height: 1.2 !important;
  }
  h2 {
    font-size: clamp(20px, 5.5vw, 28px) !important;
    line-height: 1.25 !important;
  }
  h3 {
    font-size: clamp(16px, 4.5vw, 22px) !important;
  }
  p, li, td, th {
    font-size: 14px;
    line-height: 1.6;
  }

  /* Buttons get full width at phone sizes */
  .btn-cta, .btn-primary {
    width: 100%;
    justify-content: center;
    text-align: center;
  }

  /* Reduce all padding for small screens */
  .hero, [class*="hero"] {
    padding-left: 16px !important;
    padding-right: 16px !important;
  }

  /* Stat grids: 2 columns max */
  .stats-grid, .stats-inner {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 10px !important;
  }
  .stat-value {
    font-size: 24px !important;
  }
}

/* ── 375px: iPhone SE / Standard ───────────────────────────── */
@media (max-width: 375px) {
  /* Header: tighten spacing */
  header {
    padding: 0 12px !important;
    gap: 6px;
  }
  header .btn-cta,
  header .btn-secondary {
    padding: 8px 10px !important;
    font-size: 12px !important;
  }

  /* Auth cards: tighter padding */
  .auth-card {
    padding: 20px 14px !important;
  }

  /* Landing page sections */
  .hero {
    padding-top: 40px !important;
    padding-bottom: 50px !important;
  }

  /* Reduce font sizes further */
  h1 {
    font-size: 24px !important;
  }
  h2 {
    font-size: 20px !important;
  }

  /* Pricing cards: stack */
  .pricing-grid, .plans-grid {
    grid-template-columns: 1fr !important;
  }
}

/* ── 320px: Small Phone (Galaxy S3, etc.) ──────────────────── */
@media (max-width: 320px) {
  header {
    padding: 0 8px !important;
  }
  header .btn-cta,
  header .btn-secondary {
    padding: 6px 8px !important;
    font-size: 11px !important;
  }

  .auth-card {
    padding: 16px 10px !important;
  }
  .auth-card h2 {
    font-size: 18px !important;
  }

  h1 {
    font-size: 22px !important;
  }

  /* Reduce ticker text */
  .chain-ticker, .chain-ticker span {
    font-size: 11px !important;
  }
}

/* ── FluxMoney / FluxMobile landing pages responsive ──────── */
@media (max-width: 768px) {
  /* Wizard steps — stack on mobile */
  .step-indicators, .wizard-steps {
    flex-wrap: wrap !important;
    gap: 8px !important;
  }
  .step-indicator, .wizard-step {
    font-size: 12px !important;
  }

  /* Plan cards: 2 columns at tablet, 1 at phone */
  .plans-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* Type cards: full width */
  .type-cards {
    flex-direction: column !important;
  }
  .type-card {
    width: 100% !important;
  }
}

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

/* ── SPA Dashboard mobile ─────────────────────────────────── */
@media (max-width: 768px) {
  /* App nav: scroll horizontally on overflow */
  .app-nav, .page-nav {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    flex-wrap: nowrap !important;
  }
  .app-nav::-webkit-scrollbar,
  .page-nav::-webkit-scrollbar {
    display: none;
  }
  .app-nav a, .page-nav a {
    flex-shrink: 0 !important;
    white-space: nowrap !important;
  }

  /* Dashboard content: full width */
  .page-content, .main-content {
    padding: 16px !important;
    max-width: 100% !important;
  }

  /* Server cards / inventory: single column */
  .server-card, .inventory-card {
    width: 100% !important;
  }
}

/* ── FluxMobile Signup — already has mobile styles but needs touch target fix ─ */
@media (max-width: 768px) {
  .fluxmobile-signup .btn-primary,
  .fluxmobile-signup .btn-ghost {
    min-height: 50px;
    font-size: 16px !important;
  }
}

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