:root {
  --cream:    #F4EDDF;
  --paper:    #FBF7EE;
  --paper-2:  #F8F1E2;
  --ink:      #3A2E26;
  --ink-2:    #5C4A3E;
  --ink-soft: #8B7B6C;
  --line:     #DCC9AC;
  --line-2:   #E9DCC4;
  --tan:      #B98856;

  --fruta-base: #E8A78C;
  --fruta-bg:   #FBE5DD;
  --fruta-deep: #9F4F3A;

  --prot-base:  #B27262;
  --prot-bg:    #F1DBD2;
  --prot-deep:  #6B3A2D;

  --verd-base:  #94A37C;
  --verd-bg:    #E6ECDA;
  --verd-deep:  #4A5836;

  --cer-base:   #D4A772;
  --cer-bg:     #F4E5D2;
  --cer-deep:   #82561F;

  --plato-base: #A98BB0;
  --plato-bg:   #ECE2F0;
  --plato-deep: #5C3F66;

  --shadow-sm: 0 1px 2px rgba(58, 46, 38, 0.06), 0 2px 4px rgba(58, 46, 38, 0.04);
  --shadow-md: 0 4px 12px rgba(58, 46, 38, 0.08), 0 1px 3px rgba(58, 46, 38, 0.05);
  --shadow-lg: 0 16px 40px rgba(58, 46, 38, 0.10), 0 2px 6px rgba(58, 46, 38, 0.06);
}

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

html, body { height: 100%; }

body {
  font-family: 'Manrope', system-ui, sans-serif;
  font-weight: 400;
  color: var(--ink);
  background-color: var(--cream);
  background-image:
    radial-gradient(at 12% 8%, rgba(232, 167, 140, 0.18) 0, transparent 38%),
    radial-gradient(at 88% 12%, rgba(148, 163, 124, 0.16) 0, transparent 42%),
    radial-gradient(at 75% 92%, rgba(212, 167, 114, 0.20) 0, transparent 45%),
    radial-gradient(at 8% 90%, rgba(178, 114, 98, 0.12) 0, transparent 40%),
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.23 0 0 0 0 0.18 0 0 0 0 0.15 0 0 0 0.045 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  line-height: 1.55;
  letter-spacing: 0.005em;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

.display, h1, h2, h3, h4 {
  font-family: 'Fraunces', 'Times New Roman', serif;
  font-weight: 500;
  letter-spacing: -0.012em;
  font-variation-settings: "opsz" 48, "SOFT" 60;
  color: var(--ink);
}

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

/* ========== APP SHELL ========== */

.app {
  max-width: 1480px;
  margin: 0 auto;
  padding: 28px 36px 80px;
}

@media (max-width: 900px) {
  .app { padding: 20px 16px 60px; }
}

/* ========== HEADER ========== */

.masthead {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: end;
  gap: 32px;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--line);
  position: relative;
}

.masthead::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -3px;
  height: 1px;
  background: var(--line-2);
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.eyebrow {
  font-family: 'Manrope', sans-serif;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--tan);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.eyebrow::before, .eyebrow::after {
  content: "";
  height: 1px;
  background: var(--tan);
  opacity: 0.4;
  flex: 1;
  max-width: 18px;
}
.eyebrow::before { display: none; }

.brand h1 {
  font-size: clamp(34px, 4.4vw, 56px);
  font-weight: 500;
  font-style: italic;
  font-variation-settings: "opsz" 144, "SOFT" 80;
  line-height: 1.02;
  color: var(--ink);
}

.brand .tag {
  font-size: 14px;
  color: var(--ink-soft);
  margin-top: 4px;
  font-weight: 400;
}

.tag .dot {
  display: inline-block;
  width: 4px; height: 4px;
  border-radius: 50%;
  background: var(--tan);
  margin: 0 8px;
  vertical-align: middle;
}

/* the central ornamental line */
.masthead-rule {
  align-self: center;
  height: 0;
  margin-bottom: 18px;
  position: relative;
}

.masthead-rule .ornament {
  display: block;
  text-align: center;
  font-family: 'Fraunces', serif;
  font-size: 26px;
  color: var(--tan);
  font-weight: 400;
  letter-spacing: 0.5em;
}

/* ========== TOOLBAR ========== */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
  padding: 22px 0 26px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field label {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-soft);
  padding-left: 2px;
}

.field input,
.field select {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 13px;
  font-size: 14px;
  color: var(--ink);
  min-width: 120px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.field input:focus,
.field select:focus {
  outline: none;
  border-color: var(--tan);
  box-shadow: 0 0 0 3px rgba(185, 136, 86, 0.15);
}

.field input[type="text"]::placeholder { color: var(--ink-soft); opacity: 0.7; }

.toolbar-spacer { flex: 1; }

.btn {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--ink-2);
}
.btn:hover {
  background: var(--paper-2);
  border-color: var(--tan);
  color: var(--ink);
}
.btn-primary {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
  font-weight: 600;
}
.btn-primary:hover {
  background: var(--ink-2);
  color: var(--paper);
  border-color: var(--ink-2);
}
.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--ink-soft);
}
.btn-ghost:hover {
  background: rgba(58, 46, 38, 0.04);
  border-color: transparent;
  color: var(--ink);
}

.btn svg { width: 16px; height: 16px; }

/* ========== WEEK TABS ========== */

.week-bar {
  display: flex;
  align-items: center;
  gap: 0;
  border-bottom: 1px solid var(--line-2);
  margin-bottom: 22px;
  overflow-x: auto;
}

.week-tab {
  background: none;
  border: none;
  padding: 12px 20px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-soft);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
  transition: all 0.15s ease;
  font-family: 'Fraunces', serif;
  letter-spacing: 0;
  position: relative;
}
.week-tab:hover {
  color: var(--ink);
}
.week-tab.is-active {
  color: var(--ink);
  border-bottom-color: var(--tan);
  font-weight: 600;
  font-style: italic;
}
.week-tab .num {
  display: inline-block;
  margin-right: 6px;
  font-variation-settings: "opsz" 144;
  font-size: 16px;
}

/* ========== MAIN LAYOUT ========== */

.layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 28px;
  align-items: start;
}

@media (max-width: 1040px) {
  .layout { grid-template-columns: 1fr; }
}

/* ========== PALETTE ========== */

.palette {
  position: sticky;
  top: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-height: calc(100vh - 60px);
  overflow-y: auto;
  padding-right: 4px;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}
.palette::-webkit-scrollbar { width: 6px; }
.palette::-webkit-scrollbar-thumb { background: var(--line); border-radius: 3px; }

.palette-search {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 14px 10px 36px;
  font-size: 13px;
  width: 100%;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%238B7B6C' stroke-width='2' stroke-linecap='round'><circle cx='11' cy='11' r='7'/><path d='m21 21-4.3-4.3'/></svg>");
  background-repeat: no-repeat;
  background-position: 13px center;
}
.palette-search:focus {
  outline: none;
  border-color: var(--tan);
}

.cat {
  background: var(--paper);
  border-radius: 16px;
  padding: 16px 16px 14px;
  border: 1px solid var(--line-2);
  box-shadow: var(--shadow-sm);
}

.cat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px dashed var(--line-2);
}

.cat-title {
  display: flex;
  align-items: center;
  gap: 9px;
}

.cat-title h3 {
  font-size: 17px;
  font-weight: 500;
  font-style: italic;
}

.cat-icon {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.cat[data-cat="frutas"]    .cat-icon { background: var(--fruta-bg); color: var(--fruta-deep); }
.cat[data-cat="proteinas"] .cat-icon { background: var(--prot-bg);  color: var(--prot-deep); }
.cat[data-cat="verduras"]  .cat-icon { background: var(--verd-bg);  color: var(--verd-deep); }
.cat[data-cat="cereales"]  .cat-icon { background: var(--cer-bg);   color: var(--cer-deep); }
.cat[data-cat="platos"]    .cat-icon { background: var(--plato-bg); color: var(--plato-deep); }

.cat-icon svg { width: 16px; height: 16px; }

.cat-count {
  font-size: 11px;
  color: var(--ink-soft);
  font-weight: 500;
  font-feature-settings: "tnum";
  letter-spacing: 0.02em;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  background: var(--cream);
  border: 1px solid var(--line-2);
  border-radius: 9px;
  padding: 4px 10px 4px 8px;
  font-size: 12.5px;
  font-weight: 500;
  cursor: grab;
  user-select: none;
  transition: all 0.12s ease;
  letter-spacing: 0.005em;
  color: var(--ink-2);
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.chip .food-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  pointer-events: none;
}
.chip:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
  border-color: var(--tan);
  color: var(--ink);
}
.chip:active { cursor: grabbing; }
.chip.is-dragging { opacity: 0.4; transform: scale(0.96); }

.cat[data-cat="frutas"]    .chip:hover { background: var(--fruta-bg); border-color: var(--fruta-base); }
.cat[data-cat="proteinas"] .chip:hover { background: var(--prot-bg);  border-color: var(--prot-base); }
.cat[data-cat="verduras"]  .chip:hover { background: var(--verd-bg);  border-color: var(--verd-base); }
.cat[data-cat="cereales"]  .chip:hover { background: var(--cer-bg);   border-color: var(--cer-base); }
.cat[data-cat="platos"]    .chip:hover { background: var(--plato-bg); border-color: var(--plato-base); }

.chip.is-used::after {
  content: "";
  position: absolute;
  top: 4px;
  right: 4px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--tan);
}

/* edit pencil on palette chips (change icon / delete) */
.chip { padding-right: 10px; }
.chip-edit {
  width: 16px;
  height: 16px;
  margin-left: 1px;
  margin-right: -3px;
  border: none;
  background: transparent;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--ink-soft);
  opacity: 0;
  transition: opacity 0.12s ease, background 0.12s ease, color 0.12s ease;
  flex-shrink: 0;
}
.chip:hover .chip-edit { opacity: 0.65; }
.chip-edit:hover { opacity: 1; background: rgba(58,46,38,0.10); color: var(--ink); }
.chip-edit svg { width: 11px; height: 11px; }

/* "+ Añadir" button at the bottom of each category */
.cat-add {
  margin-top: 9px;
  width: 100%;
  border: 1px dashed var(--line);
  background: transparent;
  border-radius: 9px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.12s ease;
}
.cat-add:hover { border-color: var(--tan); color: var(--ink); background: var(--paper-2); }
.cat-add svg { width: 13px; height: 13px; }

/* ========== MODAL (add / edit word + icon picker) ========== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(58, 46, 38, 0.38);
  backdrop-filter: blur(2px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}
.modal-overlay.is-open { display: flex; }
.modal {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 460px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-head {
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--line-2);
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}
.modal-head h3 {
  font-size: 21px;
  font-style: italic;
  font-weight: 500;
}
.modal-close {
  border: none;
  background: transparent;
  font-size: 22px;
  line-height: 1;
  color: var(--ink-soft);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 8px;
}
.modal-close:hover { background: rgba(58,46,38,0.06); color: var(--ink); }
.modal-body {
  padding: 18px 22px;
  overflow-y: auto;
}
.modal-field { margin-bottom: 16px; }
.modal-field > label {
  display: block;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 7px;
}
.modal-field input[type="text"],
.modal-field select {
  width: 100%;
  background: var(--cream);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 13px;
  font-size: 15px;
  color: var(--ink);
}
.modal-field input[type="text"]:focus,
.modal-field select:focus {
  outline: none;
  border-color: var(--tan);
  box-shadow: 0 0 0 3px rgba(185,136,86,0.15);
}
.icon-search {
  width: 100%;
  background: var(--cream);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13px;
  margin-bottom: 10px;
}
.icon-search:focus { outline: none; border-color: var(--tan); }
.icon-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
  gap: 6px;
  max-height: 220px;
  overflow-y: auto;
  padding: 4px;
  border: 1px solid var(--line-2);
  border-radius: 12px;
  background: var(--cream);
  scrollbar-width: thin;
}
.icon-opt {
  aspect-ratio: 1;
  border: 1px solid transparent;
  background: var(--paper);
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.1s ease;
  padding: 6px;
}
.icon-opt img { width: 26px; height: 26px; pointer-events: none; }
.icon-opt:hover { border-color: var(--tan); background: var(--paper-2); transform: translateY(-1px); }
.icon-opt.is-selected {
  border-color: var(--tan);
  background: var(--cer-bg);
  box-shadow: 0 0 0 2px rgba(185,136,86,0.25);
}
.modal-foot {
  padding: 14px 22px 18px;
  border-top: 1px solid var(--line-2);
  display: flex;
  align-items: center;
  gap: 10px;
}
.modal-foot .spacer { flex: 1; }
.btn-danger {
  background: transparent;
  border-color: transparent;
  color: var(--prot-deep);
}
.btn-danger:hover { background: var(--prot-bg); border-color: var(--prot-base); color: var(--prot-deep); }

/* ========== PLANNER GRID ========== */

.planner {
  background: var(--paper);
  border: 1px solid var(--line-2);
  border-radius: 18px;
  padding: 22px 24px 24px;
  box-shadow: var(--shadow-md);
}

.planner-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line-2);
}

.planner-head h2 {
  font-size: 26px;
  font-style: italic;
  font-weight: 500;
}

.week-meta {
  font-size: 12px;
  color: var(--ink-soft);
  letter-spacing: 0.04em;
}

.grid {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

.grid th {
  text-align: left;
  font-family: 'Manrope', sans-serif;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-soft);
  padding: 8px 12px;
  border-bottom: 1px solid var(--line-2);
}

.grid th.day-head {
  text-align: center;
  font-weight: 600;
}

.grid th.day-head .day-name {
  font-family: 'Fraunces', serif;
  display: block;
  font-size: 14px;
  font-weight: 500;
  font-style: italic;
  text-transform: none;
  letter-spacing: 0;
  color: var(--ink);
  margin-bottom: 1px;
}

.grid .meal-label {
  font-family: 'Fraunces', serif;
  font-size: 14px;
  font-weight: 500;
  font-style: italic;
  text-transform: none;
  letter-spacing: 0;
  color: var(--ink-2);
  width: 88px;
  vertical-align: middle;
  padding: 14px 12px;
  border-right: 1px solid var(--line-2);
}

.slot {
  vertical-align: top;
  padding: 10px 8px;
  height: 110px;
  min-width: 130px;
  border-bottom: 1px dashed var(--line-2);
  border-right: 1px dashed var(--line-2);
  position: relative;
  transition: background 0.12s ease;
}
.slot:last-child { border-right: 0; }

.slot.is-over {
  background: rgba(185, 136, 86, 0.10);
  box-shadow: inset 0 0 0 1px var(--tan);
  border-radius: 8px;
}

.slot.is-empty::before {
  content: "+";
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  font-size: 20px;
  color: var(--line);
  font-family: 'Fraunces', serif;
  font-weight: 300;
  pointer-events: none;
  transition: color 0.12s ease;
}
.slot.is-over.is-empty::before { color: var(--tan); }

.slot-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.slot-chip {
  font-size: 13.5px;
  font-weight: 500;
  padding: 4px 10px 4px 8px;
  border-radius: 9px;
  border: 1px solid;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: all 0.12s ease;
  white-space: nowrap;
  max-width: 100%;
}
.slot-chip .food-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  pointer-events: none;
}
.slot-chip .x {
  font-size: 16px;
  width: 14px; height: 14px;
  line-height: 13px;
}
.slot-chip:hover { transform: translateY(-1px); box-shadow: var(--shadow-sm); }

.slot-chip[data-cat="frutas"]    { background: var(--fruta-bg); color: var(--fruta-deep); border-color: rgba(159, 79, 58, 0.15); }
.slot-chip[data-cat="proteinas"] { background: var(--prot-bg);  color: var(--prot-deep);  border-color: rgba(107, 58, 45, 0.15); }
.slot-chip[data-cat="verduras"]  { background: var(--verd-bg);  color: var(--verd-deep);  border-color: rgba(74, 88, 54, 0.15); }
.slot-chip[data-cat="cereales"]  { background: var(--cer-bg);   color: var(--cer-deep);   border-color: rgba(130, 86, 31, 0.15); }
.slot-chip[data-cat="platos"]    { background: var(--plato-bg); color: var(--plato-deep); border-color: rgba(92, 63, 102, 0.15); }

.slot-chip .x {
  display: inline-block;
  width: 12px; height: 12px;
  text-align: center;
  line-height: 11px;
  font-size: 14px;
  opacity: 0.5;
  transition: opacity 0.12s;
}
.slot-chip:hover .x { opacity: 1; }

.grid tbody tr:last-child .slot { border-bottom: 0; }

/* notes textarea */
.notes-row {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line-2);
}
.notes-row label {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-soft);
  display: block;
  margin-bottom: 8px;
}
.notes-row textarea {
  width: 100%;
  background: transparent;
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 13px;
  resize: vertical;
  min-height: 56px;
  color: var(--ink);
  line-height: 1.55;
  font-family: 'Fraunces', serif;
  font-style: italic;
  font-weight: 400;
}
.notes-row textarea:focus {
  outline: none;
  border-color: var(--tan);
  border-style: solid;
  background: var(--cream);
}
.notes-row textarea::placeholder {
  color: var(--ink-soft);
  font-style: italic;
}

/* category legend (bottom) */
.legend {
  display: flex;
  gap: 18px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line-2);
  flex-wrap: wrap;
}
.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--ink-soft);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-weight: 600;
}
.legend-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  display: inline-block;
}
.legend-dot.f { background: var(--fruta-base); }
.legend-dot.p { background: var(--prot-base); }
.legend-dot.v { background: var(--verd-base); }
.legend-dot.c { background: var(--cer-base); }
.legend-dot.pl { background: var(--plato-base); }

/* ========== TOAST ========== */

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--ink);
  color: var(--paper);
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s ease;
  z-index: 100;
  box-shadow: var(--shadow-lg);
}
.toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ========== PRINT STYLES ========== */

.print-only { display: none; }

/* When capturing as PNG, render printRoot offscreen so html2canvas can rasterize it. */
.print-only.is-capturing {
  display: block;
  position: absolute;
  left: -10000px;
  top: 0;
  width: 297mm;
  background: transparent;
}

/* ----- PAGE FRAME with decorative warm wash (applies for print AND capture) ----- */

.print-page,
.reco-page {
  page-break-after: always;
  page-break-inside: avoid;
  width: 297mm;
  height: 210mm;
  overflow: hidden;
  position: relative;
  background:
    radial-gradient(at 92% 4%,  rgba(212,167,114,0.18) 0, transparent 28%),
    radial-gradient(at 4% 96%,  rgba(232,167,140,0.16) 0, transparent 30%),
    radial-gradient(at 96% 100%, rgba(148,163,124,0.14) 0, transparent 28%),
    #FDF9EE;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  padding: 10mm 12mm;
  color: #2a201a;
  font-size: 10pt;
  line-height: 1.4;
}
.print-page:last-child,
.reco-page:last-child { page-break-after: auto; }

@media print {
  @page {
    size: A4 landscape;
    margin: 0;
  }

  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    color-adjust: exact !important;
  }

  body {
    background: #FBF6EB !important;
    color: #2a201a;
    font-size: 10pt;
    line-height: 1.4;
  }

  body::before { display: none !important; }

  .app, .palette, .toolbar, .week-bar, .planner, .masthead, .toast, .legend {
    display: none !important;
  }

  .print-only {
    display: block;
  }
}

  /* ----- HEADER BAR ----- */

  .print-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    padding: 0 0 3mm 0;
    margin-bottom: 4mm;
    position: relative;
  }
  .print-head::after {
    content: "";
    position: absolute;
    left: 0; right: 0; bottom: 0;
    height: 1.6pt;
    background: linear-gradient(to right,
      #E8A78C 0%, #E8A78C 25%,
      #B27262 25%, #B27262 50%,
      #94A37C 50%, #94A37C 75%,
      #D4A772 75%, #D4A772 100%);
    border-radius: 1pt;
  }

  .print-eyebrow {
    font-size: 8pt;
    font-weight: 700;
    letter-spacing: 0.22em;
    text-transform: uppercase;
    color: #B27262;
    margin-bottom: 1.5mm;
    display: inline-flex;
    align-items: center;
    gap: 2mm;
  }
  .print-eyebrow::before {
    content: "";
    display: inline-block;
    width: 5mm;
    height: 0.6pt;
    background: #B27262;
  }

  .print-head h1 {
    font-size: 22pt;
    font-style: italic;
    font-weight: 500;
    line-height: 0.95;
    color: #2a201a;
    letter-spacing: -0.012em;
  }

  .print-head .meta {
    text-align: right;
    font-size: 8.5pt;
    color: #6a5a4e;
    line-height: 1.55;
    padding: 2mm 4mm 2mm 5mm;
    background: #F4E5D2;
    border-radius: 2mm;
    border-left: 1.6pt solid #D4A772;
  }
  .print-head .meta strong {
    font-family: 'Fraunces', serif;
    font-style: italic;
    font-weight: 500;
    color: #82561F;
    font-size: 12pt;
  }

  /* ----- WEEKLY GRID ----- */

  table.print-grid {
    width: 100%;
    table-layout: fixed;
    border-collapse: collapse;
    margin-bottom: 4mm;
    flex: 1;
    border: 0.7pt solid #a88656;
  }
  table.print-grid colgroup col.meal { width: 22mm; }
  table.print-grid colgroup col.day  { width: auto; }
  table.print-grid th,
  table.print-grid td {
    border: 0.5pt solid #c9a872;
    padding: 3mm 2.5mm;
    vertical-align: top;
    font-size: 9pt;
    background: #FFFCF4;
  }

  table.print-grid thead th {
    background: linear-gradient(to bottom, #F4E5D2 0%, #EFD9B9 100%);
    font-family: 'Fraunces', serif;
    font-style: italic;
    font-weight: 600;
    font-size: 11pt;
    text-align: center;
    color: #5a3818;
    padding: 3mm 2mm 2.5mm;
    letter-spacing: 0;
    border-bottom: 0.6pt solid #d4a772;
  }
  table.print-grid thead th:first-child {
    background: #F8EDD8;
  }

  table.print-grid td.meal-label {
    font-family: 'Fraunces', serif;
    font-style: italic;
    font-weight: 600;
    font-size: 10.5pt;
    background: linear-gradient(to right, #F8EDD8 0%, #FCF4E1 100%);
    width: 22mm;
    color: #82561F;
    text-align: center;
    vertical-align: middle;
    border-right: 0.6pt solid #d4a772;
  }

  /* alternating warm tint per meal-row for legibility */
  table.print-grid tbody tr:nth-child(even) td:not(.meal-label) {
    background: #FAF5E8;
  }

  .print-chips {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 1.4mm;
  }
  .print-chip {
    font-size: 10pt;
    font-weight: 600;
    padding: 1mm 3mm 1mm 2mm;
    border-radius: 6mm;
    border: 0.4pt solid;
    line-height: 1.25;
    box-shadow: 0 0.3pt 0.6pt rgba(0,0,0,0.06);
    display: flex;
    align-items: center;
    gap: 1.6mm;
    width: 100%;
    box-sizing: border-box;
    white-space: normal;
  }
  .print-chip .food-icon.print {
    width: 21px;
    height: 21px;
    flex-shrink: 0;
  }
  .print-chip.frutas    { background: linear-gradient(135deg, #FBE5DD 0%, #F8D6C7 100%); color: #7a3520; border-color: #d99a83; }
  .print-chip.proteinas { background: linear-gradient(135deg, #F1DBD2 0%, #ECC9B9 100%); color: #5a2814; border-color: #b07262; }
  .print-chip.verduras  { background: linear-gradient(135deg, #E6ECDA 0%, #D5DEC1 100%); color: #3a4824; border-color: #94A37C; }
  .print-chip.cereales  { background: linear-gradient(135deg, #F4E5D2 0%, #ECD3AD 100%); color: #6a4014; border-color: #c89757; }
  .print-chip.platos    { background: linear-gradient(135deg, #ECE2F0 0%, #DDCCE4 100%); color: #4d3356; border-color: #a98bb0; }

  /* ----- NOTES & FOOTER ----- */

  .print-notes {
    margin-top: 2mm;
    padding: 3mm 4mm 3mm 5mm;
    border-left: 2pt solid #B27262;
    background: linear-gradient(to right, #F1DBD2 0%, #F8EFE8 60%, transparent 100%);
    border-radius: 1mm;
    font-style: italic;
    font-family: 'Fraunces', serif;
    font-size: 10pt;
    color: #3a2e26;
  }
  .print-notes:empty { display: none; }
  .print-notes-label {
    font-style: normal;
    font-family: 'Manrope', sans-serif;
    font-size: 7.5pt;
    font-weight: 700;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: #8a3818;
    margin-bottom: 1.5mm;
    display: block;
  }

  /* ----- RECOMMENDATIONS PAGE ----- */

  .reco-page .print-head { margin-bottom: 3mm; }

  .reco-intro {
    margin-bottom: 3mm;
    padding: 2.4mm 4.5mm 2.4mm 9mm;
    background: linear-gradient(135deg, #F4E5D2 0%, #FBE5DD 100%);
    border-radius: 2.5mm;
    font-family: 'Fraunces', serif;
    font-style: italic;
    font-size: 9.5pt;
    line-height: 1.4;
    color: #2a201a;
    border: 0.4pt solid #d4a772;
    position: relative;
  }
  .reco-intro::before {
    content: "“";
    position: absolute;
    top: -1mm; left: 3mm;
    font-family: 'Fraunces', serif;
    font-size: 24pt;
    color: #B27262;
    line-height: 1;
    font-style: normal;
  }

  .reco-cols {
    column-count: 2;
    column-gap: 6mm;
  }

  .reco-block {
    break-inside: avoid;
    margin-bottom: 2.6mm;
    padding: 2mm 3mm 2mm 3.6mm;
    border-radius: 1.8mm;
    border-left: 1.8pt solid;
    background: #FFFCF4;
  }
  .reco-block { border-left-color: #94A37C; background: linear-gradient(to right, #E6ECDA 0%, #FFFCF4 30%); }

  .reco-block h3 {
    font-family: 'Fraunces', serif;
    font-style: italic;
    font-size: 10.5pt;
    font-weight: 600;
    color: #2a201a;
    margin-bottom: 1.2mm;
    padding-bottom: 0.8mm;
    border-bottom: 0.4pt solid #cdb89b;
    display: flex;
    align-items: center;
    gap: 1.5mm;
    flex-wrap: wrap;
    line-height: 1.15;
  }

  .reco-block p,
  .reco-block li {
    font-size: 8.5pt;
    line-height: 1.35;
    color: #2a201a;
    margin-bottom: 0.4mm;
  }
  .reco-block ul,
  .reco-block ol {
    padding-left: 3.5mm;
    margin: 0;
  }
  .reco-block ul li::marker { color: #B27262; }
  .reco-block ol li::marker { color: #B27262; font-family: 'Fraunces', serif; font-style: italic; font-weight: 600; }
  .reco-block strong { color: #6a3018; font-weight: 700; }

  .reco-tag {
    display: inline-block;
    font-family: 'Manrope', sans-serif;
    font-style: normal;
    font-size: 7pt;
    font-weight: 800;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    padding: 0.4mm 1.8mm;
    border-radius: 1.2mm;
    margin-right: 0.5mm;
    background: #F4E5D2;
    color: #82561F;
    border: 0.4pt solid #d4a772;
  }
  .reco-tag.danger {
    background: linear-gradient(135deg, #fbe2dc 0%, #f5cdc1 100%);
    color: #7a2818;
    border-color: #d68876;
  }
  .reco-tag.allow {
    background: linear-gradient(135deg, #e6ecda 0%, #d5dec1 100%);
    color: #3a4528;
    border-color: #94A37C;
  }

  .reco-grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.4mm 3mm;
    font-size: 8.5pt;
    margin-top: 0.5mm;
  }

  .reco-pill {
    display: flex;
    align-items: baseline;
    gap: 1.5mm;
    padding: 0.4mm 0;
    border-bottom: 0.3pt dashed #d6c4a8;
    font-size: 8.5pt;
  }

  .reco-pill .num {
    font-family: 'Fraunces', serif;
    font-style: italic;
    font-weight: 600;
    color: #B27262;
    font-size: 9pt;
    min-width: 5mm;
  }

  /* "danger" reco-block list of forbidden items */
  .reco-block.is-danger { background: linear-gradient(to right, #fbe2dc 0%, #FFFCF4 35%); border-left-color: #B27262 !important; }
  .reco-block.is-danger .reco-pill .num { color: #a04030; }

  /* ----- RULES BLOCK (full-width, foreground positive) ----- */

  .rules-block {
    margin-bottom: 4mm;
    padding: 4mm 5mm 4mm 4mm;
    background: linear-gradient(135deg, #ECF0DD 0%, #DCE5C2 100%);
    border: 0.6pt solid #94A37C;
    border-left: 3.6pt solid #4a5836;
    border-radius: 2.5mm;
    display: grid;
    grid-template-columns: 16mm 1fr;
    gap: 4mm;
    align-items: center;
    box-shadow: 0 0.4pt 1pt rgba(74, 88, 54, 0.12);
  }
  .rules-block .rules-icon {
    width: 16mm;
    height: 16mm;
    color: #4a5836;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .rules-block .rules-icon svg {
    width: 100%;
    height: 100%;
  }
  .rules-block h3 {
    font-family: 'Fraunces', serif;
    font-style: italic;
    font-size: 13pt;
    font-weight: 700;
    color: #2a3818;
    margin-bottom: 1.6mm;
    line-height: 1.1;
  }
  .rules-block ul {
    padding-left: 4mm;
    margin: 0;
    font-size: 9pt;
    color: #2a201a;
    line-height: 1.4;
  }
  .rules-block li {
    margin-bottom: 0.6mm;
  }
  .rules-block li::marker { color: #4a5836; }
  .rules-block strong { color: #2a3818; font-weight: 700; }

  /* ----- CHOKING HAZARD BLOCK (full-width, warm warning) ----- */

  .choking-block {
    margin-bottom: 4mm;
    padding: 4mm 5mm 4mm 4mm;
    background: linear-gradient(135deg, #FAEAE0 0%, #F2D6C4 100%);
    border: 0.5pt solid #d4a08c;
    border-left: 3pt solid #B27262;
    border-radius: 2.5mm;
    display: grid;
    grid-template-columns: 16mm 1fr;
    gap: 4mm;
    align-items: center;
    box-shadow: 0 0.4pt 1pt rgba(178, 114, 98, 0.10);
  }
  .choking-block .warn-icon {
    width: 16mm;
    height: 16mm;
    color: #B27262;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .choking-block .warn-icon svg {
    width: 100%;
    height: 100%;
  }
  .choking-block h3 {
    font-family: 'Fraunces', serif;
    font-style: italic;
    font-size: 13pt;
    font-weight: 700;
    color: #6B3A2D;
    margin-bottom: 1.4mm;
    line-height: 1.1;
  }
  .choking-block p {
    font-size: 9pt;
    color: #2a201a;
    line-height: 1.4;
    margin-bottom: 1.6mm;
  }
  .choking-block strong { color: #6B3A2D; font-weight: 700; }
  .choking-block .never-list {
    display: flex;
    flex-wrap: wrap;
    gap: 1.2mm 1.6mm;
    margin-top: 1.2mm;
  }
  .choking-block .never-item {
    background: rgba(255, 252, 244, 0.85);
    border: 0.4pt solid #c89478;
    padding: 0.5mm 2mm;
    border-radius: 1.4mm;
    color: #6B3A2D;
    font-weight: 600;
    font-size: 8.6pt;
    line-height: 1.2;
  }
  .choking-block .never-label {
    font-family: 'Manrope', sans-serif;
    font-size: 7.5pt;
    font-weight: 800;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: #8a4818;
    margin-bottom: 0.2mm;
  }

/* small util */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  border: 0;
}

/* ========== TOOLBAR EXTRAS (menu status, separators) ========== */

.toolbar-sep {
  width: 1px;
  align-self: stretch;
  background: var(--line-2);
  margin: 4px 2px;
}

.menu-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  background: var(--paper);
  border: 1px solid var(--line-2);
  border-radius: 10px;
  font-size: 13px;
  color: var(--ink-2);
  max-width: 280px;
}
.menu-status .status-name {
  font-family: 'Fraunces', serif;
  font-style: italic;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.menu-status .status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--verd-base);
  flex-shrink: 0;
}
.menu-status .status-dot.is-dirty { background: var(--tan); }
.menu-status .status-tag {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--tan);
}

/* ========== MENU LIBRARY LIST ========== */

.menu-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 60px;
}
.lib-empty {
  color: var(--ink-soft);
  font-style: italic;
  font-family: 'Fraunces', serif;
  text-align: center;
  padding: 24px 0;
}
.lib-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line-2);
  border-radius: 12px;
  background: var(--cream);
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
.lib-item:hover { border-color: var(--tan); box-shadow: var(--shadow-sm); }
.lib-info { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.lib-name {
  font-family: 'Fraunces', serif;
  font-style: italic;
  font-weight: 500;
  font-size: 15px;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 8px;
}
.lib-current {
  font-family: 'Manrope', sans-serif;
  font-style: normal;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--verd-deep);
  background: var(--verd-bg);
  padding: 1px 6px;
  border-radius: 6px;
}
.lib-date { font-size: 11.5px; color: var(--ink-soft); }
.lib-actions { display: flex; gap: 6px; flex-shrink: 0; }
.lib-actions .btn { padding: 6px 11px; font-size: 12.5px; }

/* ========== LOGIN OVERLAY ========== */

.login-overlay .login-modal { max-width: 360px; }
.login-error {
  color: var(--prot-deep);
  font-size: 13px;
  font-weight: 500;
  min-height: 18px;
  margin-top: 4px;
}

/* keep overlays hidden when printing */
@media print {
  .modal-overlay, .print-only.is-capturing,
  .fab, .sheet-backdrop { display: none !important; }
}

/* ============================================================ */
/* ===================== MOBILE MODE ========================== */
/* ============================================================ */

/* Mobile-only chrome: hidden on desktop. */
.palette-sheet-head { display: none; }
.sheet-backdrop { display: none; }
.fab { display: none; }
.grid-scroll { width: 100%; }

/* Tablet & down: palette already stacks above the grid (handled by .layout). */

/* ----- Phones (≤ 720px): palette becomes a bottom sheet ----- */
@media (max-width: 720px) {

  .app { padding: 16px 12px 88px; }   /* room for the FAB */

  /* tighter masthead */
  .masthead { gap: 12px; padding-bottom: 14px; }
  .masthead-rule { display: none; }
  .brand h1 { font-size: clamp(28px, 9vw, 40px); }
  .brand .tag { font-size: 12.5px; }

  /* toolbar: compact, wraps; status on its own line */
  .toolbar { gap: 8px; padding: 14px 0 16px; }
  .toolbar .field { flex: 1 1 132px; }
  .toolbar .field input,
  .toolbar .field select { min-width: 0; width: 100%; }
  .toolbar-spacer { display: none; }
  .toolbar-sep { display: none; }
  .menu-status { order: -1; width: 100%; max-width: none; }
  .toolbar .btn { padding: 9px 12px; font-size: 13px; flex: 0 0 auto; }

  /* planner: let the week scroll horizontally, keep the meal column pinned */
  .layout { gap: 14px; }
  .planner { padding: 14px 12px 16px; border-radius: 14px; }
  .planner-head h2 { font-size: 21px; }
  .grid-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -4px;
    padding-bottom: 4px;
  }
  .grid { min-width: 560px; }
  .grid .slot { min-width: 92px; height: 84px; padding: 7px 6px; }
  .grid .meal-label {
    position: sticky;
    left: 0;
    z-index: 2;
    width: 58px;
    padding: 10px 6px;
    background: var(--paper);
    font-size: 12.5px;
  }
  .grid th.day-head .day-name { font-size: 12.5px; }
  .slot-chip { font-size: 12.5px; padding: 3px 8px 3px 6px; }
  .slot.is-empty::before { font-size: 22px; color: var(--line); }

  /* the palette turns into a bottom sheet */
  .palette {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    top: auto;
    width: 100%;
    max-height: 82vh;
    margin: 0;
    padding: 0 14px env(safe-area-inset-bottom, 14px);
    background: var(--paper);
    border-top: 1px solid var(--line);
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -12px 40px rgba(58, 46, 38, 0.22);
    transform: translateY(110%);
    transition: transform 0.26s cubic-bezier(0.22, 1, 0.36, 1);
    z-index: 160;
    overflow-y: auto;
    overscroll-behavior: contain;
    gap: 10px;
  }
  .palette.is-open { transform: translateY(0); }

  .palette-sheet-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    background: var(--paper);
    padding: 14px 2px 10px;
    margin-bottom: 2px;
    border-bottom: 1px solid var(--line-2);
    z-index: 1;
  }
  .palette-sheet-head::before {
    content: "";
    position: absolute;
    top: 6px; left: 50%;
    transform: translateX(-50%);
    width: 38px; height: 4px;
    border-radius: 4px;
    background: var(--line);
  }
  .palette-sheet-title {
    font-family: 'Fraunces', serif;
    font-style: italic;
    font-weight: 500;
    font-size: 17px;
    color: var(--ink);
  }
  .palette-sheet-close {
    border: none;
    background: transparent;
    font-size: 26px;
    line-height: 1;
    color: var(--ink-soft);
    cursor: pointer;
    padding: 0 4px;
  }

  .palette-search { font-size: 16px; }  /* ≥16px avoids iOS zoom-on-focus */

  /* bigger touch targets for chips */
  .chip { padding: 7px 12px 7px 9px; font-size: 13.5px; }
  .chip .food-icon { width: 18px; height: 18px; }
  .cat-add { padding: 9px 10px; }

  .sheet-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(58, 46, 38, 0.40);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 150;
  }
  .sheet-backdrop.is-open { opacity: 1; pointer-events: auto; }

  /* floating "add food" button */
  .fab {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    position: fixed;
    right: 16px;
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    z-index: 140;
    border: none;
    background: var(--ink);
    color: var(--paper);
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    padding: 13px 18px;
    border-radius: 999px;
    box-shadow: var(--shadow-lg);
    cursor: pointer;
  }
  .fab svg { width: 18px; height: 18px; }
  .fab:active { transform: scale(0.97); }

  /* modals: full-width sheets on tiny screens */
  .modal { max-width: none; border-radius: 16px; }
  .modal-field input[type="text"],
  .modal-field select,
  .icon-search { font-size: 16px; }   /* avoid iOS zoom */
  .icon-grid { max-height: 180px; }
}

/* very narrow phones */
@media (max-width: 380px) {
  .brand h1 { font-size: 26px; }
  .grid .slot { min-width: 84px; }
}

/* respect reduced-motion (accessibility + stable test hit-testing) */
@media (prefers-reduced-motion: reduce) {
  .palette, .sheet-backdrop, .modal-overlay, .toast { transition: none !important; }
}
