/* ===========================================================================
   mobile-app.css — the MaraponeAI app shell, for the site in a phone browser
   ---------------------------------------------------------------------------
   Someone who has not installed the app still ends up on marapone.com from a
   phone, and until now they got the desktop site shrunk: a drop-down menu taller
   than the screen inside a sticky nav (so its last rows, Account and the trial
   CTA, could not be reached at all), 24px tap rows, and a workspace laid out for
   a 27" display.

   This file gives those visitors the app's chrome instead — the sheet-style
   drawer, the 44pt targets, the fixed bottom tab bar — using the same tokens the
   Capacitor app uses (MARAPONE-APP/mobile/www/css/marapone.css). The palette is
   already shared, so nothing here re-colours the site; what changes is geometry.

   Two breakpoints, and nothing outside them:

     ≤1023px  the drawer. That is where the hamburger lives (`lg:hidden`), so
              tablets get the fix for the unreachable menu too.
     ≤767px   the app shell proper — tab bar, app header, card rows. A phone.

   Desktop is deliberately untouched: there is not one rule in this file outside
   a max-width media query.
   =========================================================================== */

:root {
  /* Measured from the real nav by mobile-app.js — the fallback is only what the
     drawer uses for the frame before that first measurement lands. */
  --mp-nav-h: 61px;
  --mp-tabbar-h: 56px;
  --mp-tap: 44px;
  --mp-safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ═══════════════════════════════════════════════════════════════════════════
   1. The drawer  (≤1023px)
   ═══════════════════════════════════════════════════════════════════════════
   The bug this replaces: #mobile-menu was an ordinary block inside a
   `sticky top-0` nav. Once the menu made that nav taller than the viewport, the
   overflow had nowhere to go — a sticky box does not scroll its own overflow and
   the page cannot scroll it either, so every row past the fold, Account and
   "Start Free 7-Day Trial" included, was simply unreachable.

   It is now a fixed sheet under the nav bar with its own scroll region, and the
   two things you actually came to tap are pinned to the bottom of it so they
   never depend on scrolling at all.

   The sheet is only fixed to the viewport because mobile-app.js moves the node
   out to <body> first. Left inside the nav it is fixed to *the nav*: an ancestor
   with `backdrop-filter` (the nav's `backdrop-blur`) becomes the containing
   block for fixed descendants, so `top: 61px; bottom: 0` resolved against a
   61px-tall box and the drawer opened with zero height.

   Hence `.mp-drawer` on every selector below — the class JS adds when it makes
   the move. It also outranks the `#mobile-menu a` rules the pages carry in their
   own <style> blocks, which would otherwise win on source order. */

@media (max-width: 1023px) {

  #mobile-menu.mp-drawer {
    position: fixed;
    top: var(--mp-nav-h);
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 60;
    margin: 0;
    /* src/tailwind.css caps this at `100vh - 4.5rem` — the earlier attempt at
       the same bug, and the fallback when this file's JS never runs. On a sheet
       that already spans nav-to-bottom it only clips 11px off the end. */
    max-height: none;
    padding: 0.5rem 1rem 0;
    background: #131313;
    /* The scroll region. `overscroll-behavior: contain` is what stops a flick
       past the last row from scrolling the page underneath the open menu. */
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    gap: 0;
  }

  /* The sheet takes focus when it opens so the keyboard follows it; it is a
     container, not a control, and should not draw a ring for that. */
  #mobile-menu.mp-drawer:focus { outline: none; }

  /* Rows carry their own height now, so the wrapper's `gap-3` would double it. */
  #mobile-menu.mp-drawer > a,
  #mobile-menu.mp-drawer > .mp-drawer-actions > a {
    display: flex;
    align-items: center;
    min-height: var(--mp-tap);
    padding-top: 0.35rem;
    padding-bottom: 0.35rem;
    border-radius: 8px;
    -webkit-tap-highlight-color: rgba(249, 115, 22, 0.14);
  }

  #mobile-menu.mp-drawer > a:active { background: #1a1a1a; }

  #mobile-menu.mp-drawer > p {
    padding-top: 0.9rem;
    padding-bottom: 0.2rem;
    margin: 0;
  }

  /* The pinned footer. `margin-top: auto` seats it at the bottom of a short
     menu; `position: sticky` keeps it there when the list is long enough to
     scroll. Either way Account and the trial are on screen the moment the
     drawer opens, which is the whole point. */
  #mobile-menu.mp-drawer .mp-drawer-actions {
    position: sticky;
    bottom: 0;
    margin-top: auto;
    display: grid;
    gap: 0.5rem;
    padding: 0.75rem 0 calc(0.75rem + var(--mp-safe-bottom));
    background: linear-gradient(to bottom, rgba(19, 19, 19, 0.75), #131313 22%);
    border-top: 1px solid #232323;
  }

  #mobile-menu.mp-drawer .mp-drawer-actions > a {
    justify-content: center;
    min-height: 48px;
    text-align: center;
  }

  /* The account row reads as the secondary action: outlined, not filled. */
  #mobile-menu.mp-drawer .mp-drawer-actions > a.mp-drawer-secondary {
    border: 1px solid #323232;
    color: #f1f1f1;
    font-weight: 600;
  }

  /* While the sheet is open the page behind it must not scroll — otherwise
     closing the menu drops you somewhere you never navigated to. */
  html.mp-drawer-open,
  html.mp-drawer-open body {
    overflow: hidden;
    /* iOS Safari ignores overflow:hidden on <body> alone in some versions. */
    touch-action: none;
  }

  /* Two navigations on screen at once is noise; the drawer is the navigation
     while it is open — and nothing floats over it either. */
  html.mp-drawer-open .mp-tabbar { display: none; }

  html.mp-drawer-open #sticky-cta,
  html.mp-drawer-open #mp-wa-btn {
    display: none !important;
  }
}

/* ═══════════════════════════════════════════════════════════════════════════
   2. The tab bar  (≤767px)
   ═══════════════════════════════════════════════════════════════════════════
   Lifted from the app's `.tabbar`: fixed, blurred, four items, safe-area inset
   below. On the site the four are Home · Programs · Plans · Account, and the
   last one is the reason it exists — signing in stops being a thing you have to
   find at the bottom of a menu. */

@media (max-width: 767px) {

  .mp-tabbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 50;
    display: flex;
    padding-bottom: var(--mp-safe-bottom);
    background: rgba(20, 20, 22, 0.88);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-top: 1px solid #232323;
  }

  .mp-tab {
    flex: 1;
    height: var(--mp-tabbar-h);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    background: none;
    border: 0;
    color: #92929a;
    font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
    transition: color 0.15s ease;
  }

  .mp-tab svg {
    width: 22px;
    height: 22px;
    display: block;
  }

  .mp-tab:active { color: #f1f1f1; }
  .mp-tab.is-active { color: #f97316; }

  /* Reserve the bar's height at the end of the document so a fixed footer CTA
     is never the thing it covers. Set by JS, so a page that fails to build a
     bar is not left with a phantom gap. */
  html.mp-has-tabbar body {
    padding-bottom: calc(var(--mp-tabbar-h) + var(--mp-safe-bottom));
  }

  /* The two things already floating in that corner get out of the way rather
     than being covered: the trial bar (construction/index.html) and the
     WhatsApp button (public/widgets.js). The `!important` is only for the
     WhatsApp one — widgets.js injects its rule into <head> at runtime, so it
     lands after this file and would otherwise win the tie on source order. */
  html.mp-has-tabbar #sticky-cta {
    bottom: calc(var(--mp-tabbar-h) + var(--mp-safe-bottom) + 0.75rem);
  }

  html.mp-has-tabbar #mp-wa-btn {
    bottom: calc(var(--mp-tabbar-h) + var(--mp-safe-bottom) + 0.75rem) !important;
  }

  /* The homepage's full-width mobile trial bar. Same stacking context and the
     same z-index as the tab bar, so without this it simply loses to whichever
     came last in the DOM — which is the tab bar — and disappears. It sits on
     top of the bar instead, and gives up its safe-area padding: the tab bar
     underneath is now the thing clearing the home indicator. */
  html.mp-has-tabbar a.fixed.bottom-0.inset-x-0 {
    bottom: calc(var(--mp-tabbar-h) + var(--mp-safe-bottom));
    padding-bottom: 0.875rem !important;
  }

  html.mp-has-tabbar body:has(a.fixed.bottom-0.inset-x-0) {
    padding-bottom: calc(var(--mp-tabbar-h) + var(--mp-safe-bottom) + 3.25rem);
  }

  /* On a page carrying that bar, the floating pill is the same offer a second
     time, in the same corner, one layer up. The bar is the phone pattern; the
     pill is the desktop one, and it stands down here. The WhatsApp button
     climbs above the bar instead of sitting on it. */
  html.mp-has-tabbar body:has(a.fixed.bottom-0.inset-x-0) #sticky-cta {
    display: none;
  }

  html.mp-has-tabbar body:has(a.fixed.bottom-0.inset-x-0) #mp-wa-btn {
    bottom: calc(var(--mp-tabbar-h) + var(--mp-safe-bottom) + 4rem) !important;
  }


  /* ── The programs sheet ───────────────────────────────────────────────────
     The app's Tools tab, as a bottom sheet. It is the same five programs the
     desktop nav lists under Products; on a phone they are rows you can hit. */

  .mp-sheet-backdrop {
    position: fixed;
    inset: 0;
    z-index: 70;
    background: rgba(0, 0, 0, 0.55);
    opacity: 0;
    transition: opacity 0.18s ease;
  }

  .mp-sheet-backdrop.is-open { opacity: 1; }

  .mp-sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 71;
    max-height: 82vh;
    max-height: 82svh;
    overflow-y: auto;
    overscroll-behavior: contain;
    background: #1a1a1a;
    border-top: 1px solid #323232;
    border-radius: 18px 18px 0 0;
    padding: 0.5rem 1rem calc(1rem + var(--mp-safe-bottom));
    box-shadow: 0 -24px 64px rgba(0, 0, 0, 0.7);
    transform: translateY(100%);
    transition: transform 0.22s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  }

  .mp-sheet.is-open { transform: translateY(0); }

  /* Same treatment the drawer gets: the page under an open sheet holds still,
     and nothing floats on top of it. */
  html.mp-sheet-open,
  html.mp-sheet-open body {
    overflow: hidden;
    touch-action: none;
  }

  html.mp-sheet-open #sticky-cta,
  html.mp-sheet-open #mp-wa-btn {
    display: none !important;
  }

  .mp-sheet-grip {
    width: 36px;
    height: 4px;
    border-radius: 999px;
    background: #3c3c3c;
    margin: 0.5rem auto 0.75rem;
  }

  .mp-sheet-title {
    font-family: 'DM Mono', monospace;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.16em;
    color: #949494;
    padding: 0 0.25rem 0.5rem;
  }

  .mp-sheet-row {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    min-height: var(--mp-tap);
    padding: 0.7rem 0.5rem;
    border-radius: 10px;
    text-decoration: none;
    -webkit-tap-highlight-color: rgba(249, 115, 22, 0.14);
  }

  .mp-sheet-row:active { background: #232323; }
  .mp-sheet-row + .mp-sheet-row { border-top: 1px solid #232323; border-radius: 10px; }

  .mp-sheet-row .mp-sheet-label {
    display: block;
    color: #f1f1f1;
    font-size: 15px;
    font-weight: 600;
    line-height: 1.25;
  }

  .mp-sheet-row .mp-sheet-sub {
    display: block;
    color: #949494;
    font-size: 12px;
    margin-top: 2px;
  }

  .mp-sheet-row .mp-sheet-chev {
    margin-left: auto;
    color: #6c6c6c;
    flex: none;
  }
}

/* ═══════════════════════════════════════════════════════════════════════════
   3. Signed-in surfaces  (≤767px)
   ═══════════════════════════════════════════════════════════════════════════
   /dashboard, /account and /app are the parts of the site that are software
   rather than argument, so on a phone they get the app's shape: one column of
   full-width cards, a blurred sticky header, 44pt rows, 16px form text (below
   which iOS zooms the whole page on focus and never zooms back). */

@media (max-width: 767px) {

  /* ── Type: the app's phone scale, not the desktop site's ─────────────── */

  body.mp-app-surface .font-display.text-5xl,
  body.mp-app-surface .font-display.text-6xl {
    font-size: 2.5rem;
    line-height: 1;
  }

  body.mp-app-surface h2.font-display.text-3xl {
    font-size: 1.6rem;
  }

  /* ── Cards ────────────────────────────────────────────────────────────── */

  /* A tile at 20px padding inside a 16px gutter leaves a phone card 40px of its
     own width to say anything in. Full-bleed, and the rows breathe instead. */
  body.mp-app-surface main {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
    padding-top: 1.5rem;
  }

  body.mp-app-surface .tile {
    border-radius: 14px;
  }

  /* Program tiles become app rows: title and state on one line, blurb under,
     the whole card a 44pt+ target. */
  body.mp-app-surface #program-grid,
  body.mp-app-surface #packs-grid {
    gap: 0.6rem;
  }

  body.mp-app-surface #program-grid .tile,
  body.mp-app-surface #packs-grid .tile {
    padding: 1rem 1rem 1.1rem;
  }

  body.mp-app-surface #program-grid .tile h3 {
    font-size: 1.4rem;
  }

  body.mp-app-surface #program-grid a.tile:active {
    border-color: #f97316;
    background: #202020;
  }

  /* The hover lift is a pointer affordance; on a touch screen it only ever
     fires as a jump after the tap has already navigated. */
  body.mp-app-surface a.tile:hover {
    transform: none;
  }

  /* ── Forms ────────────────────────────────────────────────────────────── */

  body.mp-app-surface .field {
    font-size: 16px;          /* below 16px iOS zooms on focus */
    min-height: var(--mp-tap);
    padding: 0.75rem 0.85rem;
    border-radius: 10px;
  }

  body.mp-app-surface .code-field {
    font-size: 1.25rem;
    letter-spacing: 0.4em;
  }

  /* Buttons in the app are full-width and thumb-height at the bottom of a
     card, rather than inline chips sized to their text. */
  body.mp-app-surface form button[type="submit"],
  body.mp-app-surface .mp-primary-action {
    min-height: 48px;
  }

  /* ── The settings sub-tabs ────────────────────────────────────────────── */

  /* Four tabs across a 360px screen wrap into a stack and stop reading as
     tabs. Kept on one line, scrolled sideways, the way an app does it. */
  body.mp-app-surface [role="tablist"] {
    display: flex;
    gap: 1.1rem;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  body.mp-app-surface [role="tablist"]::-webkit-scrollbar { display: none; }

  body.mp-app-surface .subtab {
    min-height: var(--mp-tap);
    font-size: 0.9rem;
  }

  /* ── Dashboard nav ────────────────────────────────────────────────────── */

  /* The account menu is a 256px dropdown pinned to the right edge; on a phone
     it becomes a sheet across the full width, which is both reachable and the
     way the app shows the same list. */
  body.mp-app-surface #account-menu {
    position: fixed;
    top: auto;
    left: 0.5rem;
    right: 0.5rem;
    bottom: calc(var(--mp-tabbar-h) + var(--mp-safe-bottom) + 0.5rem);
    width: auto;
    max-height: 70vh;
    max-height: 70svh;
    overflow-y: auto;
    overscroll-behavior: contain;
    border-radius: 14px;
  }

  body.mp-app-surface #account-menu a,
  body.mp-app-surface #account-menu button {
    min-height: var(--mp-tap);
    display: flex;
    align-items: center;
    font-size: 0.95rem;
  }

  /* ── /app — the program runner ────────────────────────────────────────── */

  /* The rail is a 240px column beside the work; on a phone it is a strip of
     chips above it, and the two panes stack instead of sitting side by side. */
  body.mp-workspace #workspace {
    display: block;
    padding-bottom: calc(var(--mp-tabbar-h) + var(--mp-safe-bottom));
  }

  body.mp-workspace #workspace > aside {
    width: auto;
    border-right: 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    position: sticky;
    top: 0;
    z-index: 30;
    background: rgba(19, 19, 19, 0.92);
    backdrop-filter: saturate(180%) blur(18px);
    -webkit-backdrop-filter: saturate(180%) blur(18px);
  }

  body.mp-workspace #program-rail {
    display: flex;
    gap: 0.4rem;
    padding: 0.5rem 0.75rem;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  body.mp-workspace #program-rail::-webkit-scrollbar { display: none; }

  body.mp-workspace #program-rail > * {
    flex: none;
    white-space: nowrap;
    min-height: 38px;
    display: flex;
    align-items: center;
    border: 1px solid #323232;
    border-radius: 999px;
    padding: 0 0.85rem;
  }

  body.mp-workspace #workspace > aside > div:last-child { display: none; }

  body.mp-workspace #workspace main > div.grid {
    display: block;
  }

  body.mp-workspace #workspace main > div.grid > section {
    border-right: 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  }

  body.mp-workspace #op-list > * {
    min-height: var(--mp-tap);
  }

  body.mp-workspace #result,
  body.mp-workspace #console {
    font-size: 12px;
    /* `white-space: pre` on a phone is a horizontal scroll through a result
       nobody can read; wrapping keeps the line breaks that matter. */
    white-space: pre-wrap;
    word-break: break-word;
  }
}
