/* chat.css - Interface Chat, mobile-first */

/* ========== Reset & base (mobile) ========== */
* {
    box-sizing: border-box;
}

body {
    font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
    background-color: #f5f7fa;
    color: #1e293b;
    line-height: 1.6;
}

/* ========== Template : conteneur page Chat (mobile-first) ========== */
/* Mobile : réduire bords gauche/droite pour profiter de la largeur écran */
@media (max-width: 767px) {
    .container:has(.chat-page) {
        padding-left: 0.25rem;
        padding-right: 0.25rem;
    }
}

.chat-page {
    width: 100%;
    padding: 0.5rem 0.375rem;
    margin: 0 auto;
}

/* ========== Template : en-tête & titre ========== */
.chat-page__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.chat-page__title {
    font-size: 1.25rem;
    font-weight: 700;
    color: #1e293b;
    margin: 0;
}

/* ========== Template : toolbar ========== */
.chat-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}

.chat-btn {
    padding: 0.5rem 0.75rem;
    border: 1px solid #cbd5e1;
    background: #f8fafc;
    border-radius: 8px;
    cursor: pointer;
    color: #1e293b;
    font-weight: 500;
    font-size: 0.875rem;
    transition: background 0.2s ease, border-color 0.2s ease;
    text-decoration: none;
    display: inline-block;
}

.chat-btn:hover {
    background: #e2e8f0;
    border-color: #94a3b8;
}

.chat-btn:focus-visible {
    outline: 2px solid #0ea5e9;
    outline-offset: 2px;
}

.chat-btn--primary {
    background: #0ea5e9;
    color: #fff;
    border-color: #0ea5e9;
}

.chat-btn--primary:hover {
    background: #0284c7;
    border-color: #0284c7;
}

.chat-btn--primary:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

/* ========== Contenu : badge debug ========== */
.chat-debug-badge {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 6px;
    background: #ef4444;
    color: #fff;
    font-size: 0.75rem;
    margin-left: 0.5rem;
}

/* ========== Template : panneaux ========== */
.chat-panel {
    padding: 0.75rem 0.375rem;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    margin: 0.75rem 0;
    background: #fff;
}

.chat-panel--debug {
    border-color: #fbbf24;
    background: #fef3c7;
}

.chat-panel--debug h2 {
    margin: 0 0 0.5rem 0;
    color: #92400e;
    font-size: 1rem;
}

.chat-panel--debug ul {
    margin: 0;
    padding-left: 1rem;
    color: #78350f;
    font-size: 0.875rem;
}

/* ========== Contenu : historique ========== */
.chat-history {
    margin: 0.75rem 0;
}

.chat-history summary {
    cursor: pointer;
    font-weight: 600;
    color: #334155;
    padding: 0.5rem;
    border-radius: 6px;
}

.chat-history summary:hover {
    background: #f8fafc;
    color: #0f172a;
}

.chat-history .chat-panel {
    margin-top: 0;
}

.chat-history__list {
    margin-top: 0.75rem;
}

.chat-msg {
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 0.75rem;
}

.chat-msg:last-child {
    margin-bottom: 0;
}

.chat-msg--user {
    background: #eff6ff;
    border: 1px solid #bfdbfe;
}

.chat-msg--assistant {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
}

.chat-msg__role {
    font-weight: 600;
    font-size: 0.875rem;
    margin-bottom: 0.5rem;
}

.chat-msg--user .chat-msg__role {
    color: #1d4ed8;
}

.chat-msg--assistant .chat-msg__role {
    color: #334155;
}

.chat-msg__content {
    color: #1e293b;
    white-space: pre-wrap;
}

/* ========== Formulaire ========== */
.chat-form {
    border: 2px solid #bae6fd;
    border-radius: 8px;
    padding: 1rem 0.375rem;
    background: #fff;
}

.chat-form .chat-label {
    font-weight: 600;
    display: block;
    margin: 0.5rem 0 0.25rem;
    color: #334155;
    font-size: 0.9375rem;
}

.chat-form textarea {
    width: 100%;
    min-height: 6rem;
    padding: 0.75rem;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    font-family: inherit;
    font-size: 1rem;
    resize: vertical;
}

.chat-form textarea:focus {
    outline: 2px solid #0ea5e9;
    outline-offset: 2px;
    border-color: #0ea5e9;
}

.chat-form__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-top: 1rem;
}

.chat-form__actions .chat-btn {
    flex: 1 1 auto;
    min-width: 0;
}

.chat-form__actions .chat-btn.send {
    flex: 1 1 100%;
}

/* ========== Blocs contenu : menu, fin d'histoire ========== */
.chat-menu-wrap {
    margin-bottom: 1rem;
    padding: 1rem 0.25rem;
    background: linear-gradient(to bottom right, #ecfdf5, #f0fdf4);
    border-radius: 8px;
    border: 1px solid #a7f3d0;
}

.chat-ended {
    padding: 1.5rem 1rem;
    text-align: center;
    background: linear-gradient(to bottom right, #faf5ff, #fdf2f8);
    border-radius: 8px;
    border: 2px solid #d8b4fe;
}

.chat-ended__icon {
    font-size: 2rem;
    margin-bottom: 0.75rem;
}

.chat-ended__title {
    font-size: 1.125rem;
    font-weight: 600;
    color: #6b21a8;
    margin: 0;
}

.chat-ended__text {
    color: #7c3aed;
    margin: 0.5rem 0 0;
    font-size: 0.9375rem;
}

/* ========== Template : loader overlay (mobile-first) ========== */
.chat-loader {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, rgba(15, 23, 42, 0.95) 0%, rgba(88, 28, 135, 0.95) 100%);
    z-index: 9999;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(8px);
    opacity: 0;
    transition: opacity 0.3s ease;
    overflow: hidden;
}

.chat-loader[aria-busy="true"],
.chat-loader.is-visible {
    display: flex;
    opacity: 1;
}

/* ========== Accessibilité ========== */
.chat-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ========== Breakpoints (mobile-first) ========== */
@media (min-width: 480px) {
    .chat-page {
        padding: 1rem 1.25rem;
    }

    .chat-page__title {
        font-size: 1.375rem;
    }

    .chat-btn {
        padding: 0.625rem 1rem;
        font-size: 0.9375rem;
    }

    .chat-form__actions .chat-btn.send {
        flex: 1 1 auto;
    }
}

@media (min-width: 768px) {
    .chat-page {
        max-width: 56rem;
        margin-left: auto;
        margin-right: auto;
        padding: 1.5rem 2rem;
    }

    .chat-page__title {
        font-size: 1.875rem;
    }

    .chat-toolbar {
        gap: 0.5rem;
        margin-bottom: 1.5rem;
    }

    .chat-panel {
        padding: 1rem 1.25rem;
        margin: 1rem 0;
    }

    .chat-form {
        padding: 1.5rem;
    }

    .chat-form textarea {
        max-width: 45rem;
    }
}

/* ========== Anciens styles conservés (compatibilité) ========== */
#history {
    max-width: 100%;
    margin: 0 0 1.25rem 0;
    background-color: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 1rem;
    overflow-y: auto;
}

#history p {
    margin-bottom: 0.625rem;
}

#history p strong {
    display: inline-block;
    width: 5rem;
    color: #0ea5e9;
}

.history_summary {
    cursor: pointer;
    font-weight: 600;
    color: #334155;
}

.history_summary:hover {
    color: #0f172a;
}

/* Scrollbar WebKit */
#history::-webkit-scrollbar {
    width: 6px;
}

#history::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 4px;
}

#history::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

/* ========== Boutons de choix (mobile-first, accessibilité WCAG) ========== */
/* Contraste texte/fond ≥ 4.5:1 (AA) sur tous les états */
.chat-menu-wrap .choice_button,
button[type="button"].choice_button {
    display: block;
    width: 100%;
    min-height: 2.75rem;
    padding: 0.75rem 0.875rem;
    margin-bottom: 0.5rem;
    text-align: left;
    font-family: inherit;
    font-size: 0.9375rem;
    font-weight: 500;
    line-height: 1.45;
    color: #022c22;
    background: #ffffff;
    border: 1px solid #059669;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease, color 0.2s ease;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.chat-menu-wrap .choice_button:last-child,
button[type="button"].choice_button:last-child {
    margin-bottom: 0;
}

.chat-menu-wrap .choice_button:hover,
button[type="button"].choice_button:hover {
    background: #d1fae5;
    border-color: #047857;
    color: #022c22;
    box-shadow: 0 2px 4px rgba(2, 44, 34, 0.12);
}

.chat-menu-wrap .choice_button:active,
button[type="button"].choice_button:active {
    background: #a7f3d0;
    border-color: #047857;
    color: #022c22;
}

.chat-menu-wrap .choice_button:focus-visible,
button[type="button"].choice_button:focus-visible {
    outline: 3px solid #047857;
    outline-offset: 2px;
    border-color: #047857;
    background: #ecfdf5;
    color: #022c22;
}

@media (min-width: 480px) {
    .chat-menu-wrap .choice_button,
    button[type="button"].choice_button {
        min-height: 3rem;
        padding: 0.875rem 1rem;
        font-size: 1rem;
    }
}

/* Choix / autres formulaires */

.inscription_form_container {
    width: 100%;
    max-width: 32rem;
    margin: 0 auto;
    padding: 1.25rem;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

@media (min-width: 768px) {
    .inscription_form_container {
        width: 50%;
    }
}

.inscription_form_container form input {
    width: 100%;
    max-width: 90%;
    padding: 0.625rem 0.75rem;
    border-radius: 6px;
    border: 1px solid #cbd5e1;
}

.inscription_form_container form label {
    font-weight: 600;
    font-size: 1rem;
    margin-bottom: 0.5rem;
    margin-top: 0.5rem;
}

.inscription_form_container_button {
    width: 90%;
    padding: 0.625rem 0.75rem;
    border-radius: 6px;
    border: 1px solid #cbd5e1;
    background-color: #0ea5e9;
    color: #fff;
    font-size: 1rem;
    font-weight: 600;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 5px solid #e2e8f0;
    border-top-color: #0ea5e9;
    border-radius: 50%;
    animation: chat-spin 0.8s linear infinite;
}

@keyframes chat-spin {
    to { transform: rotate(360deg); }
}

/* ========== Debug / Perf panel ========== */
.chat-panel--perf {
    background: #0f172a;
    border: 1px solid #334155;
    border-radius: 8px;
    padding: 0.75rem 1rem;
    margin: 1.25rem 0;
    color: #e2e8f0;
    font-size: 0.875rem;
}

.chat-panel--perf__summary {
    cursor: pointer;
    font-weight: 700;
    font-size: 0.9375rem;
    color: #7dd3fc;
    user-select: none;
    list-style: none;
}

.chat-panel--perf__summary::marker,
.chat-panel--perf__summary::-webkit-details-marker {
    display: none;
}

.chat-panel--perf__summary::before {
    content: '▶ ';
    font-size: 0.75rem;
    color: #38bdf8;
}

details[open] > .chat-panel--perf__summary::before {
    content: '▼ ';
}

.chat-panel--perf__grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
    margin-top: 0.75rem;
}

@media (min-width: 640px) {
    .chat-panel--perf__grid {
        grid-template-columns: 1fr 1fr;
    }
}

.chat-panel--perf__section h3 {
    font-size: 0.8125rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #94a3b8;
    margin: 0 0 0.5rem;
}

.debug-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8125rem;
}

.debug-table th,
.debug-table td {
    padding: 0.25rem 0.375rem;
    text-align: left;
    border-bottom: 1px solid #1e293b;
    vertical-align: middle;
}

.debug-table th {
    color: #94a3b8;
    font-weight: 500;
    white-space: nowrap;
    width: 40%;
}

.debug-table td code {
    background: #1e293b;
    padding: 0.1em 0.35em;
    border-radius: 4px;
    font-size: 0.8125rem;
    color: #7dd3fc;
    word-break: break-all;
}

/* Badges de performance */
.perf-badge {
    display: inline-block;
    padding: 0.15em 0.5em;
    border-radius: 999px;
    font-weight: 700;
    font-size: 0.8125rem;
    letter-spacing: 0.02em;
}

.perf-ok   { background: #14532d; color: #86efac; }
.perf-warn { background: #713f12; color: #fde68a; }
.perf-slow { background: #7f1d1d; color: #fca5a5; }
.perf-none { background: #1e293b; color: #64748b; }

/* ========== Stagger animation : texte narratif (Html_Menu_Buttons_002) ========== */
.story-title--animated {
    display: block;
    opacity: 0;
    filter: blur(3px);
    transform: translateY(-8px);
    transition: opacity 0.6s cubic-bezier(0.22, 1, 0.36, 1),
                filter  0.6s cubic-bezier(0.22, 1, 0.36, 1),
                transform 0.6s cubic-bezier(0.22, 1, 0.36, 1);
}

.story-title--visible {
    opacity: 1;
    filter: blur(0);
    transform: translateY(0);
}

.story-word {
    display: inline-block;
    opacity: 0;
    filter: blur(4px);
    transform: translateY(8px);
    transition: opacity 0.5s cubic-bezier(0.22, 1, 0.36, 1),
                filter  0.5s cubic-bezier(0.22, 1, 0.36, 1),
                transform 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}

.story-word--visible {
    opacity: 1;
    filter: blur(0);
    transform: translateY(0);
}
