/**
 * ==========================================================================
 * 评论系统样式 - Comments System Styles
 * ==========================================================================
 * 功能：
 * 1. 评论表单 - 用户信息输入、评论内容输入
 * 2. 评论列表 - Gravatar 头像、嵌套回复、时间格式化
 * 3. Markdown 渲染 - 代码高亮、安全的 HTML 清理
 * 4. 交互状态 - 加载、提交、错误提示
 * ==========================================================================
 */


/* ========== 评论区整体 ========== */
.comments-section {
    margin-top: 60px;
    padding-top: 40px;
    border-top: 2px solid #e9ecef;
}

/* 评论布局：左侧窄边栏，右侧内容 */
.comments-layout {
    display: flex;
    gap: 20px;
    align-items: flex-start;
}

/* 左侧：窄边栏（Tab + 操作按钮） */
.comments-sidebar {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* 右侧：评论内容 */
.comments-content {
    flex: 1;
    min-width: 0;
}


/* ========== Tab 切换（竖向排列） ========== */
.comment-tabs {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.tab-btn {
    padding: 10px 12px;
    background: transparent;
    border: 2px solid #e9ecef;
    border-radius: 8px;
    color: #6c757d;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
    text-align: center;
}

.tab-btn:hover {
    border-color: #6366f1;
    color: #6366f1;
    background: rgba(99, 102, 241, 0.05);
    transform: translateX(-3px);
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.2);
}

.tab-btn.active {
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: white;
    border-color: #6366f1;
    box-shadow: 0 3px 10px rgba(99, 102, 241, 0.3);
}


/* ========== 侧边栏操作按钮（竖向排列） ========== */
.sidebar-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-top: 8px;
    border-top: 1px solid #e9ecef;
}

.sidebar-actions .btn-action {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px;
    width: 100%;
    height: 40px;
    border: 2px solid #dee2e6;
    border-radius: 8px;
    background: transparent;
    cursor: pointer;
    transition: all 0.3s ease;
}

.sidebar-actions .btn-action svg {
    width: 18px;
    height: 18px;
}

/* 点赞按钮 */
.sidebar-actions .btn-like {
    border-color: #e83e8c;
    color: #e83e8c;
}

.sidebar-actions .btn-like:hover {
    background: linear-gradient(135deg, #e83e8c, #ff6b9d);
    color: white;
    border-color: #e83e8c;
    transform: translateX(-3px);
}

.sidebar-actions .btn-like:hover svg {
    fill: white;
    stroke: white;
}

.sidebar-actions .btn-like.liked {
    background: linear-gradient(135deg, #e83e8c, #ff6b9d);
    color: white;
    border-color: #e83e8c;
}

.sidebar-actions .btn-like.liked svg {
    fill: white;
}

/* 分享按钮 */
.sidebar-actions .btn-share {
    border-color: #6366f1;
    color: #6366f1;
}

.sidebar-actions .btn-share:hover {
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: white;
    border-color: #6366f1;
    transform: translateX(-3px);
}

.sidebar-actions .btn-share:hover svg {
    stroke: white;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* ========== Giscus 容器 ========== */
.giscus-container {
    min-height: 200px;
}

/* 确保 Giscus iframe 不受外部样式影响 */
.giscus-container iframe {
    border: none !important;
    width: 100% !important;
    max-width: 100% !important;
}


/* ========== 评论表单 ========== */
.comment-form-container {
    background: #1c1f26;
    border: 1px solid #30363d;
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 40px;
}

.comment-form .form-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
    margin-bottom: 15px;
}

.comment-form .form-group {
    margin-bottom: 0;
}

.comment-form input,
.comment-form textarea {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid #30363d;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    transition: all 0.3s ease;
    background: #0d1117;
    color: #c9d1d9;
}

.comment-form input:focus,
.comment-form textarea:focus {
    outline: none;
    border-color: #6366f1;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
    background: #161b22;
}

.comment-form input::placeholder,
.comment-form textarea::placeholder {
    color: #8b949e;
}

.comment-form textarea {
    resize: vertical;
    min-height: 100px;
    line-height: 1.6;
}

.form-hint {
    font-size: 12px;
    color: #8b949e;
    margin-top: 8px;
}

.form-actions {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-top: 15px;
}

.btn-submit {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 28px;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-submit:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
}

.btn-submit:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-submit svg {
    animation: none;
}

.btn-submit.loading svg {
    animation: spin 1s linear infinite;
}

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

.reply-hint {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: #8b949e;
}

.reply-hint strong {
    color: #6366f1;
}

.btn-cancel-reply {
    background: none;
    border: none;
    color: #dc3545;
    font-size: 18px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}

.btn-cancel-reply:hover {
    color: #c82333;
}


/* ========== 评论列表 ========== */
.comments-list {
    margin-top: 30px;
}

.loading-comments {
    text-align: center;
    padding: 40px 20px;
    color: #8b949e;
}

.loading-comments .spinner {
    width: 40px;
    height: 40px;
    margin: 0 auto 15px;
    border: 3px solid #30363d;
    border-top: 3px solid #6366f1;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.empty-comments {
    text-align: center;
    padding: 60px 20px;
    color: #8b949e;
}

.empty-comments svg {
    width: 64px;
    height: 64px;
    color: #30363d;
    margin-bottom: 15px;
}


/* ========== 单个评论项 ========== */
.comment-item {
    background: #1c1f26;
    border: 1px solid #30363d;
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 16px;
    transition: all 0.3s ease;
}

.comment-item:hover {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
    border-color: #484f58;
}

.comment-header {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 12px;
}

.comment-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: #30363d;
    flex-shrink: 0;
    object-fit: cover;
}

.comment-author-info {
    flex: 1;
}

.comment-author {
    font-weight: 600;
    font-size: 15px;
    color: #c9d1d9;
    display: inline-block;
    margin-right: 8px;
}

.comment-author a {
    color: #58a6ff;
    text-decoration: none;
    transition: color 0.3s;
}

.comment-author a:hover {
    color: #79c0ff;
    text-decoration: underline;
}

.comment-featured {
    display: inline-block;
    background: linear-gradient(135deg, #ffd700, #ffed4e);
    color: #856404;
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 4px;
    font-weight: 600;
}

.comment-time {
    font-size: 13px;
    color: #8b949e;
    margin-top: 2px;
}

.comment-content {
    color: #c9d1d9;
    line-height: 1.8;
    font-size: 14px;
    margin-bottom: 12px;
    word-wrap: break-word;
}

/* Markdown 内容样式 */
.comment-content p {
    margin-bottom: 12px;
}

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

.comment-content code {
    background: #30363d;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
    font-family: 'Courier New', monospace;
    color: #f97583;
}

.comment-content pre {
    background: #0d1117;
    color: #c9d1d9;
    padding: 16px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 12px 0;
    border: 1px solid #30363d;
}

.comment-content pre code {
    background: none;
    padding: 0;
    color: inherit;
}

.comment-content a {
    color: #58a6ff;
    text-decoration: none;
}

.comment-content a:hover {
    text-decoration: underline;
}

.comment-actions {
    display: flex;
    gap: 16px;
    align-items: center;
}

.btn-reply {
    background: none;
    border: none;
    color: #58a6ff;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: color 0.3s;
}

.btn-reply:hover {
    color: #79c0ff;
}

.btn-reply svg {
    width: 14px;
    height: 14px;
}


/* ========== 嵌套回复 ========== */
.comment-replies {
    margin-top: 16px;
    margin-left: 60px;
    border-left: 2px solid #30363d;
    padding-left: 20px;
}

.comment-replies .comment-item {
    background: #161b22;
}

.comment-replies .comment-avatar {
    width: 40px;
    height: 40px;
}


/* ========== 加载更多 ========== */
.load-more-comments {
    text-align: center;
    margin-top: 30px;
}

.btn-load-more {
    padding: 12px 32px;
    background: white;
    border: 2px solid #6366f1;
    color: #6366f1;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-load-more:hover {
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: white;
    transform: translateY(-2px);
}


/* ========== 响应式设计 ========== */
@media (max-width: 768px) {
    /* 移动端：评论区垂直布局 */
    .comments-layout {
        flex-direction: column;
        gap: 16px;
    }

    .comments-sidebar {
        width: 100%;
        flex-direction: row;
        justify-content: space-between;
    }

    /* 移动端：Tab 横向排列 */
    .comment-tabs {
        flex-direction: row;
        flex: 1;
        gap: 6px;
    }

    .tab-btn {
        flex: 1;
        padding: 8px 10px;
        font-size: 12px;
    }

    .tab-btn:hover {
        transform: translateY(-2px);
    }

    /* 移动端：操作按钮横向排列 */
    .sidebar-actions {
        flex-direction: row;
        padding-top: 0;
        padding-left: 12px;
        border-top: none;
        border-left: 1px solid #e9ecef;
        gap: 6px;
    }

    .sidebar-actions .btn-action {
        width: 36px;
        height: 36px;
        padding: 8px;
    }

    .sidebar-actions .btn-action svg {
        width: 16px;
        height: 16px;
    }

    .sidebar-actions .btn-action:hover {
        transform: translateY(-2px);
    }

    /* 原有的响应式规则 */
    .comment-form .form-row {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .comment-replies {
        margin-left: 20px;
        padding-left: 12px;
    }

    .comment-avatar {
        width: 40px !important;
        height: 40px !important;
    }
}


/* ========== 错误提示 ========== */
.comment-error {
    background: #f8d7da;
    color: #721c24;
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.comment-error svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.comment-success {
    background: #d4edda;
    color: #155724;
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.comment-success svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}
