/* ==========================================================================
   DreamFundSL -- phone layout (<= 800px)

   Loaded after app.css, so it owns the app shell on small screens:

     +--------------------------------+
     |  logo  DreamFundSL      bell o |   top bar (fixed height)
     +--------------------------------+
     |                                |
     |      page content scrolls      |   .main -- the only scrolling area
     |                                |
     +--------------------------------+
     |  Home  Txns  Bank  Budget  ... |   bottom tab bar: 4 pages + More
     +--------------------------------+

   Every other page, the language picker, theme and sign-out live in the
   "More" sheet (js/shell/mobileNav.js). Desktop is untouched: every rule is
   inside a media query and the "More" pieces are hidden outside it.
   ========================================================================== */

.nav-more, .ms-backdrop, .ms-sheet { display: none; }
.ms-tile[hidden] { display: none !important; }

@media (max-width: 800px) {
  :root {
    --mb-bar-h: 56px;   /* top bar */
    --mb-nav-h: 60px;   /* bottom tab bar, without the safe-area inset */
    --mb-gutter: 16px;
  }

  html, body { height: 100%; min-height: 100vh; min-height: 100dvh; background: var(--parchment); }
  body { -webkit-tap-highlight-color: transparent; overscroll-behavior-y: none; }
  button, a, [role="button"] { touch-action: manipulation; }

  .app-shell {
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
  }

  /* ---------- Top bar: brand left, bell + avatar right ---------- */
  /* "html .app-shell .sidebar" outranks the seasonal tints in seasonal.css
     (loaded after this file), so the phone top bar is always the clean one. */
  html .app-shell .sidebar {
    flex: 0 0 auto;
    width: 100%;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-height: calc(var(--mb-bar-h) + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) var(--mb-gutter) 0;
    background: var(--card);
    border-bottom: 1px solid var(--line);
    color: var(--text-primary);
  }
  /* no seasonal hairline across the phone app */
  html:has(#appShell:not(.hidden)) .season-lights { display: none; }
  .brand {
    flex: 1 1 auto;
    min-width: 0;
    padding: 0 104px 0 0;      /* clear of the bell + avatar */
    margin: 0;
    border: 0;
    gap: 9px;
  }
  .brand-logo { width: 28px; height: 28px; border-radius: 8px; box-shadow: none; }
  .brand-mark {
    font-size: 17px; font-weight: 700; letter-spacing: -0.01em;
    color: var(--text-strong); white-space: nowrap;
    overflow: hidden; text-overflow: ellipsis;
  }

  /* Profile chip is a plain round avatar; tapping it opens the profile. */
  .user-chip-top {
    order: 3;
    flex: 0 0 auto;
    padding: 0; margin: 0;
    border: 0; border-radius: 50%;
    background: none;
  }
  .user-chip-top:hover { background: none; }
  .user-meta { display: none; }
  .user-avatar-lg { width: 34px; height: 34px; font-size: 13px; border-width: 0; }
  .user-avatar { pointer-events: none; }
  .user-avatar::after { display: none; }

  /* Theme + sign-out live in the More sheet (the sign-out button stays in the
     DOM, hidden, because the sheet triggers it). */
  .sidebar-footer { display: none; }

  /* The bell sits in the top bar, just left of the avatar. Sync status,
     presence, build tag and the language picker are not shown up here. */
  .topbar {
    position: fixed;
    top: env(safe-area-inset-top);
    right: 58px;
    height: var(--mb-bar-h);
    z-index: 31;
    margin: 0; padding: 0;
    background: none; border: 0; border-radius: 0; box-shadow: none;
    display: flex; align-items: center;
  }
  .topbar-left, .topbar-lang, .topbar-cur { display: none; }
  .notif-bell {
    width: 36px; height: 36px;
    border: 0; background: transparent; box-shadow: none;
    color: var(--text-muted);
  }
  .notif-bell:active { background: var(--parchment-dim); }
  .notif-bell svg { width: 21px; height: 21px; }
  .notif-badge { border-color: var(--card); }
  .notif-panel {
    position: fixed;
    top: calc(var(--mb-bar-h) + env(safe-area-inset-top) + 6px);
    bottom: auto; left: 10px; right: 10px;
    width: auto; max-width: none;
    max-height: min(72dvh, 560px);
    border-radius: 16px;
  }

  /* ---------- Content area ---------- */
  .main {
    flex: 1 1 auto;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    padding: 16px var(--mb-gutter) calc(var(--mb-nav-h) + 24px + env(safe-area-inset-bottom));
  }
  .main > #globalAlert:empty { display: none; }

  /* ---------- Bottom tab bar ---------- */
  .nav {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 30;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 0;
    overflow: visible;
    padding: 0 4px env(safe-area-inset-bottom);
    background: var(--card);
    border-top: 1px solid var(--line);
    box-shadow: none;
  }

  /* The tab bar is one flat row: the sidebar's category wrappers dissolve and their headings are not shown. */
  .nav-group, .nav-group-items, .nav-group.is-collapsed .nav-group-items { display: contents; }
  .nav-group + .nav-group { margin-top: 0; }
  .nav-group-head { display: none; }
  .nav-group[hidden] { display: contents; }
  .nav-item:not(.nav-primary) { display: none; }

  .nav-item.nav-primary, .nav-more {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    width: auto; min-width: 0;
    height: var(--mb-nav-h);
    padding: 0 2px;
    border: 0; border-radius: 0;
    background: none;
    color: var(--text-muted);
    text-align: center;
  }
  .nav-item.nav-primary .nav-icon, .nav-more .nav-icon { width: 22px; height: 22px; }
  .nav-item.nav-primary .nav-text, .nav-more .nav-text {
    font-size: 10.5px; font-weight: 600; line-height: 1.1; white-space: nowrap;
  }
  /* active tab: accent colour + a thin bar on the top edge */
  .nav-item.nav-primary::before, .nav-more::before {
    content: "";
    position: absolute; top: -1px; left: 50%;
    width: 28px; height: 2px; margin-left: -14px;
    border-radius: 0 0 2px 2px;
    background: var(--teal);
    opacity: 0; transition: opacity .15s ease;
  }
  .nav-item.nav-primary:hover, .nav-more:hover { background: none; color: var(--text-muted); }
  .nav-item.nav-primary.active, .nav-more.active,
  .nav-more[aria-expanded="true"] { background: none; color: var(--teal); }
  .nav-item.nav-primary.active::before, .nav-more.active::before,
  .nav-more[aria-expanded="true"]::before { opacity: 1; }
  .nav-item.nav-primary:active, .nav-more:active { background: var(--parchment); }

  .nav-more { display: flex; }

  /* ---------- Dream Biya: a quiet icon button above the tab bar ---------- */
  .biya-fab {
    right: 14px;
    bottom: calc(var(--mb-nav-h) + 12px + env(safe-area-inset-bottom));
    padding: 4px;
    transform: scale(0.88);
    transform-origin: bottom right;
  }
  .biya-fab-text { display: none; }

  /* ---------- Page chrome ---------- */
  .page-header { margin-bottom: 16px; gap: 8px; }
  .page-title { font-size: 22px; line-height: 1.2; }
  .page-subtitle { font-size: 13px; }
  .card, .ib-panel { border-radius: 14px; }

  /* Sub-navigation pills (Banking, Notifications, Account ...) become one
     swipeable row instead of wrapping into several. */
  .bnk-tabs, .acct-tabs {
    display: flex;
    flex-wrap: nowrap;
    max-width: 100%;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 16px;
  }
  .bnk-tabs::-webkit-scrollbar, .acct-tabs::-webkit-scrollbar { display: none; }
  .bnk-tabs button, .acct-tab { flex: 0 0 auto; }

  /* ---------- Touch-friendly controls ---------- */
  input:is([type="text"], [type="email"], [type="password"], [type="number"], [type="date"],
           [type="month"], [type="search"], [type="tel"], [type="url"], :not([type])),
  select, textarea {
    font-size: 16px;            /* stops iOS zooming the page on focus */
  }
  input:is([type="text"], [type="email"], [type="password"], [type="number"], [type="date"],
           [type="month"], [type="search"], [type="tel"], [type="url"], :not([type])),
  select {
    min-height: 44px;
  }
  .btn { min-height: 42px; }
  .txn-actions .btn, table .btn { min-height: 0; }

  .alert { border-radius: 12px; font-size: 13px; }
  #trialBanner .alert { padding: 10px 12px; font-size: 12.5px; line-height: 1.4; margin-bottom: 12px; }
  .offline-banner { border-radius: 12px; }

  /* ======================================================================
     Dashboard (dashboard.css owns the layout; this only tidies the phone)
     ====================================================================== */
  /* an odd card left alone in the last row spans the full width */
  .dx-kpis > .dx-kpi:last-child:nth-child(even) { grid-column: 1 / -1; }

  /* ======================================================================
     "More" bottom sheet (js/shell/mobileNav.js)
     ====================================================================== */
  .ms-backdrop:not([hidden]) { display: block; }
  .ms-sheet:not([hidden]) { display: block; }

  .ms-backdrop {
    position: fixed; inset: 0; z-index: 70;
    background: rgba(8, 12, 20, 0.5);
    opacity: 0; transition: opacity .2s ease;
  }
  .ms-backdrop.open { opacity: 1; }

  .ms-sheet {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 71;
    max-height: 86vh; max-height: 86dvh;
    overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
    padding: 0 var(--mb-gutter) calc(16px + env(safe-area-inset-bottom));
    background: var(--card);
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.22);
    transform: translateY(100%);
    transition: transform .22s cubic-bezier(.2, .8, .2, 1);
  }
  .ms-sheet.open { transform: none; }

  .ms-handle {
    position: sticky; top: 0; z-index: 1;
    display: flex; justify-content: center;
    padding: 10px 0 8px;
    background: var(--card);
    touch-action: none;
  }
  .ms-grip { width: 36px; height: 4px; border-radius: 999px; background: var(--line-strong); }

  .ms-profile {
    display: flex; align-items: center; gap: 12px;
    width: 100%; margin: 0 0 4px; padding: 10px 4px;
    border: 0; border-bottom: 1px solid var(--line); border-radius: 0;
    background: none;
    color: inherit; text-align: left;
  }
  .ms-profile:active { background: var(--parchment); }
  .ms-avatar {
    width: 42px; height: 42px; flex: none; overflow: hidden;
    display: flex; align-items: center; justify-content: center;
    border-radius: 50%;
    background: var(--teal-dim); color: var(--teal);
    font-weight: 700; font-size: 16px;
  }
  .ms-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
  .ms-profile-text { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
  .ms-profile-name { font-size: 15px; font-weight: 600; color: var(--text-strong); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .ms-profile-sub { font-size: 12px; color: var(--text-muted); }
  .ms-chev { width: 18px; height: 18px; flex: none; color: var(--text-faint); }

  .ms-group-title {
    margin: 16px 2px 6px;
    font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
    color: var(--text-faint);
  }
  .ms-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; }

  .ms-tile {
    display: flex; flex-direction: column; align-items: center; gap: 6px;
    padding: 10px 2px 8px;
    border: 0; border-radius: 12px;
    background: none; color: var(--text-primary);
  }
  .ms-tile:active { background: var(--parchment); }
  .ms-tile-icon {
    width: 44px; height: 44px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 12px;
    background: var(--parchment-dim); color: var(--text-muted);
  }
  .ms-tile-icon svg { width: 21px; height: 21px; }
  .ms-tile-label {
    font-size: 11.5px; font-weight: 500; line-height: 1.2; text-align: center;
    color: var(--text-primary);
    overflow-wrap: anywhere;
  }
  .ms-tile.active .ms-tile-icon { background: var(--teal-dim); color: var(--teal); }
  .ms-tile.active .ms-tile-label { font-weight: 700; color: var(--text-strong); }

  /* Language, theme, sign out: one quiet settings block */
  .ms-settings {
    margin-top: 18px;
    border: 1px solid var(--line); border-radius: 14px;
    overflow: hidden;
  }
  .ms-row {
    display: flex; align-items: center; gap: 12px;
    width: 100%; min-height: 48px; padding: 0 14px;
    border: 0; border-top: 1px solid var(--line); border-radius: 0;
    background: none; color: var(--text-primary);
    font-size: 14px; font-weight: 500; text-align: left;
  }
  .ms-row:first-child { border-top: 0; }
  .ms-row svg { width: 18px; height: 18px; flex: none; color: var(--text-muted); }
  .ms-row > span:not(.ms-row-control) { flex: 1 1 auto; }
  button.ms-row:active { background: var(--parchment); }
  .ms-row-danger, .ms-row-danger svg { color: var(--coral); }
  .ms-row-control { flex: 0 0 auto; }
  .ms-row .topbar-lang { display: block; margin: 0; }
  .ms-row .topbar-cur { display: block; margin: 0; }
  .ms-row .lang-switch { height: 36px; min-height: 36px; max-width: 150px; font-size: 14px; border-radius: 10px; }

  .ms-meta { display: flex; justify-content: center; margin-top: 14px; font-size: 11px; color: var(--text-faint); }
  .ms-meta:empty { display: none; }
  .ms-meta-version { font-family: var(--font-mono); }

  @media (prefers-reduced-motion: reduce) {
    .ms-sheet, .ms-backdrop, .nav-item.nav-primary::before, .nav-more::before { transition: none; }
  }
}

/* Very small phones: tighter gutters. */
@media (max-width: 360px) {
  :root { --mb-gutter: 12px; }
  .brand-mark { font-size: 16px; }
  .ms-tile-icon { width: 40px; height: 40px; }
  .ms-tile-label { font-size: 11px; }
}
