/* Страница умного поиска — отдельные стили, без toolbar каталога */
@import url("ui-feedback.css");

.rag-page-body {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.rag-page {
    flex: 1;
    width: 100%;
    max-width: 920px;
    margin: 0 auto;
    padding: 20px 24px 32px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.rag-search-card,
.rag-index-panel,
.rag-sources-card,
.rag-answer {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px 22px;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
}

.rag-card-title {
    margin: 0 0 14px;
    font-size: 17px;
    font-weight: 600;
    color: var(--text);
}

.rag-field-label {
    display: block;
    margin-bottom: 8px;
    font-size: 13px;
    font-weight: 500;
    color: var(--muted);
}

.rag-query-input {
    width: 100%;
    min-height: 110px;
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 15px;
    line-height: 1.5;
    font-family: inherit;
    resize: vertical;
    background: #fafbfc;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.rag-query-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.15);
    background: #fff;
}

.rag-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px 24px;
    margin-top: 18px;
    padding-top: 18px;
    border-top: 1px solid var(--border);
}

.rag-controls-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.rag-btn {
    padding: 10px 18px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.rag-btn-primary {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.rag-btn-primary:hover {
    background: #0d6b63;
}

.rag-btn-advise {
    min-width: 220px;
    padding-left: 20px;
    padding-right: 20px;
}

.hidden {
    display: none !important;
}

.rag-btn-secondary {
    background: #fff;
    color: var(--accent);
    border-color: var(--accent);
}

.rag-btn-secondary:hover {
    background: #ecfdf5;
}

.rag-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.rag-controls-options {
    display: flex;
    flex-wrap: wrap;
    gap: 14px 20px;
}

.rag-option {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: var(--text);
    cursor: pointer;
    user-select: none;
}

.rag-option input {
    width: 16px;
    height: 16px;
    margin: 0;
    accent-color: var(--accent);
}

/* Индикатор индексации (админка) */
.rag-index-panel {
    padding-bottom: 0;
}

.rag-index-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.rag-index-header .rag-card-title {
    margin: 0;
}

.rag-index-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
    background: #e5e7eb;
    color: #374151;
}

.rag-index-badge.is-idle {
    background: #d1fae5;
    color: #065f46;
}

.rag-index-badge.is-busy {
    background: #dbeafe;
    color: #1e40af;
}

.rag-index-badge.is-done {
    background: #d1fae5;
    color: #047857;
}

.rag-index-badge.is-error {
    background: #fee2e2;
    color: #b91c1c;
}

.rag-progress-track {
    width: 100%;
    height: 10px;
    border-radius: 999px;
    background: #e5e7eb;
    overflow: hidden;
}

.rag-progress-bar {
    height: 100%;
    width: 0;
    border-radius: 999px;
    background: linear-gradient(90deg, #0f766e, #14b8a6);
    transition: width 0.35s ease;
}

.rag-index-panel.is-busy .rag-progress-bar {
    background: linear-gradient(90deg, #0f766e, #5eead4, #0f766e);
    background-size: 200% 100%;
    animation: rag-progress-pulse 1.4s ease-in-out infinite;
}

.rag-index-panel.is-error .rag-progress-bar {
    background: #dc2626;
}

.rag-index-panel.is-done .rag-progress-bar {
    background: #059669;
}

@keyframes rag-progress-pulse {
    0% {
        background-position: 100% 0;
    }
    100% {
        background-position: -100% 0;
    }
}

.rag-index-meta {
    margin: 10px 0 0;
    font-size: 13px;
    line-height: 1.45;
    color: var(--muted);
}

/* Статус запроса */
.rag-status {
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 14px;
    background: #ecfeff;
    border: 1px solid #a5f3fc;
    color: var(--text);
}

.rag-status.hidden {
    display: none;
}

.rag-status.is-error {
    background: #fee2e2;
    border-color: #fca5a5;
}

.rag-status.is-loading {
    background: #eff6ff;
    border-color: #93c5fd;
}

.rag-status-loading {
    display: flex;
    align-items: center;
    gap: 12px;
}

.rag-status-text {
    line-height: 1.45;
}

/* Анимация работы LLM */
.rag-llm-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #bfdbfe;
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: rag-spin 0.85s linear infinite;
    flex-shrink: 0;
}

.rag-llm-spinner-inline {
    width: 22px;
    height: 22px;
    border-width: 2px;
}

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

.rag-llm-dots {
    display: flex;
    gap: 6px;
    justify-content: center;
    margin-top: 12px;
}

.rag-llm-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
    animation: rag-dot-bounce 1.2s ease-in-out infinite;
}

.rag-llm-dots span:nth-child(2) {
    animation-delay: 0.15s;
}

.rag-llm-dots span:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes rag-dot-bounce {
    0%,
    80%,
    100% {
        transform: scale(0.65);
        opacity: 0.45;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

.rag-llm-overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(15, 23, 42, 0.28);
    backdrop-filter: blur(2px);
    pointer-events: none;
}

.rag-llm-overlay.hidden {
    display: none;
}

.rag-llm-overlay-card {
    max-width: 360px;
    width: 100%;
    padding: 28px 32px 24px;
    border-radius: 14px;
    background: #fff;
    border: 1px solid var(--border);
    box-shadow: 0 12px 40px rgba(15, 23, 42, 0.18);
    text-align: center;
}

.rag-llm-overlay-card .rag-llm-spinner {
    margin: 0 auto 16px;
}

.rag-llm-overlay-text {
    margin: 0;
    font-size: 15px;
    font-weight: 500;
    line-height: 1.45;
    color: var(--text);
}

body.rag-llm-busy .rag-query-input {
    opacity: 0.72;
}

.rag-search-card.is-llm-processing,
.rag-sources-card.is-llm-processing {
    animation: rag-card-pulse 2s ease-in-out infinite;
}

.rag-recommendations-card.is-llm-processing {
    border-color: #93c5fd;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12);
}

@keyframes rag-card-pulse {
    0%,
    100% {
        box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
    }
    50% {
        box-shadow: 0 4px 18px rgba(59, 130, 246, 0.14);
    }
}

.rag-sources-loading {
    list-style: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    padding: 28px 20px;
    border: none;
    background: linear-gradient(135deg, #f8fafc 0%, #eff6ff 100%);
    border-radius: 10px;
}

.rag-sources-loading-text {
    text-align: center;
}

.rag-sources-loading-title {
    display: block;
    font-size: 15px;
    font-weight: 500;
    color: var(--text);
}

.rag-sources-loading-hint {
    display: block;
    margin-top: 4px;
    font-size: 13px;
    color: var(--muted);
}

.rag-llm-progress {
    width: 100%;
    max-width: 280px;
    height: 4px;
    border-radius: 999px;
    background: #e2e8f0;
    overflow: hidden;
}

.rag-llm-progress-bar {
    display: block;
    width: 40%;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--accent), #38bdf8, var(--accent));
    background-size: 200% 100%;
    animation: rag-progress-slide 1.4s ease-in-out infinite;
}

@keyframes rag-progress-slide {
    0% {
        transform: translateX(-120%);
    }
    100% {
        transform: translateX(320%);
    }
}

.rag-llm-skeleton {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 4px 0 8px;
}

.rag-llm-skeleton-line {
    height: 14px;
    border-radius: 6px;
    background: linear-gradient(90deg, #e2e8f0 0%, #f1f5f9 45%, #e2e8f0 90%);
    background-size: 200% 100%;
    animation: rag-shimmer 1.5s ease-in-out infinite;
}

.rag-llm-skeleton-line-wide {
    width: 88%;
    height: 18px;
}

.rag-llm-skeleton-cards {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 8px;
}

.rag-llm-skeleton-card {
    height: 72px;
    border-radius: 10px;
    background: linear-gradient(90deg, #e2e8f0 0%, #f8fafc 50%, #e2e8f0 100%);
    background-size: 200% 100%;
    animation: rag-shimmer 1.5s ease-in-out infinite;
}

.rag-llm-skeleton-card:nth-child(2) {
    animation-delay: 0.2s;
}

@keyframes rag-shimmer {
    0% {
        background-position: 100% 0;
    }
    100% {
        background-position: -100% 0;
    }
}

@media (prefers-reduced-motion: reduce) {
    .rag-llm-spinner,
    .rag-llm-dots span,
    .rag-llm-progress-bar,
    .rag-llm-skeleton-line,
    .rag-llm-skeleton-card,
    .rag-search-card.is-llm-processing,
    .rag-sources-card.is-llm-processing {
        animation: none;
    }

    .rag-llm-progress-bar {
        width: 100%;
        transform: none;
    }
}

/* Список товаров */
.rag-sources-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.rag-product-card {
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    background: #f8fafc;
}

.rag-product-card.is-expanded {
    border-color: var(--accent);
    box-shadow: 0 2px 8px rgba(15, 118, 110, 0.12);
}

.rag-product-top {
    display: flex;
    align-items: stretch;
    gap: 10px;
    padding-right: 12px;
}

.rag-product-header {
    width: auto;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
    border: none;
    background: transparent;
    cursor: pointer;
    text-align: left;
    font-family: inherit;
}

.rag-product-header:hover {
    background: #eef2ff;
}

.rag-source-cart-btn {
    align-self: center;
    flex-shrink: 0;
    padding: 9px 16px;
    white-space: nowrap;
}

.rag-product-summary {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.rag-product-name {
    font-size: 15px;
    font-weight: 500;
    color: var(--text);
}

.rag-toggle-label {
    font-size: 13px;
    color: var(--accent);
    white-space: nowrap;
}

.rag-toggle-icon {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    background: #e0f2f1;
    color: var(--accent);
    font-size: 18px;
    font-weight: 600;
    flex-shrink: 0;
}

.rag-product-body {
    padding: 0 16px 16px;
    border-top: 1px solid var(--border);
    background: #fff;
}

.rag-product-body.hidden {
    display: none;
}

.rag-product-details-inner {
    padding-top: 14px;
}

.rag-detail-block {
    margin-bottom: 14px;
}

.rag-detail-label {
    margin: 0 0 6px;
    font-size: 13px;
    font-weight: 600;
    color: var(--accent);
}

.rag-detail-text {
    margin: 0;
    line-height: 1.5;
    font-size: 14px;
    color: var(--text);
}

.rag-detail-text .field-text {
    margin: 0 0 8px;
    white-space: pre-wrap;
}

.rag-detail-text .field-intro {
    margin-bottom: 10px;
}

.rag-detail-text .field-subtitle {
    margin: 14px 0 8px;
    font-size: 13px;
    font-weight: 600;
    color: var(--accent);
}

.rag-detail-text .field-list {
    margin: 0 0 12px;
    padding-left: 22px;
}

.rag-detail-text .field-list li {
    margin-bottom: 8px;
    line-height: 1.45;
}

.rag-detail-text .field-list li::marker {
    color: var(--accent);
}

.rag-detail-empty {
    margin: 0;
    color: var(--muted);
    font-style: italic;
}

.rag-detail-terms {
    margin: 12px 0 0;
    font-size: 14px;
}

.rag-tag {
    display: inline-block;
    margin: 0 6px 6px 0;
    padding: 2px 8px;
    border-radius: 999px;
    background: #e0f2f1;
    font-size: 12px;
}

.rag-detail-links-title {
    margin: 12px 0 6px;
    font-size: 14px;
}

.rag-product-body ul {
    margin: 0;
    padding-left: 18px;
}

.rag-product-body a {
    color: var(--accent);
    word-break: break-all;
}

.rag-product-footer {
    margin: 12px 0 0;
    padding-top: 12px;
    border-top: 1px dashed var(--border);
}

.rag-product-link {
    font-weight: 500;
}

.rag-sources-empty {
    color: var(--muted);
    font-style: italic;
    background: transparent;
    border: none;
    box-shadow: none;
    padding: 6px 0;
}

.rag-sources-empty.is-initial {
    padding: 4px 0;
}

.rag-sources-list.has-results .rag-sources-empty {
    display: none;
}

.rag-source-code {
    font-weight: 600;
    color: var(--accent);
}

.rag-meta {
    color: var(--muted);
    font-size: 13px;
}

@media (max-width: 640px) {
    .rag-page {
        padding: 16px;
        gap: 16px;
    }

    .rag-controls {
        flex-direction: column;
        align-items: stretch;
    }

    .rag-controls-actions {
        flex-direction: column;
    }

    .rag-btn {
        width: 100%;
    }

    .rag-product-top {
        flex-direction: column;
        padding-right: 0;
    }

    .rag-product-header {
        width: 100%;
    }

    .rag-source-cart-btn {
        align-self: stretch;
        margin: 0 16px 14px;
    }

    .rag-index-header {
        flex-direction: column;
        align-items: flex-start;
    }
}

/* Рекомендации LLM — карточки товаров */
.rag-recommendations-hint {
    margin: -4px 0 16px;
    font-size: 14px;
    color: var(--muted);
    line-height: 1.45;
}

.rag-guest-hint {
    margin: -4px 0 16px;
    font-size: 14px;
    color: var(--muted);
    line-height: 1.45;
}

.rag-guest-hint a {
    color: var(--accent);
}

.rag-recommendations-text.rec-formatted {
    white-space: normal;
}

.rec-advice {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.rec-intro .rec-lead {
    margin: 0;
    font-size: 15px;
    line-height: 1.55;
    color: var(--text);
}

.rec-query {
    margin: 10px 0 0;
    padding: 10px 14px;
    border-radius: 8px;
    background: #f0fdfa;
    border: 1px solid #99f6e4;
    font-size: 14px;
    line-height: 1.45;
}

.rec-query-label {
    font-weight: 600;
    color: var(--accent);
}

.rec-summary {
    margin: 0;
    font-size: 13px;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.rec-cards {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.rec-full-list-note {
    margin: 0;
    padding: 12px 14px;
    border: 1px solid #99f6e4;
    border-radius: 8px;
    background: #f0fdfa;
    color: var(--text);
    font-size: 14px;
    line-height: 1.45;
}

.rec-card {
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    background: #fff;
    box-shadow: 0 1px 4px rgba(15, 23, 42, 0.06);
    transition: box-shadow 0.15s ease, border-color 0.15s ease;
}

.rec-card:hover {
    border-color: #99f6e4;
    box-shadow: 0 4px 14px rgba(13, 148, 136, 0.12);
}

.rec-card-header {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
    background: linear-gradient(135deg, #f0fdfa 0%, #ecfeff 100%);
    border-bottom: 1px solid var(--border);
}


.rec-card-body {
    padding: 14px 16px 16px;
    display: flex;
    flex-direction: column;
    gap: 0;
    min-height: 72px;
}

.rec-card-content {
    display: flex;
    flex-direction: column;
    gap: 12px;
    flex: 1;
}

.rec-card-footer {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    margin-top: auto;
    padding-top: 14px;
}

.rec-card-footer-inner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 10px 16px;
    width: 100%;
}

.rec-add-cart-btn {
    flex-shrink: 0;
    padding: 9px 20px;
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
}

.rec-price {
    margin: 0;
    font-size: 1.35rem;
    font-weight: 700;
    line-height: 1;
    color: #0f766e;
    text-align: right;
    white-space: nowrap;
}

.rec-card-title-wrap {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    min-width: 0;
    flex: 1;
}

.rec-code {
    flex-shrink: 0;
    min-width: 44px;
    padding: 6px 10px;
    border-radius: 8px;
    background: var(--accent);
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    text-align: center;
    line-height: 1.2;
}

.rec-name {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    line-height: 1.35;
    color: var(--text);
}

.rec-badge {
    flex-shrink: 0;
    padding: 5px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.2;
    white-space: nowrap;
}

.rec-badge-high {
    background: #d1fae5;
    color: #065f46;
    border: 1px solid #6ee7b7;
}

.rec-badge-medium {
    background: #fef3c7;
    color: #92400e;
    border: 1px solid #fcd34d;
}

.rec-badge-default {
    background: #f1f5f9;
    color: #475569;
    border: 1px solid var(--border);
}

.rec-row {
    display: grid;
    grid-template-columns: minmax(88px, 110px) 1fr;
    gap: 8px 14px;
    align-items: start;
}

.rec-row-label {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--accent);
    padding-top: 2px;
}

.rec-row-text {
    margin: 0;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text);
}

.rec-row-text.rec-muted {
    color: var(--muted);
    font-style: italic;
}

.rec-advice-markdown .rec-markdown {
    font-size: 15px;
    line-height: 1.55;
}

/* Сохранённые позиции и история */
.rag-saved-card,
.rag-history-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px 22px;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
}

.rag-panel-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px 16px;
    margin-bottom: 8px;
}

.rag-panel-head .rag-card-title {
    margin-bottom: 0;
}

.rag-panel-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.rag-btn-small {
    padding: 7px 12px;
    font-size: 13px;
}

.rag-saved-hint {
    margin: 0 0 14px;
    font-size: 13px;
    color: var(--muted);
    line-height: 1.45;
}

.rag-saved-list,
.rag-history-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.rag-saved-item {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 4px 12px;
    align-items: center;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #f8fafc;
}

.rag-saved-main {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 8px;
    min-width: 0;
}

.rag-saved-code {
    font-weight: 700;
    color: var(--accent);
    flex-shrink: 0;
}

.rag-saved-name {
    font-size: 14px;
    line-height: 1.35;
}

.rag-saved-meta {
    grid-column: 1;
    font-size: 12px;
    color: var(--muted);
}

.rag-saved-remove {
    grid-row: 1 / span 2;
    grid-column: 2;
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 6px;
    background: #fee2e2;
    color: #991b1b;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
}

.rag-saved-remove:hover {
    background: #fecaca;
}

.rag-history-item {
    margin: 0;
}

.rag-history-btn {
    width: 100%;
    text-align: left;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    cursor: pointer;
    font-family: inherit;
    transition: border-color 0.15s ease, background 0.15s ease;
}

.rag-history-btn:hover {
    border-color: var(--accent);
    background: #f0fdfa;
}

.rag-history-query {
    display: block;
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
    line-height: 1.4;
}

.rag-history-meta {
    display: block;
    margin-top: 4px;
    font-size: 12px;
    color: var(--muted);
}

.rec-fallback-note {
    margin: 0 0 14px;
    padding: 10px 12px;
    border-radius: 8px;
    background: #fffbeb;
    border: 1px solid #fcd34d;
    color: #92400e;
    font-size: 14px;
    line-height: 1.45;
}

@media (max-width: 640px) {
    .rec-card-header {
        flex-direction: column;
        align-items: stretch;
    }

    .rec-badge {
        align-self: flex-start;
    }

    .rec-row {
        grid-template-columns: 1fr;
        gap: 4px;
    }
}
