:root,
html[data-theme="dark"] {
  --bg: #07080d;
  --bg-2: #0b1020;
  --surface: rgba(16, 20, 31, 0.92);
  --surface-solid: #111827;
  --surface-2: #182133;
  --surface-3: #202b40;
  --card: rgba(255, 255, 255, 0.06);
  --glass: rgba(255, 255, 255, 0.075);
  --text: #f7f2e9;
  --text-strong: #ffffff;
  --muted: #9aa4b2;
  --muted-2: #707b8c;
  --line: rgba(255, 255, 255, 0.10);
  --line-strong: rgba(255, 255, 255, 0.16);
  --brand: #c9a75d;
  --brand-2: #f1d28a;
  --brand-3: #7c5c24;
  --green: #2fd37b;
  --blue: #62c7ff;
  --danger: #f25f67;
  --warning: #f6c65b;
  --bubble: rgba(255, 255, 255, 0.09);
  --self: linear-gradient(135deg, rgba(201, 167, 93, .95), rgba(124, 92, 36, .96));
  --self-text: #17120a;
  --input: rgba(255, 255, 255, 0.08);
  --input-text: #fffaf0;
  --shadow: 0 26px 70px rgba(0, 0, 0, 0.42);
  --soft-shadow: 0 16px 38px rgba(0, 0, 0, 0.22);
  --radius-xl: 30px;
  --radius-lg: 22px;
  --radius-md: 16px;
}

html[data-theme="light"] {
  --bg: #f3efe7;
  --bg-2: #ffffff;
  --surface: rgba(255, 255, 255, 0.92);
  --surface-solid: #ffffff;
  --surface-2: #f8f4ec;
  --surface-3: #eee7d9;
  --card: rgba(20, 24, 34, 0.045);
  --glass: rgba(255, 255, 255, 0.82);
  --text: #1b1d24;
  --text-strong: #0f1117;
  --muted: #687385;
  --muted-2: #8a93a1;
  --line: rgba(20, 24, 34, 0.10);
  --line-strong: rgba(20, 24, 34, 0.16);
  --brand: #a77a2b;
  --brand-2: #d9ad5c;
  --brand-3: #6b4b17;
  --green: #18a765;
  --blue: #168dd6;
  --danger: #d9434b;
  --warning: #b77713;
  --bubble: rgba(255, 255, 255, 0.92);
  --self: linear-gradient(135deg, #f1d28a, #c79a43);
  --self-text: #17120a;
  --input: rgba(255, 255, 255, 0.94);
  --input-text: #12151c;
  --shadow: 0 26px 70px rgba(90, 72, 36, 0.18);
  --soft-shadow: 0 12px 28px rgba(90, 72, 36, 0.12);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, Segoe UI, Arial, sans-serif;
  background:
    radial-gradient(circle at 10% 8%, rgba(201, 167, 93, .22), transparent 28%),
    radial-gradient(circle at 92% 10%, rgba(98, 199, 255, .12), transparent 24%),
    linear-gradient(145deg, var(--bg), var(--bg-2));
  color: var(--text);
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .34;
  background-image:
    linear-gradient(rgba(255,255,255,.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.035) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(circle at center, #000, transparent 78%);
}
button, input { font: inherit; }
button { cursor: pointer; border: 0; outline: 0; transition: .18s ease; }
button:disabled { opacity: .6; cursor: not-allowed; }
input {
  width: 100%;
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-radius: 15px;
  outline: 0;
  font-size: 14px;
  color: var(--input-text);
  background: var(--input);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.06);
}
input::placeholder { color: var(--muted-2); }
input:focus { border-color: rgba(201, 167, 93, .72); box-shadow: 0 0 0 4px rgba(201, 167, 93, .14); }
label { display: block; margin: 13px 0 7px; font-size: 13px; font-weight: 800; color: var(--text); }
label span { color: var(--muted); font-weight: 600; }

.page-loader {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at top, rgba(201,167,93,.25), transparent 34%),
    linear-gradient(145deg, #05060a, #0b1020 62%, #05060a);
  color: white;
  transition: opacity .28s ease, visibility .28s ease;
}
.page-loader.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.loader-card {
  text-align: center;
  width: min(380px, 90vw);
  padding: 34px;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 34px;
  background: rgba(255,255,255,.06);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
}
.loader-card h1 { margin: 16px 0 6px; font-size: 29px; letter-spacing: -1px; }
.loader-card p { color: #cbd3df; }
.loader-line { height: 5px; margin-top: 25px; background: rgba(255,255,255,.13); border-radius: 100px; overflow: hidden; }
.loader-line span { display: block; height: 100%; width: 45%; background: linear-gradient(90deg, var(--brand), var(--brand-2)); border-radius: inherit; animation: loading 1s infinite ease-in-out; }
@keyframes loading { 0% { transform: translateX(-110%); } 100% { transform: translateX(240%); } }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 5000;
  transform: translate(-50%, 120px);
  min-width: 260px;
  max-width: calc(100vw - 30px);
  background: rgba(10, 13, 20, .95);
  color: #fff;
  padding: 13px 17px;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 16px;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: .25s ease;
  text-align: center;
  font-size: 14px;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: rgba(126, 22, 30, .96); }
.toast.success { background: rgba(25, 87, 55, .96); }
.toast.info { background: rgba(23, 42, 73, .96); }

.brand-mark {
  width: 58px;
  height: 58px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 20px;
  background:
    linear-gradient(135deg, rgba(255,255,255,.22), transparent 34%),
    linear-gradient(135deg, var(--brand-2), var(--brand) 46%, var(--brand-3));
  color: #17120a;
  font-weight: 950;
  letter-spacing: -1px;
  box-shadow: 0 16px 40px rgba(201,167,93,.25);
  border: 1px solid rgba(255,255,255,.22);
}

.auth-wrapper {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 22px;
  position: relative;
}
.auth-box {
  width: min(450px, 100%);
  max-height: calc(100vh - 44px);
  overflow-y: auto;
  background: var(--surface);
  backdrop-filter: blur(20px);
  padding: 30px;
  border-radius: 32px;
  box-shadow: var(--shadow);
  border: 1px solid var(--line-strong);
}
.auth-brand { display: flex; align-items: center; gap: 15px; margin-bottom: 24px; }
.auth-brand .brand-mark { width: 56px; height: 56px; border-radius: 19px; flex: 0 0 auto; }
.auth-brand h1 { font-size: 25px; line-height: 1; letter-spacing: -1px; color: var(--text-strong); }
.auth-brand p { margin-top: 7px; color: var(--muted); font-size: 13px; }
.auth-top-actions { display: flex; justify-content: flex-end; margin-bottom: 14px; }
.tabs { display: flex; background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 5px; margin-bottom: 22px; }
.tab-btn { flex: 1; padding: 11px; border-radius: 13px; background: transparent; color: var(--muted); font-weight: 900; }
.tab-btn.active { background: linear-gradient(135deg, var(--brand-2), var(--brand)); color: #17120a; box-shadow: 0 8px 18px rgba(201,167,93,.2); }
.tab-content { display: none; }
.tab-content.active { display: block; }
.tab-content h2 { margin-bottom: 12px; font-size: 23px; color: var(--text-strong); letter-spacing: -.5px; }
.primary-btn, .secondary-btn, .danger-btn, .link-btn, .notify-btn {
  width: 100%;
  padding: 13px 16px;
  border-radius: 15px;
  font-weight: 900;
  margin-top: 14px;
}
.primary-btn, .notify-btn { background: linear-gradient(135deg, var(--brand-2), var(--brand)); color: #17120a; box-shadow: 0 10px 24px rgba(201,167,93,.2); }
.primary-btn:hover, .notify-btn:hover, .search-row button:hover, #sendBtn:hover { transform: translateY(-1px); filter: brightness(1.03); }
.secondary-btn { background: var(--surface-3); color: var(--text); border: 1px solid var(--line); }
.danger-btn { background: linear-gradient(135deg, #ff8b91, var(--danger)); color: white; }
.link-btn { background: transparent; color: var(--brand-2); margin-top: 8px; }
.theme-toggle {
  width: auto;
  min-width: 42px;
  height: 42px;
  padding: 0 13px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
  background: var(--glass);
  color: var(--text);
  border: 1px solid var(--line);
  font-weight: 900;
}

#chatSection {
  height: 100vh;
  width: 100%;
  display: flex;
  padding: 18px;
  gap: 0;
  position: relative;
}
#leftPanel {
  width: 400px;
  min-width: 350px;
  height: 100%;
  background: var(--surface);
  backdrop-filter: blur(18px);
  border-radius: var(--radius-xl) 0 0 var(--radius-xl);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line-strong);
  border-right: 1px solid var(--line);
  box-shadow: var(--soft-shadow);
}
.sidebar-header {
  min-height: 82px;
  padding: 16px;
  background:
    linear-gradient(135deg, rgba(201,167,93,.22), rgba(255,255,255,.02)),
    var(--surface-solid);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}
.profile-info { display: flex; align-items: center; gap: 12px; min-width: 0; cursor: pointer; }
.profile-text { min-width: 0; display: flex; flex-direction: column; }
.profile-text strong { color: var(--text-strong); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.profile-text span { font-size: 12px; color: var(--muted); margin-top: 4px; }
.profile-pic, .contact-pic, .chat-pic {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--surface-3);
  flex: 0 0 auto;
  border: 1px solid var(--line);
}
.icon-btn, .back-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--glass);
  color: var(--text);
  border: 1px solid var(--line);
  font-size: 22px;
}
.icon-btn:hover, .back-btn:hover, .theme-toggle:hover { background: var(--surface-3); }
.sidebar-actions { display: flex; align-items: center; gap: 8px; }
.search-box { padding: 14px; background: var(--surface); border-bottom: 1px solid var(--line); }
.search-row { display: flex; gap: 8px; }
.search-row input { border-radius: 15px; }
.search-row button { padding: 0 12px; min-width: 74px; border-radius: 15px; background: linear-gradient(135deg, var(--brand-2), var(--brand)); color: #17120a; font-weight: 950; }
.search-row button.hidden { display: none; }
.search-box small { display: block; color: var(--muted); margin-top: 8px; font-size: 12px; }
.search-result { max-height: 175px; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; touch-action: pan-y; border-bottom: 1px solid var(--line); }
.list-section { flex: 0 0 auto; }
.hidden-section { display: none !important; }
.contacts-section { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.section-title { padding: 15px 16px 7px; color: var(--muted); text-transform: uppercase; font-size: 11px; letter-spacing: .12em; font-weight: 950; }
.list-content { overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; touch-action: pan-y; }
.contacts-section .list-content { flex: 1; }
.empty-small { padding: 14px 16px; color: var(--muted); font-size: 13px; }

.contact-item, .request-item, .search-item {
  margin: 8px 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 19px;
  background: var(--glass);
  box-shadow: 0 2px 12px rgba(0, 0, 0, .05);
}
.contact-item { display: flex; gap: 12px; cursor: pointer; align-items: center; }
.contact-item:hover, .contact-item.active { background: rgba(201, 167, 93, .13); border-color: rgba(201,167,93,.42); }
.contact-pic-wrapper { position: relative; width: 46px; height: 46px; flex: 0 0 auto; }
.status-dot {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  border: 2px solid var(--surface-solid);
  background: #7c8797;
}
.status-dot.online { background: var(--green); box-shadow: 0 0 0 4px rgba(47,211,123,.15); }
.contact-info { flex: 1; min-width: 0; }
.contact-top, .contact-bottom { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.contact-top strong { color: var(--text-strong); min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 15px; }
.last-message { flex: 1; min-width: 0; color: var(--muted); font-size: 13px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.last-msg-time { color: var(--muted-2); font-size: 11px; white-space: nowrap; }
.unread-badge { display: none; align-items: center; justify-content: center; min-width: 21px; height: 21px; padding: 0 7px; border-radius: 100px; background: linear-gradient(135deg, var(--brand-2), var(--brand)); color: #17120a; font-size: 11px; font-weight: 950; }
.item-head { display: flex; align-items: center; gap: 10px; }
.item-head strong { display: block; color: var(--text-strong); }
.item-head small { color: var(--muted); }
.item-actions { display: flex; gap: 8px; margin-top: 10px; }
.item-actions button { padding: 8px 12px; border-radius: 12px; font-size: 12px; color: white; font-weight: 900; }
.add-btn, .accept-btn { background: linear-gradient(135deg, var(--brand-2), var(--brand)); color: #17120a !important; }
.reject-btn { background: var(--danger); }
.disabled-btn { background: #7e8794; }

#rightPanel {
  flex: 1;
  min-width: 0;
  height: 100%;
  background:
    radial-gradient(circle at 18% 12%, rgba(201,167,93,.14), transparent 28%),
    radial-gradient(circle at 90% 86%, rgba(98,199,255,.10), transparent 24%),
    var(--surface-2);
  border-radius: 0 var(--radius-xl) var(--radius-xl) 0;
  overflow: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line-strong);
  border-left: 0;
  box-shadow: var(--soft-shadow);
}
#rightPanel::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: .34;
  background-image: radial-gradient(circle at 20px 20px, rgba(201,167,93,.16) 1.4px, transparent 2.4px);
  background-size: 36px 36px;
}
.empty-state, #chatContainer, #accountPanel { position: relative; z-index: 1; }
.empty-state { flex: 1; display: flex; align-items: center; justify-content: center; text-align: center; padding: 30px; }
.empty-card { background: var(--glass); border: 1px solid var(--line); border-radius: 30px; padding: 36px; box-shadow: var(--soft-shadow); max-width: 440px; backdrop-filter: blur(16px); }
.empty-icon { font-size: 46px; margin-bottom: 12px; }
.empty-card h2 { font-size: 31px; color: var(--text-strong); letter-spacing: -1px; }
.empty-card p { color: var(--muted); margin-top: 9px; }
#chatContainer, #accountPanel { flex: 1; height: 100%; flex-direction: column; overflow: hidden; }
#chatHeader, #accountHeader {
  min-height: 76px;
  padding: 13px 18px;
  background:
    linear-gradient(135deg, rgba(201,167,93,.22), rgba(255,255,255,.02)),
    var(--surface-solid);
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 0 0 auto;
  border-bottom: 1px solid var(--line);
}
.chat-user-info { min-width: 0; }
#chatWithName { font-weight: 950; color: var(--text-strong); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#chatStatus { color: var(--muted); margin-top: 4px; font-size: 12px; }
#messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 11px;
}
.message { display: flex; }
.message.self { justify-content: flex-end; }
.msg-wrapper { display: flex; align-items: flex-start; gap: 7px; max-width: min(690px, 84%); }
.message.self .msg-wrapper { flex-direction: row-reverse; }
.bubble {
  min-width: 120px;
  max-width: 100%;
  padding: 10px 13px 8px;
  border-radius: 20px 20px 20px 6px;
  background: var(--bubble);
  box-shadow: 0 8px 20px rgba(0, 0, 0, .08);
  line-height: 1.45;
  word-break: break-word;
  border: 1px solid var(--line);
  backdrop-filter: blur(12px);
}
.message.self .bubble { background: var(--self); color: var(--self-text); border-color: rgba(255,255,255,.18); border-radius: 20px 20px 6px 20px; }
.sender { color: var(--brand-2); font-size: 12px; font-weight: 950; margin-bottom: 4px; }
.message.self .sender { display: none; }
.message-text { white-space: pre-wrap; color: inherit; }
.message-meta { display: flex; justify-content: flex-end; align-items: center; gap: 5px; margin-top: 5px; color: var(--muted); font-size: 11px; }
.message.self .message-meta { color: rgba(23,18,10,.72); }
.ticks { letter-spacing: -3px; padding-right: 3px; color: var(--muted); font-weight: 950; }
.ticks.seen { color: var(--blue); }
.msg-menu-wrap { position: relative; opacity: .62; }
.message:hover .msg-menu-wrap { opacity: 1; }
.msg-dots { width: 30px; height: 30px; border-radius: 50%; background: var(--glass); color: var(--text); border: 1px solid var(--line); font-size: 18px; }
.msg-menu { display: none; position: absolute; top: 32px; right: 0; min-width: 172px; background: var(--surface-solid); border-radius: 16px; overflow: hidden; box-shadow: var(--shadow); z-index: 20; border: 1px solid var(--line); }
.message.self .msg-menu { right: auto; left: 0; }
.msg-menu.show { display: block; }
.msg-menu button { width: 100%; background: transparent; color: var(--text); text-align: left; padding: 11px 13px; font-size: 13px; }
.msg-menu button:hover { background: var(--card); }
.msg-menu .delete-menu-btn, .msg-menu .danger-text { color: var(--danger); }
.replied-message { border-left: 4px solid var(--brand); background: rgba(201,167,93,.12); padding: 7px 8px; border-radius: 11px; margin-bottom: 7px; }
.replied-message strong { display: block; color: var(--brand-2); font-size: 12px; }
.message.self .replied-message strong { color: #513909; }
.replied-message p { color: var(--muted); font-size: 12px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 300px; }
.message.self .replied-message p { color: rgba(23,18,10,.72); }
.reply-preview { flex: 0 0 auto; margin: 0 14px 10px; padding: 10px 12px; border-left: 4px solid var(--brand); border-radius: 16px; background: var(--surface); display: flex; justify-content: space-between; align-items: center; box-shadow: var(--soft-shadow); border-top: 1px solid var(--line); border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.reply-preview strong { color: var(--brand-2); font-size: 13px; }
.reply-preview p { color: var(--muted); font-size: 13px; max-width: 65vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reply-preview button { background: transparent; color: var(--muted); font-size: 24px; }
#inputBox { flex: 0 0 auto; padding: 13px 15px; display: flex; align-items: center; gap: 10px; background: var(--surface); border-top: 1px solid var(--line); }
#messageInput { border-radius: 999px; padding: 14px 18px; }
#sendBtn { width: 49px; height: 49px; border-radius: 50%; background: linear-gradient(135deg, var(--brand-2), var(--brand)); color: #17120a; font-weight: 950; font-size: 18px; box-shadow: 0 10px 22px rgba(201,167,93,.2); }
.edit-message-box { display: flex; flex-direction: column; gap: 8px; min-width: min(330px, 70vw); }
.edit-message-input { border-color: var(--brand); padding: 9px 11px; border-radius: 12px; }
.edit-actions { display: flex; justify-content: flex-end; gap: 8px; }
.edit-actions button { padding: 7px 12px; border-radius: 10px; color: #17120a; background: linear-gradient(135deg, var(--brand-2), var(--brand)); font-weight: 900; font-size: 12px; }
.edit-actions .cancel-edit-btn { background: #64748b; color: white; }
.deleted-text { color: var(--muted); font-style: italic; }
.edited-label { font-size: 11px; color: var(--muted); margin-left: 6px; }

#accountPanel { background: var(--surface-2); }
.account-content { flex: 1; overflow-y: auto; padding: 30px; text-align: center; }
.account-big-photo { width: 132px; height: 132px; border-radius: 50%; object-fit: cover; border: 5px solid var(--surface-solid); box-shadow: var(--soft-shadow); }
.account-content h2 { margin-top: 14px; font-size: 26px; color: var(--text-strong); }
.muted { color: var(--muted); margin-top: 5px; }
.account-form-card, .account-card, .settings-card { background: var(--surface); border: 1px solid var(--line); border-radius: 22px; padding: 16px; margin: 16px auto 0; max-width: 540px; text-align: left; box-shadow: 0 8px 22px rgba(0,0,0,.04); }
.account-card p, .settings-card p { color: var(--muted); font-size: 12px; text-transform: uppercase; font-weight: 950; letter-spacing: .08em; margin-bottom: 6px; }
.account-card span { font-weight: 800; overflow-wrap: anywhere; color: var(--text-strong); }
.account-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; max-width: 540px; margin: 10px auto 0; }
.settings-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.settings-row > div { min-width: 0; }
.settings-row strong { color: var(--text-strong); display: block; }
.settings-row small { color: var(--muted); display: block; margin-top: 4px; line-height: 1.4; }
.settings-row .theme-toggle, .settings-row .notify-mini-btn { flex: 0 0 auto; }
.notify-mini-btn { padding: 10px 13px; border-radius: 999px; background: linear-gradient(135deg, var(--brand-2), var(--brand)); color: #17120a; font-weight: 950; }

@media (max-width: 900px) {
  #chatSection { padding: 0; }
  #leftPanel { width: 100%; min-width: 100%; border-radius: 0; border: 0; }
  #rightPanel { position: fixed; inset: 0; z-index: 100; display: none; border-radius: 0; height: 100dvh; border: 0; }
  #rightPanel.active { display: flex; }
  #emptyState { display: none !important; }
  #chatHeader, #accountHeader { min-height: 66px; padding: 10px 12px; }
  #messages { padding: 12px; }
  .msg-wrapper { max-width: 92%; }
  .search-result { max-height: 165px; }
  .account-content { padding: 22px 14px; }
  .account-actions { grid-template-columns: 1fr; }
  .reply-preview { margin: 0 10px 8px; }
}

@media (max-width: 520px) {
  .auth-wrapper { padding: 12px; }
  .auth-box { padding: 20px; border-radius: 24px; }
  .auth-brand h1 { font-size: 21px; }
  .brand-mark { width: 48px; height: 48px; border-radius: 16px; }
  #leftPanel { min-width: 100%; }
  .sidebar-header { min-height: 72px; padding: 12px; }
  .profile-pic, .contact-pic, .chat-pic, .contact-pic-wrapper { width: 42px; height: 42px; }
  .search-row { gap: 6px; }
  .search-row button { padding: 0 10px; min-width: 64px; font-size: 13px; }
  .bubble { font-size: 14px; }
  #inputBox { padding: 10px; }
  #sendBtn { width: 44px; height: 44px; }
  .settings-row { align-items: flex-start; flex-direction: column; }
}

/* Premium clean theme refresh — less flashy, more app-like */
:root,
html[data-theme="dark"] {
  --bg: #080b12;
  --bg-2: #0d1320;
  --surface: rgba(17, 24, 39, 0.96);
  --surface-solid: #111827;
  --surface-2: #0f172a;
  --surface-3: #1f2937;
  --card: rgba(255, 255, 255, 0.055);
  --glass: rgba(255, 255, 255, 0.065);
  --text: #e5e7eb;
  --text-strong: #f9fafb;
  --muted: #9ca3af;
  --muted-2: #6b7280;
  --line: rgba(148, 163, 184, 0.16);
  --line-strong: rgba(148, 163, 184, 0.22);
  --brand: #14b8a6;
  --brand-2: #5eead4;
  --brand-3: #0f766e;
  --green: #22c55e;
  --blue: #38bdf8;
  --danger: #ef4444;
  --warning: #f59e0b;
  --bubble: #1f2937;
  --self: linear-gradient(135deg, #14b8a6, #0f766e);
  --self-text: #ecfeff;
  --input: rgba(255, 255, 255, 0.075);
  --input-text: #f9fafb;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
  --soft-shadow: 0 14px 35px rgba(0, 0, 0, 0.20);
}

html[data-theme="light"] {
  --bg: #f6f7fb;
  --bg-2: #eef2f7;
  --surface: rgba(255, 255, 255, 0.96);
  --surface-solid: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #eef2f7;
  --card: rgba(15, 23, 42, 0.045);
  --glass: rgba(255, 255, 255, 0.82);
  --text: #334155;
  --text-strong: #0f172a;
  --muted: #64748b;
  --muted-2: #94a3b8;
  --line: rgba(15, 23, 42, 0.11);
  --line-strong: rgba(15, 23, 42, 0.16);
  --brand: #0f766e;
  --brand-2: #14b8a6;
  --brand-3: #115e59;
  --green: #16a34a;
  --blue: #0284c7;
  --danger: #dc2626;
  --warning: #d97706;
  --bubble: #ffffff;
  --self: linear-gradient(135deg, #0f766e, #115e59);
  --self-text: #ffffff;
  --input: #ffffff;
  --input-text: #0f172a;
  --shadow: 0 24px 70px rgba(15, 23, 42, 0.14);
  --soft-shadow: 0 12px 30px rgba(15, 23, 42, 0.10);
}

body {
  background:
    radial-gradient(circle at top left, rgba(20,184,166,.14), transparent 28%),
    radial-gradient(circle at bottom right, rgba(56,189,248,.10), transparent 30%),
    var(--bg);
}

.auth-box,
#leftPanel,
#rightPanel,
.empty-card,
.settings-card,
.account-form-card,
.account-card {
  box-shadow: var(--soft-shadow);
}

.auth-box,
#leftPanel,
#rightPanel {
  border-color: var(--line-strong);
}

.brand-mark,
.primary-btn,
.search-row button,
#sendBtn,
.notify-mini-btn,
.add-btn,
.accept-btn,
.edit-actions button {
  background: linear-gradient(135deg, var(--brand-2), var(--brand)) !important;
  color: #06201d !important;
}

html[data-theme="light"] .brand-mark,
html[data-theme="light"] .primary-btn,
html[data-theme="light"] .search-row button,
html[data-theme="light"] #sendBtn,
html[data-theme="light"] .notify-mini-btn,
html[data-theme="light"] .add-btn,
html[data-theme="light"] .accept-btn,
html[data-theme="light"] .edit-actions button {
  color: #ffffff !important;
}

#rightPanel {
  background:
    linear-gradient(180deg, rgba(20,184,166,.08), transparent 260px),
    var(--surface-2);
}

#rightPanel::before {
  opacity: .12;
  background-image: linear-gradient(var(--line) 1px, transparent 1px), linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 42px 42px;
}

.sidebar-header,
#chatHeader,
#accountHeader {
  background: rgba(17, 24, 39, .92);
  backdrop-filter: blur(18px);
}

html[data-theme="light"] .sidebar-header,
html[data-theme="light"] #chatHeader,
html[data-theme="light"] #accountHeader {
  background: rgba(255, 255, 255, .92);
}

.contact-item,
.request-item,
.search-item {
  border: 1px solid transparent;
  transition: transform .18s ease, background .18s ease, border-color .18s ease;
}

.contact-item:hover,
.request-item:hover,
.search-item:hover,
.contact-item.active {
  background: var(--card);
  border-color: var(--line);
  transform: translateY(-1px);
}

.bubble {
  background: var(--bubble);
  border-color: var(--line);
}

.message.self .bubble {
  background: var(--self);
  color: var(--self-text);
}

.sender,
.reply-preview strong,
.replied-message strong {
  color: var(--brand-2);
}

.theme-toggle,
.icon-btn,
.back-btn {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text-strong);
}

input {
  background: var(--input) !important;
  color: var(--input-text) !important;
  border-color: var(--line) !important;
}

input:focus {
  border-color: var(--brand) !important;
  box-shadow: 0 0 0 4px rgba(20,184,166,.16) !important;
}

.toast.info {
  background: var(--surface-solid);
  color: var(--text-strong);
  border: 1px solid var(--line-strong);
}

#notificationStatus::after {
  content: " Background push removed — no Blaze/payment needed.";
  color: var(--muted-2);
}


/* WebView/mobile scroll fixes */
#chatSection, #leftPanel, #rightPanel, #chatContainer { overscroll-behavior: none; }
.account-content { -webkit-overflow-scrolling: touch; overscroll-behavior: contain; touch-action: pan-y; }
@media (max-width: 900px) {
  body { position: fixed; width: 100%; height: 100%; }
  #messages { height: 100%; }
}

/* Final UI polish: compact search, premium scrollbars, no awkward mini-scroll on request/search areas */
.search-box {
  padding: 12px 14px 10px;
}
.search-row {
  align-items: center;
}
.search-row input {
  min-height: 48px;
  padding-right: 48px;
}
.search-row button {
  width: 46px !important;
  min-width: 46px !important;
  height: 46px !important;
  padding: 0 !important;
  border-radius: 50% !important;
  font-size: 0 !important;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  box-shadow: 0 10px 22px rgba(20, 184, 166, .18);
}
.search-row button::before {
  content: "⌕";
  font-size: 22px;
  line-height: 1;
  font-weight: 950;
}
.search-row button.hidden {
  display: none !important;
}
.search-box small {
  margin-top: 7px;
}

#searchResult {
  display: none;
  border-bottom: 0 !important;
}
#searchResult:not(:empty) {
  display: block;
  padding: 4px 0 7px;
}
.search-result,
#requestList {
  max-height: none !important;
  overflow: visible !important;
  scrollbar-width: none !important;
  -ms-overflow-style: none !important;
}
.search-result::-webkit-scrollbar,
#requestList::-webkit-scrollbar {
  width: 0 !important;
  height: 0 !important;
  display: none !important;
}
.list-section:not(.contacts-section) {
  flex: 0 0 auto;
  overflow: visible;
}
.list-section:not(.contacts-section) .list-content {
  overflow: visible !important;
}

/* Premium thin scrollbars instead of default white Windows bars */
#messages,
.contacts-section .list-content,
.account-content,
.auth-box {
  scrollbar-width: thin;
  scrollbar-color: rgba(94, 234, 212, .32) transparent;
}
#messages::-webkit-scrollbar,
.contacts-section .list-content::-webkit-scrollbar,
.account-content::-webkit-scrollbar,
.auth-box::-webkit-scrollbar {
  width: 7px;
}
#messages::-webkit-scrollbar-track,
.contacts-section .list-content::-webkit-scrollbar-track,
.account-content::-webkit-scrollbar-track,
.auth-box::-webkit-scrollbar-track {
  background: transparent;
}
#messages::-webkit-scrollbar-thumb,
.contacts-section .list-content::-webkit-scrollbar-thumb,
.account-content::-webkit-scrollbar-thumb,
.auth-box::-webkit-scrollbar-thumb {
  background: rgba(94, 234, 212, .28);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
#messages::-webkit-scrollbar-thumb:hover,
.contacts-section .list-content::-webkit-scrollbar-thumb:hover,
.account-content::-webkit-scrollbar-thumb:hover,
.auth-box::-webkit-scrollbar-thumb:hover {
  background: rgba(94, 234, 212, .48);
  background-clip: padding-box;
}
html[data-theme="light"] #messages,
html[data-theme="light"] .contacts-section .list-content,
html[data-theme="light"] .account-content,
html[data-theme="light"] .auth-box {
  scrollbar-color: rgba(15, 118, 110, .32) transparent;
}
html[data-theme="light"] #messages::-webkit-scrollbar-thumb,
html[data-theme="light"] .contacts-section .list-content::-webkit-scrollbar-thumb,
html[data-theme="light"] .account-content::-webkit-scrollbar-thumb,
html[data-theme="light"] .auth-box::-webkit-scrollbar-thumb {
  background: rgba(15, 118, 110, .28);
  background-clip: padding-box;
}

@media (max-width: 900px) {
  #messages,
  .contacts-section .list-content,
  .account-content,
  .auth-box {
    scrollbar-width: none !important;
    -ms-overflow-style: none !important;
  }
  #messages::-webkit-scrollbar,
  .contacts-section .list-content::-webkit-scrollbar,
  .account-content::-webkit-scrollbar,
  .auth-box::-webkit-scrollbar {
    width: 0 !important;
    height: 0 !important;
    display: none !important;
  }
}


/* Request panel visibility + pending request polish */
.requests-section.hidden-section { display: none !important; }
.pending-request { opacity: .92; }
.pending-request .disabled-btn { cursor: default; }


/* Helpful tutorial and creator notes */
.creator-credit {
  display: inline-flex;
  margin-top: 7px;
  color: var(--brand-2);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .01em;
}
.guide-card {
  margin: 0 0 14px;
  padding: 12px 13px;
  border-radius: 16px;
  background: rgba(201, 167, 93, .10);
  border: 1px solid rgba(201, 167, 93, .24);
  color: var(--text);
  line-height: 1.45;
}
.guide-card strong {
  display: block;
  margin-bottom: 4px;
  color: var(--text-strong);
  font-size: 13px;
}
.guide-card span {
  display: block;
  color: var(--muted);
  font-size: 12.5px;
}
.search-guide {
  margin: 10px 0 0;
  padding: 10px 11px;
}
.search-guide b { color: var(--brand-2); }
.empty-credit,
.creator-mini {
  display: block;
  margin-top: 10px;
  color: var(--brand-2);
  font-size: 12px;
  font-weight: 850;
}
.creator-mini {
  margin-top: 6px;
}
.msg-menu button {
  text-align: left;
}

/* Discord-style guided popups */
.help-btn {
  width: 38px;
  height: 38px;
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  color: var(--text-strong);
  background: rgba(201, 167, 93, .13);
  border: 1px solid rgba(201, 167, 93, .26);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.08);
}
.help-btn:hover { transform: translateY(-1px); background: rgba(201, 167, 93, .22); }
.tutorial-overlay.hidden { display: none; }
.tutorial-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  pointer-events: none;
}
.tutorial-backdrop {
  position: absolute;
  inset: 0;
  pointer-events: auto;
  background: rgba(0,0,0,.46);
  backdrop-filter: blur(3px);
}
.tutorial-card {
  position: absolute;
  z-index: 10002;
  width: min(370px, calc(100vw - 28px));
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  pointer-events: auto;
  padding: 20px;
  border-radius: 24px;
  color: var(--text);
  background:
    linear-gradient(150deg, rgba(255,255,255,.12), rgba(255,255,255,.045)),
    var(--surface-solid);
  border: 1px solid rgba(201, 167, 93, .28);
  box-shadow: 0 28px 90px rgba(0,0,0,.45);
}
.tutorial-card::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background: radial-gradient(circle at 18% 0%, rgba(201,167,93,.20), transparent 34%);
}
.tutorial-pill {
  position: relative;
  display: inline-flex;
  margin-bottom: 10px;
  padding: 6px 10px;
  border-radius: 999px;
  color: var(--self-text);
  font-size: 11px;
  font-weight: 950;
  text-transform: uppercase;
  letter-spacing: .08em;
  background: linear-gradient(135deg, var(--brand-2), var(--brand));
}
.tutorial-card h2,
.tutorial-card p,
.tutorial-actions,
.tutorial-dots { position: relative; }
.tutorial-card h2 {
  margin: 2px 0 8px;
  font-size: 22px;
  color: var(--text-strong);
}
.tutorial-card p {
  color: var(--muted);
  line-height: 1.55;
  font-size: 14px;
}
.tutorial-dots {
  display: flex;
  gap: 7px;
  margin: 18px 0 0;
}
.tutorial-dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--line-strong);
}
.tutorial-dot.active {
  width: 22px;
  background: var(--brand-2);
}
.tutorial-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}
.tutorial-skip,
.tutorial-next {
  min-width: 86px;
  padding: 11px 14px;
  border-radius: 14px;
  font-weight: 900;
}
.tutorial-skip {
  color: var(--muted);
  background: var(--card);
  border: 1px solid var(--line);
}
.tutorial-next {
  color: var(--self-text);
  background: linear-gradient(135deg, var(--brand-2), var(--brand));
  box-shadow: 0 10px 24px rgba(201,167,93,.20);
}
.tutorial-highlight {
  position: relative;
  z-index: 10001 !important;
  outline: 3px solid rgba(241, 210, 138, .92) !important;
  outline-offset: 6px;
  box-shadow: 0 0 0 9999px rgba(0,0,0,.42), 0 0 28px rgba(241,210,138,.46) !important;
  border-radius: 18px !important;
}
@media (max-width: 900px) {
  .tutorial-card {
    left: 14px !important;
    right: 14px !important;
    top: auto !important;
    bottom: 18px !important;
    width: auto;
    transform: none !important;
  }
}

/* Final mobile auth, guide spotlight, and feedback polish */
body.auth-screen {
  position: relative !important;
  width: 100% !important;
  min-height: 100dvh !important;
  height: auto !important;
  overflow-y: auto !important;
  overscroll-behavior-y: auto !important;
}
body.auth-screen .auth-wrapper {
  min-height: 100dvh;
  height: auto;
  align-items: flex-start;
  justify-content: center;
  padding: max(18px, env(safe-area-inset-top)) 14px max(24px, env(safe-area-inset-bottom));
  overflow: visible;
}
body.auth-screen .auth-box {
  max-height: none !important;
  overflow: visible !important;
  margin: 0 auto;
}
body.app-screen {
  overflow: hidden;
  overscroll-behavior: none;
}

/* Cleaner tutorial spotlight: keep the selected area visible */
.tutorial-backdrop {
  background: rgba(2, 6, 23, .42) !important;
  backdrop-filter: none !important;
}
.tutorial-highlight {
  position: relative;
  z-index: 10003 !important;
  outline: 3px solid rgba(94, 234, 212, .9) !important;
  outline-offset: 6px !important;
  box-shadow: 0 0 0 6px rgba(94, 234, 212, .13), 0 16px 40px rgba(0,0,0,.28) !important;
  filter: none !important;
}
.tutorial-card {
  z-index: 10004 !important;
}

/* Sidebar feedback area */
.sidebar-feedback {
  margin: 10px 12px 14px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--card);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}
.sidebar-feedback span {
  display: block;
  margin-bottom: 9px;
}
.sidebar-feedback a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 8px 12px;
  border-radius: 999px;
  color: var(--self-text);
  background: linear-gradient(135deg, var(--brand-2), var(--brand));
  text-decoration: none;
  font-weight: 900;
}
html[data-theme="light"] .sidebar-feedback a {
  color: #ffffff;
}
.contacts-section .list-content.empty-small + .sidebar-feedback {
  margin-top: auto;
}

@media (max-width: 900px) {
  body.auth-screen { position: relative !important; }
  body.auth-screen .auth-wrapper { padding: 12px 12px 22px; }
  body.auth-screen .auth-box { width: 100%; }
  .tutorial-highlight {
    outline-offset: 4px !important;
    box-shadow: 0 0 0 4px rgba(94, 234, 212, .12), 0 10px 28px rgba(0,0,0,.28) !important;
  }
}

@media (max-height: 720px) {
  body.auth-screen .auth-brand { margin-bottom: 16px; }
  body.auth-screen .auth-box { padding: 18px; }
  body.auth-screen label { margin-top: 9px; }
  body.auth-screen .primary-btn { margin-top: 11px; }
}


/* Final auth/mobile scroll + search/feedback refinements */
html.auth-screen-root,
html.auth-screen-root body {
  height: auto !important;
  min-height: 100% !important;
  overflow-x: hidden !important;
  overflow-y: auto !important;
  overscroll-behavior-y: contain !important;
}
html.app-screen-root,
html.app-screen-root body {
  height: 100% !important;
  overflow: hidden !important;
}
body.auth-screen {
  min-height: 100svh !important;
  overflow-x: hidden !important;
  overflow-y: auto !important;
  -webkit-overflow-scrolling: touch !important;
  touch-action: pan-y !important;
}
body.auth-screen::before {
  position: fixed;
}
body.auth-screen .auth-wrapper {
  min-height: auto !important;
  height: auto !important;
  align-items: flex-start !important;
  justify-content: center !important;
  overflow: visible !important;
  padding: max(14px, env(safe-area-inset-top)) 12px calc(44px + env(safe-area-inset-bottom)) !important;
}
body.auth-screen .auth-box {
  width: min(450px, 100%) !important;
  max-height: none !important;
  overflow: visible !important;
  margin: 0 auto 34px !important;
}
#searchInput::placeholder {
  color: var(--muted-2);
}
.sidebar-feedback {
  width: min(230px, calc(100% - 48px));
  margin: 8px auto 12px !important;
  padding: 10px 11px !important;
  border-radius: 15px !important;
  text-align: center;
  font-size: 11.5px !important;
}
.sidebar-feedback span {
  margin-bottom: 7px !important;
}
.sidebar-feedback a {
  min-height: 30px !important;
  padding: 7px 11px !important;
  font-size: 11.5px;
}
@media (max-width: 520px) {
  body.auth-screen .auth-wrapper {
    padding: 10px 10px calc(58px + env(safe-area-inset-bottom)) !important;
  }
  body.auth-screen .auth-box {
    padding: 16px !important;
    border-radius: 22px !important;
  }
  body.auth-screen .auth-brand {
    gap: 11px;
    margin-bottom: 13px !important;
  }
  body.auth-screen .auth-brand .brand-mark {
    width: 46px;
    height: 46px;
    border-radius: 15px;
    font-size: 13px;
  }
  body.auth-screen .auth-brand h1 {
    font-size: 20px !important;
  }
  body.auth-screen .auth-brand p,
  body.auth-screen .creator-credit {
    font-size: 11.5px;
  }
  body.auth-screen .tabs {
    margin-bottom: 14px;
  }
  body.auth-screen .tab-content h2 {
    font-size: 19px;
    margin-bottom: 8px;
  }
  body.auth-screen label {
    margin: 8px 0 5px !important;
    font-size: 12px;
  }
  body.auth-screen input {
    padding: 11px 12px;
    border-radius: 13px;
    font-size: 13px;
  }
  body.auth-screen .primary-btn,
  body.auth-screen .link-btn {
    margin-top: 10px !important;
    padding: 12px 14px;
  }
}

/* Feedback restored + smoother mobile panel navigation */
.sidebar-feedback {
  width: auto !important;
  margin: 12px 12px 16px !important;
  padding: 14px 14px !important;
  border-radius: 18px !important;
  text-align: left !important;
  font-size: 12px !important;
  line-height: 1.45 !important;
}
.sidebar-feedback span {
  margin-bottom: 10px !important;
}
.sidebar-feedback a {
  min-height: 34px !important;
  padding: 8px 13px !important;
  font-size: 12px !important;
}

@media (max-width: 900px) {
  #rightPanel {
    display: flex !important;
    transform: translateX(100%);
    opacity: 1;
    pointer-events: none;
    transition: transform .28s cubic-bezier(.22, 1, .36, 1), box-shadow .28s ease;
    will-change: transform;
    box-shadow: -18px 0 35px rgba(0,0,0,.20);
  }
  #rightPanel.active {
    transform: translateX(0);
    pointer-events: auto;
  }
  #leftPanel {
    transition: transform .28s cubic-bezier(.22, 1, .36, 1), opacity .28s ease;
  }
  #chatSection:has(#rightPanel.active) #leftPanel {
    transform: translateX(-3%);
    opacity: .92;
  }
  .back-btn,
  .contact-item,
  .icon-btn {
    transition: transform .18s ease, background .18s ease, border-color .18s ease, opacity .18s ease;
  }
  .back-btn:active,
  .contact-item:active,
  .icon-btn:active {
    transform: scale(.96);
  }
}

/* Final mobile viewport + keyboard feedback fix */
:root { --aa-vh: 100dvh; }
#chatSection {
  height: var(--aa-vh, 100dvh) !important;
  min-height: var(--aa-vh, 100dvh) !important;
  max-height: var(--aa-vh, 100dvh) !important;
  overflow: hidden !important;
}
#leftPanel,
#rightPanel {
  min-height: 0 !important;
  overflow: hidden !important;
}
.contacts-section {
  min-height: 0 !important;
  overflow: hidden !important;
  padding-bottom: max(10px, env(safe-area-inset-bottom)) !important;
}
.contacts-section .list-content {
  min-height: 0 !important;
  padding-bottom: 10px !important;
}
.sidebar-feedback {
  flex: 0 0 auto !important;
  margin: 10px 12px max(14px, env(safe-area-inset-bottom)) !important;
}
@media (max-width: 900px) {
  html.app-screen-root,
  html.app-screen-root body {
    height: var(--aa-vh, 100dvh) !important;
    min-height: var(--aa-vh, 100dvh) !important;
    max-height: var(--aa-vh, 100dvh) !important;
    overflow: hidden !important;
  }
  #rightPanel {
    height: var(--aa-vh, 100dvh) !important;
    min-height: var(--aa-vh, 100dvh) !important;
    max-height: var(--aa-vh, 100dvh) !important;
  }
  .sidebar-feedback {
    margin-bottom: max(18px, calc(env(safe-area-inset-bottom) + 14px)) !important;
  }
  body.search-focused .sidebar-feedback,
  body.keyboard-open .sidebar-feedback {
    display: none !important;
  }
  body.search-focused .contacts-section .list-content,
  body.keyboard-open .contacts-section .list-content {
    padding-bottom: 18px !important;
  }
}

/* 2026 polish: softer premium theme, compact contacts, profile viewer, reactions, improved auth */
html[data-theme="dark"] {
  --bg: #101827;
  --bg-2: #172235;
  --surface: rgba(25, 35, 52, 0.92);
  --surface-solid: #172235;
  --surface-2: #1d2a3f;
  --surface-3: #26364f;
  --card: rgba(255, 255, 255, 0.075);
  --glass: rgba(255, 255, 255, 0.055);
  --text: #f4f7fb;
  --text-strong: #ffffff;
  --muted: #a9b4c6;
  --muted-2: #7d8aa0;
  --line: rgba(255, 255, 255, 0.095);
  --brand: #14b8a6;
  --brand-2: #5eead4;
  --brand-3: #0f766e;
  --self: linear-gradient(135deg, #5eead4, #14b8a6);
  --self-text: #05201e;
  --bubble: rgba(255, 255, 255, 0.085);
  --input: rgba(255, 255, 255, 0.075);
}

body.auth-screen {
  background:
    radial-gradient(circle at 18% 16%, rgba(94, 234, 212, .26), transparent 28%),
    radial-gradient(circle at 84% 26%, rgba(201, 167, 93, .18), transparent 24%),
    linear-gradient(135deg, var(--bg), var(--bg-2));
}
body.auth-screen .auth-wrapper::before,
body.auth-screen .auth-wrapper::after {
  content: "";
  position: fixed;
  width: 190px;
  height: 190px;
  border-radius: 50%;
  pointer-events: none;
  filter: blur(2px);
  opacity: .42;
  animation: authFloat 7s ease-in-out infinite;
}
body.auth-screen .auth-wrapper::before {
  left: -55px;
  top: 10%;
  background: radial-gradient(circle, rgba(94,234,212,.28), transparent 65%);
}
body.auth-screen .auth-wrapper::after {
  right: -65px;
  bottom: 10%;
  background: radial-gradient(circle, rgba(201,167,93,.24), transparent 65%);
  animation-delay: -3s;
}
@keyframes authFloat {
  0%, 100% { transform: translate3d(0,0,0) scale(1); }
  50% { transform: translate3d(12px,-18px,0) scale(1.08); }
}
body.auth-screen .auth-box {
  position: relative;
  isolation: isolate;
  border: 1px solid rgba(255,255,255,.15) !important;
  box-shadow: 0 30px 90px rgba(0,0,0,.32), inset 0 1px 0 rgba(255,255,255,.08) !important;
}
body.auth-screen .auth-brand h1::after {
  content: "Private chat • Simple • Fast";
  display: block;
  margin-top: 8px;
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--brand-2);
}
body.auth-screen .primary-btn {
  animation: softPulse 2.8s ease-in-out infinite;
}
@keyframes softPulse {
  0%, 100% { box-shadow: 0 10px 24px rgba(20,184,166,.16); }
  50% { box-shadow: 0 14px 38px rgba(20,184,166,.28); }
}

.contacts-section .list-content {
  padding: 4px 10px 10px;
}
.contact-item {
  margin: 0 !important;
  padding: 9px 4px !important;
  min-height: 62px !important;
  border: 0 !important;
  border-bottom: 1px solid var(--line) !important;
  border-radius: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
  gap: 11px !important;
}
.contact-item:hover,
.contact-item.active {
  background: rgba(94, 234, 212, .08) !important;
  transform: none !important;
}
.contact-pic-wrapper {
  border: 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
  border-radius: 50%;
}
.contact-pic-wrapper:hover .contact-pic,
.chat-pic:hover,
.account-big-photo:hover {
  filter: brightness(1.06);
  transform: scale(1.02);
}
.contact-pic-wrapper .contact-pic,
.contact-pic,
.chat-pic,
.profile-pic {
  width: 44px !important;
  height: 44px !important;
  transition: transform .18s ease, filter .18s ease;
}
.contact-info { padding-right: 2px; }
.contact-top strong { font-size: 14.5px !important; }
.contact-bottom { margin-top: 2px; }
.last-message { font-size: 12.5px !important; }
.last-msg-time { font-size: 11px !important; margin-left: 8px; }
.unread-badge { min-width: 18px !important; height: 18px !important; font-size: 10px !important; padding: 0 5px !important; }

.profile-viewer {
  position: fixed;
  inset: 0;
  display: none;
  z-index: 7000;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.profile-viewer.show { display: flex; }
.profile-viewer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 6, 23, .72);
  backdrop-filter: blur(14px);
}
.profile-viewer-card {
  position: relative;
  width: min(390px, 92vw);
  padding: 20px;
  border-radius: 28px;
  border: 1px solid var(--line-strong);
  background: var(--surface-solid);
  box-shadow: var(--shadow);
  text-align: center;
  animation: viewerIn .18s ease-out;
}
@keyframes viewerIn { from { opacity: 0; transform: scale(.96) translateY(10px); } to { opacity: 1; transform: scale(1) translateY(0); } }
.profile-viewer-card img {
  width: min(290px, 76vw);
  height: min(290px, 76vw);
  object-fit: cover;
  border-radius: 26px;
  border: 1px solid var(--line);
  background: var(--surface-3);
}
.profile-viewer-card h3 { margin-top: 14px; font-size: 20px; color: var(--text-strong); }
.profile-viewer-card p { margin-top: 4px; color: var(--muted); }
.profile-viewer-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(0,0,0,.28);
  color: #fff;
  font-size: 22px;
}

.quick-reactions {
  display: flex;
  gap: 4px;
  padding: 8px;
  border-bottom: 1px solid var(--line);
}
.quick-reactions button {
  width: 30px !important;
  height: 30px;
  padding: 0 !important;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--card) !important;
  text-align: center !important;
  font-size: 15px !important;
}
.quick-reactions button:hover { transform: scale(1.12); background: var(--surface-3) !important; }
.message-reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}
.reaction-chip {
  min-width: 34px;
  height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: var(--surface-3);
  color: var(--text-strong);
  border: 1px solid var(--line);
  font-size: 12px;
}
.message.self .reaction-chip { background: rgba(255,255,255,.20); color: var(--self-text); border-color: rgba(0,0,0,.08); }
.reaction-chip.mine { outline: 2px solid rgba(94,234,212,.55); }
.reaction-chip span { font-size: 10px; font-weight: 900; }
.msg-menu { min-width: 188px !important; }

#chatHeader .chat-pic { cursor: zoom-in; }
.account-big-photo { cursor: zoom-in; }

@media (max-width: 520px) {
  .contact-item { min-height: 58px !important; padding: 8px 2px !important; }
  .contact-pic-wrapper, .contact-pic-wrapper .contact-pic, .contact-pic, .chat-pic, .profile-pic { width: 40px !important; height: 40px !important; }
  .contact-top strong { font-size: 14px !important; }
  .last-message { font-size: 12px !important; }
  .section-title { padding-top: 10px !important; }
  .profile-viewer-card { border-radius: 24px; padding: 16px; }
}

/* =========================
   Groups UI upgrade
   ========================= */
#leftPanel { position: relative; }
.groups-section { margin-top: 8px; }
.group-item .contact-pic-wrapper { position: relative; }
.group-mini-badge {
  position: absolute;
  right: -4px;
  bottom: -2px;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-size: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2, #14b8a6));
  border: 2px solid var(--panel, #111827);
}
.new-chat-fab {
  position: absolute;
  right: 18px;
  bottom: calc(86px + env(safe-area-inset-bottom));
  width: 54px;
  height: 54px;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(135deg, #2dd4bf, #14b8a6);
  color: #031411;
  font-size: 30px;
  line-height: 1;
  font-weight: 900;
  box-shadow: 0 18px 40px rgba(20, 184, 166, 0.35);
  cursor: pointer;
  z-index: 20;
  transition: transform .18s ease, box-shadow .18s ease;
}
.new-chat-fab:hover { transform: translateY(-2px) scale(1.03); box-shadow: 0 22px 50px rgba(20, 184, 166, 0.45); }
.new-chat-fab span {
  position: absolute;
  right: 64px;
  top: 50%;
  transform: translateY(-50%);
  white-space: nowrap;
  font-size: 12px;
  font-weight: 800;
  color: var(--text, #f8fafc);
  background: var(--card, #1f2937);
  padding: 8px 10px;
  border: 1px solid var(--border, rgba(148,163,184,.16));
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
}
.new-chat-fab:hover span { opacity: 1; transform: translateY(-50%) translateX(-2px); }
.group-modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 1200;
}
.group-modal.show { display: flex; }
.group-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 6, 23, 0.68);
  backdrop-filter: blur(6px);
}
.group-modal-card {
  position: relative;
  width: min(460px, 100%);
  max-height: min(680px, calc(var(--aa-vh, 100vh) - 32px));
  overflow: auto;
  border-radius: 28px;
  background: var(--panel, #101827);
  color: var(--text, #f8fafc);
  border: 1px solid var(--border, rgba(148,163,184,.16));
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.35);
  padding: 22px;
  animation: groupPop .2s ease both;
}
@keyframes groupPop { from { opacity: 0; transform: translateY(16px) scale(.98); } to { opacity: 1; transform: translateY(0) scale(1); } }
.group-modal-close {
  position: absolute;
  right: 16px;
  top: 14px;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.14);
  color: var(--text, #fff);
  font-size: 22px;
  cursor: pointer;
}
.group-modal-head {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-bottom: 18px;
  padding-right: 34px;
}
.group-modal-icon {
  width: 52px;
  height: 52px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, rgba(45, 212, 191, .26), rgba(20, 184, 166, .12));
  font-size: 24px;
}
.group-modal-head h2 { margin: 0 0 4px; font-size: 24px; }
.group-modal-head p { margin: 0; color: var(--muted, #94a3b8); font-size: 13px; line-height: 1.45; }
.group-form-grid { display: grid; gap: 10px; }
.group-form-grid label { font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; color: var(--muted, #94a3b8); }
.group-form-grid label span { text-transform: none; letter-spacing: 0; opacity: .75; }
.group-form-grid input,
.group-search-row input {
  width: 100%;
  border: 1px solid var(--border, rgba(148,163,184,.16));
  background: var(--input, rgba(15, 23, 42, 0.72));
  color: var(--text, #f8fafc);
  border-radius: 16px;
  padding: 13px 14px;
  outline: none;
}
.group-form-grid input:focus,
.group-search-row input:focus { border-color: rgba(45, 212, 191, .65); box-shadow: 0 0 0 4px rgba(45, 212, 191, .12); }
.group-search-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.group-search-row button,
.group-create-btn {
  border: 0;
  border-radius: 16px;
  padding: 0 16px;
  background: linear-gradient(135deg, #2dd4bf, #14b8a6);
  color: #031411;
  font-weight: 900;
  cursor: pointer;
}
.group-create-btn { margin-top: 16px; width: 100%; padding: 14px 18px; }
.group-member-result { min-height: 22px; font-size: 13px; }
.group-member-added { color: #2dd4bf; font-weight: 700; }
.group-member-error { color: #fb7185; font-weight: 700; }
.selected-members {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 42px;
  padding: 8px;
  border-radius: 18px;
  background: rgba(148, 163, 184, 0.08);
  border: 1px dashed var(--border, rgba(148,163,184,.22));
}
.selected-empty { color: var(--muted, #94a3b8); font-size: 13px; align-self: center; }
.member-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 0;
  border-radius: 999px;
  padding: 5px 8px 5px 5px;
  background: rgba(45, 212, 191, .12);
  color: var(--text, #fff);
  cursor: pointer;
}
.member-chip img {
  width: 24px;
  height: 24px;
  border-radius: 999px;
  object-fit: cover;
}
.member-chip b { color: #fb7185; font-size: 15px; }
.group-info-preview { text-align: center; margin-bottom: 18px; }
.group-info-preview img {
  width: 112px;
  height: 112px;
  border-radius: 34px;
  object-fit: cover;
  box-shadow: 0 18px 40px rgba(0,0,0,.25);
  border: 1px solid var(--border, rgba(148,163,184,.16));
}
.group-info-preview h2 { margin: 12px 0 4px; }
.group-info-preview p { margin: 0; color: var(--muted, #94a3b8); }

[data-theme="light"] .group-modal-card { background: #fffaf0; }
[data-theme="light"] .group-form-grid input,
[data-theme="light"] .group-search-row input { background: #fff; }
[data-theme="light"] .new-chat-fab span { color: #0f172a; background: #fff; }

@media (max-width: 900px) {
  .new-chat-fab {
    position: fixed;
    right: 18px;
    bottom: calc(78px + env(safe-area-inset-bottom));
    width: 56px;
    height: 56px;
  }
  .new-chat-fab span { display: none; }
  .group-modal { align-items: flex-end; padding: 10px; }
  .group-modal-card { width: 100%; border-radius: 26px 26px 18px 18px; max-height: calc(var(--aa-vh, 100vh) - 24px); }
  .group-search-row { grid-template-columns: 1fr 72px; }
}

/* Final groups/list polish: WhatsApp-like filter chips + combined list */
.chat-filter-tabs {
  display: flex;
  gap: 8px;
  padding: 10px 14px 8px;
  overflow-x: auto;
  flex: 0 0 auto;
  border-bottom: 1px solid var(--line);
  scrollbar-width: none;
}
.chat-filter-tabs::-webkit-scrollbar { display: none; }
.filter-chip {
  flex: 0 0 auto;
  height: 34px;
  padding: 0 14px;
  border-radius: 999px;
  background: transparent;
  border: 1px solid var(--line-strong);
  color: var(--muted);
  font-weight: 900;
  font-size: 13px;
}
.filter-chip.active {
  background: rgba(20, 184, 166, .17);
  border-color: rgba(45, 212, 191, .36);
  color: var(--brand-2);
}
.filter-chip span:not(:empty) {
  margin-left: 4px;
  color: inherit;
}
.groups-section { display: none !important; }
.contacts-section .section-title { padding-top: 12px; }
.contact-item.group-item .contact-top strong::after {
  content: " Group";
  margin-left: 6px;
  font-size: 10px;
  letter-spacing: .04em;
  color: var(--brand-2);
  font-weight: 900;
  text-transform: uppercase;
}
.new-chat-fab {
  width: 46px !important;
  height: 46px !important;
  font-size: 25px !important;
  right: 19px !important;
  bottom: calc(82px + env(safe-area-inset-bottom)) !important;
}
@media (max-width: 900px) {
  .new-chat-fab {
    width: 48px !important;
    height: 48px !important;
    font-size: 25px !important;
    bottom: calc(72px + env(safe-area-inset-bottom)) !important;
  }
}

/* Reaction chips sit like WhatsApp, attached to the bubble corner, not inside text flow */
.message { margin-bottom: 10px; }
.bubble { position: relative; }
.message-reactions {
  position: absolute !important;
  bottom: -16px !important;
  left: 10px;
  margin: 0 !important;
  padding: 0;
  gap: 3px !important;
  z-index: 2;
}
.message.self .message-reactions { left: auto; right: 10px; }
.reaction-chip {
  height: 22px !important;
  min-width: 31px !important;
  padding: 0 7px !important;
  border-radius: 999px !important;
  background: var(--surface-solid) !important;
  box-shadow: 0 5px 14px rgba(0,0,0,.22);
  border: 1px solid var(--line-strong) !important;
  color: var(--text-strong) !important;
}
.message.self .reaction-chip { background: var(--surface-solid) !important; color: var(--text-strong) !important; }
.group-members-list {
  margin-top: 12px;
  max-height: 190px;
  overflow-y: auto;
  display: grid;
  gap: 8px;
  text-align: left;
}
.group-member-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 16px;
  background: var(--card);
  border: 1px solid var(--line);
}
.group-member-row img { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; }
.group-member-row strong { display:block; color: var(--text-strong); font-size: 13px; }
.group-member-row small { display:block; color: var(--muted); font-size: 11px; margin-top: 1px; }
.group-member-row .admin-tag { margin-left: auto; font-size: 10px; font-weight: 950; color: var(--brand-2); text-transform: uppercase; }
body.filter-pending .contacts-section .sidebar-feedback { display: none; }
