/* ─── Responsive Breakpoints ────────────────────────────────────────────── */

/* ── Small Mobile (≤480px) ──────────────────────────────────────────── */
@media (max-width: 480px) {
  .shopping-quick-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .sqa-btn {
    min-height: 88px;
  }
  .sqa-btn__sub {
    max-width: none;
  }
  .profile-stats { grid-template-columns: repeat(3, 1fr); }

  .modal-box { padding: var(--sp-3) var(--sp-3) calc(var(--sp-4) + var(--safe-bottom)); }
  .recipe-preview-overlay {
    --rp-pad-y: var(--sp-3);
    --rp-pad-x: var(--sp-3);
    --rp-pad-b: calc(var(--sp-4) + var(--safe-bottom));
  }

  .modal-sticky-footer:not(.modal-sticky-footer--recipe) {
    flex-direction: column-reverse;
    align-items: stretch;
  }
  .modal-sticky-footer:not(.modal-sticky-footer--recipe) > .btn,
  .modal-sticky-footer:not(.modal-sticky-footer--recipe) > .btn--primary { width: 100%; }
  .modal-sticky-footer__secondary { justify-content: center; }

  .form-actions {
    flex-direction: column-reverse;
    align-items: stretch;
  }
  .form-actions .btn { width: 100%; }
}

/* ── Narrow Mobile (≤360px) ─────────────────────────────────────────── */
@media (max-width: 360px) {
  .modal-box { max-height: 100dvh; padding: var(--sp-4) var(--sp-3) calc(var(--sp-4) + var(--safe-bottom)); }
  .recipe-preview-overlay {
    --rp-pad-y: var(--sp-4);
    --rp-pad-x: var(--sp-3);
    --rp-pad-b: calc(var(--sp-4) + var(--safe-bottom));
  }
  .topbar__actions { gap: 0; }
  .bottom-nav__item { font-size: 0.6875rem; }
  .bottom-nav { padding-inline: var(--sp-2); }
  .fab { right: var(--sp-3); }

  .view-fab {
    left: var(--sp-3);
    right: var(--sp-3);
    bottom: calc(var(--bottom-nav-h) + var(--safe-bottom) + 14px);
    padding: 0 18px;
  }

  .empty-state__actions {
    flex-direction: column;
    align-items: stretch;
  }
  .empty-state__actions .btn {
    width: 100%;
    min-width: 0;
  }
}

/* ── Small Mobile (≤599px) ──────────────────────────────────────────── */
@media (max-width: 599px) {
  .ing-row__delete { display: none; }

  .ing-row__swipe::after {
    content: '';
    position: absolute;
    right: var(--sp-2);
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 24px;
    background: var(--ink-muted);
    opacity: 0.3;
    border-radius: 2px;
  }
}

/* ── Medium Mobile (≤640px) ─────────────────────────────────────────── */
@media (max-width: 640px) {
  .plan-hero { padding: var(--sp-4); }
  .plan-hero__stats { grid-template-columns: 1fr; }
  .plan-focus__header { flex-direction: column; }
  .plan-focus__meta { justify-content: flex-start; }

  .slot-quick-picks__label-row,
  .recipe-picker-section__head {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* ── Tablet / wider (≥600px) ────────────────────────────────────────── */
@media (min-width: 600px) {
  .modal-overlay { align-items: center; }
  .modal-box {
    border-radius: var(--r-xl);
    margin: var(--sp-4);
    max-height: 85dvh;
    transition: transform 340ms cubic-bezier(0.16, 1, 0.3, 1);
  }
  .modal-dismiss-handle { display: none; }

  /* Search modal: fixed height on desktop so results have stable space */
  .ai-search-modal {
    min-height: min(520px, 70dvh);
  }

  .confirm-modal__actions {
    flex-direction: row;
    gap: var(--sp-3);
  }
  .confirm-modal__actions .btn { flex: 1; width: auto; min-height: 48px; }

  .bsheet {
    max-width: 520px;
    margin: 0 auto;
    border-radius: var(--r-lg) var(--r-lg) 0 0;
  }

  .recipes-grid { grid-template-columns: repeat(2, 1fr); }

  .undo-toast { bottom: var(--sp-5); }

  /* Ingredient delete — show on hover/focus only on non-touch */
  .ing-row__delete {
    opacity: 0;
    transition: opacity var(--t-fast);
  }
  .ing-row:hover .ing-row__delete,
  .ing-row__delete:focus-visible {
    opacity: 1;
  }
}

/* ── Touch devices: always show member-tile actions ────────────────── */
@media (hover: none) {
  .member-tile__actions { opacity: 1; }
}

/* ── Desktop (≥900px) ───────────────────────────────────────────────── */

/* Desktop Rail — hidden on mobile */
.desktop-rail { display: none; }

/* List Panel & Detail Panel — hidden on mobile */
.list-panel { display: none; }
.detail-panel { display: none; }

@media (min-width: 900px) {
  /* ── Tokens ──────────────────────────────────────────────────────── */
  :root {
    --rail-w: 72px;
    --rail-bg: var(--s1);
    --list-panel-w: 360px;
  }

  /* ── App Shell — 3-panel grid ────────────────────────────────────── */
  #app {
    display: grid;
    grid-template-columns: var(--rail-w) var(--list-panel-w) 1fr;
    grid-template-rows: 1fr;
    min-height: 100dvh;
  }

  /* ── Hide mobile topbar + bottom-nav on desktop ──────────────────── */
  .topbar { display: none; }
  .bottom-nav { display: none; }

  /* ── Desktop Rail Navigation ─────────────────────────────────────── */
  .desktop-rail {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 16px 0;
    gap: 4px;
    background: var(--rail-bg);
    border-right: 1px solid var(--border);
    grid-column: 1;
    grid-row: 1;
    position: sticky;
    top: 0;
    height: 100dvh;
    overflow-y: auto;
    z-index: 20;
  }

  .desktop-rail__logo {
    width: 44px;
    height: 44px;
    margin-bottom: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background: var(--clay);
    border-radius: var(--r-md);
  }

  .desktop-rail__logo svg { width: 24px; height: 24px; }

  .desktop-rail__item {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--r-md);
    cursor: pointer;
    transition: color var(--t-fast), background var(--t-fast);
    color: var(--ink-muted);
    border: none;
    background: none;
    font-family: var(--font-body);
    position: relative;
  }

  .desktop-rail__item svg { width: 22px; height: 22px; flex-shrink: 0; }
  .desktop-rail__item span { display: none; }

  .desktop-rail__item:hover {
    color: var(--ink);
    background: var(--s2);
  }

  .desktop-rail__item:focus-visible {
    outline: 2px solid var(--clay);
    outline-offset: -2px;
  }

  .desktop-rail__item--active {
    color: var(--clay);
    background: var(--clay-subtle);
  }

  .desktop-rail__item--active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 24px;
    background: var(--clay);
    border-radius: 0 2px 2px 0;
  }

  .desktop-rail__spacer { flex: 1; }

  .desktop-rail__bottom {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--sp-2);
    padding-top: var(--sp-4);
    border-top: 1px solid var(--border);
  }

  .desktop-rail__avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--clay);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    color: var(--ink-on-clay);
    text-transform: uppercase;
    letter-spacing: 0.02em;
    border: none;
  }

  .desktop-rail__avatar:hover { opacity: 0.85; }
  .desktop-rail__avatar:focus-visible {
    outline: 2px solid var(--clay);
    outline-offset: 2px;
  }

  /* ── Main content — hidden in 3-panel, shown in fullwidth ──────── */
  .main-content {
    display: none;
  }

  /* ── List Panel (Master) ─────────────────────────────────────────── */
  .list-panel {
    display: flex;
    flex-direction: column;
    background: var(--s1);
    border-right: 1px solid var(--border);
    grid-column: 2;
    grid-row: 1;
    height: 100dvh;
    overflow: hidden;
  }

  .list-panel__header {
    padding: var(--sp-5);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
  }

  .list-panel__title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--sp-4);
  }

  .list-panel__title-row .list-panel__title { margin-bottom: 0; }

  .list-panel__actions {
    display: flex;
    align-items: center;
    gap: 2px;
  }

  .list-panel__actions .btn--icon {
    width: 34px;
    height: 34px;
    border-radius: var(--r-md);
    color: var(--ink-muted);
    transition: color var(--t-fast), background var(--t-fast);
  }

  .list-panel__actions .btn--icon:hover {
    color: var(--ink);
    background: var(--s2);
  }

  .list-panel__actions .btn--icon:focus-visible {
    outline: 2px solid var(--clay);
    outline-offset: -2px;
  }

  .list-panel__title {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: var(--sp-4);
  }

  .list-panel__search {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    background: var(--s0);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: var(--sp-3) var(--sp-4);
  }

  .list-panel__search svg {
    width: 18px;
    height: 18px;
    color: var(--ink-muted);
    flex-shrink: 0;
  }

  .list-panel__search input {
    flex: 1;
    background: none;
    border: none;
    color: var(--ink);
    font-size: 0.9rem;
  }

  .list-panel__search input::placeholder { color: var(--ink-muted); }

  .list-panel__content {
    flex: 1;
    overflow-y: auto;
  }

  .list-panel__footer {
    padding: var(--sp-4) var(--sp-5);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
  }

  /* List Item in Panel */
  .list-item {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: var(--sp-3) var(--sp-5);
    border-bottom: 1px solid var(--border-subtle);
    cursor: pointer;
    transition: all var(--t-fast);
  }

  .list-item:hover { background: var(--s2); }

  .list-item--selected {
    background: var(--clay-subtle);
    border-left: 3px solid var(--clay);
    padding-left: calc(var(--sp-5) - 3px);
  }

  .list-item__image {
    width: 48px;
    height: 48px;
    border-radius: var(--r-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 1.25rem;
  }

  .list-item__image--photo { object-fit: cover; }

  .list-item__info {
    flex: 1;
    min-width: 0;
  }

  .list-item__title {
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .list-item__meta {
    font-size: 0.8rem;
    color: var(--ink-muted);
  }

  /* ── Detail Panel ────────────────────────────────────────────────── */
  .detail-panel {
    display: flex;
    flex-direction: column;
    background: var(--s0);
    grid-column: 3;
    grid-row: 1;
    height: 100dvh;
    overflow: hidden;
  }

  .detail-panel__empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--ink-muted);
    text-align: center;
    padding: var(--sp-7);
  }

  .detail-panel__empty svg {
    width: 64px;
    height: 64px;
    margin-bottom: var(--sp-4);
    opacity: 0.3;
  }

  .detail-panel__empty p { font-size: 1rem; }

  /* ── Full-width views (Home, Plan, Profile, Shopping, Review) ──── */
  #app.view--fullwidth {
    grid-template-columns: var(--rail-w) 1fr;
  }

  #app.view--fullwidth .list-panel { display: none; }
  #app.view--fullwidth .detail-panel { display: none; }

  #app.view--fullwidth .main-content {
    display: block;
    grid-column: 2;
    grid-row: 1;
    height: 100dvh;
    overflow-y: auto;
    padding: var(--sp-7);
    background: var(--s0);
  }

  #app.view--fullwidth .main-content > * {
    max-width: 1000px;
    margin-left: auto;
    margin-right: auto;
  }

  /* ── FAB position on desktop ─────────────────────────────────────── */
  .fab { bottom: var(--sp-5); }

  /* ── Modal — wider on desktop ────────────────────────────────────── */
  .modal-box { max-width: 640px; }

  /* ── Toast — top anchored ────────────────────────────────────────── */
  .toast {
    top: calc(var(--safe-top) + var(--sp-5));
    bottom: auto;
    left: 50%;
    transform: translateX(-50%) translateY(-12px) scale(0.95);
  }
  .toast--visible {
    transform: translateX(-50%) translateY(0) scale(1);
  }

  /* ── Install banner ──────────────────────────────────────────────── */
  .install-banner { left: var(--rail-w); }

  /* ── Wider grids ─────────────────────────────────────────────────── */
  .recipes-grid { grid-template-columns: repeat(3, 1fr); }
  .household-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
  .members-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
  .plan-day-rail { gap: var(--sp-2); }
  .rvw-list { max-width: 600px; }

  /* ── Hover-only on desktop ───────────────────────────────────────── */
  @media (hover: hover) {
    .recipe-card:hover { box-shadow: var(--shadow-card-hover); transform: translateY(-2px); }
  }
}
