/* ============================================
   BookChat v2 - Styles
   Allineato a Platform UI Standards
   ============================================ */

/* ============================================
   LAYOUT VARIABLES - Modifica qui le % delle colonne
   ============================================ */

:root {
    /* Larghezze colonne app-grid (Desktop) */
    --bookchat-sidebar-width: 250px;      /* Larghezza sidebar documenti */
    --bookchat-chapters-width: 260px;     /* Larghezza panel capitoli */
    --bookchat-chapters-width-expanded: 320px; /* Larghezza capitoli quando la sidebar è chiusa */
    --bookchat-main-min: 360px;           /* Larghezza minima panel PDF */
    --bookchat-main-fr: 0.9fr;            /* Quota flessibile panel PDF */
    --bookchat-main-fr-expanded: 0.85fr;  /* Quota flessibile con colonne chiuse */
    --bookchat-chat-min: 460px;           /* Larghezza minima chat */
    --bookchat-chat-fr: 1.1fr;            /* Quota flessibile chat (base) */
    --bookchat-chat-fr-expanded: 1.3fr;   /* Quota flessibile chat quando c'è più spazio */
    --bookchat-chat-fr-current: var(--bookchat-chat-fr); /* Valore regolabile via slider */
    --bookchat-chat-fr-expanded-current: var(--bookchat-chat-fr-expanded); /* Valore regolabile via slider */
    /* La colonna main usa 1fr (occupa lo spazio rimanente) */
    
    /* Larghezze colonne app-grid (Tablet) */
    --bookchat-chat-width-tablet: 520px;  /* Larghezza chat su tablet, ampliata */

    /* PDF viewer max width (desktop) */
    --bookchat-pdf-max-width: 88%;
    --bookchat-pdf-padding: var(--space-3);
}

/* ============================================
   HEADER STANDARDIZATION
   ============================================ */

/* Assicura che l'header mantenga le dimensioni standard */
.main-header .header-nav .nav-btn {
    padding: 12px 20px !important;
    min-height: 25px !important;
    line-height: 1.2 !important;
    font-size: 1rem !important;
}

/* Assicura che il container header mantenga l'altezza standard */
.main-header .header-container {
    height: 70px !important;
}

/* ============================================
   LAYOUT PRINCIPALE
   ============================================ */

.app-wrapper {
    margin-top: var(--header-height, 70px);
    min-height: calc(100vh - var(--header-height, 70px) - var(--footer-height, 60px));
    background: var(--bg-body);
    padding: var(--space-4);
    padding-bottom: var(--space-2); /* Spazio extra per il footer */
}

.app-grid {
    display: grid;
    grid-template-columns: var(--bookchat-sidebar-width) var(--bookchat-chapters-width) minmax(var(--bookchat-main-min), var(--bookchat-main-fr)) minmax(var(--bookchat-chat-min), var(--bookchat-chat-fr-current));
    grid-template-areas: "sidebar chapters main chat";
    gap: var(--space-4);
    height: calc(100vh - var(--header-height, 70px) - var(--footer-height, 60px) - var(--space-8));
    margin: 0 auto;
    max-height: calc(100vh - var(--header-height, 70px) - var(--footer-height, 60px) - var(--space-8));
}

/* ============================================
   RESPONSIVE LAYOUT
   ============================================ */

/* Tablet: Hide sidebar, stack PDF and chat */
@media (max-width: 992px) {
    .app-grid {
        grid-template-columns: 1fr var(--bookchat-chat-width-tablet);
        grid-template-areas: "main chat";
        height: calc(100vh - var(--header-height, 70px) - var(--footer-height, 60px) - var(--space-8));
        max-height: calc(100vh - var(--header-height, 70px) - var(--footer-height, 60px) - var(--space-8));
    }

    .sidebar-container {
        display: none; /* Nascosto su tablet/mobile */
    }
}

/* Mobile: Stack verticale */
@media (max-width: 768px) {
    .app-wrapper {
        padding: var(--space-2);
        min-height: calc(100vh - var(--header-height, 70px) - var(--footer-height, 60px));
    }

    .app-grid {
        grid-template-columns: 1fr;
        grid-template-areas:
            "main"
            "chat";
        gap: var(--space-2);
        height: calc(100vh - var(--header-height, 70px) - var(--footer-height, 60px) - var(--space-4));
        max-height: calc(100vh - var(--header-height, 70px) - var(--footer-height, 60px) - var(--space-4));
    }

    .chat-container {
        height: 400px; /* Altezza fissa su mobile */
    }
}

/* ============================================
   SIDEBAR: Document List
   ============================================ */

.sidebar-container {
    grid-area: sidebar;
    background: var(--bg-card);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: var(--box-shadow);
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-4);
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-card-header, var(--gray-750));
}

.sidebar-header-actions {
    display: flex;
    gap: var(--space-2);
    align-items: center;
}

/* Pulsanti sidebar header - stesso stile dei mode-btn */
.sidebar-header-actions button {
    padding: var(--space-2) var(--space-3);
    background: var(--bg-hover);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: var(--font-size-xs);
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-1);
    min-width: auto;
    width: auto;
}

.sidebar-header-actions button:hover {
    background: var(--primary-bg-light, rgba(102, 126, 234, 0.1));
    border-color: var(--primary);
    color: var(--primary);
}

.sidebar-header-actions button:active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

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

.sidebar-title i {
    color: var(--primary);
}

/* Chapters panel shares base sidebar style */
.chapters-container {
    grid-area: chapters;
}

.chapters-list {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-3);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    background: var(--bg-card);
}

.chapters-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-3);
    border-bottom: 1px solid var(--border-color);
}

.chapters-header h3 {
    margin: 0;
    color: var(--text-primary);
}

.chapters-header p {
    margin: 2px 0 0;
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
}

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

.chapter-item {
    width: 100%;
    text-align: left;
    background: var(--bg-hover);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: var(--space-3);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--space-3);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.chapter-item:hover {
    border-color: var(--primary);
    box-shadow: var(--box-shadow-sm);
}

.chapter-meta {
    display: flex;
    gap: var(--space-2);
    align-items: flex-start;
}

.chapter-number {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--primary-bg-light, rgba(102, 126, 234, 0.15));
    color: var(--primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: var(--font-weight-semibold);
    font-size: var(--font-size-sm);
    flex-shrink: 0;
}

.chapter-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.chapter-title {
    font-weight: var(--font-weight-semibold);
    color: var(--text-primary);
    font-size: var(--font-size-sm);
}

.chapter-desc {
    color: var(--text-secondary);
    font-size: var(--font-size-xs);
}

.chapter-cta {
    color: var(--primary);
    font-weight: var(--font-weight-semibold);
    font-size: var(--font-size-xs);
}

.chapters-empty {
    text-align: center;
    color: var(--text-secondary);
    padding: var(--space-4);
    background: var(--bg-hover);
    border: 1px dashed var(--border-color);
    border-radius: var(--radius-sm);
}

/* Sidebar collapsed state */
.sidebar-container.collapsed {
    width: 0;
    min-width: 0;
    overflow: hidden;
    padding: 0;
    border: none;
    opacity: 0;
    transition: all var(--transition-normal);
}

.sidebar-container.collapsed .sidebar-header,
.sidebar-container.collapsed .document-list {
    display: none;
}

/* Quando sidebar è collapsed, aggiorna grid */
.app-grid.sidebar-collapsed {
    grid-template-columns: 0 var(--bookchat-chapters-width-expanded) minmax(var(--bookchat-main-min), var(--bookchat-main-fr)) minmax(var(--bookchat-chat-min), var(--bookchat-chat-fr-expanded-current));
}

.chapters-container.collapsed {
    width: 0;
    min-width: 0;
    overflow: hidden;
    padding: 0;
    border: none;
    opacity: 0;
    transition: all var(--transition-normal);
}

.chapters-container.collapsed .sidebar-header,
.chapters-container.collapsed .chapters-list,
.chapters-container.collapsed .chapters-empty {
    display: none;
}

.app-grid.chapters-collapsed {
    grid-template-columns: var(--bookchat-sidebar-width) 0 minmax(var(--bookchat-main-min), var(--bookchat-main-fr-expanded)) minmax(var(--bookchat-chat-min), var(--bookchat-chat-fr-expanded-current));
}

.app-grid.sidebar-collapsed.chapters-collapsed {
    grid-template-columns: 0 0 minmax(var(--bookchat-main-min), var(--bookchat-main-fr-expanded)) minmax(var(--bookchat-chat-min), var(--bookchat-chat-fr-expanded-current));
}

/* Bottone toggle sidebar */
#toggleSidebarBtn {
    transition: transform var(--transition-fast);
}

/* Pulsanti floating legacy (nascosti: sostituiti dalla rail sottile) */
.sidebar-toggle-floating,
.chapters-toggle-floating {
    display: none !important;
}

/* Barra sottile per riapertura pannelli collassati */
.collapsed-rail {
    position: fixed;
    left: var(--space-2);
    top: var(--space-2);
    width: 46px;
    padding: 10px 6px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: var(--color-surface, #fff);
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: 14px;
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.14);
    z-index: 120;
    backdrop-filter: blur(6px);
}

.collapsed-rail .rail-btn {
    width: 34px;
    height: 34px;
    border-radius: 12px;
    border: 1px solid var(--color-border-subtle, #eceff4);
    background: var(--color-surface-elevated, #f8fafc);
    color: var(--color-text-secondary, #6b7280);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition-fast) ease;
}

.collapsed-rail .rail-btn.active {
    background: var(--primary-soft, rgba(99, 102, 241, 0.14));
    color: var(--primary-strong, #4f46e5);
    border-color: var(--primary, #6366f1);
}

.collapsed-rail .rail-btn:hover {
    background: var(--color-surface-hover, #f1f5f9);
    color: var(--color-text, #0f172a);
    transform: translateY(-1px);
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.12);
}

.collapsed-rail .rail-btn:active {
    transform: translateY(0);
    box-shadow: 0 8px 18px rgba(0, 0, 0, 0.1);
}

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

.document-item {
    padding: var(--space-3) var(--space-4);
    margin-bottom: var(--space-2);
    background: var(--bg-hover);
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    cursor: pointer;
    transition: all var(--transition-fast);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.document-item:hover {
    background: var(--primary-bg-light, rgba(102, 126, 234, 0.1));
    border-color: var(--primary);
    transform: translateX(4px);
}

.document-item.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary-hover);
}

.document-item.active .document-name {
    color: white;
    font-weight: var(--font-weight-semibold);
}

.document-name {
    font-size: var(--font-size-sm);
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.document-delete {
    background: none;
    border: none;
    color: var(--danger);
    cursor: pointer;
    padding: var(--space-1);
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.document-item:hover .document-delete {
    opacity: 1;
}

.document-delete:hover {
    color: var(--danger-hover, #dc2626);
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-8);
    color: var(--text-muted);
    text-align: center;
}

.empty-state i {
    margin-bottom: var(--space-4);
    color: var(--gray-600);
}

/* ============================================
   MAIN CONTAINER: File Upload + PDF Viewer
   ============================================ */

.main-container {
    grid-area: main;
    background: var(--bg-card);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: var(--box-shadow);
}

/* ============================================
   FILE UPLOAD
   ============================================ */

.file-upload-container {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: var(--space-6);
}

.upload-card {
    text-align: center;
    max-width: 500px;
    width: 100%;
}

.upload-area {
    padding: var(--space-10);
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-lg);
    background: var(--bg-hover);
    transition: all var(--transition-normal);
}

.upload-area.drag-over {
    border-color: var(--primary);
    background: var(--primary-bg-light, rgba(102, 126, 234, 0.1));
    transform: scale(1.02);
}

.upload-icon {
    margin-bottom: var(--space-4);
    color: var(--primary);
}

.upload-title {
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-bold);
    color: var(--text-primary);
    margin-bottom: var(--space-2);
}

.upload-subtitle {
    font-size: var(--font-size-base);
    color: var(--text-secondary);
    margin-bottom: var(--space-6);
}

.upload-hint {
    font-size: var(--font-size-sm);
    color: var(--text-muted);
    margin-top: var(--space-4);
}

/* Upload Progress */
.upload-progress {
    margin-top: var(--space-6);
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: var(--gray-700);
    border-radius: var(--radius-full);
    overflow: hidden;
    margin-bottom: var(--space-3);
}

.progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--primary-2));
    border-radius: var(--radius-full);
    transition: width 0.3s ease;
    width: 0%;
}

.upload-status {
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
}

/* ============================================
   PDF VIEWER
   ============================================ */

.pdf-viewer-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    max-height: 100%; /* Rispetta l'altezza del container padre */
}

/* PDF Content Area - deve scrollare */
.pdf-viewer-container > div:last-child,
.pdf-viewer-container #pdfViewerRoot {
    flex: 1;
    overflow-y: auto !important; /* Abilita scroll verticale */
    overflow-x: hidden;
    min-height: 0; /* Importante per flex children con overflow */
}

.pdf-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-3) var(--space-4);
    background: var(--gray-750);
    border-bottom: 1px solid var(--border-color);
    gap: var(--space-4);
}

.toolbar-left,
.toolbar-center,
.toolbar-right {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.toolbar-center {
    flex: 1;
    justify-content: center;
}

.btn-tool {
    background: var(--bg-hover);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    font-size: var(--font-size-sm);
}

.btn-tool:hover:not(:disabled) {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.btn-tool:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.page-info,
.zoom-level,
.document-title {
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    white-space: nowrap;
}

.document-title {
    font-weight: var(--font-weight-semibold);
    color: var(--text-primary);
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pdf-viewer-root {
    flex: 1;
    overflow: auto;
    background: var(--gray-900);
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: var(--bookchat-pdf-padding);
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
}

@media (min-width: 1200px) {
    .pdf-viewer-root {
        max-width: var(--bookchat-pdf-max-width);
        padding: var(--bookchat-pdf-padding);
    }
}

/* ============================================
   BOOKMIND PANEL
   ============================================ */

.bookmind-panel {
    margin: var(--space-4);
    margin-top: 0;
    background: var(--bg-hover);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: var(--space-4);
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.bookmind-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: var(--space-3);
}

.bookmind-header h3 {
    margin: 0;
    color: var(--text-primary);
}

.bookmind-header p {
    margin: var(--space-1) 0 0;
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
}

.bookmind-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 8px;
    border-radius: var(--radius-pill);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-semibold);
    margin-left: var(--space-2);
}

.bookmind-badge.success {
    background: rgba(52, 211, 153, 0.15);
    color: #34d399;
}

.bookmind-badge.danger {
    background: rgba(248, 113, 113, 0.15);
    color: #f87171;
}

.chapter-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.chapter-card {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: var(--space-3);
    background: var(--bg-card);
    box-shadow: var(--box-shadow-soft);
}

.chapter-header {
    display: flex;
    gap: var(--space-3);
    align-items: flex-start;
    margin-bottom: var(--space-3);
}

.chapter-number {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--primary-bg-light, rgba(102, 126, 234, 0.1));
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: var(--font-weight-semibold);
}

.chapter-title {
    font-weight: var(--font-weight-semibold);
    color: var(--text-primary);
}

.chapter-desc {
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
}

.analysis-actions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: var(--space-2);
}

.analysis-btn {
    border: 1px solid var(--border-color);
    background: var(--bg-hover);
    color: var(--text-primary);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    text-align: left;
    cursor: pointer;
    transition: all var(--transition-fast);
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

.analysis-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
    transform: translateY(-1px);
}

.analysis-desc {
    font-size: var(--font-size-xs);
    color: var(--text-secondary);
}

.bookmind-empty,
.bookmind-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-4);
    color: var(--text-secondary);
    text-align: center;
}

.bookmind-loading .spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Modal for analysis selection */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: var(--space-4);
}

.modal-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    width: min(500px, 92vw);
    box-shadow: var(--box-shadow-lg);
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    padding: var(--space-4);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
}

.modal-header h4 {
    margin: 0;
    color: var(--text-primary);
}

.modal-close {
    background: transparent;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    color: var(--text-secondary);
}

.modal-body p {
    margin: 0 0 var(--space-2) 0;
    color: var(--text-primary);
    font-weight: var(--font-weight-semibold);
}

.analysis-choice-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-2);
}

@media (max-width: 640px) {
    .analysis-choice-grid {
        grid-template-columns: 1fr;
    }
}

.analysis-choice {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: var(--space-3);
    background: var(--bg-hover);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    text-align: left;
    transition: all var(--transition-fast);
}

.analysis-choice:hover {
    border-color: var(--primary);
    box-shadow: var(--box-shadow-sm);
}

.analysis-choice strong {
    color: var(--text-primary);
}

.analysis-choice span {
    color: var(--text-secondary);
    font-size: var(--font-size-xs);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
}

/* ============================================
   CHAT PANEL
   ============================================ */

.chat-container {
    grid-area: chat;
    background: var(--bg-card);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: var(--box-shadow);
}

.chat-header {
    padding: var(--space-4);
    border-bottom: 1px solid var(--border-color);
    background: var(--gray-750);
}

.chat-title {
    font-size: var(--font-size-lg);
    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);
}

.chat-title i {
    color: var(--primary);
}

.chat-mode-selector {
    display: flex;
    gap: var(--space-2);
}

.chat-width-control {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    padding: 0 var(--space-2);
    background: var(--bg-hover);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
}

.chat-width-control input[type="range"] {
    width: 100px;
    accent-color: var(--primary);
    background: transparent;
}

.mode-btn {
    flex: 1;
    padding: var(--space-2) var(--space-3);
    background: var(--bg-hover);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: var(--font-size-xs);
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-1);
}

.mode-btn:hover {
    background: var(--primary-bg-light, rgba(102, 126, 234, 0.1));
    border-color: var(--primary);
}

.mode-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    font-weight: var(--font-weight-semibold);
}

/* Messages Container */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-4);
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.empty-chat {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    text-align: center;
}

.empty-chat i {
    margin-bottom: var(--space-4);
    color: var(--gray-600);
}

/* Message Bubbles */
.message {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    animation: fadeInUp 0.3s ease;
}

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

.message.assistant {
    align-self: flex-start;
}

.message-bubble {
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    word-wrap: break-word;
    line-height: 1.6;
}

.message.user .message-bubble {
    background: #a9abf5;
    color: white;
    border-bottom-right-radius: var(--radius-sm);
}

.message.assistant .message-bubble {
    background: #cfddf4;
    color: var(--text-primary);
    border-bottom-left-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
}

.message-content {
    color: inherit;
}

.message-bubble .bubble-preview {
    margin-bottom: var(--space-3);
    padding: var(--space-3);
    border-radius: var(--radius-md);
    border: 1px solid rgba(0, 0, 0, 0.1);
    background: rgba(0, 0, 0, 0.05);
}

.message.user .bubble-preview {
    background: rgba(255, 255, 255, 0.14);
    border-color: rgba(255, 255, 255, 0.32);
}

.message.assistant .bubble-preview {
    background: rgba(255, 255, 255, 0.9);
    border-color: rgba(0, 0, 0, 0.08);
}

.bubble-preview-header {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-weight: var(--font-weight-semibold);
    color: inherit;
    margin-bottom: var(--space-2);
}

.bubble-preview-header i {
    opacity: 0.7;
}

.bubble-preview-body {
    background: var(--gray-900);
    border-radius: var(--radius-sm);
    padding: var(--space-2);
    display: flex;
    justify-content: center;
}

.bubble-preview-body img {
    max-width: 320px;
    width: 100%;
    max-height: 220px;
    object-fit: contain;
    border-radius: var(--radius-sm);
    background: var(--gray-800);
}

.bubble-preview-caption {
    margin: var(--space-2) 0 0;
    font-size: var(--font-size-sm);
    color: inherit;
    opacity: 0.85;
}

.bubble-preview + .message-content {
    margin-top: var(--space-2);
}

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

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

/* Markdown Content Styling */
.message-bubble h1,
.message-bubble h2,
.message-bubble h3 {
    margin-top: var(--space-3);
    margin-bottom: var(--space-2);
    color: inherit;
}

.message-bubble p {
    margin-bottom: var(--space-2);
}

.message-bubble ul,
.message-bubble ol {
    margin-left: var(--space-4);
    margin-bottom: var(--space-2);
}

.message-bubble code {
    background: var(--gray-800);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 0.9em;
}

.message-bubble pre {
    background: var(--gray-900);
    padding: var(--space-3);
    border-radius: var(--radius-sm);
    overflow-x: auto;
    margin-bottom: var(--space-2);
}

.message-bubble pre code {
    background: none;
    padding: 0;
}

/* KaTeX Math */
.katex {
    font-size: 1.1em;
}

.katex-display {
    margin: var(--space-3) 0;
    overflow-x: auto;
}

/* Loading Animation */
.message.loading .message-bubble {
    padding: var(--space-4);
}

.typing-indicator {
    display: flex;
    gap: 6px;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.5;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

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

.chat-input-container {
    border-top: 1px solid var(--border-color);
    padding: var(--space-4);
    background: var(--gray-750);
}

.visual-input-area {
    margin-bottom: var(--space-3);
}

.visual-selection-preview {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    padding: var(--space-3);
    margin-bottom: var(--space-3);
    background: var(--bg-hover);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
}

.preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
}

.preview-title {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-weight: 600;
    color: var(--text-primary);
}

.preview-clear-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: var(--space-1);
    border-radius: var(--radius-sm);
}

.preview-clear-btn:hover {
    color: var(--text-primary);
    background: var(--gray-800);
}

.preview-body {
    background: var(--gray-800);
    border-radius: var(--radius-sm);
    padding: var(--space-2);
    display: flex;
    justify-content: center;
}

.preview-body img {
    max-width: 100%;
    max-height: 180px;
    border-radius: var(--radius-sm);
    object-fit: contain;
}

.preview-caption {
    margin: 0;
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
}

.screenshot-label {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    margin-bottom: var(--space-2);
}

.screenshot-input {
    width: 100%;
    padding: var(--space-2);
    background: var(--bg-hover);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: var(--font-size-sm);
}

.input-wrapper {
    display: flex;
    gap: var(--space-2);
    align-items: flex-end;
}

.chat-input {
    flex: 1;
    padding: var(--space-3);
    background: var(--bg-hover);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: var(--font-size-base);
    resize: none;
    max-height: 120px;
    transition: border-color var(--transition-fast);
}

.chat-input:focus {
    outline: none;
    border-color: var(--primary);
}

.send-btn {
    padding: var(--space-3) var(--space-4);
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    font-size: var(--font-size-lg);
}

.send-btn:hover:not(:disabled) {
    background: var(--primary-hover);
    transform: translateY(-2px);
}

.send-btn:disabled {
    background: var(--gray-700);
    color: var(--text-muted);
    cursor: not-allowed;
}

/* Chat Actions */
.chat-actions {
    display: flex;
    gap: var(--space-2);
    margin-top: var(--space-3);
    flex-wrap: wrap;
}

.btn-export {
    padding: var(--space-2) var(--space-3);
    background: var(--bg-hover);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: var(--font-size-xs);
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    gap: var(--space-1);
}

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

.btn-export.btn-danger:hover {
    background: var(--danger);
    border-color: var(--danger);
}

/* ============================================
   ANIMATIONS
   ============================================ */

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ============================================
   SCROLLBAR CUSTOM
   ============================================ */

.messages-container::-webkit-scrollbar,
.document-list::-webkit-scrollbar,
.pdf-viewer-root::-webkit-scrollbar {
    width: 8px;
}

.messages-container::-webkit-scrollbar-track,
.document-list::-webkit-scrollbar-track,
.pdf-viewer-root::-webkit-scrollbar-track {
    background: var(--gray-800);
}

.messages-container::-webkit-scrollbar-thumb,
.document-list::-webkit-scrollbar-thumb,
.pdf-viewer-root::-webkit-scrollbar-thumb {
    background: var(--gray-600);
    border-radius: var(--radius-full);
}

.messages-container::-webkit-scrollbar-thumb:hover,
.document-list::-webkit-scrollbar-thumb:hover,
.pdf-viewer-root::-webkit-scrollbar-thumb:hover {
    background: var(--primary);
}

/* ============================================
   ACCESSIBILITY
   ============================================ */

/* Focus visible per keyboard navigation */
.btn-tool:focus-visible,
.mode-btn:focus-visible,
.send-btn:focus-visible,
.btn-export:focus-visible,
.chat-input:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* High contrast for readability */
@media (prefers-contrast: high) {
    .message-bubble {
        border: 2px solid currentColor;
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
