/**
 * Modul: Essensplan (Meals)
 * Zweck: Styles für Wochenansicht, Mahlzeit-Karten, Zutaten-Liste, Modal
 * Abhängigkeiten: tokens.css, layout.css
 */

/* --------------------------------------------------------
 * Modul-Akzent
 * -------------------------------------------------------- */
.meals-page { --module-accent: var(--module-meals); }

/* --------------------------------------------------------
 * Seiten-Layout
 * -------------------------------------------------------- */
.meals-page {
  display: flex;
  flex-direction: column;
  height: calc(100dvh - var(--safe-area-inset-top) - var(--nav-bottom-height) - var(--safe-area-inset-bottom));
  max-width: var(--content-max-width);
  margin: 0 auto;
  overflow: hidden;
}

@media (min-width: 1024px) {
  .meals-page {
    height: 100dvh;
  }
}

/* --------------------------------------------------------
 * Wochen-Navigation
 * -------------------------------------------------------- */
.week-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  border-top: 3px solid var(--module-accent);
  border-bottom: 1px solid var(--color-border);
  background-color: var(--color-surface);
  flex-shrink: 0;
  gap: var(--space-2);
}

.week-nav__label {
  font-size: var(--text-base);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-primary);
  flex: 1;
  text-align: center;
}

.week-nav__today {
  font-size: var(--text-sm);
  color: var(--color-accent);
  font-weight: var(--font-weight-medium);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  background: var(--color-accent-light);
  cursor: pointer;
  border: none;
  white-space: nowrap;
}

/* --------------------------------------------------------
 * Wochengitter (scroll horizontal auf Mobil)
 * -------------------------------------------------------- */
.week-grid {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.day-column {
  border-bottom: 1px solid var(--color-border-subtle);
}

.day-column:last-child {
  border-bottom: none;
}

.day-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4) var(--space-2);
  position: sticky;
  top: 0;
  background-color: var(--color-bg);
  z-index: var(--z-base);
}

.day-header__name {
  font-size: var(--text-sm);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.day-header__date {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
}

.day-header--today .day-header__name,
.day-header--today .day-header__date {
  color: var(--color-accent);
}

.day-slots {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-2);
  padding: 0 var(--space-4) var(--space-3);
}

@media (min-width: 600px) {
  .day-slots {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* --------------------------------------------------------
 * Mahlzeit-Slot
 * -------------------------------------------------------- */
.meal-slot {
  min-height: 72px;
  border-radius: var(--radius-sm);
  border: 1.5px dashed var(--color-border);
  background-color: var(--color-surface);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  text-align: left;
  overflow: hidden;
  transition: border-color var(--transition-fast);
}

.meal-slot--has-meal {
  border-style: solid;
  border-color: var(--color-border);
}

.meal-slot__type-label {
  font-size: var(--text-xs);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-disabled);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: var(--space-1) var(--space-2) 0;
  text-align: left;
}

/* Slot-Typ-Farben - zentrale Tokens aus tokens.css */
.meal-slot[data-type="breakfast"] .meal-slot__type-label { color: var(--meal-breakfast); }
.meal-slot[data-type="lunch"]     .meal-slot__type-label { color: var(--meal-lunch); }
.meal-slot[data-type="dinner"]    .meal-slot__type-label { color: var(--meal-dinner); }
.meal-slot[data-type="snack"]     .meal-slot__type-label { color: var(--meal-snack); }

.meal-slot__add-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text-disabled);
  font-size: var(--text-sm);
  padding: var(--space-2);
  transition: color var(--transition-fast);
  min-height: var(--target-lg);
}

.meal-slot__add-btn:hover {
  color: var(--color-accent);
}

/* --------------------------------------------------------
 * Mahlzeit-Karte (innerhalb des Slots)
 * -------------------------------------------------------- */
.meal-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
  padding: var(--space-4);
  cursor: pointer;
}

.meal-card__title {
  font-size: var(--text-sm);
  font-weight: var(--font-weight-medium);
  color: var(--color-text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: left;
  line-height: 1.4;
  align-self: stretch;
}

.meal-card__meta {
  margin-top: var(--space-1);
  display: flex;
  align-items: center;
  gap: var(--space-1);
  align-self: stretch;
  text-align: left;
}

.meal-card__ingredients-count {
  font-size: var(--text-xs);
  color: var(--color-text-secondary);
}

.meal-card__ing-done {
  font-size: var(--text-xs);
  color: var(--color-success);
}

.meal-card__actions {
  display: flex;
  gap: var(--space-1);
  margin-top: var(--space-1);
  align-self: stretch;
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.meal-slot:hover .meal-card__actions,
.meal-slot:focus-within .meal-card__actions {
  opacity: 1;
}

.meal-card__action-btn {
  width: 24px;
  height: 24px;
  border-radius: var(--radius-xs);
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text-disabled);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: color var(--transition-fast), background-color var(--transition-fast);
}

.meal-card__action-btn::before {
  content: '';
  position: absolute;
  inset: -12px;
}

.meal-card__action-btn:hover {
  color: var(--color-danger);
  background-color: var(--color-surface-2);
}

.meal-card__action-btn--shopping:hover {
  color: var(--color-success);
}

.meal-card__action-btn--recipe {
  text-decoration: none;
}

.meal-card__action-btn--recipe:hover {
  color: var(--color-accent);
}

/* --------------------------------------------------------
 * Meals-Modal Content-Styles (Overlay/Panel via shared modal.js)
 * -------------------------------------------------------- */

/* Autocomplete im Modal */
.meal-modal__autocomplete {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background-color: var(--color-surface);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  z-index: calc(var(--z-modal) + 1);
  overflow: hidden;
  max-height: 180px;
  overflow-y: auto;
}

.meal-modal__autocomplete-item {
  padding: var(--space-2) var(--space-3);
  cursor: pointer;
  font-size: var(--text-sm);
  transition: background-color var(--transition-fast);
}

.meal-modal__autocomplete-item:hover,
.meal-modal__autocomplete-item--active {
  background-color: var(--color-accent-light);
  color: var(--color-accent);
}

/* Zutaten-Bereich */
.ingredient-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.ingredient-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.ingredient-row__name {
  flex: 2;
}

.ingredient-row__qty {
  flex: 1;
  min-width: 0;
}

.ingredient-row__cat {
  flex: 1.5;
  min-width: 0;
  font-size: var(--text-sm);
}

.ingredient-row__remove {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text-disabled);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  position: relative;
  transition: color var(--transition-fast);
}

.ingredient-row__remove::before {
  content: '';
  position: absolute;
  inset: -8px;
}

.ingredient-row__remove:hover {
  color: var(--color-danger);
}

.add-ingredient-btn {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: var(--color-accent);
  background: none;
  border: none;
  cursor: pointer;
  padding: var(--space-1) 0;
  min-height: var(--target-lg);
}

/* Einkaufsliste-Auswahl im Modal */
.shopping-transfer {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-3);
  background-color: var(--color-accent-light);
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-accent);
}

.shopping-transfer__label {
  font-size: var(--text-sm);
  font-weight: var(--font-weight-medium);
  color: var(--color-accent);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.shopping-transfer__select {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-accent);
  background-color: var(--color-surface);
  color: var(--color-text-primary);
  font-size: var(--text-sm);
}

.shopping-transfer__btn {
  align-self: flex-start;
}

/* --------------------------------------------------------
 * Mahlzeit-Typ Labels (DE)
 * -------------------------------------------------------- */
.meal-type-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--text-xs);
  font-weight: var(--font-weight-medium);
  padding: var(--space-0h) var(--space-2);
  border-radius: var(--radius-full);
}

.meal-type-badge--breakfast { background: var(--meal-breakfast-light); color: var(--meal-breakfast); }
.meal-type-badge--lunch     { background: var(--meal-lunch-light);    color: var(--meal-lunch); }
.meal-type-badge--dinner    { background: var(--meal-dinner-light);   color: var(--meal-dinner); }
.meal-type-badge--snack     { background: var(--meal-snack-light);    color: var(--meal-snack); }

/* --------------------------------------------------------
 * Leer-Zustand (leere Slots im Wochenplan)
 * -------------------------------------------------------- */
.meal-slot--empty {
  opacity: 0.6;
}

/* --------------------------------------------------------
 * Drag & Drop
 * -------------------------------------------------------- */
.meal-card--ghost {
  position: fixed;
  z-index: var(--z-modal);
  pointer-events: none;
  opacity: 0.85;
  box-shadow: var(--shadow-lg);
  transform: rotate(2deg) scale(1.03);
  transition: none;
}

.meal-slot--dragging {
  opacity: 0.35;
}

.meal-slot--drop-target {
  outline: 2px dashed var(--color-accent);
  outline-offset: 2px;
  background: color-mix(in srgb, var(--color-accent) 8%, transparent);
}

@media (prefers-reduced-motion: reduce) {
  .meal-card--ghost {
    transform: none;
  }
}
