/* ============================================================
   Grocery App – Global Stylesheet
   ============================================================ */

/* ── Reset & base ── */
[data-account-app][hidden],
[data-signed-out-landing][hidden],
[data-auth-transition][hidden],
[data-auth-header][hidden],
[data-auth-action][hidden],
[data-administration-link][hidden],
[data-admin-detail][hidden],
[data-admin-feedback-more][hidden] {
  display: none !important;
}

.administration .account-security-summary > div { width: 100%; min-width: 0; }
.administration input[type="search"] {
  display: block;
  width: 100%;
  max-width: 30rem;
  padding: .7rem;
  margin: .5rem 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font: inherit;
}
.administration [data-admin-results] { margin-top: .75rem; }
.administration [data-admin-info] { overflow-wrap: anywhere; }
.administration [data-admin-audit] { padding-left: 1.25rem; }

[data-account-app],
[data-page-content] {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --green-dark:   #2d6a4f;
  --green-mid:    #40916c;
  --green-light:  #74c69d;
  --green-pale:   #d8f3dc;
  --green-bg:     #f0faf3;
  --text-primary: #1b4332;
  --text-muted:   #52796f;
  --text-light:   #74c69d;
  --white:        #ffffff;
  --border:       #b7e4c7;
  --shadow-sm:    0 1px 3px rgba(0,0,0,.08);
  --shadow-md:    0 4px 12px rgba(0,0,0,.12);
  --radius-sm:    6px;
  --radius-md:    10px;
  --radius-lg:    16px;
  --font:         -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

html {
  /* Safari/iOS: remove the grey tap flash and prevent accidental
     text-size inflation when rotating to landscape */
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  background: var(--green-bg);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--green-mid); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Header ── */
.app-header {
  background: var(--green-dark);
  color: var(--white);
  box-shadow: var(--shadow-md);
  position: sticky; top: 0; z-index: 100;
  width: 100%;
  flex: 0 0 auto;
  /*
   * Keep iOS Safari from repainting both the sticky and in-flow header while
   * persistent navigation swaps a long page for a shorter one.
   */
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  /* push content below the notch on iPhone */
  padding-top: env(safe-area-inset-top);
}

[data-page-content] {
  overflow-anchor: none;
}
.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: .75rem 1.5rem;
  padding-left:  max(1.5rem, env(safe-area-inset-left));
  padding-right: max(1.5rem, env(safe-area-inset-right));
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.logo { font-size: 1.25rem; font-weight: 700; letter-spacing: -.3px; }
.nav-link {
  color: var(--green-pale);
  padding: .4rem .85rem;
  border-radius: var(--radius-sm);
  font-size: .9rem;
  font-weight: 500;
  transition: background .15s;
}
.nav-link:hover { background: rgba(255,255,255,.12); text-decoration: none; }
.nav-link.active { background: rgba(255,255,255,.2); color: var(--white); }
nav { display: flex; gap: .25rem; }

/* ── Account shell / Clerk entry points ── */
.account-controls { display: flex; align-items: center; gap: .4rem; margin-left: .75rem; }
.account-status { color: var(--green-pale); font-size: .8rem; max-width: 12rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn-account { padding: .35rem .6rem; color: var(--white); background: rgba(255,255,255,.14); border: 1px solid rgba(255,255,255,.3); }
.btn-account:hover { background: rgba(255,255,255,.24); }
.auth-transition {
  flex: 1;
  min-height: min(32rem, 100dvh);
  display: grid;
  place-items: center;
  padding: max(1.25rem, env(safe-area-inset-top)) max(1.25rem, env(safe-area-inset-right))
    max(1.25rem, env(safe-area-inset-bottom)) max(1.25rem, env(safe-area-inset-left));
}
.auth-transition-card {
  width: min(100%, 20rem);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .8rem;
  min-height: 4.5rem;
  padding: 1rem 1.25rem;
  color: var(--text-muted);
  background: rgba(255,255,255,.72);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  font-size: .9rem;
  font-weight: 600;
}
.auth-transition-spinner {
  width: 1.25rem;
  height: 1.25rem;
  flex: 0 0 auto;
  border: 2px solid var(--green-pale);
  border-top-color: var(--green-mid);
  border-radius: 50%;
  animation: auth-transition-spin .8s linear infinite;
}
@keyframes auth-transition-spin {
  to { transform: rotate(360deg); }
}
@media (prefers-reduced-motion: reduce) {
  .auth-transition-spinner { animation: none; }
}
.account-landing { flex: 1; display: grid; place-items: center; padding: 2rem 1.25rem; }
.account-landing-card { width: min(100%, 34rem); text-align: center; background: var(--white); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-md); padding: 2.5rem 2rem; }
.account-kicker { color: var(--green-mid); font-weight: 700; }
.account-landing h1 { margin: .7rem 0; color: var(--green-dark); font-size: clamp(1.8rem, 5vw, 2.5rem); }
.account-landing p { color: var(--text-muted); line-height: 1.55; }
.account-landing-actions { display: flex; justify-content: center; flex-wrap: wrap; gap: .65rem; margin: 1.5rem 0 1rem; }
.account-help { font-size: .84rem; }

/* ── Welcome Landing ── */
.notebook-landing {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2.5rem 1.25rem;
  background: var(--green-bg);
}

.notebook-card {
  width: min(100%, 38rem);
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius-lg);
  box-shadow: 0 12px 32px rgba(27,67,50,0.08), 0 2px 6px rgba(27,67,50,0.04);
  position: relative;
  overflow: hidden;
  animation: notebook-fade-in 0.6s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

@media (prefers-reduced-motion: reduce) {
  .notebook-card { animation: none; }
}

@keyframes notebook-fade-in {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

.notebook-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: 8px;
  background: var(--green-mid);
  border-right: 1px solid rgba(0,0,0,0.05);
}

.notebook-header {
  padding: 2.5rem 3rem 0;
}

.notebook-brand {
  display: inline-block;
  font-size: 0.9rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--green-mid);
  margin-bottom: 1rem;
}

.notebook-content {
  padding: 0 3rem 3rem;
}

.notebook-title {
  color: var(--green-dark);
  font-size: clamp(2rem, 6vw, 2.6rem);
  line-height: 1.15;
  margin-bottom: 1rem;
  letter-spacing: -0.02em;
}

.notebook-subtitle {
  color: var(--text-primary);
  font-size: 1.1rem;
  line-height: 1.6;
  margin-bottom: 2rem;
}

.notebook-features {
  list-style: none;
  margin: 0 0 2.5rem 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.notebook-features li {
  display: flex;
  align-items: flex-start;
  gap: 0.85rem;
  font-size: 0.95rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.notebook-features li::before {
  content: "";
  display: block;
  width: 1.35rem;
  height: 1.35rem;
  flex-shrink: 0;
  background-color: var(--green-pale);
  border-radius: 50%;
  margin-top: 0.1rem;
  background-image: url('data:image/svg+xml;utf8,<svg viewBox="0 0 24 24" fill="none" stroke="%2340916c" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><polyline points="20 6 9 17 4 12"/></svg>');
  background-size: 12px;
  background-position: center;
  background-repeat: no-repeat;
}

.notebook-features strong {
  color: var(--text-primary);
  font-weight: 600;
}

.notebook-actions {
  display: flex;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.notebook-actions .btn {
  flex: 1;
  justify-content: center;
}

.notebook-help {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-align: center;
}

@media (max-width: 600px) {
  .notebook-header,
  .notebook-content {
    padding-left: 1.5rem;
    padding-right: 1.5rem;
  }
  .notebook-actions {
    flex-direction: column;
  }
}

/* ── Account settings ── */
.account-page { min-height: 100vh; }
.account-settings {
  width: min(100% - 2rem, 980px);
  margin: 0 auto;
  padding: 2rem 0 3rem;
}
.account-settings-heading { margin-bottom: 1.25rem; }
.account-settings-heading h1 { margin: .3rem 0; color: var(--green-dark); font-size: clamp(1.8rem, 5vw, 2.5rem); }
.account-settings-heading p { color: var(--text-muted); line-height: 1.55; }
.account-security-summary,
.account-data-backup,
.account-share,
.account-feedback,
.account-sign-out {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1.25rem;
  padding: 1.25rem;
  margin-bottom: 1rem;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.account-security-summary h2,
.account-data-backup h2,
.account-share h2,
.account-feedback h2,
.account-sign-out h2 { margin-bottom: .35rem; color: var(--green-dark); font-size: 1.1rem; }
.account-security-summary p,
.account-data-backup p,
.account-share p,
.account-feedback p,
.account-sign-out p { color: var(--text-muted); line-height: 1.55; }
.account-security-summary .btn,
.account-data-backup .btn,
.account-share .btn,
.account-sign-out .btn { flex: 0 0 auto; }
.account-data-backup { background: #ffffff; }
.account-backup-status { margin-top: .45rem; font-size: .84rem; }
.account-share { background: var(--green-pale); }
.account-share-status { min-height: 1.3em; margin-top: .45rem; font-size: .84rem; }
.account-feedback { display: block; }
.account-feedback label { display: block; margin: .85rem 0 .4rem; font-weight: 600; }
.account-feedback textarea {
  display: block;
  width: 100%;
  padding: .75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font: inherit;
  resize: vertical;
}
.account-feedback textarea:focus { outline: 2px solid var(--green-dark); outline-offset: 2px; }
.account-feedback-actions { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-top: .8rem; }
.account-feedback-status { color: var(--green-dark); font-size: .9rem; }
.admin-feedback-list { display: grid; gap: .7rem; margin: 1rem 0; }
.admin-feedback-item { padding: .85rem; border: 1px solid var(--border); border-radius: var(--radius-md); background: #ffffff; }
.admin-feedback-item strong { display: block; overflow-wrap: anywhere; }
.admin-feedback-item time { display: block; margin-top: .15rem; color: var(--text-muted); font-size: .8rem; }
.admin-feedback-item p { margin-top: .55rem; color: var(--text); white-space: pre-wrap; overflow-wrap: anywhere; }
.account-profile-panel {
  position: relative;
  min-height: 28rem;
  padding: 1rem;
  margin-bottom: 1rem;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.account-profile-loading { padding: 2rem; text-align: center; color: var(--text-muted); }
.account-profile-panel:has([class*="cl-"]) .account-profile-loading { display: none; }
#clerk-user-profile { width: 100%; }
#clerk-user-profile > div { width: 100%; }
/* ── Layout ── */
.two-panel {
  display: flex;
  gap: 1.25rem;
  padding: 1.25rem;
  flex: 1;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}
.single-panel {
  padding: 1.25rem;
  flex: 1;
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
}

/* ── Panel ── */
.panel {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.panel-chat    { flex: 1.2; min-width: 0; }
.panel-library { flex: 1;   min-width: 0; }
.panel-grocery { width: 100%; }

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--green-pale);
  gap: .5rem;
  flex-wrap: wrap;
}
.panel-header h2 {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--green-dark);
}
.pantry-header-actions {
  display: flex;
  align-items: center;
  gap: .25rem;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .5rem 1rem;
  border-radius: var(--radius-sm);
  font-size: .875rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: background .15s, opacity .15s, transform .1s;
  white-space: nowrap;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:not(:disabled):active { transform: scale(.97); }

.btn-primary   { background: var(--green-mid);  color: var(--white); }
.btn-primary:not(:disabled):hover   { background: var(--green-dark); }

.btn-secondary { background: var(--green-pale); color: var(--green-dark); border: 1px solid var(--border); }
.btn-secondary:not(:disabled):hover { background: var(--border); }

.btn-ghost  { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--green-pale); }

.btn-danger { background: #fee2e2; color: #b91c1c; }
.btn-danger:hover { background: #fca5a5; }

.btn-sm { padding: .3rem .65rem; font-size: .8rem; }

/* ── Chat ── */
.chat-thread {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: .75rem;
  min-height: 0;
  max-height: calc(100vh - 280px);
}
.message { display: flex; }
.message-user  { justify-content: flex-end; }
.message-agent { justify-content: flex-start; }

.bubble {
  max-width: 80%;
  padding: .65rem 1rem;
  border-radius: var(--radius-md);
  font-size: .9rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}
.message-user  .bubble { background: var(--green-mid);   color: var(--white); border-bottom-right-radius: 2px; }
.message-agent .bubble { background: var(--green-pale);  color: var(--text-primary); border-bottom-left-radius: 2px; }

.bubble.typing { font-style: italic; color: var(--text-muted); }

.pantry-guidance {
  align-self: stretch;
  padding: .8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--green-bg);
  flex-shrink: 0;
}
.pantry-guidance[hidden],
#btn-show-guidance[hidden] {
  display: none !important;
}
.pantry-guidance-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  margin-bottom: .55rem;
}
.pantry-guidance-heading h3 {
  color: var(--green-dark);
  font-size: .9rem;
}
.pantry-guidance-close {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  background: transparent;
  font: inherit;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
}
.pantry-guidance-close:hover { background: var(--green-pale); }
.pantry-starters {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .45rem;
}
.pantry-starter {
  min-height: 42px;
  padding: .5rem .65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--green-dark);
  background: var(--white);
  font: inherit;
  font-size: .82rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}
.pantry-starter:hover { background: var(--green-pale); }
.pantry-starter:disabled,
.pantry-guidance-close:disabled { opacity: .45; cursor: not-allowed; }
.pantry-starter:focus-visible,
.pantry-guidance-close:focus-visible,
.pantry-header-actions .btn:focus-visible {
  outline: 3px solid rgba(240,160,61,.35);
  outline-offset: 2px;
}
.pantry-confirmation-note {
  margin-top: .55rem;
  color: var(--text-muted);
  font-size: .78rem;
  line-height: 1.4;
}

.chat-form {
  display: flex;
  gap: .5rem;
  padding: .75rem 1rem;
  border-top: 1px solid var(--border);
  align-items: flex-end;
}
.chat-input {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .6rem .85rem;
  font-size: .875rem;
  font-family: var(--font);
  color: var(--text-primary);
  background: var(--white);
  transition: border-color .15s, box-shadow .15s;
  min-height: 60px;
  max-height: 120px;
  line-height: 1.5;
}
.chat-input:focus {
  outline: none;
  border-color: var(--green-mid);
  box-shadow: 0 0 0 3px rgba(240,160,61,.15);
}

/* ── Recipe Library ── */
.recipe-list {
  flex: 1;
  overflow-y: auto;
  padding: .75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  min-height: 0;
  max-height: calc(100vh - 240px);
}

.recipe-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  transition: box-shadow .15s;
  flex-shrink: 0; /* never compress cards to fit — overflow & scroll instead */
}
.recipe-card:hover { box-shadow: var(--shadow-sm); }
.recipe-card.selected { border-color: var(--green-mid); box-shadow: 0 0 0 2px rgba(240,160,61,.2); }

.recipe-card-header {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .65rem .85rem;
  cursor: pointer;
  background: var(--white);
  user-select: none;
}
.recipe-card-header:hover { background: var(--green-bg); }

.recipe-checkbox { width: 16px; height: 16px; accent-color: var(--green-mid); flex-shrink: 0; cursor: pointer; }
.recipe-name { flex: 1; font-weight: 600; font-size: .9rem; color: var(--text-primary); }
.recipe-expand-btn {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); font-size: .85rem; padding: .2rem .4rem;
  border-radius: var(--radius-sm); transition: background .12s;
}
.recipe-expand-btn:hover { background: var(--green-pale); }
.recipe-delete-btn {
  background: none; border: none; cursor: pointer;
  color: #b91c1c; font-size: .85rem; padding: .2rem .4rem;
  border-radius: var(--radius-sm); transition: background .12s;
  opacity: .6;
}
.recipe-delete-btn:hover { background: #fee2e2; opacity: 1; }

.recipe-card-body {
  display: none;
  padding: .6rem .85rem .85rem;
  border-top: 1px solid var(--border);
  background: var(--green-bg);
}
.recipe-card-body.open { display: block; }
.recipe-card-body ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: .25rem;
}
.recipe-card-body li {
  font-size: .855rem;
  color: var(--text-muted);
  padding: .15rem 0;
  display: flex;
  gap: .5rem;
}
.recipe-card-body li::before { content: "•"; color: var(--green-light); flex-shrink: 0; }
.ing-qty { font-weight: 600; color: var(--text-primary); min-width: 60px; }
.ing-name { color: var(--text-muted); }

.library-footer {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .75rem 1rem;
  border-top: 1px solid var(--border);
  background: var(--green-pale);
  flex-wrap: wrap;
}
.library-footer .btn-primary { margin-left: auto; }

.recipe-count { font-size: .8rem; color: var(--text-muted); font-weight: 500; }

/* ── Grocery List ── */
.list-date { font-size: .8rem; color: var(--text-muted); margin-top: .15rem; }
.grocery-actions { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }

/* Add-item form */
.add-item-form {
  display: flex;
  gap: .5rem;
  align-items: center;
  padding: .75rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--green-pale);
  flex-wrap: wrap;
}
.add-item-input {
  flex: 1;
  min-width: 120px;
  padding: .45rem .7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: .875rem;
  background: var(--white);
  color: var(--text-primary);
  outline: none;
  transition: border-color .15s;
}
.add-item-input:focus { border-color: var(--green-mid); }
.add-item-qty { max-width: 130px; }

#grocery-content { padding: 1rem 1.25rem; }

.category-group { margin-bottom: 1.5rem; }
.category-title {
  font-size: .8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--green-mid);
  padding: .35rem .6rem;
  background: var(--green-pale);
  border-radius: var(--radius-sm);
  margin-bottom: .6rem;
  display: flex;
  align-items: center;
  gap: .4rem;
}
.category-icon { font-size: 1rem; }

/* ── Grocery item – swipe-to-delete ── */

/*
 * No overflow:hidden or clip-path needed — the action pane starts at width:0
 * (genuinely invisible, no pixels rendered) and grows as the user swipes.
 * The content (flex:1) naturally shrinks to make room, so nothing is clipped.
 */
.grocery-item {
  display: flex;
  align-items: stretch;
  border-radius: var(--radius-sm);
  font-size: .9rem;
  border-bottom: 1px dashed var(--border);
}
.grocery-item:last-child { border-bottom: none; }

/* The content layer — fills available space, shrinks as action pane grows */
.grocery-item-content {
  flex: 1 1 auto;
  display: flex;
  align-items: baseline;
  gap: .6rem;
  padding: .4rem .6rem;
  background: var(--white);
  min-width: 0;
}
.grocery-item:hover .grocery-item-content { background: var(--green-bg); }
.grocery-item.swipe-open .grocery-item-content { background: var(--white); }

.grocery-item-check {
  width: 1.15rem;
  height: 1.15rem;
  flex: 0 0 auto;
  accent-color: var(--green-mid);
  cursor: pointer;
  margin: 0 .1rem 0 0;
}
.grocery-item-check:disabled { cursor: wait; }

.item-name { flex: 1; font-weight: 500; color: var(--text-primary); min-width: 0; }
.item-qty  { color: var(--text-muted); font-size: .85rem; font-weight: 600; white-space: nowrap; }
.grocery-item.completed .item-name {
  color: var(--text-muted);
  text-decoration-line: line-through;
  text-decoration-thickness: 2px;
}

/* The red trash pane — starts at width:0 (hidden), expands on swipe */
.swipe-delete-action {
  flex: 0 0 auto;
  width: 0;              /* hidden at rest — no pixels, no clipping needed */
  overflow: hidden;      /* clip the icon SVG while width < 72px */
  display: flex;
  align-items: center;
  justify-content: center;
  background: #dc2626;
  color: #ffffff;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  transition: width 0.25s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  white-space: nowrap;   /* keep the icon from wrapping during grow */
}
.grocery-item.swipe-open .swipe-delete-action { width: 72px; }
.swipe-delete-action:hover  { background: #b91c1c; }
.swipe-delete-action:active { background: #991b1b; }
.swipe-delete-action:focus-visible {
  outline: 2px solid #fca5a5;
  outline-offset: -2px;
}

/* ── Empty state ── */
.empty-state {
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--text-muted);
  font-size: .9rem;
  line-height: 1.7;
}
.empty-state p + p { margin-top: .4rem; }

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: max(1.5rem, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--green-dark);
  color: var(--white);
  padding: .65rem 1.4rem;
  border-radius: var(--radius-md);
  font-size: .88rem;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s, transform .25s;
  z-index: 999;
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Mobile tab bar (hidden on desktop) ── */
.mobile-tabs { display: none; }

/* ── Responsive — tablets & phones ── */
@media (max-width: 768px) {
  .account-settings { width: min(100% - 1rem, 980px); padding: 1rem 0 2rem; }
  .account-security-summary,
  .account-data-backup,
  .account-share,
  .account-feedback,
  .account-sign-out { align-items: stretch; flex-direction: column; }
  .account-security-summary .btn,
  .account-data-backup .btn,
  .account-share .btn,
  .account-sign-out .btn { width: 100%; justify-content: center; }
  .account-profile-panel { padding: .4rem; }
  .account-feedback-actions { align-items: stretch; flex-direction: column; }
  .account-feedback-actions .btn { width: 100%; justify-content: center; }
  #clerk-user-profile,
  #clerk-user-profile > div { min-width: 0; max-width: 100%; }

  /* ── Tab bar: Recipe Agent / Recipe Library as separate pages ── */
  .mobile-tabs {
    display: flex;
    gap: .4rem;
    padding: .5rem .6rem 0;
  }
  .mobile-tab {
    flex: 1;
    padding: .55rem .5rem;
    font-size: .9rem;
    font-weight: 600;
    font-family: inherit;
    color: var(--text-muted);
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    cursor: pointer;
  }
  .mobile-tab.active {
    color: var(--white);
    background: var(--green-dark);
    border-color: var(--green-dark);
  }

  /* Show only the active panel — each gets the full remaining height */
  .two-panel[data-mobile-view="chat"] .panel-library { display: none; }
  .two-panel[data-mobile-view="library"] .panel-chat { display: none; }
  .panel-chat, .panel-library {
    flex: 1 1 auto !important;
    min-height: 0;
  }

  /* ── Header: prevent logo + nav from wrapping on narrow screens ── */
  .header-inner {
    padding: .55rem 1rem;
    padding-left:  max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
    flex-wrap: wrap;
    gap: .45rem;
  }
  .logo { order: 1; font-size: 1.05rem; }
  .header-inner nav {
    order: 3;
    width: 100%;
    overflow-x: auto;
    padding-bottom: .1rem;
    scrollbar-width: none;
  }
  .header-inner nav::-webkit-scrollbar { display: none; }
  .nav-link { padding: .35rem .6rem; font-size: .85rem; }
  .account-controls {
    order: 2;
    flex: 0 1 auto;
    justify-content: flex-end;
    flex-wrap: nowrap;
    min-width: 0;
    margin-left: auto;
  }
  .account-status { max-width: 8rem; }

  /* ── Two-panel layout ──
     Lock the page height ONLY on the recipes page (the one with .two-panel)
     so the panels fill exactly the space below the header and the recipe
     list / chat thread scroll internally. The grocery-list page has no
     .two-panel, so it keeps natural document scrolling. */
  html:has(.two-panel), body:has(.two-panel) {
    height: 100vh;   /* fallback for older Safari without dvh support */
    height: 100dvh;  /* Safari 15.4+: tracks the collapsing URL bar correctly */
    /* Real iOS Safari: --app-height is kept in sync with the *visual*
       viewport (toolbar collapse + on-screen keyboard) by app.js, so the
       chat form is always pinned above the visible bottom edge. */
    height: var(--app-height, 100dvh);
    /* CRITICAL: the base style sets body { min-height: 100vh }. On real
       iPhones 100vh is the *large* viewport (toolbar collapsed), which
       silently overrode the locked height and pushed the chat form off
       screen. min-height must be released for the lock to actually apply. */
    min-height: 0;
    max-height: var(--app-height, 100dvh);
    overflow: hidden;
  }

  /* Keep the chat form clear of the iPhone home-indicator bar */
  .chat-form {
    padding-bottom: max(.6rem, env(safe-area-inset-bottom));
  }

  /* Safari/iOS: inputs under 16px trigger automatic page zoom on focus.
     Keep all text inputs at 16px on touch devices to prevent it. */
  .chat-input,
  input[type="text"],
  textarea {
    font-size: 16px;
  }
  .two-panel {
    flex-direction: column;
    padding: .6rem;
    gap: .6rem;
    flex: 1 1 auto;   /* fill whatever remains below the header — no magic numbers */
    min-height: 0;
    overflow: hidden;
  }

  /* Remove old 40 vh hard caps; guarantee internal touch scrolling */
  .chat-thread {
    max-height: none;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
  }
  .recipe-list {
    max-height: none;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
  }

  /* Recipe card rows: breathing room, top-align when name wraps */
  .recipe-card-header {
    padding: .85rem 1rem;
    align-items: flex-start;
    gap: .75rem;
  }
  .recipe-checkbox { margin-top: 2px; }
  .recipe-name { font-size: .95rem; line-height: 1.35; }

  /* Gap between cards */
  .recipe-list { gap: .4rem; }

  /* Library footer: full-width primary button, safe-area bottom */
  .library-footer {
    padding: .6rem .85rem;
    padding-bottom: max(.6rem, env(safe-area-inset-bottom));
    row-gap: .4rem;
  }
  .library-footer .btn-primary {
    width: 100%;
    justify-content: center;
    margin-left: 0;
  }

  /* Grocery list page */
  .single-panel {
    padding: .75rem;
    padding-bottom: max(.75rem, env(safe-area-inset-bottom));
  }
  #grocery-content { padding: .85rem 1rem; }
  .grocery-item { padding: .55rem .6rem; }
}

/* ── Pantry Agent page ── */
.pantry-main {
  display: flex;
  flex-direction: column;
  flex: 1;
  padding: 1.25rem;
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
  min-height: 0;
}
.pantry-main .panel-chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.pantry-main .recipe-box-bar {
  position: static;
  flex: 0 0 auto;
  margin-bottom: .75rem;
  width: 100%;
}
.pantry-main .chat-thread {
  max-height: none;
  flex: 1;
}
.pantry-confirm {
  align-self: stretch;
  justify-content: center;
  margin: .5rem 1rem;
  flex-shrink: 0;
}
.pantry-confirm[hidden] { display: none !important; }

/* Lock viewport height on the Pantry Agent page (same pattern as .two-panel) */
@media (max-width: 768px) {
  html:has(.pantry-page), body.pantry-page {
    height: 100vh;
    height: 100dvh;
    height: var(--app-height, 100dvh);
    min-height: 0;
    max-height: var(--app-height, 100dvh);
    overflow: hidden;
  }
  body.pantry-page {
    display: flex;
    flex-direction: column;
    /* Prevent iOS focus from panning the whole page away from the composer.
       The visual viewport's top/height follow the keyboard in pantry_agent.js. */
    position: fixed;
    top: var(--app-top, 0px);
    left: 0;
    width: 100%;
  }
  /* Reclaim the navigation's height while composing a message. The header
     returns as soon as the input loses focus (including keyboard dismissal). */
  body.pantry-page:has(#chat-input:focus) > .app-header {
    display: none;
  }
  .pantry-main {
    padding: .6rem;
    padding-bottom: 1.1rem;
    flex: 1;
    min-height: 0;
    overflow: hidden;
  }
  .pantry-main .panel-header {
    padding: .7rem .85rem;
  }
  .pantry-main .chat-thread {
    padding: .7rem .8rem;
    gap: .55rem;
  }
  .pantry-guidance {
    padding: .65rem;
  }
  .pantry-starters {
    grid-template-columns: 1fr;
    gap: .35rem;
  }
  .pantry-starter {
    min-height: 40px;
    font-size: .8rem;
  }
}

/* ── Create Grocery List row ── */
.create-grocery-row {
  display: flex;
  justify-content: flex-end;
  margin-top: .5rem;
  margin-bottom: 1.25rem;
}

/* Keep the next step visible without adding a sticky layer to the scroll area. */
body.meal-planner-page .create-grocery-row {
  position: fixed;
  inset: auto 0 0;
  z-index: 30;
  margin: 0;
  padding: .75rem max(1.25rem, env(safe-area-inset-right))
    calc(.75rem + env(safe-area-inset-bottom))
    max(1.25rem, env(safe-area-inset-left));
  background: var(--bg-card, #fff);
  border-top: 1px solid var(--border-color, #dce2e8);
  box-shadow: 0 -3px 12px rgba(35, 35, 71, .06);
}
body.meal-planner-page .planner-action-content {
  display: flex;
  justify-content: flex-end;
  width: 100%;
  max-width: 1160px;
  margin: 0 auto;
}
body.meal-planner-page .grocery-layout {
  padding-bottom: calc(6rem + env(safe-area-inset-bottom));
}
body.meal-planner-page #btn-create-grocery:disabled {
  background: #f5e6d7;
  color: var(--brand-slate, #3c5363);
  border: 1px solid #c7b6a2;
  opacity: 1;
  cursor: not-allowed;
}
@media (max-width: 700px) {
  body.meal-planner-page #btn-create-grocery { width: 100%; }
}

/* ── Meal Planner – scheduling header ── */
.add-meal-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .75rem;
  margin-bottom: 1.25rem;
}
.btn-lg { padding: .65rem 1.4rem; font-size: 1rem; }

.generate-meals-dialog {
  width: min(36rem, calc(100vw - 2rem));
  max-height: calc(100dvh - 2rem);
  margin: auto;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--white);
  color: var(--text);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .2);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.generate-meals-dialog:not([open]) { display: none !important; }
.generate-meals-dialog::backdrop { background: rgba(20, 40, 30, .48); }
.generate-meals-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}
.generate-meals-dialog-header h2 { font-size: 1.25rem; }
.generate-meals-header-actions { display: flex; align-items: center; gap: .25rem; }
.generation-info-dialog { width: min(28rem, calc(100vw - 2rem)); }
.generation-info-content p + p { margin-top: .85rem; }
.generate-meals-dialog-header button { min-height: 44px; min-width: 44px; }
.generate-meals-panel { padding: 1.25rem; }
.generate-meals-review { margin-top: 1.25rem; }
.generate-meals-review[hidden], .generate-meals-review-actions[hidden] { display: none !important; }
.generate-meals-review h3 { font-size: 1rem; margin-bottom: .75rem; }
.generate-meals-preview-list { display: grid; gap: .75rem; list-style: none; padding: 0; }
.generate-meals-preview-list li { padding: 1rem; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--green-bg); overflow-wrap: anywhere; }
.generate-meals-preview-list h4 { margin-bottom: .45rem; color: var(--text-primary); }
.generation-preview-title { display: block; margin-bottom: .45rem; font-weight: 700; color: var(--text-primary); }
.generation-preview-edit {
  display: block; width: 100%; padding: 0; border: 0; background: transparent;
  color: inherit; font: inherit; text-align: left; cursor: pointer;
}
.generation-preview-edit > span { display: block; font-size: .9rem; line-height: 1.5; }
.generation-preview-edit > .generation-preview-title { font-size: 1rem; }
.generation-preview-edit-hint { margin-top: .55rem; text-decoration: underline; color: var(--green-dark); }
.generation-preview-edit:focus-visible { outline: 2px solid var(--green-mid); outline-offset: 5px; border-radius: var(--radius-sm); }
.generation-preview-edit:disabled { cursor: default; opacity: .65; }
.generation-preview-delete { margin-top: .4rem; min-height: 28px; color: var(--danger, #a63434); }
.generation-meal-edit-fields { display: grid; gap: 1rem; }
.generation-meal-edit-fields label { display: grid; gap: .4rem; font-weight: 600; }
.generation-meal-edit-fields select { min-width: 0; width: 100%; padding: .65rem; font: inherit; font-size: 16px; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.generation-meal-edit-actions { display: flex; flex-wrap: wrap; gap: .65rem; }
.generation-meal-edit-actions button { flex: 1 1 auto; }
.generate-meals-preview-list p { font-size: .9rem; }
.generate-meals-preview-explanation { margin-top: .5rem; }
#generate-meals-review-question { margin: 1rem 0 .75rem; color: var(--text-primary); font-weight: 600; }
.generate-meals-review-actions { display: flex; flex-wrap: wrap; gap: .6rem; }
.generate-meals-review-actions button {
  min-height: 44px;
  flex: 1 1 200px;
  justify-content: center;
  text-align: center;
}
.generate-meals-dialog-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
}
.generate-meals-dialog-footer p { font-size: .85rem; color: var(--text-muted); margin-bottom: .75rem; }
.generate-meals-dialog-footer button { min-height: 44px; }
@media (max-width: 480px) {
  .generate-meals-controls > button { width: 100%; }
  .generate-meals-dialog-footer button { width: 100%; }
}
.generate-meals-panel p { line-height: 1.5; color: var(--text-muted); }
.generate-meals-controls { display: flex; flex-wrap: wrap; align-items: end; gap: .75rem; margin-top: .75rem; }
.generate-meals-controls label { display: flex; flex-direction: column; gap: .3rem; font-size: .9rem; }
.generate-meals-controls input { width: 7rem; padding: .6rem; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 16px; }
.generate-meals-controls select { max-width: 100%; padding: .6rem; border: 1px solid var(--border); border-radius: var(--radius-sm); font: inherit; font-size: 16px; }
.generation-discovery { padding: 0 1.25rem 1.25rem; min-width: 0; }
.generation-discovery[hidden] { display: none !important; }
#generation-discovery-note { font-size: .9rem; line-height: 1.5; margin-bottom: .75rem; }
.generation-discovery-info { margin-bottom: .5rem; }
.generation-discovery-info > summary {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  margin-left: auto;
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text-muted);
  cursor: pointer;
  list-style: none;
}
.generation-discovery-info > summary::-webkit-details-marker { display: none; }
.generation-discovery-info > summary:hover { background: var(--green-bg); }
.generation-discovery-info > summary:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }
.generation-discovery .discovery-scroll { overflow: visible; padding: 0; }
.generation-discovery .discovery-ing { grid-template-columns: minmax(0, 1fr) 6.5rem auto; }
.generation-discovery .discovery-card, .generation-discovery input { min-width: 0; }
@media (max-width: 480px) {
  .generation-discovery .discovery-ing { grid-template-columns: minmax(0, 1fr) auto; }
  .generation-discovery .discovery-ing input:first-child { grid-column: 1 / -1; }
}
#generate-meals-status:not(:empty) { margin-top: .7rem; }
#generate-meals-status { white-space: pre-line; overflow-wrap: anywhere; }
#generate-meals-status:empty { display: none; }
#generate-meals-status.error { color: #b91c1c; }
.meal-edit-action {
  margin: .2rem 1rem .35rem;
  min-height: 28px;
  padding: .2rem .55rem;
}
.create-meal-item-btn[hidden] { display: none !important; }

/* ── Meal Planner – Recipe Box ── */
.recipe-box-bar {
  position: sticky;
  top: calc(env(safe-area-inset-top) + 3.5rem);
  z-index: 90;
  width: 100%;
  display: flex;
  align-items: center;
  gap: .85rem;
  padding: .75rem 1rem;
  margin-bottom: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  background: var(--white);
  box-shadow: var(--shadow-sm);
  font: inherit;
  text-align: left;
  cursor: default;
}
.recipe-box-bar:hover { background: var(--green-bg); }
.recipe-box-bar:focus-visible,
.recipe-box-count-button:focus-visible,
.recipe-box-dish:focus-within,
.side-choice-card:focus-within {
  outline: 3px solid rgba(240,160,61,.35);
  outline-offset: 2px;
}
.recipe-box-title {
  color: var(--green-dark);
  font-weight: 800;
  white-space: nowrap;
}
.recipe-box-counts {
  display: flex;
  gap: .4rem;
  flex-wrap: wrap;
}
.recipe-box-count {
  display: inline-flex;
  gap: .25rem;
  align-items: baseline;
  padding: .2rem .5rem;
  border-radius: 999px;
  background: var(--green-pale);
  color: var(--text-muted);
  font-size: .76rem;
  font-weight: 600;
}
.recipe-box-count-button {
  border: 0;
  font: inherit;
  cursor: pointer;
}
.recipe-box-count-button:hover {
  background: var(--green-mid);
  color: var(--white);
}
.recipe-box-count-button:hover strong {
  color: var(--white);
}
.recipe-box-count strong { color: var(--green-dark); font-size: .9rem; }
.recipe-box-category[hidden] { display: none !important; }
.recipe-box-scrim {
  position: fixed;
  inset: 0;
  z-index: 210;
  background: rgba(20, 54, 42, .45);
  backdrop-filter: blur(1px);
}
.recipe-box-scrim[hidden],
.recipe-box-drawer[hidden],
.side-choice-modal[hidden] {
  display: none !important;
}
.recipe-box-drawer {
  position: fixed;
  z-index: 220;
  top: calc(env(safe-area-inset-top) + 4rem);
  right: 0;
  bottom: 0;
  width: min(460px, 100vw);
  display: flex;
  flex-direction: column;
  background: var(--white);
  border-radius: var(--radius-lg) 0 0 0;
  box-shadow: -8px 0 28px rgba(12, 45, 34, .24);
  transform: translateX(105%);
  transition: transform .22s ease-out;
}
.recipe-box-drawer.open { transform: translateX(0); }
.recipe-box-drawer-header {
  display: flex;
  flex-direction: column;
  gap: .4rem;
  align-items: flex-start;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--green-pale);
  flex-shrink: 0;
}
.recipe-box-drawer-header h2,
.side-choice-header h2 {
  color: var(--green-dark);
  font-size: 1.2rem;
  line-height: 1.25;
}
.eyebrow {
  display: block;
  margin-bottom: .18rem;
  color: var(--text-muted);
  font-size: .68rem;
  font-weight: 800;
  letter-spacing: .09em;
  text-transform: uppercase;
}
.recipe-box-content {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  padding: 1rem 1.25rem max(1.25rem, env(safe-area-inset-bottom));
}
.recipe-box-drawer-footer {
  flex: 0 0 auto;
  display: grid;
  gap: .5rem;
  padding: .85rem 1.25rem max(.85rem, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--green-pale);
}
.recipe-box-drawer-footer .btn { width: 100%; justify-content: center; }
.recipe-box-category + .recipe-box-category { margin-top: 1.4rem; }
.recipe-box-category-heading {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: .75rem;
  padding-bottom: .45rem;
  border-bottom: 1px solid var(--border);
}
.recipe-box-category-heading h3 {
  color: var(--green-dark);
  font-size: .88rem;
}
.recipe-box-category-heading span {
  color: var(--text-muted);
  font-size: .78rem;
  font-weight: 700;
}
.recipe-box-list {
  display: flex;
  flex-direction: column;
  gap: .65rem;
  margin-top: .65rem;
}
.recipe-box-dish {
  display: flex;
  flex-direction: column;
  gap: .55rem;
  padding: .8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--white);
  flex-shrink: 0;
}
.recipe-box-dish-header h4 {
  color: var(--text-primary);
  font-size: .95rem;
  line-height: 1.3;
}
.recipe-box-ingredients {
  display: flex;
  flex-direction: column;
  gap: .2rem;
  list-style: none;
}
.recipe-box-ingredients[hidden],
.recipe-box-dish-actions button[hidden] {
  display: none;
}
.recipe-box-ingredients li {
  display: flex;
  gap: .45rem;
  color: var(--text-muted);
  font-size: .82rem;
  line-height: 1.35;
}
.recipe-box-ingredients li::before {
  content: "•";
  color: var(--green-light);
  flex-shrink: 0;
}
.recipe-box-ingredients strong {
  min-width: 55px;
  color: var(--text-primary);
  font-weight: 700;
}
.recipe-box-ingredients .recipe-box-no-ingredients { font-style: italic; }
.recipe-box-dish-actions {
  display: flex;
  gap: .45rem;
  flex-wrap: wrap;
}
.recipe-box-empty {
  padding: .6rem .1rem;
  color: var(--text-muted);
  font-size: .84rem;
  font-style: italic;
}
.recipe-edit-form {
  display: flex;
  flex-direction: column;
  gap: .55rem;
  padding-top: .7rem;
  border-top: 1px dashed var(--border);
}
.recipe-edit-form label,
.recipe-edit-label {
  display: flex;
  flex-direction: column;
  gap: .3rem;
  color: var(--text-muted);
  font-size: .76rem;
  font-weight: 700;
}
.recipe-edit-form input,
.side-choice-card select {
  width: 100%;
  padding: .5rem .6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  background: var(--white);
  font: inherit;
}
.recipe-edit-form input {
  /* iOS Safari enlarges the entire page when a smaller text field receives focus. */
  font-size: 16px;
}
.recipe-edit-form input:focus,
.side-choice-card select:focus {
  outline: none;
  border-color: var(--green-mid);
  box-shadow: 0 0 0 3px rgba(240,160,61,.15);
}
.recipe-edit-ingredients {
  display: flex;
  flex-direction: column;
  gap: .4rem;
}
.recipe-edit-ingredient {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(86px, .7fr);
  gap: .4rem;
}
.recipe-edit-actions {
  display: flex;
  justify-content: flex-end;
  gap: .45rem;
}
.side-choice-modal {
  position: fixed;
  inset: 0;
  z-index: 230;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 1rem;
  background: rgba(20, 54, 42, .52);
}
.side-choice-card {
  width: min(440px, 100%);
  max-height: calc(100dvh - 2rem);
  overflow-y: auto;
  padding: 1.1rem;
  border-radius: var(--radius-lg);
  background: var(--white);
  box-shadow: var(--shadow-md);
}
.side-choice-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}
.side-choice-copy {
  margin: .8rem 0 1rem;
  color: var(--text-muted);
  font-size: .9rem;
  line-height: 1.45;
}
.existing-meal-choice {
  display: flex;
  flex-direction: column;
  gap: .5rem;
}
.existing-meal-choice label {
  color: var(--text-primary);
  font-size: .82rem;
  font-weight: 700;
}
.side-choice-divider {
  display: flex;
  align-items: center;
  gap: .6rem;
  margin: 1rem 0;
  color: var(--text-muted);
  font-size: .78rem;
}
.side-choice-divider::before,
.side-choice-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ── Panel sections (used on meal planner single-panel page) ── */
.panel-section {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  margin-bottom: 1.25rem;
  overflow: hidden;
}
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .85rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--green-pale);
  gap: .5rem;
}
.section-header h2 {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--green-dark);
}

/* ── Meal items (expandable wrapper) ── */
.meal-item {
  border-bottom: 1px solid var(--border);
}
.meal-item:last-child { border-bottom: none; }

/* ── Meal rows ── */
.meal-swipe-row { display: flex; align-items: stretch; }
.meal-swipe-row.swipe-open .swipe-delete-action { width: 72px; }
.meal-row {
  display: flex;
  flex: 1 1 auto;
  min-width: 0;
  align-items: center;
  gap: .75rem;
  padding: .75rem 1.25rem;
  cursor: pointer;
  user-select: none;
}
.meal-row:hover { background: var(--green-bg); }
.meal-label { flex: 1; font-size: .9rem; color: var(--text-primary); }
.meal-label strong { color: var(--green-dark); }
.meal-sides { color: var(--text-muted); font-size: .875rem; }

/* ── Chevron ── */
.meal-chevron {
  font-size: 1.1rem;
  color: var(--text-muted);
  transition: transform .2s;
  flex-shrink: 0;
  line-height: 1;
  display: inline-block;
}
.meal-item.open .meal-chevron { transform: rotate(90deg); }

/* ── Ingredient detail panel ── */
.meal-detail {
  display: none;
  padding: .65rem 1.25rem .9rem 3rem;
  border-top: 1px solid var(--border);
  background: var(--green-bg);
}
.meal-item.open .meal-detail { display: block; }
.meal-detail-group { margin-bottom: .65rem; }
.meal-detail-group:last-child { margin-bottom: 0; }
.meal-detail-group-name {
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--green-mid);
  margin-bottom: .3rem;
}
.meal-detail ul {
  list-style: none;
  padding: 0; margin: 0;
  display: flex;
  flex-direction: column;
  gap: .15rem;
}
.meal-detail li {
  display: flex;
  gap: .5rem;
  font-size: .845rem;
  padding: .05rem 0;
}

/* ── Meal selector overlay ── */
.meal-selector {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 1rem;
}
.selector-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 520px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.selector-header {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: space-between;
  padding: .85rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--green-pale);
}
.selector-step-label {
  font-size: .8rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .06em;
}
.selector-step {
  padding: 1rem 1.25rem;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}
.selector-step h3 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--green-dark);
  margin-bottom: .85rem;
}
.optional-label {
  font-size: .8rem;
  font-weight: 400;
  color: var(--text-muted);
}
.selector-item-grid {
  display: flex;
  flex-direction: column;
  gap: .4rem;
}
.selector-item-card {
  text-align: left;
  padding: .7rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--white);
  cursor: pointer;
  font-size: .9rem;
  font-weight: 600;
  color: var(--text-primary);
  transition: background .12s, border-color .12s, box-shadow .12s;
  width: 100%;
}
.selector-item-card:hover { background: var(--green-bg); border-color: var(--green-light); }
.selector-item-card.selected {
  background: var(--green-pale);
  border-color: var(--green-mid);
  box-shadow: 0 0 0 2px rgba(240,160,61,.2);
}
.selector-item-grid > .selector-item-card {
  flex-shrink: 0;
}
.selector-entree-details {
  flex-shrink: 0;
  min-width: 0;
  padding: .75rem 1rem;
  border: 1px solid var(--green-light);
  border-radius: var(--radius-md);
  background: var(--green-bg);
  overflow-wrap: anywhere;
}
.selector-entree-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  margin-bottom: .45rem;
}
.selector-entree-details h4 {
  color: var(--green-dark);
  font-size: .85rem;
  margin: 0;
}
.selector-entree-heading .btn {
  flex-shrink: 0;
}
.selector-entree-preview[hidden],
.selector-entree-edit[hidden] {
  display: none !important;
}
.selector-entree-details ul {
  margin: 0;
  padding-left: 1.2rem;
}
.selector-entree-details li {
  padding: .2rem 0;
  line-height: 1.4;
}
.selector-entree-quantity {
  color: var(--text-muted);
  margin-left: .5rem;
}
.selector-entree-details p {
  margin: 0;
  color: var(--text-muted);
  font-size: .85rem;
}
.create-meal-item-btn {
  width: 100%;
  justify-content: center;
  margin-top: .85rem;
  border-style: dashed;
}
/* ── Selector: prior-picks summary chips ── */
.selector-prior-picks {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
  margin-bottom: .85rem;
}
.selector-prior-picks:empty { margin-bottom: 0; }
.prior-chip {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  background: var(--green-pale);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: .18rem .65rem .18rem .45rem;
  font-size: .8rem;
  color: var(--text-primary);
  font-weight: 500;
  line-height: 1.4;
}
.prior-label {
  font-size: .68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
}
.prior-chip--skipped {
  color: var(--text-muted);
  font-style: italic;
  background: var(--green-bg);
  border-color: var(--border);
}

.skip-btn { margin-top: .85rem; color: var(--text-muted); }
.selector-footer {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  gap: .5rem;
  padding: .85rem 1.25rem;
  border-top: 1px solid var(--border);
  background: var(--green-pale);
  justify-content: flex-end;
}
.selector-footer #btn-selector-back { margin-right: auto; }
.loading-msg { color: var(--text-muted); font-size: .875rem; padding: .5rem 0; }
.loading-msg.error { color: #b91c1c; }

/* ── Focused Pantry Agent modal inside Meal Planner ── */
.inline-agent-modal {
  position: fixed;
  inset: 0;
  z-index: 240;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(20, 54, 42, .52);
}
.inline-agent-modal[hidden] {
  display: none !important;
}
.inline-agent-card {
  width: min(560px, 100%);
  height: min(720px, calc(100dvh - 2rem));
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--white);
  box-shadow: var(--shadow-md);
}
.inline-agent-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--green-pale);
  flex-shrink: 0;
}
.inline-agent-header h2 {
  color: var(--green-dark);
  font-size: 1.2rem;
  line-height: 1.25;
}
.inline-agent-copy {
  padding: .85rem 1.25rem 0;
  color: var(--text-muted);
  font-size: .88rem;
  line-height: 1.45;
  flex-shrink: 0;
}
.inline-agent-thread {
  max-height: none;
  flex: 1 1 auto;
  min-height: 120px;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}
.inline-agent-confirm {
  align-self: stretch;
  justify-content: center;
  margin: .5rem 1.25rem;
  flex-shrink: 0;
}
.inline-agent-confirm[hidden] { display: none !important; }
.inline-agent-error {
  margin: 0 1.25rem .55rem;
  padding: .55rem .7rem;
  border-radius: var(--radius-sm);
  color: #991b1b;
  background: #fee2e2;
  font-size: .82rem;
  line-height: 1.35;
  flex-shrink: 0;
}
.inline-agent-form {
  flex-shrink: 0;
}
.inline-agent-return {
  align-self: stretch;
  justify-content: center;
  margin: 0 1rem max(1rem, env(safe-area-inset-bottom));
  flex-shrink: 0;
}

/* ── Pantry Agent mini-chat on grocery list page ── */
.grocery-layout {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 1.25rem;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
  padding: 1.25rem;
}
.grocery-layout .panel-grocery {
  flex: 1.4;
  min-width: 0;
}
.panel-agent-mini {
  flex: 1;
  min-width: 260px;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 1rem;
  max-height: calc(100vh - 100px);
  min-height: 0;
}
.agent-mini-header { flex-shrink: 0; }
.agent-mini-hint {
  font-size: .8rem;
  color: var(--text-muted);
  margin: 0;
}
.agent-mini-thread {
  flex: 1;
  min-height: 120px;
  max-height: 320px;
  overflow-y: auto;
}
.panel-agent-mini .chat-form {
  flex-shrink: 0;
}
.panel-agent-mini .chat-input {
  min-height: 40px;
  max-height: 90px;
}

@media (max-width: 700px) {
  /* Match Pantry Agent: keep the navigation outside the scroll owner while
     allowing the entire planner (including Recipe Box and mini chat) to scroll. */
  html:has(body.meal-planner-page [data-account-app]:not([hidden])),
  body.meal-planner-page:has([data-account-app]:not([hidden])) {
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
  }
  body.meal-planner-page [data-account-app] {
    min-height: 0;
    overflow: hidden;
  }
  body.meal-planner-page [data-page-content] {
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
  }
  body.meal-planner-page .grocery-layout {
    flex: 0 0 auto;
  }
  /* No sticky layers inside the planner's scroll area. */
  body.meal-planner-page .app-header,
  body.meal-planner-page .recipe-box-bar {
    position: static;
  }
  body.meal-planner-page .app-header {
    -webkit-transform: none;
    transform: none;
  }
  .grocery-layout {
    flex-direction: column;
    padding: .75rem;
    padding-bottom: max(.75rem, env(safe-area-inset-bottom));
  }
  .panel-agent-mini {
    max-width: 100%;
    min-width: 0;
    width: 100%;
    position: static;
    max-height: 320px;
  }
  .recipe-box-bar {
    top: calc(env(safe-area-inset-top) + 3.1rem);
    align-items: flex-start;
    flex-wrap: wrap;
    gap: .55rem;
    padding: .7rem .8rem;
  }
  .recipe-box-title { width: 100%; }
  .recipe-box-drawer {
    top: 0;
    width: 100vw;
    border-radius: 0;
  }
  .recipe-box-drawer-header,
  .recipe-box-content,
  .recipe-box-drawer-footer {
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
  }
  .recipe-box-drawer-header {
    padding-top: max(1rem, env(safe-area-inset-top));
  }
  .recipe-box-content {
    padding-bottom: max(1.25rem, env(safe-area-inset-bottom));
  }
  .recipe-box-dish-actions .btn {
    flex: 1 1 130px;
    justify-content: center;
  }
  .side-choice-modal {
    align-items: flex-end;
    padding: 0;
  }
  .side-choice-card {
    width: 100%;
    max-height: min(78dvh, 680px);
    padding: 1rem max(1rem, env(safe-area-inset-right))
      max(1rem, env(safe-area-inset-bottom));
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }
  .selector-card {
    max-height: min(86dvh, 720px);
  }
  .selector-step {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    touch-action: pan-y;
  }
  .inline-agent-modal {
    align-items: flex-end;
    padding: 0;
  }
  .inline-agent-card {
    width: 100%;
    height: min(92dvh, 760px);
    max-height: var(--app-height, 100dvh);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }
  .inline-agent-header,
  .inline-agent-copy,
  .inline-agent-thread {
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
  }
  .inline-agent-copy {
    padding-top: .75rem;
  }
  .inline-agent-form {
    padding-left: max(.75rem, env(safe-area-inset-left));
    padding-right: max(.75rem, env(safe-area-inset-right));
  }
  .inline-agent-error {
    margin-left: max(1rem, env(safe-area-inset-left));
    margin-right: max(1rem, env(safe-area-inset-right));
  }
  .inline-agent-return {
    margin-left: max(1rem, env(safe-area-inset-left));
    margin-right: max(1rem, env(safe-area-inset-right));
  }
}

/* Inline grocery list content */
#grocery-content-inline { padding: 1rem 1.25rem; }

/* The standalone Grocery List prints its currently rendered items, not the app shell. */
@media print {
  @page { margin: 0.6in; }

  body.grocery-list-page {
    display: block;
    min-height: 0;
    background: #fff;
    color: #111;
    font-size: 11pt;
  }
  body.grocery-list-page .app-header,
  body.grocery-list-page .panel-agent-mini,
  body.grocery-list-page .grocery-actions,
  body.grocery-list-page .toast,
  body.grocery-list-page .empty-state,
  body.grocery-list-page .grocery-item-check,
  body.grocery-list-page .swipe-delete-action,
  body.grocery-list-page .category-icon,
  body.grocery-list-page [data-signed-out-landing] {
    display: none !important;
  }
  body.grocery-list-page [data-account-app],
  body.grocery-list-page [data-page-content],
  body.grocery-list-page .grocery-layout,
  body.grocery-list-page .panel-grocery {
    display: block;
    width: 100%;
    max-width: none;
    height: auto;
    min-height: 0;
    margin: 0;
    padding: 0;
    overflow: visible;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }
  body.grocery-list-page .panel-header {
    display: block;
    padding: 0 0 0.25in;
    margin-bottom: 0.1in;
    border: 0;
    border-bottom: 1px solid #777;
    background: none;
  }
  body.grocery-list-page .panel-header h2 {
    color: #111;
    font-size: 18pt;
  }
  body.grocery-list-page .list-date {
    color: #333;
    font-size: 10pt;
    margin-top: 0.1in;
  }
  body.grocery-list-page #grocery-content { padding: 0; }
  body.grocery-list-page .category-group {
    margin: 0 0 0.2in;
    break-inside: auto;
  }
  body.grocery-list-page .category-title {
    display: block;
    color: #111;
    font-size: 11pt;
    letter-spacing: 0;
    padding: 0 0 0.05in;
    margin: 0.15in 0 0.05in;
    background: none;
    border-bottom: 1px solid #aaa;
    break-after: avoid;
    page-break-after: avoid;
  }
  body.grocery-list-page .grocery-item {
    display: block;
    padding: 0;
    border: 0;
    break-inside: avoid;
    page-break-inside: avoid;
  }
  body.grocery-list-page .grocery-item-content {
    display: flex;
    align-items: baseline;
    gap: 0.2in;
    padding: 0.05in 0;
    background: none !important;
    color: #111;
  }
  body.grocery-list-page .item-name,
  body.grocery-list-page .grocery-item.completed .item-name {
    flex: 1 1 auto;
    min-width: 0;
    color: #111;
    text-decoration: none;
    overflow-wrap: anywhere;
  }
  body.grocery-list-page .item-qty {
    flex: 0 1 35%;
    min-width: 0;
    color: #222;
    font-size: 10pt;
    white-space: normal;
    overflow-wrap: anywhere;
    text-align: right;
  }
}

/* ── Extra-small screens (iPhone SE, 375 px) ── */
@media (max-width: 390px) {
  /* Shrink the textarea to a single line — it grows via max-height as
     the user types (the rows="3" attribute is overridden by height here) */
  .chat-input {
    height: 40px;
    min-height: 40px;
    max-height: 80px;
    padding: .5rem .75rem;
  }
  /* Tighter form padding + compact Send button */
  .chat-form { padding: .5rem .75rem; }
  .chat-form .btn { padding: .5rem .85rem; font-size: .82rem; }

  /* Tighter card padding so more cards are visible at once */
  .recipe-card-header { padding: .7rem .85rem; }

  /* Panel headers slightly smaller to recover vertical space */
  .panel-header { padding: .65rem .9rem; }
  .panel-header h2 { font-size: .95rem; }
}

/* ── Account preference memory ── */
[data-preferences][hidden],[data-pref-alert][hidden],[data-pref-confirm][hidden],[data-pref-learning][hidden]{display:none!important}
.account-preferences{padding:1.25rem;margin-bottom:1rem;background:var(--white);border:1px solid var(--border);border-radius:var(--radius-lg);box-shadow:var(--shadow-sm)}
.account-preferences h2{margin-bottom:.35rem;color:var(--green-dark);font-size:1.1rem}
.account-preferences p{color:var(--text-muted);line-height:1.55}
.pref-learning{display:flex;gap:.7rem;align-items:flex-start;margin:1rem 0;padding:.8rem;background:var(--green-pale);border-radius:var(--radius-md);font-size:.9rem;color:var(--text-muted);line-height:1.5}
.pref-learning input{width:1.15rem;height:1.15rem;margin-top:.2rem;accent-color:var(--green-mid);flex:0 0 auto}
.pref-group{border:0;margin:0 0 1.1rem;min-width:0}
.pref-group legend{font-weight:700;color:var(--green-dark);margin-bottom:.15rem}
.pref-hint{font-size:.84rem}
.pref-list{list-style:none;display:grid;gap:.45rem;margin:.5rem 0}
.pref-item{display:flex;flex-wrap:wrap;align-items:center;gap:.4rem}
.pref-item input,.pref-add input{flex:1 1 12rem;min-width:0;padding:.55rem .7rem;border:1px solid var(--border);border-radius:var(--radius-md);font:inherit;color:var(--text-primary)}
.pref-meta{font-size:.76rem;color:var(--text-muted)}
.pref-empty{font-size:.88rem;color:var(--text-muted);padding:.4rem 0}
.pref-add{display:flex;gap:.4rem}
.pref-radio{display:flex;gap:.55rem;align-items:flex-start;padding:.4rem 0;font-size:.9rem;color:var(--text-primary)}
.pref-radio input{margin-top:.2rem;accent-color:var(--green-mid)}
.pref-footer{display:flex;justify-content:space-between;align-items:center;gap:1rem;margin-top:1rem;flex-wrap:wrap}
.pref-actions{display:flex;gap:.5rem;flex-wrap:wrap}
.pref-status{font-size:.88rem;color:var(--green-dark)}
.pref-status.is-error{color:#b91c1c}
.pref-alert,.pref-confirm{margin:1rem 0;padding:.9rem;border:1px solid #f59e0b;background:#fffbeb;border-radius:var(--radius-md)}
.pref-confirm{border-color:#fca5a5;background:#fef2f2}
.pref-alert p,.pref-confirm p{color:var(--text-primary)}
.pref-alert details,.pref-alert .pref-actions,.pref-confirm .pref-actions{margin-top:.6rem}
.pref-conflict-list{padding-left:1.2rem;font-size:.85rem}
.account-preferences input:focus-visible,.account-preferences button:focus-visible{outline:2px solid var(--green-dark);outline-offset:2px}
@media (max-width:768px){.pref-footer,.pref-actions{flex-direction:column;align-items:stretch}.pref-actions .btn{width:100%;justify-content:center}.pref-add{flex-direction:row}}
