/* ---------- Base ---------- */

:root {
  --bg: #F5F0E8;
  --surface: #FFFFFF;
  --text: #3A342C;
  --text-muted: #6E6558;
  --border: #E4DBCB;
  --accent-fallback: #A8A296;
  --error-bg: #F6DCD6;
  --error-text: #7A2E20;
  --radius: 10px;
}

* {
  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);
  line-height: 1.5;
}

h1, h2, h3 {
  margin: 0 0 0.5rem;
  font-weight: 700;
}

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1.25rem 3rem;
}

/* ---------- Header / Footer ---------- */

.site-header {
  padding: 2rem 1.25rem 1.5rem;
  text-align: center;
}

.site-header h1 {
  font-size: 1.9rem;
}

.tagline {
  margin: 0;
  color: var(--text-muted);
}

.site-footer {
  text-align: center;
  padding: 2rem 1.25rem;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.site-footer a {
  color: var(--text-muted);
}

/* ---------- Sections ---------- */

section {
  margin-top: 2rem;
}

section h2 {
  font-size: 1.3rem;
  margin-bottom: 1rem;
}

.section-heading-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.section-heading-row h2 {
  margin-bottom: 0;
}

.save-day-btn {
  background: var(--surface);
  border: 2px solid var(--text-muted);
  color: var(--text);
  padding: 0.45rem 0.9rem;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 1rem;
}

.save-day-btn:hover {
  background: var(--border);
}

/* ---------- Cuisine selector ---------- */

.cuisine-selector {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 1.25rem;
  max-width: 320px;
}

.cuisine-selector label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

#cuisine-select {
  border: 2px solid var(--accent-select, var(--accent-fallback));
  background: var(--surface);
  color: var(--text);
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  font-size: 1rem;
  cursor: pointer;
}

/* ---------- Status area (loading / error / empty) ---------- */

.status-area:empty {
  display: none;
}

.status-area {
  padding: 0.9rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1.25rem;
  font-size: 0.95rem;
}

.status-area.loading {
  background: var(--surface);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.status-area.error {
  background: var(--error-bg);
  color: var(--error-text);
}

.status-area.empty {
  background: var(--surface);
  color: var(--text-muted);
}

.spinner {
  width: 1rem;
  height: 1rem;
  border: 2px solid var(--border);
  border-top-color: var(--text-muted);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ---------- Dish grid ---------- */

.dishes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
}

.dish-card {
  background: var(--surface);
  border: 2px solid var(--accent, var(--accent-fallback));
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  cursor: pointer;
}

.dish-card:focus-visible {
  outline: 2px solid var(--accent, var(--accent-fallback));
  outline-offset: 2px;
}

.dish-card img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  display: block;
  background: var(--border);
}

.dish-card-body {
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  flex: 1;
}

.dish-card-body h3 {
  font-size: 1rem;
  margin: 0;
}

.add-btn {
  margin-top: auto;
  align-self: flex-start;
  background: var(--accent, var(--accent-fallback));
  border: none;
  color: var(--text);
  padding: 0.45rem 0.85rem;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.add-btn:hover {
  filter: brightness(0.94);
}

.add-btn:disabled {
  opacity: 0.6;
  cursor: default;
}

/* ---------- Meal plan list ---------- */

.meal-plan-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.plan-item {
  background: var(--surface);
  border-left: 5px solid var(--accent, var(--accent-fallback));
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
}

.plan-item-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.plan-item-header img {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 6px;
  flex-shrink: 0;
}

.plan-item-header h3 {
  font-size: 1rem;
  margin: 0;
  flex: 1;
}

.plan-item-header .cuisine-tag {
  font-size: 0.75rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

.remove-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.8rem;
  text-decoration: underline;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
}

.remove-btn:hover {
  color: var(--error-text);
}

.plan-item details {
  margin-top: 0.6rem;
}

.plan-item summary {
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.plan-item ul.ingredients {
  margin: 0.5rem 0 0;
  padding-left: 1.1rem;
  font-size: 0.88rem;
}

/* ---------- Saved days ---------- */

.saved-days-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.saved-day-item {
  background: var(--surface);
  border: 2px solid var(--border);
  border-left: 5px solid var(--accent-fallback);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.saved-day-item .saved-day-name {
  font-weight: 600;
  flex: 1;
  cursor: pointer;
}

.saved-day-item .saved-day-name:hover {
  text-decoration: underline;
}

.saved-day-item .saved-day-name:focus-visible {
  outline: 2px solid var(--accent-fallback);
  outline-offset: 2px;
}

.saved-day-item .saved-day-count {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.saved-day-item.active {
  background: var(--bg);
  border-color: var(--text);
}

.edit-day-btn {
  background: none;
  border: none;
  color: var(--text);
  font-size: 0.8rem;
  text-decoration: underline;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
}

.edit-day-btn:hover {
  color: var(--accent-fallback);
}

.active-day-indicator {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: -0.5rem 0 1rem;
}

.active-day-indicator:empty {
  display: none;
}

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

.shopping-list {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
}

.shopping-list li {
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.92rem;
}

.shopping-list li:last-child {
  border-bottom: none;
}

/* ---------- Meal detail modal ---------- */

body.modal-open {
  overflow: hidden;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(58, 52, 44, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 1000;
}

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

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  width: 100%;
  max-width: 600px;
  max-height: 85vh;
  overflow-y: auto;
  position: relative;
  padding: 1.5rem;
}

.modal-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  background: var(--bg);
  border: none;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  color: var(--text);
}

.modal-thumb {
  width: 100%;
  height: 200px;
  object-fit: cover;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  background: var(--border);
}

.modal-body h3 {
  font-size: 1.3rem;
  padding-right: 2rem;
}

.modal-meta {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin: 0 0 1.25rem;
}

.modal-body h4 {
  font-size: 1rem;
  margin: 1.25rem 0 0.5rem;
}

.modal-body ul.ingredients {
  margin: 0;
  padding-left: 1.1rem;
  font-size: 0.92rem;
}

.modal-instructions {
  white-space: pre-line;
  font-size: 0.92rem;
  line-height: 1.6;
}

/* ---------- Save-to-day modal ---------- */

.modal-form h3 {
  padding-right: 2rem;
}

.modal-input {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  margin: 0.75rem 0 1.25rem;
}

.modal-input:focus {
  outline: none;
  border-color: var(--accent-fallback);
}

.modal-form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
}

.modal-cancel-btn {
  background: var(--surface);
  border: 2px solid var(--text-muted);
  color: var(--text);
  padding: 0.5rem 1rem;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.modal-cancel-btn:hover {
  background: var(--border);
}

.modal-save-btn {
  background: var(--accent-fallback);
  border: none;
  color: var(--text);
  padding: 0.5rem 1rem;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.modal-save-btn:hover {
  filter: brightness(0.94);
}

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

@media (max-width: 480px) {
  .site-header h1 {
    font-size: 1.5rem;
  }

  .dishes-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 0.75rem;
  }

  .plan-item-header {
    flex-wrap: wrap;
  }

  .modal {
    padding: 1.1rem;
    max-height: 90vh;
  }
}
