/* ========================================
   PersonalAssistant - Chat UI Styles
   ======================================== */

/* ========================================
   LOCAL PAGE BASE (no style-agents.css dependency)
   ======================================== */

body.agent-page {
    font-family: var(--font-sans);
    background: var(--bg-body);
    min-height: 100vh;
    overflow-x: hidden;
}

.main-layout {
    display: flex;
    flex-direction: column;
    gap: var(--space-6);
    width: 90%;
    margin: 0 auto;
    padding: var(--space-4);
}

.main-layout.full-width {
    width: 98%;
    max-width: 98%;
    margin: 0 auto;
    box-sizing: border-box;
    padding: calc(var(--header-height, 72px) + var(--space-3)) var(--space-6) var(--space-4);
}

@media (max-width: 768px) {
    .main-layout.full-width {
        width: 100%;
        max-width: 100%;
        padding: calc(var(--header-height, 72px) + var(--space-2)) var(--space-4) var(--space-3);
    }
}

/* ========================================
   CHAT LAYOUT (3 COLUMN)
   ======================================== */

.chat-layout {
    display: grid;
    grid-template-columns: 300px 1fr 280px;
    gap: var(--space-4);
    height: auto;
    min-height: 0;
    margin-bottom: var(--space-6);
    margin-top: 0;
    transition: grid-template-columns var(--transition-base);
}

/* Mobile responsive - sidebar collapsabile */
@media (max-width: 992px) {
    .chat-layout {
        grid-template-columns: 1fr;
    }

    .sessions-sidebar {
        position: fixed;
        left: -100%;
        top: var(--header-height);
        height: calc(100vh - var(--header-height));
        z-index: var(--z-index-fixed);
        transition: left var(--transition-base);
        box-shadow: var(--shadow-xl);
    }

    .sessions-sidebar.visible {
        left: 0;
    }

    .context-panel {
        display: none;
    }

    .context-panel.visible {
        display: flex;
        position: fixed;
        right: 0;
        top: var(--header-height);
        height: calc(100vh - var(--header-height));
        z-index: var(--z-index-fixed);
        box-shadow: var(--shadow-xl);
    }

    /* On mobile, collapsed state still shows full panel */
    .context-panel.context-collapsed {
        width: 280px !important;
        padding: var(--space-4) !important;
    }
}

/* ========================================
   SESSIONS SIDEBAR
   ======================================== */

.sessions-sidebar {
    background: var(--bg-card);
    border-radius: var(--card-border-radius);
    box-shadow: var(--card-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    width: 300px;
    transition: width var(--transition-base);
    position: relative;
}

/* Collapsed state - narrow sidebar with icons only */
.sessions-sidebar.sidebar-collapsed {
    width: 60px;
    overflow: hidden;
}

.sessions-sidebar.sidebar-collapsed .sidebar-content {
    display: none !important;
}

/* Hide all sidebar-content children when collapsed (but NOT sidebar-quick-actions) */
.sessions-sidebar.sidebar-collapsed .sidebar-content .sidebar-header,
.sessions-sidebar.sidebar-collapsed .sidebar-content .sidebar-sections,
.sessions-sidebar.sidebar-collapsed .sidebar-content .sidebar-footer {
    display: none !important;
}

.sessions-sidebar.sidebar-collapsed .sidebar-quick-actions {
    display: flex;
}

/* Hide scrollbar on collapsed sidebar */
.sessions-sidebar.sidebar-collapsed::-webkit-scrollbar {
    display: none;
}

.sessions-sidebar.sidebar-collapsed {
    -ms-overflow-style: none;  /* IE and Edge */
    scrollbar-width: none;  /* Firefox */
}

/* Quick Actions (visible when collapsed) */
.sidebar-quick-actions {
    display: none;
    flex-direction: column;
    padding: 0;
    gap: 0;
    align-items: stretch;
    width: 100%;
    height: 100%;
}

.sessions-sidebar.sidebar-collapsed .sidebar-quick-actions {
    display: flex !important;
}

/* Sidebar header when collapsed - use same style as expanded */
.sessions-sidebar.sidebar-collapsed .sidebar-quick-actions .sidebar-header {
    padding: var(--space-4);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: center;
    align-items: center;
    background: var(--bg-surface);
    color: var(--text-primary);
    min-height: 60px;
}

.sessions-sidebar.sidebar-collapsed .sidebar-quick-actions .sidebar-header h5 {
    display: none;
}

.sessions-sidebar.sidebar-collapsed .sidebar-quick-actions .sidebar-header .btn,
.sessions-sidebar.sidebar-collapsed .sidebar-quick-actions .sidebar-header .btn-icon {
    width: 32px;
    height: 32px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--bg-surface-alt);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    transition: var(--transition-base);
    cursor: pointer;
}

.sessions-sidebar.sidebar-collapsed .sidebar-quick-actions .sidebar-header .btn:hover,
.sessions-sidebar.sidebar-collapsed .sidebar-quick-actions .sidebar-header .btn-icon:hover {
    background: var(--bg-hover);
    color: var(--primary);
    /* No transform scale - only color change */
}

.quick-action-btn {
    width: 44px;
    height: 44px;
    min-height: 44px;
    border: none;
    background: transparent;
    border-radius: var(--radius-md);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition-fast);
    color: var(--text-secondary);
    position: relative;
    flex-shrink: 0;
    margin: var(--space-2) auto;
}

.quick-action-btn:hover {
    background: var(--bg-surface-alt);
    color: var(--primary);
    transform: scale(1.05);
}

.quick-action-btn:active {
    transform: scale(0.95);
}

.quick-action-btn i {
    font-size: 1.2rem;
    margin-bottom: 2px;
}

.quick-action-label {
    font-size: 0.6rem;
    white-space: nowrap;
    opacity: 0;
    position: absolute;
    left: 52px;
    background: var(--bg-card);
    color: var(--text-primary);
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
    pointer-events: none;
    transition: opacity var(--transition-fast);
    z-index: 1000;
    font-weight: var(--font-weight-medium);
}

.quick-action-btn:hover .quick-action-label {
    opacity: 1;
}

/* Full Sidebar Content */
.sidebar-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
    padding: var(--space-2);
    gap: var(--space-2);
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: var(--space-3);
    border-bottom: 2px solid var(--border-color);
    min-height: 40px;
    background: transparent;
}

.sidebar-header h5 {
    margin: 0;
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-semibold);
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.sidebar-header .btn,
.sidebar-header .btn-icon {
    background: var(--primary);
    color: white;
    width: 32px !important;
    height: 32px !important;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition-base);
    opacity: 0.8;
    flex-shrink: 0;
    padding: 0;
    border: none;
}

.sidebar-header .btn:hover,
.sidebar-header .btn-icon:hover {
    background: var(--primary-hover);
    opacity: 1;
    /* No transform scale - only color change */
}

/* Search Container */
.search-container {
    padding: var(--space-2);
    border-bottom: 1px solid var(--border-color);
}

.search-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.search-icon {
    position: absolute;
    left: var(--space-3);
    color: var(--text-secondary);
    pointer-events: none;
    z-index: 1;
}

.search-input {
    width: 100%;
    padding: var(--space-2) var(--space-2) var(--space-2) calc(var(--space-3) + 20px);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-surface);
    color: var(--text-primary);
    font-size: 0.9rem;
    transition: var(--transition-fast);
}

.search-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.search-input::placeholder {
    color: var(--text-secondary);
}

/* Catalog search: same style as search-input */
#catalogSearch {
    width: 100%;
    padding: var(--space-2) var(--space-2) var(--space-2) calc(var(--space-3) + 20px);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-surface);
    color: var(--text-primary);
    font-size: 0.9rem;
    transition: var(--transition-fast);
}

#catalogSearch:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

#catalogSearch::placeholder {
    color: var(--text-secondary);
}

.btn-clear-search {
    position: absolute;
    right: var(--space-2);
    width: 20px;
    height: 20px;
    padding: 0;
    border: none;
    background: var(--text-secondary);
    color: white;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    transition: var(--transition-fast);
    z-index: 2;
}

.btn-clear-search:hover {
    background: var(--danger);
    transform: scale(1.1);
}

.search-loader {
    position: absolute;
    right: 25px; /* Positioned left of clear button or replacing it */
    top: 50%;
    transform: translateY(-50%);
    color: var(--primary);
    font-size: 0.9rem;
    pointer-events: none;
    z-index: 2;
    background: var(--bg-surface); /* Hide text behind it */
    padding-left: 5px;
}

.session-list {
    flex: 1;
    overflow-y: auto;
    padding: calc(var(--space-1) / 2);
}

/* Chat section: session-list adapts to content */
#chatSection .session-list {
    flex: 0 1 auto;
    overflow-y: auto;
    max-height: 60vh; /* Max height with scroll if too many chats */
}

/* Hide scrollbar when sidebar is collapsed */
.sessions-sidebar.sidebar-collapsed .session-list {
    overflow: hidden;
}

.sessions-sidebar.sidebar-collapsed .session-list::-webkit-scrollbar {
    display: none;
}

.sessions-sidebar.sidebar-collapsed .session-list {
    -ms-overflow-style: none;  /* IE and Edge */
    scrollbar-width: none;  /* Firefox */
}

.session-item {
    background: var(--bg-surface);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    position: relative;
    width: 96%;
    margin-left: auto;
    margin-right: auto;
    padding: var(--space-2);
    margin-bottom: var(--space-1);
    cursor: pointer;
    transition: var(--transition-fast);
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: var(--space-2);
    overflow: visible;
}

/* Session item text truncation */
.session-item .session-title,
.session-item .session-meta {
    transition: opacity var(--transition-fast);
}

.session-item:hover {
    background: var(--bg-surface-alt);
    border-color: var(--primary);
    transform: translateX(4px);
}

.session-item.active {
    background: var(--primary-light);
    border-color: var(--primary);
    box-shadow: var(--shadow-sm);
}

.session-info {
    flex: 0 1 calc(100% - 38px);
    max-width: calc(100% - 38px);
    min-width: 0;
}

.session-title {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
    color: var(--text-primary);
    margin: 0 0 var(--space-1) 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.session-meta {
    font-size: var(--font-size-xs);
    color: var(--text-secondary);
    margin: 0;
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.session-meta-inline {
    margin-top: 2px;
    flex-wrap: nowrap;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    gap: 6px;
}

.session-meta-inline .session-channels {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.session-meta-dot {
    color: var(--text-muted);
    line-height: 1;
}

.session-meta-msg {
    color: var(--text-secondary);
    flex-shrink: 0;
}

.session-channels {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.session-channel-badge {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.65rem;
    border: 1px solid transparent;
}

.session-channel-whatsapp {
    color: #25D366;
    background: rgba(37, 211, 102, 0.12);
    border-color: rgba(37, 211, 102, 0.35);
}

.session-channel-telegram {
    color: #229ED9;
    background: rgba(34, 158, 217, 0.12);
    border-color: rgba(34, 158, 217, 0.35);
}

.session-channel-gmail,
.session-channel-email {
    color: #D93025;
    background: rgba(217, 48, 37, 0.1);
    border-color: rgba(217, 48, 37, 0.28);
}

.session-actions {
    position: absolute;
    top: 8px;
    right: 8px;
    opacity: 1;
    z-index: 15;
}

.session-menu-trigger {
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-fast);
}

.session-menu-trigger:hover {
    background: var(--bg-surface-alt);
    color: var(--text-primary);
}

.session-actions-menu {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    min-width: 155px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    /* Usa uno z-index molto alto per stare sopra chat e context panel */
    z-index: 1200;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

.session-actions-menu.open {
    display: block;
}

.session-menu-item {
    width: 100%;
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-size: 0.86rem;
    text-align: left;
    padding: 9px 11px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
}

.session-menu-item:hover {
    background: var(--bg-surface-alt);
}

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

.sidebar-footer {
    padding: var(--space-2);
    border-top: 2px solid var(--border-color);
    background: var(--bg-surface-alt);
}

.sidebar-footer small {
    color: var(--text-secondary);
    font-size: var(--font-size-xs);
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: var(--space-8) var(--space-4);
    color: var(--text-muted);
}

.empty-state i {
    font-size: 3rem;
    color: var(--text-muted);
    margin-bottom: var(--space-4);
    opacity: 0.5;
}

.empty-state p {
    font-weight: var(--font-weight-semibold);
    margin-bottom: var(--space-2);
}

.empty-state small {
    font-size: var(--font-size-sm);
}

/* ========================================
   CHAT AREA
   ======================================== */

.chat-area {
    background: var(--bg-card);
    border-radius: var(--card-border-radius);
    box-shadow: var(--card-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

.chat-header {
    padding: 6px 15px !important;
    border-bottom: 2px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--gradient-primary);
    color: white;
}

.chat-header-left {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.chat-header-right {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.chat-header h5 {
    margin: 0;
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-semibold);
}

.btn-icon {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition-base);
}

.btn-icon:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.05);
}

.badge {
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-full);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
}

/* ========================================
   MESSAGES CONTAINER
   ======================================== */

.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-4);
    background: var(--bg-surface);
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    min-height: 360px;
    max-height: none;
    position: relative;
}

/* Scrollbar styling */
.messages-container::-webkit-scrollbar {
    width: 8px;
}

.messages-container::-webkit-scrollbar-track {
    background: var(--bg-surface-alt);
    border-radius: var(--radius-sm);
}

.messages-container::-webkit-scrollbar-thumb {
    background: var(--primary);
    border-radius: var(--radius-sm);
}

.messages-container::-webkit-scrollbar-thumb:hover {
    background: var(--primary-hover);
}

/* Welcome message */
.welcome-message {
    text-align: center;
    padding: var(--space-10);
    max-width: 600px;
    margin: auto;
}

.welcome-icon {
    width: 80px;
    height: 80px;
    margin: 0 auto var(--space-4);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    color: white;
    box-shadow: var(--shadow-lg);
}

.welcome-icon-img {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    object-fit: cover;
}

.welcome-message h3 {
    color: var(--text-primary);
    font-weight: var(--font-weight-bold);
    margin-bottom: var(--space-3);
}

.welcome-message p {
    color: var(--text-secondary);
    font-size: var(--font-size-lg);
    margin-bottom: var(--space-6);
}

.welcome-features {
    display: flex;
    justify-content: center;
    gap: var(--space-6);
    margin-bottom: var(--space-6);
    flex-wrap: wrap;
}

.feature-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-2);
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
}

.feature-item i {
    font-size: 1.5rem;
    color: var(--primary);
}

/* Message bubbles */
.message {
    display: flex;
    gap: var(--space-3);
    max-width: 80%;
    animation: messageSlideIn 0.3s ease;
}

@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.user-message {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message.ai-message {
    align-self: flex-start;
    max-width: 100%;
}

.message-avatar {
    min-width: 40px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
    overflow: hidden;
}

.assistant-variant-badge {
    width: 50px;
    height: 50px;
    object-fit: cover;
    border-radius: 50%;
    position: absolute;
    right: 8px;
    bottom: 8px;
    border: 2px solid var(--bg-card);
    box-shadow: var(--shadow-sm);
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
    transform-origin: bottom right;
    cursor: zoom-in;
    z-index: 2;
}

.assistant-variant-badge:hover {
    transform: scale(5.1);
    width: 100px;
    height: 100px;
    box-shadow: var(--shadow-lg);
    z-index: 12;
}

.message-user-icon {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
    background: var(--gradient-secondary);
    color: white;
}


.d-one-message-avatar-img {
    width: 40px;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

.d-one-face-icon {
    width: 20px;
    height: 20px;
    border-radius: 0%;
    object-fit: cover;
    vertical-align: text-bottom;
}

.ai-message .message-avatar {
    /* background: var(--gradient-primary); */
    color: white;
}

.message-content {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.message-text {
    background: var(--bg-card);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: var(--space-3) var(--space-4);
    color: var(--text-primary);
    line-height: var(--line-height-relaxed);
    word-wrap: break-word;
    position: relative;
}

.user-message .message-text {
    background: var(--primary-light);
    border-color: var(--primary);
}

.ai-message .message-text {
    background: var(--bg-card);
    padding-right: calc(var(--space-4) + 34px);
    padding-bottom: calc(var(--space-3) + 18px);
}

.inline-action-message {
    width: 100%;
    max-width: min(100%, 1120px);
}

.inline-action-message .message-content {
    flex: 1 1 auto;
    min-width: 0;
}

.inline-action-message .message-text {
    width: 100%;
    box-sizing: border-box;
}

.inline-action-message .yt-options-card {
    width: 100%;
    max-width: none;
    box-sizing: border-box;
}

.inline-action-message .yt-actions {
    flex-wrap: wrap;
}

.message-meta {
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: 0 var(--space-2);
}

.user-message .message-meta {
    justify-content: flex-end;
}

.message-debug-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: 0 var(--space-2);
    opacity: 0.92;
}

.message-debug-label {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    padding: 2px 8px;
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.06);
    color: var(--text-secondary);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: lowercase;
}

.message-actions {
    display: flex;
    gap: var(--space-2);
    opacity: 0;
    transition: opacity var(--transition-fast);
    padding: 0 var(--space-2);
}

.message:hover .message-actions {
    opacity: 1;
}

.btn-copy {
    background: none;
    border: none;
    color: var(--text-muted);
    padding: var(--space-1);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: var(--transition-fast);
    font-size: var(--font-size-sm);
}

.btn-copy:hover {
    background: var(--bg-surface-alt);
    color: var(--primary);
}

/* RAG context badge in message */
.rag-badge {
    display: inline-flex;
    align-items: center;
    background: var(--info);
    color: white;
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    font-size: 10px;
    margin-left: var(--space-2);
    cursor: help;
}

.rag-docs-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    margin-left: 0.25rem;
    padding: 0.1rem 0.4rem;
    border-radius: 999px;
    background: rgba(100, 116, 139, 0.18);
    color: var(--text-secondary);
    font-size: 0.72rem;
    border: 1px solid rgba(100, 116, 139, 0.35);
}

/* Loading indicator */
.message-loading {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    padding: var(--space-3);
}

.loading-status {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--font-size-sm);
    color: var(--primary);
    font-weight: var(--font-weight-medium);
    margin-bottom: var(--space-1);
}

.loading-status i {
    animation: pulse 1.5s ease-in-out infinite;
}

.avatar-inline-emoji {
    width: 50px;
    object-fit: cover;
    border-radius: 50%;
    vertical-align: -0.2em;
    margin: 0 0.05em;
    display: inline-block;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.6;
        transform: scale(1.1);
    }
}

.loading-dots {
    display: flex;
    gap: var(--space-1);
}

.loading-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary);
    animation: loadingPulse 1.4s infinite ease-in-out both;
}

.loading-dot:nth-child(1) {
    animation-delay: -0.32s;
}

.loading-dot:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes loadingPulse {
    0%,
    80%,
    100% {
        transform: scale(0.6);
        opacity: 0.5;
    }

    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* ========================================
   CHAT INPUT AREA
   ======================================== */

.chat-input-area {
    padding: var(--space-4);
    border-top: 2px solid var(--border-color);
    background: var(--bg-surface-alt);
}

.chat-textarea {
    width: 100%;
    padding: var(--space-3);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    font-family: var(--font-sans);
    font-size: var(--font-size-base);
    resize: vertical;
    min-height: 60px;
    max-height: 200px;
    background: var(--bg-surface);
    color: var(--text-primary);
    transition: var(--transition-fast);
}

.chat-textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: var(--form-focus-shadow);
}

.chat-textarea:disabled {
    background: var(--bg-surface-alt);
    cursor: not-allowed;
    opacity: 0.6;
}

.attachment-info {
    margin-top: var(--space-2);
}

.attachment-chip {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 6px 10px;
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
}

.attachment-remove-btn {
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

.attachment-remove-btn:hover {
    color: var(--danger);
}

.input-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: var(--space-3);
}

.input-controls .btn {
    min-width: 120px;
}

/* Keep mic button vertically aligned with other controls */
#micBtn {
    min-height: 44px;
    height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Keep identical footprint ON/OFF for LightRAG toggle and gray solid OFF state */
#toggleLightRagBtn.lightrag-toggle-btn {
    width: 144px;
    min-width: 144px;
    max-width: 144px;

}

/* ========================================
   CONTEXT PANEL
   ======================================== */

.context-panel {
    background: var(--bg-card);
    border-radius: var(--card-border-radius);
    box-shadow: var(--card-shadow);
    padding: var(--space-4);
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    overflow-y: auto;
    width: 280px;
    transition: width var(--transition-base);
    position: relative;
}

/* Collapsed state - narrow context panel with icons only */
.context-panel.context-collapsed {
    width: 60px !important;
    padding: 0 !important;
    gap: 0 !important;
    min-width: 60px;
    max-width: 60px;
    overflow-x: hidden !important;
}

.context-panel.context-collapsed .context-content {
    display: none !important;
}

.context-panel.context-collapsed .context-quick-actions {
    display: flex !important;
}

/* Quick Actions for Context Panel (visible when collapsed) */
.context-quick-actions {
    display: none;
    flex-direction: column;
    padding: 0;
    gap: 0;
    align-items: stretch;
    width: 100%;
}

.context-panel.context-collapsed .context-quick-actions {
    display: flex;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    box-sizing: border-box;
}

/* Evita che il tooltip label fuori pannello generi scrollbar orizzontale quando collassato */
.context-panel.context-collapsed .quick-action-label {
    display: none !important;
}

/* Context header when collapsed - use same style as expanded */
.context-panel.context-collapsed .context-quick-actions .context-header {
    padding: var(--space-4);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: center;
    align-items: center;
    background: var(--bg-surface);
    color: var(--text-primary);
    min-height: 60px;
}

.context-panel.context-collapsed .context-quick-actions .context-header h6 {
    display: none;
}

.context-panel.context-collapsed .context-quick-actions .context-header .btn {
    width: 32px;
    height: 32px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--bg-surface-alt);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    transition: var(--transition-base);
}

.context-panel.context-collapsed .context-quick-actions .context-header .btn:hover {
    background: var(--bg-hover);
    color: var(--primary);
    /* No transform scale - only color change */
}

/* Quick action buttons in context panel */
.context-quick-actions .quick-action-btn {
    text-decoration: none;
    color: var(--text-secondary);
}

.context-quick-actions .quick-action-btn:hover {
    color: var(--primary);
}

/* Full Context Panel Content */
.context-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    gap: var(--space-4);
    overflow-y: auto;
}

.context-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: var(--space-3);
    border-bottom: 2px solid var(--border-color);
    min-height: 40px;
}

.context-header h6 {
    margin: 0;
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-semibold);
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

/* Context header button styling - make it visible */
.context-header .btn-icon {
    background: var(--primary);
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition-base);
    opacity: 0.8;
    flex-shrink: 0;
}

.context-header .btn-icon:hover {
    background: var(--primary-hover);
    opacity: 1;
    /* No transform scale - only color change */
}

.context-header .btn-icon.btn-sm {
    width: 28px;
    height: 28px;
    font-size: 0.875rem;
}

.panel-section {
    padding: var(--space-3);
    background: var(--bg-surface);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}

.panel-section h6 {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
    color: var(--text-primary);
    margin: 0 0 var(--space-3) 0;
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.rag-context-info p {
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    margin-bottom: var(--space-2);
}

.context-messages-list {
    list-style: none;
    padding: 0;
    margin: 0;
    font-size: var(--font-size-xs);
    color: var(--text-muted);
}

.context-messages-list li {
    padding: var(--space-2);
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    margin-bottom: var(--space-1);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.model-info p {
    margin: 0;
    font-size: var(--font-size-base);
    color: var(--text-primary);
}

.stats-list {
    list-style: none;
    padding: 0;
    margin: 0;
    font-size: var(--font-size-sm);
}

.stats-list li {
    display: flex;
    justify-content: space-between;
    padding: var(--space-2) 0;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-secondary);
}

.stats-list li:last-child {
    border-bottom: none;
}

.stats-list strong {
    color: var(--text-primary);
    font-weight: var(--font-weight-semibold);
}

/* ========================================
   DARK THEME OVERRIDES
   ======================================== */

html[data-theme='dark'] .sessions-sidebar,
html[data-theme='dark'] .chat-area,
html[data-theme='dark'] .context-panel {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
}

html[data-theme='dark'] .message-text {
    background: var(--bg-surface);
    border-color: var(--border-color);
}

html[data-theme='dark'] .user-message .message-text {
    background: rgba(102, 126, 234, 0.15);
    border-color: var(--primary);
}

html[data-theme='dark'] .message-debug-label {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-muted);
}

html[data-theme='dark'] .chat-textarea {
    background: var(--bg-surface);
    border-color: var(--border-color);
}

html[data-theme='dark'] .panel-section {
    background: var(--bg-surface);
    border-color: var(--border-color);
}

/* ========================================
   RESPONSIVE ADJUSTMENTS
   ======================================== */

@media (max-width: 768px) {
    .chat-layout {
        height: auto;
    }

    .message {
        max-width: 90%;
    }

    .welcome-features {
        flex-direction: column;
        gap: var(--space-4);
    }

    .chat-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .chat-header-right {
        width: 100%;
        justify-content: space-between;
    }

    .inline-action-message {
        max-width: 100%;
    }

}

/* ========================================
   MARKDOWN CONTENT STYLING
   ======================================== */

.markdown-content {
    line-height: var(--line-height-relaxed);
}

/* Markdown headings */
.markdown-content h1,
.markdown-content h2,
.markdown-content h3,
.markdown-content h4,
.markdown-content h5,
.markdown-content h6 {
    color: var(--text-primary);
    font-weight: var(--font-weight-bold);
    margin-top: var(--space-4);
    margin-bottom: var(--space-3);
    line-height: var(--line-height-tight);
}

.markdown-content h1 {
    font-size: var(--font-size-xl);
    border-bottom: 2px solid var(--border-color);
    padding-bottom: var(--space-2);
}

.markdown-content h2 {
    font-size: var(--font-size-lg);
    border-bottom: 1px solid var(--border-color);
    padding-bottom: var(--space-2);
}

.markdown-content h3 {
    font-size: var(--font-size-md);
}

.markdown-content h4 {
    font-size: var(--font-size-base);
}

/* Markdown paragraphs */
.markdown-content p {
    margin-bottom: var(--space-3);
    color: var(--text-primary);
}

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

/* Markdown lists */
.markdown-content ul,
.markdown-content ol {
    margin: var(--space-3) 0;
    padding-left: var(--space-6);
}

.markdown-content li {
    margin-bottom: var(--space-2);
    color: var(--text-primary);
}

.markdown-content li>p {
    margin-bottom: var(--space-1);
}

/* Markdown code blocks */
.markdown-content pre {
    background: var(--bg-surface-alt);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: var(--space-4);
    margin: var(--space-4) 0;
    overflow-x: auto;
    font-family: 'Courier New', Courier, monospace;
    font-size: var(--font-size-sm);
    line-height: var(--line-height-normal);
}

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

/* Inline code */
.markdown-content code {
    background: var(--bg-surface-alt);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 2px 6px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.9em;
    color: var(--primary);
}

/* Markdown links */
.markdown-content a {
    color: var(--primary);
    text-decoration: none;
    border-bottom: 1px solid var(--primary);
    transition: var(--transition-fast);
}

.markdown-content a:hover {
    color: var(--primary-hover);
    border-bottom-color: var(--primary-hover);
}

/* Markdown blockquotes */
.markdown-content blockquote {
    border-left: 4px solid var(--primary);
    background: var(--bg-surface-alt);
    padding: var(--space-3) var(--space-4);
    margin: var(--space-4) 0;
    font-style: italic;
    color: var(--text-secondary);
}

.markdown-content blockquote p {
    margin: 0;
}

/* Markdown tables */
.markdown-content table {
    width: 100%;
    border-collapse: collapse;
    margin: var(--space-4) 0;
    font-size: var(--font-size-sm);
}

.markdown-content table th,
.markdown-content table td {
    border: 1px solid var(--border-color);
    padding: var(--space-2) var(--space-3);
    text-align: left;
}

.markdown-content table th {
    background: var(--bg-surface-alt);
    font-weight: var(--font-weight-semibold);
    color: var(--text-primary);
}

.markdown-content table tr:nth-child(even) {
    background: var(--bg-surface);
}

/* Markdown horizontal rules */
.markdown-content hr {
    border: none;
    border-top: 2px solid var(--border-color);
    margin: var(--space-6) 0;
}

/* Markdown emphasis */
.markdown-content strong {
    font-weight: var(--font-weight-bold);
    color: var(--text-primary);
}

.markdown-content em {
    font-style: italic;
}

/* Dark theme adjustments for markdown */
html[data-theme='dark'] .markdown-content pre {
    background: rgba(0, 0, 0, 0.3);
    border-color: var(--border-color);
}

html[data-theme='dark'] .markdown-content code {
    background: rgba(0, 0, 0, 0.3);
    border-color: var(--border-color);
}

html[data-theme='dark'] .markdown-content blockquote {
    background: rgba(0, 0, 0, 0.2);
    border-left-color: var(--primary);
}

html[data-theme='dark'] .markdown-content table th {
    background: rgba(0, 0, 0, 0.3);
}

html[data-theme='dark'] .markdown-content table tr:nth-child(even) {
    background: rgba(0, 0, 0, 0.1);
}

/* ========================================
   MULTIMEDIA CONTENT (Images, Videos, Embeds)
   ======================================== */

/* Responsive Images */
.markdown-content img,
.markdown-img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius-md);
    margin: var(--space-4) 0;
    box-shadow: var(--shadow-md);
    transition: transform var(--transition-base), box-shadow var(--transition-base);
}

.markdown-content img:hover,
.markdown-img:hover {
    transform: scale(1.02);
    box-shadow: var(--shadow-lg);
    cursor: pointer;
}

/* Image with caption */
.markdown-content figure {
    margin: var(--space-4) 0;
    text-align: center;
}

.markdown-content figcaption {
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    margin-top: var(--space-2);
    font-style: italic;
}

/* Responsive iframe wrapper (YouTube, Vimeo, etc.) */
.responsive-iframe-wrapper {
    position: relative;
    width: 100%;
    padding-bottom: 56.25%; /* 16:9 aspect ratio */
    height: 0;
    margin: var(--space-4) 0;
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-lg);
}

.responsive-iframe-wrapper iframe,
.markdown-iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: none;
    border-radius: var(--radius-md);
}

/* Standalone iframe (not wrapped) */
.markdown-content iframe:not(.markdown-iframe) {
    max-width: 100%;
    margin: var(--space-4) 0;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
}

/* Responsive Videos */
.markdown-content video,
.markdown-video {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius-md);
    margin: var(--space-4) 0;
    box-shadow: var(--shadow-md);
}

/* Audio players */
.markdown-content audio {
    width: 100%;
    margin: var(--space-4) 0;
    border-radius: var(--radius-md);
}

/*
 * Placeholder solo per immagini lazy nel messaggio (markdown).
 * Non usare il selettore globale img[loading="lazy"]: la toolbar centralizzata
 * mette loading="lazy" su .toolbar-brand-img — altrimenti compare uno sfondo su SVG trasparente.
 */
.markdown-content img[loading="lazy"] {
    background: var(--bg-surface-alt);
}

/* Dark theme adjustments */
html[data-theme='dark'] .markdown-content img,
html[data-theme='dark'] .markdown-img {
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
}

html[data-theme='dark'] .responsive-iframe-wrapper {
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -2px rgba(0, 0, 0, 0.3);
}

/* Mobile responsive */
@media (max-width: 768px) {
    .markdown-content img,
    .markdown-img {
        margin: var(--space-3) 0;
    }

    .responsive-iframe-wrapper {
        margin: var(--space-3) 0;
    }
}



.log-container {
    max-height: 200px;
    overflow-y: auto;
    background-color: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 0.375rem;
    padding: 0.75rem;
}

.log-info {
    color: #0d6efd;
}

.log-success {
    color: #198754;
}

.log-warning {
    color: #fd7e14;
}

.log-error {
    color: #dc3545;
}

/* Sidebar Toggle Styles */
.sidebar-hidden {
    display: none !important;
}

/* Chat Layout adjustments when sidebar is collapsed */
.chat-layout.sidebar-collapsed {
    grid-template-columns: 60px 1fr 280px;
    transition: grid-template-columns var(--transition-base);
}

.chat-layout.sidebar-collapsed .chat-area {
    grid-column: 2;
}

.chat-layout.sidebar-collapsed .context-panel {
    grid-column: 3;
}

/* Chat Layout adjustments when context panel is collapsed */
.chat-layout.context-collapsed {
    grid-template-columns: 300px 1fr 60px;
    transition: grid-template-columns var(--transition-base);
}

.chat-layout.context-collapsed .chat-area {
    grid-column: 2;
}

.chat-layout.context-collapsed .context-panel {
    grid-column: 3;
}

/* Both collapsed */
.chat-layout.sidebar-collapsed.context-collapsed {
    grid-template-columns: 60px 1fr 60px;
}

.chat-layout.sidebar-collapsed.context-collapsed .chat-area {
    grid-column: 2;
}

.chat-layout.sidebar-collapsed.context-collapsed .context-panel {
    grid-column: 3;
}

/* Hide text elements when sidebar is collapsed */
.sessions-sidebar.sidebar-collapsed .sidebar-header-text,
.sessions-sidebar.sidebar-collapsed .sidebar-footer-text,
.sessions-sidebar.sidebar-collapsed .session-title,
.sessions-sidebar.sidebar-collapsed .session-meta,
.sessions-sidebar.sidebar-collapsed .empty-state p,
.sessions-sidebar.sidebar-collapsed .empty-state small {
    display: none;
}

/* ========================================
   SIDEBAR COLLAPSIBLE SECTIONS
   ======================================== */

.sidebar-sections {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    overflow: hidden;
}

.sidebar-section {
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-surface);
    overflow: hidden;
    transition: all var(--transition-base);
}

.sidebar-section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-3);
    background: var(--bg-surface-alt);
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    user-select: none;
    transition: background var(--transition-fast);
}

.sidebar-section-header:hover {
    background: var(--bg-hover);
}

.section-title {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-weight: var(--font-weight-semibold);
    font-size: var(--font-size-sm);
    color: var(--text-primary);
}

.section-title i {
    color: var(--primary);
    font-size: var(--font-size-base);
}

.btn-section-toggle {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: var(--space-1);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
    width: 24px;
    height: 24px;
}

.btn-section-toggle:hover {
    background: var(--bg-hover);
    color: var(--primary);
    transform: scale(1.1);
}

.btn-section-toggle i {
    transition: transform var(--transition-fast);
}

.sidebar-section.section-collapsed .btn-section-toggle i {
    transform: rotate(-90deg);
}

.sidebar-section-content {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-section.section-collapsed .sidebar-section-content {
    display: none;
}

/* Chat section: auto height based on content */
.sidebar-section:first-child {
    flex: 0 1 auto;
}

.sidebar-section:first-child .sidebar-section-content {
    flex: 0 1 auto;
    max-height: none;
}

/* Services section: takes remaining space */
.sidebar-section:last-child {
    flex: 1;
    min-height: 0;
}

.sidebar-section:last-child .sidebar-section-content {
    flex: 1;
    min-height: 0;
}

/* When services section is collapsed, make it compact (only header) */
.sidebar-section:last-child.section-collapsed {
    flex: 0 0 auto;
    min-height: auto;
}

/* Show only icon in empty state when collapsed */
.sessions-sidebar.sidebar-collapsed .empty-state {
    padding: var(--space-4);
    text-align: center;
}

.sessions-sidebar.sidebar-collapsed .empty-state i {
    font-size: 1.5rem;
    margin-bottom: 0;
}

/* Core Variables per Chat */
:root {
    --chat-primary: #06b6d4;
    --chat-primary: #4f46e5;
    --chat-primary-dark: #4338ca;
    --chat-secondary: #06b6d4;
    --chat-success: #10b981;
    --chat-warning: #f59e0b;
    --chat-error: #ef4444;
    --chat-surface: #ffffff;
    --chat-surface-alt: #f8fafc;
    --chat-border: #e2e8f0;
    --chat-text: #1e293b;
    --chat-text-muted: #64748b;
    --chat-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --chat-shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.1);

    --chat-border-radius: 16px;
    --chat-border-radius-lg: 24px;
}

/* Dark Theme Variables */
html[data-theme='dark'] {
    --chat-surface: #1e293b;
    --chat-surface-alt: #0f172a;
    --chat-border: #334155;
    --chat-text: #f1f5f9;
    --chat-text-muted: #94a3b8;
    --chat-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    --chat-shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.4);
}


.chat-services-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 1.5rem;
}

.chat-service-card {
    background: var(--chat-surface);
    border-radius: var(--chat-border-radius);
    border: 2px solid var(--chat-border);
    padding: 2rem;
    box-shadow: var(--chat-shadow);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.chat-service-card:hover {
    transform: translateY(-8px);
    box-shadow: var(--chat-shadow-lg);
    border-color: var(--chat-primary);
}

.chat-service-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: var(--chat-gradient);
    transform: scaleX(0);
    transition: transform 0.3s ease;
}

.chat-service-card:hover::before {
    transform: scaleX(1);
}

/* Status Indicator */
.status-indicator {
    position: absolute;
    top: 1.5rem;
    right: 1.5rem;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    z-index: 10;
    transition: all 0.3s ease;
}

.status-online {
    background: var(--chat-secondary);
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2);
    animation: pulse-online 2s infinite;
}

.status-offline {
    background: #ef4444;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.2);
}

@keyframes pulse-online {

    0%,
    100% {
        transform: scale(1);
        opacity: 1;
    }

    50% {
        transform: scale(1.2);
        opacity: 0.8;
    }
}

/* Chat Service Headers */
.chat-service-header {
    text-align: center;
    margin-bottom: 1.5rem;
}

.chat-service-icon {
    width: 80px;
    height: 80px;
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1.5rem auto;
    color: white;
    font-size: 2rem;
    box-shadow: var(--chat-shadow);
    transition: transform 0.3s ease;
}

.chat-service-card:hover .chat-service-icon {
    transform: scale(1.1) rotate(5deg);
}

/* Service-specific gradient colors */
.chat-service-icon {
    background: var(--chat-gradient);
}

.anythingllm-icon {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
}

.lm-studio-icon {
    background: linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%);
}

.chatgpt-icon {
    background: linear-gradient(135deg, #10a37f 0%, #0d8c6e 100%);
}

.claude-icon {
    background: linear-gradient(135deg, #cc785c 0%, #b5693e 100%);
}

.grok-icon {
    background: linear-gradient(135deg, #1da1f2 0%, #0d8bd9 100%);
}

.gemini-icon {
    background: linear-gradient(135deg, #4285f4 0%, #1a73e8 100%);
}

.qwen-icon {
    background: linear-gradient(135deg, #722ed1 0%, #531dab 100%);
}

.perplexity-icon {
    background: linear-gradient(135deg, #1fb6ff 0%, #0ea5e9 100%);
}

/* Personal Assistant Icon (D-One Principal) */
.personal-assistant-icon {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
}

/* Official Provider Icons */
.provider-logo {
    width: 50px;
    height: 50px;
    border-radius: 12px;
    object-fit: contain;
    background: white;
    padding: 6px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}


.chat-service-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0 0 0.5rem 0;
    color: var(--chat-text);
}

.chat-service-subtitle {
    color: var(--chat-text-muted);
    font-size: 0.95rem;
    font-weight: 500;
    margin: 0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Chat Service Body */
.chat-service-body {
    flex-grow: 1;
    margin-bottom: 1.5rem;
}

.chat-service-description {
    color: var(--chat-text-muted);
    line-height: 1.6;
    margin-bottom: 1.5rem;
    font-size: 0.95rem;
}

.chat-service-features {
    list-style: none;
    padding: 0;
    margin: 0;
}

.chat-service-features li {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0;
    color: var(--chat-text-muted);
    font-size: 0.9rem;
    border-bottom: 1px solid var(--chat-border);
}

.chat-service-features li:last-child {
    border-bottom: none;
}

.chat-service-features li i {
    color: var(--chat-primary);
    font-size: 0.8rem;
    width: 16px;
    text-align: center;
}

/* Chat Service Footer */
.chat-service-footer {
    display: flex;
    gap: 1rem;
    margin-top: auto;
}

/* Single button footer (per servizi esterni) */
.chat-service-footer:has(a:only-child) {
    justify-content: center;
}

/* Enhanced Buttons */
.chat-service-btn {
    flex: 1;
    padding: 0.875rem 1.5rem;
    border-radius: 12px;
    font-weight: 600;
    font-size: 0.9rem;
    text-decoration: none;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: 2px solid transparent;
    position: relative;
    overflow: hidden;
}

.btn-primary {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.15), rgba(118, 75, 162, 0.15));
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(102, 126, 234, 0.3);
    color: var(--primary, #667eea);
    border-radius: var(--radius-md, 12px);
    font-weight: var(--font-weight-semibold, 600);
    text-decoration: none;
    transition: all 0.3s ease;
    margin-top: auto;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.1);
}


.btn-secondary {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    background: linear-gradient(135deg, rgba(67, 68, 74, 0.15), rgba(118, 75, 162, 0.15));
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(49, 53, 70, 0.3);
    color: var(--primary, #3a3228);
    border-radius: var(--radius-md, 12px);
    font-weight: var(--font-weight-semibold, 600);
    text-decoration: none;
    transition: all 0.3s ease;
    margin-top: auto;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.1);
}


.btn-primary:hover {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.25), rgba(118, 75, 162, 0.25));
    border-color: rgba(102, 126, 234, 0.5);
    color: var(--primary-hover, #4f46e5);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.25);
}


.btn-primary-chat {
    background: var(--chat-gradient);
    color: white;
    box-shadow: var(--chat-shadow);



}

.btn-primary-chat:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px -5px rgba(6, 182, 212, 0.4);
    color: white;
}

.btn-secondary-chat {
    background: transparent;
    color: var(--chat-text-muted);
    border-color: var(--chat-border);
}

.btn-secondary-chat:hover {
    background: var(--chat-surface-alt);
    border-color: var(--chat-primary);
    color: var(--chat-primary);
    transform: translateY(-2px);
}

.page-header {
    padding: 0.1rem 0.1rem;
    margin-bottom: 0rem;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    /* Responsive delegato a .container-responsive (global) */

    .page-title {
        font-size: 2rem;
        gap: 1rem;
    }

    .page-header {
        padding: 1rem 1rem;
        margin-bottom: 2rem;
    }

    .chat-services-grid {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }
}

@media (max-width: 992px) and (min-width: 769px) {
    .chat-services-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 1.5rem;
    }
}

@media (max-width: 480px) {
    .page-title {
        font-size: 1.75rem;
        flex-direction: column;
        gap: 0.5rem;
    }

    .chat-service-footer {
        flex-direction: column;
        gap: 0.75rem;
    }

    .chat-service-btn {
        text-align: center;
    }
}

/* Nascondere le ultime 6 chat-service-card per modelli esterni */
.chat-services-grid .chat-service-card:nth-last-child(-n+6) {
    display: none;
}

/* ==========================================
   Content Processing Menu & YouTube
   ========================================== */
.processing-menu {
    background: var(--bg-secondary, #f8f9fa);
    border: 1px solid var(--border-color, #dee2e6);
    border-radius: 8px;
    padding: 12px;
    margin: 8px 0;
}

.processing-menu-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.btn-close-sm {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    color: var(--text-muted, #6c757d);
    padding: 2px 6px;
}

.processing-menu-steps {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 10px;
}

.processing-step-toggle {
    display: flex;
    align-items: center;
    gap: 4px;
    background: var(--bg-primary, #fff);
    border: 1px solid var(--border-color, #dee2e6);
    border-radius: 6px;
    padding: 4px 10px;
    cursor: pointer;
    font-size: 0.85rem;
}

.processing-step-toggle input:checked + span {
    font-weight: 600;
    color: var(--primary-color, #007bff);
}

.processing-menu-actions {
    display: flex;
    gap: 8px;
}

.btn-sm {
    padding: 4px 12px;
    font-size: 0.8rem;
    border-radius: 4px;
}

/* YouTube input */
.youtube-input-area {
    display: flex;
    gap: 6px;
    align-items: center;
    padding: 8px 0;
}

.youtube-url-input {
    flex: 1;
    padding: 6px 10px;
    border: 1px solid #cc0000;
    border-radius: 6px;
    font-size: 0.85rem;
}

.youtube-url-input:focus {
    outline: none;
    border-color: #ff0000;
    box-shadow: 0 0 0 2px rgba(255, 0, 0, 0.15);
}

/* Processing progress bubble */
.processing-progress {
    padding: 12px;
    color: var(--text-primary, #333);
}

.processing-progress .fa-spinner {
    margin-right: 6px;
    color: var(--primary-color, #007bff);
}

.progress-bar-mini {
    height: 4px;
    background: var(--bg-secondary, #e9ecef);
    border-radius: 2px;
    margin-top: 8px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--primary-color, #007bff);
    border-radius: 2px;
    transition: width 0.5s ease;
}

/* Processing result */
.processing-result details {
    margin-bottom: 8px;
}

.processing-result summary {
    cursor: pointer;
    padding: 4px 0;
}

.processing-text {
    max-height: 300px;
    overflow-y: auto;
    white-space: pre-wrap;
    font-size: 0.85rem;
    padding: 8px;
    background: var(--bg-secondary, #f8f9fa);
    border-radius: 4px;
    margin-top: 4px;
}

.processing-error {
    color: #dc3545;
    padding: 8px;
}

.processing-error .fa-exclamation-triangle {
    margin-right: 6px;
}

.notification-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 10px;
    padding: 5px 10px;
    background: rgba(37, 211, 102, 0.12);
    border: 1px solid rgba(37, 211, 102, 0.35);
    border-radius: 6px;
    font-size: 0.82em;
    color: #1a8a45;
}

.notification-badge .fa-bell {
    font-size: 0.9em;
}

/* ========================================
   YOUTUBE INLINE OPTIONS CARD
   ======================================== */

.yt-options-card {
    background: var(--bg-secondary, #f8f9fa);
    border: 1px solid #e0e0e0;
    border-left: 4px solid #ff0000;
    border-radius: 12px;
    padding: 16px;
    margin: 4px 0;
}

.yt-options-card .yt-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    font-size: 0.95rem;
}

.yt-options-card .yt-header i {
    color: #ff0000;
    font-size: 1.2rem;
}

.yt-options-card .yt-url-preview {
    font-size: 0.8rem;
    color: #666;
    margin-bottom: 12px;
    word-break: break-all;
}

.yt-options-card .yt-steps {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 14px;
}

.yt-options-card .yt-step-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 20px;
    border: 1px solid #ddd;
    background: #fff;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.85rem;
    -webkit-user-select: none;
    user-select: none;
}

.yt-options-card .yt-step-chip:hover {
    border-color: #aaa;
}

.yt-options-card .yt-step-chip.selected {
    background: #e8f4fd;
    border-color: #2196f3;
    color: #1565c0;
}

.yt-options-card .yt-step-chip input[type="checkbox"] {
    display: none;
}

.yt-options-card .yt-step-chip .chip-check {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 2px solid #ccc;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    transition: all 0.2s;
}

.yt-options-card .yt-step-chip.selected .chip-check {
    background: #2196f3;
    border-color: #2196f3;
    color: #fff;
}

.yt-options-card .yt-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.yt-options-card .yt-start-btn {
    background: #2196f3;
    color: #fff;
    border: none;
    padding: 8px 20px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: background 0.2s;
}

.yt-options-card .yt-start-btn:hover {
    background: #1976d2;
}

.yt-options-card .yt-start-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.yt-options-card .yt-skip-btn {
    background: transparent;
    border: 1px solid #ddd;
    padding: 8px 16px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.83rem;
    color: #666;
    transition: all 0.2s;
}

.yt-options-card .yt-skip-btn:hover {
    border-color: #999;
    color: #333;
}

/* Progress inline nella card */
.yt-processing-status {
    margin-top: 12px;
}

.yt-processing-status .progress-label {
    font-size: 0.83rem;
    color: #555;
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.yt-processing-status .progress-bar-inline {
    height: 6px;
    background: #e0e0e0;
    border-radius: 3px;
    overflow: hidden;
}

.yt-processing-status .progress-bar-inline .progress-fill-inline {
    height: 100%;
    background: linear-gradient(90deg, #2196f3, #42a5f5);
    border-radius: 3px;
    transition: width 0.4s ease;
}

/* ========================================
   MOBILE FIXES (layout, off-canvas, controls)
   ======================================== */

.mobile-only-btn {
    display: none;
}

.mobile-panel-overlay {
    display: none;
}

.mobile-panel-triggers {
    display: none;
}

@media (max-width: 992px) {
    .chat-layout {
        grid-template-columns: 1fr !important;
        height: auto;
        min-height: 0;
        margin-top: 0;
        gap: 12px;
    }

    .chat-area {
        min-height: 0;
    }

    .messages-container {
        min-height: 280px;
        max-height: none;
    }

    .mobile-panel-triggers {
        display: block;
        pointer-events: none;
        position: sticky;
        top: var(--space-3);
        z-index: 20;
        min-height: 0;
    }

    .mobile-panel-trigger {
        pointer-events: auto;
        position: absolute;
        top: 0;
        width: 40px;
        height: 40px;
        border: 1px solid var(--border-color);
        border-radius: 999px;
        background: color-mix(in srgb, var(--bg-card) 92%, transparent);
        color: var(--text-primary);
        box-shadow: var(--shadow-md);
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .mobile-panel-trigger-left {
        left: var(--space-2);
    }

    .mobile-panel-trigger-right {
        right: var(--space-2);
    }

    .sessions-sidebar {
        position: fixed;
        top: var(--header-height, 72px);
        left: 0;
        width: min(88vw, 360px);
        height: calc(100vh - var(--header-height, 72px));
        transform: translateX(-105%);
        transition: transform var(--transition-base);
        z-index: 1045;
        display: flex !important;
        border-radius: 0 var(--radius-lg) var(--radius-lg) 0;
        box-shadow: var(--shadow-xl);
        background: var(--bg-card);
        border: 1px solid var(--border-color);
    }

    .context-panel {
        position: fixed;
        top: var(--header-height, 72px);
        right: 0;
        width: min(88vw, 360px);
        height: calc(100vh - var(--header-height, 72px));
        transform: translateX(105%);
        transition: transform var(--transition-base);
        z-index: 1045;
        display: flex !important;
        border-radius: var(--radius-lg) 0 0 var(--radius-lg);
        box-shadow: var(--shadow-xl);
        background: var(--bg-card);
        border: 1px solid var(--border-color);
    }

    .sessions-sidebar.visible {
        transform: translateX(0);
        z-index: 1045;
    }

    .context-panel.visible {
        transform: translateX(0);
        z-index: 1045;
    }

    .sessions-sidebar.sidebar-collapsed,
    .context-panel.context-collapsed {
        width: min(88vw, 360px) !important;
        min-width: auto !important;
        max-width: none !important;
        padding: var(--space-4) !important;
    }

    .sessions-sidebar.sidebar-collapsed .sidebar-content,
    .context-panel.context-collapsed .context-content {
        display: flex !important;
    }

    .sessions-sidebar.sidebar-collapsed .sidebar-quick-actions,
    .context-panel.context-collapsed .context-quick-actions {
        display: none !important;
    }

    .mobile-panel-overlay {
        display: none;
        position: fixed;
        inset: var(--header-height, 72px) 0 0 0;
        background: rgba(15, 23, 42, 0.35);
        backdrop-filter: blur(1px);
        z-index: 1040;
    }

    .mobile-panel-overlay.visible {
        display: block;
    }

    .chat-layout.mobile-panel-open .chat-area {
        display: none;
    }

    .chat-layout.mobile-panel-open .mobile-panel-triggers {
        display: none;
    }

    .sessions-sidebar .sidebar-content,
    .context-panel .context-content {
        background: transparent;
    }
}

@media (max-width: 768px) {
    .chat-input-area {
        padding: 10px;
    }

    .chat-textarea {
        min-height: 52px;
        max-height: 160px;
    }

    .input-controls {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 8px;
        align-items: stretch;
    }

    .input-controls .btn {
        width: 100%;
        min-width: 0;
        height: 44px;
        min-height: 44px;
        padding: 8px 6px;
        font-size: 0.8rem;
        line-height: 1;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 6px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    #micBtn {
        height: 44px;
        min-height: 44px;
        padding: 8px 6px;
    }

    #toggleLightRagBtn.lightrag-toggle-btn {
        width: 100%;
        min-width: 0;
        max-width: none;
    }
}

@media (max-width: 480px) {
    .input-controls {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

/* Log modal sizing: 90% viewport */
#logDetailModal .log-detail-modal-dialog {
    width: 90vw;
    max-width: 90vw;
    height: 90vh;
    margin: auto;
}

#logDetailModal .modal-content {
    height: 100%;
    display: flex;
    flex-direction: column;
}

#logDetailModal .modal-body {
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

#logDetailModal .log-container {
    flex: 1;
    min-height: 0;
    height: 100%;
    max-height: none;
    overflow: auto;
}

/* Keep centralized footer links readable on this page */
body.agent-page #d-one-footer .footer-content p a,
body.agent-page .footer .footer-content p a,
body.agent-page #d-one-footer .footer-content p a:visited,
body.agent-page .footer .footer-content p a:visited {
    color: rgba(255, 255, 255, 0.95) !important;
    text-decoration: underline;
    text-underline-offset: 2px;
    font-weight: 600;
}

body.agent-page #d-one-footer .footer-content p a:hover,
body.agent-page .footer .footer-content p a:hover,
body.agent-page #d-one-footer .footer-content p a:focus,
body.agent-page .footer .footer-content p a:focus {
    color: #ffffff !important;
}

/* ========================================
   MOBILE RESPONSIVE OPTIMIZATION
   ======================================== */

/* Mobile: welcome section padding e viewport height */
@media (max-width: 992px) {
    body.agent-page {
        height: auto;
        overflow-y: auto;
    }

    body.agent-page main {
        height: auto;
        overflow: visible;
    }

    body.agent-page .main-layout.full-width {
        height: auto;
        overflow: visible;
    }

    .messages-container {
        min-height: 50vh;
        min-height: 50dvh;
    }
}

@media (max-width: 768px) {
    .welcome-message {
        padding: var(--space-6) var(--space-3);
        max-width: 100%;
    }

    .welcome-icon {
        width: 64px;
        height: 64px;
    }

    .welcome-icon-img {
        width: 52px;
        height: 52px;
    }

    .welcome-message h3 {
        font-size: 1.25rem;
    }

    .welcome-message p {
        font-size: var(--font-size-base);
        margin-bottom: var(--space-4);
    }

    .feature-item {
        font-size: var(--font-size-xs, 0.75rem);
    }

    .feature-item i {
        font-size: 1.2rem;
    }

    /* Attachment info su mobile */
    .attachment-chip {
        max-width: 100%;
        word-break: break-all;
    }

    /* Button text labels: nascondi testo su mobile stretto, mostra solo icona */
    .input-controls .btn span {
        display: none;
    }

    #sendBtn span {
        display: inline !important;
    }

    #newSessionBtn span {
        display: none;
    }
}

@media (max-width: 480px) {
    .welcome-message {
        padding: var(--space-4) var(--space-2);
    }

    .welcome-features {
        gap: var(--space-3);
    }

    .input-controls {
        grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
        gap: 6px;
    }

    .input-controls .btn {
        height: 40px;
        min-height: 40px;
        padding: 6px 4px;
        font-size: 0.75rem;
    }

    /* RAG toggle su mobile: larghezza auto */
    #toggleLightRagBtn.lightrag-toggle-btn {
        width: auto;
        min-width: 0;
        max-width: none;
    }
}

/* Desktop chat viewport lock: keep vertical scroll inside .messages-container */
@media (min-width: 993px) {
    body.agent-page {
        height: 100vh;
        overflow-y: hidden;
    }

    body.agent-page main {
        height: 100%;
        overflow: hidden;
    }

    body.agent-page .main-layout.full-width {
        height: 100%;
        box-sizing: border-box;
        overflow: hidden;
    }

    body.agent-page .chat-layout {
        height: 100%;
        min-height: 0;
        margin-bottom: 0;
    }

    body.agent-page .chat-area,
    body.agent-page .messages-container {
        min-height: 0;
    }

    /* Force full-width layout without extra side gutters */
    body.agent-page main > .main-layout.full-width {
        width: 98vw !important;
        max-width: 98vw !important;
        margin: 0 auto !important;
        margin-bottom: 20px !important;
        padding-top: calc(var(--header-height, 72px) + 6px) !important;
        padding-right: 0 !important;
        padding-bottom: 0 !important;
        padding-left: 0 !important;
    }
}
