/* =========================================================
   components.css — 交互组件与增强
   内容：移动端菜单 / Toast / 对话框 / 骨架屏 / 进度条 /
         回到顶部 / 图片淡入 / 按钮与链接微交互 / 空状态 /
         View Transitions / 文章正文排版
   来源：原 style.css 1827-2432 行（拆分时未改动任何规则）
   ========================================================= */

/* ===== Container Queries 基础 ===== */
.card-grid,
.profile-grid,
.system-grid {
    container-type: inline-size;
}

@container (max-width: 380px) {
    .card-grid > .grid-card {
        padding: 20px;
    }
    .card-grid > .grid-card h3 {
        font-size: 16px;
    }
}

/* ===== 移动端菜单 .nav-toggle 在 CSS 中的完整样式 ===== */
.nav-toggle {
    display: none;
    width: 40px;
    height: 40px;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 0;
    background: transparent;
    border: 0;
    cursor: pointer;
    color: var(--dim);
    flex-shrink: 0;
}

/* authWidget 容器布局（桌面 flex；移动端由下方媒体查询隐藏） */
#authWidget {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

@media (max-width: 860px) {
    .nav-toggle {
        display: grid;
        place-content: center;
    }
    /* 移动端隐藏顶部 authWidget，登录/注册收进汉堡菜单 */
    #authWidget,
    #authStateBtn {
        display: none;
    }    /* 汉堡菜单内的 auth 区块 */
    .nav-auth {
        display: block;
        margin-top: 10px;
        padding-top: 10px;
        border-top: 1px solid var(--line);
    }
    .nav-auth a,
    .nav-auth .nav-auth-logout {
        display: block;
        padding: 12px 24px;
        font-size: 14px;
        border-left: 2px solid transparent;
        color: var(--dim);
    }
    .nav-auth a:hover,
    .nav-auth .nav-auth-logout:hover {
        background: rgba(194, 58, 48, 0.06);
        border-left-color: var(--fire-text);
        color: var(--fire-text);
        cursor: pointer;
    }
    .nav-auth .nav-auth-logout {
        color: var(--dim);
    }
}

/* 桌面端隐藏菜单内 auth 区块 */
@media (min-width: 861px) {
    .nav-auth {
        display: none;
    }
}

/* ===== Toast 提示系统（样式类版） ===== */
#toast-container {
    position: fixed;
    top: 80px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}
.toast-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 20px;
    background: var(--surface, #fff);
    border: 1px solid var(--line-2, #ddd);
    border-radius: var(--r-lg, 12px);
    box-shadow: 0 8px 30px rgba(26, 26, 46, 0.12);
    font-size: 14px;
    color: var(--text, #1a1a2e);
    pointer-events: auto;
    max-width: 380px;
    animation: toastIn 0.3s ease;
    border-left: 4px solid var(--dim, #5c5c74);
}
.toast-item .toast-icon {
    flex-shrink: 0;
    font-size: 16px;
}
.toast-item.toast-success {
    border-left-color: var(--spring-2, #2ecc71);
}
.toast-item.toast-error {
    border-left-color: var(--fire, #c23630);
}
.toast-item.toast-info {
    border-left-color: var(--dim, #5c5c74);
}
.toast-item.toast-out {
    opacity: 0;
    transform: translateX(30px);
    transition: opacity 0.3s, transform 0.3s;
}

/* ===== 确认对话框 ===== */
/* 注意: 旧版 .confirm-overlay/.confirm-box 已被原生 <dialog> 替代，保留为 fallback */
.confirm-overlay {
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: rgba(26, 26, 46, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease;
}
.confirm-box {
    background: var(--surface, #fff);
    border-radius: var(--r-lg, 16px);
    padding: 28px 32px 20px;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 16px 48px rgba(26, 26, 46, 0.2);
    animation: scaleIn 0.2s ease;
    text-align: center;
}
.confirm-msg {
    font-size: 15px;
    color: var(--text, #1a1a2e);
    line-height: 1.6;
    margin-bottom: 24px;
}
.confirm-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
}
.confirm-ok {
    padding: 10px 28px;
    background: var(--fire, #c23630);
    color: #fff;
    border: none;
    border-radius: var(--r-sm, 8px);
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    min-width: 100px;
    transition: filter 0.2s;
}
.confirm-ok:hover {
    filter: brightness(1.1);
}
.confirm-cancel {
    padding: 10px 28px;
    background: transparent;
    color: var(--dim, #5c5c74);
    border: 1px solid var(--line-2, #ddd);
    border-radius: var(--r-sm, 8px);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    min-width: 100px;
    transition: border-color 0.2s, color 0.2s;
}
.confirm-cancel:hover {
    border-color: var(--fire-text);
    color: var(--fire-text);
}

/* ===== 骨架屏加载动画 ===== */
@keyframes skeletonPulse {
    0% { opacity: 0.6; }
    50% { opacity: 0.3; }
    100% { opacity: 0.6; }
}
.skeleton {
    background: var(--surface-3);
    border-radius: var(--r-sm);
    animation: skeletonPulse 1.8s ease-in-out infinite;
    color: transparent !important;
    pointer-events: none;
    user-select: none;
}
.skeleton-line {
    height: 14px;
    margin-bottom: 10px;
    width: 100%;
}
.skeleton-line:last-child {
    width: 65%;
}
.skeleton-line-sm {
    height: 10px;
    width: 40%;
    margin-bottom: 8px;
}
.skeleton-block {
    height: 120px;
    margin-bottom: 16px;
}
.skeleton-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    flex-shrink: 0;
}
.skeleton-table-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--line);
}
.skeleton-admin-table {
    padding: 20px 0;
}
.skeleton-admin-header {
    display: flex;
    gap: 16px;
    margin-bottom: 20px;
}
.skeleton-admin-header .skeleton {
    height: 32px;
    border-radius: var(--r-sm);
}

/* ===== :has() 优化 ===== */
/* 表单输入框聚焦时高亮父容器 */
.form-row:has(input:focus, select:focus, textarea:focus) {
    border-color: var(--fire-2);
}
/* 评论项在悬停时显示删除按钮 */
.comment-item:has(.comment-del) .comment-del {
    opacity: 0;
    transition: opacity 0.2s;
}
.comment-item:has(.comment-del):hover .comment-del {
    opacity: 1;
}
/* 导航项激活态强化 */
.site-header:has(.nav .active) .nav .active {
    color: var(--fire-text);
}

/* ===== 原生 <dialog> 确认弹框 ===== */
.confirm-dialog {
    padding: 28px 32px 20px;
    border: 1px solid var(--line-2);
    border-radius: var(--r-lg, 16px);
    max-width: 400px;
    width: 90%;
    background: var(--surface, #fff);
    color: var(--text, #1a1a2e);
    box-shadow: 0 16px 48px rgba(26, 26, 46, 0.2);
    animation: scaleIn 0.2s ease;
    text-align: center;
}
.confirm-dialog::backdrop {
    background: rgba(26, 26, 46, 0.4);
    animation: fadeIn 0.2s ease;
}
.confirm-dialog .confirm-msg {
    font-size: 15px;
    line-height: 1.6;
    margin-bottom: 24px;
}
.confirm-dialog .confirm-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
}
.confirm-dialog .confirm-ok {
    padding: 10px 28px;
    background: var(--fire, #c23630);
    color: #fff;
    border: none;
    border-radius: var(--r-sm, 8px);
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    min-width: 100px;
    transition: filter 0.2s;
}
.confirm-dialog .confirm-ok:hover {
    filter: brightness(1.1);
}
.confirm-dialog .confirm-cancel {
    padding: 10px 28px;
    background: transparent;
    color: var(--dim, #5c5c74);
    border: 1px solid var(--line-2, #ddd);
    border-radius: var(--r-sm, 8px);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    min-width: 100px;
    transition: border-color 0.2s, color 0.2s;
}
.confirm-dialog .confirm-cancel:hover {
    border-color: var(--fire-text);
    color: var(--fire-text);
}

/* ===== 页面加载进度条 ===== */

/* ===== Skip to content 无障碍跳转 ===== */
.skip-link {
    position: fixed;
    top: -100%;
    left: 16px;
    z-index: 10000;
    padding: 10px 20px;
    background: var(--fire);
    color: #fff;
    font-size: 14px;
    font-weight: 700;
    border-radius: 0 0 var(--r-sm) var(--r-sm);
    transition: top 0.2s;
    text-decoration: none;
}
.skip-link:focus {
    top: 0;
}

/* ===== Header 滚动阴影 ===== */
.site-header.scrolled {
    box-shadow: 0 4px 20px rgba(120, 80, 30, 0.10);
}
@media (prefers-color-scheme: dark) {
    .site-header.scrolled {
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.30);
    }
}

#page-progress {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 9999;
    height: 3px;
    width: 0;
    background: var(--flame-grad);
    box-shadow: 0 0 10px var(--fire-glow), 0 0 4px var(--fire-glow);
    border-radius: 0 2px 2px 0;
    transition: width 0.3s var(--ease), opacity 0.4s;
    pointer-events: none;
}
#page-progress.done {
    width: 100%;
    opacity: 0;
    transition: width 0.2s var(--ease), opacity 0.5s 0.2s;
}

/* ===== 回到顶部按钮 ===== */
#backToTop {
    position: fixed;
    right: 24px;
    bottom: 28px;
    z-index: 900;
    width: 46px;
    height: 46px;
    display: grid;
    place-content: center;
    background: var(--surface);
    border: 1px solid var(--line-2);
    border-radius: 50%;
    box-shadow: var(--shadow);
    color: var(--fire-text);
    font-size: 18px;
    cursor: pointer;
    opacity: 0;
    transform: translateY(16px) scale(0.9);
    transition: opacity 0.3s var(--ease), transform 0.3s var(--ease), border-color 0.2s, box-shadow 0.2s;
    pointer-events: none;
}
#backToTop.show {
    opacity: 1;
    transform: none;
    pointer-events: auto;
}
#backToTop:hover {
    border-color: var(--line-hot);
    box-shadow: var(--shadow), 0 0 16px var(--fire-glow);
    transform: translateY(-3px);
}
#backToTop:active {
    transform: translateY(0) scale(0.94);
}

/* ===== 图片淡入加载 ===== */
img[loading="lazy"],
.profile-pic,
.member-portrait-pic {
    opacity: 0;
    transition: opacity 0.5s var(--ease);
}
img[loading="lazy"].img-loaded,
.profile-pic.img-loaded,
.member-portrait-pic.img-loaded,
img.img-loaded {
    opacity: 1;
}
/* 深色模式下图片不再额外降低透明度（已由 img-loaded 控制） */
@media (prefers-color-scheme: dark) {
    img {
        opacity: 0;
        transition: opacity 0.5s var(--ease);
    }
    img.img-loaded {
        opacity: 0.88;
    }
    img.img-loaded:hover {
        opacity: 1;
    }
}

/* ===== 按钮微交互：按压反馈 ===== */
.primary-btn:active,
.ghost-btn:active,
.auth-btn:active,
.join-btn:active {
    transform: translateY(0) scale(0.97);
    transition-duration: 0.08s;
}

/* ===== 链接悬停下划线动画 ===== */
a.hover-line {
    position: relative;
}
a.hover-line::after {
    content: "";
    position: absolute;
    left: 0;
    bottom: -2px;
    width: 0;
    height: 2px;
    background: var(--flame-grad);
    border-radius: 2px;
    transition: width 0.3s var(--ease);
}
a.hover-line:hover::after {
    width: 100%;
}

/* ===== 空状态美化 ===== */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 60px 20px;
    text-align: center;
    color: var(--dim);
}
.empty-state .empty-icon {
    font-size: 48px;
    opacity: 0.6;
    filter: grayscale(0.3);
}
.empty-state p {
    font-size: 15px;
    line-height: 1.7;
    max-width: 320px;
}
.empty-state a {
    color: var(--fire-text);
    font-weight: 600;
    text-decoration: none;
    border-bottom: 1px solid var(--line-hot);
    transition: border-color 0.2s;
}
.empty-state a:hover {
    border-color: var(--fire-text);
}

/* ===== View Transitions ===== */
@view-transition {
    navigation: auto;
}
::view-transition-old(root) {
    animation: 0.3s ease-out both fadeOut;
}
::view-transition-new(root) {
    animation: 0.3s ease-out both fadeIn;
}
@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ===== 文章正文排版（classic 风格，保留原字体体系） ===== */
.article-body {
    font-size: 1.06rem;
    line-height: 2.1;
    color: var(--text);
    word-break: break-word;
}
.article-body > *:first-child {
    margin-top: 0;
}
.article-body h2,
.article-body h3,
.article-body h4 {
    font-family: var(--display);
    font-weight: 700;
    letter-spacing: 0.04em;
    color: var(--text);
    line-height: 1.45;
}
.article-body h2 {
    font-size: 1.55rem;
    margin: 2.2em 0 0.8em;
    padding-bottom: 0.3em;
    border-bottom: 1px solid var(--line-2);
}
.article-body h3 {
    font-size: 1.3rem;
    margin: 2em 0 0.7em;
}
.article-body h4 {
    font-size: 1.12rem;
    margin: 1.8em 0 0.6em;
}
.article-body p {
    margin: 0 0 1.4em;
    text-align: justify;
}
.article-body a {
    color: var(--fire-text);
    text-decoration: underline;
    text-underline-offset: 3px;
}
.article-body strong {
    color: var(--text);
    font-weight: 700;
}
.article-body ul,
.article-body ol {
    margin: 0 0 1.4em;
    padding-left: 1.6em;
}
.article-body li {
    margin: 0.35em 0;
    line-height: 1.9;
}
.article-body img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 1.2em 0;
}
.article-body table {
    margin: 1.6em 0;
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95rem;
    line-height: 1.7;
    overflow-x: auto;
    display: block;
}
.article-body th,
.article-body td {
    padding: 0.5em 0.9em;
    border: 1px solid var(--line-2);
    text-align: left;
}
.article-body th {
    background: var(--surface-2);
    font-weight: 700;
    color: var(--text);
}
@media (max-width: 640px) {
    .article-body {
        font-size: 1rem;
    }
}
