/* SyzeAI shared mobile/responsive layer.
   Drop-in for landing, docs, playground, dashboard, admin, setup.
   Two breakpoints: 900 (tablet/phone), 480 (small phone) + landscape rule.
   Loaded AFTER per-page styles so it wins the cascade.
*/

:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

/* universal: kill horizontal page scroll caused by stray children */
html, body { max-width: 100%; overflow-x: hidden; }
* { -webkit-tap-highlight-color: rgba(255,255,255,0.06); }

/* ========================================================
   BREAKPOINT 1 — ≤ 900px (tablet + phone)
   ======================================================== */
@media (max-width: 900px) {

  /* iOS auto-zoom killer — anything <16px on input triggers zoom */
  input, textarea, select {
    font-size: 16px !important;
  }

  /* Top nav compactness — common pattern across pages */
  .nav {
    padding: 10px 14px !important;
    gap: 8px !important;
    flex-wrap: wrap !important;
  }
  /* If page has hamburger (#menuBtn), hide nav-links; otherwise let them scroll */
  body:has(#menuBtn) .nav-links {
    display: none !important;
  }
  body:not(:has(#menuBtn)) .nav-links {
    display: flex !important;
    gap: 10px !important;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    flex-wrap: nowrap !important;
    width: 100%;
    margin-top: 4px;
    padding-bottom: 2px;
  }
  body:not(:has(#menuBtn)) .nav-links::-webkit-scrollbar { display: none; }
  body:not(:has(#menuBtn)) .nav-links a {
    flex-shrink: 0;
    white-space: nowrap;
    font-size: 13px !important;
    padding: 6px 4px;
  }
  .menu-btn {
    display: flex !important;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    min-height: 40px;
  }
  .logo { font-size: 17px !important; }

  /* Layouts — kill multi-column on small screens */
  .layout,
  .stats-grid,
  .features,
  .feature-grid,
  .models,
  .model-list,
  .tiers,
  .pricing-grid,
  .auto-grid,
  [class*="grid-list"] {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }

  /* Containers: shrink padding */
  .container, .content, .hero, .balance-hero, .stats-grid {
    padding-left: 16px !important;
    padding-right: 16px !important;
    max-width: 100% !important;
  }

  /* Headings step down */
  h1 { font-size: 26px !important; line-height: 1.25 !important; }
  h2 { font-size: 20px !important; line-height: 1.3 !important; }
  h3 { font-size: 16px !important; line-height: 1.35 !important; }

  /* Hero-style massive h1 (landing page) — extra tame */
  .hero h1, .hero-title { font-size: 30px !important; }
  .hero p, .hero-sub  { font-size: 15px !important; }

  /* Code blocks: horizontal scroll, never wrap */
  pre {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
    font-size: 12px !important;
    padding: 12px 14px !important;
    border-radius: 8px;
  }
  pre code { white-space: pre; word-break: normal; }
  /* Inline code can wrap (long URLs, API keys) */
  p code, li code, td code, .lead code {
    word-break: break-word;
    font-size: 12px;
  }

  /* Tables — horizontal scroll wrapper (preserves mental model) */
  table {
    display: block !important;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    width: 100%;
    white-space: nowrap;
  }
  th, td { padding: 10px 12px !important; font-size: 12.5px !important; }

  /* Buttons: 40px min touch target */
  button, .btn, .btn-lg, .btn-login, .btn-send, .btn-logout, a.btn {
    min-height: 40px;
  }

  /* Sidebar drawer pattern */
  .sidebar {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    bottom: 0 !important;
    width: min(300px, 86vw) !important;
    z-index: 100 !important;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 4px 0 24px rgba(0,0,0,0.5);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-top: calc(16px + var(--safe-top)) !important;
    max-height: 100vh !important;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close { display: flex !important; align-items: center; justify-content: center; }
  body.sidebar-open { overflow: hidden; }

  /* Mobile overlay backdrop */
  .overlay, #overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.55);
    z-index: 90;
    opacity: 0;
    transition: opacity 0.2s ease;
  }
  .overlay.show, #overlay.show { display: block; opacity: 1; }

  /* Tabs/pills — horizontal scroll */
  .tabs, .pills {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap !important;
    scrollbar-width: none;
    margin-left: -4px;
    margin-right: -4px;
    padding: 0 4px;
  }
  .tabs::-webkit-scrollbar, .pills::-webkit-scrollbar { display: none; }
  .tabs > *, .pills > * { flex-shrink: 0; white-space: nowrap; }

  /* Flex children need min-width 0 to truly shrink */
  .chat-head-info, .msg-content, .bh-main, .bh-stat, .user-pill {
    min-width: 0;
  }

  /* Chat playground composer — iOS safe-area + 16px no-zoom */
  .composer {
    padding: 10px 12px calc(12px + var(--safe-bottom)) !important;
  }
  #promptInput {
    font-size: 16px !important;
    max-height: 140px;
  }
  .btn-send {
    padding: 10px 18px !important;
    min-width: 72px;
    min-height: 40px;
  }
  .composer-hint { display: none; }

  /* Dashboard balance-hero stack */
  .balance-hero {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }
  .bh-main { padding: 16px !important; }
  .bh-amount { font-size: 32px !important; }
  .bh-stats, .bh-stat-row {
    grid-template-columns: 1fr 1fr !important;
    gap: 8px !important;
  }
  .bh-stat-value { font-size: 18px !important; }

  /* docs endpoint blocks (long URLs) */
  .endpoint {
    font-size: 11.5px !important;
    padding: 10px 12px !important;
    word-break: break-all;
    overflow-wrap: anywhere;
  }

  /* Cards/feature padding */
  .feature, .tier, .stat, .card, .model-card {
    padding: 16px !important;
  }
}

/* ========================================================
   BREAKPOINT 2 — ≤ 480px (small phone)
   ======================================================== */
@media (max-width: 480px) {
  .container, .content, .hero { padding: 18px 14px !important; }
  h1 { font-size: 22px !important; }
  h2 { font-size: 18px !important; }
  h3 { font-size: 15px !important; }
  .hero h1, .hero-title { font-size: 26px !important; }
  body, p, li { font-size: 14px !important; }
  pre { font-size: 11.5px !important; padding: 10px 12px !important; }
  th, td { font-size: 12px !important; padding: 9px 10px !important; }
  .nav { padding: 9px 12px !important; }
  .logo { font-size: 16px !important; }
  .btn-lg { padding: 12px 22px !important; font-size: 14px !important; }
  .bh-amount { font-size: 28px !important; }
  .bh-stats, .bh-stat-row { grid-template-columns: 1fr !important; }
  .endpoint { font-size: 11px !important; }
  /* tighter card padding */
  .feature, .tier, .stat, .card, .model-card { padding: 14px !important; }
  .suggestions { grid-template-columns: 1fr !important; }
  /* sidebar tighter */
  .sidebar { width: min(280px, 90vw) !important; }
}

/* ========================================================
   LANDSCAPE phones — height is the constraint
   ======================================================== */
@media (max-height: 500px) and (max-width: 900px) {
  .composer {
    padding-top: 6px !important;
    padding-bottom: calc(6px + var(--safe-bottom)) !important;
  }
  #promptInput { max-height: 80px !important; }
  .empty-state { min-height: auto !important; padding-top: 16px !important; }
  .hero { padding-top: 24px !important; padding-bottom: 24px !important; }
}
