/* ═══════════════════════════════════════════════════════════════════
   FinSight — Mobile Pro
   Loaded after detail-pro.css and index-pro.css.
   Mobile-first overrides for body.pro on screens ≤ 760px.
   Breakpoints:
     - tablet/landscape phone:  ≤ 760px
     - portrait phone:          ≤ 480px
     - small phone:             ≤ 360px
═══════════════════════════════════════════════════════════════════ */

/* ───────────────────────────────────────────────────────────
   1. Global mobile chrome (≤ 760px)
─────────────────────────────────────────────────────────── */
@media (max-width: 760px) {
  body.pro {
    /* Slightly tighter token rhythm on mobile */
    --radius: 8px;
    --radius-sm: 5px;
    --radius-lg: 12px;
  }

  /* Kill double padding: container handles spacing */
  body.pro .main-content {
    padding: 0 !important;
    overflow-x: hidden;
  }
  body.pro .container {
    padding: 0 12px 96px !important;  /* leave room for bottom-nav (64px) */
  }

  /* Allow full-bleed but no horizontal page scroll */
  html, body { overflow-x: hidden; }

  /* Touch targets: every clickable element should reach ≥ 40px */
  body.pro button,
  body.pro a.btn,
  body.pro .pro-icon-btn {
    min-height: 36px;
  }
}

/* ───────────────────────────────────────────────────────────
   2. Mobile titlebar — compact, sticky
─────────────────────────────────────────────────────────── */
@media (max-width: 760px) {
  body.pro .titlebar {
    height: 52px;
    padding: 0 10px;
    gap: 8px;
    position: sticky;
    top: 0;
    z-index: 40;
  }
  body.pro .titlebar-brand .brand-name { font-size: 14px; }
  body.pro .titlebar-brand .brand-dot  { width: 7px; height: 7px; }

  /* Hide noisy/desktop-only widgets */
  body.pro .titlebar .ticker-bar,
  body.pro .titlebar .titlebar-drag,
  body.pro .titlebar .win-controls { display: none !important; }

  /* Collapse 5 theme swatches into a single popover button */
  body.pro .titlebar .theme-swatches {
    display: none !important;
  }
  body.pro .titlebar .theme-swatches.mob-open {
    display: flex !important;
    position: absolute;
    top: 56px;
    right: 12px;
    background: var(--bg-elevated);
    border: 1px solid var(--line-strong);
    border-radius: 10px;
    padding: 8px;
    gap: 8px;
    box-shadow: 0 12px 32px rgba(0,0,0,0.4);
    z-index: 80;
  }
  body.pro .titlebar .theme-swatches.mob-open .swatch {
    width: 28px;
    height: 28px;
  }

  /* Kebab menu button (created by JS) */
  body.pro .mob-titlebar-kebab {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    width: 36px; height: 36px;
    background: var(--bg-elevated);
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--text-secondary);
    cursor: pointer;
  }

  /* Hamburger for sidebar (created by JS) */
  body.pro .mob-titlebar-burger {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    width: 36px; height: 36px;
    background: transparent;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--text-secondary);
    cursor: pointer;
    margin-right: 4px;
  }

  /* Search button: shrink to icon-only */
  body.pro .titlebar .search-btn {
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: 8px;
  }
  body.pro .titlebar .search-btn span,
  body.pro .titlebar .search-btn .search-btn-kbd {
    display: none !important;
  }

  /* Mode toggle: keep but compact */
  body.pro .titlebar .mode-toggle {
    width: 36px; height: 36px;
    border-radius: 8px;
  }

  body.pro .titlebar-actions { gap: 6px; }
}

/* Desktop — hide mobile-only buttons */
body.pro .mob-titlebar-burger,
body.pro .mob-titlebar-kebab { display: none; }

/* ───────────────────────────────────────────────────────────
   3. Off-canvas sidebar drawer
─────────────────────────────────────────────────────────── */
@media (max-width: 760px) {
  body.pro .sidebar {
    /* override style.css's display:none */
    display: flex !important;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    background: var(--bg-surface);
    border-right: 1px solid var(--line-strong);
    z-index: 90;
    transform: translateX(-100%);
    transition: transform .25s cubic-bezier(.4,0,.2,1);
    box-shadow: 4px 0 24px rgba(0,0,0,0.4);
    padding-top: 12px;
  }
  body.pro .sidebar.mob-open { transform: translateX(0); }

  body.pro .sidebar-toggle { display: none !important; }

  body.pro .sidebar .nav-item {
    padding: 12px 16px;
    border-radius: 0;
    font-size: 14px;
  }
  body.pro .sidebar .nav-item .nav-label {
    display: inline-block !important;
    margin-left: 12px;
  }

  /* Backdrop overlay */
  body.pro .mob-sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.55);
    z-index: 80;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s;
  }
  body.pro .mob-sidebar-overlay.active {
    opacity: 1;
    pointer-events: auto;
  }
}

/* ───────────────────────────────────────────────────────────
   4. Detail page mobile layout
─────────────────────────────────────────────────────────── */
@media (max-width: 760px) {
  /* Hero */
  body.pro .pro-hero { padding-top: 16px; margin-bottom: 14px; }
  body.pro .pro-hero-grid {
    grid-template-columns: auto 1fr;
    grid-template-rows: auto auto;
    gap: 14px;
    align-items: start;
  }
  body.pro .pro-logo { width: 52px; height: 52px; border-radius: 10px; }
  body.pro .pro-name { font-size: 20px; gap: 8px; }
  body.pro .pro-ticker { font-size: 12px; padding: 2px 8px; }
  body.pro .pro-meta { font-size: 11px; gap: 8px; margin-top: 6px; }
  body.pro .pro-meta-item { gap: 4px; }
  body.pro .pro-actions {
    grid-column: 1 / -1;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 4px;
  }
  body.pro .pro-icon-btn {
    height: 34px;
    min-height: 34px;
    padding: 0 12px;
    font-size: 12px;
    flex: 1 1 auto;
    justify-content: center;
    min-width: 0;
  }

  /* KPI strip — 2 cols, lighter */
  body.pro .pro-kpi-strip {
    grid-template-columns: 1fr 1fr;
  }
  body.pro .pro-kpi { padding: 10px 12px; }
  body.pro .pro-kpi-label { font-size: 9.5px; letter-spacing: 0.06em; }
  body.pro .pro-kpi-value { font-size: 17px; }
  body.pro .pro-kpi-meta  { font-size: 10.5px; }

  /* Snapshot grid — single column */
  body.pro .pro-snapshot {
    grid-template-columns: 1fr;
    gap: 12px;
    margin-top: 18px;
  }
  body.pro .pro-card { padding: 14px 14px 12px; }
  body.pro .pro-card-title h3 { font-size: 11px; }

  /* Scorecard rows: simpler grid on mobile */
  body.pro .pro-score-row {
    grid-template-columns: 84px 1fr auto;
    gap: 10px;
    padding: 8px 10px;
  }
  body.pro .pro-score-row .pro-score-num { display: none; }
  body.pro .pro-score-name { font-size: 12.5px; }
  body.pro .pro-score-name small { font-size: 10px; }
  body.pro .pro-grade-badge { width: 34px; height: 26px; font-size: 12px; }

  /* Radar — compact */
  body.pro .pro-radar-wrap { height: 240px; }
  body.pro .pro-radar-legend { font-size: 10.5px; gap: 10px; flex-wrap: wrap; }

  /* Insights — full width chips */
  body.pro .pro-insights {
    grid-template-columns: 1fr;
    gap: 8px;
    margin-top: 14px;
  }
  body.pro .pro-insight { padding: 10px 12px; }
  body.pro .pro-insight-msg { font-size: 12.5px; }

  /* Annual highlights — 2 col mini grid */
  body.pro .pro-annual-highlights .pro-mini-grid {
    grid-template-columns: 1fr 1fr;
  }
  body.pro .pro-mini-tile { padding: 10px 12px; }
  body.pro .pro-mini-value { font-size: 15px; }
  body.pro .pro-mini-label { font-size: 9.5px; }

  /* Sticky tabs — wider tap area + scroll cue */
  body.pro .pro-tabs-wrap {
    margin-left: -12px;
    margin-right: -12px;
    padding: 0 12px;
    top: 52px; /* below mobile titlebar */
    background-image:
      linear-gradient(to right, var(--bg-base) 0%, transparent 12px),
      linear-gradient(to left,  var(--bg-base) 0%, transparent 12px);
    background-position: left center, right center;
    background-size: 24px 100%;
    background-repeat: no-repeat;
  }
  body.pro .pro-tab {
    padding: 13px 14px;
    font-size: 13px;
    flex-shrink: 0;
  }

  /* Toolbar — wrap nicely */
  body.pro .pro-toolbar {
    gap: 8px;
    padding: 12px 0 10px;
  }
  body.pro .pro-toolbar-label { font-size: 9.5px; }
  body.pro .pro-seg button { padding: 7px 12px; font-size: 11.5px; min-height: 32px; }
  body.pro .pro-search { width: 100%; margin-left: 0; order: 99; }

  /* Statement tables — keep first col sticky, allow horizontal scroll */
  body.pro .stmt-wrap { border-radius: 8px; }
  body.pro .stmt-table thead th { font-size: 10px; padding: 8px 8px; }
  body.pro .stmt-table thead th:first-child { min-width: 170px; }
  body.pro .stmt-table tbody td { padding: 8px 8px; font-size: 12px; }
  body.pro .stmt-table tbody td:first-child { font-size: 12.5px; }
  body.pro .stmt-table tbody tr.section-hdr td { font-size: 10px; padding: 7px 8px; }

  /* Statement scroll arrows: bigger, easier to tap */
  body.pro .stmt-arrow { width: 36px; height: 36px; font-size: 20px; }

  /* Period quick nav — wrap */
  body.pro .period-quick-nav { gap: 6px; }
  body.pro .period-quick-nav .period-quick-btn {
    padding: 7px 12px;
    font-size: 12px;
    min-height: 32px;
  }

  /* Valuation tab inputs — single col on small phones, 2 col bigger */
  body.pro .pro-val-inputs { padding: 12px 14px 10px; }
  body.pro .pro-val-input-grid { gap: 10px; }
  body.pro .pro-val-input-grid .val-input-group input { padding: 9px 10px; font-size: 13px; }
  body.pro .pro-val-grid { gap: 12px; margin-top: 12px; }
  body.pro .pro-val-bigvalue { font-size: 22px; }
  body.pro .pro-val-row { padding: 9px 0; font-size: 12px; }
  body.pro .pro-val-hint { font-size: 10px; }

  /* Notes textarea */
  body.pro .pro-notes { padding: 10px 12px; }
  body.pro .pro-notes textarea { font-size: 13px; }

  /* Reports section: compact + horizontal scroll on table */
  body.pro .pro-reports { padding: 14px 14px 12px; }
  body.pro .pro-reports .data-table { font-size: 11.5px; }
  body.pro #reports-table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  body.pro #reports-tbody td { white-space: nowrap; }
}

/* ───────────────────────────────────────────────────────────
   5. Index pages mobile (Dashboard / Companies / Compare)
─────────────────────────────────────────────────────────── */
@media (max-width: 760px) {
  body.pro .page-header { padding: 18px 0 12px; margin-bottom: 14px; }
  body.pro .page-title { font-size: 19px; }
  body.pro .page-subtitle { font-size: 12px; }

  /* Dashboard */
  body.pro .bento-grid { gap: 10px; }
  body.pro .bento-sm  { grid-column: span 6; min-height: 88px; padding: 12px 14px !important; }
  body.pro .bento-md  { grid-column: span 12; }
  body.pro .bento-lg  { grid-column: span 12; }
  body.pro .bento-act { grid-column: span 12; padding: 14px !important; }
  body.pro .stat-icon { width: 24px; height: 24px; }
  body.pro .stat-icon svg { width: 13px; height: 13px; }
  body.pro .stat-label { font-size: 9.5px; }
  body.pro .stat-value { font-size: 19px; }

  body.pro .dash-company-list .dash-company-item,
  body.pro .dash-company-list a,
  body.pro .dash-company-list > div { padding: 12px 14px; font-size: 13px; }

  /* Companies page header — stack search + toggle */
  body.pro .companies-header {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  body.pro .companies-header > div { min-width: 0; }
  body.pro .companies-header .company-search-input {
    width: 100%;
    height: 38px;
    font-size: 14px;
  }
  body.pro .view-toggle { align-self: flex-end; }

  /* Companies table → existing style.css already converts to flex-wrap cards;
     Override visuals only, keep layout. */
  body.pro #page-companies > .card.glass-card,
  body.pro #page-companies > .glass-card {
    background: transparent !important;
    border: 0 !important;
  }
  body.pro #company-table tbody tr.company-row {
    background: var(--bg-surface) !important;
    border: 1px solid var(--line) !important;
    border-radius: 10px !important;
    backdrop-filter: none !important;
    box-shadow: none !important;
    padding: 12px 14px !important;
    margin-bottom: 8px !important;
    transition: background .15s, border-color .15s !important;
  }
  body.pro #company-table tbody tr.company-row:hover {
    background: var(--bg-elevated) !important;
    border-color: var(--line-strong) !important;
  }
  body.pro #company-table tbody tr.company-row:active {
    transform: scale(0.99) !important;
  }
  /* Avatar size for mobile cards */
  body.pro #company-table tbody td:nth-child(2) .co-avatar,
  body.pro #company-table tbody td:nth-child(2) .co-avatar-img {
    width: 40px !important; height: 40px !important;
    border-radius: 10px !important;
  }
  body.pro #company-table .co-name { font-size: 15px !important; font-weight: 600 !important; }
  body.pro #company-table .co-ticker {
    font-family: 'JetBrains Mono', monospace;
    font-size: 10.5px;
    padding: 1px 6px;
    background: var(--bg-elevated);
    color: var(--text-muted);
    border-radius: 4px;
  }
  /* Action buttons: full-width Pro flat */
  body.pro #company-table tbody td:nth-child(7) .btn-action-view {
    background: var(--bg-elevated) !important;
    border: 1px solid var(--line-strong) !important;
    color: var(--text-primary) !important;
    border-radius: 6px !important;
    font-size: 12.5px !important;
  }
  body.pro #company-table tbody td:nth-child(7) .btn-action-del {
    background: transparent !important;
    border: 1px solid var(--loss) !important;
    color: var(--loss) !important;
    border-radius: 6px !important;
    padding: 8px 14px !important;
    font-size: 12.5px !important;
  }
  /* Inject grade chip alignment */
  body.pro #company-table tbody td:nth-child(6) .pro-chip-grade {
    margin-left: 6px !important;
  }

  /* Bulk action bar — fixed at bottom on mobile when active */
  body.pro .bulk-action-bar { flex-wrap: wrap; gap: 8px; padding: 10px 12px; }

  /* Compare page */
  body.pro #compare-select .compare-company-grid {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  body.pro .pro-cmp-grid { grid-template-columns: 1fr; gap: 14px; }
  body.pro #pro-cmp-radar { height: 280px !important; }
  body.pro .pro-cmp-table { font-size: 11.5px; }
  body.pro .pro-cmp-table thead th { padding: 7px 4px; font-size: 9.5px; }
  body.pro .pro-cmp-table tbody td { padding: 8px 4px; }
  body.pro .pro-cmp-table .pro-chip-grade { width: 24px; height: 20px; font-size: 10px; }
  body.pro .pro-cmp-color-dot { width: 7px; height: 7px; margin-right: 5px; }
  body.pro .pro-cmp-ticker { font-size: 9.5px; padding: 1px 4px; margin-left: 4px; }

  /* Compare result table — horizontal scroll */
  body.pro .compare-table-wrap { margin: 0 -12px; padding: 0 12px; }
}

/* ───────────────────────────────────────────────────────────
   6. Mobile bottom nav — Pro skin + safe area
─────────────────────────────────────────────────────────── */
@media (max-width: 760px) {
  body.pro .mobile-bottom-nav {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 60;
    background: rgba(7,9,15,0.94);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    border-top: 1px solid var(--line-strong);
    padding-bottom: env(safe-area-inset-bottom, 0);
    display: block;
  }
  body.pro.light .mobile-bottom-nav {
    background: rgba(255,255,255,0.94);
  }
  body.pro .mobile-bottom-nav-inner {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    height: 56px;
  }
  body.pro .mob-nav-item {
    display: flex !important;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    background: transparent;
    border: 0;
    cursor: pointer;
    color: var(--text-muted);
    text-decoration: none;
    padding: 4px 2px;
    font-size: 10.5px;
    font-weight: 600;
  }
  body.pro .mob-nav-item svg {
    width: 19px; height: 19px;
  }
  body.pro .mob-nav-item.active {
    color: var(--accent);
  }
  body.pro .mob-nav-item:active {
    background: var(--bg-elevated);
  }
}

/* Hide bottom nav on desktop */
@media (min-width: 761px) {
  body.pro .mobile-bottom-nav { display: none !important; }
}

/* ───────────────────────────────────────────────────────────
   7. Small phones (≤ 480px) — extra tighten
─────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  body.pro .container { padding: 0 10px 96px !important; }
  body.pro .pro-tabs-wrap { margin-left: -10px; margin-right: -10px; padding: 0 10px; }
  body.pro .pro-name { font-size: 18px; }
  body.pro .pro-logo { width: 46px; height: 46px; }
  body.pro .pro-kpi-value { font-size: 16px; }
  body.pro .pro-val-input-grid { grid-template-columns: 1fr 1fr; }
  body.pro .pro-mini-tile { padding: 9px 10px; }
  body.pro .pro-mini-value { font-size: 14px; }
  body.pro #company-table tbody tr.company-row {
    grid-template-columns: auto 1fr auto;
    gap: 4px 10px;
  }
  body.pro #company-table .co-avatar {
    width: 34px !important; height: 34px !important;
  }
}

/* ───────────────────────────────────────────────────────────
   8. Print mode tidy
─────────────────────────────────────────────────────────── */
@media print {
  body.pro .titlebar,
  body.pro .sidebar,
  body.pro .mobile-bottom-nav,
  body.pro .pro-actions,
  body.pro .pro-tabs-wrap { display: none !important; }
  body.pro .container { padding: 0 !important; }
  body.pro .pro-card { break-inside: avoid; }
}

/* ───────────────────────────────────────────────────────────
   9. v3 — collapse sparkline column on narrow screens
   The 5期趋势 column adds ~80px; on phones it crowds the latest
   period off-screen. Hide gracefully ≤ 760px.
─────────────────────────────────────────────────────────── */
@media (max-width: 760px) {
  body.pro .stmt-table thead th.spark-h,
  body.pro .stmt-table tbody td.spark-cell {
    display: none !important;
  }
  /* Re-tighten the latest-tag on mobile (smaller cells) */
  body.pro .stmt-table thead th.latest .latest-tag {
    font-size: 8px;
    letter-spacing: 0.08em;
  }
}

/* ───────────────────────────────────────────────────────────
   10. v3 — filing lookup mobile stack
─────────────────────────────────────────────────────────── */
@media (max-width: 720px) {
  body.pro .fl-frame .fl-search-row {
    flex-direction: column;
    align-items: stretch;
    padding: 14px 14px 8px;
  }
  body.pro .fl-frame .fl-btn { width: 100%; padding: 11px 16px; }
  body.pro .fl-frame .fl-suggested { padding: 8px 14px 12px; }
  body.pro .fl-frame .fl-enter-hint { display: none; }
  body.pro .fl-frame .fl-list { grid-template-columns: 1fr; }
  body.pro .fl-frame .fl-result { padding: 14px; }
  body.pro .fl-frame .fl-meta { gap: 8px; }
  body.pro .fl-frame .fl-meta-company { font-size: 17px; }
  body.pro .fl-frame .fl-meta-count { margin-left: 0; flex-basis: 100%; }
}

/* ───────────────────────────────────────────────────────────
   11. v3 — onboarding overlay mobile
─────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .onboarding-overlay.onboarding-v3 { padding: 12px; }
  .onboarding-v3 .onboarding-card {
    padding: 32px 20px 16px;
    border-radius: 14px;
  }
  .onboarding-v3 .onb-h {
    font-size: clamp(24px, 6vw + 6px, 32px);
    line-height: 1.12;
  }
  .onboarding-v3 .onb-sub { font-size: 13px; margin-bottom: 18px; }
  .onboarding-v3 .onb-visual { min-height: 130px; margin-bottom: 14px; }
  .onboarding-v3 .ob-drag-target { width: 220px; height: 110px; }
  .onboarding-v3 .ob-drop-paper { width: 56px; height: 76px; top: -20px; right: -16px; }
  .onboarding-v3 .ob-extract { min-width: 0; width: 100%; }
  .onboarding-v3 .ob-memo { padding: 14px; }
  .onboarding-v3 .ob-memo-body { font-size: 15px; min-height: 70px; }
}

/* ───────────────────────────────────────────────────────────
   12. v3 — compare narrative & named-metric list on mobile
─────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  body.pro .cmp-narrative {
    flex-direction: column;
    align-items: flex-start;
    padding: 16px;
    gap: 12px;
  }
  body.pro .cmp-narrative-ico { width: 36px; height: 36px; font-size: 17px; }
  body.pro .cmp-narrative-text { font-size: 15px; line-height: 1.45; }
  body.pro .cmp-narrative-text .cmp-narr-list {
    display: block;
    margin: 6px 0 0;
    font-size: 10.5px;
  }
}
