/* ==========================================
   УЧЕБНИК AI — DESIGN SYSTEM
   ========================================== */

:root {
    --bg: #1b1a1a;              /* основной фон */
    --bg-soft: #333333;         /* второстепенный фон (сайдбар, карточки) */
    --bg-hover: #3d3d3d;        /* hover-состояние */
    --ink: #e8e4dc;             /* основной текст и светлые кнопки */
    --ink-soft: #b0a898;        /* второстепенный текст */
    --ink-muted: #6a6560;       /* подсказки, мета-данные */
    --rule: #484848;            /* границы, разделители */
    --rule-strong: #585858;     /* акцентные границы */
    --accent: #a0b8a0;          /* акцент: ссылки, hover кнопок, цитаты */
    --accent-soft: rgba(160, 184, 160, 0.12); /* акцент-фон (бейджи, подсветка) */
    --danger: #e05555;          /* ошибки, кнопка «Удалить» */
    --success: #4aad6a;         /* статус «Готов» */
    --warning: #c8a840;         /* статус «Индексируется» */
    --font: 'Geist', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --mono: 'Geist Mono', ui-monospace, 'SF Mono', Menlo, monospace;
    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 24px;
    --radius-pill: 100px;
    --shadow-sm: 0 1px 2px rgba(10, 10, 10, 0.04);
    --shadow-md: 0 4px 16px rgba(10, 10, 10, 0.06);
    --shadow-lg: 0 12px 40px rgba(10, 10, 10, 0.08);
}

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

html, body {
    background: var(--bg);
    color: var(--ink);
    font-family: var(--font);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-feature-settings: 'ss01', 'cv11';
    line-height: 1.5;
}

body {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

a {
    color: inherit;
    text-decoration: none;
}

button {
    font-family: inherit;
}

/* ==========================================
   NAV / HEADER
   ========================================== */

.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    padding: 18px 40px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(255, 255, 255, 0.72);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-bottom: 1px solid transparent;
    transition: border-color 0.3s ease;
}

.header.scrolled {
    border-bottom-color: var(--rule);
}

.logo {
    font-size: 17px;
    font-weight: 600;
    letter-spacing: -0.02em;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: #1b1a1a;
}

.logo-mark {
    width: 26px;
    height: 26px;
    border-radius: 7px;
    background: var(--ink);
    color: var(--bg);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-family: var(--mono);
    font-size: 13px;
    font-weight: 500;
}

.nav {
    display: flex;
    align-items: center;
    gap: 6px;
}

.nav a {
    font-size: 14px;
    font-weight: 400;
    color: #2a2825;
    padding: 8px 16px;
    border-radius: var(--radius-pill);
    transition: all 0.2s ease;
}

.nav a:hover {
    color: #0f0e0d;
    background: rgba(0, 0, 0, 0.07);
}

.nav-user {
    font-size: 13px;
    color: #3a3835;
    padding: 8px 14px;
    font-family: var(--mono);
    border-left: 1px solid rgba(0, 0, 0, 0.12);
    margin-left: 8px;
}

.nav-cta {
    background: #1f1d1b;
    color: #f0ece4 !important;
    padding: 9px 18px !important;
    border-radius: var(--radius-pill);
    font-weight: 500;
    transition: opacity 0.2s ease;
}

.nav-cta:hover {
    opacity: 0.85;
    background: #1f1d1b !important;
    color: #f0ece4 !important;
}

.nav-logout {
    color: #4a4845 !important;
    font-size: 13px !important;
}

/* ==========================================
   MAIN
   ========================================== */

.main {
    flex: 1;
    padding-top: 72px;
    position: relative;
    z-index: 10;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 60px 40px;
}

.container-narrow {
    max-width: 560px;
    margin: 0 auto;
    padding: 80px 32px;
}

/* ==========================================
   BUTTONS
   ========================================== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border-radius: var(--radius-pill);
    font-family: var(--font);
    font-size: 14px;
    font-weight: 500;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.2s ease;
    letter-spacing: -0.01em;
    white-space: nowrap;
    line-height: 1;
}

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

.btn-primary:hover {
    background: var(--accent);
    transform: translateY(-1px);
}

.btn-primary:disabled {
    background: var(--ink-muted);
    cursor: not-allowed;
    transform: none;
}

.btn-secondary {
    background: var(--bg);
    color: var(--ink);
    border-color: var(--rule);
}

.btn-secondary:hover {
    border-color: var(--ink);
    background: var(--bg);
}

.btn-danger {
    background: var(--bg);
    color: var(--danger);
    border-color: var(--rule);
}

.btn-danger:hover {
    background: var(--danger);
    color: var(--bg);
    border-color: var(--danger);
}

.btn-lg {
    padding: 15px 30px;
    font-size: 15px;
}

.btn-sm {
    padding: 8px 16px;
    font-size: 13px;
}

.btn-full {
    width: 100%;
}

/* ==========================================
   FORMS
   ========================================== */

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--ink);
    margin-bottom: 8px;
    letter-spacing: -0.01em;
}

.form-input,
.form-textarea {
    width: 100%;
    padding: 13px 16px;
    border: 1px solid var(--rule);
    border-radius: var(--radius-md);
    font-family: var(--font);
    font-size: 14px;
    color: var(--ink);
    background: var(--bg);
    transition: all 0.15s ease;
    outline: none;
}

.form-input::placeholder,
.form-textarea::placeholder {
    color: var(--ink-muted);
}

.form-input:focus,
.form-textarea:focus {
    border-color: var(--ink);
    background: var(--bg);
}

.form-hint {
    display: block;
    margin-top: 8px;
    font-size: 12px;
    color: var(--ink-muted);
    font-family: var(--mono);
}

/* ==========================================
   AUTH PAGES
   ========================================== */

.auth-container {
    min-height: calc(100vh - 72px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 60px 24px;
}

.auth-card {
    width: 100%;
    max-width: 420px;
    background: var(--bg);
    border: 1px solid var(--rule);
    border-radius: var(--radius-lg);
    padding: 48px 40px;
    box-shadow: var(--shadow-sm);
}

.auth-card h1 {
    font-size: 32px;
    font-weight: 600;
    line-height: 1.1;
    letter-spacing: -0.03em;
    margin-bottom: 8px;
}

.auth-subtitle {
    font-size: 15px;
    color: var(--ink-soft);
    margin-bottom: 32px;
}

.auth-error {
    padding: 12px 16px;
    background: rgba(220, 38, 38, 0.06);
    border: 1px solid rgba(220, 38, 38, 0.2);
    color: var(--danger);
    border-radius: var(--radius-md);
    font-size: 13px;
    margin-bottom: 20px;
}

.auth-form .btn {
    margin-top: 8px;
}

.auth-switch {
    margin-top: 24px;
    text-align: center;
    font-size: 14px;
    color: var(--ink-soft);
}

.auth-switch a {
    color: var(--ink);
    font-weight: 500;
    border-bottom: 1px solid var(--rule);
    transition: border-color 0.2s ease;
}

.auth-switch a:hover {
    border-color: var(--ink);
}

/* ==========================================
   PAGE HEADER
   ========================================== */

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 48px;
    flex-wrap: wrap;
    gap: 16px;
}

.page-header h1 {
    font-size: clamp(32px, 4vw, 44px);
    font-weight: 600;
    letter-spacing: -0.03em;
    line-height: 1.05;
}

/* ==========================================
   DASHBOARD: BOOKS GRID
   ========================================== */

.books-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 24px;
}

.book-card {
    background: var(--bg-soft);
    border: 1px solid var(--rule);
    border-radius: var(--radius-md);
    padding: 32px 28px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    transition: background 0.2s ease;
    min-height: 220px;
}

.book-card:hover {
    background: var(--bg-soft);
}

.book-card-top {
    display: flex;
    gap: 16px;
    align-items: flex-start;
}

.book-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: var(--ink);
    color: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}

.book-info {
    flex: 1;
    min-width: 0;
}

.book-title {
    font-size: 17px;
    font-weight: 600;
    line-height: 1.3;
    letter-spacing: -0.015em;
    margin-bottom: 6px;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    word-break: break-word;
}

.book-meta {
    display: block;
    font-size: 12px;
    color: var(--ink-muted);
    font-family: var(--mono);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.book-card-bottom {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: auto;
}

.book-card-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-top: 4px;
}

.inline-form {
    display: inline-flex;
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    border-radius: var(--radius-pill);
    font-size: 11px;
    font-family: var(--mono);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.badge-ready {
    background: rgba(22, 163, 74, 0.1);
    color: var(--success);
}

.badge-ready::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--success);
}

.badge-processing {
    background: rgba(245, 158, 11, 0.1);
    color: var(--warning);
}

.badge-processing::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--warning);
    animation: pulse-soft 1.4s ease-in-out infinite;
}

.badge-error {
    background: rgba(220, 38, 38, 0.1);
    color: var(--danger);
}

@keyframes pulse-soft {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* ==========================================
   EMPTY STATE
   ========================================== */

.empty-state {
    text-align: center;
    padding: 100px 20px;
    border: 1px dashed var(--rule);
    border-radius: var(--radius-lg);
}

.empty-icon {
    font-size: 56px;
    margin-bottom: 20px;
    opacity: 0.4;
}

.empty-state h2 {
    font-size: 24px;
    font-weight: 600;
    letter-spacing: -0.02em;
    margin-bottom: 8px;
}

.empty-state p {
    font-size: 15px;
    color: var(--ink-soft);
    margin-bottom: 28px;
}

/* ==========================================
   UPLOAD PAGE
   ========================================== */

.upload-form {
    margin-top: 32px;
}

.container-narrow h1 {
    font-size: 36px;
    font-weight: 600;
    letter-spacing: -0.03em;
    margin-bottom: 8px;
    line-height: 1.1;
}

.container-narrow > p {
    color: var(--ink-soft);
    margin-bottom: 8px;
}

.file-drop {
    position: relative;
    border: 1.5px dashed var(--rule);
    border-radius: var(--radius-lg);
    padding: 56px 24px;
    text-align: center;
    transition: all 0.2s ease;
    cursor: pointer;
    background: var(--bg-soft);
}

.file-drop:hover,
.file-drop-active {
    border-color: var(--ink);
    background: var(--bg);
}

.file-input {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

.file-drop-content {
    pointer-events: none;
}

.file-drop-icon {
    font-size: 40px;
    margin-bottom: 12px;
    opacity: 0.6;
}

.file-drop-text {
    font-size: 15px;
    color: var(--ink);
    font-weight: 500;
    margin-bottom: 6px;
}

.file-drop-hint {
    font-size: 12px;
    color: var(--ink-muted);
    font-family: var(--mono);
}

/* ==========================================
   CHAT PAGE
   ========================================== */

.chat-layout {
    display: grid;
    grid-template-columns: var(--sidebar-width, 300px) 1fr auto;
    height: calc(100vh - 72px);
    background: var(--bg);
    transition: grid-template-columns 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}

.chat-layout.sidebar-collapsed {
    --sidebar-width: 0px;
}

.chat-sidebar {
    border-right: 1px solid var(--rule);
    background: var(--bg-soft);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

.chat-layout.sidebar-collapsed .chat-sidebar {
    border-right-color: transparent;
}

.chat-sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 22px 22px 16px;
    flex-shrink: 0;
}

.chat-sidebar-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--ink);
    letter-spacing: -0.01em;
    text-transform: uppercase;
    font-family: var(--mono);
    letter-spacing: 0.04em;
}

.chat-sidebar-collapse,
.chat-sidebar-expand {
    width: 30px;
    height: 30px;
    border: 1px solid var(--rule);
    background: var(--bg);
    color: var(--ink-soft);
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    flex-shrink: 0;
}

.chat-sidebar-collapse:hover,
.chat-sidebar-expand:hover {
    border-color: var(--ink);
    color: var(--ink);
}

.chat-sidebar-expand {
    position: absolute;
    top: 16px;
    left: 16px;
    z-index: 5;
    display: none;
}

.chat-layout.sidebar-collapsed .chat-sidebar-expand {
    display: flex;
}

.chat-sidebar-body {
    flex: 1;
    overflow-y: auto;
    padding: 4px 14px 18px;
}

.chat-sidebar-footer {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 16px 22px 22px;
    border-top: 1px solid var(--rule);
    flex-shrink: 0;
}

/* === Список книг === */

.book-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.book-list-empty {
    padding: 24px 8px;
    text-align: center;
    font-size: 13px;
    color: var(--ink-muted);
}

.book-toggle {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    width: 100%;
    padding: 12px 12px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    cursor: pointer;
    text-align: left;
    transition: all 0.15s ease;
    font-family: var(--font);
    color: var(--ink);
}

.book-toggle:hover:not(:disabled) {
    background: var(--bg);
    border-color: var(--rule);
}

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

.book-list-item-active .book-toggle {
    background: var(--bg);
    border-color: var(--rule);
}

.book-toggle-check {
    width: 20px;
    height: 20px;
    border: 1.5px solid var(--rule-strong);
    border-radius: 6px;
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 1px;
    transition: all 0.15s ease;
    color: transparent;
}

.book-list-item-active .book-toggle-check {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--bg);
}

.book-toggle-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.book-toggle-title {
    font-size: 13px;
    font-weight: 500;
    line-height: 1.35;
    letter-spacing: -0.01em;
    color: var(--ink);
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    word-break: break-word;
}

.book-list-item-active .book-toggle-title {
    color: var(--ink);
}

.book-toggle-meta {
    font-size: 11px;
    color: var(--ink-muted);
    font-family: var(--mono);
    letter-spacing: 0.01em;
}

/* === Загрузка / индексация книги (inline upload) === */

.book-list-item-uploading .book-toggle,
.book-list-item-uploading .book-toggle:disabled {
    opacity: 1;
    cursor: default;
    background: var(--bg);
    border-color: var(--rule);
}

.book-list-item-uploading .book-toggle-check {
    border-color: var(--accent);
    background: transparent;
    color: transparent;
}

.book-toggle-spinner {
    width: 12px;
    height: 12px;
    border: 1.5px solid var(--rule);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: chat-spin 0.8s linear infinite;
}

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

.book-list-item-uploading .book-toggle-meta {
    color: var(--accent);
}

.book-list-item-error .book-toggle,
.book-list-item-error .book-toggle:disabled {
    opacity: 0.75;
    background: var(--bg);
    border-color: var(--rule);
    cursor: default;
}

.book-list-item-error .book-toggle-check {
    border-color: var(--ink-muted);
    background: transparent;
    color: var(--ink-muted);
}

.book-list-item-error .book-toggle-meta {
    color: #c0392b;
}

/* Ссылка "→ открыть отдельный чат" — появляется под только что загруженной книгой */
.book-list-item-open-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin: 4px 0 4px 44px;
    padding: 4px 0;
    font-size: 11px;
    font-family: var(--mono);
    letter-spacing: 0.01em;
    color: var(--accent);
    text-decoration: none;
    transition: opacity 0.15s ease;
}

.book-list-item-open-link:hover {
    opacity: 0.7;
    text-decoration: underline;
}

.book-list-item-open-link svg {
    flex-shrink: 0;
}

/* === Активная панель сверху чата === */

.chat-active-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 14px 48px;
    border-bottom: 1px solid var(--rule);
    background: var(--bg);
    flex-shrink: 0;
}

.chat-layout.sidebar-collapsed .chat-active-bar {
    padding-left: 64px;
}

.chat-active-bar-label {
    font-size: 12px;
    color: var(--ink-muted);
    font-family: var(--mono);
    letter-spacing: 0.02em;
}

.chat-active-bar-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    height: 22px;
    padding: 0 8px;
    background: var(--accent-soft);
    color: var(--accent);
    border-radius: var(--radius-pill);
    font-size: 12px;
    font-weight: 600;
    font-family: var(--mono);
}

.chat-area {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg);
    min-width: 0;
    position: relative;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 40px 48px 24px;
    display: flex;
    flex-direction: column;
    gap: 28px;
}

.chat-welcome {
    margin: auto;
    text-align: center;
    max-width: 540px;
    padding: 40px 20px;
}

.chat-welcome-icon {
    font-size: 56px;
    margin-bottom: 20px;
    opacity: 0.5;
}

.chat-welcome h2 {
    font-size: 32px;
    font-weight: 600;
    letter-spacing: -0.025em;
    margin-bottom: 12px;
    line-height: 1.1;
}

.chat-welcome p {
    font-size: 16px;
    color: var(--ink-soft);
    margin-bottom: 32px;
}

.chat-suggestions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: center;
}

.suggestion-btn {
    padding: 12px 22px;
    background: var(--bg);
    border: 1px solid var(--rule);
    border-radius: var(--radius-pill);
    font-family: var(--font);
    font-size: 14px;
    color: var(--ink);
    cursor: pointer;
    transition: all 0.15s ease;
}

.suggestion-btn:hover {
    border-color: var(--ink);
    background: var(--bg-soft);
}

/* ===== Сообщения ===== */

.chat-message {
    display: flex;
    gap: 14px;
    align-items: flex-start;
    max-width: 820px;
    width: 100%;
}

.chat-message-user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.chat-avatar {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    background: var(--bg-soft);
    border: 1px solid var(--rule);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    flex-shrink: 0;
}

.chat-message-user .chat-avatar {
    background: var(--ink);
    border-color: var(--ink);
}

.chat-message-body {
    flex: 1;
    min-width: 0;
}

.chat-bubble {
    background: var(--bg);
    border: 1px solid var(--rule);
    border-radius: var(--radius-lg);
    padding: 18px 22px;
    font-size: 15px;
    line-height: 1.6;
    color: var(--ink);
    word-wrap: break-word;
}

.chat-message-user .chat-bubble {
    background: var(--ink);
    color: var(--bg);
    border-color: var(--ink);
}

.chat-message-error .chat-bubble {
    background: rgba(220, 38, 38, 0.06);
    border-color: rgba(220, 38, 38, 0.2);
    color: var(--danger);
}

.chat-text p {
    margin: 0 0 12px;
}

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

.chat-text ul,
.chat-text ol {
    margin: 8px 0 12px 22px;
}

.chat-text li {
    margin-bottom: 4px;
}

.chat-text code {
    background: var(--bg-soft);
    border: 1px solid var(--rule);
    padding: 1px 6px;
    border-radius: 5px;
    font-family: var(--mono);
    font-size: 0.88em;
}

.chat-message-user .chat-text code {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.2);
}

.chat-text pre {
    background: var(--bg-soft);
    border: 1px solid var(--rule);
    padding: 14px 16px;
    border-radius: var(--radius-md);
    overflow-x: auto;
    margin: 10px 0;
}

.chat-text pre code {
    background: none;
    border: none;
    padding: 0;
}

.chat-text strong {
    font-weight: 600;
}

.md-h2 {
    display: block;
    font-size: 16px;
    font-weight: 600;
    margin: 14px 0 8px;
    letter-spacing: -0.01em;
}

.md-h3 {
    display: block;
    font-size: 15px;
    font-weight: 600;
    margin: 12px 0 6px;
}

.chat-meta {
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid var(--rule);
    font-size: 11px;
    color: var(--ink-muted);
    font-family: var(--mono);
}

.chat-message-user .chat-meta {
    border-top-color: rgba(255, 255, 255, 0.2);
}

/* ===== Inline-сноски (citations) ===== */

.cite-ref {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    margin: 0 2px;
    background: var(--accent-soft);
    color: var(--accent);
    border-radius: 5px;
    font-size: 11px;
    font-weight: 600;
    font-family: var(--mono);
    cursor: pointer;
    vertical-align: super;
    line-height: 1;
    transition: all 0.15s ease;
    user-select: none;
}

.cite-ref:hover {
    background: var(--accent);
    color: var(--bg);
    transform: translateY(-1px);
}

/* ===== Кнопка «Источники» ===== */

.sources-btn {
    margin-top: 12px;
    padding: 8px 16px;
    background: var(--bg);
    border: 1px solid var(--rule);
    border-radius: var(--radius-pill);
    font-family: var(--font);
    font-size: 13px;
    font-weight: 500;
    color: var(--ink-soft);
    cursor: pointer;
    transition: all 0.15s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.sources-btn:hover {
    border-color: var(--ink);
    color: var(--ink);
    background: var(--bg-soft);
}

/* ===== Loading dots ===== */

.loading-dots {
    display: inline-flex;
    gap: 5px;
    padding: 4px 0;
}

.loading-dots span {
    width: 7px;
    height: 7px;
    background: var(--ink-muted);
    border-radius: 50%;
    animation: bounce 1.2s ease-in-out infinite;
}

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

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

/* ===== Input area ===== */

.chat-input-area {
    border-top: 1px solid var(--rule);
    padding: 20px 48px 24px;
    background: var(--bg);
}

.chat-input-form {
    max-width: 820px;
    margin: 0 auto;
}

.chat-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    border: 1px solid var(--rule);
    border-radius: var(--radius-lg);
    padding: 8px 8px 8px 18px;
    background: var(--bg);
    transition: border-color 0.15s ease;
}

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

.chat-input {
    flex: 1;
    border: none;
    outline: none;
    background: none;
    resize: none;
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    color: var(--ink);
    padding: 10px 0;
    max-height: 150px;
    min-height: 24px;
}

.chat-input::placeholder {
    color: var(--ink-muted);
}

.chat-send-btn {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--ink);
    color: var(--bg);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    flex-shrink: 0;
}

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

.chat-send-btn:disabled {
    background: var(--ink-muted);
    cursor: not-allowed;
}

/* ==========================================
   SOURCES PANEL (right drawer)
   ========================================== */

.sources-panel {
    width: 0;
    overflow: hidden;
    border-left: 1px solid transparent;
    background: var(--bg-soft);
    display: flex;
    flex-direction: column;
    transition: width 0.28s cubic-bezier(0.16, 1, 0.3, 1), border-color 0.28s ease;
    flex-shrink: 0;
}

.sources-panel-open {
    width: 400px;
    border-left-color: var(--rule);
}

.sources-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 22px 24px;
    border-bottom: 1px solid var(--rule);
    flex-shrink: 0;
}

.sources-panel-title {
    font-size: 14px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.sources-panel-close {
    width: 30px;
    height: 30px;
    border: none;
    background: transparent;
    color: var(--ink-soft);
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
}

.sources-panel-close:hover {
    background: var(--bg);
    color: var(--ink);
}

.sources-panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 18px 20px 30px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.source-card {
    background: var(--bg);
    border: 1px solid var(--rule);
    border-radius: var(--radius-md);
    padding: 16px 18px;
    transition: all 0.2s ease;
}

.source-card:hover {
    border-color: var(--rule-strong);
}

.source-card-highlight {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.source-label {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.source-num {
    width: 22px;
    height: 22px;
    border-radius: 6px;
    background: var(--accent-soft);
    color: var(--accent);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-family: var(--mono);
    font-size: 11px;
    font-weight: 600;
    flex-shrink: 0;
}

.source-ref {
    flex: 1;
    font-size: 12px;
    color: var(--ink-soft);
    font-family: var(--mono);
}

.source-score {
    font-size: 11px;
    color: var(--ink-muted);
    font-family: var(--mono);
}

.source-text {
    font-size: 13px;
    line-height: 1.55;
    color: var(--ink-soft);
    word-wrap: break-word;
}

/* ==========================================
   LANDING (HERO + FEATURES + CTA)
   ========================================== */

#dotsCanvas {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    width: 100%;
    height: 100%;
}

.landing .header {
    background: rgba(255, 255, 255, 0.72);
}

.landing .main {
    padding-top: 0;
}

.hero {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 140px 40px 100px;
    text-align: center;
    position: relative;
}

.hero-content {
    max-width: 900px;
    width: 100%;
}

.hero-eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 6px 14px;
    background: rgba(250, 250, 250, 0.9);
    border: 1px solid var(--rule);
    border-radius: var(--radius-pill);
    font-family: var(--mono);
    font-size: 12px;
    font-weight: 500;
    color: var(--ink-soft);
    margin-bottom: 32px;
    opacity: 0;
    animation: fadeIn 0.8s ease-out 0.3s forwards;
    backdrop-filter: blur(8px);
}

.hero-eyebrow-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 0 0 rgba(0, 102, 255, 0.4);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(0, 102, 255, 0.4); }
    50% { box-shadow: 0 0 0 6px rgba(0, 102, 255, 0); }
}

.hero h1,
.hero-title {
    font-size: clamp(48px, 8vw, 96px);
    font-weight: 600;
    line-height: 1;
    letter-spacing: -0.045em;
    margin-bottom: 28px;
    opacity: 0;
    animation: fadeUp 0.9s cubic-bezier(0.16, 1, 0.3, 1) 0.5s forwards;
}

.hero-title-line {
    display: block;
}

.hero-title-accent {
    background: linear-gradient(135deg, var(--ink) 0%, #4a4a4a 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.hero-subtitle {
    font-size: clamp(18px, 2vw, 22px);
    line-height: 1.5;
    color: var(--ink-soft);
    max-width: 600px;
    margin: 0 auto 48px;
    font-weight: 400;
    letter-spacing: -0.01em;
    opacity: 0;
    animation: fadeUp 0.9s cubic-bezier(0.16, 1, 0.3, 1) 0.7s forwards;
}

.hero-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
    opacity: 0;
    animation: fadeUp 0.9s cubic-bezier(0.16, 1, 0.3, 1) 0.9s forwards;
}

.scroll-hint {
    position: absolute;
    bottom: 40px;
    left: 50%;
    transform: translateX(-50%);
    font-family: var(--mono);
    font-size: 11px;
    color: var(--ink-muted);
    letter-spacing: 0.05em;
    text-transform: uppercase;
    opacity: 0;
    animation: fadeIn 1s ease-out 1.5s forwards;
}

.scroll-hint::after {
    content: '';
    display: block;
    width: 1px;
    height: 32px;
    background: var(--ink-muted);
    margin: 12px auto 0;
    animation: scrollLine 2s ease-in-out infinite;
    transform-origin: top;
}

@keyframes scrollLine {
    0%, 100% { transform: scaleY(0.3); opacity: 0.3; }
    50% { transform: scaleY(1); opacity: 1; }
}

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

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

/* Features section */

.features-section {
    padding: 160px 40px;
    max-width: 1200px;
    margin: 0 auto;
    background: var(--bg);
}

.section-eyebrow {
    font-family: var(--mono);
    font-size: 12px;
    font-weight: 500;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 20px;
    text-align: center;
}

.section-title {
    font-size: clamp(36px, 5vw, 56px);
    font-weight: 600;
    line-height: 1.05;
    letter-spacing: -0.035em;
    text-align: center;
    margin: 0 auto 24px;
    max-width: 800px;
}

.section-subtitle {
    font-size: 19px;
    line-height: 1.5;
    color: var(--ink-soft);
    text-align: center;
    max-width: 600px;
    margin: 0 auto 80px;
    letter-spacing: -0.01em;
}

.features-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1px;
    background: var(--rule);
    border: 1px solid var(--rule);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.feature {
    background: var(--bg);
    padding: 48px 36px;
    transition: background 0.3s ease;
}

.feature:hover {
    background: var(--bg-soft);
}

.feature-num {
    font-family: var(--mono);
    font-size: 12px;
    color: var(--ink-muted);
    margin-bottom: 24px;
    letter-spacing: 0.05em;
}

.feature-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: var(--ink);
    color: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 24px;
    font-size: 20px;
}

.feature-title {
    font-size: 22px;
    font-weight: 600;
    line-height: 1.2;
    letter-spacing: -0.02em;
    margin-bottom: 12px;
}

.feature-text {
    font-size: 15px;
    line-height: 1.55;
    color: var(--ink-soft);
}

/* CTA Section */

.cta {
    padding: 120px 40px 160px;
    text-align: center;
    background: var(--bg);
}

.cta-title {
    font-size: clamp(40px, 6vw, 72px);
    font-weight: 600;
    line-height: 1;
    letter-spacing: -0.04em;
    margin-bottom: 32px;
}

.cta-title em {
    font-style: italic;
    font-weight: 400;
    color: var(--ink-soft);
}

/* ==========================================
   FOOTER
   ========================================== */

.footer {
    border-top: 1px solid var(--rule);
    padding: 28px 40px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 16px;
    background: var(--bg);
    position: relative;
    z-index: 10;
}

.footer-text,
.footer-links a {
    font-family: var(--mono);
    font-size: 12px;
    color: var(--ink-muted);
    letter-spacing: 0.02em;
}

.footer-links {
    display: flex;
    gap: 24px;
}

.footer-links a:hover {
    color: var(--ink);
}

/* ==========================================
   RESPONSIVE
   ========================================== */

@media (max-width: 900px) {
    .chat-layout {
        grid-template-columns: var(--sidebar-width, 260px) 1fr auto;
    }
    .chat-layout.sidebar-collapsed {
        --sidebar-width: 0px;
    }
    .sources-panel-open {
        position: fixed;
        top: 72px;
        right: 0;
        bottom: 0;
        width: 100%;
        z-index: 200;
    }
    .features-grid {
        grid-template-columns: 1fr;
    }
    .chat-active-bar {
        padding: 12px 20px;
    }
    .chat-layout.sidebar-collapsed .chat-active-bar {
        padding-left: 60px;
    }
}

@media (max-width: 768px) {
    .header {
        padding: 14px 20px;
    }
    .nav a:not(.nav-cta) {
        display: none;
    }
    .nav-user {
        display: none;
    }
    .container {
        padding: 40px 20px;
    }
    .container-narrow {
        padding: 50px 20px;
    }
    .auth-card {
        padding: 36px 28px;
    }
    .chat-messages {
        padding: 24px 20px;
    }
    .chat-input-area {
        padding: 16px 20px 20px;
    }
    .books-grid {
        grid-template-columns: 1fr;
    }
    .hero {
        padding: 110px 20px 80px;
    }
    .features-section {
        padding: 100px 20px;
    }
    .cta {
        padding: 80px 20px 120px;
    }
    .footer {
        padding: 24px 20px;
        flex-direction: column;
        text-align: center;
    }
}
