/* ═══════ THEME VARIABLES ═══════ */
:root {
    --accent:        #fa625c;
    --accent-hover:  #e8554f;
    --accent-dark:   #c9443f;
    --bg-page:       #f4f5f7;
    --bg-card:       #ffffff;
    --bg-secondary:  #f0f2f5;
    --bg-hover:      #eef0f3;
    --text-primary:  #1f2329;
    --text-secondary:#5a6472;
    --text-muted:    #9aa3af;
    --border:        #e4e7eb;
    --border-strong: #d4d9df;
    --success:       #1a7f37;
    --danger:        #e74c3c;
    --danger-hover:  #d44233;
    --warning:       #9a6700;
    --radius:        10px;
    --radius-lg:     14px;
    --shadow-sm:     0 1px 2px rgba(16,24,40,0.06);
    --shadow:        0 2px 8px rgba(16,24,40,0.08);
    --sidebar-w:     240px;
    --font-text:     'Rubik', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --font-head:     'Montserrat', 'Rubik', -apple-system, 'Segoe UI', Roboto, sans-serif;
}

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

html, body {
    height: 100%;
    background: var(--bg-page);
    color: var(--text-primary);
    font-family: var(--font-text);
    font-size: 15px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
/* ═══════ NAVIGATION (top bar) ═══════ */
.nav-bar {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    gap: 32px;
    height: 60px;
    padding: 0 28px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

.nav-brand {
    font-family: var(--font-head);
    font-weight: 700;
    font-size: 18px;
    color: var(--text-primary);
    white-space: nowrap;
}

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

.nav-link {
    padding: 8px 16px;
    border-radius: var(--radius);
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 14px;
    transition: background .15s, color .15s;
}
.nav-link:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    text-decoration: none;
}
.nav-link.active {
    background: var(--accent);
    color: #fff;
}

/* ═══════ PAGE SWITCHING ═══════ */
.page { display: none; }
.page.active { display: block; }

.container {
    max-width: 920px;
    margin: 0 auto;
    padding: 32px 28px 64px;
}

h1 {
    font-family: var(--font-head);
    font-weight: 700;
    font-size: 26px;
    margin-bottom: 6px;
}
h2 {
    font-family: var(--font-head);
    font-weight: 600;
    font-size: 18px;
    margin-bottom: 12px;
}
h3 {
    font-family: var(--font-head);
    font-weight: 600;
    font-size: 15px;
    margin-bottom: 8px;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 15px;
    margin-bottom: 24px;
}
/* ═══════ CARDS ═══════ */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 24px;
    margin-bottom: 20px;
}

.card-hint {
    display: block;
    color: var(--text-muted);
    font-size: 13px;
    margin-top: 6px;
}

/* ═══════ FORMS ═══════ */
.form-group {
    margin-bottom: 18px;
}
.form-group:last-child { margin-bottom: 0; }

.form-group label {
    display: block;
    font-weight: 500;
    font-size: 14px;
    margin-bottom: 7px;
    color: var(--text-primary);
}

.form-row {
    display: flex;
    gap: 20px;
    align-items: flex-start;
    flex-wrap: wrap;
}
.form-row .form-group { flex: 1; min-width: 180px; }

/* ═══════ INPUTS ═══════ */
.input,
input[type="text"],
input[type="url"],
input[type="number"],
input[type="file"],
select,
textarea {
    width: 100%;
    padding: 10px 13px;
    font-family: var(--font-text);
    font-size: 14px;
    color: var(--text-primary);
    background: var(--bg-card);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    transition: border-color .15s, box-shadow .15s;
}
.input:focus,
input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(250,98,92,0.15);
}

input[type="file"] {
    padding: 8px;
    background: var(--bg-secondary);
    cursor: pointer;
}

/* Checkbox row */
.form-group label > input[type="checkbox"],
label input[type="checkbox"] {
    width: auto;
    margin-right: 8px;
    accent-color: var(--accent);
    vertical-align: middle;
}
/* ═══════ CHAT (стиль Ассистент) ═══════ */

/* Лента сообщений */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px 32px;
    background: #f3f4f6;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Один блок сообщения */
.message {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    max-width: 70%;
}

/* Сообщение ассистента — слева */
.message.assistant {
    align-self: flex-start;
}

/* Сообщение пользователя — справа */
.message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

/* Аватарка */
.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
    box-shadow: 0 1px 3px rgba(0,0,0,.1);
}

/* Бабл с текстом */
.message-body {
    padding: 12px 16px;
    border-radius: 16px;
    line-height: 1.5;
    font-size: 15px;
    min-width: 0;
    overflow-wrap: anywhere;
    word-break: break-word;
}

/* Бабл ассистента — белый, слева */
.message.assistant .message-body {
    background: #fff;
    color: #1f2937;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0,0,0,.08);
}

/* Бабл пользователя — голубой, справа */
.message.user .message-body {
    background: #dbeafe;
    color: #1e3a5f;
    border-bottom-right-radius: 4px;
}

/* Скрываем аватар у пользователя (как в Ассистенте) */
.message.user .message-avatar {
    display: none;
}

/* ───── Источники под сообщением ───── */
.message-sources {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid #e5e7eb;
    font-size: 13px;
}
.message-sources-title {
    font-weight: 600;
    color: #6b7280;
    margin-bottom: 4px;
}

/* ───── Поле ввода (пилюля) ───── */
.chat-input-area {
    padding: 16px 32px 24px;
    background: #f3f4f6;
}
.chat-input-pill {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 24px;
    padding: 8px 8px 8px 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,.06);
    transition: border-color .15s;
}
.chat-input-pill:focus-within {
    border-color: var(--accent);
}
.chat-textarea {
    flex: 1;
    border: none;
    outline: none;
    resize: none;
    font-size: 15px;
    line-height: 1.4;
    max-height: 120px;
    padding: 8px 0;
    background: transparent;
    font-family: inherit;
}

/* Кнопка отправки */
.btn-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
/* ═══════ CHAT LAYOUT (каркас) ═══════ */

/* Страница чата на всю высоту под шапкой */
#page-chat {
    height: calc(100vh - 64px);
    padding: 0;
}

/* Двухколоночная раскладка: сайдбар + чат */
.chat-layout {
    display: flex;
    height: 100%;
}

/* ───── Левый сайдбар со списком чатов ───── */
.chat-sidebar {
    width: 280px;
    flex-shrink: 0;
    background: #fff;
    border-right: 1px solid #e5e7eb;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.chat-sidebar-header {
    padding: 16px;
    border-bottom: 1px solid #e5e7eb;
}
.btn-sidebar-new {
    width: 100%;
    justify-content: center;
}
.chat-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}
.chat-list-empty {
    padding: 16px;
    color: #9ca3af;
    text-align: center;
    font-size: 14px;
}
/* Элемент списка чатов (если JS их создаёт) */
.chat-list-item {
    position: relative;
    padding: 10px 36px 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    color: #374151;
    margin-bottom: 4px;
    transition: background .12s;
    overflow: hidden;
}
.chat-list-item:hover {
    background: #f3f4f6;
}
.chat-list-item.active {
    background: #fde8e4;
    color: var(--accent);
    font-weight: 600;
}

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

/* Шапка чата */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 24px;
    background: #fff;
    border-bottom: 1px solid #e5e7eb;
    flex-shrink: 0;
}
.chat-header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}
.chat-header-left h2 {
    margin: 0;
    font-size: 18px;
}
.kb-status {
    font-size: 13px;
    color: #6b7280;
}
.chat-actions {
    display: none;
}

/* Приветственный экран */
.chat-welcome {
    text-align: center;
    max-width: 560px;
    margin: auto;
    color: #4b5563;
}
.chat-welcome .welcome-icon {
    font-size: 48px;
    margin-bottom: 12px;
}
.chat-welcome h3 {
    margin: 0 0 12px;
}
.chat-welcome .hint {
    margin-top: 16px;
    font-size: 14px;
    color: #6b7280;
}
/* ═══════ CHAT: сворачивание сайдбара ═══════ */
.chat-sidebar-header {
    display: flex;
    align-items: center;
    gap: 8px;
}
.chat-sidebar-header .btn-sidebar-new {
    flex: 1;
}
.sidebar-toggle-btn {
    width: 32px;
    height: 32px;
    flex-shrink: 0;
    border: 1px solid #e5e7eb;
    background: #fff;
    border-radius: 8px;
    cursor: pointer;
    font-size: 18px;
    color: #6b7280;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .12s;
}
.sidebar-toggle-btn:hover {
    background: #f3f4f6;
}
.chat-sidebar {
    transition: width .2s ease;
}
.chat-sidebar.collapsed {
    width: 0;
    border-right: none;
}
.chat-sidebar.collapsed > * {
    display: none;
}
.sidebar-expand-btn {
    width: 32px;
    height: 32px;
    border: 1px solid #e5e7eb;
    background: #fff;
    border-radius: 8px;
    cursor: pointer;
    font-size: 18px;
    color: #6b7280;
    display: none;
    align-items: center;
    justify-content: center;
}
.sidebar-expand-btn:hover {
    background: #f3f4f6;
}
.chat-layout.sidebar-collapsed .sidebar-expand-btn {
    display: flex;
}


/* единый стиль кнопок шапки чата */
.chat-actions #newChatBtn,
.chat-actions #clearChatBtn {
    background: #ffffff;
    color: #374151;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    height: 32px;
    padding: 0 12px;
    font-size: 13px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}
.chat-actions #newChatBtn:hover,
.chat-actions #clearChatBtn:hover {
    background: #f3f4f6;
    border-color: #d1d5db;
}
.chat-actions #clearChatBtn {
    color: #b91c1c;
}
.chat-actions #clearChatBtn:hover {
    background: #fef2f2;
    border-color: #fca5a5;
}


/* базовые стили кнопок .btn */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 38px;
    padding: 0 16px;
    font-size: 14px;
    font-weight: 500;
    line-height: 1;
    color: #374151;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
    white-space: nowrap;
}
.btn:hover {
    background: #f3f4f6;
    border-color: #d1d5db;
}
.btn:active {
    background: #e5e7eb;
}
.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* мелкая кнопка */
.btn-sm {
    height: 32px;
    padding: 0 12px;
    font-size: 13px;
}

/* основная (акцентная) кнопка */
.btn-primary {
    background: #ef6f61;
    border-color: #ef6f61;
    color: #ffffff;
}
.btn-primary:hover {
    background: #e25b4d;
    border-color: #e25b4d;
}
.btn-primary:active {
    background: #d64e40;
}

/* опасное действие */
.btn-danger {
    color: #b91c1c;
    border-color: #fca5a5;
}
.btn-danger:hover {
    background: #fef2f2;
    border-color: #f87171;
}


/* боковое левое меню */
.nav-bar {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 100;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    width: 210px;
    height: 100vh;
    padding: 16px 12px;
    border-bottom: none;
    border-right: 1px solid var(--border);
    overflow-y: auto;
}
.nav-brand {
    padding: 8px 12px 16px;
    font-size: 20px;
}
.nav-links {
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
}
.nav-link {
    display: block;
    width: 100%;
    padding: 10px 14px;
}

/* сдвигаем весь контент вправо от боковой панели */
.page {
    margin-left: 210px;
}


/* бургер-кнопка */
#nav-burger {
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 200;
    width: 40px;
    height: 40px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: background .15s;
}
#nav-burger:hover {
    background: var(--bg-hover);
}

/* плавность панели и контента */
.nav-bar {
    transition: transform .2s ease;
}
.page {
    transition: margin-left .2s ease;
}

/* сдвигаем бренд вправо, чтобы не перекрывался бургером */
.nav-brand {
    margin-left: 44px;
}

/* СВЁРНУТОЕ состояние */
body.nav-collapsed .nav-bar {
    transform: translateX(-100%);
}
body.nav-collapsed .page {
    margin-left: 0;
}


/* выравнивание бургера по бренду */
#nav-burger {
    top: 16px;
    left: 14px;
    width: 36px;
    height: 36px;
    font-size: 16px;
}
.nav-brand {
    margin-left: 46px;
}


/* фикс высоты чата под боковое меню */
#page-chat {
    height: 100vh;
}
/* чуть больше воздуха под полем ввода */
.chat-input-area {
    padding-bottom: 28px;
}


/* бургер: точное выравнивание v2 */
.nav-brand {
    display: flex;
    align-items: center;
    min-height: 36px;
    padding-top: 0;
    padding-bottom: 0;
    margin-left: 50px;
}
#nav-burger {
    top: 12px;
    left: 14px;
}


/* меню в стиле Ассистента */
.nav-link {
    position: relative;
    color: #1f2937 !important;
    background: transparent !important;
    font-weight: 500;
    border-radius: 8px;
}
.nav-link:hover {
    background: #f3f4f6 !important;
    color: #1f2937 !important;
}
.nav-link.active {
    background: transparent !important;
    color: #111827 !important;
    font-weight: 700;
}
.nav-link.active::before {
    content: "";
    position: absolute;
    left: 4px;
    top: 50%;
    transform: translateY(-50%);
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent);
}
.nav-link.active {
    padding-left: 20px;
}


/* отступ списка меню от бренда */
.nav-links {
    margin-top: 24px;
}


/* выравнивание полей в Параметрах генерации */
.form-row {
    align-items: start;
}
.form-row .form-group label {
    display: block;
    min-height: 2.6em;
    line-height: 1.3;
}


/* карточки источников - каждый с новой строки */
.sources-grid {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 8px;
}
.source-card {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: #f5f5f7;
    border: 1px solid #e3e3e8;
    border-radius: 8px;
    text-decoration: none;
    color: #1d1d1f;
    font-size: 14px;
    transition: background 0.15s, border-color 0.15s;
}
.source-card:hover {
    background: #ececf0;
    border-color: #d0d0d6;
}
.source-card-num {
    color: #888;
    font-weight: 600;
    flex-shrink: 0;
}
.source-card-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.source-card-icon {
    color: #999;
    flex-shrink: 0;
}


/* === стили дочерних элементов карточки чата === */
.chat-list-item-title {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 500;
}
.chat-list-item-meta {
    margin-top: 3px;
    font-size: 12px;
    color: #9ca3af;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chat-list-item.active .chat-list-item-meta {
    color: var(--accent);
    opacity: 0.75;
}
.chat-list-item-delete {
    position: absolute;
    top: 50%;
    right: 8px;
    transform: translateY(-50%);
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: #9ca3af;
    font-size: 14px;
    line-height: 1;
    border-radius: 6px;
    cursor: pointer;
    opacity: 0;
    transition: opacity .12s, background .12s, color .12s;
}
.chat-list-item:hover .chat-list-item-delete {
    opacity: 1;
}
.chat-list-item-delete:hover {
    background: rgba(0,0,0,0.06);
    color: #ef4444;
}


/* === кнопки-предложки (suggestions) === */
.chat-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 24px 4px;
    background: transparent;
}
.chat-suggestions-loading {
    font-size: 13px;
    color: #9ca3af;
    padding: 4px 0;
}
.chat-suggestion-chip {
    appearance: none;
    border: 1px solid #e5e7eb;
    background: #fff;
    color: #374151;
    font-size: 13px;
    line-height: 1.35;
    padding: 7px 14px;
    border-radius: 16px;
    cursor: pointer;
    transition: background .15s, border-color .15s, color .15s;
    max-width: 100%;
    text-align: left;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.chat-suggestion-chip:hover {
    background: #fde8e4;
    border-color: var(--accent);
    color: var(--accent);
}
.chat-suggestion-chip:active {
    transform: translateY(1px);
}


/* === отступы внутри бабла ассистента === */
.message.assistant .message-body p,
.message.assistant .message-body ul,
.message.assistant .message-body ol {
    margin: 0 0 10px;
}
.message.assistant .message-body ul,
.message.assistant .message-body ol {
    padding-left: 22px;
}
.message.assistant .message-body li {
    margin-bottom: 6px;
}
.message.assistant .message-body li:last-child {
    margin-bottom: 0;
}
.message.assistant .message-body h1,
.message.assistant .message-body h2,
.message.assistant .message-body h3,
.message.assistant .message-body h4 {
    margin: 16px 0 8px;
    font-size: 15px;
    font-weight: 600;
    line-height: 1.35;
}
/* первый и последний элемент — без лишних внешних отступов */
.message.assistant .message-body > *:first-child {
    margin-top: 0;
}
.message.assistant .message-body > *:last-child {
    margin-bottom: 0;
}


/* === фикс сайдбара и наплыва бургера === */
.chat-sidebar {
    background: #fff;
}
.chat-list-item.active {
    background: #fff;
    box-shadow: 0 1px 2px rgba(0,0,0,.06);
    color: var(--accent);
}
.chat-header {
    padding-left: 60px;
}


/* === отступ шапки сайдбара под бургер === */
.chat-sidebar-header {
    padding-left: 60px;
}


/* === выравнивание трёх кнопок шапки сайдбара === */
#nav-burger {
    top: 14px;
    width: 38px;
    height: 38px;
    font-size: 18px;
}
.sidebar-toggle-btn {
    width: 38px;
    height: 38px;
}


/* expand-btn 38 */
.sidebar-expand-btn {
    width: 38px;
    height: 38px;
}


/* nav-bar grey bg */
.nav-bar {
    background: #f3f4f6;
}


/* === provider cards (added) === */
.provider-card {
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 18px 20px;
    margin-bottom: 16px;
    background: var(--bg-card);
    transition: border-color .15s, box-shadow .15s;
}
.provider-card.enabled {
    border-color: #34c759;
    box-shadow: 0 0 0 2px rgba(52,199,89,.15);
}

.provider-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
}
.provider-name { font-weight: 600; font-size: 16px; }

/* нативный чекбокс -> тогл */
.provider-header .provider-enabled {
    appearance: none;
    -webkit-appearance: none;
    width: 42px; height: 24px;
    border-radius: 999px;
    background: var(--border-strong);
    position: relative;
    cursor: pointer;
    transition: background .15s;
    margin: 0;
    flex: 0 0 auto;
}
.provider-header .provider-enabled::after {
    content: "";
    position: absolute;
    top: 2px; left: 2px;
    width: 20px; height: 20px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 2px rgba(0,0,0,.2);
    transition: transform .15s;
}
.provider-header .provider-enabled:checked { background: #34c759; }
.provider-header .provider-enabled:checked::after { transform: translateX(18px); }

/* поля в 2 колонки */
.provider-fields {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px 18px;
}
.provider-fields > * {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}
.provider-fields label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
}
@media (max-width: 720px) {
    .provider-fields { grid-template-columns: 1fr; }
}


/* === kb sources (added) === */
.kb-sources-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 14px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--border);
}
.kb-sources-toolbar .btn-danger {
    padding: 8px 14px;
    border-radius: var(--radius);
    font-size: 14px;
    cursor: pointer;
}

/* строка-источник: обёртка с кнопками-сёстрами справа */
.kb-source-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    margin-bottom: 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-card);
    transition: border-color .15s, background .15s;
}
.kb-source-item:hover { background: var(--bg-hover); }

.kb-source-row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1 1 auto;
    min-width: 0;
    cursor: pointer;
}
.kb-src-name {
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.kb-src-cbwrap { display: flex; align-items: center; flex: 0 0 auto; }
.kb-src-icon { flex: 0 0 auto; }

/* бейджи */
.kb-src-badge, .kb-emb-badge, .kb-src-date {
    flex: 0 0 auto;
    font-size: 12px;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--bg-secondary);
    color: var(--text-secondary);
}
.kb-src-date { background: transparent; padding: 0 4px; }

/* иконки-кнопки ⬇ 🗑 */
.btn-icon {
    flex: 0 0 auto;
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-card);
    cursor: pointer;
    font-size: 15px;
    line-height: 1;
    transition: background .15s, border-color .15s, color .15s;
}
.btn-icon:hover { background: var(--bg-hover); border-color: var(--border-strong); }
.kb-src-del:hover { color: var(--accent); border-color: var(--accent); }

/* блок "куда переместить" + кнопка (универсально по тулбару) */
.kb-move-bar, .kb-sources-move {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 14px;
}
.kb-move-bar select, .kb-sources-move select {
    height: 38px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 14px;
}


/* === kb move (added) === */
.btn-secondary {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border);
    padding: 8px 14px;
    border-radius: var(--radius);
    font-size: 14px;
    cursor: pointer;
    transition: background .15s, border-color .15s;
}
.btn-secondary:hover { background: var(--bg-hover); border-color: var(--border-strong); }
.btn-secondary:disabled { opacity: .5; cursor: not-allowed; }

/* селект перемещения в тулбаре — выровнять по высоте кнопок */
.kb-sources-toolbar #kbMoveTarget {
    height: 38px;
    padding: 0 10px;
    font-size: 14px;
}

/* Исправление для длинных URL в логах */
#crawlLogs pre,
#previewResult pre {
    word-break: break-all;
    white-space: pre-wrap;
    overflow-wrap: break-word;
    max-width: 100%;
}

#crawlLogs,
#previewResult {
    overflow-x: auto;
    max-width: 100%;
}

/* Стиль для прогресса предпросмотра */
.preview-progress {
    background: #f3f4f6;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 16px;
}

.preview-progress-bar {
    height: 8px;
    background: #e5e7eb;
    border-radius: 4px;
    overflow: hidden;
}

.preview-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #3b82f6, #60a5fa);
    transition: width 0.3s ease;
}

/* Счетчики предпросмотра */
.preview-counter {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: #6b7280;
}

.preview-counter-num {
    font-weight: 600;
    color: #3b82f6;
}

/* Исправление для длинных URL в логах */
#crawlLogs pre,
#previewResult pre {
    word-break: break-all;
    white-space: pre-wrap;
    overflow-wrap: break-word;
    max-width: 100%;
}

#crawlLogs {
    max-height: 400px;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 12px;
    background: #f9fafb;
    border-radius: 8px;
    font-family: 'Monaco', 'Courier New', monospace;
    font-size: 12px;
    line-height: 1.5;
}

#crawlLogs .log-entry {
    margin-bottom: 8px;
    padding: 8px;
    background: white;
    border-left: 3px solid #3b82f6;
    border-radius: 4px;
}

#crawlLogs .log-url {
    color: #1e40af;
    word-break: break-all;
}

#crawlLogs .log-time {
    color: #6b7280;
    font-size: 11px;
}

/* Улучшенный счетчик предпросмотра */
.preview-counter {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 16px 20px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    box-shadow: 0 10px 25px rgba(102, 126, 234, 0.3);
}

.preview-counter span {
    color: rgba(255, 255, 255, 0.9);
}

.preview-counter strong {
    color: white;
    font-size: 18px;
    margin: 0 4px;
}

/* Анимация для счетчиков */
@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

#previewCounterNum {
    display: inline-block;
    animation: pulse 0.3s ease-out;
}

/* Стили для логов с timestamp */
#logEntries {
    max-height: 400px;
    overflow-y: auto;
    padding: 10px;
    background: #f9fafb;
    border-radius: 8px;
    font-family: 'SF Mono', Monaco, 'Courier New', monospace;
    font-size: 13px;
}

#logEntries .log-entry {
    display: flex;
    align-items: flex-start;
    margin-bottom: 8px;
    padding: 6px 10px;
    background: white;
    border-radius: 6px;
    border-left: 3px solid #e5e7eb;
    transition: all 0.2s;
}

#logEntries .log-entry.success {
    border-left-color: #10b981;
    background: #f0fdf4;
}

#logEntries .log-entry.error {
    border-left-color: #ef4444;
    background: #fef2f2;
}

#logEntries .log-entry .log-time {
    color: #9ca3af;
    font-size: 11px;
    margin-right: 10px;
    white-space: nowrap;
    font-weight: 500;
}

#logEntries .log-entry .log-message {
    flex: 1;
    color: #374151;
    word-break: break-all;
    line-height: 1.4;
}

#logEntries .log-entry .log-url {
    color: #2563eb;
    text-decoration: none;
    cursor: pointer;
    word-break: break-all;
}

#logEntries .log-entry .log-url:hover {
    text-decoration: underline;
}

/* Анимация появления новых логов */
@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-10px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

#logEntries .log-entry {
    animation: slideIn 0.3s ease-out;
}

/* ===== УЛУЧШЕННЫЕ СТИЛИ ДЛЯ ЛОГОВ С ДАТОЙ И ВРЕМЕНЕМ ===== */
#logEntries {
    max-height: 400px;
    overflow-y: auto;
    padding: 10px;
    background: #f9fafb;
    border-radius: 8px;
    font-family: 'SF Mono', Monaco, 'Courier New', monospace;
    font-size: 13px;
}

#logEntries .log-entry {
    display: flex;
    align-items: flex-start;
    margin-bottom: 8px;
    padding: 8px 12px;
    background: white;
    border-radius: 6px;
    border-left: 3px solid #e5e7eb;
    transition: all 0.2s;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

#logEntries .log-entry:hover {
    background-color: #f0f9ff;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

#logEntries .log-entry.success {
    border-left-color: #10b981;
    background: linear-gradient(to right, #f0fdf4, white);
}

#logEntries .log-entry.error {
    border-left-color: #ef4444;
    background: linear-gradient(to right, #fef2f2, white);
}

#logEntries .log-entry .log-time {
    color: #6b7280;
    font-size: 12px;
    margin-right: 12px;
    white-space: nowrap;
    font-weight: 600;
    min-width: 80px;
}

#logEntries .log-entry .log-message {
    flex: 1;
    color: #374151;
    word-break: break-all;
    line-height: 1.5;
}

#logEntries .log-entry .log-url {
    color: #2563eb;
    text-decoration: none;
    cursor: pointer;
    word-break: break-all;
    font-weight: 500;
}

#logEntries .log-entry .log-url:hover {
    text-decoration: underline;
    color: #1d4ed8;
}

/* ===== КРАСИВЫЙ БЛОК ПРЕДПРОСМОТРА ===== */
.preview-counter {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px;
    border-radius: 12px;
    margin-bottom: 20px;
    box-shadow: 0 10px 25px rgba(102, 126, 234, 0.3);
}

.preview-counter-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
}

.preview-counter-item {
    text-align: center;
}

.preview-counter-label {
    display: block;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
    opacity: 0.9;
    margin-bottom: 5px;
}

.preview-counter-value {
    display: block;
    font-size: 32px;
    font-weight: bold;
    line-height: 1;
}

#previewCounterNum,
#previewCounterQueue {
    animation: pulse 0.5s ease-out;
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

/* Прогресс-бар для предпросмотра */
.preview-progress {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid rgba(255, 255, 255, 0.2);
}

.preview-progress-bar {
    height: 6px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 10px;
}

.preview-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #fbbf24, #f59e0b);
    transition: width 0.3s ease;
    box-shadow: 0 0 10px rgba(251, 191, 36, 0.5);
}

.preview-status {
    font-size: 13px;
    opacity: 0.95;
    text-align: center;
}

/* Результаты предпросмотра */
.preview-result {
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 15px;
    border-bottom: 2px solid #f3f4f6;
    margin-bottom: 15px;
}

.preview-stat {
    text-align: center;
}

.preview-count {
    display: block;
    font-size: 36px;
    font-weight: bold;
    color: #3b82f6;
    margin-bottom: 5px;
}

.preview-label {
    font-size: 14px;
    color: #6b7280;
}

.preview-urls-list {
    max-height: 300px;
    overflow-y: auto;
    padding: 10px;
    background: #f9fafb;
    border-radius: 8px;
    margin-top: 15px;
}

.preview-url-item {
    padding: 8px 12px;
    margin-bottom: 6px;
    background: white;
    border-radius: 6px;
    border-left: 3px solid #3b82f6;
    font-size: 13px;
    word-break: break-all;
    transition: all 0.2s;
}

.preview-url-item:hover {
    background: #f0f9ff;
    transform: translateX(2px);
}

/* Улучшенная прокрутка */
#logEntries::-webkit-scrollbar,
.preview-urls-list::-webkit-scrollbar {
    width: 8px;
}

#logEntries::-webkit-scrollbar-track,
.preview-urls-list::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

#logEntries::-webkit-scrollbar-thumb,
.preview-urls-list::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

#logEntries::-webkit-scrollbar-thumb:hover,
.preview-urls-list::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Нумерация в списке URL - продолжение */
#previewUrlsList li {
    counter-increment: url-counter;
    position: relative;
    padding-left: 40px;
}

#previewUrlsList li::before {
    content: counter(url-counter);
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    background: #3b82f6;
    color: white;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: bold;
}


/* ===== typing indicator (streaming) ===== */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 4px 2px;
}

.typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: currentColor;
    opacity: 0.4;
    animation: typingBounce 1.2s infinite ease-in-out;
}

.typing-dot:nth-child(1) { animation-delay: 0s; }
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.4;
    }
    30% {
        transform: translateY(-5px);
        opacity: 1;
    }
}
