/* ========================================
   HADITH TAKHRIJ
   ======================================== */

/* ── Сворачиваемая полоска поиска тахриджа ── */
.takhrij-bar-wrap {
    max-width: 1200px;
    margin: 0 auto 8px;
    padding: 8px 16px 0;
    box-sizing: border-box;
    width: 100%;
}
.takhrij-bar-pill {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 8px 16px;
    border: 1.5px solid var(--border-gray, #e2e8f0);
    border-radius: 999px;
    background: #fff;
    color: var(--text-dark, #1e293b);
    font: 500 13px/1 'Inter', sans-serif;
    cursor: pointer;
    transition: background .15s, border-color .15s, box-shadow .15s;
}
.takhrij-bar-pill:hover {
    background: #f8fafc;
    border-color: #cbd5e1;
    box-shadow: 0 1px 4px rgba(0,0,0,.05);
}
.takhrij-bar-pill .takhrij-bar-chevron {
    transition: transform .25s ease;
}
.takhrij-bar-pill.open .takhrij-bar-chevron {
    transform: rotate(180deg);
}
.takhrij-bar-dropdown {
    overflow: hidden;
    max-height: 0;
    transition: max-height .25s ease, margin-top .25s ease;
    margin-top: 0;
}
.takhrij-bar-dropdown.open {
    max-height: 1200px;
    margin-top: 12px;
}
.takhrij-bar-dropdown .takhrij-input {
    background: #fff;
    border: 1px solid var(--border-gray, #e2e8f0);
    border-radius: 12px;
    padding: 18px 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,.04);
}

/* ── Split-layout: книги тахриджа ── */
.takhrij-books-layout {
    display: grid;
    grid-template-columns: 260px 1fr;
    gap: 20px;
    max-width: 1280px;
    margin: 0 auto;
    padding: 16px;
    box-sizing: border-box;
}
@media (max-width: 768px) {
    .takhrij-books-layout {
        grid-template-columns: 1fr;
    }
}
.takhrij-books-sidebar .hadith-collection-item {
    cursor: pointer;
}
.takhrij-book-content {
    background: #fff;
    border: 1px solid var(--border-gray, #e2e8f0);
    border-radius: 12px;
    padding: 24px;
    min-height: 400px;
}
.takhrij-empty {
    text-align: center;
    padding: 60px 20px;
    color: #94a3b8;
}
.takhrij-empty-icon { font-size: 48px; margin-bottom: 12px; }
.takhrij-empty-title { font: 600 16px 'Inter', sans-serif; color: #475569; margin-bottom: 4px; }
.takhrij-empty-sub { font: 400 13px 'Inter', sans-serif; }

.takhrij-book-header {
    border-bottom: 1px solid #e2e8f0;
    padding-bottom: 16px;
    margin-bottom: 20px;
}
.takhrij-book-name {
    font: 700 22px/1.3 'Inter', sans-serif;
    color: #0f172a;
    margin: 0 0 6px;
}
.takhrij-book-author {
    font: 500 14px 'Inter', sans-serif;
    color: #64748b;
    margin-bottom: 8px;
}
.takhrij-book-desc {
    font: 400 13px/1.6 'Inter', sans-serif;
    color: #475569;
}

.takhrij-level-row {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    margin-bottom: 20px;
}
.takhrij-level-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1 1 240px;
}
.takhrij-level-label {
    font: 600 11px/1 'Inter', sans-serif;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: #64748b;
}
.takhrij-level-group select {
    padding: 9px 12px;
    border: 1.5px solid #e2e8f0;
    border-radius: 8px;
    font: 400 13px 'Inter', sans-serif;
    background: #fff;
    outline: none;
    cursor: pointer;
}
.takhrij-level-group select:focus { border-color: #0e9f6e; }

.takhrij-hadiths-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.takhrij-hadith-card {
    border: 1px solid #e2e8f0;
    border-inline-start: 3px solid #0e9f6e;
    border-radius: 8px;
    padding: 16px 18px;
    background: #fafbfc;
    position: relative;
}
.takhrij-hadith-num {
    display: inline-block;
    font: 600 11px 'Inter', sans-serif;
    color: #64748b;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 999px;
    padding: 2px 8px;
    margin-bottom: 8px;
}
.takhrij-source-chip[disabled] {
    opacity: 0.7;
    pointer-events: none;
}
.takhrij-hadith-text {
    font: 500 19px/1.9 'Amiri', 'Scheherazade New', serif;
    color: #0f172a;
    margin-bottom: 12px;
}
.takhrij-hadith-sources {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.takhrij-source-chip {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    background: #fff;
    border: 1px solid #cbd5e1;
    border-radius: 999px;
    font: 500 12px 'Inter', sans-serif;
    color: #334155;
    cursor: pointer;
    transition: all .15s;
}
.takhrij-source-chip:hover {
    background: #0e9f6e;
    color: #fff;
    border-color: #0e9f6e;
}


/* ── Wrapper ── */
.takhrij-section {
    flex: 1;
    max-width: 900px;
    margin: 0 auto;
    width: 100%;
    box-sizing: border-box;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* ── Форма ввода ── */
.takhrij-input {
    background: var(--white);
    border-radius: 14px;
    border: 1px solid var(--border-gray);
    padding: 28px;
    box-shadow: var(--shadow-sm);
}

.takhrij-input h2 {
    font-family: 'Scheherazade New', 'Amiri', serif;
    font-size: 22px;
    color: #1f2937;
    margin: 0 0 8px;
}

.takhrij-desc {
    font-size: 14px;
    color: #6b7280;
    line-height: 1.7;
    margin: 0 0 20px;
}

.takhrij-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.takhrij-textarea-wrap {
    position: relative;
}

.takhrij-textarea-wrap textarea {
    width: 100%;
    box-sizing: border-box;
    padding: 14px 16px;
    border: 1.5px solid var(--border-gray);
    border-radius: 10px;
    font-family: 'Scheherazade New', 'Amiri', serif;
    font-size: 18px;
    line-height: 1.8;
    color: #1f2937;
    background: white;
    resize: vertical;
    transition: border-color 0.2s, box-shadow 0.2s;
    direction: rtl;
}
.takhrij-textarea-wrap textarea:focus {
    outline: none;
    border-color: var(--emerald);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--emerald) 10%, transparent);
}
.takhrij-textarea-wrap textarea::placeholder {
    color: #9ca3af;
    font-size: 15px;
}

.takhrij-lang-hint {
    display: block;
    font-size: 12px;
    color: #9ca3af;
    margin-top: 6px;
    text-align: start;
}

.takhrij-options {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}

.takhrij-option {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 13px;
    color: #374151;
    font-weight: 500;
    cursor: pointer;
    user-select: none;
}
.takhrij-option input[type="checkbox"] {
    accent-color: var(--emerald);
    width: 15px;
    height: 15px;
    cursor: pointer;
}

.takhrij-submit {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 28px;
    background: var(--emerald);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 700;
    font-family: 'Inter', sans-serif;
    cursor: pointer;
    transition: background 0.2s;
    align-self: flex-start;
}
.takhrij-submit:hover { background: var(--emerald-dark); }
.takhrij-submit:disabled { opacity: 0.6; cursor: not-allowed; }

/* ── Область результатов ── */
.takhrij-results {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.takhrij-summary {
    background: #ecfdf5;
    border: 1px solid #a7f3d0;
    border-radius: 10px;
    padding: 12px 20px;
    font-size: 14px;
    color: #065f46;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}
.takhrij-summary b { color: #047857; }

/* Группа по сборнику */
.takhrij-group {
    background: var(--white);
    border-radius: 12px;
    border: 1px solid var(--border-gray);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.takhrij-group-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 20px;
    background: #f9fafb;
    border-bottom: 1px solid var(--border-gray);
    margin: 0;
    gap: 12px;
}

.takhrij-collection-name {
    font-family: 'Scheherazade New', 'Amiri', serif;
    font-size: 16px;
    color: #1f2937;
    font-weight: 600;
}

.takhrij-group-count {
    font-size: 12px;
    font-weight: 700;
    color: var(--emerald);
    background: #ecfdf5;
    border-radius: 9999px;
    padding: 3px 10px;
    white-space: nowrap;
}

.takhrij-group-items {
    display: flex;
    flex-direction: column;
}

/* Карточка найденного хадиса */
.takhrij-item {
    padding: 16px 20px;
    border-bottom: 1px solid #f3f4f6;
}
.takhrij-item:last-child { border-bottom: none; }

.takhrij-item-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}

.takhrij-item-num {
    font-size: 13px;
    font-weight: 700;
    color: #374151;
}

.takhrij-match-badge {
    padding: 3px 10px;
    border-radius: 9999px;
    font-size: 11px;
    font-weight: 700;
}
.takhrij-match-badge.exact    { background: #d1fae5; color: #059669; }
.takhrij-match-badge.similar  { background: #fef3c7; color: #c5a059; }
.takhrij-match-badge.mention  { background: #f3f4f6; color: #6b7280; }

.takhrij-item-kitab {
    font-size: 12px;
    color: #9ca3af;
    direction: rtl;
    font-family: 'Scheherazade New', 'Amiri', serif;
}

.takhrij-item-text {
    font-family: 'Scheherazade New', 'Amiri', serif;
    font-size: 16px;
    line-height: 1.9;
    color: #1f2937;
    direction: rtl;
    text-align: end;
    background: #f9fafb;
    border-radius: 8px;
    padding: 10px 14px;
}

.takhrij-item-diff {
    margin-top: 8px;
    font-size: 13px;
    color: #6b7280;
    line-height: 1.6;
}

/* Состояние загрузки тахриджа */
.takhrij-loading {
    text-align: center;
    padding: 32px;
    color: #6b7280;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.takhrij-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid #e5e7eb;
    border-top-color: var(--emerald);
    border-radius: 50%;
    animation: hadith-spin 0.7s linear infinite;
}

/* Пустой результат */
.takhrij-no-results {
    text-align: center;
    padding: 40px;
    color: #9ca3af;
    background: var(--white);
    border-radius: 12px;
    border: 1px solid var(--border-gray);
}
.takhrij-no-results-icon  { font-size: 36px; margin-bottom: 10px; }
.takhrij-no-results-title { font-size: 15px; font-weight: 700; color: #374151; margin-bottom: 6px; }
.takhrij-no-results-hint  { font-size: 13px; color: #9ca3af; }

/* ══════════════════════════════════════════════
   СТАТИЧЕСКИЕ ПЕРЕКРЁСТНЫЕ ССЫЛКИ (takhrij_refs)
   ══════════════════════════════════════════════ */

/* Контейнер бейджей под хадисом */
.takhrij-static-refs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 4px 0;
}

/* Бейдж-ссылка */
.takhrij-ref-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 14px;
    border-radius: 9999px;
    border: 1.5px solid;
    cursor: pointer;
    font-size: 13px;
    font-family: 'Inter', sans-serif;
    font-weight: 500;
    transition: opacity 0.15s, transform 0.1s;
    background: none;
    line-height: 1;
    white-space: nowrap;
}
.takhrij-ref-badge:hover  { opacity: 0.8; transform: translateY(-1px); }
.takhrij-ref-badge:active { transform: translateY(0); }

.takhrij-ref-badge.exact {
    background: #d1fae5;
    border-color: #059669;
    color: #065f46;
}
.takhrij-ref-badge.similar {
    background: #fef3c7;
    border-color: #d97706;
    color: #92400e;
}
.takhrij-ref-badge.related {
    background: #f3f4f6;
    border-color: #9ca3af;
    color: #374151;
}

.takhrij-ref-name { font-family: 'Scheherazade New', 'Amiri', serif; font-size: 14px; }
.takhrij-ref-num  { font-weight: 700; font-variant-numeric: tabular-nums; }

/* ══════════════════════════════════════════════
   ПОПАП ТАХРИДЖА
   ══════════════════════════════════════════════ */

.takhrij-popup-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1100;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
}
.takhrij-popup-overlay.open { display: flex; }

.takhrij-popup {
    background: var(--white, #fff);
    border-radius: 16px;
    width: 100%;
    max-width: 680px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
    overflow: hidden;
}

.takhrij-popup-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 18px 24px;
    border-bottom: 1px solid #e5e7eb;
    flex-shrink: 0;
}

.takhrij-popup-title {
    font-family: 'Scheherazade New', 'Amiri', serif;
    font-size: 18px;
    color: #1f2937;
    font-weight: 600;
    line-height: 1.3;
}

.takhrij-popup-close {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 18px;
    color: #9ca3af;
    padding: 4px 8px;
    border-radius: 6px;
    line-height: 1;
    flex-shrink: 0;
    transition: color 0.15s, background 0.15s;
}
.takhrij-popup-close:hover { color: #374151; background: #f3f4f6; }

.takhrij-popup-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.takhrij-popup-matn {
    font-family: 'Scheherazade New', 'Amiri', serif;
    font-size: 19px;
    line-height: 2;
    color: #1f2937;
    direction: rtl;
    text-align: end;
    background: #f9fafb;
    border-radius: 10px;
    padding: 14px 18px;
}

.takhrij-popup-kitab {
    font-family: 'Scheherazade New', 'Amiri', serif;
    font-size: 13px;
    color: #9ca3af;
    direction: rtl;
    text-align: end;
    padding: 0 4px;
}

.takhrij-popup-transl {
    font-size: 14px;
    color: #374151;
    line-height: 1.75;
    border-top: 1px solid #f3f4f6;
    padding-top: 12px;
}

.takhrij-popup-footer {
    padding: 14px 24px;
    border-top: 1px solid #e5e7eb;
    display: flex;
    justify-content: flex-end;
    flex-shrink: 0;
}

.takhrij-popup-nav-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    background: var(--emerald, #059669);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    font-family: 'Inter', sans-serif;
    cursor: pointer;
    transition: background 0.2s;
}
.takhrij-popup-nav-btn:hover { background: var(--emerald-dark, #047857); }

/* Подсветка целевого хадиса при навигации из тахриджа */
@keyframes takhrij-pulse {
    0%   { box-shadow: 0 0 0 0 color-mix(in srgb, var(--emerald) 50%, transparent); }
    60%  { box-shadow: 0 0 0 12px color-mix(in srgb, var(--emerald) 10%, transparent); }
    100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--emerald) 0%, transparent); }
}
.takhrij-target-highlight {
    animation: takhrij-pulse 0.9s ease-out 2;
    outline: 2px solid var(--emerald, #059669);
    outline-offset: 4px;
    border-radius: 12px;
}

/* Адаптив: на мобильном попап прилипает к низу */
@media (max-width: 600px) {
    .takhrij-popup-overlay {
        align-items: flex-end;
        padding: 0;
    }
    .takhrij-popup {
        border-radius: 20px 20px 0 0;
        max-height: 82vh;
    }
}
