/* =============================================================
   VEEDAY CONSULTANTS — mobile.css  (round 11: the phone layer)
   Loaded LAST on every page, after the page's own CSS. Pairs with js/mobile.js.

   "Phone" is exactly this query, everywhere (CSS and JS):
     (max-width: 700px), (hover: none) and (pointer: coarse) and (max-height: 500px)
   Every rule in this file is inside that query, except the few at the top that HIDE
   phone-only elements by default. Tablets (768+) and laptops never see any of it.

   ─────────────────────────────────────────────────────────────
   COMPONENT API FOR PAGE AGENTS (do not edit this file; use these)
   ─────────────────────────────────────────────────────────────

   VARIABLES (set on :root inside the phone query)
     --m-dock-h       height of the bottom dock bar (64px portrait, 52px landscape)
     --m-safe-b       env(safe-area-inset-bottom, 0px)
     --m-dock-space   dock height + safe area: the room the dock takes at the bottom
     --m-dock-offset  = --m-dock-space while the dock is showing, 0px while it is
                      hidden (scrolled away or keyboard open). Use it to stack a sticky
                      bar ABOVE the dock, e.g. a form step bar:
                        .my-stepbar { position: fixed; left: 0; right: 0;
                                      bottom: var(--m-dock-offset);
                                      transition: bottom .35s var(--ease); }
     html.m-dock-hidden   present while the dock is slid away
     html.m-kb-open       present while a text field has focus / the keyboard is up
     html.m-phone         present while js/mobile.js is active (phone + JS running)

   VISIBILITY HELPERS
     <div class="m-only">…</div>   hidden everywhere except phones. Shown as display:block;
                                   for another display set it inline or in your CSS:
                                   style="--m-display:flex" (or grid, inline-flex…).
     <div class="d-only">…</div>   hidden on phones only.

   RAIL  (horizontal scroll-snap row with a peek of the next card)
     <div class="m-rail" id="marketsRail" data-m-dots>   ← data-m-dots: JS adds a dots row after it
       <article>…</article> <article>…</article> …
     </div>
     or place the dots yourself:  <div class="m-dots" data-m-for="marketsRail"></div>
     Only a phone turns the container into a rail; on desktop your own layout applies.
     Card width: --m-rail-w (default 84%), gap: --m-rail-gap (default 12px).
     Children snap to the start edge, padded by var(--pad). Dots are decorative
     (aria-hidden); the active one gets .is-on. The rail gets .is-start / .is-end.

   SHEET  (bottom sheet: grab handle, drag down / tap scrim / Escape to close,
           focus trapped, page behind inert)
     <button type="button" data-m-sheet-open="contentsSheet">Contents</button>
     <div class="m-sheet" id="contentsSheet" role="dialog" aria-modal="true"
          aria-labelledby="contentsSheetTitle" hidden>
       <div class="m-sheet__panel">
         <div class="m-sheet__grab" aria-hidden="true"></div>
         <div class="m-sheet__head">
           <h2 class="m-sheet__title" id="contentsSheetTitle">Contents</h2>
           <button type="button" class="m-sheet__close" data-m-sheet-close aria-label="Close"></button>
         </div>
         <div class="m-sheet__body"> … links, text … </div>
       </div>
     </div>
     Put the sheet as a direct child of <body> (anywhere works, but body level is cleanest).
     Links inside a sheet close it when tapped (same-page #hash links scroll after closing).
     Events on the sheet element: 'm-sheet:open', 'm-sheet:close'.

   TOAST
     window.vdMobile.toast('Address copied');           // 2.4s, role=status, above the dock
     window.vdMobile.toast('Saved', { duration: 1600 });
     (No-op off phones. Created on demand; you add no markup.)

   JS API  (window.vdMobile, defined as soon as js/mobile.js runs; methods are
            safe no-ops off phones)
     vdMobile.PHONE              the media query string above
     vdMobile.isPhone()          true while the phone layer is active
     vdMobile.toast(text, opts)
     vdMobile.openSheet(id, openerEl?) / vdMobile.closeSheet()
     vdMobile.haptic()           8ms tick on Android; nothing under reduced motion
     vdMobile.refreshRails()     re-scan .m-rail after you add one dynamically
     vdMobile.dock               the <nav class="m-dock"> element
     document 'vd:phone' event   detail: { active: true|false } when the layer turns on/off
     Wait for it with:
       window.vdMobile ? go() : document.addEventListener('vd:mobile-ready', go, { once: true });
     and check vdMobile.isPhone() / listen to 'vd:phone' to set up and tear down your own phone bits.

   PRESS FEEDBACK
     .btn, .m-press and [data-m-press] scale to .97 while pressed; dock items dim.
     Add class="m-press" to any tappable card of your own (not to [data-reveal]
     elements whose transform is animated; put it on an inner element instead).
   ============================================================= */

/* ── Outside phones: hide every phone-only piece ─────────────── */
.m-dock, .m-sheet, .m-toast, .m-dots { display: none; }
.m-only { display: none !important; }

@media (max-width: 700px), (hover: none) and (pointer: coarse) and (max-height: 500px) {

  :root {
    --m-dock-h: 64px;
    --m-safe-b: env(safe-area-inset-bottom, 0px);
    --m-dock-space: calc(var(--m-dock-h) + var(--m-safe-b));
    --m-dock-offset: var(--m-dock-space);
    --m-sheet-ease: cubic-bezier(.22, .9, .24, 1);
  }
  html.m-dock-hidden, html.m-kb-open { --m-dock-offset: 0px; }
  /* keyboard focus and #anchor jumps never land under the dock */
  html { scroll-padding-bottom: calc(var(--m-dock-space) + 12px); }
  body { -webkit-tap-highlight-color: transparent; }

  /* ── helpers ── */
  .m-only { display: var(--m-display, block) !important; }
  .m-only[hidden] { display: none !important; }
  .d-only { display: none !important; }

  /* the footer's last line clears the dock */
  .footer { padding-bottom: calc(28px + var(--m-dock-space)); }

  /* ═════════ BOTTOM DOCK ═════════ */
  .m-dock {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 95;
    display: grid; grid-template-columns: repeat(5, 1fr); align-items: end;
    height: var(--m-dock-space); padding: 0 6px var(--m-safe-b);
    background: var(--paper);
    border-top: 1px solid rgba(17, 17, 17, .12);
    color: var(--ink);
    transition: transform .42s var(--ease), background-color .35s, border-color .35s, color .35s;
    will-change: transform;
  }
  .m-dock.is-dark { background: var(--ink); border-top-color: rgba(250, 250, 248, .12); color: var(--paper); }
  html.m-dock-hidden .m-dock, html.m-kb-open .m-dock { transform: translateY(calc(100% + 2px)); }
  html.m-kb-open .m-dock { visibility: hidden; transition: transform .2s ease, visibility 0s .2s; }

  .m-dock__item {
    position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    height: var(--m-dock-h); min-width: 44px;
    font-family: var(--sans); font-size: 13px; font-weight: 500; line-height: 1; letter-spacing: 0;
    color: currentColor; opacity: .62;
    transition: opacity .25s, transform .2s ease;
  }
  .m-dock__item svg { width: 22px; height: 22px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
  .m-dock__item[aria-current="page"] { opacity: 1; }
  /* current page: a short red tick on the dock's top edge */
  .m-dock__item[aria-current="page"]::before {
    content: ''; position: absolute; top: -1px; left: 50%; width: 18px; height: 2px; margin-left: -9px;
    background: var(--red); border-radius: 0 0 2px 2px;
  }
  .m-dock.is-dark .m-dock__item[aria-current="page"]::before { background: #F0554E; }

  /* Apply: the raised red pill in the centre */
  .m-dock__item--apply { opacity: 1; justify-content: flex-end; padding-bottom: 9px; gap: 5px; }
  .m-dock__pill {
    display: grid; place-items: center; width: 58px; height: 40px; margin-top: -18px;
    border-radius: 999px; background: var(--red); color: var(--paper);
    box-shadow: 0 0 0 4px rgba(250, 250, 248, 1), 0 8px 18px -8px rgba(200, 32, 26, .7);
    transition: box-shadow .35s, transform .2s ease, background-color .2s;
  }
  .m-dock.is-dark .m-dock__pill { box-shadow: 0 0 0 4px var(--ink), 0 8px 18px -8px rgba(0, 0, 0, .8); }
  .m-dock__item--apply > span:last-child { color: var(--red); }
  .m-dock.is-dark .m-dock__item--apply > span:last-child { color: #F0554E; }
  .m-dock__item--apply[aria-current="page"]::before { display: none; }
  .m-dock__item--apply[aria-current="page"] .m-dock__pill { background: var(--red-deep); }

  /* ═════════ PHONE HEADER + MENU AS A BOTTOM SHEET ═════════
     Scoped to html.js: without JS the nav keeps its plain no-JS layout from veeday.css. */
  html.js .nav__toggle {
    width: 44px; height: 44px; margin-right: -4px; border-radius: 50%;
    border: 1px solid rgba(250, 250, 248, .26);
    transition: border-color .3s, background-color .3s, transform .2s ease;
  }
  html.js .nav__toggle span { left: 13px; right: 13px; }
  html.js .nav__toggle span:nth-child(1) { top: 18px; }
  html.js .nav__toggle span:nth-child(2) { top: 24px; }
  html.js .nav.is-open .nav__toggle span:nth-child(1),
  html.js .nav.is-open .nav__toggle span:nth-child(2) { top: 21px; }

  /* scrim behind the sheet (a click on it lands on the .nav itself) */
  html.js .nav::before {
    content: ''; position: fixed; inset: 0; z-index: 0;
    background: rgba(18, 16, 15, .55);
    opacity: 0; visibility: hidden; transition: opacity .4s, visibility 0s .4s;
  }
  html.js .nav.is-open::before { opacity: 1; visibility: visible; transition: opacity .4s, visibility 0s; }

  html.js .nav__links {
    position: fixed; inset: auto 0 0 0; top: auto; z-index: 1;
    height: auto; max-height: min(88dvh, 680px); max-height: min(88vh, 680px);
    padding: 34px var(--pad) calc(18px + var(--m-safe-b));
    flex-direction: column; align-items: stretch; justify-content: flex-start; gap: 0;
    background: var(--paper); color: var(--ink);
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -18px 40px -20px rgba(0, 0, 0, .45);
    opacity: 1; visibility: hidden;
    transform: translateY(105%);
    transition: transform .5s var(--m-sheet-ease), visibility 0s .5s;
    overflow-y: auto; overscroll-behavior: contain;
  }
  @supports (height: 1dvh) { html.js .nav__links { max-height: min(88dvh, 680px); } }
  html.js .nav.is-open .nav__links { visibility: visible; transform: translateY(var(--m-drag, 0px)); transition: transform .5s var(--m-sheet-ease), visibility 0s; }
  html.js .nav.is-open .nav__links.is-dragging { transition: none; }
  /* grab handle */
  html.js .nav__links::before {
    content: ''; position: absolute; top: 12px; left: 50%; width: 40px; height: 4px; margin-left: -20px;
    border-radius: 4px; background: rgba(17, 17, 17, .18);
  }
  html.js .nav__links > a {
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
    min-height: 54px; padding: 10px 2px; margin: 0;
    font-family: var(--serif); font-size: 24px; line-height: 1.15; letter-spacing: -.01em;
    color: var(--ink); border-bottom: 1px solid rgba(17, 17, 17, .1);
  }
  html.js .nav__links > a:first-child { margin-top: 0; }
  /* the desktop underline becomes a quiet chevron */
  html.js .nav__links > a::after {
    position: static; flex: none; width: 8px; height: 8px; margin-right: 4px;
    background: none; border-top: 1.5px solid currentColor; border-right: 1.5px solid currentColor;
    transform: rotate(45deg); opacity: .35; transition: none;
  }
  html.js .nav__links > a:hover::after { transform: rotate(45deg); }
  html.js .nav__links > a[aria-current="page"] { color: var(--red); }
  html.js .nav__links > a[aria-current="page"]::after { opacity: 1; }
  html.js .nav__links > a:active { background: rgba(17, 17, 17, .04); }

  html.js .nav__menu-ctas { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 22px 0 0; }
  html.js .nav__menu-ctas .btn { justify-content: center; min-height: 48px; padding: 12px 10px; font-size: 14px; text-align: center; }
  html.js .nav__menu-ctas .btn--ghost { --b-bd: rgba(17, 17, 17, .22); --b-fg: var(--ink); }
  html.js .nav__menu-ctas .btn--ghost[aria-current="page"] { --b-bd: var(--red); }
  html.js .nav__menu-ctas .btn--red[aria-current="page"] { box-shadow: 0 0 0 2px var(--paper), 0 0 0 3px var(--red); }

  /* landscape phones: the sheet is a centred card so it does not span the whole width */
  @media (min-width: 560px) {
    html.js .nav__links { left: 50%; right: auto; width: min(520px, 100%); margin-left: max(-260px, -50%); }
  }

  /* ═════════ PRESSED STATES ═════════ */
  .btn:active, .m-press:active, [data-m-press]:active { transform: scale(.97); transition-duration: .08s; }
  .m-dock__item:active { opacity: .45; }
  .m-dock__item--apply:active { opacity: 1; }
  .m-dock__item--apply:active .m-dock__pill { transform: scale(.93); }
  .split__half:active { opacity: .92; transition-duration: .1s; }

  /* ═════════ RAIL + DOTS ═════════ */
  .m-rail {
    display: flex !important; flex-wrap: nowrap !important;
    gap: var(--m-rail-gap, 12px);
    overflow-x: auto; overflow-y: hidden;
    scroll-snap-type: x mandatory; scroll-padding-inline: var(--pad);
    padding-inline: var(--pad); margin-inline: calc(var(--pad) * -1);
    overscroll-behavior-x: contain; -webkit-overflow-scrolling: touch;
    touch-action: pan-x pan-y;
    scrollbar-width: none;
  }
  .m-rail::-webkit-scrollbar { display: none; }
  .m-rail > * { flex: 0 0 var(--m-rail-w, 84%); min-width: 0; scroll-snap-align: start; }
  /* a trailing spacer so the last card can snap with the same right gutter */
  .m-rail::after { content: ''; flex: 0 0 1px; margin-left: -1px; }

  .m-dots { display: flex; justify-content: center; align-items: center; gap: 7px; min-height: 20px; margin-top: 14px; }
  .m-dots > i { width: 6px; height: 6px; border-radius: 6px; background: currentColor; opacity: .22; transition: width .35s var(--ease), opacity .35s, background-color .35s; }
  .m-dots > i.is-on { width: 18px; opacity: 1; background: var(--red); }

  /* ═════════ GENERIC SHEET ═════════ */
  .m-sheet { display: block; position: fixed; inset: 0; z-index: 140; }
  .m-sheet[hidden] { display: none; }
  .m-sheet::before { content: ''; position: absolute; inset: 0; background: rgba(18, 16, 15, .55); opacity: 0; transition: opacity .4s; }
  .m-sheet.is-open::before { opacity: 1; }
  .m-sheet__panel {
    position: absolute; left: 0; right: 0; bottom: 0;
    max-height: 88vh; display: flex; flex-direction: column;
    background: var(--paper); color: var(--ink);
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -18px 40px -20px rgba(0, 0, 0, .45);
    padding: 26px var(--pad) calc(16px + var(--m-safe-b));
    transform: translateY(105%);
    transition: transform .5s var(--m-sheet-ease);
  }
  @supports (height: 1dvh) { .m-sheet__panel { max-height: 88dvh; } }
  .m-sheet.is-open .m-sheet__panel { transform: translateY(var(--m-drag, 0px)); }
  .m-sheet__panel.is-dragging { transition: none; }
  @media (min-width: 560px) { .m-sheet__panel { left: 50%; right: auto; width: min(520px, 100%); margin-left: max(-260px, -50%); } }
  .m-sheet__grab { position: absolute; top: 10px; left: 50%; width: 40px; height: 4px; margin-left: -20px; border-radius: 4px; background: rgba(17, 17, 17, .18); }
  .m-sheet__grab::after { content: ''; position: absolute; inset: -14px -40px; } /* bigger drag target */
  .m-sheet__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-bottom: 12px; border-bottom: 1px solid rgba(17, 17, 17, .1); }
  .m-sheet__title { font-family: var(--serif); font-weight: 400; font-size: 24px; line-height: 1.15; letter-spacing: -.01em; }
  .m-sheet__close { position: relative; flex: none; width: 44px; height: 44px; margin-right: -10px; border-radius: 50%; }
  .m-sheet__close::before, .m-sheet__close::after { content: ''; position: absolute; left: 14px; right: 14px; top: 21px; height: 1.5px; background: currentColor; transform: rotate(45deg); }
  .m-sheet__close::after { transform: rotate(-45deg); }
  .m-sheet__body { overflow-y: auto; overscroll-behavior: contain; padding-top: 8px; margin: 0 calc(var(--pad) * -1); padding-inline: var(--pad); }

  /* ═════════ TOAST ═════════ */
  .m-toast {
    display: block; position: fixed; left: 50%; z-index: 150;
    bottom: calc(var(--m-dock-offset) + 14px);
    max-width: calc(100% - 2 * var(--pad)); width: max-content;
    padding: 12px 18px; border-radius: 999px;
    background: var(--ink); color: var(--paper);
    font-family: var(--sans); font-size: 14px; font-weight: 500; line-height: 1.35; text-align: center;
    box-shadow: 0 10px 30px -12px rgba(0, 0, 0, .55);
    transform: translate(-50%, 12px); opacity: 0; pointer-events: none;
    transition: opacity .3s, transform .4s var(--ease), bottom .35s var(--ease);
  }
  .m-toast.is-on { opacity: 1; transform: translate(-50%, 0); }

  /* ═════════ LANDSCAPE PHONES ═════════ */
  @media (max-height: 500px) {
    :root { --m-dock-h: 52px; }
    .m-dock { padding-left: max(6px, env(safe-area-inset-left, 0px)); padding-right: max(6px, env(safe-area-inset-right, 0px)); }
    .m-dock__item { flex-direction: row; gap: 8px; }
    .m-dock__item--apply { padding-bottom: 0; justify-content: center; }
    .m-dock__pill { width: 46px; height: 34px; margin-top: 0; }
    html.js .nav__links { max-height: calc(100vh - 16px); padding-top: 28px; }
    html.js .nav__links > a { min-height: 46px; font-size: 21px; }
  }

  /* ═════════ REDUCED MOTION: everything instant ═════════ */
  @media (prefers-reduced-motion: reduce) {
    .m-dock, .m-dock__item, .m-dock__pill, .m-dots > i, .m-toast,
    html.js .nav::before, html.js .nav__links, html.js .nav.is-open .nav__links,
    .m-sheet::before, .m-sheet__panel { transition: none !important; }
    .btn:active, .m-press:active, [data-m-press]:active,
    .m-dock__item--apply:active .m-dock__pill { transform: none; }
  }
}
