:root {
  --ink: #172033;
  --leaf: #0f766e;
  --cream: #fffaf2;
  --line: #e8edf2;
}

html { scroll-behavior: smooth; }
body { font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif; }
button, a, input, select, textarea { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid rgba(15, 118, 110, .28);
  outline-offset: 2px;
}

.app-shell {
  width: 100%;
  max-width: 1800px;
  margin-left: auto;
  margin-right: auto;
}

.panel {
  border: 1px solid rgba(226, 232, 240, .9);
  background: rgba(255, 255, 255, .90);
  border-radius: 1.8rem;
  box-shadow: 0 18px 50px rgba(15, 23, 42, 0.08);
  backdrop-filter: blur(18px);
}

.page-title { font-size: clamp(2rem, 3vw, 3.35rem); line-height: .96; font-weight: 900; letter-spacing: -0.055em; }
.page-subtitle { margin-top: .75rem; max-width: 780px; color: #64748b; line-height: 1.7; }
.section-title { font-size: 1rem; line-height: 1.35; font-weight: 900; letter-spacing: -0.015em; }
.section-subtitle { margin-top: .25rem; font-size: .875rem; line-height: 1.55; color: #64748b; }
.eyebrow { font-size: .72rem; font-weight: 900; letter-spacing: .17em; text-transform: uppercase; color: var(--leaf); }

.input {
  width: 100%;
  border: 1px solid #e2e8f0;
  border-radius: 1rem;
  background: rgba(255,255,255,.92);
  padding: .78rem .9rem;
  font-size: .925rem;
  font-weight: 650;
  color: var(--ink);
  box-shadow: 0 1px 0 rgba(15,23,42,.03);
}
.input::placeholder { color: #94a3b8; font-weight: 600; }
.input:focus { border-color: rgba(15,118,110,.55); box-shadow: 0 0 0 4px rgba(15,118,110,.10); outline: none; }
textarea.input { min-height: 92px; resize: vertical; font-weight: 500; line-height: 1.45; }

.btn-primary, .btn-muted, .btn-ghost, .btn-danger {
  display: inline-flex;
  min-height: 2.7rem;
  align-items: center;
  justify-content: center;
  gap: .45rem;
  border-radius: .95rem;
  padding: .68rem 1rem;
  font-size: .875rem;
  font-weight: 900;
  line-height: 1;
  transition: transform .16s ease, box-shadow .16s ease, background-color .16s ease, border-color .16s ease;
  white-space: nowrap;
}
.btn-primary { background: var(--leaf); color: white; box-shadow: 0 14px 32px rgba(15, 118, 110, .20); }
.btn-primary:hover { transform: translateY(-1px); background: #0d665f; }
.btn-muted { border: 1px solid #e2e8f0; background: white; color: #334155; }
.btn-muted:hover { transform: translateY(-1px); border-color: #cbd5e1; box-shadow: 0 10px 22px rgba(15, 23, 42, .06); }
.btn-ghost { background: transparent; color: #475569; padding-inline: .65rem; }
.btn-ghost:hover { background: #f1f5f9; }
.btn-danger { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.btn-danger:hover { background: #fecaca; transform: translateY(-1px); }

.nav-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 7.4rem;
  border-radius: 1rem;
  padding: .78rem 1.1rem;
  font-size: .9rem;
  font-weight: 900;
  color: #64748b;
}
.nav-pill.active { background: #0f766e; color: white; box-shadow: 0 12px 28px rgba(15, 118, 110, .18); }

.tag-pill {
  border: 1px solid #e2e8f0;
  border-radius: 999px;
  background: white;
  padding: .43rem .7rem;
  font-size: .76rem;
  font-weight: 850;
  color: #475569;
}
.tag-pill.active { border-color: rgba(15,118,110,.32); background: #dff8f1; color: #0f766e; }
.planner-filter-wrap .tag-pill { font-size: .72rem; padding: .35rem .58rem; }
.planner-filter-wrap #plannerTagFilters { max-height: 5.5rem; overflow-y: auto; }

.segmented { display: inline-flex; border-radius: 1rem; background: white; border: 1px solid #e2e8f0; padding: .18rem; }
.segmented-btn { border-radius: .78rem; padding: .62rem .9rem; font-size: .84rem; font-weight: 900; color: #64748b; }
.segmented-btn.active { background: #172033; color: white; }

.recipe-card, .meal-card, .shopping-row, .cook-row {
  border: 1px solid #e8edf2;
  background: white;
  border-radius: 1.25rem;
  transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease;
}
.recipe-card { padding: 1rem; cursor: pointer; }
.recipe-card:hover { transform: translateY(-2px); border-color: rgba(15,118,110,.25); box-shadow: 0 14px 30px rgba(15,23,42,.08); }
.recipe-card.active { border-color: rgba(15,118,110,.45); background: linear-gradient(180deg, #fff, #f5fffc); box-shadow: 0 14px 30px rgba(15,118,110,.11); }
.meal-card { padding: .95rem; }
.family-card {
  border: 1px solid #e8edf2;
  background: white;
  border-radius: 1.25rem;
  padding: 1rem;
}
.family-card.active {
  border-color: rgba(15,118,110,.45);
  background: linear-gradient(180deg, #fff, #f5fffc);
  box-shadow: 0 14px 30px rgba(15,118,110,.10);
}
.shopping-row { padding: .85rem; }
.shop-mode .shopping-row { padding: 1.05rem; border-radius: 1.4rem; }
.cook-row { padding: 1rem; }

.calendar-grid { display: grid; grid-template-columns: repeat(7, minmax(9.5rem, 1fr)); gap: .5rem; }
.calendar-head { padding: .55rem .35rem; text-align: center; font-size: .73rem; font-weight: 900; color: #64748b; text-transform: uppercase; letter-spacing: .09em; }
.calendar-day {
  min-height: 8.8rem;
  border: 1px solid #e2e8f0;
  border-radius: 1.25rem;
  background: white;
  padding: .72rem;
  cursor: pointer;
  transition: transform .14s ease, border-color .14s ease, background .14s ease, box-shadow .14s ease;
}
.calendar-day:hover { transform: translateY(-1px); border-color: rgba(15,118,110,.28); box-shadow: 0 10px 24px rgba(15,23,42,.06); }
.calendar-day.selected { border-color: rgba(15,118,110,.65); background: #f5fffc; box-shadow: inset 0 0 0 2px rgba(15,118,110,.08); }
.calendar-day.outside { opacity: .48; background: #f8fafc; }
.calendar-day.today .date-badge { background: #0f766e; color: white; }
.date-badge { display: inline-grid; height: 2rem; min-width: 2rem; place-items: center; border-radius: .75rem; padding-inline: .45rem; font-size: .85rem; font-weight: 900; color: #334155; }

.calendar-date-stack {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  min-width: 0;
}
.day-label {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  background: #f1f5f9;
  padding: .28rem .5rem;
  font-size: .68rem;
  font-weight: 900;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: #64748b;
}
.calendar-day.today .day-label { background: #dff8f1; color: #0f766e; }
.calendar-day.selected .day-label { background: rgba(15,118,110,.10); color: #0f766e; }
.meal-chip { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; border-radius: .75rem; background: #f1f5f9; padding: .35rem .5rem; font-size: .72rem; font-weight: 800; color: #334155; }
.meal-chip.cooked { background: #dff8f1; color: #0f766e; text-decoration: line-through; }

.recipe-detail-hero { background: radial-gradient(circle at 20% 10%, rgba(223,248,241,1), transparent 32%), radial-gradient(circle at 90% 0%, rgba(255,241,231,.95), transparent 36%), white; }
.nutri-box { border: 1px solid #e2e8f0; border-radius: 1rem; background: white; padding: .85rem; text-align: center; }
.nutri-box strong { display: block; font-size: 1.05rem; font-weight: 900; }
.nutri-box span { display: block; margin-top: .15rem; font-size: .72rem; font-weight: 800; color: #64748b; }

.check-tile { display: flex; gap: .8rem; align-items: flex-start; }
.check-tile input[type="checkbox"] { margin-top: .2rem; height: 1.25rem; width: 1.25rem; accent-color: #0f766e; flex: 0 0 auto; }
.check-tile.done { opacity: .52; filter: grayscale(.25); background: #f8fafc; border-color: #e2e8f0; box-shadow: none; }
.check-tile.done .check-copy { color: #64748b; text-decoration: line-through; }
.check-tile.done input[type="checkbox"] { opacity: .85; }

.shop-links a { color: #0f766e; font-weight: 900; text-decoration: underline; text-underline-offset: 3px; }
.shop-links a:hover { color: #0d665f; }

.line-clamp-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.line-clamp-3 { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

@media (max-width: 640px) {
  .panel { border-radius: 1.25rem; }
  .calendar-grid { grid-template-columns: repeat(7, minmax(7.2rem, 1fr)); }
  .calendar-day { min-height: 7.5rem; padding: .55rem; border-radius: 1rem; }
  .nav-pill { min-width: 6.5rem; padding-inline: .85rem; }
}

@media print {
  header, nav, footer, #installBanner, #toast, #shareBanner, .no-print { display: none !important; }
  body { background: white !important; }
  .app-shell { max-width: none !important; padding: 0 !important; }
  .panel { box-shadow: none !important; border: 1px solid #d9dee6 !important; }
}

/* v3 mobile app refinements */
.mobile-panel-close { display: none; }

.planner-rail {
  display: flex;
  gap: .85rem;
  overflow-x: auto;
  padding: .15rem .15rem .85rem;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
}
.planner-rail::-webkit-scrollbar { height: .45rem; }
.planner-rail::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 999px; }
.planner-recipe-card {
  flex: 0 0 260px;
  scroll-snap-align: start;
  border: 1px solid #e8edf2;
  border-radius: 1.25rem;
  background: white;
  padding: 1rem;
  box-shadow: 0 10px 24px rgba(15, 23, 42, .05);
}

@media (max-width: 767px) {
  body {
    padding-bottom: calc(5.5rem + env(safe-area-inset-bottom));
    overflow-x: hidden;
  }

  header .app-shell { padding-block: .85rem; }
  header .grid.grid-cols-3 { display: none; }
  header h1 { font-size: 1.8rem !important; margin-top: .25rem; }
  header .h-14.w-14 { width: 3rem; height: 3rem; border-radius: 1rem; font-size: 1.6rem; }
  header .inline-flex.rounded-full { display: none; }

  nav {
    position: fixed !important;
    top: auto !important;
    left: .75rem;
    right: .75rem;
    bottom: calc(.75rem + env(safe-area-inset-bottom));
    z-index: 80;
    border: 0 !important;
    background: transparent !important;
    backdrop-filter: none !important;
  }
  nav .app-shell { padding: 0 !important; }
  nav .flex {
    display: grid !important;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    width: 100%;
    overflow: visible !important;
    border: 1px solid rgba(226, 232, 240, .9);
    border-radius: 1.45rem !important;
    background: rgba(255,255,255,.94) !important;
    padding: .35rem !important;
    box-shadow: 0 18px 50px rgba(15, 23, 42, .18);
  }
  .nav-pill {
    min-width: 0;
    width: 100%;
    border-radius: 1.05rem;
    padding: .9rem .35rem;
    font-size: .8rem;
  }

  main.app-shell { padding: 1rem .75rem 0; }
  footer { display: none; }
  .page-title { font-size: 2rem; line-height: 1.02; letter-spacing: -.045em; }
  .page-subtitle { display: none; }
  .panel { border-radius: 1.25rem; }
  .btn-primary, .btn-muted, .btn-ghost, .btn-danger { min-height: 2.9rem; border-radius: 1rem; }

  #recipesView > .mb-6, #plannerView > .mb-6, #shoppingView > .mb-6 {
    gap: .85rem;
    margin-bottom: 1rem;
  }
  #plannerView > .mb-6 > .flex,
  #shoppingView > .mb-6 > .flex {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0,1fr));
  }
  #plannerView > .mb-6 > .flex > *,
  #shoppingView > .mb-6 > .flex > * { width: 100%; }
  .segmented { grid-column: span 2; display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); }

  #recipesView .grid.xl\:grid-cols-\[430px_minmax\(0\,1fr\)\],
  #recipesView .grid.\32xl\:grid-cols-\[480px_minmax\(0\,1fr\)\] { display: block; }
  #recipeList { max-height: none !important; overflow: visible !important; }
  .recipe-card { padding: .9rem; }
  .recipe-card.active { box-shadow: none; }

  #recipeDetail {
    display: none;
    position: fixed;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    z-index: 95;
    overflow-y: auto;
    border-radius: 0;
    border: 0;
    background: #f7f3eb;
    box-shadow: none;
    -webkit-overflow-scrolling: touch;
  }
  body.recipe-panel-open #recipeDetail { display: block; }
  body.recipe-panel-open { overflow: hidden; }
  .mobile-panel-close { display: inline-flex; }
  body.recipe-panel-open #recipeDetail .recipe-detail-hero {
    position: sticky;
    top: 0;
    z-index: 5;
    background: rgba(255,250,242,.96);
    backdrop-filter: blur(18px);
  }
  #recipeDetail h2 { font-size: 2rem !important; line-height: 1.03 !important; }
  #recipeDetail .grid { grid-template-columns: 1fr !important; }
  #recipeDetail .nutri-box { padding: .7rem; }
  .cook-row { padding: 1rem; border-radius: 1.15rem; }

  #calendarWrap {
    overflow-x: hidden !important;
    padding: .5rem !important;
  }
  .calendar-grid {
    display: grid;
    grid-template-columns: 1fr !important;
    gap: .6rem;
    width: 100%;
    min-width: 0;
  }
  .calendar-head { display: none; }
  .calendar-day {
    width: 100%;
    min-height: 5.8rem;
    border-radius: 1.15rem;
    padding: .8rem;
  }

  .calendar-date-stack { gap: .4rem; }
  .day-label { font-size: .64rem; padding: .24rem .45rem; }
  .calendar-day.outside { display: none; }
  .calendar-day .space-y-1\.5 {
    display: flex;
    gap: .35rem;
    overflow-x: auto;
    padding-bottom: .1rem;
  }
  .meal-chip {
    display: inline-flex;
    max-width: 11rem;
    flex: 0 0 auto;
  }

  .planner-rail {
    margin-left: -.2rem;
    margin-right: -.2rem;
    padding-bottom: .9rem;
  }
  .planner-recipe-card { flex-basis: 76vw; }

  #selectedDayMeals .meal-card textarea { min-height: 72px; }

  #shoppingList { padding: .85rem !important; }
  .shopping-row { border-radius: 1.15rem; padding: .9rem; }
  .shop-mode .shopping-row { padding: 1rem; }
  #shopProgress {
    position: sticky;
    top: 0;
    z-index: 10;
    border-radius: 0;
  }
}
@media (max-width: 767px) {
  #recipesView > .grid,
  #plannerView > .grid,
  #shoppingView > .grid { display: block; }
  #plannerView aside,
  #shoppingView aside { margin-top: 1rem; }
}

/* v4 focused mobile recipe and shopping refinements */
.panel-close-x {
  position: absolute;
  top: .85rem;
  right: .85rem;
  z-index: 20;
  width: 2.6rem;
  height: 2.6rem;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  border: 1px solid #e2e8f0;
  background: rgba(255,255,255,.94);
  color: #172033;
  font-size: 1.7rem;
  font-weight: 800;
  line-height: 1;
  box-shadow: 0 12px 28px rgba(15,23,42,.10);
}
.panel-close-x:hover { background: #f8fafc; }

.shopping-dock {
  position: sticky;
  bottom: 1rem;
  z-index: 35;
  margin: 1rem auto 0;
  display: flex;
  width: min(100%, 760px);
  gap: .6rem;
  justify-content: center;
  border: 1px solid rgba(226,232,240,.9);
  border-radius: 1.35rem;
  background: rgba(255,255,255,.94);
  padding: .65rem;
  box-shadow: 0 18px 50px rgba(15,23,42,.14);
  backdrop-filter: blur(16px);
}
.shopping-dock .btn-primary,
.shopping-dock .btn-muted,
.shopping-dock .btn-danger { flex: 1 1 auto; }
body:not(.route-shopping) .shopping-dock { display: none; }

@media (min-width: 768px) {
  .mobile-panel-close.panel-close-x { display: none; }
}

@media (max-width: 767px) {
  body.recipe-panel-open #recipesView { display: block !important; }
  body.recipe-panel-open #recipeDetail .recipe-detail-hero {
    position: static;
    top: auto;
    background: white;
    backdrop-filter: none;
  }
  body.recipe-panel-open #recipeDetail .cook-mode-detail .recipe-detail-hero {
    position: sticky;
    top: 0;
    z-index: 5;
    background: rgba(255,250,242,.96);
    backdrop-filter: blur(18px);
  }
  #recipeDetail .recipe-preview-detail h2 { font-size: 2rem !important; }
  #recipeDetail .cook-mode-detail h2 { font-size: 1.35rem !important; line-height: 1.15 !important; }
  #recipeDetail .cook-mode-detail .btn-primary,
  #recipeDetail .cook-mode-detail .btn-muted { min-height: 2.45rem; padding: .55rem .72rem; font-size: .78rem; }
  .panel-close-x { display: inline-flex !important; }
  .recipe-preview-detail .btn-primary,
  .recipe-preview-detail .btn-muted { width: 100%; }
  .recipe-preview-detail .xl\:flex-row > .flex,
  .cook-mode-detail .xl\:flex-row > .flex { width: 100%; }

  #shoppingView { padding-bottom: 5.2rem; }
  .shopping-dock {
    position: fixed;
    left: .75rem;
    right: .75rem;
    bottom: calc(5.25rem + env(safe-area-inset-bottom));
    width: auto;
    margin: 0;
    display: grid;
    grid-template-columns: repeat(2, minmax(0,1fr));
    border-radius: 1.25rem;
    padding: .5rem;
  }
  .shopping-dock .btn-primary,
  .shopping-dock .btn-muted,
  .shopping-dock .btn-danger { width: 100%; min-height: 2.6rem; font-size: .78rem; padding-inline: .5rem; }
  #doneShoppingBtn:not(.hidden) { grid-column: span 2; }
}

/* v5 mobile planner and shopping refinements */
@media (max-width: 767px) {
  #recipeHeaderActions { display: none !important; }
  .period-arrow { display: none !important; }

  /* Keep planned recipes stacked inside each mobile day card. */
  .calendar-day .space-y-1\.5 {
    display: block !important;
    overflow: visible !important;
    padding-bottom: 0 !important;
  }
  .calendar-day .meal-chip {
    display: block !important;
    max-width: 100% !important;
    width: 100% !important;
    margin-top: .35rem;
    flex: none !important;
  }
  .calendar-day .meal-chip:first-child { margin-top: 0; }

  body.selected-day-open::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 84;
    background: rgba(15, 23, 42, .34);
    backdrop-filter: blur(6px);
  }
  body.selected-day-open { overflow: hidden; }
  #selectedDayPanel {
    display: none;
    position: fixed !important;
    left: 0;
    right: 0;
    bottom: 0;
    top: 4.5vh;
    z-index: 88;
    margin: 0 !important;
    overflow-y: auto;
    border-radius: 1.65rem 1.65rem 0 0 !important;
    border-left: 0;
    border-right: 0;
    border-bottom: 0;
    background: #f7f3eb;
    box-shadow: 0 -22px 80px rgba(15, 23, 42, .22);
    -webkit-overflow-scrolling: touch;
  }
  body.selected-day-open #selectedDayPanel {
    display: block;
    animation: selectedDaySheetIn .22s ease-out both;
  }
  .selected-day-close { display: inline-flex !important; }
  #selectedDayPanel > .rounded-\[1\.4rem\] {
    margin-top: .4rem;
    padding-right: 3.4rem;
  }
  #selectedDayMeals .meal-card {
    width: 100%;
    min-width: 0;
  }
  #selectedDayMeals .meal-card > .flex {
    align-items: flex-start;
  }
  #selectedDayMeals .meal-card .grid.grid-cols-2 {
    grid-template-columns: 1fr;
  }

  #shoppingView { padding-bottom: 0 !important; }
  #shoppingView > .mb-6 > .flex {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  #shoppingView > .mb-6 > .flex #doneShoppingBtn:not(.hidden) {
    grid-column: span 2;
  }
}

@keyframes selectedDaySheetIn {
  from { opacity: 0; transform: translateY(1.75rem); }
  to { opacity: 1; transform: translateY(0); }
}
@media (min-width: 768px) {
  .selected-day-close { display: none !important; }
}

/* v6 mobile polish and data-file refinements */
@media (max-width: 767px) {
  /* Give preview tables breathing room before Cook Now mode is activated. */
  .recipe-preview-detail table td:first-child { padding-left: .85rem !important; }
  .recipe-preview-detail table td:last-child { padding-right: .85rem !important; }
  .recipe-preview-detail table td { vertical-align: top; }
  .recipe-preview-detail .overflow-hidden.rounded-2xl { border-radius: 1.15rem !important; }

  /* In the mobile selected-day sheet, the swipe cards are the picker. */
  #selectedDayPanel .quick-add-controls { display: none !important; }
  #selectedDayPanel .planner-filter-wrap {
    position: sticky;
    top: -.1rem;
    z-index: 4;
    margin-left: -.15rem;
    margin-right: -.15rem;
    background: rgba(255,255,255,.96);
    backdrop-filter: blur(14px);
  }
  #plannerTagFilters { display: none !important; }

  /* Add separation between shopping source and shopping list cards on mobile. */
  #shoppingView aside { margin-bottom: 1rem !important; }
}

/* v1.5 system-icon UI refresh */
.ti { font-size: 1.15em; line-height: 1; flex: 0 0 auto; }
.eyebrow .ti, .section-title .ti { margin-right: .35rem; vertical-align: -0.12em; }
.nav-pill { gap: .45rem; }
.nav-pill .ti { font-size: 1.2rem; }
.segmented-btn { display: inline-flex; align-items: center; justify-content: center; gap: .35rem; }
#syncDebugLog { white-space: pre-wrap; word-break: break-word; }

@media (max-width: 767px) {
  .nav-pill {
    display: grid;
    grid-template-columns: 1fr;
    place-items: center;
    gap: .15rem;
    padding: .72rem .25rem !important;
    min-height: 3.45rem;
    font-size: .68rem;
  }
  .nav-pill .ti { font-size: 1.42rem; }
  .nav-pill .nav-label {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }
  nav .flex { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  #plannerView > .mb-6 > .flex,
  #shoppingView > .mb-6 > .flex {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  #plannerView > .mb-6 > .flex .btn-primary,
  #plannerView > .mb-6 > .flex .btn-muted,
  #shoppingView > .mb-6 > .flex .btn-primary,
  #shoppingView > .mb-6 > .flex .btn-muted,
  #shoppingView > .mb-6 > .flex .btn-danger {
    gap: .32rem;
    padding-inline: .55rem;
    font-size: .78rem;
  }
}

/* v1.7 mobile refinement: icon-only app navigation and safer profile layout */
@media (max-width: 767px) {
  nav {
    display: block;
    position: fixed !important;
    left: .65rem !important;
    right: .65rem !important;
    bottom: calc(.65rem + env(safe-area-inset-bottom)) !important;
    top: auto !important;
    z-index: 120 !important;
    pointer-events: none;
  }
  nav .app-shell,
  nav .flex { pointer-events: auto; }
  .nav-label { display: none !important; }
  .nav-pill {
    aspect-ratio: 1.18 / 1;
    min-height: 3.15rem;
    padding: .45rem !important;
    gap: 0 !important;
  }
  .nav-pill .ti {
    font-size: 1.55rem;
    line-height: 1;
  }
  main.app-shell {
    padding-bottom: calc(6.75rem + env(safe-area-inset-bottom)) !important;
  }
  #profileView,
  #profileView * { min-width: 0; }
  #profileView > .grid { display: block !important; }
  #profileView aside { position: static !important; }
  #profileView .panel { overflow: hidden; }
  #profileView .mb-6 > .flex { width: 100%; display: grid; grid-template-columns: 1fr 1fr; }
  #profileView .mb-6 > .flex > button { width: 100%; justify-content: center; }
  #syncDebugLog {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    word-break: break-word;
  }
  #familyCards { grid-template-columns: 1fr !important; }
}

/* v1.8 mobile navigation and profile layout hardening */
@media (max-width: 767px) {
  nav:not(.hidden) {
    display: block !important;
    position: fixed !important;
    top: auto !important;
    left: .75rem !important;
    right: .75rem !important;
    bottom: calc(.75rem + env(safe-area-inset-bottom)) !important;
    z-index: 120 !important;
    transform: none !important;
  }
  nav .app-shell {
    width: 100% !important;
    max-width: none !important;
    padding: 0 !important;
  }
  nav .flex {
    display: grid !important;
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
    gap: .25rem !important;
    width: 100% !important;
    overflow: visible !important;
  }
  .nav-pill {
    min-width: 0 !important;
    width: 100% !important;
    min-height: 3.35rem !important;
    aspect-ratio: 1 / 1 !important;
    padding: 0 !important;
    border-radius: 1.05rem !important;
    font-size: 0 !important;
    gap: 0 !important;
  }
  .nav-pill .nav-label {
    display: none !important;
    width: 0 !important;
    height: 0 !important;
    overflow: hidden !important;
  }
  .nav-pill i {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    font-size: 1.55rem !important;
    line-height: 1 !important;
  }
  main.app-shell {
    padding-bottom: calc(6.4rem + env(safe-area-inset-bottom)) !important;
    overflow-x: hidden !important;
  }
  #profileView,
  #profileView .panel,
  #profileView aside,
  #profileView section,
  #profileView div {
    max-width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
  }
  #profileView > .grid,
  #profileView .grid {
    grid-template-columns: minmax(0, 1fr) !important;
  }
  #profileView .sm\:grid-cols-\[minmax\(0\,1fr\)_auto\],
  #profileView .\32xl\:grid-cols-\[minmax\(0\,1fr\)_auto\] {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
  }
  #profileView .btn-primary,
  #profileView .btn-muted,
  #profileView .btn-danger,
  #profileView input,
  #profileView select,
  #profileView textarea {
    width: 100% !important;
    min-width: 0 !important;
  }
  #syncDebugLog {
    max-width: 100% !important;
    overflow-x: auto !important;
    white-space: pre-wrap !important;
    overflow-wrap: anywhere !important;
  }
}

/* v1.9: hard mobile app navigation and profile overflow fix */
@media (max-width: 767px) {
  html, body { width: 100%; max-width: 100%; overflow-x: hidden !important; }
  body.mobile-nav-icon-only .nav-pill .nav-label,
  body.mobile-nav-icon-only nav [data-route-link] span,
  nav .nav-pill .nav-label {
    display: none !important;
    visibility: hidden !important;
    width: 0 !important;
    height: 0 !important;
    max-width: 0 !important;
    max-height: 0 !important;
    overflow: hidden !important;
    pointer-events: none !important;
    font-size: 0 !important;
    line-height: 0 !important;
  }
  nav:not(.hidden) {
    position: fixed !important;
    display: block !important;
    left: .75rem !important;
    right: .75rem !important;
    bottom: calc(.75rem + env(safe-area-inset-bottom)) !important;
    top: auto !important;
    z-index: 999 !important;
    width: auto !important;
    max-width: none !important;
    transform: none !important;
  }
  nav .app-shell { width: 100% !important; max-width: none !important; padding: 0 !important; }
  nav .flex {
    display: grid !important;
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
    width: 100% !important;
    gap: .3rem !important;
    overflow: visible !important;
  }
  nav .nav-pill {
    width: 100% !important;
    min-width: 0 !important;
    min-height: 3.35rem !important;
    padding: 0 !important;
    aspect-ratio: 1 / 1 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-size: 0 !important;
    line-height: 0 !important;
  }
  nav .nav-pill i.ti,
  nav .nav-pill .ti {
    display: inline-flex !important;
    font-size: 1.62rem !important;
    line-height: 1 !important;
    margin: 0 !important;
  }
  #profileView { overflow-x: hidden !important; }
  #profileView .app-view,
  #profileView .panel,
  #profileView .grid,
  #profileView .flex,
  #profileView textarea,
  #profileView input,
  #profileView select,
  #profileView button { min-width: 0 !important; max-width: 100% !important; }
  #profileView .flex { flex-wrap: wrap; }
  main.app-shell { padding-bottom: calc(7rem + env(safe-area-inset-bottom)) !important; }
}


/* v1.10: slimmer mobile nav and mobile toast at top */
@media (max-width: 767px) {
  nav:not(.hidden) {
    left: .75rem !important;
    right: .75rem !important;
    bottom: calc(.45rem + env(safe-area-inset-bottom)) !important;
    padding: 0 !important;
  }
  nav .app-shell {
    padding: 0 !important;
  }
  nav .flex {
    gap: .25rem !important;
    padding: .28rem !important;
    border-radius: 1.25rem !important;
  }
  nav .nav-pill {
    min-height: 2.7rem !important;
    height: 2.7rem !important;
    aspect-ratio: auto !important;
    padding: 0 !important;
    border-radius: 1rem !important;
  }
  nav .nav-pill i.ti,
  nav .nav-pill .ti,
  nav .nav-pill i {
    font-size: 1.32rem !important;
    line-height: 1 !important;
  }
  main.app-shell {
    padding-bottom: calc(4.85rem + env(safe-area-inset-bottom)) !important;
  }
  #toast {
    top: calc(.85rem + env(safe-area-inset-top)) !important;
    bottom: auto !important;
    left: 1rem !important;
    right: 1rem !important;
    transform: none !important;
    width: auto !important;
    max-width: none !important;
    border-radius: 1.1rem !important;
    padding: .85rem 1rem !important;
    text-align: center !important;
    z-index: 130 !important;
  }
}

/* v1.12 mobile overlays above bottom navigation */
@media (max-width: 767px) {
  body.recipe-panel-open #recipeDetail,
  #recipeDetail {
    z-index: 320 !important;
  }
  body.recipe-panel-open #recipeDetail .recipe-detail-hero,
  body.recipe-panel-open #recipeDetail .cook-mode-detail .recipe-detail-hero {
    z-index: 330 !important;
  }
  body.selected-day-open::before {
    z-index: 300 !important;
  }
  body.selected-day-open #selectedDayPanel,
  #selectedDayPanel {
    z-index: 320 !important;
  }
  .panel-close-x,
  .mobile-panel-close,
  .selected-day-close {
    z-index: 340 !important;
  }
  body.recipe-panel-open nav,
  body.selected-day-open nav {
    pointer-events: none;
  }
}


/* v1.13 overlay and QR invite refinements */
.qr-invite-card img {
  display: block;
  width: min(100%, 260px);
  height: auto;
  margin: .75rem auto 0;
  border-radius: 1.35rem;
  background: white;
  padding: .65rem;
  box-shadow: 0 18px 50px rgba(15,23,42,.10);
}
@media (max-width: 767px) {
  body.recipe-panel-open #recipeDetail,
  body.recipe-panel-open.selected-day-open #recipeDetail {
    z-index: 760 !important;
  }
  body.recipe-panel-open #recipeDetail .mobile-panel-close,
  body.recipe-panel-open #recipeDetail .panel-close-x {
    z-index: 780 !important;
  }
  body.recipe-panel-open.selected-day-open #selectedDayPanel {
    z-index: 320 !important;
    pointer-events: none;
  }
  body.recipe-panel-open.selected-day-open::before {
    z-index: 300 !important;
  }
}


/* v1.16 persistent login */
#profileInstallCard .btn-primary[disabled] { transform: none !important; box-shadow: none !important; }
@media (max-width: 767px) {
  #profileInstallCard { display: block; }
}

/* v1.18: personal recipe versions and public recipe sharing */
#publicRecipeView {
  min-height: 100vh;
}
#publicRecipeView .panel {
  background: rgba(255,255,255,.94);
}
.recipe-preview-detail textarea.input {
  min-height: 80px;
}
@media (max-width: 767px) {
  .recipe-preview-detail .section-title,
  .cook-mode-detail .section-title {
    display: flex;
    align-items: center;
    gap: .4rem;
  }
}

/* v1.19 personal recipe controls */
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 999px;
  border: 1px solid rgba(15, 23, 42, 0.1);
  background: #ffffff;
  color: #0f172a;
  font-weight: 900;
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.08);
}
.btn-icon:active { transform: translateY(1px) scale(0.98); }

/* v1.21 recipe config collapsed by default */
.recipe-config-card summary::-webkit-details-marker { display: none; }
.recipe-config-card .btn-primary,
.recipe-config-card .btn-muted { white-space: normal; }
@media (max-width: 767px) {
  .recipe-config-card { margin-left: -0.125rem; margin-right: -0.125rem; }
}


.rating-stars { display: inline-flex; gap: 0.06rem; color: #cbd5e1; letter-spacing: -0.02em; line-height: 1; }
.rating-stars .filled { color: #f59e0b; }
.rating-button { display: inline-flex; align-items: center; justify-content: center; width: 2rem; height: 2rem; border-radius: 999px; border: 1px solid #e2e8f0; background: #fff; color: #cbd5e1; font-size: 1.25rem; line-height: 1; transition: transform .12s ease, background .12s ease, color .12s ease, border-color .12s ease; }
.rating-button:hover { transform: translateY(-1px); border-color: #f59e0b; color: #f59e0b; }
.rating-button.active { background: #fffbeb; border-color: #fbbf24; color: #f59e0b; }

/* v1.27: recipe share sheet */
.share-sheet-overlay {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 1rem;
  background: rgba(15, 23, 42, .42);
  backdrop-filter: blur(8px);
}
.share-sheet-panel {
  width: min(100%, 520px);
  border: 1px solid rgba(255,255,255,.75);
  border-radius: 1.7rem;
  background: rgba(255,255,255,.98);
  box-shadow: 0 24px 80px rgba(15,23,42,.24);
  padding: 1rem;
}
.share-option {
  display: grid;
  place-items: center;
  gap: .35rem;
  border-radius: 1.2rem;
  border: 1px solid rgba(15,23,42,.08);
  background: #f8fafc;
  padding: .85rem .45rem;
  text-align: center;
  font-size: .72rem;
  font-weight: 900;
  color: #172033;
}
.share-option i { font-size: 1.45rem; color: #0f766e; }
.share-option:active { transform: scale(.98); }
@media (min-width: 768px) {
  .share-sheet-overlay { align-items: center; }
}

/* v1.29 polish */
.field-label {
  display:block;
  font-size:.72rem;
  font-weight:900;
  letter-spacing:.14em;
  text-transform:uppercase;
  color:#64748b;
  margin-bottom:.35rem;
}
.selected-day-meal-rail {
  display:grid;
  gap:.75rem;
}
@media (max-width: 767px) {
  .selected-day-meal-rail {
    display:flex;
    overflow-x:auto;
    gap:.75rem;
    padding-bottom:.35rem;
    scroll-snap-type:x mandatory;
    -webkit-overflow-scrolling: touch;
  }
  .selected-day-meal-card {
    min-width: 82%;
    max-width: 82%;
    scroll-snap-align:start;
  }
}
.cook-mode-detail #wakeLockStatus,
.cook-mode-detail .serve-adjuster,
.cook-mode-detail [data-temp-serves] {
  display:none !important;
}
.route-myrecipes .app-shell { max-width: 1800px; }


/* v1.30: mobile bottom navigation fixed to one compact row for five sections */
@media (max-width: 767px) {
  nav:not(.hidden) {
    position: fixed !important;
    top: auto !important;
    left: .65rem !important;
    right: .65rem !important;
    bottom: calc(.45rem + env(safe-area-inset-bottom)) !important;
    z-index: 120 !important;
    width: auto !important;
    max-width: none !important;
    padding: 0 !important;
    border: 0 !important;
    background: transparent !important;
    backdrop-filter: none !important;
    pointer-events: none !important;
  }
  nav .app-shell {
    width: 100% !important;
    max-width: none !important;
    padding: 0 !important;
    pointer-events: auto !important;
  }
  nav .flex {
    display: grid !important;
    grid-template-columns: repeat(5, minmax(0, 1fr)) !important;
    grid-auto-flow: column !important;
    grid-auto-columns: minmax(0, 1fr) !important;
    align-items: center !important;
    gap: .18rem !important;
    width: 100% !important;
    max-width: 100% !important;
    min-height: 3.05rem !important;
    height: 3.05rem !important;
    padding: .24rem !important;
    overflow: hidden !important;
    border: 1px solid rgba(226, 232, 240, .92) !important;
    border-radius: 1.25rem !important;
    background: rgba(255,255,255,.96) !important;
    box-shadow: 0 14px 36px rgba(15, 23, 42, .18) !important;
    backdrop-filter: blur(14px) !important;
    pointer-events: auto !important;
  }
  nav .nav-pill,
  nav a.nav-pill,
  nav [data-route-link] {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: none !important;
    height: 2.45rem !important;
    min-height: 2.45rem !important;
    aspect-ratio: auto !important;
    padding: 0 !important;
    margin: 0 !important;
    border-radius: .95rem !important;
    font-size: 0 !important;
    line-height: 0 !important;
    gap: 0 !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    transform: none !important;
  }
  nav .nav-pill.active {
    box-shadow: 0 10px 22px rgba(15, 118, 110, .20) !important;
  }
  nav .nav-pill .nav-label,
  nav .nav-pill span,
  nav [data-route-link] span {
    display: none !important;
    visibility: hidden !important;
    width: 0 !important;
    height: 0 !important;
    max-width: 0 !important;
    max-height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    font-size: 0 !important;
    line-height: 0 !important;
    pointer-events: none !important;
  }
  nav .nav-pill i,
  nav .nav-pill i.ti,
  nav .nav-pill .ti {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-size: 1.26rem !important;
    line-height: 1 !important;
    margin: 0 !important;
  }
  main.app-shell {
    padding-bottom: calc(4.55rem + env(safe-area-inset-bottom)) !important;
  }
}
