/* ============================================================
   AI 聊天室 · 商业版 — 现代设计系统
   浅色（默认） + 深色主题（html[data-theme="dark"]）
   ============================================================ */

/* ===== 设计变量（浅色主题） ===== */
:root {
    /* 背景与表面 */
    --bg: #f3f5fb;
    --bg-deco-1: rgba(99, 102, 241, 0.10);
    --bg-deco-2: rgba(56, 189, 248, 0.08);
    --bg-card: #ffffff;
    --bg-card-hover: #f8fafc;
    --bg-glass: rgba(255, 255, 255, 0.78);
    --bg-input: #f1f4f9;
    --bg-overlay: rgba(15, 23, 42, 0.42);

    /* 文字 */
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;

    /* 边框 */
    --border: #e4e9f2;
    --border-light: #eef1f7;

    /* 品牌色（靛蓝 → 紫 渐变体系） */
    --accent: #6366f1;
    --accent-hover: #4f46e5;
    --accent-soft: #eef0ff;
    --accent-2: #8b5cf6;
    --accent-grad: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    --accent-grad-soft: linear-gradient(135deg, rgba(99,102,241,0.12) 0%, rgba(139,92,246,0.12) 100%);
    --accent-glow: rgba(99, 102, 241, 0.35);

    /* 功能色 */
    --green: #10b981;
    --green-soft: #e9fbf3;
    --blue: #3b82f6;
    --blue-soft: #edf4ff;
    --red: #ef4444;
    --red-soft: #fef0f0;
    --orange: #f59e0b;
    --orange-soft: #fff8e6;

    /* 气泡 */
    --bubble-ai-bg: #ffffff;
    --bubble-ai-border: #e9edf5;
    --bubble-other-bg: #effaf4;
    --bubble-other-border: #d9f2e5;

    /* 阴影 */
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
    --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-md: 0 6px 16px rgba(15, 23, 42, 0.07), 0 2px 4px rgba(15, 23, 42, 0.04);
    --shadow-lg: 0 16px 40px rgba(15, 23, 42, 0.10), 0 4px 10px rgba(15, 23, 42, 0.05);
    --shadow-accent: 0 4px 14px var(--accent-glow);

    /* 圆角 */
    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 16px;
    --radius-xl: 22px;
    --msg-radius: 18px;

    --font-mono: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
    --transition: 0.2s ease;
}

/* ===== 深色主题 ===== */
html[data-theme="dark"] {
    --bg: #0c111d;
    --bg-deco-1: rgba(99, 102, 241, 0.16);
    --bg-deco-2: rgba(56, 189, 248, 0.10);
    --bg-card: #151c2c;
    --bg-card-hover: #1b2337;
    --bg-glass: rgba(19, 25, 40, 0.78);
    --bg-input: #1c2537;
    --bg-overlay: rgba(2, 6, 16, 0.62);

    --text-primary: #e8edf7;
    --text-secondary: #a3b0c7;
    --text-muted: #64748b;

    --border: #263149;
    --border-light: #1f2940;

    --accent: #818cf8;
    --accent-hover: #a5b4fc;
    --accent-soft: rgba(129, 140, 248, 0.14);
    --accent-2: #a78bfa;
    --accent-grad: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    --accent-grad-soft: linear-gradient(135deg, rgba(99,102,241,0.20) 0%, rgba(139,92,246,0.20) 100%);
    --accent-glow: rgba(129, 140, 248, 0.30);

    --green: #34d399;
    --green-soft: rgba(52, 211, 153, 0.13);
    --blue: #60a5fa;
    --blue-soft: rgba(96, 165, 250, 0.13);
    --red: #f87171;
    --red-soft: rgba(248, 113, 113, 0.13);
    --orange: #fbbf24;
    --orange-soft: rgba(251, 191, 36, 0.13);

    --bubble-ai-bg: #1b2337;
    --bubble-ai-border: #27324c;
    --bubble-other-bg: rgba(52, 211, 153, 0.10);
    --bubble-other-border: rgba(52, 211, 153, 0.22);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.30);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.35), 0 1px 2px rgba(0, 0, 0, 0.30);
    --shadow-md: 0 6px 16px rgba(0, 0, 0, 0.40), 0 2px 4px rgba(0, 0, 0, 0.30);
    --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.50), 0 4px 10px rgba(0, 0, 0, 0.35);
    --shadow-accent: 0 4px 16px var(--accent-glow);
}

/* ===== Reset ===== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
    background: var(--bg);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    min-height: 100dvh;
    transition: background 0.3s ease, color 0.3s ease;
}

/* 全局氛围背景：两片柔和的品牌色光晕 */
body::before,
body::after {
    content: '';
    position: fixed;
    border-radius: 50%;
    filter: blur(90px);
    pointer-events: none;
    z-index: -1;
}
body::before {
    width: 480px;
    height: 480px;
    top: -160px;
    right: -120px;
    background: var(--bg-deco-1);
}
body::after {
    width: 420px;
    height: 420px;
    bottom: -160px;
    left: -120px;
    background: var(--bg-deco-2);
}

/* 带导航栏的页面顶部留白 */
body:not(.auth-page) {
    padding-top: 60px;
}
.container, .container-wide {
    margin-left: auto;
    margin-right: auto;
}

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

button {
    cursor: pointer;
    font-family: inherit;
    font-size: 0.9rem;
    border: none;
    outline: none;
    transition: all var(--transition);
}
button:focus-visible,
a:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

input, textarea, select {
    font-family: inherit;
    font-size: 0.9rem;
    outline: none;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    background: var(--bg-input);
    color: var(--text-primary);
    transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
    width: 100%;
}
input::placeholder, textarea::placeholder { color: var(--text-muted); }
input:hover, textarea:hover, select:hover { border-color: var(--text-muted); }
input:focus, textarea:focus, select:focus {
    border-color: var(--accent);
    background: var(--bg-card);
    box-shadow: 0 0 0 3.5px var(--accent-soft);
}

/* ===== 导航栏 ===== */
.navbar {
    background: var(--bg-glass);
    backdrop-filter: blur(16px) saturate(1.4);
    -webkit-backdrop-filter: blur(16px) saturate(1.4);
    border-bottom: 1px solid var(--border);
    padding: 0 20px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
    gap: 12px;
}
.navbar-left {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 1;
    min-width: 0;
}
.navbar-brand {
    font-size: 1.1rem;
    font-weight: 800;
    background: var(--accent-grad);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    white-space: nowrap;
    letter-spacing: 0.3px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}
.navbar-brand::before {
    content: '';
    width: 26px;
    height: 26px;
    border-radius: 8px;
    background: var(--accent-grad);
    box-shadow: var(--shadow-accent);
    -webkit-text-fill-color: initial;
    flex-shrink: 0;
    /* 白色对话气泡图标 */
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3E%3Cpath d='M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z'/%3E%3C/svg%3E") center / 18px no-repeat, var(--accent-grad);
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3E%3Cpath d='M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z'/%3E%3C/svg%3E") center / 18px no-repeat;
    -webkit-mask-composite: source-in;
    mask-composite: intersect;
}
.navbar-center {
    display: flex;
    align-items: center;
    gap: 4px;
    flex: 1;
    justify-content: center;
}
.navbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 1;
    min-width: 0;
}
/* 右侧元素允许收缩，退出按钮不收缩不换行 */
.navbar-right .btn {
    flex-shrink: 0;
    white-space: nowrap;
}
/* 窄屏下用户名（navbar-right 内唯一的 .nav-link）可截断 */
.navbar-right .nav-link {
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    flex-shrink: 1;
    min-width: 0;
}
.navbar-right .points-badge {
    flex-shrink: 1;
    min-width: 0;
    overflow: hidden;
}
.nav-link {
    padding: 6px 14px;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all var(--transition);
    white-space: nowrap;
}
.nav-link:hover { background: var(--accent-soft); color: var(--accent); }
.nav-link.active {
    background: var(--accent-grad-soft);
    color: var(--accent);
    font-weight: 600;
}

/* 点数徽章 */
.points-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 13px;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 700;
    background: var(--green-soft);
    color: var(--green);
    white-space: nowrap;
    border: 1px solid transparent;
}
html[data-theme="dark"] .points-badge { border-color: rgba(52, 211, 153, 0.25); }
.points-badge.zero {
    background: var(--bg-input);
    color: var(--text-muted);
}
.points-badge .dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    box-shadow: 0 0 6px currentColor;
}

/* 主题切换按钮 */
.theme-toggle {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--bg-input);
    color: var(--text-secondary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.95rem;
    flex-shrink: 0;
    border: 1px solid var(--border-light);
}
.theme-toggle:hover {
    background: var(--accent-soft);
    color: var(--accent);
    transform: rotate(15deg);
}

/* 移动端菜单按钮（竖屏） */
.menu-toggle {
    display: none;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--bg-input);
    color: var(--text-secondary);
    align-items: center;
    justify-content: center;
    font-size: 1.05rem;
    line-height: 1;
    flex-shrink: 0;
    cursor: pointer;
    border: 1px solid var(--border-light);
    transition: all var(--transition);
}
.menu-toggle:hover {
    background: var(--accent-soft);
    color: var(--accent);
}

/* 移动端下拉菜单 */
.mobile-menu {
    display: none;
    position: absolute;
    top: 60px;
    left: 0;
    right: 0;
    flex-direction: column;
    gap: 4px;
    padding: 10px 12px;
    background: var(--bg-glass);
    backdrop-filter: blur(16px) saturate(1.4);
    -webkit-backdrop-filter: blur(16px) saturate(1.4);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    z-index: 99;
}
.mobile-menu.open { display: flex; }
.mobile-menu .nav-link {
    display: block;
    padding: 11px 14px;
    font-size: 0.92rem;
    border-radius: 10px;
}

/* ===== 容器 ===== */
.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 24px 20px;
}
.container-wide {
    max-width: 1100px;
    margin: 0 auto;
    padding: 24px 20px;
}

/* ===== 磁贴卡片 ===== */
.tile {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 20px;
    transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
    border: 1px solid var(--border-light);
    min-width: 0;
}
.tile:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
    border-color: var(--border);
}
.tile-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}
.tile-title {
    font-size: 1.02rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: 0.2px;
}
.tile-subtitle {
    font-size: 0.8rem;
    color: var(--text-muted);
}
.tile-body {
    color: var(--text-secondary);
    font-size: 0.9rem;
}
.tile-footer {
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
}

/* 磁贴网格 */
.tile-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}

/* ===== 标签 ===== */
.tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 11px;
    border-radius: 999px;
    font-size: 0.73rem;
    font-weight: 600;
    white-space: nowrap;
    letter-spacing: 0.2px;
}
.tag-green { background: var(--green-soft); color: var(--green); }
.tag-blue { background: var(--blue-soft); color: var(--blue); }
.tag-red { background: var(--red-soft); color: var(--red); }
.tag-orange { background: var(--orange-soft); color: var(--orange); }
.tag-gray { background: var(--bg-input); color: var(--text-muted); }
.tag-accent { background: var(--accent-grad-soft); color: var(--accent); }

.lock-icon {
    color: var(--orange);
    font-size: 0.85rem;
}

/* ===== 按钮 ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.9rem;
    transition: all var(--transition);
    letter-spacing: 0.2px;
    white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn-primary {
    background: var(--accent-grad);
    color: #fff;
    box-shadow: 0 2px 8px var(--accent-glow);
}
.btn-primary:hover {
    filter: brightness(1.08);
    box-shadow: 0 4px 14px var(--accent-glow);
    transform: translateY(-1px);
}
.btn-primary:active { transform: scale(0.97); }
.btn-primary:disabled {
    background: var(--bg-input);
    color: var(--text-muted);
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
    filter: none;
}
.btn-secondary {
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border-light);
}
.btn-secondary:hover {
    background: var(--bg-card-hover);
    border-color: var(--border);
}
.btn-danger {
    background: var(--red-soft);
    color: var(--red);
}
.btn-danger:hover { background: var(--red); color: #fff; }
.btn-sm {
    padding: 6px 13px;
    font-size: 0.8rem;
    border-radius: 8px;
}
.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: 50%;
    background: var(--bg-input);
    color: var(--text-secondary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.btn-icon:hover { background: var(--accent-soft); color: var(--accent); }

/* ===== 登录 / 注册页 ===== */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    min-height: 100dvh;
    padding: 20px;
    position: relative;
    overflow: hidden;
}
/* 登录页专属漂浮光斑 */
.auth-page::before,
.auth-page::after {
    content: '';
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    z-index: 0;
    animation: floatBlob 12s ease-in-out infinite;
}
.auth-page::before {
    width: 460px;
    height: 460px;
    top: -10%;
    right: -8%;
    background: var(--bg-deco-1);
}
.auth-page::after {
    width: 400px;
    height: 400px;
    bottom: -12%;
    left: -8%;
    background: var(--bg-deco-2);
    animation-delay: -6s;
}
@keyframes floatBlob {
    0%, 100% { transform: translate(0, 0) scale(1); }
    50% { transform: translate(-30px, 24px) scale(1.08); }
}

.auth-card {
    background: var(--bg-glass);
    backdrop-filter: blur(20px) saturate(1.5);
    -webkit-backdrop-filter: blur(20px) saturate(1.5);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    padding: 44px 40px;
    width: 100%;
    max-width: 420px;
    border: 1px solid var(--border-light);
    position: relative;
    z-index: 1;
    animation: cardIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes cardIn {
    from { opacity: 0; transform: translateY(18px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}
.auth-card .brand-logo {
    width: 56px;
    height: 56px;
    border-radius: 16px;
    background: var(--accent-grad);
    box-shadow: var(--shadow-accent);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px;
    font-size: 1.6rem;
    color: #fff;
}
.auth-card h1 {
    font-size: 1.45rem;
    font-weight: 800;
    text-align: center;
    margin-bottom: 6px;
    letter-spacing: 0.5px;
    background: var(--accent-grad);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}
.auth-card .subtitle {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-bottom: 28px;
}
.auth-card .form-group {
    margin-bottom: 16px;
}
.auth-card .form-group label {
    display: block;
    font-size: 0.82rem;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text-secondary);
    letter-spacing: 0.2px;
}
.auth-card .form-group input {
    padding: 11px 15px;
    border-radius: 10px;
}
.auth-card .btn {
    width: 100%;
    margin-top: 10px;
    padding: 12px 20px;
    border-radius: 10px;
    font-size: 0.95rem;
    letter-spacing: 2px;
}
.auth-card .alt-link {
    text-align: center;
    margin-top: 20px;
    font-size: 0.85rem;
    color: var(--text-muted);
}
.auth-card .alt-link a { font-weight: 600; }

/* ===== 错误 / 成功提示 ===== */
.msg-error {
    background: var(--red-soft);
    color: var(--red);
    padding: 10px 14px;
    border-radius: 10px;
    font-size: 0.85rem;
    margin-bottom: 14px;
    display: none;
    border-left: 3px solid var(--red);
}
.msg-error.show { display: block; animation: shake 0.4s ease; }
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}
.msg-success {
    background: var(--green-soft);
    color: var(--green);
    padding: 10px 14px;
    border-radius: 10px;
    font-size: 0.85rem;
    margin-bottom: 12px;
    display: none;
    border-left: 3px solid var(--green);
}
.msg-success.show { display: block; }

/* ===== 房间列表页 ===== */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 12px;
}
.page-header h1 {
    font-size: 1.4rem;
    font-weight: 800;
    letter-spacing: 0.3px;
}
.room-tile {
    cursor: pointer;
    position: relative;
    overflow: hidden;
}
.room-tile::before {
    /* 顶部渐变装饰条 */
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--accent-grad);
    opacity: 0;
    transition: opacity var(--transition);
}
.room-tile:hover::before { opacity: 1; }
.room-tile .tile-title {
    display: flex;
    align-items: center;
    gap: 8px;
}
.room-tile .role-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-top: 8px;
    min-height: 24px;
}
.room-tile .my-room-badge {
    position: absolute;
    top: 12px;
    right: 12px;
}
.create-room-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.create-room-form .role-row {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}
.create-room-form .role-row input {
    flex: 1;
    min-width: 120px;
}
.create-room-form .card {
    background: var(--bg-input);
    border-radius: var(--radius);
    padding: 14px;
    border: 1px dashed var(--border);
}

/* ===== 聊天页 ===== */
.chat-container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 60px);
    height: calc(100dvh - 60px);
    max-width: 860px;
    margin: 0 auto;
    position: relative;
}

/* 聊天头部 */
.chat-header {
    padding: 12px 20px;
    background: var(--bg-glass);
    backdrop-filter: blur(16px) saturate(1.4);
    -webkit-backdrop-filter: blur(16px) saturate(1.4);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-shrink: 0;
}
.chat-header .room-info {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}
.chat-header .room-name {
    font-weight: 700;
    font-size: 1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    letter-spacing: 0.2px;
}
.chat-header .online-count {
    font-size: 0.73rem;
    color: var(--green);
    white-space: nowrap;
    font-weight: 600;
    background: var(--green-soft);
    padding: 2px 10px;
    border-radius: 999px;
}
.chat-header .header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

/* 正在输入指示 */
.typing-indicator {
    font-size: 0.75rem;
    color: var(--accent);
    font-style: italic;
    padding: 4px 12px;
    background: var(--accent-soft);
    border-radius: 999px;
    animation: pulse 1.5s ease-in-out infinite;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
}
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* 消息区 */
.messages-area {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
}
.messages-area:empty::after {
    content: '暂无消息，开始聊天吧 ✨';
    display: block;
    text-align: center;
    color: var(--text-muted);
    padding: 60px 20px;
    font-size: 0.9rem;
}

/* 历史摘要横幅 */
.summary-banner {
    background: var(--blue-soft);
    border: 1px solid transparent;
    border-radius: var(--radius);
    padding: 10px 14px;
    font-size: 0.8rem;
    color: var(--blue);
    margin-bottom: 8px;
    display: none;
}
html[data-theme="dark"] .summary-banner { border-color: rgba(96, 165, 250, 0.25); }
.summary-banner.show { display: block; }
.summary-banner .summary-label {
    font-weight: 700;
    margin-bottom: 2px;
}

/* 消息气泡 */
.msg {
    display: flex;
    gap: 9px;
    max-width: 78%;
    animation: msgIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes msgIn {
    from { opacity: 0; transform: translateY(10px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}
.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.msg.ai { align-self: flex-start; }
.msg.other { align-self: flex-start; }

.msg .avatar {
    width: 36px;
    height: 36px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.78rem;
    font-weight: 700;
    flex-shrink: 0;
    color: #fff;
    box-shadow: var(--shadow-sm);
    letter-spacing: 0;
}
.msg.user .avatar { background: var(--accent); }
.msg.ai .avatar { background: var(--blue); }
.msg.other .avatar { background: var(--green); }

.msg .bubble {
    padding: 10px 16px;
    border-radius: var(--msg-radius);
    font-size: 0.9rem;
    line-height: 1.6;
    word-break: break-word;
    position: relative;
    box-shadow: var(--shadow-sm);
    transition: box-shadow var(--transition);
}
.msg:hover .bubble { box-shadow: var(--shadow); }
.msg.user .bubble {
    background: var(--accent-grad);
    color: #fff;
    border-bottom-right-radius: 6px;
    box-shadow: 0 3px 10px var(--accent-glow);
}
.msg.ai .bubble {
    background: var(--bubble-ai-bg);
    border: 1px solid var(--bubble-ai-border);
    color: var(--text-primary);
    border-bottom-left-radius: 6px;
}
.msg.other .bubble {
    background: var(--bubble-other-bg);
    border: 1px solid var(--bubble-other-border);
    color: var(--text-primary);
    border-bottom-left-radius: 6px;
}
.msg .speaker-name {
    font-size: 0.72rem;
    font-weight: 700;
    margin-bottom: 3px;
    opacity: 0.75;
    letter-spacing: 0.3px;
}
.msg.user .speaker-name { color: rgba(255, 255, 255, 0.85); }
.msg.ai .speaker-name { color: var(--blue); }
.msg.other .speaker-name { color: var(--green); }

.msg .msg-time {
    font-size: 0.65rem;
    opacity: 0.5;
    margin-top: 4px;
    text-align: right;
}
.msg .msg-summarized {
    font-size: 0.65rem;
    opacity: 0.4;
    font-style: italic;
}
.msg .recall-btn {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.62rem;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-sm);
    z-index: 2;
}
.msg:hover .recall-btn { display: flex; }
.msg .recall-btn:hover {
    background: var(--red);
    border-color: var(--red);
    color: #fff;
}

/* 输入区 */
.input-area {
    padding: 14px 20px;
    background: var(--bg-glass);
    backdrop-filter: blur(16px) saturate(1.4);
    -webkit-backdrop-filter: blur(16px) saturate(1.4);
    border-top: 1px solid var(--border);
    display: flex;
    gap: 10px;
    align-items: flex-end;
    flex-shrink: 0;
    position: relative;
}
.input-area textarea {
    flex: 1;
    resize: none;
    min-height: 44px;
    max-height: 120px;
    border-radius: 22px;
    padding: 11px 18px;
    font-size: 0.9rem;
    line-height: 1.5;
    border: 1.5px solid var(--border);
    background: var(--bg-input);
}
.input-area textarea:focus {
    border-color: var(--accent);
    background: var(--bg-card);
    box-shadow: 0 0 0 3.5px var(--accent-soft);
}
.input-area .send-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--accent-grad);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 1.05rem;
    box-shadow: 0 3px 10px var(--accent-glow);
    transition: all var(--transition);
}
.input-area .send-btn:hover:not(:disabled) {
    transform: translateY(-2px) scale(1.05);
    box-shadow: 0 6px 16px var(--accent-glow);
}
.input-area .send-btn:active:not(:disabled) { transform: scale(0.94); }
.input-area .send-btn:disabled {
    background: var(--bg-input);
    color: var(--text-muted);
    cursor: not-allowed;
    box-shadow: none;
}

/* 在线用户侧栏 */
.online-sidebar {
    position: fixed;
    right: 16px;
    top: 76px;
    bottom: 16px;
    width: 210px;
    background: var(--bg-glass);
    backdrop-filter: blur(16px) saturate(1.4);
    -webkit-backdrop-filter: blur(16px) saturate(1.4);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 16px;
    overflow-y: auto;
    z-index: 50;
    transition: transform var(--transition);
}
.online-sidebar h3 {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-muted);
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
}
.online-sidebar .user-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 9px;
    border-radius: 9px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    transition: background var(--transition);
}
.online-sidebar .user-item:hover { background: var(--bg-input); }
.online-sidebar .user-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--green);
    flex-shrink: 0;
    box-shadow: 0 0 6px var(--green);
    animation: pulse 2s ease-in-out infinite;
}

/* 侧栏角色列表 */
.persona-item {
    font-size: 0.78rem;
    color: var(--text-muted);
    padding: 5px 9px;
    border-radius: 8px;
    cursor: pointer;
    transition: all var(--transition);
}
.persona-item:hover {
    background: var(--accent-soft);
    color: var(--accent);
}

/* ===== 个人设置页 ===== */
.profile-section {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 24px;
    margin-bottom: 16px;
    border: 1px solid var(--border-light);
    transition: box-shadow var(--transition);
}
.profile-section:hover { box-shadow: var(--shadow-md); }
.profile-section h2 {
    font-size: 1.02rem;
    font-weight: 700;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    letter-spacing: 0.2px;
}
.profile-section .info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 11px 0;
    border-bottom: 1px solid var(--border-light);
    font-size: 0.9rem;
}
.profile-section .info-row:last-child { border-bottom: none; }
.profile-section .info-label { color: var(--text-secondary); }
.profile-section .info-value { font-weight: 600; }

.font-size-control {
    display: flex;
    align-items: center;
    gap: 12px;
}
.font-size-control input[type="range"] {
    flex: 1;
    accent-color: var(--accent);
    height: 6px;
}
.font-size-preview {
    font-size: 0.85rem;
    color: var(--text-muted);
    min-width: 44px;
    text-align: center;
    font-weight: 600;
    background: var(--bg-input);
    padding: 3px 8px;
    border-radius: 8px;
}

/* 背景图预览 */
.bg-preview {
    width: 100%;
    height: 140px;
    border-radius: var(--radius);
    background-size: cover;
    background-position: center;
    background-color: var(--bg-input);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 0.85rem;
    border: 1px dashed var(--border);
}

/* ===== 管理后台 ===== */
.admin-stats {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 14px;
    margin-bottom: 24px;
}
.stat-tile {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 22px 20px;
    text-align: center;
    border: 1px solid var(--border-light);
    position: relative;
    overflow: hidden;
    transition: transform var(--transition), box-shadow var(--transition);
}
.stat-tile:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}
.stat-tile::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--accent-grad);
}
.stat-tile .stat-value {
    font-size: 2rem;
    font-weight: 800;
    background: var(--accent-grad);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    line-height: 1.2;
}
.stat-tile .stat-label {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 4px;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.admin-table-wrap {
    overflow-x: auto;
    border-radius: var(--radius);
}
.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}
.admin-table th, .admin-table td {
    padding: 11px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border-light);
}
.admin-table th {
    font-weight: 700;
    color: var(--text-muted);
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    background: var(--bg-input);
}
.admin-table tr:hover td { background: var(--bg-card-hover); }
.admin-table .actions {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

/* ===== 对话框 ===== */
dialog {
    border: none;
    border-radius: var(--radius-xl);
    padding: 0;
    box-shadow: var(--shadow-lg);
    max-width: 480px;
    width: 90%;
    background: var(--bg-card);
    color: var(--text-primary);
    animation: dialogIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}
dialog::backdrop {
    background: var(--bg-overlay);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
}
@keyframes dialogIn {
    from { opacity: 0; transform: scale(0.94) translateY(12px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}
.dialog-content {
    padding: 26px;
}
.dialog-content h3 {
    font-size: 1.08rem;
    font-weight: 800;
    margin-bottom: 10px;
    letter-spacing: 0.2px;
}
.dialog-content p {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 16px;
}
.dialog-content .form-group {
    margin-bottom: 14px;
}
.dialog-content .form-group label {
    display: block;
    font-size: 0.82rem;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text-secondary);
}
.dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 12px;
}

/* ===== <dialog> 不支持时的 div 兜底弹窗 =====
   与原生 dialog 视觉效果等价：半透黑遮罩全屏 fixed + 居中内容盒 */
.modal-fallback-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-overlay);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 300;
}
.modal-fallback-box {
    background: var(--bg-card);
    color: var(--text-primary);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    max-width: 480px;
    width: 90%;
    max-height: 85vh;
    max-height: 85dvh;
    overflow-y: auto;
    animation: dialogIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

/* ===== Toast ===== */
.toast-container {
    position: fixed;
    top: 72px;
    right: 16px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.toast {
    padding: 11px 18px;
    border-radius: 12px;
    font-size: 0.85rem;
    font-weight: 600;
    box-shadow: var(--shadow-md);
    animation: toastIn 0.3s cubic-bezier(0.16, 1, 0.3, 1), toastOut 0.3s ease 2.7s forwards;
    max-width: 320px;
    border: 1px solid var(--border-light);
    background: var(--bg-card);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    gap: 8px;
}
.toast::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}
.toast-info { color: var(--accent); }
.toast-info::before { background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.toast-success { color: var(--green); }
.toast-success::before { background: var(--green); box-shadow: 0 0 8px var(--green); }
.toast-error { color: var(--red); }
.toast-error::before { background: var(--red); box-shadow: 0 0 8px var(--red); }
@keyframes toastIn {
    from { opacity: 0; transform: translateX(50px); }
    to { opacity: 1; transform: translateX(0); }
}
@keyframes toastOut {
    from { opacity: 1; transform: translateX(0); }
    to { opacity: 0; transform: translateX(50px); }
}

/* ===== 滚动条 ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ===== 空状态 ===== */
.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--text-muted);
}
.empty-state .icon { font-size: 2.6rem; margin-bottom: 12px; }
.empty-state p { font-size: 0.9rem; }

/* ===== 工具类 ===== */
.text-center { text-align: center; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }
.flex { display: flex; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.gap-2 { gap: 8px; }
.gap-4 { gap: 16px; }
.hidden { display: none !important; }
.w-full { width: 100%; }

/* ===== 加载动画 ===== */
.spinner {
    width: 20px;
    height: 20px;
    border: 2.5px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== 封禁遮罩 ===== */
.banned-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-overlay);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
}
.banned-card {
    background: var(--bg-card);
    border-radius: var(--radius-xl);
    padding: 36px;
    text-align: center;
    max-width: 360px;
    width: 90%;
    box-shadow: var(--shadow-lg);
    animation: cardIn 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}
.banned-card h2 { color: var(--red); margin-bottom: 8px; }

/* ===== @ 提及下拉 ===== */
.mention-dropdown {
    position: absolute;
    bottom: 100%;
    left: 0;
    right: 64px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    max-height: 200px;
    overflow-y: auto;
    z-index: 60;
    margin-bottom: 6px;
    animation: dialogIn 0.15s ease;
}
.mention-item {
    padding: 9px 15px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    transition: background var(--transition);
}
.mention-item:hover {
    background: var(--accent-soft);
    color: var(--accent);
}

/* ===== 响应式 ===== */
@media (max-width: 768px) {
    .online-sidebar { display: none; }
    .msg { max-width: 90%; }
    .chat-container { height: calc(100dvh - 60px); }
    .container { padding: 16px 12px; }
    .container-wide { padding: 16px 12px; }
    .tile-grid { grid-template-columns: 1fr; }
    .navbar { padding: 0 12px; gap: 8px; }
    .navbar-center { display: none; }
    .menu-toggle { display: inline-flex; }
    .nav-link { padding: 6px 10px; font-size: 0.8rem; }
    .navbar-right { gap: 6px; }
    .navbar-right .nav-link { max-width: 90px; }
    .auth-card { padding: 32px 22px; }
    .chat-header { padding: 10px 14px; }
    .input-area { padding: 10px 14px; }
    .messages-area { padding: 14px; }
    .typing-indicator { position: static; transform: none; }
}

/* 手机竖屏窄屏：进一步精简导航，避免右侧溢出裁剪 */
@media (max-width: 480px) {
    .navbar { padding: 0 10px; gap: 6px; height: 56px; }
    .navbar-brand { font-size: 1rem; gap: 6px; }
    .navbar-brand::before { width: 23px; height: 23px; border-radius: 7px; }
    .navbar-right { gap: 5px; }
    /* 窄屏隐藏用户名，保留徽章/主题/退出 */
    .navbar-right .nav-link { display: none; }
    .navbar-right .points-badge { padding: 4px 9px; font-size: 0.72rem; gap: 4px; }
    .navbar-right .theme-toggle { width: 31px; height: 31px; font-size: 0.85rem; }
    .navbar-right .btn-sm { padding: 5px 10px; font-size: 0.75rem; }
    .menu-toggle { width: 31px; height: 31px; }
    .mobile-menu { top: 56px; }
    /* 大厅磁贴更紧凑，按钮不溢出 */
    .container { padding: 14px 10px; }
    .container-wide { padding: 14px 10px; }
    .tile { padding: 16px; }
    .tile-grid { gap: 12px; }
    .tile-footer { gap: 6px; }
    .tile-footer .btn { padding: 7px 12px; font-size: 0.8rem; }
    /* 聊天页窄屏微调 */
    .chat-container { height: calc(100dvh - 56px); }
    .chat-header { gap: 8px; padding: 10px 12px; }
    .chat-header .room-name { font-size: 0.92rem; }
    .chat-header .header-actions .btn-sm { padding: 5px 10px; font-size: 0.75rem; }
    .input-area { gap: 8px; padding: 10px 12px; }
    .input-area textarea { min-height: 42px; padding: 10px 16px; font-size: 0.88rem; }
    .input-area .send-btn { width: 42px; height: 42px; }
    .msg { max-width: 94%; }
}

/* ===== 减少动效偏好 ===== */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}
