/* Compounder on a phone (≤900 px). Every rule lives inside the media query, so the
   desktop layout cannot be touched by this file. The elements prefixed m- are built
   by js/mobile-shell.js; the rest restyle the shared page for a narrow screen.
   Loaded last on purpose: equal-specificity rules here win over the older ones. */

@media (max-width: 900px) {
  :root {
    --m-safe-t: env(safe-area-inset-top, 0px);
    --m-safe-b: env(safe-area-inset-bottom, 0px);
    --m-dock-h: 64px;
    --m-ease: cubic-bezier(.2, .8, .2, 1);
  }

  /* ---- header: small logo, search and the profile initial -------------------- */
  .global-header {
    position: sticky;
    top: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    gap: 4px;
    height: calc(56px + var(--m-safe-t));
    min-height: 0;
    padding: var(--m-safe-t) 10px 0 14px;
    background: color-mix(in srgb, var(--bg) 92%, transparent);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--hairline);
    box-shadow: none;
  }
  .global-header .desktop-navigation,
  .global-header .global-brand .brand-icon,
  .topbar-user { display: none !important; }
  .global-header .global-brand { display: flex; align-items: center; padding: 0; margin: 0; background: none; border: 0; }
  .global-header .global-brand .brand-full { display: block; width: auto; height: 22px; max-width: none; max-height: none; }
  .global-header-actions { margin-left: auto; display: flex; align-items: center; gap: 2px; }
  .global-header .header-search-button { display: none; }

  .m-avatar { position: relative; width: 40px; height: 40px; display: grid; place-items: center; border: 0; background: none; padding: 0; cursor: pointer; }
  .m-avatar[hidden] { display: none; }
  .m-avatar > span {
    width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
    font-size: 13.5px; font-weight: 700; line-height: 1; color: var(--accent);
    background: var(--accent-soft); border: 1px solid var(--accent-ring);
  }
  .m-avatar-dot { position: absolute; top: 7px; right: 6px; width: 8px; height: 8px; border-radius: 50%; background: var(--negative); border: 2px solid var(--bg); }
  .m-avatar-dot[hidden] { display: none; }

  /* Room under the content for the bar. */
  body.m-phone .main-stage { padding-bottom: calc(var(--m-dock-h) + 24px + var(--m-safe-b)); }
  body.m-sheet-open { overflow: hidden; }

  /* ---- the bar: CompAI, a rule and the menu on a solid ground ------------------- */
  .m-dock {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
    display: flex; align-items: center; gap: 10px;
    padding: 8px 10px calc(8px + var(--m-safe-b)) 12px;
    background: var(--bg);
    border-top: 1px solid var(--hairline);
    pointer-events: none;
  }
  .m-dock[hidden] { display: none; }
  .m-dock > * { pointer-events: auto; }
  body.auth-locked .m-dock { display: none; }
  .m-menu-btn {
    width: 46px; height: 46px; flex: 0 0 46px; display: grid; place-items: center;
    border: 0; border-radius: 50%; background: none; color: var(--text); padding: 0; cursor: pointer;
  }
  .m-menu-btn .m-i { width: 26px; height: 26px; stroke-width: 2; }
  .m-menu-btn:active { transform: scale(.94); }
  .m-menu-btn .m-shut { display: none; }
  .m-menu-btn.open { color: var(--accent); }
  .m-menu-btn.open .m-open { display: none; }
  .m-menu-btn.open .m-shut { display: block; }
  .m-dock-rule { width: 1px; height: 26px; flex: 0 0 1px; background: var(--border-strong); }
  /* CompAI is a line of text with its spark, no field around it: the whole left side is
     the button. */
  .m-ask {
    flex: 1; min-width: 0; height: 46px; display: flex; align-items: center; gap: 10px;
    padding: 0 4px; border: 0; border-radius: 12px; background: none;
    color: var(--text-2); font: inherit; font-size: 15px; text-align: left; cursor: pointer;
  }
  .m-ask:active { background: var(--surface-2); }
  .m-ask-spark { color: var(--accent); display: grid; }
  .m-ask-spark .m-i { width: 20px; height: 20px; }
  .m-ask-ph { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .m-ask.locked { color: var(--muted); }
  .m-ask.locked .m-ask-spark { color: var(--muted); }
  /* Charts needs the width: CompAI shrinks to its spark next to the menu. */
  .m-dock.only-menu .m-ask { flex: 0 0 46px; width: 46px; padding: 0; justify-content: center; margin-left: auto; }
  .m-dock.only-menu .m-ask-ph { display: none; }
  .m-dock.only-menu .m-dock-rule { display: none; }
  .m-dock.only-menu { background: none; border-top: 0; }

  /* ---- sheets ----------------------------------------------------------------- */
  .m-scrim { position: fixed; inset: 0; z-index: 70; background: rgba(4, 7, 14, .55); opacity: 0; pointer-events: none; transition: opacity 200ms ease; }
  .m-scrim.on { opacity: 1; pointer-events: auto; }
  .m-sheet {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 80;
    display: flex; flex-direction: column; max-height: 88vh; max-height: 88dvh;
    background: var(--surface); border-top: 1px solid var(--border-strong);
    border-radius: 22px 22px 0 0; outline: none;
    transform: translateY(105%); visibility: hidden;
    transition: transform 260ms var(--m-ease), visibility 0s linear 260ms;
    touch-action: pan-y;
  }
  .m-sheet.on { transform: translateY(0); visibility: visible; transition: transform 260ms var(--m-ease); }
  /* The bar stays on top of an open sheet, so the menu button turns into its close. */
  body.m-sheet-open .m-dock { z-index: 85; background: var(--surface); }
  body.modal-open .m-dock { display: none; }
  .m-sheet { padding-bottom: calc(var(--m-dock-h) + 6px + var(--m-safe-b)); }
  .m-sheet.dragging { transition: none; }
  .m-grip { padding: 9px 0 4px; display: grid; place-items: center; touch-action: none; cursor: grab; }
  .m-grip i { width: 38px; height: 5px; border-radius: 3px; background: var(--border-strong); display: block; }
  .m-sheet-body { overflow-y: auto; overscroll-behavior: contain; padding: 2px 16px 8px; }
  .m-fold { display: inline-flex; align-items: center; gap: 4px; border: 0; background: none; padding: 0; font: inherit; color: inherit; letter-spacing: inherit; text-transform: inherit; cursor: pointer; }
  .m-fold .m-i { width: 14px; height: 14px; transition: transform 160ms ease; }
  .m-fold[aria-expanded="true"] .m-i { transform: rotate(180deg); }
  .m-chips { display: flex; gap: 6px; overflow-x: auto; padding: 0 2px 2px; scrollbar-width: none; }
  .m-chips::-webkit-scrollbar { display: none; }
  .m-chips button { flex: 0 0 auto; height: 32px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--border-strong); background: none; color: var(--text); font: inherit; font-size: 13px; font-weight: 650; cursor: pointer; }
  .m-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
  .m-grid[hidden] { display: none; }
  .m-tile { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 10px 2px 8px; border: 0; border-radius: 14px; background: none; color: var(--text-2); font: inherit; font-size: 11.5px; font-weight: 600; line-height: 1.2; text-align: center; cursor: pointer; }
  .m-tile-ic { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; background: var(--surface-2); border: 1px solid var(--border); color: var(--text); }
  .m-tile.on { color: var(--accent); }
  .m-tile.on .m-tile-ic { background: var(--accent-soft); border-color: var(--accent-ring); color: var(--accent); }
  .m-tile:active .m-tile-ic { transform: scale(.95); }
  .m-grid + .m-row, .m-chips + .m-label { margin-top: 10px; }
  .m-find { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; gap: 9px; height: 44px; margin: 2px 0 6px; padding: 0 12px;
    border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); color: var(--muted); }
  .m-find:focus-within { border-color: var(--accent-ring); }
  .m-find .m-i { width: 18px; height: 18px; flex: 0 0 18px; }
  .m-find input { flex: 1; min-width: 0; height: 100%; border: 0; outline: 0; background: none; color: var(--text); font: inherit; font-size: 16px; }
  .m-find input::-webkit-search-cancel-button { -webkit-appearance: none; }
  .m-find input:focus, .m-find input:focus-visible { outline: 0; box-shadow: none; }
  .m-find-clear { width: 30px; height: 30px; margin-right: -6px; display: grid; place-items: center; border: 0; background: none; color: var(--muted); padding: 0; cursor: pointer; }
  .m-find-clear[hidden], .m-found[hidden], .m-menu[hidden] { display: none; }
  .m-found { display: flex; flex-direction: column; }
  .m-found-row { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 2px 10px; min-height: 52px; padding: 7px 2px; border: 0; border-bottom: 1px solid var(--hairline); background: none; color: var(--text); font: inherit; text-align: left; cursor: pointer; }
  .m-found-row b { font-size: 15px; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .m-found-row small { grid-column: 1; font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .m-found-row em { grid-column: 2; grid-row: 1 / span 2; font-style: normal; font-size: 11px; font-weight: 650; letter-spacing: .04em; text-transform: uppercase; color: var(--muted-2); }
  .m-found-row.ask b { color: var(--accent); }
  .m-found-empty { padding: 18px 2px; color: var(--muted); font-size: 14px; }

  /* ---- search: the whole screen ---------------------------------------------- */
  .quick-search-overlay { align-items: stretch; justify-content: stretch; padding: 0; background: var(--bg); backdrop-filter: none; }
  .quick-search-overlay .quick-search-card {
    width: 100%; max-width: none; height: 100%; max-height: none; margin: 0; border: 0; border-radius: 0;
    display: flex; flex-direction: column; padding: calc(8px + var(--m-safe-t)) 14px 0; background: var(--bg); box-shadow: none;
  }
  .quick-search-card > header { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 0 2px; }
  .quick-search-card > header kbd { display: none; }
  .quick-search-card > header h2 { font-size: 20px; margin: 0; }
  .m-search-cancel { border: 0; background: none; color: var(--accent); font: inherit; font-size: 15px; font-weight: 600; padding: 8px 4px; cursor: pointer; }
  .quick-search-field input { height: 46px; font-size: 16px; border-radius: 12px; }
  .quick-search-results { flex: 1; max-height: none; overflow-y: auto; padding-bottom: calc(16px + var(--m-safe-b)); }
  .quick-search-result { min-height: 54px; }
  .quick-search-result > span:nth-child(2) { display: flex; flex-direction: column; min-width: 0; }
  .quick-search-result > span:nth-child(2) small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .quick-search-card > footer { display: none; }

  /* ---- CompAI: full screen, above the bar ------------------------------------- */
  .cie-chat { z-index: 90; }
  body.cie-chat-active .m-dock { display: none; }

  /* ---- a stock or coin page: Back, the folded quote and the chart shortcut ------ */
  .global-header .m-back, .global-header .m-chart-btn, .global-header .m-mini { display: none; }
  .global-header.m-sym .m-back { display: grid; place-items: center; width: 36px; height: 40px; margin-left: -8px; border: 0; background: none; color: var(--text); cursor: pointer; }
  .global-header.m-sym .m-chart-btn { display: grid; place-items: center; }
  .global-header.m-sym .m-chart-btn[hidden], .global-header .m-back[hidden] { display: none; }
  .global-header .global-brand { transition: opacity 160ms ease; }
  .global-header.m-sym .global-brand .brand-full { height: 18px; }
  .global-header.m-sym .m-mini {
    display: flex; position: absolute; left: 50px; top: calc(var(--m-safe-t) + 16px); align-items: baseline; gap: 7px;
    opacity: 0; transform: translateY(6px); transition: opacity 160ms ease, transform 160ms ease;
    pointer-events: none; font-variant-numeric: tabular-nums; white-space: nowrap;
  }
  .m-mini b { font-size: 16px; font-weight: 700; }
  .m-mini span { font-size: 15px; }
  .m-mini em { font-style: normal; font-size: 13px; font-weight: 600; }
  .m-mini .pos { color: var(--positive); }
  .m-mini .neg { color: var(--negative); }
  /* Any other page folds to its title. */
  .global-header.m-titled .m-mini {
    display: flex; position: absolute; left: 14px; top: calc(var(--m-safe-t) + 16px); align-items: baseline;
    opacity: 0; transform: translateY(6px); transition: opacity 160ms ease, transform 160ms ease; pointer-events: none;
    max-width: calc(100% - 140px); white-space: nowrap; overflow: hidden;
  }
  .global-header.m-titled .m-mini b { overflow: hidden; text-overflow: ellipsis; }
  .global-header.m-folded .m-mini { opacity: 1; transform: none; }
  .global-header.m-folded .global-brand { opacity: 0; pointer-events: none; }
  .symbol-detail-v2 .symbol-aside-actions { display: none; }
  .symbol-detail-v2 .symbol-primary-navigation-row { top: calc(56px + var(--m-safe-t)); }
  .symbol-detail-v2 #symbol-tabs, .symbol-detail-v2 #coin-tabs {
    flex-wrap: nowrap; justify-content: flex-start; gap: 20px; overflow-x: auto; scrollbar-width: none; scroll-padding-inline: 16px;
  }
  .symbol-detail-v2 #symbol-tabs::-webkit-scrollbar, .symbol-detail-v2 #coin-tabs::-webkit-scrollbar { display: none; }
  .symbol-detail-v2 .symbol-tabs .symbol-tab { flex: 0 0 auto; white-space: nowrap; font-size: .86rem; min-height: 44px; }

  /* ---- a locked tab: blurred preview, what unlocking adds, one way in --------------- */
  /* Each locked tab explains itself below; the summary's copy of the notice goes. */
  body.m-phone #symbol-detail-page .symbol-detail-aside .symbol-aside-lock.symbol-aside-section { display: none; }
  body.m-phone #symbol-detail-page:not(.symbol-unlocked) .premium-lock-overlay { position: relative; display: block; min-height: 0; padding: 8px 0 0; background: none; backdrop-filter: none; }
  body.m-phone #symbol-detail-page:not(.symbol-unlocked) .premium-lock-overlay .premium-lock-card {
    position: relative; margin-top: -64px; padding: 22px 8px 20px; max-width: none; text-align: center;
    border: 0; border-top: 1px solid var(--hairline); border-bottom: 1px solid var(--hairline); border-radius: 0;
    background: linear-gradient(180deg, transparent, var(--bg) 46px); box-shadow: none;
  }

  /* ---- no hover on a phone: terms open a sheet instead of a tooltip -------------- */
  #metric-tooltip { display: none !important; }

  /* ---- Account: one column of lines, the slots as rows ----------------------------- */
  #account-page .account-shell { gap: 18px; }
  #account-page .account-hero { display: flex; align-items: center; gap: 12px; min-height: 0; padding: 4px 0 16px; border: 0; border-bottom: 1px solid var(--hairline); border-radius: 0; background: none; box-shadow: none; }
  #account-page .account-hero::before, #account-page .account-hero::after { display: none; }
  #account-page .account-identity { flex: 1; min-width: 0; }
  #account-page .account-identity-name { font-size: 20px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #account-page .account-plan-block { text-align: right; }
  #account-page .account-stats { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0; padding-bottom: 14px; border-bottom: 1px solid var(--hairline); }
  #account-page .account-stat { min-height: 0; padding: 2px 4px 0 0; border: 0; border-radius: 0; background: none; box-shadow: none; gap: 4px; }
  #account-page .account-stat > span { font-size: 9.5px; letter-spacing: .06em; }
  #account-page .account-stat > strong { font-size: 21px; }
  #account-page .account-stat > small { display: none; }
  #account-page .account-billing-panel, #account-page .account-layout > * { padding: 0; border: 0; border-radius: 0; background: none; box-shadow: none; }
  #account-page .account-credit-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0; border-top: 1px solid var(--hairline); border-bottom: 1px solid var(--hairline); }
  #account-page .account-credit-grid > div { min-width: 0; padding: 10px 0; border: 0; border-radius: 0; background: none; }
  #account-page .credit-slots-heading small { display: none; }
  #account-page .credit-slot-grid { display: flex; flex-direction: column; gap: 0; }
  #account-page .credit-slot {
    display: grid; grid-template-columns: 50px minmax(0, 1fr) auto; grid-template-rows: auto auto; align-items: center;
    column-gap: 10px; row-gap: 2px; min-height: 0; padding: 11px 0; border: 0; border-bottom: 1px solid var(--hairline);
    border-radius: 0; background: none; box-shadow: none;
  }
  #account-page .credit-slot .credit-slot-number { grid-row: 1 / span 2; font-size: 11.5px; color: var(--muted-2); }
  #account-page .credit-slot strong { grid-column: 2; font-size: 15px; }
  #account-page .credit-slot small { grid-column: 2; grid-row: 2; font-size: 12px; color: var(--muted); }
  #account-page .credit-slot .credit-replace-btn { grid-column: 3; grid-row: 1 / span 2; min-height: 0; height: 32px; padding: 0 12px; border-radius: 999px; font-size: 12.5px; }
  #account-page .credit-slot.available { border-style: none; border-bottom: 1px solid var(--hairline); background: none; }
  #account-page .credit-slot.available strong { color: var(--accent); }
  #account-page .account-billing-actions { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
  #account-page .account-billing-actions button { width: 100%; min-height: 46px; }
  #account-page .billing-catalog-list { display: flex; flex-direction: column; gap: 0; }
  #account-page .billing-plan-option { border-radius: 0; border: 0; border-bottom: 1px solid var(--hairline); background: none; padding: 12px 0; }
  #account-page .billing-plan-option.selected { color: var(--accent); }

  /* ---- Portfolio: the tabs get the full width; currency and actions sit below ------ */
  #portfolio-page .portfolio-section-bar { flex-wrap: wrap; row-gap: 10px; }
  #portfolio-page .portfolio-section-tabs { flex: 1 1 100%; min-width: 0; overflow-x: auto; scrollbar-width: none; }
  #portfolio-page .portfolio-section-tabs::-webkit-scrollbar { display: none; }
  #portfolio-page .portfolio-topbar { flex: 1 1 100%; display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
  #portfolio-page .portfolio-currency-switch { margin-right: auto; }

  /* ---- lists: quick actions and pull to refresh --------------------------------- */
  /* Compounder's own pull to refresh replaces the browser's reload gesture. */
  html, body { overscroll-behavior-y: none; }
  tr[data-market-row], tr[data-crypto-row] { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
  .m-ptr {
    position: fixed; left: 50%; top: calc(64px + var(--m-safe-t)); z-index: 35; display: flex; align-items: center; gap: 8px;
    padding: 8px 14px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface);
    box-shadow: var(--shadow-md); color: var(--text-2); font-size: 13px; font-weight: 600;
    transform: translate(-50%, -40px); opacity: 0; pointer-events: none; transition: opacity 120ms ease;
  }
  .m-ptr[hidden] { display: none; }
  .m-ptr.on { opacity: 1; }
  .m-ptr.ready, .m-ptr.busy { color: var(--accent); }
  .m-ptr i { width: 14px; height: 14px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; }
  .m-ptr.busy { transform: translate(-50%, 6px) !important; transition: transform 160ms ease; }
  .m-ptr.busy i { animation: m-spin 700ms linear infinite; }
  @keyframes m-spin { to { transform: rotate(360deg); } }

  /* ---- toasts sit above the bar, centred -------------------------------------- */
  .app-toasts { top: auto; right: 12px; left: 12px; bottom: calc(var(--m-dock-h) + 16px + var(--m-safe-b)); align-items: center; }
}
