/* Dashboard Styles */

.dashboard-body {
    background: var(--bg-primary);
    min-height: 100dvh;
    display: flex;
    padding: 0;
}

@supports not (min-height: 100dvh) {
    .dashboard-body {
        min-height: 100vh;
    }
}

/* Sidebar */
.sidebar {
    width: 280px;
    background: var(--bg-card);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    height: 100dvh;
    position: fixed;
    left: 0;
    top: 0;
    z-index: 100;
    transition: transform 0.3s ease;
}

/* Mobile sidebar overlay: allows tapping outside the sidebar to close */
.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 90;
}

@media (max-width: 900px) {
    .sidebar.show ~ .main-content {
        /* keep main content visible but not interactive when sidebar is open */
        pointer-events: none;
    }

    .sidebar.show ~ .main-content * {
        pointer-events: none;
    }

    /* Overlay is toggled via JS (#sidebarOverlay), keep CSS as a safety net */
    #sidebarOverlay {
        display: block;
    }
}

.sidebar.hidden {
    transform: translateX(-100%);
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
}

.logo-small {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}

.logo-text {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
}

.new-chat-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin: 16px;
    padding: 12px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: opacity 0.2s;
}

.new-chat-btn:hover {
    opacity: 0.9;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 0 12px;
}

.nav-section {
    margin-bottom: 24px;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 8px 8px;
}

.nav-section h3 {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 0;
    margin: 0;
}

.clear-history-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
    opacity: 0.6;
}

.clear-history-btn:hover {
    background: var(--bg-primary);
    color: var(--error-color);
    opacity: 1;
}

.doc-list,
.chat-list,
.chat-history {
    list-style: none;
}

.doc-item,
.chat-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    font-size: 14px;
    color: var(--text-primary);
    cursor: pointer;
    transition: background 0.2s;
}

.doc-item:hover,
.chat-item:hover {
    background: var(--bg-primary);
}

.doc-item.active {
    background: rgba(102, 126, 234, 0.1);
    color: var(--primary-color);
}

.doc-icon {
    font-size: 16px;
}

.doc-info {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    overflow: hidden;
}

.doc-name {
    font-size: 13px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.doc-delete {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    min-width: 44px;
    min-height: 44px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: all 0.2s;
}

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

.doc-delete:hover {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

/* Touch devices: always show delete button since there's no hover */
@media (pointer: coarse) {
    .doc-delete {
        opacity: 0.6;
    }
}

.no-documents {
    padding: 12px;
    font-size: 13px;
    color: var(--text-secondary);
    text-align: center;
    font-style: italic;
}

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

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--border-color);
}

.upload-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 12px;
    background: var(--bg-primary);
    border: 1px dashed var(--border-color);
    border-radius: var(--radius-md);
    font-size: 14px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
}

.upload-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
    background: rgba(102, 126, 234, 0.05);
}

/* Main Content */
.main-content {
    flex: 1;
    margin-left: 280px;
    display: flex;
    flex-direction: column;
    height: 100dvh;
}

@supports not (height: 100dvh) {
    .main-content {
        height: 100vh;
    }
}

/* Header */
.dashboard-header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px 24px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 10;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.menu-toggle {
    display: none;
    padding: 10px;
    min-width: 44px;
    min-height: 44px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-primary);
}

.back-to-apps {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
    transition: all 0.2s;
}

.back-to-apps:hover {
    background: var(--bg-card);
    color: var(--primary-color);
    border-color: var(--primary-color);
}

.back-to-apps svg {
    width: 18px;
    height: 18px;
}

.header-title {
    flex: 1;
}

.header-title h1 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
}

.header-actions {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background 0.2s;
}

.user-menu:hover {
    background: var(--bg-primary);
}

.user-avatar {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 14px;
    font-weight: 600;
}

.user-name {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
}

.user-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 8px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    min-width: 160px;
    display: none;
    z-index: 100;
}

@media (max-width: 600px) {
    .header-title h1 {
        font-size: 15px;
    }
    .user-name {
        display: none;
    }
}

.user-dropdown.show {
    display: block;
}

.user-dropdown a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    font-size: 14px;
    color: var(--text-primary);
    text-decoration: none;
    transition: background 0.2s;
}

.user-dropdown a:hover {
    background: var(--bg-primary);
}

.user-dropdown a:first-child {
    border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.user-dropdown a:last-child {
    border-radius: 0 0 var(--radius-md) var(--radius-md);
}

/* Chat Container */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    max-width: 900px;
    margin: 0 auto;
    width: 100%;
    padding: 0 24px;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px 0;
}

/* Welcome Message */
.welcome-message {
    text-align: center;
    padding: 60px 20px;
}

.welcome-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 80px;
    height: 80px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 20px;
    color: white;
    margin-bottom: 24px;
}

.welcome-message h2 {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 12px;
}

.welcome-message > p {
    font-size: 16px;
    color: var(--text-secondary);
    max-width: 500px;
    margin: 0 auto 40px;
    line-height: 1.6;
}

.quick-prompts h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.prompts-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    max-width: 600px;
    margin: 0 auto;
}

.prompt-btn {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 16px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    text-align: left;
    font-size: 14px;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s;
}

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

.prompt-icon {
    font-size: 20px;
}

/* Chat Messages */
.message {
    display: flex;
    gap: 16px;
    margin-bottom: 24px;
    animation: fadeIn 0.3s ease;
}

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

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.message.user .message-avatar {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    font-size: 14px;
    font-weight: 600;
}

.message.assistant .message-avatar {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
}

.message.assistant .message-avatar svg {
    width: 20px;
    height: 20px;
    color: var(--primary-color);
}

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

.message-sender {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.message-text {
    font-size: 15px;
    line-height: 1.7;
    color: var(--text-primary);
}

.message-text p {
    margin-bottom: 12px;
}

.message-text p:last-child {
    margin-bottom: 0;
}

.message-text code {
    background: var(--bg-primary);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'SF Mono', Monaco, monospace;
    font-size: 13px;
}

.message-text pre {
    background: #1e1e1e;
    color: #d4d4d4;
    padding: 16px;
    border-radius: var(--radius-md);
    overflow-x: auto;
    margin: 12px 0;
}

.message-text pre code {
    background: none;
    padding: 0;
    color: inherit;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 8px 0;
}

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

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

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

@keyframes bounce {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-8px);
    }
}

/* Chat Input */
.chat-input-container {
    padding: 16px 0 24px;
}

.chat-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 12px 16px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.chat-input-wrapper:focus-within {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

#chatInput {
    flex: 1;
    border: none;
    outline: none;
    font-size: 15px;
    line-height: 1.5;
    resize: none;
    max-height: 150px;
    font-family: inherit;
}

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

.send-btn {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-radius: var(--radius-md);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.2s;
    flex-shrink: 0;
}

.send-btn:hover {
    opacity: 0.9;
}

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

.input-hint {
    text-align: center;
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 8px;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal.show {
    display: flex;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
}

.modal-content {
    position: relative;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow: hidden;
    box-shadow: var(--shadow-lg);
}

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

.modal-header h2 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
}

.modal-close {
    padding: 4px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    transition: color 0.2s;
}

.modal-close:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
}

.btn-secondary {
    background: var(--bg-primary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

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

/* Upload Area */
.upload-area {
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-md);
    padding: 40px 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
}

.upload-area:hover,
.upload-area.dragover {
    border-color: var(--primary-color);
    background: rgba(102, 126, 234, 0.05);
}

.upload-area svg {
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.upload-area p {
    font-size: 14px;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.browse-link {
    color: var(--primary-color);
    cursor: pointer;
}

.upload-hint {
    font-size: 12px;
    color: var(--text-secondary);
}

.upload-area input[type="file"] {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

.upload-list {
    margin-top: 20px;
}

.upload-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: var(--bg-primary);
    border-radius: var(--radius-md);
    margin-bottom: 8px;
}

.upload-item-icon {
    width: 36px;
    height: 36px;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.upload-item-info {
    flex: 1;
    min-width: 0;
}

.upload-item-name {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.upload-item-size {
    font-size: 12px;
    color: var(--text-secondary);
}

.upload-item-remove {
    padding: 4px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
}

.upload-item-remove:hover {
    color: var(--error-color);
}

/* Responsive */
@media (max-width: 900px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.show {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
    }

    .menu-toggle {
        display: block;
    }

    .back-to-apps .back-text {
        display: none;
    }

    .prompts-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 600px) {
    .chat-container {
        padding: 0 16px;
    }

    .dashboard-header {
        padding: 12px 16px;
    }

    .welcome-message {
        padding: 40px 10px;
    }

    .welcome-message h2 {
        font-size: 22px;
    }

    .message {
        gap: 12px;
    }

    .message-avatar {
        width: 32px;
        height: 32px;
    }

    .chat-input-container {
        padding: 12px 0 16px;
    }
}

@media (max-width: 375px) {
    .chat-container {
        padding: 0 10px;
    }

    .dashboard-header {
        padding: 10px 12px;
        gap: 8px;
    }

    .welcome-message {
        padding: 24px 8px;
    }

    .welcome-message h2 {
        font-size: 20px;
    }

    .welcome-message > p {
        font-size: 14px;
    }

    .prompt-btn {
        padding: 12px;
        font-size: 13px;
    }

    .chat-input-wrapper {
        padding: 10px 12px;
    }

    .message-text {
        font-size: 14px;
    }
}

/* Demo Mode Styles */
.demo-banner {
    background: linear-gradient(90deg, #f59e0b 0%, #d97706 100%);
    color: white;
    padding: 12px 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    font-weight: 600;
    font-size: 14px;
    box-shadow: 0 2px 8px rgba(245, 158, 11, 0.3);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
}

.demo-banner svg {
    flex-shrink: 0;
}

.demo-banner span {
    text-align: center;
}

/* Adjust sidebar and main content when demo banner is present */
body:has(.demo-banner) .sidebar {
    top: 48px;
    height: calc(100dvh - 48px);
}

body:has(.demo-banner) .main-content {
    padding-top: 48px;
}

/* Demo upload notification */
.demo-upload-notification {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 32px 48px;
    box-shadow: var(--shadow-lg);
    z-index: 100;
    animation: fadeIn 0.3s ease;
}

.demo-upload-notification.fade-out {
    opacity: 0;
    transition: opacity 0.3s ease;
}

.upload-progress,
.upload-success {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    text-align: center;
}

.upload-progress svg,
.upload-success svg {
    color: var(--primary-color);
}

.upload-success svg {
    color: var(--success-color);
}

.upload-progress span,
.upload-success span {
    font-size: 16px;
    font-weight: 500;
    color: var(--text-primary);
}

.progress-bar {
    width: 200px;
    height: 6px;
    background: var(--bg-primary);
    border-radius: 3px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
    border-radius: 3px;
    transition: width 0.1s linear;
}

/* Demo document item */
.demo-document {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: rgba(102, 126, 234, 0.1);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    animation: fadeIn 0.5s ease;
}

.demo-document svg {
    color: var(--primary-color);
    flex-shrink: 0;
}

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

.demo-document .document-category {
    font-size: 11px;
    color: var(--text-secondary);
    background: var(--bg-primary);
    padding: 2px 8px;
    border-radius: 100px;
}

/* Message sources in demo */
.message-sources {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border-color);
    flex-wrap: wrap;
    transition: opacity 0.3s ease;
}

.sources-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
}

.source-tag {
    font-size: 11px;
    background: rgba(102, 126, 234, 0.1);
    color: var(--primary-color);
    padding: 4px 10px;
    border-radius: 100px;
    font-weight: 500;
}

/* Bullet styling for demo responses */
.bullet {
    color: var(--primary-color);
    font-weight: bold;
    margin-right: 4px;
}
