/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --tg-blue: #2AABEE;
  --tg-blue-dark: #1a8fcc;
  --tg-bg: #f0f2f5;
  --tg-sidebar: #ffffff;
  --tg-chat-bg: #e5ddd5;
  --tg-surface: #ffffff;
  --tg-ink: #1c1e21;
  --tg-muted: #6b7280;
  --tg-line: #e5e7eb;
  --tg-hover: #f3f4f6;
  --tg-active: #e8f4fd;
  --tg-msg-out: #dcf8c6;
  --tg-msg-in: #ffffff;
  --tg-green: #25d366;
  --tg-red: #ef4444;
  --tg-orange: #f59e0b;
  --tg-purple: #8b5cf6;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.08);
  --shadow-md: 0 4px 16px rgba(0,0,0,.12);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.18);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-msg: 18px;

  /* Font stacks */
  --font-en: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-hi: 'Hind', 'Noto Sans Devanagari', 'Mangal', sans-serif;
  --font-active: var(--font-en);   /* switched by JS via lang-hi class */
}

body.dark {
  --tg-bg: #0f1117;
  --tg-sidebar: #1c2128;
  --tg-chat-bg: #0d1117;
  --tg-surface: #1c2128;
  --tg-ink: #e6edf3;
  --tg-muted: #8b949e;
  --tg-line: #30363d;
  --tg-hover: #21262d;
  --tg-active: #1f3a4f;
  --tg-msg-out: #1a5c38;
  --tg-msg-in: #1c2128;
}

/* ── Hindi language overrides ── */
body.lang-hi {
  --font-active: var(--font-hi);
}

body.lang-hi .msg-text,
body.lang-hi .chat-name,
body.lang-hi .chat-preview,
body.lang-hi .chat-header-name,
body.lang-hi .chat-header-status,
body.lang-hi .msg-input,
body.lang-hi .auth-card h1,
body.lang-hi .auth-card p,
body.lang-hi .menu-item,
body.lang-hi .settings-item-label,
body.lang-hi .settings-item-sub,
body.lang-hi .tab-btn,
body.lang-hi button,
body.lang-hi input,
body.lang-hi textarea,
body.lang-hi label,
body.lang-hi span,
body.lang-hi div,
body.lang-hi p,
body.lang-hi h1,
body.lang-hi h2,
body.lang-hi h3 {
  font-family: var(--font-hi) !important;
  line-height: 1.65;   /* Devanagari needs a bit more line-height */
  letter-spacing: 0;   /* No letter-spacing for Devanagari */
}

/* Slightly larger base size for Hindi — glyphs are more complex */
body.lang-hi { font-size: 15px; }

body {
  font-family: var(--font-active);
  background: var(--bg);
  color: var(--tg-ink);
  height: 100dvh;
  overflow: hidden;
}

button { border: none; cursor: pointer; font: inherit; background: none; }
input, textarea { font: inherit; }
img { display: block; }

/* ===== AUTH SCREEN ===== */
.auth-screen {
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1a8fcc 0%, #2AABEE 50%, #4fc3f7 100%);
}

.auth-card {
  background: var(--tg-surface);
  border-radius: 20px;
  padding: 48px 40px;
  width: min(420px, 92vw);
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.auth-logo {
  width: 80px;
  height: 80px;
  background: var(--tg-blue);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 24px;
  font-size: 36px;
}

.auth-card h1 { font-size: 1.8rem; margin-bottom: 8px; color: var(--tg-ink); }
.auth-card p { color: var(--tg-muted); margin-bottom: 32px; font-size: 0.95rem; line-height: 1.6; }

.auth-tabs {
  display: flex;
  gap: 4px;
  background: var(--tg-bg);
  border-radius: var(--radius-sm);
  padding: 4px;
  margin-bottom: 24px;
}

.auth-tabs button {
  flex: 1;
  padding: 8px 16px;
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--tg-muted);
  transition: all .2s;
}

.auth-tabs button.active {
  background: var(--tg-surface);
  color: var(--tg-blue);
  box-shadow: var(--shadow-sm);
}

.auth-field {
  position: relative;
  margin-bottom: 16px;
  text-align: left;
}

.auth-field label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--tg-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.auth-field input {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid var(--tg-line);
  border-radius: var(--radius-sm);
  background: var(--tg-surface);
  color: var(--tg-ink);
  font-size: 1rem;
  transition: border-color .2s;
  outline: none;
}

.auth-field input:focus { border-color: var(--tg-blue); }

.btn-primary {
  width: 100%;
  padding: 14px;
  background: var(--tg-blue);
  color: #fff;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 1rem;
  transition: background .2s, transform .1s;
  margin-bottom: 12px;
}

.btn-primary:hover { background: var(--tg-blue-dark); }
.btn-primary:active { transform: scale(.98); }

.btn-ghost {
  width: 100%;
  padding: 12px;
  border: 2px solid var(--tg-line);
  border-radius: var(--radius-sm);
  font-weight: 600;
  color: var(--tg-muted);
  font-size: 0.9rem;
  transition: all .2s;
}

.btn-ghost:hover { border-color: var(--tg-blue); color: var(--tg-blue); }

.auth-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 16px 0;
  color: var(--tg-muted);
  font-size: 0.85rem;
}

.auth-divider::before, .auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--tg-line);
}

/* ===== MAIN APP LAYOUT ===== */
.app-layout {
  display: grid;
  grid-template-columns: 360px 1fr;
  height: 100dvh;
  overflow: hidden;
}

/* ===== SIDEBAR ===== */
.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--tg-sidebar);
  border-right: 1px solid var(--tg-line);
  height: 100dvh;
  overflow: hidden;
  position: relative;
  z-index: 10;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--tg-line);
  flex-shrink: 0;
}

.menu-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--tg-blue);
  font-size: 20px;
  transition: background .2s;
  flex-shrink: 0;
}

.menu-btn:hover { background: var(--tg-hover); }

.search-bar {
  flex: 1;
  position: relative;
}

.search-bar input {
  width: 100%;
  padding: 10px 16px 10px 40px;
  background: var(--tg-bg);
  border: none;
  border-radius: 20px;
  font-size: 0.9rem;
  color: var(--tg-ink);
  outline: none;
  transition: background .2s;
}

.search-bar input:focus { background: var(--tg-hover); }
.search-bar input::placeholder { color: var(--tg-muted); }

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--tg-muted);
  pointer-events: none;
  font-size: 16px;
}

/* ===== SIDEBAR MENU OVERLAY ===== */
.sidebar-menu {
  position: absolute;
  inset: 0;
  background: var(--tg-sidebar);
  z-index: 20;
  transform: translateX(-100%);
  transition: transform .3s cubic-bezier(.4,0,.2,1);
  display: flex;
  flex-direction: column;
}

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

.sidebar-menu-header {
  padding: 32px 24px 24px;
  background: var(--tg-blue);
  color: #fff;
}

.sidebar-menu-avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: rgba(255,255,255,.25);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 12px;
  overflow: hidden;
}

.sidebar-menu-avatar img { width: 100%; height: 100%; object-fit: cover; }
.sidebar-menu-name { font-size: 1.1rem; font-weight: 700; }
.sidebar-menu-phone { font-size: 0.85rem; opacity: .85; margin-top: 2px; }

.sidebar-menu-items { padding: 8px 0; flex: 1; overflow-y: auto; }

.menu-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 24px;
  cursor: pointer;
  transition: background .15s;
  color: var(--tg-ink);
  font-size: 0.95rem;
  font-weight: 500;
}

.menu-item:hover { background: var(--tg-hover); }
.menu-item .menu-icon { font-size: 20px; width: 24px; text-align: center; color: var(--tg-muted); }
.menu-item-badge {
  margin-left: auto;
  background: var(--tg-blue);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
}

/* ===== CHAT LIST ===== */
.chat-list { flex: 1; overflow-y: auto; }

.chat-list::-webkit-scrollbar { width: 4px; }
.chat-list::-webkit-scrollbar-thumb { background: var(--tg-line); border-radius: 4px; }

.chat-list-tabs {
  display: flex;
  gap: 4px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--tg-line);
  flex-shrink: 0;
}

.tab-btn {
  padding: 6px 14px;
  border-radius: 16px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--tg-muted);
  transition: all .2s;
}

.tab-btn.active {
  background: var(--tg-blue);
  color: #fff;
}

.tab-btn:hover:not(.active) { background: var(--tg-hover); }

.chat-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  cursor: pointer;
  transition: background .15s;
  position: relative;
}

.chat-item:hover { background: var(--tg-hover); }
.chat-item.active { background: var(--tg-active); }

.chat-avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 700;
  color: #fff;
  overflow: hidden;
  position: relative;
}

.chat-avatar img { width: 100%; height: 100%; object-fit: cover; }

.online-dot {
  position: absolute;
  bottom: 2px;
  right: 2px;
  width: 12px;
  height: 12px;
  background: var(--tg-green);
  border-radius: 50%;
  border: 2px solid var(--tg-sidebar);
}

.chat-info { flex: 1; min-width: 0; }

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

.chat-name {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--tg-ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-time {
  font-size: 0.75rem;
  color: var(--tg-muted);
  flex-shrink: 0;
  margin-left: 8px;
}

.chat-time.unread { color: var(--tg-blue); font-weight: 600; }

.chat-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
}

.chat-preview {
  font-size: 0.85rem;
  color: var(--tg-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.chat-preview.muted { font-style: italic; }

.unread-badge {
  background: var(--tg-blue);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.unread-badge.muted { background: var(--tg-muted); }

.check-marks { color: var(--tg-blue); font-size: 13px; margin-right: 2px; }
.check-marks.read { color: var(--tg-blue); }
.check-marks.sent { color: var(--tg-muted); }

.pinned-icon { color: var(--tg-muted); font-size: 11px; margin-left: 4px; }

/* ===== CHAT PANEL ===== */
.chat-panel {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  background: var(--tg-chat-bg);
  position: relative;
  overflow: hidden;
}

.chat-bg {
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='60' height='60'%3E%3Ccircle cx='30' cy='30' r='2' fill='%23aaa' opacity='.07'/%3E%3C/svg%3E");
  pointer-events: none;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--tg-surface);
  border-bottom: 1px solid var(--tg-line);
  box-shadow: var(--shadow-sm);
  z-index: 5;
  flex-shrink: 0;
}

.back-btn {
  display: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  align-items: center;
  justify-content: center;
  color: var(--tg-blue);
  font-size: 20px;
  transition: background .2s;
}

.back-btn:hover { background: var(--tg-hover); }

.chat-header-info { flex: 1; min-width: 0; cursor: pointer; }
.chat-header-name { font-weight: 700; font-size: 1rem; color: var(--tg-ink); }
.chat-header-status { font-size: 0.8rem; color: var(--tg-blue); }
.chat-header-status.offline { color: var(--tg-muted); }

.header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.header-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--tg-muted);
  font-size: 20px;
  transition: background .2s, color .2s;
}

.header-btn:hover { background: var(--tg-hover); color: var(--tg-ink); }
.header-btn.call { color: var(--tg-blue); }
.header-btn.video { color: var(--tg-blue); }

/* ===== MESSAGES AREA ===== */
.messages-area {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  position: relative;
  z-index: 1;
}

.messages-area::-webkit-scrollbar { width: 4px; }
.messages-area::-webkit-scrollbar-thumb { background: rgba(0,0,0,.15); border-radius: 4px; }

.msg-date-divider {
  text-align: center;
  margin: 12px 0;
}

.msg-date-divider span {
  background: rgba(0,0,0,.35);
  color: #fff;
  font-size: 0.78rem;
  padding: 4px 12px;
  border-radius: 12px;
  font-weight: 500;
}

body.dark .msg-date-divider span { background: rgba(255,255,255,.15); }

.msg-wrap {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  max-width: 72%;
  animation: msgIn .2s ease;
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg-wrap.out {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.msg-wrap.in { align-self: flex-start; }

.msg-sender-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
}

.msg-bubble {
  background: var(--tg-msg-in);
  border-radius: var(--radius-msg);
  padding: 8px 12px;
  max-width: 100%;
  box-shadow: var(--shadow-sm);
  position: relative;
  word-break: break-word;
}

.msg-wrap.out .msg-bubble { background: var(--tg-msg-out); border-bottom-right-radius: 4px; }
.msg-wrap.in .msg-bubble { border-bottom-left-radius: 4px; }

.msg-sender-name {
  font-size: 0.78rem;
  font-weight: 700;
  margin-bottom: 3px;
}

.msg-text { font-size: 0.93rem; line-height: 1.5; color: var(--tg-ink); }

.msg-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 3px;
}

.msg-time { font-size: 0.7rem; color: var(--tg-muted); white-space: nowrap; }
.msg-status { font-size: 12px; color: var(--tg-blue); }

/* Replied message */
.msg-reply {
  background: rgba(0,0,0,.07);
  border-left: 3px solid var(--tg-blue);
  border-radius: 6px;
  padding: 6px 10px;
  margin-bottom: 6px;
  font-size: 0.82rem;
}

.msg-reply-name { color: var(--tg-blue); font-weight: 600; margin-bottom: 2px; }
.msg-reply-text { color: var(--tg-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* File message */
.msg-file {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 0;
  min-width: 200px;
}

.file-icon-wrap {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--tg-blue);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
  color: #fff;
}

.file-details { flex: 1; min-width: 0; }
.file-name { font-weight: 600; font-size: 0.88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-size { font-size: 0.78rem; color: var(--tg-muted); }

/* Image message */
.msg-image {
  width: 240px;
  max-width: 100%;
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
}

.msg-image img { width: 100%; display: block; }

/* Voice message */
.msg-voice {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 220px;
  padding: 4px 0;
}

.voice-play-btn {
  width: 40px;
  height: 40px;
  background: var(--tg-blue);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 18px;
  flex-shrink: 0;
  cursor: pointer;
  transition: background .2s;
}

.voice-play-btn:hover { background: var(--tg-blue-dark); }

.voice-waveform {
  flex: 1;
  height: 32px;
  display: flex;
  align-items: center;
  gap: 2px;
}

.voice-bar {
  width: 3px;
  background: var(--tg-blue);
  border-radius: 3px;
  opacity: .6;
}

.voice-dur { font-size: 0.78rem; color: var(--tg-muted); flex-shrink: 0; }

/* Emoji reaction */
.msg-reaction {
  position: absolute;
  bottom: -10px;
  right: 8px;
  background: var(--tg-surface);
  border: 1px solid var(--tg-line);
  border-radius: 10px;
  padding: 2px 6px;
  font-size: 13px;
  box-shadow: var(--shadow-sm);
}

.msg-wrap.in .msg-reaction { right: auto; left: 8px; }

/* ===== TYPING INDICATOR ===== */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: var(--tg-msg-in);
  border-radius: var(--radius-msg);
  border-bottom-left-radius: 4px;
  width: fit-content;
  box-shadow: var(--shadow-sm);
}

.typing-dot {
  width: 8px;
  height: 8px;
  background: var(--tg-muted);
  border-radius: 50%;
  animation: typingBounce 1.2s infinite;
}

.typing-dot:nth-child(2) { animation-delay: .2s; }
.typing-dot:nth-child(3) { animation-delay: .4s; }

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}

/* ===== MESSAGE INPUT ===== */
.msg-input-area {
  padding: 10px 16px;
  background: var(--tg-surface);
  border-top: 1px solid var(--tg-line);
  z-index: 5;
  flex-shrink: 0;
}

.reply-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--tg-bg);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  border-left: 3px solid var(--tg-blue);
}

.reply-preview-content { flex: 1; min-width: 0; }
.reply-preview-name { font-size: 0.78rem; font-weight: 700; color: var(--tg-blue); }
.reply-preview-text { font-size: 0.82rem; color: var(--tg-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.reply-close-btn {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--tg-muted);
  font-size: 16px;
  transition: background .2s;
}

.reply-close-btn:hover { background: var(--tg-hover); }

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

.attach-btn, .emoji-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--tg-muted);
  font-size: 22px;
  transition: background .2s, color .2s;
  flex-shrink: 0;
}

.attach-btn:hover, .emoji-btn:hover { background: var(--tg-hover); color: var(--tg-blue); }

.msg-input-wrap {
  flex: 1;
  background: var(--tg-bg);
  border-radius: 22px;
  display: flex;
  align-items: flex-end;
  padding: 10px 16px;
  min-height: 44px;
  max-height: 160px;
  overflow: hidden;
}

.msg-input {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--tg-ink);
  font-size: 0.95rem;
  outline: none;
  resize: none;
  max-height: 120px;
  overflow-y: auto;
  line-height: 1.5;
}

.msg-input::placeholder { color: var(--tg-muted); }

.send-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--tg-blue);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  transition: background .2s, transform .1s;
  flex-shrink: 0;
}

.send-btn:hover { background: var(--tg-blue-dark); }
.send-btn:active { transform: scale(.92); }

.mic-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--tg-blue);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  transition: background .2s;
  flex-shrink: 0;
}

.mic-btn.recording { background: var(--tg-red); animation: pulse 1s infinite; }

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,.4); }
  50% { box-shadow: 0 0 0 10px rgba(239,68,68,0); }
}

/* ===== ATTACH MENU ===== */
.attach-menu {
  position: absolute;
  bottom: 70px;
  left: 60px;
  background: var(--tg-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 8px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  z-index: 50;
  animation: popUp .2s ease;
}

@keyframes popUp {
  from { opacity: 0; transform: scale(.9) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.attach-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .15s;
}

.attach-option:hover { background: var(--tg-hover); }

.attach-option-icon {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  color: #fff;
}

.attach-option span { font-size: 0.78rem; font-weight: 600; color: var(--tg-ink); }

/* ===== EMOJI PICKER ===== */
.emoji-picker {
  position: absolute;
  bottom: 70px;
  left: 16px;
  background: var(--tg-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 12px;
  z-index: 50;
  width: 320px;
  animation: popUp .2s ease;
}

.emoji-search {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--tg-line);
  border-radius: 20px;
  background: var(--tg-bg);
  color: var(--tg-ink);
  font-size: 0.9rem;
  outline: none;
  margin-bottom: 10px;
}

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  max-height: 200px;
  overflow-y: auto;
}

.emoji-btn-item {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  border-radius: 6px;
  cursor: pointer;
  transition: background .15s;
}

.emoji-btn-item:hover { background: var(--tg-hover); }

/* ===== CONTEXT MENU ===== */
.context-menu {
  position: fixed;
  background: var(--tg-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  z-index: 100;
  min-width: 180px;
  animation: popUp .15s ease;
}

.context-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--tg-ink);
  transition: background .15s;
}

.context-item:hover { background: var(--tg-hover); }
.context-item.danger { color: var(--tg-red); }
.context-item .ctx-icon { font-size: 16px; }

/* ===== EMPTY STATE ===== */
.empty-chat {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 16px;
  color: var(--tg-muted);
  padding: 24px;
  text-align: center;
}

.empty-chat-icon {
  width: 100px;
  height: 100px;
  background: rgba(42,171,238,.1);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 48px;
}

.empty-chat h2 { font-size: 1.4rem; color: var(--tg-ink); font-weight: 700; }
.empty-chat p { max-width: 320px; line-height: 1.6; }

/* ===== VOICE CALL MODAL ===== */
.call-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.85);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn .3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.call-card {
  background: linear-gradient(160deg, #1a3a5c 0%, #0d1b2a 100%);
  border-radius: 24px;
  padding: 48px 32px 32px;
  width: min(360px, 92vw);
  text-align: center;
  color: #fff;
  box-shadow: var(--shadow-lg);
}

.call-avatar-wrap {
  position: relative;
  width: 100px;
  height: 100px;
  margin: 0 auto 24px;
}

.call-avatar {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  font-weight: 700;
  color: #fff;
  overflow: hidden;
}

.call-ring {
  position: absolute;
  inset: -10px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,.3);
  animation: ringPulse 1.5s infinite;
}

.call-ring:nth-child(2) { inset: -20px; animation-delay: .5s; }

@keyframes ringPulse {
  0% { transform: scale(1); opacity: 1; }
  100% { transform: scale(1.3); opacity: 0; }
}

.call-name { font-size: 1.6rem; font-weight: 700; margin-bottom: 6px; }
.call-status { color: rgba(255,255,255,.7); font-size: 0.95rem; margin-bottom: 40px; }
.call-timer { font-size: 1.1rem; color: rgba(255,255,255,.8); margin-bottom: 40px; font-variant-numeric: tabular-nums; }

.call-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
}

.call-btn {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  color: #fff;
  transition: transform .2s;
}

.call-btn:hover { transform: scale(1.1); }
.call-btn:active { transform: scale(.92); }
.call-btn.end { background: var(--tg-red); font-size: 30px; }
.call-btn.mute { background: rgba(255,255,255,.2); }
.call-btn.mute.active { background: var(--tg-red); }
.call-btn.speaker { background: rgba(255,255,255,.2); }
.call-btn.speaker.active { background: var(--tg-blue); }
.call-btn.answer { background: var(--tg-green); font-size: 30px; }

/* Incoming call notification */
.incoming-call {
  position: fixed;
  top: 20px;
  right: 20px;
  background: var(--tg-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 16px;
  width: 300px;
  z-index: 200;
  animation: slideIn .3s ease;
}

@keyframes slideIn {
  from { transform: translateX(120%); }
  to { transform: translateX(0); }
}

.incoming-call-top {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.incoming-call-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 700;
  color: #fff;
}

.incoming-call-name { font-weight: 700; font-size: 0.95rem; }
.incoming-call-label { font-size: 0.8rem; color: var(--tg-muted); }

.incoming-call-btns {
  display: flex;
  gap: 10px;
}

.decline-btn {
  flex: 1;
  padding: 10px;
  background: var(--tg-red);
  color: #fff;
  border-radius: 22px;
  font-weight: 700;
  font-size: 0.9rem;
  transition: opacity .2s;
}

.accept-btn {
  flex: 1;
  padding: 10px;
  background: var(--tg-green);
  color: #fff;
  border-radius: 22px;
  font-weight: 700;
  font-size: 0.9rem;
  transition: opacity .2s;
}

.decline-btn:hover, .accept-btn:hover { opacity: .85; }

/* ===== PROFILE PANEL ===== */
.profile-panel {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 340px;
  background: var(--tg-surface);
  border-left: 1px solid var(--tg-line);
  z-index: 10;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform .3s cubic-bezier(.4,0,.2,1);
  overflow: hidden;
}

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

.profile-panel-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--tg-line);
  flex-shrink: 0;
}

.profile-panel-header h3 { font-size: 1rem; font-weight: 700; }

.profile-cover {
  height: 180px;
  background: linear-gradient(135deg, var(--tg-blue) 0%, #1a3a5c 100%);
  position: relative;
  flex-shrink: 0;
}

.profile-avatar-large {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  border: 3px solid var(--tg-surface);
  position: absolute;
  bottom: -30px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  font-weight: 700;
  color: #fff;
  overflow: hidden;
}

.profile-avatar-large img { width: 100%; height: 100%; object-fit: cover; }

.profile-info {
  padding: 44px 20px 20px;
  text-align: center;
  border-bottom: 1px solid var(--tg-line);
}

.profile-name { font-size: 1.2rem; font-weight: 700; margin-bottom: 4px; }
.profile-username { color: var(--tg-blue); font-size: 0.9rem; margin-bottom: 10px; }
.profile-bio { color: var(--tg-muted); font-size: 0.85rem; line-height: 1.5; }

.profile-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 14px 0;
  border-bottom: 1px solid var(--tg-line);
}

.profile-stat {
  text-align: center;
  padding: 8px;
}

.profile-stat strong { display: block; font-size: 1.1rem; font-weight: 700; }
.profile-stat span { font-size: 0.75rem; color: var(--tg-muted); }

.profile-actions {
  display: flex;
  gap: 8px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--tg-line);
}

.profile-action-btn {
  flex: 1;
  padding: 10px;
  border-radius: var(--radius-sm);
  background: var(--tg-active);
  color: var(--tg-blue);
  font-weight: 600;
  font-size: 0.85rem;
  text-align: center;
  transition: background .2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.profile-action-btn:hover { background: var(--tg-hover); }

.profile-media-grid {
  padding: 12px 16px;
  flex: 1;
  overflow-y: auto;
}

.profile-media-title {
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--tg-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 10px;
}

.media-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
}

.media-thumb {
  aspect-ratio: 1;
  border-radius: 4px;
  overflow: hidden;
  cursor: pointer;
  background: var(--tg-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
}

.media-thumb img { width: 100%; height: 100%; object-fit: cover; }
.media-thumb:hover { opacity: .85; }

/* ===== NOTIFICATIONS TOAST ===== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(0);
  background: var(--tg-ink);
  color: var(--tg-bg);
  padding: 12px 20px;
  border-radius: 20px;
  font-size: 0.9rem;
  font-weight: 500;
  z-index: 300;
  animation: toastShow .3s ease forwards;
  white-space: nowrap;
}

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

/* ===== SETTINGS PANEL ===== */
.settings-list { padding: 8px; }

.settings-section-title {
  padding: 14px 16px 8px;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--tg-blue);
  text-transform: uppercase;
  letter-spacing: .06em;
}

.settings-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 13px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .15s;
}

.settings-item:hover { background: var(--tg-hover); }

.settings-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.settings-item-label { font-weight: 600; font-size: 0.92rem; }
.settings-item-sub { font-size: 0.78rem; color: var(--tg-muted); margin-top: 1px; }
.settings-item-arrow { margin-left: auto; color: var(--tg-muted); font-size: 14px; }

/* Toggle switch */
.toggle {
  position: relative;
  width: 44px;
  height: 24px;
  margin-left: auto;
}

.toggle input { opacity: 0; width: 0; height: 0; }

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--tg-line);
  border-radius: 12px;
  cursor: pointer;
  transition: background .3s;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  background: #fff;
  border-radius: 50%;
  top: 3px;
  left: 3px;
  transition: transform .3s;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}

.toggle input:checked + .toggle-slider { background: var(--tg-blue); }
.toggle input:checked + .toggle-slider::before { transform: translateX(20px); }

/* ===== NEW CHAT MODAL ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 150;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn .2s ease;
}

.modal {
  background: var(--tg-surface);
  border-radius: 16px;
  width: min(480px, 94vw);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: popUp .25s ease;
}

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

.modal-header h3 { font-size: 1.05rem; font-weight: 700; }

.modal-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--tg-muted);
  font-size: 18px;
  transition: background .2s;
}

.modal-close:hover { background: var(--tg-hover); }

.modal-body { padding: 16px 20px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--tg-line); display: flex; gap: 10px; }

.modal-btn-primary {
  flex: 1;
  padding: 12px;
  background: var(--tg-blue);
  color: #fff;
  border-radius: var(--radius-sm);
  font-weight: 700;
  transition: background .2s;
}

.modal-btn-primary:hover { background: var(--tg-blue-dark); }

.modal-btn-secondary {
  flex: 1;
  padding: 12px;
  border: 2px solid var(--tg-line);
  color: var(--tg-muted);
  border-radius: var(--radius-sm);
  font-weight: 600;
  transition: all .2s;
}

.modal-btn-secondary:hover { border-color: var(--tg-blue); color: var(--tg-blue); }

.contact-select-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .15s;
}

.contact-select-item:hover { background: var(--tg-hover); }

.contact-select-item.selected { background: var(--tg-active); }

.contact-select-check {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid var(--tg-line);
  margin-left: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: #fff;
  transition: all .2s;
}

.contact-select-item.selected .contact-select-check {
  background: var(--tg-blue);
  border-color: var(--tg-blue);
}

/* ===== IMAGE VIEWER ===== */
.image-viewer {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.9);
  z-index: 250;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn .2s ease;
}

.image-viewer img {
  max-width: 90vw;
  max-height: 90vh;
  border-radius: 8px;
  object-fit: contain;
}

.image-viewer-close {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255,255,255,.15);
  color: #fff;
  font-size: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background .2s;
}

.image-viewer-close:hover { background: rgba(255,255,255,.25); }

/* ===== SCROLLBAR STYLES ===== */
* { scrollbar-width: thin; scrollbar-color: var(--tg-line) transparent; }

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  .app-layout { grid-template-columns: 1fr; }

  .sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    width: 100%;
    transform: translateX(0);
    z-index: 50;
  }

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

  .chat-panel {
    position: fixed;
    inset: 0;
    transform: translateX(100%);
    transition: transform .3s cubic-bezier(.4,0,.2,1);
    z-index: 50;
  }

  .chat-panel.active { transform: translateX(0); }

  .back-btn { display: flex; }

  .profile-panel {
    width: 100%;
    position: fixed;
    inset: 0;
  }
}

@media (max-width: 480px) {
  .call-card { padding: 36px 20px 24px; }
  .msg-wrap { max-width: 88%; }
}
