/* responsive.css — Gift List
   Breakpoints: 480 (phone), 720 (phablet), 960 (tablet), 1280+ (desktop)
   Mobile-first overrides. Replaces the old sparse media queries in styles.css.
*/

/* ── DESKTOP (1280px+) — bigger text, wider cards ── */
@media (min-width: 1280px) {
  body { font-size: 16px; }
  .topbar h1 { font-size: 1.55rem; }
  .section-header h2 { font-size: 1.35rem; }
  .gift-name { font-size: 1.08rem; }
  .gift-desc { font-size: .9rem; }
  .gift-grid { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 18px; }
  .main { padding: 24px 28px; }
  .sidebar { min-width: 280px; width: 280px; }
  .person-name-text { font-size: .95rem; }
  .budget-stat { font-size: .9rem; }
  .budget-stat strong { font-size: 1.05rem; }
  .filter-icon-btn { padding: 6px 13px; font-size: .88rem; }
  .filter-icon-btn .fib-label { font-size: .66rem; }
  .suggestion-name { font-size: .95rem; }
  .suggestion-desc { font-size: .85rem; }
}

/* ── LARGE DESKTOP (1600px+) ── */
@media (min-width: 1600px) {
  .gift-grid { grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); }
  .sidebar { min-width: 300px; width: 300px; }
}

/* ── TABLET (960px–1279px) — sidebar stays side, slightly compact ── */
@media (max-width: 1279px) and (min-width: 961px) {
  .sidebar { min-width: 220px; width: 220px; }
  .gift-grid { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
}

/* ── TABLET PORTRAIT / SMALL LAPTOP (720px–960px) ── */
@media (max-width: 960px) {
  .layout { flex-direction: column; }
  .sidebar {
    min-width: 100%; width: 100%;
    max-height: 280px; overflow-y: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .content-shell { overflow: visible; }
  .person-list { display: flex; flex-wrap: wrap; gap: 8px; padding: 8px; }
  .person-item {
    flex: 1 1 180px; min-width: 140px; max-width: 220px;
    padding: 8px 10px;
  }
  .group-list { display: flex; flex-wrap: wrap; gap: 8px; padding: 8px; }
  .group-item { flex: 1 1 180px; min-width: 160px; }
  .gift-grid { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
  .main { padding: 14px 16px; }
  #gift-ideas-panel { width: min(480px, 100vw); }
}

/* ── PHABLET (480px–720px) ── */
@media (max-width: 720px) {
  body { font-size: 14px; }

  /* Topbar: single row, logo centred, avatar right, no wrapping */
  .topbar {
    padding: 8px 14px;
    gap: 0;
    flex-wrap: nowrap;
    justify-content: space-between;
    align-items: center;
    position: relative;
  }
  .topbar h1 {
    font-size: 1.1rem;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    pointer-events: none;
  }
  .pills { gap: 6px; flex-wrap: wrap; }
  .pill { font-size: .72rem; padding: 3px 8px; }

  /* Sidebar */
  .sidebar { max-height: 220px; }
  .person-item { flex: 1 1 140px; min-width: 120px; padding: 6px 8px; }
  .person-name-text { font-size: .78rem; }

  /* Filter bar */
  .filter-bar { padding: 5px 10px; gap: 5px; }
  .filter-icon-btn { padding: 4px 8px; min-width: 42px; font-size: .78rem; }
  .filter-icon-btn .fib-label { font-size: .58rem; }

  /* Context bar: search + button stack nicely on mobile */
  #context-bar-actions { flex-wrap: nowrap; }
  .context-bar-search { font-size: .8rem; }

  /* Gift grid */
  .gift-grid { grid-template-columns: 1fr; gap: 10px; }
  .gift-card { padding: 12px; }
  .gift-name { font-size: .9rem; }

  /* Modals */
  .modal-content {
    margin: 10px; width: calc(100vw - 20px); max-height: calc(100vh - 20px);
    border-radius: 14px; padding: 16px;
  }
  .form-row { grid-template-columns: 1fr; }

  /* Gift ideas panel */
  #gift-ideas-panel { width: 100vw; right: 0; border-radius: 16px 16px 0 0; }

  /* Section title */
  .section-header h2 { font-size: 1rem; }
  .main { padding: 10px 12px; }
}

/* ── PHONE (max 480px) ── */
@media (max-width: 480px) {
  .topbar h1 { font-size: 1rem; }
  .topbar { padding: 8px 12px; }
  .pills { display: none; } /* hide stats on tiny screens — saves header space */

  .sidebar { max-height: 180px; }
  .person-item { flex: 1 1 120px; min-width: 100px; }

  .filter-bar { padding: 4px 8px; gap: 4px; }
  .filter-icon-btn { padding: 4px 6px; min-width: 36px; }
  .filter-icon-btn .fib-label { display: none; } /* icon only on tiny screens */

  .gift-grid { gap: 8px; }
  .gift-card { padding: 10px; }

  .suggestion-card { padding: 10px; }
  .suggestion-actions { flex-wrap: wrap; gap: 5px; }
  .btn-claim { font-size: .72rem; padding: 4px 8px; }
}

/* ── Gift ideas panel mobile full-screen ── */
@media (max-width: 720px) {
  #gift-ideas-panel {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    width: 100% !important;
    max-height: 90vh;
    overflow-y: auto;
    border-radius: 18px 18px 0 0;
    top: auto !important;
  }
  .gift-ideas-header { position: sticky; top: 0; background: #fff; z-index: 1; padding-top: 10px; }
}

/* ── Group info card responsive ── */
@media (max-width: 720px) {
  .group-info-card { padding: 10px 12px; }
  .group-info-recipient { min-width: 100%; }
  .group-info-header { flex-direction: column; align-items: flex-start; gap: 6px; }
}

/* ── Sidebar tabs responsive ── */
@media (max-width: 720px) {
  .sidebar-tabs { gap: 6px; padding: 6px 8px; }
  .sidebar-tab { font-size: .78rem; padding: 5px 10px; }
}

/* ── Budget bar responsive ── */
@media (max-width: 720px) {
  #budget-bar { flex-wrap: wrap; gap: 6px; padding: 8px 10px; }
  .budget-stat { font-size: .78rem; }
}

/* ── Toast responsive ── */
@media (max-width: 480px) {
  .toast { bottom: 80px; left: 12px; right: 12px; text-align: center; }
}

/* ── View nav responsive ── */
@media (max-width: 720px) {
  .view-nav { padding: 0; }
  .view-nav-btn { padding: 12px 6px 13px; font-size: 1.05rem; } /* +2pt from .88rem */
}
@media (max-width: 480px) {
  .view-nav-btn { font-size: 0.99rem; padding: 11px 4px 12px; } /* +2pt from .82rem */
}
/* Sidebar full-width when visible on mobile */
@media (max-width: 960px) {
  /* Mobile list mode: sidebar fills screen, no grey gap */
  .layout.mobile-list-mode {
    min-height: 0;
    flex-direction: column;
  }
  .layout.mobile-list-mode .content-shell {
    display: none !important;
  }
  .layout.mobile-list-mode .sidebar {
    width: 100vw !important;
    min-width: 0 !important;
    max-width: 100vw !important;
    padding: 8px 0 !important;
    min-height: calc(100vh - 110px);
    max-height: none;
    overflow-y: auto;
    border-right: none;
    border-bottom: none;
    box-sizing: border-box;
  }
  /* Lists: 98vw centred */
  .layout.mobile-list-mode #person-list,
  .layout.mobile-list-mode #group-list {
    width: 98vw !important;
    margin: 0 auto !important;
    display: flex !important;
    flex-direction: column !important;
    gap: 10px !important;
    padding: 8px 0 !important;
    box-sizing: border-box;
  }
  /* ── People squares grid override: flex-wrap row, centered ────────────── */
  .layout.mobile-list-mode #person-list.person-grid-squares {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: wrap !important;
    justify-content: center !important;
    align-content: flex-start !important;
    gap: 10px !important;
    padding: 12px 4px !important;
    width: 98vw !important;
    margin: 0 auto !important;
    box-sizing: border-box;
  }
  .layout.mobile-list-mode #person-list.person-grid-squares .person-square {
    width: 84px !important;
    flex-shrink: 0 !important;
    flex-grow: 0 !important;
  }
  /* ── Pet squares grid override: same flex-wrap centered grid ─────────── */
  .layout.mobile-list-mode #pet-list.person-grid-squares {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: wrap !important;
    justify-content: center !important;
    align-content: flex-start !important;
    gap: 10px !important;
    padding: 12px 4px !important;
    width: 98vw !important;
    margin: 0 auto !important;
    box-sizing: border-box;
  }
  .layout.mobile-list-mode #pet-list.person-grid-squares .person-square {
    width: 84px !important;
    flex-shrink: 0 !important;
    flex-grow: 0 !important;
  }
  /* ── Groups squares grid override ─────────────────────────────────────── */
  .layout.mobile-list-mode #group-list.person-grid-squares {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: wrap !important;
    justify-content: center !important;
    align-content: flex-start !important;
    gap: 10px !important;
    padding: 12px 4px !important;
    width: 98vw !important;
    margin: 0 auto !important;
    box-sizing: border-box;
  }
  .layout.mobile-list-mode #group-list.person-grid-squares .person-square {
    width: 84px !important;
    flex-shrink: 0 !important;
    flex-grow: 0 !important;
  }
  /* Cards: full width of the list */
  .layout.mobile-list-mode #person-list .person-item,
  .layout.mobile-list-mode #group-list .group-item {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    flex: none !important;
    box-sizing: border-box;
  }
  /* Add button: same width */
  .layout.mobile-list-mode .sidebar-section {
    width: 98vw !important;
    margin: 0 auto;
    padding: 0 !important;
  }
  /* Mobile detail mode: hide sidebar, full screen gifts */
  .layout.mobile-detail-mode .sidebar {
    display: none !important;
  }
  .layout.mobile-detail-mode .content-shell {
    display: flex !important;
  }
}

/* Mobile back button */
.mobile-back-btn {
  display: none; /* shown via JS on mobile only */
  width: 100%;
  background: var(--accent-light);
  color: var(--accent);
  border: none;
  padding: 12px 16px;
  font-size: .9rem;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.mobile-back-btn:active { background: #ddd6fe; }

/* Mobile: centre filter bar contents */
@media (max-width: 960px) {
  .filter-bar {
    justify-content: center;
    flex-wrap: wrap;
  }
}

/* ── Sticky header — tabs + filter bar, all screen sizes ── */
#mobile-sticky-header {
  position: sticky;
  top: var(--topbar-h, 80px); /* sits directly below the sticky topbar */
  z-index: 19; /* just below topbar z-index:20 */
  width: 100%;
  background: var(--bg, #fff);
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
@media (max-width: 960px) {
  #mobile-sticky-header {
    top: var(--topbar-h, 60px);
  }
  .layout {
    min-height: 0 !important;
  }
}

/* ── Global mobile overflow guard ── */
@media (max-width: 960px) {
  /* Hard stop on every element — nothing escapes the viewport */
  *, *::before, *::after {
    max-width: 100vw;
    box-sizing: border-box;
  }
  html {
    max-width: 100% !important;
    /* overflow-x:clip set above — does not create scroll context */
  }
  body {
    max-width: 100% !important;
    width: 100% !important;
    /* overflow set above — body is scroll root */
  }
  .topbar, .layout, .sidebar, .main, .content-shell, .view-nav {
    max-width: 100% !important;
    overflow-x: clip;  /* clip only — never hidden on ancestors of sticky */
    min-width: 0 !important;
  }
  /* Sidebar: never force a min-width on mobile */
  .sidebar {
    min-width: 0 !important;
    width: 100% !important;
  }
  /* Filter bar: allow wrapping on mobile so buttons don't overflow */
  .filter-bar {
    flex-wrap: wrap !important;
    overflow-x: hidden !important;
    padding: 6px 10px !important;
  }
  /* Filter buttons: shrink to fit, no enforced min-width */
  .filter-icon-btn {
    min-width: 0 !important;
    flex: 1 1 auto;
    padding: 4px 6px !important;
  }
  /* Gift ideas panel: never wider than screen */
  #gift-ideas-panel {
    width: 100vw !important;
    max-width: 100vw !important;
    right: 0 !important;
    left: 0 !important;
  }
  /* No hover transforms on touch — can trigger layout/scroll glitches */
  .person-item:hover,
  .group-item:hover,
  .filter-icon-btn:hover,
  .btn-add-person:hover,
  .pill:hover {
    transform: none !important;
  }
  /* Modals: constrain to viewport */
  .modal {
    max-width: calc(100vw - 24px) !important;
    width: calc(100vw - 24px) !important;
    margin: 0 auto;
  }
  /* Modal overlays: use inset so nothing protrudes */
  .modal-overlay {
    inset: 0 !important;
    padding: 12px !important;
  }
  /* User menu dropdown: keep within screen */
  .user-menu-dropdown {
    max-width: calc(100vw - 16px) !important;
  }
  /* Pills: hidden on mobile — topbar too narrow */
  .pills { display: none !important; }
  /* Pills: allow wrapping, no forced nowrap */
  .pill {
    white-space: normal !important;
  }
  /* Form rows: single column */
  .form-row {
    grid-template-columns: 1fr !important;
  }
  /* Member picker + group modal overlays */
  #member-picker-overlay > div,
  #group-modal .modal,
  #person-modal .modal {
    max-width: calc(100vw - 24px) !important;
    width: calc(100vw - 24px) !important;
  }
}

/* ── Sidebar action buttons — compact, uniform, not full-width on mobile ── */
@media (max-width: 960px) {
  /* Gatherings buttons + Add Person: auto-width, uniform, centred */
  .sidebar-section .btn-add-person,
  #gatherings-section .btn-add-person {
    width: auto !important;
    min-width: 160px;
    max-width: 220px;
    display: block;
    margin-left: auto;
    margin-right: auto;
    text-align: center;
  }
}

/* ── Gatherings section: tighten top gap, divider, search padding ── */
#gatherings-section {
  padding-top: 4px;
}
.gatherings-divider {
  border: none;
  border-top: 1px dashed var(--border, #e2e8f0);
  margin: 10px auto;
  width: 60%;
  opacity: 0.6;
}

/* ── People search (below Add Person button) ── */
.people-search-wrap {
  margin-top: 8px;
  width: 100%;
  padding-left: 5%;
  padding-right: 5%;
  box-sizing: border-box;
}
.people-search-input {
  width: 100%;
  box-sizing: border-box;
  padding: 8px 12px 8px 34px;
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 20px;
  font-size: 0.85rem;
  background: var(--bg2, #f8fafc) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23718096' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E") no-repeat 10px center;
  color: var(--text, #0f172a);
  outline: none;
  min-height: 36px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.people-search-input:focus {
  border-color: var(--blue, #6C3CE1);
  box-shadow: 0 0 0 3px rgba(0, 119, 182, 0.15);
}
.people-search-input::placeholder {
  color: var(--text-muted, #718096);
}
/* In mobile list mode, search should also fill the section width */
.layout.mobile-list-mode .people-search-wrap {
  width: 100%;
}
