/* ==========================================
   Juanyi Chat —  UI Theme
   ========================================== */

:root {
    color-scheme: light;
    --app-viewport-height: 100vh;
    /* Sidebar (light) */
    --sidebar-bg: #f9f9f9;
    --sidebar-hover: rgba(0, 0, 0, 0.04);
    --sidebar-active: rgba(0, 0, 0, 0.07);
    --sidebar-text: #343541;
    --sidebar-muted: #8e8ea0;
    --sidebar-line: #ececec;
    /* Chat area (light) */
    --bg: #ffffff;
    --card: #ffffff;
    --line: #e5e5e5;
    --text: #343541;
    --muted: #8e8ea0;
    /* Accents */
    --primary: #10a37f;
    --primary-dark: #0d8a6a;
    --primary-glow: rgba(16, 163, 127, 0.12);
    --accent-blue: #5b6abf;
    --danger: #ef4146;
    /* Elevation */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.10);
    /* Radii */
    --radius-xl: 16px;
    --radius-lg: 12px;
    --radius-md: 8px;
    --radius-sm: 6px;
    --radius-full: 999px;
}

@supports (height: 100dvh) {
    :root {
        --app-viewport-height: 100dvh;
    }
}

/* === Dark Theme === */
[data-theme="dark"] {
    color-scheme: dark;
    --sidebar-bg: #1e1e2e;
    --sidebar-hover: rgba(255, 255, 255, 0.06);
    --sidebar-active: rgba(255, 255, 255, 0.10);
    --sidebar-text: #cdd6f4;
    --sidebar-muted: #6c7086;
    --sidebar-line: #313244;
    --bg: #181825;
    --card: #1e1e2e;
    --line: #313244;
    --text: #cdd6f4;
    --muted: #6c7086;
    --primary-glow: rgba(16, 163, 127, 0.20);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.25);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.30);
    --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.40);
    --ui-icon-filter: brightness(0) invert(1);
}

[data-theme="dark"] body.is-embedded { background: #181825; }

/* === Dark: Message Content Bubbles === */
[data-theme="dark"] .message-item .message-content {
    --msg-bg: #252536;
    border-color: var(--line);
}

[data-theme="dark"] .message-item-other .message-content {
    --msg-bg: #252536;
    background: var(--msg-bg);
    border-color: var(--line);
    color: var(--text);
}

[data-theme="dark"] .message-item-other:hover .message-content {
    --msg-bg: #2a2a3c;
    background: var(--msg-bg);
}

[data-theme="dark"] .message-item-own .message-content {
    --msg-bg: rgba(16, 163, 127, 0.22);
    background: var(--msg-bg);
    border-color: rgba(16, 163, 127, 0.30);
    color: #cdd6f4;
}

[data-theme="dark"] .message-item-own:hover .message-content {
    --msg-bg: rgba(16, 163, 127, 0.30);
    background: var(--msg-bg);
}

[data-theme="dark"] .message-item-mention .message-content {
    border-left-color: rgba(255, 184, 0, 0.50);
}

[data-theme="dark"] .message-item-private .message-content {
    border-left-color: rgba(91, 106, 191, 0.50);
}

/* === Dark: Room Chip Text === */
[data-theme="dark"] .room-chip-name {
    color: var(--sidebar-text);
}

[data-theme="dark"] .room-chip small {
    color: var(--sidebar-muted);
}

[data-theme="dark"] .room-chip.active .room-chip-name {
    color: var(--primary);
}

/* === Dark: Chat Link in Messages === */
[data-theme="dark"] .chat-link {
    color: #7eb8f0;
}

[data-theme="dark"] .chat-link:hover {
    color: #a0d0ff;
}
[data-theme="dark"] .chat-card { background: var(--bg); }

[data-theme="dark"] .chat-header {
    background: var(--card);
    border-bottom-color: var(--line);
}

[data-theme="dark"] .chat-header h2 { color: var(--text); }

[data-theme="dark"] .chat-footer {
    background: var(--card);
    border-top-color: var(--line);
}

[data-theme="dark"] .message-tool-button {
    color: var(--muted);
    background: transparent;
}

[data-theme="dark"] .message-tool-button:hover {
    color: var(--text);
    background: var(--sidebar-hover);
}

[data-theme="dark"] .message-input-row textarea,
[data-theme="dark"] .message-input-row textarea::placeholder {
    background: #252536;
    color: var(--text);
    border-color: var(--line);
}

[data-theme="dark"] .message-input-row textarea:focus {
    border-color: var(--primary);
}

[data-theme="dark"] .message-input-row button[type="submit"] {
    background: var(--primary);
    color: #fff;
}

[data-theme="dark"] .red-packet-tool-button {
    color: #f0a060;
    background: rgba(255, 180, 80, 0.10);
}

[data-theme="dark"] .red-packet-tool-button:hover {
    background: rgba(255, 180, 80, 0.18);
}

/* === Dark: Sidebar === */
[data-theme="dark"] .desktop-sidebar,
[data-theme="dark"] .mobile-drawer-panel {
    background: var(--sidebar-bg);
    border-right-color: var(--sidebar-line);
}

[data-theme="dark"] .mobile-drawer-backdrop { background: rgba(0, 0, 0, 0.7); }

[data-theme="dark"] .mobile-drawer-header {
    background: var(--sidebar-bg);
    border-bottom-color: var(--sidebar-line);
}

[data-theme="dark"] .eyebrow { color: var(--sidebar-muted); }

[data-theme="dark"] .mobile-drawer-close {
    color: var(--sidebar-muted);
}

[data-theme="dark"] .mobile-drawer-close:hover { color: var(--sidebar-text); }

/* === Dark: Room Chips === */
[data-theme="dark"] .room-chip {
    background: var(--sidebar-hover);
    color: var(--sidebar-text);
}

[data-theme="dark"] .room-chip:hover { background: var(--sidebar-active); }

[data-theme="dark"] .room-chip.active {
    background: rgba(16, 163, 127, 0.20);
    color: var(--primary);
}

[data-theme="dark"] .room-chip-avatar {
    background: rgba(255, 255, 255, 0.08);
    color: var(--sidebar-text);
}

[data-theme="dark"] .room-chip.active .room-chip-avatar {
    background: var(--primary);
    color: #fff;
}

/* === Dark: Sidebar Brand / Headings === */
[data-theme="dark"] .brand-block h1,
[data-theme="dark"] .panel h2,
[data-theme="dark"] .panel-title-row span {
    color: var(--sidebar-text);
}

[data-theme="dark"] .sidebar-card .user-card { color: var(--sidebar-text); }

/* === Dark: Auth Buttons === */
[data-theme="dark"] .auth-trigger.ghost-button,
[data-theme="dark"] .pwa-install-btn {
    color: var(--sidebar-text);
    border-color: var(--sidebar-line);
}

[data-theme="dark"] .auth-trigger.ghost-button:hover,
[data-theme="dark"] .pwa-install-btn:hover {
    background: var(--sidebar-hover);
}

[data-theme="dark"] .auth-trigger {
    background: var(--primary);
    color: #fff;
}

/* === Dark: Pendant Wallet === */
[data-theme="dark"] .pendant-wallet-section { border-top-color: var(--sidebar-line); }

[data-theme="dark"] .wallet-btn,
[data-theme="dark"] .shop-btn {
    background: var(--sidebar-hover);
    color: var(--sidebar-text);
    border-color: var(--sidebar-line);
}

[data-theme="dark"] .wallet-btn:hover,
[data-theme="dark"] .shop-btn:hover { background: var(--sidebar-active); }

/* === Dark: Online Sidebar === */
[data-theme="dark"] .online-sidebar {
    background: var(--card);
    border-left-color: var(--line);
}

[data-theme="dark"] .online-drawer-header {
    background: var(--card);
    border-bottom-color: var(--line);
}

[data-theme="dark"] .online-drawer-header h3 { color: var(--text); }

[data-theme="dark"] .online-drawer-close { color: var(--muted); }
[data-theme="dark"] .online-drawer-close:hover { color: var(--text); }

[data-theme="dark"] .online-user-row { color: var(--text); }

[data-theme="dark"] .online-user-row:hover { background: var(--sidebar-hover); }

[data-theme="dark"] .table-row {
    background: transparent;
    border-bottom-color: var(--line);
}

[data-theme="dark"] .table-row:hover { background: var(--sidebar-hover); }

[data-theme="dark"] .load-more-users {
    color: var(--muted);
    border-color: var(--line);
    background: transparent;
}

[data-theme="dark"] .load-more-users:hover {
    background: var(--sidebar-hover);
    color: var(--text);
}

/* === Dark: Message Area === */
[data-theme="dark"] .message-list {
    background: var(--bg);
}

[data-theme="dark"] .message-item { background: transparent; }

[data-theme="dark"] .message-item-other .message-bubble {
    background: var(--sidebar-bg);
    color: var(--text);
}

[data-theme="dark"] .message-item-own .message-bubble {
    background: rgba(16, 163, 127, 0.22);
    color: #cdd6f4;
}

[data-theme="dark"] .message-time { color: var(--muted); }
[data-theme="dark"] .message-avatar { border-color: var(--line); }

[data-theme="dark"] .message-user-name { color: var(--text); }

[data-theme="dark"] .message-recall-button,
[data-theme="dark"] .message-move-button {
    color: var(--muted);
}

[data-theme="dark"] .message-recall-button:hover,
[data-theme="dark"] .message-move-button:hover { color: var(--danger); }

[data-theme="dark"] .tag-private {
    background: rgba(91, 106, 191, 0.18);
    color: #8a9cf0;
}

[data-theme="dark"] .tag-mention {
    background: rgba(255, 184, 0, 0.18);
    color: #f0c040;
}

[data-theme="dark"] .tag-system {
    background: rgba(142, 142, 160, 0.18);
    color: #a0a8c0;
}

/* === Dark: Emoji Panel === */
[data-theme="dark"] .emoji-panel {
    background: var(--card);
    border-color: var(--line);
}

[data-theme="dark"] .emoji-tab { color: var(--muted); }
[data-theme="dark"] .emoji-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

[data-theme="dark"] .emoji-item:hover { background: var(--sidebar-hover); }

[data-theme="dark"] .sticker-grid-item {
    background: var(--sidebar-bg);
    border-color: var(--line);
}

[data-theme="dark"] .sticker-grid-item:hover { background: var(--sidebar-hover); }

[data-theme="dark"] .sticker-grid-empty {
    color: var(--muted);
}

[data-theme="dark"] .sticker-upload-button {
    color: var(--muted);
    border-color: var(--line);
}

[data-theme="dark"] .sticker-upload-button:hover {
    color: var(--text);
    background: var(--sidebar-hover);
}

/* === Dark: Emoji Tab Content === */
[data-theme="dark"] .emoji-tab-content { background: var(--card); }

/* === Dark: Modals === */
[data-theme="dark"] .modal-dialog { background: var(--card); }

[data-theme="dark"] .modal-close {
    background: var(--sidebar-bg);
    color: var(--muted);
}

[data-theme="dark"] .modal-close:hover { background: var(--line); color: var(--text); }
[data-theme="dark"] .modal-backdrop { background: rgba(0, 0, 0, 0.7); }

/* === Dark: Profile Card === */
[data-theme="dark"] .profile-card { color: var(--text); }
[data-theme="dark"] .profile-card-name { color: var(--text); }

[data-theme="dark"] .profile-inline-form input,
[data-theme="dark"] .profile-inline-form button {
    background: var(--sidebar-bg);
    color: var(--text);
    border-color: var(--line);
}

[data-theme="dark"] .profile-inline-form button {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

[data-theme="dark"] .profile-header-gradient {
    background: linear-gradient(135deg, #2a7a5e, #0d6a4a);
}

/* === Dark: Auth Forms === */
[data-theme="dark"] .auth-form input,
[data-theme="dark"] .auth-form textarea {
    background: var(--sidebar-bg);
    color: var(--text);
    border-color: var(--line);
}

[data-theme="dark"] .auth-form button[type="submit"] { background: var(--primary); }
[data-theme="dark"] .auth-switch { color: var(--muted); }
[data-theme="dark"] .auth-switch.active { color: var(--primary); border-bottom-color: var(--primary); }
[data-theme="dark"] .auth-link-btn { color: var(--muted); }
[data-theme="dark"] .form-hint { color: var(--muted); }
[data-theme="dark"] .remember-row { color: var(--muted); }

/* === Dark: Header Elements === */
[data-theme="dark"] .tips-box { color: var(--muted); }
[data-theme="dark"] .ws-signal { border-color: var(--muted); }
[data-theme="dark"] .ws-signal-on { color: #4ade80; }
[data-theme="dark"] .ws-signal-on::before { background: #4ade80; box-shadow: 0 0 0 2px rgba(74, 222, 128, 0.2); }
[data-theme="dark"] .ws-signal-medium { color: #facc15; }
[data-theme="dark"] .ws-signal-medium::before { background: #facc15; box-shadow: 0 0 0 2px rgba(250, 204, 21, 0.2); }
[data-theme="dark"] .ws-signal-off { color: #f87171; }
[data-theme="dark"] .ws-signal-off::before { background: #f87171; box-shadow: 0 0 0 2px rgba(248, 113, 113, 0.2); }

[data-theme="dark"] .online-sidebar-toggle {
    color: var(--muted);
    border-color: var(--line);
    background: transparent;
}

[data-theme="dark"] .online-sidebar-toggle:hover { background: var(--sidebar-hover); }
[data-theme="dark"] .chat-header-more { color: var(--muted); }
[data-theme="dark"] .drawer-toggle-icon { color: var(--text); }

/* === Dark: Quote Preview === */
[data-theme="dark"] .quote-preview,
[data-theme="dark"] .target-preview {
    background: var(--sidebar-bg);
    border-color: var(--line);
}

[data-theme="dark"] .quote-preview-name,
[data-theme="dark"] .quote-preview-text,
[data-theme="dark"] .target-preview-label,
[data-theme="dark"] .target-preview-name { color: var(--muted); }

/* === Dark: Image Preview === */
[data-theme="dark"] .image-preview-item { border-color: var(--line); }
[data-theme="dark"] .image-lightbox-dialog { background: var(--sidebar-bg) !important; }
[data-theme="dark"] .video-lightbox-dialog { background: var(--sidebar-bg) !important; }

/* === Dark: Scroll Buttons === */
[data-theme="dark"] .scroll-bottom-btn {
    background: var(--card);
    color: var(--text);
    border-color: var(--line);
    box-shadow: var(--shadow-md);
}

[data-theme="dark"] .scroll-bottom-btn:hover { background: var(--sidebar-bg); }

/* === Dark: History Loading === */
[data-theme="dark"] .history-load-more {
    background: var(--sidebar-bg);
    color: var(--muted);
    border-color: var(--line);
}

[data-theme="dark"] .history-load-more:hover {
    background: var(--sidebar-active);
    color: var(--text);
}

[data-theme="dark"] .history-end-hint { color: var(--muted); }

/* === Dark: Context Menu === */
[data-theme="dark"] .context-menu {
    background: var(--card);
    border-color: var(--line);
    box-shadow: var(--shadow-lg);
}

[data-theme="dark"] .context-menu-item { color: var(--text); }
[data-theme="dark"] .context-menu-item:hover { background: var(--sidebar-hover); }
[data-theme="dark"] .context-menu-item.danger { color: var(--danger); }
[data-theme="dark"] .context-menu-sep { border-top-color: var(--line); }

/* === Dark: Profile Actions === */
[data-theme="dark"] .profile-card-actions button.ghost-button {
    border-color: var(--line);
    color: var(--text);
    background: transparent;
}

[data-theme="dark"] .profile-card-actions button.ghost-button:hover { background: var(--sidebar-hover); }

/* === Dark: Voice Recording === */
[data-theme="dark"] .voice-overlay { background: rgba(0, 0, 0, 0.85); }
[data-theme="dark"] .voice-exit-link { color: #f87171; }

/* === Dark: Badges === */
[data-theme="dark"] .user-title {
    color: #f0d060;
    background: linear-gradient(135deg, rgba(255, 214, 102, 0.20), rgba(255, 245, 204, 0.25));
    border-color: rgba(255, 184, 0, 0.35);
    box-shadow: 0 0 8px rgba(255, 184, 0, 0.10);
}

[data-theme="dark"] .user-level-badge {
    color: #7ed4b0;
    background: linear-gradient(135deg, rgba(16, 163, 127, 0.20), rgba(100, 220, 180, 0.20));
    border-color: rgba(16, 163, 127, 0.40);
    box-shadow: 0 0 6px rgba(16, 163, 127, 0.10);
}

[data-theme="dark"] .role-badge.role-admin {
    background: rgba(239, 65, 70, 0.20);
    color: #f06060;
}

[data-theme="dark"] .role-badge.role-vip {
    background: rgba(255, 184, 0, 0.20);
    color: #f0c040;
}

[data-theme="dark"] .role-badge.role-channel-owner {
    background: rgba(91, 106, 191, 0.18);
    color: #8a9cf0;
}

/* === Dark: Red Packet === */
[data-theme="dark"] .red-packet-open-shell { background: var(--card); }

[data-theme="dark"] .red-packet-claim-item { color: var(--text); }

[data-theme="dark"] .red-packet-claim-amount { color: var(--primary); }

[data-theme="dark"] .red-packet-send-dialog input,
[data-theme="dark"] .red-packet-send-dialog textarea {
    background: var(--sidebar-bg);
    color: var(--text);
    border-color: var(--line);
}

/* === Dark: Level === */
[data-theme="dark"] .level-progress-bar { background: var(--line); }

[data-theme="dark"] .level-progress-fill {
    background: linear-gradient(90deg, var(--primary), #40d4a0);
}

[data-theme="dark"] .level-progress-text { color: var(--muted); }

/* === Dark: Misc === */
[data-theme="dark"] .mention-alert {
    background: var(--sidebar-bg);
    color: var(--text);
    border-color: var(--line);
}

[data-theme="dark"] .button-disabled { opacity: 0.35; }

[data-theme="dark"] .profile-mute-toggle .ghost-button {
    border-color: var(--line);
    color: var(--text);
}

[data-theme="dark"] .profile-mute-toggle .ghost-button:hover { background: var(--sidebar-hover); }

[data-theme="dark"] .toast { background: rgba(30, 30, 46, 0.95); }

[data-theme="dark"] .ws-reconnect-banner {
    background: var(--sidebar-bg);
    color: var(--text);
    border-bottom-color: var(--line);
}

[data-theme="dark"] .room-access-denied { color: var(--text); }

[data-theme="dark"] .room-access-form input {
    background: var(--sidebar-bg);
    color: var(--text);
    border-color: var(--line);
}

[data-theme="dark"] .idle-modal-box { background: var(--card); color: var(--text); }

[data-theme="dark"] .idle-reconnect-btn { background: var(--primary); color: #fff; }

[data-theme="dark"] .pending-message-banner {
    background: var(--sidebar-bg);
    color: var(--text);
    border-top-color: var(--line);
}

[data-theme="dark"] .welcome-hint { color: var(--muted); }

[data-theme="dark"] .announcement-banner {
    background: var(--sidebar-bg);
    border-bottom-color: var(--line);
    color: var(--text);
}

[data-theme="dark"] .announcement-close { color: var(--muted); }

/* === Dark: Coin & Pendant Modals === */
[data-theme="dark"] .coin-history-modal .coin-list-item {
    border-bottom-color: var(--line);
    color: var(--text);
}

[data-theme="dark"] .coin-history-modal .coin-list-item .coin-amount.positive { color: #4ade80; }
[data-theme="dark"] .coin-history-modal .coin-list-item .coin-amount.negative { color: #f87171; }

[data-theme="dark"] .coin-history-modal .coin-howto {
    background: var(--sidebar-bg);
    border-color: var(--line);
    color: var(--muted);
}

[data-theme="dark"] .coin-history-modal .coin-balance-display { color: var(--text); }
[data-theme="dark"] .coin-history-modal .coin-balance-amount { color: var(--primary); }
[data-theme="dark"] .coin-history-modal .coin-history-pagination {
    color: var(--muted);
}

[data-theme="dark"] .pendant-shop-item {
    background: var(--sidebar-bg);
    border-color: var(--line);
}

[data-theme="dark"] .pendant-shop-item:hover { border-color: var(--primary); }
[data-theme="dark"] .pendant-shop-item .pendant-name { color: var(--text); }
[data-theme="dark"] .pendant-shop-item .pendant-meta { color: var(--muted); }
[data-theme="dark"] .pendant-shop-item .pendant-req-item { color: var(--muted); }
[data-theme="dark"] .pendant-shop-item .pendant-req-item.req-unmet { color: #f87171; }

[data-theme="dark"] .pendant-shop-item .pendant-action-btn {
    color: var(--text);
    border-color: var(--line);
    background: transparent;
}

[data-theme="dark"] .pendant-shop-item .pendant-action-btn:hover:not(:disabled) {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

[data-theme="dark"] .pendant-shop-item .pendant-action-btn:disabled { opacity: 0.5; color: var(--muted); }

[data-theme="dark"] .pendant-shop-item .pendant-action-btn.equipped {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

/* === Dark: Admin === */
[data-theme="dark"] .admin-layout { background: var(--bg); color: var(--text); }

[data-theme="dark"] .admin-layout .admin-nav {
    background: var(--sidebar-bg);
    border-right-color: var(--sidebar-line);
}

[data-theme="dark"] .admin-layout .admin-nav a { color: var(--sidebar-text); }
[data-theme="dark"] .admin-layout .admin-nav a:hover { background: var(--sidebar-hover); }

[data-theme="dark"] .admin-layout .admin-nav a.active {
    background: rgba(16, 163, 127, 0.20);
    color: var(--primary);
}

[data-theme="dark"] .admin-layout .admin-content input,
[data-theme="dark"] .admin-layout .admin-content select,
[data-theme="dark"] .admin-layout .admin-content textarea {
    background: var(--sidebar-bg);
    color: var(--text);
    border-color: var(--line);
}

[data-theme="dark"] .admin-layout .admin-content .btn-primary { background: var(--primary); color: #fff; }

[data-theme="dark"] .admin-layout .admin-content .btn-secondary {
    background: var(--sidebar-bg);
    color: var(--text);
    border-color: var(--line);
}

[data-theme="dark"] .admin-layout table { color: var(--text); }
[data-theme="dark"] .admin-layout table th { background: var(--sidebar-bg); color: var(--sidebar-muted); }
[data-theme="dark"] .admin-layout table td { border-bottom-color: var(--line); }

[data-theme="dark"] .admin-layout .admin-card { background: var(--card); border-color: var(--line); }
[data-theme="dark"] .admin-layout .admin-card h3 { color: var(--text); }
[data-theme="dark"] .admin-layout .form-hint { color: var(--muted); }
[data-theme="dark"] .admin-layout .stat-value { color: var(--primary); }
[data-theme="dark"] .admin-layout .toggle-label { color: var(--text); }
[data-theme="dark"] select{
    background: var(--sidebar-bg)!important;
    color: var(--text)!important;
}
[data-theme="dark"] .admin-cfg-field input, .admin-cfg-field select{
    background: var(--sidebar-bg)!important;
    color: var(--text)!important;
}

/* === Reset & Scrollbar === */
* {
    box-sizing: border-box;
    scrollbar-width: thin;
    scrollbar-color: rgba(142, 142, 160, 0.3) transparent;
}

*::-webkit-scrollbar { width: 6px; height: 6px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: rgba(142, 142, 160, 0.25); border-radius: var(--radius-full); }
*::-webkit-scrollbar-thumb:hover { background: rgba(142, 142, 160, 0.45); }

html {
    height: 100%;
    overflow: hidden;
}

body {
    margin: 0;
    font-family: "Segoe UI", "PingFang SC", "Noto Sans SC", -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    height: var(--app-viewport-height);
    min-height: 100vh;
    min-height: var(--app-viewport-height);
    overflow: hidden;
    overscroll-behavior: none;
}

body.is-embedded { background: #fff; }

button, input, textarea { font: inherit; }
button { cursor: pointer; border: none; }
h1, h2, h3, p { margin: 0; }

/* === Disable text selection globally, allow only in chat messages === */
body {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    cursor: default;
}

.message-list,
.message-list * {
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
    cursor: text;
}

.message-list button,
.message-list a,
.message-list .message-avatar-trigger {
    cursor: pointer;
}

input, textarea, select {
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
    cursor: text;
}

button, a, [role="button"] {
    cursor: pointer;
}

.ui-icon {
    width: 1em;
    height: 1em;
    display: inline-block;
    vertical-align: -0.16em;
    flex: 0 0 auto;
    filter: var(--ui-icon-filter, none);
}

button .ui-icon,
.context-menu-item .ui-icon,
.admin-nav-icon .ui-icon,
.emoji-tab .ui-icon,
.room-chip-name .ui-icon {
    width: 16px;
    height: 16px;
}

.room-chip-name .ui-icon {
    vertical-align: -0.22em;
}

.emoji-tab.active .ui-icon,
.admin-nav-item.active .ui-icon,
.scroll-to-bottom .unread-badge + .unread-arrow .ui-icon {
    --ui-icon-filter: brightness(0) saturate(100%) invert(56%) sepia(50%) saturate(1032%) hue-rotate(119deg) brightness(85%) contrast(87%);
}

.scroll-to-bottom:hover .ui-icon,
.message-input-row button[type="submit"] .ui-icon,
.voice-mic-icon .ui-icon,
.announcement-banner .announcement-icon .ui-icon,
.message-image-remove .ui-icon {
    --ui-icon-filter: brightness(0) invert(1);
}

/* === App Shell Grid === */
.app-shell {
    height: 100vh;
    height: var(--app-viewport-height);
    min-height: var(--app-viewport-height);
    display: grid;
    grid-template-columns: 300px minmax(0, 1fr);
    gap: 0;
    padding: 0;
    overflow-x: hidden;
    overflow-y: auto;
}

.app-shell-chat {
    grid-template-columns: 300px minmax(0, 1fr) 280px;
}

.app-shell-chat.online-sidebar-collapsed {
    grid-template-columns: 300px minmax(0, 1fr);
}

.app-shell-embedded {
    grid-template-columns: 1fr !important;
    padding: 0;
    gap: 0;
    height: 100vh;
    height: var(--app-viewport-height);
}

.app-shell-embedded .chat-card {
    border-radius: 0;
    height: 100vh;
    height: var(--app-viewport-height);
    border: none;
    box-shadow: none;
}

.app-shell-embedded .chat-header {
    cursor: grab;
}

.app-shell-embedded .chat-header:active {
    cursor: grabbing;
}

/* === Embed Notice === */
.embed-notice {
    position: sticky;
    top: 0;
    z-index: 10;
    text-align: center;
    padding: 8px 16px;
    background: var(--primary);
    color: #fff;
    font-size: 13px;
    font-weight: 500;
}

.embed-notice a { color: #fff; text-decoration: none; font-weight: 600; }
.embed-notice a:hover { text-decoration: underline; }

/* === Mobile Drawer System === */
.mobile-only { display: none; }
.desktop-sidebar { display: flex; }

.mobile-drawer {
    position: fixed;
    inset: 0;
    z-index: 45;
    display: none;
}

.mobile-drawer:not(.hidden) { display: block; }

.mobile-drawer-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
    opacity: 0;
    transition: opacity .25s ease;
}

.mobile-drawer.open .mobile-drawer-backdrop {
    opacity: 1;
}

.mobile-drawer-panel {
    position: absolute;
    inset: 0 auto 0 0;
    width: min(85vw, 300px);
    padding: 0;
    overflow-y: hidden;
    background: var(--sidebar-bg);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.12);
    border-right: 1px solid var(--sidebar-line);
    transform: translateX(-100%);
    transition: transform .25s ease;
}

.mobile-drawer.open .mobile-drawer-panel {
    transform: translateX(0);
}

.mobile-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 16px 12px;
    border-bottom: 1px solid var(--sidebar-line);
}

.mobile-drawer-header p,
.mobile-drawer-header h3 {
    color: var(--sidebar-text);
}

.mobile-drawer-close {
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: var(--radius-full);
    background: var(--sidebar-hover);
    color: var(--sidebar-text);
    font-size: 18px;
    position: relative;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mobile-drawer-close:hover {
    background: var(--sidebar-active);
}

.mobile-drawer-sidebar {
    min-height: 0;
    height: calc(var(--app-viewport-height) - 75px)!important;
    padding: 0;
    border: none;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
}

.mobile-online-panel { display: none; }

body.drawer-open { overflow: hidden; }

/* === Mobile Drawer Toggle Button === */
.drawer-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: var(--radius-md);
    flex-shrink: 0;
}

.drawer-toggle-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text);
    font-size: 20px;
    line-height: 1;
}

.drawer-toggle:hover {
    background: var(--bg);
    transform: none;
}

.sidebar-card {
    background: var(--sidebar-bg);
    border: none;
    border-right: 1px solid var(--sidebar-line);
    border-radius: 0;
    box-shadow: none;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0;
    height: 100vh;
    height: var(--app-viewport-height);
    position: sticky;
    top: 0;
    overflow: hidden;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
}

.chat-card {
    background: var(--card);
    border: none;
    border-radius: 0;
    box-shadow: none;
    position: relative;
    padding: 0;
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: var(--app-viewport-height);
    min-height: 0;
    overflow: hidden;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
}

/* === Init Loading === */
.init-loading-indicator {
    position: absolute;
    inset: 0;
    z-index: 3;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    background: var(--bg, #f5f5f5);
    color: var(--muted);
    font-size: 13px;
    transition: opacity 0.25s ease;
}

.init-loading-indicator.hidden {
    opacity: 0;
    pointer-events: none;
}

.init-loading-spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--line);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: history-spinner-rotate 0.75s linear infinite;
}

/* === History Loading === */
.history-loading-indicator {
    position: sticky;
    top: 0;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: fit-content;
    max-width: calc(100% - 32px);
    margin: 0 auto;
    padding: 8px 16px;
    border: 1px solid var(--line);
    border-radius: var(--radius-full);
    background: var(--card);
    box-shadow: var(--shadow-sm);
    color: var(--muted);
    font-size: 13px;
    pointer-events: none;
}

.history-end-hint {
    text-align: center;
    color: var(--muted);
    font-size: 13px;
    padding: 8px 0;
}

.history-load-more {
    display: block;
    margin: 8px auto;
    padding: 6px 16px;
    border: 1px solid var(--line);
    border-radius: var(--radius-full);
    background: var(--card);
    box-shadow: var(--shadow-sm);
    color: var(--muted);
    font-size: 13px;
    cursor: pointer;
    transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.history-load-more:hover {
    color: var(--primary);
    border-color: var(--primary);
}

.history-load-more:disabled {
    cursor: not-allowed;
    opacity: 0.6;
}

.history-loading-spinner {
    width: 14px;
    height: 14px;
    border: 2px solid var(--line);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: history-spinner-rotate 0.75s linear infinite;
}

@keyframes history-spinner-rotate {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* === Brand Block (sidebar top) === */
.brand-block {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 20px 16px 16px;
}

.brand-block h1 {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
}

/* === Panel Title Row === */
.panel-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding-bottom: 8px;
}

/* === Chat Header === */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 20px;
    border-bottom: 1px solid var(--line);
    background: var(--card);
    flex-shrink: 0;
    position: relative;
}

.chat-header h2 {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    pointer-events: none;
}

/* === User Card (sidebar bottom) === */
.user-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 16px;
    border-top: 1px solid var(--sidebar-line);
    margin: 0;
}

.user-card > div {
    width: 100%;
    border-radius: var(--radius-md);
    padding: 8px;
}

.user-identity {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0;
    background: transparent;
    color: var(--sidebar-text);
    text-align: left;
    cursor: default;
}

.user-identity:hover{
    transform: none!important;
    background: transparent!important;
}

.user-identity strong { color: var(--sidebar-text); }
.user-identity .identity-line { color: var(--sidebar-muted); }

/* === Avatar === */
.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    background: #f0f0f0;
    border: 2px solid var(--line);
    flex-shrink: 0;
}

.avatar-lg {
    width: 72px;
    height: 72px;
}

.avatar-sm {
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    border-width: 1px;
}

/* === Image Lightbox === */
.chat-inline-image { cursor: zoom-in; }
.image-lightbox {
    z-index: 70;
    display: flex;
    align-items: center;
    justify-content: center;
}

.image-lightbox-dialog {
    position: relative;
    width: 100vw;
    height: 100vh;
    max-width: 80vw!important;
    margin: 0;
    padding: 0;
    background: rgba(0, 0, 0, 0.92);
    border: none;
    border-radius: 0;
    box-shadow: none;
    display: flex;
    align-items: center;
    justify-content: center;
}

.image-lightbox-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    font-size: 24px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.image-lightbox-close:hover { background: rgba(255, 255, 255, 0.2); }

/* === Video Lightbox === */
.video-lightbox {
    z-index: 70;
    display: flex;
    align-items: center;
    justify-content: center;
}

.video-lightbox-dialog {
    position: relative;
    width: 100vw;
    height: 100vh;
    max-width: 80vw!important;
    margin: 0;
    padding: 0;
    background: rgba(0, 0, 0, 0.92);
    border: none;
    border-radius: 0;
    box-shadow: none;
    display: flex;
    align-items: center;
    justify-content: center;
}

.video-lightbox-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    font-size: 24px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1;
    cursor: pointer;
    border: none;
}

.video-lightbox-close:hover { background: rgba(255, 255, 255, 0.2); }

.video-lightbox-player {
    display: block;
    width: 100%;
    max-width: 95vw;
    max-height: 95vh;   
    border-radius: 0;
    outline: none;
}

.image-lightbox-preview {
    display: block;
    width: 100%;
    max-width: 95vw;
    max-height: 95vh;
    border-radius: 0;
    object-fit: contain;
}

/* === Eyebrow === */
.eyebrow {
    margin: 0 0 4px;
    color: var(--sidebar-muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    font-weight: 500;
}

/* === Status / Tips === */
.status-dot {
    background: var(--primary-glow);
    color: var(--primary);
    padding: 1px;
    border-radius: var(--radius-full);
    font-size: 12px;
    font-weight: 600;
}

.tips-box span {
    background: var(--primary-glow);
    color: var(--primary);
    padding: 6px 12px;
    border-radius: var(--radius-full);
    font-size: 12px;
    font-weight: 600;
}

.tips-box span.tips-denied {
    background: rgba(239, 65, 70, 0.1);
    color: var(--danger);
}

.tips-box {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    order: 1;
    margin-left: auto;
}

.chat-header-more {
    display: none;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    font-size: 20px;
    color: var(--muted);
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1;
    order: 2;
}

.online-sidebar-toggle {
    padding: 6px 12px;
    border-radius: var(--radius-full);
    font-size: 12px;
    font-weight: 500;
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--line);
}

.online-sidebar-toggle:hover {
    background: var(--bg);
    transform: none;
}

/* === Text Helpers === */
.intro-text {
    color: var(--sidebar-muted);
    line-height: 1.5;
    font-size: 13px;
    padding: 0 16px 12px;
}

.room-desc {
    color: var(--muted);
    line-height: 1.5;
    font-size: 13px;
}

.user-card p { color: rgba(255, 255, 255, 0.75); line-height: 1.5; }
.tips-box small { color: var(--muted); line-height: 1.5; }

.form-hint {
    font-size: 13px;
    color: var(--muted);
    line-height: 1.5;
}

/* === Sidebar Panel === */
.panel {
    border: none;
    border-radius: 0;
    padding: 12px 16px;
    background: transparent;
}

.panel h2 {
    color: var(--sidebar-muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 600;
}

.panel-title-row span {
    color: var(--sidebar-muted);
    font-size: 12px;
}

/* === Room List === */
.room-list,
.auth-grid,
.stack-form,
.auth-form,
.message-form {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.panel:has(.room-list) {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.room-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}

/* === Captcha / Email Token Row === */
.captcha-row {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.captcha-row .form-hint {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--primary);
}

.email-token-row,
.nickname-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    align-items: center;
}

.email-token-row .ghost-button,
.nickname-row .ghost-button { white-space: nowrap; }

.remember-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 2px 0 4px;
    color: var(--muted);
    font-size: 13px;
    cursor: pointer;
    -webkit-user-select: none;
    user-select: none;
}

.remember-row input {
    width: 16px;
    height: 16px;
    accent-color: var(--primary);
    cursor: pointer;
}

.auth-link-btn {
    background: none;
    border: none;
    color: var(--primary);
    font-size: 13px;
    cursor: pointer;
    padding: 8px 8px;
    text-align: center;
}
.auth-link-btn:hover { text-decoration: underline; }

.auth-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 4px 0;
    color: var(--muted);
    font-size: 13px;
}
.auth-divider::before,
.auth-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--line);
}

.wp-sso-button {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 16px;
    border-radius: var(--radius-md);
    border: 1px solid var(--line);
    background: var(--card);
    color: var(--text);
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}
.wp-sso-button:hover {
    background: var(--primary-glow);
    border-color: var(--primary);
    color: var(--primary);
}

#mute-duration-row {
    display: flex;
    gap: 8px;
    align-items: center;
}
#mute-duration-row.hidden { display: none; }
#move-message-room-row {
    display: flex;
    gap: 8px;
    align-items: center;
}
#mute-scope-select,
#mute-duration-select,
#move-message-room {
    flex: 1;
    width: 100%;
    min-width: 0;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    font-size: 14px;
    background: var(--bg);
    color: var(--text);
}
#move-message-room:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}
#mute-duration-custom {
    width: 100px;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    font-size: 14px;
}
#mute-duration-custom.hidden { display: none; }

/* === Auth Actions (sidebar) === */
.auth-actions {
    display: flex;
    gap: 8px;
    padding: 0 16px 12px;
}

.auth-trigger { flex: 1; }

.pwa-install-row {
    padding: 4px 16px 12px;
}
.pwa-install-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 10px 14px;
    border: none;
    border-radius: var(--radius-md);
    background: var(--primary);
    color: #fff;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: opacity .2s;
}
.pwa-install-btn:hover {
    opacity: 0.85;
}
.pwa-install-btn svg {
    flex-shrink: 0;
}

/* === Room Chip === */
.room-chip {
    text-decoration: none;
    color: var(--sidebar-text);
    background: transparent;
    border: none;
    border-radius: var(--radius-md);
    padding: 10px 12px;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
    transition: background 0.15s ease;
    font-size: 14px;
    margin: 0;
}

a.room-chip[data-room-slug] {
    min-height: 48px;
    max-height: 52px;
    padding: 8px 10px;
    gap: 10px;
}

.room-chip-avatar {
    position: relative;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-full);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 32px;
    background: #eef2f5;
    color: #4a5562;
    font-size: 13px;
    font-weight: 700;
    line-height: 1;
    overflow: visible;
}

.room-chip-name {
    min-width: 0;
    color: #333333;
    font-size: 14px;
    font-weight: 500;
    line-height: 20px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.room-chip small {
    color: var(--sidebar-muted);
    font-size: 12px;
}

.room-chip-button {
    width: 100%;
    border: none;
    text-align: left;
}

.room-chip:hover {
    background: var(--sidebar-hover);
    border-color: transparent;
}

.room-chip.active {
    background: var(--sidebar-active);
    border-color: transparent;
    color: var(--text);
    font-weight: 600;
}

.room-chip.active .room-chip-avatar {
    background: var(--primary);
    color: #fff;
}

.room-unread-badge {
    position: absolute;
    top: -4px;
    right: -5px;
    background: var(--danger);
    color: #fff;
    font-size: 10px;
    font-weight: 600;
    line-height: 14px;
    padding: 0 4px;
    border: 2px solid var(--sidebar-bg);
    border-radius: var(--radius-full);
    min-width: 16px;
    height: 16px;
    text-align: center;
    flex-shrink: 0;
}

/* === Inputs & Textarea === */
input,
textarea {
    width: 100%;
    border: 1px solid var(--line);
    background: var(--bg);
    color: var(--text);
    border-radius: var(--radius-lg);
    padding: 12px 14px;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
    font-size: 14px;
}

input:focus,
textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
    background: #fff;
}

input[type="file"] {
    padding: 8px 10px;
    cursor: pointer;
}

input[type="file"]::file-selector-button {
    margin-right: 10px;
    border: none;
    border-radius: var(--radius-md);
    background: var(--primary);
    color: #fff;
    padding: 6px 12px;
    cursor: pointer;
    font-size: 13px;
}

.profile-form-hint { margin-top: -2px; }

/* === Buttons === */
button {
    background: var(--primary);
    color: #fff;
    border-radius: var(--radius-lg);
    padding: 10px 18px;
    font-weight: 600;
    font-size: 14px;
    transition: background 0.2s ease, transform 0.15s ease, opacity 0.2s ease;
}

button:hover {
    transform: translateY(-1px);
}

button:active {
    transform: translateY(0);
}

button:disabled {
    background: #d1d5db;
    color: #9ca3af;
    cursor: not-allowed;
    transform: none;
}

.ghost-button {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--line);
}

.ghost-button:hover {
    background: var(--bg);
    transform: none;
}

/* ==========================================
   Message List & Chat Area
   ========================================== */
.message-list {
    position: relative;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-height: 0;
    flex: 1;
    background: #fff;
}

.scroll-to-bottom {
    position: absolute;
    right: 24px;
    bottom: 100px;
    min-width: 36px;
    height: auto;
    min-height: 36px;
    border-radius: 18px;
    border: 1px solid var(--line);
    background: var(--card);
    color: var(--muted);
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    box-shadow: var(--shadow-md);
    transition: opacity 0.2s, transform 0.2s, background 0.2s, width 0.2s, border-radius 0.2s;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 6px 10px;
    white-space: nowrap;
}

.scroll-to-bottom:hover {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
    transform: scale(1.05);
}

.scroll-to-bottom:hover .unread-badge {
    color: #fff;
}

.scroll-to-bottom.hidden {
    opacity: 0;
    pointer-events: none;
}

.scroll-to-bottom .unread-badge {
    font-size: 12px;
    font-weight: 600;
    color: var(--primary);
    line-height: 1;
}

.scroll-to-bottom .unread-arrow {
    font-size: 16px;
    line-height: 1;
}

/* === Message Items (QQ-style bubbles) === */
.message-item {
    background: transparent;
    border: none;
    border-radius: 0;
    padding: 0;
    width: 100%;
    max-width: 100%;
    align-self: flex-start;
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: 10px;
    transition: none;
    position: relative;
}

@keyframes slide-left {
    to { transform: translateX(-120%); opacity: 0; }
}
@keyframes slide-right {
    to { transform: translateX(120%); opacity: 0; }
}

.message-item.message-slide-left {
    animation: slide-left 1s ease-in forwards;
    pointer-events: none;
}
.message-item.message-slide-right {
    animation: slide-right 1s ease-in forwards;
    pointer-events: none;
}

.message-item:hover {
    background: transparent;
    box-shadow: none;
}

/* -- The bubble itself -- */
.message-item .message-content {
    --msg-bg: #fff;
    position: relative;
    background: var(--msg-bg);
    border: 1px solid #e8e8e8;
    border-radius: 12px;
    padding: 10px 14px;
    margin-top: 0;
    line-height: 1.6;
    word-break: break-word;
    font-size: 15px;
}


/* -- Other messages (left side) -- */
.message-item-other {
    align-self: flex-start;
    flex-direction: row;
}

.message-item-other .message-content {
    --msg-bg: #fff;
    background: var(--msg-bg);
    border-color: #e8e8e8;
    border-top-left-radius: 4px;
}

.message-item-other:hover .message-content {
    --msg-bg: #fafafa;
    background: var(--msg-bg);
}

/* -- Own messages (right side) -- */
.message-item-own {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message-item-own .message-content {
    --msg-bg: #d6e8fc;
    background: var(--msg-bg);
    border-color: #bdd4f0;
    border-top-right-radius: 4px;
    color: #000;
}


.message-item-own:hover .message-content {
    --msg-bg: #c9ddf5;
    background: var(--msg-bg);
}


/* -- Collapsible long messages -- */
.message-content.collapsible {
    position: relative;
    overflow: hidden;
    transition: max-height 0.35s ease;
}
.message-content.collapsible::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: linear-gradient(to bottom, transparent, var(--msg-bg, #fff));
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.25s ease;
}
.message-content.collapsible.collapsed::after {
    opacity: 1;
}
.message-collapse-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 4px 0 2px;
    border: none;
    background: none;
    cursor: pointer;
    color: var(--muted);
    font-size: 14px;
    transition: color 0.2s;
}
.message-collapse-toggle:hover {
    color: var(--primary);
}
.message-collapse-toggle svg {
    width: 18px;
    height: 18px;
    transition: transform 0.25s ease;
}
.message-collapse-toggle.expanded svg {
    transform: rotate(180deg);
}

/* -- Mention messages -- */
.message-item-mention .message-content {
    --msg-bg: rgba(255, 184, 0, 0.08);
    background: var(--msg-bg);
    border-left: 3px solid #f59e0b;
}

.message-item-mention:hover .message-content {
    --msg-bg: rgba(255, 184, 0, 0.12);
    background: var(--msg-bg);
}

.message-item-private .message-content {
    --msg-bg: var(--accent-blue);
    background: var(--msg-bg);
    border-left: 3px solid var(--accent-blue);
}

.message-item-private:hover .message-content {
    --msg-bg: var(--accent-blue);
    background: var(--msg-bg);
}

.message-item-highlight .message-content {
    box-shadow: 0 0 0 2px rgba(16, 163, 127, 0.35), 0 0 0 8px rgba(16, 163, 127, 0.10);
    animation: message-jump-highlight 1.8s ease-out 2;
}

@keyframes message-jump-highlight {
    0% {
        box-shadow: 0 0 0 2px rgba(16, 163, 127, 0.55), 0 0 0 14px rgba(16, 163, 127, 0.18);
    }
    60% {
        box-shadow: 0 0 0 2px rgba(16, 163, 127, 0.32), 0 0 0 8px rgba(16, 163, 127, 0.10);
    }
    100% {
        box-shadow: 0 0 0 2px rgba(16, 163, 127, 0), 0 0 0 0 rgba(16, 163, 127, 0);
    }
}

/* -- Media-only messages (single image/sticker): no bubble -- */
.message-content-media-only {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
}

.message-content-media-only::before {
    display: none !important;
}

/* === Avatar trigger (QQ-style: outside the bubble) === */
.message-avatar-trigger {
    padding: 0;
    background: transparent;
    border: none;
    flex-shrink: 0;
    cursor: pointer;
    align-self: flex-start;
    margin-top: 0;
}

.message-avatar-trigger:hover {
    background: transparent;
    transform: none;
}

/* === Bubble wrap (name + bubble + actions column) === */
.message-bubble-wrap {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    max-width: min(75%, 600px);
    min-width: 0;
}

.message-item-own .message-bubble-wrap {
    align-items: flex-end;
}

/* === Message Meta (QQ-style: name row above bubble) === */
.message-meta {
    display: flex;
    align-items: center;
    padding: 0 2px;
    gap: 6px;
    margin-bottom: 2px;
}

.message-item-own .message-meta {
    flex-direction: row-reverse;
}

.message-time-hint {
    font-size: 11px;
    color: var(--muted);
    font-weight: normal;
    white-space: nowrap;
    margin-left: 4px;
}

.message-item-own .message-user-name {
    flex-direction: row-reverse;
}

.message-item-own .message-time-hint {
    margin-left: 0;
    margin-right: 4px;
}

.message-user-name {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    flex-wrap: wrap;
    font-size: 13px;
    color: var(--muted);
    font-weight: 500;
}

.identity-line {
    display: flex;
    align-items: center;
    gap: 6px;
    overflow: hidden;
    max-width: 100%;
}

.identity-line > * {
    flex-shrink: 0;
    white-space: nowrap;
}

.identity-line > *:last-child {
    flex-shrink: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.identity-line-center {
    justify-content: center;
}

.user-title {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 2px 8px;
    border-radius: var(--radius-full);
    font-size: 11px;
    font-weight: 600;
    color: #92640d;
    background: linear-gradient(135deg, rgba(255, 214, 102, 0.25), rgba(255, 245, 204, 0.7));
    border: 1px solid rgba(255, 184, 0, 0.2);
}

.user-level-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 2px 8px;
    border-radius: var(--radius-full);
    font-size: 11px;
    font-weight: 600;
    color: #1a6b4a;
    background: linear-gradient(135deg, rgba(16, 163, 127, 0.15), rgba(200, 240, 220, 0.7));
    border: 1px solid rgba(16, 163, 127, 0.25);
    white-space: nowrap;
}

/* === 3D Flip: Title ↔ Level === */
.title-level-flip {
    display: inline-grid;
    perspective: 300px;
    vertical-align: middle;
}

.title-level-flip-inner {
    display: grid;
    grid-template-areas: "cell";
    position: relative;
    transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    transform-style: preserve-3d;
}

.title-level-front,
.title-level-back {
    grid-area: cell;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    white-space: nowrap;
}

.title-level-back {
    transform: rotateY(180deg);
}

.message-user-name:hover .title-level-flip:not(.no-title) .title-level-flip-inner {
    transform: rotateY(180deg);
}

.title-level-flip.no-title .title-level-back {
    display: none;
}

/* === Level Progress === */
.level-progress-section {
    width: 100%;
    margin-top: 8px;
    text-align: center;
}

.level-progress-label {
    margin-bottom: 6px;
}

.level-progress-bar {
    width: 100%;
    height: 10px;
    background: #e5e7eb;
    border-radius: var(--radius-full);
    overflow: hidden;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.08);
}

.level-progress-fill {
    height: 100%;
    border-radius: var(--radius-full);
    background: linear-gradient(90deg, #10a37f, #34d399);
    transition: width 0.4s ease;
    min-width: 4px;
}

.level-progress-text {
    font-size: 11px;
    color: var(--muted);
    margin-top: 4px;
}

.message-user-name .tag {
    margin-left: 0;
}

.message-user-text time {
    color: var(--muted);
    font-size: 11px;
}

.message-item p {
    margin-top: 0;
    padding-left: 0;
    line-height: 1.6;
    word-break: break-word;
}

.message-item-own p {
    padding-left: 0;
    padding-right: 0;
    text-align: right;
}

/* === Tags === */
.tag {
    display: inline-flex;
    align-items: center;
    margin-left: 6px;
    padding: 2px 8px;
    border-radius: var(--radius-full);
    font-size: 11px;
    font-weight: 600;
}

.tag-private {
    background: rgba(91, 106, 191, 0.12);
    color: var(--accent-blue);
}

.tag-system {
    background: var(--primary-glow);
    color: var(--primary);
}

.tag-mention {
    background: rgba(245, 158, 11, 0.12);
    color: #b45309;
}

/* === Table List / Online Users === */
.table-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    height: calc(100vh - 180px);
    overflow-y: auto;
}

.table-list.compact {
    margin-top: 8px;
}

.table-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 12px;
    border: none;
    border-radius: var(--radius-md);
    background: transparent;
    transition: background 0.15s ease;
}

.table-row:hover {
    background: var(--bg);
}

/* === Admin User Info === */
.admin-user-info {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    min-width: 0;
}

.admin-user-info p {
    margin: 2px 0 0;
    font-size: 12px;
    color: var(--muted);
    word-break: break-all;
}

.inline-role-form {
    display: flex;
    align-items: center;
    gap: 8px;
}

.admin-user-forms {
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: flex-end;
}

.inline-role-form select {
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    padding: 8px 10px;
    background: #fff;
    font-size: 13px;
}

.inline-role-form input[type="text"] {
    width: 120px;
    border-radius: var(--radius-md);
    padding: 8px 10px;
    font-size: 13px;
}

/* === Online User Rows === */
.online-user-row {
    align-items: center;
    width: 100%;
    text-align: left;
}

.online-user-main {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    flex: 1;
}

.online-user-name {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 120px;
    color: var(--text);
    font-size: 14px;
}

.online-user-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

/* === Avatar Status Dot === */
.avatar-wrapper {
    position: relative;
    display: inline-flex;
    flex-shrink: 0;
    overflow: visible;
}

.avatar-wrapper .avatar {
    position: relative;
    z-index: 1;
}

.avatar-pendant {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 160%;
    height: 160%;
    object-fit: contain;
    pointer-events: none;
    z-index: 2;
}

/* Profile header: pendant needs to follow avatar's translateY */
.profile-header-gradient .avatar-wrapper {
    transform: translateY(40px);
}
.profile-header-gradient .avatar-profile {
    transform: none;
}

.status-dot {
    position: absolute;
    bottom: -2px;
    right: -2px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    border: 1.5px solid var(--card, #fff);
    box-sizing: content-box;
    display: block;
    pointer-events: auto;
    z-index: 3;
}

.status-dot::before {
    content: '';
    position: absolute;
    top: -6px;
    left: -6px;
    right: -6px;
    bottom: -6px;
    border-radius: 50%;
}

.status-dot.status-online {
    background: #22c55e;
    cursor: help;
}

.status-dot.status-away {
    background: #eab308;
    cursor: help;
}

.status-dot.status-offline {
    background: #9ca3af;
    cursor: help;
}

/* === Status Tooltip Bubble === */
.status-tooltip {
    position: absolute;
    left: calc(100% + 6px);
    top: 50%;
    transform: translateY(-50%);
    background: var(--card, #fff);
    color: var(--text, #333);
    font-size: 12px;
    line-height: 1.3;
    white-space: nowrap;
    padding: 4px 8px;
    border-radius: var(--radius-sm, 4px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    border: 1px solid var(--line, #e5e7eb);
    z-index: 100;
    pointer-events: none;
    animation: statusTooltipIn 0.15s ease;
}

.status-tooltip::before {
    content: '';
    position: absolute;
    right: 100%;
    top: 50%;
    transform: translateY(-50%);
    border: 5px solid transparent;
    border-right-color: var(--line, #e5e7eb);
}

.status-tooltip::after {
    content: '';
    position: absolute;
    right: 100%;
    top: 50%;
    transform: translateY(-50%);
    border: 4px solid transparent;
    border-right-color: var(--card, #fff);
}

@keyframes statusTooltipIn {
    from { opacity: 0; transform: translateY(-50%) translateX(-4px); }
    to   { opacity: 1; transform: translateY(-50%) translateX(0); }
}

/* === Offline Members Section === */
.offline-section {
    margin-top: 8px;
}

.offline-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.offline-toggle-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px 0;
    color: var(--text);
}

.offline-toggle-btn:hover {
    opacity: 0.7;
}

.offline-toggle-btn h2 {
    margin: 0;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text);
}

.offline-toggle-arrow {
    font-size: 10px;
    transition: transform 0.2s ease;
    display: inline-block;
}

.offline-toggle-btn[aria-expanded="true"] .offline-toggle-arrow {
    transform: rotate(90deg);
}

.offline-users-list.collapsed {
    flex: 0 !important;
    min-height: 0 !important;
    overflow: hidden;
    opacity: 0;
}

.offline-users-list:not(.collapsed) {
    opacity: 1;
    transition: opacity 0.3s ease;
}


.message-user-trigger,
.message-user-name-button {
    padding: 0;
    background: transparent;
    color: inherit;
    border-radius: 0;
}

.message-user-name-button:hover,
.message-user-trigger:hover {
    background: transparent;
    transform: none;
}

/* === Profile Card === */
.profile-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    text-align: center;
    padding: 0 20px 20px;
}

.profile-card-user-action {
    align-items: center;
}

.profile-card-actions {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 8px;
}

/* --- Profile Modal Redesign --- */
.modal-dialog-profile {
    padding: 0 !important;
    overflow: hidden;
}

.modal-close-profile {
    z-index: 2;
    background: rgba(255, 255, 255, 0.35);
    color: #fff;
    backdrop-filter: blur(4px);
}

.profile-header-gradient {
    position: relative;
    width: 100%;
    height: 120px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.avatar-profile {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    border: 3px solid #fff;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
    object-fit: cover;
    transform: translateY(40px);
    background: #fff;
}

.profile-card-name {
    margin-top: 44px;
    font-size: 18px;
    font-weight: 700;
}

.profile-card-uid {
    font-size: 12px;
    color: var(--muted);
    margin: -4px 0 0;
}

.profile-edit-section {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 4px;
}

.profile-mute-toggle {
    width: 100%;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--line);
}
.sound-mute-btn {
    width: 100%;
    text-align: center;
    font-size: 13px;
}

.profile-inline-form {
    display: flex;
    gap: 6px;
    width: 100%;
}

.profile-inline-form input[type="text"],
.profile-inline-form input[type="file"] {
    flex: 1;
    min-width: 0;
}

.profile-inline-form button {
    flex-shrink: 0;
    padding: 6px 14px;
    font-size: 13px;
}

/* === WebSocket Signal === */
.ws-signal {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    vertical-align: middle;
    font-size: 11px;
    font-weight: 600;
    line-height: 1;
    padding: 4px 10px;
    border-radius: var(--radius-full);
    background: rgba(0, 0, 0, 0.04);
}

.ws-signal::before {
    content: '';
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    flex-shrink: 0;
    transition: background 0.3s ease, box-shadow 0.3s ease;
}

.ws-signal-on::before {
    background: #22c55e;
    box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.2);
}

.ws-signal-on { color: #16a34a; }

.ws-signal-medium::before {
    background: #eab308;
    box-shadow: 0 0 0 2px rgba(234, 179, 8, 0.2);
}

.ws-signal-medium { color: #a16207; }

.ws-signal-off::before {
    background: #ef4444;
    box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.2);
}

.ws-signal-off { color: #dc2626; }

/* === WebSocket Reconnect Banner === */
.ws-reconnect-banner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 8px 16px;
    background: #ef4444;
    color: #fff;
    font-size: 13px;
    font-weight: 500;
    flex-shrink: 0;
    z-index: 100;
}

.ws-reconnect-banner.hidden {
    display: none;
}

.ws-reconnect-banner svg {
    flex-shrink: 0;
    animation: ws-reconnect-pulse 1.5s ease-in-out infinite;
}

@keyframes ws-reconnect-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* === Idle Disconnect Modal === */
.idle-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(4px);
}
.idle-modal-overlay.hidden { display: none; }
.idle-modal-dialog {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius-xl);
    padding: 32px 36px;
    text-align: center;
    max-width: 360px;
    width: 90%;
    box-shadow: var(--shadow-lg);
}
.idle-modal-dialog h3 {
    margin: 0 0 12px;
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--text);
}
.idle-modal-dialog p {
    margin: 0 0 24px;
    font-size: 0.9rem;
    color: var(--muted);
    line-height: 1.5;
}
.idle-reconnect-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 28px;
    border: none;
    border-radius: var(--radius-full);
    background: var(--primary);
    color: #fff;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}
.idle-reconnect-btn:hover { background: var(--primary-dark); }

/* === Mention Alert === */
.mention-alert {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: var(--radius-full);
    background: rgba(245, 158, 11, 0.12);
    color: #92400e;
    font-size: 13px;
    flex-shrink: 0;
    cursor: pointer;
    border: none;
}

.mention-alert:hover {
    background: rgba(245, 158, 11, 0.2);
}

.hidden,
.mention-alert.hidden,
.modal.hidden {
    display: none !important;
}

.modal-dialog-sm {
    max-width: 400px;
}

/* === Role Badges === */
.role-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 48px;
    padding: 3px 8px;
    border-radius: var(--radius-full);
    font-size: 11px;
    font-weight: 600;
}

.role-admin {
    background: rgba(239, 65, 70, 0.1);
    color: #dc2626;
}

.role-member {
    background: rgba(142, 142, 160, 0.1);
    color: #6b7280;
}

.role-channel-owner {
    background: rgba(91, 106, 191, 0.12);
    color: var(--accent-blue);
}

.role-vip {
    background: rgba(245, 158, 11, 0.12);
    color: #b45309;
}

.role-muted {
    background: rgba(156, 163, 175, 0.12);
    color: #9ca3af;
}

/* === Auth Modal Switcher === */
.auth-switcher {
    display: flex;
    gap: 0;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--line);
    width: 100%;
}

.auth-switch {
    flex: 1;
    background: transparent;
    color: var(--muted);
    border-radius: 0;
    padding: 10px 12px;
    font-size: 14px;
    font-weight: 500;
    position: relative;
    transition: color 0.2s ease;
}

.auth-switch:hover {
    background: transparent;
    color: var(--text);
    transform: none;
}

.auth-switch.active {
    color: var(--primary);
    background: transparent;
}

.auth-switch.active::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--primary);
    border-radius: 2px 2px 0 0;
}

.sidebar-auth-panel {
    display: block;
    margin-top: auto;
}

/* === Pendant Wallet & Coin Section === */
.pendant-wallet-section {
    display: flex;
    gap: 8px;
    padding: 0 16px 12px;
    margin-top: 4px;
}

.wallet-btn,
.shop-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 6px 10px;
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--sidebar-text);
    border: 1px solid var(--sidebar-line);
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
}

.wallet-btn:hover,
.shop-btn:hover {
    background: var(--sidebar-hover);
    color: var(--sidebar-text);
}

.wallet-btn .ui-icon,
.shop-btn .ui-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.wallet-btn .coin-number {
    font-weight: 600;
    font-size: 13px;
}

/* === Coin History Modal === */
.coin-history-modal .coin-balance-display {
    text-align: center;
    padding: 16px 0 8px;
    font-size: 14px;
    color: var(--text);
}

.coin-history-modal .coin-balance-amount {
    font-size: 28px;
    font-weight: 700;
    color: var(--primary);
    display: block;
    margin-top: 4px;
}

.coin-history-modal .coin-list {
    max-height: 320px;
    overflow-y: auto;
    margin: 12px 0;
    list-style: none;
    padding: 0;
}

.coin-history-modal .coin-list-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--line);
    font-size: 13px;
    color: var(--text);
}

.coin-history-modal .coin-list-item:last-child {
    border-bottom: none;
}

.coin-history-modal .coin-list-item .coin-desc {
    flex: 1;
    margin-right: 12px;
    word-break: break-word;
}

.coin-history-modal .coin-list-item .coin-time {
    font-size: 11px;
    color: var(--muted);
    margin-top: 2px;
}

.coin-history-modal .coin-list-item .coin-amount {
    font-weight: 600;
    white-space: nowrap;
    font-size: 14px;
}

.coin-history-modal .coin-list-item .coin-amount.positive {
    color: #16a34a;
}

.coin-history-modal .coin-list-item .coin-amount.negative {
    color: #dc2626;
}

.coin-history-modal .coin-howto {
    background: var(--sidebar-bg);
    border-radius: var(--radius-md);
    padding: 12px 14px;
    border: 1px solid var(--line);
    font-size: 13px;
    color: var(--muted);
    line-height: 1.6;
    margin-top: 8px;
}

.coin-history-modal .coin-howto strong {
    color: var(--text);
}

.coin-history-modal .coin-empty {
    text-align: center;
    padding: 24px 0;
    color: var(--muted);
    font-size: 14px;
}

.coin-history-modal .coin-history-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-height: 34px;
    margin: 4px 0 10px;
    color: var(--muted);
    font-size: 13px;
}

.coin-history-modal .coin-page-btn {
    min-height: 32px;
    padding: 6px 12px;
    font-size: 13px;
}

.coin-history-modal .coin-page-btn:disabled {
    cursor: not-allowed;
    opacity: 0.45;
}

.coin-history-modal .coin-page-info {
    min-width: 128px;
    text-align: center;
    white-space: nowrap;
}

/* === Daily Coin Reward Modal === */
.daily-coin-dialog {
    width: min(560px, calc(100vw - 32px));
    text-align: center;
}

.daily-coin-dialog h3 {
    margin: 0 0 10px;
    font-size: 22px;
}

.daily-coin-award {
    padding: 14px 18px;
    border-radius: var(--radius-lg);
    background: linear-gradient(135deg, rgba(255, 193, 7, 0.18), rgba(99, 102, 241, 0.14));
    border: 1px solid rgba(255, 193, 7, 0.34);
    color: var(--text);
    font-weight: 600;
}

.daily-coin-award strong {
    color: #f59e0b;
    font-size: 28px;
    margin: 0 4px;
}

.daily-coin-desc {
    margin: 12px 0;
    color: var(--muted);
    font-size: 13px;
}

.daily-coin-weekdays {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 6px;
    margin: 14px 0 6px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.daily-coin-calendar {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 6px;
    margin: 0 0 16px;
}

.daily-coin-day {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-height: 54px;
    padding: 8px 4px;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: #f1f5f9;
    color: #64748b;
}

.daily-coin-day.today {
    outline: 2px solid rgba(245, 158, 11, 0.48);
    outline-offset: 2px;
}

.daily-coin-day.status-checked {
    border-color: rgba(37, 99, 235, 0.5);
    background: rgba(37, 99, 235, 0.14);
    color: #1d4ed8;
}

.daily-coin-day.status-missed {
    border-color: rgba(239, 68, 68, 0.5);
    background: rgba(239, 68, 68, 0.14);
    color: #dc2626;
}

.daily-coin-day.status-pending,
.daily-coin-day.status-outside {
    border-color: rgba(100, 116, 139, 0.22);
    background: rgba(100, 116, 139, 0.12);
    color: #64748b;
}

.daily-coin-day.outside-month {
    opacity: 0.45;
}

.daily-coin-day-number {
    font-size: 15px;
    font-weight: 800;
}

.daily-coin-day small {
    font-size: 10px;
    font-weight: 700;
}

.daily-coin-summary {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin: 0 0 16px;
}

.daily-coin-summary div {
    min-height: 74px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: var(--sidebar-bg);
}

.daily-coin-summary span,
.daily-coin-summary small {
    display: block;
    color: var(--muted);
    font-size: 12px;
}

.daily-coin-summary strong {
    display: block;
    margin: 4px 0;
    color: #f59e0b;
    font-size: 22px;
}

.daily-coin-ok {
    width: 100%;
    min-height: 42px;
    border: none;
    border-radius: var(--radius-md);
    background: var(--primary);
    color: #fff;
    font-weight: 700;
    cursor: pointer;
}

.daily-coin-ok:hover {
    opacity: 0.9;
}

/* === Pendant Shop Modal === */
.modal-dialog-shop {
    max-width: min(92vw, 500px);
    max-height: 80vh;
    overflow-y: auto;
}

.pendant-shop-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
    padding: 4px 0;
}

.pendant-shop-item {
    background: var(--sidebar-bg);
    border-radius: var(--radius-lg);
    padding: 12px;
    text-align: center;
    border: 1px solid var(--line);
    transition: border-color 0.15s;
}

.pendant-shop-item:hover {
    border-color: var(--primary);
}

.pendant-shop-item .pendant-preview {
    width: 76px;
    height: 76px;
    margin: 0 auto 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    overflow: visible;
}

.pendant-shop-item .pendant-preview-avatar {
    width: 48px;
    height: 48px;
}

.pendant-shop-item .pendant-preview-avatar .avatar {
    width: 48px;
    height: 48px;
    border-width: 1px;
}

.pendant-shop-item .pendant-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 4px;
    word-break: break-word;
}

.pendant-shop-item .pendant-meta {
    font-size: 11px;
    color: var(--muted);
    margin-bottom: 8px;
}

.pendant-shop-item .pendant-reqs {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-bottom: 8px;
}

.pendant-shop-item .pendant-req-item {
    font-size: 11px;
    color: var(--muted);
    line-height: 1.5;
}

.pendant-shop-item .pendant-req-item.req-unmet {
    color: var(--danger);
    font-weight: 600;
}

.pendant-shop-item .pendant-action-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 12px;
    border-radius: var(--radius-full);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid var(--line);
    background: transparent;
    color: var(--text);
    transition: all 0.15s;
}

.pendant-shop-item .pendant-action-btn:hover {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.pendant-shop-item .pendant-action-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: transparent;
    color: var(--muted);
    border-color: var(--line);
}

.pendant-shop-item .pendant-action-btn.equipped {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
    opacity: 0.7;
}

.pendant-shop-item .pendant-owned-badge {
    font-size: 11px;
    color: var(--primary);
    font-weight: 600;
}

/* Dark mode toggle button in profile */
.theme-toggle-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    justify-content: center;
}

.profile-mute-toggle .ghost-button .ui-icon {
    width: 16px;
    height: 16px;
    margin-right: 4px;
}

.auth-modal-panel {
    display: none;
}

.auth-modal-panel.active {
    display: block;
}

/* ==========================================
   Admin Shell
   ========================================== */
.table-row.wrap {
    align-items: flex-start;
}

.admin-shell {
    grid-template-columns: 260px minmax(0, 1fr);
    gap: 0;
    padding: 0;
    height: 100vh;
    overflow: hidden;
}

.admin-sidebar {
    background: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-line);
    padding: 20px 0;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.admin-drawer {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 50;
}

.admin-drawer-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    animation: fadeIn 0.2s;
    backdrop-filter: blur(4px);
}

.admin-drawer-panel {
    position: absolute;
    inset: 0 auto 0 0;
    width: min(85vw, 300px);
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    animation: slideInLeft 0.25s ease;
    border-right: 1px solid var(--sidebar-line);
}

@keyframes slideInLeft {
    from { transform: translateX(-100%); }
    to { transform: translateX(0); }
}

.admin-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    border-bottom: 1px solid var(--sidebar-line);
}

.admin-drawer-header h3 {
    margin: 0;
    font-size: 16px;
    color: var(--text);
}

.admin-drawer .admin-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 8px;
}

.admin-drawer-toggle {
    display: none;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    margin-bottom: 12px;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
    background: var(--bg);
    border: 1px solid var(--line);
    cursor: pointer;
    transition: background 0.15s;
}

.admin-drawer-toggle:hover {
    background: var(--sidebar-hover);
}

.admin-sidebar-header {
    padding: 0 16px 16px;
    border-bottom: 1px solid var(--sidebar-line);
    margin-bottom: 8px;
}

.admin-sidebar-header h1 {
    font-size: 18px;
    margin: 4px 0 8px;
    color: var(--text);
}

.admin-sidebar-header .eyebrow {
    color: var(--sidebar-muted);
}

.admin-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 8px 8px;
}

.admin-nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-radius: var(--radius-md);
    background: none;
    border: none;
    font-size: 14px;
    color: var(--sidebar-text);
    cursor: pointer;
    transition: background .15s, color .15s;
    text-align: left;
    width: 100%;
}

.admin-nav-item:hover {
    background: var(--sidebar-hover);
    transform: none;
}

.admin-nav-item.active {
    background: var(--sidebar-active);
    color: var(--primary);
    font-weight: 600;
}

.admin-nav-icon {
    font-size: 16px;
    width: 22px;
    text-align: center;
    flex-shrink: 0;
}

.admin-content {
    padding: 24px 28px;
    overflow-y: auto;
    max-height: 100vh;
    background: var(--card);
}

.admin-panel {
    display: none;
    flex-direction: column;
    gap: 20px;
}

.admin-panel.active {
    display: flex;
}

.admin-panel-header {
    margin-bottom: 4px;
}

.admin-panel-header h2 {
    font-size: 20px;
    margin: 0 0 4px;
    font-weight: 700;
}

.admin-config-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.admin-config-item {
    padding: 10px 14px;
    background: var(--bg);
    border-radius: var(--radius-md);
    font-size: 13px;
}

.admin-config-item strong {
    display: block;
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 4px;
}

.admin-config-item code {
    font-size: 13px;
    word-break: break-all;
}

.admin-cfg-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.admin-cfg-field span {
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
}

.admin-cfg-field input,
.admin-cfg-field select {
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    padding: 10px 12px;
    font-size: 14px;
    background: #fff;
    width: 100%;
    box-sizing: border-box;
}

.admin-cfg-field input:focus,
.admin-cfg-field select:focus {
    border-color: var(--primary);
    outline: none;
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.admin-config-sections {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.admin-config-actions {
    position: sticky;
    bottom: 0;
    background: var(--card);
    padding: 14px 0;
    border-top: 1px solid var(--line);
    margin-top: 8px;
    z-index: 5;
}

.admin-save-btn {
    padding: 10px 28px;
    border-radius: var(--radius-lg);
    font-size: 14px;
    font-weight: 600;
    background: var(--primary);
    color: #fff;
    border: none;
    cursor: pointer;
    transition: background .15s;
}

.admin-save-btn:hover {
    background: var(--primary-dark);
}

.admin-form select {
    width: 100%;
    border: 1px solid var(--line);
    background: #fff;
    border-radius: var(--radius-lg);
    padding: 10px 14px;
}

.embed-code-box {
    width: 100%;
    min-height: 80px;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    padding: 12px;
    font-family: "SF Mono", "Fira Code", monospace;
    font-size: 13px;
    background: var(--bg);
    resize: vertical;
    margin-top: 12px;
    box-sizing: border-box;
}

.embed-editor-layout {
    display: grid;
    grid-template-columns: 1fr 420px;
    gap: 24px;
    margin-top: 12px;
}

.embed-editor-form {
    min-width: 0;
}

.embed-editor-preview {
    position: sticky;
    top: 20px;
    align-self: start;
}

.embed-preview-toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 8px;
}

.embed-preview-device-btns {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.embed-device-btn {
    padding: 5px 12px !important;
    font-size: 12px !important;
    border-radius: 6px !important;
    border: 1px solid var(--line) !important;
    background: var(--bg) !important;
    cursor: pointer;
    transition: all 0.15s ease;
}

.embed-device-btn.active {
    background: var(--primary) !important;
    color: #fff !important;
    border-color: var(--primary) !important;
}

.embed-preview-container {
    width: 100%;
    height: 600px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #f0f2f5;
    position: relative;
    overflow: hidden;
    margin-top: 8px;
    display: flex;
    justify-content: center;
    transition: none;
}

.embed-preview-container.mobile-preview {
    background: #e8eaed;
}

.embed-preview-container.mobile-preview #embed-preview-frame {
    width: 375px;
    height: 100%;
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
}

.embed-editor-preview.fullscreen-preview {
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: #fff;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    width: 100vw;
    height: 100vh;
}

.embed-editor-preview.fullscreen-preview .panel-title-row {
    display: none;
}

.embed-editor-preview.fullscreen-preview .embed-preview-toolbar {
    padding: 10px 16px;
    margin: 0;
    background: #fff;
    border-bottom: 1px solid var(--line);
    flex-shrink: 0;
}

.embed-editor-preview.fullscreen-preview .embed-preview-container {
    flex: 1;
    height: auto;
    border: none;
    border-radius: 0;
    margin: 0;
}

.embed-preview-close-btn {
    display: none;
    margin-left: auto;
    padding: 5px 14px !important;
    font-size: 13px !important;
    border-radius: 6px !important;
    border: 1px solid var(--line) !important;
    background: var(--bg) !important;
    cursor: pointer;
}

.embed-editor-preview.fullscreen-preview .embed-preview-close-btn {
    display: inline-flex;
}

.admin-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
}

.admin-modal.hidden { display: none; }

.admin-modal-inner {
    background: var(--card);
    border-radius: var(--radius-xl);
    padding: 24px 28px;
    width: 500px;
    max-width: 92vw;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}

.admin-modal-inner h3 {
    margin: 0 0 16px;
    font-size: 17px;
}

.room-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.ghost-button.danger {
    color: var(--danger);
}

.ghost-button.danger:hover {
    background: rgba(239, 65, 70, 0.06);
}

.role-checkbox-group {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 14px;
}

.role-checkbox-group label {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 13px;
    cursor: pointer;
}

/* === Room Password / Access === */
.room-access-denied {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 48px 20px;
    text-align: center;
}

.room-access-denied .lock-icon {
    font-size: 40px;
    margin-bottom: 4px;
}

.room-access-denied .room-access-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    margin: 0;
}

.room-access-denied .room-access-hint {
    font-size: 13px;
    color: var(--muted);
    margin: 0;
}

.room-access-denied .room-access-form {
    display: flex;
    gap: 8px;
    margin-top: 4px;
}

.room-access-denied .room-access-form input {
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    padding: 10px 14px;
    font-size: 14px;
    transition: border-color 0.15s;
}

.room-access-denied .room-access-form input:focus {
    border-color: var(--primary);
    outline: none;
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.room-access-denied .room-access-form button {
    padding: 10px 20px;
    border-radius: var(--radius-md);
    background: var(--primary);
    color: #fff;
    font-size: 14px;
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: background 0.15s;
}

.room-access-denied .room-access-form button:hover {
    opacity: 0.9;
}

/* ==========================================
   Chat Footer & Input Area
   (Simplified per wireframe: +button | textarea | ↑send)
   ========================================== */
.chat-footer {
    padding: 12px 20px calc(16px + env(safe-area-inset-bottom, 0px));
    background: var(--card);
    border-top: 1px solid var(--line);
    flex-shrink: 0;
}

.message-form {
    display: flex;
    flex-direction: column;
    gap: 8px;
    position: relative;
}

.message-toolbar {
    display: flex;
    gap: 6px;
    position: relative;
    order: 1;
}

.message-tool-button {
    padding: 8px 12px;
    border-radius: var(--radius-md);
    font-size: 13px;
}

.message-tool-button:hover {
    transform: none;
}

.red-packet-tool-button {
    color: #c2410c;
    background: linear-gradient(135deg, #fff7ed, #ffedd5);
}

.red-packet-card {
    width: 300px;
    display: flex;
    align-items: stretch;
    gap: 0;
    padding: 0;
    border: none;
    border-radius: 14px;
    overflow: hidden;
    background: linear-gradient(135deg, #f97316 0%, #dc2626 58%, #991b1b 100%);
    box-shadow: 0 12px 26px rgba(185, 28, 28, 0.22);
    color: #fff7ed;
    text-align: left;
    cursor: pointer;
    pointer-events: auto;
    -webkit-user-select: none;
    user-select: none;
}

.red-packet-card,
.red-packet-card * {
    cursor: pointer !important;
}

.red-packet-card:hover {
    transform: translateY(-1px);
}

.red-packet-card.red-packet-expired {
    cursor: not-allowed;
    opacity: 0.7;
}

.red-packet-card.red-packet-expired:hover {
    transform: none;
}

.red-packet-cover {
    width: 86px;
    min-height: 116px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at 50% 32%, #facc15 0 18px, transparent 19px), rgba(127, 29, 29, 0.32);
    position: relative;
}

.red-packet-cover::after {
    content: '';
    position: absolute;
    inset: auto 12px 12px;
    height: 28px;
    border-radius: 999px 999px 0 0;
    border-top: 1px solid rgba(254, 215, 170, 0.45);
}

.red-packet-seal {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #fde68a, #f59e0b);
    color: #7f1d1d;
    font-weight: 800;
    box-shadow: inset 0 1px 0 rgba(255,255,255,.55), 0 5px 14px rgba(120, 53, 15, .28);
}

.red-packet-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding: 16px 16px 14px;
}

.red-packet-info strong {
    font-size: 16px;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.red-packet-info em,
.red-packet-info small,
.red-packet-password-hint,
.red-packet-status-hint {
    font-style: normal;
    color: rgba(255, 247, 237, 0.82);
    font-size: 12px;
}

.red-packet-progress {
    height: 5px;
    margin-top: 4px;
    border-radius: 999px;
    background: rgba(255, 247, 237, 0.25);
    overflow: hidden;
}

.red-packet-progress i {
    display: block;
    height: 100%;
    background: linear-gradient(90deg, #fde68a, #facc15);
}

.red-packet-compose-head {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
}

.red-packet-compose-dialog {
    background: var(--card);
    color: var(--text);
    border: 1px solid var(--line);
}

.red-packet-compose-icon {
    width: 46px;
    height: 46px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 16px;
    background: var(--primary-glow);
    color: var(--primary);
    font-size: 24px;
}

.red-packet-compose-dialog label {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.red-packet-compose-dialog label > span {
    color: var(--muted);
    font-size: 13px;
}

#red-packet-mode,
.red-packet-compose-dialog select {
    flex: 1;
    width: 100%;
    min-width: 0;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    font-size: 14px;
    background: var(--bg);
    color: var(--text);
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

#red-packet-mode:focus,
.red-packet-compose-dialog select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
    background: #fff;
}

#red-packet-lucky-row,
#red-packet-password-row {
    margin-top: 0;
}

#red-packet-exclusive-row {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

#red-packet-exclusive-row.hidden {
    display: none;
}

#red-packet-user-search {
    width: 100%;
}

.red-packet-user-results {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: var(--card);
}

.red-packet-user-results.hidden {
    display: none;
}

.red-packet-user-result-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    cursor: pointer;
    border: none;
    background: transparent;
    text-align: left;
    width: 100%;
    font-size: 13px;
    color: var(--text);
    transition: background 0.12s;
}

.red-packet-user-result-item:hover {
    background: var(--sidebar-hover);
}

.red-packet-user-result-item .avatar {
    width: 28px;
    height: 28px;
}

.red-packet-selected-users {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    min-height: 0;
}

.red-packet-selected-user {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px 4px 6px;
    border-radius: var(--radius-full);
    background: var(--sidebar-hover);
    border: 1px solid var(--line);
    font-size: 12px;
    color: var(--text);
}

.red-packet-selected-user .avatar {
    width: 22px;
    height: 22px;
}

.red-packet-selected-user .remove-user {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--muted);
    color: #fff;
    font-size: 10px;
    line-height: 1;
    border: none;
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.red-packet-submit,
.red-packet-open-action {
    background: var(--primary);
}

.red-packet-open-dialog {
    background: transparent;
    box-shadow: none;
    border: none;
    padding: 55px 30px !important;
}

.red-packet-open-shell {
    border-radius: 24px;
    overflow: hidden;
    background: linear-gradient(180deg, #dc2626, #991b1b);
    color: #fff7ed;
    box-shadow: 0 26px 70px rgba(127, 29, 29, 0.42);
}

.red-packet-open-top {
    height: 92px;
    background: radial-gradient(circle at 50% -30px, #fca5a5 0 82px, transparent 83px), linear-gradient(135deg, #ef4444, #b91c1c);
    border-bottom-left-radius: 50% 34px;
    border-bottom-right-radius: 50% 34px;
}

.red-packet-open-body {
    padding: 18px 24px 26px;
    text-align: center;
}

.red-packet-open-icon {
    font-size: 42px;
}

.red-packet-open-body h3 {
    margin-top: 6px;
    font-size: 20px;
}

.red-packet-open-body p {
    margin-top: 6px;
    color: rgba(255, 247, 237, 0.8);
}

.red-packet-open-action {
    width: 74px;
    height: 74px;
    margin: 22px auto 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #fde68a, #f59e0b);
    color: #7f1d1d;
    font-size: 24px;
    font-weight: 900;
    box-shadow: 0 8px 20px rgba(120, 53, 15, 0.35);
}

.red-packet-open-action.opening {
    animation: red-packet-open-spin .78s ease-in-out infinite;
}

.red-packet-open-action.opened {
    transform: scale(.9);
    opacity: .65;
}

@keyframes red-packet-open-spin {
    0% { transform: rotateY(0deg) scale(1); }
    50% { transform: rotateY(180deg) scale(1.12); }
    100% { transform: rotateY(360deg) scale(1); }
}

.red-packet-open-result {
    margin-top: 12px;
    padding: 14px;
    border-radius: 16px;
    background: rgba(255, 247, 237, 0.12);
    border: 1px solid rgba(255, 247, 237, 0.18);
}

.red-packet-open-result strong {
    display: block;
    margin-bottom: 6px;
    color: #fde68a;
}

.red-packet-open-result .red-packet-success-head {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

.red-packet-open-result .red-packet-success-head strong {
    margin-bottom: 0;
    flex: 1;
}

.red-packet-copy-btn {
    padding: 3px 10px;
    border: 1px solid rgba(253, 232, 138, 0.4);
    border-radius: 8px;
    background: rgba(253, 232, 138, 0.1);
    color: #fde68a;
    font-size: 12px;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s;
    position: absolute;
    right: 68px;
}

.red-packet-copy-btn:hover {
    background: rgba(253, 232, 138, 0.22);
}

.red-packet-copy-btn:active {
    background: rgba(253, 232, 138, 0.3);
}

.red-packet-copy-btn.copied {
    color: #86efac;
    border-color: rgba(134, 239, 172, 0.5);
    background: rgba(134, 239, 172, 0.12);
}

.red-packet-open-result p {
    white-space: pre-wrap;
    word-break: break-word;
    color: #fff7ed;
}

.red-packet-open-result.missed strong {
    color: #fecaca;
}

.red-packet-claims {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid rgba(255, 247, 237, 0.18);
    display: flex;
    flex-direction: column;
    gap: 6px;
    text-align: left;
    font-size: 13px;
}

.red-packet-claims strong {
    color: #fde68a;
}

.red-packet-claims span {
    display: flex;
    justify-content: space-between;
    gap: 10px;
}

.red-packet-claims em {
    font-style: normal;
    color: rgba(255, 247, 237, 0.72);
}

.voice-overlay {
    position: absolute;
    inset: 0;
    background: var(--card, #f5f5f5);
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
}

.voice-overlay.hidden {
    display: none;
}

.voice-overlay-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.voice-timer {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    font-variant-numeric: tabular-nums;
    letter-spacing: 1px;
}

.voice-mic-icon {
    width: 54px;
    height: 54px;
    border-radius: 50%;
    background: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: #fff;
    box-shadow: 0 0 0 0 var(--primary-glow);
    transition: box-shadow 0.3s;
    cursor: pointer;
}

.voice-mic-icon.recording {
    animation: voice-pulse 1.2s infinite;
}

@keyframes voice-pulse {
    0% { box-shadow: 0 0 0 0 var(--primary-glow); }
    70% { box-shadow: 0 0 0 16px transparent; }
    100% { box-shadow: 0 0 0 0 transparent; }
}

.voice-hint {
    font-size: 13px;
    color: var(--text-secondary, #888);
    margin: 0;
}

.voice-hint a {
    color: var(--primary);
    text-decoration: none;
    cursor: pointer;
}

.voice-hint a:hover {
    text-decoration: underline;
}

.voice-message {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    border-radius: var(--radius-lg);
    background: var(--primary-glow);
    min-width: 120px;
    max-width: 220px;
    cursor: default;
    user-select: none;
}

.voice-play-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--primary) !important;
    color: #fff !important;
    border: none;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0 !important;
    flex-shrink: 0;
    line-height: 1;
}

.voice-play-btn:hover {
    background: var(--primary-dark) !important;
    transform: none;
}

.voice-play-btn.playing {
    animation: voice-pulse 1.2s infinite;
}

.voice-wave {
    flex: 1;
    height: 18px;
    background: repeating-linear-gradient(
        90deg,
        var(--primary) 0px,
        var(--primary) 2px,
        transparent 2px,
        transparent 5px
    );
    border-radius: 2px;
    opacity: 0.5;
}

.voice-duration {
    font-size: 12px;
    color: var(--muted);
    white-space: nowrap;
    min-width: 24px;
    text-align: right;
}

.emoji-panel {
    display: flex;
    flex-direction: column;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: var(--card);
    box-shadow: var(--shadow-md);
    order: 2;
    max-height: 320px;
    overflow: hidden;
}

.emoji-panel-tabs {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--line);
    flex-shrink: 0;
    width: 100%;
}

.emoji-tab {
    flex: 1;
    background: transparent;
    color: var(--muted);
    border: none;
    border-radius: 0;
    padding: 10px 12px;
    font-size: 14px;
    font-weight: 500;
    position: relative;
    cursor: pointer;
    transition: color 0.2s ease;
}

.emoji-tab:hover {
    background: transparent;
    color: var(--text);
    transform: none;
}

.emoji-tab.active {
    color: var(--primary);
    background: transparent;
}

.emoji-tab.active::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--primary);
    border-radius: 2px 2px 0 0;
}

.emoji-tab-content {
    display: none;
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.emoji-tab-content.active {
    display: flex;
    flex-direction: column;
}

.emoji-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(42px, 1fr));
    gap: 6px;
    padding: 10px;
}

.emoji-item {
    height: 42px;
    border-radius: var(--radius-md);
    background: var(--bg);
    font-size: 22px;
    line-height: 1;
    padding: 0;
}

.emoji-item:hover {
    background: var(--primary-glow);
}

.sticker-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
    gap: 6px;
    padding: 10px;
    flex: 1;
    overflow-y: auto;
}

.sticker-grid-item {
    position: relative;
    aspect-ratio: 1;
    border-radius: var(--radius-md);
    overflow: hidden;
    cursor: pointer;
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
    height: 64px;
}

.sticker-grid-item:hover {
    background: var(--primary-glow);
}

.sticker-grid-item img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.sticker-grid-item .sticker-delete {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.5);
    color: #fff;
    font-size: 11px;
    line-height: 1;
    border: none;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.sticker-grid-item .sticker-delete {
    display: flex;
}

.sticker-upload-area {
    padding: 8px 10px;
    border-top: 1px solid var(--line);
    flex-shrink: 0;
}

.sticker-upload-button {
    width: 100%;
    padding: 8px;
    border-radius: var(--radius-md);
    background: var(--bg);
    border: 1px dashed var(--line);
    color: var(--muted);
    font-size: 13px;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
}

.sticker-upload-button:hover {
    color: var(--primary);
    border-color: var(--primary);
}

.sticker-grid-empty {
    padding: 20px 10px;
    text-align: center;
    color: var(--muted);
    font-size: 13px;
}

.sticker-login-hint {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 30px 10px;
    text-align: center;
}

.sticker-login-hint p {
    margin: 0;
    color: var(--muted);
    font-size: 13px;
}

.sticker-login-button {
    padding: 6px 20px;
    border-radius: var(--radius-md);
    background: var(--primary);
    color: #fff;
    font-size: 13px;
    border: none;
    cursor: pointer;
}

.sticker-login-button:hover {
    opacity: 0.9;
}

.chat-sticker {
    max-width: 120px;
    max-height: 120px;
    vertical-align: middle;
    border-radius: var(--radius-md);
}

.message-image-preview {
    order: 3;
    display: flex;
    flex-direction: row;
    gap: 8px;
    flex-wrap: wrap;
    padding: 8px 0;
}

.mention-dropdown {
    position: absolute;
    bottom: 100%;
    left: 0;
    width: fit-content;
    min-width: 200px;
    max-height: 260px;
    overflow-y: auto;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    box-shadow: 0 -4px 16px rgba(0,0,0,0.10);
    z-index: 100;
    margin-bottom: 4px;
}
.mention-dropdown.hidden { display: none; }
.mention-dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 14px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text);
    border: none;
    background: transparent;
    width: 100%;
    text-align: left;
}
.mention-dropdown-item:hover,
.mention-dropdown-item.active {
    background: var(--hover);
}
.mention-dropdown-item .avatar {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
}
.mention-dropdown-item strong {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.mention-dropdown-sep {
    height: 1px;
    background: var(--line);
    margin: 0;
}

.message-input-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    order: 4;
}

.message-input-row textarea {
    flex: 1;
    min-height: 44px;
    max-height: 120px;
    resize: none;
    border-radius: 22px;
    padding: 10px 16px;
    font-size: 14px;
    line-height: 1.5;
    background: var(--bg);
    border: 1px solid var(--line);
}

.message-input-row textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.message-input-row button[type="submit"] {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 18px;
    background: var(--primary);
    color: #fff;
}

.message-input-row button[type="submit"]:hover {
    background: var(--primary-dark);
    transform: scale(1.05);
}

.message-input-row button[type="submit"]:disabled {
    background: #d1d5db;
    transform: none;
}

/* === Image Preview === */
.message-image-preview-card {
    position: relative;
    width: 100px;
    flex-shrink: 0;
    border-radius: var(--radius-lg);
    overflow: hidden;
    border: 1px solid var(--line);
    background: #fff;
    box-shadow: var(--shadow-sm);
}

.message-image-preview-card > img {
    display: block;
    width: 100%;
    height: 80px;
    object-fit: cover;
}

.message-sticker-preview-card {
    background: var(--card);
}

.message-sticker-preview-card > img {
    object-fit: contain;
    padding: 8px;
}

.message-image-remove {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 28px;
    height: 28px;
    border-radius: var(--radius-full);
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    font-size: 18px;
    line-height: 1;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.message-image-remove .ui-icon {
    width: 14px;
    height: 14px;
}

/* === Message Content & Actions === */
.message-actions {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: 4px;
    justify-content: flex-start;
    margin-top: 4px;
    padding: 0 2px;
}

.message-item-own .message-actions {
    align-items: flex-end;
    justify-content: flex-end;
}

.message-recall-button,
.message-move-button {
    padding: 3px 8px;
    font-size: 11px;
    line-height: 1;
    border-radius: var(--radius-full);
    background: rgba(142, 142, 160, 0.08);
    color: var(--muted);
}

.message-recall-button:hover {
    background: rgba(239, 65, 70, 0.1);
    color: var(--danger);
    transform: none;
}

.message-move-button:hover {
    background: rgba(79, 70, 229, 0.1);
    color: var(--primary);
    transform: none;
}

.message-recalled {
    color: var(--muted);
    font-style: normal;
}

.welcome-hint {
    text-align: center;
    font-size: 12px;
    color: #999;
    padding: 4px 0;
    line-height: 1.6;
    opacity: 1;
}

.message-item-own .message-content {
    text-align: right;
}

/* === Quote / Target Preview Bars (above textarea) === */
.quote-preview,
.target-preview {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: #f0f0f0;
    border-radius: var(--radius-md);
    border-left: 3px solid var(--primary);
    order: 3;
    width: fit-content;
    max-width: 80vw;
}

.target-preview {
    border-left-color: var(--accent-blue);
}

.target-preview.target-preview-private {
    border-left-color: var(--danger);
}

.quote-preview.hidden,
.target-preview.hidden {
    display: none;
}

.quote-preview-body,
.target-preview-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.quote-preview-name,
.target-preview-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--primary);
}

.target-preview-private .target-preview-label {
    color: var(--danger);
}

.quote-preview-text,
.target-preview-name {
    font-size: 12px;
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.quote-preview-close,
.target-preview-close {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--muted);
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    padding: 0;
}

.quote-preview-close:hover,
.target-preview-close:hover {
    background: rgba(0, 0, 0, 0.06);
    color: var(--text);
    transform: none;
}

/* === Quote Block (rendered inside message bubble) === */
.message-quote-block {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 8px 10px;
    margin-bottom: 6px;
    background: rgba(0, 0, 0, 0.04);
    border-left: 3px solid #c0c0c0;
    border-radius: 4px;
    text-align: left;
    position: relative;
    min-width: 110px;
}

.message-quote-name {
    font-size: 12px;
    font-weight: 600;
    color: var(--primary);
}

.message-quote-text {
    font-size: 13px;
    color: var(--muted);
    word-break: break-word;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.message-quote-jump {
    position: absolute;
    top: 6px;
    right: 8px;
    width: 22px;
    height: 22px;
    padding: 0;
    border: none;
    border-radius: var(--radius-full);
    background: transparent;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
    line-height: 20px;
    cursor: pointer;
    box-shadow: none;
    transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease;
}

.message-quote-jump:hover {
    background: transparent;
    color: var(--text);
    transform: none;
}

/* === Inline Images === */
.chat-inline-image {
    display: block;
    max-width: min(100%, 260px);
    max-height: 220px;
    margin-top: 6px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--line);
    object-fit: cover;
}

.message-item-own .chat-inline-image {
    margin-left: auto;
}

/* ==========================================
   Toast
   ========================================== */
.toast {
    position: fixed;
    left: 50%;
    top: 16px;
    transform: translateX(-50%) translateY(-120px);
    background: #343541;
    color: #fff;
    padding: 10px 20px;
    border-radius: var(--radius-full);
    font-size: 14px;
    opacity: 0;
    transition: 0.25s ease;
    z-index: 999;
    box-shadow: var(--shadow-md);
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ==========================================
   Modals
   ========================================== */
.modal {
    position: fixed;
    inset: 0;
    z-index: 40;
}

.modal.hidden { display: none; }

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
}

.modal-dialog {
    position: relative;
    z-index: 1;
    max-width: min(92vw, 420px);
    margin: 10vh auto 0;
    background: var(--card);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    padding: 42px 23px;
}

.modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    background: var(--bg);
    color: var(--muted);
    padding: 0;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-close:hover {
    background: var(--line);
    color: var(--text);
    transform: none;
}

/* ==========================================
   Online Sidebar (right)
   ========================================== */
.online-sidebar {
    padding: 16px;
    background: var(--card);
    border-left: 1px solid var(--line);
    height: 100vh;
    height: var(--app-viewport-height);
    position: sticky;
    top: 0;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
}

.online-sidebar .panel {
    border: none;
    border-bottom: none;
    background: transparent;
    padding: 0;
}

.online-sidebar .panel h2 {
    color: var(--text);
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.online-sidebar .panel-title-row {
    justify-content: flex-start;
    gap: 8px;
}

.online-sidebar .panel-title-row span {
    color: var(--muted);
}

.online-sidebar.hidden-sidebar {
    display: none;
}

.online-drawer-header {
    display: none;
}

.online-drawer-backdrop {
    display: none;
}

.online-sidebar .panel:first-child {
    flex: 3;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.online-sidebar .offline-section {
    flex: 2;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.online-sidebar .table-list {
    height: auto;
    flex: none;
}

#all-users {
    /* no inline max-height — sidebar itself scrolls */
}

.load-more-users {
    display: block;
    width: 100%;
    padding: 10px;
    margin-top: 8px;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--muted);
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.load-more-users:hover {
    background: var(--sidebar-hover);
    color: var(--text);
}

.load-more-users.hidden {
    display: none;
}

/* ==========================================
   Responsive Breakpoints
   ========================================== */
@media (max-width: 960px) {
    .app-shell {
        grid-template-columns: 1fr;
        padding: 0;
        overflow-y: hidden;
    }

    .app-shell-chat {
        grid-template-columns: 1fr;
    }

    .desktop-sidebar {
        display: none;
    }

    .online-sidebar {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        padding: 0!important;
        width: 280px;
        max-width: 80vw;
        z-index: 1100;
        transform: translateX(100%);
        transition: transform .25s ease;
        border-left: 1px solid var(--line);
        border-radius: 0;
        height: 100vh;
        height: var(--app-viewport-height);
        overflow-y: auto;
        overflow-x: hidden;
        display: flex;
        flex-direction: column;
    }

    .online-sidebar.mobile-open {
        transform: translateX(0);
    }

    .online-sidebar.hidden-sidebar {
        display: flex;
        transform: translateX(100%);
    }

    .online-drawer-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 14px 16px;
        border-bottom: 1px solid var(--line);
        flex-shrink: 0;
    }

    .online-sidebar .panel,
    .online-sidebar .offline-section {
        padding: 0 12px;
    }

    .online-sidebar .offline-title-row {
        padding: 4px 0;
    }

    .online-drawer-header h3 {
        margin: 0;
        font-size: 16px;
    }

    .online-drawer-close {
        background: none;
        border: none;
        font-size: 18px;
        cursor: pointer;
        color: var(--muted);
        padding: 2px;
        border-radius: var(--radius-full);
        background: var(--sidebar-hover);
        width: 30px;
        height: 30px;
    }

    .online-drawer-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.4);
        z-index: 1099;
    }

    .online-drawer-backdrop.hidden {
        display: none;
    }

    .mobile-only {
        display: flex;
    }

    .mobile-drawer.hidden {
        display: none;
    }

    .mobile-drawer:not(.hidden) {
        display: block;
    }


    .chat-card {
        height: 100%;
        min-height: 0;
    }

    .chat-header {
        padding: 12px 16px;
    }

    .chat-header-more {
        display: flex;
    }

    .mention-alert {
        margin-left: auto;
    }

    .tips-box {
        display: none;
        position: absolute;
        top: 100%;
        right: 12px;
        flex-direction: column;
        align-items: stretch;
        background: var(--card);
        border: 1px solid var(--line);
        border-radius: var(--radius-md);
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
        padding: 8px 0;
        z-index: 200;
        min-width: 100px;
    }

    .tips-box.mobile-open {
        display: flex;
        align-items: center;
    }

    .tips-box > * {
        padding: 8px 16px;
        white-space: nowrap;
        width: fit-content;
        border-radius: var(--radius-full);
    }

    .message-list {
        min-height: 0;
        padding: 12px 12px;
    }

    .chat-footer {
        padding: 10px 12px calc(12px + env(safe-area-inset-bottom, 0px));
    }

    .admin-shell {
        grid-template-columns: 1fr;
    }

    .admin-sidebar {
        display: none;
    }

    .admin-drawer-toggle {
        display: flex;
    }

    .admin-drawer.hidden {
        display: none;
    }

    .admin-drawer:not(.hidden) {
        display: block;
    }

    .admin-content {
        padding: 16px 14px;
        max-height: none;
    }

    .admin-config-grid {
        grid-template-columns: 1fr;
    }

    .embed-editor-layout {
        grid-template-columns: 1fr;
    }

    .embed-preview-container {
        height: 400px;
    }

    .table-row {
        align-items: stretch;
    }

    .admin-user-info {
        min-width: 0;
        overflow: hidden;
    }

    .admin-user-info > div {
        min-width: 0;
        overflow: hidden;
    }

    .admin-user-forms {
        align-items: stretch;
    }

    .inline-role-form {
        width: 100%;
        justify-content: space-between;
    }

    .online-sidebar .online-user-row {
        display: flex;
        align-items: center;
        width: 100%;
    }

    .online-sidebar .online-user-main {
        min-width: 0;
        flex: 1;
    }

    .online-sidebar .online-user-meta {
        width: auto;
        flex-shrink: 0;
    }

    .online-sidebar .online-user-name {
        max-width: 100px;
    }

    .online-sidebar #all-users {
        max-height: none;
    }

    #online-sidebar-toggle {
        display: inline-flex;
    }
    .online-sidebar .panel:first-of-type > .panel-title-row {
        display: none;
    }

    .modal {
        z-index: 40;
        overflow: hidden;
    }

    .modal-backdrop {
        display: none;
    }

    .modal-dialog,
    .modal-dialog-sm,
    .modal-dialog-profile,
    .red-packet-compose-dialog,
    .red-packet-open-dialog {
        width: 100vw;
        max-width: 100vw;
        height: 100vh;
        height: var(--app-viewport-height);
        margin: 0;
        border-radius: 0;
        padding: calc(48px + env(safe-area-inset-top, 0px)) 16px calc(18px + env(safe-area-inset-bottom, 0px));
        overflow-y: auto;
        overscroll-behavior: contain;
        box-shadow: none;
    }

    .modal-close {
        top: calc(10px + env(safe-area-inset-top, 0px));
        right: 12px;
        z-index: 3;
    }

    .modal-dialog-profile {
        padding-left: 0;
        padding-right: 0;
    }

    .modal-dialog-profile .profile-card {
        border-radius: 0;
    }

    .red-packet-open-dialog {
        display: flex;
        align-items: stretch;
        justify-content: center;
        background: linear-gradient(180deg, #dc2626, #991b1b);
        padding: calc(52px + env(safe-area-inset-top, 0px)) 18px calc(18px + env(safe-area-inset-bottom, 0px)) !important;
    }

    .red-packet-open-shell {
        width: 100%;
        min-height: 100%;
        border-radius: 24px 24px 0 0;
    }

    .red-packet-open-body {
        min-height: calc(var(--app-viewport-height) - 180px);
    }
}

@media (min-width: 961px) {
    .mobile-drawer,
    .drawer-toggle.mobile-only,
    .admin-drawer,
    .admin-drawer-toggle {
        display: none !important;
    }
}

@media (max-width: 640px) {
    .sidebar-card,
    .chat-card {
        border-radius: 0;
        padding: 0;
    }

    .mobile-drawer-panel {
        width: 100vw;
        padding: 0;
    }

    .message-form {
        grid-template-columns: 1fr;
    }

    .message-meta {
        flex-wrap: wrap;
    }

    .message-list {
        min-height: 0;
        padding: 10px 8px;
    }

    .message-bubble-wrap {
        max-width: calc(100% - 50px);
    }

    .message-toolbar {
        flex-wrap: wrap;
    }

    .status-dot {
        align-self: flex-start;
    }
}

/* ==========================================
   Announcement Banner
   ========================================== */
.announcement-banner {
    display: flex;
    width: 100%;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    background: var(--primary);
    color: #fff;
    margin: 0;
    border-radius: 0;
    position: relative;
    overflow: hidden;
    flex-shrink: 0;
}

.announcement-banner.hidden { display: none; }

.announcement-banner-inner {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
}

.announcement-icon {
    flex-shrink: 0;
    font-size: 1em;
}

.announcement-text {
    flex: 1;
    font-size: 13px;
    line-height: 1.4;
    overflow: hidden;
    min-width: 0;
    transition: opacity 0.3s ease;
}

.announcement-text-content {
    display: inline-block;
    white-space: nowrap;
}

.announcement-text.announcement-fade-out { opacity: 0; }
.announcement-text.announcement-fade-in { opacity: 1; }

@media (max-width: 960px) {
    .announcement-text.announcement-overflow .announcement-text-content {
        animation: announcement-scroll var(--scroll-duration, 5s) linear infinite;
    }

    @keyframes announcement-scroll {
        0%, 10% { transform: translateX(0); }
        90%, 100% { transform: translateX(var(--scroll-distance, -50%)); }
    }
}

.announcement-close {
    flex-shrink: 0;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: #fff;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    cursor: pointer;
    line-height: 1;
    padding: 0;
    transition: background 0.2s;
}

.announcement-close:hover {
    background: rgba(255, 255, 255, 0.35);
    transform: none;
}

/* === Admin Cell === */
.admin-cell-content {
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ==========================================
   Context Menu
   ========================================== */
.user-context-menu {
    position: fixed;
    z-index: 200;
    background: var(--card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 4px 0;
    min-width: 160px;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--line);
}

.user-context-menu.hidden { display: none; }

.context-menu-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    font-size: 13px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text);
    text-align: left;
    white-space: nowrap;
    transition: background 0.15s;
    border-radius: 0;
}

.context-menu-item:hover {
    background: var(--bg);
    transform: none;
}

.admin-action-buttons {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 8px;
}

.admin-action-buttons button {
    min-width: 64px;
}

#admin-action-modal h3 {
    margin: 0 0 8px;
    font-size: 16px;
}

.context-menu-sep {
    height: 1px;
    background: var(--line);
    margin: 4px 0;
}

.context-menu-item.context-menu-mute {
    color: var(--danger);
}

.context-menu-item.context-menu-mute:hover {
    background: rgba(239, 65, 70, 0.06);
}

/* ==========================================
   Guest Remaining Hint
   ========================================== */
.guest-remaining-hint {
    margin: 6px 0 0;
    font-size: 12px;
    color: var(--muted);
    text-align: center;
}

.guest-remaining-hint a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
}

.guest-remaining-hint a:hover {
    text-decoration: underline;
}

/* ==========================================
   Smooth Transitions (prefers-reduced-motion)
   ========================================== */
/* === Admin Table === */
.admin-table-wrap {
    overflow-x: auto;
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.admin-table th,
.admin-table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}

.admin-table th {
    background: var(--bg);
    font-weight: 600;
    font-size: 12px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.admin-table td:last-child {
    white-space: normal;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.security-log-filters {
    display: flex;
    align-items: center;
    gap: 8px;
}

.security-log-search-input {
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    padding: 6px 10px;
    font-size: 13px;
    min-width: 160px;
}

.security-log-search-input:focus {
    border-color: var(--primary);
    outline: none;
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.security-log-filters select {
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    padding: 6px 10px;
    font-size: 13px;
    background: #fff;
}

.security-log-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-top: 12px;
    font-size: 13px;
}

.security-log-goto-input {
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    padding: 6px 8px;
    font-size: 13px;
    width: 64px;
    text-align: center;
}

.security-log-goto-input:focus {
    border-color: var(--primary);
    outline: none;
    box-shadow: 0 0 0 3px var(--primary-glow);
}

/* === Chat Link === */
.chat-link {
    color: #1a73e8;
    text-decoration: underline;
    word-break: break-all;
    cursor: pointer;
}

.chat-link:hover {
    color: #1558b0;
}

.chat-link-badge {
    display: inline-block;
    padding: 1px 6px;
    margin-right: 4px;
    border-radius: 14px;
    background: #e5e7eb;
    color: #6b7280;
    font-size: 11px;
    line-height: 1.4;
    vertical-align: middle;
    user-select: none;
}

.chat-link-badge-video {
    background: #ede9fe;
    color: #7c3aed;
}

/* === Link Preview Overlay === */
.link-preview-overlay {
    position: fixed;
    inset: 0;
    z-index: 100000;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: linkPreviewFadeIn 0.2s ease;
}

@keyframes linkPreviewFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.link-preview-container {
    background: #fff;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 420px;
    overflow: hidden;
    animation: linkPreviewSlideIn 0.25s ease;
}

@keyframes linkPreviewSlideIn {
    from { transform: translateY(20px) scale(0.96); opacity: 0; }
    to { transform: translateY(0) scale(1); opacity: 1; }
}

.link-preview-header {
    padding: 28px 24px 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 10px;
}

.link-preview-warning {
    font-size: 18px;
    font-weight: 700;
    color: #d97706;
}

.link-preview-url {
    font-size: 13px;
    color: var(--muted);
    word-break: break-all;
    line-height: 1.5;
}

.link-preview-footer {
    padding: 16px 24px 24px;
    display: flex;
    justify-content: center;
    gap: 12px;
}

.link-preview-btn {
    padding: 8px 18px;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: background 0.15s ease, transform 0.1s ease;
}

.link-preview-btn:active {
    transform: scale(0.97);
}

.link-preview-btn-close {
    background: #f1f1f1;
    color: #333;
}

.link-preview-btn-close:hover {
    background: #e4e4e4;
}

.link-preview-btn-open {
    background: var(--primary);
    color: #fff;
}

.link-preview-btn-open:hover {
    background: var(--primary-dark);
}

@media (max-width: 640px) {
    .link-preview-overlay {
        padding: 10px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}
