/* =============================================================
   BASE.CSS — Design System Global FiletStudio
   Variables, reset, typographie, sidebars, mini-navigation
   ============================================================= */

@font-face {
    font-family: 'Playfair Display';
    src: url('../fonts/playfair-display-variable.woff2') format('woff2');
    font-weight: 400 700;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Playfair Display';
    src: url('../fonts/playfair-display-italic.woff2') format('woff2');
    font-weight: 400;
    font-style: italic;
    font-display: swap;
}

@font-face {
    font-family: 'Plus Jakarta Sans';
    src: url('../fonts/plus-jakarta-sans-variable.woff2') format('woff2');
    font-weight: 400 800;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Press Start 2P';
    src: url('../fonts/PressStart2P-Regular.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
}

@font-face {
    font-family: 'Jacquard 12';
    src: url('../fonts/Jacquard12-Regular.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
}


*, *::before, *::after {
    box-sizing: border-box;
}

:root {
    --bg-color: #f4ecd8;
    --text-main: #3e3222;
    --text-light: #8c7d6a;
    --accent: #8b4513;
    --border: #d1c7b0;
    --panel-bg: #eae0c8;
    --shadow: 0 10px 25px rgba(62, 50, 34, 0.1);
    --font-headings: 'Playfair Display', serif;
    --font-body: 'Playfair Display', serif;
}

body {
    margin: 0;
    padding: 0;
    font-family: var(--font-body);
    background-color: var(--bg-color);
    /* Motif quadrillé filet discret en arrière-plan */
    background-image: 
        linear-gradient(rgba(209, 199, 176, 0.25) 1px, transparent 1px),
        linear-gradient(90deg, rgba(209, 199, 176, 0.25) 1px, transparent 1px);
    background-size: 24px 24px;
    color: var(--text-main);
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* =============== SIDEBAR COMMUNE =============== */
.sidebar {
    width: 300px;
    border-right: 1px solid var(--border);
    padding: 2.5rem;
    display: flex;
    flex-direction: column;
    background: var(--panel-bg);
    box-shadow: 2px 0 15px rgba(0,0,0,0.03);
    z-index: 10;
    overflow-y: auto;
}

.right-sidebar {
    width: 300px;
    border-left: 1px solid var(--border);
    padding: 2rem;
    display: flex;
    flex-direction: column;
    background: var(--panel-bg);
    box-shadow: -2px 0 15px rgba(0,0,0,0.03);
    z-index: 10;
    overflow-y: auto;
}

.book-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 2rem;
    text-align: center;
    color: var(--accent);
    border-bottom: 2px solid var(--border);
    padding-bottom: 1rem;
    font-family: var(--font-headings);
}

.book-subtitle {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: var(--text-light);
    margin-bottom: 0.5rem;
}

/* =============== BOUTONS COMMUNS =============== */
.btn {
    font-family: var(--font-body);
    font-size: 1rem;
    padding: 0.6rem 1.5rem;
    cursor: pointer;
    border: 1px solid var(--border);
    background: var(--bg-color);
    color: var(--text-main);
    transition: all 0.2s;
    font-weight: 700;
    border-radius: 4px;
}
.btn:hover { background: var(--panel-bg); border-color: var(--accent); transform: translateY(-2px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: #6b340e; color: #fff; }
.btn-danger { color: #e63946; border-color: #e63946; }
.btn-danger:hover { background: #e63946; color: white; border-color: #e63946; }

/* =============== MODALES COMMUNES ===============
   Base structurelle partagée. L'affichage (display/visibilité) est géré par contexte :
   - Modales statiques (Studio, Compagnon) : style="display:none" inline, ouvertes via style.display='flex'
   - Modales Hub/Encyclopédie animées : masquées par opacity/pointer-events, révélées via .active */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(30, 20, 10, 0.7);
    display: none;
    align-items: center; justify-content: center;
    z-index: 2000;
    backdrop-filter: blur(3px);
    padding: 1.5rem;
}
.modal-content {
    background: var(--bg-color);
    border: 2px solid var(--border);
    padding: 2rem;
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
    max-width: 800px; width: 90%;
    display: flex; flex-direction: column; gap: 1rem;
    border-radius: 4px;
}
.modal-content h2 { font-family: var(--font-headings); color: var(--accent); margin: 0 0 0.5rem 0; font-size: 1.8rem; border-bottom: 1px solid var(--border); padding-bottom: 0.5rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 1rem; margin-top: 1.5rem; }

/* =============== MINI-SIDEBAR NAVIGATION GLOBALE =============== */
.global-mini-sidebar {
    width: 70px;
    background: var(--hub-surface-card, #ffffff);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 1.5rem;
    padding-bottom: 1.5rem;
    gap: 1.5rem;
    z-index: 50;
    box-shadow: 2px 0 10px rgba(0,0,0,0.05);
}

.mini-brand {
    font-family: var(--font-headings);
    font-size: 1.8rem;
    font-weight: bold;
    color: var(--accent);
    margin-bottom: 1rem;
    text-shadow: 1px 1px 0 rgba(255,255,255,0.5);
}

.mini-nav-btn {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-light);
    text-decoration: none;
    font-size: 1.2rem;
    transition: all 0.2s ease;
    border: 1px solid transparent;
    cursor: pointer;
}

button.mini-nav-btn {
    background: transparent;
    border: 1px solid transparent;
    padding: 0;
    font-family: inherit;
}

.mini-nav-btn:hover {
    color: var(--accent);
    background: rgba(139, 69, 19, 0.05);
    transform: translateY(-2px);
}

.mini-nav-btn.active {
    color: var(--accent);
    background: rgba(139, 69, 19, 0.1);
    border: 1px solid rgba(139, 69, 19, 0.2);
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.05);
}

/* Entrées à venir : présentes pour annoncer la fonctionnalité, sans lien ni interaction.
   Assez estompées pour se lire comme inactives, assez lisibles pour rester identifiables. */
.mini-nav-btn.disabled {
    opacity: 0.55;
    filter: grayscale(0.8);
    cursor: not-allowed;
    pointer-events: auto;
}

.mini-nav-btn.disabled:hover {
    color: var(--text-light);
    background: transparent;
    transform: none;
}

/* Accès à l'espace d'administration — détaché des outils utilisateur par un filet. */
.mini-nav-admin {
    position: relative;
    margin-top: 1.25rem;
}

.mini-nav-admin::before {
    content: "";
    position: absolute;
    top: -0.75rem;
    left: 50%;
    transform: translateX(-50%);
    width: 26px;
    height: 1px;
    background: var(--border);
}

/* =============== SIDEBAR GLOBALE → BARRE HORIZONTALE (mobile portrait, pages Hub + FAQ) ===============
   Scopée à body.hub-page : .global-mini-sidebar est un composant partagé par toutes les pages,
   ce basculement ne doit affecter que les pages qui portent explicitement cette classe (/hub, /faq). */
@media (max-width: 600px) and (orientation: portrait) {
    body.hub-page {
        flex-direction: column;
        height: 100vh;
        overflow: hidden;
    }

    body.hub-page .global-mini-sidebar {
        width: 100%;
        flex-direction: row;
        align-items: center;
        padding: 0.5rem 0.75rem;
        gap: 0.5rem;
        border-right: none;
        border-bottom: 1px solid var(--border);
        box-shadow: 0 2px 10px rgba(0,0,0,0.05);
        flex-shrink: 0;
        overflow-x: auto;
    }

    /* Icônes "bientôt disponible" : masquées pour ne pas encombrer la ligne */
    body.hub-page .global-mini-sidebar .mini-nav-btn.disabled {
        display: none;
    }

    /* Réinitialise les marges verticales pensées pour la colonne desktop (ex. Déconnexion,
       qui porte un margin-top inline) : en ligne horizontale elles désalignent l'icône. */
    body.hub-page .global-mini-sidebar .mini-nav-btn {
        margin-top: 0 !important;
    }

    /* Espaceur vertical → pousse Compte/Déconnexion à droite en horizontal */
    body.hub-page .global-mini-sidebar > div[style*="margin-top: auto"] {
        margin-top: 0 !important;
        margin-left: auto;
    }

    /* Filet séparateur au-dessus d'Admin, pensé pour un layout vertical → réorienté à gauche */
    body.hub-page .global-mini-sidebar .mini-nav-admin {
        margin-top: 0;
        margin-left: 0.5rem;
    }
    body.hub-page .global-mini-sidebar .mini-nav-admin::before {
        top: 50%;
        left: -0.75rem;
        transform: translateY(-50%);
        width: 1px;
        height: 26px;
    }
}

/* =============== SIDEBAR VERTICALE — TÉLÉPHONE EN PAYSAGE ===============
   Hors de la règle portrait ci-dessus, la colonne reste verticale (voulu : cf. paysage → barre à gauche).
   Mais sur un téléphone en paysage (hauteur d'écran réduite), toutes pages confondues, les icônes
   "bientôt disponible" prennent trop de place utile dans cette colonne étroite : on les masque, comme en portrait. */
@media (orientation: landscape) and (max-height: 500px) and (hover: none) and (pointer: coarse) {
    .global-mini-sidebar .mini-nav-btn.disabled {
        display: none;
    }
}

/* =============== APP LOADING OVERLAY =============== */
.app-loading-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(253, 250, 243, 0.88);
    backdrop-filter: blur(6px);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 1;
    transition: opacity 0.25s ease;
    pointer-events: all;
}

.app-loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.loading-spinner {
    font-size: 3rem;
    animation: pulseSpin 1.4s infinite ease-in-out;
    user-select: none;
}

@keyframes pulseSpin {
    0% { transform: scale(1) rotate(0deg); }
    50% { transform: scale(1.18) rotate(180deg); }
    100% { transform: scale(1) rotate(360deg); }
}


/* ==========================================================================
   MODALES D'ALERTE HARMONISÉES (PARCHEMIN V2)
   ========================================================================== */

/* Variante animée — modales Hub et Encyclopédie, masquées par défaut, révélées par .active.
   Sur body.hub-page, toutes les .modal-overlay bénéficient de l'animation fade + scale. */
.modal-overlay--anim,
body.hub-page .modal-overlay {
    display: flex;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
    background: rgba(45, 34, 22, 0.65);
    backdrop-filter: blur(4px);
}

body.hub-page .modal-overlay.active,
.modal-overlay--anim.active {
    opacity: 1;
    pointer-events: auto;
}


.modal-card {
    background: var(--hub-surface);
    border: 2px solid var(--hub-border);
    border-radius: var(--hub-radius-lg);
    padding: 2.2rem 2rem;
    max-width: 450px;
    width: 90%;
    box-sizing: border-box;
    box-shadow: var(--hub-shadow-lg);
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
    position: relative;
    outline: 1px solid rgba(139, 69, 19, 0.15);
    outline-offset: -6px;
    transition: var(--hub-transition);
}

.modal-card::before {
    content: '';
    position: absolute;
    top: -2px;
    left: 50%;
    transform: translateX(-50%);
    width: 50px;
    height: 12px;
    background: #9d5c32;
    border-radius: 0 0 5px 5px;
    box-shadow: inset 0 1px 1px rgba(255,255,255,0.2), 0 1px 3px rgba(0,0,0,0.15);
    z-index: 10;
}

.modal-card .modal-icon {
    align-self: center;
    font-size: 2.5rem;
    margin-top: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-card h3 {
    font-family: var(--hub-font-headings);
    font-size: 1.45rem;
    font-weight: 700;
    margin: 0;
    text-align: center;
    line-height: 1.25;
}

.modal-card p {
    font-family: var(--hub-font-ui);
    font-size: 0.92rem;
    color: var(--hub-text-muted);
    line-height: 1.55;
    margin: 0;
    text-align: center;
}

.modal-card .modal-buttons,
.modal-card .modal-actions {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    margin-top: 0.5rem;
    width: 100%;
}

.modal-card .modal-buttons-row,
.modal-card .modal-actions-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.8rem;
    margin-top: 0.5rem;
    width: 100%;
}

.modal-card .btn-action {
    padding: 0.75rem 1rem;
    border-radius: var(--hub-radius-sm);
    font-family: var(--hub-font-ui);
    font-size: 0.9rem;
    font-weight: bold;
    cursor: pointer;
    transition: var(--hub-transition);
    text-align: center;
    border: 1px solid transparent;
    display: inline-block;
    box-sizing: border-box;
}

.modal-card .btn-secondary {
    background: transparent;
    color: var(--hub-text-muted);
    border: 1px solid var(--hub-border);
}
.modal-card .btn-secondary:hover {
    background: var(--hub-surface-hover);
    color: var(--hub-text);
}

.modal-card .btn-primary {
    background: var(--hub-accent);
    color: #ffffff;
    border: 1px solid var(--hub-accent);
}
.modal-card .btn-primary:hover {
    background: var(--hub-accent-hover);
    border-color: var(--hub-accent-hover);
    transform: translateY(-1px);
}

@media (max-width: 480px) {
    .modal-card .modal-buttons-row,
    .modal-card .modal-actions-row {
        grid-template-columns: 1fr;
    }
}

/* ==========================================================================
   MODALES DE FORMULAIRES (GABARIT)
   ========================================================================== */
.modal-form-group { display: flex; flex-direction: column; gap: 0.4rem; margin-bottom: 1.1rem; }
.modal-form-group label { font-size: 0.83rem; font-weight: 700; color: var(--hub-text); }
.modal-form-group input,
.modal-form-group select {
    width: 100%;
    padding: 0.75rem;
    border-radius: var(--hub-radius-sm);
    border: 1px solid var(--hub-border);
    font-family: var(--hub-font-ui);
    font-size: 0.9rem;
    background: #ffffff;
    color: var(--hub-text);
    outline: none;
    box-sizing: border-box;
    transition: border-color 0.2s;
}
.modal-form-group input:focus,
.modal-form-group select:focus { border-color: var(--hub-accent); }
.modal-form-row { display: flex; align-items: center; gap: 0.8rem; }
.modal-form-row input { flex: 1; }
.modal-dim-field { display: flex; flex-direction: column; gap: 0.3rem; flex: 1; }
.modal-dim-label { font-size: 0.72rem; font-weight: 600; color: var(--hub-text-muted); text-transform: uppercase; letter-spacing: 0.02em; }
.modal-dim-separator { font-weight: bold; color: var(--hub-text-muted); flex-shrink: 0; margin-top: 1.4rem; }
.modal-checkbox-row { display: flex; align-items: center; gap: 0.5rem; margin-top: 0.7rem; font-size: 0.85rem; font-weight: 500; color: var(--hub-text); cursor: pointer; user-select: none; }
.modal-checkbox-row input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--hub-accent); cursor: pointer; }
.modal-swap-btn {
    flex-shrink: 0;
    margin-top: 1.4rem;
    width: 38px;
    height: 38px;
    border-radius: var(--hub-radius-sm);
    border: 1px solid var(--hub-border);
    background: #ffffff;
    color: var(--hub-text-muted);
    font-size: 1.05rem;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: border-color 0.2s, color 0.2s;
}
.modal-swap-btn:hover { border-color: var(--hub-accent); color: var(--hub-accent); }
.modal-preset-field { margin-top: 0.7rem; }


/* Modificateurs de sévérité */

/* 1. INFO / SUCCESS */
.card-info h3 {
    color: var(--hub-crochet);
}
.card-info .btn-primary {
    background: var(--hub-crochet);
    color: #ffffff;
    border-color: var(--hub-crochet);
}
.card-info .btn-primary:hover {
    background: var(--hub-crochet-hover);
    border-color: var(--hub-crochet-hover);
    transform: translateY(-1px);
}

/* 2. WARNING */
.card-warning h3 {
    color: var(--hub-gold);
}
.card-warning .btn-primary {
    background: var(--hub-gold);
    color: #ffffff;
    border-color: var(--hub-gold);
}
.card-warning .btn-primary:hover {
    background: #9a4708;
    border-color: #9a4708;
    transform: translateY(-1px);
}

/* 3. DANGER */
.card-danger h3 {
    color: var(--hub-danger);
}
.card-danger .btn-primary {
    background: var(--hub-danger);
    color: #ffffff;
    border-color: var(--hub-danger);
}
.card-danger .btn-primary:hover {
    background: #b91c1c;
    border-color: #b91c1c;
    transform: translateY(-1px);
}
