:root {
    /* Thème clair inspiré de l'identité Vertical M2M (estimation) */
    --bg-main: #f5f7fb;
    --bg-panel: #ffffff;
    --bg-panel-alt: #f0f3f8;
    --bg-input: #ffffff;
    --accent: #005C9F; /* bleu principal */
    --accent-soft: rgba(0, 92, 159, 0.14);
    --accent-light: #00AEEF; /* cyan/secondaire */
    --text-primary: #1e2a35;
    --text-secondary: rgba(30, 42, 53, 0.7);
    --border: rgba(0, 0, 0, 0.08);
    --radius: 22px;
    --shadow: 0 22px 50px rgba(16, 24, 40, 0.08);
}

*, *::before, *::after {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    min-height: 100%;
    height: 100%;
    background: linear-gradient(180deg, #ffffff 0%, var(--bg-main) 100%);
    font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--text-primary);
}

body {
    display: flex;
    justify-content: center;
    align-items: stretch;
    width: 100%;
    transition: padding 0.3s ease;
    overflow: hidden; /* Empêche le scroll global, on scrolle uniquement dans les zones prévues */
}

body.compact {
    padding: 32px 16px;
}

p {
    margin: 5px;
}

.app {
    width: 100%;
    max-width: 100%;
    display: grid;
    grid-template-columns: minmax(0, 1fr); /* une seule colonne, le panneau d'options sera flottant */
    min-height: 100vh; /* fallback */
    height: 100dvh; /* taille fixe au viewport pour éviter le scroll de page */
    backdrop-filter: blur(18px);
    position: relative;
    box-shadow: var(--shadow);
    border-left: 1px solid rgba(255, 255, 255, 0.05);
    border-right: 1px solid rgba(255, 255, 255, 0.05);
}

/* Backdrop pour le panneau d'options flottant */
.options-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(8, 0, 14, 0.45);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
    z-index: 20; /* sous le panneau (z-index: 30) mais au-dessus du chat */
}

.options-backdrop.is-visible {
    opacity: 1;
    pointer-events: auto;
}

body.compact .app {
    max-width: 800px;
    border-radius: 26px;
    overflow: hidden;
    min-height: calc(100vh - 64px); /* fallback */
    height: calc(100dvh - 64px);
}

.chat-panel {
    position: relative;
    display: flex;
    flex-direction: column;
    background: var(--bg-panel);
    border-right: 1px solid var(--border);
    overflow: hidden;
    height: 100%; /* occupe toute la hauteur de .app */
}

.chat-panel::before {
    content: "";
    position: absolute;
    inset: 0;
    background: none;
    opacity: 0;
    mix-blend-mode: normal;
    z-index: 0;
}

.chat-shell {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* -----------------------------
   HTMX indicators visibility
   ----------------------------- */
/* Hidden by default */
.htmx-indicator {
    display: none;
}

/* When a parent is in request state */
.htmx-request .htmx-indicator {
    display: inline;
}

/* When the indicator element itself is marked as requesting (hx-indicator target) */
.htmx-request.htmx-indicator {
    display: flex !important;
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 28px 34px;
    background: linear-gradient(180deg, #ffffff, #f9fbfe);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 8px 24px rgba(16, 24, 40, 0.06);
}

.chat-header__main {
    display: flex;
    align-items: center;
    gap: 16px;
}

.chat-header__info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.chat-header__title {
    font-size: 19px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.chat-header__subtitle {
    font-size: 13px;
    color: var(--text-secondary);
}

.chat-header__avatar {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid rgba(0, 0, 0, 0.06);
    box-shadow: 0 8px 18px rgba(16, 24, 40, 0.08);
}

.options-toggle {
    display: inline-flex; /* visible sur tous les écrans puisque le panneau est flottant */
    border: none;
    border-radius: 999px;
    width: 46px;
    height: 46px;
    background: var(--accent);
    color: #ffffff;
    box-shadow: 0 16px 32px rgba(16, 24, 40, 0.18);
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.options-toggle:hover {
    transform: translateY(-1px) scale(1.05);
}

.chat-body {
    flex: 1;
    padding: 34px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 24px;
    /* Custom scrollbar (cross-browser) */
    scrollbar-width: thin; /* Firefox */
    scrollbar-color: var(--accent) rgba(255, 255, 255, 0.08); /* thumb, track */
    scrollbar-gutter: stable both-edges; /* avoid layout shift */
}

/* Container that holds all chat messages. Must be a flex column so message align-self works */
.messages {
    display: flex;
    flex-direction: column;
    gap: 24px;
    width: 100%;
}

body.compact .chat-body {
    padding: 28px;
}

.message {
    /* Les messages ne s'étendent pas au-delà de 2/3 de la largeur du conteneur */
    max-width: 75%;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.message__bubble {
    padding: 12px 14px;
    border-radius: calc(var(--radius) - 8px);
    line-height: 1.45;
    font-size: 15px;
    letter-spacing: -0.01em;
    backdrop-filter: blur(8px);
}

.message__meta {
    font-size: 12px;
    color: var(--text-secondary);
}

.message--sent {
    align-self: flex-end;
    text-align: right;
}

.message--sent .message__bubble {
    background: linear-gradient(135deg, var(--accent), var(--accent-light));
    color: #ffffff;
    border-bottom-right-radius: 12px;
    box-shadow: 0 24px 36px rgba(0, 92, 159, 0.25);
}

.message--received {
    align-self: flex-start;
}

.message--received .message__bubble {
    background: #ffffff;
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-bottom-left-radius: 12px;
    box-shadow: 0 12px 24px rgba(16, 24, 40, 0.08);
}

/* Toolcall sub-bubble (more beautiful) */
.message__subbubble--toolcall {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border);
    border-radius: 12px;
    /* Compact when collapsed */
    padding: 4px 6px;
    margin: 4px 0 6px;
    display: inline-flex; /* shrink to content when closed */
    align-items: center;
    max-width: 100%;
    box-shadow: 0 10px 24px rgba(18, 0, 35, 0.25);
    transition: padding 0.2s ease, margin 0.2s ease, box-shadow 0.2s ease;
}

/* Expanded state: take full width and comfortable spacing */
.message__subbubble--toolcall:has(.toolcall[open]) {
    display: block;
    padding: 10px 12px;
    margin: 8px 0 10px;
    width: 100%; /* take full width when expanded */
}

/* Reset native marker and style the summary as a clean icon row */
.toolcall {
    display: block;
}

.toolcall summary {
    list-style: none; /* Firefox */
}

.toolcall summary::-webkit-details-marker {
    display: none; /* Chrome/Safari */
}

.toolcall__summary {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 4px 2px;
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
    transition: color 0.2s ease, opacity 0.2s ease, transform 0.2s ease;
}

.toolcall__summary:hover {
    color: var(--text-primary);
}

.toolcall__summary:focus-visible {
    outline: none;
    box-shadow: 0 0 0 4px var(--accent-soft);
    border-radius: 8px;
}

.toolcall__icon {
    opacity: 0.9;
}

/* Icon state control during streaming */
.toolcall__icon--done {
    display: none; /* hidden by default */
}

.toolcall__icon--spinner {
    display: inline; /* hidden by default */
}

/* When tools are done, swap spinner for checkmark */
.toolcall:has(.toolcall__text .tools-done-flag) .toolcall__icon--spinner {
    display: none;
}

.toolcall:has(.toolcall__text .tools-done-flag) .toolcall__icon--done {
    display: inline;
    color: #34d399; /* subtle success tint */
}

/* Optional: dim spinner when details are opened */
.toolcall[open] .toolcall__icon--spinner {
    opacity: 0.7;
}

.toolcall__chevron {
    opacity: 0.8;
    transition: transform 0.25s ease;
    transform: rotate(-90deg);
}

.toolcall[open] .toolcall__chevron {
    transform: rotate(0deg);
}

.toolcall__text {
    font-size: 13px;
    line-height: 1.55;
    color: var(--text-primary);
    margin-top: 8px;
    opacity: 0;
    transform-origin: top;
    transform: translateY(-4px);
    transition: opacity 0.22s ease, transform 0.22s ease;
}

.toolcall__result {
    color: var(--text-primary);
    background: #ffffff;
    border-radius: 12px;
    border: 1px solid var(--border);
    text-wrap: auto;
}

.toolcall[open] .toolcall__text {
    opacity: 1;
    transform: translateY(0);
}

/* Utility for accessibility */
.visually-hidden {
    position: absolute !important;
    height: 1px;
    width: 1px;
    overflow: hidden;
    clip: rect(1px, 1px, 1px, 1px);
    white-space: nowrap;
}

.typing-indicator {
    display: none; /* hidden by default, shown during request */
    align-items: center;
    gap: 6px;
    padding: 12px 14px;
    background: var(--accent-soft);
    border-radius: 999px;
    align-self: flex-start;
    box-shadow: 0 12px 24px rgba(0, 92, 159, 0.18);
}

/* Show the typing indicator while an HTMX request is in progress on it */
.typing-indicator.htmx-request {
    display: flex;
}

.typing-indicator__dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--accent);
    opacity: 0.45;
    animation: typing 1.2s infinite ease-in-out;
}

.typing-indicator__dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator__dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 80%, 100% {
        transform: translateY(0);
        opacity: 0.45;
    }
    40% {
        transform: translateY(-6px);
        opacity: 1;
    }
}

.chat-input {
    padding: 28px 34px;
    background: #ffffff;
    border-top: 1px solid var(--border);
    box-shadow: 0 -8px 24px rgba(16, 24, 40, 0.06);
}

body.compact .chat-input {
    padding: 24px 28px;
}

.chat-input__form {
    position: relative;
    display: flex;
    align-items: center;
    gap: 14px;
    background: var(--bg-input);
    border-radius: calc(var(--radius) - 6px);
    padding: 14px 18px;
    border: 1px solid rgba(255, 255, 255, 0.07);
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.chat-input__form:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 5px var(--accent-soft);
    background: var(--bg-input);
}

.chat-input__field {
    flex: 1;
    border: none;
    background: transparent;
    font: inherit;
    font-size: 15px;
    color: var(--text-primary);
    outline: none;
}

.chat-input__field::placeholder {
    color: rgba(30, 42, 53, 0.5);
}

.chat-input__actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-icon-btn {
    width: 46px;
    height: 46px;
    border-radius: 999px;
    border: none;
    background: linear-gradient(135deg, var(--accent), var(--accent-light));
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    box-shadow: 0 20px 34px rgba(0, 92, 159, 0.22);
}

.chat-icon-btn:hover {
    transform: translateY(-1px) scale(1.06);
}

.chat-icon-btn:active {
    transform: scale(0.95);
}

.chat-icon-btn svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

.chat-icon-btn--upload {
    background: #ffffff;
    color: var(--accent);
    box-shadow: 0 8px 20px rgba(16, 24, 40, 0.12);
}

.chat-input__file {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

.options-panel {
    position: absolute; /* flottant par-dessus la zone de chat */
    top: 0;
    bottom: 0;
    right: 0;
    left: auto;
    width: min(360px, 100%);
    background: var(--bg-panel-alt);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 32px;
    padding: 34px 30px;
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.04);
    transition: transform 0.35s ease, opacity 0.35s ease;
    z-index: 30; /* au-dessus du contenu */
    overflow-y: auto; /* scroll local si le contenu dépasse */
    max-height: 100%;
    transform: translateX(100%);
    opacity: 0;
    pointer-events: none;
    /* Custom scrollbar (Firefox) */
    scrollbar-width: thin;
    scrollbar-color: var(--accent) rgba(0, 0, 0, 0.06);
}

.options-panel .options-close {
    position: absolute;
    top: 14px;
    right: 14px;
    width: 42px;
    height: 42px;
    border: none;
    border-radius: 999px;
    background: #ffffff;
    color: var(--accent);
    box-shadow: 0 8px 20px rgba(16, 24, 40, 0.12);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 31;
    transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}

.options-panel .options-close:hover {
    transform: translateY(-1px) scale(1.05);
}

.options-panel .options-close:active {
    transform: scale(0.96);
}

.options-panel .options-close:focus-visible {
    outline: none;
    box-shadow: 0 0 0 5px var(--accent-soft), 0 8px 20px rgba(16, 24, 40, 0.12);
}

.options-panel .options-close svg {
    width: 20px;
    height: 20px;
}

.options-panel.is-open {
    transform: translateX(0);
    opacity: 1;
    pointer-events: auto;
}

/* WebKit scrollbars for chat body */
.chat-body::-webkit-scrollbar {
    width: 10px;
}

.chat-body::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.06);
    border-radius: 999px;
}

.chat-body::-webkit-scrollbar-thumb {
    border-radius: 999px;
    background: linear-gradient(180deg, var(--accent), var(--accent-light));
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.4), 0 6px 12px rgba(16, 24, 40, 0.18);
}

.chat-body::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(180deg, var(--accent-light), #21b6ff);
}

.chat-body::-webkit-scrollbar-corner {
    background: transparent;
}

/* WebKit scrollbars for options panel */
.options-panel::-webkit-scrollbar {
    width: 10px;
}

.options-panel::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.06);
    border-radius: 999px;
}

.options-panel::-webkit-scrollbar-thumb {
    border-radius: 999px;
    background: linear-gradient(180deg, var(--accent), var(--accent-light));
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.4), 0 6px 12px rgba(16, 24, 40, 0.18);
}

.options-panel::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(180deg, var(--accent-light), #21b6ff);
}

.options-panel::-webkit-scrollbar-corner {
    background: transparent;
}

/* Slightly slimmer scrollbars on small screens */
@media (max-width: 680px) {
    .chat-body::-webkit-scrollbar,
    .options-panel::-webkit-scrollbar {
        width: 8px;
    }

    /* Sur les petits écrans (téléphones), ne pas proposer le choix de largeur */
    #toggleLayoutMode {
        display: none;
    }
}

.options-panel__section {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.options-panel__title {
    font-size: 15px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-secondary);
}

.options-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.options-item {
    padding: 18px 20px;
    border-radius: calc(var(--radius) - 6px);
    background: #ffffff;
    border: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: transform 0.2s ease, background 0.2s ease, border-color 0.2s ease;
    cursor: pointer;
}

.options-item:hover {
    transform: translateY(-2px);
    background: var(--bg-panel-alt);
    border-color: var(--accent);
}

.options-item__label {
    font-size: 14px;
    font-weight: 500;
}

.options-item__badge {
    font-size: 12px;
    padding: 5px 12px;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent);
}

/* ============ History list (Options > Historique des conversations) ============ */
.options-subpanel {
    margin: 6px 16px 4px;
}

/* When the history subpanel is empty (collapsed), remove its space entirely */
.options-subpanel:empty {
    display: none;
    margin: 0;
    padding: 0;
}

.option-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.option-list__items {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.option-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 14px;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border);
    transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}

.option-item:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 124, 229, 0.25);
    transform: translateY(-1px);
}

.option-item:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.option-item__icon {
    width: 22px;
    height: 22px;
    flex: 0 0 22px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--accent-light);
    opacity: 0.9;
    margin-top: 2px;
}

.option-item__icon svg {
    width: 20px;
    height: 20px;
}

.option-item__content {
    min-width: 0; /* enable text truncation */
    flex: 1; /* push actions to the right */
}

.option-item__title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: wrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.option-item__meta {
    margin-top: 2px;
    font-size: 12px;
    color: var(--text-secondary);
}

/* Actions (delete button) */
.option-item__actions {
    display: inline-flex;
    align-items: center;
    margin-left: 8px;
}

.option-item__button {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: #ffffff;
    color: var(--text-primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease, color 0.2s ease;
}

.option-item__button:hover {
    background: var(--bg-panel-alt);
    border-color: var(--accent);
    color: var(--accent);
}

.option-item__button:active {
    transform: scale(0.96);
}

.option-item__button:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.option-item__button svg {
    width: 18px;
    height: 18px;
}

.option-item .option-item__actions {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

/* Global fixed tooltip banner (bottom of the page) */
#historyTooltipBanner {
    position: fixed;
    left: 50%;
    bottom: 12px;
    transform: translateX(-50%);
    max-width: min(92vw, 720px);
    box-sizing: border-box;
    padding: 10px 14px;
    /* Extra bottom padding to avoid partial clipping of the last line on some engines */
    padding-bottom: 24px;
    border-radius: 10px;
    background: var(--bg-panel);
    color: var(--text-primary);
    border: 1px solid var(--border);
    box-shadow: 0 8px 28px rgba(16, 24, 40, 0.15);
    backdrop-filter: saturate(120%) blur(2px);
    font-size: 13px;
    line-height: 1.4; /* slightly larger to prevent sub-pixel cropping */
    z-index: 3000;
    pointer-events: none; /* do not block clicks */
    opacity: 0;
    visibility: hidden;
    transition: opacity 90ms ease-out, visibility 0s linear 90ms;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 4; /* clamp to 4 lines */
    overflow: hidden;
    white-space: pre-wrap; /* respect line breaks */
    overflow-wrap: anywhere; /* allow long words/urls to wrap */
    word-break: break-word;
}

/* ============ Modal dialog ============ */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(1.5px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
    z-index: 60;
}

.modal-backdrop.is-visible {
    opacity: 1;
    pointer-events: auto;
}

.modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    z-index: 61;
}

.modal.is-open {
    opacity: 1;
    pointer-events: auto;
}

.modal__container {
    width: min(520px, calc(100% - 32px));
    background: var(--bg-panel-alt);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 26px 60px rgba(16, 24, 40, 0.18), 0 0 0 1px rgba(255, 255, 255, 0);
    transform: translateY(10px) scale(0.98);
    opacity: 0;
    transition: transform 0.22s ease, opacity 0.22s ease;
}

.modal.is-open .modal__container {
    transform: translateY(0) scale(1);
    opacity: 1;
}

.modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 18px 8px;
}

.modal__title {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
}

.modal__close {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: #ffffff;
    color: var(--text-primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}

.modal__close:hover {
    background: var(--bg-panel-alt);
    border-color: var(--accent);
}

.modal__body {
    padding: 8px 18px 16px;
    color: var(--text-primary);
    line-height: 1.5;
}

.modal__footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 8px 18px 18px;
}

/* Buttons */
.btn {
    min-width: 110px;
    height: 40px;
    border-radius: 10px;
    border: 1px solid var(--border);
    padding: 0 14px;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s ease, background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.btn:active {
    transform: scale(0.98);
}

.btn--secondary {
    background: #ffffff;
    color: var(--text-primary);
}

.btn--secondary:hover {
    background: var(--bg-panel-alt);
    border-color: var(--accent);
}

.btn--primary {
    background: linear-gradient(135deg, var(--accent), var(--accent-light));
    color: #ffffff;
    box-shadow: 0 14px 26px rgba(0, 92, 159, 0.25);
}

.btn--primary:hover {
    filter: brightness(1.05);
}

/* Variant danger accent for confirm button */
.modal[data-variant="danger"] .btn--primary {
    background: linear-gradient(135deg, #ff3c3c, #b3003c, #7a003f);
    box-shadow: 0 14px 26px rgba(255, 60, 60, 0.35);
}

/* Prevent background scroll when modal open */
body.modal-open {
    overflow: hidden;
}

#historyTooltipBanner.is-visible {
    opacity: 1;
    visibility: visible;
    transition: opacity 90ms ease-out;
}

@media (prefers-reduced-motion: reduce) {
    #historyTooltipBanner {
        transition: none;
    }
}

/* Files section: upload row */
.file-upload {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0; /* allow truncation */
}

/* Stack the browse and submit icons vertically and make them compact */
.files-root .file-upload__icons {
    display: inline-flex;
    flex-direction: column;
    gap: 6px;
    align-items: center;
}

/* Visually-hidden but accessible input */
.file-upload__input {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap; /* added line */
    border: 0;
}

.file-upload__label {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 28px;
    min-height: 28px;
    padding: 4px 6px;
}

.file-upload__name {
    flex: 1 1 auto;
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 12px;
    color: var(--text-secondary);
    padding: 6px 10px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

/* Center icons and reduce size for file upload actions */
.files-root .file-upload button.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 28px;
    min-height: 28px;
    min-width: 0; /* override global button min-width */
    width: 32px; /* compact icon button */
    padding: 2px 4px;
}

.files-root .file-upload__label svg,
.files-root .file-upload button.btn svg {
    width: 16px;
    height: 16px;
}

/* Make the browse label look like the compact icon button too */
.files-root .file-upload__label.btn {
    min-width: 0;
    width: 32px;
    padding: 2px 4px;
}

.option-list__empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    text-align: center;
    padding: 14px 12px;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px dashed rgba(255, 255, 255, 0.14);
}

.option-list__empty-icon {
    width: 28px;
    height: 28px;
    color: var(--accent-light);
    opacity: 0.9;
}

.option-list__empty-text {
    font-size: 13px;
    font-weight: 600;
}

.option-list__empty-help {
    font-size: 12px;
    color: var(--text-secondary);
}

/* Attached file chips inside chat input */
.chat-attached {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin: 0 6px;
    flex: 0 0 auto;
}

.chat-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 46px;
    height: 46px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.14);
    color: var(--text-primary);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.18) inset;
    position: relative; /* needed for the close button positioning */
}

.chat-chip svg {
    width: 36px;
    height: 36px;
}

/* Small close button inside the chip (top-right) */
.chat-chip__remove {
    position: absolute;
    top: -10px;
    right: -10px;
    width: 26px;
    height: 26px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 999px;
    cursor: pointer;
    background: linear-gradient(135deg, rgba(255, 60, 60, 0.95), rgba(234, 0, 94, 0.95));
    color: #fff;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.22);
    padding: 0;
}

.chat-chip__remove svg {
    width: 16px;
    height: 16px;
}

.chat-chip__remove:hover,
.chat-chip__remove:focus-visible {
    filter: brightness(1.05);
    outline: none;
}

.scroll-down-button {
    position: absolute;
    right: 18px;
    bottom: 18px;
    display: none;
    border: none;
    border-radius: 999px;
    width: 44px;
    height: 44px;
    cursor: pointer;
    color: #005C9F;
    background: linear-gradient(135deg, rgba(255, 240, 254, 0.92), rgba(255, 176, 240, 0.88));
    box-shadow: 0 12px 26px rgba(26, 0, 41, 0.35);
    z-index: 5;
}

@media (max-width: 1180px) {
    .chat-body {
        padding: 30px;
    }

    .chat-header,
    .chat-input {
        padding: 24px 30px;
    }
}

@media (max-width: 980px) {
    .chat-body {
        padding: 26px;
    }

    .message {
        max-width: clamp(220px, 72vw, 520px);
    }
}

@media (max-width: 680px) {
    /* Appliquer automatiquement le mode largeur 800px (compact) sur mobile */
    body { /* au lieu de body.compact uniquement */
        padding: 16px;
    }

    .app { /* conserver des arrondis comme en mode 800px */
        border-radius: 20px;
    }

    body.compact {
        padding: 16px;
    }

    body.compact .app {
        border-radius: 20px;
    }

    .chat-header,
    .chat-input {
        padding: 20px 22px;
    }

    .chat-body {
        padding: 20px;
        gap: 18px;
    }

    .chat-icon-btn {
        width: 42px;
        height: 42px;
    }
}

@media (max-width: 480px) {
    /* Conserver l'effet "mode 800px" même sur très petits écrans
       -> garder des marges et des coins arrondis */
    body {
        padding: 12px;
    }

    body.compact {
        padding: 12px;
    }

    .app {
        border-radius: 16px;
        min-height: 100vh;
    }

    .chat-header,
    .chat-input {
        padding: 18px;
    }

    .chat-body {
        padding: 18px;
        gap: 16px;
    }
}

.dialog-backdrop {
    background: rgba(0, 0, 0, .5);
    position: absolute;
    inset: 0;
}

.dialog-panel {
    background: #ffffff;
    border-color: var(--border);
    border-style: solid;
    position: relative;
    color: #111;
    width: min(600px, 92vw);
    border-radius: 10px;
    box-shadow: 0 16px 48px rgba(0, 0, 0, .28);
    font-size: 15px;
    line-height: 1.5;
}

.dialog-panel-btn {
    background: rgba(255, 255, 255, 0.10);
    color: var(--text-primary);
}

.dialog-panel-btn:hover {
    background: rgba(255, 255, 255, 0.20);
    border-color: var(--accent);
}
