:root {
  --bg: #FFF8F0;
  --surface: #FFFFFF;
  --rose: #FFD6E0;
  --menthe: #C8F7DC;
  --jaune: #FFF3B0;
  --lavande: #DCCBFF;
  --bleu: #CDE7FF;
  --corail: #FFB5A7;
  --text: #2F2F2F;
  --muted: #6B7280;
  --border: #F0E6DC;
  --shadow: 0 6px 20px rgba(47,47,47,.06);
  --shadow-lg: 0 12px 32px rgba(47,47,47,.12);
  --grad: linear-gradient(135deg, #FFB5A7, #FFD6E0);
  --radius: 20px;
  --radius-sm: 14px;
  --font-head: 'Quicksand', sans-serif;
  --font-body: 'Inter', sans-serif;
  --bg-soft: rgba(255, 182, 193, .14);
}

[data-theme="dark"] {
  --bg: #1F2937;
  --surface: #374151;
  --rose: #4c3a44;
  --menthe: #2f4a3a;
  --jaune: #4a4528;
  --lavande: #3d3550;
  --bleu: #33485a;
  --corail: #FFB5A7;
  --text: #F9FAFB;
  --muted: #D1D5DB;
  --border: #4B5563;
  --shadow: 0 6px 20px rgba(0,0,0,.25);
  --shadow-lg: 0 12px 32px rgba(0,0,0,.35);
  --bg-soft: rgba(255,181,167,.12);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  transition: background .4s ease, color .4s ease;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { font-family: var(--font-head); margin: 0; }

.app { display: flex; min-height: 100vh; }
.main { flex: 1; margin-left: 240px; transition: margin .3s ease; }
.main.collapsed { margin-left: 76px; }

.page { padding: 28px 32px 40px; max-width: 1200px; margin: 0 auto; }
.page-title { font-size: 28px; font-weight: 700; }
.page-sub { color: var(--muted); margin: 6px 0 0; }

/* Layout grid helpers */
.grid { display: grid; gap: 16px; }
.grid-stats { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.grid-recipes { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }

.mt0 { margin-top: 0; }
.mt8 { margin-top: 8px; }
.mt16 { margin-top: 16px; }
.mt24 { margin-top: 24px; }
.mb16 { margin-bottom: 16px; }
.flex { display: flex; align-items: center; gap: 8px; }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }

/* Sidebar */
.sidebar {
  position: fixed; left: 0; top: 0; bottom: 0; width: 240px;
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 24px 16px; display: flex; flex-direction: column; gap: 6px;
  z-index: 40; transition: width .3s ease, transform .3s ease;
  box-shadow: var(--shadow);
}
.sidebar.collapsed { width: 76px; }
.logo { display: flex; align-items: center; gap: 10px; padding: 4px 10px 20px; }
.logo-mark {
  width: 40px; height: 40px; border-radius: 12px;
  background: var(--grad); display: grid; place-items: center; color: #fff;
  flex-shrink: 0;
}
.logo-name { font-family: var(--font-head); font-weight: 700; font-size: 20px; }
.sidebar.collapsed .logo-name, .sidebar.collapsed .nav-label, .sidebar.collapsed .collapse-label { display: none; }

.nav-link {
  display: flex; align-items: center; gap: 12px; padding: 12px 12px;
  border-radius: var(--radius-sm); color: var(--muted); text-decoration: none;
  font-weight: 600; border: none; background: none; cursor: pointer; width: 100%;
  font-size: 15px; transition: background .2s, color .2s; font-family: var(--font-body);
}
.nav-link:hover { background: var(--bg-soft); color: var(--text); }
.nav-link.active { background: var(--grad); color: #4a2e2a; }
.sidebar.collapsed .nav-link { justify-content: center; }
.sidebar-spacer { flex: 1; }
.nav-foot { margin-top: auto; }

/* Bottom nav (mobile) */
.bottom-nav {
  display: none; position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--surface); border-top: 1px solid var(--border);
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); z-index: 40;
  justify-content: space-around;
}
.bottom-nav .bn-item {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: none; border: none; color: var(--muted); font-size: 11px;
  font-weight: 600; cursor: pointer; font-family: var(--font-body); padding: 4px 6px;
  border-radius: 12px;
}
.bottom-nav .bn-item.active { color: #e0717f; }
.bottom-nav .bn-item.active svg { color: #e0717f; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: none; cursor: pointer; font-family: var(--font-head); font-weight: 700;
  border-radius: 999px; padding: 12px 20px; font-size: 15px; transition: transform .15s, box-shadow .2s, opacity .2s;
  text-decoration: none;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--grad); color: #4a2e2a; box-shadow: 0 4px 14px rgba(255,181,167,.4); }
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(255,181,167,.5); }
.btn-secondary { background: var(--surface); color: var(--text); border: 1.5px solid var(--border); }
.btn-secondary:hover { border-color: var(--corail); background: var(--bg-soft); }
.btn-success { background: var(--menthe); color: #1f5c3a; }
.btn-ghost { background: none; color: var(--muted); }
.btn-danger { background: #fee2e2; color: #b91c1c; }
.btn-sm { padding: 8px 14px; font-size: 13px; }
.btn-icon { padding: 9px; border-radius: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

/* Cards */
.card {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); border: 1px solid var(--border);
  animation: fadeUp .4s ease both;
}
@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* Stat card */
.stat-card { padding: 18px; display: flex; flex-direction: column; gap: 10px; }
.stat-icon { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; }
.stat-value { font-family: var(--font-head); font-size: 26px; font-weight: 700; }
.stat-label { color: var(--muted); font-size: 13px; }

/* Recipe card */
.recipe-card { overflow: hidden; cursor: pointer; display: flex; flex-direction: column; }
.recipe-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); }
.recipe-thumb { height: 150px; background: linear-gradient(135deg, var(--lavande), var(--bleu)); display: grid; place-items: center; font-size: 44px; position: relative; background-size: cover; background-position: center; }
.recipe-thumb .thumb-icon { filter: drop-shadow(0 4px 8px rgba(0,0,0,.12)); }
.recipe-body { padding: 14px 14px 16px; display: flex; flex-direction: column; gap: 8px; }
.recipe-name { font-weight: 700; font-size: 17px; }
.recipe-meta { display: flex; gap: 12px; color: var(--muted); font-size: 12.5px; font-weight: 600; }
.recipe-meta span { display: inline-flex; align-items: center; gap: 4px; }
.recipe-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.fav-btn { position: absolute; top: 10px; right: 10px; background: rgba(255,255,255,.85); border: none; width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; cursor: pointer; }
.fav-btn.on { color: #e0717f; }

/* Badges */
.badge { display: inline-flex; align-items: center; padding: 4px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 700; font-family: var(--font-head); }
.badge-rose { background: var(--rose); color: #8a3a4a; }
.badge-menthe { background: var(--menthe); color: #1f5c3a; }
.badge-jaune { background: var(--jaune); color: #7a6420; }
.badge-lavande { background: var(--lavande); color: #4a3580; }
.badge-bleu { background: var(--bleu); color: #2a5070; }
.badge-corail { background: var(--corail); color: #7a2a20; }
.badge-soft { background: var(--bg-soft); color: var(--muted); }
[data-theme="dark"] .badge-rose, [data-theme="dark"] .badge-menthe, [data-theme="dark"] .badge-jaune, [data-theme="dark"] .badge-lavande, [data-theme="dark"] .badge-bleu, [data-theme="dark"] .badge-corail { color: var(--text); }

/* Category pilule color */
.category-pil { display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 999px; border: 1.5px solid var(--border); background: var(--surface); cursor: pointer; font-family: var(--font-head); font-weight: 700; font-size: 13px; color: var(--text); transition: background .2s; }
.category-pil.active { background: var(--grad); border-color: transparent; color: #4a2e2a; }

/* Filters */
.filters-bar { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.filters-inline { padding: 18px; }
.filters-mobile { display: none; padding: 12px; }
@media (max-width: 767px) {
  .filters-inline { display: none; }
  .filters-mobile { display: block; }
}
.field { display: flex; flex-direction: column; gap: 6px; min-width: 140px; }
.field label { font-size: 12px; font-weight: 700; color: var(--muted); font-family: var(--font-head); }
.input, .select, .textarea {
  font-family: var(--font-body); font-size: 14.5px; padding: 11px 14px;
  border-radius: 12px; border: 1.5px solid var(--border); background: var(--surface);
  color: var(--text); width: 100%; transition: border .2s, box-shadow .2s;
}
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--corail); box-shadow: 0 0 0 3px rgba(255,181,167,.25); }
.textarea { resize: vertical; min-height: 90px; }

/* Search */
.search-wrap { position: relative; flex: 1; min-width: 200px; }
.search-wrap svg { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search-wrap .input { padding-left: 40px; }

/* Toggle */
.toggle { position: relative; width: 48px; height: 27px; border-radius: 999px; background: var(--border); border: none; cursor: pointer; transition: background .2s; }
.toggle::after { content: ''; position: absolute; top: 3px; left: 3px; width: 21px; height: 21px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.toggle.on { background: var(--corail); }
.toggle.on::after { transform: translateX(21px); }

/* Progress */
.progress { height: 10px; border-radius: 999px; background: var(--border); overflow: hidden; }
.progress-fill { height: 100%; border-radius: 999px; background: var(--menthe); transition: width .4s ease; }

/* Modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(30,30,30,.45); display: grid; place-items: center; z-index: 100; padding: 16px; animation: fadeIn .2s ease; }
.modal { background: var(--surface); border-radius: 22px; max-width: 520px; width: 100%; max-height: 88vh; overflow: auto; box-shadow: var(--shadow-lg); animation: fadeUp .25s ease; }
.modal-head { padding: 20px 22px 0; display: flex; align-items: center; justify-content: space-between; }
.modal-body { padding: 16px 22px 24px; }

/* Drawer (mobile filters) */
.drawer-overlay { position: fixed; inset: 0; background: rgba(30,30,30,.4); z-index: 110; animation: fadeIn .2s ease; }
.drawer { position: fixed; left: 0; right: 0; bottom: 0; background: var(--surface); border-radius: 22px 22px 0 0; padding: 20px 20px 30px; z-index: 111; animation: slideUp .3s ease; max-height: 85vh; overflow: auto; }

/* Toast */
.toast-wrap { position: fixed; top: 20px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--surface); color: var(--text); border-radius: 14px; padding: 12px 18px; box-shadow: var(--shadow-lg); border-left: 4px solid var(--menthe); font-weight: 600; display: flex; align-items: center; gap: 10px; animation: fadeUp .3s ease; }
.toast.error { border-left-color: #ff6b6b; }
.toast.info { border-left-color: var(--bleu); }

/* Empty state */
.empty { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty-icon { font-size: 64px; margin-bottom: 16px; opacity: .5; }
.empty h3 { color: var(--text); margin-bottom: 8px; }

/* FAB */
.fab {
  position: fixed; right: 20px; bottom: 84px; width: 58px; height: 58px;
  border-radius: 50%; background: var(--grad); border: none; color: #4a2e2a;
  display: grid; place-items: center; box-shadow: 0 8px 24px rgba(255,181,167,.5);
  cursor: pointer; z-index: 45; transition: transform .15s;
}
.fab:hover { transform: scale(1.08); }

/* Planning table */
.planner { display: flex; flex-direction: column; gap: 18px; }
.day-card { border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); overflow: hidden; border: 1px solid var(--border); }
.day-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; cursor: pointer; background: var(--bg-soft); font-family: var(--font-head); font-weight: 700; }
.day-head.today { background: var(--grad); color: #4a2e2a; }
.day-meals { padding: 14px; display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(220px,1fr)); }
.meal-slot { display: flex; flex-direction: column; gap: 8px; }
.meal-label { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; font-family: var(--font-head); }
.meal-box { border: 1.5px dashed var(--border); border-radius: var(--radius-sm); padding: 12px; min-height: 76px; display: flex; align-items: center; }
.meal-empty { color: var(--muted); margin: auto; font-size: 13px; cursor: pointer; }
.meal-filled { width: 100%; display: flex; flex-direction: column; gap: 6px; }
.meal-name { font-family: var(--font-head); font-weight: 700; }
.meal-meta { font-size: 12px; color: var(--muted); display: flex; gap: 10px; }
.meal-actions { display: flex; gap: 6px; margin-top: 4px; }
.meal-actions button { border: none; background: var(--bg-soft); width: 26px; height: 26px; border-radius: 8px; cursor: pointer; display: grid; place-items: center; color: var(--muted); }
.meal-actions button:hover { background: var(--rose); color: var(--text); }

/* Planner desktop table */
.planner-table { display: none; width: 100%; border-collapse: separate; border-spacing: 10px; }
.planner-table th, .planner-table td { vertical-align: top; }
.planner-table .meal-col { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 10px; box-shadow: var(--shadow); min-height: 110px; }
.planner-table th { font-family: var(--font-head); font-weight: 700; padding: 6px 10px; text-align: left; }
.planner-table .today-cell { outline: 2px solid var(--corail); }

/* Shopping */
.shop-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px,1fr)); gap: 16px; }
.shop-cat { border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); border: 1px solid var(--border); background: var(--surface); }
.shop-cat-head { display: flex; align-items: center; gap: 8px; font-family: var(--font-head); font-weight: 700; margin-bottom: 10px; }
.shop-item { display: flex; align-items: center; gap: 10px; padding: 8px 4px; border-bottom: 1px dashed var(--border); }
.shop-item:last-child { border-bottom: none; }
.checkbox { width: 22px; height: 22px; border-radius: 7px; border: 2px solid var(--border); cursor: pointer; display: grid; place-items: center; background: var(--surface); flex-shrink: 0; transition: background .15s; }
.checkbox.checked { background: var(--menthe); border-color: var(--menthe); color: #1f5c3a; }
.shop-name.done { text-decoration: line-through; color: var(--muted); opacity: .7; }
.shop-qty { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.shop-qty button { border: none; background: var(--bg-soft); width: 24px; height: 24px; border-radius: 7px; cursor: pointer; }
.shop-price { font-size: 12px; color: var(--muted); width: 52px; text-align: right; }

/* Recipe detail */
.detail-hero { border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); background: var(--surface); }
.detail-banner { height: 260px; background: linear-gradient(135deg, var(--lavande), var(--bleu)); display: grid; place-items: center; font-size: 90px; background-size: cover; background-position: center; }
.detail-content { padding: 24px 28px; }
.detail-stats { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 14px; }
.stat-chip { display: flex; align-items: center; gap: 8px; background: var(--bg-soft); padding: 10px 16px; border-radius: 14px; font-weight: 600; }
.detail-sec { margin-top: 28px; }
.detail-sec h3 { margin-bottom: 12px; font-size: 18px; }
.ing-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; background: var(--bg-soft); border-radius: 12px; margin-bottom: 8px; }
.step-item { display: flex; gap: 14px; margin-bottom: 14px; }
.step-num { width: 30px; height: 30px; border-radius: 50%; background: var(--grad); color: #4a2e2a; font-weight: 700; display: grid; place-items: center; flex-shrink: 0; font-family: var(--font-head); }

/* Form */
.form { display: flex; flex-direction: column; gap: 18px; }
.form-row { display: flex; flex-direction: column; gap: 16px; }
@media (min-width: 640px) { .form-row.two { flex-direction: row; } .form-row.two .field { flex: 1; } }
.form-sec { border: 1.5px solid var(--border); border-radius: var(--radius); padding: 18px; }
.form-sec h3 { margin-bottom: 14px; display: flex; align-items: center; gap: 8px; }
.dyn-row { display: grid; gap: 8px; grid-template-columns: 1fr; }
@media (min-width: 640px) { .dyn-row { grid-template-columns: 1fr 80px 120px auto; align-items: end; } }
.add-line-btn { border: 1.5px dashed var(--border); background: none; border-radius: 12px; padding: 10px; cursor: pointer; color: var(--muted); font-family: var(--font-head); font-weight: 700; }
.add-line-btn:hover { border-color: var(--corail); color: var(--text); }
.del-btn { background: none; border: none; color: var(--muted); cursor: pointer; padding: 10px; }
.del-btn:hover { color: #e0717f; }

.action-bar { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 12px; }

/* Settings rows */
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 16px 4px; border-bottom: 1px solid var(--border); }
.setting-row:last-child { border-bottom: none; }
.setting-label h4 { font-size: 15px; }
.setting-label p { font-size: 13px; color: var(--muted); margin: 3px 0 0; }

/* Header for mobile pages */
.mobile-head { display: none; }

/* Chips multi-select */
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }

/* responsiveness */
@media (min-width: 1024px) {
  .planner-mobile { display: none; }
  .planner-table { display: table; }
}
@media (max-width: 1023px) {
  .sidebar { transform: translateX(-105%); width: 240px !important; }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .main, .main.collapsed { margin-left: 0; }
  .page { padding: 24px 18px 120px; }
  .bottom-nav { display: flex; }
  .fab { display: grid; }
  .collapse-ctrl { display: none; }
}
@media (min-width: 1024px) {
  .fab { display: none; }
}
@media (max-width: 560px) {
  .page-title { font-size: 24px; }
  .grid-recipes { grid-template-columns: 1fr; }
}

/* hide collapse control on mobile via class */
.collapse-ctrl { border: none; background: var(--bg-soft); color: var(--muted); width: 100%; padding: 10px; border-radius: 12px; cursor: pointer; }
.sidebar.collapsed .collapse-ctrl { padding: 10px; }

@media print {
  .sidebar, .bottom-nav, .fab, .action-bar, .no-print { display: none !important; }
  .main { margin: 0 !important; }
  body { background: #fff; }
  .shop-grid { grid-template-columns: 1fr; }
  .app { display: block; }
}
