: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; }

.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; }
.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; }
.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 .check-copy { color: #64748b; text-decoration: line-through; }

.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(3, 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-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; }

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