/* ==========================================================================
   FreightTerms.co.uk — Mobile-First Patches
   Loads after each page's inline <style> block
   Last updated: 2026-06-19
   ========================================================================== */

/* ---------- Universal safety: prevent iOS rotation text-resize + horizontal scroll ---------- */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

html, body {
  max-width: 100%;
  overflow-x: hidden;
}

/* Break long words in body content so they never burst containers */
p, li, td, .term-def, .help-text, .calc-result {
  word-wrap: break-word;
  overflow-wrap: break-word;
}

/* Break long URLs gracefully */
a {
  word-break: break-word;
}

/* ---------- Header: safe-area-inset support (iPhone notch / landscape) ---------- */
header {
  padding-left: max(2rem, env(safe-area-inset-left)) !important;
  padding-right: max(2rem, env(safe-area-inset-right)) !important;
}

/* ---------- Hamburger button (injected by mobile.js) ---------- */
.menu-toggle {
  display: none;
  background: transparent;
  border: 1px solid #243d55;
  color: #f5f0e8;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  width: 44px;
  height: 44px;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  -webkit-tap-highlight-color: transparent;
  font-family: inherit;
  flex-shrink: 0;
}
.menu-toggle:hover, .menu-toggle:focus-visible {
  border-color: #f0a500;
  color: #f0a500;
  outline: none;
}

/* ============================================================
   MOBILE LAYOUT (≤768px) — the main fixes
   ============================================================ */
@media (max-width: 768px) {

  /* --- Header: show hamburger, hide inline nav by default --- */
  header {
    padding-left: 1rem !important;
    padding-right: 1rem !important;
  }
  header nav {
    display: none !important;
  }
  .menu-toggle {
    display: flex !important;
  }

  /* Mobile drawer: nav.mobile-open is added by mobile.js on toggle */
  header nav.mobile-open {
    display: flex !important;
    position: fixed;
    top: 64px;
    left: 0;
    right: 0;
    background: #0d1b2a;
    border-bottom: 1px solid #243d55;
    flex-direction: column;
    padding: 0.5rem 1.25rem 1rem;
    gap: 0;
    z-index: 99;
    max-height: calc(100vh - 64px);
    max-height: calc(100dvh - 64px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
  }
  header nav.mobile-open a {
    padding: 0.9rem 0 !important;
    border-bottom: 1px solid #243d55;
    font-size: 0.85rem !important;
    min-height: 44px;
    display: flex;
    align-items: center;
    letter-spacing: 0.08em;
  }
  header nav.mobile-open a:last-child {
    border-bottom: none;
  }

  /* Logo scales down */
  .logo {
    font-size: 1.05rem !important;
  }

  /* --- Body type / spacing --- */
  body {
    font-size: 15px;
  }

  /* Heroes: tighten padding so users see content faster */
  .page-hero {
    padding: 2.5rem 1rem 2rem !important;
  }
  .hero {
    padding: 3rem 1rem 2rem !important;
  }

  /* Container padding */
  .container,
  .glossary-container,
  .page-wrap {
    padding-left: 1rem !important;
    padding-right: 1rem !important;
  }

  /* --- Touch target minimums (Apple HIG 44x44pt) --- */
  button,
  .calc-btn,
  .mode-btn,
  .unit-btn,
  .menu-toggle {
    min-height: 44px;
  }

  /* Sidebar links: increase tap area */
  .sidebar-links a {
    padding: 0.85rem 0 !important;
    min-height: 44px;
    display: flex;
    align-items: center;
  }
  .alpha-nav a {
    width: 1.85rem !important;
    height: 1.85rem !important;
    line-height: 1.85rem !important;
    font-size: 0.72rem !important;
  }

  /* --- Forms: prevent iOS auto-zoom on focus by using 16px font --- */
  input[type="text"],
  input[type="number"],
  input[type="email"],
  input[type="search"],
  select,
  textarea {
    font-size: 16px !important;
    min-height: 44px;
  }

  /* --- Tables: horizontal scroll wrappers --- */
  .matrix-wrap,
  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-left: -1rem;
    margin-right: -1rem;
    padding-left: 1rem;
    padding-right: 1rem;
  }

  /* Standalone tables inside main: make them horizontally scrollable */
  main table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: normal;
    min-width: 100%;
  }
  main table thead,
  main table tbody {
    display: table;
    width: 100%;
    min-width: 480px;
  }

  /* --- Calculators --- */
  .calc-fields {
    grid-template-columns: 1fr 1fr !important;
  }
  .calc-grid {
    grid-template-columns: 1fr !important;
  }
  .calc-fields-2 {
    grid-template-columns: 1fr !important;
  }
  .calc-btn {
    grid-column: 1 / -1;
    width: 100%;
  }
  .pva-compare {
    grid-template-columns: 1fr !important;
  }

  /* --- Alpha nav: tighter on mobile --- */
  .alpha-nav {
    padding-left: 1rem !important;
    padding-right: 1rem !important;
    gap: 0.3rem !important;
  }

  /* --- Sidebar: stack below main --- */
  .sidebar {
    position: static !important;
  }

  /* --- Breadcrumb: better wrapping --- */
  .breadcrumb {
    padding-left: 1rem !important;
    padding-right: 1rem !important;
    line-height: 1.7;
  }

  /* --- Ad slots: scale gracefully --- */
  .ad-leaderboard {
    max-width: calc(100% - 2rem) !important;
    height: 60px !important;
    margin-left: auto !important;
    margin-right: auto !important;
  }
  .ad-rect {
    width: 100% !important;
    max-width: 300px;
    margin-left: auto !important;
    margin-right: auto !important;
  }

  /* --- Footer: better readability + tappable spacing on links --- */
  footer {
    padding: 1.5rem 1rem !important;
    font-size: 0.78rem;
    line-height: 1.9;
  }
  footer a {
    display: inline-block;
    padding: 0.15rem 0.2rem;
  }

  /* --- Term cards: tighter padding --- */
  .term-card {
    padding: 1.05rem 0;
  }
  .term-name {
    font-size: 0.97rem;
  }

  /* --- Section letters in glossary: smaller --- */
  .section-letter {
    font-size: 2.2rem !important;
  }

  /* --- Tip boxes: tighter --- */
  .tip-box {
    padding: 1rem 1.2rem !important;
  }

  /* --- Verdict boxes --- */
  .verdict-box {
    padding: 1.2rem 1.3rem !important;
  }

  /* --- Compare grid (2-up): stack on mobile --- */
  .compare-grid {
    grid-template-columns: 1fr !important;
  }
  .credential-grid {
    grid-template-columns: 1fr !important;
  }

  /* --- Incoterm hub: keep inco-row readable --- */
  .inco-row {
    grid-template-columns: 60px 1fr !important;
  }
  .inco-risk,
  .inco-modes {
    display: none !important;
  }

}

/* ============================================================
   EXTRA-SMALL (≤375px — iPhone SE, mini)
   ============================================================ */
@media (max-width: 375px) {
  .logo {
    font-size: 0.95rem !important;
  }
  h1 {
    font-size: 1.6rem !important;
  }
  .container,
  .glossary-container,
  .page-wrap {
    padding-left: 0.75rem !important;
    padding-right: 0.75rem !important;
  }
  .page-hero {
    padding: 2rem 0.75rem 1.5rem !important;
  }
  .alpha-nav a {
    width: 1.65rem !important;
    height: 1.65rem !important;
    line-height: 1.65rem !important;
    font-size: 0.65rem !important;
  }
  .calc-fields {
    grid-template-columns: 1fr !important;
  }
}

/* ============================================================
   LANDSCAPE iPhone — avoid notch occlusion
   ============================================================ */
@media (max-width: 932px) and (orientation: landscape) {
  header {
    padding-left: max(2rem, env(safe-area-inset-left)) !important;
    padding-right: max(2rem, env(safe-area-inset-right)) !important;
  }
  header nav.mobile-open {
    padding-left: max(1.25rem, env(safe-area-inset-left));
    padding-right: max(1.25rem, env(safe-area-inset-right));
  }
}

/* ============================================================
   ACCESSIBILITY: keyboard focus rings, contrast safety
   ============================================================ */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid #f0a500;
  outline-offset: 2px;
}

/* Reduce motion preference */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ============================================================
   SEARCH UX: hide no-results before any search performed
   ============================================================ */
.no-results {
  display: none;
}
.no-results.is-visible {
  display: block;
}


/* ============================================================
   ADSENSE PLACEHOLDER CLEANUP
   Hide "Advertisement" placeholder boxes until real ad code is placed.
   Once <ins class="adsbygoogle"> or <iframe> renders inside, box shows.
   Prevents AdSense reviewers seeing empty placeholder text and misjudging.
   ============================================================ */
.ad-slot:not(:has(ins, iframe, img)) {
  display: none !important;
}

/* ============================================================
   CONTENT ELEMENT PATCHES
   .field-note provides styled practical example boxes inside content.
   .reader-path is used on the homepage.
   ============================================================ */
.field-note,
.reader-path {
  max-width: 860px;
  margin: 1.25rem auto;
  padding: 1rem 1.25rem;
  background: #1a2d42;
  border: 1px solid #243d55;
  color: #ddd8ce;
  font-size: 0.84rem;
  line-height: 1.65;
}
.field-note strong,
.reader-path strong {
  color: #f5f0e8;
}
.field-note a,
.reader-path a {
  color: #c4841a;
}
h2.section-tag,
h2.matrix-title {
  display: block;
}
.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}
@media (max-width: 768px) {
  .field-note,
  .reader-path {
    margin: 1rem;
    padding: 1rem;
  }
}
