/**
 * 参考文献列表 + 详情弹层
 */

.dify-references-container {
    margin-top: 12px;
    padding: 0;
    background: #f8fafc;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
    overflow: hidden;
}

.dify-references-title {
    font-weight: 600;
    margin: 0;
    padding: 10px 12px;
    font-size: 13px;
    color: #1e3a8a;
    line-height: 1.4 !important;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    list-style: none;
    user-select: none;
    background: linear-gradient(180deg, #f8fbff 0%, #f1f5f9 100%);
    border-bottom: 1px solid #e2e8f0;
}

.dify-references-container:not([open]) .dify-references-title {
    border-bottom: none;
}

.dify-references-title::-webkit-details-marker {
    display: none;
}

.dify-references-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.dify-references-icon {
    width: 18px;
    height: 18px;
    border-radius: 5px;
    background: #dbeafe;
    position: relative;
    flex-shrink: 0;
}

.dify-references-icon::before {
    content: '';
    position: absolute;
    inset: 4px 5px;
    border: 1.5px solid #2563eb;
    border-radius: 2px;
}

.dify-references-title .expand-hint {
    font-size: 12px;
    color: #64748b;
    font-weight: 400;
    flex-shrink: 0;
}

.dify-references-list {
    display: flex;
    flex-direction: column;
    gap: 0;
    padding: 6px;
}

.dify-reference-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    text-align: left;
    background: #fff;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid transparent;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
    font: inherit;
    color: inherit;
    margin: 0 0 4px;
}

.dify-reference-item:last-child {
    margin-bottom: 0;
}

.dify-reference-item:hover {
    background: #f8fbff;
    border-color: #bfdbfe;
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.06);
}

.dify-reference-number {
    flex: 0 0 auto;
    width: 22px;
    min-width: 22px;
    height: 22px;
    padding: 0;
    border-radius: 999px;
    background: #eff6ff;
    color: #2563eb;
    font-size: 11px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.dify-reference-main {
    flex: 1;
    min-width: 0;
}

.dify-reference-title {
    display: block;
    font-weight: 560;
    color: #0f172a;
    font-size: 13px;
    line-height: 1.45;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dify-reference-sub {
    margin-top: 3px;
    font-size: 12px;
    color: #64748b;
    line-height: 1.35;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dify-reference-arrow {
    color: #94a3b8;
    font-size: 18px;
    line-height: 1;
    flex-shrink: 0;
}

.dify-reference-item:hover .dify-reference-arrow {
    color: #2563eb;
}

/* ===== 单例弹层（不走 layui layer） ===== */
html.hbm-ref-modal-open,
html.hbm-ref-modal-open body {
    overflow: hidden !important;
}

.hbm-ref-modal-shade {
    position: fixed;
    inset: 0;
    z-index: 21000000;
    background: rgba(15, 23, 42, 0.45);
    opacity: 0;
    pointer-events: none;
    transition: opacity .15s ease;
}

.hbm-ref-modal-shade.is-open {
    opacity: 1;
    pointer-events: auto;
}

.hbm-ref-modal {
    position: fixed;
    z-index: 21000001;
    display: none;
    box-sizing: border-box;
    border-radius: 16px;
    overflow: hidden;
    background: #fff;
    border: 1px solid #e2e8f0;
    box-shadow: 0 24px 64px rgba(15, 23, 42, 0.22);
    transform: none !important;
    margin: 0 !important;
}

.hbm-ref-modal.is-open {
    display: block;
}

.hbm-ref-modal .reference-popup-content {
    background: #fff;
    height: 100%;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.hbm-ref-modal .reference-popup-body {
    flex: 1 1 auto;
    overflow-y: auto;
    min-height: 0;
    -webkit-overflow-scrolling: touch;
}

/* 旧 layui tip 皮肤保留兼容，避免历史缓存样式冲突 */
.layui-layer.dify-reference-tip {
    border-radius: 16px !important;
    overflow: hidden;
    box-shadow: 0 24px 64px rgba(15, 23, 42, 0.22) !important;
    border: 1px solid #e2e8f0;
    position: fixed !important;
    transform: none !important;
    margin: 0 !important;
}

.dify-reference-tip .layui-layer-content {
    padding: 0 !important;
    background: #ffffff;
    border-radius: 16px;
    overflow: hidden;
    height: 100%;
    box-sizing: border-box;
}

.reference-popup-content {
    background: #fff;
}

.reference-popup-header {
    background: linear-gradient(180deg, #f8fbff 0%, #f8fafc 100%);
    border-bottom: 1px solid #e2e8f0;
    padding: 16px 48px 14px 18px;
    position: relative;
    color: #0f172a;
}

.reference-popup-kicker {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}

.reference-popup-badge {
    display: inline-flex;
    align-items: center;
    height: 22px;
    padding: 0 8px;
    border-radius: 999px;
    background: #dbeafe;
    color: #1d4ed8;
    font-size: 12px;
    font-weight: 600;
}

.reference-popup-score {
    display: inline-flex;
    align-items: center;
    height: 22px;
    padding: 0 8px;
    border-radius: 999px;
    background: #ecfdf5;
    color: #047857;
    font-size: 12px;
    font-weight: 500;
}

.reference-popup-cite {
    display: inline-flex;
    align-items: center;
    height: 22px;
    padding: 0 8px;
    border-radius: 999px;
    background: #f1f5f9;
    color: #475569;
    font-size: 12px;
    font-weight: 500;
}

.reference-popup-title {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
    color: #0f172a;
    line-height: 1.45;
    word-wrap: break-word;
    white-space: normal;
}

.reference-popup-heading {
    margin-top: 6px;
    font-size: 12px;
    color: #64748b;
    line-height: 1.4;
}

.reference-popup-body {
    padding: 16px 18px;
    background: #ffffff;
}

.reference-popup-text {
    color: #334155;
    font-size: 14px;
    line-height: 1.7;
    word-wrap: break-word;
    white-space: normal;
}

.reference-popup-text .md-table-wrap {
    margin: 10px 0;
    overflow-x: auto;
}

.reference-popup-text .md-p {
    margin: 0.5em 0;
}

.reference-popup-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 16px;
    border-top: 1px solid #e2e8f0;
    background: #f8fafc;
}

.reference-popup-source {
    font-size: 12px;
    color: #475569;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

.reference-popup-copy {
    flex-shrink: 0;
    height: 32px;
    padding: 0 12px;
    border-radius: 8px;
    border: 1px solid #bfdbfe;
    background: #eff6ff;
    color: #1d4ed8;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.reference-popup-copy:hover {
    background: #dbeafe;
    border-color: #93c5fd;
}

.reference-popup-copy.is-copied {
    background: #ecfdf5;
    border-color: #a7f3d0;
    color: #047857;
}

.reference-popup-close {
    position: absolute;
    right: 12px;
    top: 12px;
    width: 30px;
    height: 30px;
    cursor: pointer;
    font-size: 20px;
    color: #64748b;
    text-align: center;
    line-height: 30px;
    border: none;
    border-radius: 50%;
    background: #e2e8f0;
    padding: 0;
    transition: background 0.15s ease, color 0.15s ease;
}

.reference-popup-close:hover {
    background: #cbd5e1;
    color: #0f172a;
}

@media (max-width: 768px) {
    .dify-references-title {
        padding: 10px;
    }

    .reference-popup-header,
    .reference-popup-body {
        padding: 14px;
    }

    .reference-popup-header {
        padding-right: 44px;
    }

    .reference-popup-footer {
        flex-direction: column;
        align-items: stretch;
    }

    .reference-popup-copy {
        width: 100%;
    }

    .reference-popup-source {
        white-space: normal;
    }
}
