/* ==========================================
   LifeGuide - 生活常识科普网站 全局样式
   ========================================== */

/* --- CSS 变量（主题色） --- */
:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #eff6ff;
    --accent: #f59e0b;
    --text: #1f2937;
    --text-light: #6b7280;
    --bg: #f9fafb;
    --white: #ffffff;
    --border: #e5e7eb;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
    --radius: 8px;
    --max-width: 1200px;
}

/* --- 基础重置 --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans SC", sans-serif;
    color: var(--text);
    background: var(--bg);
    line-height: 1.7;
    font-size: 16px;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }
img { max-width: 100%; }

/* --- 布局容器 --- */
.container {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 20px;
}

/* 主内容区域：左侧内容 + 右侧边栏 */
.main-layout {
    display: flex;
    gap: 30px;
    margin-top: 30px;
    margin-bottom: 40px;
}
.main-content { flex: 1; min-width: 0; }
.sidebar { width: 300px; flex-shrink: 0; }

/* --- 头部导航 --- */
.site-header {
    background: var(--white);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}
.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 60px;
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 20px;
}
.logo a {
    font-size: 22px;
    font-weight: 700;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 8px;
}
.logo a:hover { color: var(--primary-dark); }

/* 搜索栏 */
.header-search form {
    display: flex;
    align-items: center;
}
.header-search input {
    width: 260px;
    padding: 8px 14px;
    border: 2px solid var(--border);
    border-radius: 20px 0 0 20px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}
.header-search input:focus { border-color: var(--primary); }
.header-search button {
    padding: 8px 18px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 0 20px 20px 0;
    cursor: pointer;
    font-size: 14px;
}
.header-search button:hover { background: var(--primary-dark); }

/* 导航链接 */
.header-nav { display: flex; align-items: center; gap: 16px; }
.header-nav a {
    color: var(--text);
    font-size: 14px;
    padding: 6px 12px;
    border-radius: var(--radius);
    transition: background 0.2s;
}
.header-nav a:hover { background: var(--primary-light); color: var(--primary); }
.header-nav .btn-login {
    background: var(--primary);
    color: white;
    padding: 7px 18px;
    border-radius: 20px;
}
.header-nav .btn-login:hover { background: var(--primary-dark); color: white; }
.header-nav .user-info { font-size: 14px; color: var(--text-light); }

/* --- 页脚 --- */
.site-footer {
    background: var(--text);
    color: #d1d5db;
    padding: 30px 0 20px;
    margin-top: 50px;
}
.footer-inner {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 20px;
    text-align: center;
}
.footer-inner a { color: #93c5fd; }
.footer-links { margin-bottom: 12px; display: flex; justify-content: center; gap: 24px; }

/* --- 首页 Hero 区域 --- */
.hero {
    background: linear-gradient(135deg, var(--primary) 0%, #7c3aed 100%);
    color: white;
    padding: 60px 20px;
    text-align: center;
}
.hero h1 { font-size: 36px; font-weight: 700; margin-bottom: 12px; }
.hero p { font-size: 18px; opacity: 0.9; max-width: 600px; margin: 0 auto 20px; }
.hero-search input {
    width: 480px; max-width: 90%;
    padding: 14px 20px;
    border: none;
    border-radius: 30px;
    font-size: 16px;
    outline: none;
}
.hero-search button {
    padding: 14px 30px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 30px;
    font-size: 16px;
    font-weight: 600;
    margin-left: 8px;
    cursor: pointer;
    transition: background 0.2s;
}
.hero-search button:hover { background: #d97706; }

/* --- 分类卡片 --- */
.section-title {
    font-size: 24px;
    font-weight: 700;
    margin: 40px 0 20px;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--primary);
    display: inline-block;
}
.category-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
}
.category-card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 24px 16px;
    text-align: center;
    box-shadow: var(--shadow);
    transition: transform 0.2s, box-shadow 0.2s;
    border: 1px solid var(--border);
}
.category-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.12);
}
.category-card .cat-icon { font-size: 32px; margin-bottom: 8px; }
.category-card .cat-name { font-weight: 600; font-size: 15px; color: var(--text); }
.category-card .cat-desc { font-size: 12px; color: var(--text-light); margin-top: 4px; }

/* --- 文章卡片 --- */
.article-list { display: flex; flex-direction: column; gap: 20px; }
.article-card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    transition: box-shadow 0.2s;
}
.article-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,0.12); }
.article-card .card-title {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 8px;
}
.article-card .card-title a { color: var(--text); }
.article-card .card-title a:hover { color: var(--primary); }
.article-card .card-summary {
    color: var(--text-light);
    font-size: 14px;
    margin-bottom: 12px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.article-card .card-meta {
    display: flex;
    align-items: center;
    gap: 16px;
    font-size: 13px;
    color: var(--text-light);
}
.article-card .card-meta .category-tag {
    background: var(--primary-light);
    color: var(--primary);
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 12px;
}
.article-card .card-meta span { display: flex; align-items: center; gap: 4px; }

/* --- 文章详情页 --- */
.article-detail { background: var(--white); border-radius: var(--radius); padding: 40px; box-shadow: var(--shadow); }
.article-detail .article-title { font-size: 28px; font-weight: 700; margin-bottom: 16px; line-height: 1.4; }
.article-detail .article-meta {
    display: flex; gap: 20px; font-size: 14px; color: var(--text-light);
    padding-bottom: 20px; border-bottom: 1px solid var(--border); margin-bottom: 24px;
}
.article-detail .article-body {
    font-size: 17px;
    line-height: 1.9;
}
/* Markdown 渲染后的内容样式 */
.article-body h1 { font-size: 26px; margin: 24px 0 12px; }
.article-body h2 { font-size: 22px; margin: 20px 0 10px; }
.article-body h3 { font-size: 18px; margin: 16px 0 8px; }
.article-body p { margin-bottom: 16px; }
.article-body img { border-radius: var(--radius); margin: 12px 0; }
.article-body blockquote {
    border-left: 4px solid var(--primary);
    padding: 8px 16px;
    margin: 16px 0;
    background: var(--primary-light);
    border-radius: 0 var(--radius) var(--radius) 0;
}
.article-body pre {
    background: #1e293b; color: #e2e8f0;
    padding: 16px; border-radius: var(--radius); overflow-x: auto;
    font-size: 14px; line-height: 1.5; margin: 16px 0;
}
.article-body code {
    background: #f1f5f9; color: #e11d48;
    padding: 2px 6px; border-radius: 4px; font-size: 0.9em;
}
.article-body pre code { background: none; color: inherit; padding: 0; }
.article-body ul, .article-body ol { margin: 12px 0; padding-left: 24px; }
.article-body li { margin-bottom: 6px; }
.article-body table { width: 100%; border-collapse: collapse; margin: 16px 0; }
.article-body th, .article-body td { border: 1px solid var(--border); padding: 10px; text-align: left; }
.article-body th { background: #f1f5f9; font-weight: 600; }
.article-body tbody tr:nth-child(even) { background: #f8fafc; }
.article-body tbody tr:hover { background: #f1f5f9; }

/* --- 侧边栏 --- */
.sidebar .widget {
    background: var(--white);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}
.sidebar .widget-title {
    font-size: 16px; font-weight: 700; margin-bottom: 14px;
    padding-bottom: 10px; border-bottom: 2px solid var(--primary);
}
.sidebar .category-list { list-style: none; }
.sidebar .category-list li { margin-bottom: 2px; }
.sidebar .category-list a {
    display: block; padding: 8px 12px; border-radius: 6px;
    color: var(--text); font-size: 14px; transition: background 0.2s;
}
.sidebar .category-list a:hover { background: var(--primary-light); color: var(--primary); }
.sidebar .popular-item {
    padding: 10px 0; border-bottom: 1px solid var(--border);
    display: flex; gap: 10px; align-items: center;
}
.sidebar .popular-item:last-child { border-bottom: none; }
.sidebar .popular-rank {
    width: 26px; height: 26px; border-radius: 50%;
    background: var(--primary); color: white;
    display: flex; align-items: center; justify-content: center;
    font-size: 13px; font-weight: 700; flex-shrink: 0;
}
.sidebar .popular-title { font-size: 14px; line-height: 1.4; }
.sidebar .popular-meta { font-size: 12px; color: var(--text-light); }

/* --- 评论区域 --- */
.comment-section { margin-top: 40px; }
.comment-section .section-title { font-size: 20px; margin-bottom: 20px; }
.comment-form { margin-bottom: 30px; }
.comment-form textarea {
    width: 100%; padding: 14px; border: 2px solid var(--border);
    border-radius: var(--radius); font-size: 15px; resize: vertical;
    min-height: 100px; outline: none; font-family: inherit;
}
.comment-form textarea:focus { border-color: var(--primary); }
.comment-form button {
    margin-top: 10px; padding: 10px 24px;
    background: var(--primary); color: white; border: none;
    border-radius: 20px; font-size: 14px; cursor: pointer;
    transition: background 0.2s;
}
.comment-form button:hover { background: var(--primary-dark); }

/* 评论列表 */
.comment-item {
    background: var(--white); border-radius: var(--radius); padding: 20px;
    margin-bottom: 16px; box-shadow: var(--shadow); border: 1px solid var(--border);
}
.comment-item .comment-header {
    display: flex; align-items: center; gap: 10px; margin-bottom: 10px;
}
.comment-item .comment-avatar {
    width: 36px; height: 36px; border-radius: 50%;
    background: var(--primary-light); color: var(--primary);
    display: flex; align-items: center; justify-content: center;
    font-size: 16px; font-weight: 600;
}
.comment-item .comment-author { font-weight: 600; font-size: 14px; }
.comment-item .comment-time { font-size: 12px; color: var(--text-light); }
.comment-item .comment-content { font-size: 15px; margin-bottom: 8px; line-height: 1.6; }
.comment-item .comment-actions { font-size: 13px; }
.comment-item .comment-actions a {
    color: var(--text-light); margin-right: 16px; cursor: pointer;
}
.comment-item .comment-actions a:hover { color: var(--primary); }

/* 回复列表缩进 */
.comment-replies { margin-left: 40px; }

/* 回复表单（默认隐藏） */
.reply-form {
    display: none; margin-top: 12px; padding-top: 12px;
    border-top: 1px solid var(--border);
}
.reply-form textarea {
    width: 100%; padding: 10px; border: 2px solid var(--border);
    border-radius: var(--radius); font-size: 14px; resize: vertical;
    min-height: 70px; outline: none; font-family: inherit;
}
.reply-form textarea:focus { border-color: var(--primary); }
.reply-form button {
    margin-top: 8px; padding: 7px 18px;
    background: var(--primary); color: white; border: none;
    border-radius: 16px; font-size: 13px; cursor: pointer;
}

/* --- 分页 --- */
.pagination {
    display: flex; justify-content: center; gap: 6px; margin-top: 30px;
}
.pagination a, .pagination span {
    display: inline-block; padding: 8px 14px; border-radius: 6px;
    font-size: 14px; border: 1px solid var(--border);
    color: var(--text); transition: all 0.2s;
}
.pagination a:hover { background: var(--primary-light); color: var(--primary); border-color: var(--primary); }
.pagination .current { background: var(--primary); color: white; border-color: var(--primary); }
.pagination .disabled { color: #ccc; pointer-events: none; }

/* --- 登录/注册表单 --- */
.auth-page { display: flex; justify-content: center; margin-top: 50px; }
.auth-form {
    background: var(--white); padding: 40px; border-radius: var(--radius);
    box-shadow: var(--shadow); width: 420px; max-width: 100%;
}
.auth-form h2 { text-align: center; margin-bottom: 28px; font-size: 24px; }
.form-group { margin-bottom: 18px; }
.form-group label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; color: var(--text); }
.form-group input, .form-group select, .form-group textarea {
    width: 100%; padding: 10px 14px; border: 2px solid var(--border);
    border-radius: var(--radius); font-size: 15px; outline: none; font-family: inherit;
    transition: border-color 0.2s;
}
.form-group input:focus { border-color: var(--primary); }
.form-group .error-msg { color: #dc2626; font-size: 13px; margin-top: 4px; }
.btn-primary {
    width: 100%; padding: 12px; background: var(--primary); color: white;
    border: none; border-radius: 24px; font-size: 16px; font-weight: 600;
    cursor: pointer; transition: background 0.2s; margin-top: 8px;
}
.btn-primary:hover { background: var(--primary-dark); }
.auth-switch { text-align: center; margin-top: 16px; font-size: 14px; color: var(--text-light); }

/* 提示消息 */
.alert {
    padding: 12px 16px; border-radius: var(--radius); margin-bottom: 16px; font-size: 14px;
}
.alert-error { background: #fef2f2; color: #dc2626; border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: #16a34a; border: 1px solid #bbf7d0; }

/* --- 搜索页 --- */
.search-header { margin: 30px 0; }
.search-header input {
    width: 100%; padding: 14px 20px; border: 2px solid var(--border);
    border-radius: 30px; font-size: 16px; outline: none;
}
.search-header input:focus { border-color: var(--primary); }
.search-result-count { color: var(--text-light); margin-bottom: 20px; font-size: 14px; }

/* --- 管理后台 --- */
.admin-layout { display: flex; gap: 30px; margin-top: 30px; }
.admin-sidebar { width: 220px; flex-shrink: 0; }
.admin-sidebar .widget { position: sticky; top: 80px; }
.admin-sidebar ul { list-style: none; }
.admin-sidebar a {
    display: block; padding: 10px 14px; border-radius: 6px; color: var(--text);
    font-size: 14px; transition: background 0.2s;
}
.admin-sidebar a:hover, .admin-sidebar a.active { background: var(--primary-light); color: var(--primary); }
.admin-content { flex: 1; min-width: 0; }
.admin-table { width: 100%; border-collapse: collapse; background: var(--white); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.admin-table th, .admin-table td { padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--border); font-size: 14px; }
.admin-table th { background: #f8fafc; font-weight: 600; }
.admin-table tr:hover { background: #f8fafc; }
.badge { display: inline-block; padding: 2px 10px; border-radius: 12px; font-size: 12px; font-weight: 600; }
.badge-published { background: #d1fae5; color: #065f46; }
.badge-draft { background: #fef3c7; color: #92400e; }
.badge-archived { background: #e5e7eb; color: #4b5563; }
.badge-pending { background: #dbeafe; color: #1e40af; }
.badge-rejected { background: #fee2e2; color: #991b1b; }
.btn-sm {
    padding: 6px 14px; border-radius: 6px; font-size: 13px; border: none; cursor: pointer;
    transition: background 0.2s; display: inline-block;
}
.btn-edit { background: var(--primary-light); color: var(--primary); }
.btn-edit:hover { background: #dbeafe; }
.btn-danger { background: #fef2f2; color: #dc2626; }
.btn-danger:hover { background: #fecaca; }
.admin-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 30px; }
.stat-card {
    background: var(--white); padding: 24px; border-radius: var(--radius);
    box-shadow: var(--shadow); text-align: center;
}
.stat-card .stat-number { font-size: 32px; font-weight: 700; color: var(--primary); }
.stat-card .stat-label { font-size: 14px; color: var(--text-light); margin-top: 4px; }

/* --- 响应式 --- */
@media (max-width: 768px) {
    .main-layout { flex-direction: column; }
    .sidebar { width: 100%; }
    .category-grid { grid-template-columns: repeat(2, 1fr); }
    .hero h1 { font-size: 26px; }
    .hero-search input { width: 100%; margin-bottom: 10px; }
    .hero-search button { width: 100%; margin-left: 0; }
    .header-search { display: none; }
    .comment-replies { margin-left: 20px; }
    .admin-layout { flex-direction: column; }
    .admin-sidebar { width: 100%; }
    .admin-stats { grid-template-columns: repeat(2, 1fr); }
    .article-detail { padding: 20px; }
}
