/* knowledge_base/frontend/css/styles.css */

/* ============================================================= */
/* Variables & Reset                                              */
/* ============================================================= */
:root {
    --pipeline-sanitize:  #ffc107;
    --pipeline-chunk:     #0dcaf0;
    --pipeline-vectorize: #6c757d;
    --pipeline-qdrant:    #212529;
    --pipeline-reindex:   #0d6efd;
    --status-indexed:     #198754;
    --status-failed:      #dc3545;
    --status-processing:  #0d6efd;
    --status-unknown:     #6c757d;
}

body {
    background-color: #f8f9fa;
    font-size: 0.9rem;
}

/* ============================================================= */
/* Catalog Map                                                    */
/* ============================================================= */
#catalog-map-container svg path.lot {
    fill: transparent;
    stroke: transparent;
    cursor: pointer;
    transition: fill 0.15s ease, stroke 0.15s ease, opacity 0.15s ease;
}
#catalog-map-container svg path.lot:hover {
    filter: brightness(1.15);
    stroke-width: 5px !important;
}

/* ============================================================= */
/* Navigation                                                     */
/* ============================================================= */
.navbar-brand {
    font-weight: 600;
    font-size: 1.1rem;
}

/* ============================================================= */
/* Status Badges                                                  */
/* ============================================================= */
.status-badge {
    display: inline-block;
    padding: 0.25em 0.65em;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 0.375rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.status-indexed    { background: #d1e7dd; color: #0f5132; }
.status-failed     { background: #f8d7da; color: #842029; }
.status-processing { background: #cfe2ff; color: #084298; }
.status-unknown    { background: #e9ecef; color: #495057; }

/* ============================================================= */
/* Pages                                                          */
/* ============================================================= */
.page-content {
    animation: fadeIn 0.2s ease-in;
}

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

/* ============================================================= */
/* Pipeline Steps (в модальном окне деталей источника)           */
/* ============================================================= */
.pipeline-steps {
    border-left: 2px solid #dee2e6;
    padding-left: 1rem;
    margin-left: 0.5rem;
}

.pipeline-steps .bi {
    width: 1.4rem;
    text-align: center;
}

/* ============================================================= */
/* Resume Pipeline Buttons (в таблице источников)                */
/* ============================================================= */

/* Кнопки шагов пайплайна чуть компактнее */
.btn-sm[onclick*="resumeSanitize"],
.btn-sm[onclick*="resumeChunk"],
.btn-sm[onclick*="resumeVectorize"],
.btn-sm[onclick*="resumeIndex"],
.btn-sm[onclick*="reindex"] {
    font-size: 0.75rem;
    padding: 0.2rem 0.5rem;
}

/* Разные цвета для кнопок шагов */
.btn-outline-warning:hover  { background: var(--pipeline-sanitize);  color: #000; }
.btn-outline-info:hover     { background: var(--pipeline-chunk);      color: #000; }

/* ============================================================= */
/* Vectorization Progress (на странице загрузки)                 */
/* ============================================================= */
.vectorization-progress {
    border: 1px solid #dee2e6;
    border-radius: 8px;
    padding: 1.25rem;
    background: white;
}

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

.stage-item {
    display: flex;
    align-items: center;
    padding: 0.6rem 0;
    position: relative;
}

.stage-item + .stage-item::before {
    content: '';
    position: absolute;
    top: 0;
    left: 20px;
    width: 2px;
    height: 0.6rem;
    background: #dee2e6;
}

.stage-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: #e9ecef;
    margin-right: 1rem;
    font-size: 1.1rem;
    flex-shrink: 0;
    color: #6c757d;
}

.stage-item.stage-active .stage-icon {
    background: #0d6efd;
    color: white;
    animation: pulseShadow 1.5s infinite;
}

.stage-item.stage-completed .stage-icon {
    background: #198754;
    color: white;
}

.stage-item.stage-failed .stage-icon {
    background: #dc3545;
    color: white;
}

.stage-label {
    font-weight: 500;
    font-size: 0.9rem;
    flex-grow: 1;
}

.stage-status {
    margin-left: 1rem;
}

@keyframes pulseShadow {
    0%, 100% { box-shadow: 0 0 0 0 rgba(13, 110, 253, 0.6); }
    50%       { box-shadow: 0 0 0 8px rgba(13, 110, 253, 0);  }
}

/* ============================================================= */
/* Metrics                                                        */
/* ============================================================= */
.metric-card {
    text-align: center;
    padding: 1rem;
    background: #f8f9fa;
    border-radius: 8px;
    border: 1px solid #e9ecef;
}

.metric-value {
    font-size: 1.6rem;
    font-weight: 700;
    color: #0d6efd;
    margin-bottom: 0.2rem;
}

.metric-label {
    font-size: 0.8rem;
    color: #6c757d;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* ============================================================= */
/* Chunks                                                         */
/* ============================================================= */
.chunks-visualization {
    max-height: 600px;
    overflow-y: auto;
    padding: 0.25rem;
}

.chunk-card {
    border: 1px solid #dee2e6;
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 0.75rem;
    background: white;
    transition: box-shadow 0.15s, transform 0.15s;
}

.chunk-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    transform: translateY(-1px);
}

.chunk-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.6rem;
    padding-bottom: 0.4rem;
    border-bottom: 1px solid #e9ecef;
}

.chunk-index {
    font-weight: 600;
    font-size: 1rem;
    color: #495057;
}

.chunk-content {
    padding: 0.6rem 0.8rem;
    background: #f8f9fa;
    border-radius: 6px;
    font-family: 'Courier New', monospace;
    font-size: 0.85rem;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
}

.chunk-metadata {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-top: 0.6rem;
}

.metadata-tag {
    background: #e9ecef;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    color: #495057;
}

/* ============================================================= */
/* Search Results                                                 */
/* ============================================================= */
.search-result-item {
    border: 1px solid #dee2e6;
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 0.75rem;
    background: white;
    transition: box-shadow 0.15s;
}

.search-result-item:hover {
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.07);
}

.search-result-clickable {
    cursor: pointer;
    transition: box-shadow 0.15s, border-color 0.15s;
}

.search-result-clickable:hover {
    box-shadow: 0 4px 14px rgba(13, 110, 253, 0.15);
    border-color: #86b7fe;
}

.score-high   { color: #198754; font-weight: 600; }
.score-medium { color: #fd7e14; font-weight: 600; }
.score-low    { color: #6c757d; font-weight: 600; }

/* ============================================================= */
/* Activity Log                                                   */
/* ============================================================= */
.activity-entry {
    padding: 0.35rem 0.75rem;
    border-bottom: 1px solid #f0f0f0;
    font-size: 0.75rem;
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
}

.activity-entry:last-child { border-bottom: none; }

.activity-entry.log-success { border-left: 3px solid #198754; }
.activity-entry.log-error   { border-left: 3px solid #dc3545; }
.activity-entry.log-info    { border-left: 3px solid #0d6efd; }
.activity-entry.log-warning { border-left: 3px solid #ffc107; }

.activity-time {
    color: #adb5bd;
    white-space: nowrap;
    flex-shrink: 0;
}

/* ============================================================= */
/* Resume Pipeline Modal                                         */
/* ============================================================= */

/* Подсветка текущего шага в описании */
#resume-modal-description .alert {
    border-left: 4px solid;
}

#resume-modal-description .alert-info    { border-left-color: #0dcaf0; }
#resume-modal-description .alert-warning { border-left-color: #ffc107; }

/* Кнопка запуска шага пайплайна */
#resume-modal-form button.btn:last-child {
    margin-top: 0.25rem;
}

/* Spinner при выполнении шага */
#resume-modal-form button:disabled {
    opacity: 0.8;
}

/* ============================================================= */
/* Tables                                                         */
/* ============================================================= */
.table td { vertical-align: middle; }
.table th { font-size: 0.82rem; font-weight: 600; letter-spacing: 0.03em; }

/* Кнопки действий компактнее */
.btn-group.btn-group-sm .btn { font-size: 0.8rem; }

/* ============================================================= */
/* Cards                                                          */
/* ============================================================= */
.card { box-shadow: 0 1px 4px rgba(0,0,0,0.06); border: 1px solid #e9ecef; }
.card-header {
    background: white;
    border-bottom: 1px solid #e9ecef;
    padding: 0.75rem 1rem;
}

/* ============================================================= */
/* Toasts                                                         */
/* ============================================================= */
.toast { min-width: 280px; }

/* ============================================================= */
/* Loading / Empty / Error states                                 */
/* ============================================================= */
.state-placeholder {
    text-align: center;
    padding: 2rem;
    color: #6c757d;
}

.state-placeholder i { font-size: 2.5rem; display: block; margin-bottom: 0.75rem; }

/* ============================================================= */
/* Responsive tweaks                                             */
/* ============================================================= */
@media (max-width: 768px) {
    .btn-sm { font-size: 0.7rem; padding: 0.15rem 0.4rem; }
    .metric-value { font-size: 1.3rem; }
}

/* ============================================================= */
/* File Preview (js/components/ingestion.js → showFilePreview)   */
/* ============================================================= */

/* Карточка */
.fp-card {
    border: 1px solid #dee2e6;
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 1rem;
    background: #fff;
    opacity: 0;
    transform: translateY(6px);
    transition: opacity .2s ease, transform .2s ease;
}
.fp-card--in {
    opacity: 1;
    transform: translateY(0);
}

/* Заголовок карточки */
.fp-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 12px;
    background: #f8f9fa;
    border-bottom: 1px solid #e9ecef;
}
.fp-header-left {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1;
}
.fp-filename {
    font-size: .85rem;
    font-weight: 600;
    color: #212529;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.fp-size {
    font-size: .75rem;
}

/* Кнопка закрытия */
.fp-close {
    flex-shrink: 0;
    background: none;
    border: 1px solid transparent;
    border-radius: 5px;
    padding: 3px 7px;
    color: #6c757d;
    cursor: pointer;
    line-height: 1;
    transition: all .15s;
}
.fp-close:hover {
    background: #f8d7da;
    border-color: #f5c2c7;
    color: #842029;
}

/* Тело предпросмотра */
.fp-body {
    background: #1a1a2e;
}

/* Скелетон загрузки */
.fp-body--loading {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 160px;
    background: #f8f9fa;
}
.fp-spinner {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 3px solid #dee2e6;
    border-top-color: #0d6efd;
    animation: fp-spin .7s linear infinite;
}
@keyframes fp-spin { to { transform: rotate(360deg); } }

/* Изображение */
.fp-image {
    display: block;
    max-width: 100%;
    max-height: 460px;
    object-fit: contain;
    margin: 0 auto;
    padding: 10px;
}

/* Видео */
.fp-video {
    display: block;
    width: 100%;
    max-height: 460px;
    background: #000;
}

/* PDF */
.fp-pdf {
    display: block;
    width: 100%;
    height: 500px;
    border: none;
}

/* Office / Unknown placeholder */
.fp-office {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 36px 20px;
    text-align: center;
    background: #f8f9fa;
    min-height: 180px;
}
.fp-office i { font-size: 3.5rem; }

/* Текстовый вьюер */
.fp-text {
    display: flex;
    flex-direction: column;
}
.fp-text-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: #16162a;
    border-bottom: 1px solid #2d2d4e;
}
.fp-text-badge {
    font-size: .68rem;
    font-weight: 700;
    letter-spacing: .07em;
    color: #a6e3a1;
    background: rgba(166,227,161,.12);
    border: 1px solid rgba(166,227,161,.25);
    border-radius: 3px;
    padding: 1px 6px;
}
.fp-text-copy {
    font-size: .72rem;
    padding: 2px 8px;
    background: #2d2d4e;
    border: 1px solid #3d3d5e;
    color: #cdd6f4;
    border-radius: 4px;
    transition: all .15s;
}
.fp-text-copy:hover {
    background: #3d3d6e;
    border-color: #89b4fa;
    color: #89b4fa;
}
.fp-text-pre {
    margin: 0;
    padding: 14px;
    max-height: 420px;
    overflow: auto;
    font-family: 'Cascadia Code', 'JetBrains Mono', 'Fira Code', monospace;
    font-size: .78rem;
    line-height: 1.6;
    color: #cdd6f4;
    white-space: pre-wrap;
    word-break: break-word;
    background: transparent;
}
.fp-text-pre::-webkit-scrollbar        { width: 5px; height: 5px; }
.fp-text-pre::-webkit-scrollbar-track  { background: #16162a; }
.fp-text-pre::-webkit-scrollbar-thumb  { background: #3d3d6e; border-radius: 3px; }
.fp-text-more {
    padding: 6px 12px;
    background: #16162a;
    border-top: 1px solid #2d2d4e;
    font-size: .72rem;
    color: #6e6e8e;
    text-align: center;
}


#hybrid-options {
    border-left: 3px solid #0d6efd;
    padding-left: 1rem;
    background: #f8f9fa;
    border-radius: 0.25rem;
    padding: 1rem;
    margin-bottom: 1rem;
}

#hybrid-options .alert-info {
    border-left: 3px solid #0dcaf0;
}

.search-type-badge {
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    text-transform: uppercase;
    font-weight: 600;
}

.search-type-dense {
    background: #0d6efd;
    color: white;
}

.search-type-sparse {
    background: #6c757d;
    color: white;
}

.search-type-hybrid {
    background: #20c997;
    color: white;
}

.search-type-colbert {
    background: #fd7e14;
    color: white;
}

#search-results .search-result-item {
    transition: all 0.2s ease;
}

#search-results .search-result-item:hover {
    box-shadow: 0 0.125rem 0.5rem rgba(0,0,0,0.1);
    transform: translateY(-2px);
}

/* ============================================================
   Document-centric ingestion layout
   ============================================================ */

.ingestion-layout {
    display: flex;
    gap: 0;
    min-height: calc(100vh - 120px);
    align-items: flex-start;
}

/* ---- Left panel: document library ---- */
.doc-library {
    width: 280px;
    min-width: 240px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 0.375rem;
    margin-right: 16px;
    height: calc(100vh - 130px);
    position: sticky;
    top: 16px;
    overflow: hidden;
}

.doc-library-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px 8px;
    border-bottom: 1px solid #e9ecef;
    background: #f8f9fa;
    border-radius: 0.375rem 0.375rem 0 0;
    font-size: 0.85rem;
    font-weight: 600;
    color: #495057;
    flex-shrink: 0;
}

.doc-library-search {
    padding: 8px 8px 4px;
    flex-shrink: 0;
}

.doc-library-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px 0;
}

.doc-library-list::-webkit-scrollbar        { width: 4px; }
.doc-library-list::-webkit-scrollbar-track  { background: transparent; }
.doc-library-list::-webkit-scrollbar-thumb  { background: #ced4da; border-radius: 2px; }

.doc-library-footer {
    padding: 8px;
    border-top: 1px solid #e9ecef;
    flex-shrink: 0;
}

/* ---- Library item ---- */
.doc-library-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 10px;
    cursor: pointer;
    border-radius: 4px;
    margin: 2px 4px;
    transition: background 0.12s;
    min-width: 0;
}

.doc-library-item:hover {
    background: #f0f4ff;
}

.doc-library-item.active {
    background: #e8f0fe;
    border-left: 3px solid #0d6efd;
    padding-left: 7px;
}

.doc-lib-icon {
    font-size: 1.1rem;
    color: #6c757d;
    flex-shrink: 0;
    width: 18px;
    text-align: center;
}

.doc-library-item.active .doc-lib-icon {
    color: #0d6efd;
}

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

.doc-lib-title {
    font-size: 0.8rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: #212529;
    line-height: 1.3;
}

.doc-lib-meta {
    display: flex;
    gap: 5px;
    align-items: center;
    margin-top: 2px;
}

/* ---- Right panel: main content ---- */
.ingestion-main {
    flex: 1;
    min-width: 0;
}

/* ---- Vectorizations table inside details ---- */
.doc-vectorizations {
    border: 1px solid #dee2e6;
    border-radius: 0.375rem;
    overflow: hidden;
}

.doc-vectorizations .table {
    margin-bottom: 0;
    font-size: 0.875rem;
}

/* ---- Duplicate warning tweaks ---- */
#duplicate-warning {
    display: none;
}

/* ---- Responsive: collapse library on small screens ---- */
@media (max-width: 768px) {
    .ingestion-layout {
        flex-direction: column;
    }
    .doc-library {
        width: 100%;
        height: auto;
        max-height: 220px;
        position: static;
        margin-right: 0;
        margin-bottom: 12px;
    }
}

/* ============================================================= */
/* Telegram-style Posts Feed                                      */
/* ============================================================= */
.tg-feed {
    background: #e5e5ea;
    padding: 12px 16px;
    min-height: 200px;
}

.tg-post-card {
    background: #fff;
    border-radius: 12px;
    padding: 12px 14px;
    margin-bottom: 10px;
    box-shadow: 0 1px 2px rgba(0,0,0,.12);
    max-width: 720px;
    word-break: break-word;
}

.tg-post-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}

.tg-post-channel {
    font-weight: 600;
    color: #2b5278;
    font-size: 0.85rem;
}

.tg-post-date {
    color: #8e8e93;
    font-size: 0.78rem;
    white-space: nowrap;
    margin-left: 8px;
}

.tg-post-text {
    font-size: 0.92rem;
    line-height: 1.5;
    color: #222;
    white-space: pre-wrap;
    margin-bottom: 8px;
}

.tg-post-media-wrap {
    margin: 8px 0;
}

.tg-post-media {
    max-width: 100%;
    max-height: 420px;
    border-radius: 8px;
    display: block;
    object-fit: contain;
    background: #f0f0f0;
}

.tg-post-caption {
    font-size: 0.85rem;
    color: #444;
    margin-top: 6px;
    white-space: pre-wrap;
}

.tg-post-reactions {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 8px;
}

.tg-reaction {
    background: #f0f4ff;
    border: 1px solid #d0d9ff;
    border-radius: 20px;
    padding: 2px 8px;
    font-size: 0.82rem;
    color: #3a5fb8;
}

.tg-post-stats {
    display: flex;
    gap: 12px;
    margin-top: 8px;
    color: #8e8e93;
    font-size: 0.78rem;
}

.tg-post-stats i {
    margin-right: 2px;
}

.tg-post-doc-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #f0f4ff;
    border: 1px solid #d0d9ff;
    border-radius: 8px;
    padding: 6px 12px;
    font-size: 0.85rem;
    color: #2b5278;
    text-decoration: none;
    margin-top: 6px;
}

.tg-post-doc-link:hover {
    background: #dce5ff;
}

.tg-no-media-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: #aaa;
    font-size: 0.82rem;
    margin-top: 4px;
}}

/* === Finishing option media thumbnails === */
.fo-thumbs-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
    margin-bottom: 4px;
}
.fo-thumb-item {
    display: flex;
    flex-direction: column;
    gap: 3px;
    width: 88px;
}
.fo-thumb-img {
    width: 88px;
    height: 64px;
    object-fit: cover;
    border-radius: 5px;
    border: 1px solid #dee2e6;
    cursor: zoom-in;
    transition: opacity .15s;
    display: block;
}
.fo-thumb-img:hover { opacity: .8; }
.fo-thumb-remove {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 18px;
    height: 18px;
    background: rgba(0,0,0,.55);
    color: #fff;
    border: none;
    border-radius: 50%;
    font-size: 11px;
    line-height: 18px;
    text-align: center;
    cursor: pointer;
    padding: 0;
    display: none;
}
.fo-thumb-item:hover .fo-thumb-remove { display: block; }
.fo-desc-ta {
    width: 100%;
    box-sizing: border-box;
    font-size: 10px;
    padding: 2px 4px;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    resize: vertical;
    line-height: 1.3;
    background: #f8f9fa;
    color: #333;
}
.fo-desc-ta::placeholder { color: #aaa; font-size: 10px; }
.fo-video-block { display: flex; flex-direction: column; gap: 4px; }
.fo-video-preview {
    width: 100%;
    max-height: 140px;
    border-radius: 5px;
    border: 1px solid #dee2e6;
    background: #000;
}
