/* ---------- Shell ---------- */

body.app {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.meal-app {
  width: min(1200px, 100%);
  min-height: calc(100vh - 48px);
  display: grid;
  grid-template-columns: 82px 1fr;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

/* ---------- Sidebar ---------- */

.app-sidebar {
  background: var(--sidebar);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 18px 0 16px;
  border-right: 1px solid var(--border);
}

.app-sidebar .logo {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--primary);
  color: var(--primary-ink);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 6px;
  flex-shrink: 0;
}

.app-sidebar .logo svg { width: 16px; height: 16px; }

.app-sidebar .brand {
  font-size: 10px;
  font-weight: 800;
  color: var(--primary);
  margin-bottom: 18px;
  letter-spacing: 0.01em;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
  align-items: center;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  width: 62px;
  min-height: 58px;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
  border-radius: 9px;
  cursor: pointer;
  position: relative;
  text-decoration: none;
  transition: background .15s ease, color .15s ease, transform .1s ease;
}

.nav-item .nav-icon { width: 18px; height: 18px; }
.nav-item .nav-icon svg { width: 100%; height: 100%; }

.nav-item:hover { color: var(--primary); }
.nav-item:active { transform: scale(0.93); }

.nav-item.active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: 0 2px 8px rgba(12, 140, 128, .14);
}

.nav-item.active::before {
  content: "";
  position: absolute;
  left: -1px;
  top: 10px;
  bottom: 10px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--primary);
}

/* ---------- Theme toggle ---------- */

.theme-toggle {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}

.theme-toggle:hover { color: var(--primary); border-color: var(--primary); }
.theme-toggle svg { width: 17px; height: 17px; }

.theme-toggle .icon-sun { display: none; }
.theme-toggle .icon-moon { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

.sidebar-theme-toggle { margin-top: auto; }

.theme-toggle--floating {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 5;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

/* ---------- Language switcher ---------- */

.lang-switcher {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.lang-link {
  min-width: 30px;
  padding: 5px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-align: center;
  text-decoration: none;
  color: var(--muted);
  transition: background .15s ease, color .15s ease;
}

.lang-link:hover { color: var(--primary); }

.lang-link.active {
  background: var(--primary);
  color: var(--primary-ink);
}

.lang-switcher--floating {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 5;
  box-shadow: var(--shadow-sm);
}

/* ---------- Main column ---------- */

.app-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--page-bg);
}

.app-header {
  padding: 22px 24px 14px;
}

.app-header h1 {
  color: var(--text);
  margin: 0 0 4px;
  font-size: 21px;
}

.app-header-sub {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

.app-header-sub a, .link-btn {
  color: var(--primary);
  font-weight: 700;
}

.link-btn {
  border: none;
  background: none;
  font-size: 13px;
  cursor: pointer;
  padding: 0;
}

.app-content {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  padding: 4px 24px 32px;
  position: relative;
}

.app-content::-webkit-scrollbar { width: 8px; }
.app-content::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }

.alert p { margin: 0; }

.empty-state {
  text-align: center;
  padding: 48px 16px;
  color: var(--muted);
}

.empty-state p { margin: 0 0 6px; }
.lede-small { font-size: 13px; color: var(--muted); }

/* ---------- Dish icon circles (shared) ---------- */

.dish-icon {
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  line-height: 1;
}

/* ---------- Dish list (index.php) ---------- */

.search-field { margin-top: 4px; }

.search-field input {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  padding: 11px 16px;
  font-size: 15px;
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.dish-list {
  list-style: none;
  margin: 16px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.dish-card[hidden] { display: none; }

.dish-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 12px 16px;
  transition: transform .15s ease, border-color .15s ease;
}

.dish-card:hover { transform: translateY(-2px); border-color: var(--primary); box-shadow: var(--shadow); }

.dish-card .dish-icon { width: 46px; height: 46px; }

.dish-card-body { flex: 1; min-width: 0; }

.dish-name {
  display: block;
  font-weight: 700;
  font-size: 15px;
  margin-bottom: 8px;
  color: var(--text);
  text-decoration: none;
}

.dish-ratings {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.rate-chip {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: var(--page-bg);
  color: var(--text);
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
}

.rate-chip:active { transform: scale(0.94); }

.rate-chip.score-0 { opacity: 0.6; }
.rate-chip.score-1 { background: var(--danger); border-color: var(--danger); color: #fff; box-shadow: var(--shadow-sm); }
.rate-chip.score-2 { background: var(--warning); border-color: var(--warning); color: var(--warning-ink); box-shadow: var(--shadow-sm); }
.rate-chip.score-3 { background: var(--success); border-color: var(--success); color: #fff; box-shadow: var(--shadow-sm); }

/* ---------- Buttons ---------- */

.fab {
  position: absolute;
  right: 8px;
  bottom: 8px;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: none;
  font-size: 26px;
  line-height: 1;
  color: var(--primary-ink);
  background: var(--primary);
  box-shadow: var(--shadow-primary), var(--shadow);
  cursor: pointer;
  transition: transform .15s ease;
}

.fab:hover { transform: translateY(-1px); }
.fab:disabled { opacity: 0.4; cursor: default; box-shadow: var(--shadow); transform: none; }

.secondary-btn {
  display: block;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--muted);
  padding: 12px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s ease, color .15s ease, transform .1s ease;
}

.secondary-btn:hover { background: var(--primary-soft); color: var(--primary); }
.secondary-btn:active { transform: scale(0.97); }

.primary-btn {
  display: block;
  width: 100%;
  border: none;
  border-radius: 10px;
  padding: 14px;
  font-size: 15px;
  font-weight: 700;
  color: var(--primary-ink);
  background: var(--primary);
  cursor: pointer;
  box-shadow: var(--shadow-primary);
  transition: background .15s ease, transform .15s ease;
}

.primary-btn:hover { background: var(--primary-hover); transform: translateY(-1px); }
.primary-btn:active { transform: scale(0.98); }
.primary-btn:disabled { opacity: 0.5; cursor: default; box-shadow: none; transform: none; }

.logout-link {
  display: block;
  text-align: center;
  margin-top: 24px;
  padding: 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--danger);
  text-decoration: none;
}

/* ---------- Sheet / modal ---------- */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(15, 30, 27, .45);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.sheet[hidden] { display: none; }

.sheet-form {
  width: 100%;
  max-width: 460px;
  background: var(--surface);
  color: var(--text);
  border-radius: 18px 18px 0 0;
  padding: 22px 20px calc(22px + env(safe-area-inset-bottom));
  box-shadow: var(--shadow);
}

.sheet-actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}

.sheet-actions .secondary-btn,
.sheet-actions .primary-btn { flex: 1; }

/* ---------- Forms ---------- */

.field-label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
  color: var(--muted);
}

.setup-form { max-width: 480px; }

.setup-form input[type="number"],
.setup-form input[type="text"],
.setup-form textarea {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 16px;
  color: var(--text);
  margin-bottom: 10px;
  font-family: inherit;
  resize: vertical;
  box-shadow: var(--shadow-sm);
}

.person-rows { margin-top: 12px; }

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
}

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

.child-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

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

.child-row input[type="text"] { flex: 2; }
.child-row input[type="number"] { flex: 1; }

.icon-counter {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 9px;
}

.icon-btn svg { width: 100%; height: 100%; }
.icon-btn:active { transform: scale(0.94); }
.icon-btn[hidden] { display: none; }

.icon-btn.adult-icon {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-ink);
  box-shadow: var(--shadow-sm);
}

.icon-btn.child-icon {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  box-shadow: var(--shadow-sm);
}

.icon-btn.plus-btn {
  background: transparent;
  border-style: dashed;
  color: var(--muted);
  padding: 11px;
}

/* ---------- Week navigation ---------- */

.week-nav {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.week-nav-btn {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
}

.week-nav-btn svg { width: 16px; height: 16px; }
.week-nav-btn:active { transform: scale(0.94); }

.week-nav-label {
  font-weight: 700;
  font-size: 14px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.week-nav-current {
  margin-left: auto;
  font-size: 12px;
  font-weight: 700;
  color: var(--primary);
}

/* ---------- Week plan ---------- */

.week-plan {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 16px;
}

.day-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.day-card-head {
  padding: 13px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
}

.day-card-head .day-title, .day-title {
  color: var(--text);
  margin: 0;
  font-size: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.day-card-head.today { background: var(--primary-soft); }

.today-badge {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--primary-ink);
  background: var(--primary);
  border-radius: 999px;
  padding: 3px 9px;
}

.meal-row {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

.meal-row:last-child { border-bottom: none; }

.meal-row-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.meal-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.meal-row-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.meal-portions {
  font-size: 11px;
  font-weight: 700;
  color: var(--primary);
  background: var(--primary-soft);
  border-radius: 999px;
  padding: 3px 10px;
  white-space: nowrap;
}

/* Per-meal generate button — one for lunch, one for dinner, so generating an
   idea for one never touches the other (used to be a single day-level button
   that regenerated both meals at once). */
.meal-generate-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}

.meal-generate-btn svg { width: 14px; height: 14px; }
.meal-generate-btn:disabled { opacity: 0.4; cursor: default; box-shadow: none; }

.meal-clear-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
}

.meal-clear-btn svg { width: 14px; height: 14px; }
.meal-clear-btn:active { transform: scale(0.94); background: var(--danger); color: #fff; border-color: var(--danger); }
.meal-clear-btn:disabled { opacity: 0.4; cursor: default; }
.meal-clear-btn[hidden] { display: none; }

.meal-dish { margin-bottom: 4px; }

.meal-filled {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.meal-filled .dish-icon { width: 38px; height: 38px; }

.meal-dish-name {
  font-weight: 700;
  font-size: 15px;
  text-decoration: none;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.meal-dish-empty {
  color: var(--muted);
  font-size: 13px;
  font-style: italic;
}

.meal-toggle-btn {
  border: none;
  background: none;
  padding: 0;
  font-size: 12px;
  font-weight: 700;
  color: var(--primary);
  cursor: pointer;
}

.meal-row.is-empty .meal-toggle-btn {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 7px 14px;
  border: 1.5px dashed var(--border);
  border-radius: 999px;
  color: var(--muted);
}

.meal-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.meal-controls[hidden] { display: none; }

.slot-pick-form select {
  font-size: 12px;
  color: var(--text);
  background: var(--page-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 6px;
  max-width: 160px;
}

.new-dish-toggle-btn { display: block; margin-top: 10px; font-size: 12px; }

.new-dish-form {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.new-dish-form input[type="text"],
.new-dish-form textarea {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 14px;
  color: var(--text);
  font-family: inherit;
  resize: vertical;
  box-shadow: var(--shadow-sm);
}

.new-dish-form .primary-btn { font-size: 13px; padding: 10px; }

.meal-members {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.presence-chip {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 10px;
  font-weight: 700;
  font-size: 12px;
  cursor: pointer;
}

.presence-chip:active { transform: scale(0.94); }

.presence-chip.adult-chip {
  background: var(--primary);
  color: var(--primary-ink);
  box-shadow: var(--shadow-sm);
}

.presence-chip.child-chip {
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: var(--shadow-sm);
}

.presence-chip.absent {
  opacity: 0.5;
  background: transparent;
  border: 1.5px solid var(--border);
  color: var(--muted);
}

/* ---------- Leftovers ---------- */

.leftover-form { margin-bottom: 20px; }

.leftover-form .field {
  display: flex;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px;
  box-shadow: var(--shadow-sm);
}

.leftover-form input[type="text"] {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  padding: 10px 10px 10px 14px;
  font-size: 16px;
  color: var(--text);
}

.mic-btn {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border: none;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mic-btn.listening {
  background: var(--primary);
  color: var(--primary-ink);
  box-shadow: var(--shadow-primary);
}

.leftover-form button[type="submit"] {
  border: none;
  border-radius: 999px;
  padding: 0 18px;
  font-size: 14px;
  font-weight: 700;
  color: var(--primary-ink);
  background: var(--primary);
  cursor: pointer;
  box-shadow: var(--shadow-primary);
}

.leftover-list,
.shopping-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.shopping-group { margin-bottom: 20px; }
.shopping-group:last-child { margin-bottom: 0; }

.shopping-group-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 0 0 8px 4px;
}

.shopping-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 14px;
  box-shadow: var(--shadow-sm);
}

.shopping-item .checkbox-row { min-height: 48px; }
.shopping-item.checked .checkbox-row span { text-decoration: line-through; color: var(--muted); }

.leftover-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 6px 4px 14px;
  font-size: 14px;
  box-shadow: var(--shadow-sm);
}

.leftover-item.used { opacity: 0.55; }

.leftover-tag {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  background: var(--warning);
  color: var(--warning-ink);
  border-radius: 999px;
  padding: 3px 8px;
  margin-left: 4px;
  vertical-align: 2px;
}

.remove-leftover {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---------- Dish detail ---------- */

.back-link {
  display: inline-block;
  margin-bottom: 8px;
  font-size: 13px;
  color: var(--muted);
  text-decoration: none;
}

.dish-hero {
  display: flex;
  justify-content: center;
  margin: 8px auto 18px;
}

.recipe-text {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 16px;
  font-size: 15px;
  line-height: 1.6;
  white-space: pre-line;
}

/* ---------- Responsive ---------- */

@media (max-width: 900px) {
  .meal-app { grid-template-columns: 72px 1fr; }
}

@media (max-width: 760px) {
  body.app { padding: 0; }

  .meal-app {
    width: 100%;
    min-height: 100vh;
    grid-template-columns: 1fr;
    border-radius: 0;
    overflow: visible;
  }

  /* Pinned to the viewport, out of normal flow — the page itself scrolls
     underneath it (see .app-content's bottom padding, which reserves room
     for this bar so content never ends up hidden behind it). */
  .app-sidebar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10;
    flex-direction: row;
    width: 100%;
    padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
    border-right: none;
    border-top: 1px solid var(--border);
    justify-content: space-around;
  }

  .app-sidebar .logo, .app-sidebar .brand { display: none; }
  .sidebar-nav { flex-direction: row; justify-content: space-around; flex: 1; }
  .nav-item { width: auto; flex: 1; min-height: 56px; }
  .sidebar-theme-toggle { margin-top: 0; margin-left: 4px; }

  /* Let the page itself scroll instead of this inner region — on mobile
     .app-main has no fixed height, so an inner overflow:auto here never
     actually had anything to scroll and just ate the touch gesture. */
  .app-content { overflow-y: visible; padding: 4px 16px 96px; }
  .fab { position: fixed; right: 20px; bottom: 84px; }
}
