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

/* Reset */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Tokens */
:root {
    --accent:        #4f46e5;
    --accent-hover:  #4338ca;

    --success:       #16a34a;
    --error:         #dc2626;

    --bg:            #ffffff;
    --bg-muted:      #f7f7f8;
    --bg-subtle:     #f2f2f3;

    --border:        #e4e4e7;
    --border-strong: #d1d1d6;

    --text-1:        #111111;
    --text-2:        #555555;
    --text-3:        #999999;

    --sidebar-width: 280px;
    --radius:        0.5rem;
    --radius-sm:     0.375rem;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text-1);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    font-size: 0.9375rem;
}

/* ─── App shell ─────────────────────────────── */
.app-layout {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    height: 100vh;
    overflow: hidden;
}

/* ─── Sidebar ────────────────────────────────── */
.sidebar {
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    background: var(--bg-muted);
    overflow: hidden;
}

.sidebar-brand {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    padding: 1.25rem 1.25rem 1rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.brand-name {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text-1);
    letter-spacing: -0.02em;
}

.brand-tag {
    font-size: 0.75rem;
    color: var(--text-3);
    font-weight: 400;
}

.sidebar-body {
    flex: 1;
    overflow-y: auto;
    padding: 1.25rem;
}

/* ─── Upload ──────────────────────────────────── */
.upload-area {
    border: 1.5px dashed var(--border-strong);
    border-radius: var(--radius);
    padding: 1.5rem 1rem;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}

.upload-area:hover {
    border-color: var(--accent);
    background: #f5f4ff;
}

.upload-area.drag-over {
    border-color: var(--accent);
    background: #eeecff;
}

.upload-icon {
    width: 2rem;
    height: 2rem;
    color: var(--text-3);
    margin-bottom: 0.625rem;
}

.upload-text {
    font-size: 0.875rem;
    color: var(--text-1);
    margin-bottom: 0.25rem;
}

.upload-hint {
    font-size: 0.8rem;
    color: var(--text-3);
}

/* Upload Progress */
.upload-progress {
    margin-top: 1rem;
}

.progress-bar {
    width: 100%;
    height: 3px;
    background: var(--border);
    border-radius: 9999px;
    overflow: hidden;
    margin-bottom: 0.5rem;
}

.progress-fill {
    height: 100%;
    background: var(--accent);
    transition: width 0.3s ease;
    border-radius: 9999px;
}

.progress-text {
    text-align: center;
    font-size: 0.8rem;
    color: var(--text-3);
}

/* Upload Status */
.upload-status {
    margin-top: 0.75rem;
    padding: 0.75rem;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
}

.upload-status.success {
    background: #f0fdf4;
    color: #166534;
    border: 1px solid #bbf7d0;
}

.upload-status.error {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

.status-close {
    background: none;
    border: none;
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
    color: inherit;
    opacity: 0.5;
    flex-shrink: 0;
    transition: opacity 0.15s;
}

.status-close:hover { opacity: 1; }

/* Documents List */
.documents-list {
    margin-top: 1.25rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border);
}

.documents-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-3);
    margin-bottom: 0.625rem;
}

.document-item {
    display: grid;
    grid-template-columns: auto 1fr auto;
    grid-template-rows: auto auto;
    gap: 0.375rem 0.625rem;
    padding: 0.75rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 0.5rem;
}

.document-icon {
    width: 1.25rem;
    height: 1.25rem;
    color: var(--accent);
    flex-shrink: 0;
    grid-row: 1 / 3;
    align-self: start;
    margin-top: 0.1rem;
}

.document-info {
    grid-column: 2;
    grid-row: 1 / 3;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-width: 0;
}

.document-name {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-1);
    word-break: break-word;
    line-height: 1.35;
}

.document-meta {
    font-size: 0.75rem;
    color: var(--text-3);
    display: flex;
    align-items: center;
    gap: 0.375rem;
}

.document-status {
    font-size: 0.7rem;
    padding: 0.2rem 0.5rem;
    border-radius: 9999px;
    font-weight: 500;
    white-space: nowrap;
}

.status-ready {
    background: #f0fdf4;
    color: #166534;
}

.status-processing {
    background: #fffbeb;
    color: #92400e;
}

.status-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.375rem;
}

.delete-button {
    padding: 0.25rem;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--text-3);
    transition: color 0.15s, background 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
    grid-column: 3;
    grid-row: 1;
    align-self: start;
}

.delete-button:hover {
    background: #fef2f2;
    color: var(--error);
}

.delete-button svg {
    width: 1rem;
    height: 1rem;
}

/* Sidebar footer */
.sidebar-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.demo-notice {
    font-size: 0.775rem;
    color: var(--text-3);
    margin-bottom: 0.25rem;
}

.sidebar-credit {
    font-size: 0.775rem;
    color: var(--text-3);
}

.sidebar-credit a {
    color: var(--text-2);
    text-decoration: none;
}

.sidebar-credit a:hover {
    color: var(--text-1);
    text-decoration: underline;
}

/* ─── Chat section ───────────────────────────── */
.chat-section {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    background: var(--bg);
}

.chat-toolbar {
    padding: 0.875rem 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    min-height: 53px;
    flex-shrink: 0;
}

.new-conversation-button {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.4rem 0.875rem;
    background: var(--bg);
    color: var(--text-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    font-family: inherit;
    transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.new-conversation-button:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: #f5f4ff;
}

.new-conversation-button svg {
    width: 1rem;
    height: 1rem;
}

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

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 2rem 2.5rem;
    max-width: 780px;
    width: 100%;
    margin: 0 auto;
}

/* Welcome */
.welcome-message {
    padding: 4rem 0 2rem;
}

.welcome-eyebrow {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--accent);
    margin-bottom: 0.75rem;
}

.welcome-heading {
    font-size: 1.75rem;
    font-weight: 600;
    color: var(--text-1);
    letter-spacing: -0.03em;
    line-height: 1.2;
    margin-bottom: 0.75rem;
}

.welcome-sub {
    font-size: 0.95rem;
    color: var(--text-2);
}

/* Messages */
.message {
    margin-bottom: 1.75rem;
    animation: fadeIn 0.2s ease;
}

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

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

.message-content {
    max-width: 72%;
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    font-size: 0.9375rem;
    line-height: 1.55;
}

.message-user .message-content {
    background: var(--accent);
    color: #ffffff;
    border-bottom-right-radius: 0.2rem;
}

.message-assistant {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.message-assistant .message-content {
    background: var(--bg-muted);
    border: 1px solid var(--border);
    border-bottom-left-radius: 0.2rem;
    max-width: 100%;
}

.message-text {
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* Sources */
.sources {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

.sources-header {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-3);
    margin-bottom: 0.625rem;
}

.source-item {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 0.375rem;
    overflow: hidden;
}

.source-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.625rem 0.875rem;
    cursor: pointer;
    transition: background 0.15s;
}

.source-header:hover {
    background: var(--bg-muted);
}

.source-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-1);
}

.citation-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.375rem;
    height: 1.375rem;
    background: var(--accent);
    color: white;
    border-radius: 9999px;
    font-size: 0.7rem;
    font-weight: 600;
    flex-shrink: 0;
}

.source-chevron {
    width: 1rem;
    height: 1rem;
    color: var(--text-3);
    transition: transform 0.2s;
    flex-shrink: 0;
}

.source-header.expanded .source-chevron {
    transform: rotate(180deg);
}

.source-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.25s ease;
}

.source-content.expanded {
    max-height: 500px;
}

.source-text {
    padding: 0.875rem;
    font-size: 0.875rem;
    line-height: 1.6;
    color: var(--text-2);
    background: var(--bg-subtle);
    border-top: 1px solid var(--border);
}

.source-scores {
    display: flex;
    gap: 1.25rem;
    padding: 0.625rem 0.875rem;
    background: var(--bg-subtle);
    border-top: 1px solid var(--border);
}

.score-item {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
}

.score-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-3);
}

.score-value {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-1);
}

/* Loading */
.loading {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 0;
    color: var(--text-3);
    font-size: 0.875rem;
}

.loading-spinner {
    width: 1.25rem;
    height: 1.25rem;
    border: 1.5px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    flex-shrink: 0;
}

.spinner {
    width: 2rem;
    height: 2rem;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-right-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

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

/* ─── Input ──────────────────────────────────── */
.input-container {
    display: flex;
    gap: 0.625rem;
    padding: 1.25rem 2.5rem;
    border-top: 1px solid var(--border);
    background: var(--bg);
    max-width: 780px;
    width: 100%;
    margin: 0 auto;
    align-self: stretch;
}

/* Make input container stretch full width within the chat section */
.chat-section .input-container {
    max-width: none;
    padding: 1.25rem 2.5rem;
}

.query-input {
    flex: 1;
    padding: 0.65rem 0.875rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.9375rem;
    line-height: 1.5;
    resize: none;
    color: var(--text-1);
    background: var(--bg);
    transition: border-color 0.15s;
}

.query-input::placeholder {
    color: var(--text-3);
}

.query-input:focus {
    outline: none;
    border-color: var(--accent);
}

.query-input:disabled {
    background: var(--bg-muted);
    cursor: not-allowed;
}

.send-button {
    padding: 0.65rem 1rem;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
    flex-shrink: 0;
}

.send-button:hover:not(:disabled) {
    background: var(--accent-hover);
}

.send-button:disabled {
    background: var(--border);
    cursor: not-allowed;
}

.send-button svg {
    width: 1.125rem;
    height: 1.125rem;
}

/* ─── Utility ────────────────────────────────── */
.hidden {
    display: none !important;
}

/* ─── Responsive ─────────────────────────────── */
@media (max-width: 768px) {
    .app-layout {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr;
        height: auto;
        min-height: 100vh;
        overflow: auto;
    }

    .sidebar {
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .chat-section {
        height: 80vh;
    }

    .chat-messages {
        padding: 1.25rem 1rem;
    }

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

    .message-content {
        max-width: 88%;
    }
}
