/* meal — household planner + grocery list. 2026.
   Shares the Love & Maneuver design language with `track`:
   neutral slate system + teal accent, light & dark. */

:root {
  color-scheme: light dark;

  --bg: #f7f4ef;
  --bg-grad: radial-gradient(110% 70% at 50% -20%, #f1e6d6 0%, rgba(241, 230, 214, 0) 45%);
  --surface: #fffdfb;
  --surface-2: #f3ede4;
  --ink: #2a2019;
  --ink-soft: #6b5d4f;
  --ink-faint: #9c8f80;
  --line: #ece4d8;
  --line-strong: #dccfbe;

  --brand: #985c2c;
  --brand-strong: #7c4a22;
  --brand-tint: #f4ead9;
  --on-brand: #ffffff;
  --ring: rgba(152, 92, 44, 0.30);

  --danger: #d6453c;

  --ui: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 22px;

  --shadow-xs: 0 1px 2px rgba(12, 19, 32, 0.05);
  --shadow-sm: 0 1px 3px rgba(12, 19, 32, 0.06), 0 1px 2px rgba(12, 19, 32, 0.04);
  --shadow-md: 0 10px 30px -8px rgba(12, 19, 32, 0.18);
  --shadow-lg: 0 30px 70px -20px rgba(12, 19, 32, 0.45);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17120d;
    --bg-grad: radial-gradient(110% 70% at 50% -20%, rgba(224, 165, 100, 0.10) 0%, rgba(23, 18, 13, 0) 48%);
    --surface: #211a13;
    --surface-2: #2a2118;
    --ink: #f0e9e0;
    --ink-soft: #b3a795;
    --ink-faint: #82776a;
    --line: #332a20;
    --line-strong: #463a2c;

    --brand: #e0a564;
    --brand-strong: #ecbd87;
    --brand-tint: rgba(224, 165, 100, 0.15);
    --on-brand: #2a1a0b;
    --ring: rgba(224, 165, 100, 0.35);

    --danger: #f2555b;

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.5);
    --shadow-md: 0 12px 34px -10px rgba(0, 0, 0, 0.6);
    --shadow-lg: 0 30px 80px -24px rgba(0, 0, 0, 0.8);
  }
}

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

body {
  font-family: var(--ui);
  color: var(--ink);
  background: var(--bg-grad), var(--bg);
  background-attachment: fixed;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  letter-spacing: -0.011em;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 4px; }
.muted { color: var(--ink-soft); font-size: 0.9rem; }
.empty-hint { padding: 2.5rem 0.5rem; line-height: 1.6; max-width: 48ch; }

/* ── header ── */
.chrome {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.95rem clamp(1rem, 4vw, 2.5rem);
  background: color-mix(in srgb, var(--surface) 72%, transparent);
  backdrop-filter: saturate(150%) blur(14px);
  -webkit-backdrop-filter: saturate(150%) blur(14px);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
}
.mark { display: inline-flex; align-items: center; gap: 0.55rem; color: var(--brand); }
.heart { width: 1.3rem; height: 1.3rem; }
.mark-word { font-size: 1.12rem; font-weight: 700; letter-spacing: -0.02em; color: var(--ink); }
.chrome-nav { display: flex; align-items: center; gap: 1.25rem; font-size: 0.85rem; }
.who { color: var(--ink-faint); font-size: 0.78rem; font-weight: 450; }

/* ── tabs ── */
.tabs {
  display: flex;
  gap: 2px;
  padding: 3px;
  margin: 1.4rem auto 0;
  max-width: 360px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
}
.tab {
  flex: 1;
  font-family: var(--ui);
  font-size: 0.88rem;
  font-weight: 600;
  padding: 0.5rem 0.8rem;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  transition: background 0.14s, color 0.14s;
}
.tab.active { background: var(--surface); color: var(--brand); box-shadow: var(--shadow-xs); }

main { max-width: 1120px; margin: 0 auto; padding: clamp(1.25rem, 3.5vw, 2.5rem); }

/* ── buttons (shared with track) ── */
.btn {
  font-family: var(--ui);
  font-size: 0.875rem;
  font-weight: 550;
  padding: 0.58rem 1.05rem;
  border-radius: var(--r-md);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  transition: background 0.14s, border-color 0.14s, box-shadow 0.14s, transform 0.08s;
}
.btn:hover { border-color: var(--brand); box-shadow: var(--shadow-xs); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); box-shadow: 0 4px 14px -4px var(--ring); }
.btn-primary:hover { background: var(--brand-strong); border-color: var(--brand-strong); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); border-color: var(--line); }
.btn-danger { background: transparent; border-color: color-mix(in srgb, var(--danger) 55%, transparent); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn:disabled { opacity: 0.5; cursor: default; box-shadow: none; }
.icon-btn {
  font-family: var(--ui);
  background: none; border: none; cursor: pointer;
  color: var(--ink-faint); font-size: 0.85rem; line-height: 1;
  padding: 0.3rem 0.4rem; border-radius: var(--r-sm); transition: background 0.12s, color 0.12s;
}
.icon-btn:hover { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }

/* ── week nav ── */
.week-nav { display: flex; align-items: center; gap: 0.55rem; flex-wrap: wrap; margin-bottom: 1.4rem; }
.nav-arrow { font-size: 1.2rem; line-height: 1; padding: 0.4rem 0.7rem; font-weight: 700; }
.week-label { font-size: 1.05rem; font-weight: 700; letter-spacing: -0.02em; min-width: 9.5rem; }
.gen-btn { margin-left: auto; }

/* ── plan board ── */
.board {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.85rem;
}
.day-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 0.85rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.day-card.is-today { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand), var(--shadow-sm); }
.day-head { display: flex; align-items: baseline; gap: 0.5rem; }
.day-dow { font-size: 0.95rem; font-weight: 700; letter-spacing: -0.02em; }
.day-num { font-size: 0.78rem; color: var(--ink-faint); font-weight: 500; }

.slot {
  text-align: left;
  font-family: var(--ui);
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface-2);
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s, transform 0.08s;
}
.slot:hover { border-color: var(--brand); }
.slot:active { transform: scale(0.99); }
.slot.empty { background: transparent; border-style: dashed; border-color: var(--line-strong); }
.slot-track { font-size: 0.62rem; text-transform: uppercase; letter-spacing: 0.09em; color: var(--ink-faint); font-weight: 700; }
.slot-meal { font-size: 0.92rem; font-weight: 600; color: var(--ink); line-height: 1.25; }
.slot-add { font-size: 0.85rem; color: var(--ink-faint); font-weight: 500; }
.slot-tag { font-size: 0.58rem; color: var(--brand-strong); font-weight: 650; text-transform: uppercase; letter-spacing: 0.06em; }

/* ── grocery ── */
.add-row { display: flex; gap: 0.5rem; margin-bottom: 1rem; flex-wrap: wrap; }
.add-row input, .add-row select {
  font-family: var(--ui);
  font-size: 0.95rem;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--ink);
}
.add-row input { flex: 1; min-width: 9rem; }
.add-row input.qty { flex: 0 0 5.5rem; min-width: 0; }
.add-row input:focus, .add-row select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--ring); }

.grocery-actions { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 0.9rem; min-height: 1.8rem; }
.g-count { font-size: 0.8rem; color: var(--ink-faint); font-weight: 550; }
.grocery-actions .btn { margin-left: auto; }

.grocery-list { display: flex; flex-direction: column; gap: 1.1rem; }
.g-group { display: flex; flex-direction: column; gap: 0.3rem; }
.g-aisle { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-faint); font-weight: 700; margin-bottom: 0.15rem; }
.g-item {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  cursor: pointer;
}
.g-item input[type="checkbox"] { width: 1.15rem; height: 1.15rem; accent-color: var(--brand); flex: 0 0 auto; }
.g-text { display: flex; align-items: baseline; gap: 0.5rem; flex: 1; min-width: 0; }
.g-name { font-weight: 550; color: var(--ink); }
.g-qty { font-size: 0.8rem; color: var(--ink-soft); }
.g-item.checked .g-name { text-decoration: line-through; color: var(--ink-faint); }
.g-item.checked .g-qty { color: var(--ink-faint); }
.g-item .icon-btn { margin-left: auto; }

/* ── meals ── */
.toolbar { display: flex; gap: 0.6rem; margin-bottom: 1.2rem; }
.toolbar input {
  font-family: var(--ui); font-size: 0.95rem; padding: 0.6rem 0.7rem; flex: 1;
  border: 1px solid var(--line-strong); border-radius: var(--r-md); background: var(--surface); color: var(--ink);
}
.toolbar input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--ring); }

.meal-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 0.75rem; }
.meal-card {
  text-align: left; font-family: var(--ui);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: 0.9rem 1rem; cursor: pointer; box-shadow: var(--shadow-sm);
  display: flex; flex-direction: column; gap: 0.35rem;
  transition: transform 0.12s, box-shadow 0.12s, border-color 0.12s;
}
.meal-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--brand); }
.mc-head { display: flex; align-items: baseline; justify-content: space-between; gap: 0.5rem; }
.mc-name { font-size: 1rem; font-weight: 650; letter-spacing: -0.01em; }
.mc-effort { font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-faint); font-weight: 650; }
.mc-sub { font-size: 0.78rem; color: var(--ink-soft); }
.mc-tags { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 0.1rem; }
.tag { font-size: 0.62rem; background: var(--brand-tint); color: var(--brand-strong); padding: 0.14rem 0.5rem; border-radius: 999px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.05em; }

/* ── dialogs (shared with track) ── */
.dialog {
  border: none; border-radius: var(--r-xl); padding: 0; margin: auto;
  width: min(480px, 94vw); background: var(--surface); color: var(--ink);
  box-shadow: var(--shadow-lg);
  animation: dialog-in 0.18s cubic-bezier(0.2, 0.7, 0.3, 1);
}
@keyframes dialog-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: none; } }
.dialog::backdrop { background: rgba(6, 12, 18, 0.5); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
.dialog form, .dialog #picker-body { padding: 1.6rem; display: flex; flex-direction: column; gap: 1.05rem; max-height: 88vh; overflow-y: auto; }
.dialog h2 { font-weight: 700; font-size: 1.3rem; letter-spacing: -0.025em; }

.field { display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.8rem; color: var(--ink-soft); font-weight: 550; }
.field input, .field select {
  font-family: var(--ui); font-size: 0.95rem; padding: 0.6rem 0.7rem;
  border: 1px solid var(--line-strong); border-radius: var(--r-md);
  background: var(--surface); color: var(--ink);
  transition: border-color 0.14s, box-shadow 0.14s;
}
.field input:focus, .field select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--ring); }
fieldset { border: none; }
fieldset legend { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-faint); margin-bottom: 0.5rem; font-weight: 650; }

.chips { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.chip {
  font-family: var(--ui); font-size: 0.82rem; font-weight: 550;
  padding: 0.4rem 0.75rem; border: 1px solid var(--line-strong); border-radius: 999px;
  background: var(--surface); color: var(--ink); cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s, transform 0.08s;
}
.chip:hover { border-color: var(--brand); background: var(--brand-tint); }
.chip:active { transform: scale(0.96); }
.chip.active { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }

/* ingredient editor rows */
.ing-list { display: flex; flex-direction: column; gap: 0.4rem; margin-bottom: 0.5rem; }
.ing-row { display: flex; gap: 0.4rem; align-items: center; }
.ing-row input, .ing-row select {
  font-family: var(--ui); font-size: 0.9rem; padding: 0.45rem 0.55rem;
  border: 1px solid var(--line-strong); border-radius: var(--r-sm); background: var(--surface); color: var(--ink);
}
.ing-row .ing-name { flex: 1; min-width: 0; }
.ing-row .ing-qty { flex: 0 0 4.5rem; min-width: 0; }
.ing-row .ing-aisle { flex: 0 0 7rem; }
.ing-row input:focus, .ing-row select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--ring); }
.add-ing { align-self: flex-start; }

/* picker list */
.picker-list { display: flex; flex-direction: column; gap: 0.3rem; max-height: 40vh; overflow-y: auto; }
.picker-item {
  text-align: left; font-family: var(--ui);
  display: flex; align-items: baseline; justify-content: space-between; gap: 0.6rem;
  padding: 0.6rem 0.75rem; border: 1px solid var(--line); border-radius: var(--r-md);
  background: var(--surface); color: var(--ink); cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
.picker-item:hover { border-color: var(--brand); background: var(--brand-tint); }
.pi-name { font-weight: 600; }
.pi-meta { font-size: 0.74rem; color: var(--ink-soft); }
#picker-search {
  font-family: var(--ui); font-size: 0.95rem; padding: 0.6rem 0.7rem;
  border: 1px solid var(--line-strong); border-radius: var(--r-md); background: var(--surface); color: var(--ink);
}
#picker-search:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--ring); }

.form-error { color: var(--danger); font-size: 0.8rem; min-height: 1em; font-weight: 500; }
.dialog-actions { display: flex; gap: 0.6rem; align-items: center; list-style: none; padding: 0; margin: 0; }
.dialog-actions .spacer { flex: 1; }

@media (max-width: 560px) {
  .gen-btn { margin-left: 0; width: 100%; order: 5; }
  .week-label { min-width: 0; flex: 1; text-align: center; }
}

/* ── plan layout: board + meal library ── */
.plan-layout { display: flex; gap: 1.1rem; align-items: flex-start; }
.plan-main { flex: 1; min-width: 0; }

.library {
  flex: 0 0 290px;
  width: 290px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  padding: 0.9rem;
  position: sticky;
  top: 1rem;
  max-height: calc(100dvh - 2rem);
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.library-head { display: flex; align-items: center; justify-content: space-between; }
.library-head strong { font-size: 0.95rem; letter-spacing: -0.01em; }
.lib-close { display: none; }
#lib-search, #lib-writein {
  font-family: var(--ui); font-size: 0.9rem; padding: 0.5rem 0.6rem; width: 100%;
  border: 1px solid var(--line-strong); border-radius: var(--r-md);
  background: var(--surface); color: var(--ink);
}
#lib-search:focus, #lib-writein:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--ring); }
.lib-writein { display: flex; gap: 0.4rem; }
.lib-writein input { flex: 1; }
.lib-writein-btn { padding: 0.45rem 0.75rem; }
.lib-list { display: flex; flex-direction: column; gap: 0.35rem; overflow-y: auto; }
.lib-empty { padding: 1rem 0.2rem; }
.lib-card {
  text-align: left; font-family: var(--ui); cursor: pointer;
  display: flex; align-items: center; justify-content: space-between; gap: 0.5rem;
  padding: 0.5rem 0.65rem; border: 1px solid var(--line); border-radius: var(--r-md);
  background: var(--surface-2); color: var(--ink);
  transition: background 0.12s, border-color 0.12s, transform 0.08s;
}
.lib-card:hover { border-color: var(--brand); background: var(--brand-tint); }
.lib-card:active { transform: scale(0.98); }
.lib-card.dragging { opacity: 0.5; }
.lib-card.armed { background: var(--brand); border-color: var(--brand); color: var(--on-brand); box-shadow: 0 4px 14px -4px var(--ring); }
.lib-card.armed .lib-tracks { color: rgba(255, 255, 255, 0.8); }
.lib-name { font-weight: 600; font-size: 0.88rem; line-height: 1.2; }
.lib-tracks { font-size: 0.62rem; color: var(--ink-faint); font-weight: 700; letter-spacing: 0.04em; flex: 0 0 auto; }

/* arming + drop-target feedback on the board */
.board.arming .slot { border-style: dashed; border-color: var(--brand); }
.board.arming .slot:hover { background: var(--brand-tint); }
.slot.drop-target {
  border-style: solid !important;
  border-color: var(--brand) !important;
  background: var(--brand-tint) !important;
  box-shadow: 0 0 0 2px var(--ring);
}

/* "placing…" toast */
.arm-bar {
  position: fixed; bottom: 1.1rem; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 0.6rem; z-index: 30;
  background: var(--ink); color: var(--surface);
  padding: 0.5rem 0.6rem 0.5rem 1rem; border-radius: 999px;
  box-shadow: var(--shadow-lg); max-width: calc(100vw - 2rem);
}
.arm-bar[hidden] { display: none; }
.arm-bar .arm-text { font-size: 0.85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.arm-bar .arm-text strong { font-weight: 700; }
.arm-bar .btn { background: transparent; border-color: transparent; color: var(--surface); padding: 0.3rem 0.8rem; }
.arm-bar .btn:hover { background: rgba(255, 255, 255, 0.16); border-color: transparent; box-shadow: none; }

/* mobile-only: FAB + bottom-sheet library */
.fab { display: none; }
.sheet-backdrop { display: none; }

@media (max-width: 900px) {
  .plan-layout { display: block; }
  .library {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto;
    width: auto; flex: none; max-height: 75vh; z-index: 25;
    border-radius: var(--r-xl) var(--r-xl) 0 0;
    transform: translateY(105%);
    transition: transform 0.22s cubic-bezier(0.2, 0.7, 0.3, 1);
    box-shadow: var(--shadow-lg);
  }
  .library.open { transform: none; }
  .lib-close { display: inline-flex; }
  .sheet-backdrop { display: block; position: fixed; inset: 0; background: rgba(6, 12, 18, 0.45); z-index: 24; }
  .sheet-backdrop[hidden] { display: none; }
  .fab {
    display: inline-flex; align-items: center; gap: 0.4rem;
    position: fixed; right: 1.1rem; bottom: 1.1rem; z-index: 20;
    background: var(--brand); color: var(--on-brand); border: none; border-radius: 999px;
    padding: 0.8rem 1.15rem; font-family: var(--ui); font-weight: 650; font-size: 0.9rem;
    box-shadow: var(--shadow-md); cursor: pointer;
  }
  .fab.hidden-while-arming { display: none; }
}
