/* =========================================================
   🎨 Bubblai – CSS Principal (Extrait de l'index original)
   Auteur : Nicolas Vuillier
   Version : Monolithique (sera découpé si nécessaire)
   ========================================================= */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

/* ======================= HIÉRARCHIE Z-INDEX =======================
 * z-index 0: Arrière-plans et éléments de base
 * z-index 1: Connexions (lignes SVG)
 * z-index 10: Bulles satellites et boutons d'ajout
 * z-index 15-20: Tooltips et éléments flottants
 * z-index 30-40: Modales et overlays
 * z-index 1000+: Éléments critiques (notifications, etc.)
 * ================================================================ */

:root {
    --primary: #00D4FF;
    --secondary: #FF6B6B;
    --accent: #4ECDC4;
    --bg-primary: #0A0E1A;
    --bg-secondary: #1A1F2E;
    --bg-tertiary: #252B3D;
    --text-primary: #FFFFFF;
    --text-secondary: #B0B7C3;
    --text-muted: #6B7280;
    --border: rgba(255, 255, 255, 0.1);
    --success: #10B981;
    --warning: #F59E0B;
    --danger: #EF4444;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
}

.bg-animation {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    opacity: 0.1;
}

.bg-animation::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at 20% 80%, var(--primary) 0%, transparent 50%),
                radial-gradient(circle at 80% 20%, var(--accent) 0%, transparent 50%),
                radial-gradient(circle at 40% 40%, var(--secondary) 0%, transparent 50%);
    animation: pulse 4s ease-in-out infinite alternate;
}

@keyframes pulse {
    0% { opacity: 0.05; transform: scale(1); }
    100% { opacity: 0.15; transform: scale(1.1); }
}

@keyframes float-bubble {
    0%   { transform: translate(-50%, -50%) translateY(0px) scale(1); }
    50%  { transform: translate(-50%, -50%) translateY(-14px) scale(1.04); }
    100% { transform: translate(-50%, -50%) translateY(0px) scale(1); }
}

/* Effet de petites bulles flottantes */
.floating-bubbles {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
}

.particle {
    position: absolute;
    border-radius: 50%;
    pointer-events: none;
    will-change: transform, opacity, filter;
    background: rgba(255, 255, 255, 0.18);
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 0 8px rgba(255, 255, 255, 0.05);
}

/* Quand le sidebar droit est ouvert : abaisser le workspace pour qu'il ne
   déborde pas sur le sidebar (problème stacking context mobile/Safari) */
body:has(#rightSidebar.open) .workspace {
    z-index: 0;
}

.workspace {
    position: relative;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    z-index: 1;
    touch-action: none; /* pas de scroll sur cette page — permet drag bulle sans interférence navigateur */
}

.center-bubble {
    position: absolute;
    left: 50%;
    top: 44%;
    transform: translate(-50%, -50%);
    width: 120px;
    height: 120px;
    background: linear-gradient(135deg, rgba(0, 212, 255, 0.3) 0%, rgba(78, 205, 196, 0.3) 100%), 
                linear-gradient(135deg, rgba(26, 31, 46, 0.98) 0%, rgba(37, 43, 61, 0.98) 100%);
    border: 2px solid rgba(0, 212, 255, 0.3);
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    font-weight: 700;
    font-size: 12px;
    cursor: pointer;
    box-shadow: 0 20px 60px rgba(0, 212, 255, 0.2),
                inset 0 1px 0 rgba(255, 255, 255, 0.2);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 10;
    text-align: center;
    padding: 8px;
    outline: none;
}

.center-bubble .agent-icon {
    font-size: 32px;
    line-height: 1;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border-radius: 8px;
}

.center-bubble .agent-icon img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 8px;
}

.center-bubble .agent-name {
    font-size: 12px;
    font-weight: 700;
    line-height: 1.2;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Quand il n'y a pas d'icône, centrer le nom */
.center-bubble.no-icon {
    justify-content: center;
    gap: 0;
}

.center-bubble.no-icon .agent-icon {
    display: none;
}

/* Quand une image est définie : elle remplit toute la bulle circulaire */
.center-bubble.has-bg-image {
    padding: 0;
    gap: 0;
    overflow: visible;
    border: 2px solid rgba(0, 212, 255, 0.5);
}

.center-bubble.has-bg-image .agent-icon {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    overflow: hidden;
}

.center-bubble.has-bg-image .agent-icon img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
    display: block;
}

.center-bubble.has-bg-image .agent-name {
    position: absolute;
    top: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    white-space: nowrap;
    background: none;
    color: var(--text-primary, #e8eaf6);
    font-size: 11px;
    font-weight: 700;
    text-shadow: 0 1px 4px rgba(0,0,0,0.8);
    text-align: center;
    z-index: 1300;
    pointer-events: none;
}

.center-bubble:hover {
    transform: translate(-50%, -50%) scale(1.05);
    box-shadow: 0 25px 80px rgba(0, 212, 255, 0.4),
                inset 0 1px 0 rgba(255, 255, 255, 0.3);
    border-color: rgba(0, 212, 255, 0.5);
}

.center-bubble::before {
    content: '';
    position: absolute;
    inset: -2px;
    border-radius: 50%;
    background: conic-gradient(from 0deg, var(--primary), var(--accent), var(--secondary), var(--primary));
    z-index: -1;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.center-bubble:hover::before {
    opacity: 0.6;
    animation: rotate 2s linear infinite;
}

@keyframes rotate {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.satellite {
    position: absolute;
    width: 80px;
    height: 80px;
    background: linear-gradient(135deg, rgba(26, 31, 46, 0.98) 0%, rgba(37, 43, 61, 0.98) 100%);
    border: 1px solid var(--border);
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 9px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 10;
    min-width: 60px;
    min-height: 60px;
    max-width: 105px;
    max-height: 105px;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.satellite[style*="width: 60px"] {
    font-size: 8px;
}

.satellite[style*="width: 75px"] {
    font-size: 9px;
}

.satellite[style*="width: 90px"] {
    font-size: 10px;
}

.satellite[style*="width: 105px"] {
    font-size: 11px;
    z-index: 10;
    text-align: center;
    padding: 8px;
    gap: 4px;
    outline: none;
}

.satellite .logo {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.satellite .logo svg {
    width: 100%;
    height: 100%;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.5;
}

/* Exception pour l'icône mémoire : toujours blanche */
.satellite[data-type="memoire"] .logo svg {
    stroke: white !important;
}

.satellite .logo i {
    font-size: 18px;
}

.satellite .label {
    font-size: 8px;
    opacity: 0.9;
    font-weight: 500;
    line-height: 1.1;
    text-align: center;
}

.satellite:hover {
    transform: scale(1.1);
    border-color: var(--primary);
    box-shadow: 0 15px 40px rgba(0, 212, 255, 0.3);
    background: linear-gradient(135deg, rgba(0, 212, 255, 0.15) 0%, rgba(78, 205, 196, 0.15) 100%),
                linear-gradient(135deg, rgba(26, 31, 46, 1) 0%, rgba(37, 43, 61, 1) 100%);
}

.satellite.role1 { border-color: #00ffb6; }
.satellite.documents { border-color: #FFB84D; }
.satellite.memoire { border-color: #9B59B6; }
.satellite.projets { border-color: #E74C3C; }
.satellite.instruction1 { border-color: #2ECC71; }
.satellite.directive1 { border-color: #3498DB; }
.satellite.voix { border-color: #F39C12; }
.satellite.image { border-color: #ffffff; }
.satellite.video { border-color: #ff0061; }
.satellite.action { border-color: #1ABC9C; }
.satellite.custom { border-color: #95A5A6; }
.satellite.connecteur { border-color: #6B46C1; }
.satellite.communication { border-color: #EF4444; }
.satellite.web { border-color: #0EA5E9; }
.satellite.code { border-color: #6C757D; }

.satellite::before {
    content: '';
    position: absolute;
    inset: -2px;
    border-radius: 50%;
    z-index: -1;
    opacity: 0.25;
    transition: opacity 0.3s ease;
    background: radial-gradient(circle, rgba(0, 212, 255, 0.4) 0%, rgba(78, 205, 196, 0.2) 50%, transparent 100%);
    filter: blur(7px);
}

.satellite:hover::before {
    opacity: 0.6;
    animation: rotate 2s linear infinite;
}

.satellite.dragging {
    transform: scale(1.05);
    transition: none !important;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    z-index: 100;
    background: linear-gradient(135deg, rgba(26, 31, 46, 1) 0%, rgba(37, 43, 61, 1) 100%);
}

/* ==================== TOOLTIP POUR BULLES ==================== */
.bubble-tooltip {
    position: absolute;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 50px;
    padding: 16px 20px;
    max-width: 320px;
    min-width: 240px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3);
    z-index: 10000;
    opacity: 0;
    transform: translateY(5px);
    transition: all 0.15s ease;
    pointer-events: none;
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    font-size: 0.85rem;
    line-height: 1.4;
}

.bubble-tooltip.show {
    opacity: 1;
    transform: translateY(0);
}

.bubble-tooltip::before {
    content: '';
    position: absolute;
    top: -6px;
    left: 50%;
    transform: translateX(-50%);
    width: 12px;
    height: 12px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-bottom: none;
    border-right: none;
    transform: translateX(-50%) rotate(45deg);
}

.bubble-tooltip .tooltip-title {
    font-weight: 600;
    color: var(--primary);
    margin-bottom: 6px;
    font-size: 0.9rem;
}

.bubble-tooltip .tooltip-content {
    color: var(--text-secondary);
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    -webkit-box-orient: vertical;
}

.bubble-tooltip .tooltip-type {
    font-size: 0.75rem;
    color: var(--text-muted);
    opacity: 0.7;
    margin-top: 4px;
    font-style: italic;
}

.satellite.dragging::before {
    opacity: 0.8;
    animation: rotate 1s linear infinite;
}

.satellite {
    cursor: grab;
}

.satellite:active {
    cursor: grabbing;
}

/* Tooltip pour aperçu de contenu */
.bubble-tooltip {
    position: absolute;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 50px;
    padding: 16px 20px;
    max-width: 320px;
    min-width: 240px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3);
    z-index: 10000;
    opacity: 0;
    transform: translateY(5px);
    transition: all 0.15s ease;
    pointer-events: none;
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    font-size: 0.85rem;
    line-height: 1.4;
}

.bubble-tooltip.show {
    opacity: 1;
    transform: translateY(0);
}

.bubble-tooltip::before {
    content: '';
    position: absolute;
    top: -6px;
    left: 50%;
    transform: translateX(-50%);
    width: 12px;
    height: 12px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-bottom: none;
    border-right: none;
    transform: translateX(-50%) rotate(45deg);
}

.bubble-tooltip .tooltip-title {
    font-weight: 600;
    color: var(--primary);
    margin-bottom: 6px;
    font-size: 0.9rem;
}

.bubble-tooltip .tooltip-content {
    color: var(--text-secondary);
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    -webkit-box-orient: vertical;
}

.bubble-tooltip .tooltip-type {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    opacity: 0.7;
    margin-top: 4px;
    font-style: italic;
}

.satellite.documents::before {
    background: conic-gradient(from 0deg, #FFB84D, #FF8C42, #FF6B35, #FFB84D);
}

.satellite.memoire::before {
    background: conic-gradient(from 0deg, #9B59B6, #8E44AD, #BB6BD9, #9B59B6);
}

.satellite.projets::before {
    background: conic-gradient(from 0deg, #fc0070, #e0ceda, #f18a95, #f1b9c3);
}

.satellite.instruction1::before {
    background: conic-gradient(from 0deg, #2ECC71, #27AE60, #58D68D, #2ECC71);
}

.satellite.role1::before {
    background: conic-gradient(from 0deg, #34dbda, #5aedff, #94ffe8, #34dbd0);
}

.satellite.directive1::before {
    background: conic-gradient(from 0deg, #3498DB, #2980B9, #5DADE2, #3498DB);
}

.satellite.voix::before {
    background: conic-gradient(from 0deg, #efff07, #ffeb00, #f1f871, #bdbe83);
}

.satellite.image::before {
    background: conic-gradient(from 0deg, #e8e8e8, #ffffff, #ffffff, #fffbf400);
}

[data-theme="light"] .satellite.image::before {
    background: conic-gradient(from 0deg, #c3ef50, #9ad403, #ffffff, #9ad403);
}

.satellite.video::before {
    background: conic-gradient(from 0deg, #ff0061, #ffbfdb, #ff0061, #ffbfdb, #ffbfdb);
}

[data-theme="light"] .satellite.video::before {
    background: conic-gradient(from 0deg, #ff0061, #ffbfdb, #ff0061, #ffbfdb, #ffbfdb);
}

.satellite.action::before {
    background: conic-gradient(from 0deg, #1ABC9C, #16A085, #48C9B0, #1ABC9C);
}

.satellite.custom::before {
    background: conic-gradient(from 0deg, #95A5A6, #7F8C8D, #BDC3C7, #95A5A6);
}

.satellite.connecteur::before {
    background: conic-gradient(from 0deg, #6B46C1, #553C9A, #8B5CF6, #6B46C1);
}

.satellite.communication::before {
    background: conic-gradient(from 0deg, #EF4444, #DC2626, #F87171, #EF4444);
}

.satellite.web::before {
    background: conic-gradient(from 0deg, #0EA5E9, #0284C7, #38BDF8, #0EA5E9);
}

.satellite.code::before {
    background: conic-gradient(from 0deg, #fffdfd, #141414, #000000, #000000);
}

.add-bubble {
    position: absolute;
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, var(--bg-tertiary) 0%, var(--bg-secondary) 100%);
    border: 2px dashed var(--border);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    cursor: pointer;
    transition: all 0.3s ease;
    z-index: 10;
    outline: none;
}

.add-bubble:hover {
    border-color: var(--primary);
    background: linear-gradient(135deg, rgba(0, 212, 255, 0.1) 0%, rgba(78, 205, 196, 0.1) 100%);
    transform: scale(1.05);
}

.connection {
    position: absolute;
    height: 2px;
    background: linear-gradient(90deg, var(--primary) 0%, var(--accent) 100%);
    transform-origin: left center;
    z-index: 1;
    opacity: 0.7;
    animation: pulse-line 2s ease-in-out infinite alternate;
    pointer-events: auto;
}

.connection.inactive {
    background: linear-gradient(90deg, var(--text-muted) 0%, var(--border) 100%);
    opacity: 0.3;
}

@keyframes pulse-line {
    0% { opacity: 0.7; }
    100% { opacity: 1; }
}

.connection::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 12px;
    height: 12px;
    background: var(--primary);
    border: 2px solid var(--bg-primary);
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 0 8px rgba(0, 212, 255, 0.6);
    animation: pulse-dot 2s ease-in-out infinite;
    z-index: 2;
}

.connection.inactive::after {
    content: '✕';
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: bold;
    color: #ffffff;
    background: var(--bg-secondary);
    border: 2px solid rgba(255, 255, 255, 0.3);
    box-shadow: none;
    animation: none;
}

.connection::after:hover {
    transform: translate(-50%, -50%) scale(1.3);
    box-shadow: 0 0 12px rgba(0, 212, 255, 0.8);
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

.sidebar-left {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: 300px;
    background: linear-gradient(180deg, var(--bg-secondary) 0%, var(--bg-tertiary) 100%);
    -webkit-backdrop-filter: blur(20px);
    backdrop-filter: blur(20px);
    border-right: 1px solid var(--border);
    transform: translateX(-100%);
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1300;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--primary) var(--bg-tertiary);
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.sidebar-left::-webkit-scrollbar {
    width: 8px;
}

.sidebar-left::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
    border-radius: 4px;
}

.sidebar-left::-webkit-scrollbar-thumb {
    background: var(--primary);
    border-radius: 4px;
    transition: background 0.3s ease;
}

.sidebar-left::-webkit-scrollbar-thumb:hover {
    background: var(--accent);
}

.sidebar-left.open {
    transform: translateX(0);
    box-shadow: 20px 0 40px rgba(0, 0, 0, 0.3);
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.sidebar-header h3 {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
    user-select: none;
}

.sidebar-close-btn {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    font-size: 16px;
    cursor: pointer;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.sidebar-close-btn:hover {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
    transform: translateX(-2px);
}

.close-sidebar-btn {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    font-size: 16px;
    cursor: pointer;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.close-sidebar-btn:hover {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
    transform: translateX(2px);
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 15px 20px;
    margin: 4px 12px;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 14px;
    font-weight: 500;
    color: #ffffff;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.menu-item:hover {
    background: rgba(0, 212, 255, 0.1);
    transform: translateX(4px);
}

.menu-item .icon {
    font-size: 18px;
}

/* Icône Custom en vert vif */
.menu-item[data-type="custom"] .icon {
    filter: hue-rotate(100deg) saturate(2) brightness(1.3);
}

.sidebar-right {
    position: fixed;
    right: 0;
    top: 0;
    bottom: 0;
    width: 340px;
    background: linear-gradient(180deg, var(--bg-secondary) 0%, var(--bg-tertiary) 100%);
    -webkit-backdrop-filter: blur(20px);
    backdrop-filter: blur(20px);
    border-left: 1px solid var(--border);
    transform: translateX(100%);
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1300;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    scrollbar-width: thin;
    scrollbar-color: var(--primary) var(--bg-tertiary);
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.sidebar-right::-webkit-scrollbar {
    width: 8px;
}

.sidebar-right::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
    border-radius: 4px;
}

.sidebar-right::-webkit-scrollbar-thumb {
    background: var(--primary);
    border-radius: 4px;
    transition: background 0.3s ease;
}

.sidebar-right::-webkit-scrollbar-thumb:hover {
    background: var(--accent);
}

.sidebar-right.open {
    transform: translateX(0);
    box-shadow: -20px 0 40px rgba(0, 0, 0, 0.3);
}

/* Cacher le bouton agents FAB quand le sidebar droit est ouvert
   (le sidebar a son propre bouton fermer, le FAB flottant par-dessus est gênant) */
.sidebar-right.open ~ button.fab.agents {
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}
button.fab.agents {
    transition: opacity 0.3s ease, transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.3s ease;
}

.agents-content {
    flex: 1;
    overflow-y: auto;
    padding: 0;
    scrollbar-width: thin;
    scrollbar-color: var(--primary) var(--bg-tertiary);
}

.agents-content::-webkit-scrollbar {
    width: 8px;
}

.agents-content::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
    border-radius: 4px;
}

.agents-content::-webkit-scrollbar-thumb {
    background: var(--primary);
    border-radius: 4px;
    transition: background 0.3s ease;
}

.agents-content::-webkit-scrollbar-thumb:hover {
    background: var(--accent);
}

#bulleThequeBody {
    max-height: 70vh;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--primary) var(--bg-tertiary);
}

#bulleThequeBody::-webkit-scrollbar {
    width: 8px;
}

#bulleThequeBody::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
    border-radius: 4px;
}

#bulleThequeBody::-webkit-scrollbar-thumb {
    background: var(--primary);
    border-radius: 4px;
    transition: background 0.3s ease;
}

#bulleThequeBody::-webkit-scrollbar-thumb:hover {
    background: var(--accent);
}

.agent-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    margin: 8px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 12px;
    transition: all 0.3s ease;
    position: relative;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.agent-item:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(0, 212, 255, 0.2);
}

.agent-item.active {
    border-color: var(--primary);
    background: linear-gradient(135deg, rgba(0, 212, 255, 0.1) 0%, rgba(78, 205, 196, 0.1) 100%);
}

.agent-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background: var(--primary);
    border-radius: 0 4px 4px 0;
}

.agent-info {
    flex: 1;
}

.agent-name {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.agent-name span:first-child {
    font-size: 24px;
    line-height: 1;
}

.agent-status {
    font-size: 12px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
    animation: pulse-status 2s ease-in-out infinite;
}

.status-indicator.inactive {
    background: var(--text-muted);
    animation: none;
}

@keyframes pulse-status {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.agent-actions {
    display: flex;
    gap: 4px;
    align-items: center;
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.agent-item:hover .agent-actions,
.agent-item.active .agent-actions,
.agent-item.show-actions .agent-actions {
    opacity: 1;
    pointer-events: auto;
}

.action-btn {
    width: 25px;
    height: 25px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    font-size: 11px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.action-btn:hover {
    border-color: var(--primary);
    background: rgba(0, 212, 255, 0.1);
    color: var(--primary);
}

.action-btn.danger:hover {
    border-color: var(--danger);
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
}

.agent-form {
    padding: 20px;
    border-top: 1px solid var(--border);
    background: var(--bg-tertiary);
}

.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-input {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 14px;
    transition: all 0.3s ease;
}

.form-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(0, 212, 255, 0.1);
}

.form-textarea {
    resize: vertical;
    min-height: 80px;
}

/* Textarea rôle : hauteur confortable sur desktop */
#editRoleModal #roleModalContent {
    min-height: 240px;
}

.agent-type-selector {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 8px;
}

.type-option {
    padding: 12px 8px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-secondary);
    cursor: pointer;
    text-align: center;
    font-size: 12px;
    transition: all 0.3s ease;
}

.type-option:hover, .type-option.selected {
    border-color: var(--primary);
    background: rgba(0, 212, 255, 0.1);
}

button.fab, a.fab {
    position: fixed;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
    box-shadow: 0 8px 25px rgba(0, 212, 255, 0.4);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 15;
}

button.fab:hover, a.fab:hover {
    transform: scale(1.1);
    box-shadow: 0 12px 35px rgba(0, 212, 255, 0.6);
}

.fab.menu {
    top: 20px;
    left: 20px;
}

.fab.settings {
    top: 80px;
    left: 20px;
}

button.fab i, a.fab i {
    color: white;
    font-size: 20px;
}

.fab.agents {
    top: 20px;
    right: 20px;
}

.fab.chat {
    top: 140px;
    left: 20px;
    bottom: auto;
    transform: none;
    width: 44px;
    height: 44px;
    font-size: 24px;
    text-decoration: none;
    display: flex;
    align-items: center;
    justify-content: center;
}

.fab.avatar {
    bottom: 80px;
    left: calc(50% + 80px);
    transform: translateX(-50%);
    width: 44px;
    height: 44px;
    font-size: 24px;
    text-decoration: none;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    box-shadow: 0 4px 20px rgba(102, 126, 234, 0.4);
}

.fab.voice-btn {
    bottom: 80px;
    right: 20px;
    background: linear-gradient(135deg, #00D4FF 0%, #0099CC 100%);
    box-shadow: 0 8px 32px rgba(0, 212, 255, 0.3);
    z-index: 9999 !important;
}

.fab.voice-btn:hover {
    background: linear-gradient(135deg, #33DDFF 0%, #00AADD 100%);
    transform: scale(1.05);
    box-shadow: 0 12px 40px rgba(0, 212, 255, 0.4);
}

.fab.voice-stop-btn {
    bottom: 80px;
    right: 90px;
    background: linear-gradient(135deg, #e74c3c 0%, #c0392b 100%);
    width: 56px;
    height: 56px;
    font-size: 20px;
    z-index: 9999 !important;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn {
    padding: 10px 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn:hover {
    border-color: var(--primary);
    background: rgba(0, 212, 255, 0.1);
}

.btn.primary {
    background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
    border-color: var(--primary);
    color: white;
}

.btn.success {
    background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
    border-color: #28a745;
    color: white;
}

.btn.success:hover {
    background: linear-gradient(135deg, #218838 0%, #1c7a60 100%);
    border-color: #1e7e34;
}

.btn.outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
}

.btn.outline:hover {
    background: var(--bg-secondary);
    border-color: var(--primary);
}

.btn.small {
    padding: 6px 12px;
    font-size: 12px;
}

/* 📷 Modal galerie : dimensions desktop */
.media-gallery-content {
    width: min(1400px, 92vw);
    max-width: 92vw;
    height: 90vh;
    max-height: 90vh;
}

/* ⚠️ Surcharge .modal-content générique (min(500px,90vw)) pour la galerie */
#mediaLibraryModal .modal-content,
#mediaLibraryModal .media-gallery-content {
    width: min(1400px, 92vw) !important;
    max-width: 92vw !important;
}

/* 📷 Desktop : galerie sans padding-bottom du FAB */
#mediaLibraryModal {
    padding-bottom: 0 !important;
    align-items: center;
    justify-content: center;
}

/* 📷 Grille galerie desktop : colonnes dynamiques (min 200px → ~4-6 colonnes sur grand écran) */
@media (min-width: 769px) {
    #mediaLibraryGrid {
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)) !important;
        gap: 16px !important;
    }
}

.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 10001; /* Au-dessus de tous les autres éléments */
    padding-bottom: 80px;
    /* isolation: isolate empêche ce modal de créer un stacking context
       qui bloquerait les modaux enfants/frères ayant un z-index supérieur */
    isolation: isolate;
}

/* Modal secondaire (clés API, confirmation, etc.) :
   doit toujours apparaître AU-DESSUS du modal de paramètres.
   backdrop-filter: none évite la création d'un stacking context concurrent. */
#apiKeysManagerModal {
    z-index: 10010 !important;
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    background: rgba(0, 0, 0, 0.85) !important;
    isolation: auto !important;
}

.modal.open {
    display: flex;
}

.modal-content {
    width: min(500px, 90vw);
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 0 25px 80px rgba(0, 0, 0, 0.5);
    animation: modal-in 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes modal-in {
    0% { opacity: 0; transform: scale(0.9) translateY(20px); }
    100% { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
    padding: 20px;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(135deg, var(--bg-tertiary) 0%, var(--bg-secondary) 100%);
}

.modal-header h4 {
    font-size: 16px;
    font-weight: 600;
    margin: 0;
}

.modal-body {
    padding: 20px;
}

.modal-footer {
    padding: 0 20px 20px;
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

.notification {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 16px 20px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    z-index: 40;
    max-width: 300px;
    animation: notification-in 0.3s ease;
    transition: all 0.3s ease;
}

.notification.success {
    border-color: var(--success);
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.1) 0%, var(--bg-secondary) 100%);
}

.notification.error {
    border-color: var(--danger);
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.1) 0%, var(--bg-secondary) 100%);
}

@keyframes notification-in {
    0% { opacity: 0; transform: translateX(100%); }
    100% { opacity: 1; transform: translateX(0); }
}

@media (max-width: 768px) {
    /* 📱 Layout mobile global (on garde les modales classiques centrées) */

    /* 📱 Modales scrollables sur mobile : le body scroll, header + footer restent fixes */
    .modal {
        align-items: flex-start;
        padding: 16px;
        padding-bottom: 16px;
        box-sizing: border-box;
    }

    .modal-content {
        width: 100% !important;
        max-width: 100% !important;
        max-height: calc(100dvh - 32px);
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    .modal-body {
        flex: 1 1 auto;
        min-height: 0;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .modal-footer {
        flex-shrink: 0;
    }

    .sidebar-left, .sidebar-right {
        width: 280px;
        /* S'assurer que la hauteur utile couvre bien tout l'écran */
        top: 0;
        bottom: 0;
        max-height: 100vh;
    }

    /* Contenu de la sidebar gauche : permettre le scroll complet sur mobile */
    .sidebar-left {
        padding-bottom: 24px; /* petit espace pour voir le dernier item */
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .center-bubble {
        /* Bulle centrale un peu plus grande en mobile pour bien comparer */
        width: 90px;
        height: 90px;
    }
    
    .satellite {
        font-size: 8px;
        z-index: 10;
    /* 🔒 Taille max des bulles satellites en mobile (réduite ~15%) */
    max-width: 75px;
    max-height: 75px;
    }

    .satellite .logo {
        font-size: 20px;
    }

    .satellite .label {
        font-size: 7px;
        text-align: center;
    }

    /* 📱 Réduire les FAB buttons sur mobile (-30%) */
    button.fab, a.fab {
        width: 32px !important;
        height: 32px !important;
        font-size: 14px !important;
    }
    
    button.fab svg, a.fab svg {
        width: 16px !important;
        height: 16px !important;
    }
    
    button.fab i, a.fab i {
        font-size: 14px !important;
    }
    
    .fab.menu {
        top: 12px !important;
        left: 12px !important;
    }
    
    .fab.settings {
        top: 56px !important;
        left: 12px !important;
    }
    
    .fab.agents {
        top: 12px !important;
        right: 12px !important;
    }
    
    .fab.chat {
        top: 100px !important;
        left: 12px !important;
        bottom: auto !important;
        transform: none !important;
    }

    /* 📱 FIX: Zone de texte principale ne doit pas passer devant les menus sur mobile */
    #mainPrompt {
        position: relative !important;
        z-index: 1 !important;
    }
    
    /* Le conteneur de l'input doit avoir un z-index très bas sur mobile */
    body > div[style*="position: fixed"][style*="bottom: 30px"] {
        z-index: 10 !important;
    }
    
    /* Forcer aussi pour le conteneur parent direct */
    div[style*="z-index: 10"] {
        z-index: 10 !important;
    }

    .floating-bubbles .particle {
        transform: scale(0.4) !important;
        opacity: 0.6 !important;
    }
    
    .floating-bubbles .particle[style*="width: 2"],
    .floating-bubbles .particle[style*="width: 3"] {
        transform: scale(0.35) !important;
        opacity: 0.5 !important;
    }
    
    .floating-bubbles .particle[style*="width: 1"] {
        transform: scale(0.4) !important;
    }
    
    .floating-bubbles .particle[style*="width: 8px"],
    .floating-bubles .particle[style*="width: 9px"],
    .floating-bubbles .particle[style*="width: 10px"],
    .floating-bubbles .particle[style*="width: 11px"],
    .floating-bubbles .particle[style*="width: 12px"],
    .floating-bubbles .particle[style*="width: 13px"],
    .floating-bubbles .particle[style*="width: 14px"] {
        transform: scale(0.5) !important;
    }

    /* 📱 editInstructionModal : flex column, footer toujours visible — même pattern que settingsModal */
    #editInstructionModal {
        align-items: stretch !important;
        justify-content: stretch !important;
        padding: 0 !important;
        padding-bottom: 0 !important;
    }

    #editInstructionModal .modal-content {
        width: 100vw !important;
        max-width: 100vw !important;
        height: 100dvh !important;
        max-height: 100dvh !important;
        border-radius: 0 !important;
        margin: 0 !important;
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;
    }

    #editInstructionModal .modal-header {
        flex-shrink: 0 !important;
    }

    #editInstructionModal .modal-body {
        flex: 1 1 auto !important;
        min-height: 0 !important;
        max-height: none !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
        padding: 15px !important;
    }

    #editInstructionModal .modal-footer {
        flex-shrink: 0 !important;
        background: linear-gradient(180deg, rgba(10,14,26,0.85) 0%, rgba(10,14,26,1) 40%);
        padding: 12px 16px max(24px, env(safe-area-inset-bottom)) !important;
        display: flex !important;
        gap: 12px !important;
        justify-content: flex-end !important;
        z-index: 10;
    }

    /* 📱 codeModal : pattern uniforme, footer toujours visible */
    #codeModal .modal-content {
        width: min(600px, 92vw) !important;
        height: min(88vh, 90vh) !important;
        max-height: unset !important;
        border-radius: 12px !important;
        overflow: hidden !important;
        display: flex !important;
        flex-direction: column !important;
    }

    #codeModal .modal-header {
        flex-shrink: 0 !important;
    }

    #codeModal .modal-body {
        flex: 1 1 auto !important;
        min-height: 0 !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }

    #codeModal #codeEditor {
        min-height: 200px !important;
        resize: none !important;
    }

    #codeModal .modal-footer {
        flex-shrink: 0 !important;
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 8px !important;
        justify-content: flex-end !important;
    }

    /* 📱 Paramètres : pattern uniforme, footer toujours visible */
    #settingsModal .modal-content {
        width: min(680px, 92vw) !important;
        height: min(88dvh, 90dvh) !important;
        max-height: unset !important;
        border-radius: 12px !important;
        overflow: hidden !important;
        display: flex !important;
        flex-direction: column !important;
    }

    #settingsModal .modal-header {
        flex-shrink: 0 !important;
    }

    #settingsModal .modal-body {
        flex: 1 1 auto !important;
        min-height: 0 !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
        overscroll-behavior: contain !important;
    }

    #settingsModal .modal-footer {
        flex-shrink: 0 !important;
        display: flex !important;
        gap: 12px !important;
        justify-content: flex-end !important;
        border-top: 1px solid var(--border) !important;
        background: var(--bg-secondary) !important;
        padding: 12px 20px !important;
    }

    /* 📱 Gestion clés API : même pattern que settingsModal */
    #apiKeysManagerModal .modal-content {
        width: 100vw !important;
        max-width: 100vw !important;
        height: 100dvh !important;
        max-height: 100dvh !important;
        border-radius: 0 !important;
        overflow: hidden !important;
        display: flex !important;
        flex-direction: column !important;
    }

    #apiKeysManagerModal {
        padding: 0 !important;
        align-items: stretch !important;
        justify-content: stretch !important;
    }

    #apiKeysManagerModal .modal-header {
        flex-shrink: 0 !important;
        border-bottom: 1px solid var(--border) !important;
    }

    #apiKeysManagerModal .modal-body {
        flex: 1 1 auto !important;
        min-height: 0 !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
        overscroll-behavior: contain !important;
        padding: 16px !important;
    }

    #apiKeysManagerModal .modal-footer {
        flex-shrink: 0 !important;
        display: flex !important;
        gap: 12px !important;
        justify-content: flex-end !important;
        padding: 12px 16px !important;
        border-top: 1px solid var(--border) !important;
        background: var(--bg-secondary) !important;
    }

    /* 📱 Modal galerie : responsive élégant sur mobile portrait */
    #mediaLibraryModal {
        padding: 16px !important;
        padding-bottom: 24px !important;
        align-items: center !important;
        justify-content: center !important;
    }

    #mediaLibraryModal .media-gallery-content,
    #mediaLibraryModal .modal-content {
        width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
        max-height: 92vh !important;
        min-height: 60vh !important;
        border-radius: 16px !important;
        margin: 0 !important;
        box-sizing: border-box !important;
        overflow: hidden !important;
        display: flex !important;
        flex-direction: column !important;
    }

    #mediaLibraryModal .modal-header {
        flex-shrink: 0;
    }

    #mediaLibraryModal .modal-body {
        flex: 1 !important;
        min-height: 0 !important;
        max-height: none !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
    }

    /* 📱 Grille galerie : 2 colonnes sur mobile portrait */
    #mediaLibraryGrid {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    /* 📱 Modal d'édition/création d'agent (centerAgentModal) en plein écran mobile */
    #centerAgentModal {
        align-items: stretch !important;
        justify-content: stretch !important;
        padding: 0 !important;
        padding-bottom: 0 !important;
    }

    #centerAgentModal .modal-content {
        width: 100vw !important;
        max-width: 100vw !important;
        height: 100dvh !important;
        max-height: 100dvh !important;
        border-radius: 0 !important;
        margin: 0 !important;
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;
        padding-bottom: env(safe-area-inset-bottom, 0px) !important;
    }

    #centerAgentModal .modal-header {
        flex-shrink: 0 !important;
    }

    #centerAgentModal .modal-body {
        flex: 1 1 auto !important;
        min-height: 0 !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }

    #centerAgentModal .modal-footer {
        flex-shrink: 0 !important;
        position: static !important;
        background: var(--bg-secondary) !important;
        border-top: 1px solid var(--border) !important;
        padding: 12px 16px !important;
        padding-bottom: max(20px, env(safe-area-inset-bottom, 20px)) !important;
        display: flex !important;
        gap: 12px !important;
        justify-content: space-between !important;
        flex-wrap: wrap !important;
        z-index: 1 !important;
    }

    /* 📱 Modal "Nouvel Agent" (#newAgentModal) — plein écran mobile (même pattern que centerAgentModal) */
    #newAgentModal {
        align-items: stretch !important;
        justify-content: stretch !important;
        padding: 0 !important;
        padding-bottom: 0 !important;
    }

    #newAgentModal .modal-content {
        width: 100vw !important;
        max-width: 100vw !important;
        height: 100dvh !important;
        max-height: 100dvh !important;
        border-radius: 0 !important;
        margin: 0 !important;
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;
        padding-bottom: env(safe-area-inset-bottom, 0px) !important;
    }

    #newAgentModal .modal-header {
        flex-shrink: 0 !important;
    }

    #newAgentModal .modal-body {
        flex: 1 1 auto !important;
        min-height: 0 !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }

    #newAgentModal .modal-footer {
        flex-shrink: 0 !important;
        position: static !important;
        background: var(--bg-secondary) !important;
        border-top: 1px solid var(--border) !important;
        padding: 12px 16px !important;
        padding-bottom: max(20px, env(safe-area-inset-bottom, 20px)) !important;
        display: flex !important;
        gap: 12px !important;
        justify-content: flex-end !important;
        z-index: 1 !important;
    }

    #newAgentModal .agent-type-selector {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    /* 📱 Modal Rôle : plein écran, header + footer fixes, body scrollable */
    #editRoleModal {
        align-items: stretch !important;
        justify-content: stretch !important;
        padding: 0 !important;
    }

    #editRoleModal .modal-content {
        width: 100vw !important;
        max-width: 100vw !important;
        height: 100dvh !important;
        max-height: 100dvh !important;
        border-radius: 0 !important;
        margin: 0 !important;
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;
        padding-bottom: env(safe-area-inset-bottom, 0px) !important;
    }

    #editRoleModal .modal-header {
        flex-shrink: 0 !important;
    }

    #editRoleModal .modal-body {
        flex: 1 1 auto !important;
        min-height: 0 !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }

    #editRoleModal .modal-footer {
        flex-shrink: 0 !important;
        position: static !important;
        background: var(--bg-secondary) !important;
        border-top: 1px solid var(--border) !important;
        padding: 12px 16px 20px !important;
        display: flex !important;
        gap: 10px !important;
        justify-content: flex-end !important;
    }

    /* Textarea rôle : compacte sur mobile pour que les exemples soient accessibles */
    #editRoleModal #roleModalContent {
        min-height: 100px !important;
        max-height: 180px !important;
        resize: none !important;
    }

    /* Assure le padding interne du body rôle sur mobile */
    #editRoleModal .modal-body {
        padding: 16px !important;
    }

    /* 📱 Barre d'input principale en bas : safe area + z-index corrigé */
    #mainPrompt {
        font-size: 16px !important; /* Évite le zoom iOS au focus */
    }

    /* Conteneur de la barre d'input principale */
    body > div[style*="bottom: 30px"] {
        bottom: max(16px, env(safe-area-inset-bottom, 16px)) !important;
        width: 96% !important;
        left: 2% !important;
        transform: none !important; /* Supprimer le translateX(-50%) problématique sur iOS */
        z-index: 20 !important; /* Au-dessus des FABs (z-index: 15) */
    }
}

/* 📱 Mode paysage sur petits écrans : pattern uniforme settingsModal */
@media (max-width: 1024px) and (orientation: landscape) {
    #settingsModal .modal-content {
        width: min(680px, 92vw) !important;
        height: min(88dvh, 90dvh) !important;
        max-height: unset !important;
        border-radius: 12px !important;
        overflow: hidden !important;
        display: flex !important;
        flex-direction: column !important;
    }

    #settingsModal .modal-header {
        flex-shrink: 0 !important;
    }

    #settingsModal .modal-body {
        flex: 1 1 auto !important;
        min-height: 0 !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
        overscroll-behavior: contain !important;
    }

    #settingsModal .modal-footer {
        flex-shrink: 0 !important;
        display: flex !important;
        gap: 12px !important;
        justify-content: flex-end !important;
        border-top: 1px solid var(--border) !important;
        background: var(--bg-secondary) !important;
        padding: 12px 20px !important;
    }

    /* 📱 Gestion clés API paysage : même pattern que settingsModal */
    #apiKeysManagerModal .modal-content {
        width: min(680px, 92vw) !important;
        height: min(88dvh, 90dvh) !important;
        max-height: unset !important;
        border-radius: 12px !important;
        overflow: hidden !important;
        display: flex !important;
        flex-direction: column !important;
    }

    #apiKeysManagerModal .modal-header {
        flex-shrink: 0 !important;
    }

    #apiKeysManagerModal .modal-body {
        flex: 1 1 auto !important;
        min-height: 0 !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
        overscroll-behavior: contain !important;
    }

    #apiKeysManagerModal .modal-footer {
        flex-shrink: 0 !important;
        display: flex !important;
        gap: 12px !important;
        justify-content: flex-end !important;
        border-top: 1px solid var(--border) !important;
        background: var(--bg-secondary) !important;
        padding: 12px 16px !important;
    }

    /* 📱 Modal galerie plein écran sur mobile (DOIT être APRÈS .modal générique) */
    #mediaLibraryModal {
        padding: 0 !important;
        padding-bottom: 0 !important;
        align-items: stretch !important;
        justify-content: stretch !important;
    }

    #mediaLibraryModal .media-gallery-content,
    #mediaLibraryModal .modal-content {
        width: 100vw !important;
        max-width: 100vw !important;
        height: 100vh !important;
        max-height: 100vh !important;
        border-radius: 0 !important;
        margin: 0 !important;
        box-sizing: border-box !important;
        overflow: hidden !important;
    }

    #mediaLibraryModal .modal-body {
        flex: 1 !important;
        min-height: 0 !important;
        max-height: none !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
    }

    /* 📱 Grille galerie : 2 colonnes sur mobile */
    #mediaLibraryGrid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

.bubble-actions-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
    padding: 16px 16px 90px 16px;
    box-sizing: border-box;
    /* Caché via visibility + opacity + pointer-events — plus fiable que display:none sur mobile */
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

.bubble-actions-modal.open {
    visibility: visible;
    opacity: 1;
    pointer-events: auto;
}

.bubble-actions-content {
    background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-tertiary) 100%);
    border: 1px solid var(--primary);
    border-radius: 20px;
    padding: 20px;
    max-width: 380px;
    width: 100%;
    box-sizing: border-box;
    box-shadow: 0 25px 80px rgba(0, 212, 255, 0.3);
    animation: bubble-actions-fade-in 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    text-align: center;
    overflow-y: auto;
    max-height: calc(100dvh - 120px);
}

@keyframes bubble-actions-fade-in {
    0% { 
        opacity: 0;
        transform: scale(0.9) translateY(20px);
    }
    100% { 
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.bubble-actions-header {
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.bubble-actions-header h4 {
    font-size: 18px;
    color: var(--text-primary);
    margin: 0 0 12px 0;
    font-weight: 600;
}

.bubble-actions-preview {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px 16px;
    font-size: 14px;
    font-weight: 500;
}

.bubble-actions-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.action-btn-bubble {
    padding: 14px 20px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.action-btn-bubble:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(0, 212, 255, 0.2);
}

.action-btn-bubble.edit {
    border-color: var(--primary);
}

.action-btn-bubble.edit:hover {
    background: rgba(0, 212, 255, 0.1);
    border-color: var(--primary);
    color: var(--primary);
}

.action-btn-bubble.save {
    border-color: var(--success);
}

.action-btn-bubble.save:hover {
    background: rgba(16, 185, 129, 0.1);
    border-color: var(--success);
    color: var(--success);
}

.action-btn-bubble.delete {
    border-color: var(--danger);
}

.action-btn-bubble.delete:hover {
    background: rgba(239, 68, 68, 0.1);
    border-color: var(--danger);
    color: var(--danger);
}

.action-btn-bubble.cancel {
    border-color: var(--text-muted);
    color: var(--text-muted);
}

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

@media (max-width: 480px) {
    .bubble-actions-content {
        padding: 16px 14px;
        border-radius: 16px;
        max-height: calc(100dvh - 100px);
    }

    .bubble-actions-header {
        margin-bottom: 14px;
        padding-bottom: 12px;
    }

    .bubble-actions-header h4 {
        font-size: 15px;
        margin: 0 0 8px 0;
    }

    .bubble-actions-preview {
        font-size: 12px;
        padding: 7px 12px;
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .bubble-actions-buttons {
        gap: 8px;
    }

    .action-btn-bubble {
        padding: 11px 16px;
        font-size: 13px;
    }
}

@media (hover: none) and (pointer: coarse) {
    .satellite {
        cursor: pointer;
    }
    
    .action-btn-bubble:hover {
        transform: none;
        box-shadow: none;
    }

    /* Sur touch, les actions mémoire sont toujours visibles (pas de hover) */
    .memory-actions {
        opacity: 1;
    }
}

.icon-library-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 11000;
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
}

.icon-library-modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 24px;
    max-width: 500px;
    width: 90%;
    max-height: 70vh;
    overflow: hidden;
    box-shadow: 0 25px 80px rgba(0, 0, 0, 0.55);
    -webkit-backdrop-filter: blur(16px);
    backdrop-filter: blur(16px);
}

.icon-library-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.icon-library-title {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 16px;
    margin: 0;
}

.icon-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 20px;
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    transition: all 0.2s ease;
}

.icon-close:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.icon-search {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 14px;
    margin-bottom: 16px;
}

.icon-search:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(0, 212, 255, 0.1);
}

.icon-categories {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.icon-category {
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.icon-category:hover,
.icon-category.active {
    background: var(--primary);
    color: #041018;
    border-color: var(--primary);
}

.icon-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(50px, 1fr));
    gap: 8px;
    max-height: 300px;
    overflow-y: auto;
    padding: 4px;
}

.icon-item {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 50px;
    height: 50px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-tertiary);
    cursor: pointer;
    font-size: 20px;
    transition: all 0.2s ease;
}

.icon-item svg {
    width: 24px;
    height: 24px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.5;
}

.icon-item i {
    font-size: 20px;
}

.icon-item:hover {
    background: var(--primary);
    border-color: var(--primary);
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(0, 212, 255, 0.3);
}

.icon-item.selected {
    background: var(--primary);
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(0, 212, 255, 0.4);
}

.icon-library-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 16px 0 0;
    margin-top: 16px;
    border-top: 1px solid var(--border);
}

.btn-cancel, .btn-validate {
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-secondary);
    color: var(--text);
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s ease;
}

.btn-cancel:hover {
    background: var(--bg-tertiary);
}

.btn-validate {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

.btn-validate:hover:not(:disabled) {
    background: #0099cc;
    transform: translateY(-1px);
}

.btn-validate:disabled {
    background: var(--bg-tertiary);
    border-color: var(--border);
    color: var(--text-secondary);
    cursor: not-allowed;
}

/* 📱 Optimisation mobile pour la bibliothèque d'icônes */
@media (max-width: 768px) {
    .icon-library-overlay {
        align-items: flex-end;
        justify-content: stretch;
        padding: 0;
    }

    .icon-library-modal {
        width: 100vw;
        max-width: 100vw;
        height: 92dvh;
        max-height: 92dvh;
        border-radius: 20px 20px 0 0;
        padding: 16px 16px 0 16px;
        box-sizing: border-box;
        display: flex;
        flex-direction: column;
        overflow: hidden;
        position: relative;
    }

    .icon-library-header {
        flex-shrink: 0;
    }

    .icon-search,
    .icon-categories {
        flex-shrink: 0;
    }

    .icon-grid {
        flex: 1 1 auto;
        min-height: 0;
        max-height: none;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        /* Espace en bas pour ne pas être masqué par le footer fixe (~70px) */
        padding-bottom: 80px;
    }

    .icon-library-footer {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        padding: 12px 16px max(16px, env(safe-area-inset-bottom));
        background: var(--bg-secondary);
        border-top: 1px solid var(--border);
        z-index: 12000;
        display: flex;
        justify-content: flex-end;
        gap: 12px;
    }
}

.app-header {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(135deg, rgba(26, 31, 46, 0.9) 0%, rgba(10, 14, 26, 0.9) 100%);
    -webkit-backdrop-filter: blur(15px);
    backdrop-filter: blur(15px);
    border: 1px solid rgba(0, 212, 255, 0.3);
    border-radius: 20px;
    padding: 15px 25px;
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    box-shadow: 0 8px 32px rgba(0, 212, 255, 0.15);
    /* Empêcher le header de s'étaler hors des FABs */
    max-width: calc(100vw - 120px);
    white-space: nowrap;
}

@media (max-width: 768px) {
    .app-header {
        top: 10px;
        padding: 8px 14px;
        border-radius: 14px;
        gap: 3px;
        /* Centré entre les deux colonnes de FABs (left: 56px, right: 56px) */
        max-width: calc(100vw - 130px);
    }

    .app-title {
        font-size: 13px !important;
        letter-spacing: 1px !important;
    }

    .current-agent {
        font-size: 10px !important;
        padding: 2px 8px !important;
    }
}

.app-title {
    font-family: 'Orbitron', sans-serif;
    font-size: 18px;
    font-weight: 900;
    background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin: 0;
    letter-spacing: 2px;
    text-transform: uppercase;
}

.current-agent {
    font-size: 12px;
    color: var(--text-secondary);
    padding: 3px 10px;
    background: rgba(0, 212, 255, 0.1);
    border-radius: 10px;
    border: 1px solid rgba(0, 212, 255, 0.2);
}

.header-settings-btn {
    position: absolute;
    right: -15px;
    top: 50%;
    transform: translateY(-50%);
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: linear-gradient(135deg, rgba(0, 212, 255, 0.2) 0%, rgba(78, 205, 196, 0.2) 100%);
    border: 1px solid rgba(0, 212, 255, 0.3);
    color: white;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.header-settings-btn:hover {
    transform: translateY(-50%) scale(1.1);
    background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
    box-shadow: 0 4px 15px rgba(0, 212, 255, 0.4);
}

.header-user-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: linear-gradient(135deg, rgba(0, 212, 255, 0.1) 0%, rgba(78, 205, 196, 0.1) 100%);
    border: 1px solid rgba(0, 212, 255, 0.3);
    border-radius: 20px;
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
}

.header-user-btn:hover {
    background: linear-gradient(135deg, rgba(0, 212, 255, 0.2) 0%, rgba(78, 205, 196, 0.2) 100%);
    border-color: rgba(0, 212, 255, 0.5);
    box-shadow: 0 4px 15px rgba(0, 212, 255, 0.3);
    transform: translateY(-1px);
}

.user-avatar {
    font-size: 18px;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: rgba(0, 212, 255, 0.2);
}

.user-name {
    font-size: 13px;
    color: var(--text-secondary);
}

.header-user-btn.connected .user-avatar {
    background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
}

.header-user-btn.connected .user-name {
    color: var(--text-primary);
}

.memory-item {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    transition: background-color 0.2s ease;
}

.memory-item:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

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

.memory-content {
    flex: 1;
    cursor: pointer;
    padding: 4px 0;
    border-radius: 4px;
    transition: background-color 0.2s ease;
}

.memory-content:hover {
    background-color: rgba(0, 212, 255, 0.1);
    padding-left: 8px;
}

.memory-actions {
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.2s ease;
}

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

.btn-icon {
    padding: 4px 8px;
    font-size: 12px;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    color: var(--text);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-icon:hover {
    background: var(--primary);
    color: var(--bg);
}

.btn-icon.danger:hover {
    background: var(--error);
    color: white;
}

/* ============================================
   🌞 THÈME CLAIR
   © 2026 Bubblai
   ============================================ */
[data-theme="light"] {
    /* Couleurs principales - Thème Clair */
    --primary: #0099CC;
    --secondary: #E74C3C;
    --accent: #16A085;
    
    /* Backgrounds - Inversés pour le clair */
    --bg-primary: #F8F9FA;
    --bg-secondary: #FFFFFF;
    --bg-tertiary: #E9ECEF;
    
    /* Textes - Inversés */
    --text-primary: #212529;
    --text-secondary: #495057;
    --text-muted: #6C757D;
    
    /* Bordures - Plus visibles */
    --border: rgba(0, 0, 0, 0.1);
    
    /* Status colors - Ajustés */
    --success: #28A745;
    --warning: #FFC107;
    --danger: #DC3545;
}

/* Styles spécifiques au thème clair */
[data-theme="light"] body {
    background: linear-gradient(135deg, #F8F9FA 0%, #E9ECEF 100%);
}

[data-theme="light"] .bg-animation::before {
    background: radial-gradient(circle at 20% 80%, rgba(0, 153, 204, 0.08) 0%, transparent 50%),
                radial-gradient(circle at 80% 20%, rgba(22, 160, 133, 0.08) 0%, transparent 50%),
                radial-gradient(circle at 40% 40%, rgba(231, 76, 60, 0.08) 0%, transparent 50%);
}

[data-theme="light"] .particle {
    background: rgba(0, 153, 204, 0.25);
    border: 1px solid rgba(0, 153, 204, 0.35);
    box-shadow: 0 0 12px rgba(0, 153, 204, 0.3);
}

[data-theme="light"] .center-bubble {
    background: linear-gradient(135deg, rgba(0, 153, 204, 0.3) 0%, rgba(22, 160, 133, 0.3) 100%), 
                linear-gradient(135deg, rgba(255, 255, 255, 0.98) 0%, rgba(249, 250, 251, 0.98) 100%);
    border: 2px solid rgba(0, 153, 204, 0.3);
    box-shadow: 0 20px 60px rgba(0, 153, 204, 0.15),
                inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

[data-theme="light"] .center-bubble:hover {
    box-shadow: 0 25px 80px rgba(0, 153, 204, 0.25),
                inset 0 1px 0 rgba(255, 255, 255, 0.9);
    border-color: rgba(0, 153, 204, 0.5);
}

[data-theme="light"] .satellite {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.98) 0%, rgba(249, 250, 251, 0.98) 100%);
    border: 0.8px solid var(--border);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

[data-theme="light"] .satellite:hover {
    border-color: var(--primary);
    box-shadow: 0 8px 24px rgba(0, 153, 204, 0.2);
    background: linear-gradient(135deg, rgba(0, 153, 204, 0.08) 0%, rgba(22, 160, 133, 0.08) 100%);
}

[data-theme="light"] .satellite.dragging {
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
}

/* Couleurs spécifiques par type de bulle en thème clair */
[data-theme="light"] .satellite.role1 { border-color: #00ffb6; }
[data-theme="light"] .satellite.documents { border-color: #FFB84D; }
[data-theme="light"] .satellite.memoire { border-color: #9B59B6; }
[data-theme="light"] .satellite.projets { border-color: #E74C3C; }
[data-theme="light"] .satellite.instruction1 { border-color: #2ECC71; }
[data-theme="light"] .satellite.directive1 { border-color: #3498DB; }
[data-theme="light"] .satellite.voix { border-color: #F39C12; }
[data-theme="light"] .satellite.image { border-color: #000000; }
[data-theme="light"] .satellite.action { border-color: #1ABC9C; }
[data-theme="light"] .satellite.custom { border-color: #95A5A6; }
[data-theme="light"] .satellite.connecteur { border-color: #6B46C1; }
[data-theme="light"] .satellite.communication { border-color: #EF4444; }
[data-theme="light"] .satellite.web { border-color: #0EA5E9; }
[data-theme="light"] .satellite.code { border-color: #6C757D; }

/* Backgrounds colorés en gradient conique pour l'intérieur des bulles (::before) */
[data-theme="light"] .satellite.documents::before {
    background: conic-gradient(from 0deg, #FFB84D, #FF8C42, #FF6B35, #FFB84D);
}

[data-theme="light"] .satellite.memoire::before {
    background: conic-gradient(from 0deg, #9B59B6, #8E44AD, #BB6BD9, #9B59B6);
}

[data-theme="light"] .satellite.projets::before {
    background: conic-gradient(from 0deg, #fc0070, #e0ceda, #f18a95, #f1b9c3);
}

[data-theme="light"] .satellite.instruction1::before {
    background: conic-gradient(from 0deg, #2ECC71, #27AE60, #58D68D, #2ECC71);
}

[data-theme="light"] .satellite.directive1::before {
    background: conic-gradient(from 0deg, #3498DB, #2980B9, #5DADE2, #3498DB);
}

[data-theme="light"] .satellite.voix::before {
    background: conic-gradient(from 0deg, #efff07, #ffeb00, #f1f871, #bdbe83);
}

[data-theme="light"] .satellite.action::before {
    background: conic-gradient(from 0deg, #1ABC9C, #16A085, #48C9B0, #1ABC9C);
}

[data-theme="light"] .satellite.custom::before {
    background: conic-gradient(from 0deg, #95A5A6, #7F8C8D, #BDC3C7, #95A5A6);
}

[data-theme="light"] .satellite.connecteur::before {
    background: conic-gradient(from 0deg, #6B46C1, #553C9A, #8B5CF6, #6B46C1);
}

[data-theme="light"] .satellite.communication::before {
    background: conic-gradient(from 0deg, #EF4444, #DC2626, #F87171, #EF4444);
}

[data-theme="light"] .satellite.web::before {
    background: conic-gradient(from 0deg, #0EA5E9, #0284C7, #38BDF8, #0EA5E9);
}

[data-theme="light"] .satellite.code::before {
    background: conic-gradient(from 0deg, #fffdfd, #141414, #000000, #000000);
}

/* Opacité subtile pour les backgrounds colorés */
[data-theme="light"] .satellite::before {
    opacity: 0.5;
    transition: opacity 0.3s ease;
    background: radial-gradient(circle, rgba(0, 153, 204, 0.08) 0%, rgba(22,  160, 133, 0.04) 50%, transparent 100%);
    filter: blur(4px);
}

[data-theme="light"] .satellite.role1::before {
    background: conic-gradient(from 0deg, #34dbda, #5aedff, #94ffe8, #34dbd0);
}

[data-theme="light"] .satellite:hover::before {
    opacity: 0.7;
    animation: rotate 2s linear infinite;
}

[data-theme="light"] .satellite.dragging::before {
    opacity: 0.8;
    animation: rotate 1s linear infinite;
}

[data-theme="light"] .add-bubble {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.9) 0%, rgba(249, 250, 251, 0.9) 100%);
    border: 2px dashed rgba(0, 0, 0, 0.2);
    color: var(--text-secondary);
}

[data-theme="light"] .add-bubble:hover {
    border-color: var(--primary);
    background: linear-gradient(135deg, rgba(0, 153, 204, 0.1) 0%, rgba(22, 160, 133, 0.1) 100%);
    color: var(--primary);
}

[data-theme="light"] .connection {
    background: linear-gradient(90deg, rgba(0, 153, 204, 0.4) 0%, rgba(22, 160, 133, 0.4) 100%);
    opacity: 0.6;
}

[data-theme="light"] .connection.inactive {
    background: linear-gradient(90deg, rgba(108, 117, 125, 0.3) 0%, rgba(0, 0, 0, 0.1) 100%);
    opacity: 0.3;
}

[data-theme="light"] .connection::after {
    background: var(--primary);
    border: 2px solid var(--bg-primary);
    box-shadow: 0 0 8px rgba(0, 153, 204, 0.4);
}

[data-theme="light"] .connection.inactive::after {
    content: '✕';
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
    color: #dc3545;
    background: transparent;
    border: none;
    border-radius: 0;
    box-shadow: none;
    animation: none;
    width: auto;
    height: auto;
    padding: 0;
}

[data-theme="light"] .sidebar-left,
[data-theme="light"] .sidebar-right {
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.98) 0%, rgba(249, 250, 251, 0.98) 100%);
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.1);
}

[data-theme="light"] .sidebar-left.open {
    box-shadow: 20px 0 40px rgba(0, 0, 0, 0.12);
}

[data-theme="light"] .sidebar-right.open {
    box-shadow: -20px  0 40px rgba(0, 0, 0, 0.12);
}

[data-theme="light"] .sidebar-header {
    border-bottom: 1px solid var(--border);
    background: rgba(0, 153, 204, 0.03);
}

[data-theme="light"] .menu-item {
    color: var(--text-primary);
}

[data-theme="light"] .menu-item:hover {
    background: rgba(0, 153, 204, 0.08);
    color: var(--primary);
}

[data-theme="light"] .agent-item {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

[data-theme="light"] .agent-item:hover {
    border-color: var(--primary);
    box-shadow: 0 4px 16px rgba(0, 153, 204, 0.15);
}

[data-theme="light"] .agent-item.active {
    border-color: var(--primary);
    background: linear-gradient(135deg, rgba(0, 153, 204, 0.08) 0%, rgba(22, 160, 133, 0.08) 100%);
}

[data-theme="light"] button.fab, [data-theme="light"] a.fab {
    background: linear-gradient(135deg, var(--primary) 0%, #007A99 100%);
    box-shadow: 0 8px 25px rgba(0, 153, 204, 0.3);
}

[data-theme="light"] button.fab:hover, [data-theme="light"] a.fab:hover {
    box-shadow: 0 12px 35px rgba(0, 153, 204, 0.4);
}

[data-theme="light"] .fab.voice-btn {
    background: linear-gradient(135deg, #0099CC 0%, #007A99 100%);
    box-shadow: 0 8px 32px rgba(0, 153, 204, 0.3);
}

[data-theme="light"] .fab.voice-btn:hover {
    background: linear-gradient(135deg, #00AADD 0%, #0088BB 100%);
    box-shadow: 0 12px 40px rgba(0, 153, 204, 0.4);
}

[data-theme="light"] .app-header {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.95) 0%, rgba(249, 250, 251, 0.95) 100%);
    border: 1px solid rgba(0, 153, 204, 0.2);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.08);
}

[data-theme="light"] .current-agent {
    background: rgba(0, 153, 204, 0.08);
    border: 1px solid rgba(0, 153, 204, 0.2);
    color: var(--primary);
}

[data-theme="light"] .header-settings-btn {
    background: linear-gradient(135deg, rgba(0, 153, 204, 0.1) 0%, rgba(22, 160, 133, 0.1) 100%);
    border: 1px solid rgba(0, 153, 204, 0.2);
    color: var(--primary);
}

[data-theme="light"] .header-settings-btn:hover {
    background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
    color: white;
}

[data-theme="light"] .modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    box-shadow: 0 25px 80px rgba(0, 0, 0, 0.2);
}

[data-theme="light"] .modal-header {
    border-bottom: 1px solid var(--border);
    background: linear-gradient(135deg, var(--bg-tertiary) 0%, var(--bg-secondary) 100%);
}

[data-theme="light"] .form-input {
    border: 1px solid var(--border);
    background: var(--bg-primary);
}

[data-theme="light"] .form-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(0, 153, 204, 0.15);
}

[data-theme="light"] .btn {
    border: 1px solid var(--border);
    background: var(--bg-tertiary);
}

[data-theme="light"] .btn:hover {
    border-color: var(--primary);
    background: rgba(0, 153, 204, 0.08);
    color: var(--primary);
}

[data-theme="light"] .btn.primary {
    background: linear-gradient(135deg, var(--primary) 0%, #007A99 100%);
    color: white;
}

[data-theme="light"] .btn.success {
    background: linear-gradient(135deg, #28A745 0%, #1E7E34 100%);
    color: white;
}

[data-theme="light"] .action-btn-bubble {
    background: var(--bg-secondary);
}

[data-theme="light"] .action-btn-bubble:hover {
    border-color: var(--primary);
    background: rgba(0, 153, 204, 0.08);
    color: var(--primary);
}

[data-theme="light"] .bubble-tooltip {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
}

[data-theme="light"] .bubble-tooltip::before {
    background: var(--bg-primary);
    border: 1px solid var(--border);
}

[data-theme="light"] .bubble-tooltip .tooltip-title {
    color: var(--primary);
}

[data-theme="light"] .notification {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
}

[data-theme="light"] .notification.success {
    border-color: var(--success);
    background: linear-gradient(135deg, rgba(40, 167, 69, 0.1) 0%, var(--bg-secondary) 100%);
}

[data-theme="light"] .notification.error {
    border-color: var(--danger);
    background: linear-gradient(135deg, rgba(220, 53, 69, 0.1) 0%, var(--bg-secondary) 100%);
}

[data-theme="light"] .icon-library-modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    box-shadow: 0 25px 80px rgba(0, 0, 0, 0.25);
}

[data-theme="light"] .icon-search {
    border: 1px solid var(--border);
    background: var(--bg-tertiary);
}

[data-theme="light"] .icon-search:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(0, 153, 204, 0.15);
}

[data-theme="light"] .icon-category {
    border: 1px solid var(--border);
    background: var(--bg-tertiary);
}

[data-theme="light"] .icon-category:hover,
[data-theme="light"] .icon-category.active {
    background: var(--primary);
    color: white;
}

[data-theme="light"] .icon-item {
    border: 1px solid var(--border);
    background: var(--bg-tertiary);
}

[data-theme="light"] .icon-item:hover,
[data-theme="light"] .icon-item.selected {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 12px rgba(0, 153, 204, 0.3);
}

[data-theme="light"] .memory-item:hover {
    background-color: rgba(0, 0, 0, 0.02);
}

[data-theme="light"] .memory-content:hover {
    background-color: rgba(0, 153, 204, 0.08);
}

[data-theme="light"] .btn-icon {
    background: rgba(0, 0, 0, 0.05);
    border: 1px solid var(--border);
}

[data-theme="light"] .btn-icon:hover {
    background: var(--primary);
    color: white;
}

/* ==================== NOTIFICATIONS ==================== */
.notification-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.notification {
    background: rgba(30, 30, 30, 0.95);
    border-radius: 12px;
    padding: 16px 20px;
    min-width: 300px;
    max-width: 400px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
    border-left: 4px solid;
    display: flex;
    align-items: center;
    gap: 12px;
    pointer-events: all;
    animation: slideInRight 0.3s ease-out;
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
}

.notification.success {
    border-left-color: #10b981;
    background: rgba(16, 185, 129, 0.1);
}

.notification.warning {
    border-left-color: #f59e0b;
    background: rgba(245, 158, 11, 0.1);
}

.notification.error {
    border-left-color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
}

.notification.info {
    border-left-color: #3b82f6;
    background: rgba(59, 130, 246, 0.1);
}

.notification-icon {
    font-size: 20px;
    flex-shrink: 0;
}

.notification.success .notification-icon { color: #10b981; }
.notification.warning .notification-icon { color: #f59e0b; }
.notification.error .notification-icon { color: #ef4444; }
.notification.info .notification-icon { color: #3b82f6; }

.notification-message {
    flex: 1;
    color: #ffffff;
    font-size: 14px;
    line-height: 1.5;
}

/* ── Thème clair : notifications bien contrastées ── */
[data-theme="light"] .notification {
    background: rgba(255, 255, 255, 0.97);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
    border-left-color: #94a3b8;
}

[data-theme="light"] .notification.success {
    border-left-color: #10b981;
    background: rgba(236, 253, 245, 0.97);
}

[data-theme="light"] .notification.warning {
    border-left-color: #f59e0b;
    background: rgba(255, 251, 235, 0.97);
}

[data-theme="light"] .notification.error {
    border-left-color: #ef4444;
    background: rgba(254, 242, 242, 0.97);
}

[data-theme="light"] .notification.info {
    border-left-color: #3b82f6;
    background: rgba(239, 246, 255, 0.97);
}

[data-theme="light"] .notification-message {
    color: #1e293b;
}

[data-theme="light"] .notification-icon {
    filter: none;
}

@keyframes slideInRight {
    from {
        transform: translateX(400px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.notification.hiding {
    animation: slideOutRight 0.3s ease-in forwards;
}

@keyframes slideOutRight {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(400px);
        opacity: 0;
    }
}

/* 📱 Fix z-index modal Structure (bulle action) sur mobile */
#actionStructureModal {
    z-index: 10050 !important;
}

@media (max-width: 768px) {

    /* 📱 editActionModal — même pattern que bulle rôle : min() gère la taille, pas de plein écran forcé */
    #editActionModal .modal-content {
        width: min(680px, 92vw) !important;
        max-height: min(88vh, 88vh) !important;
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;
        border-radius: 12px !important;
    }

    #editActionModal .modal-header {
        flex-shrink: 0 !important;
    }

    #editActionModal .modal-body {
        flex: 1 1 auto !important;
        min-height: 0 !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
        padding: 14px !important;
    }

    #editActionModal .modal-footer {
        flex-shrink: 0 !important;
        padding: 12px 14px 16px !important;
        display: flex !important;
        gap: 10px !important;
        justify-content: flex-end !important;
    }

    /* 📱 Textarea Schéma : hauteur adaptée à l'écran mobile */
    #editActionModal #actionContent {
        min-height: 100px !important;
        max-height: 25vh !important;
        resize: none !important;
    }

    /* 📱 actionStructureModal — même pattern */
    #actionStructureModal .modal-content {
        width: min(680px, 92vw) !important;
        max-height: min(88vh, 88vh) !important;
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;
        border-radius: 12px !important;
    }

    #actionStructureModal .modal-header {
        flex-shrink: 0 !important;
    }

    #actionStructureModal .modal-body {
        flex: 1 1 auto !important;
        min-height: 0 !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
        padding: 14px !important;
    }

    #actionStructureModal .modal-footer {
        flex-shrink: 0 !important;
        padding: 12px 14px 16px !important;
        display: flex !important;
        gap: 10px !important;
        justify-content: flex-end !important;
    }

    /* 📱 bubbleContentModal : flex column, footer toujours visible */
    #bubbleContentModal .modal-content {
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;
        max-height: 85vh !important;
    }

    #bubbleContentModal .modal-body {
        flex: 1 1 auto !important;
        min-height: 0 !important;
        max-height: none !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }

    #bubbleContentModal .modal-footer {
        flex-shrink: 0 !important;
        padding: 12px 16px max(12px, env(safe-area-inset-bottom)) !important;
    }

    /* 📱 editWebModal : centré, pas de bottom-sheet */
    #editWebModal {
        align-items: center !important;
        justify-content: center !important;
        padding: 16px !important;
    }

    #editWebModal .modal-content {
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;
        width: 100% !important;
        max-width: 100% !important;
        max-height: 88dvh !important;
        border-radius: 16px !important;
        margin: 0 !important;
    }

    #editWebModal .modal-body {
        flex: 1 1 auto !important;
        min-height: 0 !important;
        max-height: none !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }

    #editWebModal .modal-footer {
        flex-shrink: 0 !important;
        padding: 12px 16px max(12px, env(safe-area-inset-bottom)) !important;
    }
}

/* ============================================================
   DOC DOWNLOAD CARD — carte de téléchargement dans le chat
   ============================================================ */
.doc-download-card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 12px;
  padding: 12px 14px;
  max-width: 340px;
}
.doc-dl-icon {
  font-size: 1.6rem;
  flex-shrink: 0;
}
.doc-dl-info {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}
.doc-dl-name {
  font-size: 0.88rem;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.doc-dl-size {
  font-size: 0.75rem;
  color: rgba(255,255,255,0.5);
  margin-top: 2px;
}
.doc-dl-btn {
  flex-shrink: 0;
  background: linear-gradient(135deg, #4f8ef7, #7b5ea7);
  color: #fff;
  text-decoration: none;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 0.82rem;
  font-weight: 600;
  white-space: nowrap;
  transition: opacity 0.2s;
}
.doc-dl-btn:hover {
  opacity: 0.85;
}

/* ============================================================
   CUSTOM ACTION CARD — résultat d'une bulle Action dans le chat
   ============================================================ */
.custom-action-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.13);
  border-radius: 12px;
  padding: 12px 14px;
  max-width: 420px;
}
.custom-action-header {
  display: flex;
  align-items: center;
  gap: 6px;
}
.custom-action-icon {
  font-size: 1rem;
}
.custom-action-name {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: rgba(255,255,255,0.45);
}
.custom-action-body {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* 📥 Badge auto-save image vers bulle Documents */
.doc-save-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin: 6px 0 4px 0;
  padding: 4px 10px;
  background: rgba(56, 161, 105, 0.1);
  border: 1px solid rgba(56, 161, 105, 0.3);
  border-radius: 20px;
  font-size: 11px;
  color: rgba(56, 161, 105, 0.9);
  font-weight: 500;
}
