/* Mistral AI Inspired Chat Interface */
:root {
    --primary-color: #6496FF;
    --primary-hover: #4d7fe6;
    --background-color: #F7F7FC;
    --background-secondary: #EEF0F6;
    --chat-background: #FFFFFF;
    --sidebar-bg: #2D3748;
    --sidebar-text: #E2E8F0;
    --sidebar-hover: #4A5568;
    --message-user-bg: var(--primary-color);
    --message-bot-bg: #F7F7FC;
    --input-bg: #FFFFFF;
    --border-color: #E2E8F0;
    --text-primary: #2D3748;
    --text-secondary: #718096;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: var(--background-color);
    color: var(--text-primary);
    line-height: 1.5;
}

/* Header - Plus minimaliste */
.header {
    background-color: var(--primary-color);
    color: white;
    padding: 12px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    position: sticky;
    top: 0;
    z-index: 100;
}

/* Badge « IA souveraine française » dans le bandeau (visible sur tous les écrans).
   Discret : pastille translucide sur le bleu. Sur mobile, seul le drapeau reste (place). */
#hdr-sovereign {
    display: inline-flex; align-items: center; gap: 5px;
    margin-left: 8px; flex-shrink: 0;
    font-size: 11px; font-weight: 600; letter-spacing: .01em;
    color: rgba(255, 255, 255, .92);
    background: rgba(255, 255, 255, .10);
    border: 1px solid rgba(255, 255, 255, .20);
    border-radius: 20px; padding: 3px 10px;
    white-space: nowrap; cursor: default; user-select: none;
}
.hdr-sov-flag { font-size: 12.5px; line-height: 1; }
@media (max-width: 700px) {
    #hdr-sovereign .hdr-sov-txt { display: none; }
    #hdr-sovereign { padding: 3px 7px; margin-left: 4px; gap: 0; }
}

.header h1 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}


.user-info {
    display: flex;
    gap: 12px;
    align-items: center;
}

.user-info a {
    color: white;
    text-decoration: none;
    font-size: 14px;
    padding: 6px 12px;
    border-radius: 6px;
    transition: background-color 0.2s;
}

.user-info a:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

/* Container principal */
.container {
    display: flex;
    height: calc(100vh - 52px);
    overflow: hidden;
}

/* Main content area */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background-color: var(--chat-background);
}

/* Content header with tabs */
.content-header {
    display: flex;
    align-items: center;
    background-color: var(--background-color);
    border-bottom: 1px solid var(--border-color);
    padding: 0 16px 0 24px;
}

.content-header-spacer { flex: 1; min-width: 0; overflow: hidden; }

.content-header-settings {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 8px;
    border: none;
    background: none;
    cursor: pointer;
    color: var(--text-secondary);
    transition: background .15s, color .15s;
    flex-shrink: 0;
}
.content-header-settings:hover { background: var(--background-secondary); color: var(--primary-color); }
.content-header-settings.active { color: var(--primary-color); }

.content-tab {
    padding: 12px 20px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 15px;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all 0.2s;
    border-bottom: 2px solid transparent;
    margin-right: 8px;
}

.content-tab:hover {
    color: var(--primary-color);
}

.content-tab.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

/* Content panels */
.content-panel {
    flex: 1;
    display: none;
    overflow: hidden;
}

.content-panel.active {
    display: flex;
    flex-direction: column;
}

/* Chat content (now a panel) */
#chat-content {
    flex-direction: column;
}

#chat-content .chat-messages {
    flex: 1;
    min-height: 0; /* autorise le scroll interne et empêche la zone de pousser/compresser la barre de saisie */
    padding: 24px;
    overflow-y: auto;
}

/* Settings panel */
.settings-container {
    flex: 1;
    min-height: 0;
    padding: 16px 24px;
    overflow-y: auto;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
}

.settings-container h2 {
    color: var(--primary-color);
    margin-bottom: 14px;
    font-size: 18px;
}


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

.settings-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.settings-section h3 {
    color: var(--text-secondary);
    margin-bottom: 8px;
    font-size: 10.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    opacity: 0.7;
}

.setting-item {
    margin-bottom: 6px;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    min-height: 30px;
}

.setting-item label {
    font-size: 13px;
    color: var(--text-primary);
    font-weight: 500;
    flex: 0 0 auto;
    min-width: 155px;
}

.setting-item select,
.setting-item input[type="text"] {
    flex: 1;
    padding: 5px 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background-color: var(--input-bg);
    font-size: 13px;
    transition: border-color 0.2s;
}

.setting-item select:focus,
.setting-item input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.setting-item input[type="checkbox"] {
    width: 15px;
    height: 15px;
    cursor: pointer;
    flex-shrink: 0;
    accent-color: var(--primary-color);
}

/* Sliders */
.setting-item input[type="range"] {
    flex: 1;
    height: 5px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--border-color);
    border-radius: 3px;
    outline: none;
    padding: 0;
    border: none;
}

.setting-item input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 15px;
    height: 15px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
    transition: background-color 0.2s;
}

.setting-item input[type="range"]::-webkit-slider-thumb:hover {
    background: var(--primary-hover);
}

.setting-item input[type="range"]::-moz-range-thumb {
    width: 15px;
    height: 15px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

.setting-item span {
    font-size: 12px;
    color: var(--text-secondary);
    min-width: 2.8em;
    text-align: right;
    flex-shrink: 0;
}

.setting-item.display-flex {
    flex-direction: row;
    align-items: center;
    gap: 10px;
}

.setting-item.display-flex label {
    min-width: unset;
    font-weight: normal;
    cursor: pointer;
}

.danger-button {
    background-color: #F56565;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    transition: background-color 0.2s;
    margin-top: 12px;
}

.danger-button:hover {
    background-color: var(--danger);
}

/* Test button style */
.test-button {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    transition: background-color 0.2s;
    margin-top: 12px;
}

.test-button:hover {
    background-color: var(--primary-hover);
}

/* Agents management styles */
.agents-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    gap: 16px;
}

.primary-button {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    transition: background-color 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
}

.primary-button:hover {
    background-color: var(--primary-hover);
}

.secondary-button {
    background-color: var(--background-color);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
}

.secondary-button:hover {
    background-color: var(--border-color);
}

.agent-selector {
    display: flex;
    align-items: center;
    gap: 8px;
}

.agent-selector select {
    padding: 6px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background-color: var(--input-bg);
    font-size: 14px;
}

#agent-configuration {
    margin-top: 16px;
    padding: 16px;
    background-color: var(--background-color);
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

#agent-configuration textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background-color: var(--input-bg);
    font-size: 14px;
    font-family: inherit;
    resize: vertical;
    min-height: 100px;
}

.learning-module {
    margin-top: 16px;
    padding: 12px;
    background-color: white;
    border-radius: 6px;
    border: 1px solid var(--border-color);
}

.learning-module h4 {
    margin-bottom: 12px;
    color: var(--primary-color);
    font-size: 15px;
}

.special-actions-module {
    margin-top: 16px;
    padding: 12px;
    background-color: white;
    border-radius: 6px;
    border: 1px solid var(--border-color);
}

.special-actions-module h4 {
    margin-bottom: 12px;
    color: var(--primary-color);
    font-size: 15px;
}

.special-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 12px;
}

.special-action {
    display: flex;
    gap: 8px;
    align-items: center;
}

.special-action input {
    flex: 1;
    padding: 6px 10px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 13px;
}

.special-action .action-command {
    min-width: 120px;
}

.remove-action {
    background: none;
    border: none;
    color: var(--danger);
    cursor: pointer;
    font-size: 14px;
    padding: 0 4px;
    transition: color 0.2s;
}

.remove-action:hover {
    color: #C53030;
}

/* Rating system styles */
.rating-system {
    margin-top: 16px;
    padding: 12px;
    background-color: white;
    border-radius: 6px;
    border: 1px solid var(--border-color);
}

.rating-system h4 {
    margin-bottom: 12px;
    color: var(--primary-color);
    font-size: 15px;
}

.rating-stars {
    display: flex;
    gap: 4px;
    margin-bottom: 12px;
    justify-content: center;
}

.star {
    font-size: 24px;
    cursor: pointer;
    color: #E2E8F0;
    transition: color 0.2s;
}

.star:hover,
.star.active {
    color: var(--warning);
}

.rating-feedback {
    margin-top: 12px;
    padding: 8px;
    background-color: var(--background-color);
    border-radius: 4px;
    text-align: center;
    font-size: 13px;
}

.rating-feedback.text-area {
    min-height: 60px;
    text-align: left;
}

.learning-examples {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 12px;
}

.learning-example {
    display: flex;
    gap: 8px;
    align-items: center;
}

.learning-example input {
    flex: 1;
    padding: 6px 10px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 13px;
}

.remove-example {
    background: none;
    border: none;
    color: var(--danger);
    cursor: pointer;
    font-size: 14px;
    padding: 0 4px;
    transition: color 0.2s;
}

.remove-example:hover {
    color: #C53030;
}

.agent-actions {
    display: flex;
    gap: 12px;
    margin-top: 16px;
    flex-wrap: wrap;
}

.danger-button {
    background-color: #F56565;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    transition: background-color 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
}

.danger-button:hover {
    background-color: var(--danger);
}

.test-button:disabled {
    background-color: #E2E8F0;
    color: #718096;
    cursor: not-allowed;
}

.about-info {
    color: var(--text-secondary);
    font-size: 12px;
    margin: 0;
}
.about-sovereign {
    color: var(--text-secondary);
    font-size: 11.5px;
    margin: 6px 0 0;
    opacity: .8;
    letter-spacing: .01em;
}

/* Sidebar - Plus moderne */
.sidebar {
    width: 280px;
    background-color: var(--sidebar-bg);
    color: var(--sidebar-text);
    padding: 16px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-color);
}

.sidebar #conversations-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}

.sidebar-bottom {
    flex-shrink: 0;
    padding-top: 12px;
    border-top: 1px solid var(--border-color);
}

/* Bouton principal "Nouvelle conversation" */
.sidebar button {
    width: 100%;
    padding: 10px 14px;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: background-color 0.2s, transform 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-bottom: 8px;
}

.sidebar button:hover {
    background-color: var(--primary-hover);
}

.sidebar button:active {
    transform: scale(0.98);
}

/* Style discret pour Nouveau chat et Nouveau contact */
#new-chat-btn,
#sidebar-bottom-contacts button {
    background: rgba(255,255,255,0.04) !important;
    border: 1px solid rgba(255,255,255,0.1) !important;
    color: rgba(226,232,240,0.5) !important;
    font-size: 12px !important;
    font-weight: 500 !important;
    padding: 7px 14px !important;
    border-radius: 8px !important;
    letter-spacing: 0.01em;
}
#new-chat-btn:hover,
#sidebar-bottom-contacts button:hover {
    background: rgba(255,255,255,0.08) !important;
    border-color: rgba(255,255,255,0.18) !important;
    color: rgba(226,232,240,0.8) !important;
    transform: none !important;
}
#new-chat-btn::before,
#sidebar-bottom-contacts button::before {
    content: "+";
    font-size: 14px;
    font-weight: 400;
    line-height: 1;
    opacity: 0.7;
}

/* Boutons d'action (⚙️ et 🗑️) */
.sidebar-actions {
    display: flex;
    gap: 4px;
    margin-bottom: 20px;
}

.sidebar-actions button {
    width: 32px !important;
    height: 32px;
    padding: 0 !important;
    background: none !important;
    color: var(--sidebar-text);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 16px;
    transition: background-color 0.15s, opacity 0.15s;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    opacity: 0.45;
    margin-bottom: 0 !important;
}

.sidebar-actions button:hover {
    background-color: rgba(255, 255, 255, 0.1) !important;
    opacity: 1;
}

/* Header de section (Conversations récentes) */
.sidebar h3 {
    margin: 0 0 6px 0;
    padding: 0 4px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--sidebar-text);
    opacity: 0.45;
}

.sidebar-info {
    font-size: 11px;
    color: var(--sidebar-text);
    opacity: 0.4;
    margin-bottom: 8px;
    padding: 0 4px;
    line-height: 1.4;
}

.sidebar ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

/* Items de conversation */
.sidebar li {
    padding: 5px 8px 5px 10px;
    border-radius: 6px;
    cursor: pointer;
    margin-bottom: 1px;
    font-size: 12.5px;
    color: rgba(226, 232, 240, 0.65);
    transition: background-color 0.12s, color 0.12s, border-color 0.12s;
    display: flex;
    align-items: center;
    gap: 7px;
    border-left: 2px solid transparent;
}

.sidebar li::before {
    content: "";
    display: block;
    width: 13px;
    height: 13px;
    flex-shrink: 0;
    opacity: 0.45;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23E2E8F0' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z'%3E%3C/path%3E%3C/svg%3E");
    background-size: contain;
    background-repeat: no-repeat;
}

.conv-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Bouton × — visible uniquement au survol, spécificité augmentée */
.sidebar li .conv-delete-btn {
    background: none !important;
    border: none;
    color: inherit;
    cursor: pointer;
    width: 18px !important;
    height: 18px;
    padding: 0 !important;
    border-radius: 3px;
    font-size: 16px;
    line-height: 1;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    opacity: 0;
    margin-bottom: 0 !important;
    transition: opacity 0.12s, background-color 0.12s, color 0.12s;
}

.sidebar li:hover .conv-delete-btn {
    opacity: 0.4;
}

.sidebar li .conv-delete-btn:hover {
    opacity: 1 !important;
    color: var(--danger) !important;
    background-color: rgba(229, 62, 62, 0.1) !important;
}

/* ── Section dossiers ──────────────────────────── */

.folders-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 4px;
    margin-top: 24px;
    margin-bottom: 4px;
}

.folders-section-header h3 {
    margin: 0;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    opacity: 0.45;
}

/* Spécificité augmentée pour battre .sidebar button (0-1-1) */
.sidebar .folder-add-btn {
    background: none !important;
    border: none;
    color: var(--sidebar-text);
    cursor: pointer;
    width: 18px !important;
    height: 18px;
    font-size: 15px;
    padding: 0 !important;
    border-radius: 3px;
    opacity: 0.4;
    margin-bottom: 0 !important;
    transition: opacity 0.15s, background-color 0.15s;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    line-height: 1;
    flex-shrink: 0;
}

.sidebar .folder-add-btn:hover {
    opacity: 1;
    background-color: rgba(255, 255, 255, 0.1) !important;
}

/* Supprimer les pseudo-éléments hérités sur les items dossier */
.sidebar .folder-item::before {
    content: none;
}

/* Item dossier — spécificité augmentée pour battre .sidebar li (0-1-1) */
.sidebar .folder-item {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 5px 8px;
    border-radius: 5px;
    cursor: pointer;
    margin-bottom: 1px;
    font-size: 13px;
    color: var(--sidebar-text);
    transition: background-color 0.15s;
}

.sidebar .folder-item:hover {
    background-color: var(--sidebar-hover);
}

.sidebar .folder-item.active {
    background-color: var(--primary-color);
    color: white;
}

.folder-item-icon {
    font-size: 13px;
    opacity: 0.6;
    flex-shrink: 0;
    line-height: 1;
}

.folder-item-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: inherit;
}

/* Bouton ⋮ — spécificité augmentée pour battre .sidebar button (0-1-1) */
.sidebar .folder-item .folder-menu-button {
    background: none !important;
    border: none;
    color: inherit;
    cursor: pointer;
    width: 20px !important;
    height: 20px;
    padding: 0 !important;
    border-radius: 3px;
    font-size: 14px;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    opacity: 0;
    margin-bottom: 0 !important;
    transition: opacity 0.12s, background-color 0.12s;
    line-height: 1;
}

.sidebar .folder-item:hover .folder-menu-button {
    opacity: 0.55;
}

.sidebar .folder-item .folder-menu-button:hover {
    opacity: 1 !important;
    background-color: rgba(255, 255, 255, 0.12) !important;
}

/* Menu contextuel dossier */
.folder-context-menu {
    background-color: #ffffff;
    border: 1px solid rgba(0,0,0,0.08);
    border-radius: 10px;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.08), 0 10px 24px -4px rgba(0,0,0,0.14);
    min-width: 148px;
    z-index: 1000;
    display: none;
    overflow: hidden;
    padding: 5px;
}

.folder-context-menu.active {
    display: block;
}

.folder-context-menu-item {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 450;
    border-radius: 6px;
    color: #1a202c;
    transition: background-color 0.1s;
    white-space: nowrap;
    letter-spacing: 0.01em;
}

.folder-context-menu-item svg {
    opacity: 0.55;
    flex-shrink: 0;
}

.folder-context-menu-item:hover {
    background-color: #f1f5f9;
}

.folder-context-menu-item:hover svg {
    opacity: 0.8;
}

.folder-context-menu-item.danger {
    color: var(--danger);
}

.folder-context-menu-item.danger svg {
    opacity: 0.7;
}

.folder-context-menu-item.danger:hover {
    background-color: #fef2f2;
    color: var(--danger-strong);
}

/* Conversation items in folders */
.folder-conversation-item {
    padding-left: 30px;
    font-size: 13px;
    opacity: 0.9;
}

.folder-conversation-item::before {
    content: "📄";
    margin-right: 6px;
}

/* Uncategorized list style */
.uncategorized-list {
    min-height: 50px;
}

.sidebar li:hover {
    background-color: rgba(255, 255, 255, 0.06);
    color: var(--sidebar-text);
}

.sidebar li.active {
    background-color: rgba(var(--primary-rgb), 0.18);
    color: white;
    border-left-color: var(--primary-color);
}

.sidebar li.active::before {
    opacity: 0.9;
}

/* Chat container - Design inspiré de Mistral */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background-color: var(--chat-background);
}

.chat-messages {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
    background-color: var(--chat-background);
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.chat-messages::-webkit-scrollbar {
    width: 8px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background-color: var(--border-color);
    border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-track {
    background-color: var(--background-color);
}

/* Messages - Style Mistral */
.message {
    margin-bottom: 16px;
    padding: 12px 16px;
    border-radius: 18px;
    max-width: 80%;
    word-wrap: break-word;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    position: relative;
    font-size: 15px;
    line-height: 1.4;
}

.user-message {
    background-color: var(--message-user-bg);
    color: white;
    margin-left: auto;
    border-bottom-right-radius: 4px;
}

.user-message details.ctx-details {
    margin-top: 8px;
    border-top: 1px solid rgba(255,255,255,0.2);
    padding-top: 6px;
}
.user-message details.ctx-details > summary {
    cursor: pointer;
    font-size: 12px;
    opacity: 0.7;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 5px;
    user-select: none;
}
.user-message details.ctx-details > summary::-webkit-details-marker { display: none; }
.user-message details.ctx-details > summary::after { content: "▾"; font-size: 11px; }
.user-message details[open].ctx-details > summary::after { content: "▴"; }
.user-message details.ctx-details .ctx-body {
    margin-top: 8px;
    font-size: 13px;
    opacity: 0.85;
    max-height: 280px;
    overflow-y: auto;
    line-height: 1.5;
    white-space: pre-wrap;
}

.bot-message {
    background-color: var(--message-bot-bg);
    color: var(--text-primary);
    margin-right: auto;
    border-bottom-left-radius: 4px;
    border: 1px solid var(--border-color);
}

.typing-indicator {
    color: var(--text-secondary);
    font-style: italic;
    display: flex;
    align-items: center;
    gap: 6px;
}

.typing-indicator::before {
    content: "✍️";
}

/* Input container - Design intégré */
.input-container {
    display: flex;
    flex-direction: column;
    flex-shrink: 0; /* la barre de saisie ne doit jamais être compressée par la zone messages */
    padding: 12px 20px calc(16px + env(safe-area-inset-bottom, 0px));
    background-color: var(--chat-background);
    border-top: 1px solid var(--border-color);
}

.input-row input,
.input-row textarea {
    flex: 1;
    padding: 11px 16px;
    border: 1px solid var(--border-color);
    border-radius: 24px;
    font-size: 15px;
    font-family: inherit;
    background-color: var(--input-bg);
    color: var(--text-color);
    transition: border-color 0.2s, box-shadow 0.2s;
    outline: none;
}

.input-row input:focus,
.input-row textarea:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.1);
}

.input-row button {
    padding: 11px 20px;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 24px;
    cursor: pointer;
    font-size: 15px;
    font-weight: 500;
    transition: background-color 0.2s, transform 0.1s;
    white-space: nowrap;
    flex-shrink: 0;
}

.input-row button:hover {
    background-color: var(--primary-hover);
}

.input-row button:active {
    transform: scale(0.98);
}

.input-row button:disabled {
    background-color: #E2E8F0;
    color: #718096;
    cursor: not-allowed;
}

/* ── Bouton hamburger (caché sur desktop) ───────────────── */
.mobile-menu-btn {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 7px;
    border-radius: 8px;
    color: white;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}
.mobile-menu-btn:hover { background: rgba(255,255,255,0.15); }
.mobile-menu-btn svg { display: block; }

/* ── Backdrop (caché par défaut) ────────────────────────── */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 999;
    -webkit-tap-highlight-color: transparent;
}
.sidebar-backdrop.visible { display: block; }

/* ── Bottom nav (mobile) ─────────────────────────────────── */
.bottom-nav {
    display: none;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    /* box-sizing:border-box global → la hauteur DOIT inclure la safe-area basse, sinon
       (mode PWA plein écran) la nav ne fait que 56px, ses icônes sont écrasées et il reste
       un décalage de la hauteur de la safe-area (blanc au-dessus, bande sombre en bas).
       Total = 56px de contenu + safe-area ; c'est exactement ce que .container réserve. */
    height: calc(56px + env(safe-area-inset-bottom, 0px));
    background: var(--sidebar-bg, #1e1e2e);
    border-top: 1px solid rgba(255,255,255,.1);
    z-index: 998;
    padding-bottom: env(safe-area-inset-bottom, 0px);
}
.bottom-nav-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    background: none;
    border: none;
    cursor: pointer;
    color: rgba(255,255,255,.45);
    font-size: 10px;
    font-weight: 500;
    font-family: inherit;
    padding: 6px 4px;
    min-height: 44px;
    transition: color .15s;
    -webkit-tap-highlight-color: transparent;
}
.bottom-nav-btn svg { width: 20px; height: 20px; flex-shrink: 0; }
.bottom-nav-btn span { line-height: 1; letter-spacing: .01em; }
.bottom-nav-btn:active { opacity: .7; }
#bnav-home.active        { color: #fbbf24; }
#bnav-conversations.active { color: #60a5fa; }
#bnav-clients.active     { color: #34d399; }
#bnav-recordings.active  { color: #a78bfa; }
#bnav-contacts.active    { color: #f472b6; }

/* ── Mobile ≤ 768px ─────────────────────────────────────── */
@media (max-width: 768px) {

    /* Hamburger visible */
    .mobile-menu-btn { display: flex; }

    /* Bottom nav visible */
    .bottom-nav { display: flex; }

    /* Header compact + dégagement de la barre d'état / encoche (PWA plein écran).
       Sans ce padding-top, le logo et les boutons passent sous la barre d'état iOS. */
    .header {
        padding: calc(8px + env(safe-area-inset-top, 0px)) 12px 8px !important;
        gap: 6px !important;
    }
    #home-btn h1 { font-size: 1em !important; }
    .user-widget-name { display: none !important; }
    #logout .logout-label { display: none; }
    #logout { padding: 7px !important; gap: 0 !important; }

    /* Sidebar : overlay fixe glissant depuis la gauche */
    .sidebar {
        position: fixed !important;
        top: 0 !important;
        left: -290px !important;
        height: 100dvh !important;
        width: 280px !important;
        z-index: 1000 !important;
        border-right: none !important;
        box-shadow: 4px 0 32px rgba(0, 0, 0, 0.4);
        transition: left 0.25s cubic-bezier(.4, 0, .2, 1);
        padding-top: 60px !important;
        overflow-y: auto !important;
    }
    .sidebar.mobile-open { left: 0 !important; }

    /* Tabs sidebar cachés (remplacés par le bottom nav) */
    .sidebar-tabs { display: none !important; }

    /* Main content pleine largeur ; container réduit pour la barre de nav + safe area */
    .main-content { width: 100% !important; }
    .container {
        /* 52px header + 56px bottom-nav + les deux safe-areas (le header inclut désormais
           la safe-area du haut → on la retranche aussi ici pour ne pas déborder). */
        height: calc(100dvh - 52px - 56px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)) !important;
    }
    /* Clavier ouvert (iOS) : la bottom-nav est masquée derrière le clavier → on abandonne
       sa réserve de 56px et la safe-area basse, et on retranche la hauteur du clavier
       (--kb-inset, posée par visualViewport) pour poser la barre de saisie juste dessus. */
    body.kb-open .container {
        height: calc(100dvh - 52px - env(safe-area-inset-top, 0px) - var(--kb-inset, 0px)) !important;
    }

    /* Chat */
    .chat-messages { padding: 12px 10px !important; }

    /* Bulles élargies : le plafond desktop de 80 % gaspille ~75px par côté sur un
       écran de téléphone. Réponses (rapports, tableaux…) = pleine largeur ; questions
       = 90 % pour garder la bulle utilisateur identifiable à droite. */
    .message { max-width: 100%; padding: 11px 13px; }
    .user-message { max-width: 90%; }

    /* Zone saisie — pas de safe-area ici (absorbée par la hauteur du container) */
    .input-container { padding: 8px 10px 10px !important; }

    /* Boutons d'action : cibles tactiles min 44px */
    .input-row button,
    .content-header-settings {
        min-width: 44px !important;
        min-height: 44px !important;
    }

    /* Empêcher le zoom iOS sur les inputs */
    .input-row textarea,
    .input-row input { font-size: 16px !important; }

    /* Welcome screen : empiler les colonnes */
    .welcome-screen {
        flex-direction: column !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        height: auto !important;
        min-height: 100% !important;
        padding: 16px !important;
        gap: 16px !important;
    }
    .welcome-col-left,
    .welcome-col-right {
        overflow: visible !important;
        min-height: 0 !important;
    }

    /* Panneaux glissants : pleine largeur */
    .admin-panel,
    .doc-library-panel,
    .dashboard-panel,
    .usage-panel { width: 100vw !important; }

    /* Panneau infos client : caché sur mobile (trop étroit) — SAUF ouvert en tiroir
       plein écran (app.css) : sans :not(.open), ce !important battait silencieusement
       la règle .open et les styles inline → Infos/Contacts inaccessibles au tap. */
    .ccc-info-sidebar:not(.open) { display: none !important; }
    .ccc-info-sidebar.open { display: block !important; }

    /* iOS zoome automatiquement sur tout champ < 16px au focus (et casse le layout) */
    input, select, textarea { font-size: 16px !important; }

    /* Tables : scroll horizontal */
    .md-table-wrapper { -webkit-overflow-scrolling: touch; }
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message {
    animation: fadeIn 0.2s ease-out;
}

/* Style pour le conteneur admin (padding seulement, pas de contrainte de largeur) */
.container {
    padding: 0;
}

/* ── Plan / Table of contents ──────────────────────────── */
.main-content {
    position: relative;
    transition: padding-right .22s cubic-bezier(.4,0,.2,1);
}
.main-content.toc-open { padding-right: 220px; }

#toc-sidebar {
    position: absolute;
    top: 0; right: 0; bottom: 0;
    width: 220px;
    background: var(--background-color);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 1001;
    transform: translateX(100%);
    transition: transform .22s cubic-bezier(.4,0,.2,1);
    pointer-events: none;
}
#toc-sidebar.open {
    transform: translateX(0);
    pointer-events: auto;
}
#toc-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border-color);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--text-secondary);
    flex-shrink: 0;
}
#toc-close-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 16px;
    color: var(--text-secondary);
    line-height: 1;
    padding: 0 2px;
    opacity: .5;
    transition: opacity .15s;
}
#toc-close-btn:hover { opacity: 1; }
#toc-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
    position: relative;
}
/* Indicateur glissant */
#toc-indicator {
    position: absolute;
    left: 0;
    width: 2px;
    background: var(--primary-color);
    border-radius: 1px;
    opacity: 0;
    pointer-events: none;
    transition: top .2s cubic-bezier(.4,0,.2,1), height .2s cubic-bezier(.4,0,.2,1), opacity .15s;
}
#toc-indicator.visible { opacity: 1; }
.toc-empty {
    padding: 16px 14px;
    font-size: 12px;
    color: var(--text-secondary);
    opacity: .55;
    line-height: 1.5;
}
.toc-item {
    display: flex;
    align-items: baseline;
    gap: 7px;
    padding: 4px 12px 4px 14px;
    font-size: 12px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: color .15s, background .15s;
    line-height: 1.4;
    border-radius: 6px;
}
.toc-item:hover {
    background: rgba(var(--primary-rgb),.06);
    color: var(--primary-color);
}
.toc-item.active {
    color: var(--primary-color);
    font-weight: 600;
    background: rgba(var(--primary-rgb),.08);
}
.toc-bullet { flex: 0 0 auto; opacity: .5; font-size: 10px; }
.toc-item.active .toc-bullet { opacity: 1; color: var(--primary-color); }
.toc-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Question = en-tête d'échange : badge « Q1 » + intitulé (jusqu'à 2 lignes), nettement
   séparé du groupe précédent → on repère d'un coup d'œil où commence chaque échange. */
.toc-question {
    align-items: flex-start;
    gap: 8px;
    margin-top: 12px;
    padding: 7px 12px;
    font-weight: 600;
    color: var(--text-primary);
}
.toc-question:first-of-type { margin-top: 2px; }
.toc-q-badge {
    flex: 0 0 auto;
    font-size: 10px;
    font-weight: 700;
    color: #fff;
    background: var(--primary-color);
    border-radius: 5px;
    padding: 1px 6px;
    letter-spacing: .02em;
}
.toc-q-text {
    flex: 1; min-width: 0;
    font-size: 12px;
    line-height: 1.35;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.toc-question.active { background: rgba(var(--primary-rgb),.10); }

/* Titres de la réponse : indentés sous leur question, reliés par un liseré vertical. */
.toc-answer-group {
    margin: 2px 0 2px 20px;
    border-left: 1.5px solid rgba(var(--primary-rgb),.20);
    padding-left: 2px;
}
.toc-h1 { font-size: 12px; font-weight: 600; color: var(--text-primary); }
.toc-h1.active { color: var(--primary-color); }
.toc-h2 { padding-left: 20px; font-size: 11.5px; }
.toc-h3 { padding-left: 32px; font-size: 11px; opacity: .8; }