/* --- Variables de thème --- */
:root {
    --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: #3d3520;
        color: #ffc107;
        border-color: #665a28;
    }
    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 {
    opacity: 0.3;
    pointer-events: none;
}

.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;
    pointer-events: none;
    filter: grayscale(1);
}

#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-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 {
    position: fixed;
    top: 10px;
    right: 264px;
    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: right 0.25s ease, color 0.15s, background 0.15s;
}

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

.right-panel-toggle.collapsed {
    right: 8px;
}

body:has(#right-panel.collapsed) .chat-container {
    padding-right: 56px;
}

@media (max-width: 768px) {
    .right-panel {
        display: none;
    }
    .right-panel-toggle {
        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;
}

.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;
}

@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: 18;
    margin: 0 32px;
    padding: 8px 16px;
    background: #fff3cd;
    color: #856404;
    border: 1px solid #ffc107;
    border-radius: 8px;
    font-size: 0.82rem;
    text-align: center;
    animation: fadeIn 0.2s ease;
}

body.dark .model-alert {
    background: #3d3520;
    color: #ffc107;
    border-color: #665a28;
}

@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-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.35;
    padding: 6px 10px;
    border-radius: 6px;
    white-space: normal;
    width: 220px;
    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;
    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;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    pointer-events: auto;
}

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

/* 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: 20;
    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;
}

.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;
    gap: 8px;
}

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

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

.apikey-input {
    flex: 1;
    min-width: 0;
}

.apikey-intro {
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.5;
    margin: 0 0 20px 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 {
    flex-shrink: 0;
    align-self: stretch;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    padding: 0;
    border: 1px solid var(--border-input);
    background: var(--bg-input);
    color: var(--text-secondary);
    border-radius: 10px;
    cursor: pointer;
    transition: color 0.15s, background 0.15s, border-color 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: 8px;
}

.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: 6px 0 0;
    min-height: 1.1em;
}

.apikey-local-status.success { color: #22c55e; }
.apikey-local-status.error   { color: #ef4444; }

/* Modale à onglets (Configuration) */
.apikeys-modal {
    flex-direction: row !important;
    padding: 0 !important;
    width: 720px !important;
    height: 580px !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-input);
    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: 140px;
    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(--bg-input);
    color: var(--accent);
    font-weight: 600;
}

.apikeys-tab-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 0;
    overflow-y: auto;
    max-height: 80vh;
    min-width: 0;
}

.apikeys-panel {
    display: none;
    flex-direction: column;
    gap: 12px;
    flex: 1;
    padding: 0 24px 24px;
}

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

.apikeys-panel > h3,
.apikeys-panel > .dashboard-tabs {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--bg-input);
    margin: 0 -24px 4px;
    padding: 18px 56px 14px 24px;
    border-bottom: 1px solid var(--border-input);
}

.apikeys-panel > .dashboard-tabs {
    padding-top: 14px;
    padding-bottom: 10px;
}

/* Spacer pour séparer les onglets du bas */
.apikeys-tabs-spacer {
    flex: 1;
    min-height: 12px;
    border-bottom: 1px solid var(--border-input);
    margin: 4px 8px 4px 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: 5px 8px;
    cursor: pointer;
}

.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: #3b82f6;
}

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

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

.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;
}

.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"] {
    accent-color: var(--accent);
    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;
    gap: 4px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0;
}

.dashboard-tab {
    font-family: inherit;
    font-size: 0.82rem;
    padding: 7px 14px;
    border: none;
    background: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: color 0.15s, border-color 0.15s;
}

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

.dashboard-tab.active {
    color: var(--text);
    border-bottom-color: var(--text);
    font-weight: 600;
}

.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);
}

.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;
    border-top: 1px solid var(--border);
}

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

.thinking-content p:last-child {
    margin-bottom: 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;
}

.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;
}

.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;
}
