/* ==========================================================================
   Intelligent Research Assistant - Core CSS Styling
   Aesthetics: Rich dark mode, HSL tailored gradients, and Glassmorphism
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
    --bg-dark: #070913;
    --bg-panel: rgba(13, 17, 34, 0.55);
    --bg-sidebar: rgba(10, 12, 26, 0.7);
    --border-color: rgba(255, 255, 255, 0.06);
    --border-active: rgba(99, 102, 241, 0.4);
    --text-primary: #f3f4f6;
    --text-secondary: #9ca3af;
    --accent-primary: #6366f1; /* Indigo */
    --accent-hover: #4f46e5;
    --accent-success: #10b981;
    --accent-error: #ef4444;
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --card-shadow: 0 10px 40px 0 rgba(0, 0, 0, 0.5);
    --glass-blur: blur(18px);
}

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

body {
    font-family: var(--font-sans);
    background-color: var(--bg-dark);
    background-image: 
        radial-gradient(at 0% 0%, rgba(99, 102, 241, 0.12) 0px, transparent 40%),
        radial-gradient(at 100% 100%, rgba(59, 130, 246, 0.08) 0px, transparent 40%),
        radial-gradient(at 50% 50%, rgba(139, 92, 246, 0.05) 0px, transparent 60%);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

/* ==========================================
   Authentication Screens (Login / Signup)
   ========================================== */

.auth-container {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-grow: 1;
    padding: 2rem;
    position: relative;
}

.auth-card {
    background: var(--bg-panel);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 3rem 2.5rem;
    width: 100%;
    max-width: 440px;
    box-shadow: var(--card-shadow);
    animation: fadeIn 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

.auth-header {
    text-align: center;
    margin-bottom: 2.25rem;
}

.auth-header h1 {
    font-size: 1.85rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    background: linear-gradient(135deg, #ffffff 30%, #a5b4fc 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.auth-header p {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.form-input {
    width: 100%;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 0.75rem 1rem;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.95rem;
    transition: all 0.25s ease;
}

.form-input:focus {
    outline: none;
    border-color: var(--accent-primary);
    background: rgba(255, 255, 255, 0.06);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.auth-btn {
    width: 100%;
    background: linear-gradient(135deg, var(--accent-primary) 0%, var(--accent-hover) 100%);
    color: white;
    border: none;
    border-radius: 10px;
    padding: 0.85rem;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.25s ease;
    box-shadow: 0 4px 20px rgba(99, 102, 241, 0.2);
    margin-top: 1rem;
}

.auth-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 24px rgba(99, 102, 241, 0.3);
}

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

.auth-footer {
    text-align: center;
    margin-top: 2rem;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.auth-link {
    color: var(--accent-primary);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s;
}

.auth-link:hover {
    color: #a5b4fc;
}

.alert {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.2);
    border-radius: 8px;
    padding: 0.75rem 1rem;
    color: #f87171;
    font-size: 0.9rem;
    margin-bottom: 1.5rem;
    text-align: center;
    animation: shake 0.4s;
}

/* ==========================================
   Dashboard Workspace Layout (chat.html)
   ========================================== */

.app-layout {
    display: flex;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
}

/* --- Left Sidebar (File Manager) --- */
.sidebar {
    width: 320px;
    flex-shrink: 0;
    background: var(--bg-sidebar);
    backdrop-filter: var(--glass-blur);
    border-right: 1px solid var(--border-color);
    padding: 1.75rem;
    display: flex;
    flex-direction: column;
}

.logo-section {
    margin-bottom: 2rem;
}

.logo-section h2 {
    font-size: 1.45rem;
    font-weight: 700;
    background: linear-gradient(135deg, #ffffff 40%, var(--accent-primary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.logo-subtitle {
    font-size: 0.75rem;
    color: var(--text-secondary);
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.user-badge {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 0.75rem 1rem;
    margin-bottom: 2rem;
}

.username {
    font-size: 0.88rem;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-right: 1rem;
}

.logout-link {
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-decoration: none;
    padding: 0.25rem 0.5rem;
    border-radius: 6px;
    transition: all 0.2s;
}

.logout-link:hover {
    color: var(--accent-error);
    background: rgba(239, 68, 68, 0.1);
}

.section-title {
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
}

.upload-box {
    background: rgba(99, 102, 241, 0.02);
    border: 1.5px dashed var(--border-color);
    border-radius: 12px;
    padding: 1.5rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.25s ease;
    margin-bottom: 2rem;
}

.upload-box:hover {
    background: rgba(99, 102, 241, 0.04);
    border-color: var(--accent-primary);
}

.upload-icon {
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    transition: color 0.25s;
}

.upload-box:hover .upload-icon {
    color: var(--accent-primary);
}

.upload-text {
    font-size: 0.88rem;
    font-weight: 500;
    margin-bottom: 0.25rem;
}

.upload-formats {
    display: block;
    font-size: 0.7rem;
    color: var(--text-secondary);
}

.status-msg {
    display: block;
    font-size: 0.75rem;
    margin-top: 0.5rem;
    font-weight: 500;
}

.file-list {
    flex-grow: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
}

.file-item {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 0.75rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.file-item:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.15);
}

.file-item.active {
    background: rgba(99, 102, 241, 0.07);
    border-color: var(--border-active);
    box-shadow: 0 0 12px rgba(99, 102, 241, 0.1);
}

.file-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1;
    margin-right: 0.75rem;
}

.file-name {
    font-size: 0.88rem;
    font-weight: 500;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-item.active .file-name {
    color: #c7d2fe;
}

.file-size {
    font-size: 0.72rem;
    color: var(--text-secondary);
    margin-top: 0.1rem;
}

.file-actions {
    display: flex;
    gap: 0.25rem;
}

.action-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 0.4rem;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.action-btn:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.06);
}

.delete-btn:hover {
    color: var(--accent-error);
    background: rgba(239, 68, 68, 0.08);
}

.empty-files {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.82rem;
    padding: 2rem 0;
}

.loading-placeholder {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.85rem;
    padding: 2rem 0;
}

/* --- Right Workspace Area (Chat View) --- */
.chat-area {
    flex-grow: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    background: transparent;
    overflow: hidden;
}

.chat-header {
    height: 76px;
    border-bottom: 1px solid var(--border-color);
    padding: 0 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    backdrop-filter: var(--glass-blur);
}

.header-info h2 {
    font-size: 1.15rem;
    font-weight: 600;
}

.scope-text {
    font-size: 0.78rem;
    color: var(--accent-primary);
    margin-top: 0.15rem;
}

.system-badge {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    border-radius: 30px;
    padding: 0.4rem 0.85rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.78rem;
    color: var(--text-secondary);
}

.live-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: var(--accent-success);
    box-shadow: 0 0 8px var(--accent-success);
    display: inline-block;
}

.chat-window {
    flex-grow: 1;
    padding: 2rem;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    width: 100%;
}

.welcome-card {
    background: linear-gradient(145deg, rgba(17, 21, 40, 0.96) 0%, rgba(10, 12, 26, 0.96) 100%);
    backdrop-filter: var(--glass-blur);
    border: 1px solid rgba(255, 255, 255, 0.12); /* Brighter border to outline card */
    border-top: 1px solid rgba(99, 102, 241, 0.5); /* Stronger top glow */
    border-radius: 16px;
    padding: 1.5rem 1.75rem;
    max-width: 680px;
    width: 90%;
    margin: 1.5rem auto;
    box-shadow: var(--card-shadow), 0 20px 50px rgba(0, 0, 0, 0.65), 0 0 40px rgba(99, 102, 241, 0.04);
    animation: fadeIn 0.5s cubic-bezier(0.16, 1, 0.3, 1) ease-out;
}

.welcome-header {
    text-align: center;
    margin-bottom: 1.25rem;
}

.brand-badge {
    display: inline-block;
    background: rgba(99, 102, 241, 0.2);
    border: 1px solid rgba(99, 102, 241, 0.35);
    border-radius: 30px;
    color: #c7d2fe;
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding: 0.2rem 0.65rem;
    margin-bottom: 0.5rem;
}

.welcome-card h3 {
    font-size: 1.35rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    background: linear-gradient(135deg, #ffffff 40%, #c7d2fe 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.project-overview {
    color: #d1d5db; /* Lighter text color for better contrast */
    font-size: 0.88rem;
    line-height: 1.5;
    max-width: 600px;
    margin: 0 auto 0.5rem auto !important;
}

.project-overview strong {
    color: #c7d2fe;
    font-weight: 600;
}

.features-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.85rem;
    margin-bottom: 1.5rem;
}

.feature-item {
    background: rgba(7, 9, 19, 0.5); /* Recessed darker panel background */
    border: 1px solid rgba(255, 255, 255, 0.08); /* Distinct border */
    border-radius: 10px;
    padding: 0.85rem 1rem;
    transition: all 0.25s ease;
}

.feature-item:hover {
    background: rgba(7, 9, 19, 0.7);
    border-color: rgba(99, 102, 241, 0.35);
    transform: translateY(-1px);
}

.feature-item.full-width {
    grid-column: span 2;
    background: rgba(99, 102, 241, 0.02); /* Tinted full-width item */
    border-color: rgba(99, 102, 241, 0.2);
}

.feature-item.full-width:hover {
    background: rgba(99, 102, 241, 0.04);
    border-color: rgba(99, 102, 241, 0.35);
}

.feature-title-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.35rem;
}

.feature-icon {
    font-size: 1.05rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.feature-item h4 {
    font-size: 0.88rem;
    font-weight: 600;
    color: #f3f4f6;
}

.feature-item p {
    font-size: 0.78rem;
    color: #9ca3af;
    line-height: 1.4;
    margin-bottom: 0 !important;
}

.suggestions-section {
    border-top: 1px solid var(--border-color);
    padding-top: 1.25rem;
}

.suggestion-header {
    font-size: 0.8rem;
    font-weight: 600;
    color: #f3f4f6;
    margin-bottom: 0.75rem !important;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.suggestions-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 0.75rem;
}

.suggestion-action-card {
    background: rgba(7, 9, 19, 0.5); /* Recessed dark panels */
    border: 1px solid rgba(255, 255, 255, 0.08); /* Clear border */
    border-radius: 10px;
    padding: 0.75rem 0.85rem;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
}

.suggestion-action-card:hover {
    background: rgba(99, 102, 241, 0.08); /* Highlight on hover */
    border-color: var(--accent-primary);
    transform: translateY(-1px);
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.1);
}

.suggestion-action-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: #c7d2fe;
    margin-bottom: 0.25rem;
}

.suggestion-action-desc {
    font-size: 0.72rem;
    color: #9ca3af;
    line-height: 1.35;
}

.suggestion-action-card:hover .suggestion-action-title {
    color: white;
}

/* --- Message Bubbles --- */
.message {
    display: flex;
    max-width: 75%;
}

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

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

.message-content {
    padding: 0.95rem 1.25rem;
    border-radius: 16px;
    font-size: 0.94rem;
    line-height: 1.5;
}

.message.user .message-content {
    background: linear-gradient(135deg, var(--accent-primary) 0%, var(--accent-hover) 100%);
    color: white;
    border-bottom-right-radius: 4px;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.15);
}

.message.assistant .message-content {
    background: var(--bg-panel);
    backdrop-filter: var(--glass-blur);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
}

/* Markdown styling inside bubbles */
.message-content pre {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    padding: 0.75rem;
    overflow-x: auto;
    margin: 0.75rem 0;
}

.message-content code {
    font-family: Courier, monospace;
    font-size: 0.85rem;
    background: rgba(255, 255, 255, 0.08);
    padding: 0.125rem 0.25rem;
    border-radius: 4px;
}

.message-content pre code {
    background: transparent;
    padding: 0;
}

.message-content br {
    margin-bottom: 0.5rem;
}

.message-content ul, .message-content ol {
    margin-left: 1.5rem;
    margin-top: 0.5rem;
    margin-bottom: 0.5rem;
}

.message-content li {
    margin-bottom: 0.25rem;
}

/* --- Typing Indicator --- */
.typing-indicator {
    display: flex;
    gap: 4px;
    align-items: center;
    padding: 0.25rem 0;
}

.typing-dot {
    width: 6px;
    height: 6px;
    background-color: var(--text-secondary);
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out both;
}

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

@keyframes typing {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1.0); }
}

/* --- Input Area --- */
.chat-footer {
    padding: 0.85rem 1.5rem 1.5rem 1.5rem; /* Increased bottom padding to lift it up */
    background: transparent;
    width: 100%;
}

.input-container {
    display: flex;
    max-width: 700px; /* Reduced width to match the cockpit alignment */
    margin: 0 auto; /* Center the input bar */
    width: 100%;
    background: var(--bg-panel);
    backdrop-filter: var(--glass-blur);
    border: 1px solid var(--border-color);
    border-radius: 12px; /* Slightly tighter rounding */
    padding: 0.45rem 0.65rem; /* Reduced container padding */
    align-items: center;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6), 0 0 20px rgba(99, 102, 241, 0.08), 0 0 0 1px rgba(255, 255, 255, 0.06); /* Indigo glow + border outline */
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.input-container:focus-within {
    border-color: rgba(99, 102, 241, 0.5); /* Indigo border glow */
    background: rgba(16, 20, 38, 0.7); /* Deepen background on focus */
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.7), 0 0 25px rgba(99, 102, 241, 0.3), 0 0 0 1px rgba(99, 102, 241, 0.4); /* Stronger glowing shadow */
}

.chat-input {
    flex-grow: 1;
    width: 100%;
    background: transparent !important;
    border: none !important;
    color: var(--text-primary) !important;
    font-family: inherit;
    font-size: 0.9rem; /* Reduced font size from 0.95rem */
    padding: 0.25rem 0.4rem; /* Reduced input padding from 0.4rem 0.5rem */
    resize: none;
    max-height: 180px;
    min-height: 24px;
    outline: none;
    box-shadow: none !important;
}

.chat-input::placeholder {
    color: var(--text-secondary) !important;
}

.send-btn {
    background: var(--accent-primary);
    color: white;
    border: none;
    border-radius: 8px; /* Tighter button rounding */
    padding: 0.45rem; /* Reduced padding from 0.55rem */
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.send-btn:hover {
    background: var(--accent-hover);
    transform: scale(1.02);
}

.send-btn:active {
    transform: scale(1);
}

/* ==========================================
   Animations & Transitions
   ========================================== */

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

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-6px); }
    40%, 80% { transform: translateX(6px); }
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.08);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.15);
}

/* ==========================================
   Custom Confirmation Modal
   ========================================== */

.custom-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(4, 5, 11, 0.7);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.25s ease;
}

.custom-modal-overlay.active {
    opacity: 1;
}

.custom-modal-content {
    background: var(--bg-panel);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 2rem;
    width: 90%;
    max-width: 400px;
    box-shadow: var(--card-shadow);
    transform: translateY(20px) scale(0.95);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    animation: modalSlideIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes modalSlideIn {
    to {
        transform: translateY(0) scale(1);
    }
}

.custom-modal-header h3 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    color: var(--text-primary);
}

.custom-modal-body p {
    font-size: 0.92rem;
    color: var(--text-secondary);
    line-height: 1.5;
    margin-bottom: 1.75rem;
}

.custom-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
}

.modal-btn {
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    padding: 0.6rem 1.2rem;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
}

.modal-btn.cancel-btn {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.modal-btn.cancel-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
}

.modal-btn.delete-confirm-btn {
    background: var(--accent-error);
    color: white;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.25);
}

.modal-btn.delete-confirm-btn:hover {
    background: #dc2626;
    box-shadow: 0 6px 16px rgba(239, 68, 68, 0.35);
}
