/* Design Tokens & Theme Variables */
:root {
    --bg-primary: hsl(230, 35%, 7%);
    --bg-sidebar: hsla(230, 35%, 9%, 0.85);
    --bg-card: hsla(230, 25%, 14%, 0.45);
    --bg-message-user: hsla(265, 70%, 55%, 0.25);
    --bg-message-assistant: hsla(230, 25%, 14%, 0.4);
    --border-color: hsla(230, 20%, 30%, 0.25);
    --border-glow: hsla(265, 80%, 65%, 0.15);
    
    --accent-purple: hsl(265, 80%, 65%);
    --accent-purple-hover: hsl(265, 90%, 70%);
    --accent-cyan: hsl(185, 95%, 48%);
    --accent-cyan-hover: hsl(185, 100%, 60%);
    
    --text-primary: hsl(220, 20%, 96%);
    --text-secondary: hsl(220, 15%, 75%);
    --text-muted: hsl(220, 12%, 55%);
    
    --success-green: hsl(142, 76%, 45%);
    --error-red: hsl(350, 76%, 50%);
    --warning-orange: hsl(35, 85%, 55%);
    
    --font-family: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-fast: all 0.15s ease;
}

/* Global Reset */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body, html {
    height: 100%;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font-family);
    overflow: hidden;
    line-height: 1.5;
}

/* App Container Layout */
.app-container {
    display: grid;
    grid-template-columns: 320px 1fr;
    height: 100vh;
    width: 100vw;
    position: relative;
    background-image: 
        radial-gradient(circle at 10% 20%, hsla(265, 70%, 40%, 0.08) 0%, transparent 40%),
        radial-gradient(circle at 80% 80%, hsla(185, 70%, 40%, 0.06) 0%, transparent 40%);
}

/* ---------------------------------------------------- */
/* SIDEBAR PANEL STYLES                                 */
/* ---------------------------------------------------- */
.sidebar {
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    backdrop-filter: blur(20px);
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow-y: auto;
    z-index: 10;
}

/* Brand Section */
.brand-section {
    padding: 24px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--border-color);
}
.logo-container {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--accent-purple), var(--accent-cyan));
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 15px hsla(265, 80%, 65%, 0.3);
}
.brand-logo {
    width: 24px;
    height: 24px;
    color: white;
}
.brand-section h1 {
    font-size: 18px;
    font-weight: 600;
    letter-spacing: 0.5px;
    background: linear-gradient(to right, #ffffff, var(--text-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}
.subtitle {
    font-size: 11px;
    color: var(--accent-cyan);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 1.5px;
}

/* Status Indicator Card */
.status-card {
    margin: 16px 20px;
    padding: 16px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: inset 0 0 10px rgba(255, 255, 255, 0.02);
}
.status-card h3 {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
}
.status-indicator {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
    font-size: 13px;
}
.status-indicator:last-of-type {
    margin-bottom: 0;
}
.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}
.status-dot.green {
    background-color: var(--success-green);
    box-shadow: 0 0 8px var(--success-green);
}
.status-dot.red {
    background-color: var(--error-red);
    box-shadow: 0 0 8px var(--error-red);
    animation: pulse 2s infinite;
}
.status-dot.yellow {
    background-color: var(--warning-orange);
    box-shadow: 0 0 8px var(--warning-orange);
}
.status-text {
    color: var(--text-secondary);
}
.status-text strong {
    color: var(--text-primary);
}

/* Warning Banner for API Key */
.api-warning-banner {
    margin-top: 12px;
    padding: 10px;
    background: hsla(35, 85%, 55%, 0.1);
    border: 1px solid hsla(35, 85%, 55%, 0.25);
    border-radius: 8px;
    display: flex;
    gap: 8px;
    font-size: 11px;
    color: hsl(35, 90%, 75%);
    line-height: 1.4;
}
.warning-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

/* Upload Dropzone Section */
.upload-section {
    margin: 12px 20px;
}
.upload-section h3 {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
}
.dropzone {
    border: 2px dashed var(--border-color);
    background: hsla(230, 25%, 14%, 0.25);
    border-radius: 12px;
    padding: 24px 16px;
    text-align: center;
    cursor: pointer;
    transition: var(--transition-smooth);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}
.dropzone:hover, .dropzone.dragover {
    border-color: var(--accent-purple);
    background: hsla(265, 80%, 65%, 0.05);
    box-shadow: 0 0 15px rgba(139, 92, 246, 0.05);
}
.upload-icon {
    width: 32px;
    height: 32px;
    color: var(--text-secondary);
    transition: var(--transition-smooth);
}
.dropzone:hover .upload-icon {
    color: var(--accent-purple);
    transform: translateY(-2px);
}
.dropzone-text {
    font-size: 12px;
    color: var(--text-secondary);
}
.browse-link {
    color: var(--accent-cyan);
    font-weight: 500;
    text-decoration: underline;
}

/* Progress bar container */
.upload-progress-container {
    margin-top: 12px;
    padding: 10px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
}
.progress-bar-bg {
    height: 12px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 6px;
    overflow: hidden;
    margin-bottom: 6px;
}
.progress-bar-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(to right, var(--accent-purple), var(--accent-cyan));
    border-radius: 6px;
    transition: width 0.2s ease;
    font-size: 9px;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
}
.progress-status-text {
    font-size: 11px;
    color: var(--text-secondary);
}

/* Ingested Documents List */
.document-section {
    flex: 1;
    margin: 16px 20px;
    display: flex;
    flex-direction: column;
    min-height: 200px;
}
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}
.section-header h3 {
    font-size: 13px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.8px;
}
.doc-count-badge {
    background: var(--border-color);
    color: var(--text-secondary);
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
}
.document-list-container {
    flex: 1;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    background: hsla(230, 25%, 10%, 0.3);
    border-radius: 12px;
    padding: 8px;
}
.document-list {
    list-style: none;
}
.empty-docs-placeholder {
    padding: 30px 10px;
    text-align: center;
    font-size: 12px;
    color: var(--text-muted);
    font-style: italic;
}
.doc-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    background: hsla(230, 25%, 14%, 0.3);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    margin-bottom: 8px;
    transition: var(--transition-fast);
}
.doc-item:hover {
    border-color: var(--accent-purple-glow);
    background: hsla(230, 25%, 18%, 0.4);
}
.doc-info {
    display: flex;
    flex-direction: column;
    gap: 3px;
    max-width: 80%;
}
.doc-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.doc-meta {
    font-size: 10px;
    color: var(--text-muted);
}
.delete-doc-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: var(--transition-fast);
}
.delete-doc-btn:hover {
    color: var(--error-red);
    background: rgba(239, 68, 68, 0.1);
}
.delete-icon {
    width: 16px;
    height: 16px;
}

/* Sidebar Footer */
.sidebar-footer {
    padding: 16px;
    text-align: center;
    border-top: 1px solid var(--border-color);
    font-size: 11px;
    color: var(--text-muted);
}

/* ---------------------------------------------------- */
/* MAIN CHAT PANEL STYLES                               */
/* ---------------------------------------------------- */
.chat-panel {
    display: flex;
    flex-direction: column;
    height: 100vh;
    position: relative;
    background: transparent;
}

/* Header Area */
.chat-header {
    padding: 20px 30px;
    border-bottom: 1px solid var(--border-color);
    backdrop-filter: blur(10px);
    background: hsla(230, 35%, 7%, 0.4);
    z-index: 5;
}
.chat-header h2 {
    font-size: 18px;
    font-weight: 600;
}
.chat-header p {
    font-size: 12px;
    color: var(--text-secondary);
}

/* Message Scrolling Container */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 30px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    scroll-behavior: smooth;
}

/* Chat Message Styling */
.message {
    display: flex;
    gap: 16px;
    max-width: 85%;
    animation: messageIn 0.3s ease-out;
}
.message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}
.message.assistant {
    align-self: flex-start;
}
.avatar {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.message.user .avatar {
    background: linear-gradient(135deg, var(--accent-purple), #9061f9);
    box-shadow: 0 4px 10px rgba(139, 92, 246, 0.2);
}
.message.assistant .avatar {
    background: linear-gradient(135deg, #2b304a, #1a1e35);
    border: 1px solid var(--border-color);
    color: var(--accent-cyan);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
}
.avatar svg {
    width: 20px;
    height: 20px;
    color: white;
}
.message-bubble {
    padding: 16px 20px;
    border-radius: 16px;
    font-size: 14.5px;
    line-height: 1.6;
}
.message.user .message-bubble {
    background: var(--bg-message-user);
    border: 1px solid hsla(265, 80%, 65%, 0.25);
    color: var(--text-primary);
    border-top-right-radius: 4px;
}
.message.assistant .message-bubble {
    background: var(--bg-message-assistant);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-top-left-radius: 4px;
}

/* Welcome Grid Cards */
.message.welcome {
    max-width: 95%;
}
.prompt-hint {
    margin-top: 14px;
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
}
.suggestions-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 12px;
    margin-top: 16px;
}
.suggestion-btn {
    background: hsla(230, 25%, 16%, 0.4);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 12px 14px;
    text-align: left;
    cursor: pointer;
    color: var(--text-secondary);
    transition: var(--transition-smooth);
    display: flex;
    gap: 10px;
}
.suggestion-btn:hover {
    border-color: var(--accent-purple-glow);
    background: hsla(265, 80%, 65%, 0.08);
    color: var(--text-primary);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}
.suggestion-icon {
    font-size: 16px;
    margin-top: 1px;
}
.suggestion-text {
    font-size: 12px;
    font-weight: 500;
    line-height: 1.4;
}

/* Citations within messages */
.citations-wrapper {
    margin-top: 12px;
    border-top: 1px solid var(--border-color);
    padding-top: 10px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}
.citations-title {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-right: 4px;
}
.citation-badge {
    background: hsla(185, 95%, 48%, 0.08);
    border: 1px solid hsla(185, 95%, 48%, 0.25);
    color: var(--accent-cyan);
    font-size: 11px;
    font-weight: 500;
    padding: 2px 8px;
    border-radius: 6px;
    cursor: pointer;
    transition: var(--transition-smooth);
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.citation-badge:hover {
    background: hsla(185, 95%, 48%, 0.18);
    border-color: var(--accent-cyan);
    box-shadow: 0 0 8px hsla(185, 95%, 48%, 0.3);
    transform: scale(1.03);
}

/* Chat Input Bar Container */
.chat-input-container {
    padding: 20px 30px 30px;
    background: linear-gradient(to top, var(--bg-primary) 80%, transparent);
    z-index: 5;
}
.chat-form {
    display: flex;
    background: hsla(230, 25%, 12%, 0.7);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: 8px 12px;
    align-items: flex-end;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3);
    transition: var(--transition-smooth);
}
.chat-form:focus-within {
    border-color: var(--accent-purple);
    box-shadow: 0 8px 30px hsla(265, 80%, 65%, 0.08);
}
.chat-form textarea {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-family: var(--font-family);
    font-size: 14.5px;
    padding: 8px;
    resize: none;
    max-height: 120px;
    line-height: 1.5;
}
.chat-form textarea::placeholder {
    color: var(--text-muted);
}
.send-btn {
    background: linear-gradient(135deg, var(--accent-purple), #9061f9);
    border: none;
    color: white;
    cursor: pointer;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 3px;
    margin-left: 8px;
    transition: var(--transition-smooth);
    box-shadow: 0 4px 10px rgba(139, 92, 246, 0.3);
}
.send-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 4px 14px rgba(139, 92, 246, 0.4);
    filter: brightness(1.1);
}
.send-btn:disabled {
    background: var(--bg-card);
    color: var(--text-muted);
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}
.send-btn svg {
    width: 18px;
    height: 18px;
}

/* Typing / Generating Loader */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 6px 12px;
}
.typing-dot {
    width: 6px;
    height: 6px;
    background-color: var(--accent-cyan);
    border-radius: 50%;
    animation: dotFlashing 1s infinite alternate;
}
.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}
.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

/* ---------------------------------------------------- */
/* SLIDE OUT DRAWER STYLES                              */
/* ---------------------------------------------------- */
.citation-drawer {
    position: absolute;
    top: 0;
    right: 0;
    width: 420px;
    height: 100vh;
    background: hsla(230, 35%, 8%, 0.95);
    border-left: 1px solid var(--border-color);
    box-shadow: -10px 0 30px rgba(0, 0, 0, 0.5);
    z-index: 100;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    backdrop-filter: blur(15px);
}
.citation-drawer.open {
    transform: translateX(0);
}
.drawer-header {
    padding: 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.drawer-header h3 {
    font-size: 16px;
    font-weight: 600;
}
.close-drawer-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px;
    border-radius: 50%;
    transition: var(--transition-fast);
}
.close-drawer-btn:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
}
.close-drawer-btn svg {
    width: 20px;
    height: 20px;
}
.drawer-content {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
}
.citation-meta {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 24px;
    padding: 16px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-color);
    border-radius: 10px;
}
.meta-item {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
}
.meta-label {
    color: var(--text-muted);
}
.meta-value {
    color: var(--text-primary);
    font-weight: 500;
}
.meta-value.score {
    color: var(--accent-cyan);
    font-weight: 600;
}
.citation-text-container h4 {
    font-size: 13px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
}
.citation-body {
    background: hsla(230, 25%, 14%, 0.5);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 16px;
    font-size: 13.5px;
    line-height: 1.6;
    color: var(--text-secondary);
    white-space: pre-wrap;
}

/* Background Overlay for drawer */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: 90;
    backdrop-filter: blur(2px);
}
.overlay.active {
    opacity: 1;
    pointer-events: auto;
}

/* ---------------------------------------------------- */
/* ANIMATIONS KEYFRAMES                                 */
/* ---------------------------------------------------- */
@keyframes pulse {
    0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.5); }
    70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(239, 68, 68, 0); }
    100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

@keyframes dotFlashing {
    0% { opacity: 0.2; }
    100% { opacity: 1; }
}

@keyframes messageIn {
    0% { opacity: 0; transform: translateY(10px); }
    100% { opacity: 1; transform: translateY(0); }
}

/* Custom Scrollbars */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.08);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.15);
}

/* ---------------------------------------------------- */
/* RESPONSIVE CSS                                       */
/* ---------------------------------------------------- */
@media (max-width: 900px) {
    .app-container {
        grid-template-columns: 1fr;
    }
    .sidebar {
        display: none; /* In a full responsive app we would toggle this drawer */
    }
    .citation-drawer {
        width: 100%;
    }
}
