/* ─── Knowledge Bases page ───
 * Outer flex layout (sidebar + main) is handled by .app-shell in base.css.
 * This stylesheet only styles the main card and its internals.
 */

.kb-main {
    box-sizing: border-box;
    width: 100%;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 24px;
    padding: 32px;
    background: rgba(255, 255, 255, 0.4);
    border: 1px solid rgba(0, 0, 0, 0.05);
    border-radius: 40px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.1), 0 0 25px rgba(14, 165, 233, 0.15);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

/* ─── Header ─── */
.kb-header {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.kb-header__top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.kb-header__title {
    margin: 0;
    color: #1e293b;
    font-family: var(--font-heading);
    font-size: 30px;
    line-height: 36px;
    font-weight: 700;
    letter-spacing: -0.75px;
}

.kb-header__subtitle {
    margin: 0;
    color: #64748b;
    font-family: var(--font-heading);
    font-size: 14px;
    line-height: 20px;
    font-weight: 400;
}

.kb-header__action {
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 32px;
    min-width: 160px;
    padding: 0 16px;
    border: var(--border-width-default) solid var(--color-primary);
    border-radius: var(--radius-xl);
    background: var(--color-primary);
    color: #ffffff;
    cursor: pointer;
    font-family: var(--font-heading);
    font-size: 14px;
    font-weight: 700;
    line-height: 16px;
    transition: background-color var(--transition-fast), transform var(--transition-fast);
}

.kb-header__action:hover {
    background: var(--color-primary-hover);
    transform: translateY(-1px);
}

/* ─── List ─── */
.kb-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow-y: auto;
}

.kb-list .select-input {
    box-shadow: none;
}

.kb-list__empty {
    margin: 0;
    padding: 12px 16px;
    color: var(--color-slate-400);
    font-family: var(--font-body);
    font-size: 12px;
    line-height: 16px;
}

/* ─── Accordion row (single column) ─── */
.kb-list .select-input__trigger {
    grid-template-columns: minmax(0, 1fr) auto;
}

/* ─── Create form (inline card shown above the list when creating) ─── */
.kb-create {
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 24px;
    background: var(--color-surface);
    border: var(--border-width-default) solid var(--color-border-soft);
    border-radius: var(--radius-4xl);
}

.kb-create__title {
    margin: 0;
    font-family: var(--font-heading);
    font-size: 18px;
    font-weight: 700;
    line-height: 22px;
    color: var(--color-slate-800);
    letter-spacing: -0.25px;
}

.kb-create__subtitle {
    margin: 0;
    color: var(--color-slate-600);
    font-family: var(--font-heading);
    font-size: 12px;
    line-height: 16px;
    font-weight: 400;
}

.kb-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* ─── Field control (bigger than select-input__control) ─── */
.kb-field {
    box-sizing: border-box;
    width: 100%;
    min-height: 45px;
    padding: 14px;
    border: 1px solid var(--color-border-soft);
    border-radius: 24px;
    background: #f8fafc;
    color: var(--color-slate-800);
    font-family: var(--font-heading);
    font-size: 12px;
    line-height: 15px;
    font-weight: 400;
    outline: none;
    resize: none;
    appearance: none;
}

.kb-field::placeholder {
    color: var(--color-slate-400);
    opacity: 1;
}

.kb-field--description {
    min-height: 75px;
    resize: vertical;
}

.kb-field--text {
    min-height: 120px;
    resize: vertical;
}

.kb-field:focus-visible {
    outline: 2px solid var(--color-primary-soft);
    outline-offset: 2px;
    border-color: var(--color-primary-soft);
}

/* ─── Sources section ─── */
.kb-sources {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.kb-sources__header {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.kb-sources__title {
    margin: 0;
    font-family: var(--font-heading);
    font-size: 14px;
    line-height: 20px;
    font-weight: 700;
    color: var(--color-slate-800);
}

.kb-sources__hint {
    margin: 0;
    font-family: var(--font-heading);
    font-size: 12px;
    line-height: 16px;
    font-weight: 600;
    color: var(--color-slate-600);
}

.kb-file-drop {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 64px;
    padding: 16px;
    border: 1px dashed var(--color-slate-400);
    border-radius: 24px;
    background: #f8fafc;
    color: var(--color-slate-600);
    font-family: var(--font-heading);
    font-size: 12px;
    line-height: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: border-color var(--transition-fast), background-color var(--transition-fast);
    text-align: center;
}

.kb-file-drop:hover {
    border-color: var(--color-primary-soft);
    background: rgba(14, 165, 233, 0.04);
}

.kb-file-drop input[type="file"] {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

.kb-doc {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px;
    border: 1px solid var(--color-border-soft);
    border-radius: 24px;
    background: rgba(255, 255, 255, 0.6);
    transition: border-color var(--transition-fast), background-color var(--transition-fast);
}

/* ─── Upload-in-progress state ───
 * Tinted background + animated border draws the eye while the file is being
 * shipped to the server. The row's inputs are disabled by the markup; we just
 * style the container here. */
.kb-doc--uploading {
    border-color: rgba(14, 165, 233, 0.45);
    background: linear-gradient(180deg, rgba(14, 165, 233, 0.06), rgba(255, 255, 255, 0.6));
    box-shadow: 0 0 0 1px rgba(14, 165, 233, 0.18) inset;
    animation: kb-doc-pulse 1.8s ease-in-out infinite;
}

@keyframes kb-doc-pulse {
    0%, 100% { box-shadow: 0 0 0 1px rgba(14, 165, 233, 0.18) inset, 0 0 0 0 rgba(14, 165, 233, 0); }
    50%      { box-shadow: 0 0 0 1px rgba(14, 165, 233, 0.18) inset, 0 0 0 8px rgba(14, 165, 233, 0.08); }
}

.kb-doc--error {
    border-color: rgba(220, 38, 38, 0.5);
    background: rgba(243, 76, 61, 0.05);
}

/* Status pill (spinner + "Загрузка…") shown in place of the Remove button
   while the upload runs. */
.kb-doc__status {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex: none;
    padding: 6px 12px;
    border-radius: 999px;
    background: rgba(14, 165, 233, 0.08);
    border: 1px solid rgba(14, 165, 233, 0.25);
    color: var(--color-primary);
    font-family: var(--font-heading);
    font-size: 12px;
    font-weight: 600;
    line-height: 16px;
    white-space: nowrap;
}

.kb-doc__status-label {
    color: var(--color-slate-600);
    font-weight: 600;
}

.kb-doc__spinner {
    display: inline-flex;
    flex: none;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(14, 165, 233, 0.25);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: kb-doc-spin 0.8s linear infinite;
}

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

/* Skeleton lines that stand in for the textarea while the file content is
   still being processed on the server. Three bars of varying width feel more
   "alive" than a single rectangle. */
.kb-doc__placeholder {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px 14px;
    border: 1px dashed rgba(14, 165, 233, 0.35);
    border-radius: 18px;
    background: rgba(14, 165, 233, 0.04);
}

.kb-doc__skeleton {
    display: block;
    height: 10px;
    border-radius: 999px;
    background: linear-gradient(
        90deg,
        rgba(14, 165, 233, 0.08) 0%,
        rgba(14, 165, 233, 0.22) 50%,
        rgba(14, 165, 233, 0.08) 100%
    );
    background-size: 200% 100%;
    animation: kb-doc-shimmer 1.4s linear infinite;
}

.kb-doc__skeleton--lg { width: 92%; }
.kb-doc__skeleton--md { width: 76%; }
.kb-doc__skeleton--sm { width: 58%; }

@keyframes kb-doc-shimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.kb-doc__error {
    margin: 0;
    padding: 8px 12px;
    border-radius: 12px;
    background: rgba(243, 76, 61, 0.08);
    color: var(--color-danger);
    font-family: var(--font-body);
    font-size: 12px;
    line-height: 16px;
}

.kb-doc__row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.kb-doc__row .kb-field {
    flex: 1;
}

.kb-doc__remove {
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: none;
    min-height: 32px;
    padding: 0 14px;
    border: 1px solid #dc2626;
    border-radius: var(--radius-xl);
    background: var(--color-surface-muted);
    color: #dc2626;
    font-family: var(--font-heading);
    font-size: 12px;
    font-weight: 600;
    line-height: 16px;
    cursor: pointer;
    transition: background-color var(--transition-fast), color var(--transition-fast);
}

.kb-doc__remove:hover {
    background: #dc2626;
    color: #ffffff;
}

.kb-sources__add {
    box-sizing: border-box;
    align-self: flex-start;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 32px;
    padding: 0 16px;
    border: var(--border-width-default) solid var(--color-primary);
    border-radius: var(--radius-xl);
    background: var(--color-surface);
    color: var(--color-primary);
    cursor: pointer;
    font-family: var(--font-heading);
    font-size: 12px;
    font-weight: 600;
    line-height: 16px;
    transition: background-color var(--transition-fast), color var(--transition-fast);
}

.kb-sources__add:hover {
    background: var(--color-primary);
    color: #ffffff;
}

/* ─── Actions row (shared by create + edit) ─── */
.kb-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 16px;
    padding-top: 4px;
}

.kb-btn {
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    min-width: 184px;
    padding: 0 16px;
    border: 1px solid var(--color-primary);
    border-radius: var(--radius-xl);
    background: var(--color-surface);
    color: var(--color-primary);
    cursor: pointer;
    font-family: var(--font-heading);
    font-size: 14px;
    font-weight: 700;
    line-height: 16px;
    white-space: nowrap;
    transition: background-color var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast), transform var(--transition-fast);
}

.kb-btn:hover {
    transform: translateY(-1px);
}

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

.kb-btn--muted {
    border-color: #94a3b8;
    color: #94a3b8;
    background: #f8fafc;
    font-weight: 400;
}

.kb-btn--muted:hover {
    border-color: var(--color-slate-600);
    color: var(--color-slate-600);
}

.kb-btn--danger {
    border-color: #dc2626;
    color: #dc2626;
}

.kb-btn--danger:hover {
    background: #dc2626;
    color: #ffffff;
}

/* ─── Error ─── */
.kb-error {
    margin: 0;
    padding: 8px 14px;
    border: 1px solid #fecaca;
    border-radius: var(--radius-xl);
    background: #fef2f2;
    color: #dc2626;
    font-family: var(--font-body);
    font-size: 12px;
    line-height: 16px;
}

/* ─── Section blocks inside edit panel (matches update_db look) ─── */
.kb-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.kb-section__copy {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.kb-section__title {
    margin: 0;
    color: #334155;
    font-family: var(--font-heading);
    font-size: 14px;
    line-height: 20px;
    font-weight: 700;
}

.kb-section__description {
    margin: 0;
    color: #64748b;
    font-family: var(--font-heading);
    font-size: 12px;
    line-height: 16px;
    font-weight: 400;
}

/* ─── Responsive ─── */
@media (max-width: 760px) {
    .kb-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .kb-btn {
        width: 100%;
        min-width: 0;
    }

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

    .kb-header__action {
        width: 100%;
    }
}

/* ─── Toast ───
 * Page-local notification that pops out at the bottom-right after a KB
 * assignment action. Auto-dismisses via timer; clicking × dismisses early.
 */
.kb-toast {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 240px;
    max-width: 420px;
    padding: 12px 16px;
    border-radius: 10px;
    color: #fff;
    font-size: 14px;
    line-height: 1.4;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
    animation: kb-toast-in 180ms ease-out;
}

.kb-toast--success {
    background: #2e7d32;
}

.kb-toast--error {
    background: #c62828;
}

.kb-toast__message {
    flex: 1;
    overflow-wrap: anywhere;
}

.kb-toast__close {
    flex: none;
    width: 24px;
    height: 24px;
    padding: 0;
    border: none;
    background: transparent;
    color: inherit;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    opacity: 0.85;
}

.kb-toast__close:hover {
    opacity: 1;
}

@keyframes kb-toast-in {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (max-width: 760px) {
    .kb-toast {
        right: 16px;
        left: 16px;
        bottom: 16px;
        max-width: none;
    }
}
