/**
 * Custom styling for the knowledge blog
 * Fully compatible with DaisyUI themes and design system
 */

/* Global base configurations */
@layer base {
  :root {
    --fallback-b1: 0 0% 100%;
    --fallback-b2: 0 0% 95%;
  }
}

/* Base custom font stack settings allowing smooth combination with DaisyUI */
html, body {
  font-family: "Inter", "LXGW WenKai Lite", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* General article content styling with DaisyUI variables */
.article-content {
    font-size: 1.05rem;
    line-height: 1.8;
    /* 让文字颜色继承父元素，不要强制设置 */
}

/* Headings with DaisyUI theme compatibility */
.article-content h1,
.article-content h2,
.article-content h3,
.article-content h4,
.article-content h5,
.article-content h6 {
    display: block;
    padding: 0.35rem 0;
    opacity: 0.9;
    transition: all 0.2s;
    text-decoration: none;
    border-left: 2px solid transparent;
    margin-bottom: 0.75rem;
    /* 让标题颜色继承，不强制设置 */
    font-weight: 700;
    position: relative;
    scroll-margin-top: 80px;
}

/* 文章内容标题大小层次 */
.article-content h1 {
    font-size: 2.25rem; /* text-4xl */
    line-height: 1.2;
    margin-top: 3rem;
}

.article-content h2 {
    font-size: 1.875rem; /* text-3xl */
    line-height: 1.25;
    margin-top: 2.5rem;
}

.article-content h3 {
    font-size: 1.5rem; /* text-2xl */
    line-height: 1.33;
    margin-top: 2rem;
}

.article-content h4 {
    font-size: 1.25rem; /* text-xl */
    line-height: 1.4;
}

.article-content h5 {
    font-size: 1.125rem; /* text-lg */
    line-height: 1.44;
}

.article-content h6 {
    font-size: 1rem; /* text-base */
    line-height: 1.5;
    font-weight: 600;
}

/* 第一个标题顶部间距调整 */
.article-content h1:first-child,
.article-content h2:first-child,
.article-content h3:first-child,
.article-content h4:first-child,
.article-content h5:first-child,
.article-content h6:first-child {
    margin-top: 0;
}

/* Keep toc-link as separate selector */
.toc-link {
    display: block;
    padding: 0.35rem 0.25rem;
    opacity: 0.8;
    transition: all 0.2s;
    text-decoration: none;
    border-left: 2px solid transparent;
    margin-bottom: 0.25rem;
}

.toc-link:hover {
    opacity: 1;
    padding-left: 0.5rem;
}

.toc-link.active {
    opacity: 1;
    font-weight: 600;
    padding-left: 0.5rem;
    border-left-width: 3px;
    border-left-color: currentColor; /* 与文字颜色一致，由 JS 添加 text-primary 控制颜色 */
    background: rgba(127, 127, 127, 0.12);
    box-shadow: inset 0 0 0 1px rgba(0,0,0,0.04);
    border-radius: 0 0.25rem 0.25rem 0;
}

/* Heading anchor links with DaisyUI theme integration */
.heading-anchor {
    opacity: 0;
    text-decoration: none;
    margin-left: 0.5rem;
    font-weight: normal;
    transition: opacity 0.2s ease;
}

.article-content h1:hover .heading-anchor,
.article-content h2:hover .heading-anchor,
.article-content h3:hover .heading-anchor,
.article-content h4:hover .heading-anchor,
.article-content h5:hover .heading-anchor,
.article-content h6:hover .heading-anchor {
    opacity: 1;
}


/* Paragraphs and lists with better spacing */
.article-content p {
    margin-bottom: 1.25rem;
    /* 移除强制颜色设置，让其继承 */
}

.article-content ul, .article-content ol {
    margin-left: 1.5rem;
    margin-bottom: 1.25rem;
    /* 移除强制颜色设置，让其继承 */
}

.article-content ul {
    list-style-type: disc;
}

.article-content ol {
    list-style-type: decimal;
}

.article-content li {
    margin-bottom: 0.5rem;
}


/* Enhanced links with DaisyUI primary color */
.article-content a {
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
    transition: all 0.2s ease;
}

.article-content a:hover {
    text-decoration-thickness: 2px;
}

/* Enhanced images with modal support and theme-aware styling */
.article-content img {
    max-width: 100%;
    height: auto;
    max-height: 400px;
    object-fit: contain;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.3s ease;
    margin: 1.5rem auto;
    display: block;
}

.article-content img:hover {
    transform: scale(1.02);
}

/* 简洁现代的引用块样式 - 兼容 DaisyUI 主题 */
.article-content blockquote {
    position: relative;
    padding: 1rem 1.25rem 1rem 3rem;
    border-radius: 0.5rem;
    margin: 1.5rem 0;
    font-style: italic;
    background: rgba(0, 0, 0, 0.03);
    border-left: 4px solid currentColor;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    transition: all 0.2s ease;
}

/* Dark theme 适配 */
[data-theme*="dark"] .article-content blockquote {
    background: rgba(255, 255, 255, 0.05);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.article-content blockquote:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    transform: translateY(-1px);
}

[data-theme*="dark"] .article-content blockquote:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* 引用符号 */
.article-content blockquote::before {
    content: "\201C";
    position: absolute;
    top: 0.5rem;
    left: 0.75rem;
    font-size: 2rem;
    line-height: 1;
    color: currentColor;
    font-family: serif;
    opacity: 0.6;
}

.article-content blockquote p {
    margin-bottom: 0.5rem;
    opacity: 0.9;
}

.article-content blockquote p:last-child {
    margin-bottom: 0;
}

/* 嵌套引用样式 */
.article-content blockquote blockquote {
    margin: 0.75rem 0;
    padding: 0.75rem 1rem 0.75rem 2rem;
    border-left-width: 3px;
    background: rgba(0, 0, 0, 0.02);
}

[data-theme*="dark"] .article-content blockquote blockquote {
    background: rgba(255, 255, 255, 0.03);
}

.article-content blockquote blockquote::before {
    font-size: 1.5rem;
    top: 0.25rem;
    left: 0.5rem;
}

/* 简洁的代码块容器 - 只负责外框，内容交给Pygments */
.article-content pre {
    border-radius: 0.5rem;
    overflow-x: auto;
    margin: 1.5rem 0;
    /* 移除背景色和内边距，让Pygments自己处理 */
}

.article-content pre code {
    background-color: transparent;
    color: inherit;
    padding: 0;
    border-radius: 0;
}


/* Custom scrollbar for code blocks */
.article-content pre::-webkit-scrollbar {
    height: 6px;
    background: transparent;
}

.article-content pre::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 6px;
}

.article-content pre::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.3);
}

.article-content pre::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.05);
    border-radius: 6px;
}

/* Firefox scrollbar styling */
.article-content pre {
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 0, 0, 0.2) transparent;
}

/* DaisyUI风格的代码块外框 - 为Pygments提供容器 */
.highlight {
    border-radius: 0.5rem;
    overflow: hidden;
    margin: 1.5rem 0;
    background-color: transparent; /* 让Pygments决定背景色 */
}


/* 简化的Pygments兼容性 - 只处理必要的外框 */
.highlight pre {
    /* 不强制背景色，让Pygments主题自己决定 */
    margin: 0;
    padding: 1rem;
    border-radius: inherit;
}

/* Enhanced tables with DaisyUI styling */
.article-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.5rem 0;
    border-radius: 0.5rem;
    overflow: hidden;
}

.article-content table th {
    font-weight: 600;
    padding: 0.75rem 1rem;
    text-align: left;
    /* 移除强制颜色设置 */
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    border-right: 1px solid rgba(0, 0, 0, 0.1);
}

.article-content table th:last-child {
    border-right: none;
}

.article-content table td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    border-right: 1px solid rgba(0, 0, 0, 0.05);
    /* 移除强制颜色设置 */
}

.article-content table td:last-child {
    border-right: none;
}

.article-content table tr:last-child td {
    border-bottom: none;
}

.article-content table tr:nth-child(even) {
    background-color: rgba(0, 0, 0, 0.02);
}

.article-content table tr:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

/* Horizontal rule with theme-aware styling */
.article-content hr {
    height: 1px;
    background: linear-gradient(to right, transparent, rgba(0, 0, 0, 0.2), transparent);
    border: none;
    margin: 2rem 0;
}



/* TOC level-based styling */
.toc-level-1 { padding-left: 0; font-size: 1.1rem; font-weight: 600; }
.toc-level-2 { padding-left: 12px; font-size: 0.95rem; }
.toc-level-3 { padding-left: 24px; font-size: 0.90rem; }
.toc-level-4 { padding-left: 36px; font-size: 0.85rem; opacity: 0.9; }
.toc-level-5 { padding-left: 48px; font-size: 0.80rem; opacity: 0.8; }
.toc-level-6 { padding-left: 60px; font-size: 0.75rem; opacity: 0.7; }

/* Tag badge styles (unified across pages) */
.k-tags { display: flex; flex-wrap: wrap; gap: 0.5rem; }

.badge-tag {
    display: inline-flex;
    align-items: center;
    white-space: nowrap;
    gap: 0.25rem;
    padding: 0.25rem 0.7rem; /* 小一号的按钮 */
    line-height: 1.25;
    font-size: 0.75rem; /* ≈ btn-xs */
    border-radius: 9999px;
    text-decoration: none;
    border: 1px solid rgba(0,0,0,0.18);
    background: rgba(0,0,0,0.02);
    color: inherit;
    transition: background-color .2s ease, border-color .2s ease, transform .1s ease, color .2s ease;
}

.badge-tag:hover {
    background: rgba(0,0,0,0.08);
    border-color: rgba(0,0,0,0.28);
}

/* 作为主色按钮的近似外观（激活或强调时） */
.badge-tag[data-active="true"],
.badge-tag.is-active {
    background: #2563eb; /* 近似 daisyUI primary 默认蓝 */
    border-color: #1d4ed8;
    color: #ffffff;
}

.badge-tag:active { transform: translateY(1px); }

/* Hide scrollbars for toc container visually while keeping scroll */
#toc-container { scrollbar-width: none; }
#toc-container::-webkit-scrollbar { display: none; }

/* Search overlay animation */
#search-overlay {
    transition: opacity 0.3s ease;
}

#search-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

#search-overlay.flex {
    opacity: 1;
}

/* 代码块复制按钮样式 */
.code-copy-btn {
    position: absolute !important;
    top: 8px !important;
    right: 8px !important;
    opacity: 0 !important;
    transition: all 0.2s ease !important;
    z-index: 10 !important;
    border-radius: 6px !important;
    padding: 6px 8px !important;
    font-size: 12px !important;
    min-height: auto !important;
    height: auto !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1) !important;
    cursor: pointer !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}

.code-copy-btn:hover {
    transform: translateY(-1px) !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15) !important;
}

.code-copy-btn:active {
    transform: translateY(0) !important;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1) !important;
}

/* 代码块容器悬浮时显示复制按钮 */
.prose pre:hover .code-copy-btn {
    opacity: 1 !important;
}

/* 确保代码块有相对定位 */
.prose pre {
    position: relative !important;
}

/* 成功状态样式 */
.code-copy-btn.success {
    background: #22c55e !important;
    color: white !important;
}

/* 错误状态样式 */
.code-copy-btn.error {
    background: #ef4444 !important;
    color: white !important;
}

/* Inline code wrapping to avoid overflow for single long lines */
.article-content :not(pre) > code,
.prose :not(pre) > code {
    white-space: normal;
    word-break: break-word;
    overflow-wrap: anywhere;
}

/* Text truncation utilities for better card display */
.line-clamp-1 {
    display: -webkit-box;
    -webkit-line-clamp: 1;
    line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.line-clamp-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.line-clamp-3 {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Favorites card hover effects */
.favorites-card {
    transition: all 0.3s ease;
}

.favorites-card:hover {
    transform: translateY(-2px);
}

.favorites-card figure img {
    transition: transform 0.3s ease;
}

.favorites-card:hover figure img {
    transform: scale(1.05);
}

/* Ensure consistent card heights in favorites grid */
#favorites-container .card {
    height: 100%;
    min-height: 350px; /* Set minimum height for consistency */
}

#favorites-container .card-body {
    min-height: 140px; /* Ensure consistent body height */
    padding-bottom: 0.75rem; /* Add padding to bottom for better spacing */
}

#favorites-container figure {
    height: 200px; /* Fixed height for image container */
}

/* Improve spacing for favorites card footer */
#favorites-container .card-body > div:last-child {
    margin-top: auto;
    padding-top: 0.75rem;
    border-top: 1px solid hsl(var(--bc) / 0.1);
    min-height: 24px;
}

/* Ensure badge has proper spacing */
#favorites-container .badge {
    min-height: 18px;
    line-height: 1.2;
}

/* Favorites image loading states */
#favorites-container .lozad {
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
}

#favorites-container .lozad.lozad-loaded {
    opacity: 1;
}

/* Loading skeleton for favorites */
.favorites-loading-skeleton {
    background: linear-gradient(90deg, 
        hsl(var(--b2)) 25%, 
        hsl(var(--b3)) 50%, 
        hsl(var(--b2)) 75%);
    background-size: 200% 100%;
    animation: loading-skeleton 1.5s infinite;
}

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

/* TOC container scroll behavior and visible scrollbar */
@media (min-width: 1024px) {
  aside .sticky { max-height: calc(100vh - 6rem); display: flex; flex-direction: column; }
  aside .sticky #toc-container { overflow-y: auto; flex: 1 1 auto; min-height: 0; }
}

#toc-container { scrollbar-width: auto; }
#toc-container::-webkit-scrollbar { width: 8px; }
#toc-container::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.25); border-radius: 8px; }
#toc-container::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,0.35); }
#toc-container::-webkit-scrollbar-track { background: transparent; }