/* ==========================================================================
   MOBILE-APP SHELL
   Phones (<=768px): true mobile-app experience — slim top app bar + fixed
   bottom tab bar, 44px+ touch targets, safe-area insets.
   Tablets (769-1024px): icon-rail sidebar.
   Desktop (>1024px): intentionally untouched — every rule below lives inside
   a max-width media query. Loaded after style.css and home.css.
   ========================================================================== */

/* Base: mobile shell elements are hidden everywhere; enabled in queries. */
.mtopbar,
.mtabs { display: none; }

/* --------------------------------------------------------------------------
   PHONES — max-width: 768px
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
  /* ---- 1. Swap the desktop sidebar for a slim top app bar ---- */
  body.is-authed .sidebar { display: none; }

  body.is-authed .mtopbar {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    position: sticky; top: 0; z-index: 60;
    padding: 10px 16px;
    padding-top: max(10px, env(safe-area-inset-top));
    background: var(--grad-dark); color: #fff;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
  }
  body.is-authed .mtopbar .brand { font-size: 15px; padding: 0; gap: 9px; }
  body.is-authed .mtopbar .brand-tile { width: 32px; height: 32px; border-radius: 10px; }
  body.is-authed .mtopbar .mbell { position: relative; display: flex; align-items: center; justify-content: center; width: 42px; height: 42px; border-radius: 12px; color: #fff; text-decoration: none; }
  body.is-authed .mtopbar .mbell:active { background: rgba(255, 255, 255, .12); }
  .mbell-badge { position: absolute; top: 3px; right: 3px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: #ef4444; color: #fff; font-size: 11px; font-weight: 700; line-height: 18px; text-align: center; border: 2px solid var(--grad-dark, #0f172a); }
  .msheet-lang { display: flex; justify-content: center; padding: 10px 0 4px; }

  /* ---- 2. Bottom tab bar ---- */
  body.is-authed .mtabs {
    display: flex; align-items: stretch;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
    margin: 0; padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    background: rgba(255, 255, 255, .96);
    -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
    border-top: 1px solid var(--border-soft);
    box-shadow: 0 -10px 28px -14px rgba(15, 23, 42, .22);
  }
  body.is-authed .mtab {
    flex: 1 1 0; position: relative;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    min-height: 58px; padding: 9px 2px 7px;
    color: var(--muted); font-size: 10.5px; font-weight: 600;
    letter-spacing: .015em; line-height: 1.25;
    text-decoration: none; background: none; border: 0;
    font-family: inherit; cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
  body.is-authed .mtab span {
    max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  body.is-authed .mtab .ic { width: 23px; height: 23px; flex-shrink: 0; }
  body.is-authed .mtab.active { color: var(--accent-deep); }
  body.is-authed .mtab.active::before {
    content: ''; position: absolute; top: 3px; left: 50%; transform: translateX(-50%);
    width: 20px; height: 3px; border-radius: 999px; background: var(--grad-accent);
  }
  body.is-authed .mtab:active { transform: scale(.95); }
  body.is-authed .mtab:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: 12px; }

  /* "More" tab: a <details> bottom sheet — no JS required. */
  body.is-authed .mtab-more { flex: 1 1 0; display: flex; padding: 0; margin: 0; border: 0; }
  body.is-authed .mtab-more > summary {
    flex: 1; position: relative; list-style: none; cursor: pointer;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    min-height: 58px; padding: 9px 2px 7px; border-radius: 12px;
    color: var(--muted); font-size: 10.5px; font-weight: 600;
    letter-spacing: .015em; line-height: 1.25;
    -webkit-tap-highlight-color: transparent;
  }
  body.is-authed .mtab-more > summary::-webkit-details-marker { display: none; }
  body.is-authed .mtab-more > summary::marker { content: ''; }
  body.is-authed .mtab-more > summary .ic { width: 23px; height: 23px; flex-shrink: 0; }
  body.is-authed .mtab-more > summary span {
    max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  body.is-authed .mtab-more[open] > summary,
  body.is-authed .mtab-more.sheet-active > summary { color: var(--accent-deep); }
  body.is-authed .mtab-more[open] > summary::before,
  body.is-authed .mtab-more.sheet-active > summary::before {
    content: ''; position: absolute; top: 3px; left: 50%; transform: translateX(-50%);
    width: 20px; height: 3px; border-radius: 999px; background: var(--grad-accent);
  }
  body.is-authed .mtab-more > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
  body.is-authed .msheet {
    position: fixed; left: 12px; right: 12px; z-index: 70;
    bottom: calc(92px + env(safe-area-inset-bottom));
    background: var(--surface); border: 1px solid var(--border-soft);
    border-radius: 20px; box-shadow: var(--shadow-lg);
    padding: 8px;
    animation: msheet-in .22s var(--ease);
    max-height: min(62vh, 520px);
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }
  @keyframes msheet-in {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: none; }
  }
  body.is-authed .msheet a,
  body.is-authed .msheet button {
    display: flex; align-items: center; gap: 13px; width: 100%;
    min-height: 50px; padding: 10px 14px; border-radius: 13px;
    color: var(--ink); font-size: 15px; font-weight: 550; text-decoration: none;
    background: none; border: 0; font-family: inherit; cursor: pointer; text-align: left;
    -webkit-tap-highlight-color: transparent;
  }
  body.is-authed .msheet a:active,
  body.is-authed .msheet button:active { background: var(--surface-2); }
  body.is-authed .msheet .ic { color: var(--muted); flex-shrink: 0; }
  body.is-authed .msheet .sheet-accent { color: var(--accent-deep); font-weight: 700; }
  body.is-authed .msheet .sheet-accent .ic { color: var(--accent); }
  body.is-authed .msheet hr { border: 0; border-top: 1px solid var(--border-soft); margin: 6px; }

  /* ---- 3. Clearance above the tab bar + comfortable touch sizing ---- */
  body.is-authed .content { padding: 18px 14px calc(112px + env(safe-area-inset-bottom)); }
  body.is-authed .content .btn {
    min-height: 44px; display: inline-flex; align-items: center; justify-content: center;
  }
  body.is-authed .content input,
  body.is-authed .content select,
  body.is-authed .content textarea { font-size: 16px; } /* prevent iOS auto-zoom */

  /* ---- 4. App-screen card polish (rounder, thumb-friendly) ---- */
  body.is-authed .stat { border-radius: 18px; }
  body.is-authed .vcard { border-radius: 20px; }

  /* ---- 5. Public landing + auth touch polish ---- */
  body.is-public .hp-ctas { flex-direction: column; align-items: stretch; }
  body.is-public .hp-ctas .hp-btn { width: 100%; justify-content: center; }
  body.is-public .auth-card input { font-size: 16px; min-height: 48px; }
  body.is-public .auth-card .btn { min-height: 48px; width: 100%; }
}

/* Respect reduced motion for the sheet animation. */
@media (prefers-reduced-motion: reduce) {
  body.is-authed .msheet { animation: none; }
}

/* --------------------------------------------------------------------------
   TABLETS — 769px to 1024px: icon-rail sidebar (consistent, compact)
   -------------------------------------------------------------------------- */
@media (min-width: 769px) and (max-width: 1024px) {
  body.is-authed .app { flex-direction: row; }
  body.is-authed .sidebar {
    width: 70px; min-width: 70px;
    height: 100vh; position: sticky; top: 0;
    padding: 16px 8px; gap: 14px; align-items: stretch;
    border-bottom: 0;
  }
  body.is-authed .sidebar .brand { font-size: 0; justify-content: center; padding: 4px 0; gap: 0; }
  body.is-authed .sidebar .brand-tile { font-size: 14px; }
  body.is-authed .sidebar .who { display: none; }
  body.is-authed .sidebar nav { flex-direction: column; align-items: stretch; gap: 4px; overflow: visible; padding: 0; }
  body.is-authed .sidebar nav a { justify-content: center; padding: 11px 0; gap: 0; }
  body.is-authed .sidebar nav a span { display: none; }
  body.is-authed .sidebar nav a .ic { width: 21px; height: 21px; }
  body.is-authed .sidebar .nav-label { display: none; }
  body.is-authed .sidebar .side-foot { margin-top: auto; flex-direction: column; align-items: stretch; gap: 10px; }
  body.is-authed .sidebar .lang-switch { justify-content: center; padding: 0; }
  body.is-authed .sidebar .lang-switch > .ic { display: none; }
  body.is-authed .sidebar .lang-pill a { padding: 5px 8px; font-size: 11px; }
  body.is-authed .sidebar .logout button { font-size: 0; gap: 0; padding: 11px 0; justify-content: center; }
  body.is-authed .sidebar .logout button .ic { width: 19px; height: 19px; }
  body.is-authed .content { padding: 26px 24px 60px; }
  /* Two-column grids make good use of tablet width. */
  body.is-authed .vcards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
