:root {
    /* === PALETTE UNIFIÉE SIMCRISE === */
    /* Variables principales - NOUVELLE ARCHITECTURE */
    --simcrise-primary: #2563eb;      /* Bleu institutionnel unifié */
    --simcrise-secondary: #64748b;    /* Gris professionnel */
    --simcrise-accent: #059669;       /* Vert validation/succès */
    --simcrise-warning: #ea580c;      /* Orange attention */
    --simcrise-error: #dc2626;        /* Rouge danger */
    --simcrise-info: #3b82f6;         /* Bleu information */
    
    /* Backgrounds unifiés */
    --simcrise-bg-primary: #f8fafc;   /* Fond principal */
    --simcrise-bg-secondary: #ffffff; /* Fond cartes */
    --simcrise-bg-hover: #f1f5f9;     /* Fond survol */
    
    /* Bordures unifiées */
    --simcrise-border-light: #e2e8f0;
    --simcrise-border-medium: #cbd5e1;
    --simcrise-border-dark: #94a3b8;
    
    /* === COMPATIBILITÉ LEGACY === */
    /* Variables existantes - mappées sur la nouvelle palette */
    --primary-color: var(--simcrise-primary);
    --secondary-color: var(--simcrise-secondary);
    --accent-color: var(--simcrise-info);
    --success-color: var(--simcrise-accent);
    --warning-color: var(--simcrise-warning);
    --error-color: var(--simcrise-error);
    --text-color: var(--simcrise-primary);
    --text-light: #64748b;  /* Amélioré pour contraste WCAG */
    --background-color: var(--simcrise-bg-primary);
    --card-background: var(--simcrise-bg-secondary);
    --border-color: var(--simcrise-border-light);
    --border-radius: 8px;
    --spacing-unit: 1rem;
    --transition-speed: 0.3s;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    line-height: 1.6;
    color: var(--text-color);
    background-color: var(--background-color);
    padding: var(--spacing-unit);
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
    margin-bottom: var(--spacing-unit);
    font-weight: 600;
    line-height: 1.2;
}

h1 {
    font-size: 2.5rem;
    color: var(--primary-color);
    text-align: center;
    margin-bottom: calc(var(--spacing-unit) * 2);
}

.subtitle {
    text-align: center;
    color: var(--text-light);
    margin-bottom: calc(var(--spacing-unit) * 2);
}

/* Support Markdown dans les messages */
.msg h1, .msg h2, .msg h3, .msg h4, .msg h5, .msg h6 {
    font-size: inherit;
    font-weight: 600;
    margin: 0.5em 0 0.3em 0;
    color: var(--primary-color);
}

.msg h1 { font-size: 1.2em; }
.msg h2 { font-size: 1.15em; }
.msg h3 { font-size: 1.1em; }

.msg p {
    margin: 0.5em 0;
}

.msg ul, .msg ol {
    margin: 0.5em 0;
    padding-left: 1.5em;
}

.msg li {
    margin: 0.2em 0;
}

.msg blockquote {
    border-left: 3px solid var(--accent-color);
    margin: 0.5em 0;
    padding: 0.3em 0 0.3em 0.8em;
    background: rgba(52, 152, 219, 0.05);
    font-style: italic;
}

.msg code {
    /* Afficher le code inline comme du texte en gras sans badge */
    background: transparent !important;
    padding: 0 !important;
    border-radius: 0 !important;
    font-family: inherit !important;
    font-size: inherit !important;
    font-weight: 700 !important;
    color: inherit !important; /* Utiliser la couleur du texte parent */
    border: none !important;
    box-shadow: none !important;
}

/* Force transparence sur tous les code possibles */
code {
    background: transparent !important;
    padding: 0 !important;
    border: none !important;
    font-weight: 700;
}

.msg pre {
    background: rgba(0, 0, 0, 0.05);
    padding: 0.8em;
    border-radius: 5px;
    overflow-x: auto;
    margin: 0.5em 0;
}

.msg pre code {
    background: none;
    padding: 0;
}

/* Styles pour les éléments narratifs et le texte en gras */
.msg strong {
    font-weight: 700;
    color: var(--primary-color);
}

.msg strong[style*="color: #dc2626"] {
    color: #dc2626 !important;
    font-weight: 700;
}

.msg strong[style*="color: #2563eb"] {
    color: #2563eb !important;
    font-weight: 700;
}

.msg em {
    font-style: italic;
    color: var(--text-light);
}

/* Styles spéciaux pour les éléments narratifs */
.msg .narrative {
    font-style: italic;
    color: #666;
    font-weight: 500;
}

.msg .action {
    color: #888;
    font-style: italic;
    opacity: 0.8;
}

/* Amélioration du rendu des doubles astérisques */
.msg **text** {
    font-weight: bold;
    color: var(--primary-color);
}

/* Styles pour les messages système */
.msg.system-info {
    margin: 15px 0;
    padding: 0;
    background: none;
    border: none;
}

.msg.system-info div {
    animation: fadeIn 0.5s ease-in;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Cards */
.card {
    background: var(--card-background);
    border-radius: var(--border-radius);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    padding: calc(var(--spacing-unit) * 2);
    margin-bottom: calc(var(--spacing-unit) * 2);
    transition: transform var(--transition-speed), box-shadow var(--transition-speed);
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

/* Forms */
.form-group {
    margin-bottom: calc(var(--spacing-unit) * 1.5);
}

label {
    display: block;
    margin-bottom: calc(var(--spacing-unit) * 0.5);
    font-weight: 500;
    color: var(--primary-color);
}

label i {
    margin-right: 0.5rem;
}

textarea, input[type="text"] {
    width: 100%;
    padding: calc(var(--spacing-unit) * 0.75);
    border: 2px solid #e0e0e0;
    border-radius: var(--border-radius);
    font-size: 1rem;
    transition: border-color var(--transition-speed);
    background-color: white;
}

textarea:focus, input[type="text"]:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

.form-text {
    font-size: 0.875rem;
    color: var(--text-light);
    margin-top: 0.25rem;
}

/* Buttons */
.action-buttons {
    display: flex;
    gap: var(--spacing-unit);
    justify-content: flex-end;
    margin-top: calc(var(--spacing-unit) * 1.5);
}

.btn {
    display: inline-flex;
    align-items: center;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: var(--border-radius);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-speed);
}

.btn i {
    margin-right: 0.5rem;
}

.btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

.btn-primary {
    background-color: var(--accent-color);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background-color: #2980b9;
}

.btn-secondary {
    background-color: #95a5a6;
    color: white;
}

.btn-secondary:hover:not(:disabled) {
    background-color: #7f8c8d;
}

.btn-info {
    background-color: #3b82f6;
    color: white;
}

.btn-info:hover:not(:disabled) {
    background-color: #2563eb;
}

/* Messages */
.message {
    padding: var(--spacing-unit);
    border-radius: var(--border-radius);
    margin-bottom: var(--spacing-unit);
    background-color: #f8f9fa;
    border-left: 4px solid var(--accent-color);
}

.message-assistant {
    white-space: pre-wrap;
    font-family: monospace;
    font-size: 0.9rem;
    line-height: 1.5;
}

/* Toast Notifications */
.toast {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    padding: 1rem 2rem;
    border-radius: var(--border-radius);
    background: white;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 1000;
    animation: slideIn 0.3s ease-out;
}

.toast-info {
    border-left: 4px solid var(--accent-color);
}

.toast-success {
    border-left: 4px solid var(--success-color);
}

.toast-error {
    border-left: 4px solid var(--error-color);
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Timer/Clock Styles */
#timer {
    position: fixed;
    top: 20px;
    right: 20px;
    background: linear-gradient(135deg, var(--simcrise-primary), var(--simcrise-secondary));
    color: white;
    padding: 12px 20px;
    border-radius: 25px;
    font-weight: 700;
    font-size: 1.1rem;
    box-shadow: 0 4px 15px rgba(37, 99, 235, 0.3);
    z-index: 999;
    transition: all var(--transition-speed);
    border: 2px solid rgba(255,255,255,0.1);
    backdrop-filter: blur(10px);
    min-width: 180px;
    text-align: center;
}

#timer:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(0,0,0,0.3);
}

/* Timer warning states */
#timer.warning {
    background: linear-gradient(135deg, var(--simcrise-warning), #d97706);
    animation: pulse-warning 2s infinite;
}

#timer.critical {
    background: linear-gradient(135deg, var(--simcrise-error), #b91c1c);
    animation: pulse-critical 1s infinite;
}

#timer.grace-period {
    background: linear-gradient(135deg, #f59e0b, var(--simcrise-warning));
    animation: pulse-grace 1.5s infinite;
    border: 2px solid #fff;
}

@keyframes pulse-warning {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.02); }
}

@keyframes pulse-critical {
    0%, 100% { transform: scale(1); box-shadow: 0 4px 15px rgba(220, 38, 38, 0.3); }
    50% { transform: scale(1.05); box-shadow: 0 6px 20px rgba(220, 38, 38, 0.5); }
}

@keyframes pulse-grace {
    0%, 100% { transform: scale(1); box-shadow: 0 4px 15px rgba(245, 158, 11, 0.4); }
    50% { transform: scale(1.03); box-shadow: 0 6px 20px rgba(245, 158, 11, 0.6); }
}

/* Simulation Title Styles */
#simulation h1 {
    color: var(--simcrise-primary);
    text-align: center;
    font-size: 2.2rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
    text-shadow: 0 2px 4px rgba(37, 99, 235, 0.1);
}

/* Responsive timer positioning */
@media (max-width: 768px) {
    body {
        padding: calc(var(--spacing-unit) * 0.5);
    }

    .card {
        padding: var(--spacing-unit);
    }

    .action-buttons {
        flex-direction: column;
    }

    .btn {
        width: 100%;
        justify-content: center;
    }

    h1 {
        font-size: 2rem;
    }

    #timer {
        position: fixed;
        top: 10px;
        right: 10px;
        left: 10px;
        font-size: 1rem;
        padding: 10px 16px;
        min-width: auto;
        margin: 0 auto;
        max-width: 200px;
    }
}

@media (max-width: 480px) {
    #timer {
        font-size: 0.9rem;
        padding: 8px 12px;
    }
}

/* Accessibility Improvements */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

/* Focus Styles */
:focus {
    outline: 3px solid var(--accent-color);
    outline-offset: 2px;
}

:focus:not(:focus-visible) {
    outline: none;
}

:focus-visible {
    outline: 3px solid var(--accent-color);
    outline-offset: 2px;
}

/* ============================= */
/* RESPONSIVE DESIGN */  
/* ============================= */

/* Large tablets and small laptops */
@media (max-width: 1024px) {
    .wrap {
        max-width: 95%;
        padding: 0 12px;
        margin: 16px auto;
    }
    
    .configuration-grid {
        grid-template-columns: 1fr 1fr;
        gap: 12px;
    }
}

/* Tablets */
@media (max-width: 768px) {
    body {
        padding: 0.5rem;
    }
    
    .wrap {
        margin: 8px auto;
        padding: 0 8px;
    }
    
    .card {
        padding: 12px;
        border-radius: 8px;
    }
    
    h1 {
        font-size: 1.8rem;
        margin-bottom: 1rem;
    }
    
    /* Navigation responsive */
    .config-mode {
        flex-direction: column;
        gap: 12px;
    }
    
    .config-mode label {
        justify-content: center;
        padding: 8px;
        border: 1px solid var(--border-color);
        border-radius: 6px;
        background: var(--card-background);
    }
    
    /* Configuration grid responsive */
    .configuration-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    
    /* Messages responsive */
    .msg {
        max-width: 90%;
        padding: 8px 10px;
        font-size: 0.95rem;
    }
    
    /* Barre de chat responsive */
    .bar {
        flex-direction: column;
        gap: 8px;
    }
    
    .bar input, .bar button {
        width: 100%;
        padding: 12px;
        font-size: 1rem;
    }
    
    /* Boutons responsive */
    button {
        padding: 12px 16px;
        font-size: 1rem;
        min-height: 44px; /* Touch target minimum */
    }
    
    /* Formulaires responsive */
    select, input[type="text"], textarea {
        padding: 12px;
        font-size: 1rem;
        min-height: 44px;
    }
}

/* Mobile phones */
@media (max-width: 480px) {
    body {
        padding: 0.25rem;
    }
    
    .wrap {
        margin: 4px auto;
        padding: 0 4px;
    }
    
    .card {
        padding: 8px;
        margin-bottom: 8px;
    }
    
    h1 {
        font-size: 1.5rem;
        text-align: center;
    }
    
    /* Messages mobiles */
    .msg {
        max-width: 95%;
        padding: 6px 8px;
        font-size: 0.9rem;
        line-height: 1.5;
    }
    
    #chat {
        min-height: 250px;
        gap: 6px;
    }
    
    /* Navigation mobile */
    .mt-12 {
        margin-top: 8px;
    }
    
    .mt-16 {
        margin-top: 12px;
    }
    
    .mt-24 {
        margin-top: 16px;
    }
    
    /* Boutons groupés mobile */
    .mt-12 [style*="display: flex"] {
        flex-direction: column;
        gap: 8px;
        width: 100%;
    }
    
    .mt-12 button {
        width: 100%;
        margin: 0;
    }
}

/* Very small mobile screens */
@media (max-width: 320px) {
    .card {
        padding: 6px;
    }
    
    .msg {
        font-size: 0.85rem;
        padding: 5px 6px;
    }
    
    h1 {
        font-size: 1.3rem;
    }
    
    button, select, input[type="text"], textarea {
        font-size: 0.9rem;
        padding: 10px;
    }
}

/* High DPI displays adjustments */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .msg {
        border-width: 0.5px;
    }
    
    .card {
        border-width: 0.5px;
    }
}

/* Landscape orientation adjustments for mobile */
@media (max-height: 500px) and (orientation: landscape) {
    #chat {
        min-height: 150px;
    }
    
    .card {
        padding: 8px;
    }
    
    h1 {
        font-size: 1.3rem;
        margin-bottom: 0.5rem;
    }
}

/* ==================== Loading States & Spinners ==================== */
.loading-spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: calc(var(--spacing-unit) * 2);
    color: var(--text-light);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--border-color);
    border-top: 4px solid var(--accent-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: var(--spacing-unit);
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-spinner p {
    margin: 0;
    font-size: 0.9rem;
    text-align: center;
}

/* Variantes de couleurs pour différents contextes */
.spinner.success {
    border-top-color: var(--success-color);
}

.spinner.warning {
    border-top-color: var(--warning-color);
}

.spinner.error {
    border-top-color: var(--error-color);
}

/* Loading state pour les messages de chat */
.msg.loading {
    background-color: #f8f9fa;
    border-left: 4px solid var(--accent-color);
    position: relative;
}

.msg.loading::before {
    content: '';
    position: absolute;
    left: -4px;
    top: 0;
    width: 4px;
    height: 100%;
    background: linear-gradient(45deg, 
        var(--accent-color) 25%, 
        transparent 25%, 
        transparent 50%, 
        var(--accent-color) 50%, 
        var(--accent-color) 75%, 
        transparent 75%);
    background-size: 10px 10px;
    animation: loading-bar 1s linear infinite;
}

@keyframes loading-bar {
    0% { background-position: 0 0; }
    100% { background-position: 10px 10px; }
}

/* Auto-save indicator */
.auto-save-status {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 8px 16px;
    border-radius: var(--border-radius);
    font-size: 0.8rem;
    opacity: 0;
    transition: opacity var(--transition-speed);
    z-index: 1000;
    pointer-events: none;
}

.auto-save-status.saving {
    background-color: var(--warning-color);
    color: white;
    opacity: 1;
}

.auto-save-status.saved {
    background-color: var(--success-color);
    color: white;
    opacity: 1;
}

.auto-save-status.error {
    background-color: var(--error-color);
    color: white;
    opacity: 1;
}

/* ========================================
   INDICATEUR DE FRAPPE (TYPING INDICATOR)
   ======================================== */

/* Container de l'indicateur de frappe */
.msg.typing-indicator {
    background: #f0f0f0;
    border-left: 3px solid var(--simcrise-info);
    padding: 12px 16px;
    max-width: 80px;
    display: inline-block;
}

/* Container des points */
.typing-dots {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 20px;
}

/* Points individuels */
.typing-dots .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--simcrise-info);
    animation: typing-bounce 1.4s infinite ease-in-out;
}

/* Animation décalée pour chaque point */
.typing-dots .dot:nth-child(1) {
    animation-delay: 0s;
}

.typing-dots .dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dots .dot:nth-child(3) {
    animation-delay: 0.4s;
}

/* Animation de rebond */
@keyframes typing-bounce {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.7;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

/* Responsive - réduire la taille sur mobile */
@media (max-width: 768px) {
    .typing-dots .dot {
        width: 6px;
        height: 6px;
    }
    
    .typing-dots {
        gap: 4px;
    }
}
