* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --bg: #eef2f8;
  --surface: #f8fafc;
  --white: #ffffff;
  --primary: #2563eb;
  --primary-hover: #3b82f6;
  --primary-light: #eff6ff;
  --primary-glow: rgba(37,99,235,.12);
  --accent: #06b6d4;
  --accent-light: #ecfeff;
  --text: #0f172a;
  --text-secondary: #64748b;
  --text-light: #94a3b8;
  --shadow-dark: #c8d0dd;
  --shadow-light: #ffffff;
  --shadow-raised: 12px 12px 24px var(--shadow-dark), -12px -12px 24px var(--shadow-light);
  --shadow-pressed: inset 6px 6px 12px var(--shadow-dark), inset -6px -6px 12px var(--shadow-light);
  --shadow-soft: 6px 6px 14px var(--shadow-dark), -6px -6px 14px var(--shadow-light);
  --shadow-sm: 4px 4px 8px var(--shadow-dark), -4px -4px 8px var(--shadow-light);
  --shadow-lg: 16px 16px 32px var(--shadow-dark), -16px -16px 32px var(--shadow-light);
  --shadow-inset-sm: inset 4px 4px 8px var(--shadow-dark), inset -4px -4px 8px var(--shadow-light);
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --sidebar-w: 230px;
  --header-h: 62px;
  --font: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"PingFang SC","Microsoft YaHei","Helvetica Neue",sans-serif;
}
html, body { height: 100%; font-family: var(--font); background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.6; overflow: hidden; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }

::selection { background: var(--primary); color: var(--white); }
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #c8d0dd; border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: var(--primary); }
.sidebar-inner::-webkit-scrollbar { width: 3px; }
.sidebar-inner::-webkit-scrollbar-thumb { background: #dce4f0; }
.sidebar-inner::-webkit-scrollbar-thumb:hover { background: var(--primary); }

/* ============ LOGIN ============ */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; background: var(--bg); }
.login-container { width: 100%; max-width: 400px; }
.login-box { background: var(--white); border-radius: var(--radius-xl); padding: 44px 36px 34px; box-shadow: var(--shadow-lg); position: relative; overflow: hidden; }
.login-box::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px; background: linear-gradient(90deg, var(--primary), var(--accent)); z-index: 1; }
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo-icon { width: 56px; height: 56px; border-radius: 16px; background: linear-gradient(135deg, var(--primary), var(--accent)); display: inline-flex; align-items: center; justify-content: center; color: var(--white); margin-bottom: 14px; box-shadow: var(--shadow-soft); overflow: hidden; }
.login-logo-icon:has(img) { background: none; }
.login-logo-icon img { width: 100%; height: 100%; object-fit: contain; display: block; }
.login-logo h1 { font-size: 24px; font-weight: 700; color: var(--text); }
.login-subtitle { font-size: 14px; color: var(--text-secondary); margin-top: 4px; }
.login-form { transition: opacity .3s; }
.form-tip { font-size: 13px; color: var(--text-secondary); margin-bottom: 14px; text-align: center; }
.login-footer { text-align: center; margin-top: 18px; }
.login-footer a { color: var(--primary); font-size: 13px; text-decoration: none; font-weight: 500; display: inline-flex; align-items: center; gap: 4px; }
.login-footer a:hover { opacity: .8; }
.login-footer-text { text-align: center; margin-top: 20px; font-size: 12px; color: var(--text-light); }

.form-input { width: 100%; padding: 12px 18px; border: none; border-radius: var(--radius); font-size: 14px; outline: none; transition: all .25s; background: var(--bg); box-shadow: var(--shadow-inset-sm); color: var(--text); }
.form-input:focus { box-shadow: inset 6px 6px 12px var(--shadow-dark), inset -6px -6px 12px var(--shadow-light), 0 0 0 3px var(--primary-glow); }
.form-input::placeholder { color: var(--text-light); }
.input-group { margin-bottom: 16px; }
.input-group label { display: block; font-size: 13px; font-weight: 500; color: var(--text-secondary); margin-bottom: 5px; }

.btn { display: inline-flex; align-items: center; justify-content: center; padding: 10px 24px; border: none; border-radius: var(--radius); font-size: 14px; cursor: pointer; transition: all .2s cubic-bezier(.34,1.56,.64,1); white-space: nowrap; text-decoration: none; gap: 6px; user-select: none; font-weight: 600; box-shadow: var(--shadow-soft); background: var(--white); color: var(--text); position: relative; overflow: hidden; }
.btn:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; }
.btn:active:not(:disabled) { transform: scale(.96); }
.btn-block { width: 100%; }
.btn-primary { background: linear-gradient(135deg, var(--primary), var(--accent)); color: var(--white); box-shadow: var(--shadow-soft); }
.btn-primary:hover:not(:disabled) { transform: translateY(-2px); box-shadow: var(--shadow-raised); }
.btn-primary:active:not(:disabled) { transform: translateY(0) scale(.97); box-shadow: var(--shadow-pressed); }
.btn-default { background: var(--white); color: var(--text); }
.btn-default:hover { box-shadow: var(--shadow-raised); }
.btn-default:active { box-shadow: var(--shadow-pressed); }
.btn-danger { background: linear-gradient(135deg, #ef4444, #dc2626); color: var(--white); }
.btn-danger:hover:not(:disabled) { transform: translateY(-2px); box-shadow: var(--shadow-raised); }
.btn-danger:active:not(:disabled) { transform: translateY(0) scale(.97); }
.btn-outline { background: transparent; box-shadow: none; color: var(--primary); }
.btn-outline:hover { box-shadow: var(--shadow-soft); background: var(--white); }
.btn-sm { padding: 6px 16px; font-size: 12px; border-radius: var(--radius-sm); }
.btn-xs { padding: 3px 10px; font-size: 11px; border-radius: 6px; }
.error-msg { color: #ef4444; font-size: 13px; }
.shake { animation: shake .4s ease; }
@keyframes shake { 0%,100% { transform: translateX(0); } 20% { transform: translateX(-6px); } 40% { transform: translateX(6px); } 60% { transform: translateX(-4px); } 80% { transform: translateX(4px); } }
.form-input.shake { box-shadow: inset 4px 4px 8px var(--shadow-dark), inset -4px -4px 8px var(--shadow-light), 0 0 0 3px rgba(239,68,68,.2); }

/* ============ CHAT APP ============ */
.chat-app { height: 100vh; height: 100dvh; padding: 50px; background: var(--bg); }
.chat-container { width: 100%; max-width: 1300px; height: 100%; margin: 0 auto; display: flex; flex-direction: column; background: var(--white); box-shadow: var(--shadow-lg); border-radius: var(--radius-xl); overflow: hidden; }

/* ----- Header ----- */
.chat-header { display: flex; align-items: center; justify-content: space-between; padding: 0 28px; height: var(--header-h); background: var(--white); flex-shrink: 0; z-index: 10; box-shadow: 0 1px 0 #e2e8f0; }
.header-left { display: flex; align-items: center; gap: 14px; }
.menu-toggle { display: none; background: none; border: none; cursor: pointer; padding: 6px; color: var(--text-secondary); border-radius: var(--radius-sm); transition: all .15s; }
.menu-toggle:hover { background: var(--bg); color: var(--primary); }
@media (max-width: 767px) { .menu-toggle { display: flex; align-items: center; } }
.header-logo { width: 36px; height: 36px; border-radius: var(--radius); background: linear-gradient(135deg, var(--primary), var(--accent)); display: flex; align-items: center; justify-content: center; flex-shrink: 0; box-shadow: var(--shadow-sm); color: var(--white); overflow: hidden; }
.header-logo:has(img) { background: none; }
.header-logo img { width: 100%; height: 100%; object-fit: contain; display: block; }
.header-title { font-size: 18px; font-weight: 700; color: var(--text); letter-spacing: .3px; }
.header-right { display: flex; align-items: center; gap: 8px; }

/* User Menu */
.user-menu { position: relative; }
.user-menu-trigger { display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 4px 14px 4px 4px; border-radius: 24px; user-select: none; background: var(--bg); box-shadow: var(--shadow-sm); }
.user-menu-trigger:hover { box-shadow: var(--shadow-soft); }
.header-avatar { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; border: 2px solid var(--white); flex-shrink: 0; }
.header-nickname { font-size: 13px; font-weight: 600; color: var(--text); }
.menu-arrow { color: var(--text-light); transition: transform .2s; display: flex; align-items: center; }
.user-menu:hover .menu-arrow { transform: rotate(180deg); }

.user-menu-dropdown { position: absolute; top: calc(100% + 10px); right: 0; min-width: 180px; background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 6px; display: none; z-index: 500; animation: dropIn .15s ease; }
.user-menu-dropdown.open { display: block; }
@keyframes dropIn { from { opacity: 0; transform: translateY(-6px) scale(.96); } to { opacity: 1; transform: translateY(0) scale(1); } }
.um-item { display: flex; align-items: center; gap: 10px; padding: 10px 16px; font-size: 13px; cursor: pointer; border-radius: var(--radius-sm); transition: all .15s; color: var(--text); }
.um-item:hover { background: var(--primary-light); color: var(--primary); }
.um-item iconify-icon { width: 16px; height: 16px; flex-shrink: 0; color: var(--text-secondary); }
.um-item:hover iconify-icon { color: var(--primary); }
.um-item-danger { color: #ef4444; }
.um-item-danger iconify-icon { color: #ef4444; }
.um-item-danger:hover { background: #fef2f2 !important; color: #dc2626; }
.um-divider { height: 1px; background: #e2e8f0; margin: 4px 12px; }

/* ----- Chat Body ----- */
.chat-body { flex: 1; display: flex; overflow: hidden; }

/* ----- Sidebar ----- */
.chat-sidebar { width: var(--sidebar-w); flex-shrink: 0; background: linear-gradient(180deg, #f8faff, var(--white)); display: flex; flex-direction: column; border-right: 1px solid #dce4f0; }
.sidebar-inner { flex: 1; overflow-y: auto; padding: 14px 0; }
.sidebar-footer { padding: 10px 14px; flex-shrink: 0; background: var(--white); border-top: 1px solid #dce4f0; }
.sidebar-section { padding: 2px 0; }
.sidebar-title { font-size: 10px; font-weight: 700; color: var(--primary); padding: 14px 20px 6px 28px; text-transform: uppercase; letter-spacing: 1.2px; position: relative; }
.sidebar-title::before { content: ''; position: absolute; left: 14px; top: 16px; bottom: 6px; width: 3px; border-radius: 3px; background: linear-gradient(180deg, var(--primary), var(--accent)); }
.sidebar-divider { height: 1px; background: #e2e8f0; margin: 6px 14px; }
.sidebar-list { display: flex; flex-direction: column; gap: 2px; padding: 0 10px; }
.sidebar-item { display: flex; align-items: center; gap: 10px; padding: 10px 14px; cursor: pointer; font-size: 13px; color: var(--text); transition: all .15s; border-radius: var(--radius); margin: 1px 0; position: relative; transform: translateX(0); }
.sidebar-item:hover { background: var(--primary-light); transform: translateX(3px); }
.sidebar-item-active { background: var(--primary-light); color: var(--primary); font-weight: 600; }
.sidebar-item-active::before { content: ''; position: absolute; left: -10px; top: 50%; transform: translateY(-50%); width: 4px; height: 22px; border-radius: 4px; background: linear-gradient(180deg, var(--primary), var(--accent)); }
.si-icon { width: 20px; height: 20px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; color: var(--text-secondary); }
.sidebar-item-active .si-icon { color: var(--primary); }
.si-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.si-avatar { width: 24px; height: 24px; border-radius: 50%; object-fit: cover; flex-shrink: 0; border: 2px solid var(--white); box-shadow: var(--shadow-sm); }
.si-online { width: 9px; height: 9px; border-radius: 50%; background: #22c55e; flex-shrink: 0; box-shadow: 0 0 0 2px var(--white); margin-left: auto; animation: pulse-dot 2s ease infinite; }
@keyframes pulse-dot { 0%,100% { opacity: 1; } 50% { opacity: .5; } }
.si-role { font-size: 10px; color: var(--primary); background: var(--primary-light); padding: 2px 10px; border-radius: 12px; font-weight: 600; flex-shrink: 0; }

.sidebar-item-cardkey { border: 1px dashed var(--primary); border-radius: var(--radius); background: var(--primary-light); color: var(--primary); gap: 8px; padding: 9px 14px; justify-content: center; }
.sidebar-item-cardkey:hover { background: var(--white); }
.sidebar-item-cardkey .si-icon { color: var(--primary); }

/* ----- Main Chat ----- */
.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--white); }

.chat-channel-header { display: flex; align-items: center; padding: 14px 28px; background: linear-gradient(90deg, #f8faff, var(--white)); flex-shrink: 0; font-size: 14px; font-weight: 600; gap: 10px; border-bottom: 1px solid #e2e8f0; position: relative; }
.chat-channel-header::before { content: ''; position: absolute; left: 0; top: 6px; bottom: 6px; width: 3px; border-radius: 0 3px 3px 0; background: linear-gradient(180deg, var(--primary), var(--accent)); }
.channel-header-icon { width: 22px; height: 22px; color: var(--primary); flex-shrink: 0; display: flex; align-items: center; justify-content: center; }
.channel-actions { margin-left: auto; }

/* Messages Area */
.chat-messages { flex: 1; overflow-y: auto; padding: 18px 28px; display: flex; flex-direction: column; gap: 3px; position: relative; }
.chat-messages::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 4px; background: linear-gradient(90deg, var(--primary-light), transparent); z-index: 1; pointer-events: none; }

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

.msg-loading-text { display: flex; align-items: center; justify-content: center; gap: 6px; padding: 60px 0; color: var(--text-secondary); font-size: 14px; }
.media-loading { display: flex; align-items: center; justify-content: center; gap: 6px; padding: 20px; color: var(--text-secondary); font-size: 13px; background: var(--surface); border-radius: 8px; min-width: 80px; min-height: 80px; }
.msg-image { position: relative; }
.msg-image .media-loading { position: absolute; inset: 0; z-index: 2; }
.msg-image img { position: relative; z-index: 1; }
.msg-video { position: relative; min-width: 80px; min-height: 80px; background: var(--surface); border-radius: var(--radius); }
.msg-video .media-loading { position: absolute; inset: 0; z-index: 2; }
.msg-video video { position: relative; z-index: 1; min-width: 80px; min-height: 80px; }

/* Messages */
.message { display: flex; gap: 10px; max-width: min(78%, 700px); margin-bottom: 6px; animation: msgIn .25s ease; position: relative; transition: transform .15s, box-shadow .15s; }
.message-other:hover { transform: translateX(4px); }
@keyframes msgIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
.message-self { align-self: flex-end; flex-direction: row-reverse; }
.message-other { align-self: flex-start; }

.msg-avatar { width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0; overflow: hidden; margin-top: 2px; box-shadow: var(--shadow-sm); }
.msg-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.msg-avatar .avatar-placeholder { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 600; color: var(--white); }
.message-self .msg-avatar .avatar-placeholder { background: linear-gradient(135deg, var(--primary), var(--accent)); }
.message-other .msg-avatar .avatar-placeholder { background: linear-gradient(135deg, #22c55e, #14b8a6); }

.message-grouped .msg-avatar { visibility: hidden; }
.message-grouped .msg-username { display: none; }
.message-grouped { margin-top: -6px; }

.msg-body { display: flex; flex-direction: column; gap: 3px; max-width: 100%; position: relative; }
.msg-username { font-size: 11px; font-weight: 600; color: var(--text-secondary); padding: 0 6px 1px; display: flex; align-items: center; gap: 8px; }
.message-self .msg-username { justify-content: flex-end; padding-right: 8px; }
.msg-admin-action { cursor: pointer; opacity: 0; transition: opacity .15s; display: flex; align-items: center; color: var(--text-light); padding: 0 4px; border-radius: 4px; }
.message-other:hover .msg-admin-action { opacity: .6; }
.msg-admin-action:hover { opacity: 1 !important; background: var(--bg); }

.msg-bubble { padding: 10px 18px; border-radius: 18px; font-size: 14px; line-height: 1.55; word-break: break-word; position: relative; }
.message-self .msg-bubble { background: linear-gradient(135deg, var(--primary), var(--accent)); color: var(--white); border-bottom-right-radius: 6px; box-shadow: var(--shadow-soft); }
.message-other .msg-bubble { background: var(--surface); color: var(--text); border-bottom-left-radius: 6px; box-shadow: var(--shadow-sm); transition: box-shadow .2s; }
.message-other:hover .msg-bubble { box-shadow: var(--shadow-soft); }
.message-self .msg-bubble::after { content: ''; position: absolute; bottom: 8px; right: -6px; width: 10px; height: 10px; background: var(--primary); border-radius: 2px; transform: rotate(45deg); }
.message-other .msg-bubble::after { content: ''; position: absolute; bottom: 8px; left: -6px; width: 10px; height: 10px; background: var(--surface); border-radius: 2px; transform: rotate(45deg); }

.msg-time { font-size: 10px; color: var(--text-light); padding: 0 4px; display: none; }
.message-self .msg-time { text-align: right; }
.message:hover .msg-time { display: block; }

/* Announcement */
.message-announcement { align-self: center; max-width: min(88%, 720px); margin: 8px 0; }
.message-announcement .msg-body { align-items: center; }
.message-announcement .msg-bubble { background: var(--surface); color: var(--primary); font-size: 13px; text-align: center; padding: 10px 24px; box-shadow: var(--shadow-sm); border-radius: var(--radius); }
.message-announcement .msg-bubble::after { display: none; }
.message-announcement .msg-avatar { display: none; }
.message-announcement .msg-username { display: none !important; }
.message-announcement .msg-time { display: none !important; }
.announcement-prefix { font-size: 15px; margin-right: 6px; }

/* System message */
.message-system { align-self: center; max-width: 80%; margin: 14px 0; }
.message-system .msg-bubble { background: transparent; color: var(--text-light); font-size: 12px; text-align: center; padding: 4px 16px; box-shadow: none; border-radius: 0; }
.message-system .msg-bubble::after { display: none; }

/* Date separator */
.date-separator { text-align: center; font-size: 11px; color: var(--text-light); padding: 16px 0 10px; position: relative; }
.date-separator::before, .date-separator::after { content: ''; position: absolute; top: 50%; height: 1px; width: 28%; background: linear-gradient(to right, transparent, #e2e8f0); }
.date-separator::after { background: linear-gradient(to left, transparent, #e2e8f0); right: 0; left: auto; }
.date-separator span { background: var(--white); padding: 0 14px; position: relative; z-index: 1; color: var(--text-light); }

/* Message content */
.msg-text a { color: inherit; text-decoration: underline; opacity: .9; }
.message-self .msg-text a { color: rgba(255,255,255,.85); }
.msg-image { margin: -3px -5px; min-width: 80px; min-height: 80px; background: var(--bg); border-radius: var(--radius); display: flex; align-items: center; justify-content: center; }
.msg-image img { max-width: 280px; max-height: 340px; border-radius: var(--radius); display: block; cursor: pointer; transition: transform .15s, opacity .3s; box-shadow: var(--shadow-sm); }
.msg-image img:hover { transform: scale(1.03); }
.msg-image img[src] { background: var(--bg); }
.msg-video video { max-width: 280px; max-height: 340px; border-radius: var(--radius); display: block; }

.msg-file { display: flex; align-items: center; gap: 10px; padding: 2px 0; }
.msg-file-icon { width: 40px; height: 40px; border-radius: var(--radius-sm); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.message-self .msg-file-icon { background: rgba(255,255,255,.15); }
.message-other .msg-file-icon { background: var(--primary-light); }
.message-self .msg-file-icon svg { color: rgba(255,255,255,.8); }
.message-other .msg-file-icon svg { color: var(--primary); }
.msg-file-info { flex: 1; min-width: 0; }
.msg-file-name { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.message-self .msg-file-name { color: rgba(255,255,255,.9); }
.message-other .msg-file-name { color: var(--text); }
.msg-file-size { font-size: 11px; color: var(--text-secondary); }
.message-self .msg-file-size { color: rgba(255,255,255,.6); }
.msg-file-download { font-size: 12px; padding: 4px 14px; border-radius: var(--radius-sm); text-decoration: none; flex-shrink: 0; font-weight: 500; transition: all .12s; }
.message-self .msg-file-download { background: rgba(255,255,255,.15); color: rgba(255,255,255,.9); }
.message-self .msg-file-download:hover { background: rgba(255,255,255,.25); }
.message-other .msg-file-download { background: var(--primary-light); color: var(--primary); }
.message-other .msg-file-download:hover { background: var(--primary); color: var(--white); }

.msg-audio { margin: 2px 0; }
.msg-audio audio { max-width: 260px; height: 36px; border-radius: 20px; }
.message-self .msg-audio audio { filter: hue-rotate(140deg) saturate(1.2); }

/* Input bar */
.chat-input-bar { display: flex; align-items: center; gap: 12px; padding: 14px 28px; background: var(--white); flex-shrink: 0; border-top: 1px solid #e2e8f0; box-shadow: 0 -1px 0 #f1f5f9; }
.input-actions { display: flex; align-items: center; gap: 4px; }
.input-action-btn { background: none; border: none; cursor: pointer; padding: 6px; color: var(--text-secondary); display: flex; align-items: center; border-radius: var(--radius-sm); transition: all .15s; }
.input-action-btn:hover { color: var(--primary); background: var(--primary-light); transform: scale(1.1); }
.input-wrap { flex: 1; }
.msg-input { width: 100%; padding: 12px 22px; border: none; border-radius: 28px; font-size: 14px; outline: none; transition: all .25s; background: var(--bg); box-shadow: var(--shadow-inset-sm); }
.msg-input:focus { box-shadow: inset 6px 6px 12px var(--shadow-dark), inset -6px -6px 12px var(--shadow-light), 0 0 0 3px var(--primary-glow); }
.msg-input:disabled { opacity: .6; cursor: not-allowed; }
.msg-input::placeholder { color: var(--text-light); }
.btn-send { width: 44px; height: 44px; border-radius: 50%; border: none; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all .2s cubic-bezier(.34,1.56,.64,1); flex-shrink: 0; background: linear-gradient(135deg, var(--primary), var(--accent)); color: var(--white); box-shadow: var(--shadow-soft); position: relative; overflow: hidden; }
.btn-send:hover { transform: scale(1.1); box-shadow: var(--shadow-raised); }
.btn-send:active { transform: scale(.85); box-shadow: var(--shadow-pressed); }
.btn-send:disabled { opacity: .4; cursor: not-allowed; transform: none; box-shadow: none; }
.btn-send::before { content: ''; position: absolute; inset: 0; border-radius: 50%; background: rgba(255,255,255,.15); transform: scale(0); transition: transform .3s cubic-bezier(.34,1.56,.64,1); }
.btn-send:hover::before { transform: scale(1); }

/* ============ UPLOAD PREVIEW ============ */
.upload-preview { position: fixed; bottom: 0; left: 0; right: 0; background: var(--white); border-radius: var(--radius-xl) var(--radius-xl) 0 0; box-shadow: var(--shadow-lg); z-index: 100; padding: 20px 28px 24px; max-height: 55vh; overflow-y: auto; animation: slideUp .3s cubic-bezier(.16,1,.3,1); }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.upload-preview-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.upload-preview-header span { font-weight: 600; font-size: 15px; }
.upload-preview-thumb { margin-bottom: 12px; text-align: center; }
.upload-preview-thumb img { max-width: 200px; max-height: 200px; border-radius: var(--radius); object-fit: cover; box-shadow: var(--shadow-sm); }
.upload-progress-wrap { width: 100%; height: 8px; background: var(--bg); border-radius: 4px; overflow: hidden; margin: 10px 0; box-shadow: var(--shadow-inset-sm); }
.upload-progress-bar { height: 100%; background: linear-gradient(90deg, var(--primary), var(--accent)); border-radius: 4px; transition: width .3s; width: 0; }
.upload-progress-text { font-size: 13px; color: var(--text-secondary); text-align: center; margin: 4px 0 14px; }

/* ============ MODAL ============ */
.modal-overlay { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 20px; backdrop-filter: blur(12px); animation: overlayIn .15s ease; }
@keyframes overlayIn { from { opacity: 0; } to { opacity: 1; } }
.modal { background: var(--white); border-radius: var(--radius-xl); width: 100%; max-width: 420px; box-shadow: var(--shadow-lg); animation: modalIn .25s cubic-bezier(.16,1,.3,1); overflow: hidden; }
@keyframes modalIn { from { opacity: 0; transform: translateY(16px) scale(.94); } to { opacity: 1; transform: translateY(0) scale(1); } }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 18px 24px; border-bottom: 1px solid #e2e8f0; background: linear-gradient(135deg, var(--primary-light), var(--white)); }
.modal-header h3 { font-size: 16px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.modal-close { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--text-secondary); padding: 0; width: 30px; height: 30px; border-radius: var(--radius-sm); display: flex; align-items: center; justify-content: center; transition: all .12s; line-height: 1; }
.modal-close:hover { background: var(--bg); }
.modal-body { padding: 24px; }
.modal-footer { display: flex; gap: 10px; justify-content: flex-end; padding: 16px 24px; border-top: 1px solid #e2e8f0; }

.avatar-preview-img { width: 108px; height: 108px; border-radius: 50%; object-fit: cover; margin-bottom: 14px; background: var(--bg); border: 3px solid var(--white); box-shadow: var(--shadow-sm); }
.card-key-icon { width: 50px; height: 50px; border-radius: var(--radius); background: var(--primary-light); display: flex; align-items: center; justify-content: center; margin: 0 auto 12px; box-shadow: var(--shadow-sm); }

/* ============ ADMIN PAGE ============ */
.admin-page { background: var(--bg); overflow-y: auto; }
.admin-wrapper { max-width: 1060px; margin: 0 auto; padding: 28px 20px; min-height: 100vh; }
.admin-header { display: flex; align-items: center; justify-content: space-between; padding: 18px 24px; background: var(--white); border-radius: var(--radius-lg); box-shadow: var(--shadow-raised); margin-bottom: 20px; flex-wrap: wrap; gap: 10px; }
.admin-header h2 { font-size: 18px; font-weight: 700; }
.admin-header-right { display: flex; align-items: center; gap: 10px; }
.admin-user { font-size: 13px; color: var(--text-secondary); }
.admin-tabs { display: flex; gap: 4px; background: var(--bg); border-radius: var(--radius); padding: 4px; margin-bottom: 20px; box-shadow: var(--shadow-sm); }
.tab-btn { display: inline-flex; align-items: center; gap: 6px; flex: 1; padding: 10px 16px; border: none; background: transparent; border-radius: var(--radius-sm); font-size: 13px; cursor: pointer; transition: all .2s; color: var(--text-secondary); font-weight: 500; justify-content: center; }
.tab-btn:hover:not(.active) { color: var(--text); background: rgba(255,255,255,.5); }
.tab-btn.active { background: var(--white); color: var(--primary); font-weight: 600; box-shadow: var(--shadow-soft); transform: translateY(-1px); }
.tab-btn:active:not(.active) { transform: scale(.96); }
.tab-content { display: none; }
.tab-content.active { display: block; animation: fadeIn .2s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.toolbar { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.search-box { display: flex; align-items: center; gap: 8px; background: var(--bg); border-radius: var(--radius); padding: 0 16px; box-shadow: var(--shadow-inset-sm); }
.search-box:focus-within { box-shadow: inset 6px 6px 12px var(--shadow-dark), inset -6px -6px 12px var(--shadow-light), 0 0 0 3px var(--primary-glow); }
.search-box iconify-icon { color: var(--text-light); }
.search-box .form-input { border: none; padding: 10px 0; background: transparent; max-width: 240px; box-shadow: none; }
.search-box .form-input:focus { box-shadow: none; }

/* Card */
.card { background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow-raised); overflow: hidden; margin-bottom: 16px; }
.card-header { display: flex; align-items: center; gap: 8px; padding: 16px 22px; border-bottom: 1px solid #dce4f0; font-weight: 600; font-size: 14px; }
.card-body { padding: 22px; }
.card-body.p-0 { padding: 0; }
.ah-left { display: flex; align-items: center; gap: 12px; }
.ah-left h2 { font-size: 18px; font-weight: 700; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 12px 18px; text-align: left; border-bottom: 1px solid #f1f5f9; }
th { background: var(--surface); font-weight: 600; color: var(--text-secondary); font-size: 11px; text-transform: uppercase; letter-spacing: .5px; }
tr:last-child td { border-bottom: none; }
.td-muted { color: var(--text-secondary); font-size: 12px; }
.td-actions { white-space: nowrap; }
.user-cell { display: flex; align-items: center; gap: 10px; }
.user-avatar-sm { width: 30px; height: 30px; border-radius: 50%; background: linear-gradient(135deg, var(--primary), var(--accent)); color: var(--white); display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 600; flex-shrink: 0; }
.role-badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 12px; border-radius: 12px; font-size: 11px; font-weight: 600; }
.role-admin { background: var(--primary-light); color: var(--primary); }
.role-user { background: var(--bg); color: var(--text-secondary); }
.status-normal { color: #22c55e; font-weight: 500; font-size: 12px; }
.status-banned { color: #ef4444; font-weight: 500; font-size: 12px; }
.status-muted { color: #eab308; font-weight: 500; font-size: 12px; }
.action-btn { padding: 6px 12px; font-size: 11px; border-radius: var(--radius-sm); border: none; background: var(--white); cursor: pointer; margin: 0 2px; transition: all .12s; line-height: 1; box-shadow: var(--shadow-sm); }
.action-btn:hover { box-shadow: var(--shadow-soft); }
.action-btn.danger { color: #ef4444; }
.action-btn.danger:hover { background: #ef4444; color: var(--white); }
.action-btn.success { color: #22c55e; }
.action-btn.success:hover { background: #22c55e; color: var(--white); }
.card-token { font-size: 12px; background: var(--bg); padding: 4px 12px; border-radius: var(--radius-sm); font-family: "SF Mono","Fira Code",monospace; letter-spacing: .5px; }

.setting-row { display: flex; align-items: center; gap: 14px; padding: 14px 0; border-bottom: 1px solid #f1f5f9; flex-wrap: wrap; }
.setting-row:last-child { border-bottom: none; }
.setting-row label { width: 140px; font-size: 14px; flex-shrink: 0; font-weight: 500; }
.setting-row .form-input { max-width: 100px; }
.set-input { display: flex; align-items: center; gap: 8px; }
.set-unit { font-size: 13px; color: var(--text-light); font-weight: 500; }
.setting-desc { font-size: 12px; color: var(--text-secondary); margin-bottom: 14px; }

.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 767px) { .settings-grid { grid-template-columns: 1fr; } }
.bg-preview { width: 100%; height: 140px; border-radius: var(--radius); display: flex; align-items: center; justify-content: center; margin-bottom: 14px; position: relative; overflow: hidden; background: var(--bg); box-shadow: var(--shadow-inset-sm); }
.bg-preview-overlay { width: 100%; height: 100%; background: rgba(15,23,42,.2); display: flex; align-items: center; justify-content: center; backdrop-filter: blur(3px); }
.bg-actions { display: flex; gap: 8px; }

.empty { text-align: center; padding: 40px 20px; color: var(--text-light); }
.empty p { font-size: 13px; margin-top: 6px; }

/* Toast */
.toast { position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--white); padding: 12px 28px; border-radius: var(--radius); font-size: 14px; z-index: 9999; animation: toastUp .35s cubic-bezier(.16,1,.3,1); box-shadow: var(--shadow-lg); display: flex; align-items: center; gap: 8px; }
@keyframes toastUp { from { opacity: 0; transform: translateX(-50%) translateY(16px) scale(.92); } to { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); } }

/* Admin action menu */
.admin-action-menu { position: absolute; background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 6px; z-index: 100; min-width: 150px; animation: dropIn .12s ease; }
.admin-action-menu div { display: flex; align-items: center; gap: 8px; padding: 9px 14px; font-size: 13px; cursor: pointer; border-radius: var(--radius-sm); transition: all .1s; }
.admin-action-menu div:hover { background: var(--primary-light); }
.admin-action-menu div iconify-icon { width: 15px; height: 15px; }
.admin-action-menu .aam-danger { color: #ef4444; }
.admin-action-menu .aam-success { color: #22c55e; }

/* ============ RESPONSIVE ============ */
@media (max-width: 767px) {
  .chat-app { padding: 0; }
  .chat-container { max-width: 100%; border-radius: 0; box-shadow: none; }
  .chat-header { padding: 0 12px; }
  .header-title { font-size: 15px; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .chat-sidebar { position: fixed; left: -280px; top: 0; bottom: 0; width: 220px; z-index: 100; box-shadow: var(--shadow-lg); transition: left .3s cubic-bezier(.16,1,.3,1); border-right: none; }
  .chat-sidebar.open { left: 0; }
  .sidebar-overlay { position: fixed; inset: 0; background: rgba(15,23,42,.4); z-index: 99; display: none; }
  .sidebar-overlay.open { display: block; }
  .sidebar-title { display: block; font-size: 9px; padding: 12px 16px 4px 24px; }
  .sidebar-title::before { left: 10px; top: 14px; bottom: 4px; }
  .sidebar-item { justify-content: flex-start; padding: 11px 12px; border-radius: var(--radius-sm); margin: 1px 6px; }
  .sidebar-item-active::before { display: none; }
  .sidebar-item .si-label { display: block; font-size: 12px; }
  .sidebar-item .si-role { display: inline-flex; }
  .sidebar-item .si-avatar { display: block; }
  .sidebar-item .si-online { display: block; }
  .sidebar-item .si-icon { width: 18px; height: 18px; }
  .sidebar-footer .si-label { display: block; font-size: 12px; }
  .sidebar-item-cardkey .si-label { display: block; }
  .sidebar-item-cardkey { padding: 9px 12px; justify-content: flex-start; border: 1px dashed var(--primary); margin: 2px 6px; }
  .sidebar-section { padding: 2px 0; }
  .sidebar-list { padding: 0 4px; }
  .sidebar-inner { padding: 8px 0; }
  .sidebar-overlay { display: none; }
  .sidebar-footer { padding: 6px 4px; }
  .message { max-width: 96%; gap: 6px; }
  .msg-avatar { width: 28px; height: 28px; margin-top: 4px; }
  .msg-avatar .avatar-placeholder { font-size: 11px; }
  .message-grouped .msg-avatar { visibility: visible; }
  .message-grouped { margin-top: 2px; }
  .message-announcement { margin: 12px 0; }
  .message-system { margin: 16px 0; }
  .msg-body { gap: 2px; }
  .msg-bubble { font-size: 13px; padding: 8px 14px; }
  .msg-image img, .msg-video video { max-width: 160px; max-height: 180px; }
  .login-box { padding: 28px 20px; }
  .login-page { padding: 12px; }
  .admin-wrapper { padding: 10px 8px; }
  .admin-header { padding: 12px 14px; flex-direction: column; align-items: flex-start; gap: 8px; }
  .admin-header-right { width: 100%; justify-content: flex-end; }
  .admin-tabs { flex-wrap: nowrap; overflow-x: auto; gap: 2px; padding: 3px; -webkit-overflow-scrolling: touch; }
  .admin-tabs::-webkit-scrollbar { display: none; }
  .tab-btn { flex: none; padding: 8px 12px; font-size: 12px; white-space: nowrap; }
  .setting-row label { width: 100%; }
  .setting-row { flex-direction: column; align-items: flex-start; gap: 6px; }
  .set-input { width: 100%; }
  .setting-row .form-input { max-width: 100%; }
  th, td { padding: 8px 8px; font-size: 12px; }
  td { white-space: normal; word-break: break-word; }
  .td-actions { white-space: nowrap; }
  .card-body { padding: 14px; }
  .card-body.p-0 { overflow-x: auto; }
  table { font-size: 12px; }
  .settings-grid { gap: 10px; }
  .bg-preview { height: 100px; }
  .chat-messages { padding: 10px 12px; }
  .chat-input-bar { padding: 8px 10px; gap: 6px; }
  .msg-input { padding: 9px 14px; font-size: 13px; }
  .btn-send { width: 38px; height: 38px; }
  .user-menu-trigger { padding: 2px 8px 2px 2px; }
  .header-nickname { max-width: 60px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .modal { max-width: 100%; margin: 0 10px; }
  .modal-body { padding: 18px; }
  .action-btn { padding: 8px 12px; margin: 1px; }
  .admin-user { font-size: 12px; }
  .search-box .form-input { max-width: 140px; }
  .toast { bottom: 16px; font-size: 13px; padding: 10px 20px; max-width: 90vw; }
}
