:root {
    --primary: #10b981;
    --primary-dark: #059669;
    --primary-light: #d1fae5;
    --ai: #6366f1;
    --ai-light: #e0e7ff;
    --fav: #ec4899;
    --bg: #f1f5f9;
    --card: #ffffff;
    --text: #0f172a;
    --muted: #64748b;
    --danger: #ef4444;
    --warn: #f59e0b;
    --border: #e2e8f0;
}

* { box-sizing: border-box; margin: 0; padding: 0; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; }
body { background: var(--bg); color: var(--text); padding-bottom: 90px; -webkit-tap-highlight-color: transparent; }

.screen { display: none; }
.screen.active { display: block; }
.hidden { display: none !important; }
.opt { font-weight: 400; color: var(--muted); font-size: 0.76rem; }

/* BARRE SUPÉRIEURE */
.top-bar {
    position: sticky; top: 0; z-index: 15;
    background: rgba(255,255,255,0.92); backdrop-filter: blur(8px);
    padding: 14px 18px; display: flex; justify-content: space-between; align-items: center;
    border-bottom: 1px solid var(--border);
}

.tab-view { display: none; padding: 14px; max-width: 540px; margin: 0 auto; }
.tab-view.active { display: block; animation: fadeIn 0.18s ease-out; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

.card {
    background: var(--card); border-radius: 18px; padding: 18px;
    margin-bottom: 14px; box-shadow: 0 4px 12px rgba(15,23,42,0.04);
    border: 1px solid rgba(226,232,240,0.7);
}
.auth-card { max-width: 420px; margin: 32px auto; }
.subtitle { color: var(--muted); font-size: 0.88rem; margin: 4px 0 16px; }

label { display: block; font-size: 0.84rem; font-weight: 600; margin: 12px 0 5px; color: #334155; }
input, select {
    width: 100%; padding: 12px 14px; border: 1.5px solid #cbd5e1;
    border-radius: 12px; font-size: 1rem; background: #fff; color: var(--text);
    transition: border-color 0.15s;
}
input:focus, select:focus { outline: none; border-color: var(--primary); }

.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row-inline { display: flex; gap: 8px; align-items: center; }

/* CHAMP DATE NUMÉRIQUE + ICÔNE CALENDRIER */
.date-action-row { display: flex; gap: 8px; align-items: stretch; }
.date-input-wrapper {
    position: relative; flex: 1; display: flex; align-items: center;
}
.date-input-wrapper input[type="text"] {
    padding-right: 44px; font-variant-numeric: tabular-nums; letter-spacing: 0.5px;
}
.calendar-trigger-btn {
    position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
    background: #f1f5f9; border: none; border-radius: 8px;
    width: 34px; height: 34px; display: flex; align-items: center; justify-content: center;
    font-size: 1.1rem; cursor: pointer; padding: 0; pointer-events: none;
}
/* Le picker natif recouvre uniquement l'icône 📅 pour ouvrir directement le calendrier du téléphone au clic */
.hidden-native-picker {
    position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
    width: 38px; height: 38px; opacity: 0; cursor: pointer; z-index: 3; padding: 0; border: none;
}

/* BOUTONS */
button {
    cursor: pointer; border: none; border-radius: 12px;
    font-weight: 600; font-size: 0.94rem; padding: 12px 16px; transition: transform 0.1s, opacity 0.15s;
}
button:active { transform: scale(0.98); }
.btn-primary { width: 100%; background: var(--primary); color: #fff; margin-top: 14px; box-shadow: 0 2px 6px rgba(16,185,129,0.25); }
.btn-secondary { width: 100%; background: #e2e8f0; color: var(--text); margin-top: 10px; }
.btn-ai { background: var(--ai); color: #fff; white-space: nowrap; padding: 0 16px; }
.btn-danger { width: 100%; background: var(--danger); color: #fff; margin-top: 10px; }
.btn-icon { background: transparent; font-size: 1.15rem; padding: 6px 8px; border-radius: 8px; }
.btn-icon:hover { background: #f1f5f9; }

.tabs-small { display: flex; gap: 6px; margin-bottom: 12px; background: #f1f5f9; padding: 4px; border-radius: 12px; }
.tabs-small button { flex: 1; background: transparent; padding: 9px 6px; font-size: 0.84rem; color: var(--muted); border-radius: 9px; }
.tabs-small button.active { background: #fff; color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,0.08); }

/* CARTES DU STOCK */
.alert-banner {
    background: #fef2f2; border: 1px solid #fecaca; color: #991b1b;
    padding: 12px 14px; border-radius: 14px; margin-bottom: 12px; font-size: 0.88rem; font-weight: 600;
}
.item-card {
    background: var(--card);
    border-radius: 14px;
    margin-bottom: 10px;
    display: flex;
    align-items: stretch;
    overflow: hidden;
    box-shadow: 0 2px 6px rgba(15,23,42,0.04);
    border: 1px solid var(--border);
}
.item-strip {
    writing-mode: vertical-rl;
    transform: rotate(180deg);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    flex-shrink: 0;
    font-size: 0.65rem;
    font-weight: 800;
    letter-spacing: 1.2px;
    color: #ffffff;
    text-transform: uppercase;
    user-select: none;
}
.item-card.urgent { border-left-color: var(--danger); }
.item-card.soon { border-left-color: var(--warn); }
.item-card.nodate { border-left-color: #94a3b8; }

/* Couleurs par emplacement */
.strip-frigo   { background: #0ea5e9; } /* Bleu frais */
.strip-congel  { background: #6366f1; } /* Indigo glacé */
.strip-placard { background: #d97706; } /* Ambre / Placard */
.strip-none    { background: #94a3b8; } /* Gris si non spécifié */

/* Priorité rouge si < 3 jours de la péremption */
.strip-urgent  { background: var(--danger); }

.item-body {
    flex: 1;
    padding: 13px 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.item-title { font-weight: 700; font-size: 1rem; color: var(--text); }
.item-qty-pill {
    display: inline-block; background: #f1f5f9; color: #475569;
    font-size: 0.75rem; font-weight: 600; padding: 2px 8px; border-radius: 6px; margin-left: 6px;
}
.item-meta { font-size: 0.8rem; color: var(--muted); margin-top: 4px; display: flex; gap: 8px; align-items: center; }

.badge { font-size: 0.75rem; padding: 4px 9px; border-radius: 99px; font-weight: 700; white-space: nowrap; }
.badge.urgent { background: #fee2e2; color: #b91c1c; }
.badge.soon { background: #fef3c7; color: #b45309; }
.badge.ok { background: #d1fae5; color: #047857; }
.badge.nodate { background: #f1f5f9; color: #64748b; }

/* DESIGN MODERNE DES RECETTES */
.recipe-filters {
    display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; margin: 10px 0 4px;
    scrollbar-width: none;
}
.recipe-filters::-webkit-scrollbar { display: none; }
.chip {
    background: #f1f5f9; color: #475569; padding: 7px 13px; border-radius: 99px;
    font-size: 0.8rem; font-weight: 600; white-space: nowrap; border: 1px solid transparent;
}
.chip.active { background: var(--primary-light); color: var(--primary-dark); border-color: var(--primary); }

.recipe-card {
    background: var(--card); border-radius: 18px; margin-bottom: 14px;
    overflow: hidden; border: 1px solid var(--border);
    box-shadow: 0 4px 12px rgba(15,23,42,0.05); transition: box-shadow 0.2s;
}
.recipe-header {
    padding: 16px; cursor: pointer; display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
    background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
}
.recipe-title { font-size: 1.05rem; font-weight: 700; color: var(--text); line-height: 1.3; }
.recipe-desc { font-size: 0.83rem; color: var(--muted); margin-top: 4px; line-height: 1.4; }
.recipe-pills { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.r-pill {
    font-size: 0.74rem; font-weight: 600; padding: 4px 9px; border-radius: 8px;
    background: #f1f5f9; color: #334155; display: inline-flex; align-items: center; gap: 4px;
}
.r-pill.time { background: #e0f2fe; color: #0369a1; }
.r-pill.match { background: var(--primary-light); color: var(--primary-dark); }

.recipe-chevron {
    background: #f1f5f9; width: 32px; height: 32px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center; font-size: 0.8rem; color: var(--muted);
    flex-shrink: 0; transition: transform 0.2s;
}
.recipe-card.open .recipe-chevron { transform: rotate(180deg); background: var(--primary-light); color: var(--primary-dark); }

.recipe-body { padding: 0 16px 16px; border-top: 1px solid var(--border); background: #fff; }
.recipe-section-title {
    font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.6px;
    color: var(--muted); font-weight: 700; margin: 16px 0 10px;
}

/* Liste d'ingrédients cochables */
.ing-list { list-style: none; display: grid; gap: 6px; }
.ing-item {
    display: flex; align-items: center; gap: 10px; padding: 8px 10px;
    background: #f8fafc; border-radius: 10px; font-size: 0.9rem; cursor: pointer;
}
.ing-item input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--primary); cursor: pointer; }
.ing-item.checked span { text-decoration: line-through; color: var(--muted); }

/* Étapes numérotées */
.step-list { list-style: none; display: grid; gap: 10px; }
.step-item { display: flex; gap: 12px; align-items: flex-start; font-size: 0.92rem; line-height: 1.5; color: #1e293b; }
.step-num {
    background: var(--primary); color: #fff; font-weight: 700; font-size: 0.78rem;
    width: 24px; height: 24px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; margin-top: 2px;
}

/* Zone de customisation de la recette */
.recipe-custom-box {
    margin-top: 16px; padding: 12px; background: #f8fafc; border-radius: 12px; border: 1px solid var(--border);
}
.recipe-adapt-chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0; }
.adapt-btn {
    background: var(--ai-light); color: var(--ai); font-size: 0.76rem; padding: 6px 10px; border-radius: 8px; font-weight: 600;
}
.recipe-actions-bar { display: flex; gap: 8px; margin-top: 12px; }
.btn-fav { flex: 1; background: #fdf2f8; color: #db2777; border: 1px solid #fbcfe8; }
.btn-fav.saved { background: var(--fav); color: #fff; }

/* MODALE D'ÉDITION (BOTTOM SHEET MOBILE) */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(15,23,42,0.5); backdrop-filter: blur(3px);
    z-index: 50; display: flex; align-items: flex-end; justify-content: center;
}
.modal-sheet {
    background: var(--card); width: 100%; max-width: 540px;
    border-radius: 22px 22px 0 0; padding: 20px; max-height: 90vh; overflow-y: auto;
    animation: slideUp 0.2s ease-out;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }

/* TOAST NOTIFICATIONS */
#toast-container {
    position: fixed; top: 16px; left: 50%; transform: translateX(-50%);
    z-index: 100; display: flex; flex-direction: column; gap: 8px; width: 90%; max-width: 400px; pointer-events: none;
}
.toast {
    background: #0f172a; color: #fff; padding: 12px 16px; border-radius: 12px;
    font-size: 0.88rem; font-weight: 600; box-shadow: 0 8px 20px rgba(0,0,0,0.18);
    display: flex; align-items: center; gap: 8px; animation: fadeIn 0.2s ease-out;
}
.toast.success { border-left: 4px solid var(--primary); }
.toast.error { border-left: 4px solid var(--danger); }

/* NAVIGATION BASSE */
.bottom-nav {
    position: fixed; bottom: 0; left: 0; right: 0;
    background: rgba(255,255,255,0.95); backdrop-filter: blur(8px);
    display: flex; justify-content: space-around; padding: 8px 0; border-top: 1px solid var(--border); z-index: 20;
}
.nav-btn {
    background: none; display: flex; flex-direction: column;
    align-items: center; font-size: 1.25rem; color: var(--muted); padding: 4px 12px;
}
.nav-btn span { font-size: 0.7rem; margin-top: 2px; }
.nav-btn.active { color: var(--primary); }

.recovery-box { margin-top: 14px; padding: 12px; background: #fffbeb; border: 1px solid #fde68a; border-radius: 12px; font-size: 0.85rem; }
.recovery-box code { display: block; font-size: 1.1rem; font-weight: 700; text-align: center; padding: 8px; margin: 8px 0; background: #fff; border-radius: 6px; }
.hint { display: block; font-size: 0.78rem; color: var(--muted); margin-top: 4px; }
.msg { margin-top: 10px; font-size: 0.86rem; font-weight: 600; color: var(--primary-dark); }
.user-list { list-style: none; margin-top: 10px; font-size: 0.86rem; }
.user-list li { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid #f1f5f9; }
#reader { width: 100%; border-radius: 12px; overflow: hidden; margin-top: 8px; }

/* BARRE DE TRI & GROUPES D'INVENTAIRE */
.stock-toolbar { padding: 14px; }
.stock-toolbar select { width: auto; min-width: 165px; font-size: 0.85rem; padding: 10px; font-weight: 600; }
.storage-group-title {
    font-size: 0.85rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.5px;
    color: var(--muted); margin: 16px 4px 8px; display: flex; justify-content: space-between;
}

/* ALERTE RAPPEL PRODUIT */
.recall-box {
    margin-top: 12px; padding: 12px 14px; border-radius: 12px; font-size: 0.85rem; line-height: 1.45;
}
.recall-box.danger {
    background: #fef2f2; border: 2px solid var(--danger); color: #7f1d1d;
}
.recall-box.safe {
    background: #f0fdf4; border: 1px solid #bbf7d0; color: #166534;
}
.recall-box h4 { font-size: 0.95rem; margin-bottom: 4px; display: flex; align-items: center; gap: 6px; }

/* PROPOSITION DE RECETTE UTILISATEUR */
.custom-idea-box {
    margin-top: 14px; padding-top: 14px; border-top: 1px dashed var(--border);
}
.custom-idea-box label { margin-top: 0; color: var(--ai); }

.search-row { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }
.search-row select { width: auto; min-width: 150px; padding: 10px; font-size: 0.85rem; font-weight: 600; }
.filter-chips { display: grid; gap: 6px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none;  grid-template-columns: auto auto auto;}
.filter-chips::-webkit-scrollbar { display: none; }
.filter-chips .chip span {
    background: rgba(15,23,42,0.08); padding: 1px 6px; border-radius: 99px; font-size: 0.7rem; margin-left: 4px;
}
.row-between { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.btn-recall-mini { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; padding: 6px 10px; font-size: 0.78rem; border-radius: 8px; }

/* OVERLAY BLOQUANT PENDANT LES REQUÊTES IA */
body.ai-busy { overflow: hidden; pointer-events: none; user-select: none; }
.ai-overlay {
    position: fixed; inset: 0; z-index: 9999; pointer-events: all;
    background: rgba(15, 23, 42, 0.55); backdrop-filter: blur(6px);
    display: flex; align-items: center; justify-content: center; padding: 20px;
    animation: fadeIn 0.2s ease-out;
}
.ai-loader-card {
    background: var(--card); width: 100%; max-width: 340px; border-radius: 22px;
    padding: 26px 22px; text-align: center;
    box-shadow: 0 20px 40px rgba(15, 23, 42, 0.25);
    border: 1px solid rgba(255, 255, 255, 0.6);
}
.ai-spinner-wrap {
    position: relative; width: 68px; height: 68px; margin: 0 auto 16px;
    display: flex; align-items: center; justify-content: center;
}
.ai-spinner-ring {
    position: absolute; inset: 0; border-radius: 50%;
    border: 4px solid var(--ai-light); border-top-color: var(--ai); border-right-color: var(--primary);
    animation: aiSpin 0.9s cubic-bezier(0.5, 0.1, 0.5, 0.9) infinite;
}
.ai-spinner-icon { font-size: 1.8rem; animation: aiPulse 1.5s ease-in-out infinite; }
@keyframes aiSpin { to { transform: rotate(360deg); } }
@keyframes aiPulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.12); } }

.ai-loader-card h4 { font-size: 1.05rem; color: var(--text); margin-bottom: 6px; }
.ai-loader-card p { font-size: 0.83rem; color: var(--muted); line-height: 1.45; margin-bottom: 16px; }
.ai-progress-bar {
    height: 6px; width: 100%; background: #f1f5f9; border-radius: 99px; overflow: hidden;
}
.ai-progress-fill {
    height: 100%; width: 45%; background: linear-gradient(90deg, var(--ai), var(--primary));
    border-radius: 99px; animation: aiSlide 1.3s ease-in-out infinite alternate;
}
@keyframes aiSlide { from { transform: translateX(-20%); } to { transform: translateX(140%); } }

/* ÉDITION & CONFIRMATION DE SAUVEGARDE DES FAVORIS */
.fav-save-banner {
    margin-top: 10px; padding: 10px 12px; border-radius: 10px; font-size: 0.82rem; font-weight: 700;
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.fav-save-banner.unsaved { background: #fffbeb; color: #b45309; border: 1px solid #fde68a; }
.fav-save-banner.saved { background: #ecfdf5; color: #047857; border: 1px solid #a7f3d0; }

.fav-manual-editor {
    margin-top: 12px; padding: 12px; background: #fff; border: 1.5px solid #cbd5e1;
    border-radius: 12px;
}
.fav-manual-editor textarea {
    width: 100%; padding: 10px; border: 1.5px solid #cbd5e1; border-radius: 10px;
    font-size: 0.88rem; min-height: 80px; resize: vertical; background: #f8fafc;
}
.btn-save-fav-changes {
    flex: 1.4; background: var(--primary); color: #fff; box-shadow: 0 2px 6px rgba(16,185,129,0.25);
}
.btn-save-fav-changes.saved-state {
    background: #059669;
}

/* CHANGELOGS / NOUVEAUTÉS */
.btn-with-badge { position: relative; }
.notif-dot {
    position: absolute; top: 3px; right: 4px;
    width: 11px; height: 11px; border-radius: 50%;
    background: var(--danger); border: 2px solid #fff;
}
.changelog-form {
    display: flex; flex-direction: column; gap: 8px;
    margin-bottom: 16px; padding-bottom: 14px; border-bottom: 1px solid var(--border);
}
.changelog-form textarea {
    width: 100%; padding: 12px 14px; border: 1.5px solid #cbd5e1; border-radius: 12px;
    font: inherit; font-size: 1rem; resize: vertical; color: var(--text);
}
.changelog-form textarea:focus { outline: none; border-color: var(--primary); }
.changelog-item {
    padding: 12px 14px; margin-bottom: 10px; background: #fff;
    border: 1px solid var(--border); border-radius: 14px;
}
.changelog-item.is-new { border-color: var(--primary); background: var(--primary-light); }
.changelog-new {
    display: inline-block; background: var(--danger); color: #fff; font-size: 0.64rem;
    font-weight: 700; padding: 2px 7px; border-radius: 99px; vertical-align: middle; margin-left: 4px;
}
.changelog-body { font-size: 0.9rem; line-height: 1.45; color: var(--text); }

/* Modale changelog : popup flottante centrée au lieu du bottom sheet */
.modal-overlay.modal-center { align-items: center; padding: 16px; }
.modal-overlay.modal-center .modal-sheet {
    border-radius: 22px;
    max-height: 80vh;
    max-height: 80dvh;
    box-shadow: 0 20px 50px rgba(15, 23, 42, 0.25);
    animation: popIn 0.18s ease-out;
}
@keyframes popIn {
    from { opacity: 0; transform: scale(0.94); }
    to   { opacity: 1; transform: scale(1); }
}

/* Contenu des changelogs : liste élégante */
.cl-para { margin: 6px 0 2px; color: var(--muted); }
.cl-list {
    list-style: none; margin: 10px 0 0; padding: 0;
    display: flex; flex-direction: column; gap: 8px;
}
.cl-list li { display: flex; align-items: flex-start; gap: 10px; }
.cl-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }

/* Simple puce */
.cl-dot::before {
    content: ''; flex: none; width: 6px; height: 6px;
    margin: 0.6em 3px 0; border-radius: 50%; background: var(--primary);
}

/* Pastilles de catégorie */
.cl-tag {
    flex: none; min-width: 70px; text-align: center;
    font-size: 0.64rem; font-weight: 700; letter-spacing: 0.4px; text-transform: uppercase;
    padding: 3px 8px; border-radius: 99px; margin-top: 2px;
}
.cl-add .cl-tag { background: var(--primary-light); color: var(--primary-dark); }
.cl-imp .cl-tag { background: var(--ai-light); color: var(--ai); }
.cl-fix .cl-tag { background: #fef3c7; color: #b45309; }

/* Fond des entrées non vues plus discret, pour que les pastilles restent lisibles */
.changelog-item.is-new { background: #f0fdf4; }