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

:root {
    /* Палитра редизайна (Claude Design). Новые имена — канонические;
       старые (--bg-soft/--bg-hover/--rule-strong/--warning) оставлены алиасами,
       чтобы существующие компоненты продолжали работать без переименований. */
    --bg: #1b1a1a;              /* основной фон */
    --surface: #232222;         /* карточки/панели (второстепенный фон) */
    --surface-2: #2a2928;       /* приподнятые поверхности (поповеры) */
    --hover: #333130;           /* hover-состояние */
    --bg-soft: var(--surface);  /* алиас: карточки/сайдбар */
    --bg-hover: var(--hover);   /* алиас: hover */
    --ink: #ece7de;             /* основной текст и светлые кнопки */
    --ink-soft: #b3ab9f;        /* второстепенный текст */
    --ink-muted: #7c746b;       /* подсказки, мета-данные */
    --rule: rgba(255,255,255,.08);   /* границы, разделители */
    --rule-2: rgba(255,255,255,.15); /* акцентные границы */
    --rule-strong: var(--rule-2);    /* алиас: акцентные границы */
    --accent: #a9c6a3;          /* акцент: ссылки, hover кнопок, цитаты */
    --accent-soft: rgba(169, 198, 163, 0.13); /* акцент-фон (бейджи, подсветка) */
    --accent-ink: #0f1a0e;      /* текст на акцентной заливке */
    --danger: #e0776b;          /* ошибки, кнопка «Удалить» */
    --success: #82c28d;         /* статус «Готов» */
    --warn: #d3b25e;            /* предупреждение/обработка */
    --warning: var(--warn);     /* алиас */
    --info: #8fb2c4;            /* инфо-callout */
    --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 {
    height: 26px;
    padding: 3px 5px;
    border-radius: 7px;
    background: var(--ink);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.logo-mark img {
    height: 100%;
    width: auto;
    display: block;
}

.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-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 20px 0 4px;
    color: var(--ink-muted);
    font-size: 13px;
}

.auth-divider::before,
.auth-divider::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--rule);
}

.btn-google {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    margin-top: 12px;
    background: var(--bg-soft);
    color: var(--ink);
    border: 1px solid var(--rule);
    border-radius: var(--radius-pill);
    padding: 10px 20px;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: border-color 0.15s ease, background 0.15s ease;
}

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

.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-page .header { display: none; }
.chat-page .main { padding-top: 0; height: 100vh; overflow: hidden; }

.chat-layout {
    display: grid;
    grid-template-columns: 240px 1fr 0px;
    height: 100vh;
    background: var(--bg);
    transition: grid-template-columns 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}

.chat-layout.drawer-open {
    grid-template-columns: 240px 1fr 320px;
}

/* ── Left column: conversation history ── */

.chat-history {
    background: #232222;
    border-right: 1px solid #2a2929;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

.chat-history-top {
    padding: 18px 14px 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-shrink: 0;
}

.chat-logo {
    font-size: 15px;
    font-weight: 600;
    letter-spacing: -0.02em;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--ink);
    padding: 2px 0 6px;
    text-decoration: none;
}

.chat-logo .logo-mark {
    width: auto;
    height: 22px;
    padding: 2px 4px;
    border-radius: 6px;
}

.btn-new-chat {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 14px;
    background: transparent;
    border: none;
    border-radius: var(--radius-pill);
    font-family: var(--font);
    font-size: 15px;
    font-weight: 500;
    color: var(--ink-soft);
    cursor: pointer;
    transition: all 0.15s ease;
}

.btn-new-chat:hover { color: var(--ink); }

.conv-search-wrap { position: relative; }

.conv-search {
    width: 100%;
    padding: 7px 12px;
    background: var(--bg);
    border: 1px solid #2a2929;
    border-radius: var(--radius-md);
    font-family: var(--font);
    font-size: 13px;
    color: var(--ink);
    outline: none;
    transition: border-color 0.15s ease;
}

.conv-search::placeholder { color: var(--ink-muted); }
.conv-search:focus { border-color: var(--ink-muted); }

.conv-list-wrap {
    flex: 1;
    overflow-y: auto;
    padding: 4px 8px;
}

.conv-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.conv-group-label {
    font-family: var(--mono);
    font-size: 10px;
    font-weight: 500;
    color: var(--ink-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 14px 8px 4px;
}

.conv-item {
    border-radius: var(--radius-md);
    overflow: hidden;
    position: relative;
}

.conv-item-actions {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    gap: 2px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.12s ease;
    background: linear-gradient(to left, #2a2929 60%, transparent);
    padding-left: 16px;
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
}

.conv-item:hover .conv-item-actions { opacity: 1; pointer-events: auto; }

.conv-action-btn {
    width: 24px;
    height: 24px;
    border-radius: var(--radius-sm);
    border: none;
    background: transparent;
    color: var(--ink-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.12s ease;
    flex-shrink: 0;
}

.conv-rename-btn:hover { background: rgba(255,255,255,0.08); color: var(--ink); }
.conv-delete-btn:hover { background: rgba(224,85,85,0.15); color: var(--danger); }

.conv-item-link {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: var(--radius-md);
    transition: background 0.12s ease;
    text-decoration: none;
    color: var(--ink);
}

.conv-item-link:hover { background: rgba(255,255,255,0.04); }

.conv-item-active .conv-item-link {
    background: rgba(255,255,255,0.06);
    box-shadow: inset 2px 0 0 var(--accent);
}

.conv-item-title {
    flex: 1;
    font-size: 13px;
    font-weight: 400;
    color: var(--ink-soft);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.35;
}

.conv-item-active .conv-item-title { color: var(--ink); font-weight: 500; }

.conv-item-dots {
    display: flex;
    align-items: center;
    gap: 3px;
    flex-shrink: 0;
}

.conv-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent);
    opacity: 0.7;
}

.conv-dot-more {
    font-family: var(--mono);
    font-size: 9px;
    color: var(--ink-muted);
}

.conv-empty {
    padding: 24px 8px;
    text-align: center;
    font-size: 13px;
    color: var(--ink-muted);
    line-height: 1.6;
}

/* Profile block */

.chat-profile {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border-top: 1px solid #2a2929;
    flex-shrink: 0;
}

.chat-profile-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--accent);
    color: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    font-family: var(--mono);
    flex-shrink: 0;
}

.chat-profile-name {
    flex: 1;
    font-size: 12px;
    color: var(--ink-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-profile-logout {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    color: var(--ink-muted);
    transition: all 0.15s ease;
    flex-shrink: 0;
    text-decoration: none;
}

.chat-profile-logout:hover { color: var(--ink); }

.chat-profile-login {
    padding: 6px 14px;
    border-radius: 8px;
    background: var(--accent);
    color: var(--bg);
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
    flex-shrink: 0;
    text-decoration: none;
    transition: opacity 0.15s ease;
}
.chat-profile-login:hover { opacity: 0.85; }

/* ── Sidebar toggle & collapsed state ── */

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
}

.sidebar-toggle-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 8px;
    color: var(--ink);
    cursor: pointer;
    transition: background 0.12s, color 0.12s, border-color 0.12s;
    flex-shrink: 0;
}
.sidebar-toggle-btn:hover {
    background: rgba(255,255,255,0.12);
    border-color: rgba(255,255,255,0.15);
    color: var(--ink);
}

.chat-layout.sidebar-collapsed {
    grid-template-columns: 52px 1fr 0px;
}
.chat-layout.sidebar-collapsed.drawer-open {
    grid-template-columns: 52px 1fr 320px;
}
.library-layout.sidebar-collapsed {
    grid-template-columns: 52px 1fr;
}

.sidebar-collapsed .chat-history-top {
    padding: 14px 0 10px;
    align-items: center;
}
.sidebar-collapsed .sidebar-header {
    justify-content: center;
    padding-bottom: 4px;
}
.sidebar-collapsed .chat-logo { display: none; }
.sidebar-collapsed .sidebar-label { display: none; }
.sidebar-collapsed .conv-search-wrap { display: none; }
.sidebar-collapsed .conv-list-wrap { display: none; }

.sidebar-collapsed .sidebar-toggle-btn {
    width: 34px;
    height: 34px;
}
.sidebar-collapsed .btn-new-chat,
.sidebar-collapsed .btn-library {
    width: 36px;
    height: 36px;
    padding: 0;
    justify-content: center;
    align-self: center;
    border-radius: 10px;
}
.sidebar-collapsed .btn-library {
    background: var(--bg);
    border: 1px solid #2a2929;
}
.sidebar-collapsed .btn-new-chat svg,
.sidebar-collapsed .btn-library svg {
    width: 16px;
    height: 16px;
}
.sidebar-collapsed .chat-profile {
    margin-top: auto;
    justify-content: center;
    padding: 12px 0;
}
.sidebar-collapsed .chat-profile-name { display: none; }
.sidebar-collapsed .chat-profile-logout { display: none; }
.sidebar-collapsed .chat-profile-login { display: none; }

/* ── Center column ── */

/* Sources pill button */

.sources-pill-btn {
    position: absolute;
    top: 14px;
    right: 16px;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    background: var(--bg-soft);
    border: 1px solid #2a2929;
    border-radius: var(--radius-pill);
    font-family: var(--font);
    font-size: 15px;
    font-weight: 500;
    color: var(--ink-soft);
    cursor: pointer;
    transition: all 0.15s ease;
}

.sources-pill-btn:hover { border-color: var(--ink-muted); color: var(--ink); }
.sources-pill-btn-empty { color: var(--ink-muted); }

.sources-pill-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    background: var(--accent);
    color: var(--bg);
    border-radius: var(--radius-pill);
    font-size: 11px;
    font-weight: 600;
    font-family: var(--mono);
}

/* Mobile history button */

.chat-mobile-history-btn {
    display: none;
    position: absolute;
    top: 12px;
    left: 14px;
    z-index: 10;
    width: 34px;
    height: 34px;
    border: 1px solid #2a2929;
    background: var(--bg-soft);
    border-radius: var(--radius-md);
    color: var(--ink-soft);
    cursor: pointer;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
}

.chat-mobile-history-btn:hover { color: var(--ink); }

/* ── Chat area ── */

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

/* Messages */

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 56px 24px 16px;
    display: flex;
    flex-direction: column;
}

.chat-messages-inner {
    width: 100%;
    max-width: 720px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 18px;
    flex: 1;
}

/* Welcome screen */

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

.chat-welcome-mark {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    background: var(--ink);
    color: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--mono);
    font-size: 22px;
    font-weight: 500;
    margin: 0 auto 20px;
}

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

.chat-welcome p {
    font-size: 14px;
    color: var(--ink-soft);
    margin-bottom: 24px;
    line-height: 1.55;
}

.chat-suggestions-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    text-align: left;
}

/* Drag & drop overlay */

.drag-drop-overlay {
    position: absolute;
    inset: 0;
    z-index: 20;
    background: rgba(27, 26, 26, 0.88);
    display: none;
    align-items: center;
    justify-content: center;
    border: 2px dashed var(--accent);
    pointer-events: none;
}

.drag-drop-overlay.drag-active { display: flex; }

.drag-drop-content { text-align: center; }
.drag-drop-icon { font-size: 40px; margin-bottom: 12px; }

.drag-drop-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--ink);
    letter-spacing: -0.02em;
    margin-bottom: 6px;
}

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

/* Input area */

.chat-input-area {
    border-top: 1px solid #2a2929;
    padding: 14px 24px 18px;
    background: var(--bg);
    flex-shrink: 0;
}

.chat-input-outer {
    max-width: 720px;
    margin: 0 auto;
}

/* ── Right column: drawer ── */

.chat-drawer {
    border-left: 1px solid transparent;
    background: #232222;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
    transition: border-color 0.28s ease;
}

.chat-layout.drawer-open .chat-drawer {
    border-left-color: #2a2929;
}

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

.drawer-title {
    font-family: var(--mono);
    font-size: 10px;
    font-weight: 500;
    color: var(--ink-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

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

.drawer-btn-add {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 1px solid rgba(160, 184, 160, 0.3);
    background: rgba(160, 184, 160, 0.08);
    color: var(--accent);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
}

.drawer-btn-add:hover {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--bg);
}

.drawer-btn-close {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 1px solid rgba(220, 38, 38, 0.25);
    background: rgba(220, 38, 38, 0.06);
    color: rgba(220, 38, 38, 0.7);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    line-height: 1;
    transition: all 0.15s ease;
}

.drawer-btn-close:hover {
    background: rgba(220, 38, 38, 0.14);
    color: rgb(220, 38, 38);
    border-color: rgba(220, 38, 38, 0.5);
}

.drawer-tabs {
    display: flex;
    align-items: center;
    border-bottom: 1px solid #2a2929;
    padding: 0 16px;
    flex-shrink: 0;
    gap: 6px;
}

.drawer-tab {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 9px 4px;
    margin-right: 16px;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    font-family: var(--font);
    font-size: 13px;
    font-weight: 500;
    color: var(--ink-muted);
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.drawer-tab:hover { color: var(--ink-soft); }
.drawer-tab-active { color: var(--ink); border-bottom-color: var(--accent); }

.drawer-tab-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    background: var(--bg);
    color: var(--ink-muted);
    border-radius: var(--radius-pill);
    font-size: 10px;
    font-family: var(--mono);
    font-weight: 500;
}

.drawer-tab-active .drawer-tab-count {
    background: var(--accent-soft);
    color: var(--accent);
}

.drawer-body {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.drawer-panel {
    flex: 1;
    overflow-y: auto;
    padding: 10px 12px 20px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.drawer-section {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.drawer-section-hd {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 6px 6px;
    font-size: 10px;
    font-family: var(--mono);
    color: var(--ink-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.drawer-section-link {
    background: none;
    border: none;
    font-family: var(--mono);
    font-size: 10px;
    color: var(--ink-muted);
    cursor: pointer;
    transition: color 0.15s ease;
    text-transform: none;
    letter-spacing: 0;
}

.drawer-section-link:hover { color: var(--danger); }

/* Sources panel body */

.sources-panel-body {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Mobile overlay backdrops */

.chat-history-backdrop,
.chat-drawer-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 299;
}

.chat-history-backdrop.open,
.chat-drawer-backdrop.open { display: block; }

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

.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;
}

.suggestion-btn {
    padding: 11px 14px;
    background: #232222;
    border: 1px solid #2a2929;
    border-radius: var(--radius-md);
    font-family: var(--font);
    font-size: 13px;
    color: var(--ink-soft);
    cursor: pointer;
    transition: all 0.15s ease;
    text-align: left;
    line-height: 1.4;
}

.suggestion-btn:hover {
    border-color: var(--ink-muted);
    color: var(--ink);
}

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

.chat-message {
    display: flex;
    width: 100%;
}

.chat-message-user { justify-content: flex-end; }
.chat-message-assistant, .chat-message-error, .chat-message-warning { justify-content: flex-start; }

.chat-message-body {
    max-width: 80%;
    min-width: 0;
}

.chat-bubble {
    background: var(--bg-soft);
    border: 1px solid var(--rule);
    border-radius: 18px;
    border-bottom-left-radius: 4px;
    padding: 14px 18px;
    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);
    border-radius: 18px;
    border-bottom-left-radius: 4px;
}

.chat-message-error .chat-bubble {
    background: rgba(220, 38, 38, 0.06);
    border-color: rgba(220, 38, 38, 0.2);
    color: var(--danger);
    border-radius: 18px;
    border-bottom-left-radius: 4px;
}

.chat-message-warning .chat-bubble {
    background: rgba(234, 179, 8, 0.06);
    border-color: rgba(234, 179, 8, 0.25);
    color: #c9a000;
    border-radius: 18px;
    border-bottom-left-radius: 4px;
}

.warn-hl {
    color: var(--ink);
    font-weight: 600;
    font-style: normal;
}

.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);
}

/* ===== Тултип для сносок ===== */

.cite-tooltip {
    display: none;
    position: fixed;
    z-index: 9999;
    max-width: 320px;
    background: var(--surface-2, #1c1c1c);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 10px;
    padding: 12px 14px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
    pointer-events: none;
    opacity: 0;
    transform: translateY(4px);
    transition: opacity 0.15s ease, transform 0.15s ease;
}

.cite-tooltip.cite-tooltip-visible {
    opacity: 1;
    transform: translateY(0);
}

.cite-tooltip-header {
    font-size: 11px;
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 7px;
    font-family: var(--mono);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cite-tooltip-text {
    font-size: 12px;
    color: var(--ink-soft);
    line-height: 1.55;
    display: -webkit-box;
    -webkit-line-clamp: 7;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.cite-tooltip-hint {
    margin-top: 8px;
    padding-top: 7px;
    border-top: 1px solid rgba(255,255,255,0.08);
    font-size: 11px;
    color: var(--ink-muted);
    font-style: italic;
    text-align: center;
}

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

.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: 15px;
    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);
}

/* ===== Accordion sources (mobile) ===== */

.sources-accordion {
    display: none;
    flex-direction: column;
    gap: 8px;
    margin-top: 10px;
}

.sources-accordion.sources-accordion-open {
    display: flex;
}

/* ===== 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; }
}

.chat-input-form { width: 100%; }

.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;
}


.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-ref-link {
    text-decoration: none;
    color: var(--accent);
    cursor: pointer;
}
.source-ref-link:hover {
    text-decoration: underline;
}

.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) {
    .features-grid { grid-template-columns: 1fr; }
}

@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; }
    .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; }

    /* ── Chat layout mobile ── */
    .chat-layout {
        grid-template-columns: 1fr !important;
    }

    .chat-history {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        width: 280px;
        transform: translateX(-100%);
        transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1);
        z-index: 300;
        box-shadow: 4px 0 24px rgba(0,0,0,0.2);
    }

    .chat-history.mobile-open { transform: translateX(0); }

    .chat-drawer {
        position: fixed;
        right: 0;
        top: 0;
        bottom: 0;
        width: 88%;
        max-width: 340px;
        transform: translateX(100%);
        transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1);
        z-index: 300;
        border-left: none;
        box-shadow: -4px 0 24px rgba(0,0,0,0.2);
    }

    .chat-drawer.mobile-open { transform: translateX(0); }

    .chat-mobile-history-btn { display: flex; }

    .sources-pill-btn { top: 10px; right: 12px; }

    .chat-messages { padding: 50px 14px 12px; }

    .chat-message-body { max-width: 88%; }
    .chat-message-user .chat-message-body { max-width: 80%; }

    .chat-input-area {
        padding: 10px 12px calc(14px + env(safe-area-inset-bottom));
    }

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

    /* ── New chat layout mobile ── */
    .new-chat-layout {
        grid-template-columns: 1fr !important;
    }
    .new-chat-mark { width: 44px; height: 44px; font-size: 26px; }
    .new-chat-heading { font-size: 22px; }
    .new-chat-form-wrap { padding: 0 4px; }
    .new-chat-textarea { font-size: 15px; }

    /* ── Library layout mobile ── */
    .library-layout {
        grid-template-columns: 1fr !important;
    }
    .library-layout .chat-history {
        position: fixed;
        left: 0; top: 0; bottom: 0;
        width: 280px;
        transform: translateX(-100%);
        transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1);
        z-index: 300;
        box-shadow: 4px 0 24px rgba(0,0,0,0.2);
    }
    .library-layout .chat-history.mobile-open { transform: translateX(0); }

    /* На мобильном свёрнутый сайдбар не имеет смысла — показываем как обычный off-canvas */
    .library-layout.sidebar-collapsed,
    .chat-layout.sidebar-collapsed,
    .new-chat-layout.sidebar-collapsed {
        grid-template-columns: 1fr !important;
    }
    .sidebar-collapsed .chat-logo,
    .sidebar-collapsed .sidebar-label,
    .sidebar-collapsed .conv-search-wrap,
    .sidebar-collapsed .conv-list-wrap,
    .sidebar-collapsed .chat-profile-name,
    .sidebar-collapsed .chat-profile-logout,
    .sidebar-collapsed .chat-profile-login {
        display: revert;
    }
    .sidebar-collapsed .btn-new-chat,
    .sidebar-collapsed .btn-library {
        width: auto;
        height: auto;
        padding: 8px 14px;
        justify-content: flex-start;
        align-self: stretch;
        border-radius: var(--radius-pill);
    }
    .sidebar-collapsed .sidebar-header {
        justify-content: space-between;
        flex-direction: row;
    }
    .sidebar-collapsed .chat-profile { margin-top: 0; }

    /* На мобильном кнопка сворачивания не нужна (есть бургер) */
    .sidebar-toggle-btn { display: none; }

    /* Library page header & content on mobile */
    .library-header {
        padding: 14px 16px 14px 56px; /* место под бургер слева */
        flex-wrap: wrap;
        gap: 10px;
    }
    .library-title { font-size: 17px; }
    .library-title svg { width: 18px; height: 18px; }
    .library-header-actions { gap: 8px; }
    .library-upload-btn { padding: 6px 12px; font-size: 12px; }
    .lib-delete-selected-btn { padding: 6px 10px; font-size: 11px; }
    .library-search-wrap { padding: 12px 16px; }
    .library-books { padding: 0 16px; }

    /* Library row on mobile */
    .library-row { gap: 10px; padding: 12px 0; }
    .library-row-title { font-size: 13px; }
    .library-row-meta { font-size: 11px; }
    .lib-badge { font-size: 10px; padding: 2px 8px; }
    .library-row-actions { opacity: 1; } /* всегда видно на тач-устройствах */
    .conv-item-actions { opacity: 1; }

    /* Cite tooltip mobile */
    .cite-tooltip {
        max-width: calc(100vw - 32px);
    }

    /* Touch-friendly conv items */
    .conv-item-link { min-height: 40px; }

    /* Sources panel button mobile */
    .sources-btn { font-size: 12px; padding: 7px 12px; }
}

/* ── Очень узкие экраны (≤ 480px) ── */
@media (max-width: 480px) {
    .library-header {
        padding: 12px 12px 12px 52px;
    }
    .library-upload-btn,
    .lib-delete-selected-btn {
        width: 36px;
        height: 36px;
        padding: 0;
        justify-content: center;
    }
    .library-upload-btn .btn-text-label,
    .lib-delete-selected-btn .btn-text-label { display: none; }

    .library-search-wrap { padding: 10px 12px; }
    .library-books { padding: 0 12px; }

    .new-chat-heading { font-size: 18px; }
    .chat-message-body { max-width: 92%; }
}

/* ==========================================
   МОДАЛЬНОЕ ОКНО ПЕРЕИМЕНОВАНИЯ
   ========================================== */

.rename-modal {
    position: fixed;
    inset: 0;
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(10, 10, 10, 0.6);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.18s ease;
}

.rename-modal.open { opacity: 1; pointer-events: auto; }

.rename-modal-inner {
    width: 100%;
    max-width: 380px;
    margin: 0 20px;
    background: #222121;
    border: 1px solid #333;
    border-radius: var(--radius-md);
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    transform: translateY(8px);
    transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.rename-modal.open .rename-modal-inner { transform: translateY(0); }

.rename-modal-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--ink);
}

.rename-modal-input {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg);
    border: 1px solid #333;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 14px;
    color: var(--ink);
    outline: none;
    transition: border-color 0.15s ease;
}

.rename-modal-input:focus { border-color: var(--ink-muted); }

.rename-modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.rename-modal-cancel {
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    border: 1px solid #333;
    background: transparent;
    font-family: var(--font);
    font-size: 13px;
    color: var(--ink-muted);
    cursor: pointer;
    transition: all 0.15s ease;
}

.rename-modal-cancel:hover { color: var(--ink); border-color: var(--ink-muted); }

.rename-modal-save {
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    border: none;
    background: var(--ink);
    font-family: var(--font);
    font-size: 13px;
    font-weight: 500;
    color: var(--bg);
    cursor: pointer;
    transition: opacity 0.15s ease;
}

.rename-modal-save:hover { opacity: 0.85; }

/* ==========================================
   СТРАНИЦА НОВОГО ЧАТА (/new)
   ========================================== */

.new-chat-layout {
    display: grid;
    grid-template-columns: 240px 1fr 0px;
    height: 100vh;
    background: var(--bg);
    transition: grid-template-columns 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}

.new-chat-layout.drawer-open {
    grid-template-columns: 240px 1fr 320px;
}
.new-chat-layout.sidebar-collapsed {
    grid-template-columns: 52px 1fr 0px;
}
.new-chat-layout.sidebar-collapsed.drawer-open {
    grid-template-columns: 52px 1fr 320px;
}

.new-chat-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 24px;
    overflow-y: auto;
    position: relative;
}

/* Центральный блок по умолчанию */
.new-chat-center {
    width: 100%;
    max-width: 640px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
}

/* Панель сообщений — скрыта по умолчанию */
.new-chat-messages-panel {
    display: none;
    flex: 1;
    overflow-y: auto;
}

/* Нижняя форма — скрыта по умолчанию */
.new-chat-bottom-form {
    display: none;
    flex-shrink: 0;
}

/* ЧАТ-РЕЖИМ: идентичен .chat-area */
.new-chat-area.new-chat-active {
    padding: 0;
    overflow: hidden;
    justify-content: flex-start;
    align-items: stretch;
    min-width: 0;
}

.new-chat-area.new-chat-active .new-chat-center {
    display: none;
}

.new-chat-area.new-chat-active .new-chat-messages-panel {
    display: flex;
}

.new-chat-area.new-chat-active .new-chat-bottom-form {
    display: block;
}

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

.new-chat-heading {
    font-size: 28px;
    font-weight: 600;
    letter-spacing: -0.02em;
    color: var(--ink);
    text-align: center;
}

.new-chat-form-wrap {
    position: relative;
    width: 100%;
}

.new-chat-textarea {
    width: 100%;
    min-height: 60px;
    max-height: 200px;
    padding: 18px 56px 18px 20px;
    background: #222121;
    border: 1px solid #333;
    border-radius: var(--radius-md);
    font-family: var(--font);
    font-size: 15px;
    color: var(--ink);
    outline: none;
    resize: none;
    line-height: 1.6;
    transition: border-color 0.15s ease;
}

.new-chat-textarea::placeholder { color: var(--ink-muted); }
.new-chat-textarea:focus { border-color: var(--ink-muted); }

.new-chat-send {
    position: absolute;
    bottom: 12px;
    right: 12px;
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    border: none;
    background: var(--ink);
    color: var(--bg);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.15s ease;
}

.new-chat-send:hover { opacity: 0.85; }
.new-chat-send:disabled { opacity: 0.35; cursor: not-allowed; }


/* ── Кнопка «Моя библиотека» в сайдбаре ── */
.btn-library {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 14px;
    background: transparent;
    border: none;
    border-radius: var(--radius-pill);
    font-family: var(--font);
    font-size: 15px;
    font-weight: 500;
    color: var(--ink-soft);
    cursor: pointer;
    text-decoration: none;
    transition: color 0.15s ease;
}
.btn-library:hover { color: var(--ink); }
.btn-library-active { color: var(--ink); }

/* ── Страница библиотеки ── */
.library-layout {
    display: grid;
    grid-template-columns: 240px 1fr;
    height: 100vh;
    background: var(--bg);
}

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

.library-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 28px 40px 20px;
    border-bottom: 1px solid #2a2929;
    flex-shrink: 0;
}

.library-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 20px;
    font-weight: 600;
    color: var(--ink);
}

.library-header-actions {
    display: flex;
    align-items: center;
    gap: 14px;
}

.library-book-count {
    font-size: 13px;
    color: var(--ink-muted);
}

.library-upload-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    background: var(--ink);
    color: var(--bg);
    border: none;
    border-radius: var(--radius-pill);
    font-family: var(--font);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: opacity 0.15s;
}
.library-upload-btn:hover { opacity: 0.82; }

.library-books {
    flex: 1;
    overflow-y: auto;
    padding: 0 40px;
}

.library-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 80px 0;
    color: var(--ink-muted);
    font-size: 14px;
    text-align: center;
}

.library-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.library-row {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 8px;
    border-bottom: 1px solid #1e1e1e;
    border-radius: 6px;
    transition: background 0.1s;
}
.library-row:last-child { border-bottom: none; }
.library-row[data-status="ready"] { cursor: pointer; }
.library-row[data-status="ready"]:hover { background: rgba(255,255,255,0.03); }

.library-row-icon {
    color: var(--ink-muted);
    flex-shrink: 0;
}

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

.library-row-title {
    font-size: 14px;
    font-weight: 500;
    color: var(--ink);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.library-rename-input {
    font-size: 14px;
    font-weight: 500;
    font-family: var(--font);
    color: var(--ink);
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--ink-muted);
    outline: none;
    width: 100%;
    padding: 1px 0;
}

.library-row-meta {
    font-size: 12px;
    color: var(--ink-muted);
}

.library-row-status { flex-shrink: 0; }

.lib-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 500;
}

.lib-badge-ready {
    background: rgba(100, 180, 100, 0.1);
    color: #6ab56a;
}
.lib-badge-processing {
    background: rgba(200, 168, 64, 0.1);
    color: var(--warning);
}
.lib-badge-error {
    background: rgba(220, 80, 80, 0.1);
    color: var(--danger);
}

.library-row-actions {
    display: flex;
    gap: 2px;
    opacity: 0;
    transition: opacity 0.15s;
    flex-shrink: 0;
}
.library-row:hover .library-row-actions { opacity: 1; }
.library-row-uploading .library-row-actions { display: none; }

.lib-action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: transparent;
    border: none;
    border-radius: 6px;
    color: var(--ink-muted);
    cursor: pointer;
    transition: background 0.12s, color 0.12s;
}
.lib-action-btn:hover { background: rgba(255,255,255,0.06); color: var(--ink); }
.lib-delete-btn:hover { color: var(--danger); }
.lib-read-btn { color: var(--accent); }
.lib-read-btn:hover { background: var(--accent-soft); }

.library-search-wrap {
    padding: 16px 40px;
}
.library-search {
    width: 100%;
    background: var(--surface-3, #2a2a2a);
    border: 1.5px solid rgba(255,255,255,0.15);
    border-radius: 8px;
    color: var(--ink);
    font-size: 13px;
    padding: 9px 14px;
    outline: none;
    box-sizing: border-box;
}
.library-search::placeholder { color: var(--ink-muted); }
.library-search:focus { border-color: var(--accent); background: var(--surface-3, #2a2a2a); }

@keyframes lib-spin {
    to { transform: rotate(360deg); }
}
.lib-spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255,255,255,0.15);
    border-top-color: var(--accent, #7c6af7);
    border-radius: 50%;
    animation: lib-spin 0.75s linear infinite;
    flex-shrink: 0;
}
.library-row-status {
    display: flex;
    align-items: center;
    gap: 8px;
}

.lib-delete-selected-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(220,60,60,0.12);
    border: 1px solid rgba(220,60,60,0.3);
    border-radius: 8px;
    color: var(--danger, #e06060);
    font-size: 12px;
    font-weight: 500;
    padding: 6px 12px;
    cursor: pointer;
    transition: background 0.12s;
}
.lib-delete-selected-btn:hover { background: rgba(220,60,60,0.22); }

.lib-checkbox-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 24px;
    cursor: pointer;
}
.lib-checkbox { display: none; }
.lib-checkbox-box {
    width: 16px;
    height: 16px;
    border: 1.5px solid rgba(255,255,255,0.35);
    border-radius: 4px;
    background: rgba(255,255,255,0.05);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color 0.12s, background 0.12s;
}
.lib-checkbox:checked + .lib-checkbox-box {
    background: var(--accent);
    border-color: var(--accent);
}
.lib-checkbox:checked + .lib-checkbox-box::after {
    content: '';
    display: block;
    width: 9px;
    height: 6px;
    border-left: 2px solid #fff;
    border-bottom: 2px solid #fff;
    transform: rotate(-45deg) translateY(-1px);
}

.library-row-selected { background: rgba(100,160,100,0.06); }

.btn-new-chat-active { color: var(--ink); }

/* ── Поиск в drawer ── */
.drawer-book-search-wrap {
    padding: 8px 12px 4px;
}
.drawer-book-search {
    width: 100%;
    box-sizing: border-box;
    background: var(--bg-soft);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px 10px;
    font-size: 12px;
    color: var(--text);
    outline: none;
    transition: border-color .15s;
}
.drawer-book-search:focus { border-color: var(--accent); }
.drawer-book-search::placeholder { color: var(--text-muted); }

/* ── Кнопка rename на книге ── */
.book-list-item { position: relative; }
.book-item-rename-btn {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    display: none;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border: none;
    background: var(--bg-soft);
    border-radius: 5px;
    color: var(--text-muted);
    cursor: pointer;
    transition: color .15s, background .15s;
    flex-shrink: 0;
}
.book-list-item:hover .book-item-rename-btn { display: flex; }
.book-item-rename-btn:hover { color: var(--text); background: var(--surface-hover); }

/* ── Inline-редактирование названия книги ── */
.book-rename-input {
    background: var(--bg-soft);
    border: 1px solid var(--accent);
    border-radius: 4px;
    padding: 1px 5px;
    font-size: 13px;
    color: var(--text);
    outline: none;
    width: 100%;
    min-width: 0;
}

/* ── Mode toggle bar ── */
.chat-mode-bar {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 10px 2px;
}

.mode-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 20px;
    border: 1px solid transparent;
    background: none;
    color: var(--text-muted);
    font-size: 12px;
    cursor: pointer;
    transition: color .15s, background .15s, border-color .15s;
    white-space: nowrap;
}
.mode-btn:hover {
    color: var(--text);
    background: var(--surface-hover);
}
.mode-btn-active {
    color: var(--accent);
    background: rgba(160, 184, 160, 0.10);
    border-color: rgba(160, 184, 160, 0.30);
}

.mode-help {
    position: relative;
    display: flex;
    align-items: center;
    margin-right: 2px;
}

.mode-help-btn {
    width: 17px;
    height: 17px;
    border-radius: 50%;
    border: 1px solid rgba(255,255,255,0.18);
    background: none;
    color: var(--ink-muted);
    font-size: 10px;
    font-weight: 700;
    font-family: var(--mono);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: border-color 0.12s, color 0.12s;
    line-height: 1;
}
.mode-help-btn:hover {
    border-color: var(--ink-muted);
    color: var(--ink);
}

.mode-help-tooltip {
    display: none;
    position: absolute;
    bottom: calc(100% + 10px);
    left: 0;
    width: 270px;
    background: var(--surface-2, #1c1c1c);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 10px;
    padding: 12px 14px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
    z-index: 200;
    pointer-events: none;
}
.mode-help:hover .mode-help-tooltip { display: flex; flex-direction: column; gap: 8px; }

.mode-help-row {
    font-size: 12px;
    color: var(--ink-soft);
    line-height: 1.5;
}
.mode-help-row strong {
    color: var(--ink);
    font-weight: 600;
}

/* ── Mode label under assistant bubble ── */
.chat-mode-label {
    display: inline-block;
    margin-left: 8px;
    padding: 1px 7px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 500;
    vertical-align: middle;
}
.chat-mode-label-rag {
    background: rgba(160, 184, 160, 0.12);
    color: var(--accent);
    border: 1px solid rgba(160, 184, 160, 0.25);
}
.chat-mode-label-free {
    background: rgba(120, 160, 220, 0.10);
    color: #7ab4d8;
    border: 1px solid rgba(120, 160, 220, 0.22);
}

/* ==========================================
   ЧИТАЛКА
   ========================================== */

/* === PDF.js text layer === */
.reader-pdf-page-wrap {
    position: relative;
    margin: 0 auto 16px;
    background: #fff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
    overflow: hidden;
}

.reader-pdf-canvas {
    display: block;
    user-select: none;
}

.reader-pdf-page-wrap .textLayer {
    position: absolute;
    inset: 0;
    overflow: hidden;
    opacity: 0.25;
    line-height: 1;
}

.reader-pdf-page-wrap .textLayer span,
.reader-pdf-page-wrap .textLayer br {
    color: transparent;
    position: absolute;
    white-space: pre;
    cursor: text;
    transform-origin: 0% 0%;
}

.reader-pdf-page-wrap .textLayer ::selection {
    background: rgba(0, 100, 255, 0.3);
}

.reader-pdf-placeholder {
    width: 100%;
    background: linear-gradient(180deg, #f5f5f5 0%, #ebebeb 100%);
    border: 1px solid #e0e0e0;
}

/* Подсветка фрагментов из ссылок LLM */
.reader-highlight,
.reader-pdf-page-wrap .textLayer .highlight {
    background: rgba(255, 235, 59, 0.5);
    padding: 0 2px;
    border-radius: 2px;
    box-shadow: 0 0 0 2px rgba(255, 193, 7, 0.3);
    animation: highlight-pulse 1.4s ease-in-out 2;
}

@keyframes highlight-pulse {
    0%, 100% { background: rgba(255, 235, 59, 0.5); }
    50%       { background: rgba(255, 235, 59, 0.85); }
}

/* ── Iframe-режим ────────────────────────────────────────────────── */
.reader-content-iframe {
    height: 100%;
    background: #fff;
}

.reader-iframe {
    width: 100%;
    height: 100%;
    border: 0;
    display: block;
}

/* ── HTML-режим ──────────────────────────────────────────────────── */
.reader-content.reader-content-html {
    max-width: none;
    padding: 32px 24px 80px;
    color: #000;
}

.reader-html-doc,
.reader-html-doc *:not(a) {
    color: #000 !important;
}
.reader-html-doc {
    max-width: 900px;
    margin: 0 auto;
    padding: 56px 72px;
    background: #fff;
    font-family: Georgia, 'Times New Roman', serif;
    line-height: 1.7;
    hyphens: none;
    -webkit-hyphens: none;
    word-break: normal;
    overflow-wrap: break-word;
    border-radius: 4px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.25);
}

.reader-html-doc h1,
.reader-html-doc h2,
.reader-html-doc h3,
.reader-html-doc h4,
.reader-html-doc h5,
.reader-html-doc h6 {
    margin: 1.4em 0 0.6em;
    line-height: 1.3;
    font-weight: 700;
}
.reader-html-doc h1 { font-size: 1.9em; }
.reader-html-doc h2 { font-size: 1.6em; }
.reader-html-doc h3 { font-size: 1.35em; }
.reader-html-doc h4 { font-size: 1.2em; }
.reader-html-doc h5 { font-size: 1.1em; }
.reader-html-doc h6 { font-size: 1.05em; }

.reader-html-doc p {
    margin: 0 0 1em;
}

.reader-html-doc img {
    max-width: 100%;
    height: auto;
    margin: 0.8em 0;
}

.reader-html-doc table {
    border-collapse: collapse;
    margin: 1em 0;
    width: 100%;
}

.reader-html-doc th,
.reader-html-doc td {
    border: 1px solid #ddd;
    padding: 6px 10px;
}

.reader-html-doc blockquote {
    border-left: 3px solid #ccc;
    margin: 1em 0;
    padding: 0 1em;
    color: #555;
}

.reader-html-doc .verse {
    text-align: center;
    font-style: italic;
    margin: 0.3em 0;
}

.reader-page-anchor {
    display: block;
    height: 0;
    overflow: hidden;
}

/* ── EPUB-режим ──────────────────────────────────────────────────── */
.reader-content-epub {
    background: #fafafa;
    padding: 32px 0;
}

.reader-content-epub .epub-container {
    background: #fff;
    max-width: 760px;
    margin: 0 auto;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    border-radius: 4px;
}

.reader-page { overflow: hidden; }
/* В reader-режиме base-хедер скрыт, но .main всё равно держит padding-top: 72px —
   убираем его, чтобы reader-layout начинался от верха viewport. */
body.reader-page .main { padding-top: 0; }

.reader-layout {
    display: flex;
    height: 100vh;
    background: var(--bg);
    color: var(--ink);
}

/* ── Левая панель: оглавление ── */
.reader-toc {
    width: 260px;
    flex-shrink: 0;
    background: var(--bg-soft);
    border-right: 1px solid var(--rule);
    display: flex;
    flex-direction: column;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    position: absolute;
    /* топбар 48px + прогресс 2px = 50 */
    top: 50px; left: 0; bottom: 0;
    z-index: 20;
}
.reader-layout.reader-toc-visible .reader-toc { transform: translateX(0); }
.toc-open { transform: translateX(0) !important; }

.reader-toc-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--rule);
    flex-shrink: 0;
}
.reader-toc-title { font-size: 13px; font-weight: 600; color: var(--ink); }
.reader-toc-close {
    background: none; border: none; color: var(--ink-muted);
    cursor: pointer; padding: 4px; border-radius: 4px;
    display: flex; align-items: center; justify-content: center;
}
.reader-toc-close:hover { color: var(--ink); background: rgba(255,255,255,0.06); }

.reader-toc-list { flex: 1; overflow-y: auto; padding: 8px 0; }
.reader-toc-empty { font-size: 12px; color: var(--ink-muted); padding: 12px 16px; }

.reader-toc-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 7px 16px;
    background: none; border: none;
    color: var(--ink-soft); font-size: 12px;
    text-align: left; cursor: pointer;
    transition: background 0.12s, color 0.12s;
    gap: 8px;
}
.reader-toc-item:hover { background: rgba(255,255,255,0.05); color: var(--ink); }
.reader-toc-item-active { color: var(--accent); background: var(--accent-soft); }
.reader-toc-item-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reader-toc-item-page { color: var(--ink-muted); font-size: 11px; flex-shrink: 0; }

/* ── Основная область ── */
.reader-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
}

/* ── Топбар ── */
.reader-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    height: 48px;
    border-bottom: 1px solid var(--rule);
    flex-shrink: 0;
    gap: 12px;
}
.reader-topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.reader-topbar-right { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

.reader-back-btn {
    display: flex; align-items: center; justify-content: center;
    width: 30px; height: 30px;
    color: var(--ink-muted); border-radius: 6px;
    text-decoration: none; flex-shrink: 0;
    transition: background 0.12s, color 0.12s;
}
.reader-back-btn:hover { background: rgba(255,255,255,0.06); color: var(--ink); }

/* Когда читалка работает в iframe (встроена в чат) — скрываем «назад в библиотеку» */
html.reader-embedded .reader-back-btn { display: none; }

.reader-toc-toggle {
    display: flex; align-items: center; justify-content: center;
    width: 30px; height: 30px;
    background: none; border: none;
    color: var(--ink-muted); border-radius: 6px; cursor: pointer;
    transition: background 0.12s, color 0.12s; flex-shrink: 0;
}
.reader-toc-toggle:hover { background: rgba(255,255,255,0.06); color: var(--ink); }

.reader-page-info {
    display: flex; align-items: center; gap: 4px;
    font-size: 12px; color: var(--ink-muted); flex-shrink: 0;
}
.reader-page-input {
    width: 44px; text-align: center;
    background: var(--bg-soft); border: 1px solid var(--rule);
    border-radius: 4px; color: var(--ink); font-size: 12px;
    padding: 2px 4px;
    -moz-appearance: textfield;
}
.reader-page-input::-webkit-inner-spin-button,
.reader-page-input::-webkit-outer-spin-button { -webkit-appearance: none; }
.reader-page-total { color: var(--ink-muted); font-size: 12px; }

.reader-book-title {
    font-size: 13px; color: var(--ink-soft);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.reader-font-btn {
    background: none; border: 1px solid var(--rule);
    border-radius: 6px; color: var(--ink-muted);
    font-size: 12px; font-weight: 600;
    padding: 4px 8px; cursor: pointer;
    transition: background 0.12s, color 0.12s;
}
.reader-font-btn:hover { background: rgba(255,255,255,0.06); color: var(--ink); }

/* ── Прогресс-бар ── */
.reader-progress-bar {
    height: 2px; background: var(--rule); flex-shrink: 0;
}
.reader-progress-fill {
    height: 100%; background: var(--accent);
    transition: width 0.2s ease; width: 0%;
}

/* ── Контент ── */
.reader-content-wrap {
    flex: 1; overflow-y: auto; overflow-x: hidden;
}
.reader-content {
    max-width: 740px;
    margin: 0 auto;
    padding: 32px 24px 80px;
    font-size: 16px;
    line-height: 1.65;
    color: var(--ink);
}

.reader-loading {
    display: flex; align-items: center; gap: 10px;
    justify-content: center;
    padding: 60px 24px;
    color: var(--ink-muted); font-size: 14px;
}
.reader-error {
    max-width: 480px; margin: 60px auto;
    padding: 24px; border-radius: 10px;
    background: rgba(224,85,85,0.08);
    border: 1px solid rgba(224,85,85,0.2);
    color: var(--ink-soft); font-size: 14px;
    text-align: center; line-height: 1.6;
}

.reader-page-block { margin-bottom: 32px; }
.reader-page-label {
    font-size: 11px; color: var(--ink-muted);
    text-transform: uppercase; letter-spacing: 0.06em;
    margin-bottom: 12px; padding-bottom: 8px;
    border-bottom: 1px solid var(--rule);
}
.reader-para { margin: 0 0 1em; }
.reader-heading {
    font-size: 1.1em; font-weight: 600;
    margin: 1.4em 0 0.6em; color: var(--ink);
}

.reader-warning-banner {
    display: flex; align-items: flex-start; gap: 12px;
    padding: 14px 16px; margin-bottom: 28px;
    background: rgba(200,168,64,0.08);
    border: 1px solid rgba(200,168,64,0.25);
    border-radius: 8px; font-size: 13px;
    color: var(--ink-soft); line-height: 1.5;
}
.reader-warning-icon { font-size: 16px; flex-shrink: 0; margin-top: 1px; }
.reader-warning-text { flex: 1; }
.reader-warning-btn {
    flex-shrink: 0; padding: 5px 12px;
    background: rgba(200,168,64,0.12);
    border: 1px solid rgba(200,168,64,0.3);
    border-radius: 6px; color: var(--warning);
    font-size: 12px; text-decoration: none;
    white-space: nowrap;
    transition: background 0.12s;
}
.reader-warning-btn:hover { background: rgba(200,168,64,0.2); }

/* ==========================================
   ВСТРОЕННАЯ ЧИТАЛКА-САЙДПАНЕЛЬ (chat → клик по выдержке)
   ========================================== */

.source-card-clickable {
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s;
}
.source-card-clickable:hover {
    background: rgba(255, 255, 255, 0.04);
    border-color: var(--rule-strong);
}

.chat-reader-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 720px;
    max-width: 100vw;
    background: var(--bg);
    border-left: 1px solid var(--rule);
    display: flex;
    flex-direction: column;
    z-index: 200;
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.4);
    transform: translateX(100%);
    transition: transform 0.22s ease;
    visibility: hidden;
}
.chat-reader-panel.chat-reader-panel-open {
    transform: translateX(0);
    visibility: visible;
}
.chat-reader-panel.chat-reader-panel-fullscreen {
    width: 100vw !important;
}

.chat-reader-resize-handle {
    position: absolute;
    top: 0;
    left: -4px;
    width: 8px;
    height: 100%;
    cursor: ew-resize;
    background: transparent;
    z-index: 1;
}
.chat-reader-resize-handle:hover,
.chat-reader-resize-handle:active {
    background: rgba(160, 184, 160, 0.25);
}
.chat-reader-panel-fullscreen .chat-reader-resize-handle { display: none; }

.chat-reader-toolbar {
    flex-shrink: 0;
    height: 48px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 12px;
    border-bottom: 1px solid var(--rule);
    background: var(--bg-soft);
}

.chat-reader-back {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: none;
    border: 1px solid var(--rule);
    color: var(--ink-soft);
    font-size: 12px;
    padding: 6px 12px;
    border-radius: var(--radius-pill);
    cursor: pointer;
    transition: background 0.12s, color 0.12s, border-color 0.12s;
    flex-shrink: 0;
}
.chat-reader-back:hover {
    background: rgba(255, 255, 255, 0.06);
    color: var(--ink);
    border-color: var(--rule-strong);
}

.chat-reader-title {
    flex: 1;
    min-width: 0;
    font-size: 13px;
    color: var(--ink-soft);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-reader-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.chat-reader-fullscreen,
.chat-reader-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    background: none;
    border: none;
    color: var(--ink-muted);
    cursor: pointer;
    border-radius: 6px;
    transition: background 0.12s, color 0.12s;
}
.chat-reader-fullscreen:hover,
.chat-reader-close:hover {
    background: rgba(255, 255, 255, 0.06);
    color: var(--ink);
}
.chat-reader-close { font-size: 22px; line-height: 1; }

.chat-reader-iframe {
    flex: 1;
    width: 100%;
    border: 0;
    background: var(--bg);
}

@media (max-width: 768px) {
    .chat-reader-panel { width: 100vw; }
    .chat-reader-resize-handle { display: none; }
}
