/* ═══════════════════════════════════════════════════════════════
   FLUID TRADER — Mobile Dashboard
   Breakpoint : ≤ 768px
   Desktop    : UNTOUCHED (every rule is inside a media query)
   Strategy   : bottom-tab navigation + card/column rearrangement
   ═══════════════════════════════════════════════════════════════ */

/* ── Hide mobile-only elements on desktop ─────────────────────── */
@media (min-width: 769px) {
  .mobile-bottom-nav,
  .mbn-sheet,
  .mbn-backdrop { display: none !important; }
}

/* ══════════════════════════════════════════════════════════════════
   MOBILE  ≤ 768px
   ══════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {

  /* ────────────────────────────────────────────────────────────────
     BOTTOM NAVIGATION BAR
     ──────────────────────────────────────────────────────────────── */
  .mobile-bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    z-index: 1000;
    height: 56px;
    background: var(--bg-dark);
    border-top: 1px solid rgba(0,229,255,0.15);
    box-shadow: 0 -6px 28px rgba(0,0,0,0.72), 0 -1px 0 rgba(0,229,255,0.06);
  }

  .mbn-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    color: var(--text-muted);
    text-decoration: none;
    font-family: var(--font-mono);
    cursor: pointer;
    transition: color 0.15s, background 0.15s;
    -webkit-tap-highlight-color: rgba(0,229,255,0.1);
    min-height: 44px;
    border: none;
    background: transparent;
    padding: 0.3rem 0.15rem;
  }

  .mbn-item:active { background: rgba(0,229,255,0.06); }

  .mbn-item.mbn-active { color: var(--accent); }
  .mbn-item.mbn-active .mbn-icon {
    filter: drop-shadow(0 0 5px rgba(0,229,255,0.65));
  }

  .mbn-icon { font-size: 1.18rem; line-height: 1; }
  .mbn-label { font-size: 0.52rem; letter-spacing: 0.04em; text-transform: uppercase; line-height: 1; }

  /* ── More sheet (slides up from bottom) ────────────────────── */
  .mbn-backdrop {
    display: none;
    position: fixed; inset: 0; z-index: 998;
    background: rgba(0,0,0,0.62);
  }
  .mbn-backdrop.open { display: block; }

  .mbn-sheet {
    display: block;
    position: fixed;
    bottom: -100%; left: 0; right: 0;
    z-index: 999;
    background: var(--bg-secondary);
    border-top: 1px solid rgba(0,229,255,0.22);
    border-radius: 14px 14px 0 0;
    padding-bottom: 1rem;
    transition: bottom 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 -10px 48px rgba(0,0,0,0.75);
  }
  .mbn-sheet.open { bottom: 56px; }

  .mbn-sheet-handle {
    width: 38px; height: 4px;
    background: rgba(0,229,255,0.18);
    border-radius: 2px;
    margin: 0.6rem auto 0.75rem;
    cursor: pointer;
  }

  .mbn-sheet-item {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    padding: 0.72rem 1.5rem;
    font-family: var(--font-mono);
    font-size: 0.78rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-secondary);
    text-decoration: none;
    border-bottom: 1px solid var(--border-color);
    transition: background 0.12s, color 0.12s;
    -webkit-tap-highlight-color: rgba(0,229,255,0.08);
  }
  .mbn-sheet-item:last-child { border-bottom: none; }
  .mbn-sheet-item:active { background: rgba(0,229,255,0.06); color: var(--accent); }
  .mbn-sheet-item.mbn-logout { color: var(--color-danger); }

  /* ────────────────────────────────────────────────────────────────
     TOPBAR — compact on mobile
     ──────────────────────────────────────────────────────────────── */
  .topbar {
    padding: 0.45rem 0.75rem !important;
    flex-wrap: nowrap !important;
    min-height: 46px;
  }

  /* Hamburger — keep as compact icon-only tap trigger (fallback menu) */
  .hamburger {
    border: none !important;
    padding: 0.28rem 0.45rem !important;
    background: transparent !important;
  }
  .hamburger-brand { display: none !important; }
  .hamburger-icon  { font-size: 1.1rem; }

  /* Hamburger dropdown — make touch-friendly */
  .hamburger-menu { min-width: 175px; font-size: 0.7rem; }
  .hamburger-menu a { padding: 0.55rem 1rem; font-size: 0.7rem; }

  /* Topbar right */
  .topbar-right { gap: 0.45rem !important; }

  /* Logout btn — icon only */
  .btn-logout {
    font-size: 0 !important;
    padding: 0.32rem 0.55rem !important;
    min-width: 32px;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
  }
  .btn-logout::before { content: '↩'; font-size: 0.88rem; color: var(--text-secondary); }

  /* SSE text labels — hide, keep dot only */
  #sse-label, .sse-label { display: none !important; }
  .sse-status { gap: 0 !important; }

  /* FT toggle label — hide text */
  .ft-toggle .ft-lbl { display: none; }

  /* Node topbar-status */
  .topbar-status { font-size: 0.6rem !important; gap: 4px !important; }

  /* ────────────────────────────────────────────────────────────────
     MAIN CONTENT — bottom padding above tab bar
     ──────────────────────────────────────────────────────────────── */
  .main,
  .journal-main,
  .xp-main {
    padding: 0.75rem 0.6rem 5.5rem !important;
    max-width: 100% !important;
  }

  /* ────────────────────────────────────────────────────────────────
     UNIVERSAL CARD + TABLE
     ──────────────────────────────────────────────────────────────── */
  .card { margin-bottom: 0.6rem; }
  .card-head { padding: 0.52rem 0.75rem !important; }
  .card-head h2, .card-title { font-size: 0.74rem !important; }

  /* All scrollable table wrappers */
  .tbl-wrap,
  div[style*="overflow-x:auto"],
  div[style*="overflow-x: auto"] {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Generic table styles */
  table { min-width: 440px; font-size: 0.77rem; }
  th, td { padding: 0.4rem 0.52rem !important; font-size: 0.74rem !important; }

  /* Footer */
  .footer {
    padding: 0.55rem !important;
    font-size: 0.57rem !important;
    margin-bottom: 4.75rem;
  }

  /* Tooltips — suppress on mobile (hover = tap = poor UX) */
  [data-tip]::after { display: none !important; }
  .has-tip .tip    { display: none !important; }

  /* ────────────────────────────────────────────────────────────────
     DASHBOARD PAGE  (/dashboard)
     ──────────────────────────────────────────────────────────────── */

  /* Balance hero strip */
  .usdt-hero {
    padding: 0.8rem 0.9rem !important;
    margin-bottom: 0.65rem !important;
    flex-wrap: nowrap !important;
    gap: 0.5rem !important;
  }
  .usdt-amount { font-size: 1.6rem !important; }
  .btn-buy-main { padding: 0.42rem 0.8rem !important; font-size: 0.7rem !important; white-space: nowrap; }

  /* Chips → 2-col grid */
  .chips {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 0.38rem !important;
    flex-wrap: unset !important;
    margin-bottom: 0.65rem !important;
  }
  .chip {
    flex: none !important;
    min-width: unset !important;
    padding: 0.52rem 0.65rem !important;
  }
  .chip .cval   { font-size: 0.92rem !important; }
  .chip .clabel { font-size: 0.6rem !important; }

  /* Modal */
  #modal-overlay { padding: 0.75rem; }
  #modal-box {
    min-width: unset !important;
    width: 100% !important;
    max-width: 100% !important;
    padding: 1.25rem !important;
    margin: 0 !important;
  }

  /* Toast — sit above bottom nav */
  #toast { bottom: 4.75rem !important; right: 0.6rem !important; }
  .toast-item { font-size: 0.7rem; padding: 0.48rem 0.8rem; max-width: 250px; }

  /* ────────────────────────────────────────────────────────────────
     KLINES PAGE  (/klines)
     ──────────────────────────────────────────────────────────────── */
  .summary {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 0.38rem !important;
    flex-wrap: unset !important;
  }

  .sort-bar {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap !important;
    gap: 0.28rem !important;
    padding: 0.38rem 0.65rem !important;
  }
  .sort-btn { white-space: nowrap; font-size: 0.58rem !important; padding: 0.18rem 0.42rem !important; }

  /* ────────────────────────────────────────────────────────────────
     TRADER PAGE  (/trader)
     ──────────────────────────────────────────────────────────────── */
  .vol-grid   { grid-template-columns: repeat(2, 1fr) !important; gap: 0.35rem !important; }
  .price-row  { grid-template-columns: 1fr !important; }
  .signal-row { grid-template-columns: repeat(3, 1fr) !important; gap: 0.2rem !important; }
  .te-row {
    grid-template-columns: 22px 56px 85px 66px 1fr !important;
    font-size: 0.59rem !important;
    gap: 0.28rem !important;
    padding: 0.22rem 0.5rem !important;
  }
  .bt-ready-grid { grid-template-columns: 1fr !important; gap: 0.3rem !important; }
  .bt-trade-row  { font-size: 0.57rem !important; }

  /* ────────────────────────────────────────────────────────────────
     MARKET PAGE  (/market)
     ──────────────────────────────────────────────────────────────── */
  .spark-grid  { grid-template-columns: 1fr !important; }
  .vol-windows { grid-template-columns: 1fr !important; }
  .pct-grid    { grid-template-columns: repeat(3, 1fr) !important; }
  .pair-selector { gap: 0.28rem; flex-wrap: wrap; }
  .pair-btn { font-size: 0.65rem !important; padding: 0.22rem 0.48rem !important; }
  .card-body { padding: 0.55rem 0.7rem !important; }

  /* ────────────────────────────────────────────────────────────────
     FLOW / JOURNAL PAGE  (/flow)
     ──────────────────────────────────────────────────────────────── */
  .journal-grid { grid-template-columns: 1fr !important; gap: 0.6rem !important; }
  .log-wrap { max-height: 52vh !important; }

  .stats-strip {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap !important;
    gap: 0.7rem !important;
    padding: 0.38rem 0.65rem !important;
  }
  .log-controls {
    gap: 0.28rem !important;
    padding: 0.32rem 0.5rem !important;
    flex-wrap: wrap !important;
  }
  .filter-btn { font-size: 0.57rem !important; padding: 0.16rem 0.38rem !important; }

  /* FSM pair cards */
  .positions-list { gap: 0.38rem !important; padding: 0.45rem !important; }
  .pair-card { padding: 0.42rem 0.6rem !important; }
  .pc-sym  { font-size: 0.8rem !important; }
  .pc-metrics { gap: 0.55rem !important; }

  /* ────────────────────────────────────────────────────────────────
     SPREAD PAGE  (/spread)
     ──────────────────────────────────────────────────────────────── */
  .xp-grid     { grid-template-columns: 1fr !important; gap: 0.6rem !important; }
  .xp-banner   { padding: 0.42rem 0.7rem !important; gap: 0.6rem !important; }
  .xp-banner-ts { display: none; }

  /* Keep 3-col quote tiles but compact */
  .xp-quotes-row { grid-template-columns: repeat(3, 1fr) !important; }
  .xp-quote { padding: 0.45rem 0.55rem !important; }
  .xq-mid   { font-size: 0.85rem !important; }
  .xq-bidask{ font-size: 0.54rem !important; }
  .xq-ex-label { font-size: 0.55rem !important; }

  .xp-spreads-grid { grid-template-columns: repeat(3, 1fr) !important; gap: 0.45rem !important; }
  .spi-value       { font-size: 0.7rem !important; }
  .spi-label       { font-size: 0.55rem !important; }

  .xp-price-chart-wrap { height: 96px !important; padding: 0.25rem 0.65rem 0.4rem !important; }
  .xp-legend-row { padding: 0 0.65rem 0.3rem !important; gap: 0.5rem !important; font-size: 0.55rem !important; }
  .xp-sec-hdr { padding: 0.4rem 0.65rem 0 !important; }

  /* ────────────────────────────────────────────────────────────────
     NODE PAGE  (/node)
     ──────────────────────────────────────────────────────────────── */
  /* Node uses its own `.main` — ensure bottom padding */
  main.main { padding-bottom: 5.5rem !important; }

  .gauges-row   { grid-template-columns: repeat(3, 1fr) !important; gap: 8px !important; }
  .tiles-row    { grid-template-columns: repeat(2, 1fr) !important; gap: 8px !important; }
  .sparklines-row { grid-template-columns: 1fr !important; gap: 10px !important; }
  .net-grid     { grid-template-columns: 1fr !important; gap: 10px !important; }
  .cpu-row      { grid-template-columns: 1fr 1fr !important; gap: 8px !important; }
  .feeds-summary{ grid-template-columns: repeat(2, 1fr) !important; gap: 8px !important; }
  .cache-tiles  { grid-template-columns: repeat(2, 1fr) !important; gap: 8px !important; }
  .trader-grid  { grid-template-columns: repeat(3, 1fr) !important; gap: 8px !important; }
  .ws-summary-bar { grid-template-columns: repeat(2, 1fr) !important; gap: 8px !important; }

  /* Node tab bar */
  .tab-bar {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap !important;
  }
  .tab-btn {
    white-space: nowrap;
    font-size: 0.64rem !important;
    padding: 0.48rem 0.65rem !important;
  }

  /* ────────────────────────────────────────────────────────────────
     INDICATOR / ALL PAIRS  (/indicator, /indicator/all)
     ──────────────────────────────────────────────────────────────── */
  #pairs-table th,
  #pairs-table td { padding: 0.28rem 0.32rem !important; font-size: 0.64rem !important; }

  /* Hide low-priority columns to save horizontal space */
  .col-macd, .col-stoch, .col-vwap, .col-ema, .col-candle { display: none !important; }

  .ctrl-bar { gap: 0.5rem !important; flex-wrap: wrap !important; }
  .filter-input { width: 108px !important; font-size: 0.72rem !important; }

  /* ────────────────────────────────────────────────────────────────
     STRATEGY PAGE  (/strategies)
     ──────────────────────────────────────────────────────────────── */
  .form-grid  { grid-template-columns: 1fr !important; gap: 0.55rem !important; }
  .pairs-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 0.38rem !important; }

  /* Strategy layout grid (the 280px + 1fr two-column) */
  [style*="grid-template-columns:280px"],
  [style*="grid-template-columns: 280px"] {
    grid-template-columns: 1fr !important;
  }

  /* ────────────────────────────────────────────────────────────────
     VOLATILITY PAGE  (/volatility)
     ──────────────────────────────────────────────────────────────── */
  .stats-bar { grid-template-columns: repeat(2, 1fr) !important; gap: 0.45rem !important; }
  .vbar-row  { font-size: 0.7rem !important; }

}

/* ═══════════════════════════════════════════════════════════════
   EXTRA SMALL  ≤ 380px  (iPhone SE, small Android)
   ═══════════════════════════════════════════════════════════════ */
@media (max-width: 380px) {
  .chips, .summary { grid-template-columns: 1fr 1fr !important; }
  .chip .cval    { font-size: 0.82rem !important; }

  .vol-grid      { grid-template-columns: 1fr !important; }
  .pairs-grid    { grid-template-columns: 1fr !important; }
  .gauges-row    { grid-template-columns: 1fr 1fr !important; }
  .pct-grid      { grid-template-columns: repeat(2, 1fr) !important; }

  .xp-quotes-row { grid-template-columns: 1fr !important; }
  .xp-spreads-grid { grid-template-columns: 1fr !important; }

  /* Very small: hide bottom nav labels, show icons only */
  .mbn-label { display: none !important; }
  .mbn-icon  { font-size: 1.3rem; }
  .mbn-item  { padding: 0.2rem 0.1rem; }
}
