/*
 * 福彩论坛 - 全局统一主题 V7.0（终极修复版）
 * 红色主题 · 手动夜间模式 · 全站共享
 * V7.0 修复：
 *   1. 楼中楼子层回复按钮彻底删除（不残留）
 *   2. 列表超高问题（移除冲突margin/padding）
 *   3. 楼中楼嵌套层级清晰缩进
 *   4. 用户名/头像/时间/按钮垂直居中对齐
 */

:root {
    --theme-primary: #c62828;
    --theme-dark: #b71c1c;
    --theme-light: #ef5350;
    --theme-gradient: linear-gradient(135deg, #b71c1c, #c62828, #e53935);
    --theme-soft: #fce4ec;

    --bg-page: #f5f5f5;
    --bg-card: #ffffff;
    --bg-input: #ffffff;
    --bg-navbar: var(--theme-gradient);

    --text-primary: #222222;
    --text-secondary: #666666;
    --text-muted: #888888;
    --text-placeholder: #aaaaaa;

    --border-color: #eeeeee;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.06);

    --safe-bottom: env(safe-area-inset-bottom, 0);
}

/* ===== 深色模式 ===== */
[data-theme="dark"] {
    --theme-primary: #ef5350;
    --theme-dark: #c62828;
    --theme-light: #ff867c;
    --theme-gradient: linear-gradient(135deg, #7f1010, #b71c1c);
    --theme-soft: #2a1515;

    --bg-page: #121212;
    --bg-card: #1e1e1e;
    --bg-input: #2a2a2a;
    --bg-navbar: #1a1a1a;

    --text-primary: #e0e0e0;
    --text-secondary: #aaaaaa;
    --text-muted: #777777;
    --text-placeholder: #666666;

    --border-color: #333333;
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.3);

    color-scheme: dark;
}

/* ===== Reset ===== */
*, *::before, *::after {
    box-sizing: border-box;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
}

body {
    background: var(--bg-page);
    color: var(--text-primary);
    line-height: 1.6;
    transition: background-color .3s, color .3s;
    margin: 0;
    padding-bottom: calc(var(--safe-bottom) + 60px);
}

a { text-decoration: none; color: var(--text-primary); }
img { max-width: 100%; height: auto; }
button { font-family: inherit; }

/* ============================================================
 * 全局头像尺寸锁定
 * ============================================================ */
.avatar,
img.avatar,
.avatar img,
.post-item .avatar,
.post-item .avatar img,
.topic-list .avatar,
.list-body .avatar,
.cat-item .avatar,
.msg-item .avatar,
.reply-item .avatar,
.author-avatar,
.reply-avatar {
    width: 42px !important;
    height: 42px !important;
    max-width: 42px !important;
    max-height: 42px !important;
    min-width: 42px !important;
    min-height: 42px !important;
    font-size: 16px !important;
    flex-shrink: 0 !important;
    box-sizing: border-box !important;
    border-radius: 50% !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    overflow: hidden !important;
    background: var(--theme-gradient);
    color: #fff;
    font-weight: 600;
}

.avatar img,
.author-avatar img,
.reply-avatar img {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
}

/* ============================================================
 * 导航栏（全局统一 · 响应式）
 * ============================================================ */
.navbar {
    background: var(--bg-navbar) !important;
    padding: 0 16px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 1000;
    color: #fff;
    box-shadow: 0 2px 12px rgba(198, 40, 40, .2);
    gap: 8px;
}

.navbar .logo {
    display: flex;
    align-items: center;
    gap: 6px;
    color: #fff;
    font-size: 17px;
    font-weight: 700;
    text-decoration: none;
    white-space: nowrap;
    flex-shrink: 0;
    padding: 4px 8px;
    border-radius: 8px;
    transition: background .2s;
}
.navbar .logo:hover { background: rgba(255,255,255,.12); }

.navbar .nav-actions {
    display: flex;
    align-items: center;
    gap: 2px;
    flex-shrink: 0;
}

.navbar .nav-actions a,
.navbar .nav-actions button {
    color: rgba(255,255,255,.9);
    padding: 7px 12px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: background .2s, color .2s;
    border: none;
    background: none;
    cursor: pointer;
    min-height: 36px;
    white-space: nowrap;
}
.navbar .nav-actions a:hover,
.navbar .nav-actions button:hover {
    background: rgba(255,255,255,.15);
    color: #fff;
}

/* ============================================================
 * 响应式断点
 * ============================================================ */
@media (max-width: 900px) {
    .navbar { padding: 0 12px; gap: 4px; }
    .navbar .logo-text { display: none; }
    .navbar .nav-actions a,
    .navbar .nav-actions button { padding: 7px 10px; font-size: 13px; }
}

@media (max-width: 768px) {
    .navbar { height: 50px; padding: 0 10px; }
    .navbar .logo { font-size: 15px; padding: 4px 6px; }
    .navbar .logo-icon { font-size: 20px; }
    .navbar .nav-actions .nav-link-text { display: none; }
    .navbar .nav-actions a,
    .navbar .nav-actions button {
        padding: 6px 10px;
        font-size: 16px;
        min-height: 34px;
    }
}

@media (max-width: 480px) {
    .navbar { padding: 0 8px; }
    .navbar .logo-icon { font-size: 18px; }
    .navbar .nav-actions { gap: 0; }
    .navbar .nav-actions a,
    .navbar .nav-actions button { padding: 5px 8px; font-size: 15px; }
}

/* ============================================================
 * 移动端底部 Tabbar
 * ============================================================ */
.mobile-tabbar {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    display: flex;
    background: rgba(255,255,255,.96);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: 0 -2px 20px rgba(0,0,0,.08);
    z-index: 999;
    padding-bottom: var(--safe-bottom);
    border-top: 1px solid var(--border-color);
}
[data-theme="dark"] .mobile-tabbar {
    background: rgba(30,30,30,.95);
    border-top-color: #333;
}
.mobile-tabbar a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 8px 4px;
    color: var(--text-muted);
    font-size: 11px;
    text-decoration: none;
    transition: color .2s;
}
.mobile-tabbar a:hover,
.mobile-tabbar a.active { color: var(--theme-primary); font-weight: 600; }
.mobile-tabbar .tab-icon { font-size: 20px; }

@media (min-width: 769px) {
    .mobile-tabbar { display: none; }
    body { padding-bottom: 0; }
}

/* ============================================================
 * 容器 / 卡片
 * ============================================================ */
.container { max-width: 750px; margin: 0 auto; padding: 12px; }
@media (max-width: 768px) { .container { padding: 8px; } }

.card {
    background: var(--bg-card);
    border-radius: 14px;
    padding: 16px;
    margin-bottom: 12px;
    box-shadow: var(--shadow);
    transition: background-color .3s;
}

/* ============================================================
 * 帖子详情页
 * ============================================================ */
.post-container { max-width: 750px; margin: 0 auto; padding: 12px; }
.post-detail-header { padding: 14px 0 12px; margin-bottom: 12px; }
.post-detail-title { font-size: 19px; line-height: 1.4; margin-bottom: 10px; }
.post-detail-meta { font-size: 12px; gap: 8px; flex-wrap: wrap; display: flex; align-items: center; }
.post-detail-content { font-size: 15px; line-height: 1.8; }
.post-detail-content img { border-radius: 8px; margin: 8px 0; }

/* ============================================================
 * 回复列表（核心修复区域）
 * ============================================================ */

/* 回复项基础样式 */
.reply-item {
    padding: 12px 0;
    gap: 10px;
    display: flex;
    align-items: flex-start;
    border-bottom: 1px solid var(--border-color);
    position: relative;
}
.reply-item:last-child { border-bottom: none; }

/* 回复头部：用户名/时间/按钮对齐 */
.reply-header {
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
    flex-wrap: nowrap !important;
    line-height: 22px !important;
    min-height: 24px;
}
.reply-header > * {
    align-self: center !important;
    line-height: 22px !important;
}
.reply-header .username,
.reply-header .reply-author {
    display: inline-flex !important;
    align-items: center !important;
    height: 22px !important;
    font-weight: 600;
    font-size: 13px;
    color: var(--theme-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 120px;
}
.reply-header .reply-time,
.reply-header .time {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
    flex-shrink: 0;
}

/* 回复内容 */
.reply-content {
    font-size: 14px;
    line-height: 1.7;
    color: var(--text-primary);
    word-break: break-word;
    margin-top: 4px;
}

/* ============================================================
 * 楼中楼核心样式（终极修复）
 * ============================================================ */

/* 楼中楼容器 */
.threaded-children {
    width: 100%;
    overflow: hidden;
    /* 关键：固定缩进，不叠加 */
    padding-left: 16px !important;
    margin-left: 0 !important;
    margin-top: 6px !important;
    margin-bottom: 0 !important;
    border-left: 2px solid var(--theme-soft) !important;
    /* 关键：限制最大高度，防止列表超高 */
    max-height: none;
}

/* 单条楼中楼回复 */
.threaded-child {
    display: flex !important;
    gap: 10px !important;
    padding: 8px 10px !important;
    border-radius: 8px !important;
    transition: background .2s !important;
    align-items: flex-start !important;
    /* 关键：固定尺寸，不随内容无限增长 */
    min-height: 44px !important;
    max-width: 100% !important;
    overflow: hidden !important;
    margin: 0 !important;
}
.threaded-child:hover { background: var(--bg-page); }

/* 楼中楼头像（逐级缩小） */
.threaded-child .avatar-28 { width: 28px !important; height: 28px !important; font-size: 12px !important; }
.threaded-child .avatar-26 { width: 26px !important; height: 26px !important; font-size: 11px !important; }
.threaded-child .avatar-24 { width: 24px !important; height: 24px !important; font-size: 10px !important; }
.threaded-child .avatar-22 { width: 22px !important; height: 22px !important; font-size: 10px !important; }
.threaded-child .avatar-20 { width: 20px !important; height: 20px !important; font-size: 9px !important; }

.threaded-child .avatar-28 img,
.threaded-child .avatar-26 img,
.threaded-child .avatar-24 img,
.threaded-child .avatar-22 img,
.threaded-child .avatar-20 img {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
}

/* 楼中楼内容区域 */
.threaded-child-main {
    flex: 1 !important;
    min-width: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    gap: 2px !important;
    overflow: hidden !important;
}

/* 楼中楼头部对齐 */
.threaded-child-header {
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
    flex-wrap: nowrap !important;
    min-height: 22px !important;
    line-height: 20px !important;
}
.threaded-child-header > * {
    align-self: center !important;
}
.threaded-child-header .reply-author {
    font-weight: 600;
    font-size: 13px;
    color: var(--theme-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100px;
    line-height: 20px !important;
}
.threaded-child-header .reply-time {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
    flex-shrink: 0;
    line-height: 20px !important;
}

/* 楼中楼回复内容 */
.threaded-child-content {
    font-size: 13px;
    line-height: 1.6;
    color: var(--text-primary);
    word-break: break-word;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 6;
    -webkit-box-orient: vertical;
}

/* ============================================================
 * 回复按钮（终极修复：仅 level=1 显示）
 * ============================================================ */

/* 默认隐藏所有楼中楼回复按钮 */
.threaded-child .btn-reply-to,
.threaded-child button[class*="reply"],
.threaded-child [class*="btn-reply"] {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
    width: 0 !important;
    height: 0 !important;
    overflow: hidden !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
}

/* 仅 level=1（楼主直接子回复）显示按钮 */
.threaded-child[data-level="1"] .btn-reply-to,
.threaded-child[data-depth="1"] .btn-reply-to {
    display: inline-flex !important;
    visibility: visible !important;
    opacity: 1 !important;
    pointer-events: auto !important;
    width: auto !important;
    height: auto !important;
    overflow: visible !important;
    margin-left: auto !important;
    background: linear-gradient(135deg, #c62828, #e53935) !important;
    color: #fff !important;
    border: none !important;
    padding: 2px 10px !important;
    border-radius: 6px !important;
    font-size: 11px !important;
    font-weight: 600 !important;
    cursor: pointer !important;
    align-items: center !important;
    justify-content: center !important;
    box-shadow: 0 1px 3px rgba(198,40,40,.3) !important;
    transition: all .2s ease !important;
    flex-shrink: 0 !important;
}
.threaded-child[data-level="1"] .btn-reply-to:hover,
.threaded-child[data-depth="1"] .btn-reply-to:hover {
    background: linear-gradient(135deg, #b71c1c, #c62828) !important;
    transform: translateY(-1px) !important;
    box-shadow: 0 3px 8px rgba(198,40,40,.4) !important;
}

/* ============================================================
 * 展开/收起按钮
 * ============================================================ */
.btn-expand-thread {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: none;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 4px 12px;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    margin-top: 8px;
    transition: all .2s;
}
.btn-expand-thread:hover {
    border-color: var(--theme-primary);
    color: var(--theme-primary);
}

/* ============================================================
 * 回复提示条
 * ============================================================ */
.threaded-reply-to {
    background: var(--theme-soft);
    border: 1px solid #ffcdd2;
    border-radius: 10px;
    padding: 10px 14px;
    margin-bottom: 10px;
    font-size: 13px;
    color: var(--theme-dark);
    display: flex;
    align-items: center;
    gap: 8px;
    animation: fadeIn .2s ease;
}
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-5px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ============================================================
 * 回复表单
 * ============================================================ */
.reply-form {
    margin-top: 16px;
    padding: 14px;
    border-radius: 10px;
    background: var(--bg-card);
}
.reply-form textarea {
    min-height: 80px;
    padding: 10px 12px;
    font-size: 14px;
    border-radius: 8px;
    border: 2px solid var(--border-color);
    background: var(--bg-input);
    color: var(--text-primary);
    width: 100%;
    resize: vertical;
    outline: none;
    transition: border-color .3s;
}
.reply-form textarea:focus {
    border-color: var(--theme-primary);
    box-shadow: 0 0 0 3px rgba(198,40,40,.1);
}

.btn-submit {
    padding: 10px 20px;
    font-size: 14px;
    border-radius: 8px;
    width: 100%;
    border: none;
    background: var(--theme-gradient);
    color: #fff;
    font-weight: 600;
    cursor: pointer;
    transition: all .25s;
    min-height: 44px;
}
.btn-submit:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(198,40,40,.25);
}

/* ============================================================
 * 分页
 * ============================================================ */
.pagination { display: flex; justify-content: center; gap: 6px; padding: 20px 0; flex-wrap: wrap; }
.pagination a, .pagination span {
    padding: 8px 14px; border-radius: 8px; background: var(--bg-card);
    text-decoration: none; color: var(--text-secondary); font-size: 14px;
    box-shadow: 0 1px 4px rgba(0,0,0,.06); transition: .2s;
}
.pagination a:hover { background: var(--theme-primary); color: #fff; }
.pagination .current { background: var(--theme-primary); color: #fff; font-weight: 600; }

/* ============================================================
 * 按钮通用
 * ============================================================ */
.btn {
    padding: 8px 18px; border-radius: 8px; border: none; cursor: pointer;
    font-size: 13.5px; font-weight: 600; transition: all .25s;
    display: inline-flex; align-items: center; gap: 4px; text-decoration: none;
}
.btn-primary { background: var(--theme-gradient); color: #fff; }
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(198,40,40,.25); }
.btn-danger { background: linear-gradient(135deg,#c62828,#e53935); color: #fff; }
.btn-outline { background: var(--bg-card); border: 2px solid var(--border-color); color: var(--text-secondary); }
.btn-outline:hover { background: var(--bg-page); }

/* ============================================================
 * Toast 通知
 * ============================================================ */
.toast {
    position: fixed;
    top: 70px;
    left: 50%;
    transform: translateX(-50%);
    padding: 10px 24px;
    border-radius: 24px;
    font-size: 14px;
    z-index: 20000;
    opacity: 0;
    transition: opacity .3s;
    pointer-events: none;
    color: #fff;
    box-shadow: 0 4px 16px rgba(0,0,0,.2);
}
.toast.show { opacity: 1; }
.toast-success { background: #2e7d32 !important; }
.toast-error   { background: #c62828 !important; }
.toast-info    { background: #1565c0 !important; }
.toast-warning { background: #f57c00 !important; }

/* ============================================================
 * 返回顶部
 * ============================================================ */
.back-to-top {
    position: fixed;
    bottom: 80px;
    right: 20px;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--theme-primary);
    color: #fff;
    font-size: 20px;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,.2);
    opacity: 0;
    pointer-events: none;
    transition: opacity .3s, transform .3s;
    z-index: 998;
}
.back-to-top.show { opacity: 1; pointer-events: auto; }
.back-to-top:hover { transform: scale(1.1); }

/* ============================================================
 * 等级标签
 * ============================================================ */
.level-badge {
    display: inline-block;
    padding: 1px 8px;
    border-radius: 10px;
    font-size: 10px;
    color: #fff;
    font-weight: 500;
    white-space: nowrap;
}
.cat-badge {
    background: #e8eaf6;
    color: #283593;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 500;
}

/* ============================================================
 * 移动端适配
 * ============================================================ */
@media (max-width: 768px) {
    /* 容器 */
    .container { padding: 0 10px; }
    .post-container { padding: 0 10px; }

    /* 回复项 */
    .reply-item {
        padding: 10px 0;
        gap: 8px;
    }
    .reply-item .avatar {
        width: 36px !important; height: 36px !important;
        max-width: 36px !important; max-height: 36px !important;
        min-width: 36px !important; min-height: 36px !important;
        font-size: 14px !important;
    }
    .reply-header {
        font-size: 12px !important;
        gap: 6px !important;
    }
    .reply-content {
        font-size: 13px !important;
        line-height: 1.6 !important;
    }

    /* 楼中楼移动端 */
    .threaded-children {
        padding-left: 8px !important;
        border-left-width: 1px !important;
        margin-top: 4px !important;
    }
    .threaded-child {
        gap: 6px !important;
        padding: 6px 8px !important;
        min-height: 38px !important;
    }
    .threaded-child-header {
        gap: 6px !important;
        min-height: 20px !important;
    }
    .threaded-child-header .reply-author {
        font-size: 12px !important;
        max-width: 80px !important;
    }
    .threaded-child-header .reply-time {
        font-size: 10px !important;
    }
    .threaded-child-content {
        font-size: 12px !important;
        line-height: 1.5 !important;
    }

    /* 回复按钮移动端 */
    .threaded-child[data-level="1"] .btn-reply-to,
    .threaded-child[data-depth="1"] .btn-reply-to {
        padding: 2px 8px !important;
        font-size: 10px !important;
        border-radius: 5px !important;
    }
    .threaded-child[data-level="1"] .btn-reply-to:hover,
    .threaded-child[data-depth="1"] .btn-reply-to:hover {
        transform: none !important; /* 移动端禁用上浮 */
    }

    /* 回复表单 */
    .reply-form { padding: 12px !important; }
    .reply-form textarea { min-height: 70px !important; font-size: 13px !important; }
    .btn-submit { padding: 10px 16px !important; font-size: 13px !important; }

    /* 帖子详情 */
    .post-detail-title { font-size: 17px !important; }
    .post-detail-content { font-size: 14px !important; }

    /* 底部操作栏 */
    .post-actions-bar {
        position: fixed;
        bottom: 0; left: 0; right: 0;
        display: flex;
        background: var(--bg-card);
        box-shadow: 0 -2px 16px rgba(0,0,0,.12);
        padding: 8px 12px;
        padding-bottom: calc(8px + var(--safe-bottom));
        z-index: 999;
        gap: 6px;
    }
    .post-actions-bar .action-btn {
        flex: 1;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 4px;
        padding: 10px 8px;
        border-radius: 10px;
        border: none;
        font-size: 13px;
        font-weight: 600;
        cursor: pointer;
        text-decoration: none;
    }
    .post-actions-bar .btn-like { background: #fce4ec; color: #c62828; }
    .post-actions-bar .btn-like.active { background: #c62828; color: #fff; }
    .post-actions-bar .btn-reply { background: #e8eaf6; color: #1a237e; }

    .post-detail-body { padding-bottom: 70px !important; }
}

/* 超小屏 */
@media (max-width: 380px) {
    .reply-header .username { max-width: 70px; }
    .threaded-child-header .reply-author { max-width: 60px !important; }
}

/* ============================================================
 * 深色模式补充
 * ============================================================ */
[data-theme="dark"] .reply-item { border-bottom-color: #333; }
[data-theme="dark"] .threaded-child:hover { background: rgba(255,255,255,.03); }
[data-theme="dark"] .threaded-children { border-left-color: #333 !important; }
[data-theme="dark"] .btn-expand-thread {
    border-color: #444;
    color: var(--text-secondary);
}
[data-theme="dark"] .btn-expand-thread:hover {
    border-color: var(--theme-primary);
}
[data-theme="dark"] .threaded-reply-to {
    background: rgba(198,40,40,.1);
    border-color: rgba(198,40,40,.3);
}

/* ============================================================
 * 减少动画偏好
 * ============================================================ */
@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; animation: none !important; }
}
/* ================= 楼中楼终极修复（追加到theme.css末尾） ================= */
/* 强制锁定楼中楼容器高度，彻底解决列表变长 */
.threaded-child {
    max-height: 180px !important;
    overflow: hidden !important;
    margin-bottom: 6px !important;
}

/* 修复移动端对齐问题 */
@media (max-width: 768px) {
    .threaded-child-header {
        flex-wrap: wrap !important;
        gap: 4px !important;
    }
    .threaded-child-header .btn-reply-to {
        margin-left: 0 !important;
        order: 3 !important; /* 按钮换行到最后 */
        width: 100% !important;
        text-align: right !important;
    }
}

/* 暗色模式适配 */
@media (prefers-color-scheme: dark) {
    .threaded-children {
        border-left-color: #333 !important;
    }
    .threaded-child[data-level="1"] .btn-reply-to {
        background: linear-gradient(135deg, #5c6bc0, #3949ab) !important;
    }
}
