:root {
    --espresso: #3d2b1f;
    --walnut: #5c4033;
    --tan: #d4a373;
    --cream: #fdfaf7;
    --border: #e9e0d2;
    --white: #ffffff;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Inter', sans-serif; background: var(--cream); color: var(--espresso); }

/* === Authentication Modal === */
.auth-overlay {
    position: fixed;
    top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(61, 43, 31, 0.7);
    backdrop-filter: blur(5px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.auth-overlay.hidden {
    display: none;
    opacity: 0;
}

.auth-modal {
    background: var(--white);
    padding: 2.5rem;
    border-radius: 1.5rem;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 20px 40px rgba(61, 43, 31, 0.15);
    transform: translateY(0);
    animation: modalPop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

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

.auth-tabs {
    display: flex;
    border-bottom: 2px solid var(--border);
    margin-bottom: 1.5rem;
}

.auth-tab {
    flex: 1;
    padding: 0.8rem;
    background: none;
    border: none;
    cursor: pointer;
    font-weight: 600;
    color: var(--walnut);
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    transition: all 0.2s;
}

.auth-tab.active {
    color: var(--tan);
    border-bottom-color: var(--tan);
}

.input-group {
    margin-bottom: 1.2rem;
}

.input-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--espresso);
}

.input-group input {
    width: 100%;
    padding: 0.8rem 1rem;
    border: 1px solid var(--border);
    border-radius: 0.8rem;
    font-family: 'Inter', sans-serif;
    font-size: 0.95rem;
    color: var(--espresso);
    transition: all 0.2s;
}

.input-group input:focus {
    outline: none;
    border-color: var(--tan);
    box-shadow: 0 0 0 3px rgba(212, 163, 115, 0.1);
}
.app-container { display: flex; height: 100vh; overflow: hidden; }

/* === Sidebar Styling === */
.sidebar {
    width: 320px;
    background: var(--white);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
}
.sidebar-footer {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

.logout-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.8rem;
    background: none;
    border: 1px solid transparent;
    border-radius: 0.8rem;
    color: var(--walnut);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

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

.logout-btn i {
    width: 18px;
    height: 18px;
}
.logo { 
    display: flex; align-items: center; gap: 0.5rem; 
    font-size: 1.5rem; font-weight: 300; margin-bottom: 2rem;
}
.logo b { color: var(--tan); font-weight: 700; }

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

.drop-zone {
    border: 2px dashed var(--tan);
    border-radius: 1rem;
    padding: 1.5rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}
.drop-zone:hover { background: var(--cream); border-color: var(--espresso); }

.document-list-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.section-title {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--walnut);
    margin-bottom: 1rem;
    opacity: 0.7;
}

.document-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    padding-right: 5px;
}


.doc-item {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    padding: 1rem;
    background: var(--cream);
    border: 1px solid var(--border);
    border-radius: 0.8rem;
    font-size: 0.9rem;
    transition: all 0.2s;
    cursor: pointer;
    position: relative;
}

.doc-item:hover { transform: translateX(3px); border-color: var(--tan); }

.doc-item.selected {
    background: rgba(212, 163, 115, 0.1);
    border-color: var(--tan);
    border-width: 2px;
}

.doc-checkbox {
    width: 20px;
    height: 20px;
    min-width: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.doc-item.selected .doc-checkbox {
    background: var(--tan);
    border-color: var(--tan);
    color: var(--white);
}

.doc-title-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    cursor: pointer;
    overflow: hidden;
}

.truncate {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 180px;
}

/* === Main Stage === */
.main-content { flex: 1; display: flex; flex-direction: column; background: var(--cream); }

.top-nav {
    height: 80px;
    background: var(--white);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 3rem;
}

.tabs { display: flex; gap: 1rem; }

.tab-btn {
    background: none; border: none; font-size: 1rem;
    padding: 0.5rem 1.5rem; cursor: pointer; color: var(--walnut);
    position: relative; transition: 0.3s;
}
.tab-btn.active { font-weight: 700; color: var(--espresso); }
.tab-btn.active::after {
    content: ''; position: absolute; bottom: -10px; left: 0;
    width: 100%; height: 3px; background: var(--tan);
}

.status-group { display: flex; flex-direction: column; gap: 0.6rem; align-items: flex-end; }
.status-indicator { display: flex; align-items: center; font-size: 0.9rem; color: var(--walnut); }
.progress-container { display: flex; flex-direction: column; gap: 0.35rem; width: 240px; }
.progress-container.hidden { display: none; }
.progress-bar { width: 100%; height: 8px; background: rgba(212, 163, 115, 0.2); border-radius: 999px; overflow: hidden; }
.progress-fill {
    width: 0%;
    height: 100%;
    background: var(--tan);
    /* Make the bar glide smoothly between page updates */
    transition: width 0.8s cubic-bezier(0.4, 0, 0.2, 1); 
}
.progress-text { font-size: 0.78rem; color: var(--espresso); letter-spacing: 0.2px; }

.pulse {
    display: inline-block;
    width: 8px;
    height: 8px;
    background: #10b981;
    border-radius: 50%;
    margin-right: 8px;
    animation: pulse-animation 2s infinite;
}
.pulse.hidden { display: none; }
@keyframes pulse-animation {
    0% { box-shadow: 0 0 0 0px rgba(16, 185, 129, 0.4); }
    100% { box-shadow: 0 0 0 10px rgba(16, 185, 129, 0); }
}

/* === Content Views === */
.content-stage { display: none; flex: 1; padding: 3rem; overflow-y: hidden; }
.content-stage.active { display: flex; flex-direction: column; }

/* Report Container */
.report-container {
    background: var(--white);
    border-radius: 2rem;
    padding: 3rem;
    box-shadow: 0 10px 30px rgba(61, 43, 31, 0.05);
    line-height: 1.6;
    overflow-y: auto;
    height: 100%;
}

.empty-state {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    height: 100%; text-align: center; color: var(--walnut); opacity: 0.6; gap: 1rem;
}

.report-header {
    border-bottom: 2px solid var(--cream);
    margin-bottom: 2rem;
    padding-bottom: 1.5rem;
}
.report-header h1 { font-size: 2rem; color: var(--espresso); letter-spacing: -0.5px; margin-bottom: 0.5rem; }
.report-header p { color: var(--tan); font-size: 0.9rem; font-weight: 600; }

/* Highlighted Summary Box */
.summary-box {
    background: var(--cream);
    border: 1px solid var(--tan);
    border-radius: 1rem;
    padding: 2rem;
    margin-bottom: 2rem;
}
.summary-box-header {
    display: flex; align-items: center; gap: 0.5rem;
    font-weight: 700; color: var(--tan); text-transform: uppercase; letter-spacing: 1px;
    margin-bottom: 1rem; border-bottom: 1px solid rgba(212, 163, 115, 0.3); padding-bottom: 0.5rem;
}

.report-content-body h1, .report-content-body h2, .report-content-body h3 {
    margin: 1.5rem 0 1rem 0;
    color: var(--espresso);
}
.report-content-body h3 { font-size: 1.2rem; color: var(--walnut); }
.report-content-body blockquote { border-left: 4px solid var(--tan); padding-left: 1rem; font-style: italic; background: var(--white); padding: 1rem; border-radius: 0.5rem;}
.report-content-body li { margin-bottom: 0.5rem; list-style-type: none; padding-left: 1.2rem; position: relative;}
.report-content-body li::before { content: "•"; position: absolute; left: 0; color: var(--tan); font-weight: bold; }

.mt-8 { margin-top: 2rem; }

/* Delete Document Button */
.delete-doc-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    transition: opacity 0.2s ease, background-color 0.2s ease;
    border-radius: 4px;
    display: flex;
    align-items: center;
    opacity: 1;
    color: #ef4444;
}

.doc-item:hover .delete-doc-btn {
    opacity: 1; /* Show when hovering over the document row */
}

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

/* Action Button (Regenerate) */
.action-btn {
    background: var(--cream);
    border: 1px solid var(--border);
    color: var(--walnut);
    padding: 0.6rem 1rem;
    border-radius: 0.6rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    font-weight: 600;
    transition: all 0.2s ease;
}

.action-btn:hover:not(:disabled) {
    background: var(--white);
    border-color: var(--tan);
    color: var(--espresso);
    box-shadow: 0 2px 8px rgba(212, 163, 115, 0.15);
}

.action-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Spinning Animation for Icons */
.spinning {
    animation: spin 1.2s linear infinite;
}

@keyframes spin {
    100% { transform: rotate(360deg); }
}

/* === Markdown Tables === */
.table-wrapper {
    overflow-x: auto;
    margin: 1.5rem 0;
    border-radius: 0.8rem;
    border: 1px solid var(--border);
    background: var(--white);
}

.markdown-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-size: 0.9rem;
}

.markdown-table th {
    background: var(--cream);
    color: var(--tan);
    font-weight: 700;
    padding: 1rem;
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}

.markdown-table td {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    color: var(--espresso);
    vertical-align: top;
}

.markdown-table tr:hover td {
    background: rgba(212, 163, 115, 0.05);
}

.markdown-table tr:last-child td {
    border-bottom: none;
}

/* === Ask/Chat Interface === */
.ask-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: var(--white);
    border-radius: 2rem;
    padding: 2rem;
    box-shadow: 0 10px 30px rgba(61, 43, 31, 0.05);
    gap: 1.5rem;
}

.chat-history {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding-right: 5px;
    min-height: 200px;
}

.chat-message {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
    animation: slideIn 0.3s ease;
}

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

.chat-message.user {
    justify-content: flex-end;
}

.message-content {
    max-width: 75%;
    padding: 1rem;
    border-radius: 1rem;
    line-height: 1.6;
    word-wrap: break-word;
    overflow-wrap: break-word;
    word-break: break-word;
    -webkit-hyphens: auto;
    hyphens: auto;
}

@media (max-width: 768px) {
    .message-content {
        max-width: 90%;
    }
}

.message-content.user {
    background: var(--tan);
    color: var(--white);
    border-bottom-right-radius: 0.2rem;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.message-content.user strong,
.message-content.user b,
.message-content.user em,
.message-content.user i {
    color: inherit;
    opacity: 0.95;
}

.message-content.assistant {
    background: var(--cream);
    color: var(--espresso);
    border-bottom-left-radius: 0.2rem;
    border: 1px solid var(--border);
}

/* Formatting support in chat messages */
.message-content h1, .message-content h2, .message-content h3,
.message-content h4, .message-content h5, .message-content h6 {
    margin: 0.75rem 0 0.5rem 0;
    color: var(--espresso);
    font-weight: 700;
}

.message-content h1 { font-size: 1.4rem; }
.message-content h2 { font-size: 1.2rem; }
.message-content h3 { font-size: 1.1rem; }
.message-content h4 { font-size: 1rem; }
.message-content h5 { font-size: 0.95rem; }
.message-content h6 { font-size: 0.9rem; }

.message-content strong, .message-content b {
    font-weight: 700;
    color: var(--walnut);
}

.message-content em, .message-content i {
    font-style: italic;
    color: var(--walnut);
}

.message-content ul, .message-content ol {
    margin: 0.75rem 0;
    padding-left: 1.5rem;
}

.message-content li {
    margin-bottom: 0.4rem;
    line-height: 1.5;
}

.message-content ul li::marker {
    color: var(--tan);
}

.message-content a {
    color: var(--tan);
    text-decoration: underline;
    cursor: pointer;
    transition: all 0.2s;
}

.message-content a:hover {
    color: var(--walnut);
    text-decoration-thickness: 2px;
}

.message-content code {
    background: rgba(212, 163, 115, 0.15);
    padding: 0.2rem 0.4rem;
    border-radius: 0.3rem;
    font-family: 'Courier New', monospace;
    font-size: 0.85rem;
    color: var(--espresso);
}

.message-content blockquote {
    border-left: 4px solid var(--tan);
    padding-left: 1rem;
    margin: 0.75rem 0;
    font-style: italic;
    color: var(--walnut);
    opacity: 0.9;
}

.message-content hr {
    border: 0;
    border-top: 1px solid rgba(212, 163, 115, 0.3);
    margin: 1rem 0;
}

.message-content .table-wrapper {
    margin: 0.75rem 0;
    border-radius: 0.5rem;
    overflow-x: auto;
}

.message-content .markdown-table {
    font-size: 0.85rem;
}

.message-content .markdown-table th {
    background: rgba(212, 163, 115, 0.2);
    color: var(--espresso);
    font-weight: 600;
}

.message-content .markdown-table td,
.message-content .markdown-table th {
    padding: 0.6rem;
}

.message-content .markdown-table tr:hover td {
    background: rgba(212, 163, 115, 0.08);
}

.chat-loading {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--walnut);
    font-size: 0.9rem;
}

.chat-loading span {
    animation: blink 1.4s infinite;
}

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

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

@keyframes blink {
    0%, 60%, 100% {
        opacity: 0.3;
    }
    30% {
        opacity: 1;
    }
}

.chat-input-area {
    display: flex;
    gap: 1rem;
    align-items: flex-end;
    border-top: 1px solid var(--border);
    padding-top: 1rem;
}

#askInput {
    flex: 1;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: 0.8rem;
    font-family: 'Inter', sans-serif;
    font-size: 0.95rem;
    color: var(--espresso);
    resize: none;
    transition: all 0.2s ease;
}

#askInput:focus {
    outline: none;
    border-color: var(--tan);
    box-shadow: 0 0 0 3px rgba(212, 163, 115, 0.1);
}

#askButton {
    flex-shrink: 0;
    padding: 0.75rem 1.5rem;
    background: var(--tan);
    color: var(--white);
    border: none;
    border-radius: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

#askButton:hover:not(:disabled) {
    background: var(--walnut);
    box-shadow: 0 4px 12px rgba(212, 163, 115, 0.3);
}

#askButton:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.chat-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--walnut);
    gap: 1rem;
    text-align: center;
    opacity: 0.6;
}

.select-all-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    color: var(--tan);
    transition: all 0.2s;
    border-radius: 4px;
}

.select-all-btn:hover {
    background: rgba(212, 163, 115, 0.1);
    color: var(--espresso);
}

.selected-docs-badge {
    display: inline-block;
    background: var(--tan);
    color: var(--white);
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    margin-left: 0.5rem;
}

/* === Quota & Token Styles === */
.quota-container {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: rgba(212, 163, 115, 0.15);
    padding: 0.5rem 1rem;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--espresso);
    border: 1px solid rgba(212, 163, 115, 0.3);
    margin-right: auto;
    margin-left: 2rem;
    transition: all 0.3s ease;
}

.quota-container.empty {
    background: rgba(239, 68, 68, 0.1);
    border-color: rgba(239, 68, 68, 0.3);
    color: #ef4444;
}

/* Chat Upgrade Message Style */
.message-content.assistant-error {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.3);
    font-weight: 500;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.upgrade-btn {
    background: #ef4444;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    font-weight: 600;
    cursor: pointer;
    align-self: flex-start;
    margin-top: 0.5rem;
}

/* --- NEW: Drag active state --- */
.drop-zone.drag-active {
    background: rgba(212, 163, 115, 0.15);
    border-color: var(--tan);
    transform: scale(1.02);
}
