/* ========================================
   Modals et Toasts
   ======================================== */

/* Modal - Overlay de fond */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--color-background-overlay);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-normal);
    z-index: var(--z-modal);
    padding: var(--spacing-lg);
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* Conteneur du modal */
.modal {
    background: var(--color-background);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    max-width: 600px;
    width: 100%;
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transform: scale(0.9);
    transition: transform var(--transition-normal);
}

.modal-overlay.active .modal {
    transform: scale(1);
}

/* Tailles de modals personnalisées */
.modal-small {
    max-width: 400px;
}

.modal-medium {
    max-width: 600px;
}

.modal-large {
    max-width: 800px;
}

.modal-xlarge {
    max-width: 1000px;
}

.modal-full {
    max-width: 95vw;
    max-height: 95vh;
}

/* En-tête du modal */
.modal-header {
    padding: var(--spacing-lg);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.modal-title {
    font-size: var(--font-size-xl);
    font-weight: 600;
    color: var(--color-text-primary);
    margin: 0;
}

.modal-close {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-text-secondary);
    transition: all var(--transition-fast);
}

.modal-close:hover {
    background: var(--color-background-light);
    color: var(--color-text-primary);
}

.modal-close svg {
    width: 20px;
    height: 20px;
}

/* Corps du modal */
.modal-body {
    padding: var(--spacing-lg);
    overflow-y: auto;
    flex: 1;
}

.modal-body p:last-child {
    margin-bottom: 0;
}

.modal-body img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius-md);
    margin: var(--spacing-md) 0;
}

.modal-body h1,
.modal-body h2,
.modal-body h3,
.modal-body h4 {
    margin-top: var(--spacing-lg);
}

.modal-body h1:first-child,
.modal-body h2:first-child,
.modal-body h3:first-child,
.modal-body h4:first-child {
    margin-top: 0;
}

/* Pied du modal (optionnel) */
.modal-footer {
    padding: var(--spacing-lg);
    border-top: 1px solid var(--color-border);
    display: flex;
    gap: var(--spacing-sm);
    justify-content: flex-end;
    flex-shrink: 0;
}

.modal-footer button {
    padding: var(--spacing-sm) var(--spacing-lg);
    border-radius: var(--radius-md);
    font-weight: 500;
    transition: all var(--transition-fast);
}

.modal-footer .btn-primary {
    background: var(--color-primary);
    color: var(--color-text-light);
}

.modal-footer .btn-primary:hover {
    background: var(--color-primary-dark);
}

.modal-footer .btn-secondary {
    background: var(--color-background-light);
    color: var(--color-text-primary);
}

.modal-footer .btn-secondary:hover {
    background: var(--color-border);
}

/* Toasts */
.toast-container {
    position: fixed;
    bottom: 70px;
    right: var(--spacing-xl);
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
    z-index: var(--z-toast);
    max-width: 400px;
    pointer-events: none; /* Permet de cliquer à travers le conteneur vide */
}

.toast {
    background: var(--color-background);
    border-radius: var(--radius-lg);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    padding: var(--spacing-lg);
    display: flex;
    gap: var(--spacing-md);
    transform: translateX(calc(100% + var(--spacing-xl)));
    transition: transform var(--transition-normal);
    border-left: 4px solid var(--color-primary);
    pointer-events: auto; /* Réactive les interactions sur le toast lui-même */
}

.toast.active {
    transform: translateX(0);
}

.toast.toast-success {
    border-left-color: var(--color-success);
}

.toast.toast-warning {
    border-left-color: var(--color-warning);
}

.toast.toast-error {
    border-left-color: var(--color-error);
}

.toast-content {
    flex: 1;
}

.toast-title {
    font-weight: 600;
    margin-bottom: var(--spacing-xs);
    color: var(--color-text-primary);
}

.toast-message {
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
    margin: 0;
}

.toast-close {
    width: 24px;
    height: 24px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-text-secondary);
    flex-shrink: 0;
    transition: all var(--transition-fast);
}

.toast-close:hover {
    background: var(--color-background-light);
    color: var(--color-text-primary);
}

/* Barre de progression pour auto-fermeture */
.toast-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--color-border);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    overflow: hidden;
}

.toast-progress-bar {
    height: 100%;
    background: var(--color-primary);
    transition: width linear;
}

.toast-success .toast-progress-bar {
    background: var(--color-success);
}

.toast-warning .toast-progress-bar {
    background: var(--color-warning);
}

.toast-error .toast-progress-bar {
    background: var(--color-error);
}

/* Responsive */
@media (max-width: 768px) {
    .modal {
        max-width: 100%;
        max-height: 90vh;
    }
    
    .modal-overlay {
        padding: var(--spacing-md);
    }
    
    .toast-container {
        left: var(--spacing-md);
        right: var(--spacing-md);
        max-width: none;
    }
}

@media (min-width: 768px) {
    .modal {
        max-width: 700px;
    }
    
    .modal-header {
        padding: var(--spacing-xl);
    }
    
    .modal-body {
        padding: var(--spacing-xl);
    }
    
    .modal-footer {
        padding: var(--spacing-xl);
    }
}

/* Support tactile */
@media (hover: none) and (pointer: coarse) {
    .modal-close,
    .toast-close {
        min-width: 44px;
        min-height: 44px;
    }
    
    .modal-footer button {
        min-height: 44px;
        padding: var(--spacing-md) var(--spacing-xl);
    }
}

/* Amélioration de l'accessibilité */
.modal-overlay:focus-within .modal {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

/* ========================================
   Bulle de dialogue (Speech Bubble)
   ======================================== */

/* Overlay pour bulle - transparent, pas de fond sombre */
.modal-overlay.bubble-overlay {
    background: transparent;
    align-items: flex-start;
    justify-content: flex-start;
    pointer-events: none;
}

.modal-overlay.bubble-overlay.active {
    pointer-events: auto;
}

/* Conteneur de la bulle */
.modal-bubble {
    background: white;
    border-radius: 20px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    max-width: 450px;
    width: auto;
    min-width: 300px;
    position: absolute;
    opacity: 0;
    transition: opacity var(--transition-normal);
    pointer-events: auto;
    border: 2px solid #e5e7eb;
    padding: 0;
}

.modal-overlay.active .modal-bubble {
    opacity: 1;
}

/* Flèche de la bulle pointant vers le bas */
.modal-bubble::after {
    content: '';
    position: absolute;
    bottom: -20px;
    left: 50px;
    width: 0;
    height: 0;
    border-left: 20px solid transparent;
    border-right: 20px solid transparent;
    border-top: 20px solid white;
    filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.1));
}

.modal-bubble::before {
    content: '';
    position: absolute;
    bottom: -22px;
    left: 48px;
    width: 0;
    height: 0;
    border-left: 22px solid transparent;
    border-right: 22px solid transparent;
    border-top: 22px solid #e5e7eb;
    z-index: -1;
}

/* En-tête de la bulle - cachée pour les bulles de dialogue */
.modal-bubble .modal-header {
    display: none;
}

/* Corps de la bulle */
.modal-bubble .modal-body {
    padding: 24px;
    font-size: 1rem;
    line-height: 1.7;
    color: #1f2937;
}

.modal-bubble .modal-body p {
    margin-bottom: var(--spacing-md);
}

.modal-bubble .modal-body strong {
    color: #1f2937;
    font-weight: 600;
}

/* Bouton de navigation dans la bulle */
.modal-navigate-button {
    display: inline-block;
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: white;
    padding: 12px 28px;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
    text-decoration: none;
}

.modal-navigate-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(59, 130, 246, 0.4);
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
}

.modal-navigate-button:active {
    transform: translateY(0);
}

/* Positionnement responsive de la bulle */
@media (max-width: 768px) {
    .modal-bubble {
        max-width: calc(100vw - 40px);
        min-width: calc(100vw - 40px);
        left: 20px !important;
        right: 20px;
    }
    
    .modal-bubble::after,
    .modal-bubble::before {
        left: 30px;
    }
}

/* Variante de bulle avec flèche à droite (pour personnage à droite) */
.modal-bubble.bubble-left {
    /* Position initiale pour éviter le "saut" */
    transform: translate(-100%, -50%) scale(0.8);
}

.modal-overlay.active .modal-bubble.bubble-left {
    transform: translate(-100%, -50%) scale(1);
}

.modal-bubble.bubble-left::after {
    /* Flèche pointant vers la droite */
    bottom: auto;
    left: auto;
    right: -20px;
    top: 50%;
    transform: translateY(-50%);
    border-left: 20px solid white;
    border-right: none;
    border-top: 20px solid transparent;
    border-bottom: 20px solid transparent;
}

.modal-bubble.bubble-left::before {
    /* Bordure de la flèche pointant vers la droite */
    bottom: auto;
    left: auto;
    right: -22px;
    top: 50%;
    transform: translateY(-50%);
    border-left: 22px solid #e5e7eb;
    border-right: none;
    border-top: 22px solid transparent;
    border-bottom: 22px solid transparent;
}

/* Variante de bulle avec flèche à gauche (pour personnage à gauche) */
.modal-bubble.bubble-right {
    /* Position initiale pour éviter le "saut" */
    transform: translateY(-50%) scale(0.8);
}

.modal-overlay.active .modal-bubble.bubble-right {
    transform: translateY(-50%) scale(1);
}

.modal-bubble.bubble-right::after {
    /* Flèche pointant vers la gauche */
    bottom: auto;
    left: -20px;
    right: auto;
    top: 50%;
    transform: translateY(-50%);
    border-right: 20px solid white;
    border-left: none;
    border-top: 20px solid transparent;
    border-bottom: 20px solid transparent;
}

.modal-bubble.bubble-right::before {
    /* Bordure de la flèche pointant vers la gauche */
    bottom: auto;
    left: -22px;
    right: auto;
    top: 50%;
    transform: translateY(-50%);
    border-right: 22px solid #e5e7eb;
    border-left: none;
    border-top: 22px solid transparent;
    border-bottom: 22px solid transparent;
}

/* Animation d'apparition - scale seulement, pas de translateY */
@keyframes bubblePop {
    0% {
        transform: translateY(-100%) scale(0.8);
        opacity: 0;
    }
    50% {
        transform: translateY(-100%) scale(1.05);
    }
    100% {
        transform: translateY(-100%) scale(1);
        opacity: 1;
    }
}

.modal-overlay.active .modal-bubble {
    animation: bubblePop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Animation pour bulle à gauche */
@keyframes bubblePopLeft {
    0% {
        transform: translate(-100%, -50%) scale(0.8);
        opacity: 0;
    }
    50% {
        transform: translate(-100%, -50%) scale(1.05);
    }
    100% {
        transform: translate(-100%, -50%) scale(1);
        opacity: 1;
    }
}

.modal-overlay.active .modal-bubble.bubble-left {
    animation: bubblePopLeft 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Animation pour bulle à droite */
@keyframes bubblePopRight {
    0% {
        transform: translateY(-50%) scale(0.8);
        opacity: 0;
    }
    50% {
        transform: translateY(-50%) scale(1.05);
    }
    100% {
        transform: translateY(-50%) scale(1);
        opacity: 1;
    }
}

.modal-overlay.active .modal-bubble.bubble-right {
    animation: bubblePopRight 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ========================================
   Popover (Le saviez-vous ?)
   ======================================== */

.popover {
    position: absolute;
    background: var(--color-primary);
    color: white;
    padding: 16px 20px;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 255, 0.4);
    max-width: 320px;
    min-width: 250px;
    z-index: var(--z-modal);
    opacity: 0;
    transform: scale(0.8) translateY(10px);
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    pointer-events: auto;
}

.popover.active {
    opacity: 1;
    transform: scale(1) translateY(0);
}

.popover-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
    font-weight: 600;
    font-size: 0.95rem;
}

.popover-icon {
    font-size: 1.3rem;
}

.popover-body {
    font-size: 0.9rem;
    line-height: 1.6;
    color: rgba(255, 255, 255, 0.95);
}

.popover-body p {
    margin: 0;
}

.popover-body p + p {
    margin-top: 8px;
}

/* Flèche du popover */
.popover::before {
    content: '';
    position: absolute;
    top: -8px;
    left: 20px;
    width: 0;
    height: 0;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-bottom: 8px solid var(--color-primary);
}

/* Variantes de position du popover */
.popover.popover-bottom::before {
    top: -8px;
    bottom: auto;
    border-top: none;
    border-bottom: 8px solid var(--color-primary);
}

.popover.popover-top::before {
    top: auto;
    bottom: -8px;
    border-bottom: none;
    border-top: 8px solid var(--color-primary);
}

.popover.popover-left::before {
    top: 50%;
    left: auto;
    right: -8px;
    transform: translateY(-50%);
    border-top: 8px solid transparent;
    border-bottom: 8px solid transparent;
    border-left: 8px solid var(--color-primary);
    border-right: none;
}

.popover.popover-right::before {
    top: 50%;
    left: -8px;
    right: auto;
    transform: translateY(-50%);
    border-top: 8px solid transparent;
    border-bottom: 8px solid transparent;
    border-right: 8px solid var(--color-primary);
    border-left: none;
}

/* Animation d'apparition */
@keyframes popoverShow {
    0% {
        opacity: 0;
        transform: scale(0.8) translateY(10px);
    }
    100% {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* Animation pour popovers left/right (centrés verticalement) */
@keyframes popoverShowCentered {
    0% {
        opacity: 0;
        transform: translateY(-50%) scale(0.8);
    }
    100% {
        opacity: 1;
        transform: translateY(-50%) scale(1);
    }
}

.popover.active {
    animation: popoverShow 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.popover.popover-left.active,
.popover.popover-right.active {
    animation: popoverShowCentered 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Responsive */
@media (max-width: 768px) {
    .popover {
        max-width: calc(100vw - 40px);
        font-size: 0.85rem;
    }
}
