:root {
  --bg: #faf7f2;
  --surface: #ffffff;
  --surface-2: #f5efe6;
  --border: #e8e0d3;
  --text: #2d2a26;
  --muted: #7a7268;
  --primary: #c75a3a;
  --primary-hover: #ad4a2e;
  --primary-soft: #fbe9e1;
  --accent: #7a9471;
  --accent-soft: #e8efe5;
  --warn: #d4a548;
  --shadow-sm: 0 1px 2px rgba(45, 42, 38, 0.06), 0 1px 3px rgba(45, 42, 38, 0.04);
  --shadow-md: 0 4px 12px rgba(45, 42, 38, 0.08);
  --shadow-lg: 0 12px 32px rgba(45, 42, 38, 0.12);
  --radius: 10px;
  --radius-lg: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 20px; }
h2 { font-size: 22px; }
h3 { font-size: 16px; }
p { margin: 0; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 14px; }

.muted { color: var(--muted); font-size: 13px; }

/* HEADER */
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}
.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 28px; height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--primary), #e58162);
  display: inline-block;
  position: relative;
}
.brand-mark::after {
  content: "";
  position: absolute;
  inset: 7px;
  border-radius: 50%;
  background: var(--surface);
}

.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 10px; }
.tab {
  background: transparent;
  border: none;
  padding: 8px 14px;
  border-radius: 8px;
  color: var(--muted);
  font-weight: 500;
  font-size: 14px;
  transition: all 0.15s;
}
.tab:hover { color: var(--text); }
.tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

/* MAIN */
.app-main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 20px 80px;
}
.view { display: none; }
.view.active { display: block; }

.view-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 20px;
  gap: 16px;
  flex-wrap: wrap;
}
.view-header h2 { margin-bottom: 4px; }
.view-header .actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* BUTTONS */
.btn {
  border: 1px solid transparent;
  background: var(--surface);
  color: var(--text);
  padding: 9px 14px;
  border-radius: 8px;
  font-weight: 500;
  font-size: 14px;
  transition: all 0.15s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn-primary {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { padding: 6px 10px; font-size: 13px; }
.btn-icon { padding: 6px 8px; }
.btn-danger { color: #b54a3a; }
.btn-danger:hover { background: #fbe9e1; }

/* PLANNER */
.week-nav { display: flex; gap: 6px; align-items: center; }
.portions-control {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 12px;
}
.portions-control input[type="number"] {
  width: 60px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  text-align: center;
  margin: 0 4px;
}
.planner-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.propose-option {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 4px;
}
.propose-option input { margin: 0; }

.day-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 12px 0 0;
}
.day-row {
  display: grid;
  grid-template-columns: 80px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  background: var(--surface-2);
  border-radius: 8px;
}
.day-row-label {
  font-weight: 500;
  font-size: 14px;
  text-transform: capitalize;
}
.day-hint {
  width: 100%;
  padding: 6px 10px;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
}
.day-hint::placeholder { color: var(--muted); opacity: 0.7; }
.time-input {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  color: var(--muted);
}
.time-input input {
  width: 56px;
  padding: 4px 6px;
  text-align: right;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
}
@media (max-width: 540px) {
  .day-row { grid-template-columns: 1fr; }
  .day-row .time-input { justify-self: end; }
}

/* Season + like badges */
.season-badge {
  display: inline-block;
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
}
.season-printemps { background: #e8efe5; color: #4a7a3e; }
.season-ete       { background: #fbe9e1; color: #c75a3a; }
.season-automne   { background: #f5e6d3; color: #a06727; }
.season-hiver     { background: #e6ecf2; color: #4a6a8a; }
.season-all       { background: #f0ece6; color: #7a7268; }

.recipe-card .tag-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 2px;
}
.recipe-card.liked { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent-soft); }
.recipe-card.has-image { padding: 0; overflow: hidden; }
.recipe-card.has-image .card-body { padding: 14px 16px 16px; }
.card-photo {
  width: 100%;
  height: 140px;
  background-size: cover;
  background-position: center;
  background-color: var(--surface-2);
  position: relative;
}
.detail-hero {
  width: calc(100% + 40px);
  height: 220px;
  margin: -20px -20px 16px;
  background-size: cover;
  background-position: center;
  background-color: var(--surface-2);
  position: relative;
}
.rating-overlay {
  position: absolute;
  top: 10px;
  right: 10px;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.rating-overlay .rating-count {
  font-weight: 400;
  opacity: 0.8;
  font-size: 11px;
}
.rating-overlay-lg {
  font-size: 14px;
  padding: 6px 14px;
}
.rating-overlay-lg .rating-count { font-size: 12px; }
.rating-inline {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  background: #fef3c7;
  color: #92400e;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 600;
}
.rating-inline .rating-count { font-weight: 400; opacity: 0.75; }
.tm-badge {
  display: inline-block;
  background: #2d2a26;
  color: #f5efe6;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.mm-badge {
  display: inline-block;
  background: #FF6B35;
  color: #fff;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.recipe-card .like-mark {
  position: absolute;
  top: 12px;
  right: 12px;
  font-size: 14px;
  color: var(--accent);
}
.recipe-card { position: relative; }

.like-controls {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}
.like-btn {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.15s;
}
.like-btn:hover { background: var(--surface-2); }
.like-btn.active-like { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.like-btn.active-dislike { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }

.planner-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 12px;
}
@media (max-width: 900px) {
  .planner-grid { grid-template-columns: 1fr; }
}

.day-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 220px;
}
.day-card.today {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary-soft);
}
.day-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 4px;
}
.day-name { font-weight: 600; font-size: 14px; text-transform: capitalize; }
.day-date { font-size: 12px; color: var(--muted); }

.meal-slot {
  background: var(--surface-2);
  border-radius: 8px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  cursor: pointer;
  transition: all 0.15s;
  border: 1px dashed transparent;
  min-height: 54px;
  justify-content: center;
}
.meal-slot:hover {
  background: var(--primary-soft);
  border-color: var(--primary);
}
.meal-slot.empty {
  background: transparent;
  border: 1px dashed var(--border);
  color: var(--muted);
  align-items: center;
  justify-content: center;
  font-size: 13px;
}
.meal-slot.empty:hover { color: var(--primary); }
.meal-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.meal-name { font-size: 13px; font-weight: 500; line-height: 1.3; }
.meal-portions { font-size: 11px; color: var(--muted); }
.meal-slot .clear-meal {
  position: absolute;
  top: 4px; right: 4px;
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 14px;
  padding: 2px 6px;
  opacity: 0;
  transition: opacity 0.15s;
}
.meal-slot { position: relative; }
.meal-slot:hover .clear-meal { opacity: 1; }
.clear-meal:hover { color: var(--primary); }

/* RECIPES */
.filters {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 20px;
}

/* Suggestions section (top of Recettes view) */
.suggestions-section {
  margin-bottom: 24px;
  padding: 16px;
  background: linear-gradient(135deg, #fef7ed 0%, #fff 100%);
  border: 1px solid #f0e6d2;
  border-radius: 12px;
}
.suggestions-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.suggestions-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}
.suggestions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}
.suggestion-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}
.suggestion-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.06);
}
.suggestion-photo {
  width: 100%;
  height: 100px;
  background-size: cover;
  background-position: center;
  background-color: var(--surface-2);
  position: relative;
}
.suggestion-photo .rating-overlay {
  top: 6px;
  right: 6px;
  font-size: 11px;
  padding: 2px 8px;
}
.suggestion-body {
  padding: 10px 12px 12px;
}
.suggestion-cat {
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
  margin-bottom: 4px;
}
.suggestion-name {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
  margin-bottom: 6px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.suggestion-meta {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 8px;
}
.btn-xs {
  padding: 4px 10px;
  font-size: 11px;
}
.suggestion-add {
  width: 100%;
}

/* Add-to-plan block inside recipe detail */
.add-to-plan {
  margin: 16px 0 12px;
  padding: 12px;
  background: var(--surface-2);
  border-radius: 10px;
}
.add-to-plan h4 {
  font-size: 13px;
  margin: 0;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
}
.plan-form {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.plan-form select {
  flex: 1;
  min-width: 100px;
  padding: 6px 28px 6px 10px;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23999' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}
#recipe-search {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 14px;
}
#recipe-search:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }

.chip-row { display: flex; gap: 6px; flex-wrap: wrap; }

.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}
.filter-row label {
  display: inline-flex;
  flex-direction: column;
  gap: 3px;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
}
.filter-row select {
  padding: 6px 28px 6px 10px;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23999' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  text-transform: none;
}
.filter-row select:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
.filter-row #filter-reset {
  align-self: flex-end;
}

.chip {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
  color: var(--muted);
  transition: all 0.15s;
}
.chip:hover { color: var(--text); }
.chip.active {
  background: var(--text);
  color: var(--surface);
  border-color: var(--text);
}

.recipe-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}
.recipe-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.recipe-card:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}
.recipe-card .cat {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.recipe-card h3 { line-height: 1.3; }
.recipe-card .meta {
  display: flex;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
  margin-top: auto;
  padding-top: 8px;
}

/* SHOPPING */
.shopping-list { display: flex; flex-direction: column; gap: 16px; }
.shopping-category {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.shopping-category-header {
  padding: 12px 16px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.shopping-category-header h3 { font-size: 14px; text-transform: uppercase; letter-spacing: 0.04em; }
.shopping-category-count { font-size: 12px; color: var(--muted); }

.shopping-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}
.shopping-item:last-child { border-bottom: none; }
.shopping-item:hover { background: var(--surface-2); }
.shopping-item input[type="checkbox"] {
  width: 18px; height: 18px;
  accent-color: var(--primary);
  cursor: pointer;
  flex-shrink: 0;
}
.shopping-item.checked .item-name,
.shopping-item.checked .item-qty,
.shopping-item.checked .item-meta {
  text-decoration: line-through;
  color: var(--muted);
}
.item-main { flex: 1; min-width: 0; }
.item-name { font-weight: 500; }
.item-meta { font-size: 12px; color: var(--muted); }
.item-qty {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}
.item-delete {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 4px 8px;
  border-radius: 6px;
  opacity: 0;
  transition: opacity 0.15s;
}
.shopping-item:hover .item-delete { opacity: 1; }
.item-delete:hover { color: var(--primary); background: var(--primary-soft); }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius-lg);
}
.empty-state h3 { color: var(--text); margin-bottom: 6px; }

/* MODAL */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(45, 42, 38, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  max-width: 560px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
}
.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  background: var(--surface);
}
.modal-body { padding: 20px; }
.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  position: sticky;
  bottom: 0;
  background: var(--surface);
}
.close-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  padding: 4px 8px;
  border-radius: 6px;
}
.close-btn:hover { background: var(--surface-2); color: var(--text); }

/* RECIPE PICKER */
.recipe-picker-search {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 12px;
  font-size: 14px;
}
.recipe-picker-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 400px;
  overflow-y: auto;
}
.picker-item {
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: background 0.1s;
}
.picker-item:hover { background: var(--primary-soft); }
.picker-item .picker-cat { font-size: 12px; color: var(--muted); }

/* RECIPE DETAIL */
.recipe-detail .cat-badge {
  display: inline-block;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  margin-bottom: 8px;
}
.recipe-detail h4 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-top: 18px;
  margin-bottom: 8px;
}
.recipe-detail ul { margin: 0; padding-left: 18px; }
.recipe-detail li { padding: 3px 0; }
.recipe-detail p { white-space: pre-wrap; }
.recipe-meta-row {
  display: flex;
  gap: 16px;
  color: var(--muted);
  font-size: 13px;
  margin-top: 4px;
}

/* FORM */
.form-grid { display: flex; flex-direction: column; gap: 14px; }
.form-row { display: flex; flex-direction: column; gap: 5px; }
.form-row label { font-size: 13px; color: var(--muted); font-weight: 500; }
.form-row input, .form-row textarea, .form-row select {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}
.form-row input:focus, .form-row textarea:focus, .form-row select:focus {
  outline: 2px solid var(--primary-soft);
  border-color: var(--primary);
}
.form-row textarea { min-height: 80px; resize: vertical; }
.ingredient-row {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1.2fr auto;
  gap: 6px;
  align-items: center;
}
.ingredient-row input, .ingredient-row select { padding: 7px 10px; font-size: 13px; }
.ingredient-row .remove-ing {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--muted);
  padding: 6px 10px;
}
.ingredient-row .remove-ing:hover { color: var(--primary); border-color: var(--primary); }

/* PRINT */
@media print {
  .app-header, .view-header .actions, .item-delete, .shopping-item input[type="checkbox"] { display: none !important; }
  body { background: white; }
  .shopping-category { break-inside: avoid; border: 1px solid #ccc; }
  .shopping-list { gap: 8px; }
  #planner-view, #recipes-view { display: none !important; }
  #shopping-view { display: block !important; }
}

/* MOBILE */
@media (max-width: 600px) {
  .header-inner { padding: 12px 14px; }
  .app-main { padding: 16px 14px 60px; }
  .view-header { align-items: flex-start; }
  h2 { font-size: 19px; }
  .tab { padding: 7px 11px; font-size: 13px; }
  .ingredient-row { grid-template-columns: 1fr 1fr; }
}
