/* ===================================
   TiMemory Blog - 主样式文件
   =================================== */

/* CSS 变量定义 - 白天模式 */
:root {
    --primary-color: #4a90e2;
    --secondary-color: #7ed321;
    --accent-color: #f5a623;
    --danger-color: #d0021b;
    
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fa;
    --bg-tertiary: #e9ecef;
    
    --text-primary: #2c3e50;
    --text-secondary: #5a6c7d;
    --text-muted: #868e96;
    
    --border-color: #dee2e6;
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
    
    --transition: all 0.3s ease;
}

/* 黑夜模式 */
[data-theme="dark"] {
    --primary-color: #5aa3f5;
    --secondary-color: #8ce236;
    --accent-color: #ffb84d;
    --danger-color: #ff3344;
    
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-tertiary: #0f3460;
    
    --text-primary: #e8e8e8;
    --text-secondary: #b8b8b8;
    --text-muted: #6c757d;
    
    --border-color: #2d3748;
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
}

/* 全局重置 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    line-height: 1.6;
    transition: var(--transition);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

a {
    text-decoration: none;
    color: var(--primary-color);
    transition: var(--transition);
}

a:hover {
    color: var(--accent-color);
}

img {
    max-width: 100%;
    height: auto;
    display: block;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

/* ===================================
   头部导航
   =================================== */
.site-header {
    background: var(--bg-primary);
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 1000;
    transition: var(--transition);
}

.header-top {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    padding: 30px 0;
    color: white;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    font-size: 2rem;
    font-weight: bold;
    color: white !important;
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo i {
    font-size: 2.5rem;
}

.search-bar {
    flex: 1;
    max-width: 500px;
    margin: 0 30px;
    position: relative;
}

.search-bar input {
    width: 100%;
    padding: 12px 45px 12px 20px;
    border: none;
    border-radius: 25px;
    font-size: 14px;
    background: rgba(255, 255, 255, 0.9);
    color: var(--text-primary);
}

.search-bar button {
    position: absolute;
    right: 5px;
    top: 50%;
    transform: translateY(-50%);
    background: var(--primary-color);
    border: none;
    width: 35px;
    height: 35px;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    transition: var(--transition);
}

.search-bar button:hover {
    background: var(--accent-color);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 15px;
}

.theme-toggle {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    width: 45px;
    height: 45px;
    border-radius: 50%;
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.theme-toggle:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: rotate(30deg);
}

.nav-menu {
    background: var(--bg-primary);
    padding: 0;
    border-bottom: 1px solid var(--border-color);
}

.nav-menu ul {
    list-style: none;
    display: flex;
    gap: 0;
}

.nav-menu li {
    position: relative;
}

.nav-menu a {
    display: block;
    padding: 15px 25px;
    color: var(--text-primary);
    font-weight: 500;
    border-bottom: 3px solid transparent;
    transition: var(--transition);
}

.nav-menu a:hover,
.nav-menu a.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
    background: var(--bg-secondary);
}

/* ===================================
   主要内容区
   =================================== */
.main-content {
    padding: 40px 0;
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 30px;
    flex: 1;
}

/* 文章列表 */
.articles-section {
    min-width: 0; /* 允许在网格中缩小 */
    width: 100%;  /* 占满可用空间 */
}

/* 侧边栏 - 固定宽度防止被挤压 */
.sidebar {
    display: flex;
    flex-direction: column;
    gap: 25px;
    width: 320px; /* 固定宽度 */
    min-width: 320px; /* 最小宽度 */
    max-width: 320px; /* 最大宽度 */
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
    padding-bottom: 15px;
    border-bottom: 2px solid var(--border-color);
}

.section-title {
    font-size: 1.5rem;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 10px;
}

.section-title i {
    color: var(--primary-color);
}

.filter-tabs {
    display: flex;
    gap: 10px;
}

.filter-btn {
    padding: 8px 16px;
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    color: var(--text-secondary);
    border-radius: 20px;
    cursor: pointer;
    transition: var(--transition);
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.filter-btn i {
    font-size: 14px;
    transition: var(--transition);
}

.filter-btn:hover,
.filter-btn.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.filter-btn:hover i,
.filter-btn.active i {
    color: white;
    transform: scale(1.1);
    filter: drop-shadow(0 0 8px rgba(255, 255, 255, 0.6));
}

.filter-btn.active i {
    animation: iconPulse 1.5s ease-in-out infinite;
}

@keyframes iconPulse {
    0%, 100% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.15);
        opacity: 0.9;
    }
}

.article-card {
    background: var(--bg-primary);
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 25px;
    box-shadow: var(--shadow-md);
    transition: var(--transition);
    display: grid;
    grid-template-columns: 280px 1fr;
    width: 100%; /* 确保占满容器 */
    min-width: 0; /* 允许内容缩小 */
}

.article-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-lg);
}

.article-cover-img {
    width: 100%;
    height: 200px;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    position: relative;
    overflow: hidden;
}

.article-cover-overlay {
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 3rem;
    transition: var(--transition);
}

.article-card:hover .article-cover-overlay {
    background: rgba(0, 0, 0, 0.5);
}

.article-cover-overlay i {
    opacity: 0.8;
}

.article-content {
    padding: 25px;
}

.article-category {
    display: inline-block;
    padding: 5px 12px;
    background: var(--primary-color);
    color: white;
    border-radius: 15px;
    font-size: 12px;
    margin-bottom: 12px;
}

.article-title {
    font-size: 1.4rem;
    margin-bottom: 12px;
    color: var(--text-primary);
    line-height: 1.4;
}

.article-title a {
    color: inherit;
}

.article-title a:hover {
    color: var(--primary-color);
}

.article-excerpt {
    color: var(--text-secondary);
    margin-bottom: 15px;
    line-height: 1.7;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.article-meta {
    display: flex;
    gap: 20px;
    color: var(--text-muted);
    font-size: 13px;
    margin-bottom: 15px;
}

.article-meta span {
    display: flex;
    align-items: center;
    gap: 5px;
}

.article-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.tag {
    padding: 4px 12px;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    border-radius: 12px;
    font-size: 12px;
    transition: var(--transition);
}

.tag:hover {
    background: var(--primary-color);
    color: white;
}

/* ===================================
   侧边栏
   =================================== */
.sidebar {
    display: flex;
    flex-direction: column;
    gap: 25px;
}

.widget {
    background: var(--bg-primary);
    border-radius: 12px;
    padding: 25px;
    box-shadow: var(--shadow-md);
}

.widget-title {
    font-size: 1.2rem;
    margin-bottom: 20px;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 10px;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--border-color);
}

.widget-title i {
    color: var(--primary-color);
}

/* 日历组件 */
.calendar-widget {
    overflow: hidden;
}

.calendar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.calendar-header button {
    background: var(--bg-secondary);
    border: none;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    color: var(--text-primary);
    cursor: pointer;
    transition: var(--transition);
}

.calendar-header button:hover {
    background: var(--primary-color);
    color: white;
}

.calendar-month {
    font-weight: bold;
    color: var(--text-primary);
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 5px;
}

.calendar-day-name {
    text-align: center;
    font-size: 12px;
    color: var(--text-muted);
    padding: 5px;
    font-weight: 600;
}

.calendar-day {
    text-align: center;
    padding: 8px;
    border-radius: 5px;
    font-size: 13px;
    cursor: pointer;
    transition: var(--transition);
}

.calendar-day:hover:not(.empty) {
    background: var(--bg-secondary);
}

.calendar-day.today {
    background: var(--primary-color);
    color: white;
    font-weight: bold;
}

.calendar-day.has-article {
    position: relative;
}

.calendar-day.has-article::after {
    content: '';
    position: absolute;
    bottom: 3px;
    left: 50%;
    transform: translateX(-50%);
    width: 4px;
    height: 4px;
    background: var(--accent-color);
    border-radius: 50%;
}

.calendar-day.empty {
    cursor: default;
}

/* 分类统计 */
.category-list {
    list-style: none;
}

.category-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 15px;
    margin-bottom: 8px;
    background: var(--bg-secondary);
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
}

.category-item:hover {
    background: var(--primary-color);
    color: white;
}

.category-item.active {
    background: var(--primary-color);
    color: white;
    box-shadow: 0 2px 8px rgba(74, 144, 226, 0.3);
}

.category-count {
    background: var(--bg-tertiary);
    padding: 3px 10px;
    border-radius: 10px;
    font-size: 12px;
    font-weight: bold;
}

.category-item:hover .category-count {
    background: rgba(255, 255, 255, 0.3);
}

.category-item.active .category-count {
    background: rgba(255, 255, 255, 0.3);
}

/* 标签云 */
.tag-cloud {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.tag-cloud-item {
    padding: 6px 14px;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    border-radius: 20px;
    font-size: 13px;
    cursor: pointer;
    transition: var(--transition);
    border: 1px solid transparent;
}

.tag-cloud-item:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
    transform: translateY(-2px);
}

/* 热门文章 */
.popular-article {
    display: flex;
    gap: 12px;
    margin-bottom: 15px;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
}

.popular-article:last-child {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

.popular-article-img {
    width: 80px;
    height: 60px;
    border-radius: 6px;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    flex-shrink: 0;
}

.popular-article-info h4 {
    font-size: 14px;
    margin-bottom: 5px;
    line-height: 1.4;
}

.popular-article-info h4 a {
    color: var(--text-primary);
}

.popular-article-info h4 a:hover {
    color: var(--primary-color);
}

.popular-article-meta {
    font-size: 12px;
    color: var(--text-muted);
}

/* ===================================
   友情链接
   =================================== */
.friend-links {
    max-height: 400px;
    overflow-y: auto;
    /* 预留滚动条空间，防止抖动 */
    padding-right: 6px;
    margin-right: -6px;
}

.friend-links-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.friend-link-item {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    background: var(--bg-secondary);
    border-radius: 8px;
    transition: var(--transition);
    text-decoration: none;
    color: var(--text-primary);
}

.friend-link-item:hover {
    background: var(--primary-color);
    color: white;
    transform: translateX(5px);
}

.friend-link-icon {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    background: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 12px;
    flex-shrink: 0;
    font-size: 16px;
    color: var(--primary-color);
}

.friend-link-item:hover .friend-link-icon {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

.friend-link-info {
    flex: 1;
    min-width: 0;
}

.friend-link-name {
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.friend-link-desc {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.friend-link-item:hover .friend-link-desc {
    color: rgba(255, 255, 255, 0.8);
}

/* 滚动条美化 */
.friend-links::-webkit-scrollbar {
    width: 6px;
}

.friend-links::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
    border-radius: 3px;
}

.friend-links::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.friend-links::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ===================================
   页脚
   =================================== */
.site-footer {
    background: var(--bg-primary);
    border-top: 1px solid var(--border-color);
    padding: 30px 0;
    margin-top: auto;
}

.footer-content {
    text-align: center;
    color: var(--text-secondary);
}

.footer-links {
    display: flex;
    justify-content: center;
    gap: 25px;
    margin-bottom: 15px;
}

.footer-links a {
    color: var(--text-secondary);
}

.footer-links a:hover {
    color: var(--primary-color);
}

.icp-info {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 10px;
}

.copyright {
    font-size: 13px;
}

/* ===================================
   响应式设计
   =================================== */
@media (max-width: 968px) {
    .main-content {
        grid-template-columns: 1fr;
    }
    
    .article-card {
        grid-template-columns: 1fr;
    }
    
    .article-cover {
        height: 220px;
    }
}

@media (max-width: 768px) {
    .header-content {
        flex-direction: column;
        gap: 15px;
    }
    
    .search-bar {
        max-width: 100%;
        margin: 15px 0;
    }
    
    .nav-menu ul {
        flex-wrap: wrap;
    }
    
    .filter-tabs {
        flex-wrap: wrap;
    }
}

/* ===================================
   工具类
   =================================== */
.fade-in {
    animation: fadeIn 0.5s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* 文章列表容器 - 固定宽度 */
#articlesList {
    width: 100%; /* 占满父容器 */
}

/* Loading 状态 - 与文章卡片保持完全一致的尺寸 */
.loading {
    text-align: center;
    padding: 25px; /* 与 .article-content 的 padding 一致 */
    color: var(--text-muted);
    /* 保持与文章卡片相似的尺寸，防止布局跳动 */
    min-height: 250px; /* 考虑卡片图片高度 + 内容 padding */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--bg-primary); /* 与卡片背景一致 */
    border-radius: 12px; /* 与卡片圆角一致 */
    box-shadow: var(--shadow-md); /* 与卡片阴影一致 */
    width: 100%; /* 确保占满容器 */
}

.spinner {
    border: 3px solid var(--bg-tertiary);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 0 auto 15px;
}

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

/* ===================================
   加载更多按钮
   =================================== */
.load-more-container {
    text-align: center;
    padding: 30px 0;
    margin-top: 20px;
}

.load-more-btn {
    padding: 12px 40px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 25px;
    font-size: 16px;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: var(--shadow-md);
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.load-more-btn:hover {
    background: var(--accent-color);
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.load-more-btn:active {
    transform: translateY(0);
}

.load-more-btn.loading {
    cursor: not-allowed;
    opacity: 0.7;
}

.load-more-btn i {
    transition: var(--transition);
}

.load-more-btn.loading i {
    animation: spin 1s linear infinite;
}

.load-more-btn.hidden {
    display: none;
}

/* ===================================
   回到顶部按钮
   =================================== */
.back-to-top {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 50px;
    height: 50px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: var(--shadow-md);
    transition: var(--transition);
    z-index: 999;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px);
}

.back-to-top.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.back-to-top:hover {
    background: var(--accent-color);
    transform: translateY(-5px);
    box-shadow: var(--shadow-lg);
}

.back-to-top:active {
    transform: translateY(-2px);
}

@media (max-width: 768px) {
    .back-to-top {
        bottom: 20px;
        right: 20px;
        width: 45px;
        height: 45px;
        font-size: 1rem;
    }
}
