/* ============================================================
   assets/css/mobile.css — SmartSwap full mobile stylesheet
   Covers all app + admin pages. No horizontal scrolling.
   Breakpoints: 768px (tablet), 480px (phone)
   ============================================================ */

/* ── 1. ELEMENTS HIDDEN/SHOWN ON DESKTOP vs MOBILE ─────── */

/* Mobile topbar — hidden on desktop, shown on mobile */
.mobile-topbar,
.admin-mobile-topbar { display: none; }

/* (sidebar-hamburger removed — backdrop tap and Escape close the panel) */

/* ── 2. SIDEBAR — OVERLAY PATTERN ───────────────────────── */
@media (max-width: 768px) {

  body.nav-open { overflow: hidden; }

  .app-layout,
  .admin-layout {
    flex-direction: column;
    position: relative;
  }

  /* Sidebar slides in from left as overlay */
  .sidebar {
    position: fixed;
    top: 0; left: 0;
    width: 270px;
    height: 100%;
    transform: translateX(-100%);
    transition: transform 0.25s cubic-bezier(0.4,0,0.2,1);
    z-index: 900;
    overflow-y: auto;
    box-shadow: none;
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: 6px 0 32px rgba(0,0,0,0.22);
  }

  /* Scrim backdrop */
  .nav-backdrop {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 899;
  }
  .nav-backdrop.visible { display: block; }

  /* Mobile topbar — sticky at top, below sidebar z-index */
  .mobile-topbar,
  .admin-mobile-topbar {
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    height: 56px;
    background: var(--c-surface);
    border-bottom: 1px solid var(--c-border2);
    position: sticky;
    top: 0;
    z-index: 800;
    flex-shrink: 0;
    order: -1; /* ensure topbar renders before main content */
  }
  .admin-mobile-topbar {
    background: #1C1B18 !important;
    border-bottom-color: rgba(255,255,255,0.06) !important;
  }
  .mobile-topbar-logo {
    font-family: var(--font-serif);
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--c-text);
    text-decoration: none;
  }
  .mobile-topbar-logo span { color: var(--c-accent); }
  .admin-mobile-topbar .mobile-topbar-logo { color: #fff !important; }
  .admin-mobile-topbar .mobile-topbar-logo span { color: #40916C !important; }

  .mobile-hamburger {
    width: 40px; height: 40px;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    gap: 5px; cursor: pointer;
    background: none; border: none; padding: 4px;
  }
  .mobile-hamburger span {
    display: block;
    width: 22px; height: 2px;
    background: var(--c-text2);
    border-radius: 2px;
  }
  .admin-mobile-topbar .mobile-hamburger span { background: rgba(255,255,255,0.65); }

  /* Main content — full width, no overflow */
  .app-main,
  .admin-main {
    width: 100%;
    padding: 14px 14px 24px;
    min-width: 0;
    overflow-x: hidden;
  }

  .sidebar-section { display: block; }
  .sidebar-link {
    padding: 11px 20px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

/* ── 3. PAGE HEADERS ─────────────────────────────────────── */
@media (max-width: 768px) {
  .app-header,
  .admin-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 16px;
  }
  .app-header h1,
  .admin-header h1 { font-size: 1.4rem; }
  .admin-sub { font-size: 12px; }
  .admin-header > .btn,
  .admin-header > a.btn { align-self: flex-start; }
}

/* ── 4. KPI GRIDS ────────────────────────────────────────── */
@media (max-width: 768px) {
  .admin-kpi-grid,
  .stats-grid {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }
}
@media (max-width: 360px) {
  .admin-kpi-grid,
  .stats-grid { grid-template-columns: 1fr; }
}

/* ── 5. CARDS ────────────────────────────────────────────── */
@media (max-width: 768px) {
  .card, .admin-card { padding: 14px 16px; border-radius: 12px; }
  .admin-grid-2 { grid-template-columns: 1fr !important; }
}

/* ── 6. DASHBOARD ────────────────────────────────────────── */
@media (max-width: 768px) {
  .dashboard-actions { grid-template-columns: 1fr !important; gap: 8px; }
  .dashboard-actions .admin-card { padding: 10px 6px; }
  .dashboard-actions .admin-card > a > div > div:first-child { font-size: 20px; }
}
@media (max-width: 400px) {
  .dashboard-actions { grid-template-columns: 1fr !important; }
}

/* ── 7. BREATHWORK ───────────────────────────────────────── */
@media (max-width: 768px) {
  .breathwork-layout {
    grid-template-columns: 1fr !important;
    gap: 16px;
  }
  .breathwork-sidebar {
    min-width: 0;
    width: 100%;
  }
  .technique-selector { grid-template-columns: repeat(2,1fr) !important; gap: 8px; }
  #breathCanvas { width: 220px !important; height: 220px !important; }
}

/* ── 8. MEDITATION ───────────────────────────────────────── */
@media (max-width: 768px) {
  .meditation-layout { grid-template-columns: 1fr !important; }
  #meditationTimer { font-size: 3.2rem !important; }
}

/* ── 9. BREATH HOLD ──────────────────────────────────────── */
@media (max-width: 768px) {
  .breathhold-layout { grid-template-columns: 1fr !important; }
}

/* ── 10. MOOD LOG ────────────────────────────────────────── */
@media (max-width: 768px) {
  .mood-layout { grid-template-columns: 1fr !important; }
}

/* ── 11. GUT TRACKER ─────────────────────────────────────── */
@media (max-width: 768px) {
  .gut-layout { grid-template-columns: 1fr !important; }
  .gut-inputs-2col,
  .gut-sliders-3col { grid-template-columns: 1fr !important; }
}

/* ── 12. SLEEP SCORE ─────────────────────────────────────── */
@media (max-width: 768px) {
  /* Results two-col grid → stack (targets inline style) */
  .sleep-results-grid { grid-template-columns: 1fr !important; }
  .toggle-grid { grid-template-columns: 1fr !important; }
  .step-nav { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .step-pill { font-size: 10px; padding: 8px 4px; min-width: 52px; flex-shrink: 0; }
  .step-pill .num { font-size: 14px; }
  .score-ring { width: 150px; height: 150px; }
  .score-ring canvas { width: 150px !important; height: 150px !important; }
  .score-num { font-size: 2.2rem; }
  /* Domain bars readable on mobile */
  .domain-bar-row .top { flex-wrap: wrap; gap: 2px; }
  /* Swap reco cards */
  .swap-reco { padding: 14px 14px; }
}

/* ── 13. LEADERBOARD ─────────────────────────────────────── */
@media (max-width: 768px) {
  .lb-tabs { overflow-x: auto; white-space: nowrap; gap: 0; }
  .lb-tab { font-size: 13px; padding: 10px 14px; }
  /* All grid panels → 1 col */
  #tab-rankings > div,
  #tab-trending > div { grid-template-columns: 1fr !important; }
  .lb-row { gap: 8px; padding: 10px 12px; }
}

/* ── 14. SMARTSWAP FEED ──────────────────────────────────── */
@media (max-width: 768px) {
  .swap-comparison-grid { grid-template-columns: 1fr !important; }
  .swap-arrow-col { transform: rotate(90deg); text-align: center; padding: 4px 0; }
  .swap-detail-grid { grid-template-columns: 1fr !important; }
}

/* ── 15. GUIDE PAGE ──────────────────────────────────────── */
@media (max-width: 600px) {
  .guide-module-grid { grid-template-columns: 1fr !important; }
  .guide-hero { padding: 20px 0; }
  .guide-step-header { padding: 14px 16px; gap: 10px; }
  .guide-step-body { padding: 0 16px 18px; }
}

/* ── 16. SETTINGS & SUBSCRIPTION ────────────────────────── */
@media (max-width: 768px) {
  .settings-layout { grid-template-columns: 1fr !important; }
  .subscription-layout { grid-template-columns: 1fr !important; }
  .payments-table th:nth-child(2),
  .payments-table td:nth-child(2) { display: none; }
}

/* ── 17. ABOUT PAGE ──────────────────────────────────────── */
@media (max-width: 600px) {
  .principle-grid { grid-template-columns: 1fr !important; }
  .about-nav { padding: 0 14px; }
  .about-wrap { padding: 0 16px; }
  .about-hero { padding: 28px 0; }
  .about-section { padding: 32px 0; }
}

/* ── 19. ADMIN TABLES ────────────────────────────────────── */
@media (max-width: 768px) {
  /* Wrap table in scrollable container */
  .admin-card .admin-table-full {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  /* Hide lower-priority columns in user/module tables */
  .admin-table-full th:nth-child(5),
  .admin-table-full td:nth-child(5),
  .admin-table-full th:nth-child(6),
  .admin-table-full td:nth-child(6) {
    display: none;
  }
  /* Action button groups wrap */
  .admin-table td > div { flex-wrap: wrap; gap: 4px; }
}
@media (max-width: 600px) {
  .admin-card .admin-table,
  .card .admin-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* ── 20. FORMS ───────────────────────────────────────────── */
@media (max-width: 768px) {
  .form-input,
  select.form-input,
  textarea.form-input {
    font-size: 16px; /* Prevents iOS zoom */
  }
  .form-btn-row { flex-direction: column; }
  .form-btn-row .btn { width: 100%; }
}

/* ── 21. MODALS — SHEET PATTERN ON MOBILE ────────────────── */
@media (max-width: 600px) {
  /* Session complete / mood / breathwork modals → bottom sheet */
  #moodModal,
  #reflectModal {
    align-items: flex-end !important;
    padding: 0 !important;
  }
  #moodModal > .modal-inner,
  #reflectModal > .card {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    border-radius: 20px 20px 0 0 !important;
    max-height: 90vh;
    overflow-y: auto;
    padding-bottom: calc(20px + env(safe-area-inset-bottom, 0));
  }
  /* Tour stays centred */
  .tour-overlay { padding: 12px !important; }
  .tour-card { max-height: 88vh; overflow-y: auto; }
  .tour-header,
  .tour-body,
  .tour-footer { padding-left: 18px; padding-right: 18px; }
  .tour-title { font-size: 1.2rem; }
  .tour-module-grid { grid-template-columns: 1fr !important; }
}

/* ── 22. TOUCH TARGETS ───────────────────────────────────── */
@media (max-width: 768px) {
  .btn,
  .preset-btn,
  .sidebar-link,
  .opt-btn { min-height: 44px; }
  .toggle-item { min-height: 48px; }
  .preset-btn {
    display: flex;
    align-items: center;
    justify-content: center;
  }
  input[type=range] { height: 44px; }
  input[type=range]::-webkit-slider-thumb { width: 26px; height: 26px; }
  input[type=range]::-moz-range-thumb { width: 26px; height: 26px; }
}

/* ── 23. TYPOGRAPHY ──────────────────────────────────────── */
@media (max-width: 480px) {
  .stat-value,
  .kpi-value { font-size: 1.5rem !important; }
  h1 { font-size: 1.35rem; }
  h2 { font-size: 1.2rem; }
  .admin-card-title { font-size: 11px; }
}

/* ── 24. PWA / SAFE AREA ─────────────────────────────────── */
@supports (padding: env(safe-area-inset-bottom)) {
  .mobile-topbar,
  .admin-mobile-topbar {
    padding-top: env(safe-area-inset-top, 0);
    height: calc(56px + env(safe-area-inset-top, 0));
  }
  .sidebar {
    padding-top: env(safe-area-inset-top, 0);
  }
  .app-main,
  .admin-main {
    padding-bottom: calc(20px + env(safe-area-inset-bottom, 0));
  }
}
