/* =========================================================================
   NightRug — Mobile navigation
   Cleans up the app top bar (hide ticker / bell / help), injects a
   hamburger button, and styles the bottom nav + slide-up sheet.
   Only applies at <= 900px. Desktop is untouched.
   ========================================================================= */
@media (max-width: 900px) {

  /* -----------------------------------------------------------------------
     1) Make room at the bottom of every page for the fixed bottom nav
     ----------------------------------------------------------------------- */
  body.has-sheet-open { overflow: hidden; }

  .app-content,
  .app-main,
  main {
    padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px));
  }

  /* -----------------------------------------------------------------------
     2) Top bar cleanup — too much noise by default
     ----------------------------------------------------------------------- */
  .app-top {
    gap: 8px !important;
    padding: 0 14px !important;
    min-height: 56px;
  }

  /* Hide the page title (h1) — the bottom nav active state already tells
     the user where they are. The hamburger will fill the space. */
  .app-top-left { display: none !important; }

  /* Hide the elements that don't fit and aren't essential */
  .app-top .price-ticker { display: none !important; }

  /* Notifications bell + help button are moved into the sheet */
  .app-top [data-bell],
  .app-top .icon-btn[aria-label="Help"],
  .app-top [aria-label="Notifications"] {
    display: none !important;
  }

  /* Slim the right cluster down to just the wallet + sign-in */
  .app-top-right { gap: 6px !important; flex-shrink: 0; }
  .app-top-right .has-dd:not([data-signin]):not(.profile-chip-wrap) {
    /* any extra has-dd wrappers the upgrade injects — drop on mobile */
  }

  /* Make the wallet connect button compact */
  .app-top .wallet-landing-cta,
  .app-top [data-wallet-landing],
  .app-top .signed-out-btn {
    height: 36px !important;
    padding: 0 12px !important;
    font-size: 13px !important;
  }
  .app-top .wallet-landing-cta .wl-label { display: inline !important; }
  .app-top .profile-chip {
    height: 36px !important;
    padding: 0 10px !important;
    font-size: 13px !important;
  }
  .app-top .profile-chip span:not(.avatar) { display: none; } /* keep avatar only */
  .app-top .profile-chip .avatar {
    width: 28px !important; height: 28px !important; font-size: 13px !important;
  }

  /* -----------------------------------------------------------------------
     3) Hamburger button (injected into the existing top bar)
     ----------------------------------------------------------------------- */
  .app-burger {
    appearance: none;
    -webkit-tap-highlight-color: transparent;
    background: var(--s2, rgba(255,255,255,0.04));
    border: 1px solid var(--line, rgba(255,255,255,0.08));
    color: var(--t, #fff);
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    margin-right: 8px;
    transition: background 0.15s ease, transform 0.15s ease;
  }
  .app-burger:hover  { background: rgba(255,255,255,0.08); }
  .app-burger:active { transform: scale(0.96); }
  .app-burger svg    { width: 20px; height: 20px; }

  /* Brand wordmark that goes next to the hamburger */
  .app-brand-mini {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
  }
  .app-brand-mini img {
    width: 26px;
    height: 26px;
    flex-shrink: 0;
  }
  .app-brand-mini span {
    font-size: 15px;
    font-weight: 600;
    color: var(--t, #fff);
    letter-spacing: 0.01em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* -----------------------------------------------------------------------
     4) Bottom nav — 4 items, centered icons
     ----------------------------------------------------------------------- */
  .app-bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 60;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    background: rgba(15, 14, 22, 0.92);
    backdrop-filter: saturate(180%) blur(18px);
    -webkit-backdrop-filter: saturate(180%) blur(18px);
    border-top: 1px solid var(--line, rgba(255,255,255,0.07));
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -6px 24px rgba(0,0,0,0.35);
  }

  .bn-item {
    appearance: none;
    -webkit-tap-highlight-color: transparent;
    background: transparent;
    border: 0;
    color: var(--t3, #9aa0aa);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 6px 4px;
    border-radius: 10px;
    text-decoration: none;
    font-size: 11px;
    font-weight: 500;
    min-height: 56px;
    transition: color 0.15s ease, background 0.15s ease;
  }
  .bn-item:hover  { color: var(--t, #fff); }
  .bn-item:active { background: rgba(255,255,255,0.04); }

  .bn-icon {
    width: 22px;
    height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
  }

  .bn-item.is-on {
    color: var(--accent, #a7ff8a);
  }
  .bn-item.is-on .bn-icon { stroke-width: 2.2; }

  /* -----------------------------------------------------------------------
     5) Slide-up sheet (hamburger menu)
     ----------------------------------------------------------------------- */
  .app-more-sheet {
    position: fixed;
    inset: 0;
    z-index: 80;
    pointer-events: none;
  }
  .app-more-sheet.is-open { pointer-events: auto; }

  .ms-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.55);
    opacity: 0;
    transition: opacity 0.22s ease;
  }
  .app-more-sheet.is-open .ms-backdrop { opacity: 1; }

  .ms-panel {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    max-height: 86vh;
    background: var(--s1, #14131c);
    border-top-left-radius: 18px;
    border-top-right-radius: 18px;
    border-top: 1px solid var(--line, rgba(255,255,255,0.08));
    box-shadow: 0 -10px 40px rgba(0,0,0,0.5);
    transform: translateY(100%);
    transition: transform 0.26s cubic-bezier(0.32, 0.72, 0, 1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  .app-more-sheet.is-open .ms-panel { transform: translateY(0); }

  .ms-handle {
    width: 38px;
    height: 4px;
    border-radius: 2px;
    background: var(--line, rgba(255,255,255,0.18));
    margin: 8px auto 4px;
    flex-shrink: 0;
  }

  .ms-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 16px 12px;
    flex-shrink: 0;
  }
  .ms-brand {
    display: flex;
    align-items: center;
    gap: 10px;
  }
  .ms-brand-mark {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
  }
  .ms-brand-text {
    font-size: 16px;
    font-weight: 600;
    color: var(--t, #fff);
  }
  .ms-close {
    appearance: none;
    -webkit-tap-highlight-color: transparent;
    background: var(--s2, rgba(255,255,255,0.04));
    border: 1px solid var(--line, rgba(255,255,255,0.08));
    color: var(--t, #fff);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
  }
  .ms-close:hover { background: rgba(255,255,255,0.08); }

  .ms-body {
    overflow-y: auto;
    overflow-x: hidden;
    padding: 4px 12px calc(20px + env(safe-area-inset-bottom, 0px));
    flex: 1;
  }
  .ms-body::-webkit-scrollbar { width: 0; height: 0; }

  .ms-section { padding: 10px 4px; }
  .ms-section + .ms-section { border-top: 1px solid var(--line, rgba(255,255,255,0.06)); }

  .ms-section-title {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--t3, #9aa0aa);
    padding: 0 8px 8px;
  }

  .ms-item,
  .ms-account {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 12px;
    border-radius: 12px;
    color: var(--t, #fff);
    text-decoration: none;
    font-size: 15px;
    font-weight: 500;
    background: transparent;
    border: 0;
    width: 100%;
    text-align: left;
    cursor: pointer;
    transition: background 0.12s ease;
    -webkit-tap-highlight-color: transparent;
  }
  .ms-item:hover,
  .ms-account:hover { background: var(--s2, rgba(255,255,255,0.05)); }
  .ms-item:active,
  .ms-account:active { background: rgba(255,255,255,0.08); }

  .ms-ico {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: var(--s2, rgba(255,255,255,0.05));
    color: var(--t2, #d6d8de);
    flex-shrink: 0;
  }
  .ms-ico svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
  }

  .ms-item.is-on {
    background: rgba(167, 255, 138, 0.08);
    color: var(--accent, #a7ff8a);
  }
  .ms-item.is-on .ms-ico {
    background: rgba(167, 255, 138, 0.12);
    color: var(--accent, #a7ff8a);
  }

  .ms-item.ms-danger { color: #ff7a7a; }
  .ms-item.ms-danger .ms-ico { color: #ff7a7a; background: rgba(255, 122, 122, 0.10); }

  /* Account block (top of sheet) */
  .ms-account {
    background: var(--s2, rgba(255,255,255,0.04));
    border: 1px solid var(--line, rgba(255,255,255,0.06));
    margin-bottom: 4px;
    padding: 14px 14px;
  }
  .ms-account-out { background: rgba(167, 255, 138, 0.08); border-color: rgba(167,255,138,0.18); color: var(--accent, #a7ff8a); }
  .ms-account-avatar {
    width: 40px; height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #9945FF, #14F195);
    color: #fff;
    font-weight: 600;
    font-size: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
  }
  .ms-account-avatar-out {
    background: rgba(167, 255, 138, 0.15);
    color: var(--accent, #a7ff8a);
  }
  .ms-account-avatar-out svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; }
  .ms-account-body { flex: 1; min-width: 0; }
  .ms-account-name { font-size: 15px; font-weight: 600; color: inherit; }
  .ms-account-sub  { font-size: 12.5px; color: var(--t3, #9aa0aa); margin-top: 2px; }

  /* -----------------------------------------------------------------------
     6) Balance card fix — buttons were overflowing
     ----------------------------------------------------------------------- */
  .balance-card {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 18px !important;
  }
  .balance-card .b-l,
  .balance-card .b-r {
    min-width: 0 !important;
    width: 100% !important;
    flex: 0 0 auto !important;
  }
  .balance-card .b-r {
    display: grid !important;
    grid-template-columns: 1fr 1fr 1fr !important;
    gap: 8px !important;
  }
  .balance-card .b-r .btn {
    width: 100% !important;
    padding: 0 8px !important;
    font-size: 13.5px !important;
    white-space: nowrap;
    text-align: center;
    justify-content: center;
  }

  /* -----------------------------------------------------------------------
     7) Generic app-page improvements
     ----------------------------------------------------------------------- */
  .app-content { padding: 16px !important; }
  .panel       { padding: 18px !important; }

  /* Make horizontal grids that were 2-col become 1-col */
  [style*="grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr)"] {
    grid-template-columns: 1fr !important;
  }

  /* Wallet-gate — when locked, make the CTA sit below the text */
  .wallet-gate {
    flex-direction: column !important;
    align-items: stretch !important;
    text-align: left !important;
    padding: 18px !important;
  }
  .wallet-gate .wg-cta { width: 100%; }
  .wallet-gate .wg-cta .btn { width: 100%; }

  /* KPI row: 2 columns on phone instead of 4 */
  .kpi-row { grid-template-columns: 1fr 1fr !important; }

  /* Dashboard launch progress: stack */
  .launch { grid-template-columns: 1fr !important; }

  /* Withdraw / deposit: stack any 3-col grid (How-it-works cards) */
  [style*="grid-template-columns:repeat(3,1fr)"],
  [style*="grid-template-columns: repeat(3, 1fr)"] {
    grid-template-columns: 1fr !important;
  }
}
