/**
 * ============================================================================
 * MOODIA EDITOR - STYLES MINIMAUX
 * ============================================================================
 *
 * Ce fichier contient uniquement les styles qui ne peuvent pas être en Tailwind :
 * - Animations @keyframes
 * - Pseudo-éléments (::before, ::after, ::placeholder)
 * - Scrollbar custom
 * - WYSIWYG typography
 *
 * Tout le reste est en Tailwind inline dans le template et le JS.
 *
 * ============================================================================
 */

/* ========================================================================
   ANIMATIONS
   ======================================================================== */

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

/* Animation barre de chargement audio */
@keyframes loading-bar {
    0% { transform: translateX(-100%); }
    50% { transform: translateX(0%); }
    100% { transform: translateX(100%); }
}

.animate-loading-bar {
    animation: loading-bar 1.5s ease-in-out infinite;
}

@keyframes pulse-amber {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.7; transform: scale(1.2); }
}

@keyframes pulse-icon {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

@keyframes slide-in-right {
    from { opacity: 0; transform: translateX(20px); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes slide-in-left {
    from { opacity: 0; transform: translateX(-20px); }
    to { opacity: 1; transform: translateX(0); }
}

.animate-slide-right {
    animation: slide-in-right 200ms ease;
}

.animate-slide-left {
    animation: slide-in-left 200ms ease;
}

/* ========================================================================
   SCROLLBAR CUSTOM POUR NAVIGATOR
   ======================================================================== */

.scrollbar-thin {
    scrollbar-width: thin;
}

.scrollbar-thumb-gray-200 {
    scrollbar-color: #E5E7EB transparent;
}

.scrollbar-track-transparent {
    scrollbar-color: inherit transparent;
}

/* Webkit (Chrome, Safari, Edge) */
.scrollbar-thin::-webkit-scrollbar {
    width: 6px;
}

.scrollbar-thin::-webkit-scrollbar-track {
    background: transparent;
}

.scrollbar-thin::-webkit-scrollbar-thumb {
    background: #E5E7EB;
    border-radius: 3px;
}

.scrollbar-thin::-webkit-scrollbar-thumb:hover {
    background: #9CA3AF;
}

/* ========================================================================
   WYSIWYG PLACEHOLDER
   ======================================================================== */

[contenteditable][data-placeholder]:empty::before {
    content: attr(data-placeholder);
    color: #9CA3AF;
    pointer-events: none;
    display: block;
}

/* Placeholder réel de la zone d'écriture : un <p data-placeholder> vide (il contient un <br>,
   donc pas :empty) affiche son data-placeholder, lu via attr(). Disparaît dès la 1re frappe.
   :only-of-type → affiché UNIQUEMENT quand l'éditeur ne contient qu'UN paragraphe (il ignore le
   <div clear:both> final, d'un type différent). Sinon, faire Entrée clonait le paragraphe avec son
   data-placeholder et le placeholder s'affichait sur chaque ligne vide. */
.moodia-rich-text > p[data-placeholder]:only-of-type:empty::before,
.moodia-rich-text > p[data-placeholder]:only-of-type:has(> br:only-child)::before {
    content: attr(data-placeholder);
    color: #9CA3AF;
    pointer-events: none;
}

/* ========================================================================
   WYSIWYG TYPOGRAPHY
   ======================================================================== */

[contenteditable] {
    font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
    color: #1E293B;
    line-height: 1.8;
}

[contenteditable] h2 {
    margin-top: 1.5rem;
    margin-bottom: 0.75rem;
    font-size: 1.5rem;
    font-weight: 700;
    font-family: 'Inter', 'Poppins', sans-serif;
}

[contenteditable] h3 {
    margin-top: 1.25rem;
    margin-bottom: 0.5rem;
    font-size: 1.25rem;
    font-weight: 600;
    font-family: 'Inter', 'Poppins', sans-serif;
}

[contenteditable] p {
    margin-bottom: 1rem;
}

[contenteditable] ul,
[contenteditable] ol {
    margin-bottom: 1rem;
    padding-left: 1.5rem;
}

[contenteditable] ul li {
    list-style-type: disc;
}

[contenteditable] ol li {
    list-style-type: decimal;
}

[contenteditable] li {
    margin-bottom: 0.25rem;
}

[contenteditable] a {
    color: #2563EB;
    text-decoration: underline;
}

[contenteditable] blockquote {
    margin: 1rem 0;
    padding: 1rem 1.5rem;
    border-left: 4px solid #8B5CF6;
    background: #F5F3FF;
    border-radius: 0 0.5rem 0.5rem 0;
    font-style: italic;
    color: #4C1D95;
}

[contenteditable] s,
[contenteditable] strike {
    text-decoration: line-through;
    color: #9CA3AF;
}

/* Tables AI-générées */
[contenteditable] table {
    width: 100%;
    border-collapse: collapse;
    border-radius: 8px;
    overflow: hidden;
    margin: 1.5rem 0;
}

[contenteditable] table th {
    padding: 0.75rem 1rem;
    text-align: left;
    font-weight: 600;
}

[contenteditable] table td {
    padding: 0.6rem 1rem;
    border-bottom: 1px solid #E2E8F0;
}

/* Images dans le contenu */
[contenteditable] img {
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    max-width: 100%;
    height: auto;
}

/* Séparateurs */
[contenteditable] hr {
    border: none;
    height: 1px;
    background: linear-gradient(to right, transparent, #CBD5E1, transparent);
    margin: 2rem 0;
}

/* ========================================================================
   EXPORT SUCCESS - ANIMATIONS PREMIUM
   ======================================================================== */

/* Checkmark animé (SVG stroke draw) */
@keyframes check-draw {
    0% { stroke-dashoffset: 30; }
    100% { stroke-dashoffset: 0; }
}

.animate-check-draw {
    stroke-dasharray: 30;
    stroke-dashoffset: 30;
    animation: check-draw 0.5s ease-out 0.2s forwards;
}

/* Fade-up pour étapes staggerées */
@keyframes fade-up-in {
    0% { opacity: 0; transform: translateY(12px); }
    100% { opacity: 1; transform: translateY(0); }
}

.animate-fade-up {
    opacity: 0;
    animation: fade-up-in 0.4s ease-out forwards;
}

/* Sparkles en orbite autour du cercle de succès */
@keyframes sparkle-orbit-1 {
    0% { transform: rotate(0deg) translateX(42px) scale(0); opacity: 0; }
    20% { transform: rotate(72deg) translateX(42px) scale(1); opacity: 1; }
    80% { transform: rotate(288deg) translateX(42px) scale(0.8); opacity: 0.8; }
    100% { transform: rotate(360deg) translateX(42px) scale(0); opacity: 0; }
}

@keyframes sparkle-orbit-2 {
    0% { transform: rotate(120deg) translateX(38px) scale(0); opacity: 0; }
    25% { transform: rotate(210deg) translateX(38px) scale(1); opacity: 1; }
    75% { transform: rotate(330deg) translateX(38px) scale(0.6); opacity: 0.6; }
    100% { transform: rotate(480deg) translateX(38px) scale(0); opacity: 0; }
}

@keyframes sparkle-orbit-3 {
    0% { transform: rotate(240deg) translateX(45px) scale(0); opacity: 0; }
    30% { transform: rotate(348deg) translateX(45px) scale(1); opacity: 1; }
    70% { transform: rotate(492deg) translateX(45px) scale(0.7); opacity: 0.7; }
    100% { transform: rotate(600deg) translateX(45px) scale(0); opacity: 0; }
}

.animate-sparkle {
    animation: sparkle-orbit-1 2.5s ease-in-out 0.3s infinite;
}

.animate-sparkle-2 {
    animation: sparkle-orbit-2 3s ease-in-out 0.8s infinite;
}

.animate-sparkle-3 {
    animation: sparkle-orbit-3 3.5s ease-in-out 1.3s infinite;
}

/* Transition progress → tutorial */
@keyframes scale-fade-out {
    0% { opacity: 1; transform: scale(1); }
    100% { opacity: 0; transform: scale(0.95); }
}

@keyframes scale-fade-in {
    0% { opacity: 0; transform: scale(1.02); }
    100% { opacity: 1; transform: scale(1); }
}

.animate-scale-fade-out {
    animation: scale-fade-out 0.3s ease-in forwards;
}

.animate-scale-fade-in {
    animation: scale-fade-in 0.4s ease-out 0.15s forwards;
    opacity: 0;
}

/* Cercle de succès pulse lent */
@keyframes success-pulse {
    0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.4); }
    50% { transform: scale(1.03); box-shadow: 0 0 0 12px rgba(16, 185, 129, 0); }
}

.animate-success-pulse {
    animation: success-pulse 2s ease-in-out infinite;
}

/* ========================================================================
   RESPONSIVE - PAGINATION
   ======================================================================== */

@media (max-width: 1024px) {
    /* Sur mobile/tablette, la pagination prend toute la largeur */
    [data-moodia--editor-target="pagination"] {
        left: 0 !important;
    }
}


/* Key terms (dl/dt/dd) */
[contenteditable] dl {
    margin: 1.5rem 0;
}

[contenteditable] dt {
    font-weight: 600;
    color: #0F172A;
    margin-top: 1rem;
}

[contenteditable] dd {
    margin: 0.25rem 0 0 1rem;
    color: #475569;
    border-left: 2px solid #E2E8F0;
    padding-left: 0.75rem;
}

/* === Formules LaTeX (KaTeX) dans l'éditeur === */
.moodia-math {
    cursor: pointer;
    border-radius: 4px;
    transition: background-color 0.12s ease;
}
.moodia-math:hover {
    background-color: rgba(124, 58, 237, 0.1); /* violet léger au survol = éditable */
}
.moodia-math--display {
    display: block;
    margin: 0.75rem 0;
    clear: both;            /* dégage une image flottée : la formule prend toute la largeur */
    max-width: 100%;
    overflow-x: auto;       /* formule trop large → défilement horizontal au lieu de déborder */
    overflow-y: hidden;
}
/* Formule en cours d'édition (LaTeX brut) */
.moodia-math-editing {
    background-color: rgba(124, 58, 237, 0.08);
    border-radius: 4px;
    padding: 0 2px;
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', monospace;
    font-size: 0.95em;
}

/* Alignement horizontal d'une image (sans float). Gauche/droite avec texte à côté = rangée flex. */
/* Image gauche/droite = float : le texte s'écoule à côté puis sous l'image.
   Les blocs « pleine largeur » (citation, tableau, séparateur, encadré) DÉGAGENT le float
   pour ne pas s'enrouler autour de l'image et casser leur mise en page. */
.moodia-rich-text blockquote,
.moodia-rich-text table,
.moodia-rich-text hr,
.moodia-rich-text [data-callout] {
    clear: both;
}

/* Image : sélection au clic (anneau), poignée de resize + pastille de % visibles à la sélection.
   Les contrôles sont gérés par une barre flottante (alignement / largeur / remplacer / supprimer). */
.moodia-img { cursor: pointer; }
.moodia-img .moodia-img-frame { transition: box-shadow 0.12s ease; }
.moodia-img.is-selected .moodia-img-frame {
    box-shadow: 0 0 0 2px var(--color-primary, #0C81E4);
    border-color: transparent;
}
.moodia-img .moodia-img-handle,
.moodia-img .moodia-img-pct {
    opacity: 0;
    transition: opacity 0.12s ease;
}
.moodia-img.is-selected .moodia-img-handle,
.moodia-img.is-resizing .moodia-img-handle,
.moodia-img.is-selected .moodia-img-pct,
.moodia-img.is-resizing .moodia-img-pct {
    opacity: 1;
}
/* Pendant le redimensionnement, le curseur reste cohérent sur toute la page. */
.moodia-img.is-resizing,
.moodia-img.is-resizing * { cursor: nwse-resize !important; }

/* Poignée de déplacement (drag) : visible quand l'image est sélectionnée. */
.moodia-img .moodia-img-drag { opacity: 0; transition: opacity 0.12s ease; }
.moodia-img.is-selected .moodia-img-drag { opacity: 1; }
.moodia-img.is-selected .moodia-img-drag:active { cursor: grabbing; }
.moodia-img.is-dragging { opacity: 0.4; }
/* Indicateur de dépôt : trait droit coloré au-dessus/en dessous du bloc visé. */
.moodia-drop-before { box-shadow: inset 0 3px 0 var(--color-primary, #0C81E4); border-radius: 0; }
.moodia-drop-after  { box-shadow: inset 0 -3px 0 var(--color-primary, #0C81E4); border-radius: 0; }
