/* ---------- Tokens */
:root {
  --page: #EEF1EC; --card: #FFFFFF; --tile: #F8FAF6; --line: #DFE5DB;
  --text: #222820; --text-2: #5E665D; --text-3: #676F66;
  --accent: #4F7A55; --accent-ink: #365C3C; --accent-soft: #E3EDE2; --danger: #B3452F;
  --shadow: 0 8px 24px rgb(0 0 0 / .12);
  --on-accent: #FFFFFF;
  --ease: 140ms ease-out;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --page: #141714; --card: #1C201C; --tile: #232823; --line: #313831;
    --text: #E6EAE4; --text-2: #A9B1A7; --text-3: #858D83;
    --accent: #7FAE86; --accent-ink: #A6CFAB; --accent-soft: #26352A; --danger: #E0806C;
    --shadow: 0 8px 24px rgb(0 0 0 / .5);
    --on-accent: #141714;
  }
}

/* ---------- Base */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; min-height: 100vh; background: var(--page); color: var(--text);
       font: 400 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, sans-serif;
       -webkit-font-smoothing: antialiased; }
h1, h2, h3 { font-weight: 600; line-height: 1.3; }
h1 { font-size: 20px; margin: 0 0 16px; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; }
p { margin: 0 0 12px; }
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
code { font: 13px ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--tile);
       border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
main { max-width: 1400px; margin: 0 auto; padding: 24px; }
.icon { width: 16px; height: 16px; flex: none; vertical-align: -3px; }
@media (max-width: 759px) { main { padding: 16px; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0s !important; animation-duration: 0s !important; }
}

/* ---------- Top bar */
.topbar { position: sticky; top: 0; z-index: 30; background: var(--page); border-bottom: 1px solid var(--line); }
.topbar-in { max-width: 1400px; height: 56px; margin: 0 auto; padding: 0 24px; display: flex;
             align-items: center; gap: 24px; }
.wordmark { display: inline-flex; align-items: center; gap: 8px; color: var(--text); font-size: 16px;
            font-weight: 600; letter-spacing: -.01em; }
a.wordmark:hover { text-decoration: none; }
.mark { width: 20px; height: 20px; flex: none; }
.mark-leaf { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 1.5; stroke-linejoin: round; }
.mark-rib { fill: none; stroke: var(--accent); stroke-width: 1.5; stroke-linecap: round; }
.topnav { display: flex; align-items: center; gap: 4px; }
.topnav a { color: var(--text-2); padding: 6px 8px; border-radius: 8px; transition: color var(--ease); }
.topnav a:hover { color: var(--text); text-decoration: none; }
.topnav a[aria-current=page] { color: var(--accent-ink); font-weight: 600; }
.topbar-slot { flex: 1; min-width: 0; display: flex; align-items: center; justify-content: center; }
.topbar .icon-btn[aria-current=page] { color: var(--accent-ink); }
@media (max-width: 759px) {
  /* It may wrap (the plan's "Desktop view" puts the week switcher on a row of its own). */
  .topbar-in { flex-wrap: wrap; height: auto; min-height: 56px; padding: 12px 16px; gap: 8px 12px; }
  .topnav a { padding: 6px; }
}

/* ---------- Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 32px;
       padding: 0 12px; border: 1px solid var(--line); border-radius: 8px; background: transparent;
       color: var(--text); font: inherit; font-weight: 600; white-space: nowrap; cursor: pointer;
       text-decoration: none;
       transition: background-color var(--ease), border-color var(--ease), color var(--ease); }
.btn:hover { background: var(--tile); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-ink); border-color: var(--accent-ink); }
.btn-ghost { border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--tile); color: var(--text); }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; flex: none; width: 32px;
            height: 32px; padding: 0; border: 0; border-radius: 8px; background: transparent;
            color: var(--text-2); font: inherit; cursor: pointer;
            transition: background-color var(--ease), color var(--ease); }
.icon-btn:hover { background: var(--tile); color: var(--text); }
.btn:disabled, .icon-btn:disabled { opacity: .5; cursor: default; }

/* ---------- Cards */
.card { background: var(--card); border-radius: 12px; padding: 16px; }

/* ---------- Tiles and chips */
.tile { background: var(--tile); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px;
        transition: border-color var(--ease), background-color var(--ease); }
.chip { display: inline-flex; align-items: center; gap: 4px; max-width: 100%; padding: 2px 8px;
        border-radius: 999px; background: var(--accent-soft); color: var(--accent-ink); font-size: 12px;
        font-weight: 600; }

/* ---------- Popover */
.popover { position: absolute; z-index: 40; min-width: 220px; padding: 6px; background: var(--card);
           border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }

/* ---------- Toast */
#toasts { position: fixed; left: 50%; bottom: 24px; z-index: 100; display: flex; flex-direction: column;
          align-items: center; gap: 8px; width: max-content; max-width: calc(100% - 32px);
          transform: translateX(-50%); pointer-events: none; }
.toast { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-radius: 8px;
         background: var(--text); color: var(--page); box-shadow: var(--shadow); pointer-events: auto; }
.toast button { padding: 0; border: 0; background: none; color: var(--accent-soft); font: inherit;
                font-weight: 600; cursor: pointer; }

/* ---------- Forms */
.label { display: block; margin: 0 0 6px; color: var(--text-2); font-size: 12px; font-weight: 600; }
.field { display: block; width: 100%; height: 36px; padding: 0 10px; border: 1px solid var(--line);
         border-radius: 8px; background: var(--card); color: var(--text); font: inherit;
         transition: border-color var(--ease); }
.field::placeholder { color: var(--text-3); }
.field:hover { border-color: var(--text-3); }
.field:focus-visible { border-color: var(--accent); outline: 2px solid var(--accent); outline-offset: 2px; }
input[type=checkbox], input[type=radio], input[type=time], input[type=date] { accent-color: var(--accent); }
textarea.field { height: auto; min-height: 80px; padding: 8px 10px; resize: vertical; }
/* 16px stops iOS zooming in on focus. */
@media (max-width: 759px) { .field { font-size: 16px; } }

/* ---------- Utilities */
.muted { color: var(--text-2); }
.error { color: var(--danger); font-weight: 600; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden;
           clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ---------- Sign-in */
.signin-page .topbar { display: none; }
.signin-page main { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.signin-card { width: 100%; max-width: 360px; padding: 32px 28px 28px; }
.signin-card .wordmark { display: flex; justify-content: center; margin: 0 0 24px; font-size: 20px; }
.signin-card .wordmark .mark { width: 24px; height: 24px; }
.signin-card .btn-primary { width: 100%; height: 36px; margin-top: 16px; }
.signin-card .error, .signin-card p { margin: 0 0 16px; }
/* ---------- Plan page */
/* Phones get the agenda; wider screens the week of day cards (or always, with body.force-desktop). */
.desktop { display: none; }
.agenda { display: block; }
@media (min-width: 760px) {
  .desktop { display: block; }
  .plan-page .agenda { display: none; }
}
body.force-desktop .desktop { display: block; }
body.force-desktop .agenda { display: none; }
@media (max-width: 759px) {
  .plan-page:not(.force-desktop) .week-switcher { display: none; }
  body.force-desktop .weeks { overflow-x: auto; }
  body.force-desktop .week-row { min-width: 900px; }
  /* "Desktop view" on a phone: the week switcher gets its own row under the wordmark and nav. */
  body.force-desktop .topbar-slot { order: 1; flex: 1 0 100%; }
  body.force-desktop .topbar-in > .icon-btn { margin-left: auto; }
}

/* Week switcher, in the top bar. */
.week-switcher { position: relative; display: flex; align-items: center; gap: 2px; }
/* The calendar button's native date input, in a small popover under the switcher. */
#jump-form { position: absolute; top: calc(100% + 6px); right: 0; z-index: 40; padding: 8px;
             background: var(--card); border: 1px solid var(--line); border-radius: 12px;
             box-shadow: var(--shadow); }
#jump-form input { height: 32px; padding: 0 8px; border: 1px solid var(--line); border-radius: 8px;
                   background: var(--card); color: var(--text); font: inherit; }
.week-label { min-width: 150px; padding: 0 4px; text-align: center; font-weight: 600;
              font-variant-numeric: tabular-nums; white-space: nowrap; }
.chip-link { margin: 0 4px 0 8px; padding: 3px 10px; border-radius: 999px; background: var(--accent-soft);
             color: var(--accent-ink); font-size: 12px; font-weight: 600; white-space: nowrap; }
.chip-link:hover { text-decoration: none; color: var(--text); }

/* Weeks: seven day cards and, on the first week, the queue card. */
.week { margin: 0 0 28px; }
.week-range { margin: 0 0 10px; color: var(--text-2); font-size: 12px; font-weight: 600; }
/* Both hints are always in the markup and follow the content, so they can't go stale: the week's shows while
   none of its day cards holds a tile, place or task; the queue's while #queue has no items (it renders
   truly empty then). */
.week-empty { display: none; margin: -4px 0 10px; color: var(--text-3); font-size: 13px; }
.week:not(:has(.day .tile, .day .place-chip, .day .task-chip)) .week-empty { display: block; }
.week-row { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)) 150px; gap: 10px;
            align-items: start; }
@media (max-width: 1099px) {
  .week-row { grid-template-columns: repeat(7, minmax(0, 1fr)); }
  .queue-card { grid-column: 1 / -1; }
}

/* Day card. */
.day { display: flex; flex-direction: column; gap: 8px; min-width: 0; padding: 12px; border-radius: 12px;
       background: var(--card); }
.day.today { box-shadow: inset 0 0 0 1.5px var(--accent); }
.day-head { position: relative; display: flex; align-items: center; justify-content: space-between;
            gap: 4px; min-height: 24px; }
.day-title { margin: 0; font-size: 16px; white-space: nowrap; }
.day.today .day-title { color: var(--accent-ink); }
.day-note { margin-top: -6px; color: var(--text-2); font-size: 12px; line-height: 1.4; white-space: pre-wrap;
            overflow-wrap: break-word; cursor: text; }
.add-note { align-self: flex-start; padding: 0; border: 0; background: none; color: var(--text-3);
            font: inherit; font-size: 12px; line-height: 1.4; cursor: pointer; opacity: 0;
            transition: opacity var(--ease); }
.add-note:hover { color: var(--accent-ink); }

/* The day's "+" for a prep task, and its menu. */
.add-task, .tile-row-add { display: inline-flex; align-items: center; justify-content: center; flex: none;
                           width: 22px; height: 22px; padding: 0; border: 0; border-radius: 6px;
                           background: none; color: var(--text-3); cursor: pointer; opacity: 0;
                           transition: opacity var(--ease), background-color var(--ease), color var(--ease); }
.add-task:hover, .tile-row-add:hover { background: var(--tile); color: var(--accent-ink); }
.add-task .icon, .tile-row-add .icon { width: 14px; height: 14px; }
.task-menu { position: absolute; top: 100%; right: 0; z-index: 20; min-width: 150px; margin: 4px 0 0;
             padding: 4px; list-style: none; background: var(--card); border: 1px solid var(--line);
             border-radius: 12px; box-shadow: var(--shadow); }
.task-menu button { display: block; width: 100%; padding: 6px 10px; border: 0; border-radius: 8px;
                    background: none; color: var(--text); font: inherit; text-align: left; cursor: pointer; }
.task-menu button:hover { background: var(--tile); }

/* Slots: a small label, then tiles, a place chip and the entry note, or a dashed "+ Add". */
.slot { position: relative; display: flex; flex-direction: column; gap: 4px; border-radius: 8px; }
.day .slot-label { color: var(--text-3); font-size: 12px; line-height: 1.3; }
/* The slot's "+" sits on the label row; the first tile's ✕ (z-index 2) stays on top where they meet. */
.tile-row-add { position: absolute; top: -3px; right: 14px; z-index: 1; width: 20px; height: 20px; }
.slot-note { color: var(--text-2); font-size: 12px; line-height: 1.4; white-space: pre-wrap;
             overflow-wrap: break-word; }
.add-tile { display: block; width: 100%; padding: 5px 8px; border: 1px dashed var(--line); border-radius: 8px;
            background: none; color: var(--text-3); font: inherit; font-size: 13px; line-height: 1.35;
            text-align: left; cursor: pointer;
            transition: border-color var(--ease), color var(--ease), background-color var(--ease); }
.add-tile:hover { border-color: var(--accent); color: var(--accent-ink); }

/* Meal and queue tiles: the name wraps between words; ✕ floats on the corner on hover. */
.day .tile, .queue-card .tile { position: relative; display: flex; align-items: flex-start; gap: 6px;
                                padding: 6px 8px; font-size: 13px; line-height: 1.35; cursor: grab; }
.tile .meal-name { flex: 1; min-width: 0; color: var(--text); overflow-wrap: break-word; }
.tile-link { display: inline-flex; flex: none; margin-top: 1px; color: var(--text-3); }
.tile-link:hover { color: var(--accent-ink); }
.tile-link .icon { width: 14px; height: 14px; }
.note-dot { flex: none; width: 6px; height: 6px; margin: 6px 1px 0; border-radius: 50%;
            background: var(--accent); }
.place-chip { position: relative; display: flex; align-items: flex-start; gap: 6px; padding: 5px 8px;
              border-radius: 8px; background: var(--accent-soft); color: var(--accent-ink); font-size: 13px;
              line-height: 1.35; cursor: grab; }
.place-chip .icon { width: 14px; height: 14px; margin-top: 1px; }
.place-text { min-width: 0; overflow-wrap: break-word; }
.tile-x { position: absolute; top: -7px; right: -7px; z-index: 2; display: inline-flex; align-items: center;
          justify-content: center; width: 18px; height: 18px; padding: 0; border: 1px solid var(--line);
          border-radius: 50%; background: var(--card); color: var(--text-2); cursor: pointer; opacity: 0;
          pointer-events: none; transition: opacity var(--ease), color var(--ease); }
.tile-x .icon { width: 10px; height: 10px; }
.tile-x:hover { color: var(--danger); }

/* Task chips: small pills with a snowflake (Thaw) or a dot. */
.task-chip { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: start; gap: 0 6px;
             align-self: flex-start;
             max-width: 100%; padding: 2px 10px; border: 1px solid var(--line); border-radius: 11px;
             background: var(--tile); color: var(--text-2); font-size: 12px; line-height: 1.4; }
.task-chip > .icon { width: 12px; height: 12px; margin-top: 2px; color: var(--accent); }
.task-dot { flex: none; width: 6px; height: 6px; margin: 5px 2px 0; border-radius: 50%; background: var(--text-3); }
.task-text { min-width: 0; overflow-wrap: break-word; }
.task-chip .slot-note { grid-column: 2; }

/* Narrower windows: tighter cards, so long words keep to their lines. */
@media (max-width: 1299px) {
  .plan-page main { padding-left: 16px; padding-right: 16px; }
  .week-row { gap: 8px; }
  .day, .queue-card { padding: 10px; }
  .day .tile, .queue-card .tile, .place-chip { gap: 4px; padding: 5px 6px; }
}

/* Hover (or keyboard focus) reveals the tools; at rest the cards stay calm. */
.day:hover .add-task, .day:focus-within .add-task, .day:hover .add-note, .add-note:focus-visible,
.slot:hover .tile-row-add, .slot:focus-within .tile-row-add { opacity: 1; }
.tile:hover .tile-x, .place-chip:hover .tile-x, .slot:focus-within .tile-x, .tile:focus-within .tile-x {
  opacity: 1; pointer-events: auto; }

/* Queue card. */
.queue-card { display: flex; flex-direction: column; gap: 8px; min-width: 0; padding: 12px; border-radius: 12px;
              background: var(--card); }
.queue-card h3 { margin: 0; font-size: 16px; }
.queue-empty { display: none; margin: 0; color: var(--text-3); font-size: 13px; line-height: 1.4; }
#queue:empty + .queue-empty { display: block; }
#queue { display: flex; flex-direction: column; gap: 6px; margin: 0; padding: 0; list-style: none; }
@media (max-width: 1099px) {
  #queue { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
  .queue-card .add-tile { max-width: 160px; }
}


/* Editing: inline text (task, day note, entry note), drag and drop, copy, and a failed save's shake. */
.day [contenteditable] { outline: 2px solid var(--accent); outline-offset: 1px; border-radius: 4px;
                         cursor: text; }
.day [contenteditable]:empty::before { content: attr(data-placeholder); color: var(--text-3); }
.day .task-chip .task-text[contenteditable] { min-width: 6em; }
.dragging { box-shadow: var(--shadow); transform: scale(1.03); opacity: .9; cursor: grabbing; }
.copying { position: relative; }
.copying::after { content: "+"; position: absolute; top: -8px; left: -8px; display: flex; align-items: center;
                  justify-content: center; width: 18px; height: 18px; border-radius: 50%;
                  background: var(--accent); color: var(--on-accent); font-size: 13px; font-weight: 600;
                  line-height: 1; }
/* The target under the pointer: an --accent-soft fill with an accent ring, so it reads on light and dark. */
.slot.drop-ok, .day.drop-ok, .queue-card.drop-ok, #queue .tile.drop-ok {
  background: var(--accent-soft); box-shadow: 0 0 0 4px var(--accent-soft), 0 0 0 5.5px var(--accent);
  transition: background-color var(--ease), box-shadow var(--ease); }
.day.drop-ok, .queue-card.drop-ok { box-shadow: inset 0 0 0 1.5px var(--accent); }
.slot.copied { outline: 2px dashed var(--text-2); outline-offset: 2px; }
.shake { animation: shake 300ms ease-out; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-4px); }
  40%, 80% { transform: translateX(4px); }
}
/* ---------- Picker */
.picker { position: fixed; display: flex; flex-direction: column; width: 320px; max-width: calc(100vw - 16px);
          max-height: 360px; padding: 0; overflow: hidden; animation: picker-in var(--ease); }
@keyframes picker-in { from { opacity: 0; transform: translateY(-4px); } }
.picker-search { position: relative; flex: none; padding: 8px; border-bottom: 1px solid var(--line); }
.picker-search > .picker-icon { position: absolute; top: 50%; left: 18px; transform: translateY(-50%);
                                color: var(--text-3); pointer-events: none; }
.picker-search .field { padding-left: 32px; }
.picker-search .field:focus-visible { outline: none; border-color: var(--accent);
                                      box-shadow: 0 0 0 3px var(--accent-soft); }
.picker-list { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 4px; }
.picker-list:empty { display: none; }
.picker-group { padding: 8px 8px 4px; color: var(--text-3); font-size: 12px; font-weight: 600; }
.picker-row { display: flex; align-items: center; gap: 8px; min-height: 34px; padding: 6px 8px;
              border-radius: 8px; color: var(--text); font-size: 14px; cursor: pointer; }
.picker-row[aria-selected=true] { background: var(--accent-soft); }
.picker-row > .picker-icon { flex: none; display: inline-flex; color: var(--text-3); }
.picker-name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picker-hint { flex: none; color: var(--text-3); font-size: 12px; }
.picker-row[aria-selected=true] .picker-hint { color: var(--text-2); }
.picker-create { margin-top: 2px; color: var(--accent-ink); font-weight: 600; }
.picker-create > .picker-icon { color: var(--accent); }
.picker-status { margin: 0; padding: 10px 12px; color: var(--text-2); font-size: 13px; }
/* ---------- Meal drawer */
.drawer-scrim { position: fixed; inset: 0; z-index: 49; background: rgb(20 23 20 / .18);
                animation: scrim-in 160ms ease-out; }
@keyframes scrim-in { from { opacity: 0; } }
#drawer { position: fixed; top: 0; right: 0; bottom: 0; z-index: 50; width: 380px; max-width: 100%;
          overflow-y: auto; overscroll-behavior: contain; background: var(--card);
          border-left: 1px solid var(--line); box-shadow: var(--shadow); animation: drawer-in 160ms ease-out; }
#drawer:focus { outline: none; }
.popover.picker { z-index: 60; } /* "Merge into…" opens the picker from the sheet's menu */
@keyframes drawer-in { from { transform: translateX(100%); } }
@media (max-width: 519px) { #drawer { width: 100%; border-left: 0; } }
@media (prefers-color-scheme: dark) { .drawer-scrim { background: rgb(0 0 0 / .45); } }
#drawer > .error { margin: 20px; }

/* ---------- Meal panel */
.meal-panel { display: flex; flex-direction: column; min-height: 100%; padding: 16px 20px 12px;
              overflow-wrap: anywhere; }
.meal-panel > .error { margin: 0 0 12px; }
.panel-head { display: flex; align-items: flex-start; gap: 8px; }
.meal-title { flex: 1 1 auto; min-width: 0; margin: 0; font-size: 20px; line-height: 1.35; }
.read-only .meal-title { padding: 2px 0; }
.title-edit { display: block; margin-left: -6px; padding: 2px 6px; border-radius: 8px; cursor: text;
              outline: none; transition: background-color var(--ease), box-shadow var(--ease); }
.title-edit:hover { background: var(--tile); }
.title-edit:focus { background: var(--tile); box-shadow: 0 0 0 2px var(--accent); }
.archived-chip { flex: none; margin-top: 6px; background: var(--tile); color: var(--text-2);
                 border: 1px solid var(--line); }
.drawer-close { display: none; margin: 0 -8px 0 0; }
#drawer .drawer-close { display: inline-flex; }
.title-error { margin: 6px 0 0; font-size: 13px; }
.panel-section { margin-top: 24px; }
.panel-label { display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
               margin: 0 0 6px; color: var(--text-3); font-size: 12px; font-weight: 600; }
.panel-label label { display: inline; margin: 0; font-weight: inherit; }
.saved-hint { color: var(--text-3); font-weight: 400; }

/* Links: quiet rows; the grip and ✕ show on hover or focus (always on touch screens). */
.link-list { list-style: none; margin: 0 -8px; padding: 0; }
.link-list:empty { display: none; }
.link-list li { display: flex; align-items: center; gap: 2px; min-height: 36px; padding: 0 4px;
                border-radius: 8px; background: var(--card); transition: background-color var(--ease); }
.link-list li:hover, .link-list li:focus-within { background: var(--tile); }
.read-only .link-list li { padding: 0 8px; }
.link-list a, .link-label { flex: 1 1 auto; min-width: 0; padding: 6px 4px; overflow: hidden;
                            text-overflow: ellipsis; white-space: nowrap; }
.link-label { border-radius: 6px; color: var(--text); cursor: default; }
.link-list a.link-open { display: inline-flex; flex: none; align-items: center; justify-content: center;
                         width: 28px; height: 28px; padding: 0; border-radius: 6px; color: var(--accent-ink); }
.link-list a.link-open:hover { background: var(--accent-soft); }
.link-edit { flex: 1 1 auto; display: grid; gap: 4px; min-width: 0; padding: 4px 0; }
.link-edit .field { height: 30px; }
.link-edit .error { margin: 0; font-size: 13px; }
.link-list li.editing { align-items: flex-start; background: var(--tile); }
.link-list li.editing > .grip, .link-list li.editing > .link-open { margin-top: 5px; }
.link-list li.editing > .tile-x { margin-top: 7px; }
.link-list .grip { display: inline-flex; align-items: center; justify-content: center; flex: none; width: 20px;
                   height: 28px; padding: 0; border: 0; border-radius: 6px; background: none;
                   color: var(--text-3); cursor: grab; touch-action: none; opacity: 0;
                   transition: opacity var(--ease); }
.link-list .tile-x { position: static; flex: none; width: 24px; height: 24px; border: 0; background: none; }
.link-list .tile-x .icon { width: 12px; height: 12px; }
.link-list li:hover > .grip, .link-list li:focus-within > .grip { opacity: 1; }
.link-list li:hover > .tile-x, .link-list li:focus-within > .tile-x { opacity: 1; pointer-events: auto; }
@media (hover: none) {
  .link-list .grip, .link-list .tile-x { opacity: 1; pointer-events: auto; }
}
.link-list li.lifted { position: relative; z-index: 1; background: var(--card); box-shadow: var(--shadow);
                       cursor: grabbing; }
.add-link { display: inline-flex; align-items: center; gap: 6px; height: 32px; margin: 2px -8px 0;
            padding: 0 8px; border: 0; border-radius: 8px; background: none; color: var(--text-2); font: inherit;
            cursor: pointer; transition: background-color var(--ease), color var(--ease); }
.add-link:hover { background: var(--tile); color: var(--text); }
.link-form { display: grid; gap: 6px; margin: 6px 0 0; }
.link-form .error { margin: 0; font-size: 13px; }

/* Notes: borderless until you're in them. */
textarea.notes { display: block; width: calc(100% + 16px); min-height: 72px; margin: 0 -8px; padding: 6px 8px;
                 border: 1px solid transparent; border-radius: 8px; background: transparent; color: var(--text);
                 font: inherit; line-height: 1.5; resize: none; field-sizing: content;
                 transition: background-color var(--ease), border-color var(--ease); }
textarea.notes::placeholder { color: var(--text-3); }
textarea.notes:hover { background: var(--tile); }
textarea.notes:focus { outline: none; background: var(--tile); border-color: var(--accent); }
@media (max-width: 759px) { textarea.notes { font-size: 16px; } }
.meal-panel p.notes { margin: 0; white-space: pre-wrap; }

/* History. */
.history-line { margin: 0 0 8px; color: var(--text-2); }
.date-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; list-style: none; }
.date-chips .chip { border: 1px solid var(--line); background: var(--tile); color: var(--text-2);
                    font-weight: 400; }

/* The ⋯ menu opens upwards from the footer. */
.panel-foot { display: flex; margin-top: auto; padding-top: 24px; }
.more-wrap { position: relative; }
.menu { position: absolute; bottom: calc(100% + 4px); left: 0; z-index: 20; min-width: 180px; margin: 0;
        padding: 4px; list-style: none; background: var(--card); border: 1px solid var(--line);
        border-radius: 12px; box-shadow: var(--shadow); animation: picker-in var(--ease); }
.menu form { margin: 0; }
.menu button { display: block; width: 100%; height: auto; padding: 6px 10px; border: 0; border-radius: 8px;
               background: none; color: var(--text); font: inherit; text-align: left; cursor: pointer; }
.menu button:hover { background: var(--tile); }

/* The meal page and the share view: the panel in a card. */
.meal-detail { max-width: 560px; margin: 0 auto; border-radius: 12px; background: var(--card); }
.meal-detail .meal-panel { min-height: 0; padding: 24px; }
/* ---------- Library */
.library-section { max-width: 720px; margin: 0 auto; }
.library-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0 0 16px; }
.search-field { position: relative; flex: 1 1 220px; min-width: 0; }
.search-field .icon { position: absolute; left: 10px; top: 10px; color: var(--text-3); pointer-events: none; }
.search-field .field { padding-left: 32px; }
.library-bar select.field { width: auto; flex: none; }
.archived-toggle[aria-pressed=true] { background: var(--accent-soft); border-color: var(--accent);
                                      color: var(--accent-ink); }
.library-list { list-style: none; margin: 0; padding: 4px 0; background: var(--card); border-radius: 12px; }
.meal-row .archived-chip { margin-top: 0; }
.library-list li + li { border-top: 1px solid var(--line); }
.meal-row { display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 8px 16px;
            color: var(--text); transition: background-color var(--ease); }
.meal-row:hover { background: var(--tile); text-decoration: none; }
.meal-row:focus-visible { outline-offset: -2px; }
.row-name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.row-icon { display: inline-flex; flex: none; color: var(--text-3); }
.row-icon .icon { width: 14px; height: 14px; }
.meal-row .meta { flex: none; color: var(--text-2); font-size: 12px; white-space: nowrap; }
.meal-row .chip { flex: none; }
.library-empty { padding: 24px 0; text-align: center; }
@media (max-width: 759px) { .meal-row { padding: 8px 12px; flex-wrap: wrap; row-gap: 2px; } }
/* ---------- Settings */
.settings { max-width: 640px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.settings h1 { margin-bottom: 0; }
.settings-card h2 { margin-bottom: 8px; }
.btn-sm { height: 28px; padding: 0 10px; font-size: 12px; }
.slot-list { list-style: none; margin: 0 -16px; padding: 0; }
.slot-row { position: relative; display: grid; grid-template-columns: 24px minmax(0, 1fr); align-items: center;
            padding: 0 16px;
            border-top: 1px solid var(--line); background: var(--card); }
.slot-row:first-child { border-top: 0; }
.slot-row.dragging { opacity: .4; }
.grip { display: inline-flex; align-items: center; justify-content: center; flex: none; width: 24px;
        height: 44px; margin-left: -8px; color: var(--text-3); cursor: grab; border-radius: 8px;
        touch-action: none; }
.grip:hover { color: var(--text); }
.grip:active { cursor: grabbing; }
.slot-toggle { grid-column: 2; min-width: 0; display: flex; align-items: center; gap: 10px; min-height: 44px;
               padding: 0 4px; border: 0; background: transparent; color: var(--text); font: inherit;
               text-align: left; cursor: pointer; }
.slot-toggle:hover .slot-name { color: var(--accent-ink); }
.slot-name { flex: 1; min-width: 0; overflow-wrap: anywhere; font-weight: 600; }
.slot-toggle .meta { flex: none; color: var(--text-2); font-size: 12px; white-space: nowrap; }
.slot-row.is-off .slot-name { color: var(--text-2); font-weight: 400; }
.slot-edit { grid-column: 1 / -1; margin: 0 -16px; padding: 12px 16px 16px 40px; background: var(--tile);
             border-top: 1px solid var(--line); }
.slot-edit[hidden] { display: none; }
.edit-grid { display: grid; grid-template-columns: 80px 1fr; gap: 8px 12px; align-items: center;
             max-width: 420px; }
.edit-grid .label { margin: 0; }
.check-row, .switch-row { display: flex; align-items: center; gap: 8px; margin-top: 12px; cursor: pointer; }
.switch-row { justify-content: space-between; margin: 0; min-height: 36px; }
.slot-moves { grid-column: 1 / -1; display: flex; gap: 8px; padding: 0 0 8px 40px; }
.slot-add-open { margin-top: 8px; }
.slot-add-form { margin-top: 8px; }
.add-line { display: flex; gap: 8px; }
.add-line select { width: 110px; flex: none; }
.setting { margin: 0 0 16px; }
.setting:last-child { margin-bottom: 0; }
.setting select.field { max-width: 100%; }
.copy-row { display: flex; gap: 8px; align-items: center; }
.copy-row form { margin: 0; }
.copy-row .field { flex: 1; min-width: 0; text-overflow: ellipsis; }
.hint { margin: 8px 0 0; font-size: 12px; }
.account-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.account-actions form { margin: 0; }
.switch { appearance: none; -webkit-appearance: none; position: relative; flex: none; width: 40px; height: 24px;
          margin: 0; border-radius: 999px; background: var(--line); cursor: pointer;
          transition: background-color var(--ease); }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px;
                 border-radius: 50%; background: var(--card); box-shadow: 0 1px 2px rgb(0 0 0 / .3);
                 transition: transform var(--ease); }
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(16px); }
@media (max-width: 759px) {
  .slot-list { margin: 0 -12px; }
  .slot-row { padding: 0 12px; }
  .slot-edit { margin: 0 -12px; padding-left: 36px; padding-right: 12px; }
  .slot-toggle { flex-wrap: wrap; gap: 0 10px; padding: 6px 4px; }
  .copy-row { flex-wrap: wrap; }
  .copy-row .field { flex: 1 1 100%; }
}
/* ---------- Phone agenda and share view */
.agenda-page .agenda { max-width: 560px; margin: 0 auto; }
.agenda > h1, .agenda > h2 { margin: 0 0 12px; }
.agenda .day { margin: 0 0 10px; }
.agenda .day-head { justify-content: flex-start; gap: 8px; }
.agenda .day-empty { margin: 0; color: var(--text-3); font-size: 13px; }
.agenda .slot-view { display: flex; flex-direction: column; gap: 4px; }
.agenda .tile, .agenda .place-chip { cursor: default; }
.agenda .tile .meal-name:hover { text-decoration: none; color: var(--accent-ink); }
.agenda-note { margin-top: -6px; color: var(--text-2); font-size: 13px; line-height: 1.4;
               white-space: pre-wrap; overflow-wrap: break-word; }
.btn-block { display: flex; width: 100%; height: 40px; margin-top: 4px; }

/* "Desktop view": in the slim top bar on phones (always on /agenda), never in the wide plan page. */
.desktop-view { display: none; margin-left: auto; padding: 6px 8px; border-radius: 8px;
                color: var(--text-2); font-size: 13px; white-space: nowrap; }
.desktop-view:hover { background: var(--tile); color: var(--text); text-decoration: none; }
.agenda-page .desktop-view { display: inline-block; }
@media (max-width: 759px) { .plan-page:not(.force-desktop) .desktop-view { display: inline-block; } }