/* 自定义样式以改进空行显示 */
.memos__text p {
    margin-bottom: 1em;
}

.memos__text p:last-child {
    margin-bottom: 0;
}

.memos__text p:first-child {
    margin-top: 0;
}

/* Markdown高亮语法样式 */
.memos__text mark {
    background-color: #ffee9f;
    color: #333;
    padding: 0 3px;
    border-radius: 3px;
    box-decoration-break: clone;
}

/* 暗色模式下的高亮样式 */
body.dark-theme .memos__text mark {
    background-color: #665c2a;
    color: #f8f8f8;
}

/* Mermaid 图表样式 */
.mermaid {
    margin: 1.5em 0;
    text-align: center;
    overflow: auto;
    background-color: #f5f5f5;
    padding: 15px;
    border-radius: 8px;
    max-width: 100%;
}

/* 暗色模式下的 Mermaid 图表样式 */
body.dark-theme .mermaid {
    background-color: #2d333b;
}

/* Mermaid 图表文本颜色 */
.mermaid text {
    font-family: 'Source Sans Pro', sans-serif !important;
    font-size: 14px !important;
}

/* Mermaid SVG 样式 */
.mermaid svg {
    max-width: 100%;
    height: auto !important;
}

/* 确保空段落显示 */
.memos__text p:empty,
.memos__text p.empty-line {
    min-height: 0.5em;
    display: block;
    margin: 0.3em 0;
}

/* 移除卡片首尾的空行 */
.memos__text p:first-child:empty,
.memos__text p:first-child.empty-line {
    display: none;
    margin: 0;
}

.memos__text p:last-child:empty,
.memos__text p:last-child.empty-line {
    display: none;
    margin: 0;
}

/* 对于特定的空格占位符 */
.memos__text p:has(br + br) {
    min-height: 1em;
}

/* 改进段落间间距 */
.memos__text {
    line-height: 1.6 !important;
    padding: 1rem 0.75rem 1rem 1rem;
}

/* 在黑暗模式下调整 */
body.dark-theme .memos__text p:empty,
body.dark-theme .memos__text p.empty-line {
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    margin: 0.3em 0;
}

/* 黑暗模式下同样移除首尾空行 */
body.dark-theme .memos__text p:first-child:empty,
body.dark-theme .memos__text p:first-child.empty-line,
body.dark-theme .memos__text p:last-child:empty,
body.dark-theme .memos__text p:last-child.empty-line {
    display: none;
    margin: 0;
    border-bottom: none;
}

/* 标签筛选相关样式 */
#tag-filter {
    background-color: var(--color-text-bg);
    padding: 10px 15px;
    border-radius: 8px;
    margin-bottom: 20px;
    font-size: 14px;
}

.clear-filter {
    margin-left: 8px;
    font-size: 12px;
    color: #718096;
}

.clear-filter a {
    color: #718096;
    text-decoration: none;
}

.clear-filter a:hover {
    text-decoration: underline;
    color: var(--color-tag-hover);
}

/* 加载状态样式 */
p.loading {
    text-align: center;
    padding: 20px;
    color: #718096;
}

p.loading:after {
    content: "...";
    animation: loading-dots 1.5s infinite;
}

@keyframes loading-dots {
    0% { content: "."; }
    33% { content: ".."; }
    66% { content: "..."; }
}

/* 错误和空数据状态样式 */
p.error-text, p.empty-data {
    text-align: center;
    padding: 20px;
    border-radius: 8px;
}

p.error-text {
    background-color: rgba(254, 226, 226, 0.3);
    color: #dc2626;
}

p.empty-data {
    background-color: var(--color-text-bg);
    color: #718096;
}

/* ========== 统一图片尺寸样式(参考echo-noise) ========== */
/* 图片网格容器 */
.images-wrapper {
    display: grid;
    gap: 8px;
    margin: 12px 0;
    width: 100%;
    grid-auto-flow: dense;
    align-items: stretch;
    justify-items: stretch;
}

/* 根据图片数量设置列数 */
.images-wrapper.cols-1 {
    grid-template-columns: 1fr;
}

.images-wrapper.cols-2 {
    grid-template-columns: repeat(2, 1fr);
}

.images-wrapper.cols-3 {
    grid-template-columns: repeat(3, 1fr);
}

/* 图片网格项 - 统一尺寸的关键 */
.image-grid-item {
    position: relative;
    aspect-ratio: 1 / 1; /* 1:1 正方形比例,确保所有图片高度一致 */
    overflow: hidden;
    border-radius: 8px;
    background: var(--color-img-border);
}

/* 图片样式 - 使用object-fit裁剪图片 */
.image-grid-item img {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important; /* 裁剪图片填充容器 */
    object-position: center center !important;
    display: block !important;
    margin: 0 !important;
    max-width: none !important;
    cursor: pointer;
    transition: transform 0.3s ease;
}

.image-grid-item img:hover {
    transform: scale(1.05);
}

/* 如果图片被链接包裹 */
.image-grid-item > a {
    display: block;
    width: 100%;
    height: 100%;
}

.image-grid-item > a > img {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
    object-position: center center !important;
    display: block !important;
}

/* 移动端适配 */
@media (max-width: 600px) {
    .images-wrapper {
        gap: 6px;
    }

    .images-wrapper.cols-3 {
        grid-template-columns: repeat(2, 1fr); /* 移动端3列变2列 */
    }
}

/* 单张图片时保持原始比例 */
.images-wrapper.cols-1 .image-grid-item {
    aspect-ratio: auto; /* 单图时不强制1:1 */
    max-height: 400px;
}

.images-wrapper.cols-1 .image-grid-item img {
    object-fit: contain !important; /* 单图时完整显示 */
    height: auto !important;
    max-height: 400px;
}

/* ========== 长内容展开/收起功能 ========== */
/* 可折叠内容容器 */
.memos__text.has-expand {
    position: relative;
}

/* 折叠内容主体，但不包括meta区域 */
.memos__text.has-expand.collapsed .collapsible-content {
    max-height: 400px;
    overflow: hidden;
    position: relative;
}

/* 渐变遮罩 */
.memos__text.has-expand.collapsed .collapsible-content::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 80px;
    background: linear-gradient(to bottom, transparent, var(--color-text-bg));
    pointer-events: none;
}

/* 确保meta区域始终可见 */
.memos__text.has-expand .memos__meta {
    position: relative;
    z-index: 1;
    margin-top: 8px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

/* 展开/收起链接 - 在时间上方，独立一行 */
.expand-link {
    display: block;
    color: #3b82f6;
    font-size: 14px;
    cursor: pointer;
    margin-bottom: 6px;
    text-decoration: none;
    transition: color 0.2s ease;
    order: -1; /* 确保在时间之前 */
}

.expand-link:hover {
    color: #2563eb;
    text-decoration: underline;
}

/* 确保时间保持原有样式 */
.memos__text.has-expand .memos__meta small {
    display: block;
}

/* 暗色主题适配 */
body.dark-theme .expand-link {
    color: #60a5fa;
}

body.dark-theme .expand-link:hover {
    color: #93c5fd;
}
