:root{
  --bg:#f9fafb; --card:#fff; --text:#0f172a; --muted:#475569;
  --border:#e5e7eb; --accent:#16a34a; --danger:#dc2626; --radius:14px;
}

*{box-sizing:border-box}
html,body{height:100%}
body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial;
  background: url("images/cutting-board-thyme.jpg") no-repeat center center fixed;
  background-size: cover;
  color: #0f172a;
}

.container{max-width:1280px; margin:2rem auto; padding:0 1rem;}
.topbar h1{margin:0 0 .5rem;}
.week-controls{
  display:flex; gap:.5rem; align-items:center; flex-wrap:wrap;
  margin:.5rem 0 0;
}
.weekpicker{display:inline-flex; align-items:center; gap:.5rem; padding:.25rem .75rem; border:1px solid var(--border); border-radius:999px; background:#fff;}
.weekpicker input{border:0; outline:none; font:inherit; background:transparent;}
.week-controls button{border:1px solid var(--border); background:#fff; padding:.4rem .7rem; border-radius:999px; cursor:pointer}
.week-controls .ghost{background:#fff}
.week-controls .danger{border-color:var(--danger); color:var(--danger)}
.week-controls #printBtn{border-color:var(--border); color:var(--muted)}
.week-controls #prevWeek, .week-controls #nextWeek{width:2.25rem}
.spacer{flex:1}
.hint{color:var(--muted); margin:.5rem 0 1rem; font-size:.95rem}

.planner,
.grocery {
  background: rgba(255, 255, 255, 0.65);   /* semi-transparent white */
  backdrop-filter: blur(8px);              /* frosted glass blur */
  -webkit-backdrop-filter: blur(8px);      /* Safari support */
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(0,0,0,0.15);
  overflow: visible; /* keep dropdowns visible */
}
.planner-table{width:100%; border-collapse:collapse}
.planner-table thead th{
  text-align:left; background:#fff; position:sticky; top:0; z-index:1;
  padding:.9rem .9rem; border-bottom:1px solid var(--border); color:var(--muted);
}
.planner-table tbody td, .planner-table tbody th{
  padding:.75rem .9rem; border-top:1px solid var(--border); vertical-align:top;
}
.planner-table tbody th{width:8.5rem; white-space:nowrap}

.meal-slot{display:grid; gap:.45rem}
.meal-select{
  width:100%; padding:.5rem .6rem; border:1px solid var(--border);
  border-radius:10px; background:#fff; font:inherit; color:var(--text);
}

.servings{
  display:inline-flex; align-items:center; gap:.45rem;
  padding:.25rem .6rem; border:1px solid var(--border); border-radius:999px;
  background:#fff; width:max-content;
}
.servings label{font-size:.85rem; color:var(--muted)}
.servings input{
  width:6ch; border:0; outline:none; background:transparent; font:inherit;
}
.servings small{color:var(--muted)}

.meal-meta{display:flex; gap:.5rem; align-items:center; font-size:.9rem; color:var(--muted)}
.meal-meta a{color:inherit; text-decoration:underline}
.tag{display:inline-block; font-size:.75rem; padding:.15rem .5rem; border:1px solid var(--border); border-radius:999px; color:var(--muted)}

/* === Per-day nutrition row (inserted under each day) === */
.nutri-row td{
  padding: .5rem .9rem .9rem;
  border-top: 0; /* sits under a main row which already has a border */
}
.nutri-line{
  display:flex; gap:.75rem; flex-wrap:wrap; align-items:center;
  font-size:.9rem; color:var(--muted);
}
.nutri-line .label{font-weight:600; color:var(--text); margin-right:.25rem}
.nutri-chip{
  display:inline-flex; align-items:center; gap:.35rem;
  padding:.2rem .55rem; border:1px solid var(--border); border-radius:999px;
  background:#fff; font-variant-numeric: tabular-nums;
}

/* Mobile stacking */
@media (max-width:900px){
  .planner-table thead{display:none}
  .planner-table, .planner-table tbody, .planner-table tr, .planner-table td, .planner-table th{display:block; width:100%}
  .planner-table tbody th{background:#fff; position:sticky; top:0; border-top:0; border-bottom:1px solid var(--border)}
  .planner-table tbody tr{padding-bottom:.25rem; border-bottom:1px solid var(--border)}
  .planner-table tbody td{border:0; padding:.6rem .9rem}
  .planner-table tbody td::before{
    content:attr(data-label); display:block; color:var(--muted); font-size:.8rem; margin-bottom:.25rem;
  }
  /* Don't prepend labels on the nutrition row */
  .nutri-row td::before{content:''; display:none}
  .nutri-line{padding-top:.25rem}
}

@media print{
  body{background:#fff}
  .container{margin:0; padding:0}
  .topbar .week-controls button, .hint{display:none}
  .planner{box-shadow:none; border:0}
}
.site-nav {
  max-width: 1100px; margin: 1rem auto; padding: 0 1rem;
  display: flex; justify-content: flex-end;
}
.site-nav .btn {
  display: inline-block; text-decoration: none;
  border: 1px solid #e5e7eb; border-radius: 999px; padding: .5rem .9rem;
  background: #fff; color: #0f172a; font: inherit;
}
.site-nav .btn:hover { background: #f3f4f6; }
.page-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
}

.planner-title {
  font-size: 2rem;
  font-weight: bold;
  margin: 0;
}

.menu-nav {
  position: relative;
}

#menuBtn {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: .4rem .6rem;
  cursor: pointer;
  display: flex;
  align-items: center;
}

#menuPanel {
  display: none;
  position: absolute;
  top: 2.8rem; /* just below the button */
  left: 0;     /* aligns panel with button, which is right above W */
  min-width: 180px;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  box-shadow: 0 10px 28px rgba(0,0,0,.08);
}

#menuPanel a {
  display: block;
  padding: .7rem .9rem;
  text-decoration: none;
  color: #0f172a;
  border-bottom: 1px solid #f1f5f9;
}

#menuPanel a:last-child {
  border-bottom: none;
}
/* Daily view style */
.planner-table.daily tbody tr {
  display: none;
}
.planner-table.daily tbody tr[data-day="today"] {
  display: table-row;
}
/* Highlight today's rows (main + nutrition) */
.planner-table [data-day="today"] > th,
.planner-table [data-day="today"] > td {
  background: #fffceb; /* pale highlight */
}
/* Daily view style */
.planner-table.daily tbody tr {
  display: none;
}
.planner-table.daily tbody tr[data-day="today"] {
  display: table-row;
}
/* Highlight today's rows */
.planner-table [data-day="today"] > th,
.planner-table [data-day="today"] > td {
  background: #fffceb;
}
/* Weekpicker layout */
.weekpicker {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
}
/* Constant-size, no-year date display (clickable) */
/* Hide the native date input but keep it accessible to scripts */
.visually-hidden-date {
  position: absolute !important;
  opacity: 0 !important;
  width: 0 !important;
  height: 0 !important;
  pointer-events: none !important;
}
/* Weekpicker layout */
.weekpicker {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
}

/* Constant-size "date box" with icon + text INSIDE */
.date-box {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  inline-size: 20ch;        /* fits "Wednesday 00/00" and "Week of 00/00" */
  min-inline-size: 20ch;
  max-inline-size: 20ch;
  flex: 0 0 20ch;           /* no grow/shrink */
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-variant-numeric: tabular-nums;
  padding: .4rem .6rem;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  white-space: nowrap;
}
.date-box:focus {
  outline: 2px solid #6366f1;
  outline-offset: 2px;
}
.date-box .cal-ic {
  width: 1rem;
  height: 1rem;
  opacity: .75;
  flex: 0 0 auto;
}
.date-box #dateText {
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Hide the native date input but keep it accessible to scripts */
.visually-hidden-date {
  position: absolute !important;
  opacity: 0 !important;
  width: 0 !important;
  height: 0 !important;
  pointer-events: none !important;
}
/* ---------- Date box sizing & layout overrides ---------- */

/* Weekpicker container */
.weekpicker {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
}

/* Constant-size button with icon + text INSIDE */
.date-box {
  box-sizing: border-box;         /* include padding & border in width */
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  inline-size: 24ch;              /* fits "Wednesday 00/00" plus icon */
  min-inline-size: 24ch;
  max-inline-size: 24ch;
  flex: 0 0 24ch;                 /* don't grow or shrink */
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-variant-numeric: tabular-nums;
  padding: .45rem .65rem;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  white-space: nowrap;
}
.date-box:focus-visible {
  outline: 2px solid #6366f1;
  outline-offset: 2px;
}

.date-box .cal-ic {
  width: 1rem;
  height: 1rem;
  opacity: .75;
  flex: 0 0 auto;
}

#dateText {
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Keep the native date input present for scripts, but invisible to users */
.visually-hidden-date {
  position: absolute !important;
  opacity: 0 !important;
  width: 0 !important;
  height: 0 !important;
  pointer-events: none !important;
}
/* ---------- MOBILE LAYOUT TWEAKS (keep arrows + date on one line) ---------- */

/* Let controls wrap so we can push Print/Clear below on small screens */
@media (max-width: 480px) {
  .week-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .35rem; /* tighter spacing on mobile */
  }

  /* Keep Prev [ ◀ ]  [DATE BOX]  [ ▶ ] on the first line */
  .week-controls > #prevWeek,
  .week-controls > .weekpicker,
  .week-controls > #nextWeek {
    order: 1;
  }

  /* Force everything after the spacer (Print / Clear) to the next line */
  .week-controls > .spacer {
    order: 2;
    flex-basis: 100%;
    height: 0; /* no visual space; just a wrap point */
  }

  .week-controls > #printBtn,
  .week-controls > #clearBtn {
    order: 3;
  }

  /* Date box: smaller font, padding, and icon so arrows + box fit on one line */
  .date-box {
    font-size: 0.92rem;       /* down from 1rem */
    padding: .35rem .55rem;   /* slightly tighter */
    gap: .4rem;
    inline-size: 22ch;        /* shrinks with font-size (ch units) */
    min-inline-size: 22ch;
    max-inline-size: 22ch;
  }

  .date-box .cal-ic {
    width: 1em;
    height: 1em;
  }
}

/* Ultra-small screens: shrink a bit more */
@media (max-width: 360px) {
  .date-box {
    font-size: 0.85rem;
    inline-size: 20ch;
    min-inline-size: 20ch;
    max-inline-size: 20ch;
  }
}
/* ===== Macro pie row layout ===== */
.nutri-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.nutri-side {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
}

.nutri-side.actual {
  justify-content: flex-start;
}

.nutri-side.goal {
  justify-content: flex-end;
}

.nutri-side .label {
  font-weight: 600;
  color: #475569; /* slate-600 */
}

.nutri-side .kcal {
  font-weight: 700;
  color: #0f172a; /* slate-900 */
}

.nutri-row canvas {
  width: 56px;
  height: 56px;
  display: inline-block;
}
.nutri-line { display:flex; justify-content:space-between; align-items:center; gap:1rem; }
.nutri-side { display:inline-flex; align-items:center; gap:.5rem; }
.nutri-side.actual { justify-content:flex-start; }
.nutri-side.goal { justify-content:flex-end; }
.nutri-side .label { font-weight:600; color:#475569; }
.nutri-side .kcal { font-weight:700; color:#0f172a; }
.nutri-row canvas { width:56px; height:56px; display:inline-block; }

.meal-meta .tag.warn { color:#b91c1c; border:1px solid #fecaca; background:#fee2e2; padding:.1rem .35rem; border-radius:.4rem; font-weight:600; }
/* Hamburger menu */
.menu-nav { position: relative; }
#menuPanel {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + .5rem);
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  box-shadow: 0 12px 24px rgba(0,0,0,.12);
  min-width: 220px;
  max-height: 70vh;         /* show all items with scroll if needed */
  overflow: auto;
  z-index: 1000;
  padding: .25rem 0;
}
#menuPanel a {
  display: block;
  padding: .6rem .9rem;
  text-decoration: none;
  color: #0f172a;
  white-space: nowrap;
}
#menuPanel a:hover { background: #f1f5f9; }
/* Dynamic column scaling by meal count */
.planner-table[class*="cols-n"] .meal-slot { gap: .45rem; }
.planner-table.cols-n5 .add-meal,
.planner-table.cols-n5 .servings input { font-size: .95rem; padding: .35rem .5rem; }
.planner-table.cols-n6 .add-meal,
.planner-table.cols-n6 .servings input { font-size: .9rem;  padding: .32rem .45rem; }
.planner-table.cols-n7 .add-meal,
.planner-table.cols-n7 .servings input { font-size: .86rem; padding: .3rem  .4rem; }

/* Keep “Servings” compact */
.servings label { display: inline-flex; align-items: center; gap: .45rem; }
.servings input {
  width: 5.5rem;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: .38rem .55rem;
  font: inherit;
  background: #fff;
}

/* Row action area (Add + Auto) aligns with inputs */
.row-actions { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }

/* Auto buttons match the button style but smaller */
.btn.auto, .btn.auto-mini {
  padding: .38rem .55rem;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #fff;
}
.btn.auto-mini { font-size: .85rem; }

/* Keep chosen line tight (link + Change only) */
.meal-meta { display: flex; align-items: center; gap: .5rem; }
.meal-meta .change-meal { color:#0ea5e9; }

/* The Add Meal visual (in case JS-injected style is overridden) */
.add-meal{
  display:inline-flex; align-items:center; gap:.45rem;
  padding:.38rem .55rem; border:1px solid #e5e7eb; border-radius:8px;
  background:#fff; cursor:pointer; font:inherit;
}
.add-meal .plus{ color:#ef4444; font-weight:900; font-size:1.05rem; line-height:1; }

/* Optional: keep header meal labels centered and tidy */
.planner-table thead th.meal-col { text-align: center; white-space: nowrap; }
/* Transposed layout tweaks */
.planner-table thead th.meal-col-left { text-align:left; white-space:nowrap; }
.planner-table .meal-label { font-weight:600; white-space:nowrap; }
.totals-row .meal-label { text-align:right; color:#475569; }

/* Keep action row compact inside tighter cells */
.row-actions { display:flex; align-items:center; gap:.4rem; flex-wrap:wrap; }

/* Reuse existing .add-meal / .servings styles from earlier file */
/* Fit 7-day week view inside frosted section */
.planner-table { table-layout: fixed; width: 100%; }
.planner-table.compact th,
.planner-table.compact td { padding: 6px; vertical-align: top; }

.planner-table.compact .meal-slot { gap: .35rem; }
.planner-table.compact .add-meal { padding: .28rem .42rem; font-size: .85rem; }
.planner-table.compact .add-meal .plus { font-size: .95rem; }
.planner-table.compact .btn.auto-mini { padding: .28rem .42rem; font-size: .8rem; }

.planner-table.compact .servings input {
  width: 4.5rem;
  padding: .28rem .42rem;
  font-size: .85rem;
}

/* Shrink totals pies + labels for compact */
.planner-table.compact .nutri-line { display:flex; align-items:center; justify-content:space-between; gap:.35rem; }
.planner-table.compact .nutri-line .label { font-size:.75rem; color:#475569; }
.planner-table.compact .nutri-line .kcal { font-size:.8rem; }
/* --- Change button below recipe link, match standard button look --- */
.meal-slot .meal-meta .change-meal.btn {
  display: inline-flex;
  margin-top: .35rem;
  padding: .38rem .55rem;
  font-size: .85rem;
  border: 1px solid #e5e7eb;
  background: #fff;
  border-radius: 8px;
}

/* --- Compact servings input sized for 0.00 with arrows --- */
.meal-slot .servings {
  display: flex;
  align-items: center;
  gap: .45rem;
}
.meal-slot .servings-label {
  font-size: .85rem;
  color: #475569;
}
.meal-slot .servings-input {
  width: 4.2rem;                  /* fits 0.00 + steppers */
  padding: .32rem .42rem;
  font-size: .9rem;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #fff;
}

/* In compact (7-day) view, nudge a bit smaller */
.planner-table.compact .servings-input {
  width: 3.9rem;
  font-size: .85rem;
  padding: .28rem .38rem;
}
/* Stack the recipe link over the Change button */
.meal-slot .meal-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: .25rem;
}
.meal-slot .meal-meta .recipe-line { width: 100%; }
.meal-slot .meal-meta .change-meal.btn {
  align-self: flex-start;
  display: inline-flex;
  margin-top: .25rem;
  padding: .38rem .55rem;
  font-size: .85rem;
  border: 1px solid #e5e7eb;
  background: #fff;
  border-radius: 8px;
}

/* Narrower servings input (still fits 1.25 with arrows) */
.meal-slot .servings-input {
  width: 3.5rem;          /* was ~4.2rem */
  padding: .30rem .38rem;
  font-size: .9rem;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #fff;
}

/* In compact (7-day) view, nudge smaller */
.planner-table.compact .servings-input {
  width: 3.2rem;
  font-size: .85rem;
  padding: .26rem .34rem;
}
/* Stack link/button and Change neatly */
.meal-slot .meal-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: .25rem;
}

/* Recipe button with thumbnail */
.recipe-btn {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  padding: .42rem .6rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
}
.recipe-thumb {
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
}
.recipe-title {
  font-weight: 600;
  color: var(--text);
}

/* Change button – consistent look */
.meal-slot .meal-meta .change-meal.btn {
  align-self: flex-start;
  display: inline-flex;
  margin-top: .15rem;
  padding: .38rem .55rem;
  font-size: .85rem;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 8px;
}

/* Servings compact (already injected in JS, but keep here too if desired) */
.meal-slot .servings-input {
  width: 3.5rem;
}
.planner-table.compact .servings-input {
  width: 3.2rem;
}
