@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@400;500;600;700;800&display=swap');

:root {
  --bg: #fbfaf7;
  --bg-2: #ffffff;
  --panel: rgba(255, 255, 255, 0.75);
  --panel-border: rgba(20, 20, 20, 0.08);
  --panel-strong: rgba(20, 20, 20, 0.04);
  --text: #1c1b18;
  --text-dim: #767268;
  --accent: #c8961f;
  --accent-2: #f0c65f;
  --accent-soft: rgba(200, 150, 31, 0.14);
  --danger: #d64545;
  --success: #2f9e6e;
  --radius: 18px;
  --radius-sm: 12px;
  --field-bg: rgba(20,20,20,0.02);
  --icon-bg: rgba(20,20,20,0.03);
  --icon-bg-hover: rgba(20,20,20,0.07);
  --hover-bg: rgba(20,20,20,0.04);
  --bubble-in-bg: rgba(20,20,20,0.045);
  --scrollbar-thumb: rgba(0,0,0,0.14);
  --shadow-card: 0 10px 40px rgba(20,20,20,0.06);
}

html[data-theme="dark"] {
  --bg: #0a0a0b;
  --bg-2: #101113;
  --panel: rgba(255, 255, 255, 0.045);
  --panel-border: rgba(255, 255, 255, 0.09);
  --panel-strong: rgba(255, 255, 255, 0.06);
  --text: #f1f0ee;
  --text-dim: #93928f;
  --accent: #d9a635;
  --accent-2: #f3cf6d;
  --accent-soft: rgba(217, 166, 53, 0.18);
  --danger: #ef6161;
  --success: #45c98a;
  --field-bg: rgba(255,255,255,0.035);
  --icon-bg: rgba(255,255,255,0.05);
  --icon-bg-hover: rgba(255,255,255,0.1);
  --hover-bg: rgba(255,255,255,0.06);
  --bubble-in-bg: rgba(255,255,255,0.07);
  --scrollbar-thumb: rgba(255,255,255,0.16);
  --shadow-card: 0 10px 40px rgba(0,0,0,0.35);
}

html, body, .glass, .field input, .composer input[type=text], .btn-icon,
.contact-item, .msg-row .bubble, .presence-dot {
  transition: background-color .35s ease, color .35s ease, border-color .35s ease, box-shadow .35s ease;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Vazirmatn', sans-serif;
  background:
    radial-gradient(900px 700px at 12% -8%, rgba(200,150,31,0.16), transparent 55%),
    radial-gradient(800px 650px at 100% 8%, rgba(240,198,95,0.14), transparent 50%),
    radial-gradient(700px 600px at 25% 100%, rgba(160,120,20,0.10), transparent 55%),
    var(--bg);
  color: var(--text);
  direction: rtl;
  min-height: 100vh;
}
html[data-theme="dark"] body {
  background:
    radial-gradient(900px 700px at 12% -8%, rgba(217,166,53,0.14), transparent 55%),
    radial-gradient(800px 650px at 100% 8%, rgba(243,207,109,0.12), transparent 50%),
    radial-gradient(700px 600px at 25% 100%, rgba(120,90,20,0.14), transparent 55%),
    var(--bg);
}

a { color: inherit; text-decoration: none; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

.glass {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(28px) saturate(160%);
  -webkit-backdrop-filter: blur(28px) saturate(160%);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card), inset 0 1px 0 rgba(255,255,255,0.12);
  position: relative;
  overflow: hidden;
}
.glass::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.35), transparent);
  pointer-events: none;
}
html[data-theme="dark"] .glass {
  box-shadow: var(--shadow-card), inset 0 1px 0 rgba(255,255,255,0.06);
}

/* ---------- Auth pages ---------- */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  padding: 40px 34px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 20px;
  color: #1a1207;
  flex-shrink: 0;
  overflow: hidden;
}
.brand-mark img { width: 100%; height: 100%; object-fit: contain; }

.brand-title {
  font-size: 22px;
  font-weight: 800;
}

.brand-sub {
  font-size: 13px;
  color: var(--text-dim);
}

h1.page-title {
  font-size: 20px;
  font-weight: 700;
  margin: 0 0 6px;
}

p.page-desc {
  color: var(--text-dim);
  font-size: 14px;
  margin: 0 0 24px;
}

.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.field input {
  width: 100%;
  padding: 13px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--panel-border);
  background: var(--field-bg);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 13px 16px;
  border-radius: var(--radius-sm);
  border: none;
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: transform .12s, opacity .15s, box-shadow .15s;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #1a1207;
  box-shadow: 0 8px 24px rgba(255,122,48,0.25);
}

.btn-primary:hover { transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }

.btn-ghost {
  background: var(--field-bg);
  color: var(--text);
  border: 1px solid var(--panel-border);
}

.btn-danger {
  background: rgba(239, 91, 91, 0.15);
  color: #ff9d9d;
  border: 1px solid rgba(239,91,91,0.3);
}

.btn-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--panel-border);
  background: var(--icon-bg);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background .15s, transform .12s;
}
.btn-icon:hover { background: var(--icon-bg-hover); transform: translateY(-1px); }

.switch-link {
  text-align: center;
  margin-top: 20px;
  font-size: 13px;
  color: var(--text-dim);
}
.switch-link a { color: var(--accent-2); font-weight: 600; }

.error-box {
  background: rgba(239,91,91,0.12);
  border: 1px solid rgba(239,91,91,0.3);
  color: #ff9d9d;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 16px;
  display: none;
}
.error-box.show { display: block; }

.status-icon {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
  font-size: 32px;
}
.status-icon.pending { background: rgba(255,179,71,0.15); color: var(--accent-2); }
.status-icon.rejected { background: rgba(239,91,91,0.15); color: #ff9d9d; }

/* ---------- Chat app layout ---------- */
.app-shell {
  height: 100vh;
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 12px;
  padding: 12px;
}

@media (max-width: 800px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar.hide-mobile { display: none; }
  .chat-panel.hide-mobile { display: none; }
}

.sidebar {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  padding: 18px 18px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--panel-border);
}

.me-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: #1a1207;
  overflow: hidden;
  flex-shrink: 0;
  position: relative;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }

.avatar-sm { width: 34px; height: 34px; font-size: 13px; }
.avatar-lg { width: 84px; height: 84px; font-size: 28px; }

.me-name { font-weight: 700; font-size: 14px; }
.me-tag { font-size: 12px; color: var(--text-dim); }

.header-actions { display: flex; gap: 8px; }

.contact-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.contact-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .12s;
  position: relative;
}
.contact-item:hover { background: var(--hover-bg); }
.contact-item.active { background: var(--accent-soft); }

.presence-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #555;
  border: 2px solid var(--bg-2);
  position: absolute;
  bottom: 10px;
  right: 34px;
}
.presence-dot.online { background: var(--success); }

.contact-name { font-weight: 600; font-size: 14px; }
.contact-last { font-size: 12px; color: var(--text-dim); max-width: 190px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  gap: 10px;
  text-align: center;
  padding: 20px;
}

/* Chat panel */
.chat-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--panel-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255,255,255,0.02);
  backdrop-filter: blur(10px);
}

.chat-header-info { display: flex; align-items: center; gap: 12px; }
.chat-header-name { font-weight: 700; font-size: 15px; }
.chat-header-status { font-size: 12px; color: var(--text-dim); }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.msg-row {
  display: flex;
  margin-bottom: 6px;
}
.msg-row.out { justify-content: flex-start; }
.msg-row.in { justify-content: flex-end; }

.bubble {
  max-width: 62%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.6;
  position: relative;
}
.msg-row.out .bubble {
  background: linear-gradient(135deg, rgba(200,150,31,0.88), rgba(240,198,95,0.88));
  backdrop-filter: blur(6px);
  color: #1a1207;
  border-bottom-left-radius: 4px;
  box-shadow: 0 4px 18px rgba(200,150,31,0.18);
}
.msg-row.in .bubble {
  background: var(--bubble-in-bg);
  backdrop-filter: blur(10px);
  border: 1px solid var(--panel-border);
  border-bottom-right-radius: 4px;
}

.bubble img.chat-img { max-width: 260px; border-radius: 10px; display: block; margin-top: 4px; cursor: pointer; }
.bubble .file-chip { display: flex; align-items: center; gap: 8px; margin-top: 4px; padding: 8px 10px; background: rgba(0,0,0,0.15); border-radius: 10px; }
.bubble-time { font-size: 10px; opacity: 0.65; margin-top: 4px; text-align: left; }

.composer {
  padding: 14px 18px;
  border-top: 1px solid var(--panel-border);
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255,255,255,0.02);
  backdrop-filter: blur(10px);
  position: relative;
}

.composer input[type=text] {
  flex: 1;
  padding: 13px 16px;
  border-radius: 24px;
  border: 1px solid var(--panel-border);
  background: var(--field-bg);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  outline: none;
}
.composer input[type=text]:focus { border-color: var(--accent); }

/* Call overlay */
.call-overlay {
  position: fixed;
  inset: 0;
  background: rgba(6,7,10,0.92);
  backdrop-filter: blur(10px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  flex-direction: column;
  gap: 24px;
}
.call-overlay.show { display: flex; }

.call-videos {
  position: relative;
  width: min(80vw, 720px);
  aspect-ratio: 16/10;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
}
.call-videos video#remoteVideo { width: 100%; height: 100%; object-fit: cover; }
.call-videos video#localVideo {
  position: absolute;
  bottom: 14px;
  left: 14px;
  width: 140px;
  border-radius: 10px;
  border: 2px solid rgba(255,255,255,0.2);
}

.call-controls { display: flex; gap: 16px; flex-wrap: wrap; justify-content: center; }

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(20,22,28,0.95);
  border: 1px solid var(--panel-border);
  padding: 12px 20px;
  border-radius: 12px;
  font-size: 13px;
  z-index: 200;
  display: none;
}
.toast.show { display: block; }

/* Admin */
.admin-wrap { max-width: 900px; margin: 0 auto; padding: 30px 20px; }
.admin-table { width: 100%; border-collapse: collapse; margin-top: 16px; }
.admin-table th, .admin-table td { padding: 12px 10px; text-align: right; border-bottom: 1px solid var(--panel-border); font-size: 13px; }
.admin-table th { color: var(--text-dim); font-weight: 600; }
.pill { padding: 4px 10px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.pill.pending { background: rgba(255,179,71,0.15); color: var(--accent-2); }
.pill.approved { background: rgba(76,195,138,0.15); color: var(--success); }
.pill.rejected { background: rgba(239,91,91,0.15); color: #ff9d9d; }
.action-btns { display: flex; gap: 8px; }
.action-btns button { padding: 6px 14px; font-size: 12px; border-radius: 8px; }

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

/* ============ Animations ============ */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes popIn {
  from { opacity: 0; transform: scale(0.92); }
  to { opacity: 1; transform: scale(1); }
}
@keyframes msgSlideOut {
  from { opacity: 0; transform: translateX(-14px); }
  to { opacity: 1; transform: translateX(0); }
}
@keyframes msgSlideIn {
  from { opacity: 0; transform: translateX(14px); }
  to { opacity: 1; transform: translateX(0); }
}
@keyframes pulseRing {
  0% { box-shadow: 0 0 0 0 rgba(47, 158, 110, 0.45); }
  70% { box-shadow: 0 0 0 7px rgba(47, 158, 110, 0); }
  100% { box-shadow: 0 0 0 0 rgba(47, 158, 110, 0); }
}
@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .5; }
  30% { transform: translateY(-4px); opacity: 1; }
}
@keyframes spinLogo {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.auth-card { animation: fadeInUp .5s ease both; }
.brand-mark { animation: popIn .5s cubic-bezier(.34,1.56,.64,1) both; }

.app-shell { animation: fadeIn .35s ease both; }
.sidebar { animation: msgSlideOut .4s ease both; }
.chat-panel { animation: fadeIn .4s ease both; }

.msg-row { animation: msgSlideOut .28s ease both; }
.msg-row.in { animation-name: msgSlideIn; }

.contact-item { animation: fadeIn .3s ease both; }
.contact-item:active { transform: scale(0.98); }

.presence-dot.online { animation: pulseRing 2s infinite; }

.btn-primary:active, .btn-icon:active { transform: scale(0.94); }

.call-overlay .call-videos { animation: popIn .3s ease both; }

/* ============ Theme toggle ============ */
.theme-toggle {
  position: relative;
  overflow: hidden;
}
.theme-toggle .icon-sun, .theme-toggle .icon-moon {
  position: absolute;
  transition: transform .4s cubic-bezier(.4,0,.2,1), opacity .3s ease;
}
html[data-theme="dark"] .theme-toggle .icon-sun { transform: translateY(30px); opacity: 0; }
html[data-theme="dark"] .theme-toggle .icon-moon { transform: translateY(0); opacity: 1; }
html:not([data-theme="dark"]) .theme-toggle .icon-sun { transform: translateY(0); opacity: 1; }
html:not([data-theme="dark"]) .theme-toggle .icon-moon { transform: translateY(-30px); opacity: 0; }

/* ============ Typing indicator ============ */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 3px;
  height: 12px;
}
.typing-indicator span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
  display: inline-block;
  animation: typingBounce 1.2s infinite ease-in-out;
}
.typing-indicator span:nth-child(2) { animation-delay: .15s; }
.typing-indicator span:nth-child(3) { animation-delay: .3s; }

/* ============ Unread badge ============ */
.unread-badge {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #1a1207;
  font-size: 11px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  animation: popIn .3s cubic-bezier(.34,1.56,.64,1) both;
}

/* ============ Search box ============ */
.search-box {
  padding: 10px 12px;
  position: relative;
}
.search-box input {
  width: 100%;
  padding: 10px 14px;
  border-radius: 20px;
  border: 1px solid var(--panel-border);
  background: var(--field-bg);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.search-box input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ============ Message ticks (read receipts) ============ */
.msg-ticks {
  display: inline-flex;
  margin-right: 4px;
  font-size: 12px;
}
.msg-ticks.seen { color: #2f7fd6; }

/* ============ Message delete button ============ */
.msg-row { position: relative; }
.msg-delete-btn {
  opacity: 0;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.08);
  color: var(--text-dim);
  font-size: 11px;
  cursor: pointer;
  align-self: center;
  margin: 0 6px;
  transition: opacity .15s, background .15s;
  flex-shrink: 0;
}
.msg-row.in:hover .msg-delete-btn { opacity: 1; }
.msg-delete-btn:hover { background: rgba(214,69,69,0.18); color: var(--danger); }
.msg-row.in { align-items: center; }

/* ================================================================
   V2 — Redesign: split auth layout, settings panel, modals, groups,
   voice recorder, reply preview, skeletons, refined micro-interactions
   ================================================================ */

/* ---------- Icon system (inline SVG, currentColor) ---------- */
.icon { width: 20px; height: 20px; display: inline-block; vertical-align: middle; }
.icon-sm { width: 16px; height: 16px; }
.icon-lg { width: 26px; height: 26px; }
.btn-icon svg { width: 19px; height: 19px; }

/* ---------- Ripple micro-interaction ---------- */
.ripple-surface { position: relative; overflow: hidden; }
.ripple {
  position: absolute;
  border-radius: 50%;
  background: rgba(255,255,255,0.5);
  transform: scale(0);
  animation: rippleAnim .5s ease-out;
  pointer-events: none;
}
html[data-theme="dark"] .ripple { background: rgba(255,255,255,0.25); }
@keyframes rippleAnim { to { transform: scale(2.6); opacity: 0; } }

/* ---------- Split auth layout (two columns like a real product) ---------- */
.auth-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.05fr 1fr;
}
@media (max-width: 900px) {
  .auth-shell { grid-template-columns: 1fr; }
  .auth-side { display: none; }
}
.auth-side {
  position: relative;
  background:
    radial-gradient(600px 500px at 20% 20%, rgba(200,150,31,0.16), transparent 60%),
    radial-gradient(700px 600px at 90% 85%, rgba(240,198,95,0.14), transparent 55%),
    linear-gradient(160deg, #15130f 0%, #0c0b09 100%);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 56px 52px;
  color: #f1ece0;
  overflow: hidden;
}
html[data-theme="dark"] .auth-side { background:
    radial-gradient(600px 500px at 20% 20%, rgba(217,166,53,0.14), transparent 60%),
    radial-gradient(700px 600px at 90% 85%, rgba(243,207,109,0.12), transparent 55%),
    linear-gradient(160deg, #0b0b0c 0%, #050506 100%);
}
.auth-side::before {
  content: '';
  position: absolute;
  inset: -20% -10%;
  background: radial-gradient(circle at 50% 50%, rgba(255,255,255,0.03), transparent 60%);
  animation: driftGlow 14s ease-in-out infinite;
}
@keyframes driftGlow {
  0%, 100% { transform: translate(0,0) rotate(0deg); }
  50% { transform: translate(3%, -3%) rotate(8deg); }
}
.auth-side-top { display: flex; align-items: center; gap: 14px; position: relative; z-index: 1; }
.auth-side-logo { width: 46px; height: 46px; border-radius: 12px; overflow: hidden; }
.auth-side-logo img { width: 100%; height: 100%; object-fit: contain; }
.auth-side-brand { font-size: 19px; font-weight: 800; }
.auth-side-tag { font-size: 12px; color: rgba(241,236,224,0.55); }

.auth-side-mid { position: relative; z-index: 1; max-width: 420px; }
.auth-side-headline { font-size: 30px; font-weight: 800; line-height: 1.55; margin-bottom: 14px; }
.auth-side-sub { font-size: 14px; color: rgba(241,236,224,0.6); line-height: 1.9; }

.auth-side-features { display: flex; flex-direction: column; gap: 16px; margin-top: 32px; position: relative; z-index: 1; }
.auth-feature { display: flex; align-items: center; gap: 12px; font-size: 13px; color: rgba(241,236,224,0.75); }
.auth-feature-dot {
  width: 30px; height: 30px; border-radius: 9px; flex-shrink: 0;
  background: linear-gradient(135deg, rgba(200,150,31,0.25), rgba(240,198,95,0.15));
  display: flex; align-items: center; justify-content: center;
  color: #f0c65f;
}
.auth-side-bottom { position: relative; z-index: 1; font-size: 11px; color: rgba(241,236,224,0.35); }

.auth-form-col {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
}
.auth-form-col .auth-card { box-shadow: none; border: none; background: transparent; backdrop-filter: none; max-width: 380px; }

/* ---------- Settings panel (slide-over) ---------- */
.settings-backdrop {
  position: fixed; inset: 0;
  background: rgba(10,10,10,0.4);
  backdrop-filter: blur(3px);
  opacity: 0; visibility: hidden;
  transition: opacity .25s ease, visibility .25s ease;
  z-index: 90;
}
.settings-backdrop.show { opacity: 1; visibility: visible; }

.settings-panel {
  position: fixed;
  top: 0; right: 0;
  height: 100%;
  width: min(380px, 92vw);
  background: var(--panel);
  backdrop-filter: blur(26px) saturate(160%);
  -webkit-backdrop-filter: blur(26px) saturate(160%);
  border-left: 1px solid var(--panel-border);
  box-shadow: -20px 0 60px rgba(0,0,0,0.18), inset 1px 0 0 rgba(255,255,255,0.1);
  transform: translateX(100%);
  transition: transform .32s cubic-bezier(.22,1,.36,1);
  z-index: 91;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}
.settings-panel.show { transform: translateX(0); }

.settings-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 22px;
  border-bottom: 1px solid var(--panel-border);
}
.settings-title { font-size: 16px; font-weight: 800; }

.settings-body { padding: 22px; display: flex; flex-direction: column; gap: 22px; }

.settings-profile { display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; }
.settings-avatar-wrap { position: relative; width: 92px; height: 92px; }
.settings-avatar-wrap .avatar { width: 92px; height: 92px; font-size: 30px; }
.settings-avatar-edit {
  position: absolute; bottom: -2px; left: -2px;
  width: 30px; height: 30px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #1a1207;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--bg-2);
  cursor: pointer;
}

.settings-section-label {
  font-size: 11px;
  color: var(--text-dim);
  font-weight: 700;
  letter-spacing: .03em;
  margin-bottom: 8px;
  padding-right: 2px;
}

.settings-item {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--panel-border);
  background: var(--field-bg);
  cursor: pointer;
  transition: background .15s;
  font-size: 14px;
}
.settings-item:hover { background: var(--hover-bg); }
.settings-item.danger { color: var(--danger); }
.settings-item .settings-item-icon { flex-shrink: 0; opacity: .8; }
.settings-item .settings-item-right { margin-right: auto; color: var(--text-dim); font-size: 12px; }

/* ---------- Generic modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(10,10,10,0.45);
  backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
  z-index: 95;
  opacity: 0; visibility: hidden;
  transition: opacity .2s ease, visibility .2s ease;
  padding: 20px;
}
.modal-backdrop.show { opacity: 1; visibility: visible; }
.modal-box {
  background: var(--panel);
  backdrop-filter: blur(26px) saturate(160%);
  -webkit-backdrop-filter: blur(26px) saturate(160%);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  width: 100%; max-width: 440px;
  max-height: 86vh;
  display: flex; flex-direction: column;
  box-shadow: 0 30px 80px rgba(0,0,0,0.25), inset 0 1px 0 rgba(255,255,255,0.12);
  transform: scale(0.94) translateY(10px);
  transition: transform .25s cubic-bezier(.22,1,.36,1);
}
.modal-backdrop.show .modal-box { transform: scale(1) translateY(0); }
.modal-header { padding: 20px 22px; border-bottom: 1px solid var(--panel-border); display:flex; align-items:center; justify-content:space-between; }
.modal-title { font-size: 16px; font-weight: 800; }
.modal-body { padding: 20px 22px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 16px 22px; border-top: 1px solid var(--panel-border); display: flex; gap: 10px; }
.modal-footer .btn { width: auto; flex: 1; }

/* ---------- Member picker (group creation) ---------- */
.member-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .12s;
}
.member-row:hover { background: var(--hover-bg); }
.member-check {
  width: 20px; height: 20px;
  border-radius: 6px;
  border: 1.5px solid var(--panel-border);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background .15s, border-color .15s;
  color: transparent;
}
.member-row.selected .member-check {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent;
  color: #1a1207;
}
.member-name { font-size: 14px; font-weight: 600; flex: 1; }

/* ---------- FAB "new chat" button ---------- */
.fab {
  position: absolute;
  bottom: 18px; left: 18px;
  width: 52px; height: 52px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #1a1207;
  display: flex; align-items: center; justify-content: center;
  border: none; cursor: pointer;
  box-shadow: 0 10px 26px rgba(200,150,31,0.35);
  transition: transform .18s cubic-bezier(.34,1.56,.64,1);
  z-index: 5;
}
.fab:hover { transform: scale(1.07) rotate(90deg); }
.fab:active { transform: scale(0.95) rotate(90deg); }

/* ---------- New-chat choice menu ---------- */
.fab-menu {
  position: absolute;
  bottom: 78px; left: 18px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 6;
}
.fab-menu-item {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg-2);
  border: 1px solid var(--panel-border);
  padding: 10px 16px;
  border-radius: 30px;
  font-size: 13px; font-weight: 600;
  box-shadow: var(--shadow-card);
  cursor: pointer;
  white-space: nowrap;
  opacity: 0; transform: translateY(10px) scale(0.9);
  animation: popIn .25s cubic-bezier(.34,1.56,.64,1) forwards;
}
.fab-menu-item:nth-child(1) { animation-delay: .03s; }
.fab-menu-item:nth-child(2) { animation-delay: .09s; }

/* ---------- Group avatar (initials stack fallback) ---------- */
.avatar.group-avatar { background: linear-gradient(135deg, #6d7a8c, #3f4b5c); }

/* ---------- Reply preview / quote block ---------- */
.reply-bar {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-top: 1px solid var(--panel-border);
  background: var(--field-bg);
}
.reply-bar.show { display: flex; }
.reply-bar-strip { width: 3px; height: 30px; border-radius: 2px; background: var(--accent); flex-shrink: 0; }
.reply-bar-text { flex: 1; overflow: hidden; }
.reply-bar-name { font-size: 12px; font-weight: 700; color: var(--accent); }
.reply-bar-snippet { font-size: 12px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reply-bar-close { cursor: pointer; color: var(--text-dim); flex-shrink: 0; }

.msg-quote {
  border-right: 3px solid rgba(0,0,0,0.2);
  padding: 4px 8px;
  margin-bottom: 6px;
  border-radius: 8px;
  background: rgba(0,0,0,0.06);
  font-size: 12px;
  cursor: pointer;
}
.msg-row.in .msg-quote { border-right-color: rgba(0,0,0,0.35); background: rgba(0,0,0,0.08); }
.msg-quote-name { font-weight: 700; opacity: .85; }
.msg-quote-snippet { opacity: .7; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; max-width: 220px; }

/* ---------- Message action bar (reply / edit / delete on hover) ---------- */
.msg-actions {
  display: flex; align-items: center; gap: 2px;
  opacity: 0;
  transition: opacity .15s;
  margin: 0 4px;
  align-self: center;
}
.msg-row:hover .msg-actions { opacity: 1; }
.msg-action-btn {
  width: 24px; height: 24px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-dim);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.msg-action-btn:hover { background: var(--hover-bg); color: var(--text); }
.msg-action-btn.danger:hover { color: var(--danger); background: rgba(214,69,69,0.12); }
.msg-row { align-items: center; }
.msg-edited-tag { font-size: 10px; opacity: .6; margin-right: 4px; }

/* ---------- Voice message bubble ---------- */
.voice-bubble {
  display: flex; align-items: center; gap: 10px;
  min-width: 180px;
}
.voice-play-btn {
  width: 32px; height: 32px; border-radius: 50%;
  border: none; flex-shrink: 0;
  background: rgba(0,0,0,0.14);
  color: inherit;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: background .15s, transform .12s;
}
.voice-play-btn:active { transform: scale(0.92); }
.msg-row.in .voice-play-btn { background: rgba(0,0,0,0.2); }
.voice-wave {
  flex: 1; height: 22px;
  display: flex; align-items: center; gap: 2px;
}
.voice-wave span {
  width: 2px; border-radius: 1px;
  background: currentColor;
  opacity: .55;
  transform-origin: center;
  transition: opacity .2s;
}
.voice-wave.playing span {
  opacity: .95;
  animation: waveBounce 0.9s ease-in-out infinite;
}
@keyframes waveBounce {
  0%, 100% { transform: scaleY(0.4); }
  50% { transform: scaleY(1); }
}
.voice-duration { font-size: 11px; opacity: .75; flex-shrink: 0; }

/* ---------- Voice recorder in composer ---------- */
.recording-ui {
  display: none;
  align-items: center;
  gap: 12px;
  flex: 1;
  padding: 0 6px;
}
.recording-ui.show { display: flex; }
.recording-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--danger);
  animation: pulseRing 1.4s infinite;
  flex-shrink: 0;
}
.recording-time { font-size: 13px; font-weight: 700; color: var(--danger); font-family: monospace; }
.recording-hint { font-size: 12px; color: var(--text-dim); flex: 1; }

/* ---------- Skeleton loaders ---------- */
@keyframes shimmer {
  0% { background-position: -400px 0; }
  100% { background-position: 400px 0; }
}
.skeleton {
  background: linear-gradient(90deg, var(--panel-strong) 25%, var(--hover-bg) 37%, var(--panel-strong) 63%);
  background-size: 400px 100%;
  animation: shimmer 1.4s infinite linear;
  border-radius: 8px;
}
.skeleton-row { display: flex; align-items: center; gap: 12px; padding: 12px; }
.skeleton-avatar { width: 42px; height: 42px; border-radius: 50%; flex-shrink: 0; }
.skeleton-lines { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.skeleton-line { height: 10px; }

/* ---------- Group call grid ---------- */
.call-grid {
  display: grid;
  gap: 10px;
  width: min(90vw, 800px);
}
.call-grid.n1 { grid-template-columns: 1fr; }
.call-grid.n2 { grid-template-columns: 1fr 1fr; }
.call-grid.n3, .call-grid.n4 { grid-template-columns: 1fr 1fr; }
.call-tile {
  position: relative;
  background: #14151a;
  border-radius: 14px;
  overflow: hidden;
  aspect-ratio: 4/3;
  display: flex; align-items: center; justify-content: center;
}
.call-tile video { width: 100%; height: 100%; object-fit: cover; }
.call-tile-name {
  position: absolute; bottom: 8px; right: 10px;
  font-size: 12px; color: #fff;
  background: rgba(0,0,0,0.4);
  padding: 3px 10px; border-radius: 20px;
}
.call-tile-avatar-fallback {
  width: 64px; height: 64px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #1a1207; font-weight: 800; font-size: 22px;
  display: flex; align-items: center; justify-content: center;
}

/* ---------- Refined empty state (no emoji, subtle icon) ---------- */
.empty-illustration {
  width: 76px; height: 76px;
  border-radius: 22px;
  background: linear-gradient(135deg, var(--accent-soft), transparent);
  display: flex; align-items: center; justify-content: center;
  color: var(--accent);
  margin-bottom: 6px;
}

/* ---------- Group info drawer members list ---------- */
.group-member-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--panel-border);
}
.group-member-item:last-child { border-bottom: none; }
.group-member-name { font-weight: 600; font-size: 13px; flex: 1; }
.group-owner-tag { font-size: 10px; color: var(--accent); font-weight: 700; }
.group-member-remove {
  background: none; border: none; color: var(--text-dim); cursor: pointer;
  padding: 4px; border-radius: 6px;
}
.group-member-remove:hover { color: var(--danger); background: rgba(214,69,69,0.1); }

/* ---------- Small helper utility classes ---------- */
.flex-center { display: flex; align-items: center; justify-content: center; }
.mt-8 { margin-top: 8px; }
.text-center { text-align: center; }

/* ================================================================
   V3 — Emoji/GIF/Sticker pickers, profile modal, bio field, glass polish
   ================================================================ */

.field textarea {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--panel-border);
  background: var(--field-bg);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  line-height: 1.7;
  outline: none;
  resize: none;
  transition: border-color .15s, box-shadow .15s;
}
.field textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---------- Emoji / GIF / Sticker picker popover ---------- */
.picker-popover {
  position: absolute;
  bottom: 74px;
  left: 16px;
  width: min(340px, calc(100% - 32px));
  max-height: 360px;
  background: var(--panel);
  backdrop-filter: blur(26px) saturate(160%);
  -webkit-backdrop-filter: blur(26px) saturate(160%);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0,0,0,0.22), inset 0 1px 0 rgba(255,255,255,0.12);
  display: none;
  flex-direction: column;
  overflow: hidden;
  z-index: 20;
  opacity: 0;
  transform: translateY(8px) scale(0.97);
  transition: opacity .18s ease, transform .18s ease;
}
.picker-popover.show { display: flex; opacity: 1; transform: translateY(0) scale(1); }

.picker-tabs {
  display: flex;
  gap: 2px;
  padding: 8px 8px 0;
  border-bottom: 1px solid var(--panel-border);
  flex-shrink: 0;
}
.picker-tab {
  flex: 1;
  text-align: center;
  padding: 8px 6px;
  font-size: 14px;
  border-radius: 10px 10px 0 0;
  cursor: pointer;
  color: var(--text-dim);
  font-weight: 700;
  transition: background .15s, color .15s;
}
.picker-tab.active { background: var(--hover-bg); color: var(--accent); }

.picker-grid {
  padding: 10px;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  overflow-y: auto;
  flex: 1;
}
.picker-grid .emoji-item {
  font-size: 21px;
  text-align: center;
  padding: 5px 0;
  border-radius: 8px;
  cursor: pointer;
  transition: background .12s, transform .12s;
}
.picker-grid .emoji-item:hover { background: var(--hover-bg); transform: scale(1.15); }

.gif-search-row { padding: 8px 10px 0; flex-shrink: 0; }
.gif-search-row input {
  width: 100%;
  padding: 9px 12px;
  border-radius: 20px;
  border: 1px solid var(--panel-border);
  background: var(--field-bg);
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  outline: none;
}
.gif-search-row input:focus { border-color: var(--accent); }

.picker-grid.gif-grid {
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}
.gif-grid-item {
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  aspect-ratio: 1.4;
  background: var(--field-bg);
  transition: transform .12s;
}
.gif-grid-item:hover { transform: scale(1.03); }
.gif-grid-item img { width: 100%; height: 100%; object-fit: cover; display: block; }

.picker-grid.sticker-cols { grid-template-columns: repeat(4, 1fr); }
.sticker-item {
  font-size: 32px;
  text-align: center;
  padding: 8px 0;
  border-radius: 12px;
  cursor: pointer;
  transition: background .12s, transform .12s;
}
.sticker-item:hover { background: var(--hover-bg); transform: scale(1.1); }

.picker-empty-hint {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--text-dim);
  font-size: 12px;
  padding: 24px 10px;
}

/* ---------- Sticker message bubble (no background, like real stickers) ---------- */
.msg-row.sticker-row .bubble {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  backdrop-filter: none !important;
  padding: 0;
}
.sticker-bubble-emoji {
  font-size: 64px;
  line-height: 1;
  display: block;
}
.msg-row.sticker-row .bubble-time {
  text-align: center;
  margin-top: 2px;
  color: var(--text-dim);
}

/* ---------- Profile detail rows ---------- */
.profile-detail-row {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--panel-border);
  background: var(--field-bg);
  font-size: 13px;
  line-height: 1.8;
  color: var(--text);
  min-height: 20px;
}

/* ---------- Clickable member/peer avatar hint ---------- */
.avatar.clickable { cursor: pointer; transition: transform .15s; }
.avatar.clickable:hover { transform: scale(1.06); }

/* ---------- GIF badge on gif messages ---------- */
.gif-tag {
  position: absolute;
  bottom: 6px; left: 6px;
  background: rgba(0,0,0,0.55);
  color: #fff;
  font-size: 9px;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: 6px;
  letter-spacing: .03em;
}
.chat-img-wrap { position: relative; display: inline-block; }
