/* Modern ChatGPT-style CSS */
:root {
    --bg-primary: #0f0f0f;
    --bg-secondary: #1a1a1a;
    --bg-tertiary: #2a2a2a;
    --bg-hover: #2d2d2d;
    --text-primary: #ececec;
    --text-secondary: #b4b4b4;
    --text-tertiary: #8e8e8e;
    --accent: #10a37f;
    --accent-hover: #0d8f6f;
    --border: #3a3a3a;
    --user-msg: #2d2d2d;
    --ai-msg: transparent;
    --shadow: rgba(0, 0, 0, 0.3);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
}

/* App Container */
.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* Sidebar */
.sidebar {
    width: 260px;
    height: 100vh;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    overflow: hidden;
    transition: transform 0.3s ease;
}

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

.logo {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.logo-icon {
    width: 24px;
    height: 24px;
    color: var(--accent);
}

.new-chat-btn {
    width: 100%;
    padding: 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: background 0.2s;
}

.new-chat-btn:hover {
    background: var(--bg-hover);
}

.new-chat-btn svg {
    width: 18px;
    height: 18px;
    stroke-width: 2;
}

/* Chat History */
.chat-history {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.history-section {
    margin-bottom: 16px;
}

.history-section h3 {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-tertiary);
    padding: 8px 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.history-items {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.history-item {
    padding: 10px 12px;
    border-radius: 8px;
    color: var(--text-secondary);
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.history-item.active {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

/* Sidebar Footer */
.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--border);
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-info {
    border: 0;
    color: inherit;
    font: inherit;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
    width: 100%;
}

.user-info:hover {
    background: var(--bg-hover);
}

/* Authentication dialog */
.auth-modal[hidden] {
    display: none;
}

.auth-modal {
    position: fixed;
    inset: 0;
    z-index: 1100;
    display: grid;
    place-items: center;
    padding: 20px;
}

.auth-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
}

.auth-dialog {
    position: relative;
    width: min(420px, 100%);
    padding: 32px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 24px 80px var(--shadow);
}

.auth-dialog h2 {
    margin-bottom: 8px;
    font-size: 24px;
}

.auth-subtitle {
    margin-bottom: 24px;
    color: var(--text-secondary);
    font-size: 14px;
    line-height: 1.5;
}

.auth-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--text-secondary);
    font-size: 24px;
    cursor: pointer;
}

.auth-close:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.auth-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 24px;
    padding: 4px;
    background: var(--bg-tertiary);
    border-radius: 8px;
}

.auth-tab {
    flex: 1;
    padding: 9px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
}

.auth-tab.active {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

#authForm label {
    display: block;
    margin: 14px 0 6px;
    color: var(--text-secondary);
    font-size: 13px;
}

#authForm label span {
    color: var(--text-tertiary);
}

#authForm input {
    width: 100%;
    padding: 11px 12px;
    border: 1px solid var(--border);
    border-radius: 7px;
    outline: none;
    background: var(--bg-primary);
    color: var(--text-primary);
    font: inherit;
}

#authForm input:focus {
    border-color: var(--accent);
}

.auth-submit {
    width: 100%;
    margin-top: 22px;
    padding: 11px;
    border: 0;
    border-radius: 7px;
    background: var(--accent);
    color: white;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

.auth-submit:hover {
    background: var(--accent-hover);
}

.auth-submit:disabled {
    cursor: wait;
    opacity: 0.6;
}

.auth-error {
    margin-top: 14px;
    color: #ff8f8f;
    font-size: 13px;
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
}

.user-avatar svg {
    width: 18px;
    height: 18px;
    stroke-width: 2;
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
}

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

/* Welcome Screen */
.welcome-screen {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    max-width: 900px;
    margin: 0 auto;
    width: 100%;
}

.welcome-content {
    width: 100%;
}

.welcome-title {
    font-size: 36px;
    font-weight: 700;
    text-align: center;
    margin-bottom: 8px;
    background: linear-gradient(90deg, var(--accent), #3b82f6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.welcome-subtitle {
    font-size: 18px;
    color: var(--text-secondary);
    text-align: center;
    margin-bottom: 48px;
}

.capabilities {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 48px;
}

.capability-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    transition: transform 0.2s, border-color 0.2s;
}

.capability-card:hover {
    transform: translateY(-2px);
    border-color: var(--accent);
}

.capability-icon {
    width: 40px;
    height: 40px;
    background: var(--accent);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
}

.capability-icon svg {
    width: 24px;
    height: 24px;
    stroke-width: 2;
}

.capability-card h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 8px;
}

.capability-card p {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.5;
}

/* Example Prompts */
.example-prompts {
    text-align: center;
}

.example-prompts h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text-secondary);
}

.prompt-cards {
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-width: 600px;
    margin: 0 auto;
}

.prompt-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px 20px;
    color: var(--text-primary);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    text-align: left;
}

.prompt-card:hover {
    background: var(--bg-tertiary);
    border-color: var(--accent);
    transform: translateX(4px);
}

.prompt-card svg {
    width: 18px;
    height: 18px;
    stroke-width: 2;
    opacity: 0.5;
    transition: opacity 0.2s;
}

.prompt-card:hover svg {
    opacity: 1;
}

/* Messages Container */
.messages-container {
    flex: 1;
    padding: 20px;
    max-width: 800px;
    width: 100%;
    margin: 0 auto;
}

.message {
    margin-bottom: 24px;
    animation: fadeIn 0.3s ease;
}

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

.message-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
}

.message.user .message-avatar {
    background: #3b82f6;
}

.message.assistant .message-avatar {
    background: var(--accent);
}

.message-author {
    font-weight: 600;
    font-size: 14px;
}

.message-content {
    padding-left: 44px;
    color: var(--text-primary);
    line-height: 1.6;
}

.message.user .message-content {
    background: var(--user-msg);
    padding: 12px 16px;
    border-radius: 12px;
    margin-left: 44px;
}

.message.assistant .message-content {
    font-size: 15px;
}

.message-content p {
    margin-bottom: 12px;
}

.message-content p:last-child {
    margin-bottom: 0;
}

.message-content ul, .message-content ol {
    margin-left: 20px;
    margin-bottom: 12px;
}

.message-content li {
    margin-bottom: 8px;
}

.message-content strong {
    font-weight: 600;
    color: var(--text-primary);
}

.message-content code {
    background: var(--bg-tertiary);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 13px;
}

/* Tier Badge */
.tier-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.tier-badge.simple {
    background: rgba(59, 130, 246, 0.2);
    color: #60a5fa;
}

.tier-badge.verification {
    background: rgba(251, 146, 60, 0.2);
    color: #fb923c;
}

.tier-badge.complex {
    background: rgba(168, 85, 247, 0.2);
    color: #c084fc;
}

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

.sources-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.source-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.source-link {
    color: var(--accent);
    text-decoration: none;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: opacity 0.2s;
}

.source-link:hover {
    opacity: 0.8;
    text-decoration: underline;
}

.source-link svg {
    width: 14px;
    height: 14px;
    stroke-width: 2;
}

/* Loading Animation */
.loading-dots {
    display: flex;
    gap: 6px;
    padding: 12px 0;
}

.loading-dots span {
    width: 8px;
    height: 8px;
    background: var(--text-secondary);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out;
}

.loading-dots span:nth-child(1) {
    animation-delay: -0.32s;
}

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

@keyframes bounce {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Input Container */
.input-container {
    padding: 20px;
    border-top: 1px solid var(--border);
    background: var(--bg-primary);
}

.input-wrapper {
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    align-items: flex-end;
    gap: 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px;
    transition: border-color 0.2s;
}

.input-wrapper:focus-within {
    border-color: var(--accent);
}

.attach-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, color 0.2s;
}

.attach-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.attach-btn svg {
    width: 20px;
    height: 20px;
    stroke-width: 2;
}

#messageInput {
    flex: 1;
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-size: 15px;
    font-family: inherit;
    resize: none;
    outline: none;
    max-height: 200px;
    overflow-y: auto;
}

#messageInput::placeholder {
    color: var(--text-tertiary);
}

.send-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: var(--accent);
    color: white;
    cursor: pointer;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

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

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

.send-btn svg {
    width: 18px;
    height: 18px;
    stroke-width: 2;
}

/* Stop Button */
.stop-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: var(--error, #ef4444);
    color: white;
    cursor: pointer;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.1s;
}

.stop-btn:hover {
    background: #dc2626;
    transform: scale(1.05);
}

.stop-btn:active {
    transform: scale(0.95);
}

.stop-btn svg {
    width: 16px;
    height: 16px;
    stroke-width: 2;
    fill: white;
}

.input-footer {
    max-width: 800px;
    margin: 8px auto 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.file-count {
    font-size: 12px;
    color: var(--accent);
    font-weight: 500;
}

.input-hint {
    font-size: 11px;
    color: var(--text-tertiary);
}

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

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: var(--bg-tertiary);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--border);
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        height: 100vh;
        z-index: 1000;
        transform: translateX(-100%);
    }

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

    .capabilities {
        grid-template-columns: 1fr;
    }

    .welcome-title {
        font-size: 28px;
    }

    .input-container {
        padding: 12px;
    }
}

/* Structured Answer Sections */
.answer-section {
    margin-bottom: 24px;
}

.section-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.text-section .section-content {
    font-size: 15px;
    line-height: 1.7;
    color: var(--text-primary);
    margin: 0;
}

/* Table Styling */
.table-section {
    margin-top: 16px;
}

.table-wrapper {
    overflow-x: auto;
    margin-top: 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
    background: var(--bg-secondary);
}

.data-table thead {
    background: var(--bg-tertiary);
}

.data-table th {
    padding: 12px 16px;
    text-align: left;
    font-weight: 600;
    color: var(--text-primary);
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}

.data-table td {
    padding: 12px 16px;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border);
}

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

.data-table tbody tr:hover {
    background: var(--bg-hover);
}

/* Responsive table */
@media (max-width: 768px) {
    .table-wrapper {
        font-size: 13px;
    }
    
    .data-table th,
    .data-table td {
        padding: 10px 12px;
    }
}


/* Stop Button */
.stop-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: #ef4444;
    color: white;
    cursor: pointer;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    margin-left: 8px;
}

.stop-btn:hover {
    background: #dc2626;
}

.stop-btn svg {
    width: 18px;
    height: 18px;
    stroke-width: 2;
}

/* Input disabled state */
.input-wrapper.disabled {
    opacity: 0.6;
    pointer-events: none;
}

.input-wrapper.disabled textarea {
    cursor: not-allowed;
}

/* Answer sections */
.answer-section {
    margin-bottom: 24px;
}

.answer-section:last-child {
    margin-bottom: 0;
}

.section-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 12px;
    line-height: 1.4;
}

.text-section .section-content {
    color: var(--text-primary);
    line-height: 1.7;
    font-size: 14px;
}

.text-section .section-content p {
    margin-bottom: 12px;
}

.text-section .section-content p:last-child {
    margin-bottom: 0;
}

/* Table section */
.table-section {
    margin: 20px 0;
}

.table-wrapper {
    overflow-x: auto;
    border-radius: 8px;
    border: 1px solid var(--border);
    margin-top: 12px;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
    background: var(--bg-secondary);
}

.data-table thead {
    background: var(--bg-tertiary);
    border-bottom: 2px solid var(--border);
}

.data-table th {
    padding: 12px 16px;
    text-align: left;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
}

.data-table tbody tr {
    border-bottom: 1px solid var(--border);
    transition: background 0.15s;
}

.data-table tbody tr:last-child {
    border-bottom: none;
}

.data-table tbody tr:hover {
    background: var(--bg-hover);
}

.data-table td {
    padding: 12px 16px;
    color: var(--text-primary);
    vertical-align: top;
}

.data-table td:first-child {
    font-weight: 500;
}

/* Responsive table */
@media (max-width: 768px) {
    .data-table {
        font-size: 13px;
    }
    
    .data-table th,
    .data-table td {
        padding: 8px 12px;
    }
}

/* ==========================================================================
   Bottom-Left Authentication UI & JWT Controls
   ========================================================================== */

.sidebar-footer {
    padding: 12px 14px;
    border-top: 1px solid var(--border);
    background: var(--bg-secondary);
    margin-top: auto;
    display: flex;
    align-items: center;
}

.auth-logged-out {
    width: 100%;
    display: flex;
    align-items: center;
}

/* Compact, Fitted Green Auth Box */
.auth-btn-green {
    width: fit-content;
    max-width: 100%;
    height: 38px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 0 16px;
    background: #10a37f;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 8px;
    color: #ffffff;
    font-size: 13.5px;
    font-weight: 700;
    letter-spacing: 0.01em;
    cursor: pointer;
    white-space: nowrap;
    text-align: center;
    transition: background 0.18s ease, transform 0.15s ease, box-shadow 0.18s ease;
    box-shadow: 0 2px 8px rgba(16, 163, 127, 0.3);
}

.auth-btn-green:hover {
    background: #0d8f6f;
    box-shadow: 0 4px 14px rgba(16, 163, 127, 0.45);
    transform: translateY(-1px);
}

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

.auth-btn-label {
    font-weight: 700;
    color: #ffffff;
    letter-spacing: 0.01em;
}

.auth-btn-svg {
    width: 16px !important;
    height: 16px !important;
    max-width: 16px !important;
    max-height: 16px !important;
    flex-shrink: 0;
    display: inline-block;
    vertical-align: middle;
}

/* Logged-In User Profile Card */
.user-profile-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 10px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    transition: background 0.2s, border-color 0.2s;
}

.user-profile-card:hover {
    border-color: rgba(255, 255, 255, 0.15);
}

.user-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: linear-gradient(135deg, #10a37f, #0d8f6f);
    color: #ffffff;
    font-weight: 700;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(16, 163, 127, 0.35);
    text-transform: uppercase;
}

.user-details {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1;
}

.user-name-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.user-display-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.status-dot-active {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 6px var(--accent);
    flex-shrink: 0;
}

.user-display-email {
    font-size: 11px;
    color: var(--text-tertiary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

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

.logout-btn svg {
    width: 17px;
    height: 17px;
}

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

/* ==========================================================================
   JWT Auth Modal Dialog
   ========================================================================== */

.auth-modal {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: authFadeIn 0.2s ease-out;
}

.auth-modal[hidden] {
    display: none !important;
}

@keyframes authFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.auth-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(8px);
}

.auth-dialog-wrapper {
    position: relative;
    z-index: 10000;
    width: 100%;
    max-width: 440px;
    padding: 16px;
}

.auth-dialog {
    position: relative;
    background: #171717;
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 28px 24px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.65), 0 0 0 1px rgba(255, 255, 255, 0.04);
    color: var(--text-primary);
    animation: authPopIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes authPopIn {
    from {
        opacity: 0;
        transform: scale(0.96) translateY(8px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.auth-close {
    position: absolute;
    top: 16px;
    right: 16px;
    background: transparent;
    border: none;
    color: var(--text-tertiary);
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.auth-close:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.auth-header {
    text-align: center;
    margin-bottom: 20px;
}

.auth-brand-title {
    font-size: 24px;
    font-weight: 700;
    color: #ffffff;
    letter-spacing: 0.04em;
    margin-bottom: 6px;
}

.auth-subtitle {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.4;
}

.auth-tabs {
    display: flex;
    background: #0d0d0d;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 3px;
    margin-bottom: 20px;
    gap: 4px;
}

.auth-tab {
    flex: 1;
    padding: 8px 12px;
    background: transparent;
    border: none;
    border-radius: 7px;
    color: var(--text-secondary);
    font-size: 13.5px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.auth-tab.active {
    background: var(--bg-hover);
    color: #ffffff;
    font-weight: 600;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.auth-tab:hover:not(.active) {
    color: var(--text-primary);
}

.auth-form-group {
    margin-bottom: 14px;
}

.auth-form-group label {
    display: block;
    font-size: 12.5px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.auth-form-group .label-hint {
    font-size: 11px;
    color: var(--text-tertiary);
    font-weight: 400;
}

.auth-form-group input {
    width: 100%;
    padding: 10px 14px;
    background: #0d0d0d;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
    transition: all 0.2s;
    font-family: inherit;
}

.auth-form-group input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(16, 163, 127, 0.2);
}

.auth-form-group input::placeholder {
    color: #555555;
}

.auth-error {
    margin-bottom: 14px;
    padding: 9px 12px;
    border-radius: 8px;
    background: rgba(239, 68, 68, 0.12);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: #fca5a5;
    font-size: 12.5px;
    line-height: 1.35;
}

.auth-success {
    margin-bottom: 14px;
    padding: 9px 12px;
    border-radius: 8px;
    background: rgba(16, 163, 127, 0.12);
    border: 1px solid rgba(16, 163, 127, 0.3);
    color: #6ee7b7;
    font-size: 12.5px;
    line-height: 1.35;
}

.auth-submit {
    width: 100%;
    padding: 11px 16px;
    background: var(--accent);
    border: 1px solid transparent;
    border-radius: 8px;
    color: #ffffff;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-top: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.auth-submit:hover {
    background: var(--accent-hover);
    box-shadow: 0 4px 14px rgba(16, 163, 127, 0.3);
}

.auth-submit:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.auth-footer-toggle {
    margin-top: 18px;
    text-align: center;
    font-size: 12.5px;
    color: var(--text-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.auth-toggle-btn {
    background: transparent;
    border: none;
    color: var(--accent);
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    padding: 0;
    text-decoration: underline;
    text-underline-offset: 3px;
    transition: color 0.15s;
}

.auth-toggle-btn:hover {
    color: #34d399;
}

/* ==========================================================================
   Document Intelligence & Attachment Styles
   ========================================================================== */

.input-error-banner {
    max-width: 800px;
    margin: 0 auto 10px auto;
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid rgba(239, 68, 68, 0.35);
    border-radius: 8px;
    padding: 8px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: #fca5a5;
    font-size: 13.5px;
    animation: fadeIn 0.2s ease-in-out;
}

.error-banner-content {
    display: flex;
    align-items: center;
    gap: 8px;
}

.error-icon {
    width: 16px;
    height: 16px;
    stroke: #ef4444;
    flex-shrink: 0;
}

.error-close-btn {
    background: transparent;
    border: none;
    color: #fca5a5;
    font-size: 20px;
    cursor: pointer;
    line-height: 1;
    padding: 0 4px;
    transition: color 0.15s;
}

.error-close-btn:hover {
    color: #ffffff;
}

.active-doc-banner {
    max-width: 800px;
    margin: 0 auto 10px auto;
    background: rgba(16, 163, 127, 0.12);
    border: 1px solid rgba(16, 163, 127, 0.35);
    border-radius: 8px;
    padding: 8px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 13px;
    color: #6ee7b7;
    animation: fadeIn 0.2s ease-in-out;
}

.active-doc-info {
    display: flex;
    align-items: center;
    gap: 8px;
}

.active-doc-icon {
    font-size: 15px;
}

.active-doc-label {
    color: #a7f3d0;
    font-weight: 500;
}

.active-doc-name {
    font-weight: 600;
    color: #ffffff;
    max-width: 350px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.active-doc-pages {
    font-size: 11.5px;
    color: #a7f3d0;
    background: rgba(16, 163, 127, 0.25);
    padding: 2px 6px;
    border-radius: 4px;
}

.detach-doc-btn {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    color: #d1d5db;
    padding: 4px 10px;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 5px;
    transition: all 0.15s;
}

.detach-doc-btn:hover {
    background: rgba(239, 68, 68, 0.2);
    border-color: rgba(239, 68, 68, 0.4);
    color: #fca5a5;
}

.upload-progress-container {
    max-width: 800px;
    margin: 0 auto 10px auto;
    animation: fadeIn 0.2s ease-in-out;
}

.progress-bar-wrapper {
    width: 100%;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #10a37f, #3b82f6);
    width: 0%;
    transition: width 0.3s ease;
}

.progress-status {
    font-size: 11.5px;
    color: var(--text-secondary);
    margin-top: 4px;
    text-align: right;
}

.attachment-preview-tray {
    max-width: 800px;
    margin: 0 auto 10px auto;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    animation: fadeIn 0.2s ease-in-out;
}

.attachment-chip {
    background: #232323;
    border: 1px solid #3f3f46;
    border-radius: 8px;
    padding: 6px 10px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: #e4e4e7;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
    transition: border-color 0.15s;
}

.attachment-chip:hover {
    border-color: #52525b;
}

.attachment-chip .chip-icon {
    font-size: 15px;
}

.attachment-chip .chip-name {
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 500;
}

.attachment-chip .chip-size {
    font-size: 11.5px;
    color: #a1a1aa;
}

.attachment-chip .chip-remove-btn {
    background: transparent;
    border: none;
    color: #a1a1aa;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    padding: 0 2px;
    margin-left: 2px;
    border-radius: 4px;
    transition: color 0.15s;
}

.attachment-chip .chip-remove-btn:hover {
    color: #ef4444;
}

/* Citations & Evidence Pill in Chat Answers */
.citation-pill {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    background: rgba(59, 130, 246, 0.16);
    border: 1px solid rgba(59, 130, 246, 0.35);
    border-radius: 4px;
    padding: 2px 7px;
    font-size: 11.5px;
    color: #93c5fd;
    font-weight: 600;
    margin: 0 2px;
    cursor: default;
    vertical-align: middle;
}

.citation-pill.image-ref {
    background: rgba(168, 85, 247, 0.16);
    border-color: rgba(168, 85, 247, 0.35);
    color: #d8b4fe;
}

/* ==========================================================================
   Markdown Content & GFM Styling (Tables, Headings, Lists, Code, Citations)
   ========================================================================== */

.markdown-content {
    line-height: 1.7;
    overflow-wrap: anywhere;
    min-width: 0;
    color: var(--text-primary, #ffffff);
    font-size: 15px;
}

.markdown-content h1,
.markdown-content h2,
.markdown-content h3,
.markdown-content h4,
.markdown-content h5,
.markdown-content h6 {
    margin: 1.2em 0 0.5em;
    line-height: 1.35;
    font-weight: 700;
    color: var(--text-primary, #ffffff);
}

.markdown-content h1:first-child,
.markdown-content h2:first-child,
.markdown-content h3:first-child {
    margin-top: 0.2em;
}

.markdown-content h1 {
    font-size: 1.6rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
    padding-bottom: 0.4rem;
}

.markdown-content h2 {
    font-size: 1.35rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    padding-bottom: 0.3rem;
}

.markdown-content h3 {
    font-size: 1.15rem;
}

.markdown-content h4 {
    font-size: 1.05rem;
}

.markdown-content p {
    margin: 0.65em 0;
    line-height: 1.7;
}

.markdown-content strong {
    font-weight: 700;
    color: #ffffff;
}

.markdown-content em {
    font-style: italic;
    color: #d1d5db;
}

.markdown-content del {
    text-decoration: line-through;
    color: #9ca3af;
}

.markdown-content ul,
.markdown-content ol {
    padding-left: 1.5rem;
    margin: 0.65em 0;
}

.markdown-content li {
    margin: 0.3em 0;
    line-height: 1.6;
}

.markdown-content li > p {
    margin: 0.2em 0;
}

/* GFM Task Lists */
.markdown-content ul.contains-task-list,
.markdown-content ul:has(input[type="checkbox"]) {
    list-style: none;
    padding-left: 0.2rem;
}

.markdown-content input[type="checkbox"] {
    margin-right: 0.5rem;
    accent-color: #10a37f;
}

/* GFM Tables with horizontal scrolling */
.markdown-table-wrapper {
    width: 100%;
    overflow-x: auto;
    margin: 1.1rem 0;
    border: 1px solid #3a3a3a;
    border-radius: 8px;
    background: #181818;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
    -webkit-overflow-scrolling: touch;
}

.markdown-content table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
    min-width: 480px;
}

.markdown-content th,
.markdown-content td {
    border: 1px solid #333333;
    padding: 0.75rem 0.95rem;
    text-align: left;
    vertical-align: top;
    line-height: 1.55;
}

.markdown-content th {
    font-weight: 700;
    background-color: #242424;
    color: #10a37f;
    border-bottom: 2px solid #444444;
    white-space: nowrap;
}

.markdown-content tbody tr:nth-child(even) {
    background-color: #1f1f1f;
}

.markdown-content tbody tr:nth-child(odd) {
    background-color: #181818;
}

.markdown-content tbody tr:hover {
    background-color: #282828;
}

/* Code Blocks & Inline Code */
.markdown-content pre {
    overflow-x: auto;
    padding: 1rem;
    border-radius: 8px;
    background: #141414;
    border: 1px solid #2e2e2e;
    margin: 0.85em 0;
    font-family: 'Fira Code', 'Cascadia Code', Consolas, Monaco, monospace;
    font-size: 13.5px;
    line-height: 1.5;
}

.markdown-content code {
    font-family: 'Fira Code', 'Cascadia Code', Consolas, Monaco, monospace;
    font-size: 13px;
    background: rgba(255, 255, 255, 0.08);
    color: #38bdf8;
    padding: 0.15em 0.4em;
    border-radius: 4px;
    overflow-wrap: anywhere;
}

.markdown-content pre code {
    background: transparent;
    padding: 0;
    color: #e2e8f0;
    font-size: 13px;
}

/* Links */
.markdown-content a {
    color: #10a37f;
    text-decoration: underline;
    text-underline-offset: 3px;
    font-weight: 500;
    transition: color 0.15s ease;
}

.markdown-content a:hover {
    color: #1dd1a1;
}

/* Blockquotes */
.markdown-content blockquote {
    border-left: 3px solid #10a37f;
    margin: 0.85em 0;
    padding: 0.5em 1.1em;
    color: #a1a1aa;
    background: rgba(16, 163, 127, 0.06);
    border-radius: 0 6px 6px 0;
}

.markdown-content blockquote p {
    margin: 0.25em 0;
}

/* Horizontal Rule */
.markdown-content hr {
    border: none;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    margin: 1.5em 0;
}


/* ==========================================================================
   Chat layout hardening
   Prevent flex children / oversized content from collapsing the sidebar or
   pushing the chat canvas outside the viewport.
   ========================================================================== */

html,
body {
    width: 100%;
    min-width: 320px;
    height: 100%;
    min-height: 0;
}

body {
    overflow: hidden;
    background: var(--bg-primary);
}

.app-container {
    display: flex;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
}

.sidebar {
    flex: 0 0 260px;
    width: 260px;
    min-width: 260px;
    max-width: 260px;
    min-height: 0;
}

.main-content {
    flex: 1 1 0%;
    width: calc(100% - 260px);
    min-width: 0;
    min-height: 0;
    overflow: hidden;
}

.chat-container {
    flex: 1 1 auto;
    width: 100%;
    min-width: 0;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    background: var(--bg-primary);
    align-items: stretch;
}

.welcome-screen {
    box-sizing: border-box;
    flex: 1 0 auto;
    width: 100%;
    max-width: 960px;
    min-width: 0;
    min-height: 100%;
    margin: 0 auto;
    padding: clamp(20px, 4vw, 40px);
    color: var(--text-primary);
    background: var(--bg-primary);
}

.welcome-screen[hidden] {
    display: none !important;
}

.welcome-content {
    width: 100%;
    max-width: 820px;
    min-width: 0;
    margin: 0 auto;
}

.welcome-screen img,
.welcome-screen svg,
.welcome-screen canvas {
    max-width: 100%;
}

.welcome-screen .capability-icon svg {
    width: 24px;
    height: 24px;
    flex: 0 0 24px;
}

.welcome-screen .prompt-card svg {
    width: 18px;
    height: 18px;
    flex: 0 0 18px;
}

.capabilities {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    min-width: 0;
}

.capability-card {
    min-width: 0;
}

.messages-container {
    flex: 0 0 auto;
    width: 100%;
    max-width: 800px;
    min-width: 0;
    margin: 0 auto;
}

.message,
.message-content,
.markdown-content {
    min-width: 0;
    overflow-wrap: anywhere;
}

.input-container {
    flex: 0 0 auto;
    width: 100%;
    min-width: 0;
    position: relative;
    z-index: 2;
    background: var(--bg-primary);
}

.input-wrapper,
.input-footer {
    width: 100%;
    max-width: 800px;
    min-width: 0;
}

.input-wrapper {
    box-sizing: border-box;
}

.logo-icon,
.new-chat-btn svg,
.capability-icon svg,
.prompt-card svg,
.attach-btn svg,
.send-btn svg,
.stop-btn svg,
.message-avatar svg {
    flex: 0 0 auto;
    max-width: 100%;
}

/* Tablet / mobile */
@media (max-width: 768px) {
    .sidebar {
        flex: 0 0 min(260px, 88vw);
        width: min(260px, 88vw);
        min-width: min(260px, 88vw);
        max-width: 88vw;
        height: 100dvh;
    }

    .main-content {
        width: 100%;
        min-width: 0;
    }

    .welcome-screen {
        min-height: auto;
        padding: 24px 16px;
    }

    .capabilities {
        grid-template-columns: minmax(0, 1fr);
        gap: 12px;
        margin-bottom: 28px;
    }

    .welcome-subtitle {
        margin-bottom: 28px;
    }

    .input-container {
        padding: 12px;
    }

    .message-content {
        padding-left: 0;
    }

    .message.user .message-content {
        margin-left: 0;
    }
}



/* Floating chat scroll control. Keep the SVG constrained: without explicit
   dimensions the browser renders its 300x150 intrinsic SVG viewport. */
.chat-container {
    position: relative;
}

.scroll-to-bottom-btn {
    position: absolute;
    right: max(20px, calc((100% - 800px) / 2));
    bottom: 20px;
    z-index: 5;
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    box-shadow: 0 4px 14px var(--shadow);
    cursor: pointer;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(8px);
    transition: opacity 0.18s ease, transform 0.18s ease, background 0.18s ease, visibility 0.18s;
}

.scroll-to-bottom-btn.visible {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0);
}

.scroll-to-bottom-btn:hover {
    background: var(--bg-hover);
}

.scroll-to-bottom-btn svg {
    display: block;
    width: 20px;
    height: 20px;
    min-width: 20px;
    min-height: 20px;
    max-width: 20px;
    max-height: 20px;
    flex: 0 0 20px;
}

@media (prefers-reduced-motion: reduce) {
    .scroll-to-bottom-btn {
        transition: none;
    }
}
