/* --- Splash de bienvenue ---
   N'utilise QUE des propriétés compositées (opacity, transform) pour rester
   fluide même quand le main thread est occupé (chargement des conversations,
   parsing JSON, etc.). Le fond reprend var(--bg) du thème actif (déjà posé
   par le script de thème en tête de body), donc pas de flash de fond clair
   en mode sombre. */
.kiro-splash {
    position: fixed;
    inset: 0;
    z-index: 99999;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 18px;
    background: var(--bg);
    pointer-events: none;
}
/* Fade-out déclenché par JS quand la durée minimale (1.4s) ET le chargement
   de la base sont tous deux satisfaits. */
.kiro-splash.fading-out {
    animation: kiro-splash-out 0.5s ease-in forwards;
}
.kiro-splash-logo {
    width: 96px;
    height: 96px;
    will-change: transform, opacity;
    animation: kiro-splash-logo-in 0.7s cubic-bezier(0.2, 0.8, 0.3, 1.1) both;
}
.kiro-splash-text {
    font-size: 1.4rem;
    font-weight: 600;
    color: var(--text);
    margin: 0;
    letter-spacing: -0.01em;
    will-change: transform, opacity;
    animation: kiro-splash-text-in 0.7s cubic-bezier(0.2, 0.8, 0.3, 1.1) 0.2s both;
}
/* Spinner : tourne en continu (transform), reste invisible par défaut.
   Apparaît en fondu UNIQUEMENT si le splash reçoit `show-spinner` (posée
   par JS quand la BD met plus de 1.5s à charger). transform + opacity =
   propriétés compositées = animation fluide même sous charge JS. */
.kiro-splash-spinner {
    width: 26px;
    height: 26px;
    border: 2.5px solid color-mix(in srgb, var(--text) 18%, transparent);
    border-top-color: var(--accent);
    border-radius: 50%;
    opacity: 0;
    will-change: transform, opacity;
    animation: kiro-splash-spin 0.9s linear infinite;
}
.kiro-splash.show-spinner .kiro-splash-spinner {
    animation:
        kiro-splash-spin 0.9s linear infinite,
        kiro-splash-spinner-in 0.4s ease-out forwards;
}
@keyframes kiro-splash-logo-in {
    from { opacity: 0; transform: scale(0.6); }
    to   { opacity: 1; transform: scale(1); }
}
@keyframes kiro-splash-text-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}
@keyframes kiro-splash-spin {
    to { transform: rotate(360deg); }
}
@keyframes kiro-splash-spinner-in {
    to { opacity: 0.85; }
}
@keyframes kiro-splash-out {
    from { opacity: 1; }
    to   { opacity: 0; visibility: hidden; }
}

/* --- Variables de thème --- */
:root {
    accent-color: #F06D13;
    /* Hauteur effective du toggle .catalog-type-btns (boutons + padding + bordure).
       Sert aussi à dimensionner .catalog-section-header pour que les sections
       sans toggle gardent la même hauteur visuelle. */
    --catalog-toggle-h: 32px;
    --bg: #ffffff;
    --bg-sidebar: #fafafa;
    --bg-msg-user: #f0f0f0;
    --bg-msg-assistant: #f9f9f9;
    --text: #1a1a1a;
    --text-secondary: #888;
    --border: #eaeaea;
    --bg-input: #fff;
    --bg-hover: #f0f0f0;
    --bg-active: #e8e8e8;
    --btn-bg: #1a1a1a;
    --btn-text: #fff;
    --border-light: #f0f0f0;
    --border-input: #ddd;
    --sp-title-color: #555;
    --scrollbar-thumb: rgba(0,0,0,0.13);
    --scrollbar-thumb-hover: rgba(0,0,0,0.25);
    --tooltip-bg: #1f1f1f;
    --tooltip-text: #f0f0f0;
    --conv-delete-color: #999;
    --link: #2563eb;
    --link-hover: #1d4ed8;
    --accent: #F06D13;
    --accent-dark: #c95a0e;
    --accent-light: rgba(240, 109, 19, 0.08);
    --accent-gradient: var(--accent-gradient);
    --accent-gradient-active: var(--accent-gradient-active);
    --danger: #dc2626;
    --danger-dark: #b91c1c;
    --danger-light: rgba(220, 38, 38, 0.1);
    --bg-thinking: #fdfdfd;

}

body.dark {
    --bg: #1a1a1a;
    --bg-sidebar: #212121;
    --bg-msg-user: #2a2a2a;
    --bg-msg-assistant: #323232;
    --text: #e0e0e0;
    --text-secondary: #999;
    --border: #2e2e2e;
    --bg-input: #2a2a2a;
    --bg-hover: #2e2e2e;
    --bg-active: #3a3a3a;
    --btn-bg: #e0e0e0;
    --btn-text: #1a1a1a;
    --border-light: #2e2e2e;
    --border-input: #444;
    --sp-title-color: #aaa;
    --scrollbar-thumb: rgba(255,255,255,0.13);
    --scrollbar-thumb-hover: rgba(255,255,255,0.28);
    --tooltip-bg: #2a2a2a;
    --tooltip-text: #e8e8e8;
    --conv-delete-color: #777;
    --link: #60a5fa;
    --link-hover: #93bbfd;
    --accent: #F06D13;
    --accent-dark: #c95a0e;
    --accent-light: rgba(240, 109, 19, 0.12);
    --accent-gradient: var(--accent-gradient);
    --accent-gradient-active: var(--accent-gradient-active);
    --danger: #dc2626;
    --danger-dark: #b91c1c;
    --danger-light: rgba(220, 38, 38, 0.15);
    --bg-thinking: #1e1e1e;
}

@media (prefers-color-scheme: dark) {
    body.theme-auto {
        --bg: #1a1a1a;
        --bg-sidebar: #212121;
        --bg-msg-user: #2a2a2a;
        --bg-msg-assistant: #323232;
        --text: #e0e0e0;
        --text-secondary: #999;
        --border: #2e2e2e;
        --bg-input: #2a2a2a;
        --bg-hover: #2e2e2e;
        --bg-active: #3a3a3a;
        --btn-bg: #e0e0e0;
        --btn-text: #1a1a1a;
        --border-light: #2e2e2e;
        --border-input: #444;
        --sp-title-color: #aaa;
        --scrollbar-thumb: rgba(255,255,255,0.13);
        --scrollbar-thumb-hover: rgba(255,255,255,0.28);
        --tooltip-bg: #2a2a2a;
        --tooltip-text: #e8e8e8;
        --conv-delete-color: #777;
        --link: #60a5fa;
        --link-hover: #93bbfd;
        --accent: #F06D13;
        --accent-dark: #c95a0e;
        --accent-light: rgba(240, 109, 19, 0.12);
        --accent-gradient: var(--accent-gradient);
        --accent-gradient-active: var(--accent-gradient-active);
        --danger: #dc2626;
        --danger-dark: #b91c1c;
        --danger-light: rgba(220, 38, 38, 0.15);
        --bg-thinking: #1e1e1e;
    }
    body.theme-auto .message-text pre {
        background: rgba(255,255,255,0.08);
    }
    body.theme-auto .message-text code {
        background: rgba(255,255,255,0.1);
    }
    body.theme-auto .message-text th {
        background: rgba(255,255,255,0.06);
    }
    body.theme-auto .web-search-toggle.active {
        color: var(--link);
        border-color: var(--link);
        background: rgba(96, 165, 250, 0.12);
    }
    body.theme-auto .model-alert {
        background:
            linear-gradient(rgba(240, 145, 58, 0.10), rgba(240, 145, 58, 0.10)),
            var(--bg);
        color: #e8e8e8;
        border-color: rgba(240, 145, 58, 0.4);
    }
    body.theme-auto #token-info,
    body.theme-auto #cost-info {
        background: rgba(30, 30, 30, 0.85);
    }
    body.theme-auto .input-wrapper:focus-within {
        border-color: var(--active-cat-color, #f0913a);
    }
    body.theme-auto .input-action-btn {
        background: var(--bg-input);
        border-color: var(--border-input);
    }
    body.theme-auto .input-action-btn.active {
        color: var(--link);
        border-color: rgba(96, 165, 250, 0.4);
        background: rgba(96, 165, 250, 0.08);
        box-shadow: 0 0 0 1px rgba(96, 165, 250, 0.08);
    }
    body.theme-auto .input-action-btn.active:hover {
        background: rgba(96, 165, 250, 0.15);
    }
    body.theme-auto .input-action-arrow:hover {
        background: rgba(255, 255, 255, 0.06);
    }
    body.theme-auto .input-action-btn.active .input-action-arrow {
        border-left-color: rgba(96, 165, 250, 0.2);
    }
    body.theme-auto .faq-answer code {
        background: rgba(255,255,255,0.08);
    }
    body.theme-auto .models-error {
        background: #3b1111;
        border-color: #7f1d1d;
        color: #fca5a5;
    }
    body.theme-auto .budget-alert-popup {
        box-shadow:
            0 4px 12px rgba(0,0,0,0.2),
            0 16px 40px rgba(0,0,0,0.4);
    }
    body.theme-auto .code-copy-btn {
        background: rgba(255,255,255,0.2);
    }
    body.theme-auto .code-copy-btn:hover {
        background: rgba(255,255,255,0.35);
    }
    .theme-auto .conv-search {
        background-color: #2a2a2a;
    }
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-thumb) transparent;
}

*::-webkit-scrollbar {
    width: 4px;
    height: 4px;
}

*::-webkit-scrollbar-track {
    background: transparent;
}

*::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 4px;
}

*::-webkit-scrollbar-thumb:hover {
    background: var(--scrollbar-thumb-hover);
}

html, body {
    overflow-x: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    display: flex;
    height: 100vh;
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
}

/* Sidebar */
.sidebar-toggle {
    position: fixed;
    top: 10px;
    left: 224px;
    z-index: 100;
    background: var(--bg-sidebar);
    border: 1px solid var(--border-input);
    border-radius: 6px;
    padding: 4px 6px;
    cursor: pointer;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: left 0.25s ease, color 0.15s, background 0.15s;
}

.sidebar-toggle:hover {
    color: var(--text);
    background: var(--bg-hover);
}

.sidebar-toggle.collapsed {
    left: 8px;
}

.sidebar {
    width: 240px;
    min-width: 240px;
    background: var(--bg-sidebar);
    display: flex;
    flex-direction: column;
    padding: 20px 14px;
    border-right: 1px solid var(--border);
    transition: width 0.25s ease, min-width 0.25s ease, padding 0.25s ease, opacity 0.2s ease;
    overflow: hidden;
    gap: 8px;
}

.sidebar.collapsed {
    width: 0;
    min-width: 0;
    padding: 24px 0;
    opacity: 0;
    border-right: none;
}

/* --- Panneau droit (Rôle) --- */
.right-panel {
    width: 280px;
    min-width: 280px;
    background: var(--bg-sidebar);
    display: flex;
    flex-direction: column;
    padding: 20px 14px;
    border-left: 1px solid var(--border);
    transition: width 0.25s ease, min-width 0.25s ease, padding 0.25s ease, opacity 0.2s ease;
    overflow: hidden;
}

.right-panel.collapsed {
    width: 0;
    min-width: 0;
    padding: 24px 0;
    opacity: 0;
    border-left: none;
}

.rp-panel-title {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 12px;
    white-space: nowrap;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.rp-close-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 1rem;
    line-height: 1;
    padding: 2px 4px;
    border-radius: 4px;
    transition: color 0.15s, background 0.15s;
    flex-shrink: 0;
}

.rp-close-btn:hover {
    color: var(--text);
    background: var(--bg-hover);
}

.rp-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 14px;
    border-bottom: 1px solid var(--border);
    position: relative;
}

.rp-tabs::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: var(--rp-tab-x, 0);
    width: var(--rp-tab-w, 0);
    height: 2px;
    background: var(--accent);
    transition: left 0.28s cubic-bezier(0.4, 0, 0.2, 1), width 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
}

.rp-tab {
    flex: 1;
    padding: 6px 0;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-secondary);
    background: none;
    border: none;
    cursor: pointer;
    transition: color 0.2s;
}

.rp-tab:hover {
    color: var(--text);
}

.rp-tab.active {
    color: var(--accent);
}

.rp-tab-content {
    display: none;
    flex-direction: column;
    flex: 1;
    overflow-y: auto;
}

.rp-tab-content.active {
    display: flex;
    animation: rp-tab-fade-in 0.22s ease;
}

@keyframes rp-tab-fade-in {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: none; }
}

.right-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.right-panel-title {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--accent);
}

.right-panel-actions {
    display: flex;
    gap: 4px;
}

.rp-action-btn {
    background: none;
    border: 1px solid transparent;
    cursor: pointer;
    padding: 4px 6px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: all 0.15s;
}

.rp-action-btn:hover {
    color: var(--accent);
    background: var(--accent-light);
    border-color: var(--accent);
}

.right-panel-role-actions {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding-top: 8px;
}


.rp-role-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    width: 100%;
    background: none;
    border: 1px solid var(--border-input);
    border-radius: 6px;
    padding: 4px 10px;
    font-size: 0.72rem;
    font-family: inherit;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s;
}

.rp-role-btn:hover {
    background: var(--bg-hover);
    color: var(--text);
}

.right-panel-section {
    margin-bottom: 14px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--border);
}

.right-panel-section:last-of-type {
    border-bottom: none;
}

.right-panel-section.disabled {
    display: none;
}

.rp-range-value {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

.rp-range {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 4px;
    border-radius: 2px;
    background: var(--border);
    outline: none;
    margin: 6px 0 0;
}

.rp-range::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: none;
}

.rp-range::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: none;
}

.rp-title-group {
    display: flex;
    align-items: center;
    gap: 6px;
}

.rp-param-toggle {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    border: 1.5px solid var(--accent);
    border-radius: 3px;
    background: var(--bg-input);
    cursor: pointer;
    flex-shrink: 0;
    position: relative;
    transition: background 0.15s, border-color 0.15s;
}

.rp-param-toggle:checked {
    background: var(--accent);
    border-color: var(--accent);
}

.rp-param-toggle:checked::after {
    content: '';
    position: absolute;
    left: 3px;
    top: 0px;
    width: 4px;
    height: 7px;
    border: solid #fff;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.right-panel-section.rp-param-disabled .rp-range,
.right-panel-section.rp-param-disabled .rp-range-value,
.right-panel-section.rp-param-disabled .rp-cat-select,
.right-panel-section.rp-param-disabled select,
.right-panel-section.rp-param-disabled .rp-text-input {
    opacity: 0.3;
    pointer-events: none;
}

.rp-text-input {
    width: 100%;
    padding: 8px 10px;
    font-size: 0.82rem;
    font-family: inherit;
    color: var(--text);
    background: var(--bg-input, var(--bg));
    border: 1px solid var(--border);
    border-radius: 8px;
    box-sizing: border-box;
    transition: border-color 0.2s;
}

.rp-text-input:focus {
    outline: none;
    border-color: var(--accent);
}

.rp-text-input::-webkit-outer-spin-button,
.rp-text-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.rp-text-input[type="number"] {
    -moz-appearance: textfield;
}

.right-panel-section.rp-param-mandatory .rp-param-toggle {
    display: none;
}

.rp-hint-btn.custom-select-info {
    width: 16px;
    height: 16px;
    min-width: 16px;
    min-height: 16px;
    font-size: 10px;
    font-weight: 700;
    font-style: normal;
    font-family: inherit;
    background: var(--bg-hover);
    border: none;
    color: var(--text-secondary);
    opacity: 1;
    margin-left: 0;
}

.image-format-options {
    display: flex;
    gap: 6px;
}

.image-format-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px 4px;
    border: 1px solid var(--border-input);
    border-radius: 8px;
    background: var(--bg-input);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.72rem;
    transition: border-color 0.2s, color 0.2s, background 0.2s;
}

.image-format-btn:hover {
    border-color: var(--text-secondary);
    color: var(--text);
}

.image-format-btn.active {
    border-color: var(--accent);
    color: var(--accent);
    background: rgba(255, 120, 50, 0.06);
}

.image-format-btn.disabled {
    opacity: 0.35;
    filter: grayscale(1);
    /* Reste cliquable : un clic réactive les boutons en clearant le ratio précis */
}

#rp-tab-image [data-providers].disabled {
    display: none;
}

.rp-cat-select {
    width: 100%;
    padding: 8px 10px;
    font-size: 0.82rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    box-sizing: border-box;
    transition: border-color 0.2s;
}

.rp-cat-select:focus {
    border-color: var(--accent);
}

/* Section conversations sidebar */
.conv-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    gap: 8px;
    position: relative;
}

.cat-select-row {
    display: flex;
    align-items: stretch;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-input);
    overflow: hidden;
}

.cat-select-custom {
    flex: 1;
    min-width: 0;
    font-size: 0.78rem;
    font-family: inherit;
    padding: 7px 8px;
    border: none;
    border-radius: 0;
    background: transparent;
    display: flex;
    align-items: center;
    cursor: pointer;
    color: var(--text-secondary);
}

.cat-select-label {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cat-select-arrow {
    flex-shrink: 0;
    margin-left: 6px;
    opacity: 0.5;
}

.cat-select-custom.open .cat-select-arrow {
    display: none;
}

.cat-select-dropdown {
    position: absolute;
    left: 0;
    right: 0;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 6px 20px rgba(0,0,0,0.2);
    max-height: 220px;
    overflow-y: auto;
    z-index: 100;
}

.cat-select-option {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    font-size: 0.78rem;
    cursor: pointer;
    transition: background 0.1s;
    color: var(--text);
}

.cat-select-option:hover {
    background: var(--bg-hover);
}

.cat-select-option.active {
    background: var(--bg-hover);
    font-weight: 600;
}

.cat-select-option .cat-option-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.cat-manage-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    flex-shrink: 0;
    border: none;
    border-left: 1px solid var(--border);
    border-radius: 0;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: color 0.15s, background 0.15s;
    padding: 0;
}

.cat-manage-btn:hover {
    color: var(--text);
    background: var(--bg-hover);
}

/* --- Modale Sauvegarde --- */
.save-modal {
    width: 440px;
    max-width: 95vw;
    position: relative;
    padding-top: 28px;
}

.save-modal-close-x {
    position: absolute;
    top: 14px;
    right: 14px;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: none;
    color: var(--text-secondary);
    font-size: 1.3rem;
    cursor: pointer;
    border-radius: 6px;
    line-height: 1;
    transition: background 0.15s, color 0.15s;
}

.save-modal-close-x:hover {
    background: var(--bg-hover);
    color: var(--text);
}

.save-modal-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    margin-bottom: 4px;
}

.save-modal-header h3 {
    text-align: center;
}

.save-modal-icon-circle {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--accent-light);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent);
}

.save-modal-warning {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    background: rgba(234, 179, 8, 0.10);
    border-left: 3px solid rgba(234, 179, 8, 0.7);
    border-radius: 0 8px 8px 0;
    padding: 11px 14px;
    margin-bottom: 10px;
}

.save-modal-warning-icon {
    flex-shrink: 0;
    color: #ca8a04;
    margin-top: 1px;
}

.save-modal-warning p {
    margin: 0;
    font-size: 0.82rem;
    line-height: 1.55;
    color: var(--text);
}

.save-modal-desc {
    font-size: 0.82rem;
    color: var(--text-secondary);
    margin: 0 0 16px;
    line-height: 1.55;
    text-align: center;
}

.save-modal-option {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    padding: 10px 12px;
    margin-bottom: 14px;
    background: rgba(0, 0, 0, 0.03);
    border-radius: 8px;
    cursor: pointer;
    user-select: none;
}

body.dark .save-modal-option {
    background: rgba(255, 255, 255, 0.04);
}

.save-modal-option input[type="checkbox"] {
    margin-top: 3px;
    flex-shrink: 0;
    cursor: pointer;
}

.save-modal-option span {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.save-modal-option strong {
    font-size: 0.85rem;
    color: var(--text);
}

.save-modal-option small {
    font-size: 0.75rem;
    color: var(--text-secondary);
    line-height: 1.45;
}

.save-modal-btns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.save-modal-action-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 16px 12px;
    border-radius: 10px;
    font-size: 0.9rem;
    cursor: pointer;
    border: 1px solid var(--border-input);
    background: var(--bg-sidebar);
    color: var(--text);
    transition: background 0.15s, border-color 0.15s, transform 0.1s;
    font-family: inherit;
    text-align: center;
}

.save-modal-action-btn:hover {
    background: var(--bg-hover);
    border-color: var(--text-secondary);
    transform: translateY(-1px);
}

.save-modal-action-btn svg {
    flex-shrink: 0;
}

.save-modal-btn-content {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.save-modal-btn-content strong {
    font-size: 0.88rem;
    font-weight: 600;
}

.save-modal-btn-content small {
    font-size: 0.72rem;
    color: var(--text-secondary);
    font-weight: 400;
}

.save-modal-action-btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.save-modal-action-btn-primary .save-modal-btn-content small {
    color: rgba(255, 255, 255, 0.75);
}

.save-modal-action-btn-primary:hover {
    filter: brightness(1.08);
    border-color: transparent;
    background: var(--accent);
}

/* --- Popups Gestion Rôles / Prompts --- */
.manage-list-modal {
    width: 400px;
    max-width: 95vw;
    position: relative;
}

.manage-list-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.manage-list-header h3 {
    margin: 0;
}

.manage-list-items {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 340px;
    overflow-y: auto;
    padding: 2px 0;
}

.manage-list-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 10px;
    background: var(--bg-sidebar);
    cursor: pointer;
    transition: background 0.15s, box-shadow 0.15s;
    position: relative;
}

.manage-list-item:hover {
    background: var(--bg-hover);
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

.manage-list-item-icon {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    background: var(--accent-light);
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.manage-list-item-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.manage-list-item-name {
    font-size: 0.88rem;
    font-weight: 500;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.manage-list-item-preview {
    font-size: 0.72rem;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.manage-list-item-arrow {
    color: var(--text-secondary);
    flex-shrink: 0;
    opacity: 0;
    transition: opacity 0.15s;
    font-size: 0.8rem;
}

.manage-list-item:hover .manage-list-item-arrow {
    opacity: 1;
}

.manage-list-item-share {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border: none;
    background: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.15s, background 0.15s, color 0.15s;
}

.manage-list-item:hover .manage-list-item-share {
    opacity: 1;
}

.manage-list-item-share:hover {
    background: var(--accent-light);
    color: var(--accent);
}

.manage-list-empty {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.82rem;
    padding: 20px 0;
}


/* Popup Gestion des catégories */
.cat-manage-modal {
    width: 380px;
    position: relative;
}

#cat-manage-list-view,
#cat-manage-edit-view {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.cat-manage-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.cat-manage-header h3 {
    margin: 0;
}

.cat-manage-close-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.3rem;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
    border-radius: 6px;
    transition: color 0.15s, background 0.15s;
}

.cat-manage-close-btn:hover {
    color: var(--text);
    background: var(--bg-hover);
}

.cat-manage-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 320px;
    overflow-y: auto;
    padding: 2px 0;
}

.cat-manage-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 10px;
    background: var(--bg-sidebar);
    cursor: pointer;
    transition: background 0.15s, box-shadow 0.15s;
    position: relative;
}

.cat-manage-item:hover {
    background: var(--bg-hover);
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

.cat-manage-item-badge {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    flex-shrink: 0;
    line-height: 1;
}

.cat-manage-item-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.cat-manage-item-name {
    font-size: 0.88rem;
    font-weight: 500;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cat-manage-item-meta {
    font-size: 0.72rem;
    color: var(--text-secondary);
}

.cat-manage-item-arrow {
    color: var(--text-secondary);
    flex-shrink: 0;
    opacity: 0;
    transition: opacity 0.15s;
    font-size: 0.8rem;
}

.cat-manage-item:hover .cat-manage-item-arrow {
    opacity: 1;
}

.cat-manage-add-btn {
    width: 100%;
    padding: 9px 20px;
    border: 1px solid var(--accent);
    border-radius: 10px;
    background: var(--accent);
    color: #fff;
    font-size: 0.85rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s;
    margin-top: 4px;
}

.cat-manage-add-btn:hover {
    background: var(--accent-dark);
    border-color: var(--accent-dark);
    color: #fff;
}

.cat-manage-add-btn:active {
    transform: translateY(0);
}

.cat-manage-add-btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    box-sizing: border-box;
}

.cat-manage-add-btn-icon svg {
    flex-shrink: 0;
}

.manage-list-footer {
    display: flex;
    gap: 8px;
    align-items: stretch;
}

.manage-list-footer .cat-manage-add-btn {
    flex: 1;
    margin-top: 0;
}

.cat-manage-empty {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.82rem;
    padding: 24px 0;
    line-height: 1.5;
}

.cat-modal-delete-btn {
    font-family: inherit;
    font-size: 0.85rem;
    padding: 9px 20px;
    border-radius: 10px;
    border: 1px solid var(--danger);
    background: transparent;
    color: var(--danger);
    cursor: pointer;
    transition: background 0.15s, color 0.15s, transform 0.15s;
}

.cat-modal-delete-btn:hover {
    background: var(--danger);
    color: #fff;
    transform: translateY(-1px);
}

.cat-modal-delete-btn:active {
    transform: translateY(0);
}

.conv-search {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    font-size: 0.75rem;
    font-family: inherit;
    padding: 6px 10px;
    margin-right: -5px;
    border: 1px solid transparent;
    border-radius: 8px;
    background-color: #eaeaea;
    color: var(--text-secondary);
    outline: none;
    box-sizing: border-box;
    transition: background 0.2s, border-color 0.2s, box-shadow 0.2s, color 0.2s;
}

.dark .conv-search {
    background-color: #2a2a2a;
}

.conv-search:focus {
    background: var(--bg-input);
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-light);
    color: var(--text);
}

.conv-search::placeholder {
    color: var(--text-secondary);
    opacity: 0.5;
}

.rp-role-btn-danger:hover {
    color: var(--danger);
    border-color: var(--danger);
    background: var(--danger-light);
}

.right-panel-select-row {
    margin-bottom: 12px;
}

.right-panel-select-row .model-select {
    width: 100%;
    padding: 8px 10px;
    font-size: 0.82rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    box-sizing: border-box;
    transition: border-color 0.2s;
}

.right-panel-select-row .model-select:focus {
    border-color: var(--accent);
}

.sp-textarea {
    width: 100%;
    min-height: 100px;
    max-height: 200px;
    border: 1px solid var(--border-input);
    border-radius: 8px;
    background: var(--bg-input);
    color: var(--text);
    font-family: inherit;
    font-size: 0.83rem;
    line-height: 1.5;
    padding: 10px 12px;
    resize: vertical;
    outline: none;
    box-sizing: border-box;
    transition: border-color 0.2s;
}

.sp-textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-light);
}

.sp-textarea::placeholder {
    color: var(--text-secondary);
    opacity: 0.6;
}

.right-panel-toggle {
    /* Ancien bouton conservé caché pour compatibilité JS */
    display: none !important;
}

/* ---- Nouvelle barre latérale : gear (réglages) + canvas ---- */
.side-panel-toolbar {
    position: fixed;
    top: 10px;
    right: 264px; /* position par défaut : volet droit ouvert (280px) */
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 6px;
    transition: right 0.25s ease;
}

.side-panel-btn {
    position: relative;
    background: var(--bg-sidebar);
    border: 1px solid var(--border-input);
    border-radius: 6px;
    padding: 4px 6px;
    cursor: pointer;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.15s, background 0.15s;
}

.side-panel-btn:hover {
    color: var(--text);
    background: var(--bg-hover);
}

.side-panel-btn.active {
    color: var(--text);
    background: var(--bg-hover);
}

.side-canvas-count {
    position: absolute;
    top: -4px;
    right: -4px;
    background: var(--accent, #5865f2);
    color: #fff;
    font-size: 0.62rem;
    line-height: 1;
    min-width: 14px;
    padding: 2px 4px;
    border-radius: 8px;
    font-weight: 600;
    text-align: center;
    pointer-events: none;
}

.side-canvas-count:empty {
    display: none;
}

/* Décalage de la zone chat quand aucun volet n'est ouvert
   (pour laisser de la place aux icônes flottantes) */
body:has(#right-panel.collapsed):not(.canvas-active) .chat-container {
    padding-right: 56px;
}

/* Position de la toolbar selon l'état des volets :
   - volet réglages ouvert  : right 264px (= 280 - 16, bord gauche du volet)
   - volet canvas ouvert    : pilotée en JS via --side-toolbar-right
   - aucun volet ouvert     : 8px (flottante) */
body:has(#right-panel.collapsed):not(.canvas-active) .side-panel-toolbar {
    right: 8px;
}

body.canvas-active .side-panel-toolbar {
    right: var(--side-toolbar-right, 464px);
}

@media (max-width: 768px) {
    .right-panel {
        display: none;
    }
    .side-panel-toolbar {
        display: none;
    }
}

.sidebar-title {
    font-size: 2.2rem;
    font-weight: 700;
    margin-bottom: 0;
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.sidebar-logo {
    width: 40px;
    height: 40px;
}
.version-badge {
    font-size: 0.45em;
    font-weight: 600;
    opacity: 0.5;
    vertical-align: super;
}

.sidebar-credit {
    display: block;
    text-align: center;
    font-size: 0.65rem;
    color: var(--text-secondary);
    text-decoration: none;
    margin-top: -6px;
    margin-bottom: 8px;
    transition: color 0.15s;
}

.sidebar-credit:hover {
    color: var(--text);
    text-decoration: underline;
}


.new-chat-btn {
    background: var(--accent);
    border: 1px solid var(--accent);
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    text-align: center;
    transition: all 0.2s;
    color: #fff;
}

.new-chat-btn:hover {
    background: var(--accent-dark);
    border-color: var(--accent-dark);
    color: #fff;
}

/* Boutons bas de sidebar */
.sidebar-bottom {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: auto;
    margin-bottom: 0;
    position: relative;
}

.sidebar-bottom::before {
    content: '';
    position: absolute;
    top: -40px;
    left: -16px;
    right: -16px;
    height: 40px;
    background: linear-gradient(to bottom, transparent 0%, var(--bg-sidebar) 80%);
    pointer-events: none;
}

.sidebar-bottom-row {
    display: flex;
    gap: 6px;
}

.sidebar-bottom-row .sidebar-bottom-btn {
    flex: 1;
}

.sidebar-bottom-btn {
    background: none;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px 10px;
    font-size: 0.75rem;
    font-family: inherit;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.15s;
    text-align: center;
}

.sidebar-bottom-btn:hover {
    background: var(--bg-hover);
    color: var(--text);
    border-color: var(--border-input);
}

/* Recherche de conversations — styles fusionnés dans .conv-search */

/* Liste des conversations */
.conv-list-container {
    flex: 1;
    overflow-y: auto;
    margin-top: 4px;
    margin-right: -10px;
    padding-right: 3px;
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-thumb) transparent;
}

.conv-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.conv-item {
    display: flex;
    align-items: center;
    padding: 8px 6px 8px 10px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.25s ease, border-color 0.25s ease;
    overflow: hidden;
    border: 1px solid transparent;
}

.conv-item-content {
    flex: 1;
    min-width: 0;
}

.conv-item-actions {
    display: flex;
    gap: 1px;
    opacity: 0;
    flex-shrink: 0;
}

.conv-item:hover .conv-item-actions {
    opacity: 1;
}

.conv-action-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 1px 3px;
    border-radius: 4px;
    line-height: 1;
    display: flex;
    align-items: center;
    transition: color 0.15s, background 0.15s;
}

.conv-action-btn:hover {
    color: var(--text);
    background: var(--bg-hover);
}

.conv-action-btn.danger:hover {
    color: var(--danger);
    background: var(--danger-light);
}

.conv-item:hover {
    background: var(--bg-hover);
    border-color: var(--border);
}

.conv-item.active {
    background: var(--cat-color-light, var(--accent-light));
    border-color: transparent;
}

.conv-item.active .conv-item-title {
    color: var(--cat-color, var(--accent));
}

.conv-item-title {
    font-size: 0.85rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text);
    transition: color 0.25s ease;
}

.conv-item-date-line {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 4px;
    margin-top: 2px;
}

.conv-item-date {
    font-size: 0.7rem;
    color: var(--text-secondary);
}


.conv-rename-input {
    width: 100%;
    font-family: inherit;
    font-size: 0.8rem;
    padding: 1px 4px;
    border: 1px solid var(--border-input);
    border-radius: 4px;
    background: var(--bg-input);
    color: var(--text);
    outline: none;
}

/* Popup changement de catégorie */
.conv-cat-popup {
    position: fixed;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 6px 20px rgba(0,0,0,0.15);
    padding: 6px;
    z-index: 2000;
    min-width: 180px;
    max-height: 80vh;
    overflow-y: auto;
}

.conv-cat-popup::before {
    content: '';
    position: absolute;
    left: -5px;
    top: 16px;
    width: 9px;
    height: 9px;
    background: var(--bg-input);
    border-left: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    transform: rotate(45deg);
}

.conv-cat-popup-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.82rem;
    color: var(--text);
    transition: background 0.1s;
}

.conv-cat-popup-item:hover {
    background: var(--bg-hover);
}

.conv-cat-popup-item.active {
    font-weight: 600;
}

.conv-cat-popup-separator {
    height: 1px;
    background: var(--border-light);
    margin: 4px 2px;
}

.conv-list-container::-webkit-scrollbar {
    width: 4px;
}

/* Main */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    position: relative;
}

/* Chat header */
.input-settings-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: color 0.2s;
}

.input-settings-btn:hover {
    color: var(--text);
}

/* Chat container */
.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 24px 32px 48px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

@keyframes chat-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

.chat-container.fade-in {
    animation: chat-fade-in 0.3s ease;
}

.empty-chat-placeholder {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    opacity: 0.5;
}

.empty-chat-logo {
    width: 80px;
    height: 80px;
}

.empty-chat-text {
    font-size: 0.9rem;
    color: var(--text-secondary);
    text-align: center;
    max-width: 360px;
    line-height: 1.5;
}

.empty-chat-category {
    font-size: 0.82rem;
    font-weight: 500;
    text-align: center;
    padding: 8px 24px;
    border-radius: 10px;
    border: 1px solid;
    max-width: 480px;
    line-height: 1.4;
}

/* Messages */
.message {
    max-width: 75%;
    padding: 14px 18px;
    border-radius: 16px;
    font-size: 0.95rem;
    line-height: 1.6;
    word-wrap: break-word;
    position: relative;
}

.message-user .message-text {
    white-space: pre-wrap;
}

.message-text {
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* Placeholder « Génération en cours… » : couleur catégorie active + lumière
   qui traverse. Le gradient est répété (background-repeat: repeat) pour qu'il
   recouvre toujours le texte — sinon, à mi-cycle, la zone hors-gradient laisse
   apparaître le `transparent` du text-fill et le texte « disparaît ». */
.generation-placeholder {
    --gp-color: var(--active-cat-color, var(--accent, #6b7280));
    --gp-highlight: color-mix(in srgb, var(--gp-color) 35%, #ffffff);
    display: inline-block;
    font-weight: 500;
    background-image: linear-gradient(
        90deg,
        var(--gp-color) 0%,
        var(--gp-color) 40%,
        var(--gp-highlight) 50%,
        var(--gp-color) 60%,
        var(--gp-color) 100%
    );
    background-size: 200% 100%;
    background-repeat: repeat;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: transparent;
    animation: generation-shimmer 2.2s linear infinite;
}
body.dark .generation-placeholder {
    --gp-highlight: color-mix(in srgb, var(--gp-color) 25%, #e8e8e8);
}
@keyframes generation-shimmer {
    0%   { background-position: 0% 0; }
    100% { background-position: -200% 0; }
}

/* Flash sur les caractères qui viennent d'apparaître pendant le streaming.
   La couleur de départ et la transition sont posées en inline-style par JS
   (cf. _wrapNewChars), ce qui contourne les problèmes de cascade et garantit
   que le 1er paint montre la teinte de départ. Cette règle ne sert que de
   filet de sécurité si l'inline style était retiré avant la transition. */
.char-flash {
    transition: color 600ms linear;
}

.message-text p {
    margin: 0 0 0.5em 0;
}

.message-text p:last-child {
    margin-bottom: 0;
}

.message-text pre {
    background: rgba(0,0,0,0.08);
    border-radius: 8px;
    padding: 12px;
    overflow-x: auto;
    margin: 0.5em 0;
    font-size: 0.85rem;
}

body.dark .message-text pre {
    background: rgba(255,255,255,0.08);
}

.message-text code {
    background: rgba(0,0,0,0.06);
    border-radius: 3px;
    padding: 1px 4px;
    font-size: 0.88em;
}

body.dark .message-text code {
    background: rgba(255,255,255,0.1);
}

.message-text pre code {
    background: none;
    padding: 0;
    border-radius: 0;
    font-size: inherit;
}

.message-text ul, .message-text ol {
    margin: 0.4em 0;
    padding-left: 1.5em;
}

.message-text h1, .message-text h2, .message-text h3 {
    margin: 0.6em 0 0.3em 0;
    line-height: 1.3;
}

.message-text h1 { font-size: 1.2em; }
.message-text h2 { font-size: 1.1em; }
.message-text h3 { font-size: 1em; }

.message-text blockquote {
    border-left: 3px solid var(--border-input);
    margin: 0.5em 0;
    padding: 0.2em 0 0.2em 12px;
    color: var(--text-secondary);
}

.message-text table {
    border-collapse: collapse;
    margin: 0.5em 0;
    font-size: 0.9em;
}

.message-text th, .message-text td {
    border: 1px solid var(--border);
    padding: 4px 10px;
}

.message-text th {
    background: rgba(0,0,0,0.04);
}

body.dark .message-text th {
    background: rgba(255,255,255,0.06);
}

/* Citations Perplexity */
.citations-block {
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid var(--border-light);
}

.citations-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 6px;
}

.citations-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.citations-list li {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.8rem;
    background: var(--bg-hover);
    border-radius: 6px;
    padding: 3px 8px;
    transition: background 0.15s;
}

.citations-list li:hover {
    background: var(--bg-active);
}

.citation-num {
    color: var(--text-secondary);
    font-size: 0.7rem;
    font-weight: 600;
}

.citations-list a {
    color: var(--text);
    text-decoration: none;
}

.citations-list a:hover {
    text-decoration: underline;
}

.message-text a {
    color: var(--link);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.message-text a:hover {
    color: var(--link-hover);
}

/* Wrapper message + bouton copier */
.message-wrapper {
    display: flex;
    flex-direction: column;
    width: 100%;
}

.message-wrapper-user {
    align-items: flex-end;
}

.message-wrapper-assistant {
    align-items: flex-start;
}

.message-wrapper .message {
    max-width: 75%;
}

.message-btn-row {
    display: flex;
    gap: 4px;
    align-items: center;
}

.message-wrapper-assistant .message-btn-row {
    justify-content: flex-start;
    align-self: flex-start;
    opacity: 0;
    transition: opacity 0.2s;
}

.message-wrapper-user .message-btn-row {
    justify-content: flex-end;
    align-self: flex-end;
    opacity: 0;
    transition: opacity 0.2s;
}

.message-wrapper-user:hover .message-btn-row,
.message-wrapper-assistant:hover .message-btn-row,
.message-wrapper-assistant:not(:has(~ .message-wrapper-assistant)) .message-btn-row {
    opacity: 1;
}

.message-btn-row .message-copy-btn,
.message-btn-row .message-tts-btn,
.message-btn-row .message-save-prompt-btn,
.message-btn-row .message-edit-btn,
.message-btn-row .regen-btn {
    opacity: 0.5;
    transition: opacity 0.15s;
}

.message-btn-row .message-copy-btn:hover,
.message-btn-row .message-tts-btn:hover,
.message-btn-row .message-save-prompt-btn:hover,
.message-btn-row .message-edit-btn:hover,
.message-btn-row .regen-btn:hover,
.message-btn-row .message-copy-btn.menu-open,
.message-btn-row .message-tts-btn.menu-open {
    opacity: 1;
}

.message-gen-time {
    color: var(--text-secondary);
    opacity: 0.5;
    margin-right: 2px;
    position: relative;
    cursor: default;
    display: inline-flex;
    align-items: center;
    transition: opacity 0.15s;
}

.message-gen-time:hover {
    opacity: 1;
}

.message-gen-time[data-tooltip]:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 4px);
    left: 0;
    background: var(--tooltip-bg);
    color: var(--tooltip-text);
    font-size: 0.65rem;
    padding: 3px 7px;
    border-radius: 5px;
    white-space: nowrap;
    pointer-events: none;
    z-index: 100;
}

.message-copy-btn,
.message-tts-btn {
    background: none;
    border: none;
    padding: 4px 6px;
    cursor: pointer;
    color: var(--text-secondary);
    line-height: 1;
    transition: color 0.15s;
}

.message-copy-btn:hover,
.message-tts-btn:hover {
    color: var(--text);
}

/* Menu de copie (Copier / Copier Markdown) */
.copy-menu {
    display: none;
    position: fixed;
    background: var(--bg-input);
    border: 1px solid var(--border-input);
    border-radius: 6px;
    box-shadow: 0 3px 12px rgba(0,0,0,0.12);
    z-index: 10000;
    white-space: nowrap;
}
.copy-menu.open {
    display: block;
}
.copy-menu-item {
    padding: 6px 14px;
    font-size: 0.78rem;
    color: var(--text);
    cursor: pointer;
    text-align: left;
    transition: background 0.12s;
}
.copy-menu-item:hover {
    background: var(--bg-hover);
    color: var(--text);
}

/* Images dans les messages */
.message-images {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 8px;
}

.message-images img {
    max-width: 400px;
    max-height: 400px;
    border-radius: 8px;
    object-fit: contain;
    cursor: pointer;
}

.message-user .message-images img {
    max-width: 200px;
    max-height: 200px;
    object-fit: cover;
}

.message-image-wrap {
    position: relative;
    display: inline-block;
}

.image-download-btn {
    position: absolute;
    bottom: 8px;
    right: 8px;
    background: rgba(0,0,0,0.55);
    border: none;
    border-radius: 6px;
    padding: 5px 7px;
    cursor: pointer;
    color: #fff;
    line-height: 1;
    opacity: 0;
    transition: opacity 0.15s;
}

.message-image-wrap:hover .image-download-btn {
    opacity: 1;
}

.image-download-btn:hover {
    background: rgba(0,0,0,0.8);
}

/* Bouton régénérer (dans btn-row) */
.regen-btn {
    background: none;
    border: none;
    padding: 4px 6px;
    cursor: pointer;
    color: var(--text-secondary);
    line-height: 1;
    transition: color 0.15s;
}

.regen-btn:hover {
    color: var(--text);
}

/* Bouton micro */

.web-search-toggle {
    background: none;
    border: 1px solid var(--border-input);
    border-radius: 6px;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 3px 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.web-search-toggle:hover {
    color: var(--text);
    background: var(--bg-hover);
}

.web-search-toggle.active {
    color: var(--link);
    border-color: var(--link);
    background: rgba(37, 99, 235, 0.1);
}

body.dark .web-search-toggle.active {
    color: var(--link);
    border-color: var(--link);
    background: rgba(96, 165, 250, 0.12);
}

.mic-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    color: var(--text-secondary);
    flex-shrink: 0;
    transition: color 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mic-btn:hover {
    color: var(--text);
}

.mic-btn.recording {
    color: var(--danger);
    animation: pulse-mic 1s ease-in-out infinite;
}

@keyframes pulse-mic {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* Spinner pour chargement TTS / Whisper */
.spin {
    animation: spin 1s linear infinite;
}

.conv-list-loading {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px 0;
    opacity: 0.6;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* Effet shimmer pendant l'amélioration du prompt */
@keyframes enhance-shimmer {
    0% { background-position: 200% center; }
    100% { background-position: -200% center; }
}

.prompt-input.enhancing,
.sp-modal-textarea-wrap .sp-modal-textarea.enhancing,
.sp-modal-textarea.enhancing {
    background-color: transparent !important;
    background-image: linear-gradient(
        90deg,
        var(--active-cat-color, var(--accent)) 0%,
        #f7a76a 25%,
        var(--active-cat-color, var(--accent)) 50%,
        #f7a76a 75%,
        var(--active-cat-color, var(--accent)) 100%
    ) !important;
    background-size: 200% auto !important;
    -webkit-background-clip: text !important;
    background-clip: text !important;
    -webkit-text-fill-color: transparent !important;
    animation: enhance-shimmer 3s linear infinite !important;
}

.message-user {
    align-self: flex-end;
    background: var(--bg-msg-user);
    border-bottom-right-radius: 4px;
}

.message-assistant {
    align-self: flex-start;
    background: var(--bg-msg-assistant);
    border-bottom-left-radius: 4px;
}

.message-assistant.message-error {
    background: rgba(200, 0, 0, 0.08);
    border: 1px solid rgba(200, 0, 0, 0.25);
}
.message-assistant.message-error .message-text {
    color: #c00;
}

.message-assistant.streaming {
    min-height: 40px;
    --_stream-color: var(--active-cat-color, var(--accent));
    background:
        linear-gradient(
            135deg,
            var(--bg-msg-assistant) 0%,
            color-mix(in srgb, var(--_stream-color) var(--streaming-intensity, 16%), var(--bg-msg-assistant)) 50%,
            var(--bg-msg-assistant) 100%
        );
    background-size: 300% 300%;
    animation: streaming-shimmer 3s ease-in-out infinite;
}

.message-assistant.streaming-done {
    --_stream-color: var(--active-cat-color, var(--accent));
    background:
        linear-gradient(
            135deg,
            var(--bg-msg-assistant) 0%,
            color-mix(in srgb, var(--_stream-color) var(--streaming-intensity, 16%), var(--bg-msg-assistant)) 50%,
            var(--bg-msg-assistant) 100%
        );
    background-size: 300% 300%;
    animation: streaming-fade-out 0.8s ease-out forwards;
}

@keyframes streaming-shimmer {
    0%   { background-position: 0% 50%; }
    50%  { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

@keyframes streaming-fade-out {
    0%   { --streaming-intensity: 16%; }
    100% { --streaming-intensity: 0%; }
}

@property --streaming-intensity {
    syntax: '<percentage>';
    initial-value: 16%;
    inherits: false;
}

/* Animation d'apparition des messages */
@keyframes message-appear {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-wrapper.animate-in {
    animation: message-appear 0.25s ease-out;
}

/* Alerte modèle manquant */
.model-alert {
    position: relative;
    z-index: 25;
    margin: 8px 32px 0;
    padding: 10px 40px 10px 38px;
    background:
        linear-gradient(rgba(240, 145, 58, 0.08), rgba(240, 145, 58, 0.08)),
        var(--bg);
    color: var(--text, #333);
    border: 1px solid rgba(240, 145, 58, 0.35);
    border-left: 3px solid #f0913a;
    border-radius: 8px;
    font-size: 0.85rem;
    line-height: 1.4;
    text-align: left;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
    animation: modelAlertSlide 0.25s ease;
}
.model-alert::before {
    content: '';
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 18px;
    height: 18px;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23f0913a' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'><circle cx='12' cy='12' r='10'/><line x1='12' y1='8' x2='12' y2='12'/><line x1='12' y1='16' x2='12.01' y2='16'/></svg>");
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
}
.model-alert-close {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: inherit;
    opacity: 0.55;
    cursor: pointer;
    padding: 4px;
    line-height: 0;
    border-radius: 4px;
    transition: opacity 0.15s ease, background 0.15s ease;
}
.model-alert-close:hover {
    opacity: 1;
    background: rgba(240, 145, 58, 0.12);
}

body.dark .model-alert {
    background:
        linear-gradient(rgba(240, 145, 58, 0.10), rgba(240, 145, 58, 0.10)),
        var(--bg);
    color: #e8e8e8;
    border-color: rgba(240, 145, 58, 0.4);
}

@keyframes modelAlertSlide {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Sélecteur de modèle */
.model-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

.model-select {
    font-size: 0.8rem;
    font-family: inherit;
    padding: 4px 8px;
    border: 1px solid var(--border-input);
    border-radius: 6px;
    background: var(--bg-input);
    color: var(--text);
    cursor: pointer;
    outline: none;
}

.model-select:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: var(--bg-sidebar);
}

/* Sélecteur de modèle personnalisé */
.custom-select {
    position: relative;
    display: inline-block;
}

.custom-select-trigger {
    display: flex;
    align-items: center;
    font-size: 0.8rem;
    font-family: inherit;
    padding: 4px 10px;
    border: 1px solid var(--border-input);
    border-radius: 6px;
    background: var(--bg-input);
    color: var(--text);
    cursor: pointer;
    outline: none;
    white-space: nowrap;
    min-width: 90px;
    user-select: none;
}

.custom-select.open .custom-select-trigger {
    border-top-left-radius: 0;
    border-top-right-radius: 0;
}

.custom-select-dropdown {
    display: none;
    position: absolute;
    bottom: 100%;
    left: 0;
    min-width: 220px;
    max-height: 320px;
    overflow-y: auto;
    background: var(--bg-input);
    border: 1px solid var(--border-input);
    border-radius: 8px 8px 0 0;
    box-shadow: 0 -4px 16px rgba(0,0,0,0.12);
    z-index: 1000;
    padding: 0 0 4px;
    scrollbar-width: none;
}

.custom-select.open .custom-select-dropdown {
    display: block;
}

/* Le custom-select dans input-wrapper devient static pour que le dropdown se positionne par rapport à input-wrapper */
.input-wrapper > .custom-select {
    position: static;
}

/* Dropdown du sélecteur principal (unifié) : taille fixe, aligné à gauche de input-wrapper */
.input-wrapper > .custom-select .custom-select-dropdown {
    width: 300px;
    min-width: 300px;
    height: 360px;
    max-height: 360px;
    overflow: hidden;
    border-radius: 12px;
    bottom: calc(100% + 6px);
    left: 0;
}

.input-wrapper > .custom-select.open .custom-select-dropdown {
    display: flex;
    flex-direction: column;
}

.input-wrapper > .custom-select .custom-select-tabs {
    flex-shrink: 0;
}

.input-wrapper > .custom-select .custom-select-tab-content {
    flex: 1;
    overflow-y: auto;
    scrollbar-width: none;
}

/* Onglets Texte / Image / Recherche dans le sélecteur unifié */
.custom-select-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-input);
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--bg-input);
    padding: 0;
    margin: 0;
}

.custom-select-tab {
    flex: 1;
    padding: 7px 4px;
    text-align: center;
    cursor: pointer;
    font-size: 0.72rem;
    font-weight: 500;
    color: var(--text-secondary);
    border-bottom: 2px solid transparent;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    user-select: none;
    white-space: nowrap;
}

.custom-select-tab:hover {
    color: var(--text);
    background: var(--bg-hover);
}

.custom-select-tab.active {
    color: var(--text);
    border-bottom-color: var(--active-cat-color, var(--accent));
    font-weight: 600;
}

.custom-select-tab svg {
    opacity: 0.6;
    flex-shrink: 0;
}

.custom-select-tab.active svg {
    opacity: 1;
}

/* Contenu des modèles sous les onglets */
.custom-select-tab-content {
    /* conteneur pour les options de modèles */
}

.custom-select-provider {
    padding: 0;
}

.custom-select-group {
    position: sticky;
    top: 0;
    z-index: 1;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    padding: 6px 12px;
    background: var(--bg-sidebar);
    border-bottom: none;
    pointer-events: none;
    user-select: none;
    display: flex;
    align-items: center;
    gap: 10px;
    text-align: center;
}

.custom-select-group::before,
.custom-select-group::after {
    content: '';
    flex: 1;
    height: 2px;
    background: var(--border-light, rgba(0,0,0,0.12));
}

.custom-select-group-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
    color: #282828;
}

.custom-select-group-icon {
    width: 14px;
    height: 14px;
    object-fit: contain;
    flex-shrink: 0;
}

.custom-select-trigger-icon {
    width: 14px;
    height: 14px;
    object-fit: contain;
    flex-shrink: 0;
    margin-right: 6px;
    filter: brightness(0) opacity(0.75);
}

body.dark .custom-select-group-label {
    color: #fff;
}

body.dark .custom-select-group-icon,
body.dark .custom-select-trigger-icon {
    filter: invert(1) brightness(1.1);
}

.custom-select-option {
    display: flex;
    flex-direction: row;
    align-items: center;
    padding: 5px 12px;
    cursor: pointer;
    transition: background 0.1s;
}

.custom-select-option:hover {
    background: var(--bg-hover);
}

.custom-select-option.active {
    background: var(--active-cat-color, var(--accent));
    color: #fff;
}
.custom-select-option.active .custom-select-option-name,
.custom-select-option.active .custom-select-option-price {
    color: #fff;
}
.custom-select-option.active .custom-select-info {
    color: #fff;
    border-color: rgba(255,255,255,0.6);
}

.custom-select-option-text {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
}

.custom-select-option-name {
    font-size: 0.8rem;
    color: var(--text);
}

.custom-select-option-price {
    font-size: 0.65rem;
    color: var(--text-secondary);
}
.custom-select-info {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    min-width: 14px;
    border-radius: 50%;
    border: 1px solid var(--text-secondary);
    font-size: 0.55rem;
    font-weight: 700;
    font-style: italic;
    font-family: Georgia, serif;
    color: var(--text-secondary);
    cursor: default;
    margin-left: 8px;
    opacity: 0;
    transition: opacity 0.15s;
}

.custom-select-option:hover .custom-select-info {
    opacity: 1;
}

#custom-select-tooltip {
    position: fixed;
    background: var(--tooltip-bg);
    color: var(--tooltip-text);
    font-size: 0.7rem;
    font-weight: 400;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    line-height: 1.45;
    padding: 8px 11px;
    border-radius: 6px;
    white-space: pre-line;
    width: 260px;
    max-width: calc(100vw - 16px);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s;
    z-index: 10001;
}

#custom-select-tooltip.visible {
    opacity: 1;
}

.custom-select-option--empty {
    font-size: 0.8rem;
    color: var(--text-secondary);
    padding: 5px 12px;
    cursor: pointer;
}

.custom-select-option--empty:hover {
    background: var(--bg-hover);
}

.custom-select-empty-message {
    padding: 16px 18px;
    font-size: 0.82rem;
    color: var(--text-secondary);
    text-align: center;
    line-height: 1.5;
}
.custom-select-empty-link {
    color: var(--accent, #3b82f6);
    text-decoration: underline;
    cursor: pointer;
}
.custom-select-empty-link:hover {
    opacity: 0.85;
}

.custom-select.disabled .custom-select-trigger {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
    background: var(--bg-sidebar);
}

.custom-select-dropdown::-webkit-scrollbar {
    display: none;
}

/* Barre de tokens */
.token-bar {
    display: flex;
    justify-content: space-between;
    padding: 6px 32px;
    font-size: 0.75rem;
    color: var(--text-secondary);
    position: relative;
    z-index: 17;
    isolation: isolate;
    background: var(--bg);
}

.token-bar::before {
    content: '';
    position: absolute;
    top: -40px;
    left: 0;
    right: 0;
    height: 40px;
    background: linear-gradient(to bottom, transparent, var(--bg));
    pointer-events: none;
    z-index: -1;
}

#token-info,
#cost-info {
    font-variant-numeric: tabular-nums;
    background: rgba(255, 255, 255, 0.85);
    padding: 3px 0;
    border-radius: 12px;
    backdrop-filter: blur(4px);
}

body.dark #token-info,
body.dark #cost-info {
    background: rgba(30, 30, 30, 0.85);
}

/* Zone de prévisualisation des pièces jointes */
#attach-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    width: 100%;
    max-width: 800px;
}

#attach-preview:empty {
    display: none;
}

.attach-thumb {
    position: relative;
    display: inline-block;
}

.attach-thumb img {
    width: 60px;
    height: 60px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid var(--border-input);
}

.attach-thumb-remove {
    position: absolute;
    top: -6px;
    right: -6px;
    background: var(--btn-bg);
    color: var(--btn-text);
    border: none;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    font-size: 0.7rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

/* Zone de saisie */
.input-area {
    padding: 16px 32px 24px;
    border-top: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    transition: background 0.15s;
    position: relative;
    z-index: 18;
    background: var(--bg);
}

/* dégradé déplacé sur .token-bar::before */

.input-area.drag-over {
    background: rgba(59, 130, 246, 0.06);
    border-top-color: #3b82f6;
}

.input-area.drag-over .input-wrapper {
    border-color: #3b82f6;
}

.input-row {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    max-width: 800px;
}

.input-hint {
    display: block;
    text-align: center;
    font-size: 0.68rem;
    color: var(--text-secondary);
    opacity: 0.5;
    padding-top: 3px;
    user-select: none;
    width: 100%;
    max-width: 800px;
    box-sizing: border-box;
}

.input-wrapper {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    width: 100%;
    border: 2px solid var(--border-input);
    border-radius: 24px;
    padding: 8px 12px;
    transition: border-color 0.2s;
    background: var(--bg-input);
    gap: 6px;
    position: relative;
}

/* Contenu principal à droite du sélecteur de modèle */
.input-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
    gap: 2px;
    position: relative;
}

/* Ligne 1 : textarea */
.input-line-1 {
    display: flex;
    align-items: center;
    width: 100%;
}

/* Ligne 2 : icônes gauche | boutons centre | micro droite */
.input-line-2 {
    display: flex;
    align-items: center;
    width: 100%;
    justify-content: space-between;
    min-height: 30px;
    position: relative;
}

.input-line-2 {
    container-type: inline-size;
}

.input-line-2-left {
    display: flex;
    align-items: center;
    gap: 2px;
    flex-shrink: 0;
}

.input-line-2-center {
    display: flex;
    align-items: center;
    gap: 6px;
    justify-content: center;
    flex: 1 1 auto;
    min-width: 0;
    position: relative;
    pointer-events: auto;
}

.input-line-2-right {
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

/* Bouton icône générique dans la ligne 2 */
.input-icon-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: color 0.15s;
    border-radius: 6px;
}

.input-icon-btn:hover {
    color: var(--text);
}

.input-icon-btn.active {
    background: var(--active-cat-color, var(--accent, #F06D13));
    color: #fff;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    min-width: 28px;
    min-height: 28px;
    padding: 0;
}

.input-icon-btn.active:hover {
    background: var(--active-cat-color, var(--accent-dark, #c95a0e));
    color: #fff;
    filter: brightness(0.9);
}

#web-search-btn.custom-select-info {
    opacity: 1;
    width: 28px;
    height: 28px;
    min-width: 28px;
    min-height: 28px;
    padding: 0;
    font-size: inherit;
    margin-left: 0;
    cursor: pointer;
}

/* Boutons toolbar dans la ligne 2 */
.input-line-2-center .prompt-toolbar-btn {
    font-size: 0.72rem;
    padding: 4px 10px;
    border-radius: 16px;
    transition: opacity 0.2s ease, transform 0.15s ease;
}

/* Bouton "Insérer un prompt" flottant au-dessus du curseur */
#toolbar-insert-btn.floating {
    position: absolute;
    z-index: 120;
    translate: -50% -100%;
    margin-top: -10px;
    background: var(--bg-input, #fff);
    border-color: var(--active-cat-color, var(--accent));
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    transition: left 0.25s ease, top 0.25s ease, opacity 0.2s ease;
}

/* Micro en mode stop (streaming) */
.mic-btn.stop-mode {
    background: var(--active-cat-color, var(--accent, #F06D13));
    color: #fff;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    min-width: 28px;
    min-height: 28px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mic-btn.stop-mode:hover {
    background: var(--accent-dark, #c95a0e);
    color: #fff;
}

.input-wrapper:focus-within {
    border-color: var(--active-cat-color, var(--accent));
}

body.dark .input-wrapper:focus-within {
    border-color: var(--active-cat-color, #f0913a);
}

/* Sélecteur de modèle intégré dans la barre de saisie */
.input-line-1 > .custom-select .custom-select-trigger,
.input-wrapper > .custom-select .custom-select-trigger {
    border: none;
    background: transparent;
    border-radius: 0;
    padding: 4px 10px 4px 8px;
    color: var(--text-secondary);
    font-weight: 500;
    min-width: auto;
    flex: 1;
    align-self: stretch;
    display: flex;
    align-items: center;
    cursor: pointer;
}

.input-line-1 > .custom-select .custom-select-trigger::after,
.input-wrapper > .custom-select .custom-select-trigger::after {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    margin-left: 6px;
    border-right: 1.5px solid var(--text-secondary);
    border-bottom: 1.5px solid var(--text-secondary);
    transform: rotate(45deg);
    position: relative;
    top: -2px;
    flex-shrink: 0;
    opacity: 0.5;
}

.input-line-1 > .custom-select,
.input-wrapper > .custom-select {
    flex-shrink: 0;
    border-right: 1px solid var(--border-input);
    margin-right: 2px;
    align-self: stretch;
    display: flex;
    align-items: center;
    min-height: 100%;
    max-width: 160px;
}

.input-line-1 > .custom-select .custom-select-trigger,
.input-wrapper > .custom-select .custom-select-trigger {
    max-width: 100%;
    overflow: hidden;
}

.input-line-1 > .custom-select .custom-select-text,
.input-wrapper > .custom-select .custom-select-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: block;
    max-width: 110px;
}

.input-line-1 > .custom-select.open .custom-select-trigger,
.input-wrapper > .custom-select.open .custom-select-trigger {
    border-radius: 0;
}

/* Boutons d'action sous la barre de saisie */
.input-action-buttons {
    display: flex;
    gap: 6px;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 800px;
    position: relative;
    padding-top: 2px;
    z-index: 100;
}

.input-action-btn {
    display: inline-flex;
    align-items: stretch;
    border: 1px solid var(--border-light);
    border-radius: 20px;
    background: var(--bg);
    cursor: pointer;
    font-size: 0.76rem;
    font-family: inherit;
    color: var(--text-secondary);
    user-select: none;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
    transition: all 0.2s ease;
    overflow: visible;
    position: relative;
    letter-spacing: 0.01em;
}

.input-action-btn:hover {
    border-color: var(--text-secondary);
    color: var(--text);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
    transform: translateY(-1px);
}

.input-action-btn:active {
    transform: translateY(0);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

body.dark .input-action-btn {
    background: var(--bg-input);
    border-color: var(--border-input);
}

.input-action-btn.active {
    color: var(--link);
    border-color: rgba(37, 99, 235, 0.4);
    background: rgba(37, 99, 235, 0.06);
    box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.08);
}

.input-action-btn.active:hover {
    background: rgba(37, 99, 235, 0.12);
}

body.dark .input-action-btn.active {
    color: var(--link);
    border-color: rgba(96, 165, 250, 0.4);
    background: rgba(96, 165, 250, 0.08);
    box-shadow: 0 0 0 1px rgba(96, 165, 250, 0.08);
}

body.dark .input-action-btn.active:hover {
    background: rgba(96, 165, 250, 0.15);
}

.input-action-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 6px 5px 10px;
    white-space: nowrap;
    font-weight: 500;
}

.input-action-label svg {
    opacity: 0.7;
    flex-shrink: 0;
}

.input-action-btn.active .input-action-label svg {
    opacity: 1;
}

.input-action-arrow {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 7px;
    border-left: 1px solid var(--border-input);
    opacity: 0.4;
    transition: all 0.15s ease;
    border-radius: 0 20px 20px 0;
}

.input-action-arrow:hover {
    opacity: 0.8;
    background: rgba(0, 0, 0, 0.04);
}

body.dark .input-action-arrow:hover {
    background: rgba(255, 255, 255, 0.06);
}

.input-action-btn.active .input-action-arrow {
    border-left-color: rgba(37, 99, 235, 0.2);
    opacity: 0.6;
}

body.dark .input-action-btn.active .input-action-arrow {
    border-left-color: rgba(96, 165, 250, 0.2);
}

/* Custom select dropdown positionné au-dessus du bouton d'action */
.input-action-btn .custom-select {
    position: static;
}

.input-action-btn .custom-select .custom-select-trigger {
    display: none;
}

.input-action-btn .custom-select .custom-select-dropdown {
    bottom: calc(100% + 4px);
    top: auto;
    left: 0;
}

#attach-btn {
    background: none;
    border: none;
    border-radius: 0;
    cursor: pointer;
    padding: 4px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: color 0.15s;
    line-height: 1;
}

#attach-btn:hover {
    color: var(--text);
}

#attach-btn.has-files {
    background: var(--active-cat-color, var(--accent, #F06D13));
    color: #fff;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    min-width: 28px;
    min-height: 28px;
    padding: 0;
}

#attach-btn.has-files:hover {
    background: var(--active-cat-color, var(--accent-dark, #c95a0e));
    color: #fff;
    filter: brightness(0.9);
}

/* Barre d'outils prompt (anciennement flottante, désormais masquée) */
.prompt-toolbar {
    display: none !important;
}

.prompt-toolbar.visible {
    display: none !important;
}

.prompt-toolbar-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: transparent;
    border: 1px solid var(--border-light, rgba(0,0,0,0.1));
    cursor: pointer;
    padding: 4px 10px;
    font-size: 0.7rem;
    font-family: inherit;
    font-weight: 500;
    color: var(--text-secondary);
    border-radius: 16px;
    transition: all 0.15s ease;
    white-space: nowrap;
    box-shadow: none;
}

.prompt-toolbar-btn svg {
    stroke: currentColor;
    flex-shrink: 0;
    opacity: 0.6;
}

.prompt-toolbar-btn:hover {
    color: var(--active-cat-color, var(--accent));
    border-color: var(--active-cat-color, var(--accent));
    background: var(--bg-hover, rgba(0,0,0,0.03));
    transform: none;
    box-shadow: none;
}

.prompt-toolbar-btn:hover svg {
    opacity: 1;
}

.prompt-toolbar-btn:active {
    transform: none;
    box-shadow: none;
}

.prompt-toolbar-btn.revert {
    background: transparent;
    border-color: var(--border-light, rgba(0,0,0,0.1));
    color: var(--text-secondary);
    box-shadow: none;
}

.prompt-toolbar-btn.revert svg {
    stroke: currentColor;
}

.prompt-toolbar-btn.revert:hover {
    color: var(--text);
    border-color: var(--text-secondary);
    background: var(--bg-hover, rgba(0,0,0,0.03));
    box-shadow: none;
}

.prompt-toolbar-btn svg.spin {
    animation: spin 1s linear infinite;
}

/* Masquer le texte des boutons toolbar quand l'espace manque */
@container (max-width: 360px) {
    .prompt-toolbar-btn:not(.floating) .btn-label {
        display: none;
    }
    .prompt-toolbar-btn:not(.floating) {
        padding: 4px 6px;
        gap: 0;
    }
}

/* Dropdown prompt picker */
.prompt-picker-dropdown-wrapper {
    position: absolute;
    bottom: calc(100% + 6px);
    left: 0;
    right: 0;
    background: var(--bg-input);
    border: 1px solid var(--border-input);
    border-radius: 10px;
    max-height: 220px;
    overflow: hidden;
    box-shadow: 0 -4px 16px rgba(0,0,0,0.12);
    z-index: 100;
}
.prompt-picker-dropdown {
    max-height: 220px;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: none;
}

.prompt-picker-item {
    padding: 8px 14px;
    font-size: 0.85rem;
    cursor: pointer;
    color: var(--text);
    transition: background 0.1s;
    border-bottom: 1px solid var(--border-light);
}

.prompt-picker-item:last-child {
    border-bottom: none;
}

.prompt-picker-item:hover {
    background: var(--bg-hover);
}

.prompt-picker-item-name {
    font-weight: 500;
}

.prompt-picker-item-preview {
    font-size: 0.75rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}

.prompt-picker-empty {
    padding: 12px 14px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-align: center;
}

/* Bouton sauvegarder prompt (sous message user) */
.message-save-prompt-btn,
.message-edit-btn {
    background: none;
    border: none;
    padding: 4px 6px;
    cursor: pointer;
    color: var(--text-secondary);
    line-height: 1;
    transition: color 0.15s;
}

.message-save-prompt-btn:hover,
.message-edit-btn:hover {
    color: var(--text);
}

/* Mode édition d'un message */
.message-edit-textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1.5px solid var(--border-input);
    border-radius: 10px;
    background: var(--bg-input);
    color: var(--text);
    font-family: inherit;
    font-size: 0.9rem;
    line-height: 1.5;
    resize: both;
    outline: none;
    transition: border-color 0.15s;
    box-sizing: border-box;
}

.message-edit-textarea:focus {
    border-color: var(--accent);
}

.message-edit-actions {
    display: flex;
    gap: 6px;
    align-items: center;
    margin-top: 4px;
}

.message-edit-confirm,
.message-edit-cancel {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: 14px;
    font-size: 0.72rem;
    font-family: inherit;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid var(--border-light, rgba(0,0,0,0.1));
    transition: all 0.15s;
}

.message-edit-confirm {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.message-edit-confirm:hover {
    background: var(--accent-dark);
}

.message-edit-cancel {
    background: transparent;
    color: var(--text-secondary);
}

.message-edit-cancel:hover {
    color: var(--text);
    border-color: var(--text-secondary);
}

.prompt-input {
    flex: 1;
    min-width: 0;
    border: none;
    outline: none;
    font-size: 0.95rem;
    font-family: inherit;
    resize: none;
    max-height: 200px;
    line-height: 1.5;
    padding: 4px 0;
    background: transparent;
    align-self: center;
    color: var(--text);
}

.send-btn {
    background: var(--btn-bg);
    color: var(--btn-text);
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    min-width: 36px;
    min-height: 36px;
    padding: 0;
    cursor: pointer;
    transition: opacity 0.15s, transform 0.15s, background 0.15s;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.send-btn:disabled {
    opacity: 0.25;
    cursor: not-allowed;
}

.send-btn:not(:disabled):hover {
    opacity: 0.85;
    transform: scale(1.05);
}

/* Groupe de boutons export */
.export-btns-group {
    position: absolute;
    bottom: 100%;
    left: 32px;
    z-index: 1;
    display: flex;
    flex-direction: row;
    gap: 6px;
    pointer-events: none;
}

.export-action-btn {
    pointer-events: auto;
    flex-shrink: 0;
    background: var(--bg-sidebar);
    border: 1px solid var(--border-input);
    border-radius: 8px;
    padding: 6px 8px;
    cursor: pointer;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.15s, background 0.15s;
    opacity: 0.9;
}

.export-action-btn:hover {
    color: var(--text);
    background: var(--bg-hover);
    opacity: 1;
}

/* Share menu dropdown */
.share-btn-wrapper {
    pointer-events: auto;
}
.share-menu {
    display: none;
    position: absolute;
    bottom: calc(100% + 4px);
    left: 0;
    background: var(--bg-input);
    border: 1px solid var(--border-input);
    border-radius: 6px;
    box-shadow: 0 3px 12px rgba(0,0,0,0.12);
    z-index: 10000;
    white-space: nowrap;
}
.share-menu.open {
    display: block;
}
.share-menu-item {
    padding: 6px 14px;
    font-size: 0.78rem;
    color: var(--text);
    cursor: pointer;
    text-align: left;
    transition: background 0.12s;
}
.share-menu-item:first-child {
    border-radius: 6px 6px 0 0;
}
.share-menu-item:last-child {
    border-radius: 0 0 6px 6px;
}
.share-menu-item:hover {
    background: var(--bg-hover);
    color: var(--text);
}

.chat-container::-webkit-scrollbar {
    width: 4px;
}

/* --- System Prompts sidebar --- */
.sp-section {
    margin-top: 16px;
    border-top: 1px solid var(--border);
    padding-top: 12px;
}

.sp-header {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-bottom: 4px;
    cursor: pointer;
}

.sp-header .sp-add-btn:first-of-type {
    margin-left: auto;
}

.sp-toggle {
    font-size: 1rem;
    color: var(--text-secondary);
    display: inline-block;
    transition: transform 0.2s;
    user-select: none;
    width: 14px;
    text-align: center;
    line-height: 1;
}

.sp-collapsible {
    overflow: hidden;
    transition: max-height 0.25s ease, opacity 0.2s ease;
    max-height: 2000px;
    opacity: 1;
}

.sp-collapsible.collapsed {
    max-height: 0;
    opacity: 0;
}

.sp-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--sp-title-color);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.sp-add-btn {
    background: none;
    border: 1px solid var(--scrollbar-thumb);
    border-radius: 4px;
    width: 24px;
    height: 24px;
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
    color: var(--sp-title-color);
    display: flex;
    align-items: center;
    justify-content: center;
}

.sp-add-btn:hover {
    background: var(--bg-hover);
    color: var(--text);
}

.sp-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sp-item {
    display: flex;
    align-items: center;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 0.82rem;
    cursor: default;
    color: var(--text);
}

.sp-item:hover {
    background: var(--bg-hover);
}

.sp-item-name {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sp-item-actions {
    display: flex;
    gap: 2px;
    flex-shrink: 0;
    visibility: hidden;
}

.sp-item:hover .sp-item-actions {
    visibility: visible;
}

.sp-item-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.85rem;
    padding: 2px 5px;
    border-radius: 4px;
    color: var(--text-secondary);
    line-height: 1;
}

.sp-item-btn:hover {
    color: var(--text);
    background: var(--bg-hover);
}

.sp-item-btn.delete:hover {
    color: var(--danger);
    background: var(--danger-light);
}

/* --- Modale System Prompt --- */
.sp-modal-overlay,
.budget-alert-overlay,
.custom-dialog-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.35);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    /* Évite les flashs de la couche backdrop-blur quand un enfant animé
       (scale + opacity de la modale) force le compositeur à re-snapshoter
       la zone floutée. `isolation: isolate` la met dans son propre groupe
       de compositing, et `will-change: backdrop-filter` indique au moteur
       de la maintenir sur une couche GPU stable. */
    isolation: isolate;
    will-change: backdrop-filter;
}

.budget-alert-overlay { z-index: 9999; animation: budgetFadeIn 0.2s ease; }
.custom-dialog-overlay { z-index: 10000; }

.sp-modal {
    background: var(--bg-input);
    border: 1px solid var(--border-input);
    border-radius: 16px;
    padding: 28px;
    width: 480px;
    max-width: 90vw;
    max-height: 80vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 14px;
    box-shadow:
        0 4px 12px rgba(0,0,0,0.08),
        0 16px 40px rgba(0,0,0,0.16),
        0 0 0 1px rgba(0,0,0,0.04);
    color: var(--text);
    animation: sp-modal-appear 0.2s ease-out;
}

@keyframes sp-modal-appear {
    from { opacity: 0; transform: scale(0.96) translateY(8px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.sp-modal h3 {
    font-size: 1.15rem;
    font-weight: 600;
    margin: 0;
    letter-spacing: -0.01em;
}

.sp-modal-label {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--sp-title-color);
}

.sp-modal-input {
    font-family: inherit;
    font-size: 0.9rem;
    padding: 10px 14px;
    border: 1px solid var(--border-input);
    border-radius: 10px;
    outline: none;
    background: var(--bg);
    color: var(--text);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.sp-modal-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-light);
}

.sp-modal-textarea {
    font-family: inherit;
    font-size: 0.9rem;
    padding: 10px 14px;
    border: 1px solid var(--border-input);
    border-radius: 10px;
    outline: none;
    resize: vertical;
    min-height: 120px;
    width: 100%;
    background: var(--bg);
    color: var(--text);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.sp-modal-textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-light);
}

.sp-modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 4px;
}

.sp-modal-btn {
    font-family: inherit;
    font-size: 0.85rem;
    padding: 9px 20px;
    border-radius: 10px;
    cursor: pointer;
    border: none;
    transition: background 0.15s, color 0.15s, transform 0.15s, box-shadow 0.15s;
}

.sp-modal-btn:hover {
    transform: translateY(-1px);
}

.sp-modal-btn:active {
    transform: translateY(0);
}

.sp-modal-btn-cancel {
    background: var(--bg-sidebar);
    color: var(--sp-title-color);
    border: 1px solid var(--border-input);
}

.sp-modal-btn-cancel:hover {
    color: var(--accent);
    border-color: var(--accent);
    background: var(--accent-light);
}

.sp-modal-btn-save {
    background: var(--btn-bg);
    color: var(--btn-text);
}

.sp-modal-btn-save:hover {
    opacity: 0.9;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}


.sp-modal-btn-enhance {
    background: none;
    border: 1px solid var(--accent);
    color: var(--accent);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: background 0.15s, color 0.15s;
}

.sp-modal-btn-enhance:hover {
    background: var(--accent);
    color: #fff;
}

.sp-modal-btn-enhance:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.sp-modal-spacer {
    flex: 1;
}

.sp-modal-textarea-wrap {
    position: relative;
    width: 100%;
    border: 1px solid var(--border-input);
    border-radius: 10px;
    background: var(--bg);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.sp-modal-textarea-wrap:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-light);
}

.sp-modal-textarea-wrap .sp-modal-textarea {
    width: 100%;
    border: none;
    border-radius: 10px 10px 0 0;
    padding-bottom: 4px;
    background: transparent;
    resize: none;
    overflow-y: auto;
    max-height: 45vh;
}

.sp-modal-textarea-wrap .sp-modal-textarea:focus {
    border-color: transparent;
    box-shadow: none;
}

.sp-modal-enhance-inside {
    display: flex;
    align-items: center;
    gap: 4px;
    margin: 0 6px 6px auto;
    width: fit-content;
    font-family: inherit;
    font-size: 0.72rem;
    padding: 5px 12px;
    border-radius: 8px;
    border: none;
    background: transparent;
    color: var(--accent);
    cursor: pointer;
    transition: background 0.15s, color 0.15s, transform 0.15s;
    opacity: 0.7;
}

.sp-modal-enhance-inside:hover {
    background: var(--accent-light);
    opacity: 1;
    transform: translateY(-1px);
}

.sp-modal-enhance-inside:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

/* --- Champs clés API (modale Config) --- */
.apikey-label-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: -8px;
}

.apikey-label-row .sp-modal-label {
    margin: 0;
}

.apikey-label-row .apikey-get-link {
    margin-left: auto;
}

.apikey-field {
    display: flex;
    align-items: center;
    gap: 6px;
}

.apikey-input-wrap {
    position: relative;
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: stretch;
}

.apikey-input {
    flex: 1;
    min-width: 0;
    width: 100%;
    padding-right: 44px;
}

.apikey-intro {
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.5;
    margin: 0 0 20px 0;
}

.apikeys-panel > h3 + .apikey-intro {
    background: var(--bg-sidebar);
    margin: 0;
    padding: 4px 56px 14px 24px;
    border-bottom: 1px solid var(--border-input);
    font-size: 0.76rem;
    line-height: 1.3;
    flex-shrink: 0;
}

.apikey-get-link {
    font-family: inherit;
    font-size: 0.75rem;
    color: var(--accent);
    text-decoration: none;
    white-space: nowrap;
    transition: color 0.15s;
}

.apikey-get-link:hover {
    color: var(--accent-dark);
    text-decoration: underline;
}

.apikey-eye-btn {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    border-radius: 6px;
    cursor: pointer;
    transition: color 0.15s, background 0.15s;
}

.apikey-eye-btn:hover {
    color: var(--text);
    background: var(--bg-hover);
}

.apikey-eye-btn .apikey-eye-hide { display: none; }
.apikey-eye-btn.shown .apikey-eye-show { display: none; }
.apikey-eye-btn.shown .apikey-eye-hide { display: block; }

.apikey-separator {
    border: none;
    border-top: 1px solid var(--border);
    margin: 14px 0 10px;
}

.apikey-local-hint {
    font-weight: 400;
    font-size: 0.8rem;
    color: var(--text-secondary);
    display: inline-block;
    margin-bottom: 0;
}

.apikey-local-update-btn {
    flex-shrink: 0;
    font-family: inherit;
    font-size: 0.78rem;
    font-weight: 500;
    padding: 10px 14px;
    border-radius: 10px;
    border: 1px solid var(--accent);
    background: var(--accent);
    color: #fff;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    align-self: stretch;
}

.apikey-local-update-btn:hover {
    background: var(--accent-dark);
    border-color: var(--accent-dark);
    color: #fff;
}

.apikey-local-status {
    font-size: 0.75rem;
    margin: 0;
}

/* Quand le status est vide, on le retire complètement du flow pour ne pas ajouter
   d'espace entre le champ URL et la liste de modèles. */
.apikey-local-status:empty {
    display: none;
}

.apikey-local-status.success { color: #22c55e; }
.apikey-local-status.error   { color: #ef4444; }
.apikey-local-status.warning { color: #f59e0b; }
.apikey-local-status.warning .apikey-local-status-msg { display: block; margin-bottom: 6px; }
.apikey-local-status.warning .apikey-local-status-success-line { color: #22c55e; }
.apikey-local-help-img {
    display: block;
    max-width: 100%;
    max-height: 220px;
    margin-top: 4px;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    cursor: zoom-in;
    transition: transform 0.15s;
}
.apikey-local-help-img.apikey-local-help-img-small {
    max-width: 160px;
    max-height: 110px;
}
.apikey-local-help-img:hover { transform: scale(1.02); }
.apikey-local-help-img-caption {
    margin: 8px 0 4px;
    font-size: 0.78rem;
    color: #6b7280;
}
.apikey-local-help.apikey-local-help-flat {
    background: transparent;
    border: none;
    padding: 0;
    color: #6b7280;
}
.apikey-local-help.apikey-local-help-flat > .apikey-local-help-body {
    margin-top: 0;
}
.apikey-local-help.apikey-local-help-flat .apikey-local-help-body strong {
    color: #6b7280;
}
.apikey-local-help.apikey-local-help-flat .apikey-local-help-body code {
    background: #f3f4f6;
    border-color: #e5e7eb;
    color: #6b7280;
}

.apikey-local-status .apikey-local-status-msg {
    display: block;
    font-weight: 500;
}

.apikey-local-help {
    margin-top: 8px;
    padding: 10px 12px;
    background: var(--bg-hover);
    border: 1px solid var(--border-input);
    border-radius: 8px;
    color: var(--text);
    font-size: 0.78rem;
    font-weight: 400;
    line-height: 1.5;
}

.apikey-local-help > summary {
    cursor: pointer;
    color: var(--text-secondary);
    font-weight: 500;
    list-style: none;
    user-select: none;
}

.apikey-local-help > summary::-webkit-details-marker {
    display: none;
}

.apikey-local-help > summary::before {
    content: '▸ ';
    display: inline-block;
    transition: transform 0.15s;
}

.apikey-local-help[open] > summary::before {
    content: '▾ ';
}

.apikey-local-help-body {
    margin-top: 8px;
}

.apikey-local-help-body p {
    margin: 6px 0;
}

.apikey-local-help-body ol,
.apikey-local-help-body ul {
    margin: 6px 0 6px 20px;
    padding: 0;
}

.apikey-local-help-body ul {
    list-style: disc;
}

.apikey-local-help-body li {
    margin: 4px 0;
}

.apikey-local-help-body code {
    background: var(--bg-input);
    border: 1px solid var(--border-input);
    border-radius: 4px;
    padding: 1px 5px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.92em;
    color: var(--text);
    white-space: nowrap;
}

.apikey-local-help-body strong {
    color: var(--text);
}

/* Barre de sauvegarde — n'apparaît que lorsqu'une modification est en attente
   (ou pendant le flash de confirmation), à l'image de .storage-action-bar.
   Animation d'entrée et de sortie via transition + @starting-style. */
.models-save-row {
    flex-shrink: 0;
    /* `margin-top: auto` la pousse en bas du panneau (qui est un flex column,
       cf. .apikeys-panel) même quand le contenu au-dessus est court — sinon
       sticky `bottom: 12px` ne contraindrait que le scroll, pas la position
       initiale, et la barre flotterait juste sous le contenu. */
    margin-top: auto;
    display: none;
    justify-content: flex-end;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: var(--bg);
    border: 1px solid var(--border-input);
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
    position: sticky;
    bottom: 12px;
    z-index: 9;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.2s ease, transform 0.2s ease, display 0.2s allow-discrete;
}
.models-save-row:has(.models-save-btn--dirty),
.models-save-row:has(.models-save-btn--saved),
.models-save-row:has(.models-save-btn--saved-exit) {
    display: flex;
    opacity: 1;
    transform: translateY(0);
    @starting-style {
        opacity: 0;
        transform: translateY(8px);
    }
}

.models-cancel-btn {
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 600;
    padding: 9px 14px;
    border-radius: 10px;
    border: 1px solid var(--border-input);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 0.18s, color 0.18s, border-color 0.18s;
}
.models-cancel-btn:hover {
    background: var(--bg-hover);
    color: var(--text);
}

.models-save-btn {
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 600;
    padding: 9px 14px;
    border-radius: 10px;
    border: 1px solid var(--border, rgba(128,128,128,0.3));
    background: transparent;
    color: var(--text-muted, #888);
    cursor: not-allowed;
    transition: all 0.18s;
    opacity: 0.5;
    /* Largeur figée — couvre à la fois « Sauvegarder » et « Sauvegardé ✓ »
       (le second est plus large à cause de l'icône + gap) pour éviter
       tout reflow lors du flash de confirmation. */
    min-width: 140px;
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.models-save-btn--dirty {
    border-color: var(--accent);
    background: var(--accent);
    color: #fff;
    cursor: pointer;
    opacity: 1;
}

.models-save-btn--dirty:hover {
    background: var(--accent-dark, var(--accent));
    border-color: var(--accent-dark, var(--accent));
}

/* État « Sauvegardé » — affiché brièvement après un clic réussi.
   Le bouton est désactivé (clean), mais on lui redonne l'apparence verte
   pleine pour signaler le succès, indépendamment de --dirty. */
.models-save-btn--saved,
.models-save-btn--saved-exit {
    color: #fff !important;
    opacity: 1 !important;
    cursor: default;
    transition: background 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

.models-save-btn--saved {
    border-color: #22c55e !important;
    background: #22c55e !important;
    animation: models-save-saved-in 0.22s ease-out;
}

/* Phase de sortie : le fond revient à transparent en s'estompant en parallèle
   de la rétractation de l'icône. */
.models-save-btn--saved-exit {
    border-color: var(--border, rgba(128,128,128,0.3)) !important;
    background: transparent !important;
    color: var(--text-muted, #888) !important;
}

@keyframes models-save-saved-in {
    from { transform: scale(0.96); opacity: 0.7; }
    to   { transform: scale(1);    opacity: 1; }
}

.models-save-btn--saved .models-save-label {
    display: inline-block;
}

.models-save-check {
    display: inline-block;
    flex-shrink: 0;
    overflow: visible;
    stroke-dasharray: 24;
    stroke-dashoffset: 24;
    /* Valeurs cibles (état stable « saved ») — la transition gère le retour
       fluide quand on retire la classe via --saved-exit. */
    width: 14px;
    margin-left: 8px;
    opacity: 1;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Animation d'apparition (depuis width:0) — déclenchée par .models-save-btn--saved */
.models-save-btn--saved .models-save-check {
    animation:
        models-save-check-grow 0.3s cubic-bezier(0.4, 0, 0.2, 1) forwards,
        models-save-check-draw 0.4s cubic-bezier(0.4, 0, 0.2, 1) 0.18s forwards;
}

/* Phase de sortie : on repasse en width:0 / opacity:0 pour que le texte se
   recentre progressivement avant que l'innerHTML soit nettoyé. */
.models-save-btn--saved-exit .models-save-check {
    width: 0;
    margin-left: 0;
    opacity: 0;
    stroke-dashoffset: 0;
}

/* Le label « Sauvegarder » glisse de gauche à droite au moment où l'icône
   se masque. Il part de la position qu'occupait « Sauvegardé » et rejoint
   sa position naturelle centrée. */
.models-save-btn--saved-exit .models-save-label {
    animation: models-save-label-slide-right 0.3s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes models-save-label-slide-right {
    from { transform: translateX(-11px); }
    to   { transform: translateX(0); }
}

@keyframes models-save-check-grow {
    from {
        width: 0;
        margin-left: 0;
        opacity: 0;
    }
    to {
        width: 14px;
        margin-left: 8px;
        opacity: 1;
    }
}

@keyframes models-save-check-draw {
    to { stroke-dashoffset: 0; }
}

/* Modale à onglets (Configuration) */
.apikeys-modal {
    flex-direction: row !important;
    padding: 0 !important;
    width: 840px !important;
    height: 640px !important;
    gap: 0 !important;
    overflow: hidden !important;
}

.apikeys-close-btn {
    position: sticky;
    top: 10px;
    align-self: flex-end;
    margin: 10px 14px -46px auto;
    z-index: 30;
    background: var(--bg-sidebar);
    border: none;
    color: var(--text-secondary);
    font-size: 1.6rem;
    line-height: 1;
    cursor: pointer;
    padding: 4px 10px;
    border-radius: 8px;
    transition: color 0.15s, background 0.15s;
}

.apikeys-close-btn:hover {
    color: var(--text);
    background: var(--bg-hover);
}

.apikeys-tabs {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 20px 12px;
    border-right: 1px solid var(--border-input);
    width: 150px;
    flex-shrink: 0;
    background: var(--bg-sidebar);
    border-radius: 12px 0 0 12px;
}

.apikeys-tab {
    background: none;
    border: none;
    text-align: left;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.82rem;
    color: var(--text-secondary);
    font-family: inherit;
    transition: background 0.12s, color 0.12s;
}

.apikeys-tab:hover {
    background: var(--bg-hover);
    color: var(--text);
}

.apikeys-tab.active {
    background: var(--accent);
    color: #fff;
    font-weight: 600;
}

.apikeys-tab.active:hover {
    background: var(--accent);
    color: #fff;
}

.apikeys-tab-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 0;
    /* Le scroll est porté par .apikeys-panel-body : pas d'overflow ici, sinon
       la scrollbar court le long du titre (sticky), même si on ne peut pas
       scroller dans cette zone. */
    overflow: hidden;
    min-height: 0;
    min-width: 0;
}

.apikeys-panel {
    display: none;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    padding: 0;
}

.apikeys-panel.active {
    display: flex;
}

.apikeys-panel > h3 {
    flex-shrink: 0;
    background: var(--bg-sidebar);
    margin: 0;
    padding: 18px 56px 14px 24px;
    border-bottom: 1px solid var(--border-input);
}

/* Zone scrollable du panneau : reçoit la scrollbar SOUS le header. Tous les
   panneaux ont leur contenu enveloppé dans ce wrapper. */
.apikeys-panel-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 20px 24px 12px;
}

/* Lorsqu'un intro suit le titre, le titre n'a plus de bordure ni de marge basse :
   le bloc « titre + description » forme un seul header collant.
   Hauteur figée à 38px pour matcher exactement `top: 38px` de l'intro et éviter
   un vide entre les deux pendant le scroll. */
.apikeys-panel:has(.apikey-intro) > h3 {
    height: 38px;
    box-sizing: border-box;
    margin-bottom: 0;
    padding: 14px 56px 0 24px;
    border-bottom: none;
    line-height: 1.2;
}


/* Spacer pour séparer les onglets du bas */
.apikeys-tabs-spacer {
    flex: 1;
    min-height: 12px;
    margin: 4px 8px 4px 8px;
}

/* --- Sous-onglets fournisseurs (panel API et Modèles) --- */
.providers-tabs {
    display: flex;
    flex-wrap: nowrap;
    justify-content: space-between;
    align-items: center;
    gap: 2px;
    background: var(--bg-hover);
    border-radius: 10px;
    padding: 3px;
    margin-bottom: 14px;
    flex-shrink: 0;
}

.provider-tab {
    flex: 0 0 auto;
    display: inline-grid;
    grid-template-columns: auto 0fr;
    align-items: center;
    gap: 0;
    padding: 6px 8px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: grid-template-columns 0.28s cubic-bezier(0.4, 0, 0.2, 1),
                gap 0.28s cubic-bezier(0.4, 0, 0.2, 1),
                padding 0.28s cubic-bezier(0.4, 0, 0.2, 1),
                background 0.22s ease,
                color 0.22s ease,
                box-shadow 0.22s ease;
    overflow: hidden;
}

.provider-tab:hover {
    color: var(--text);
    background: var(--bg);
}

.provider-tab.active {
    grid-template-columns: auto 1fr;
    gap: 6px;
    padding: 6px 12px;
    background: var(--bg);
    color: var(--text);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.provider-tab-icon {
    width: 18px;
    height: 18px;
    display: block;
    flex-shrink: 0;
    object-fit: contain;
}

body.dark .provider-tab-icon {
    filter: invert(1) brightness(1.1);
}

.provider-tab-label {
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    opacity: 0;
    transform: translateX(-4px);
    transition: opacity 0.22s ease, transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

.provider-tab.active .provider-tab-label {
    opacity: 1;
    transform: translateX(0);
    transition: opacity 0.28s ease 0.08s, transform 0.28s cubic-bezier(0.4, 0, 0.2, 1) 0.04s;
}

/* Sections par fournisseur */
.provider-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.provider-section {
    display: none;
    flex-direction: column;
    gap: 14px;
}

/* Espace plus important entre le champ URL/clé et la liste de modèles, pour
   refléter visuellement la respiration entre les onglets de providers et le
   label « Clé API X » au-dessus. */
.provider-section > .provider-catalog-list {
    margin-top: 12px;
}

.provider-section.active {
    display: flex;
    animation: provider-section-fade 0.22s ease-out;
}

@keyframes provider-section-fade {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.provider-models-header {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    margin: 4px 0;
}

.provider-models-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
}

.provider-models-empty {
    font-size: 0.78rem;
    color: var(--text-secondary);
    padding: 14px 8px;
    text-align: center;
    border: 1px dashed var(--border);
    border-radius: 8px;
}

/* --- FAQ --- */
.faq-tabs {
    display: flex;
    background: var(--bg-hover);
    border-radius: 10px;
    padding: 3px;
    margin-bottom: 14px;
}

.faq-tab {
    flex: 1;
    padding: 6px 18px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
}

.faq-tab:hover {
    color: var(--text);
}

.faq-tab.active {
    background: var(--bg);
    color: var(--text);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.faq-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.faq-item {
    border: 1px solid var(--border-input);
    border-radius: 10px;
    overflow: hidden;
    background: var(--bg);
}

.faq-question {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 12px 14px;
    border: none;
    background: none;
    color: var(--text);
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 500;
    text-align: left;
    cursor: pointer;
    transition: background 0.15s;
}

.faq-question:hover {
    background: var(--bg-hover);
}

.faq-question-arrow {
    flex-shrink: 0;
    font-size: 0.7rem;
    color: var(--text-secondary);
    transition: transform 0.2s;
}

.faq-item.open .faq-question-arrow {
    transform: rotate(90deg);
}

.faq-answer {
    display: none;
    padding: 0 14px 14px;
    font-size: 0.82rem;
    line-height: 1.6;
    color: var(--text-secondary);
}

.faq-answer ul, .faq-answer ol {
    margin: 6px 0;
    padding-left: 20px;
}

.faq-answer li {
    margin-bottom: 3px;
}

.faq-answer a {
    color: var(--accent);
    text-decoration: none;
}

.faq-answer a:hover {
    text-decoration: underline;
}

.faq-answer code {
    background: rgba(0,0,0,0.06);
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 0.8rem;
}

body.dark .faq-answer code {
    background: rgba(255,255,255,0.08);
}

.faq-item.open .faq-answer {
    display: block;
}

/* --- Panel Partager --- */
.share-panel-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 12px;
    padding: 10px 0;
}

.share-panel-icon {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--accent-light);
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
}

.share-panel-text {
    font-size: 0.84rem;
    line-height: 1.6;
    color: var(--text-secondary);
    margin: 0;
    max-width: 400px;
}

.share-panel-link-box {
    display: flex;
    gap: 8px;
    width: 100%;
    max-width: 400px;
    margin-top: 4px;
}

.share-link-input {
    flex: 1;
    font-family: inherit;
    font-size: 0.82rem;
    padding: 8px 12px;
    border: 1px solid var(--border-input);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
    outline: none;
    min-width: 0;
}

.share-copy-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border: none;
    border-radius: 8px;
    background: var(--accent);
    color: #fff;
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: filter 0.15s;
}

.share-copy-btn:hover {
    filter: brightness(1.1);
}


.theme-toggle {
    display: flex;
    background: var(--bg-hover);
    border-radius: 10px;
    padding: 3px;
}

.theme-toggle-btn {
    flex: 1;
    padding: 6px 24px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

.theme-toggle-btn:hover {
    color: var(--text);
}

.theme-toggle-btn.active {
    background: var(--bg);
    color: var(--text);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

/* Sonde invisible pour détecter le thème système (fonctionne même en file://) */


.audio-setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 8px;
}

.audio-setting-label {
    font-size: 0.82rem;
    color: var(--text);
    white-space: nowrap;
    flex: 0 0 190px;
}

.audio-setting-select {
    flex: 1;
    min-width: 0;
    background: var(--bg-input);
    border: 1px solid var(--border-input);
    border-radius: 6px;
    color: var(--text);
    font-size: 0.8rem;
    /* padding-right élargi pour que la flèche native du <select> ne chevauche
       pas le libellé sélectionné quand celui-ci est long. */
    padding: 5px 26px 5px 8px;
    cursor: pointer;
    text-overflow: ellipsis;
}

.audio-setting-select:focus,
.budget-field:focus,
.storage-sort-select:focus {
    outline: none;
    border-color: var(--accent);
}

/* --- Panel Fonctionnalités : icône à gauche, sélecteurs uniformes -------- */
/* Les autres panneaux (Budget, Apparence, Stockage) partagent .audio-setting-row
   et conservent leur layout d'origine — on scope tout sous #panel-models. */
#panel-models .audio-setting-row {
    justify-content: flex-start;
}
#panel-models .audio-setting-label {
    flex: 1 1 auto;
    min-width: 0;
}
#panel-models .audio-setting-select {
    flex: 0 0 280px;
}
.audio-setting-icon {
    flex: 0 0 18px;
    width: 18px;
    height: 18px;
    color: var(--text-secondary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.audio-setting-icon svg {
    width: 18px;
    height: 18px;
}

.local-fallback-box {
    margin-top: 10px;
    padding: 10px 12px;
    border: none;
    border-radius: 8px;
    background: var(--bg-hover);
}

.local-fallback-box .audio-setting-row {
    margin-bottom: 0;
}

.models-error {
    margin-top: 8px;
    padding: 8px 10px;
    background: #fef2f2;
    border: 1px solid #fca5a5;
    border-radius: 6px;
    color: var(--danger-dark);
    font-size: 0.8rem;
    line-height: 1.4;
}

body.dark .models-error {
    background: #3b1111;
    border-color: #7f1d1d;
    color: #fca5a5;
}

/* --- Budget --- */
.budget-toggle {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 22px;
    cursor: pointer;
}

.budget-toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.budget-toggle-slider {
    position: absolute;
    inset: 0;
    background: var(--border-input);
    border-radius: 22px;
    transition: background 0.2s;
}

.budget-toggle-slider::before {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    left: 3px;
    bottom: 3px;
    background: white;
    border-radius: 50%;
    transition: transform 0.2s;
}

.budget-toggle input:checked + .budget-toggle-slider {
    background: var(--accent);
}

.budget-toggle input:checked + .budget-toggle-slider::before {
    transform: translateX(18px);
}

.budget-field {
    width: 120px;
    flex: 0 0 120px;
}

.budget-amount-wrapper {
    position: relative;
    display: inline-flex;
    align-items: center;
}

.budget-amount-prefix {
    position: absolute;
    left: 8px;
    font-size: 0.82rem;
    color: var(--text-secondary);
    pointer-events: none;
}

.budget-amount-wrapper .budget-field {
    padding-left: 18px;
}

.budget-amount-suffix {
    font-size: 0.82rem;
    color: var(--text-secondary);
    white-space: nowrap;
    margin-left: 4px;
}

.budget-help-note {
    margin-top: 14px;
    font-size: 0.78rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

.budget-preview-label {
    font-size: 0.78rem;
    color: var(--text-secondary);
    margin-bottom: 6px;
    font-weight: 500;
}

.budget-preview {
    margin-top: 12px;
}

.budget-progress-bar {
    width: 100%;
    height: 10px;
    background: var(--border-input);
    border-radius: 5px;
    overflow: hidden;
}

.budget-progress-fill {
    height: 100%;
    border-radius: 5px;
    transition: width 0.3s ease, background 0.3s ease;
    min-width: 0;
}

.budget-progress-text {
    margin-top: 6px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-align: center;
}


@keyframes budgetFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.no-model-alert-link {
    color: var(--accent, #3b82f6);
    text-decoration: underline;
    cursor: pointer;
}
.no-model-alert-link:hover {
    opacity: 0.85;
}

@keyframes configFieldHighlight {
    0% { background-color: rgba(255, 200, 0, 0.35); }
    100% { background-color: transparent; }
}
.config-field-highlight {
    animation: configFieldHighlight 2.2s ease-out;
    border-radius: 8px;
}

@keyframes budgetPopIn {
    from { opacity: 0; transform: scale(0.9) translateY(8px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.budget-alert-popup {
    background: var(--bg-input);
    border: 1px solid var(--border-input);
    border-radius: 16px;
    padding: 32px 36px 24px;
    max-width: 380px;
    width: 90%;
    text-align: center;
    box-shadow:
        0 4px 12px rgba(0,0,0,0.08),
        0 16px 40px rgba(0,0,0,0.16);
    animation: budgetPopIn 0.25s ease;
    color: var(--text);
}

body.dark .budget-alert-popup {
    box-shadow:
        0 4px 12px rgba(0,0,0,0.2),
        0 16px 40px rgba(0,0,0,0.4);
}

.budget-alert-icon {
    font-size: 2.4rem;
    margin-bottom: 12px;
}

.budget-alert-text {
    color: var(--text);
    font-size: 0.95rem;
    line-height: 1.5;
    margin-bottom: 20px;
}

.budget-alert-close {
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 10px;
    padding: 9px 24px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, transform 0.15s;
}

.budget-alert-close:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

/* --- Custom Dialog (alert / confirm) --- */

.custom-dialog {
    background: var(--bg-input);
    border: 1px solid var(--border-input);
    border-radius: 16px;
    padding: 32px 36px 24px;
    max-width: 420px;
    width: 90%;
    text-align: center;
    box-shadow:
        0 4px 12px rgba(0,0,0,0.08),
        0 16px 40px rgba(0,0,0,0.16);
    animation: sp-modal-appear 0.2s ease-out;
    color: var(--text);
}

.custom-dialog-icon {
    font-size: 2.2rem;
    margin-bottom: 12px;
    color: var(--text-secondary);
    line-height: 1;
    display: flex;
    justify-content: center;
}

.custom-dialog-icon svg {
    width: 36px;
    height: 36px;
}

.custom-dialog-message {
    font-size: 0.95rem;
    line-height: 1.6;
    margin-bottom: 24px;
    color: var(--text);
    white-space: pre-line;
    text-align: center;
}

.custom-dialog-checkbox {
    margin-bottom: 18px;
    text-align: center;
}
.custom-dialog-checkbox label {
    font-size: 0.82rem;
    color: var(--text-secondary);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.custom-dialog-checkbox input[type="checkbox"] {
    cursor: pointer;
}

.error-alert-header {
    text-align: center;
    margin-bottom: 12px;
}
.error-alert-body {
    text-align: left;
    margin-bottom: 12px;
    padding: 10px 14px;
    background: var(--bg-sidebar);
    border-radius: 10px;
}
.error-raw-details {
    margin-top: 4px;
    font-size: 0.82rem;
    text-align: center;
}
.error-raw-details summary {
    cursor: pointer;
    color: var(--placeholder);
    user-select: none;
    list-style: none;
}
.error-raw-details summary::-webkit-details-marker { display: none; }
.error-raw-pre {
    margin-top: 8px;
    padding: 10px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.78rem;
    line-height: 1.4;
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 200px;
    overflow-y: auto;
    text-align: left;
}

.custom-dialog-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.custom-dialog-btn {
    font-family: inherit;
    font-size: 0.85rem;
    padding: 9px 24px;
    border-radius: 10px;
    cursor: pointer;
    border: none;
    transition: background 0.15s, color 0.15s, transform 0.15s, box-shadow 0.15s;
}

.custom-dialog-btn:hover {
    transform: translateY(-1px);
}

.custom-dialog-btn:active {
    transform: translateY(0);
}

.custom-dialog-btn-cancel {
    background: var(--bg-sidebar);
    color: var(--sp-title-color);
    border: 1px solid var(--border-input);
}

.custom-dialog-btn-cancel:hover {
    color: var(--accent);
    border-color: var(--accent);
    background: var(--accent-light);
}

.custom-dialog-btn-ok {
    background: var(--btn-bg);
    color: var(--btn-text);
}

.custom-dialog-btn-ok:hover {
    opacity: 0.9;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.custom-dialog-btn-ok.danger {
    background: var(--danger);
    color: #fff;
}

.custom-dialog-btn-ok.danger:hover {
    background: var(--danger-dark);
}

/* --- Dashboard Statistiques (intégré dans config) --- */
.dashboard-tabs {
    display: flex;
    background: var(--bg-hover);
    border-radius: 10px;
    padding: 3px;
    margin-bottom: 14px;
}

.dashboard-tab {
    flex: 1;
    padding: 6px 18px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
}

.dashboard-tab:hover {
    color: var(--text);
}

.dashboard-tab.active {
    background: var(--bg);
    color: var(--text);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.dashboard-content {
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

.dashboard-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
}

.dashboard-table th,
.dashboard-table td {
    padding: 7px 10px;
    text-align: left;
    border-bottom: 1px solid var(--border-light);
}

.dashboard-table th {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    position: sticky;
    top: 0;
    background: var(--bg-input);
}

.dashboard-table td {
    color: var(--text);
}

.dashboard-table td.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.dashboard-table th.num {
    text-align: right;
}

.dashboard-table tbody tr:hover {
    background: var(--bg-hover);
}

.dashboard-empty {
    text-align: center;
    color: var(--text-secondary);
    padding: 32px 0;
    font-size: 0.85rem;
}

.dashboard-content::-webkit-scrollbar {
    width: 4px;
}

/* --- Chips fichiers joints (preview + messages) --- */
.attach-file-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    background: var(--bg-hover);
    border: 1px solid var(--border-input);
    border-radius: 8px;
    font-size: 0.8rem;
    color: var(--text);
    max-width: 200px;
}

.attach-file-chip-icon {
    flex-shrink: 0;
}

.attach-file-chip-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.attach-file-chip-remove {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.85rem;
    padding: 0 2px;
    flex-shrink: 0;
    line-height: 1;
    transition: color 0.15s;
}

.attach-file-chip-remove:hover {
    color: var(--danger);
}

.attach-file-chip-loading {
    opacity: 0.85;
    border-style: dashed;
}
.attach-file-chip-spinner {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--accent);
    margin-right: 4px;
}

.message-file-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    background: var(--bg-hover);
    border: 1px solid var(--border-input);
    border-radius: 6px;
    font-size: 0.8rem;
    color: var(--text);
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s;
    margin: 4px 4px 4px 0;
}

.message-file-chip:hover {
    background: var(--bg-active);
}

.message-file-chip {
    position: relative;
}

.message-file-chip-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.message-file-chip-dl {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 28px;
    display: none;
    align-items: center;
    justify-content: center;
    background: var(--bg-active);
    border: none;
    border-radius: 0 6px 6px 0;
    color: var(--text);
    cursor: pointer;
    transition: color 0.15s;
}

.message-file-chip:hover .message-file-chip-dl {
    display: flex;
}

.message-file-chip-dl:hover {
    color: var(--accent);
}

.message-files {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 8px;
}

/* --- Graphiques dashboard --- */
.dashboard-chart {
    padding: 16px 0;
}

.dashboard-chart-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-bottom: 10px;
}

.dashboard-bar-chart {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.dashboard-bar-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
}

.dashboard-bar-label {
    width: 120px;
    min-width: 120px;
    text-align: right;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dashboard-bar-track {
    flex: 1;
    height: 20px;
    background: var(--bg-hover);
    border-radius: 4px;
    overflow: hidden;
    position: relative;
}

.dashboard-bar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.3s ease;
    min-width: 2px;
}

.dashboard-bar-value {
    width: 70px;
    min-width: 70px;
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

.dashboard-charts-row {
    display: flex;
    gap: 24px;
}

.dashboard-charts-row .dashboard-chart {
    flex: 1;
    min-width: 0;
}

.dashboard-separator {
    border: none;
    border-top: 1px solid var(--border-light);
    margin: 8px 0;
}

/* --- Barre de catégories --- */
.cat-color-grid {
    display: grid;
    grid-template-columns: repeat(11, 1fr);
    gap: 8px;
    margin-top: 4px;
    justify-items: center;
}

.cat-color-swatch {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    position: relative;
    transition: transform 0.15s, border-color 0.15s;
    padding: 0;
    outline: none;
}

.cat-color-swatch:hover {
    transform: scale(1.15);
    border-color: var(--text-secondary);
}

.cat-color-swatch.selected {
    border-color: var(--text);
    box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--text);
}

.cat-color-swatch.selected::after {
    content: '\2713';
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: bold;
    color: #fff;
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}

/* Emoji Picker */
.emoji-picker-wrapper {
}

.cat-name-row-labels {
    display: flex;
    gap: 20px;
}

.cat-label-emoji {
    width: 44px;
    text-align: center;
    flex-shrink: 0;
}

.cat-name-row {
    display: flex;
    align-items: stretch;
    gap: 20px;
}

.cat-name-row .sp-modal-input {
    flex: 1;
    min-height: 44px;
}

.emoji-picker-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    flex-shrink: 0;
    border: 1px solid var(--border-input);
    border-radius: 8px;
    background: var(--bg-input);
    color: var(--text);
    font-size: 1.4rem;
    cursor: pointer;
    transition: border-color 0.15s;
}

.emoji-picker-btn:hover {
    border-color: var(--text-secondary);
}

.emoji-picker-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    border-radius: 12px;
    z-index: 199;
}

.emoji-picker {
    position: absolute;
    top: 10%;
    left: 10%;
    width: 80%;
    height: 80%;
    z-index: 200;
    background: var(--bg-input);
    border: 1px solid var(--border-input);
    border-radius: 12px;
    box-shadow: 0 12px 40px rgba(0,0,0,0.35);
    padding: 10px;
    display: flex;
    flex-direction: column;
}

.emoji-search {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid var(--border-input);
    border-radius: 6px;
    font-size: 0.82rem;
    background: var(--bg);
    color: var(--text);
    outline: none;
    margin-bottom: 6px;
}

.emoji-search:focus {
    border-color: var(--text-secondary);
}

.emoji-tabs {
    display: none;
    gap: 2px;
    margin-bottom: 6px;
    overflow-x: auto;
    flex-shrink: 0;
}

.emoji-tab {
    background: none;
    border: none;
    padding: 4px 6px;
    font-size: 1.1rem;
    cursor: pointer;
    border-radius: 6px;
    transition: background 0.1s;
    flex-shrink: 0;
    line-height: 1;
}

.emoji-tab:hover {
    background: var(--bg-hover);
}

.emoji-tab.active {
    background: var(--bg-active);
}

.emoji-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 2px;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

.emoji-grid-item {
    background: none;
    border: none;
    padding: 4px;
    font-size: 1.25rem;
    cursor: pointer;
    border-radius: 6px;
    transition: background 0.1s;
    line-height: 1.3;
    text-align: center;
}

.emoji-grid-item:hover {
    background: var(--bg-hover);
}

.emoji-cat-label {
    grid-column: 1 / -1;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-secondary);
    padding: 6px 4px 2px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.conv-item[draggable="true"] {
    cursor: pointer;
}

.conv-item.dragging {
    opacity: 0.4;
}


/* --- Bloc de raisonnement dépliable --- */
.thinking-block {
    margin-bottom: 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    font-size: 0.85rem;
    background: var(--bg-thinking);
}

.thinking-block summary {
    padding: 8px 12px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.78rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    background: transparent;
    user-select: none;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 6px;
}

.thinking-block summary::before {
    content: '\25B6';
    font-size: 0.6rem;
    transition: transform 0.2s;
}

.thinking-block[open] summary::before {
    transform: rotate(90deg);
}

.thinking-block summary::-webkit-details-marker {
    display: none;
}

.thinking-content {
    padding: 12px 14px 12px 20px;
    color: var(--text-secondary);
    font-size: 0.82rem;
    line-height: 1.5;
    max-height: 300px;
    overflow-y: auto;
    overflow-x: hidden;
    border-top: 1px solid var(--border);
    word-wrap: break-word;
    overflow-wrap: anywhere;
}

.thinking-content pre,
.thinking-content code {
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: anywhere;
    max-width: 100%;
}

.thinking-content table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
}

.thinking-content p {
    margin: 0 0 0.4em 0;
}

.thinking-content p:last-child {
    margin-bottom: 0;
}

.thinking-content ul,
.thinking-content ol {
    margin: 0.4em 0;
    padding-left: 1.4em;
}

.thinking-content li {
    margin: 0.15em 0;
}

.thinking-content h1,
.thinking-content h2,
.thinking-content h3,
.thinking-content h4,
.thinking-content h5,
.thinking-content h6 {
    margin: 0.6em 0 0.3em 0;
    line-height: 1.3;
    font-weight: 600;
    color: var(--text);
}

.thinking-content h1 { font-size: 1.05em; }
.thinking-content h2 { font-size: 1em; }
.thinking-content h3 { font-size: 0.95em; }
.thinking-content h4,
.thinking-content h5,
.thinking-content h6 { font-size: 0.9em; }

.thinking-content code {
    background: rgba(0,0,0,0.06);
    border-radius: 3px;
    padding: 1px 4px;
    font-size: 0.88em;
}

body.dark .thinking-content code {
    background: rgba(255,255,255,0.1);
}

.thinking-content pre {
    background: rgba(0,0,0,0.08);
    border-radius: 8px;
    padding: 10px;
    margin: 0.4em 0;
    font-size: 0.82em;
}

body.dark .thinking-content pre {
    background: rgba(255,255,255,0.08);
}

.thinking-content pre code {
    background: none;
    padding: 0;
    border-radius: 0;
    font-size: inherit;
}

.thinking-content blockquote {
    border-left: 3px solid var(--border-input);
    margin: 0.5em 0;
    padding: 0.2em 0 0.2em 12px;
    color: var(--text-secondary);
}

.thinking-content table {
    border-collapse: collapse;
    margin: 0.5em 0;
    font-size: 0.85em;
}

.thinking-content th,
.thinking-content td {
    border: 1px solid var(--border);
    padding: 3px 8px;
}

.thinking-content th {
    background: rgba(0,0,0,0.04);
}

body.dark .thinking-content th {
    background: rgba(255,255,255,0.06);
}

.thinking-content a {
    color: var(--link);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.thinking-content a:hover {
    color: var(--link-hover);
}

.thinking-content strong {
    font-weight: 600;
    color: var(--text);
}

.thinking-content hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 0.6em 0;
}

.thinking-content::-webkit-scrollbar {
    width: 4px;
}

/* --- Marqueur changement de modèle --- */
.model-switch-marker {
    text-align: center;
    font-size: 0.7rem;
    color: var(--text-secondary);
    opacity: 0.5;
    padding: 6px 0;
    user-select: none;
}

/* --- Bouton Stop (send-btn en mode streaming) --- */
.send-btn.stop-mode {
    background: var(--danger);
    color: #fff;
}

.send-btn.stop-mode:hover {
    opacity: 0.85;
}

/* --- Bouton copier sur les blocs de code --- */
.message-text pre {
    position: relative;
}

.code-copy-btn {
    position: absolute;
    top: 6px;
    right: 6px;
    background: rgba(0,0,0,0.45);
    color: #fff;
    border: none;
    border-radius: 4px;
    padding: 3px 8px;
    font-size: 0.72rem;
    font-family: inherit;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s;
    z-index: 1;
}

body.dark .code-copy-btn {
    background: rgba(255,255,255,0.2);
}

.message-text pre:hover .code-copy-btn {
    opacity: 1;
}

.code-copy-btn:hover {
    background: rgba(0,0,0,0.7);
}

body.dark .code-copy-btn:hover {
    background: rgba(255,255,255,0.35);
}

/* --- Lightbox images --- */
.lightbox-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.88);
    z-index: 9000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: lightbox-overlay-in 0.18s ease-out both;
}
.lightbox-overlay.closing {
    animation: lightbox-overlay-out 0.16s ease-in forwards;
}

.lightbox-img {
    max-width: 92vw;
    max-height: 92vh;
    border-radius: 8px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.5);
    object-fit: contain;
    animation: lightbox-img-in 0.22s cubic-bezier(0.2, 0.8, 0.3, 1.1) both;
}
.lightbox-overlay.closing .lightbox-img,
.lightbox-overlay.closing .file-viewer-container {
    animation: lightbox-img-out 0.16s ease-in forwards;
}
.file-viewer-container {
    animation: lightbox-img-in 0.22s cubic-bezier(0.2, 0.8, 0.3, 1.1) both;
}

@keyframes lightbox-overlay-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}
@keyframes lightbox-overlay-out {
    from { opacity: 1; }
    to   { opacity: 0; }
}
@keyframes lightbox-img-in {
    from { opacity: 0; transform: scale(0.92); }
    to   { opacity: 1; transform: scale(1); }
}
@keyframes lightbox-img-out {
    from { opacity: 1; transform: scale(1); }
    to   { opacity: 0; transform: scale(0.94); }
}

.lightbox-close {
    position: fixed;
    top: 16px;
    right: 20px;
    background: rgba(255,255,255,0.15);
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    font-size: 1.5rem;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9001;
    transition: background 0.15s;
}

.lightbox-close:hover {
    background: rgba(255,255,255,0.3);
}

.file-viewer-container {
    width: 90vw;
    height: 88vh;
    max-width: 1000px;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 8px 40px rgba(0,0,0,0.5);
}

.file-viewer-title {
    padding: 10px 16px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
    background: var(--bg-sidebar);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-viewer-iframe {
    flex: 1;
    border: none;
    width: 100%;
    background: #fff;
}

/* --- Sidebar : section conversations flex + boutons bas toujours visibles --- */
#conv-sp-section {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

#conv-sp-section > .sp-collapsible {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

#conv-sp-section > .sp-collapsible.collapsed {
    flex: 0;
    max-height: 0;
    overflow: hidden;
}

/* ============================================================================
 * Canvas — panneau artefact multi-fichiers + modal preview
 * ========================================================================= */

/* Bouton "ouvrir le canvas" dans la toolbar, à côté du toggle */
.canvas-open-btn .canvas-open-count {
    font-size: 0.7rem;
    font-weight: 600;
    margin-left: 2px;
    opacity: 0.8;
}

/* Panneau canvas — volet latéral droit, remplace le panneau de réglages */
.canvas-panel {
    --canvas-width: 480px;
    width: var(--canvas-width);
    min-width: 320px;
    max-width: 90vw;
    height: 100vh;
    background: var(--bg);
    color: var(--text);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-left: 1px solid var(--border);
    flex-shrink: 0;
    box-sizing: border-box;
    position: relative;
}

/* Poignée de redimensionnement sur le bord gauche */
.canvas-resize-handle {
    position: absolute;
    top: 0;
    left: -4px;
    width: 8px;
    height: 100%;
    cursor: col-resize;
    z-index: 20;
    background: transparent;
    transition: background 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Petit bouton visuel (grip) centré verticalement pour indiquer qu'on peut
   redimensionner le volet. Utilise ::before pour ne pas toucher au DOM. */
.canvas-resize-handle::before {
    content: '';
    display: block;
    width: 4px;
    height: 42px;
    border-radius: 3px;
    background: var(--border);
    box-shadow:
        inset 1px 0 0 rgba(255, 255, 255, 0.12),
        0 1px 3px rgba(0, 0, 0, 0.18);
    transition: background 0.15s, height 0.15s, width 0.15s;
    pointer-events: none;
}

.canvas-resize-handle:hover::before,
body.canvas-resizing .canvas-resize-handle::before {
    background: var(--accent);
    height: 56px;
    width: 5px;
}

.canvas-resize-handle:hover,
body.canvas-resizing .canvas-resize-handle {
    background: transparent;
}

/* Pendant le drag : on désactive la sélection de texte globalement */
body.canvas-resizing,
body.canvas-resizing * {
    user-select: none !important;
    cursor: col-resize !important;
}

/* Pendant le drag : l'iframe preview ne capte plus la souris */
body.canvas-resizing .canvas-preview-iframe {
    pointer-events: none;
}

/* Quand le canvas est ouvert, on masque le panneau de réglages (la toolbar
   latérale reste visible pour pouvoir basculer entre les deux volets). */
body.canvas-active .right-panel {
    display: none !important;
}

/* Onglets Code / Prévisualiser — style pill inspiré de .faq-tabs,
   placés dans le header à côté du titre */
.canvas-tabs {
    display: flex;
    background: var(--bg-hover);
    border-radius: 9px;
    padding: 3px;
    gap: 2px;
    flex-shrink: 0;
}

.canvas-tab {
    padding: 4px 12px;
    border: none;
    border-radius: 7px;
    background: transparent;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.76rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

.canvas-tab:hover {
    color: var(--text);
}

.canvas-tab.active {
    background: var(--bg);
    color: var(--text);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* Vues d'onglet */
.canvas-tab-view {
    display: none;
    flex: 1;
    min-height: 0;
    position: relative;
}

.canvas-tab-view.active {
    display: flex;
}

.canvas-preview-view {
    flex-direction: column;
    background: #fff;
}

.canvas-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: var(--bg-sidebar);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    min-width: 0;
}

.canvas-header-title {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 600;
    font-size: 0.88rem;
    color: var(--text);
    flex-shrink: 0;
}

.canvas-header-actions {
    display: flex;
    align-items: center;
    gap: 2px;
    margin-left: auto;
    flex-shrink: 0;
}

/* Sur des largeurs réduites, on masque le libellé "Canvas" — l'icône suffit */
@media (max-width: 560px) {
    .canvas-header-title span {
        display: none;
    }
}

.canvas-header-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    border-radius: 6px;
    padding: 5px 10px;
    font-size: 0.8rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.canvas-header-btn:hover:not(:disabled) {
    background: var(--bg-hover);
    color: var(--text);
}

.canvas-header-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.canvas-header-btn-danger:hover:not(:disabled) {
    color: var(--danger);
    border-color: var(--danger);
}

/* Corps : sidebar fichiers + viewer + empty state
   (display/flex sont gérés par .canvas-tab-view, pas redéfinis ici) */
.canvas-body {
    min-height: 0;
    position: relative;
}

.canvas-sidebar {
    width: 220px;
    min-width: 180px;
    border-right: 1px solid var(--border);
    background: var(--bg-sidebar);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.canvas-sidebar-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    padding: 10px 12px 6px;
}

.canvas-file-list {
    flex: 1;
    overflow-y: auto;
    padding: 0 6px 8px;
}

.canvas-file-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    font-size: 0.82rem;
    border-radius: 6px;
    cursor: pointer;
    color: var(--text);
    transition: background 0.1s;
    user-select: none;
}

.canvas-file-item:hover {
    background: var(--bg-hover);
}

.canvas-file-item.selected {
    background: var(--accent-light);
    color: var(--accent);
}

.canvas-file-item.entrypoint .canvas-file-name {
    font-weight: 600;
}

/* Fichier en cours de génération par l'IA : fond animé type "shimmer" pour
   signaler visuellement l'écriture en temps réel. */
.canvas-file-item.streaming .canvas-file-name {
    background-image: linear-gradient(
        90deg,
        rgba(59, 130, 246, 0.18) 0%,
        rgba(59, 130, 246, 0.55) 50%,
        rgba(59, 130, 246, 0.18) 100%
    );
    background-size: 200% 100%;
    background-repeat: no-repeat;
    background-position: 100% 0;
    animation: canvas-streaming-shimmer 1.4s linear infinite;
    border-radius: 4px;
    padding: 2px 6px;
    margin: -2px -6px;
    color: var(--text);
}

.canvas-file-item.streaming .canvas-file-size::after {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #3b82f6;
    margin-left: 6px;
    vertical-align: middle;
    animation: canvas-streaming-pulse 1s ease-in-out infinite;
}

@keyframes canvas-streaming-shimmer {
    from { background-position: 100% 0; }
    to   { background-position: -100% 0; }
}

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

/* Variante sombre : on renforce légèrement l'opacité pour contraster */
body.dark .canvas-file-item.streaming .canvas-file-name {
    background-image: linear-gradient(
        90deg,
        rgba(96, 165, 250, 0.22) 0%,
        rgba(96, 165, 250, 0.65) 50%,
        rgba(96, 165, 250, 0.22) 100%
    );
}

.canvas-file-icon {
    font-size: 0.95rem;
    flex-shrink: 0;
}

.canvas-file-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.canvas-file-size {
    font-size: 0.7rem;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.canvas-viewer {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
}

.canvas-viewer-title {
    padding: 6px 14px;
    font-size: 0.78rem;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border);
    background: var(--bg);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-height: 30px;
}

.canvas-viewer-title-name {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.canvas-diff-toggle {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
    font-size: 0.72rem;
    color: var(--text-secondary);
    flex-shrink: 0;
    user-select: none;
}

.canvas-diff-toggle:hover {
    color: var(--text);
}

.canvas-diff-toggle input[type="checkbox"] {
    cursor: pointer;
    margin: 0;
}

/* Lignes de diff dans le viewer */
.canvas-diff-line {
    display: block;
}

/* --- Badge inline "Modification/Création/Suppression de {fichier}" --- */
/* Émis par le parser canvas à la position exacte où l'IA modifie un fichier,
   affiché dans le flux du message IA comme une petite pastille. */
.canvas-inline-op {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    margin: 6px 0;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--bg-hover);
    font-size: 0.82em;
    line-height: 1.4;
    color: var(--text);
    vertical-align: middle;
    user-select: none;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, transform 0.08s;
}

.canvas-inline-op:hover {
    background: var(--accent-light, rgba(59, 130, 246, 0.1));
    border-color: var(--accent, #3b82f6);
}

.canvas-inline-op:active {
    transform: scale(0.97);
}

.canvas-inline-op-missing {
    opacity: 0.55;
    cursor: not-allowed;
}

.canvas-inline-op-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.canvas-inline-op-create .canvas-inline-op-icon { color: #16a34a; }
.canvas-inline-op-edit   .canvas-inline-op-icon { color: var(--accent, #3b82f6); }
.canvas-inline-op-delete .canvas-inline-op-icon { color: #dc2626; }

.canvas-inline-op-label {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 420px;
}

body.dark .canvas-inline-op {
    background: rgba(255, 255, 255, 0.04);
}

.canvas-diff-line.added {
    background: rgba(34, 197, 94, 0.18);
}

.canvas-diff-line.removed {
    background: rgba(239, 68, 68, 0.18);
    color: var(--text);
}

body.dark .canvas-diff-line.added {
    background: rgba(34, 197, 94, 0.22);
}

body.dark .canvas-diff-line.removed {
    background: rgba(239, 68, 68, 0.22);
}

.canvas-diff-marker {
    display: inline-block;
    width: 1em;
    text-align: center;
    user-select: none;
    opacity: 0.7;
    margin-right: 4px;
}

.canvas-diff-line.added .canvas-diff-marker {
    color: #16a34a;
}

.canvas-diff-line.removed .canvas-diff-marker {
    color: #dc2626;
}

.canvas-viewer-content {
    flex: 1;
    margin: 0;
    padding: 12px 14px;
    overflow: auto;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.8rem;
    line-height: 1.5;
    background: var(--bg);
    color: var(--text);
    white-space: pre;
    tab-size: 4;
}

.canvas-line-num {
    display: inline-block;
    width: 3em;
    margin-right: 12px;
    color: var(--text-secondary);
    opacity: 0.5;
    text-align: right;
    user-select: none;
}

.canvas-empty {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    color: var(--text-secondary);
    text-align: center;
    padding: 40px;
    pointer-events: none;
}

.canvas-empty p {
    margin: 0;
    font-size: 0.88rem;
    line-height: 1.6;
}

.canvas-empty em {
    color: var(--text);
    font-style: italic;
    opacity: 0.75;
}

/* Footer : status */
.canvas-footer {
    flex-shrink: 0;
    padding: 8px 14px;
    border-top: 1px solid var(--border);
    background: var(--bg-sidebar);
    font-size: 0.75rem;
    color: var(--text-secondary);
    min-height: 32px;
    display: flex;
    align-items: center;
}

.canvas-status.error {
    color: var(--danger);
}

/* Scrollbar fine pour le viewer et la liste */
.canvas-viewer-content::-webkit-scrollbar,
.canvas-file-list::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.canvas-viewer-content::-webkit-scrollbar-thumb,
.canvas-file-list::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 4px;
}

.canvas-viewer-content::-webkit-scrollbar-thumb:hover,
.canvas-file-list::-webkit-scrollbar-thumb:hover {
    background: var(--scrollbar-thumb-hover);
}

/* ---- Iframe de prévisualisation (dans l'onglet Prévisualiser) ---- */
.canvas-preview-iframe {
    flex: 1;
    width: 100%;
    height: 100%;
    border: none;
    background: #fff;
    display: block;
}

/* Responsive : sur petit écran, le canvas passe en overlay plein écran */
@media (max-width: 900px) {
    .canvas-panel {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
        width: 100vw !important;
        min-width: 0;
        max-width: none;
        height: 100vh;
        z-index: 9200;
        border-left: none;
    }
    .canvas-resize-handle {
        display: none;
    }
    #canvas-code-view {
        flex-direction: column;
    }
    .canvas-sidebar {
        width: 100%;
        min-width: 0;
        max-height: 35%;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
    .canvas-header-btn span {
        display: none;
    }
}

/* --- Catalogue de modèles --- */

.catalog-toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
    flex-shrink: 0;
}

.catalog-search-wrap {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
}

.catalog-search-icon {
    position: absolute;
    left: 10px;
    color: var(--text-secondary);
    pointer-events: none;
    flex-shrink: 0;
}

.catalog-search-input {
    width: 100%;
    padding: 8px 10px 8px 32px;
    border-radius: 8px;
    border: 1px solid var(--border-input);
    background: var(--bg-input);
    color: var(--text);
    font-family: inherit;
    font-size: 0.82rem;
    outline: none;
    transition: border-color 0.15s;
}

.catalog-search-input:focus {
    border-color: var(--accent);
}

.catalog-type-btns {
    display: inline-flex;
    flex-shrink: 0;
    box-sizing: border-box;
    height: var(--catalog-toggle-h);
    background: var(--bg-input);
    border: 1px solid var(--border-input);
    border-radius: 999px;
    padding: 3px;
    position: relative;
}

/* Pastille de surlignage glissante : positionnée derrière les boutons,
   elle se translate horizontalement selon le bouton actif (sélection via
   :has(), évite tout couplage JS). */
.catalog-type-btns::before {
    content: '';
    position: absolute;
    top: 3px;
    bottom: 3px;
    left: 3px;
    width: calc(50% - 3px);
    background: var(--accent);
    border-radius: 999px;
    transition: transform 0.25s cubic-bezier(0.2, 0.8, 0.3, 1);
    z-index: 0;
}
.catalog-type-btns:has(.catalog-type-btn.active[data-type="image"])::before {
    transform: translateX(100%);
}

.catalog-type-btn {
    flex: 1;
    padding: 4px 15px;
    border: none;
    border-radius: 999px;
    background: transparent;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.76rem;
    font-weight: 500;
    cursor: pointer;
    transition: color 0.2s ease;
    white-space: nowrap;
    position: relative;
    z-index: 1;
}

.catalog-type-btn:not(.active):hover {
    color: var(--text);
}

.catalog-type-btn.active,
.catalog-type-btn.active:hover {
    color: #fff;
}

.catalog-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Section provider */
.catalog-section {
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    flex-shrink: 0;
}

.catalog-section-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    /* Réserve la place du toggle même quand il est absent → toutes les sections
       ont la même hauteur. 16px = padding vertical (8px × 2). */
    min-height: calc(var(--catalog-toggle-h) + 16px);
    box-sizing: border-box;
    background: var(--bg-hover);
    border-bottom: 1px solid var(--border);
}

.catalog-section-name {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text);
    flex: 1;
}


.catalog-section-master-cb {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
    cursor: pointer;
    margin: 0;
}

.catalog-section-badge {
    font-size: 0.72rem;
    font-weight: 600;
    padding: 2px 7px;
    border-radius: 999px;
    background: var(--accent-light);
    color: var(--accent);
    flex-shrink: 0;
}

.catalog-or-load-btn {
    font-family: inherit;
    font-size: 0.72rem;
    font-weight: 500;
    padding: 3px 9px;
    border-radius: 6px;
    border: 1px solid var(--border-input);
    background: var(--bg-input);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s;
    flex-shrink: 0;
    white-space: nowrap;
}

.catalog-or-load-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.catalog-or-load-btn {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-color: var(--accent);
    color: var(--accent);
}

.catalog-or-load-btn:hover {
    background: var(--accent);
    color: #fff;
}

.catalog-or-load-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.catalog-section-models {
    padding: 4px 0;
}

/* Ligne modèle */
.catalog-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 6px 0 12px;
    transition: background 0.1s;
    user-select: none;
}

.catalog-row:hover {
    background: var(--bg-hover);
}

/* Zone cliquable principale (label) — toggle la checkbox */
.catalog-row-main {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 0;
    cursor: pointer;
}

.catalog-row input[type="checkbox"] {
    width: 15px;
    height: 15px;
    cursor: pointer;
    flex-shrink: 0;
    margin: 0;
}

.catalog-row-name {
    flex: 1;
    font-size: 0.82rem;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    gap: 6px;
}

.catalog-row-price {
    font-size: 0.72rem;
    color: var(--text-secondary);
    flex-shrink: 0;
    white-space: nowrap;
    width: 140px;
    text-align: right;
}

.catalog-row-maker {
    font-size: 0.72rem;
    color: var(--text-secondary);
    flex-shrink: 0;
    white-space: nowrap;
    width: 100px;
    padding-left: 10px;
    border-left: 1px solid var(--border-input);
}

/* Réservation d'espace pour l'icône info quand absente, pour conserver un alignement
   strict des colonnes (prix/fournisseur) sur toutes les lignes. */
.catalog-row-info-spacer {
    display: inline-block;
    width: 14px;
    min-width: 14px;
    height: 14px;
    flex-shrink: 0;
}

/* Badges NEW / expiration */
.catalog-row-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 16px;
    padding: 0 6px;
    border-radius: 8px;
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    line-height: 1;
    flex-shrink: 0;
}

.catalog-row-badge--new {
    background: transparent;
    color: var(--accent);
    border: 1px solid var(--accent-light, rgba(0, 0, 0, 0.12));
    font-weight: 600;
    font-size: 0.55rem;
    height: 14px;
    padding: 0 5px;
    opacity: 0.85;
}

.catalog-row-badge--warn {
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
    font-size: 0.7rem;
    padding: 0 5px;
}

/* Icône info ouvrant le tooltip enrichi (override de .custom-select-info) */
.catalog-row-info {
    margin-left: 0;
    cursor: help;
    opacity: 0.55;
}

.catalog-row:hover .catalog-row-info,
.catalog-row-info:hover {
    opacity: 1;
}

.catalog-row-info:hover {
    border-color: var(--accent);
    color: var(--accent);
}

/* Section OpenRouter */
.catalog-or-section {
    border-color: var(--border);
    border-style: solid;
}

.catalog-or-section .catalog-section-header {
    background: var(--bg-hover);
}

/* Wrapper du select de catégorie OR (avec caret personnalisé) */
.catalog-or-cat-select-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;
}

.catalog-or-cat-select-caret {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
    color: var(--text-secondary);
}

/* Champ de recherche OpenRouter */
.catalog-or-search-wrap {
    position: relative;
    display: flex;
    align-items: center;
    flex: 1;
    min-width: 0;
}

.catalog-or-search-wrap > svg {
    position: absolute;
    left: 10px;
    color: var(--text-secondary);
    pointer-events: none;
}

.catalog-or-search {
    flex: 1;
    width: 100%;
    border: 1px solid var(--border-input);
    background: var(--bg-input);
    color: var(--text);
    font-family: inherit;
    font-size: 0.78rem;
    padding: 6px 10px 6px 30px;
    border-radius: 6px;
    outline: none;
    transition: border-color 0.15s;
}

.catalog-or-search:focus {
    border-color: var(--accent);
}

/* Toolbar OR (catégorie + recherche + bouton charger) */
.catalog-or-toolbar {
    display: flex;
    align-items: stretch;
    gap: 8px;
    padding: 8px 12px;
    background: var(--bg-hover);
    border-bottom: 1px solid var(--border);
    --or-ctl-h: 32px;
    --or-ctl-radius: 6px;
}

.catalog-or-toolbar > .catalog-or-cat-select-wrap,
.catalog-or-toolbar > .catalog-or-search-wrap {
    height: var(--or-ctl-h);
}

.catalog-or-toolbar .catalog-or-cat-select,
.catalog-or-toolbar .catalog-or-search {
    height: 100%;
    box-sizing: border-box;
    border: 1px solid var(--border-input);
    border-radius: var(--or-ctl-radius);
    background: var(--bg-input);
}

.catalog-or-toolbar .catalog-or-load-btn {
    flex-shrink: 0;
    width: var(--or-ctl-h);
    min-width: var(--or-ctl-h);
    height: var(--or-ctl-h);
    box-sizing: border-box;
    padding: 0;
    margin: 0;
    gap: 0;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    background: var(--bg-input);
    border: 1px solid var(--border-input);
    border-radius: var(--or-ctl-radius);
}

.catalog-or-toolbar .catalog-or-load-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--bg-input);
}

/* Sélecteur de catégorie OR */
.catalog-or-cat-select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    border: 1px solid var(--border-input);
    background: var(--bg-input);
    color: var(--text);
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 400;
    padding: 5px 28px 5px 12px;
    border-radius: 6px;
    cursor: pointer;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.catalog-or-cat-select:hover {
    border-color: var(--accent);
}

.catalog-or-cat-select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-light, rgba(0,0,0,0.08));
}

/* Tri du catalogue (par fournisseur) — réutilise le look du select OR. */
.catalog-sort-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;
}
.catalog-sort-caret {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
    color: var(--text-secondary);
}
.catalog-sort-select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    border: 1px solid var(--border-input);
    background: var(--bg-input);
    color: var(--text);
    font-family: inherit;
    font-size: 0.78rem;
    font-weight: 400;
    padding: 5px 26px 5px 10px;
    border-radius: 6px;
    cursor: pointer;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.catalog-sort-select:hover {
    border-color: var(--accent);
}
.catalog-sort-select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-light, rgba(0,0,0,0.08));
}
/* Dans la toolbar OR, on aligne la hauteur sur les autres contrôles. */
.catalog-or-toolbar > .catalog-sort-wrap {
    height: var(--or-ctl-h);
}
.catalog-or-toolbar .catalog-sort-select {
    height: 100%;
    box-sizing: border-box;
}

.catalog-or-empty {
    padding: 14px 12px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-align: center;
    line-height: 1.5;
}

.catalog-or-loading {
    padding: 14px 12px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.catalog-or-hint {
    border: 1px dashed var(--border-input);
    border-radius: 10px;
    padding: 14px 16px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    display: flex;
    align-items: flex-start;
    gap: 8px;
    line-height: 1.5;
}

.catalog-or-hint svg {
    flex-shrink: 0;
    margin-top: 1px;
}

.catalog-or-hint strong {
    color: var(--text);
}

/* Animation rotation (chargement) */
@keyframes catalog-spin {
    to { transform: rotate(360deg); }
}

.catalog-spin {
    animation: catalog-spin 0.8s linear infinite;
    display: inline-block;
}

/* --- Toast mise à jour --- */
.update-toast {
    position: fixed;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    display: flex;
    align-items: center;
    gap: 0;
    border-radius: 999px;
    background: var(--accent);
    box-shadow: 0 6px 28px rgba(240, 109, 19, 0.45);
    font-size: 0.84rem;
    font-weight: 500;
    color: #fff;
    white-space: nowrap;
    animation: update-toast-in 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes update-toast-in {
    from { opacity: 0; transform: translateX(-50%) translateY(-16px) scale(0.95); }
    to   { opacity: 1; transform: translateX(-50%) translateY(0)      scale(1); }
}

.update-toast-link {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px 10px 16px;
    color: #fff;
    text-decoration: none;
    border-radius: 999px 0 0 999px;
    transition: background 0.15s;
}

.update-toast-link:hover {
    background: rgba(0,0,0,0.12);
}

.update-toast-icon {
    flex-shrink: 0;
    opacity: 0.9;
}

.update-toast-text {
    line-height: 1;
}

.update-toast-close {
    flex-shrink: 0;
    background: none;
    border: none;
    border-left: 1px solid rgba(255,255,255,0.3);
    color: rgba(255,255,255,0.8);
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
    padding: 10px 14px;
    border-radius: 0 999px 999px 0;
    transition: background 0.15s, color 0.15s;
}

.update-toast-close:hover {
    background: rgba(0,0,0,0.12);
    color: #fff;
}

/* ===== Panel Stockage ===== */
#panel-stockage { position: relative; padding-bottom: 16px; }
/* Bloque le scroll du parent : seul le contenu interne (la liste) scrolle */
#panel-stockage.active {
    overflow: hidden;
    min-height: 0;
    max-height: 80vh;
}
#panel-stockage[data-storage-view="list"] .storage-list-view {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
}
#panel-stockage[data-storage-view="list"] .storage-list {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
}

/* Bascule entre vue accueil et vue liste */
#panel-stockage .storage-home { display: none; }
#panel-stockage .storage-list-view { display: none; }
#panel-stockage[data-storage-view="home"] .storage-home { display: block; }

/* Vue d'accueil */
.storage-home-description {
    margin: 18px 2px 16px;
    font-size: 0.88rem;
    line-height: 1.55;
    color: var(--text-secondary);
}
.storage-home-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}
.storage-home-btn {
    display: flex;
    flex-direction: column;
    gap: 18px;
    width: 100%;
    padding: 18px 18px 16px;
    border: 1px solid var(--border-input);
    border-radius: 14px;
    background: var(--bg-input);
    color: var(--text);
    font-family: inherit;
    text-align: left;
    cursor: pointer;
    transition: border-color 0.15s, transform 0.12s, box-shadow 0.18s;
}
.storage-home-btn:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(240, 109, 19, 0.12);
}
.storage-home-btn:active { transform: translateY(0); box-shadow: 0 2px 6px rgba(240, 109, 19, 0.10); }
.storage-home-btn:focus { outline: none; }
.storage-home-btn:focus-visible {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
}
.storage-home-btn-top {
    display: flex;
    align-items: center;
    gap: 12px;
}
.storage-home-btn-icon {
    flex: 0 0 auto;
    width: 38px;
    height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    background: var(--accent-light);
    color: var(--accent);
    transition: background 0.18s, color 0.18s;
}
.storage-home-btn:hover .storage-home-btn-icon {
    background: var(--accent);
    color: #fff;
}
.storage-home-btn-icon svg { width: 18px; height: 18px; }
.storage-home-btn-size {
    flex: 1 1 auto;
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text);
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.01em;
    line-height: 1.1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.storage-home-btn-bottom {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 10px;
}
.storage-home-btn-text {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
}
.storage-home-btn-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text);
    line-height: 1.25;
}
.storage-home-btn-meta {
    font-size: 0.78rem;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}
.storage-home-btn-chevron {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: color 0.15s, transform 0.18s;
}
.storage-home-btn-chevron svg { width: 16px; height: 16px; }
.storage-home-btn:hover .storage-home-btn-chevron {
    color: var(--accent);
    transform: translateX(3px);
}

@media (max-width: 480px) {
    .storage-home-actions { grid-template-columns: 1fr; gap: 10px; }
}

/* Titre du panneau (intègre bouton retour + sous-section) */
#panel-stockage .storage-heading {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}
.storage-heading-main,
.storage-heading-sep,
.storage-heading-sub {
    color: var(--text);
    font-weight: inherit;
}
#panel-stockage[data-storage-view="home"] .storage-back-btn,
#panel-stockage[data-storage-view="home"] .storage-heading-sep,
#panel-stockage[data-storage-view="home"] .storage-heading-sub { display: none; }
.storage-back-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    padding: 0;
    border: 1px solid var(--border-input);
    border-radius: 8px;
    background: var(--bg-input);
    color: var(--text-secondary);
    font-family: inherit;
    cursor: pointer;
    flex: 0 0 auto;
    transition: background 0.15s, color 0.15s, border-color 0.15s, transform 0.12s;
}
.storage-back-btn:hover {
    background: var(--accent-light);
    color: var(--accent);
    border-color: var(--accent);
    transform: translateX(-1px);
}
.storage-back-btn:focus { outline: none; }
.storage-back-btn:focus-visible { box-shadow: 0 0 0 2px var(--accent-light), 0 0 0 1px var(--accent); }
.storage-back-btn svg { width: 14px; height: 14px; }

/* Spinner de transition */
.storage-loading {
    display: none;
    position: absolute;
    inset: 0;
    align-items: center;
    justify-content: center;
    background: color-mix(in srgb, var(--bg) 70%, transparent);
    backdrop-filter: blur(2px);
    border-radius: inherit;
    z-index: 5;
}
#panel-stockage[data-storage-loading="true"] .storage-loading { display: flex; }
.storage-spinner {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 3px solid var(--accent-light);
    border-top-color: var(--accent);
    animation: spin 0.8s linear infinite;
}

/* Vue d'ensemble */
.storage-overview {
    position: relative;
    background: var(--bg-input);
    border: 1px solid var(--border-input);
    border-radius: 14px;
    padding: 18px 20px;
    margin: 6px 0 4px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.storage-overview-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
}
.storage-overview-label {
    font-size: 0.72rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.07em;
    font-weight: 600;
}
.storage-overview-value {
    font-size: 1.55rem;
    font-weight: 700;
    color: var(--text);
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.01em;
    line-height: 1;
}
.storage-overview-bar {
    display: flex;
    height: 8px;
    border-radius: 999px;
    overflow: hidden;
    background: var(--bg-active);
    gap: 2px;
}
.storage-overview-seg {
    height: 100%;
    width: 0;
    transition: width 0.45s cubic-bezier(0.4, 0, 0.2, 1);
    min-width: 0;
}
.storage-overview-seg-texts { background: var(--accent); }
.storage-overview-seg-images { background: #f59e0b; }
.storage-overview-seg-pdf { background: #ef4444; }
.storage-overview-seg-audio { background: #8b5cf6; }
.storage-overview-seg-video { background: #10b981; }
.storage-overview-seg-other { background: color-mix(in srgb, var(--text-secondary) 55%, var(--bg-active)); }

.storage-overview-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    font-size: 0.8rem;
}
.storage-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 7px;
}
.storage-legend-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    flex: 0 0 auto;
}
.storage-legend-dot-texts { background: var(--accent); }
.storage-legend-dot-images { background: #f59e0b; }
.storage-legend-dot-pdf { background: #ef4444; }
.storage-legend-dot-audio { background: #8b5cf6; }
.storage-legend-dot-video { background: #10b981; }
.storage-legend-dot-other { background: color-mix(in srgb, var(--text-secondary) 55%, var(--bg-active)); }
.storage-legend-text { color: var(--text-secondary); }
.storage-legend-size {
    color: var(--text);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

/* Sous-onglets */
.storage-subtabs {
    display: flex;
    gap: 6px;
    background: var(--bg-hover);
    padding: 4px;
    border-radius: 10px;
    margin-bottom: 14px;
}
.storage-subtab {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 14px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.86rem;
    font-weight: 500;
    border-radius: 7px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}
.storage-subtab:hover { color: var(--text); }
.storage-subtab.active {
    background: var(--bg);
    color: var(--text);
    font-weight: 600;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.storage-subtab-icon { font-size: 1rem; }
.storage-subtab-count {
    font-size: 0.72rem;
    background: var(--bg-active);
    color: var(--text-secondary);
    padding: 1px 7px;
    border-radius: 999px;
    font-variant-numeric: tabular-nums;
}
.storage-subtab.active .storage-subtab-count { background: var(--bg-hover); color: var(--text); }

/* Contrôles */
.storage-controls {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
    align-items: center;
    flex-wrap: nowrap;
}
.storage-search-wrap {
    position: relative;
    overflow: hidden;
    transition: flex-basis 0.28s ease, flex-grow 0.28s ease, max-width 0.28s ease, opacity 0.2s ease;
    min-width: 0;
}
.storage-sort-wrap {
    overflow: hidden;
    transition: flex-basis 0.28s ease, flex-grow 0.28s ease, max-width 0.28s ease, opacity 0.2s ease;
    min-width: 0;
}
.storage-icon-btn {
    flex: 0 0 auto;
    width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border-input);
    border-radius: 8px;
    background: var(--bg-input);
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0;
    overflow: hidden;
    transition: width 0.28s ease, padding 0.28s ease, opacity 0.2s ease, background 0.15s, color 0.15s, border-color 0.15s;
}
.storage-icon-btn:hover { background: var(--bg-hover); color: var(--text); border-color: var(--text-secondary); }
.storage-icon-btn svg { width: 16px; height: 16px; flex: 0 0 auto; }
.storage-icon-btn:focus { outline: none; }
.storage-icon-btn:focus-visible { box-shadow: 0 0 0 3px var(--accent-light); border-color: var(--accent); }

/* État "rétracté" pour les wraps et icon buttons */
.storage-search-wrap.collapsed,
.storage-sort-wrap.collapsed {
    flex: 0 0 0;
    max-width: 0;
    opacity: 0;
    pointer-events: none;
}
.storage-icon-btn.collapsed {
    width: 0;
    padding: 0;
    border-width: 0;
    opacity: 0;
    pointer-events: none;
}

/* Conversations : recherche + tri toujours côte à côte, pas d'icon button */
.storage-controls.controls-conv .storage-search-wrap { flex: 1 1 200px; max-width: 100%; opacity: 1; pointer-events: auto; }
.storage-controls.controls-conv .storage-sort-wrap { flex: 0 0 auto; max-width: 220px; opacity: 1; pointer-events: auto; }
.storage-controls.controls-conv #storage-search-btn,
.storage-controls.controls-conv #storage-sort-btn { width: 0; padding: 0; border-width: 0; opacity: 0; pointer-events: none; }

/* Médias + recherche active */
.storage-controls.controls-media.search-active .storage-search-wrap { flex: 1 1 200px; max-width: 100%; opacity: 1; pointer-events: auto; }
.storage-controls.controls-media.search-active .storage-sort-wrap { flex: 0 0 0; max-width: 0; opacity: 0; pointer-events: none; }
.storage-controls.controls-media.search-active #storage-search-btn { width: 0; padding: 0; border-width: 0; opacity: 0; pointer-events: none; }
.storage-controls.controls-media.search-active #storage-sort-btn { width: 36px; opacity: 1; pointer-events: auto; border-width: 1px; }

/* Médias + tri actif */
.storage-controls.controls-media.sort-active .storage-search-wrap { flex: 0 0 0; max-width: 0; opacity: 0; pointer-events: none; }
.storage-controls.controls-media.sort-active .storage-sort-wrap { flex: 1 1 200px; max-width: 100%; opacity: 1; pointer-events: auto; }
.storage-controls.controls-media.sort-active #storage-search-btn { width: 36px; opacity: 1; pointer-events: auto; border-width: 1px; }
.storage-controls.controls-media.sort-active #storage-sort-btn { width: 0; padding: 0; border-width: 0; opacity: 0; pointer-events: none; }
.storage-controls.controls-media.sort-active .storage-sort-select { width: 100%; }
.storage-search-icon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.85rem;
    opacity: 0.5;
    pointer-events: none;
}
.storage-search-input {
    width: 100%;
    padding: 8px 12px 8px 32px;
    border: 1px solid var(--border-input);
    border-radius: 8px;
    background: var(--bg-input);
    color: var(--text);
    font-family: inherit;
    font-size: 0.85rem;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.storage-search-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
}
.storage-filter-group {
    display: inline-flex;
    gap: 4px;
    background: var(--bg-hover);
    padding: 3px;
    border-radius: 8px;
}
.storage-filter-chip {
    padding: 6px 12px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.78rem;
    font-weight: 500;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    outline: none;
}
.storage-filter-chip:focus { outline: none; }
.storage-filter-chip:focus-visible { box-shadow: 0 0 0 2px var(--accent-light); }
.storage-filter-chip:hover { color: var(--text); }
.storage-filter-chip.active {
    background: var(--bg);
    color: var(--text);
    box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}
.storage-subtab:focus { outline: none; }
.storage-subtab:focus-visible { box-shadow: 0 0 0 2px var(--accent-light); }
.storage-sort-select {
    padding: 8px 28px 8px 32px;
    border: 1px solid var(--border-input);
    border-radius: 8px;
    background-color: var(--bg-input);
    color: var(--text);
    font-family: inherit;
    font-size: 0.82rem;
    cursor: pointer;
    appearance: none;
    background-image:
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23666' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E"),
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23666' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 6h13'/%3E%3Cpath d='M3 12h9'/%3E%3Cpath d='M3 18h5'/%3E%3Cpath d='M17 9l3 -3l3 3'/%3E%3Cpath d='M20 6v12'/%3E%3C/svg%3E");
    background-repeat: no-repeat, no-repeat;
    background-position: right 8px center, left 10px center;
    background-size: 12px 12px, 14px 14px;
}

/* Toolbar de sélection */
.storage-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px 8px;
    border-bottom: 1px solid var(--border-light);
}
.storage-master-label {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    font-size: 0.82rem;
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
}
.storage-master-label input {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
    cursor: pointer;
    margin: 0;
}
.storage-summary {
    flex: 1;
    text-align: right;
    font-size: 0.78rem;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

/* Liste */
.storage-list {
    max-height: 48vh;
    overflow-y: auto;
    padding: 4px 0;
    margin-bottom: 8px;
}
.storage-row {
    position: relative;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.15s, box-shadow 0.15s;
    user-select: none;
}
.storage-row:hover { background: var(--bg-hover); }
.storage-row.selected {
    background: var(--accent-light);
    box-shadow: inset 3px 0 0 var(--accent);
}
/* Continuité visuelle de la barre d'accent : on ne désarrondit le coin gauche
   qu'au point de jonction avec une autre ligne sélectionnée. Les groupes
   isolés gardent leurs coins arrondis. */
.storage-row.selected + .storage-row.selected {
    border-top-left-radius: 0;
}
.storage-row.selected:has(+ .storage-row.selected) {
    border-bottom-left-radius: 0;
}
.storage-row.selected:hover { background: color-mix(in srgb, var(--accent-light) 80%, var(--accent) 12%); }
.storage-row-cb {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
    cursor: pointer;
    margin: 0;
}
.storage-row-thumb {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    object-fit: cover;
    background: var(--bg-hover);
    flex: 0 0 auto;
    cursor: zoom-in;
}
.storage-row-icon {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    background: var(--bg-hover);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    font-size: 1.4rem;
}
.storage-row-main { flex: 1; min-width: 0; }
.storage-row-title {
    font-size: 0.88rem;
    color: var(--text);
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 3px;
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}
.storage-row-title-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
    flex: 1 1 auto;
}
.storage-row-date {
    font-size: 0.74rem;
    color: var(--text-secondary);
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    flex: 0 0 auto;
}
.storage-row-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.74rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}
.storage-row-meta-item {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}
.storage-row-meta-item:not(.storage-row-badge):last-of-type { flex-shrink: 0; }
.storage-row-meta-sep { opacity: 0.4; flex-shrink: 0; }
.storage-row-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 6px;
    background: var(--bg-active);
    color: var(--text-secondary);
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.storage-row-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
    flex: 0 0 auto;
    min-width: 84px;
    position: relative;
}
.storage-row-size {
    font-size: 0.82rem;
    color: var(--text);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}
.storage-row:hover .storage-row-size,
.storage-row:hover .storage-row-bar { visibility: hidden; }

/* Médias en vue liste : groupe d'actions (conv / aperçu / télécharger /
   supprimer) qui apparaît au survol de la ligne, masque la taille + barre. */
.storage-row-actions {
    position: absolute;
    top: 50%;
    right: 0;
    transform: translateY(-50%);
    display: none;
    align-items: center;
    gap: 4px;
}
.storage-row:hover .storage-row-actions { display: inline-flex; }
.storage-row-action {
    width: 30px;
    height: 30px;
    padding: 0;
    border: none;
    border-radius: 6px;
    background: var(--bg-active);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, transform 0.15s;
}
.storage-row-action svg { width: 15px; height: 15px; }
.storage-row-action:hover {
    background: color-mix(in srgb, var(--text) 14%, var(--bg-active));
    color: var(--text);
    transform: scale(1.06);
}
.storage-row-action-danger { color: #dc2626; }
.storage-row-action-danger:hover {
    background: rgba(220, 38, 38, 0.12);
    color: #dc2626;
}
body.dark .storage-row-action-danger,
body.dark .storage-row-action-danger:hover { color: #f87171; }
body.dark .storage-row-action-danger:hover { background: rgba(248, 113, 113, 0.18); }
.storage-row-bar {
    width: 80px;
    height: 4px;
    background: var(--bg-active);
    border-radius: 999px;
    overflow: hidden;
}
.storage-row-bar-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 999px;
    min-width: 2px;
    transition: width 0.2s ease;
}
.storage-row-bar-fill.media { background: color-mix(in srgb, var(--accent) 45%, var(--bg-active)); }
.storage-empty {
    padding: 48px 16px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.88rem;
}
.storage-empty-icon { display: inline-block; margin-bottom: 10px; opacity: 0.35; }
.storage-empty-icon svg { width: 40px; height: 40px; }

/* Icônes SVG inline (héritent de currentColor) */
.storage-row-icon svg,
.storage-subtab-icon svg,
.storage-search-icon svg,
.storage-row-meta-item svg,
.storage-row-icon svg { width: 16px; height: 16px; vertical-align: middle; }
.storage-row-icon svg { width: 22px; height: 22px; color: var(--text-secondary); }
.storage-subtab-icon svg { width: 16px; height: 16px; }
.storage-search-icon svg { width: 14px; height: 14px; }
.storage-row-meta-item svg { width: 12px; height: 12px; opacity: 0.7; margin-right: 2px; }
.storage-delete-btn svg { width: 14px; height: 14px; }

.storage-load-more {
    display: block;
    width: 100%;
    margin: 12px 0 4px;
    padding: 10px;
    border: 1px dashed var(--border-input);
    border-radius: 8px;
    background: transparent;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.82rem;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
.storage-load-more:hover { background: var(--bg-hover); color: var(--text); }

/* Barre d'action ancrée en bas du panneau */
.storage-action-bar {
    flex-shrink: 0;
    margin-top: 12px;
    display: none;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    background: var(--bg);
    border: 1px solid var(--border-input);
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
    z-index: 5;
}
.storage-action-bar.visible {
    display: flex;
    animation: storage-action-slide 0.2s ease;
}
@keyframes storage-action-slide {
    from { transform: translateY(8px); opacity: 0; }
    to   { transform: translateY(0); opacity: 1; }
}
.storage-action-info {
    flex: 1;
    font-size: 0.85rem;
    color: var(--text);
    font-weight: 500;
}
.storage-clear-btn {
    padding: 7px 12px;
    background: transparent;
    border: 1px solid var(--border-input);
    border-radius: 7px;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.8rem;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
.storage-clear-btn:hover { background: var(--bg-hover); color: var(--text); }
.storage-delete-btn {
    padding: 8px 16px;
    border: none;
    border-radius: 7px;
    background: #ef4444;
    color: #fff;
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.storage-delete-btn:hover { background: #dc2626; }
.storage-download-btn {
    padding: 8px 14px;
    border: 1px solid var(--border-input);
    border-radius: 7px;
    background: var(--bg);
    color: var(--text);
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.storage-download-btn:hover { background: var(--bg-hover); border-color: var(--accent); }
.storage-download-btn svg { width: 14px; height: 14px; }

/* Vue galerie pour les médias */
.storage-list.storage-list-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    grid-auto-rows: max-content;
    gap: 10px;
    align-content: start;
    padding: 4px;
}
.storage-tile {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1;
    border-radius: 10px;
    overflow: hidden;
    background: var(--bg-hover);
    border: 1px solid var(--border-input);
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s;
    box-sizing: border-box;
}
.storage-tile:hover {
    border-color: color-mix(in srgb, var(--accent) 60%, var(--border-input));
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
}
.storage-tile.selected {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent) inset;
}
.storage-tile-img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.storage-tile-img.storage-tile-img-svg {
    object-fit: contain;
    padding: 8px;
    background-image:
        linear-gradient(45deg, rgba(0,0,0,0.06) 25%, transparent 25%),
        linear-gradient(-45deg, rgba(0,0,0,0.06) 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, rgba(0,0,0,0.06) 75%),
        linear-gradient(-45deg, transparent 75%, rgba(0,0,0,0.06) 75%);
    background-size: 12px 12px;
    background-position: 0 0, 0 6px, 6px -6px, -6px 0;
    background-color: #fff;
}
.storage-row-thumb-svg {
    object-fit: contain;
    background: #fff;
    padding: 3px;
}
.storage-tile-icon {
    position: absolute;
    inset: 0;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
}
.storage-tile-icon svg { width: 44px; height: 44px; }
.storage-tile-check {
    position: absolute;
    top: 8px;
    left: 8px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.85);
    border: 1.5px solid var(--border-input);
    display: flex;
    align-items: center;
    justify-content: center;
    color: transparent;
    transition: background 0.15s, color 0.15s, border-color 0.15s, box-shadow 0.15s;
    backdrop-filter: blur(4px);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}
.storage-tile-check svg { width: 14px; height: 14px; }
.storage-tile.selected .storage-tile-check {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}
.storage-tile-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    padding: 2px 6px;
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    border-radius: 4px;
    pointer-events: none;
}
.storage-tile-size {
    position: absolute;
    bottom: 8px;
    left: 8px;
    padding: 2px 6px;
    font-size: 0.7rem;
    font-weight: 600;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    border-radius: 4px;
    pointer-events: none;
}
.storage-tile-overlay {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 28px 8px 8px;
    background: linear-gradient(to top, rgba(0,0,0,0.85), rgba(0,0,0,0));
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 8px;
    opacity: 0;
    transition: opacity 0.15s;
}
.storage-tile:hover .storage-tile-overlay { opacity: 1; }
.storage-tile:hover .storage-tile-size { opacity: 0; }
.storage-tile-action {
    width: 30px;
    height: 30px;
    border-radius: 6px;
    border: none;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.15s, transform 0.15s, color 0.15s;
    backdrop-filter: blur(4px);
    padding: 0;
}
.storage-tile-action svg { width: 15px; height: 15px; }
.storage-tile-action:hover { background: rgba(0, 0, 0, 0.85); transform: scale(1.08); }
.storage-tile-action-danger { background: rgba(220, 38, 38, 0.7); }
.storage-tile-action-danger:hover { background: rgba(220, 38, 38, 0.95); }

/* Toggle Liste / Grille */
.storage-viewmode-toggle {
    display: inline-flex;
    border: 1px solid var(--border-input);
    border-radius: 8px;
    overflow: hidden;
    margin-left: 8px;
    background: var(--bg);
}
.storage-viewmode-btn {
    width: 30px;
    height: 30px;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
}
.storage-viewmode-btn + .storage-viewmode-btn { border-left: 1px solid var(--border-input); }
.storage-viewmode-btn:hover { background: var(--bg-hover); color: var(--text); }
.storage-viewmode-btn.active {
    background: var(--accent-light);
    color: var(--accent);
}
.storage-viewmode-btn svg { width: 16px; height: 16px; }

/* Dock de prévisualisation d'une conversation (mode "réduit" des paramètres) */
.storage-preview-dock {
    position: fixed;
    left: 50%;
    bottom: 18px;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 10px 16px;
    background: var(--bg);
    border: 1px solid var(--border-input);
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.18);
    z-index: 9999;
    max-width: calc(100vw - 32px);
    animation: storage-preview-dock-in 0.22s ease;
}
@keyframes storage-preview-dock-in {
    from { transform: translate(-50%, 12px); opacity: 0; }
    to   { transform: translate(-50%, 0);     opacity: 1; }
}
.storage-preview-dock-info {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    max-width: 360px;
}
.storage-preview-dock-label {
    font-size: 0.78rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    flex-shrink: 0;
}
.storage-preview-dock-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.storage-preview-dock-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}
.storage-preview-btn {
    padding: 8px 14px;
    border-radius: 7px;
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.storage-preview-btn-ghost {
    background: transparent;
    border-color: var(--border-input);
    color: var(--text-secondary);
}
.storage-preview-btn-ghost:hover { background: var(--bg-hover); color: var(--text); }
.storage-preview-btn-primary {
    background: var(--accent, #2563eb);
    color: #fff;
}
.storage-preview-btn-primary:hover { filter: brightness(1.08); }
.storage-preview-btn-danger {
    background: #ef4444;
    color: #fff;
}
.storage-preview-btn-danger:hover { background: #dc2626; }

/* En mode aperçu depuis Stockage : masquer tout le footer (alertes, tokens/coût, zone de saisie) */
/* En mode aperçu : volets non interactifs, curseur "interdit" visible.
   Astuce : on ne met PAS pointer-events:none sur le volet (sinon le curseur
   ne s'applique pas). On met cursor:not-allowed sur le volet et
   pointer-events:none sur ses enfants : les événements remontent au volet
   (qui ne fait rien) et les boutons ne peuvent plus être activés. */
body.storage-preview-mode .sidebar,
body.storage-preview-mode .right-panel,
body.storage-preview-mode .side-panel-toolbar {
    cursor: not-allowed;
}
body.storage-preview-mode .sidebar *,
body.storage-preview-mode .right-panel *,
body.storage-preview-mode .side-panel-toolbar * {
    pointer-events: none !important;
    cursor: not-allowed !important;
}

/* Neutralise l'animation d'apparition par défaut (sp-modal-appear) sur la
   modale Paramètres : elle entrait en conflit avec l'animation de morphing
   en se rejouant à chaque transition display:none → flex (effet de zoom
   superposé au morphing → clignotement). Les animations sont désormais
   pilotées par les classes `.opening` / `.closing` posées par JS, pour ne
   pas se rejouer en parallèle du morphing vers/depuis le dock. */
.sp-modal.apikeys-modal {
    animation: none !important;
}
.sp-modal.apikeys-modal.opening {
    animation: sp-modal-appear 0.2s ease-out !important;
}
.sp-modal.apikeys-modal.closing {
    animation: sp-modal-disappear 0.18s ease-in forwards !important;
}
@keyframes sp-modal-disappear {
    from { opacity: 1; transform: scale(1) translateY(0); }
    to   { opacity: 0; transform: scale(0.96) translateY(8px); }
}

/* Morphing fluide de la modale Paramètres vers le dock du bas
   (translation + downscale + fondu, courbe douce) */
.sp-modal.morphing-to-dock {
    animation: modal-morph-to-dock 0.42s cubic-bezier(0.32, 0.72, 0.35, 1) both !important;
    transform-origin: 50% 100%;
    will-change: transform, opacity;
}
@keyframes modal-morph-to-dock {
    0%   { transform: translate3d(0, 0, 0)        scale(1);    opacity: 1; }
    100% { transform: translate3d(0, 45vh, 0)     scale(0.25); opacity: 0; }
}
.sp-modal.morphing-from-dock {
    animation: modal-morph-from-dock 0.42s cubic-bezier(0.22, 1, 0.36, 1) both !important;
    transform-origin: 50% 100%;
    will-change: transform, opacity;
}
@keyframes modal-morph-from-dock {
    0%   { transform: translate3d(0, 45vh, 0)     scale(0.25); opacity: 0; }
    100% { transform: translate3d(0, 0, 0)        scale(1);    opacity: 1; }
}

body.storage-preview-mode #model-alert,
body.storage-preview-mode #token-bar,
body.storage-preview-mode .input-area,
body.storage-preview-mode .message-btn-row,
body.storage-preview-mode .message-copy-btn,
body.storage-preview-mode .regen-btn,
body.storage-preview-mode .code-copy-btn {
    display: none !important;
}
