/* ========== AFAMILY HQ — PWA UTILITIES + v3 MOBILE NAV ========== */

/* Pending rewards badge on nav */
.nav-pending-badge {
  position: absolute;
  top: 2px; right: 2px;
  min-width: 18px; height: 18px;
  background: var(--brand-cognac, #c36a2d);
  color: #fff;
  border-radius: 999px;
  font-size: 10px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  padding: 0 4px;
  box-shadow: 0 2px 6px rgba(195,106,45,0.5);
  line-height: 1;
  border: 2px solid var(--brand-cream, #f6f1e8);
}
.nav-link { position: relative; }

/* PWA install banner */
.pwa-install-banner {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 9999;
  padding: 8px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--brand-cognac, #c36a2d);
  color: var(--brand-cream, #f6f1e8);
  font-size: 12px;
  font-weight: 600;
}
body.pwa-banner-shown main { padding-top: 44px; }

/* ============================================================
   v3 MOBILE NAV — top header + X-style drawer + bottom tab bar
   Owns this file. Tokens: --page, --card, --ink, --ink-muted,
   --hairline, --primary, --primary-tint, --space-*, --radius-*.
   ============================================================ */
.mobile-header,
.mobile-side-drawer,
.mobile-side-backdrop,
.bottom-tabs { display: none; }

@media (max-width: 768px) {
  /* Hide legacy desktop sidebar (it doubled as mobile bottom nav). */
  #sidebar { display: none !important; }

  /* ---------- TOP HEADER ---------- */
  .mobile-header {
    display: flex;
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 190;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2, 8px);
    height: calc(52px + env(safe-area-inset-top, 0px));
    padding: env(safe-area-inset-top, 0px) 12px 0;
    background: var(--page, #FAF6EE);
    border-bottom: 1px solid var(--hairline, rgba(20,20,20,0.08));
  }
  body.pwa-banner-shown .mobile-header { top: 36px; }

  .mh-avatar-btn {
    width: 36px; height: 36px;
    display: inline-flex; align-items: center; justify-content: center;
    background: transparent; border: 0; padding: 0;
    border-radius: 999px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
  .mh-avatar-btn:active { transform: scale(0.96); }
  .mh-avatar {
    display: inline-flex; align-items: center; justify-content: center;
    width: 32px; height: 32px;
    border-radius: 999px;
    background: var(--card, #fff);
    border: 1px solid var(--hairline, rgba(20,20,20,0.08));
    font-size: 18px;
    line-height: 1;
  }

  .mh-title {
    flex: 1; min-width: 0;
    display: flex; align-items: center; justify-content: center;
  }
  .mh-wordmark {
    font-family: var(--font-display, 'Fraunces', serif);
    font-weight: 700;
    font-size: 16px;
    letter-spacing: -0.01em;
    color: var(--ink, #1A1A18);
  }

  .mh-bell-btn {
    width: 36px; height: 36px;
    display: inline-flex; align-items: center; justify-content: center;
    background: transparent; border: 0;
    border-radius: 999px;
    color: var(--ink, #1A1A18);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
  .mh-bell-btn:active { background: var(--primary-tint, rgba(195,106,45,0.10)); }
  .mh-bell-btn svg { display: block; }

  /* Push main content under header + above bottom tabs */
  #main-content {
    padding-top: calc(60px + env(safe-area-inset-top, 0px)) !important;
    padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px)) !important;
  }

  /* ---------- DRAWER BACKDROP + SHELL ---------- */
  .mobile-side-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 999;
    background: rgba(0,0,0,0.55);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 240ms ease;
  }
  .mobile-side-backdrop.open { opacity: 1; pointer-events: auto; }

  .mobile-side-drawer {
    display: flex;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 86vw;
    max-width: 360px;
    z-index: 1000;
    flex-direction: column;
    background: var(--page, #FAF6EE);
    box-shadow: 4px 0 24px rgba(0,0,0,0.18);
    transform: translateX(-105%);
    transition: transform 240ms ease;
    overscroll-behavior: contain;
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .mobile-side-drawer.open { transform: translateX(0); }
  body.msd-locked { overflow: hidden; }

  /* ---------- DRAWER HEADER (X-style profile card) ---------- */
  .msd-header {
    display: flex; flex-direction: column;
    gap: 4px;
    padding: 14px 18px 16px;
    border-bottom: 1px solid var(--hairline, rgba(20,20,20,0.08));
  }
  .msd-header-btn {
    background: transparent;
    border: 0;
    width: 100%;
    text-align: left;
    font: inherit;
    color: inherit;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
  .msd-header-btn:active { background: var(--primary-tint, rgba(195,106,45,0.06)); }
  .msd-header-row {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 8px;
  }
  .msd-user-avatar-lg {
    display: inline-flex; align-items: center; justify-content: center;
    width: 56px; height: 56px;
    border-radius: 999px;
    background: var(--card, #fff);
    border: 1px solid var(--hairline, rgba(20,20,20,0.08));
    font-size: 30px;
    line-height: 1;
  }
  .msd-close {
    width: 36px; height: 36px;
    display: inline-flex; align-items: center; justify-content: center;
    background: transparent; border: 0;
    border-radius: 999px;
    color: var(--ink-muted, #6B6B66);
    cursor: pointer;
  }
  .msd-close:active { background: var(--hairline, rgba(20,20,20,0.08)); }

  .msd-user-name {
    font-family: var(--font-display, 'Fraunces', serif);
    font-weight: 700;
    font-size: 22px;
    color: var(--ink, #1A1A18);
    line-height: 1.2;
    letter-spacing: -0.01em;
  }
  .msd-user-handle {
    font-family: var(--font-ui, 'Inter', sans-serif);
    font-size: 13px;
    color: var(--ink-muted, #6B6B66);
    line-height: 1.3;
    margin-top: 2px;
  }
  .msd-stats {
    display: flex; align-items: center;
    gap: 6px;
    margin-top: 6px;
    font-family: var(--font-ui, 'Inter', sans-serif);
    font-size: 12px;
    color: var(--ink-faint, #A6A39B);
  }
  .msd-stat b {
    color: var(--ink, #1A1A18);
    font-weight: 700;
    margin-right: 2px;
  }
  .msd-stat-sep { color: var(--ink-faint, #A6A39B); }

  /* ---------- DRAWER BODY (X-style: layered sections) ---------- */
  .msd-body {
    flex: 1;
    overflow-y: auto;
    padding: 4px 0 16px;
    display: flex; flex-direction: column;
    gap: 0;
    -webkit-overflow-scrolling: touch;
  }
  .msd-section {
    display: flex; flex-direction: column;
    padding: 6px 0;
  }
  .msd-section + .msd-section {
    border-top: 1px solid var(--hairline, rgba(20,20,20,0.08));
  }
  /* Hide ops section entirely when Admin Hub is hidden (non-admin users) */
  .msd-section-ops:not(:has(> .msd-item:not([style*="display: none"]):not([style*="display:none"]))) {
    display: none;
  }
  .msd-item {
    position: relative;
    display: flex; align-items: center;
    gap: 18px;
    padding: 14px 18px;
    min-height: 56px;
    background: transparent;
    border: 0;
    width: 100%;
    text-align: left;
    text-decoration: none;
    color: var(--ink, #1A1A18);
    font-family: var(--font-ui, 'Inter', sans-serif);
    font-size: 17px;
    font-weight: 500;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
  .msd-item:active { background: var(--primary-tint, rgba(195,106,45,0.10)); }
  .msd-item.msd-active {
    color: var(--primary, #C36A2D);
  }
  .msd-item.msd-active::before {
    content: "";
    position: absolute;
    left: 0; top: 8px; bottom: 8px;
    width: 4px;
    border-radius: 0 3px 3px 0;
    background: var(--primary, #C36A2D);
  }
  .msd-item.msd-active .msd-icon { color: var(--primary, #C36A2D); opacity: 1; }
  .msd-icon {
    width: 22px; height: 22px;
    display: inline-flex; align-items: center; justify-content: center;
    color: var(--ink, #1A1A18);
    opacity: 0.7;
    flex-shrink: 0;
  }
  .msd-icon svg { width: 22px; height: 22px; }
  .msd-label { flex: 1; min-width: 0; }

  /* Footer items: smaller icon + label, muted */
  .msd-item.msd-foot {
    min-height: 48px;
    padding: 10px 18px;
    font-size: 14px;
    font-weight: 400;
    color: var(--ink, #1A1A18);
    opacity: 0.7;
  }
  .msd-item.msd-foot .msd-icon {
    width: 18px; height: 18px;
    opacity: 0.6;
  }
  .msd-item.msd-foot .msd-icon svg { width: 18px; height: 18px; }
  .msd-item.msd-foot:active { opacity: 1; }

  /* ============================================================
     BOTTOM TAB BAR — fixed 56px, 5 equal tabs, hairline top
     ============================================================ */
  .bottom-tabs {
    display: flex;
    position: fixed;
    left: 0; right: 0;
    bottom: 0;
    z-index: 200;
    height: calc(56px + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: var(--card, #fff);
    border-top: 1px solid var(--hairline, rgba(20,20,20,0.08));
    box-shadow: 0 -2px 8px rgba(0,0,0,0.03);
  }
  .btab {
    flex: 1 1 0;
    position: relative;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    gap: 2px;
    background: transparent; border: 0;
    padding: 6px 0 0;
    color: var(--ink-muted, #6B6B66);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: color 160ms ease;
  }
  .btab-icon { display: block; width: 22px; height: 22px; }
  .btab-label {
    font-family: var(--font-ui, 'Inter', sans-serif);
    font-size: 11px;
    font-weight: 500;
    line-height: 1.1;
    letter-spacing: 0;
  }
  .btab-dot {
    position: absolute;
    top: 2px;
    width: 4px; height: 4px;
    border-radius: 999px;
    background: transparent;
    transition: background 160ms ease;
  }
  .btab:active { color: var(--ink, #1A1A18); }
  .btab-active { color: var(--primary, #C36A2D); }
  .btab-active .btab-dot { background: var(--primary, #C36A2D); }
}

/* ============================================================
   DESKTOP — sidebar stays, mobile header + drawer + tabs hide
   ============================================================ */
@media (min-width: 769px) {
  .mobile-header,
  .mobile-side-drawer,
  .mobile-side-backdrop,
  .bottom-tabs { display: none !important; }
}

/* ============================================================
   MOBILE OVERFLOW + RESPONSIVENESS FIXES (preserved)
   ============================================================ */
@media (max-width: 768px) {
  html, body { max-width: 100vw; overflow-x: hidden; }
  #main-content, main { max-width: 100vw; }
  .section, .dash-card, .card-item { max-width: 100%; }
  img, svg, video, canvas { max-width: 100%; height: auto; }
  table { max-width: 100%; display: block; overflow-x: auto; }

  .budget-caps-cards {
    grid-template-columns: 1fr !important;
    gap: 10px;
  }
  .budget-cap-card { width: 100%; box-sizing: border-box; }
  .budget-cap-bar { width: 100%; min-height: 8px; }
  .budget-cap-bar-fill { min-width: 2px; }
}

@media (max-width: 420px) {
  .budget-cap-card { padding: 11px 12px; }
  .mh-wordmark { font-size: 15px; }
}
