/* ============================================
   APP SIDEBAR - Left Navigation
   ============================================ */

/* ===== MAIN SIDEBAR ===== */
.app-sidebar {
    position: fixed;
    left: 0;
    top: 60px; /* Below the fixed nav header */
    width: 52px;
    height: calc(100vh - 60px); /* Account for header */
    background: rgba(12, 15, 25, 0.98);
    border-right: 1px solid rgba(255, 255, 255, 0.08);
    display: none; /* Hidden by default, shown on workflow screens */
    flex-direction: column;
    justify-content: space-between;
    padding: 16px 0;
    z-index: 999; /* Below the nav (z-index: 1000) */
    backdrop-filter: blur(12px);
}

.app-sidebar.visible {
    display: flex;
}

.sidebar-top,
.sidebar-bottom {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.sidebar-top {
    padding-top: 8px;
}

.sidebar-bottom {
    padding-bottom: 8px;
}

/* ===== SIDEBAR ICONS ===== */
.sidebar-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    border: none;
    background: transparent;
    color: rgba(255, 255, 255, 0.5);
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

.sidebar-icon:hover {
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.9);
}

.sidebar-icon.active {
    background: rgba(99, 147, 255, 0.15);
    color: #7eb0ff;
}

.sidebar-icon svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
    fill: none;
}

/* Notification badge on icon */
.sidebar-icon .notification-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 8px;
    height: 8px;
    background: var(--vc-status-unsupported);
    border-radius: 50%;
    border: 2px solid rgba(12, 15, 25, 0.98);
}

/* ===== TOOLTIPS ===== */
.sidebar-icon::after {
    content: attr(data-tooltip);
    position: absolute;
    left: 100%;
    margin-left: 12px;
    padding: 6px 12px;
    background: rgba(25, 30, 45, 0.98);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    color: #fff;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s ease, visibility 0.15s ease;
    pointer-events: none;
    z-index: 1001;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.sidebar-icon:hover::after {
    opacity: 1;
    visibility: visible;
}

/* ===== DIVIDER ===== */
.sidebar-divider {
    width: 28px;
    height: 1px;
    background: rgba(255, 255, 255, 0.08);
    margin: 8px 0;
}

/* ===== DISABLED STATE ===== */
.sidebar-icon.disabled {
    opacity: 0.35;
    cursor: not-allowed;
    pointer-events: none;
}

.sidebar-icon.disabled:hover {
    background: transparent;
    color: rgba(255, 255, 255, 0.5);
}

/* Session button colors */
.sidebar-icon.session-export-btn:hover:not(.disabled) {
    color: #60a5fa;
}

.sidebar-icon.session-import-btn:hover:not(.disabled) {
    color: #34d399;
}

/* ============================================
   DOCUMENTS PANEL - Smart Matching Aesthetic
   ============================================ */

.documents-panel {
    position: fixed;
    left: 52px;
    top: 60px; /* Below the fixed nav header */
    width: 320px;
    height: calc(100vh - 60px); /* Account for header */
    background: rgba(15, 20, 35, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-right: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.3);
    z-index: 998; /* Below sidebar and nav */
    display: flex;
    flex-direction: column;
    transform: translateX(-100%);
    opacity: 0;
    visibility: hidden;
    transition: transform 0.25s ease, opacity 0.25s ease, visibility 0.25s ease;
}

.documents-panel.open {
    transform: translateX(0);
    opacity: 1;
    visibility: visible;
}

/* Panel Header - Refined styling */
.documents-panel-header {
    display: flex;
    align-items: center;
    padding: 16px 20px;
    padding-top: 40px; /* Extra top spacing below nav */
    background: rgba(0, 0, 0, 0.2);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    gap: 10px;
    flex-shrink: 0;
}

.documents-panel-header h3 {
    font-size: 16px;
    font-weight: 600;
    color: #fff;
    margin: 0;
    flex: 1;
}

.document-count-badge {
    background: rgba(99, 147, 255, 0.15);
    color: #7eb0ff;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    border: 1px solid rgba(99, 147, 255, 0.2);
}

.documents-panel-close {
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    color: rgba(255, 255, 255, 0.5);
    cursor: pointer;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.documents-panel-close:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.documents-panel-close svg {
    width: 16px;
    height: 16px;
}

/* Panel Content */
.documents-panel-content {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Loading State */
.documents-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    gap: 12px;
    color: rgba(255, 255, 255, 0.5);
    font-size: 13px;
}

.documents-loading .loading-spinner {
    width: 24px;
    height: 24px;
    border: 2px solid rgba(99, 147, 255, 0.2);
    border-top-color: #7eb0ff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.no-documents {
    text-align: center;
    padding: 40px 20px;
    color: rgba(255, 255, 255, 0.4);
    font-size: 13px;
}

.error-message {
    text-align: center;
    padding: 40px 20px;
    color: var(--vc-status-unsupported);
    font-size: 13px;
}

/* ===== DOCUMENT CARDS ===== */
.document-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 12px;
    padding: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.document-card:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.1);
}

.document-card.active-filter {
    background: rgba(99, 147, 255, 0.08);
    border-color: rgba(99, 147, 255, 0.3);
}

.document-card-header {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 12px;
}

.document-card-icon {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.document-card-icon.pdf {
    background: rgba(239, 68, 68, 0.15);
    color: var(--vc-status-unsupported);
}

.document-card-icon.docx {
    background: rgba(59, 130, 246, 0.15);
    color: #60a5fa;
}

.document-card-icon.txt {
    background: rgba(156, 163, 175, 0.15);
    color: var(--vc-text-secondary);
}

.document-card-icon.unknown {
    background: rgba(156, 163, 175, 0.15);
    color: var(--vc-text-secondary);
}

.document-card-icon svg {
    width: 18px;
    height: 18px;
}

.document-card-info {
    flex: 1;
    min-width: 0;
}

.document-card-name {
    font-size: 13px;
    font-weight: 600;
    color: #fff;
    margin: 0 0 4px 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.document-card-meta {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.45);
}

/* Source Stats */
.document-stats {
    display: flex;
    gap: 14px;
    margin-bottom: 10px;
}

.document-stat {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.5);
}

.document-stat-value {
    font-weight: 600;
    color: rgba(255, 255, 255, 0.85);
}

/* Claim Stats (Screen 2a) */
.document-stats-claims {
    flex-wrap: wrap;
}

.document-stats-claims .stat-ready {
    color: var(--vc-status-supported); /* Green for ready claims */
}

.document-stats-claims .stat-ready .document-stat-value {
    color: var(--vc-status-supported);
}

.document-stats-claims .stat-review {
    color: var(--vc-status-partial); /* Amber for needs review */
}

.document-stats-claims .stat-review .document-stat-value {
    color: var(--vc-status-partial);
}

.document-stats-claims .stat-missing {
    color: var(--vc-status-unverifiable); /* Gray for source missing */
}

.document-stats-claims .stat-missing .document-stat-value {
    color: var(--vc-status-unverifiable);
}

/* Progress Bar */
.document-progress {
    height: 4px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 12px;
}

.document-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #3b82f6, #60a5fa);
    border-radius: 2px;
    transition: width 0.3s ease;
}

/* Filter Button */
.document-filter-btn {
    width: 100%;
    padding: 8px 12px;
    background: rgba(99, 147, 255, 0.08);
    border: 1px solid rgba(99, 147, 255, 0.25);
    border-radius: 8px;
    color: #7eb0ff;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.document-filter-btn:hover {
    background: rgba(99, 147, 255, 0.15);
    border-color: rgba(99, 147, 255, 0.4);
}

.document-card.active-filter .document-filter-btn {
    background: rgba(99, 147, 255, 0.2);
    border-color: rgba(99, 147, 255, 0.45);
    color: #a5c8ff;
}

.document-filter-btn svg {
    width: 12px;
    height: 12px;
}

/* Panel Footer */
.documents-panel-footer {
    padding: 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    flex-shrink: 0;
}

.clear-filter-btn {
    width: 100%;
    padding: 10px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    color: rgba(255, 255, 255, 0.7);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.clear-filter-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

/* ============================================
   DOCUMENT FILTER INDICATOR
   ============================================ */

.document-filter-indicator {
    display: none;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: rgba(99, 147, 255, 0.1);
    border: 1px solid rgba(99, 147, 255, 0.25);
    border-radius: 10px;
    margin-bottom: 16px;
}

.document-filter-indicator.visible {
    display: flex;
}

.filter-indicator-icon {
    color: #7eb0ff;
    display: flex;
    align-items: center;
}

.filter-indicator-icon svg {
    width: 14px;
    height: 14px;
}

.filter-indicator-text {
    flex: 1;
    font-size: 13px;
    color: rgba(255, 255, 255, 0.75);
}

.filter-indicator-text strong {
    color: #fff;
    font-weight: 600;
}

.filter-indicator-clear {
    width: 26px;
    height: 26px;
    border: none;
    background: transparent;
    color: rgba(255, 255, 255, 0.5);
    cursor: pointer;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.filter-indicator-clear:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.filter-indicator-clear svg {
    width: 14px;
    height: 14px;
}

/* ============================================
   CONTENT LAYOUT - Sidebar Overlays Content
   ============================================ */

/* Main container stays centered regardless of sidebar state */
/* Sidebar overlays content, doesn't push it */
body.sidebar-visible {
    /* No padding-left - sidebar overlays content */
}

/* Content containers stay centered with max-width */
body.sidebar-visible .cs-main-container,
body.sidebar-visible .app-screen {
    /* Keep max-width and margin: 0 auto from base styles */
    /* Content stays centered, sidebar overlays on left */
}

/* When documents panel is also open - still no push */
body.sidebar-visible.panel-open {
    /* No padding-left - documents panel also overlays */
}

body.sidebar-visible.panel-open .cs-main-container,
body.sidebar-visible.panel-open .app-screen {
    /* Content stays centered */
}

/* Loading overlay adjusts for icon sidebar only */
body.sidebar-visible #loadingOverlay {
    left: 52px;
    width: calc(100% - 52px);
}

body.sidebar-visible.panel-open #loadingOverlay {
    left: 52px;
    width: calc(100% - 52px);
}

/* ============================================
   MOBILE RESPONSIVE
   ============================================ */

@media (max-width: 768px) {
    .app-sidebar {
        position: fixed;
        bottom: 0;
        left: 0;
        top: auto;
        width: 100%;
        height: 60px;
        flex-direction: row;
        justify-content: space-around;
        align-items: center;
        padding: 0 8px;
        border-right: none;
        border-top: 1px solid rgba(255, 255, 255, 0.08);
    }

    .sidebar-top,
    .sidebar-bottom {
        flex-direction: row;
        padding: 0;
        gap: 8px;
    }

    .sidebar-divider {
        display: none;
    }

    /* Reset body padding for mobile (bottom bar instead of left sidebar) */
    body.sidebar-visible {
        padding-left: 0;
        padding-bottom: 60px;
    }

    body.sidebar-visible.panel-open {
        padding-left: 0;
    }

    /* Content adjustments - restore full width on mobile */
    body.sidebar-visible .cs-main-container,
    body.sidebar-visible .app-screen {
        max-width: 100%;
    }

    body.sidebar-visible #loadingOverlay {
        left: 0;
        width: 100%;
        bottom: 60px;
        height: calc(100% - 60px);
    }

    /* Documents panel - full screen on mobile */
    .documents-panel {
        left: 0;
        width: 100%;
        height: calc(100vh - 60px);
        top: 0;
    }

    body.sidebar-visible.panel-open .cs-main-container,
    body.sidebar-visible.panel-open .app-screen {
        max-width: 100%;
    }

    /* Hide tooltips on mobile */
    .sidebar-icon::after {
        display: none;
    }
}

/* ============================================
   VIEW MODE TOGGLE - Refined Styling
   ============================================ */

.documents-view-toggle {
    display: flex;
    gap: 6px;
    padding: 10px 16px;
    background: rgba(0, 0, 0, 0.25);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.view-toggle-btn {
    flex: 1;
    padding: 8px 14px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--vc-text-secondary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: all 0.2s ease;
}

.view-toggle-btn.active {
    background: rgba(99, 147, 255, 0.12);
    border-color: rgba(99, 147, 255, 0.35);
    color: #7eb0ff;
}

.view-toggle-btn:hover:not(.active) {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.15);
    color: rgba(255, 255, 255, 0.85);
}

.view-toggle-btn svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    opacity: 0.9;
}

/* ============================================
   DOCUMENT FILTER BUTTON STATES
   ============================================ */

.document-filter-btn.viewing {
    background: rgba(16, 185, 129, 0.1) !important;
    border-color: rgba(16, 185, 129, 0.3) !important;
    color: var(--vc-status-supported) !important;
    cursor: default;
}

.document-filter-btn.viewing:hover {
    background: rgba(16, 185, 129, 0.1) !important;
}

/* ============================================
   LIGHT THEME OVERRIDES
   ============================================ */

[data-theme="light"] .app-sidebar {
    background: var(--vc-bg-surface, #ECEAF2);
    border-right: 1px solid var(--vc-border, rgba(100, 90, 130, 0.12));
    backdrop-filter: none;
}

[data-theme="light"] .sidebar-icon {
    color: var(--vc-t3, #6E6587);
}

[data-theme="light"] .sidebar-icon:hover {
    background: var(--vc-bg-hover, #E4E1ED);
    color: var(--vc-t1, #1C1829);
}

[data-theme="light"] .sidebar-icon.active {
    background: var(--vc-accent-bg, #EDEBF6);
    color: var(--vc-accent, #4F46A0);
}

[data-theme="light"] .sidebar-divider {
    background: var(--vc-border, rgba(100, 90, 130, 0.12));
}

[data-theme="light"] .sidebar-icon::after {
    background: var(--vc-bg-card, #FAF9FC);
    border-color: var(--vc-border, rgba(100, 90, 130, 0.12));
    color: var(--vc-t1, #1C1829);
    box-shadow: var(--vc-shadow-md, 0 2px 8px rgba(60, 50, 90, 0.08));
}

[data-theme="light"] .sidebar-icon .notification-badge {
    border-color: var(--vc-bg-surface, #ECEAF2);
}

/* ============================================
   SETTINGS POPOVER
   ============================================ */

.sidebar-settings-popover {
    position: absolute;
    left: 56px;
    bottom: 8px;
    width: 200px;
    background: rgba(20, 24, 38, 0.98);
    border: 1px solid rgba(255, 255, 255, 0.10);
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    padding: 6px;
    opacity: 0;
    visibility: hidden;
    transform: translateX(-8px);
    transition: opacity 0.15s ease, visibility 0.15s ease, transform 0.15s ease;
    z-index: 1002;
}

.sidebar-settings-popover.open {
    opacity: 1;
    visibility: visible;
    transform: translateX(0);
}

.settings-popover-header {
    padding: 8px 10px 6px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: rgba(255, 255, 255, 0.4);
}

.settings-popover-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s ease;
    color: rgba(255, 255, 255, 0.75);
}

.settings-popover-row:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
}

.settings-popover-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.settings-popover-icon svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    fill: none;
}

.settings-popover-label {
    font-size: 13px;
    font-weight: 500;
}

/* ── Light theme popover ── */
[data-theme="light"] .sidebar-settings-popover {
    background: var(--vc-bg-card, #FAF9FC);
    border-color: var(--vc-border, rgba(100, 90, 130, 0.12));
    box-shadow: var(--vc-shadow-lg, 0 8px 24px rgba(60, 50, 90, 0.10));
}

[data-theme="light"] .settings-popover-header {
    color: var(--vc-t4, #9B93B0);
}

[data-theme="light"] .settings-popover-row {
    color: var(--vc-t2, #3D3654);
}

[data-theme="light"] .settings-popover-row:hover {
    background: var(--vc-bg-hover, #E4E1ED);
    color: var(--vc-t1, #1C1829);
}
