:root {
  --bg: #090512;
  --panel: rgba(18, 12, 32, 0.92);
  --panel-2: rgba(27, 19, 45, 0.94);
  --text: #f3efff;
  --muted: #a59bbb;
  --pink: #ff4fc8;
  --pink-2: #ff7de2;
  --violet: #7b5cff;
  --green: #35ff8d;
  --border: rgba(255, 79, 200, 0.18);
  --shadow: 0 20px 40px rgba(0, 0, 0, 0.35);
  --radius: 24px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: radial-gradient(circle at top, #17102a 0%, #090512 58%); color: var(--text); font-family: Inter, system-ui, sans-serif; }
body { overscroll-behavior: none; }
#app { height: 100vh; overflow: hidden; }
button, input, textarea { font: inherit; }
img { max-width: 100%; }
.app-shell { display: grid; grid-template-columns: 340px 1fr; height: 100vh; gap: 12px; padding: 12px; overflow: hidden; }
.sidebar, .chat-panel, .auth-card, .modal-box { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); backdrop-filter: blur(18px); min-height: 0; }
.sidebar { display: flex; flex-direction: column; overflow: hidden; min-height: 0; }
.sidebar-head { padding: 18px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.brand { font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.brand span { color: var(--pink); text-shadow: 0 0 18px rgba(255, 79, 200, .55); }
.icon-btn, .primary-btn, .secondary-btn, .danger-btn, .chat-tool, .emoji-btn, .reaction-chip, .message-action, .message-menu-btn {
  border: none; cursor: pointer; transition: background .15s ease, filter .15s ease, box-shadow .15s ease, opacity .15s ease; border-radius: 16px; padding: 12px 14px; position: relative; user-select: none; -webkit-tap-highlight-color: transparent;
}
.icon-btn { background: rgba(255, 255, 255, .04); color: var(--text); }
.primary-btn { background: linear-gradient(135deg, var(--pink), var(--violet)); color: white; box-shadow: 0 0 18px rgba(255,79,200,.24); }
.secondary-btn { background: rgba(255,255,255,.05); color: var(--text); }
.danger-btn { background: rgba(255,65,111,.15); color: #ff9eb8; }
.chat-tool, .message-menu-btn, .message-action { background: rgba(255,255,255,.05); color: var(--text); }
@media (hover: hover) and (pointer: fine) {
  .icon-btn:hover, .secondary-btn:hover, .chat-tool:hover, .emoji-btn:hover, .reaction-chip:hover, .message-menu-btn:hover, .message-action:hover { background: rgba(255,255,255,.08); }
  .primary-btn:hover { filter: brightness(1.06); }
}
.icon-btn:active, .primary-btn:active, .secondary-btn:active, .danger-btn:active, .chat-tool:active, .emoji-btn:active, .reaction-chip:active, .message-action:active, .message-menu-btn:active { opacity: .92; transform: none; }
.text-input, .text-area { width: 100%; background: rgba(255,255,255,.04); border: 1px solid rgba(255,255,255,.08); color: var(--text); border-radius: 16px; padding: 14px 16px; outline: none; }
.text-input:focus, .text-area:focus { border-color: rgba(255,79,200,.45); box-shadow: 0 0 0 4px rgba(255,79,200,.11); }
.search-wrap { padding: 14px 18px; border-bottom: 1px solid var(--border); }
.sidebar-head-actions, .sidebar-actions { display: flex; gap: 10px; align-items: center; }
.sidebar-actions { padding: 16px 18px 12px; margin-top: 6px; border-bottom: 1px solid var(--border); }
.sidebar-actions .secondary-btn { flex: 1; }
.chat-list { overflow: auto; padding: 10px; display: flex; flex-direction: column; gap: 10px; flex: 1; min-height: 0; }
.chat-item { padding: 14px; border-radius: 18px; background: rgba(255,255,255,.03); border: 1px solid transparent; cursor: pointer; display: flex; gap: 12px; align-items: center; }
.chat-item:hover, .chat-item.active { background: rgba(255,255,255,.055); border-color: rgba(255,79,200,.22); }
.chat-item.dragging { opacity: .55; }
.avatar { width: 52px; height: 52px; border-radius: 50%; background: linear-gradient(135deg, rgba(255,79,200,.6), rgba(123,92,255,.6)); display: grid; place-items: center; font-weight: 700; font-size: 18px; position: relative; overflow: hidden; flex-shrink: 0; }
.avatar img, .profile-btn img { width: 100%; height: 100%; object-fit: cover; display: block; }
.profile-btn { width: 48px; height: 48px; padding: 0; display: grid; place-items: center; overflow: hidden; }
.profile-btn.has-avatar { border: 1px solid rgba(255, 79, 200, .35); box-shadow: 0 0 16px rgba(255,79,200,.18); background: rgba(255,255,255,.03); }
.online-dot { position: absolute; right: 1px; bottom: 1px; width: 14px; height: 14px; background: var(--green); border: 2px solid #0e0b17; border-radius: 50%; box-shadow: 0 0 14px rgba(53,255,141,.85); }
.chat-meta { min-width: 0; flex: 1; }
.chat-title-row { font-weight: 700; display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.chat-title-main { display: flex; align-items: center; gap: 8px; min-width: 0; }
.chat-title, .chat-title-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pin-mark { font-size: 13px; opacity: .9; }
.chat-tools { display: flex; gap: 6px; opacity: .92; }
.chat-tool { padding: 6px 8px; border-radius: 10px; color: var(--muted); }
.muted, .chat-preview, .status-text, .hint { color: var(--muted); font-size: 13px; }
.chat-preview { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 4px; }
.unread-badge { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; display: inline-flex; align-items: center; justify-content: center; background: linear-gradient(135deg, var(--pink), var(--violet)); color: white; font-size: 11px; font-weight: 800; box-shadow: 0 0 12px rgba(255,79,200,.22); }
.msg-status { font-weight: 800; letter-spacing: -.05em; color: var(--muted); }
.msg-status.read { color: #7dd6ff; }
.msg-status.sent { color: var(--muted); }
.chat-panel { display: flex; flex-direction: column; overflow: hidden; min-height: 0; height: calc(100vh - 24px); }
#main-area { display: flex; flex-direction: column; flex: 1; min-height: 0; overflow: hidden; }
.chat-head-wrap { border-bottom: 1px solid var(--border); }
.chat-head { padding: 18px; display: flex; justify-content: space-between; align-items: center; gap: 14px; }
.chat-user { display: flex; gap: 12px; align-items: center; }
.clickable-profile { cursor: pointer; }
.pinned-banner { padding: 10px 18px 0; color: var(--pink-2); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.messages { flex: 1; overflow: auto; padding: 18px; display: flex; flex-direction: column; gap: 12px; min-height: 0; overscroll-behavior: contain; }
.message-row { display: flex; align-items: flex-end; gap: 10px; }
.message-row.me { justify-content: flex-end; }
.message-avatar { border: none; background: transparent; padding: 0; cursor: pointer; }
.avatar-sm { width: 38px; height: 38px; font-size: 14px; }
.message-stack { display: flex; flex-direction: column; max-width: min(72%, 760px); }
.message-stack.me { align-items: flex-end; margin-left: auto; }
.message { position: relative; padding: 12px 14px 24px; border-radius: 18px; background: rgba(255,255,255,.05); border: 1px solid rgba(255,255,255,.06); cursor: pointer; }
.message.me { background: linear-gradient(135deg, rgba(255,79,200,.16), rgba(123,92,255,.16)); border-color: rgba(255,79,200,.22); }
.message.attachment-only { padding: 8px 8px 24px; width: fit-content; }
.message.flash { box-shadow: 0 0 0 1px var(--pink), 0 0 24px rgba(255,79,200,.35); }
.message-sender-line { margin-bottom: 6px; }
.message-sender-link { border: none; background: transparent; color: var(--pink-2); padding: 0; font-weight: 700; cursor: pointer; }
.message-body { white-space: pre-wrap; word-wrap: break-word; }
.message-meta { position: absolute; right: 12px; bottom: 8px; font-size: 11px; color: var(--muted); }
.reply-preview, .reply-bar { border-left: 3px solid var(--pink); background: rgba(255,255,255,.04); border-radius: 12px; padding: 8px 10px; margin-bottom: 8px; }
.reply-preview { cursor: pointer; }
.reply-author { color: var(--pink-2); font-size: 13px; font-weight: 700; }
.reply-text { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.attachment { margin-top: 8px; border-radius: 14px; overflow: hidden; border: 1px solid rgba(255,255,255,.08); background: rgba(0,0,0,.16); width: fit-content; max-width: 100%; display: inline-block; }
.attachment img, .attachment video { display: block; width: auto; max-width: 100%; max-height: 320px; background: #000; }
.file-link { display: flex; gap: 10px; align-items: center; padding: 12px; color: var(--text); text-decoration: none; background: rgba(255,255,255,.03); }
.reactions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; min-height: 0; padding-left: 4px; }
.reaction-chip { border-radius: 999px; padding: 4px 10px; background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.08); font-size: 13px; color: var(--text); }
.reaction-popover { position: absolute; left: 12px; bottom: calc(100% + 8px); display: grid; gap: 8px; padding: 10px; border-radius: 18px; background: rgba(21, 16, 34, .98); border: 1px solid rgba(255,255,255,.08); box-shadow: 0 16px 40px rgba(0,0,0,.35), 0 0 18px rgba(255,79,200,.15); z-index: 20; min-width: 250px; }
.reaction-popover.bottom { bottom: auto; top: calc(100% + 8px); }
.message.me .reaction-popover { left: auto; right: 12px; }
.reaction-row, .message-action-row { display: flex; gap: 6px; flex-wrap: wrap; }
.message-action { padding: 8px 12px; border-radius: 12px; font-size: 13px; }
.composer { border-top: 1px solid var(--border); padding: 16px; display: grid; gap: 10px; flex-shrink: 0; background: rgba(18, 12, 32, 0.98); }
.composer-row { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center; }
.composer-actions { display: flex; gap: 10px; align-items: center; }
.composer-middle { min-width: 0; }
.emoji-picker { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; padding: 8px; background: rgba(255,255,255,.04); border-radius: 14px; border: 1px solid rgba(255,255,255,.08); }
.emoji-btn { background: rgba(255,255,255,.05); border: 1px solid rgba(255,255,255,.08); border-radius: 12px; padding: 7px 10px; color: var(--text); }
.text-area { min-height: 54px; max-height: 160px; resize: vertical; }
.composer .icon-btn, .composer .primary-btn { height: 54px; display: inline-flex; align-items: center; justify-content: center; }
.composer .primary-btn { padding-inline: 20px; }
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 18px; }
.auth-card { width: min(470px, 100%); padding: 28px; }
.auth-title { font-size: 30px; font-weight: 800; margin-bottom: 8px; }
.auth-subtitle { color: var(--muted); margin-bottom: 20px; }
.auth-grid { display: grid; gap: 12px; }
.switch-line { margin-top: 16px; text-align: center; color: var(--muted); }
.switch-line a { color: var(--pink-2); text-decoration: none; }
.hidden { display: none !important; }
.empty-state { margin: auto; max-width: 520px; text-align: center; color: var(--muted); padding: 24px; }
.badge { padding: 5px 10px; border-radius: 999px; font-size: 12px; background: rgba(53,255,141,.12); color: #9effc6; border: 1px solid rgba(53,255,141,.16); }
.modal { position: fixed; inset: 0; background: rgba(4, 3, 7, 0.72); display: none; place-items: center; padding: 18px; z-index: 1000; }
.modal.active { display: grid; }
.modal-box { width: min(620px, 100%); padding: 22px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.user-pick-list { max-height: 260px; overflow: auto; display: grid; gap: 10px; }
.user-pick { display: flex; gap: 10px; align-items: center; background: rgba(255,255,255,.04); padding: 12px; border-radius: 16px; }
.user-pick input { width: 18px; height: 18px; }
.profile-card { display: grid; gap: 12px; }
.profile-preview { display:flex; gap:12px; align-items:center; padding: 10px 0 4px; }
.profile-avatar-preview { width: 72px; height: 72px; font-size: 24px; }
.profile-preview-name { font-weight: 700; font-size: 18px; }
.topbar-mobile { display: none; }
#toast-box { position: fixed; right: 18px; bottom: 18px; z-index: 2000; pointer-events: none; opacity: 0; transform: translateY(10px); transition: .2s ease; }
#toast-box.show { opacity: 1; transform: translateY(0); }
.toast { min-width: 220px; max-width: 360px; background: rgba(20,15,32,.95); border: 1px solid rgba(255,255,255,.08); border-radius: 16px; padding: 14px 16px; box-shadow: 0 16px 32px rgba(0,0,0,.35); }
.toast-success { border-color: rgba(53,255,141,.24); }
.toast-error { border-color: rgba(255,79,120,.24); }
@media (max-width: 920px) {
  html, body, #app { height: 100%; }
  .app-shell { grid-template-columns: 1fr; padding: 8px; height: 100vh; }
  .sidebar { display: none; }
  .sidebar.mobile-open { display: flex; position: fixed; inset: 8px; z-index: 900; }
  .topbar-mobile { display: flex; padding: 12px 14px; gap: 10px; align-items: center; border-bottom: 1px solid var(--border); }
  .chat-head { padding: 14px; }
  .composer-row { grid-template-columns: 1fr; }
  .composer-actions { order: 2; }
  .message-stack { max-width: 92%; }
  .sidebar-actions { padding-top: 14px; }
}

.sidebar, .chat-list { overscroll-behavior: contain; }
.chat-list { min-height: 0; }
.message-bubble { user-select: text; }


.message { min-width: 120px; padding-right: 54px; }
.message.attachment-only { min-width: 210px; }
.message-body:empty::after { content: ' a0'; }
.pinned-banner { padding: 10px 18px 8px; display: flex; align-items: center; gap: 10px; color: var(--pink-2); }
.pinned-banner-main { min-width: 0; flex: 1; cursor: pointer; background: rgba(255,255,255,.04); border: 1px solid rgba(255,255,255,.06); border-radius: 14px; padding: 10px 12px; }
.pinned-top { font-size: 12px; color: var(--pink-2); }
.pinned-text { color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pin-nav { width: 34px; height: 34px; border-radius: 12px; border: none; background: rgba(255,255,255,.05); color: var(--text); cursor: pointer; }
.pin-nav:disabled { opacity: .4; cursor: default; }
#chat-search, #user-search, #group-member-search, #direct-phone { autocomplete: off; }
.chat-list, .messages, .user-pick-list, .modal-box { scrollbar-width: thin; scrollbar-color: rgba(255,79,200,.65) rgba(255,255,255,.05); }
.chat-list::-webkit-scrollbar, .messages::-webkit-scrollbar, .user-pick-list::-webkit-scrollbar, .modal-box::-webkit-scrollbar { width: 10px; height: 10px; }
.chat-list::-webkit-scrollbar-track, .messages::-webkit-scrollbar-track, .user-pick-list::-webkit-scrollbar-track, .modal-box::-webkit-scrollbar-track { background: rgba(255,255,255,.04); border-radius: 999px; }
.chat-list::-webkit-scrollbar-thumb, .messages::-webkit-scrollbar-thumb, .user-pick-list::-webkit-scrollbar-thumb, .modal-box::-webkit-scrollbar-thumb { background: linear-gradient(180deg, rgba(255,79,200,.85), rgba(123,92,255,.85)); border-radius: 999px; border: 2px solid rgba(8,5,18,.65); }

.ghost-autofill{position:absolute;opacity:0;pointer-events:none;width:1px;height:1px;left:-9999px;top:-9999px;}


#push-host { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 10px; z-index: 80; }
.push-card { width: 320px; max-width: calc(100vw - 32px); border: 1px solid var(--border); border-radius: 18px; background: rgba(20,14,34,.96); color: var(--text); display: flex; gap: 12px; padding: 12px; cursor: pointer; box-shadow: var(--shadow); text-align: left; }
.push-avatar { width: 44px; height: 44px; border-radius: 50%; overflow: hidden; background: linear-gradient(135deg, rgba(255,79,200,.6), rgba(123,92,255,.6)); display: grid; place-items: center; flex: 0 0 auto; }
.push-avatar img { width: 100%; height: 100%; object-fit: cover; }
.push-meta { min-width: 0; }
.push-title { font-weight: 700; margin-bottom: 4px; }
.push-text { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sticker-panel { position: absolute; left: 0; right: 0; bottom: calc(100% + 12px); background: rgba(19,13,33,.98); border: 1px solid var(--border); border-radius: 18px; padding: 12px; box-shadow: var(--shadow); z-index: 12; }
.composer-middle { position: relative; }
.sticker-panel-top { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.sticker-pack-title { font-weight: 700; }
.sticker-help-tip { background: rgba(255,255,255,.05); border: 1px solid rgba(255,255,255,.08); border-radius: 14px; padding: 10px 12px; color: var(--muted); margin-bottom: 10px; font-size: 13px; }
.sticker-grid { max-height: 240px; overflow: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 8px; padding-right: 4px; }
.sticker-btn { border: none; background: rgba(255,255,255,.03); border-radius: 14px; padding: 8px; cursor: pointer; }
.sticker-btn img, .sticker-attachment img { width: 100%; height: 100%; object-fit: contain; }
.sticker-attachment { width: 140px; height: 140px; }
.sticker-packs-strip { display: flex; gap: 8px; overflow: auto; margin-top: 10px; padding-top: 8px; }
.sticker-pack-chip { width: 44px; height: 44px; border-radius: 12px; border: 1px solid transparent; background: rgba(255,255,255,.05); overflow: hidden; flex: 0 0 auto; cursor: pointer; }
.sticker-pack-chip.active { border-color: rgba(255,79,200,.45); box-shadow: 0 0 0 3px rgba(255,79,200,.14); }
.sticker-pack-chip img { width: 100%; height: 100%; object-fit: cover; }
.message.attachment-only .sticker-attachment { margin-top: 0; }

.sticker-settings-menu { margin-bottom: 10px; display: flex; justify-content: flex-start; }
.danger-btn { border: 1px solid rgba(255,70,120,.35); background: rgba(255,70,120,.12); color: #ffd5e5; padding: 10px 14px; border-radius: 12px; cursor: pointer; }
.danger-btn:hover { background: rgba(255,70,120,.18); }
