/**
 * 知识库内部链接（kb-link）样式
 *
 * 覆盖以下场景：
 *   - 详情页（.knowledge-content / #detailMain / #detailPanelMain）
 *   - 编辑器内（.ql-editor）
 *   - "选择知识库" 选择器对话框
 *   - 详情页"返回上一篇"小按钮
 *   - 暗色模式（[data-theme="dark"]）
 */

:root {
    --kb-link-color: #2563eb;          /* blue-600 */
    --kb-link-color-hover: #1d4ed8;    /* blue-700 */
    --kb-link-bg-hover: rgba(37, 99, 235, 0.08);
    --kb-link-border: rgba(37, 99, 235, 0.25);
    --kb-link-invalid: #9ca3af;        /* gray-400 */
}

[data-theme="dark"],
html.dark {
    --kb-link-color: #60a5fa;          /* blue-400 */
    --kb-link-color-hover: #93c5fd;    /* blue-300 */
    --kb-link-bg-hover: rgba(96, 165, 250, 0.12);
    --kb-link-border: rgba(96, 165, 250, 0.35);
    --kb-link-invalid: #6b7280;        /* gray-500 */
}

/* ============================================================
 * 1. 内部链接（详情页 + 编辑器内通用样式）
 * ============================================================ */

a.kb-link,
a.kb-link:link,
a.kb-link:visited {
    /* 覆盖 mobile.css 的全局 inline-flex，避免整条链接被挪到下一行 */
    display: inline;
    color: var(--kb-link-color);
    text-decoration: none;
    background-image: linear-gradient(transparent calc(100% - 1px), var(--kb-link-border) 1px);
    background-repeat: no-repeat;
    background-size: 100% 100%;
    border-radius: 3px;
    padding: 1px 4px 1px 2px;
    margin: 0 1px;
    cursor: pointer;
    font-weight: 500;
    transition: background-color 0.15s ease, color 0.15s ease;
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: break-word;
}

a.kb-link::before {
    content: "\eeb7"; /* 超链接图标 */
    font-family: "remixicon" !important;
    font-style: normal;
    font-weight: normal;
    font-variant: normal;
    text-transform: none;
    line-height: 1;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    display: inline-block;
    margin-right: 3px;
    font-size: 0.92em;
    vertical-align: -0.08em;
    opacity: 0.85;
}

a.kb-link:hover {
    color: var(--kb-link-color-hover);
    background-color: var(--kb-link-bg-hover);
    background-image: linear-gradient(transparent calc(100% - 1px), var(--kb-link-color-hover) 1px);
}

a.kb-link:focus-visible {
    outline: 2px solid var(--kb-link-color);
    outline-offset: 2px;
}

/* 失效链接样式 */
a.kb-link.kb-link--invalid,
a.kb-link.kb-link--invalid:hover {
    color: var(--kb-link-invalid) !important;
    background: none !important;
    background-image: none !important;
    text-decoration: line-through;
    cursor: not-allowed;
}

/* 编辑器内同步样式（让所见即所得） */
.ql-editor a.kb-link {
    pointer-events: auto;
}

/* ============================================================
 * 2. 详情页"返回上一篇"按钮
 * ============================================================ */

/*
 * 外观不写在这里：按钮挂着 .detail-action-btn，与标题行右侧的收藏/编辑/导出
 * 走同一条规则（css/detail-export.css 的 `.detail-title-row .detail-action-btn`），
 * 纸感主题的覆盖也在 reading-theme.css 里按同一选择器给。
 * 这里原先有一份自己的高度/字号/蓝色 hover，结果同一行里出现了两种按钮。
 * 本文件只负责窄屏隐藏：窄屏详情用 #detailPanelBackBtn 上的角标表达「可返回」。
 */
@media (max-width: 1023px) {
    .kb-link-back-btn {
        display: none;
    }
}

/* 移动端返回箭头高亮（栈非空时） */
.detail-panel-back.has-kb-link-back {
    color: var(--kb-link-color);
}

.detail-panel-back.has-kb-link-back::after {
    content: attr(data-kb-back-count);
    position: absolute;
    top: 4px;
    right: 4px;
    min-width: 14px;
    height: 14px;
    padding: 0 3px;
    border-radius: 7px;
    background: var(--kb-link-color);
    color: #fff;
    font-size: 10px;
    line-height: 14px;
    text-align: center;
    font-weight: 600;
}

.detail-panel-back {
    position: relative;
}

/* ============================================================
 * 3. 选择器对话框（KbLinkPicker）
 * ============================================================ */

.kb-link-picker {
    display: flex;
    flex-direction: column;
    min-height: 420px;
    max-height: 65vh;
}

.kb-link-picker-search {
    position: relative;
    margin-bottom: 12px;
    flex-shrink: 0;
}

.kb-link-picker .kb-link-picker-search-icon {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: #9ca3af;
    font-size: 18px;
    line-height: 1;
    pointer-events: none;
    z-index: 1;
}

.kb-link-picker .kb-link-picker-input {
    box-sizing: border-box;
    width: 100%;
    height: 44px;
    padding-top: 0;
    padding-right: 40px;
    padding-bottom: 0;
    padding-left: 44px;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    background: #f9fafb;
    color: #111827;
    font-size: 14px;
    line-height: 1.5;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

.kb-link-picker-input:focus {
    border-color: var(--kb-link-color);
    background: #ffffff;
    box-shadow: 0 0 0 3px var(--kb-link-bg-hover);
}

[data-theme="dark"] .kb-link-picker-input,
html.dark .kb-link-picker-input {
    background: rgba(255, 255, 255, 0.04);
    border-color: rgba(255, 255, 255, 0.12);
    color: #f3f4f6;
}

[data-theme="dark"] .kb-link-picker-input:focus,
html.dark .kb-link-picker-input:focus {
    background: rgba(255, 255, 255, 0.06);
}

.kb-link-picker-clear {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: 24px;
    height: 24px;
    padding: 0;
    margin: 0;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: #6b7280;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.kb-link-picker-clear:hover {
    background: rgba(0, 0, 0, 0.06);
}

[data-theme="dark"] .kb-link-picker-clear:hover,
html.dark .kb-link-picker-clear:hover {
    background: rgba(255, 255, 255, 0.08);
}

.kb-link-picker-list {
    flex: 1;
    overflow-y: auto;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 6px;
    background: #ffffff;
    min-height: 240px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

[data-theme="dark"] .kb-link-picker-list,
html.dark .kb-link-picker-list {
    background: rgba(255, 255, 255, 0.02);
    border-color: rgba(255, 255, 255, 0.08);
}

.kb-link-picker-list::-webkit-scrollbar {
    width: 6px;
}

.kb-link-picker-list::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.18);
    border-radius: 3px;
}

[data-theme="dark"] .kb-link-picker-list::-webkit-scrollbar-thumb,
html.dark .kb-link-picker-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.14);
}

.kb-link-picker-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.12s ease;
    border: 1px solid transparent;
}

.kb-link-picker-item:hover {
    background: var(--kb-link-bg-hover);
}

.kb-link-picker-item.selected {
    background: var(--kb-link-bg-hover);
    border-color: var(--kb-link-border);
}

.kb-link-picker-item-icon {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border-radius: 8px;
    background: var(--kb-link-bg-hover);
    color: var(--kb-link-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    margin-top: 1px;
}

.kb-link-picker-item-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.kb-link-picker-item-title {
    font-size: 14px;
    font-weight: 600;
    color: #111827;
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

[data-theme="dark"] .kb-link-picker-item-title,
html.dark .kb-link-picker-item-title {
    color: #f3f4f6;
}

.kb-link-picker-item-excerpt {
    font-size: 12.5px;
    color: #6b7280;
    line-height: 1.45;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

[data-theme="dark"] .kb-link-picker-item-excerpt,
html.dark .kb-link-picker-item-excerpt {
    color: #9ca3af;
}

.kb-link-picker-item-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 2px;
}

.kb-link-picker-tag {
    display: inline-flex;
    align-items: center;
    height: 18px;
    padding: 0 6px;
    border-radius: 999px;
    background: rgba(107, 114, 128, 0.12);
    color: #4b5563;
    font-size: 11px;
    line-height: 18px;
}

[data-theme="dark"] .kb-link-picker-tag,
html.dark .kb-link-picker-tag {
    background: rgba(255, 255, 255, 0.08);
    color: #d1d5db;
}

.kb-link-picker-hl {
    background: #fef08a;
    color: #92400e;
    padding: 0 1px;
    border-radius: 2px;
}

[data-theme="dark"] .kb-link-picker-hl,
html.dark .kb-link-picker-hl {
    background: rgba(250, 204, 21, 0.25);
    color: #fde68a;
}

.kb-link-picker-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #9ca3af;
    padding: 36px 12px;
    text-align: center;
    gap: 6px;
    min-height: 220px;
}

.kb-link-picker-empty i {
    font-size: 36px;
    opacity: 0.6;
}

.kb-link-picker-empty p {
    margin: 0;
    font-size: 13px;
}

.kb-link-picker-loading-row,
.kb-link-picker-more-hint,
.kb-link-picker-end-hint {
    text-align: center;
    color: #9ca3af;
    font-size: 12px;
    padding: 10px 0;
}

.kb-link-picker-skeleton-row {
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    border-radius: 8px;
}

.kb-link-picker-skeleton-line {
    height: 12px;
    border-radius: 6px;
    background: linear-gradient(90deg, rgba(0, 0, 0, 0.06) 0%, rgba(0, 0, 0, 0.10) 50%, rgba(0, 0, 0, 0.06) 100%);
    background-size: 200% 100%;
    animation: kbLinkSkeletonShimmer 1.4s linear infinite;
}

.kb-link-picker-skeleton-line.w-60 { width: 60%; }
.kb-link-picker-skeleton-line.w-90 { width: 90%; }

[data-theme="dark"] .kb-link-picker-skeleton-line,
html.dark .kb-link-picker-skeleton-line {
    background: linear-gradient(90deg, rgba(255, 255, 255, 0.04) 0%, rgba(255, 255, 255, 0.10) 50%, rgba(255, 255, 255, 0.04) 100%);
    background-size: 200% 100%;
}

@keyframes kbLinkSkeletonShimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.kb-link-spin {
    display: inline-block;
    animation: kbLinkSpin 1s linear infinite;
}

@keyframes kbLinkSpin {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

.kb-link-picker-status {
    flex-shrink: 0;
    text-align: right;
    color: #9ca3af;
    font-size: 11.5px;
    padding-top: 6px;
    min-height: 18px;
}

/* ============================================================
 * 4. 编辑器工具栏 - "链接知识库" 按钮
 * ============================================================ */

.ql-toolbar button.ql-kb-link {
    width: 28px;
    height: 24px;
    padding: 3px 5px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.ql-toolbar button.ql-kb-link i {
    font-size: 16px;
    line-height: 1;
    color: #444;
}

.ql-toolbar button.ql-kb-link:hover i,
.ql-toolbar button.ql-kb-link.ql-active i {
    color: var(--kb-link-color);
}

[data-theme="dark"] .ql-toolbar button.ql-kb-link i,
html.dark .ql-toolbar button.ql-kb-link i {
    color: #d1d5db;
}

[data-theme="dark"] .ql-toolbar button.ql-kb-link:hover i,
[data-theme="dark"] .ql-toolbar button.ql-kb-link.ql-active i,
html.dark .ql-toolbar button.ql-kb-link:hover i,
html.dark .ql-toolbar button.ql-kb-link.ql-active i {
    color: var(--kb-link-color);
}

/* ============================================================
 * 5. 移动端微调
 * ============================================================ */

@media (max-width: 640px) {
    .kb-link-picker {
        min-height: 320px;
    }

    .kb-link-picker-list {
        min-height: 200px;
    }

    .kb-link-picker-item-title {
        font-size: 13.5px;
    }
}
