/* ============================================
   CHAT INTERFACE STYLES
   Modern, ChatGPT-inspired design with glassmorphism
   ============================================ */

/* Chat-specific color variables */
:root {
    --chat-primary: #3b82f6;
    --chat-primary-hover: #2563eb;
    --chat-primary-light: #dbeafe;
    --chat-user-bg: #3b82f6;
    --chat-ai-bg: #f3f4f6;
    --chat-sidebar-bg: rgba(255, 255, 255, 0.7);
    --chat-sidebar-border: rgba(229, 231, 235, 0.8);
    --chat-input-bg: rgba(255, 255, 255, 0.9);
    --chat-input-border: rgba(229, 231, 235, 0.6);
    --chat-message-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    --chat-glass-bg: rgba(255, 255, 255, 0.75);
    --chat-glass-border: rgba(255, 255, 255, 0.3);
}

[data-theme="dark"] {
    --chat-primary: #60a5fa;
    --chat-primary-hover: #3b82f6;
    --chat-primary-light: #1e3a8a;
    --chat-user-bg: #2563eb;
    --chat-ai-bg: #1e293b;
    --chat-sidebar-bg: rgba(15, 23, 42, 0.85);
    --chat-sidebar-border: rgba(51, 65, 85, 0.8);
    --chat-input-bg: rgba(30, 41, 59, 0.95);
    --chat-input-border: rgba(51, 65, 85, 0.6);
    --chat-message-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    --chat-glass-bg: rgba(30, 41, 59, 0.75);
    --chat-glass-border: rgba(51, 65, 85, 0.3);
}

/* ============================================
   CHAT VIEW LAYOUT
   ============================================ */

.chat-view {
    display: none;
    position: relative;
    background: var(--bg-secondary);
    overflow: hidden;
}

.chat-view.active {
    display: flex;
}

/* ============================================
   CHAT SIDEBAR (History)
   ============================================ */

.chat-sidebar {
    width: 280px;
    background: var(--chat-sidebar-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-right: 1px solid var(--chat-sidebar-border);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 10;
}

.chat-sidebar-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.chat-new-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.875rem;
    font-size: 0.875rem;
    font-weight: 600;
    border-radius: var(--radius-lg);
    background: var(--chat-primary);
    color: white;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
}

.chat-new-btn:hover {
    background: var(--chat-primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.chat-new-btn:active {
    transform: translateY(0);
}

.chat-history-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

.chat-history-item {
    padding: 0.875rem 1rem;
    margin-bottom: 0.25rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    position: relative;
}

.chat-history-item:hover {
    background: var(--bg-tertiary);
}

.chat-history-item.active {
    background: var(--chat-primary-light);
    color: var(--chat-primary);
}

.chat-history-icon {
    font-size: 0.875rem;
    opacity: 0.7;
}

.chat-history-title {
    flex: 1;
    font-size: 0.8125rem;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-history-date {
    font-size: 0.6875rem;
    color: var(--text-tertiary);
}

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

.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    background: var(--bg-secondary);
}

/* Chat Header (NEW) */
.chat-header {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 1.5rem;
    position: sticky;
    top: 0;
    z-index: 5;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.chat-header-content {
    max-width: 900px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-header h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.chat-pdf-context {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    background: var(--primary-light);
    padding: 0.25rem 0.75rem;
    border-radius: var(--radius-md);
    font-weight: 500;
}

.chat-sidebar-toggle {
    position: absolute;
    top: 4.5rem;
    left: 1rem;
    width: 40px;
    height: 40px;
    background: var(--chat-glass-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--chat-glass-border);
    border-radius: var(--radius-md);
    display: none;
    align-items: center;
    justify-content: center;
    color: var(--text-primary);
    cursor: pointer;
    z-index: 5;
    transition: all 0.2s ease;
    box-shadow: var(--shadow-md);
}

.chat-sidebar-toggle:hover {
    background: var(--bg-card);
    transform: scale(1.05);
}

.chat-sidebar-toggle:active {
    transform: scale(0.95);
}

/* ============================================
   CHAT MESSAGES
   ============================================ */

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 2rem 1rem;
    scroll-behavior: smooth;
}

/* Welcome Screen */
.chat-welcome {
    max-width: 700px;
    margin: 0 auto;
    text-align: center;
    padding: 3rem 1rem;
    animation: fadeInUp 0.6s ease;
}

.chat-welcome-icon {
    width: 80px;
    height: 80px;
    margin: 0 auto 1.5rem;
    background: linear-gradient(135deg, var(--chat-primary), var(--secondary-color));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 2rem;
    box-shadow: 0 8px 24px rgba(59, 130, 246, 0.3);
}

.chat-welcome h2 {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.75rem;
}

.chat-welcome p {
    font-size: 1rem;
    color: var(--text-secondary);
    margin-bottom: 2rem;
    line-height: 1.6;
}

.chat-suggestions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 0.75rem;
    max-width: 600px;
    margin: 0 auto;
}

.suggestion-chip {
    padding: 1rem;
    background: var(--chat-glass-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--chat-glass-border);
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    text-align: left;
    font-size: 0.875rem;
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
}

.suggestion-chip:hover {
    background: var(--bg-card);
    border-color: var(--chat-primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.suggestion-chip i {
    color: var(--chat-primary);
    font-size: 1.125rem;
}

/* Message Bubbles */
.chat-message {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
    max-width: 900px;
    animation: fadeInUp 0.4s ease;
}

.chat-message.user {
    flex-direction: row-reverse;
    margin-left: auto;
}

.chat-message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 1rem;
    color: white;
    box-shadow: var(--shadow-sm);
}

.chat-message.user .chat-message-avatar {
    background: linear-gradient(135deg, var(--chat-primary), var(--secondary-color));
}

.chat-message.ai .chat-message-avatar {
    background: linear-gradient(135deg, #10b981, #059669);
}

.chat-message-content {
    flex: 1;
    max-width: 70%;
}

.chat-message-bubble {
    padding: 1rem 1.25rem;
    border-radius: var(--radius-lg);
    font-size: 0.9375rem;
    line-height: 1.6;
    word-wrap: break-word;
    box-shadow: var(--chat-message-shadow);
    position: relative;
}

.chat-message.user .chat-message-bubble {
    background: var(--chat-user-bg);
    color: white;
    border-bottom-right-radius: 0.25rem;
}

.chat-message.ai .chat-message-bubble {
    background: var(--chat-ai-bg);
    color: var(--text-primary);
    border-bottom-left-radius: 0.25rem;
}

.chat-message-time {
    font-size: 0.6875rem;
    color: var(--text-tertiary);
    margin-top: 0.5rem;
    display: block;
}

/* Typing Indicator */
.chat-typing {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
    max-width: 900px;
}

.chat-typing .chat-message-bubble {
    background: var(--chat-ai-bg);
    padding: 1rem 1.25rem;
    display: flex;
    gap: 0.375rem;
}

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

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

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

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

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

.chat-input-container {
    padding: 1.5rem;
    background: var(--bg-card);
    border-top: 1px solid var(--border-color);
}

.chat-input-wrapper {
    max-width: 900px;
    margin: 0 auto;
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
    background: var(--chat-input-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--chat-input-border);
    border-radius: var(--radius-xl);
    padding: 0.75rem 1rem;
    box-shadow: var(--shadow-lg);
    transition: all 0.3s ease;
}

.chat-input-wrapper:focus-within {
    border-color: var(--chat-primary);
    box-shadow: 0 0 0 3px var(--chat-primary-light), var(--shadow-lg);
}

.chat-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    font-size: 0.9375rem;
    color: var(--text-primary);
    resize: none;
    max-height: 150px;
    line-height: 1.5;
    font-family: inherit;
}

.chat-input::placeholder {
    color: var(--text-tertiary);
}

.chat-send-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--chat-primary);
    color: white;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.chat-send-btn:hover:not(:disabled) {
    background: var(--chat-primary-hover);
    transform: scale(1.1);
}

.chat-send-btn:active:not(:disabled) {
    transform: scale(0.95);
}

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

.chat-input-hint {
    max-width: 900px;
    margin: 0.75rem auto 0;
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-tertiary);
}

.chat-input-hint kbd {
    padding: 0.125rem 0.375rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 0.25rem;
    font-family: monospace;
    font-size: 0.6875rem;
}

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

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

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

@media (max-width: 768px) {
    .chat-sidebar {
        position: absolute;
        top: 0;
        left: 0;
        bottom: 0;
        transform: translateX(-100%);
        box-shadow: var(--shadow-xl);
    }

    .chat-sidebar.open {
        transform: translateX(0);
    }

    .chat-sidebar-toggle {
        display: flex;
        top: 4.5rem;
    }
    
    .chat-header-content {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .chat-messages {
        padding: 5rem 1rem 2rem;
    }

    .chat-welcome {
        padding: 2rem 1rem;
    }

    .chat-welcome-icon {
        width: 64px;
        height: 64px;
        font-size: 1.5rem;
    }

    .chat-welcome h2 {
        font-size: 1.5rem;
    }

    .chat-suggestions {
        grid-template-columns: 1fr;
    }

    .chat-message-content {
        max-width: 85%;
    }

    .chat-input-container {
        padding: 1rem;
    }

    .chat-input-wrapper {
        padding: 0.625rem 0.875rem;
    }

    .chat-input {
        font-size: 0.875rem;
    }
}

/* ============================================
   SCROLLBAR STYLING
   ============================================ */

.chat-messages::-webkit-scrollbar,
.chat-history-list::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track,
.chat-history-list::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb,
.chat-history-list::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover,
.chat-history-list::-webkit-scrollbar-thumb:hover {
    background: var(--text-tertiary);
}

/* ============================================
   UTILITY CLASSES
   ============================================ */

.chat-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9;
}

.chat-overlay.active {
    display: block;
}

/* Message content formatting */
.chat-message-bubble p {
    margin: 0;
}

.chat-message-bubble p + p {
    margin-top: 0.75rem;
}

.chat-message-bubble code {
    background: rgba(0, 0, 0, 0.1);
    padding: 0.125rem 0.375rem;
    border-radius: 0.25rem;
    font-size: 0.875em;
    font-family: 'Courier New', monospace;
}

.chat-message.user .chat-message-bubble code {
    background: rgba(255, 255, 255, 0.2);
}

.chat-message-bubble pre {
    background: rgba(0, 0, 0, 0.05);
    padding: 0.75rem;
    border-radius: var(--radius-md);
    overflow-x: auto;
    margin: 0.5rem 0;
}

.chat-message.user .chat-message-bubble pre {
    background: rgba(255, 255, 255, 0.15);
}

/* Empty state for chat history */
.chat-history-empty {
    padding: 2rem 1rem;
    text-align: center;
    color: var(--text-tertiary);
    font-size: 0.875rem;
}

.chat-history-empty i {
    font-size: 2rem;
    margin-bottom: 0.5rem;
    opacity: 0.5;
}