/* =============================================================
   PultScanner — mobile-polish.css
   Additive refinement layer for phones. Loaded AFTER styles.css.
   Non-destructive: only touches spacing, tap targets, stickiness,
   safe-area insets and scroll affordances. No markup/JS changes.
   Scope: <= 720px (phones) with a tighter pass at <= 480px.
   ============================================================= */

/* ---- Global mobile comfort (safe areas + momentum scroll) ---- */
@media (max-width: 720px) {
  html { -webkit-text-size-adjust: 100%; }
  body {
    -webkit-tap-highlight-color: transparent;
    text-rendering: optimizeLegibility;
  }
  /* Momentum scrolling for any horizontally-scrolling strip */
  .nav,
  .toolbar,
  .segmented,
  .scanner-mode-switch,
  .card-actions {
    -webkit-overflow-scrolling: touch;
  }

  /* Sticky header respects the notch / status bar */
  .sidebar {
    padding-top: calc(8px + env(safe-area-inset-top)) !important;
    padding-left: calc(12px + env(safe-area-inset-left)) !important;
    padding-right: calc(12px + env(safe-area-inset-right)) !important;
  }

  /* Give the workspace breathing room at the bottom (home indicator) */
  .workspace {
    padding-bottom: calc(40px + env(safe-area-inset-bottom)) !important;
  }
}

/* ---- Primary nav: clearer scroll affordance + comfy targets ---- */
@media (max-width: 720px) {
  .sidebar > .nav:not(.auth-nav) {
    scroll-snap-type: x proximity;
    /* Fade the right edge so it's obvious the row scrolls */
    -webkit-mask-image: linear-gradient(90deg, #000 0, #000 88%, transparent 100%);
            mask-image: linear-gradient(90deg, #000 0, #000 88%, transparent 100%);
    padding-bottom: 3px;
  }
  .sidebar > .nav:not(.auth-nav) a {
    scroll-snap-align: start;
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    border-radius: 9px;
  }
  /* Language switch: keep tap targets >= 40px */
  .lang-switch button {
    min-height: 40px;
    min-width: 40px;
  }
}

/* ---- Reduce time-to-first-signal: trim hero + mode switch ---- */
@media (max-width: 720px) {
  .scanner-mode-switch { margin-bottom: 10px; }
  .title-block { margin-bottom: 8px; }
  .title-block h1 { font-size: 20px; margin-bottom: 2px; }
  .title-block p { font-size: 12px; line-height: 1.45; }

  /* The onboarding / tutorial panel eats the whole first screen on
     mobile — tighten its padding so token cards surface sooner. */
  .scanner-tutorial-panel { padding: 14px !important; margin-bottom: 12px !important; }
  .scanner-tutorial-step h2 { font-size: 18px !important; }
  .scanner-tutorial-step p { margin-top: 10px !important; font-size: 13px !important; }

  /* Market-pulse strip: compact on phones */
  .scanner-market-pulse { padding: 10px 12px !important; margin-bottom: 10px !important; }
}

/* ---- Sticky filter toggle: refilter without scrolling to top ---- */
@media (max-width: 720px) {
  .mobile-filter-toggle {
    position: sticky;
    /* Sit just under the sticky header (approx header height ~52px). */
    top: calc(52px + env(safe-area-inset-top));
    z-index: 60;
    margin-bottom: 10px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, .32);
  }
}

/* ---- Token cards: rhythm + full-bleed chart + touch actions ---- */
@media (max-width: 720px) {
  .card-grid { gap: 14px !important; }
  .card-grid .token-card { border-radius: 14px; }

  .token-card .chart,
  .token-card .chart-wrap { width: 100%; }

  /* Card action buttons comfortable to tap */
  .card-actions .button,
  .card-actions button {
    min-height: 40px;
  }
}

/* ---- iOS: prevent zoom-on-focus (inputs must be >= 16px) ---- */
@media (max-width: 720px) {
  .input,
  .select,
  input[type="search"],
  input[type="text"],
  input[type="email"],
  input[type="password"],
  textarea,
  select {
    font-size: 16px !important;
    min-height: 44px;
  }
  /* Multi-select summaries and segmented buttons: keep tappable */
  .multi-select-trigger,
  .segmented button {
    min-height: 40px;
  }
}

/* ---- Full-screen sheets / quick-view respect the home indicator ---- */
@media (max-width: 720px) {
  .quick-view-panel {
    padding-bottom: calc(12px + env(safe-area-inset-bottom)) !important;
  }
}

/* ---- Tighter pass for small phones (<= 480px) ---- */
@media (max-width: 480px) {
  .workspace { padding-left: 12px !important; padding-right: 12px !important; }
  .scanner-mode-switch button { padding: 6px 8px; }
  .scanner-mode-switch strong { font-size: 12.5px; }
  .scanner-mode-switch span { font-size: 9px; }

  /* Two-up stat grid stays readable; avoid cramped 3-col on tiny screens */
  .card-stats,
  .quick-info { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
}

/* Persistent bottom navigation for phone-sized screens. */
.mobile-tabbar { display: none; }

@media (max-width: 720px) {
  .workspace {
    padding-bottom: calc(86px + env(safe-area-inset-bottom)) !important;
  }
  .sidebar > .nav:not(.auth-nav) { display: none !important; }
  .mobile-tabbar {
    position: fixed;
    z-index: 140;
    left: max(8px, env(safe-area-inset-left));
    right: max(8px, env(safe-area-inset-right));
    bottom: max(8px, env(safe-area-inset-bottom));
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    min-height: 58px;
    padding: 5px;
    border: 1px solid rgba(255, 184, 77, .24);
    border-radius: 12px;
    background: rgba(14, 18, 25, .96);
    box-shadow: 0 12px 34px rgba(0, 0, 0, .55);
    backdrop-filter: blur(16px);
  }
  .mobile-tabbar > a,
  .mobile-tabbar > details > summary {
    min-width: 0;
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 5px 4px;
    border: 0;
    border-radius: 8px;
    color: #9da8b8;
    font-size: 10px;
    font-weight: 700;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
  }
  .mobile-tabbar > a.active {
    color: #17120b;
    background: #f4b454;
    box-shadow: 0 4px 14px rgba(244, 180, 84, .22);
  }
  .mobile-tabbar-more { position: static; }
  .mobile-tabbar-more > summary { list-style: none; }
  .mobile-tabbar-more > summary::-webkit-details-marker { display: none; }
  .mobile-tabbar-more[open] > summary {
    color: #f4b454;
    background: rgba(244, 180, 84, .09);
  }
  .mobile-tabbar-sheet {
    position: fixed;
    left: max(8px, env(safe-area-inset-left));
    right: max(8px, env(safe-area-inset-right));
    bottom: calc(74px + env(safe-area-inset-bottom));
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    padding: 12px;
    border: 1px solid #303744;
    border-radius: 12px;
    background: #141923;
    box-shadow: 0 18px 42px rgba(0, 0, 0, .62);
  }
  .mobile-tabbar-sheet a {
    min-height: 44px;
    display: flex;
    align-items: center;
    padding: 0 12px;
    border: 1px solid #2b3340;
    border-radius: 8px;
    color: #dbe2ec;
    font-size: 12px;
    font-weight: 700;
    text-decoration: none;
  }
  .mobile-tabbar-sheet a.active {
    color: #f4b454;
    border-color: rgba(244, 180, 84, .45);
  }
}
