@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700;800&family=Fira+Code&display=swap');

/* --- VARIABLES ET THÈMES --- */
:root {
    --bg-primary: #ffffff;
    --bg-sidebar: #f8fafc;
    --bg-card: #ffffff;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --accent: #2563eb;
    --accent-soft: #eff6ff;
    --border: #e2e8f0;
    --code-bg: #0f172a;
    --danger: #ef4444;
    --danger-soft: #fef2f2;
    --sidebar-width: 300px;
    --radius: 12px;
    --transition: 0.2s ease;
}

[data-theme="dark"] {
    --bg-primary: #0b1220;
    --bg-sidebar: #111827;
    --bg-card: #0f172a;
    --text-main: #e5e7eb;
    --text-muted: #9ca3af;
    --border: #1f2937;
    --code-bg: #020617;
    --accent-soft: rgba(37, 99, 235, 0.15);
    --danger-soft: rgba(239, 68, 68, 0.15);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body { 
    font-family: 'Inter', sans-serif; 
    background: var(--bg-primary); 
    color: var(--text-main); 
    display: flex; 
    min-height: 100vh; 
    transition: background var(--transition), color var(--transition);
}

/* --- SIDEBAR --- */
.sidebar { 
    width: var(--sidebar-width); 
    height: 100vh; 
    background: var(--bg-sidebar); 
    border-right: 1px solid var(--border); 
    position: fixed; 
    padding: 32px 16px; 
    overflow-y: auto; 
    z-index: 100; 
}

.logo { 
    display: flex; 
    align-items: center; 
    gap: 12px; 
    font-weight: 800; 
    color: var(--accent); 
    margin-bottom: 40px; 
    padding-left: 10px; 
}

.family-group { margin-bottom: 30px; }

.nav-group-header { 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    padding-right: 8px; 
    margin-bottom: 8px; 
    gap: 5px; 
}

.family-name { 
    font-size: 0.75rem; 
    font-weight: 700; 
    color: var(--text-muted); 
    text-transform: uppercase; 
    letter-spacing: 0.05em; 
    padding-left: 10px; 
    flex-grow: 1; 
}

.nav-title { 
    font-size: 0.85rem; 
    font-weight: 600; 
    opacity: 0.85; 
    padding-left: 10px; 
    flex-grow: 1; 
}

.nav-group { 
    margin-left: 12px; 
    border-left: 1px solid var(--border); 
    margin-bottom: 20px; 
}

.nav-link { 
    display: block; 
    padding: 8px 16px; 
    text-decoration: none; 
    color: var(--text-muted); 
    border-radius: 0 8px 8px 0; 
    cursor: pointer; 
    font-size: 0.95rem; 
    transition: var(--transition); 
}

.nav-link:hover {
    background: var(--accent-soft);
    color: var(--accent);
}

.nav-link.active { 
    color: var(--accent); 
    background: var(--accent-soft); 
    font-weight: 600; 
    box-shadow: inset 3px 0 0 var(--accent); 
}

/* --- ADMIN ACTIONS --- */
.admin-actions { display: none; gap: 4px; }
.edit-mode-active .admin-actions { display: flex; }

.add-btn-small, .delete-btn-small { 
    background: var(--accent-soft); 
    color: var(--accent); 
    border: none; 
    width: 24px; 
    height: 24px; 
    border-radius: 6px; 
    cursor: pointer; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    transition: 0.2s; 
}

.delete-btn-small { 
    color: var(--danger); 
    background: var(--danger-soft); 
}

.add-btn-small:hover { 
    background: var(--accent); 
    color: white; 
}

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

.add-family-area { 
    margin-top: 20px; 
    padding: 10px; 
    border-top: 1px dashed var(--border); 
}

.btn-ghost { 
    width: 100%; 
    background: transparent; 
    border: 1px dashed var(--border); 
    color: var(--text-muted); 
    padding: 10px; 
    border-radius: 8px; 
    cursor: pointer; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    gap: 8px; 
    font-size: 0.85rem; 
    transition: 0.2s;
}

.btn-ghost:hover { 
    border-color: var(--accent); 
    color: var(--accent); 
    background: var(--accent-soft); 
}

/* --- MAIN CONTENT & TOPBAR --- */
.main-content { 
    margin-left: var(--sidebar-width); 
    width: 100%; 
}

.top-bar { 
    height: 72px; 
    padding: 0 40px; 
    border-bottom: 1px solid var(--border); 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    position: sticky; 
    top: 0; 
    background: var(--bg-primary); 
    z-index: 90; 
}

.admin-zone { 
    display: flex; 
    align-items: center; 
    gap: 12px; 
}

.theme-btn { 
    background: none; 
    border: 1px solid var(--border); 
    padding: 8px; 
    border-radius: 8px; 
    cursor: pointer; 
    color: var(--text-main); 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    transition: 0.2s;
}

.theme-btn:hover { 
    background: var(--accent-soft); 
    border-color: var(--accent); 
    color: var(--accent); 
}

.theme-btn.primary { 
    background: var(--accent); 
    color: white; 
    border: none; 
    padding: 8px 16px; 
    font-weight: 600; 
}

/* --- TOOLBAR --- */
.toolbar { 
    display: flex; 
    gap: 4px; 
    background: var(--bg-sidebar); 
    padding: 4px; 
    border-radius: 8px; 
    border: 1px solid var(--border); 
}

.toolbar button {
    background: none; 
    border: none; 
    padding: 6px 10px; 
    cursor: pointer; 
    color: var(--text-main); 
    border-radius: 4px; 
    font-size: 0.85rem; 
    font-weight: 600; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    transition: 0.2s;
}

.toolbar button:hover { 
    background: var(--accent-soft); 
    color: var(--accent); 
}

.btn-clear-format { 
    color: var(--danger) !important; 
}

.btn-clear-format:hover { 
    background: var(--danger-soft) !important; 
    color: var(--danger) !important; 
}

/* --- CONTENT --- */
.content { 
    max-width: 800px; 
    margin: 60px auto; 
    padding: 0 40px; 
    min-height: 400px; 
}

#docContent {
    line-height: 1.8;
    outline: none;
    min-height: 300px;
    color: var(--text-main);
}

/* Texte uniquement (évite d’écraser les styles utiles) */
#docContent h1,
#docContent h2,
#docContent h3,
#docContent p,
#docContent li {
    color: var(--text-main);
}

#docContent img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 20px 0;
    border: 1px solid var(--border);
    background: var(--bg-card);
    display: block;
}

/* Listes */
#docContent ul {
    margin-left: 1.5rem;
    margin-bottom: 20px;
}

#docContent ul li::marker {
    color: var(--accent);
}

/* Soulignage custom */
#docContent u {
    text-decoration: none;
    border-bottom: 1px solid var(--accent);
}

/* --- CODE --- */
pre {
    position: relative;
    background: var(--code-bg);
    color: #e5e7eb;
    padding: 24px;
    border-radius: 12px;
    margin: 32px 0;
    overflow-x: auto;
    border: 1px solid var(--border);
    font-family: 'Fira Code', monospace;
}

code {
    font-family: 'Fira Code', monospace;
}

.copy-btn { 
    position: absolute; 
    top: 12px; 
    right: 12px; 
    background: rgba(255,255,255,0.1); 
    border: none; 
    color: white; 
    padding: 6px; 
    border-radius: 6px; 
    cursor: pointer; 
    opacity: 0; 
    transition: 0.2s; 
}

pre:hover .copy-btn { opacity: 1; }

/* --- BOUTONS NAVIGATION FOOTER (STYLE REFAIT) --- */
.content-footer { 
    margin-top: 80px; 
    padding: 48px 40px 80px; 
    border-top: 1px solid var(--border); 
}

.nav-wrapper { 
    display: grid; 
    grid-template-columns: 1fr 1fr; 
    gap: 20px; 
    max-width: 800px; 
    margin: 0 auto; 
}

.nav-card { 
    display: flex;
    flex-direction: column;
    padding: 20px; 
    background: var(--bg-card); 
    border: 1px solid var(--border); 
    border-radius: 12px; 
    text-decoration: none;
    transition: all var(--transition); 
    cursor: pointer; 
}

/* Étiquette "Suivant" ou "Précédent" */
.nav-card::before {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

.nav-card.prev::before { content: "← Précédent"; }
.nav-card.next::before { content: "Suivant →"; align-self: flex-end; }

/* Style du titre de la page dans le bouton */
.nav-card .nav-title {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--accent);
}

.nav-card.next { text-align: right; }

.nav-card:hover { 
    border-color: var(--accent); 
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.1);
    transform: translateY(-2px);
}

/* Quand un bouton est vide/caché (ex: pas de page précédente) */
.nav-card:empty {
    visibility: hidden;
}

/* =============================== */
/*    MODALE CONFIRMATION DELETE   */
/* =============================== */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(2, 6, 23, 0.7);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}
.modal-overlay.active { display: flex; }

/* Carte principale */
.modal-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    width: 90%;
    max-width: 400px;
    padding: 32px;
    text-align: center;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.2);
}

/* Icône danger */
.modal-icon {
    display: flex;
    justify-content: center;
    margin-bottom: 16px;
    color: var(--danger);
}

.modal-icon svg {
    width: 48px;
    height: 48px;
}

/* Titre */
.modal-card h3 {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 8px;
}

/* Texte */
.modal-card p {
    font-size: 0.95rem;
    color: var(--text-muted);
    margin-bottom: 28px;
    line-height: 1.5;
}

/* Actions */
.modal-actions {
    display: flex;
    gap: 12px;
}

/* Boutons */
.modal-btn {
    flex: 1;
    padding: 12px;
    border-radius: 8px;
    border: none;
    font-weight: 600;
    cursor: pointer;
    transition: 0.2s;
}
.modal-btn.confirm { background: var(--danger); color: white; }
.modal-btn.cancel { background: var(--bg-sidebar); color: var(--text-main); border: 1px solid var(--border); }

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

.modal-btn.confirm:hover {
    background: #dc2626;
}

/* Animation */
@keyframes deleteModalIn {
    from {
        opacity: 0;
        transform: translateY(16px) scale(0.97);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* --- IMAGE INPUT --- */
#imageInput { display: none; }

/* --- MOBILE --- */
@media (max-width: 768px) {
    .sidebar { display: none; }
    .main-content { margin-left: 0; }
    .content { padding: 0 20px; }
    .nav-wrapper { grid-template-columns: 1fr; }
}





/* --- RESPONSIVE DESIGN --- */

/* Affichage conditionnel des éléments mobiles */
.mobile-only {
    display: none;
}

@media (max-width: 1024px) {
    :root {
        --sidebar-width: 260px;
    }
    .content {
        padding: 0 30px;
    }
}

@media (max-width: 768px) {
    .mobile-only {
        display: flex;
    }

    /* Sidebar Mobile (Overlay) */
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        box-shadow: 10px 0 30px rgba(0,0,0,0.1);
    }

    .sidebar.active {
        transform: translateX(0);
        display: block; /* Force l'affichage car votre CSS initial avait display: none */
    }

    .main-content {
        margin-left: 0;
    }

    /* Top Bar Mobile */
    .top-bar {
        padding: 0 15px;
        height: 64px;
    }

    .breadcrumb {
        font-size: 0.85rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 120px;
    }

    /* Toolbar d'édition mobile (Scroll horizontal si trop de boutons) */
    .toolbar {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        border-radius: 0;
        border-top: 1px solid var(--border);
        overflow-x: auto;
        justify-content: flex-start;
        padding: 8px;
        z-index: 1000;
        background: var(--bg-sidebar);
    }

    .edit-mode-active .content-footer {
        padding-bottom: 80px; /* Espace pour la barre d'outils fixe */
    }

    .admin-zone .theme-btn span {
        display: none; /* Cache le texte "Mode Édition" pour ne garder que l'icône */
    }

    /* Contenu */
    .content {
        margin: 30px auto;
        padding: 0 20px;
    }

    #docContent h1 { font-size: 1.8rem; }
    #docContent h2 { font-size: 1.4rem; }

    /* Navigation Footer */
    .nav-wrapper {
        grid-template-columns: 1fr; /* Empile les boutons */
        gap: 12px;
    }

    .nav-card {
        padding: 15px;
    }
}

/* Overlay pour fermer le menu en cliquant à côté */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 95;
}

.sidebar-overlay.active {
    display: block;
}