/* ════════════════════════════════════════════════════════════════════════
   market-mobile.css  —  Mobile support for Market Investment
   ────────────────────────────────────────────────────────────────────────
   DROP-IN. Two ways to use:
     A) <link rel="stylesheet" href="/market-mobile.css"> after the inline <style>, OR
     B) paste the whole file inside the existing <style> block at the END.

   Everything is scoped to @media (max-width: 768px) and uses the SAME design
   tokens (--bg, --surface, --violet, --positive…) and the SAME class/ID names
   already in public/index.html. No new colors. Desktop is untouched.

   Covers EVERY page:
     · Chrome: header, #portfolio-strip, bottom tab bar
     · Home: hero, kpi-strip, shortcut-bar, holdings (table→cards)
     · Peak AI (#page-ai): header, tabs, composer, output, recent rail
     · Opportunities, News, Recommendations
     · Ticker (#page-ticker): chart, timeframes, actions, quick-add
     · Compare, Checkpoints, Checkpoint-compare
     · Search, Upload, Modals, Auth

   A handful of NEW classes are introduced for the bottom nav + holding cards
   (.mobile-tabbar/.mtab, .hcard*). Their markup is in MOBILE_HANDOFF.md.
   ════════════════════════════════════════════════════════════════════════ */

/* ╔══════════════════════════════════════════════════════════════════════╗
   ║  BOTTOM TAB BAR  (always present in DOM; shown only on mobile)         ║
   ╚══════════════════════════════════════════════════════════════════════╝ */
.mobile-tabbar { display: none; }

@media (max-width: 768px) {

  /* ── Bottom tab bar ──────────────────────────────────────────────── */
  .mobile-tabbar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
    background: var(--bg); border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom, 18px);
    /* Force own compositing layer so iOS Safari keeps the bar pinned to the
       bottom during momentum scrolling instead of letting it "float" mid-page
       until the fling settles. */
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    -webkit-backface-visibility: hidden;
  }
  .mtab {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px;
    padding: 9px 0 5px; background: none; border: none; cursor: pointer;
    color: var(--ink-faint); font: 500 10px/1 'Space Grotesk', system-ui, sans-serif;
  }
  .mtab.active { color: var(--violet); }
  /* keep all page content clear of the fixed bar */
  body { padding-bottom: calc(64px + env(safe-area-inset-bottom, 18px)); overscroll-behavior-y: contain; }

  /* ╔════════════════════════════════════════════════════════════════╗
     ║  HEADER                                                          ║
     ╚════════════════════════════════════════════════════════════════╝ */
  header { gap: 10px; padding: 0 14px; flex-wrap: nowrap; }
  .header-nav { display: none; }          /* moved to bottom tab bar */
  .header-search-wrap { display: none; }   /* search is a tab now */
  .header-wordmark-sub { display: none; }  /* keep just "Market" */
  /* user chip: trim to avatar only to save room (optional) */
  .header-user-chip { padding: 4px; }
  .header-user-chip > span:not(.header-avatar) { display: none; }

  /* ╔════════════════════════════════════════════════════════════════╗
     ║  PORTFOLIO STRIP  →  collapsible single row + 2×2 grid           ║
     ╚════════════════════════════════════════════════════════════════╝
     Production change (see handoff): add a #pstrip-summary-row element as the
     FIRST child of #portfolio-strip (mobile-only summary). Tapping it toggles
     .pstrip-open on #portfolio-strip. */
  #portfolio-strip {
    position: sticky; top: 56px; z-index: 4;
    height: auto; padding: 0; flex-direction: column; align-items: stretch;
  }
  #pstrip-summary-row {
    display: flex; align-items: center; gap: 10px;
    height: 44px; padding: 0 16px; cursor: pointer;
  }
  #pstrip-summary-row .sum-lbl { font-size: 10px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.14em; color: var(--ink-faint); }
  #pstrip-summary-row .sum-val { font-size: 15px; font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }
  #pstrip-summary-row .sum-delta { font-size: 12px; font-weight: 500; font-variant-numeric: tabular-nums; }
  #pstrip-summary-row .sum-chevron { margin-left: auto; color: var(--ink-faint); transition: transform 0.2s; }
  #portfolio-strip.pstrip-open #pstrip-summary-row .sum-chevron { transform: rotate(180deg); }

  /* the 4 desktop stats: hidden when collapsed, 2×2 grid when open */
  #portfolio-strip .pstrip-stat { display: none; }
  #portfolio-strip .pstrip-divider { display: none; }
  #portfolio-strip.pstrip-open {
    display: grid; grid-template-columns: 1fr 1fr; gap: 1px;
    background: var(--border); padding-top: 1px;
  }
  #portfolio-strip.pstrip-open #pstrip-summary-row { grid-column: 1 / -1; background: var(--bg); }
  #portfolio-strip.pstrip-open .pstrip-stat {
    display: flex; flex-direction: column; align-items: flex-start; gap: 4px;
    background: var(--bg); padding: 12px 16px;
  }
  #portfolio-strip.pstrip-open #pstrip-live-wrap { background: var(--bg); padding: 12px 16px; }

  /* ╔════════════════════════════════════════════════════════════════╗
     ║  HOME — hero / kpi rail / shortcut rail                          ║
     ╚════════════════════════════════════════════════════════════════╝ */
  .hero-grid { grid-template-columns: 1fr; gap: 14px; padding: 22px 16px 16px; }
  .hero-number { font-size: 42px; letter-spacing: -0.035em; }
  .hero-deltas { gap: 12px; font-size: 13px; }
  .hero-right { display: none; }   /* hide 30-day sparkline; see handoff to keep it */

  /* KPI strip: 5 cards → horizontal snap rail */
  .kpi-strip {
    display: flex; gap: 10px; padding: 4px 16px 18px;
    overflow-x: auto; scroll-snap-type: x mandatory; -webkit-overflow-scrolling: touch;
  }
  .kpi-strip::-webkit-scrollbar { display: none; }
  .kpi-card { flex: 0 0 auto; min-width: 132px; scroll-snap-align: start; }

  /* Shortcut bar: wrap → single scrollable pill rail */
  .shortcut-bar {
    margin: 0 16px 18px; padding: 6px; gap: 8px;
    flex-wrap: nowrap; overflow-x: auto; border-radius: 99px; -webkit-overflow-scrolling: touch;
  }
  .shortcut-bar::-webkit-scrollbar { display: none; }
  .shortcut-brand { border-right: none; margin-right: 0; flex: 0 0 auto; }
  .shortcut-btn { flex: 0 0 auto; }
  .shortcut-bar > div[style*="flex:1"] { display: none; }  /* kill the desktop spacer */

  /* ╔════════════════════════════════════════════════════════════════╗
     ║  HOLDINGS — table → cards                                        ║
     ╚════════════════════════════════════════════════════════════════╝
     Primary path: renderHoldings()/renderDryRun() output .hcard markup on
     mobile (see handoff). These styles cover that. */
  .holdings-header { padding: 14px 16px; flex-wrap: wrap; gap: 8px; }
  .holdings-header > div[style*="margin-left:16px"] { margin-left: 0 !important; }

  .hcard-list { display: flex; flex-direction: column; gap: 10px; padding: 0 16px; }
  /* Swipe-to-sell: the wrapper hosts a Sell layer that sits behind the card
     and shows only while the card is dragged sideways (see 06-misc.js). */
  .hcard-wrap { position: relative; }
  .hcard-sell-reveal {
    position: absolute; inset: 0; border-radius: 12px;
    background: rgba(239,68,68,0.14); border: 1px solid rgba(239,68,68,0.35);
    display: flex; align-items: center; gap: 6px;
    /* flex-end tracks the writing direction: right in LTR, left in RTL —
       exactly the edge the card exposes when swiped toward the reading end. */
    justify-content: flex-end; padding: 0 20px;
    color: var(--negative, #ef4444); font-size: 12px; font-weight: 600;
  }
  .hcard {
    position: relative;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 12px; padding: 14px; cursor: pointer;
  }
  .hcard:active { border-color: var(--border-strong); }
  .hcard-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
  .hcard-symwrap { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
  .hcard-symline { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
  .hcard-sym { font-size: 15px; font-weight: 600; letter-spacing: -0.01em; color: var(--ink); }
  .hcard-name { font-size: 11.5px; color: var(--ink-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 170px; }
  .hcard-price { text-align: right; flex-shrink: 0; font-variant-numeric: tabular-nums; }
  .hcard-price .p { font-size: 15px; font-weight: 600; color: var(--ink); }
  .hcard-price .d { font-size: 11.5px; margin-top: 3px; }
  .hcard-bottom {
    display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
    margin-top: 13px; padding-top: 13px; border-top: 1px solid var(--border);
    font-variant-numeric: tabular-nums;
  }
  .hcard-metric { display: flex; flex-direction: column; gap: 3px; }
  .hcard-metric .lbl { font-size: 9.5px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.12em; color: var(--ink-faint); }
  .hcard-metric .val { font-size: 13px; font-weight: 500; color: var(--ink); }
  /* Stacked change metrics (Today / Total P&L): amount line + percent line. */
  .hcard-metric .val span { display: block; line-height: 1.3; }
  .hcard-metric .val .hcard-pct { font-size: 11px; }
  .hcard-metric.grow { flex: 1; max-width: 120px; }
  /* Allocation weight on its own slim full-width line below the metrics. */
  .hcard-weight { display: flex; align-items: center; gap: 8px; margin-top: 11px; }
  .hcard-weight .lbl { font-size: 9.5px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.12em; color: var(--ink-faint); flex-shrink: 0; }
  .hcard-weight .weight-track { flex: 1; height: 4px; border-radius: 2px; background: rgba(255,255,255,0.06); overflow: hidden; }
  .hcard-weight .weight-pct { font-size: 11px; font-weight: 500; color: var(--ink-dim); min-width: 38px; text-align: right; font-variant-numeric: tabular-nums; }

  /* OPTIONAL zero-JS fallback: if you'd rather NOT change renderHoldings(),
     uncomment to stack the existing <table> into card-like blocks.
  .section table, .section thead, .section tbody, .section tr, .section td { display: block; width: 100%; }
  .section thead { display: none; }
  .section tr { border: 1px solid var(--border); border-radius: 12px; margin: 0 0 10px; padding: 6px 12px; background: var(--surface); }
  .section td { border: none !important; padding: 6px 0; display: flex; justify-content: space-between; }
  .section td::before { content: attr(data-label); color: var(--ink-faint); font-size: 10px; text-transform: uppercase; letter-spacing: 0.1em; }
  */

  /* ╔════════════════════════════════════════════════════════════════╗
     ║  SUB-PAGE HEADERS  (.page padding + .page-header)                ║
     ╚════════════════════════════════════════════════════════════════╝ */
  .page { padding: 16px 14px; }
  .page-header { gap: 10px; margin-bottom: 18px; flex-wrap: wrap; }
  .page-title { font-size: 18px; }
  /* action buttons that pile up in headers (ticker has 5) → wrap to a scroll row */
  .page-header button, .page-header .back-btn { flex-shrink: 0; }

  /* ╔════════════════════════════════════════════════════════════════╗
     ║  PEAK AI  (#page-ai)                                             ║
     ╚════════════════════════════════════════════════════════════════╝ */
  .peak-header-inner { padding: 16px 14px 0 !important; }
  .peak-hero { font-size: 26px !important; }
  .peak-mini-metric { display: none; }          /* mini metrics row → hide on phone */
  .ai-tabs {
    margin-top: 18px !important; gap: 6px;
    overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .ai-tabs::-webkit-scrollbar { display: none; }
  .ai-tab { flex: 0 0 auto; padding: 7px 12px; font-size: 12px; }

  /* 2-col → 1-col; recent rail drops below and goes static full-width */
  .peak-main { grid-template-columns: 1fr !important; gap: 24px; padding: 20px 14px 32px; }
  .peak-rail { position: static !important; width: 100% !important; }
  #advisor-history-panel, #discovery-history-panel,
  #analysis-history-panel, #ticker-history-panel,
  #search-history-panel { width: 100% !important; position: static !important; }
  .ai-panel-layout, .ticker-news-row, #analysis-layout { flex-direction: column; }

  /* Composer: tighten padding, scale the big textarea text */
  .peak-composer-inner { padding: 16px 16px 12px; }
  .peak-composer textarea { font-size: 17px; }
  .peak-composer-footer { padding: 12px 4px 6px; gap: 10px; }
  .peak-chips { margin-left: 0; justify-content: flex-start; }
  .peak-cta { height: 44px; }   /* 44px touch target */

  /* Discovery candidate cards: single column */
  #discovery-cards { grid-template-columns: 1fr !important; }

  /* KPI bar inside AI panels */
  .peak-kpi-bar { gap: 16px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .peak-kpi { min-width: 90px; }

  /* ╔════════════════════════════════════════════════════════════════╗
     ║  OPPORTUNITIES                                                   ║
     ╚════════════════════════════════════════════════════════════════╝ */
  .opp { grid-template-columns: auto 1fr; gap: 10px; padding: 14px; }
  .opp-type { display: none; }   /* drop the type chip; the badge carries severity */

  /* ╔════════════════════════════════════════════════════════════════╗
     ║  NEWS                                                            ║
     ╚════════════════════════════════════════════════════════════════╝ */
  .news-tabs { padding: 10px 12px; }   /* already horizontally scrollable */
  .news-item { padding: 14px; gap: 12px; }
  .news-thumb { width: 56px; height: 42px; }

  /* ╔════════════════════════════════════════════════════════════════╗
     ║  RECOMMENDATIONS                                                 ║
     ╚════════════════════════════════════════════════════════════════╝ */
  .rec-card { grid-template-columns: minmax(56px, max-content) 1fr auto; gap: 10px; padding: 14px; }
  .rec-sym { font-size: 15px; }
  .rec-upside { font-size: 16px; }

  /* ╔════════════════════════════════════════════════════════════════╗
     ║  TICKER  (#page-ticker)                                          ║
     ╚════════════════════════════════════════════════════════════════╝ */
  /* header has 5 action buttons — let them wrap and shrink */
  #page-ticker .page-header { gap: 6px; }
  #page-ticker .page-header button { padding: 5px 9px; font-size: 11px; min-height: 32px; }
  #page-ticker #compare-inline-input { width: 100% !important; }
  #compare-inline-wrap { width: 100%; }
  /* chart timeframe buttons → scroll row */
  #page-ticker .section-header { flex-wrap: wrap; gap: 6px; }
  #page-ticker .section-header > div[style*="display:flex"] {
    flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%;
  }
  #page-ticker .section-header > div::-webkit-scrollbar { display: none; }
  #page-ticker .section-header button { flex: 0 0 auto; }
  #ticker-chart { height: 200px !important; }
  /* quick-add form: 3-col → 1-col */
  #qa-body div[style*="grid-template-columns:1fr 1fr 2fr"] { grid-template-columns: 1fr !important; }
  /* news + history → stacked, history full width */
  .ticker-news-row { flex-direction: column; }
  #ticker-history-panel { width: 100% !important; }

  /* ╔════════════════════════════════════════════════════════════════╗
     ║  COMPARE  (#page-compare-tickers)                                ║
     ╚════════════════════════════════════════════════════════════════╝ */
  #page-compare-tickers .section-header > div[style*="display:flex"] {
    flex-wrap: nowrap; overflow-x: auto; max-width: 100%; -webkit-overflow-scrolling: touch;
  }
  #page-compare-tickers .section-header button { flex: 0 0 auto; }
  #compare-chart { height: 200px !important; }
  /* side-by-side metrics 1fr 1fr → stack */
  #page-compare-tickers div[style*="grid-template-columns:1fr 1fr"] { grid-template-columns: 1fr !important; }

  /* ╔════════════════════════════════════════════════════════════════╗
     ║  CHECKPOINTS + CHECKPOINT COMPARE                                ║
     ╚════════════════════════════════════════════════════════════════╝ */
  .cp-row, .cp-row-header { grid-template-columns: 70px 1fr 1fr; gap: 6px; }
  .cp-row > :nth-child(4), .cp-row > :nth-child(5),
  .cp-row-header > :nth-child(4), .cp-row-header > :nth-child(5) { display: none; } /* drop 2 cols */
  .cp-checkpoint-row { padding: 14px; gap: 12px; }
  /* compare summary cards 1fr 1fr 1fr → horizontal scroll */
  #cp-summary-cards { display: flex !important; overflow-x: auto; gap: 10px; -webkit-overflow-scrolling: touch; }
  #cp-summary-cards > * { flex: 0 0 70%; }
  /* side-by-side real vs dry-run → stack */
  #page-checkpoint-compare div[style*="grid-template-columns:1fr 1fr"] { grid-template-columns: 1fr !important; }

  /* ╔════════════════════════════════════════════════════════════════╗
     ║  SEARCH                                                          ║
     ╚════════════════════════════════════════════════════════════════╝ */
  #page-search > div[style*="display:flex"][style*="gap:16px"] { flex-direction: column; }
  #search-history-panel { width: 100% !important; }

  /* ╔════════════════════════════════════════════════════════════════╗
     ║  UPLOAD                                                          ║
     ╚════════════════════════════════════════════════════════════════╝ */
  #page-upload > div[style*="flex-wrap:wrap"] { gap: 10px; }   /* mode toggle */
  #page-upload label[style*="margin-left:auto"], 
  #page-upload span[style*="margin-left:auto"] { margin-left: 0 !important; }
  .upload-zone { padding: 36px 18px; }

  /* ╔════════════════════════════════════════════════════════════════╗
     ║  MODALS + AUTH                                                   ║
     ╚════════════════════════════════════════════════════════════════╝ */
  .modal { width: calc(100vw - 28px); max-width: 100%; padding: 20px 16px; margin: 0 14px; }
  .form-grid { grid-template-columns: 1fr !important; }
  .modal-overlay { align-items: flex-end; }          /* bottom-sheet feel */
  .modal { border-radius: 16px 16px 0 0; }
  .auth-card { margin: 0 14px; padding: 28px 20px; }
}

/* ── True touch devices (any width): keep row actions tappable ── */
@media (hover: none) {
  .row-actions { opacity: 1 !important; }
}

/* ── Watchlist rows: icon-only Dry Run button on mobile ── */
@media (max-width: 768px) {
  .wl-dry-label { display: none; }
  .wl-row { gap: 8px !important; }
}

/* ── Compare tab: per-symbol Real-vs-DryRun cards (mobile only) ── */
@media (max-width: 768px) {
  .cmp-list { display: flex; flex-direction: column; gap: 10px; }
  .cmp-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 14px; padding: 13px 14px; cursor: pointer;
  }
  .cmp-id { display: flex; flex-direction: column; gap: 2px; margin-bottom: 10px; }
  .cmp-name { font-size: 14px; font-weight: 600; color: var(--ink); }
  .cmp-sym { font-size: 11.5px; font-weight: 500; color: var(--ink-dim); display: flex; align-items: center; gap: 5px; }
  .cmp-body {
    display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
    border-top: 1px solid var(--border); padding-top: 10px;
  }
  .cmp-side { display: flex; flex-direction: column; gap: 2px; }
  .cmp-side .lbl { font-size: 10px; font-weight: 600; color: var(--ink-faint); text-transform: uppercase; letter-spacing: .06em; }
  .cmp-side .val { font-size: 14.5px; font-weight: 650; color: var(--ink); font-variant-numeric: tabular-nums; }
  .cmp-side .pl { font-size: 11.5px; font-variant-numeric: tabular-nums; }
}

/* ── Pull-to-refresh indicator (created by JS, mobile only) ── */
#ptr-indicator {
  position: fixed; top: 8px; left: 50%;
  transform: translate(-50%, 0);
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--surface); border: 1px solid var(--border);
  display: none; align-items: center; justify-content: center;
  color: var(--ink-dim); opacity: 0; z-index: 300;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .25);
  pointer-events: none;
  transition: opacity .15s;
}
@media (max-width: 768px) { #ptr-indicator { display: flex; } }
#ptr-indicator.ready { color: var(--violet); border-color: var(--violet); }
#ptr-indicator.spinning svg { animation: ptr-spin .8s linear infinite; }
@keyframes ptr-spin { to { transform: rotate(360deg); } }

/* ── Mobile search page: prominent full-width search bar under the header ── */
@media (max-width: 768px) {
  body.on-search-page header { height: auto; flex-wrap: wrap; padding-bottom: 10px; }
  body.on-search-page .header-search-wrap {
    display: block !important;
    order: 99;                /* drop to its own row below the header items */
    flex-basis: 100%;
    max-width: none;
    margin: 6px 0 0;
  }
  body.on-search-page .header-search-wrap input {
    height: 48px;
    font-size: 16px !important;  /* ≥16px prevents iOS auto-zoom on focus */
    border-radius: 12px;
    border: 1.5px solid var(--violet);
    padding: 0 44px 0 40px;
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.12);
  }
  body.on-search-page .header-search-icon { left: 14px; }
  body.on-search-page .header-search-kbd { display: none; }
  body.on-search-page #search-dropdown {
    width: 100%;
    left: 0;
    right: 0;
  }
}
