/**
 * Tala Sanj - MOBILE GUARD LAYER (v2.0.1)
 * Loaded last, so it always wins.
 *
 * Why this file exists: in v1/v2.0.0 the mobile breakpoint never collapsed
 * .hero-grid, .article-content-wrapper or .footer-grid, and wide tables pushed
 * the document wider than the screen. The result was the squeezed two-column
 * layout you saw on the iPhone preview.
 *
 * Rules of this layer (checked by tools/responsive-audit.py):
 *   1. No element may be wider than the viewport.
 *   2. Every multi-column grid collapses at 768px and below.
 *   3. Every tappable element is at least 44x44px.
 *   4. Form fields use 16px font so iOS does not zoom on focus.
 */

/* ---------- 1. Global overflow guard (all screen sizes) ---------- */
html {
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

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

img,
svg,
video,
canvas,
iframe,
embed,
object {
  max-width: 100%;
  height: auto;
}

pre,
code,
table {
  max-width: 100%;
}

/* Long Persian/Latin strings and URLs must never widen the page. */
p,
li,
h1,
h2,
h3,
h4,
td,
th,
a {
  overflow-wrap: break-word;
  word-break: break-word;
}

/* Grid and flex children default to min-width:auto, which is the #1 cause of
   horizontal overflow inside grids. */
.hero-grid > *,
.footer-grid > *,
.ts-calc-grid > *,
.ts-fact-grid > *,
.ts-tools-grid > * {
  min-width: 0;
}

/* Dropdown and drawer can never exceed the screen. */
.dropdown-menu {
  max-width: min(240px, 88vw);
}

.mobile-drawer {
  width: min(320px, 86vw);
  max-width: 86vw;
}

/* =====================================================================
 * 2. TABLET AND BELOW (<=1024px)
 * =================================================================== */
@media (max-width: 1024px) {
  .hero-grid {
    grid-template-columns: 1fr;
    gap: 2.5rem;
  }

  .article-content-wrapper {
    grid-template-columns: 1fr;
  }

  .footer-grid {
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
  }
}

/* =====================================================================
 * 3. MOBILE (<=768px) - the layer that was missing
 * =================================================================== */
@media (max-width: 768px) {

  /* --- Layout skeleton --- */
  .container,
  .container-narrow {
    padding-left: 1rem;
    padding-right: 1rem;
    max-width: 100%;
  }

  .section-py {
    padding-top: 2.5rem;
    padding-bottom: 2.5rem;
  }

  /* --- Every multi-column grid collapses --- */
  .hero-grid,
  .footer-grid,
  .article-content-wrapper,
  .pros-cons-grid,
  .ts-calc-grid,
  .ts-tools-grid,
  .platform-grid,
  .fund-grid,
  .method-grid,
  .card-grid,
  .features-grid,
  .stats-grid {
    grid-template-columns: 1fr !important;
    gap: 1.25rem;
  }

  /* --- Hero --- */
  .hero-section {
    padding: 2.25rem 0 3rem;
  }

  .hero-content {
    text-align: right;
  }

  .hero-content h1 {
    font-size: clamp(1.55rem, 6.5vw, 2rem);
    line-height: 1.4;
  }

  .hero-content p {
    font-size: 0.98rem;
    line-height: 1.9;
  }

  .hero-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
    text-align: right;
  }

  .stat-item .stat-num {
    font-size: 1.3rem;
    justify-content: flex-start;
  }

  .hero-calculator-card {
    padding: 1.15rem;
    border-radius: var(--radius-lg);
  }

  .calc-header {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  /* --- Buttons: full width, thumb friendly --- */
  .btn-group {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }

  .btn,
  .btn-lg,
  .btn-primary,
  .btn-secondary {
    width: 100%;
    min-height: 48px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  /* --- Forms: 16px stops iOS auto zoom --- */
  .form-control,
  input[type="text"],
  input[type="number"],
  input[type="email"],
  input[type="search"],
  select,
  textarea {
    font-size: 16px;
    min-height: 48px;
  }

  .form-label {
    font-size: 0.9rem;
  }

  /* --- Header --- */
  .header-inner {
    gap: 0.5rem;
  }

  .brand-logo-img {
    max-height: 34px;
  }

  .mobile-nav-toggle,
  .drawer-close {
    min-width: 44px;
    min-height: 44px;
  }

  /* --- Tables that are not the platform table --- */
  .table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .platform-table {
    min-width: 0;
    width: 100%;
  }

  /* Never hide data on mobile any more (v1 hid columns 4 and 5). */
  .platform-table th:nth-child(4),
  .platform-table td:nth-child(4),
  .platform-table th:nth-child(5),
  .platform-table td:nth-child(5) {
    display: table-cell;
  }

  /* --- Typography --- */
  .section-title {
    font-size: 1.45rem;
    line-height: 1.5;
  }

  .section-subtitle {
    font-size: 0.95rem;
  }

  /* --- Tool pages --- */
  .ts-tool-title {
    font-size: 1.5rem;
    line-height: 1.45;
  }

  .ts-calc-card {
    padding: 1.15rem;
  }

  .ts-calc-heading {
    font-size: 1.15rem;
  }

  .calc-result-box {
    padding: 1rem;
  }

  .calc-result-row {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    font-size: 0.9rem;
    padding: 0.35rem 0;
  }

  /* --- Footer --- */
  .footer-col {
    text-align: right;
  }

  .footer-links a,
  .footer-bottom-links a,
  .drawer-nav a {
    min-height: 44px;
    display: flex;
    align-items: center;
  }
}

/* =====================================================================
 * 4. SMALL PHONES (<=430px, iPhone 390px included)
 * =================================================================== */
@media (max-width: 430px) {
  .hero-stats {
    grid-template-columns: 1fr;
  }

  .hero-content h1 {
    font-size: 1.45rem;
  }

  .ts-tool-title {
    font-size: 1.32rem;
  }

  .container,
  .container-narrow {
    padding-left: 0.85rem;
    padding-right: 0.85rem;
  }

  .calc-title {
    font-size: 1.02rem;
  }

  .calc-badge {
    font-size: 0.68rem;
  }

  .ts-score-pill {
    font-size: 0.88rem;
  }
}

/* =====================================================================
 * 5. Landscape phones: keep the drawer scrollable
 * =================================================================== */
@media (max-height: 480px) and (max-width: 900px) {
  .mobile-drawer {
    overflow-y: auto;
  }
}
