:root {
    --color-bg: #f8f9fa;
    --color-surface: #ffffff;
    --color-primary: #4f46e5;
    --color-primary-hover: #4338ca;
    --color-text: #1f2937;
    --color-text-secondary: #6b7280;
    --color-border: #e5e7eb;
    --color-success: #10b981;
    --color-warning: #f59e0b;
    --color-error: #ef4444;
    --color-info: #3b82f6;
    --radius: 0.5rem;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 4px 6px rgba(0, 0, 0, 0.1);
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'SF Mono', Monaco, 'Cascadia Code', monospace;
}

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

[hidden] {
    display: none !important;
}

body {
    font-family: var(--font-sans);
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.6;
}

/* Navigation */
.nav {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    height: 3.5rem;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow);
}

.nav__brand {
    font-weight: 700;
    font-size: 1.25rem;
    color: var(--color-primary);
    margin-right: 2rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
    cursor: pointer;
    transition: opacity 0.15s;
}

.nav__brand:hover {
    opacity: 0.8;
}

.nav__logo {
    width: 2rem;
    height: 2rem;
    object-fit: contain;
    flex-shrink: 0;
}

.nav__links {
    display: flex;
    gap: 0.25rem;
}

.nav__link {
    padding: 0.5rem 1rem;
    text-decoration: none;
    color: var(--color-text-secondary);
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
}

.nav__link:hover {
    background: var(--color-bg);
    color: var(--color-text);
}

.nav__link--active {
    background: var(--color-primary);
    color: white;
}

.nav__link--active:hover {
    background: var(--color-primary-hover);
    color: white;
}

/* Main content */
.main {
    max-width: 72rem;
    margin: 0 auto;
    padding: 2rem 1.5rem;
}

/* Upload view */
.upload {
    max-width: 40rem;
    margin: 0 auto;
}

.upload__title {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
}

.upload__dropzone {
    border: 2px dashed var(--color-border);
    border-radius: var(--radius);
    padding: 3rem 2rem;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
    background: var(--color-surface);
}

.upload__dropzone:hover,
.upload__dropzone--active {
    border-color: var(--color-primary);
    background: #f0f0ff;
}

.upload__dropzone-text {
    color: var(--color-text-secondary);
    margin-bottom: 0.5rem;
}

.upload__dropzone-hint {
    font-size: 0.75rem;
    color: var(--color-text-secondary);
}

.upload__input {
    display: none;
}

.upload__status {
    margin-top: 1.5rem;
}

.upload__file {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.upload__file-name {
    font-weight: 500;
    font-size: 0.875rem;
}

/* Badges */
.badge {
    display: inline-block;
    padding: 0.125rem 0.5rem;
    border-radius: 1rem;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

.badge--pending { background: #fef3c7; color: #92400e; }
.badge--processing { background: #dbeafe; color: #1e40af; }
.badge--ready { background: #d1fae5; color: #065f46; }
.badge--error { background: #fee2e2; color: #991b1b; }

/* Library view */
.library__title {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
}

.library__grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(18rem, 1fr));
    gap: 1rem;
}

.library__empty {
    text-align: center;
    color: var(--color-text-secondary);
    padding: 3rem;
}

/* Document card */
.doc-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
    transition: box-shadow 0.15s;
    cursor: pointer;
    text-decoration: none;
    color: inherit;
    display: block;
}

.doc-card:hover {
    box-shadow: var(--shadow-lg);
}

.doc-card__header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 0.75rem;
}

.doc-card__name {
    font-weight: 600;
    font-size: 0.9375rem;
    word-break: break-word;
}

.doc-card__meta {
    font-size: 0.75rem;
    color: var(--color-text-secondary);
    display: flex;
    gap: 1rem;
    margin-top: 0.5rem;
}

.doc-card__actions {
    margin-top: 0.75rem;
    display: flex;
    gap: 0.5rem;
}

/* Full-width modifier for chat view */
.main--fullwidth {
    max-width: none;
    padding: 0;
}

/* ─── Chat layout ─────────────────────────────────────────────── */

.chat {
    display: grid;
    grid-template-columns: 1fr 16rem;
    gap: 0;
    height: calc(100vh - 3.5rem);
}

.chat__main {
    display: flex;
    flex-direction: column;
    background: var(--color-bg);
    overflow: hidden;
    min-width: 0;
}

.chat__messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem 1.5rem 1rem;
    scroll-behavior: smooth;
}

/* ─── Welcome state ───────────────────────────────────────────── */

.chat__welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 4rem 2rem 2rem;
    animation: fadeInUp 0.4s ease-out;
}

.chat__welcome-icon {
    width: 4.5rem;
    height: 4.5rem;
    border-radius: 1.25rem;
    background: linear-gradient(135deg, var(--color-primary), #7c3aed);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1.5rem;
    box-shadow: 0 8px 24px rgba(79, 70, 229, 0.25);
}

.chat__welcome-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--color-text);
    margin-bottom: 0.5rem;
}

.chat__welcome-subtitle {
    font-size: 0.9375rem;
    color: var(--color-text-secondary);
    max-width: 28rem;
    line-height: 1.5;
    margin-bottom: 2rem;
}

.chat__suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
    max-width: 36rem;
}

.chat__suggestion {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 2rem;
    font-family: var(--font-sans);
    font-size: 0.8125rem;
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.chat__suggestion:hover {
    border-color: var(--color-primary);
    color: var(--color-primary);
    background: #f5f3ff;
    box-shadow: 0 2px 8px rgba(79, 70, 229, 0.1);
    transform: translateY(-1px);
}

.chat__suggestion svg {
    flex-shrink: 0;
    opacity: 0.6;
}

.chat__suggestion:hover svg {
    opacity: 1;
}

/* ─── Input area ──────────────────────────────────────────────── */

.chat__form {
    padding: 0.75rem 1.5rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
}

.chat__input-wrapper {
    display: flex;
    align-items: center;
    gap: 0;
    background: var(--color-surface);
    border: 2px solid var(--color-border);
    border-radius: 0.75rem;
    padding: 0.25rem 0.25rem 0.25rem 0.875rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.chat__input-wrapper:focus-within {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.chat__input {
    flex: 1;
    padding: 0.5rem 0;
    border: none;
    font-family: var(--font-sans);
    font-size: 0.9375rem;
    resize: none;
    outline: none;
    background: transparent;
    color: var(--color-text);
    line-height: 1.5;
}

.chat__input::placeholder {
    color: var(--color-text-secondary);
    opacity: 0.7;
}

.chat__send-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    border: none;
    border-radius: 0.5rem;
    background: var(--color-primary);
    color: white;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    flex-shrink: 0;
}

.chat__send-btn:hover:not(:disabled) {
    background: var(--color-primary-hover);
    transform: scale(1.05);
}

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

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

.chat__model-select {
    appearance: none;
    -webkit-appearance: none;
    background: var(--color-bg);
    border: none;
    border-radius: 0.375rem;
    padding: 0.25rem 1.25rem 0.25rem 0.5rem;
    font-family: var(--font-sans);
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--color-primary);
    cursor: pointer;
    outline: none;
    flex-shrink: 0;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2.5'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.25rem center;
    transition: background-color 0.15s, color 0.15s;
}

.chat__model-select:hover {
    background-color: #eef2ff;
}

.chat__model-select:focus {
    background-color: #eef2ff;
}

.chat__input-divider {
    width: 1px;
    height: 1.25rem;
    background: var(--color-border);
    flex-shrink: 0;
}

.chat__form-hint {
    font-size: 0.6875rem;
    color: var(--color-text-secondary);
    opacity: 0.6;
    text-align: center;
}

/* ─── Messages ────────────────────────────────────────────────── */

.message {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
    max-width: 48rem;
    animation: fadeIn 0.3s ease-out;
}

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

.message__avatar {
    width: 2rem;
    height: 2rem;
    border-radius: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 0.125rem;
}

.message__avatar--user {
    background: var(--color-primary);
    color: white;
}

.message__avatar--assistant {
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
}

.message__content {
    min-width: 0;
    max-width: calc(100% - 3rem);
}

.message__role {
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-secondary);
    margin-bottom: 0.25rem;
}

.message--user .message__role {
    text-align: right;
}

.message__bubble {
    display: inline-block;
    max-width: 100%;
    padding: 0.75rem 1rem;
    border-radius: 0.75rem;
    text-align: left;
    font-size: 0.875rem;
    line-height: 1.7;
    word-break: break-word;
}

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

.message--assistant .message__bubble {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-bottom-left-radius: 0.25rem;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.message--assistant .message__bubble h2,
.message--assistant .message__bubble h3,
.message--assistant .message__bubble h4 {
    margin: 0.75rem 0 0.375rem;
    line-height: 1.3;
}

.message--assistant .message__bubble h2:first-child,
.message--assistant .message__bubble h3:first-child,
.message--assistant .message__bubble h4:first-child {
    margin-top: 0;
}

.message--assistant .message__bubble h2 { font-size: 1.0625rem; }
.message--assistant .message__bubble h3 { font-size: 0.9375rem; }
.message--assistant .message__bubble h4 { font-size: 0.875rem; }

.message--assistant .message__bubble p {
    margin: 0.375rem 0;
}

.message--assistant .message__bubble ul,
.message--assistant .message__bubble ol {
    margin: 0.375rem 0;
    padding-left: 1.5rem;
}

.message--assistant .message__bubble li {
    margin-bottom: 0.375rem;
}

.message__sources {
    margin-top: 0.625rem;
    font-size: 0.75rem;
    color: var(--color-text-secondary);
    padding-left: 0;
}

.message__source {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 1rem;
    padding: 0.1875rem 0.625rem;
    margin: 0.1875rem 0.125rem;
    font-size: 0.6875rem;
    font-weight: 500;
    transition: all 0.15s;
}

/* ─── Report download button ─────────────────────────────────── */

.message__download {
    margin-top: 0.75rem;
}

.message__download-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1.125rem;
    background: linear-gradient(135deg, var(--color-primary), #7c3aed);
    color: white;
    border: none;
    border-radius: 2rem;
    font-family: var(--font-sans);
    font-size: 0.8125rem;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 2px 8px rgba(79, 70, 229, 0.2);
}

.message__download-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
    color: white;
}

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

.message__download-btn svg {
    flex-shrink: 0;
}

/* ─── Viewer panel ─────────────────────────────────────────────── */

.chat--viewer-open {
    grid-template-columns: minmax(22rem, 32rem) 1fr;
}

.chat--viewer-open .chat__sidebar {
    display: none;
}

.chat__viewer {
    display: none;
    flex-direction: column;
    background: var(--color-surface);
    overflow: hidden;
    border-left: 1px solid var(--color-border);
    animation: slideInRight 0.25s ease-out;
}

.chat--viewer-open .chat__viewer {
    display: flex;
}

.chat__viewer-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1rem;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-surface);
    min-height: 2.75rem;
}

.chat__viewer-icon {
    color: var(--color-primary);
    flex-shrink: 0;
}

.chat__viewer-filename {
    font-size: 0.8125rem;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
}

.chat__viewer-page {
    font-size: 0.6875rem;
    font-weight: 500;
    color: var(--color-text-secondary);
    white-space: nowrap;
    flex-shrink: 0;
    background: var(--color-bg);
    padding: 0.125rem 0.5rem;
    border-radius: 1rem;
}

.chat__viewer-close {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.25rem;
    color: var(--color-text-secondary);
    padding: 0.25rem 0.375rem;
    line-height: 1;
    border-radius: 0.375rem;
    flex-shrink: 0;
    transition: all 0.15s;
}

.chat__viewer-close:hover {
    background: var(--color-error);
    color: white;
}

.chat__viewer-content {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    background: #1a1a2e;
    min-height: 0;
}

.chat__viewer-content canvas {
    display: block;
    margin: 0 auto;
    max-width: 100%;
    height: auto;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
    border-radius: 4px;
}

.chat__viewer-status {
    padding: 0.75rem;
    font-size: 0.8125rem;
    text-align: center;
    color: #999;
}

.chat__viewer-snippet {
    font-size: 0.75rem;
    line-height: 1.5;
    padding: 0.625rem 1rem;
    background: #fffbeb;
    border-top: 1px solid #fde68a;
    border-left: 3px solid #f59e0b;
    color: #92400e;
    max-height: 5rem;
    overflow-y: auto;
}

.chat__viewer-snippet:empty {
    display: none;
}

/* ─── Clickable source badges ──────────────────────────────────── */

.message__source--clickable {
    cursor: pointer;
    transition: all 0.15s;
}

.message__source--clickable:hover {
    border-color: var(--color-primary);
    color: var(--color-primary);
    background: #f5f3ff;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(79, 70, 229, 0.15);
}

.message__source--clickable:focus {
    outline: 2px solid var(--color-primary);
    outline-offset: 1px;
}

.message__source--active {
    border-color: var(--color-primary);
    background: var(--color-primary);
    color: white;
    box-shadow: 0 2px 8px rgba(79, 70, 229, 0.3);
}

/* ─── Inline [Source N] links ──────────────────────────────────── */

.source-ref {
    color: var(--color-primary);
    text-decoration: none;
    font-weight: 600;
    cursor: pointer;
    border-bottom: 1px dashed var(--color-primary);
    padding: 0 0.125rem;
    border-radius: 2px;
    transition: background 0.15s, color 0.15s;
}

.source-ref:hover {
    background: var(--color-primary);
    color: white;
    border-bottom-color: transparent;
}

.source-ref:focus {
    outline: 2px solid var(--color-primary);
    outline-offset: 1px;
}

/* ─── Sidebar ─────────────────────────────────────────────────── */

.chat__sidebar {
    background: var(--color-surface);
    border-left: 1px solid var(--color-border);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.chat__sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.875rem 1rem 0.625rem;
    border-bottom: 1px solid var(--color-border);
}

.chat__sidebar-title {
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-text-secondary);
    display: flex;
    align-items: center;
    gap: 0.375rem;
}

.chat__sidebar-title svg {
    opacity: 0.5;
}

.chat__sidebar-count {
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--color-primary);
    background: #f5f3ff;
    padding: 0.0625rem 0.5rem;
    border-radius: 1rem;
    min-width: 1.25rem;
    text-align: center;
}

.chat__sidebar-count:empty {
    display: none;
}

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

.chat__doc-loading {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 1rem;
    font-size: 0.75rem;
    color: var(--color-text-secondary);
}

.chat__doc-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.375rem;
    padding: 2rem 1rem;
    text-align: center;
    color: var(--color-text-secondary);
    font-size: 0.75rem;
}

.chat__doc-upload-link {
    font-size: 0.75rem;
    color: var(--color-primary);
    text-decoration: none;
    font-weight: 500;
}

.chat__doc-upload-link:hover {
    text-decoration: underline;
}

.chat__doc-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4375rem 0.5rem;
    border-radius: 0.375rem;
    cursor: pointer;
    font-size: 0.8125rem;
    margin-bottom: 0.125rem;
    transition: background 0.1s;
}

.chat__doc-item:hover {
    background: var(--color-bg);
}

.chat__doc-item input[type="checkbox"] {
    accent-color: var(--color-primary);
    width: 0.875rem;
    height: 0.875rem;
    flex-shrink: 0;
}

.chat__doc-icon {
    color: var(--color-text-secondary);
    opacity: 0.5;
    flex-shrink: 0;
}

.chat__doc-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.chat__doc-name--hoverable {
    cursor: help;
    text-decoration: underline;
    text-decoration-style: dotted;
    text-decoration-color: var(--color-primary);
    text-underline-offset: 2px;
}

/* Document detail view */
.doc-detail {
    max-width: 48rem;
    margin: 0 auto;
}

.doc-detail__header {
    margin-bottom: 1.5rem;
}

.doc-detail__title {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.doc-detail__meta {
    font-size: 0.875rem;
    color: var(--color-text-secondary);
    display: flex;
    gap: 1.5rem;
    flex-wrap: wrap;
}

.doc-detail__actions {
    margin: 1.5rem 0;
    display: flex;
    gap: 0.75rem;
}

.doc-detail__chunks {
    margin-top: 1.5rem;
}

.doc-detail__chunk {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 0.75rem;
}

.doc-detail__chunk-header {
    font-size: 0.75rem;
    color: var(--color-text-secondary);
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.doc-detail__chunk-text {
    font-size: 0.8125rem;
    line-height: 1.6;
    white-space: pre-wrap;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.5rem 1rem;
    border: none;
    border-radius: var(--radius);
    font-family: var(--font-sans);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, opacity 0.15s;
}

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

.btn--primary {
    background: var(--color-primary);
    color: white;
}

.btn--primary:hover:not(:disabled) {
    background: var(--color-primary-hover);
}

.btn--danger {
    background: var(--color-error);
    color: white;
}

.btn--danger:hover:not(:disabled) {
    background: #dc2626;
}

.btn--ghost {
    background: transparent;
    color: var(--color-text-secondary);
    border: 1px solid var(--color-border);
}

.btn--ghost:hover:not(:disabled) {
    background: var(--color-bg);
}

.btn--icon {
    background: transparent;
    color: var(--color-text-secondary);
    border: 1px solid var(--color-border);
    padding: 0.5rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn--icon:hover:not(:disabled) {
    background: var(--color-bg);
    color: var(--color-primary);
    border-color: var(--color-primary);
}

.btn--small {
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
}

/* PDF Viewer Modal */
.pdf-viewer-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    animation: fadeIn 0.2s ease-out;
}

.pdf-viewer-modal--open {
    display: flex;
    align-items: center;
    justify-content: center;
}

.pdf-viewer-modal__content {
    background: var(--color-surface);
    border-radius: var(--radius);
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    width: 90vw;
    height: 90vh;
    max-width: 1200px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: slideUp 0.3s ease-out;
}

.pdf-viewer-modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-surface);
}

.pdf-viewer-modal__title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 80%;
}

.pdf-viewer-modal__close {
    background: transparent;
    border: none;
    color: var(--color-text-secondary);
    cursor: pointer;
    padding: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius);
    transition: background 0.15s, color 0.15s;
}

.pdf-viewer-modal__close:hover {
    background: var(--color-bg);
    color: var(--color-text);
}

.pdf-viewer-modal__iframe {
    flex: 1;
    border: none;
    width: 100%;
    height: 100%;
}

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

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

/* PDF Preview Popup */
.pdf-preview-popup {
    position: fixed;
    z-index: 999;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    padding: 0.5rem;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
    pointer-events: none;
    max-width: 300px;
}

.pdf-preview-popup--visible {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.pdf-preview-popup canvas {
    display: block;
    width: 100%;
    height: auto;
    border-radius: calc(var(--radius) - 0.25rem);
}

.doc-card__name--hoverable {
    cursor: help;
    position: relative;
    text-decoration: underline;
    text-decoration-style: dotted;
    text-decoration-color: var(--color-primary);
    text-underline-offset: 2px;
}

/* Spinner */
.spinner {
    display: inline-block;
    width: 1rem;
    height: 1rem;
    border: 2px solid var(--color-border);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

/* ─── Animations ──────────────────────────────────────────────── */

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

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

@keyframes slideInRight {
    from { opacity: 0; transform: translateX(1rem); }
    to { opacity: 1; transform: translateX(0); }
}

/* ─── Custom scrollbar ────────────────────────────────────────── */

.chat__messages::-webkit-scrollbar,
.chat__doc-list::-webkit-scrollbar,
.chat__viewer-content::-webkit-scrollbar {
    width: 6px;
}

.chat__messages::-webkit-scrollbar-track,
.chat__doc-list::-webkit-scrollbar-track {
    background: transparent;
}

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

.chat__messages::-webkit-scrollbar-thumb:hover,
.chat__doc-list::-webkit-scrollbar-thumb:hover {
    background: var(--color-text-secondary);
}

.chat__viewer-content::-webkit-scrollbar-track {
    background: #111;
}

.chat__viewer-content::-webkit-scrollbar-thumb {
    background: #444;
    border-radius: 3px;
}

/* ─── Responsive ──────────────────────────────────────────────── */

@media (max-width: 64rem) {
    .chat--viewer-open {
        grid-template-columns: minmax(18rem, 24rem) 1fr;
    }

    .chat__welcome-title {
        font-size: 1.25rem;
    }

    .chat__suggestions {
        flex-direction: column;
        align-items: center;
    }
}

/* ─── Logout button ───────────────────────────────────────────── */

.nav__logout {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.375rem 0.75rem;
    background: transparent;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-family: var(--font-sans);
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.nav__logout:hover {
    background: #fee2e2;
    color: var(--color-error);
    border-color: var(--color-error);
}

/* ─── Login page ──────────────────────────────────────────────── */

.login {
    min-height: calc(100vh - 3.5rem);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem 1rem;
    background: var(--color-bg);
}

.login__card {
    width: 100%;
    max-width: 22rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 1rem;
    padding: 2.5rem 2rem;
    box-shadow: var(--shadow-lg);
    animation: fadeInUp 0.3s ease-out;
}

.login__header {
    text-align: center;
    margin-bottom: 2rem;
}

.login__logo {
    width: 4rem;
    height: 4rem;
    object-fit: contain;
    margin-bottom: 1rem;
}

.login__title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--color-primary);
    margin-bottom: 0.25rem;
}

.login__subtitle {
    font-size: 0.875rem;
    color: var(--color-text-secondary);
}

.login__form {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.login__field {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
}

.login__label {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--color-text);
}

.login__input {
    padding: 0.625rem 0.875rem;
    border: 2px solid var(--color-border);
    border-radius: var(--radius);
    font-family: var(--font-sans);
    font-size: 0.9375rem;
    color: var(--color-text);
    background: var(--color-surface);
    transition: border-color 0.2s, box-shadow 0.2s;
    outline: none;
}

.login__input:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.login__input::placeholder {
    color: var(--color-text-secondary);
    opacity: 0.6;
}

.login__error {
    padding: 0.625rem 0.875rem;
    background: #fee2e2;
    border: 1px solid #fca5a5;
    border-radius: var(--radius);
    font-size: 0.8125rem;
    color: #991b1b;
}

.login__btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem;
    background: var(--color-primary);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-family: var(--font-sans);
    font-size: 0.9375rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    margin-top: 0.25rem;
}

.login__btn:hover:not(:disabled) {
    background: var(--color-primary-hover);
}

.login__btn:active:not(:disabled) {
    transform: scale(0.98);
}

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

@media (max-width: 48rem) {
    .chat {
        grid-template-columns: 1fr;
    }

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

    .chat__sidebar {
        display: none;
    }

    .chat--viewer-open .chat__viewer {
        position: fixed;
        top: 3.5rem;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 50;
    }

    .chat__welcome {
        padding: 2rem 1rem 1rem;
    }

    .chat__welcome-icon {
        width: 3.5rem;
        height: 3.5rem;
        border-radius: 1rem;
    }

    .chat__welcome-icon svg {
        width: 36px;
        height: 36px;
    }

    .chat__welcome-title {
        font-size: 1.125rem;
    }

    .chat__welcome-subtitle {
        font-size: 0.8125rem;
    }

    .chat__form {
        padding: 0.5rem 0.75rem 0.75rem;
    }

    .message {
        max-width: 100%;
    }

    .message__avatar {
        width: 1.75rem;
        height: 1.75rem;
    }

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

/* ─── History view (email browser style) ─────────────────────────── */

.history {
    display: grid;
    grid-template-columns: 24rem 1fr;
    height: calc(100vh - 3.5rem);
    background: var(--color-bg);
}

.history__sidebar {
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.history__sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-surface);
}

.history__sidebar-title {
    font-size: 0.875rem;
    font-weight: 700;
    color: var(--color-text);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.history__sidebar-title svg {
    color: var(--color-primary);
}

.history__count {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--color-primary);
    background: #f5f3ff;
    padding: 0.125rem 0.625rem;
    border-radius: 1rem;
    min-width: 1.5rem;
    text-align: center;
}

.history__actions {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--color-border);
}

.history__delete-all-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    width: 100%;
    padding: 0.5rem 0.75rem;
    background: transparent;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-family: var(--font-sans);
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: all 0.15s;
}

.history__delete-all-btn:hover:not(:disabled) {
    background: #fee2e2;
    color: var(--color-error);
    border-color: var(--color-error);
}

.history__delete-all-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.history__list {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

.history__loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 2rem 1rem;
    font-size: 0.875rem;
    color: var(--color-text-secondary);
}

.history__empty-list {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    padding: 3rem 1.5rem;
    text-align: center;
    color: var(--color-text-secondary);
}

.history__empty-list p {
    font-size: 0.875rem;
}

.history__chat-link {
    font-size: 0.8125rem;
    color: var(--color-primary);
    text-decoration: none;
    font-weight: 600;
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    border: 1px solid var(--color-primary);
    transition: all 0.2s;
}

.history__chat-link:hover {
    background: var(--color-primary);
    color: white;
}

.history__error {
    padding: 1.5rem 1rem;
    text-align: center;
    color: var(--color-error);
}

.history__error-message {
    font-size: 0.75rem;
    margin-top: 0.5rem;
    color: var(--color-text-secondary);
}

.history__item {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    cursor: pointer;
    transition: all 0.15s;
}

.history__item:hover {
    border-color: var(--color-primary);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.history__item--active {
    background: #f5f3ff;
    border-color: var(--color-primary);
    box-shadow: 0 2px 8px rgba(79, 70, 229, 0.15);
}

.history__item-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.375rem;
}

.history__item-user {
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-primary);
}

.history__item-time {
    font-size: 0.6875rem;
    font-weight: 500;
    color: var(--color-text-secondary);
}

.history__item-question {
    font-size: 0.8125rem;
    line-height: 1.4;
    color: var(--color-text);
    margin-bottom: 0.375rem;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.history__item-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 0.25rem;
}

.history__item-date {
    font-size: 0.6875rem;
    color: var(--color-text-secondary);
}

.history__item-delete {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.25rem;
    background: transparent;
    border: none;
    border-radius: 0.25rem;
    color: var(--color-text-secondary);
    cursor: pointer;
    opacity: 0;
    transition: all 0.15s;
}

.history__item:hover .history__item-delete {
    opacity: 1;
}

.history__item-delete:hover {
    background: #fee2e2;
    color: var(--color-error);
}

.history__item-delete:active {
    transform: scale(0.9);
}

.history__content {
    background: var(--color-bg);
    overflow-y: auto;
    padding: 2rem;
}

.history__empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    color: var(--color-text-secondary);
    gap: 1rem;
}

.history__empty p {
    font-size: 0.9375rem;
}

.history__detail {
    max-width: 56rem;
    margin: 0 auto;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 2rem;
    box-shadow: var(--shadow);
    animation: fadeInUp 0.3s ease-out;
}

.history__detail-header {
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--color-border);
}

.history__detail-meta {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8125rem;
}

.history__detail-user {
    font-weight: 700;
    color: var(--color-primary);
}

.history__detail-separator {
    color: var(--color-text-secondary);
    opacity: 0.5;
}

.history__detail-date {
    color: var(--color-text-secondary);
}

.history__detail-question,
.history__detail-answer {
    margin-bottom: 1.5rem;
}

.history__detail-label {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-text-secondary);
    margin-bottom: 0.5rem;
}

.history__detail-text {
    font-size: 0.9375rem;
    line-height: 1.7;
    color: var(--color-text);
}

.history__detail-question .history__detail-text {
    font-weight: 500;
    color: var(--color-text);
}

.history__detail-answer .history__detail-text h2,
.history__detail-answer .history__detail-text h3,
.history__detail-answer .history__detail-text h4 {
    margin: 1rem 0 0.5rem;
    line-height: 1.3;
}

.history__detail-answer .history__detail-text h2:first-child,
.history__detail-answer .history__detail-text h3:first-child,
.history__detail-answer .history__detail-text h4:first-child {
    margin-top: 0;
}

.history__detail-answer .history__detail-text h2 { font-size: 1.25rem; }
.history__detail-answer .history__detail-text h3 { font-size: 1.0625rem; }
.history__detail-answer .history__detail-text h4 { font-size: 0.9375rem; }

.history__detail-answer .history__detail-text p {
    margin: 0.5rem 0;
}

.history__detail-answer .history__detail-text ul,
.history__detail-answer .history__detail-text ol {
    margin: 0.5rem 0;
    padding-left: 1.5rem;
}

.history__detail-answer .history__detail-text li {
    margin-bottom: 0.375rem;
}

.history__sources {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--color-border);
}

.history__sources-title {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-text-secondary);
    margin-bottom: 0.75rem;
}

.history__source {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    margin-bottom: 0.5rem;
    font-size: 0.8125rem;
}

.history__source-badge {
    font-weight: 700;
    color: var(--color-primary);
    flex-shrink: 0;
}

.history__source-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--color-text);
}

.history__source-pages {
    font-size: 0.75rem;
    color: var(--color-text-secondary);
    flex-shrink: 0;
}

.history__download {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--color-border);
}

.history__download-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    background: linear-gradient(135deg, var(--color-primary), #7c3aed);
    color: white;
    border: none;
    border-radius: 2rem;
    font-family: var(--font-sans);
    font-size: 0.875rem;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 2px 8px rgba(79, 70, 229, 0.2);
}

.history__download-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
    color: white;
}

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

.history__download-btn svg {
    flex-shrink: 0;
}

.history__list::-webkit-scrollbar,
.history__content::-webkit-scrollbar {
    width: 6px;
}

.history__list::-webkit-scrollbar-track,
.history__content::-webkit-scrollbar-track {
    background: transparent;
}

.history__list::-webkit-scrollbar-thumb,
.history__content::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: 3px;
}

.history__list::-webkit-scrollbar-thumb:hover,
.history__content::-webkit-scrollbar-thumb:hover {
    background: var(--color-text-secondary);
}

@media (max-width: 64rem) {
    .history {
        grid-template-columns: 20rem 1fr;
    }
}

@media (max-width: 48rem) {
    .history {
        grid-template-columns: 1fr;
    }

    .history__sidebar {
        display: none;
    }

    .history__content {
        padding: 1rem;
    }

    .history__detail {
        padding: 1.25rem;
    }
}

/* ─── Admin view ──────────────────────────────────────────────── */

.admin {
    max-width: 56rem;
    margin: 0 auto;
}

.admin__header {
    margin-bottom: 2rem;
}

.admin__title {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--color-text);
    margin-bottom: 0.5rem;
}

.admin__subtitle {
    font-size: 0.9375rem;
    color: var(--color-text-secondary);
}

.admin__sections {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.admin__section {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1.75rem;
    box-shadow: var(--shadow);
}

.admin__section-header {
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--color-border);
}

.admin__section-title {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--color-text);
    margin-bottom: 0.375rem;
}

.admin__section-description {
    font-size: 0.875rem;
    color: var(--color-text-secondary);
    line-height: 1.5;
}

.admin__field {
    margin-bottom: 1.5rem;
}

.admin__label {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: 0.5rem;
}

.admin__textarea {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid var(--color-border);
    border-radius: var(--radius);
    font-family: var(--font-sans);
    font-size: 0.9375rem;
    color: var(--color-text);
    background: var(--color-surface);
    resize: vertical;
    transition: border-color 0.2s, box-shadow 0.2s;
    outline: none;
    line-height: 1.6;
}

.admin__textarea:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.admin__textarea::placeholder {
    color: var(--color-text-secondary);
    opacity: 0.6;
}

.admin__hint {
    font-size: 0.8125rem;
    color: var(--color-text-secondary);
    margin-top: 0.5rem;
    line-height: 1.5;
}

.admin__actions {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

.admin__status {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 500;
    margin-top: 1rem;
}

.admin__status--success {
    background: #d1fae5;
    color: #065f46;
    border: 1px solid #6ee7b7;
}

.admin__status--error {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fca5a5;
}

.admin__status--info {
    background: #dbeafe;
    color: #1e40af;
    border: 1px solid #93c5fd;
}

.admin__section--placeholder {
    background: var(--color-bg);
    border-style: dashed;
}

.admin__placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 2rem;
    text-align: center;
    color: var(--color-text-secondary);
}

.admin__placeholder svg {
    opacity: 0.3;
}

.admin__placeholder p {
    font-size: 0.875rem;
}

@media (max-width: 48rem) {
    .admin {
        padding: 1rem;
    }

    .admin__section {
        padding: 1.25rem;
    }

    .admin__actions {
        flex-direction: column;
        align-items: stretch;
    }

    .admin__actions .btn {
        width: 100%;
        justify-content: center;
    }
}
