:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1a1d21;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #16a34a;
  --accent-soft: #dcfce7;
  --chip-bg: #f3f4f6;
  --vegan: #16a34a;
  --vegetarian: #65a30d;
  --meat: #b91c1c;
  --alcohol: #b45309;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}

.app-header {
  padding: 18px 16px 12px;
  padding-top: calc(18px + env(safe-area-inset-top));
  background: var(--accent);
  color: #fff;
}
.app-header h1 { margin: 0; font-size: 1.4rem; font-weight: 700; letter-spacing: -0.01em; }
.subtitle { margin: 4px 0 0; font-size: 0.85rem; opacity: 0.92; }

/* --- Controls (sticky) --- */
.controls {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 16px;
  background: rgba(244, 245, 247, 0.92);
  backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--line);
}

.segmented {
  display: flex;
  gap: 6px;
}
.segmented.wrap { flex-wrap: wrap; }
.segmented button {
  flex: 1 1 auto;
  min-height: 40px;
  padding: 8px 12px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}
.segmented button.active {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}
.segmented button:active { transform: scale(0.98); }
.segmented button:disabled { opacity: 0.4; cursor: default; }
.segmented button:disabled:active { transform: none; }

/* --- Day bar (Mon–Fri of the active week) --- */
.day-bar { display: flex; gap: 6px; }
.day-btn {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  min-height: 50px;
  padding: 7px 2px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
  position: relative;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.day-btn .dow { font-size: 0.7rem; font-weight: 600; color: var(--muted); }
.day-btn .dom { font-size: 0.98rem; font-weight: 700; color: var(--text); }
.day-btn:active { transform: scale(0.97); }
.day-btn.active { background: var(--accent); border-color: var(--accent); }
.day-btn.active .dow, .day-btn.active .dom { color: #fff; }
.day-btn.today::after {
  content: "";
  position: absolute;
  top: 5px;
  right: 6px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
}
.day-btn.active.today::after { background: #fff; }
.day-btn.disabled,
.day-btn:disabled {
  opacity: 0.38;
  cursor: default;
}
.day-btn:disabled:active { transform: none; }

.sort-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.sort-row label { font-size: 0.85rem; color: var(--muted); font-weight: 600; }
.sort-controls { display: flex; gap: 6px; }
#sort-select {
  min-height: 40px;
  padding: 8px 12px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
}
#order-toggle {
  min-width: 44px;
  min-height: 40px;
  font-size: 0.9rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
}

/* --- List --- */
.list {
  max-width: 640px;
  margin: 0 auto;
  padding: 14px 16px 28px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.dish {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
}
.dish-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}
.badges { display: flex; flex-wrap: wrap; gap: 6px; }
.badge {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  padding: 3px 9px;
  border-radius: 999px;
  color: #fff;
}
.badge.vegan { background: var(--vegan); }
.badge.vegetarian { background: var(--vegetarian); }
.badge.meat { background: var(--meat); }
.badge.alcohol { background: var(--alcohol); }

.price {
  flex: 0 0 auto;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
}

.dish-name {
  margin: 2px 0 10px;
  font-size: 1.02rem;
  font-weight: 600;
  line-height: 1.3;
}

.nutrients {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.nutrient {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  min-width: 56px;
  padding: 6px 8px;
  background: var(--chip-bg);
  border-radius: 9px;
  line-height: 1.15;
}
.nutrient .val { font-size: 0.88rem; font-weight: 700; }
.nutrient .lbl { font-size: 0.66rem; color: var(--muted); margin-top: 1px; }
.nutrient.active {
  background: var(--accent-soft);
  outline: 1.5px solid var(--accent);
}
.nutrient.active .lbl { color: var(--accent); }

/* --- States --- */
.state {
  max-width: 640px;
  margin: 0 auto;
  padding: 48px 24px;
  text-align: center;
  color: var(--muted);
}
.state.error { color: var(--meat); }
.state button {
  margin-top: 14px;
  padding: 10px 18px;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 10px;
  cursor: pointer;
}
.spinner {
  width: 26px; height: 26px;
  margin: 0 auto 12px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.app-footer {
  max-width: 640px;
  margin: 0 auto;
  padding: 8px 16px 24px;
  font-size: 0.72rem;
  color: var(--muted);
  text-align: center;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115; --card: #1a1d23; --text: #e7e9ec; --muted: #9aa1ab;
    --line: #2a2f37; --chip-bg: #242830; --accent-soft: #14361f;
  }
  .controls { background: rgba(15, 17, 21, 0.92); }
}
