:root {
  --bg: #fdf6ec;
  --bg-card: #ffffff;
  --ink: #3a2e26;
  --ink-soft: #8a7a6d;
  --accent: #d97a3f;
  --accent-dark: #b85f2a;
  --accent-soft: #f6e2ce;
  --line: #ece0d1;
  --shadow: 0 2px 10px rgba(90, 60, 30, 0.08);
  --shadow-lg: 0 12px 32px rgba(90, 60, 30, 0.18);
  --radius: 16px;

  --c-desayuno: #f2b134;
  --c-comida: #d97a3f;
  --c-snacks: #8a5cb8;
  --c-cena: #3f6fa8;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  height: 100%;
  overscroll-behavior-y: none;
}

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

/* ---------- Topbar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg-card);
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 10px 14px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 18px;
  color: var(--accent-dark);
  margin-right: auto;
}

.brand-icon {
  font-size: 22px;
}

.logout-btn {
  border: none;
  background: transparent;
  color: var(--ink-soft);
  font-size: 12px;
  cursor: pointer;
  text-decoration: underline;
  padding: 4px;
}

.logout-btn:hover {
  color: var(--accent-dark);
}

.profile-switcher {
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--bg-card);
  color: var(--ink);
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  cursor: pointer;
}

.profile-switcher[hidden] {
  display: none;
}

.topbar-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  order: 3;
  flex-basis: 100%;
  justify-content: center;
}

@media (min-width: 720px) {
  .topbar-nav {
    order: 2;
    flex-basis: auto;
    margin-right: auto;
  }
}

.topbar-nav[hidden] {
  display: none;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--accent-dark);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:hover {
  background: var(--accent-soft);
}

.today-btn {
  border: 1px solid var(--accent);
  color: var(--accent-dark);
  background: var(--bg-card);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.today-btn:hover {
  background: var(--accent-soft);
}

.period-label {
  font-size: 15px;
  font-weight: 700;
  margin: 0 4px;
  min-width: 160px;
  text-align: center;
  text-transform: capitalize;
}

.view-switcher {
  display: flex;
  background: var(--bg);
  border-radius: 20px;
  padding: 3px;
  gap: 2px;
  order: 2;
}

@media (min-width: 720px) {
  .view-switcher {
    order: 3;
  }
}

.view-btn {
  border: none;
  background: transparent;
  padding: 7px 14px;
  border-radius: 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
  cursor: pointer;
}

.view-btn.active {
  background: var(--accent);
  color: #fff;
}

/* ---------- View root ---------- */

.view-root {
  padding: 16px;
  max-width: 1100px;
  margin: 0 auto;
  padding-bottom: 100px;
}

/* ---------- Year view ---------- */

.year-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 16px;
}

.mini-month {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px;
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease;
}

.mini-month:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.mini-month-title {
  font-weight: 700;
  font-size: 14px;
  color: var(--accent-dark);
  margin: 0 0 8px;
  text-align: center;
  text-transform: capitalize;
}

.mini-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 3px;
}

.mini-day {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  border-radius: 5px;
  color: var(--ink-soft);
  position: relative;
}

.mini-day.today {
  outline: 2px solid var(--accent);
  font-weight: 700;
}

.mini-day.has-entries {
  background: var(--accent-soft);
  color: var(--ink);
  font-weight: 600;
}

.mini-day.empty-cell {
  visibility: hidden;
}

/* ---------- Month view ---------- */

.month-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
}

.weekday-header {
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-soft);
  padding-bottom: 4px;
  text-transform: uppercase;
}

.month-day {
  background: var(--bg-card);
  border-radius: 12px;
  box-shadow: var(--shadow);
  min-height: 92px;
  padding: 6px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow: hidden;
  transition: transform .12s ease, box-shadow .12s ease;
}

.month-day:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.month-day.empty-cell {
  visibility: hidden;
  box-shadow: none;
  cursor: default;
}

.month-day.today {
  border: 2px solid var(--accent);
}

.month-day-header {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.month-day-num {
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-soft);
}

.month-day.today .month-day-num {
  color: var(--accent-dark);
}

.month-day-kcal {
  font-size: 10px;
  font-weight: 600;
  color: var(--accent-dark);
  white-space: nowrap;
}

.dot-row {
  display: flex;
  gap: 3px;
  flex-wrap: wrap;
  margin-top: auto;
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ---------- Week view ---------- */

.week-actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.week-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.week-day-block {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px;
  border-left: 4px solid transparent;
}

.week-day-block.today {
  border-left-color: var(--accent);
}

.week-day-block-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
  text-transform: capitalize;
}

.week-day-block-name-group {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.week-day-open-btn {
  border: none;
  background: none;
  padding: 0;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  opacity: 0.7;
}

.week-day-open-btn:hover {
  opacity: 1;
}

.week-day-block-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
}

.week-day-block-num {
  font-size: 13px;
  color: var(--ink-soft);
}

.week-day-block-kcal {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
  white-space: nowrap;
}

.week-day-block.today .week-day-block-name {
  color: var(--accent-dark);
}

.week-day-block.today .week-day-block-num {
  color: #fff;
  background: var(--accent);
  border-radius: 50%;
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}

.week-day-meals {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

@media (max-width: 620px) {
  .week-day-meals {
    grid-template-columns: 1fr;
  }
}

.meal-slot {
  position: relative;
  background: var(--bg);
  border-radius: 12px;
  box-shadow: var(--shadow);
  min-height: 84px;
  padding: 8px;
  cursor: pointer;
  border-left: 4px solid transparent;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: transform .12s ease, box-shadow .12s ease;
}

.meal-slot:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.meal-slot.drag-over {
  outline: 2px dashed var(--accent);
  outline-offset: -2px;
  background: var(--accent-soft);
}

.meal-slot-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--ink-soft);
  text-transform: uppercase;
}

.meal-slot-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.meal-slot-label-group {
  display: flex;
  align-items: baseline;
  gap: 6px;
  min-width: 0;
}

.meal-slot-kcal {
  font-size: 10px;
  font-weight: 700;
  color: var(--accent-dark);
  white-space: nowrap;
}

.meal-slot-add {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.meal-slot-add:hover {
  background: var(--accent-dark);
}

.meal-slot-tiles {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  flex: 1;
}

.meal-slot-tile {
  cursor: grab;
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg-card);
}

.meal-slot-tile.dragging {
  opacity: .4;
}

/* Insertion marker while dragging a dish over another one. */
.meal-slot-tile.drop-before {
  box-shadow: -3px 0 0 var(--accent);
}

.meal-slot-tile.drop-after {
  box-shadow: 3px 0 0 var(--accent);
}

.meal-slot-thumb {
  width: 100%;
  height: 44px;
  border-radius: 8px;
  object-fit: cover;
}

.meal-slot-tile .meal-slot-thumb {
  border-radius: 8px 8px 0 0;
}

.meal-slot-title {
  font-size: 12px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.meal-slot-tile .meal-slot-title {
  padding: 3px 4px;
}

.meal-slot-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-soft);
  font-size: 22px;
  flex: 1;
}

/* ---------- Day view ---------- */

.day-header-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.day-header {
  text-align: center;
  font-size: 18px;
  font-weight: 700;
  text-transform: capitalize;
  color: var(--accent-dark);
}

.view-mode-toggle {
  display: flex;
  gap: 2px;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 2px;
}

.view-mode-btn {
  border: none;
  background: none;
  border-radius: 16px;
  width: 28px;
  height: 26px;
  font-size: 13px;
  color: var(--ink-soft);
  cursor: pointer;
}

.view-mode-btn.active {
  background: var(--accent);
  color: #fff;
}

.day-totals {
  font-size: 15px;
  font-weight: 600;
  color: var(--ink-soft);
  white-space: nowrap;
}

@media (max-width: 619px) {
  .day-totals {
    font-size: 12px;
    white-space: nowrap;
    text-align: center;
  }
}

.shopping-btn {
  border: 1px solid var(--accent);
  color: var(--accent-dark);
  background: var(--bg-card);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.shopping-btn:hover {
  background: var(--accent-soft);
}

.shopping-btn-icon {
  padding: 6px 10px;
}

/* Narrow phones: tighten the week's action buttons so Generar / Borrar /
   Comprar / 📄 all stay on one line instead of the last one wrapping. */
@media (max-width: 420px) {
  .week-actions,
  .day-header-row {
    gap: 6px;
  }

  .week-actions .shopping-btn,
  .day-header-row .shopping-btn {
    padding: 6px 11px;
  }

  .week-actions .shopping-btn-icon,
  .day-header-row .shopping-btn-icon {
    padding: 6px 9px;
  }
}

.shopping-btn-danger {
  border-color: #b8412a;
  color: #b8412a;
}

.shopping-btn-danger:hover {
  background: #fbe4e0;
}

.day-meals {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
}

.meal-section {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  border-top: 4px solid transparent;
}

.meal-section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-weight: 700;
  margin-bottom: 10px;
}

.meal-section-kcal {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent-dark);
  white-space: nowrap;
}

.entry-card {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 10px;
  cursor: pointer;
  background: var(--bg);
  transition: transform .12s ease;
}

.entry-card:hover {
  transform: translateY(-2px);
}

.entry-swap-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 2;
}

.entry-swap-btn:hover {
  background: #fff;
}

.entry-card img,
.entry-card video {
  width: 100%;
  max-height: 220px;
  object-fit: cover;
  display: block;
  background: var(--accent-soft);
}

.entry-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 10px;
  margin-bottom: 10px;
}

.entry-cards-grid .entry-card {
  margin-bottom: 0;
}

.entry-card-compact img {
  max-height: 90px;
}

.entry-card-compact .entry-swap-btn {
  width: 22px;
  height: 22px;
  top: 4px;
  right: 4px;
  font-size: 11px;
}

.entry-card-compact .entry-card-body {
  padding: 8px;
}

.entry-card-compact .entry-card-title {
  font-size: 12px;
}

.entry-card-lines .entry-card-body {
  padding: 10px 12px;
  display: flex;
  align-items: center;
  min-height: 40px;
}

.entry-card-lines .entry-card-title {
  font-size: 13px;
  white-space: normal;
}

.entry-card-body {
  padding: 10px;
}

.entry-card-title-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 2px;
}

.entry-card-title {
  font-weight: 700;
  font-size: 14px;
}

.entry-card-badges {
  display: flex;
  align-items: baseline;
  gap: 6px;
  flex-shrink: 0;
}

.servings-badge,
.portion-badge,
.portion-kcal-badge {
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-soft);
  white-space: nowrap;
  flex-shrink: 0;
}

.portion-kcal-badge {
  color: var(--accent-dark);
}

.entry-card-notes {
  font-size: 12px;
  color: var(--ink-soft);
  margin-bottom: 6px;
}

.entry-card-sublabel {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 2px;
}

.entry-card-ingredients {
  margin: 0 0 6px;
  padding-left: 18px;
  font-size: 12px;
  color: var(--ink);
}

.entry-card-ingredients li {
  margin-bottom: 1px;
}

.entry-card-nutrition {
  font-size: 11px;
  color: var(--ink-soft);
  margin-top: 4px;
  line-height: 1.6;
}

.add-meal-btn {
  width: 100%;
  border: 2px dashed var(--line);
  background: transparent;
  color: var(--ink-soft);
  border-radius: 12px;
  padding: 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.add-meal-btn:hover {
  border-color: var(--accent);
  color: var(--accent-dark);
}

/* ---------- FAB ---------- */

.fab {
  position: fixed;
  right: 22px;
  bottom: 24px;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 30px;
  border: none;
  box-shadow: var(--shadow-lg);
  cursor: pointer;
  z-index: 30;
  line-height: 0;
}

.fab:hover {
  background: var(--accent-dark);
}

/* ---------- Modal ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(58, 46, 38, 0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
}

.modal-overlay[hidden] {
  display: none;
}

@media (min-width: 620px) {
  .modal-overlay {
    align-items: center;
  }
}

.modal {
  background: var(--bg-card);
  width: 100%;
  max-width: 520px;
  max-height: 92vh;
  overflow-y: auto;
  border-radius: 20px 20px 0 0;
  padding: 22px;
  position: relative;
  box-shadow: var(--shadow-lg);
}

@media (min-width: 620px) {
  .modal {
    border-radius: 20px;
  }
}

/* Below 620px, modals go full-screen (like navigating to a page) instead of
   a capped bottom sheet — avoids a dead gap above and controls sliding out
   of view on long forms (recipe editor). */
@media (max-width: 619px) {
  .modal-overlay {
    align-items: stretch;
  }

  .modal {
    max-width: 100%;
    height: 100%;
    max-height: 100vh;
    max-height: 100dvh;
    border-radius: 0;
  }

  .modal-sm {
    height: auto;
    max-height: 92vh;
    max-height: 92dvh;
    border-radius: 20px 20px 0 0;
  }

  .modal-overlay:has(.modal-sm) {
    align-items: flex-end;
  }
}

.modal-sm {
  max-width: 360px;
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: var(--bg);
  font-size: 18px;
  cursor: pointer;
  color: var(--ink-soft);
}

.modal h2 {
  margin: 0 0 16px;
  font-size: 18px;
  color: var(--accent-dark);
}

.field {
  display: block;
  margin-bottom: 14px;
}

.field[hidden] {
  display: none;
}

.field span {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-soft);
  margin-bottom: 5px;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  font-size: 14px;
  color: var(--ink);
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: 2px solid var(--accent);
}

.ingredients-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 8px;
}

.ingredient-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.ingredient-row .ingredient-input {
  flex: 1;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  font-size: 13px;
  color: var(--ink);
}

.ingredient-row .ingredient-input:focus {
  outline: 2px solid var(--accent);
}

.ingredient-remove {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  border-radius: 50%;
  border: none;
  background: var(--bg);
  color: var(--ink-soft);
  font-size: 16px;
  cursor: pointer;
  line-height: 1;
}

.ingredient-remove:hover {
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.add-ingredient-btn {
  border: 1px dashed var(--line);
  background: transparent;
  color: var(--ink-soft);
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
}

.add-ingredient-btn:hover {
  border-color: var(--accent);
  color: var(--accent-dark);
}

.field-title-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 5px;
}

.field-title-row>span {
  margin-bottom: 0;
}

.servings-field {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.servings-field span {
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-soft);
  white-space: nowrap;
  margin-bottom: 0;
}

.servings-field input {
  width: 56px;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  font-size: 13px;
  color: var(--ink);
  text-align: center;
}

.servings-field input:focus {
  outline: 2px solid var(--accent);
}

.portion-size-row {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  margin-bottom: 6px;
}

.portion-size-field {
  max-width: 160px;
  margin-bottom: 0;
}

.portion-size-kcal {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent-dark);
  padding-bottom: 9px;
  white-space: nowrap;
}

.portion-size-hint {
  display: block;
  font-size: 12px;
  color: var(--ink-soft);
  margin-bottom: 10px;
}

.convert-to-100-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.convert-to-100-input {
  max-width: 110px;
}

.convert-to-100-row .btn {
  flex-shrink: 0;
  white-space: nowrap;
}

.nutrition-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
  gap: 8px;
}

.nutrition-field span {
  display: block;
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-soft);
  margin-bottom: 4px;
}

.nutrition-input {
  display: flex;
  align-items: center;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  padding: 0 8px;
}

.nutrition-input input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  padding: 8px 2px;
  font-size: 13px;
  color: var(--ink);
}

.nutrition-input input:focus {
  outline: none;
}

.nutrition-input:focus-within {
  outline: 2px solid var(--accent);
}

.nutrition-input small {
  font-size: 11px;
  color: var(--ink-soft);
  flex-shrink: 0;
}

.nutrition-input input::-webkit-outer-spin-button,
.nutrition-input input::-webkit-inner-spin-button {
  margin-left: 4px;
}

.media-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-bottom: 14px;
}

.ai-analyze-row {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  margin-bottom: 14px;
}

.ai-analyze-row[hidden] {
  display: none;
}

.ai-analyze-hint {
  font-size: 11px;
  color: var(--ink-soft);
}

.media-field>span {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-soft);
  margin-bottom: 5px;
}

.media-field input[type="file"] {
  width: 100%;
  font-size: 11px;
}

.media-preview {
  margin-top: 8px;
  position: relative;
}

.media-preview img,
.media-preview video {
  width: 100%;
  border-radius: 10px;
  max-height: 140px;
  object-fit: cover;
  background: var(--accent-soft);
}

.barcode-video {
  width: 100%;
  max-height: 260px;
  border-radius: 10px;
  background: #000;
  object-fit: cover;
}

.barcode-hint {
  margin-top: 8px;
  font-size: 12px;
  color: var(--ink-soft);
  text-align: center;
}

.barcode-status {
  font-size: 13px;
  color: var(--ink-soft);
  text-align: center;
  min-height: 18px;
}

.barcode-grams-input {
  max-width: 120px;
}

.barcode-nutrition-preview {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
}

.media-remove {
  margin-top: 4px;
  width: 100%;
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: 8px;
  padding: 4px;
  font-size: 11px;
  cursor: pointer;
  color: var(--ink-soft);
}

.modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 18px;
  flex-wrap: wrap;
}

.modal-actions-right {
  display: flex;
  gap: 10px;
  margin-left: auto;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-dark);
}

.btn-ghost {
  background: transparent;
  color: var(--ink-soft);
}

.btn-ghost:hover {
  color: var(--ink);
}

.btn-danger {
  background: #fbe4e0;
  color: #b8412a;
}

.btn-danger:hover {
  background: #f6cec7;
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  bottom: 96px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 10px 18px;
  border-radius: 20px;
  font-size: 13px;
  z-index: 60;
  box-shadow: var(--shadow-lg);
}

/* ---------- Login ---------- */

.login-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.login-screen[hidden] {
  display: none;
}

.login-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 36px 28px;
  width: 100%;
  max-width: 340px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-icon {
  font-size: 44px;
  display: block;
  margin-bottom: 4px;
}

.login-card h1 {
  margin: 0;
  color: var(--accent-dark);
  font-size: 22px;
}

.login-sub {
  margin: 0 0 8px;
  color: var(--ink-soft);
  font-size: 13px;
}

.login-card input[type="password"] {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  font-size: 15px;
  text-align: center;
}

.login-card input[type="password"]:focus {
  outline: 2px solid var(--accent);
}

.login-btn {
  width: 100%;
  padding: 12px;
  font-size: 15px;
}

.login-error {
  color: #b8412a;
  font-size: 12px;
  margin: 0;
}

.generate-select-all-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: -6px 0 12px;
}

.generate-hint {
  font-size: 13px;
  color: var(--ink-soft);
  margin: 0;
}

.generate-select-all-row .btn {
  flex-shrink: 0;
  padding: 4px 12px;
  font-size: 12px;
}

/* ---------- Shopping list ---------- */

.shopping-body {
  max-height: 75vh;
  overflow-y: auto;
}

.shopping-group {
  margin-bottom: 16px;
}

.shopping-group-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 6px;
}

.shopping-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}

.shopping-item input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  flex-shrink: 0;
}

.shopping-item label {
  flex: 1;
  cursor: pointer;
}

.generate-row-kcal {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent-dark);
  flex-shrink: 0;
  margin-right: 14px;
}

.generate-title-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.generate-title-row h2 {
  margin: 0;
}

.generate-total-kcal {
  font-size: 19px;
  font-weight: 800;
  color: var(--ink);
  flex-shrink: 0;
  margin-right: 14px;
}

.generate-group-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 6px;
}

.generate-group-kcal {
  font-size: 15px;
  font-weight: 800;
  color: var(--ink);
  text-transform: none;
  margin-right: 14px;
}

.shopping-item.checked label {
  text-decoration: line-through;
  color: var(--ink-soft);
}

.shopping-empty {
  text-align: center;
  color: var(--ink-soft);
  padding: 30px 10px;
  font-size: 13px;
}

.empty-state {
  text-align: center;
  color: var(--ink-soft);
  padding: 60px 20px;
  font-size: 14px;
}

/* ---------- Shopping-list "PDF" (print-only view) ---------- */

#shopping-print-area {
  display: none;
}

@media print {
  body * {
    visibility: hidden;
  }

  #shopping-print-area,
  #shopping-print-area * {
    visibility: visible;
  }

  /* visibility:hidden alone still leaves the whole app's (tall) layout in
     the document, which prints as extra blank pages — drop every other
     top-level element from layout entirely so the page count is just the
     print area's own content. */
  body>*:not(#shopping-print-area) {
    display: none !important;
  }

  #shopping-print-area {
    display: block;
    position: static;
    width: auto;
    padding: 8px;
  }

  #shopping-print-area h1 {
    font-size: 20px;
    margin: 0 0 16px;
  }

  #shopping-print-area h2 {
    font-size: 14px;
    margin: 16px 0 6px;
  }

  #shopping-print-area ul {
    margin: 0;
    padding-left: 20px;
  }

  #shopping-print-area li {
    font-size: 13px;
    padding: 2px 0;
  }

  /* Week-summary PDF: day rows x meal columns, dish names only. */
  #shopping-print-area .print-week-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
  }

  #shopping-print-area .print-week-table th,
  #shopping-print-area .print-week-table td {
    border: 1px solid #999;
    padding: 4px 8px;
    vertical-align: top;
    text-align: left;
    font-size: 12px;
  }

  #shopping-print-area .print-week-table th {
    background: #eee;
    font-size: 12px;
  }

  #shopping-print-area .print-week-table tr {
    page-break-inside: avoid;
  }

  #shopping-print-area .print-week-day {
    font-weight: 700;
    width: 14%;
  }

  #shopping-print-area .print-week-dish {
    padding: 1px 0;
  }

  /* Day PDF (landscape): one band per meal, one column per dish (4 across),
     each band kept whole on a page. */
  #shopping-print-area .print-day-meal {
    margin: 0 0 10px;
    page-break-inside: avoid;
  }

  #shopping-print-area .print-day-meal h2 {
    margin: 0 0 6px;
    padding-bottom: 3px;
    border-bottom: 1px solid #999;
  }

  #shopping-print-area .print-day-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px 12px;
  }

  #shopping-print-area .print-day-dish {
    page-break-inside: avoid;
  }

  #shopping-print-area .print-day-dish-name {
    font-size: 13px;
    font-weight: 700;
    margin-bottom: 2px;
  }

  #shopping-print-area.print-day ul {
    padding-left: 16px;
  }

  #shopping-print-area.print-day li {
    font-size: 11px;
    padding: 1px 0;
  }

  #shopping-print-area .print-day-dish-sub {
    font-size: 11px;
    font-style: italic;
    margin: 4px 0 0;
  }
}

/* ---------- Recipe library / picker ---------- */

.library-toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.library-search-wrap {
  flex: 1;
  min-width: 160px;
  display: flex;
  gap: 6px;
}

.library-search {
  flex: 1;
  min-width: 0;
  padding: 10px 14px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: var(--bg-card);
  font-size: 14px;
  color: var(--ink);
}

.library-search:focus {
  outline: 2px solid var(--accent);
}

.library-search-btn {
  flex-shrink: 0;
  width: 40px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--bg-card);
  font-size: 15px;
  cursor: pointer;
  color: var(--ink-soft);
}

.library-search-btn:hover {
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.category-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 16px;
}

.category-chips[hidden] {
  display: none;
}

.category-chip {
  border: 1px solid var(--line);
  background: var(--bg-card);
  color: var(--ink-soft);
  border-radius: 16px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.category-chip:hover {
  border-color: var(--accent);
}

.category-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.nutrition-chip.active {
  background: #4a8f5c;
  border-color: #4a8f5c;
  color: #fff;
}

.diet-chip.active {
  background: #4f6fa8;
  border-color: #4f6fa8;
  color: #fff;
}

.cooking-chip.active {
  background: #b0682a;
  border-color: #b0682a;
  color: #fff;
}

.filter-group {
  margin-bottom: 6px;
}

.filter-group-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  text-align: left;
  border: none;
  background: none;
  padding: 8px 0;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: var(--ink-soft);
  cursor: pointer;
}

.filter-group-toggle::after {
  content: '▾';
  margin-left: auto;
  font-size: 10px;
  transition: transform .15s ease;
}

.filter-group-toggle.open::after {
  transform: rotate(180deg);
}

.filter-group-toggle.has-active {
  color: var(--accent-dark);
}

.filter-group-toggle.has-active::before {
  content: '';
  width: 6px;
  height: 6px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--accent);
}

.library-grid,
.picker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 12px;
}

.picker-grid {
  margin: 10px 0;
  max-height: 42vh;
  overflow-y: auto;
}

.recipe-card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  padding: 0;
  text-align: left;
  display: flex;
  flex-direction: column;
  transition: transform .12s ease, box-shadow .12s ease;
}

.recipe-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.recipe-card img {
  width: 100%;
  height: 90px;
  object-fit: cover;
  display: block;
  background: var(--accent-soft);
}

.recipe-card-placeholder {
  width: 100%;
  height: 90px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  background: var(--accent-soft);
}

.recipe-card-title {
  padding: 8px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
}

.recipe-card-title-name {
  font-size: 12px;
  font-weight: 700;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.recipe-card-kcal {
  font-size: 10px;
  font-weight: 700;
  color: var(--accent-dark);
  flex-shrink: 0;
}

.recipe-card-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  padding: 0 8px 8px;
}

.nutrition-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  background: #eaf4ec;
  color: #2f6b3f;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
}

.nutrition-badge-sm {
  padding: 2px 5px;
  font-size: 13px;
}

.nutrition-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.diet-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  background: #e8edf7;
  color: #33507d;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
}

.diet-badge-sm {
  padding: 2px 5px;
  font-size: 13px;
}

.cooking-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  background: #f7ece0;
  color: #8a4c1a;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
}

.cooking-badge-sm {
  padding: 2px 5px;
  font-size: 13px;
}

.picker-empty {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--ink-soft);
  padding: 30px 10px;
  font-size: 13px;
}

/* ---------- Entry detail (calendar day view) ---------- */

.entry-detail-body {
  margin-top: 6px;
}

.entry-detail-media {
  width: 100%;
  max-height: 260px;
  object-fit: cover;
  border-radius: 12px;
  margin-bottom: 10px;
  background: var(--accent-soft);
}

.entry-detail-title {
  margin: 0;
  font-size: 18px;
  color: var(--ink);
}

.entry-detail-meta {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 10px;
}