/* --- VARIABLES ET THÈMES --- */
:root {
    /* Couleurs de marque et accents */
    --primary: #6c5ce7;
    --secondary: #a29bfe;
    --accent-orange: #e67e22;
    --delete-red: #ff7675;

    /* Interface (Mode Clair) */
    --bg: #d5c7e5;
    --bgdeg: #dadaff;
    --text: #2d3436;
    --text-light: #b2bec3;
    --white: #fafafa;
    --border: #ddd;
    --card-bg: #fafafa;

    /* Effets Nostalgie & Animation */
    --paper-ivoire: #fffcf5;
    --paper-border: #e2d7c7;
    --blob-color: #e0d5c5;
    --overlay-bg: rgba(0, 0, 0, 0.7);
    --shadow-light: rgba(0, 0, 0, 0.05);
    --shadow-heavy: rgba(0, 0, 0, 0.2);
}

body.dark-mode {
    --bg: #1e1e2e;
    --bgdeg: #0d1416;
    --text: #f1f1f1;
    --text: #f1f1f1;
    --text-light: #a29bfe;
    --white: #2b2b3d;
    --border: #444;
    --card-bg: #2b2b3d;

    /* Adaptations Nostalgie & Animation */
    --paper-ivoire: #2b2b3d;
    --paper-border: #444;
    --blob-color: var(--primary);
}

/* Reset de base */
* {
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(45deg, var(--bg), var(--bgdeg));
    color: var(--text);
    margin: 0;
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: background 0.3s ease;
    min-height: 100vh;
}

/* --- LOGIQUE MODES GLOBAUX --- */
body.global-read-mode .day-card:not(.has-event) {
    display: none;
}

#globalModeSwitch.active {
    background: var(--primary);
    color: var(--white);
    border: none;
}

/* --- BARRE DE CONNEXION (REMANIÉE) --- */
.auth-bar {
    display: flex;
    flex-wrap: wrap; 
    justify-content: space-between;
    align-items: center;
    width: 100%;
    max-width: 1200px;
    gap: 10px;
    margin-bottom: 20px;
    padding: 12px 15px;
    background: var(--white);
    border-radius: 15px;
    box-shadow: 0 4px 12px var(--shadow-light);
}

.nav-controls, .user-controls {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-email { 
    font-weight: 600; 
    font-size: 0.85rem; 
    color: var(--primary);
    max-width: 180px; 
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.legal-link-nav {
    font-size: 0.7rem;
    color: var(--text-light);
    text-decoration: none;
    opacity: 0.8;
}

/* --- ADAPTATION MOBILE --- */
@media (max-width: 600px) {
    .auth-bar {
        flex-direction: column;
        padding: 15px;
    }

    .nav-controls, .user-controls {
        width: 100%;
        justify-content: center;
        flex-wrap: wrap;
    }

    .user-email {
        max-width: none;
        width: 100%;
        text-align: center;
        margin: 5px 0;
    }

    header h1 { font-size: 2.2rem; } /* Titre plus petit sur tel */

    .view-controls {
        display: flex;
        flex-direction: column;
        width: 100%;
    }

    .view-controls select, .view-controls input {
        width: 100%;
    }
}

/* --- HEADER ET RECHERCHE --- */
header {
    text-align: center;
    margin-bottom: 30px;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

header h1 { font-size: 3rem; margin-bottom: 20px; font-weight: 800; }

.search-container {
    width: 100%;
    max-width: 500px;
    margin: 0 auto 25px auto;
}

#searchInput {
    width: 100%;
    padding: 15px 25px;
    border-radius: 30px;
    border: 2px solid var(--border);
    background: var(--white);
    color: var(--text);
    font-size: 1rem;
    transition: all 0.3s ease;
    outline: none;
}

#searchInput:focus {
    border-color: var(--primary);
    box-shadow: 0 4px 15px rgba(108, 92, 231, 0.2);
}

.filter-label {
    font-size: 0.8rem;
    color: var(--text);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 15px;
}

.view-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

/* --- INPUTS / SELECTS GÉNÉRAUX --- */
input, textarea, select {
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background-color: var(--white);
    color: var(--text);
    font-family: inherit;
    font-size: 0.9rem;
    outline: none;
}

/* --- CALENDRIER --- */
#calendar {
    display: grid;
    gap: 15px;
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
}

#calendar.view-year { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
#calendar.view-month { grid-template-columns: repeat(7, 1fr); }

.day-card {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 15px;
    min-height: 120px;
    box-shadow: 0 4px 6px var(--shadow-light);
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    display: flex;
    flex-direction: column;
}

.day-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 15px rgba(0,0,0,0.1);
}

.day-number { font-weight: bold; font-size: 1.2rem; color: var(--secondary); }
.month-label { font-size: 0.75rem; text-transform: uppercase; color: var(--text-light); letter-spacing: 1px; }

.has-event {
    border-top: 5px solid var(--primary);
    background: var(--paper-ivoire) !important;
    border-left: 1px solid var(--paper-border);
    border-right: 1px solid var(--paper-border);
    border-bottom: 1px solid var(--paper-border);
    box-shadow: 2px 2px 10px var(--shadow-light);
}

.event-preview-title {
    font-size: 0.85rem;
    font-weight: 600;
    margin-top: 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.event-thumbnail {
    width: 100%;
    height: 60px;
    object-fit: cover;
    border-radius: 6px;
    margin-top: auto;
    filter: sepia(0.3) contrast(0.9);
    transition: all 0.5s ease;
}

.day-card:hover .event-thumbnail {
    filter: sepia(0) contrast(1.1);
    transform: scale(1.05);
}

/* --- MODALES --- */
#modal, #authModal {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: var(--overlay-bg);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 100;
    backdrop-filter: blur(5px);
}

.modal-content {
    background: var(--white);
    padding: 30px;
    border-radius: 20px;
    width: 90%;
    max-width: 600px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    box-shadow: 0 20px 40px var(--shadow-heavy);
}

/* --- MODE VISUALISATION (LECTURE) --- */
#viewMode {
    display: flex;
    flex-direction: column;
}

#viewImage {
    width: 100%;
    max-height: 400px;
    object-fit: contain;
    border-radius: 12px;
    margin: 15px 0;
    background: #000;
}

#viewTitle { font-size: 1.8rem; margin: 0; color: var(--primary); }
#viewDesc { font-size: 1.1rem; line-height: 1.6; white-space: pre-wrap; margin: 15px 0; }

/* --- MODE ÉDITION (FIXÉ) --- */
#editMode {
    display: flex;
    flex-direction: column;
    gap: 15px; /* Espace constant entre chaque élément */
    width: 100%;
}

/* On force tous les éléments internes à prendre toute la largeur */
#editMode input[type="text"],
#editMode textarea,
#editMode input[type="file"],
#previewImage {
    width: 100% !important; /* Force la largeur totale de la modale */
    max-width: 100%;
    display: block;
    box-sizing: border-box; /* Indispensable pour que le padding ne fasse pas déborder l'input */
}

#editMode textarea {
    resize: vertical; /* Permet d'agrandir en hauteur seulement */
    min-height: 100px;
}

#previewImage {
    max-height: 300px;
    object-fit: contain; /* Évite de déformer l'image chargée */
    background: #000;
    border-radius: 10px;
    margin: 10px 0;
}

/* On s'assure que les boutons en bas restent alignés à droite sur une seule ligne */
#editMode .modal-footer {
    display: flex;
    flex-direction: row; /* On repasse en ligne pour les boutons */
    justify-content: flex-end;
    gap: 10px;
    width: 100%;
    padding-top: 15px;
    border-top: 1px solid var(--border);
}

/* --- BOUTONS --- */
button {
    padding: 12px 20px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.2s ease;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 10px;
    padding-top: 15px;
    border-top: 1px solid var(--border);
}

.btn-save { background: var(--primary); color: var(--white); }
.btn-delete { background: var(--delete-red); color: var(--white); }
.btn-cancel { background: var(--white); border: 1px solid var(--border); color: var(--text); }

/* --- RESPONSIVE --- */
@media (max-width: 600px) {
    #calendar.view-month { grid-template-columns: repeat(3, 1fr); }
    .view-controls { flex-direction: column; width: 100%; }
    input, select { width: 100%; }
}

/* Effets nostalgiques */
body::before {
    content: "";
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    opacity: 0.04;
    pointer-events: none;
    background-image: url('https://www.transparenttextures.com/patterns/stardust.png');
    z-index: 9999;
}

/* --- ANIMATION DE FOND --- */
.bg-animation {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    z-index: -1;
    overflow: hidden;
    pointer-events: none;
}

.blob {
    position: absolute;
    width: 500px;
    height: 500px;
    background: var(--blob-color);
    filter: blur(80px);
    opacity: 0.15;
    border-radius: 50%;
    animation: move 20s infinite alternate;
    transition: background 0.5s ease;
}

.blob:nth-child(2) {
    width: 600px; height: 600px;
    right: -10%; top: -10%;
    animation-duration: 30s;
    opacity: 0.1;
}

@keyframes move {
    from { transform: translate(0, 0) rotate(0deg); }
    to { transform: translate(20vw, 20vh) rotate(360deg); }
}

body.dark-mode .blob {
    opacity: 0.2;
    filter: blur(120px);
}

body:not(.dark-mode) .blob {
    opacity: 0.7;
    filter: blur(120px);
}

/* --- STYLES EXCLUSIFS AU MODE CLAIR --- */
body:not(.dark-mode) {
    background-image: url('https://www.transparenttextures.com/patterns/p6.png'), /* Texture plus forte */
    linear-gradient(var(--bg), var(--bgdeg));
    background-blend-mode: multiply;
    background-attachment: fixed;
    /* On peut aussi jouer sur la taille de la texture pour la rendre plus brute */
    background-size: 20px 20px, auto;
}

/* Animation de "flottaison" pour les cartes souvenirs en mode clair */
body:not(.dark-mode)
.day-card.has-event {
    animation: float 6s ease-in-out infinite;
    /* Rotation aléatoire légère pour le côté "photos jetées sur une table" */
    transform: rotate(var(--rotation, -1deg));
}

/* On alterne la rotation pour ne pas que tout soit penché du même côté */
body:not(.dark-mode)
.day-card.has-event:nth-child(even) {
    --rotation: 1.5deg;
    animation-delay: -2s;
}

body:not(.dark-mode) .day-card.has-event:nth-child(3n) {
    --rotation: -2deg;
    animation-delay: -4s;
}

/* Effet de survol "Focus" : la carte se remet droite et s'illumine */
body:not(.dark-mode) .day-card.has-event:hover {
    transform: rotate(0deg) scale(1.08) !important;
    z-index: 10;
    box-shadow: 0 15px 30px rgba(0,0,0,0.1);
    background: #ffffff !important;
}

/* Petite décoration : une épingle ou un bout de scotch sur les souvenirs */
body:not(.dark-mode) .day-card.has-event::before {
    content: "";
    position: absolute;
    top: -10px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 15px;
    background: rgba(210, 180, 140, 0.3); /* Effet scotch translucide */
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

/* --- PLACEHOLDER "+" SUR LES CASES VIDES --- */

/* On s'assure que la carte est bien le référentiel pour le positionnement */
.day-card {
    position: relative; /* Important pour centrer le + */
}

/* Le style du "+" (caché par défaut) */
body:not(.global-read-mode) .day-card:not(.has-event)::after {
    content: "+";
    position: absolute;
    top: 50%;
    left: 50%;
    /* On le centre et on le réduit un peu au début pour l'animation */
    transform: translate(-50%, -50%) scale(0.5);
    
    font-size: 4rem;       /* Assez grand */
    font-weight: 200;      /* Fin et élégant */
    color: var(--secondary); /* Utilise la couleur secondaire du thème */
    opacity: 0;            /* Invisible par défaut */
    
    /* Animation fluide "pop" */
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    pointer-events: none;  /* Le clic traverse le + pour cliquer sur la div */
}

/* Au survol, on l'affiche et on le fait grandir */
body:not(.global-read-mode) .day-card:not(.has-event):hover::after {
    opacity: 0.5;  /* Reste discret (translucide) */
    transform: translate(-50%, -50%) scale(1); /* Taille normale */
}

/* Optionnel : changer légèrement la couleur de fond de la case vide au survol */
body:not(.global-read-mode) .day-card:not(.has-event):hover {
    background-color: rgba(255, 255, 255, 0.5); /* Éclaircit légèrement */
}

/* --- FIX POP-UP MENTIONS LÉGALES --- */
#legalModal {
    position: fixed;
    inset: 0; /* Prend tout l'écran */
    background: var(--overlay-bg);
    display: none; /* Caché par défaut */
    justify-content: center;
    align-items: center;
    z-index: 200; /* Au-dessus de tout, même des autres modales */
    backdrop-filter: blur(5px);
    padding: 20px;
}

#legalModal .modal-content {
    /* On s'assure qu'elle ne soit pas collée aux bords */
    margin: auto; 
    box-shadow: 0 20px 40px var(--shadow-heavy);
}

/* Espacement pour le lien en bas de page */
.legal-link-container {
    margin-top: 40px;
    margin-bottom: 20px;
    text-align: center;
    width: 100%;
}
