/* ========================================
   STYLES PRINCIPAUX - Mes Recettes
   Thème sombre homogène avec l'accueil / CinéDuo
   ======================================== */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --safe-top:    env(safe-area-inset-top,    0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html {
    height: -webkit-fill-available;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(160deg, var(--bg-gradient-start) 0%, var(--bg-gradient-mid) 55%, var(--bg-gradient-end) 100%);
    background-attachment: fixed;
    color: var(--text);
    min-height: 100vh;
    min-height: -webkit-fill-available;
    padding: 10px;
    padding-top: calc(var(--safe-top) + 10px);
    padding-bottom: calc(var(--safe-bottom) + 80px);
}

::-webkit-scrollbar       { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ========================================
   NAVBAR DU HAUT (homogène avec CinéDuo)
   ======================================== */

.top-navbar {
    position: sticky;
    top: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    gap: 12px;
    margin: -10px -10px 12px;
    margin-top: calc(-1 * (var(--safe-top) + 10px));
    padding: calc(var(--safe-top) + 10px) 16px 10px;
    background: rgba(15,12,41,0.85);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border);
}

.navbar-back {
    display: flex;
    align-items: center;
    gap: 4px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    padding: 6px 10px 6px 6px;
    border-radius: 8px;
    flex-shrink: 0;
}

.navbar-back:active { background: rgba(255,255,255,0.08); color: var(--text); }
.navbar-back-icon { font-size: 18px; line-height: 1; }

.navbar-logo {
    font-weight: 700;
    font-size: 16px;
    letter-spacing: 0.2px;
}

/* ========================================
   HEADER (dans chaque vue)
   ======================================== */

.header {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 15px;
    box-shadow: var(--shadow);
    padding: 20px;
    margin-bottom: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

.header h1 {
    color: var(--text);
    font-size: 24px;
}

.header-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

/* ========================================
   BOUTONS
   ======================================== */

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    white-space: nowrap;
    font-family: inherit;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: var(--white);
}

.btn-success {
    background: var(--success);
    color: var(--white);
}

.btn-danger {
    background: var(--danger);
    color: var(--white);
}

.btn-warning {
    background: var(--warning);
    color: #1c1a33;
}

.btn-neutral {
    background: rgba(255,255,255,0.08);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn:active {
    transform: scale(0.97);
    opacity: 0.85;
}

.btn-small {
    padding: 6px 12px;
    font-size: 12px;
}

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ========================================
   CONTAINERS
   ======================================== */

.container {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 15px;
    box-shadow: var(--shadow);
    padding: 20px;
    margin-bottom: 15px;
}

.subsection-title {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin: 22px 0 10px;
}

.subsection-title:first-child { margin-top: 0; }

/* ========================================
   RECHERCHE + FILTRES
   ======================================== */

.search-box {
    width: 100%;
    padding: 12px 15px;
    border: 2px solid var(--border);
    border-radius: 25px;
    font-size: 14px;
    margin-bottom: 12px;
    background: rgba(255,255,255,0.04);
    color: var(--text);
}

.search-box::placeholder { color: var(--text-faint); }

.search-box:focus {
    outline: none;
    border-color: var(--primary);
}

.filter-chips {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 15px;
}

.filter-chip {
    padding: 6px 14px;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: rgba(255,255,255,0.04);
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    white-space: nowrap;
}

.filter-chip.active {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: var(--white);
    border-color: transparent;
}

mark {
    background: var(--secondary);
    color: #1c1a33;
    border-radius: 3px;
    padding: 0 2px;
}

/* ========================================
   GRID DE RECETTES
   ======================================== */

.recipe-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 15px;
    margin-top: 5px;
}

.recipe-card {
    background: var(--card-solid);
    border: 1px solid var(--border);
    border-radius: 14px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.recipe-card:active {
    transform: scale(0.98);
}

.recipe-card-media {
    height: 110px;
    background-size: cover;
    background-position: center;
    background-color: rgba(255,255,255,0.04);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 40px;
    flex-shrink: 0;
}

.recipe-card-media.has-photo { font-size: 0; }

.recipe-card-body {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
}

.recipe-card h3 {
    color: var(--text);
    font-size: 18px;
}

.recipe-card .meta {
    color: var(--text-muted);
    font-size: 13px;
}

.recipe-card .description {
    color: var(--text-muted);
    font-size: 13px;
}

.recipe-card .actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: auto;
    padding-top: 6px;
}

.recipe-card .actions .btn {
    flex: 1 1 90px;
    justify-content: center;
    min-width: 0;
}

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

.badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 3px 9px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}

.badge-category { background: rgba(255,107,107,0.16); color: var(--secondary); }
.badge-time      { background: rgba(255,255,255,0.08); color: var(--text-muted); }
.badge-tag       { background: rgba(255,255,255,0.06); color: var(--text-muted); }

.badge-diff-facile     { background: rgba(52,199,89,0.16);  color: var(--success); }
.badge-diff-moyen      { background: rgba(255,159,10,0.16); color: var(--warning); }
.badge-diff-difficile  { background: rgba(255,59,48,0.16);  color: var(--danger); }

/* Badge ingrédient trouvé dans recherche */
.ingredient-match-badge {
    background: linear-gradient(135deg, var(--success), #2dd36f);
    color: white;
    padding: 5px 10px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    display: inline-block;
    margin-top: 4px;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-5px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ========================================
   VUE RECETTE
   ======================================== */

.recipe-banner {
    height: 160px;
    margin: -20px -20px 20px;
    border-radius: 15px 15px 0 0;
    overflow: hidden;
}

.recipe-banner img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.recipe-header {
    text-align: center;
    margin-bottom: 15px;
}

.recipe-title {
    color: var(--text);
    font-size: 28px;
    margin-bottom: 5px;
}

.recipe-subtitle {
    color: var(--text-muted);
    font-size: 14px;
}

.recipe-meta-row {
    display: flex;
    justify-content: center;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 12px;
}

.servings-control {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    padding: 20px;
    border-radius: 12px;
    margin-bottom: 20px;
    text-align: center;
    color: var(--white);
}

.servings-label {
    font-size: 16px;
    margin-bottom: 10px;
    font-weight: 600;
}

.servings-display {
    font-size: 42px;
    font-weight: bold;
    margin: 10px 0;
}

.slider {
    width: 100%;
    height: 6px;
    border-radius: 5px;
    background: rgba(255, 255, 255, 0.3);
    outline: none;
    -webkit-appearance: none;
    margin: 15px 0;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--white);
    cursor: pointer;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

.slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--white);
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

/* ========================================
   INGRÉDIENTS
   ======================================== */

.ingredients-section {
    background: var(--light);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 20px;
}

.section-title {
    font-size: 20px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.ingredient-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    margin-bottom: 8px;
    background: rgba(255,255,255,0.04);
    border-radius: 8px;
    transition: background 0.2s;
}

.ingredient-item:hover {
    background: rgba(255,255,255,0.07);
}

.ingredient-name {
    color: var(--text);
    font-weight: 500;
    flex: 1;
}

.ingredient-amount {
    color: var(--ingredient-text);
    font-weight: bold;
    background: var(--ingredient-bg);
    padding: 6px 12px;
    border-radius: 6px;
    min-width: 80px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
}

.ingredient-amount:hover {
    border: 2px solid var(--primary);
}

.ingredient-amount input {
    width: 100%;
    background: transparent;
    border: none;
    color: var(--ingredient-text);
    font-weight: bold;
    text-align: center;
    outline: none;
}

/* ========================================
   INSTRUCTIONS
   ======================================== */

.instructions-section {
    background: var(--instructions-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 20px;
}

.instructions-section ol {
    margin-left: 20px;
    line-height: 1.8;
}

.instructions-section li {
    margin-bottom: 10px;
    color: var(--text);
}

/* ========================================
   FORMULAIRES
   ======================================== */

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    color: var(--text);
    font-weight: 600;
    margin-bottom: 8px;
    font-size: 14px;
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 12px;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    background: rgba(255,255,255,0.04);
    color: var(--text);
    transition: border 0.2s;
}

.form-group select option { background: var(--card-solid); color: var(--text); }

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary);
}

.form-group textarea {
    min-height: 100px;
    resize: vertical;
}

.form-group small {
    color: var(--text-muted);
    font-size: 12px;
    display: block;
    margin-top: 5px;
}

.form-row-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

.ingredient-builder {
    background: var(--light);
    border: 1px solid var(--border);
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 15px;
}

.ingredient-form {
    display: grid;
    grid-template-columns: 1fr 120px 80px;
    gap: 10px;
    margin-bottom: 10px;
}

.photo-preview {
    margin-top: 10px;
    border-radius: 10px;
    overflow: hidden;
    height: 140px;
    border: 1px solid var(--border);
}

.photo-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* ── Bloc "pré-remplir via IA" ── */
.ai-import-box {
    background: rgba(255,107,107,0.08);
    border: 1.5px dashed rgba(255,107,107,0.4);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 22px;
}

.ai-import-box summary {
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    color: var(--secondary);
    list-style: none;
    display: flex;
    align-items: center;
    gap: 8px;
}

.ai-import-box summary::-webkit-details-marker { display: none; }
.ai-import-box summary::after { content: '▾'; margin-left: auto; color: var(--text-muted); }
.ai-import-box[open] summary::after { content: '▴'; }

.ai-import-box p {
    color: var(--text-muted);
    font-size: 12px;
    margin: 8px 0 10px;
    line-height: 1.5;
}

.ai-import-box textarea {
    width: 100%;
    min-height: 90px;
    background: rgba(0,0,0,0.2);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 12px;
    padding: 10px;
    margin-bottom: 10px;
    resize: vertical;
}

.ai-import-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* ========================================
   NAVIGATION INFÉRIEURE (homogène avec CinéDuo)
   ======================================== */

.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(15,12,41,0.9);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-around;
    padding: 8px 4px calc(var(--safe-bottom) + 8px);
    z-index: 1000;
}

.nav-btn {
    flex: 1;
    max-width: 120px;
    padding: 8px 4px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 11px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    transition: color 0.2s;
    text-decoration: none;
    font-family: inherit;
}

.nav-btn.active {
    color: var(--secondary);
    font-weight: 600;
}

.nav-btn:active {
    transform: scale(0.95);
}

.nav-icon {
    font-size: 22px;
}

/* ========================================
   VUES
   ======================================== */

.view {
    display: none;
}

.view.active {
    display: block;
}

/* ========================================
   ÉTAT VIDE
   ======================================== */

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.empty-state-icon {
    font-size: 64px;
    margin-bottom: 15px;
}

.empty-state h3 {
    color: var(--text);
    margin-bottom: 10px;
}

/* ========================================
   MODAL
   ======================================== */

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--card-solid);
    border: 1px solid var(--border);
    border-radius: 15px;
    padding: 25px;
    max-width: 420px;
    width: 100%;
    text-align: center;
    max-height: 85vh;
    overflow-y: auto;
}

.modal-content h3 {
    color: var(--text);
    margin-bottom: 15px;
}

.modal-content p {
    color: var(--text-muted);
    margin-bottom: 20px;
    line-height: 1.6;
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

/* ========================================
   TOAST NOTIFICATIONS
   ======================================== */

.toast {
    position: fixed;
    top: calc(var(--safe-top) + 16px);
    right: 16px;
    left: 16px;
    background: var(--card-solid);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 15px 20px;
    border-radius: 12px;
    box-shadow: var(--shadow);
    z-index: 3000;
    display: none;
    animation: slideIn 0.3s ease;
    max-width: 380px;
    margin: 0 auto;
}

.toast.show {
    display: block;
}

.toast.success {
    background: var(--success);
    color: #06280f;
    border-color: transparent;
}

.toast.error {
    background: var(--danger);
    color: #2b0b09;
    border-color: transparent;
}

@keyframes slideIn {
    from {
        transform: translateY(-20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* ========================================
   SPINNER DE CHARGEMENT
   ======================================== */

.spinner {
    border: 3px solid rgba(255,255,255,0.1);
    border-top: 3px solid var(--primary);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 40px auto;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ========================================
   INDICATEUR DE STATUT
   ======================================== */

.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
    margin-right: 8px;
    animation: pulse 2s infinite;
}

.status-dot.offline {
    background: var(--danger);
    animation: none;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* ========================================
   ADMIN — STATS & IMPORT
   ======================================== */

.stats-box {
    background: var(--light);
    border: 1px solid var(--border);
    padding: 15px;
    border-radius: 8px;
}

.stats-box p { color: var(--text); margin-bottom: 4px; }
.stats-box p:last-child { margin-bottom: 0; }

/* ========================================
   RESPONSIVE MOBILE
   ======================================== */

@media (max-width: 768px) {
    body {
        padding: 6px;
        padding-top: calc(var(--safe-top) + 6px);
        padding-bottom: calc(var(--safe-bottom) + 76px);
    }

    .top-navbar {
        margin: -6px -6px 12px;
        margin-top: calc(-1 * (var(--safe-top) + 6px));
    }

    .header {
        padding: 15px;
    }

    .header h1 {
        font-size: 20px;
        width: 100%;
    }

    .container {
        padding: 15px;
    }

    .recipe-grid {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .ingredient-form {
        grid-template-columns: 1fr;
    }

    .form-row-grid {
        grid-template-columns: 1fr;
        gap: 0;
    }

    .btn {
        font-size: 13px;
        padding: 8px 15px;
    }

    .recipe-title {
        font-size: 22px;
    }

    .servings-display {
        font-size: 36px;
    }
}

/* Deux colonnes uniquement à partir d'un écran assez large (tablette) */
@media (min-width: 560px) and (max-width: 768px) {
    .recipe-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

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

    .recipe-card h3 {
        font-size: 16px;
    }

    .btn-small {
        padding: 5px 10px;
        font-size: 11px;
    }
}
