/* ============================================================
   MARATHA CHAT — WhatsApp Web-style UI
   ============================================================ */
* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --bg-app: #00a884;            /* WhatsApp green band behind panes */
  --pane-header: #f0f2f5;       /* pane headers */
  --panel-bg: #ffffff;
  --panel-item: #111b21;
  --text-primary: #111b21;
  --text-secondary: #667781;
  --text-tertiary: #8696a0;
  --border-light: #e9edef;
  --hover: #f5f6f6;
  --active-item: #f0f2f5;
  --bubble-out: #d9fdd3;
  --bubble-in: #ffffff;
  --wa-green: #00a884;
  --wa-green-dark: #008069;
  --wa-green-bright: #25d366;
  --tick-blue: #53bdeb;
  --shadow-bubble: 0 1px 0.5px rgba(11,20,26,.13);
  --shadow-menu: 0 2px 5px 0 rgba(11,20,26,.1), 0 1px 2px 0 rgba(11,20,26,.08);
}
html, body { height: 100%; overflow: hidden; }
body {
  font-family: "Segoe UI", "Helvetica Neue", Helvetica, "Lucida Grande", Arial, Ubuntu, Cantarell, "Fira Sans", sans-serif;
  background: var(--bg-app);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; }

#app { display: flex; height: 100vh; height: 100dvh; max-width: 1600px; margin: 0 auto; background: var(--panel-bg); box-shadow: 0 6px 18px rgba(0,0,0,.1); border-top: 4px solid var(--wa-green); }

/* ---------------- Login gate ---------------- */
.login-gate {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, #00a884 0%, #008069 100%);
  padding: 20px;
}
.login-gate .auth-card {
  width: 100%; max-width: 400px; background: #fff; border-radius: 16px;
  box-shadow: 0 20px 50px rgba(0,0,0,.25); overflow: hidden;
}
.login-gate .auth-header { background: #f0f2f5; text-align: center; padding: 28px 24px 22px; }
.login-gate .auth-header .logo { display: flex; justify-content: center; margin-bottom: 10px; }
.login-gate .auth-header h1 { font-size: 22px; color: var(--panel-item); margin-bottom: 6px; }
.login-gate .auth-header p { font-size: 13px; color: var(--text-secondary); line-height: 1.5; }
.login-gate .auth-body { padding: 22px 24px 20px; display: flex; flex-direction: column; gap: 12px; }
.login-gate .auth-body input {
  width: 100%; padding: 13px 14px; border: 1px solid #d8dfe3; border-radius: 10px;
  font-size: 15px; outline: none; transition: border-color .15s ease;
}
.login-gate .auth-body input:focus { border-color: var(--wa-green); }
.login-gate .btn-primary {
  background: var(--wa-green); color: #fff; border: none; border-radius: 10px;
  padding: 13px; font-size: 15px; font-weight: 600; cursor: pointer;
  transition: background-color .15s ease; width: 100%;
}
.login-gate .btn-primary:hover { background: var(--wa-green-dark); }
.login-gate .btn-primary:disabled { opacity: .6; cursor: default; }
.login-gate .gate-error { color: #d1453b; font-size: 13px; margin: 0; min-height: 0; }
.gate-recovery-link { background: none; border: none; color: var(--wa-green); font-size: 12.5px; text-decoration: underline; cursor: pointer; padding: 4px 0; }
.login-gate .auth-footer { text-align: center; font-size: 12px; color: var(--text-tertiary); padding: 14px; border-top: 1px solid var(--border-light); background: #fafafa; }

/* ---------------- Icons / buttons ---------------- */
.icon-btn {
  background: none; border: none; color: var(--text-secondary); cursor: pointer;
  width: 40px; height: 40px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background-color .15s ease, color .15s ease;
}
.icon-btn:hover { background: rgba(11,20,26,.06); color: var(--text-primary); }
.icon-btn svg { width: 22px; height: 22px; }

/* ---------------- Avatar ---------------- */
.avatar {
  width: 49px; height: 49px; border-radius: 50%;
  background: linear-gradient(135deg,#1ebea5,#00a884);
  color: #fff; font-size: 18px; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; user-select: none;
}
.avatar.small { width: 40px; height: 40px; font-size: 15px; }
.avatar.xl { width: 200px; height: 200px; font-size: 60px; }
.wa-logo { background: var(--wa-green); }

/* ============================================================
   SIDEBAR (left pane)
   ============================================================ */
.sidebar {
  width: 420px; max-width: 420px; min-width: 340px; height: 100vh;
  display: flex; flex-direction: column;
  background: var(--panel-bg); border-right: 1px solid var(--border-light);
  animation: slideIn .35s ease;
}
@keyframes slideIn { from { transform: translateX(-16px); opacity: 0; } to { transform: none; opacity: 1; } }

/* pane header (green band show-through convention) */
.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; background: var(--pane-header); height: 59px;
}
.sidebar-actions { display: flex; gap: 4px; }

/* search */
.search-wrap { padding: 8px 12px; background: var(--panel-bg); }
.search-box {
  display: flex; align-items: center; gap: 12px;
  background: var(--pane-header); border-radius: 8px;
  padding: 0 12px; height: 36px;
  transition: background .2s ease;
}
.search-box:focus-within { background: #fff; box-shadow: 0 1px 3px rgba(11,20,26,.08); }
.search-box input {
  flex: 1; background: transparent; border: none; outline: none;
  font-size: 14px; color: var(--text-primary); min-width: 0;
}
.search-box input::placeholder { color: var(--text-secondary); }

/* chat list */
.chat-list { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; scrollbar-width: thin; scrollbar-color: rgba(0,0,0,.2) transparent; }
.chat-list::-webkit-scrollbar { width: 6px; }
.chat-list::-webkit-scrollbar-thumb { background: rgba(0,0,0,.2); border-radius: 3px; }

.chat-item {
  display: flex; align-items: center; gap: 14px; height: 72px; padding: 0 12px;
  cursor: pointer; border-bottom: 1px solid var(--border-light);
  transition: background .12s ease;
}
.chat-item:hover { background: var(--hover); }
.chat-item.active { background: var(--active-item); }
.chat-item-info { flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: center; }
.chat-item-top { display: flex; justify-content: space-between; align-items: baseline; }
.chat-item-name { font-size: 16px; font-weight: 500; color: var(--panel-item); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item-time { font-size: 12px; color: var(--text-secondary); white-space: nowrap; }
.chat-item-bottom { display: flex; justify-content: space-between; align-items: center; margin-top: 3px; gap: 8px; }
.chat-item-msg { font-size: 13px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.chat-item-msg.me { color: var(--text-secondary); }
.chat-item-msg .you { color: var(--text-tertiary); }
.unread-badge {
  background: var(--wa-green); color: #fff; border: 3px solid var(--panel-bg);
  box-sizing: content-box; font-size: 12px; font-weight: 600; min-width: 22px; height: 22px;
  border-radius: 50%; display: flex; align-items: center; justify-content: center; padding: 0 2px;
}
.unread-single { background: var(--tick-blue); }

/* install banner (bottom of sidebar) */
.install-banner {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; background: #fff; border-top: 1px solid var(--border-light);
  box-shadow: 0 -2px 6px rgba(11,20,26,.04);
}
.install-banner img { border-radius: 12px; }
.install-text { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.install-text strong { font-size: 14px; color: var(--text-primary); }
.install-text span { font-size: 12px; color: var(--text-secondary); }
.install-cta {
  background: var(--wa-green); color: #fff; border: none; border-radius: 999px;
  font-size: 14px; font-weight: 600; padding: 8px 22px; cursor: pointer;
  transition: background .15s ease, transform .15s ease;
}
.install-cta:hover { background: var(--wa-green-dark); transform: translateY(-1px); }

/* ============================================================
   CHAT AREA (right pane)
   ============================================================ */
.chat-area { flex: 1; display: flex; flex-direction: column; min-width: 0; background: #efeae2; position: relative; }
.active-chat { flex: 1; display: flex; flex-direction: column; min-height: 0; position: relative; }

.pane-header {
  height: 59px; padding: 10px 16px; background: var(--pane-header);
  display: flex; align-items: center; gap: 10px;
}
.pane-header h4 { font-size: 16px; font-weight: 500; color: var(--panel-item); }
.chat-info { display: flex; align-items: center; gap: 15px; flex: 1; min-width: 0; cursor: pointer; }
.chat-info-text { min-width: 0; }
.subtitle { font-size: 13px; color: var(--wa-green); }
.subtitle.offline { color: var(--text-secondary); }
.back-btn { display: none; }
.chat-actions { display: flex; gap: 2px; }
.wa-btn { color: #25d366 !important; }
.wa-btn:hover { background: rgba(37,211,102,.12) !important; }

/* help-actions (WhatsApp + Call on the empty / welcome screen) */
.help-actions { flex-direction: column; gap: 10px; align-items: center; margin-top: 4px; }
.help-btn {
  display: inline-flex; align-items: center; gap: 10px;
  padding: 12px 22px; border: none; border-radius: 999px;
  font-size: 14px; font-weight: 600; cursor: pointer;
  transition: background .15s ease, transform .15s ease;
}
.help-btn:hover { transform: translateY(-1px); }
.wa-help { background: linear-gradient(135deg,#25d366,#00a884); color: #fff; }
.wa-help:hover { background: linear-gradient(135deg,#1fc354,#00997a); }
.call-help { background: #fff; color: var(--wa-green-dark); box-shadow: 0 1px 4px rgba(11,20,26,.12); }
.call-help:hover { background: #f0f2f5; }
.wa-number-label { font-size: 13px; color: var(--text-secondary); }

/* encryption toast */
.enc-toast {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; text-align: center;
}
.enc-toast span { font-size: 13px; color: var(--panel-item); line-height: 1.4; max-width: 460px; }

/* messages background - WhatsApp doodle pattern */
.messages {
  flex: 1; min-height: 0; overflow-y: auto; padding: 10px 6%;
  display: flex; flex-direction: column;
  overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  scrollbar-width: thin; scrollbar-color: rgba(0,0,0,.2) transparent;
  background-color: #efeae2;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120' viewBox='0 0 120 120'%3E%3Cg fill='none' stroke='%23d6d2ca' stroke-width='1'%3E%3Cpath d='M20 16c6 6 14 9 22 8'/%3E%3Ccircle cx='18' cy='30' r='4'/%3E%3Ccircle cx='92' cy='24' r='5'/%3E%3Ccircle cx='62' cy='14' r='3'/%3E%3Cpath d='M96 66c-9 2-15 8-18 16'/%3E%3Ccircle cx='28' cy='72' r='5'/%3E%3Ccircle cx='14' cy='58' r='3'/%3E%3Crect x='70' y='58' width='10' height='10' rx='3'/%3E%3Cpath d='M38 100c7-9 15-13 26-12 8 1 14-1 18-6'/%3E%3Ccircle cx='64' cy='96' r='4'/%3E%3Cpath d='M108 44c-6-2-12-2-17 2-6 4-9 9-8 15'/%3E%3Ccircle cx='104' cy='8' r='3'/%3E%3C/g%3E%3C/svg%3E");
  background-size: 340px 340px;
}
.messages::-webkit-scrollbar { width: 6px; }
.messages::-webkit-scrollbar-thumb { background: rgba(0,0,0,.2); border-radius: 3px; }

/* date divider */
.date-divider { text-align: center; margin: 14px 0; }
.date-divider span {
  display: inline-block; background: #fff; color: var(--text-secondary);
  font-size: 12.5px; padding: 6px 12px; border-radius: 8px;
  box-shadow: 0 1px 1px rgba(11,20,26,.08); font-weight: 500;
}

/* message bubbles */
.message {
  max-width: 65%; margin-bottom: 3px; position: relative; padding: 6px 7px 7px 9px;
  border-radius: 8px; box-shadow: var(--shadow-bubble);
  word-wrap: break-word; overflow-wrap: break-word;
  animation: msgIn .2s ease;
}
@keyframes msgIn { from { opacity: 0; transform: translateY(6px) scale(.98); } to { opacity: 1; transform: none; } }
.message.in { align-self: flex-start; background: var(--bubble-in); border-top-left-radius: 0; }
.message.out { align-self: flex-end; background: var(--bubble-out); border-top-right-radius: 0; }
.message.in::before {
  content: ''; position: absolute; top: 0; left: -8px;
  border-left: 8px solid transparent; border-top: 8px solid var(--bubble-in);
}
.message.out::after {
  content: ''; position: absolute; top: 0; right: -8px;
  border-right: 8px solid transparent; border-top: 8px solid var(--bubble-out);
}
.msg-text { font-size: 14.2px; line-height: 1.45; color: var(--text-primary); white-space: pre-wrap; }
.msg-meta {
  display: flex; align-items: center; justify-content: flex-end; gap: 4px;
  font-size: 11px; color: var(--text-secondary);
  float: right; margin-left: 10px; margin-top: 4px;
  user-select: none;
}
.msg-meta svg { width: 16px; height: 16px; fill: currentColor; }
.msg-meta .ticks { display: inline-flex; align-items: center; }
.msg-meta .ticks svg { fill: var(--text-secondary); }
.msg-meta .ticks.read svg { fill: var(--tick-blue); }
.msg-meta.read .ticks svg { fill: var(--tick-blue); }
.excerpt { font-size: 12.5px; color: var(--text-secondary); margin-top: 6px; font-style: italic; }

/* searchable highlight */
mark.hl { background: #fff3b0; color: inherit; border-radius: 2px; padding: 0 1px; }

/* typing indicator */
.typing-indicator {
  display: flex; align-items: center; gap: 8px; padding: 4px 6%;
  font-size: 13px; color: var(--text-secondary);
  animation: msgIn .2s ease;
}
.typing-bubble {
  background: #fff; border-radius: 8px; box-shadow: var(--shadow-bubble);
  padding: 9px 14px; display: inline-flex; align-items: center; gap: 6px;
}
.typing-dots { display: inline-flex; gap: 4px; }
.typing-dots span {
  width: 7px; height: 7px; background: var(--wa-green); border-radius: 50%;
  animation: typingBounce 1.2s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: .2s; }
.typing-dots span:nth-child(3) { animation-delay: .4s; }
@keyframes typingBounce { 0%,60%,100% { transform: translateY(0); } 30% { transform: translateY(-5px); } }

/* emoji panel */
.emoji-panel {
  background: var(--pane-header); border-top: 1px solid var(--border-light);
  padding: 12px; display: grid; grid-template-columns: repeat(auto-fill, minmax(46px, 1fr));
  gap: 6px; max-height: 240px; overflow-y: auto; animation: slideUp .2s ease;
}
@keyframes slideUp { from { transform: translateY(10px); opacity: 0; } to { transform: none; opacity: 1; } }
.emoji-panel button {
  font-size: 26px; border: none; background: none; cursor: pointer; padding: 8px;
  border-radius: 8px; transition: background .12s ease, transform .12s ease;
}
.emoji-panel button:hover { background: #fff; transform: scale(1.15); }

/* input area */
.input-area {
  display: flex; align-items: flex-end; gap: 8px; padding: 8px 12px;
  background: var(--pane-header); position: relative;
}
.input-shell {
  flex: 1; background: #fff; border-radius: 8px; padding: 9px 12px;
  display: flex; align-items: flex-end; box-shadow: var(--shadow-bubble);
}
.input-shell textarea {
  width: 100%; background: transparent; border: none; outline: none; resize: none;
  font-size: 15px; color: var(--text-primary); font-family: inherit;
  line-height: 1.4; max-height: 120px;
}
.input-shell textarea::placeholder { color: var(--text-secondary); }
.send-btn { color: var(--text-secondary); transition: color .15s ease, transform .12s ease; }
.send-btn.has-text { color: var(--wa-green); transform: rotate(-90deg); }
.send-btn.has-text:hover { background: rgba(0,168,132,.12); }
.emoji-btn { color: var(--text-tertiary); }

/* ============================================================
   OVERLAYS / MENU / PROFILE
   ============================================================ */
.overlay {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center;
  background: rgba(11,20,26,.55); -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
  animation: fadeIn .2s ease; padding: 20px;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.overlay-shell {
  width: 100%; max-width: 440px; max-height: 92vh; overflow-y: auto;
  display: flex; flex-direction: column; background: #fff;
  border-radius: 16px; box-shadow: 0 24px 60px rgba(0,0,0,.3);
}
.overlay-header {
  display: flex; align-items: center; gap: 12px; padding: 14px 18px;
  background: var(--wa-green); color: #fff;
  border-radius: 16px 16px 0 0; position: sticky; top: 0; z-index: 2;
}
.overlay-header .icon-btn { color: #fff; }
.overlay-header .icon-btn:hover { background: rgba(255,255,255,.15); }
.overlay-header h3 { font-size: 17px; font-weight: 600; }
.profile-hero {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 28px 20px 22px;
  background: linear-gradient(160deg, #e7f7f1 0%, #ffffff 100%);
  border-bottom: 1px solid var(--border-light);
}
.profile-body { padding: 8px 22px 24px; }
.profile-row { padding: 14px 2px; border-bottom: 1px solid var(--border-light); display: flex; flex-direction: column; gap: 4px; }
.profile-row:last-child { border-bottom: none; }
.profile-label { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--wa-green); font-weight: 600; }
.profile-value { font-size: 15.5px; color: var(--text-primary); word-break: break-word; }
.logout-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px; width: 100%;
  margin-top: 22px; padding: 13px 24px; border: none; border-radius: 12px;
  background: #fcf4f4; color: #d33d3a; font-size: 14px; font-weight: 600; cursor: pointer;
  transition: background .15s ease;
}
.logout-btn:hover { background: #f5e3e3; }

.dropdown-menu {
  position: absolute; top: 60px; right: 8px; z-index: 70;
  background: #fff; border-radius: 10px; box-shadow: var(--shadow-menu);
  overflow: hidden; min-width: 200px; animation: dropIn .15s ease;
}
@keyframes dropIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
.dropdown-menu a {
  display: block; padding: 12px 20px; font-size: 14px; color: var(--text-primary);
  cursor: pointer; transition: background .12s ease;
}
.dropdown-menu a:hover { background: var(--hover); }

/* empty / loading state */
.empty-state {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 18px; padding: 40px; text-align: center; background: var(--pane-header);
}
.empty-state h2 { font-size: 26px; font-weight: 500; color: var(--panel-item); }
.empty-state p { font-size: 14px; color: var(--text-secondary); max-width: 420px; line-height: 1.6; }
.brand-mark {
  width: 72px; height: 72px; border-radius: 20px; background: #fff;
  box-shadow: 0 4px 20px rgba(0,0,0,.12); display: flex; align-items: center; justify-content: center;
}
.brand-mark svg { width: 46px; height: 46px; }
.empty-state .conn-dots { display: flex; gap: 5px; margin-top: 6px; }
.empty-state .conn-dots span { width: 8px; height: 8px; border-radius: 50%; background: var(--wa-green); animation: bounce 1s infinite; }
.empty-state .conn-dots span:nth-child(2) { animation-delay: .15s; }
.empty-state .conn-dots span:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-6px); opacity: 1; } }

/* responsive */
@media (max-width: 896px) {
  .sidebar { width: 100%; max-width: none; min-width: 0; height: auto; }
  .chat-area { display: none; }
  .chat-area.show-chat {
    display: flex; position: fixed; left: 0; right: 0; top: 0; bottom: auto; z-index: 40;
    height: var(--vvh, 100dvh);
    animation: slideInRight .25s ease;
  }
  @keyframes slideInRight { from { transform: translateX(100%); } to { transform: none; } }
  .back-btn { display: inline-flex; }
  .messages { padding: 10px 4%; }
  .message { max-width: 78%; }
  .empty-state h2 { font-size: 20px; }
  .pane-header.chat-header { padding-top: calc(10px + env(safe-area-inset-top, 0px)); }
  .input-area { padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px)); }
}
@media (max-width: 480px) {
  .header-emoji-btn { display: none !important; }
  body.regular-user .chat-actions { gap: 0; }
  body.regular-user .chat-actions .icon-btn svg { width: 20px; height: 20px; }
  .input-area { padding: 6px 6px 8px; gap: 6px; }
  .input-shell { padding: 8px 10px; }
  .message { padding: 6px 6px 6px 8px; }
  .install-modal { padding: 22px 16px 16px; }
}
@media (min-width: 1200px) { .message { max-width: 55%; } }

/* reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ============================================================
   NEW: avatars as images, media bubbles, voice, groups, modal
   ============================================================ */
.avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.avatar.xl img { border-radius: 50%; }

/* message bubbles with attachments */
.msg-body { display: block; }
.msg-text { word-break: break-word; }
.att-img { display: block; border-radius: 8px; overflow: hidden; margin: 0 0 2px; cursor: pointer; max-width: 260px; }
.att-img img { display: block; max-width: 100%; max-height: 320px; object-fit: cover; border-radius: 8px; }
.att-video { display: block; max-width: 280px; margin: 0 0 2px; }
.att-video video { width: 100%; border-radius: 8px; max-height: 320px; }
.att-audio { display: block; max-width: 260px; margin: 0 0 2px; width: 100%; }
.voice-bubble { display: flex; align-items: center; gap: 10px; border: none; background: transparent; cursor: pointer; padding: 0; width: 100%; text-align: left; font-family: inherit; color: inherit; }
.v-ic { flex: 0 0 36px; width: 36px; height: 36px; border-radius: 50%; background: var(--wa-green); color: #fff; display: inline-flex; align-items: center; justify-content: center; transition: transform .15s ease, background-color .15s ease; }
.voice-bubble:hover .v-ic { transform: scale(1.06); }
.voice-bubble:active .v-ic, .voice-bubble.playing .v-ic { background: #008f72; }
.v-track { flex: 1; height: 3px; border-radius: 2px; background: rgba(17,27,33,.14); overflow: hidden; min-width: 56px; }
.v-progress { display: block; height: 100%; width: 100%; background: var(--wa-green); transform-origin: left center; transform: scaleX(0); will-change: transform; }
.v-t { flex: 0 0 auto; font-size: 11px; color: var(--text-tertiary); min-width: 30px; text-align: right; font-variant-numeric: tabular-nums; letter-spacing: .3px; }
.voice-bubble.loading .v-ic svg { animation: vpulse 1s ease-in-out infinite; }
@keyframes vpulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
.voice-bubble.playing .v-progress { transition: transform .25s linear; }
.voice-bubble.play-error { cursor: default; }
.voice-bubble.play-error .v-ic { background: var(--danger); }
.voice-html-audio { display: none; }
.att-caption { display: block; font-size: 14px; margin-top: 2px; word-break: break-word; }
.att-file {
  display: flex; align-items: center; gap: 10px; background: rgba(0,168,132,.08);
  border-radius: 8px; padding: 10px; cursor: pointer; max-width: 220px;
}
.file-meta { font-size: 12px; color: var(--text-secondary); min-width: 0; }
.file-meta strong { color: var(--text-primary); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sender-name { font-size: 11px; font-weight: 700; color: var(--wa-green-dark); margin-bottom: 2px; }

/* sidebar: group + multiple chats */
.group-avatar { background: linear-gradient(135deg,#65aadd,#027eb5); }
.group-tag {
  font-size: 9px; font-weight: 700; color: var(--wa-green-dark);
  background: rgba(0,168,132,.12); border-radius: 8px; padding: 1px 5px; vertical-align: 2px;
}
.chat-list-empty { padding: 30px 20px; text-align: center; color: var(--text-secondary); font-size: 13px; line-height: 1.6; }

/* attach + voice buttons */
.attach-btn { color: var(--text-tertiary); }
.voice-btn { color: var(--text-secondary); }
.voice-btn.recording {
  background: #ea4335 !important; color: #fff !important;
  animation: pulse-red 1.1s infinite;
}
@keyframes pulse-red {
  0%, 100% { box-shadow: 0 0 0 0 rgba(234,67,53,.5); }
  55% { box-shadow: 0 0 0 8px rgba(234,67,53,0); }
}

/* profile avatar change */
.avatar-change {
  position: absolute; bottom: -4px; right: -4px; width: 36px; height: 36px; border-radius: 50%;
  border: 3px solid #fff; background: var(--wa-green); color: #fff;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,.25);
}
.profile-hero { position: relative; }
.profile-hero .avatar.xl { position: relative; width: 112px; height: 112px; font-size: 40px; box-shadow: 0 6px 20px rgba(0,0,0,.14); }
.avatar.xl img { border-radius: 50%; width: 100%; height: 100%; object-fit: cover; }

/* group modal */
.modal-overlay {
  position: fixed; inset: 0; z-index: 80; background: rgba(17,27,33,.55);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal-box {
  width: 480px; max-width: 100%; max-height: 88vh; background: #fff; border-radius: 14px;
  overflow: hidden; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.3);
  animation: modalIn .18s ease;
}
@keyframes modalIn { from { transform: scale(.95) translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-header { display: flex; align-items: center; gap: 8px; padding: 10px 16px; background: var(--wa-green); }
.modal-header .icon-btn { color: #fff; }
.modal-header h3 { color: #fff; font-size: 17px; }
.modal-body { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.group-search-row { display: flex; align-items: center; gap: 8px; background: #f0f2f5; border-radius: 8px; padding: 8px 12px; }
.group-search-row input { flex: 1; background: transparent; border: none; outline: none; font-size: 14px; }
.group-members { max-height: 280px; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.group-member {
  display: flex; align-items: center; gap: 12px; padding: 8px 10px; border-radius: 8px;
  cursor: pointer; border-bottom: 1px solid var(--border-light);
}
.group-member:hover { background: var(--hover); }
.group-member.pick { background: rgba(0,168,132,.08); }
.group-member input { accent-color: var(--wa-green); width: 18px; height: 18px; }
.gm-info { flex: 1; font-size: 13px; min-width: 0; }
.gm-info strong { font-size: 14px; color: var(--text-primary); }
.gm-info small { color: var(--text-secondary); }
.modal-body .logout-btn { margin-top: 4px; justify-content: center; }

/* invite/share group link support in chat list created via search badge */
.share-note { font-size: 12px; color: var(--text-secondary); margin-top: 10px; text-align: center; line-height: 1.5; }

/* ============================================================
   SINGLE-CHAT MODE (regular users only — Maratha Helpdesk)
   ============================================================ */
body.regular-user .sidebar { display: none !important; }
body.regular-user #app { max-width: none; height: var(--vvh, 100dvh); }
body.regular-user .chat-area { width: 100%; max-width: 100%; }
body.regular-user .back-btn { display: none !important; }
body.regular-user .empty-state { padding: 16px; }
body.regular-user .messages { padding: 14px 5%; }
body.regular-user .message { max-width: 80%; }
@media (max-width: 896px) {
  body.regular-user .chat-area,
  body.regular-user .chat-area.show-chat {
    display: flex !important; position: relative; inset: auto; z-index: auto;
    animation: none;
  }
  body.regular-user .message { max-width: 86%; }
}

/* ============================================================
   INSTALL APP MODAL (auto popup)
   ============================================================ */
.install-modal-overlay {
  position: fixed; inset: 0; z-index: 320; background: rgba(17,27,33,.6);
  display: flex; align-items: center; justify-content: center; padding: 20px;
  animation: fadeIn .2s ease;
}
.install-modal {
  width: 360px; max-width: 100%; background: #fff; border-radius: 18px;
  padding: 28px 24px 20px; text-align: center;
  box-shadow: 0 24px 70px rgba(0,0,0,.35);
  animation: modalIn .22s ease;
}
.install-modal img { border-radius: 18px; box-shadow: 0 6px 20px rgba(0,0,0,.15); }
.install-modal h3 { font-size: 20px; color: var(--text-primary); margin: 16px 0 6px; }
.install-modal p { font-size: 14px; color: var(--text-secondary); line-height: 1.55; margin-bottom: 16px; }
.install-feat { display: flex; justify-content: center; gap: 6px; flex-wrap: wrap; margin-bottom: 20px; }
.install-feat span { font-size: 11.5px; color: #41525d; background: #f0f2f5; padding: 5px 11px; border-radius: 20px; }
.install-modal-actions { display: flex; gap: 10px; }
.install-skip {
  flex: 1; padding: 13px; border: 1.5px solid #d8dfe3; background: #fff; color: #667781;
  border-radius: 24px; font-size: 14px; font-weight: 600; cursor: pointer;
  transition: background .15s ease;
}
.install-skip:hover { background: #f5f6f6; }
.install-now {
  flex: 1; padding: 13px; border: none; background: var(--wa-green); color: #fff;
  border-radius: 24px; font-size: 14px; font-weight: 700; cursor: pointer;
  box-shadow: 0 3px 10px rgba(0,168,132,.35);
  transition: background .15s ease, transform .15s ease;
}
.install-now:hover { background: var(--wa-green-dark); transform: translateY(-1px); }

/* send error toast */
#send-error {
  position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%);
  z-index: 200; background: #2b3941; color: #fff; font-size: 13px;
  padding: 10px 16px; border-radius: 20px; box-shadow: 0 4px 16px rgba(0,0,0,.3);
  max-width: 85%; text-align: center; display: none; animation: msgIn .2s ease;
}
/* "New messages" floating chip above the composer */
.new-msg-chip {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: calc(10px + 62px); z-index: 25;
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--wa-green); color: #fff; border: none; border-radius: 999px;
  font-size: 12.5px; font-weight: 600; padding: 9px 16px; cursor: pointer;
  box-shadow: 0 4px 16px rgba(11,20,26,.24);
  animation: msgIn .18s ease-out;
}
.new-msg-chip:hover { background: var(--wa-green-dark); }
@media (max-width: 480px) {
  .input-area { padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px)); }
}
/* ---- Helpdesk profile link rows ---- */
.hd-link-row { flex-direction: row !important; align-items: center; justify-content: space-between; gap: 10px; border-radius: 10px; padding: 12px 10px; transition: background .15s; }
.hd-link-row:hover { background: #f0f4f2; }
#hd-panel-links .hd-link-row + .hd-link-row { margin-top: 0; }

/* ---- Talk to an agent ---- */
.agent-connect-body { padding: 20px 22px 26px; }
.agent-connect-hint { font-size: 13.5px; color: var(--text-secondary, #667781); margin-bottom: 14px; line-height: 1.45; }
.agent-connect-input { display: flex; gap: 8px; }
.agent-connect-input input { flex: 1; padding: 12px 14px; border: 1px solid var(--border-light); border-radius: 10px; font-size: 14px; outline: none; transition: border-color .15s; }
.agent-connect-input input:focus { border-color: var(--wa-green); }
.btn-connect { background: var(--wa-green); color: #fff; border: none; border-radius: 10px; padding: 0 18px; font-size: 14px; font-weight: 600; cursor: pointer; transition: filter .15s; }
.btn-connect:hover { filter: brightness(.95); }
.btn-connect.sm { padding: 9px 16px; }
.btn-connect:disabled { opacity: .5; cursor: not-allowed; }
.agent-connect-error { color: #d33d3a; font-size: 13px; margin-top: 8px; min-height: 18px; }
.saved-agents-title { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-secondary, #667781); font-weight: 700; margin: 18px 0 10px; }
.saved-agents-list { display: flex; flex-direction: column; gap: 8px; }
.saved-agent-row { display: flex; align-items: center; justify-content: space-between; padding: 11px 13px; border: 1px solid var(--border-light); border-radius: 12px; }
.saved-agent-info { display: flex; flex-direction: column; gap: 2px; }
.saved-agent-name { font-size: 14.5px; font-weight: 600; color: var(--text-primary); }
.saved-agent-status { font-size: 12px; }
.saved-agent-status.on { color: var(--wa-green); }
.saved-agent-status.off { color: #b93c30; }

/* ---- Overlay: full-screen on small phones ---- */
@media (max-width: 600px) {
  .overlay { padding: 0; align-items: stretch; }
  .overlay-shell { max-width: 100%; max-height: 100%; height: 100%; border-radius: 0; }
  .overlay-header { border-radius: 0; }
}

/* ---- Persistent install ribbon ---- */
.install-topbar { position: fixed; top: 0; left: 0; right: 0; z-index: 9000; display: flex; align-items: center; gap: 10px; padding: 8px 14px; background: var(--wa-green); color: #fff; font-size: 13.5px; box-shadow: 0 2px 10px rgba(0,0,0,.18); }
.install-topbar img { border-radius: 6px; flex-shrink: 0; }
.install-topbar span { flex: 1; min-width: 0; line-height: 1.3; }
.install-topbar button { background: #fff; color: var(--wa-green); border: none; border-radius: 18px; padding: 7px 18px; font-weight: 700; font-size: 13px; cursor: pointer; flex-shrink: 0; }
.install-topbar button:hover { filter: brightness(.97); }
.install-topbar .install-topbar-x { background: rgba(255,255,255,.18); color: #fff; min-width: 26px; width: 26px; height: 26px; padding: 0; border-radius: 50%; font-size: 13px; line-height: 1; }
.install-topbar .install-topbar-x:hover { background: rgba(255,255,255,.32); filter: none; }
body.has-install-topbar #app { height: calc(var(--vvh, 100vh) - 46px); margin-top: 46px; }
body.has-install-topbar .login-gate { top: 46px; height: calc(100% - 46px); }
@media (max-width: 600px) {
  .install-topbar { font-size: 12.5px; padding: 7px 10px; gap: 8px; }
  .install-topbar button { padding: 6px 14px; }
}

/* ---- Client toast ---- */
.client-toast { position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(20px); background: #111b21; color: #fff; padding: 12px 20px; border-radius: 24px; font-size: 14px; box-shadow: 0 6px 24px rgba(0,0,0,.28); opacity: 0; pointer-events: none; transition: all .25s; z-index: 400; max-width: 90%; text-align: center; }
.client-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---- Profile security (saved numbers) ---- */
.profile-sec { border-top: 1px solid var(--border-light); margin-top: 10px; padding-top: 12px; display: flex; flex-direction: column; gap: 9px; width: 100%; }
.profile-sec-head { display: flex; align-items: flex-start; gap: 10px; }
.profile-sec-icon { width: 38px; height: 38px; flex-shrink: 0; border-radius: 50%; background: rgba(0,168,132,.12); color: var(--wa-green); display: flex; align-items: center; justify-content: center; }
.profile-sec-head > div:last-child { min-width: 0; }
.profile-sec-title { font-size: 13px; font-weight: 700; color: var(--text-primary); }
.profile-sec-intro { font-size: 12px; color: var(--text-tertiary); line-height: 1.45; }
.profile-sec-numbers { display: flex; flex-direction: column; gap: 6px; }
.profile-sec-num { display: flex; align-items: center; justify-content: space-between; gap: 8px; background: #f0f2f5; border-radius: 8px; padding: 7px 10px; font-size: 13.5px; color: var(--text-primary); }
.profile-sec-empty { font-size: 12.5px; color: var(--text-tertiary); }
.profile-sec-add { display: flex; gap: 8px; }
.profile-sec-add input { flex: 1; min-width: 0; border: 1px solid var(--border-light); border-radius: 8px; padding: 8px 10px; font-size: 13.5px; }
.profile-sec-add input:focus { outline: none; border-color: var(--wa-green); }
.btn-x-ghost { background: transparent; border: none; color: var(--text-secondary); font-size: 13px; cursor: pointer; padding: 2px 6px; border-radius: 6px; }
.btn-x-ghost:hover { background: rgba(0,0,0,.06); }
.profile-sec-msg { font-size: 12.5px; color: var(--text-tertiary); min-height: 0; }

/* ---- Gate: confirm-it's-you (new device) ---- */
.gate-verify { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; padding: 18px 16px; margin-bottom: 4px; border-radius: 14px; background: rgba(0,168,132,.06); border: 1px solid rgba(0,168,132,.22); }
.gate-verify-icon { width: 52px; height: 52px; border-radius: 50%; background: rgba(0,168,132,.14); display: flex; align-items: center; justify-content: center; }
.gate-verify-title { font-size: 16px; font-weight: 700; color: #111b21; }
.gate-verify-sub { font-size: 13px; color: var(--text-tertiary); line-height: 1.5; }
.gate-verify input { width: 100%; border: 1px solid var(--border-light); border-radius: 10px; padding: 11px 12px; font-size: 14px; text-align: center; background: #fff; }
.gate-verify input:focus { outline: none; border-color: var(--wa-green); box-shadow: 0 0 0 2px rgba(0,168,132,.15); }
/* ============ UI REFINEMENT (additive layer) ============ */
:focus-visible { outline: 2px solid var(--wa-green); outline-offset: 2px; }
.chat-item.active { background: var(--active-item); box-shadow: inset 3px 0 0 var(--wa-green); }
.chat-item .chat-item-name { letter-spacing: -.1px; }
.composer-input { transition: border-color .15s ease, box-shadow .15s ease; }
.composer-input:focus-within { border-color: var(--wa-green); box-shadow: 0 0 0 3px rgba(0,168,132,.14); background: #fff; }
.composer .send-btn { box-shadow: 0 1px 2px rgba(0,105,83,.25); }
.composer .send-btn:hover { box-shadow: 0 2px 7px rgba(0,105,83,.3); }
.pane-header { background-image: linear-gradient(180deg, #ffffff 0%, #f0f2f5 100%); }
.sidebar-header { background-image: linear-gradient(180deg, #ffffff 0%, #f0f2f5 100%); }
#app { border-top: 3px solid var(--wa-green); }
.empty-state .brand-mark svg { filter: drop-shadow(0 8px 20px rgba(0,168,132,.28)); }
.search-box { border-radius: 10px; }
.login-gate.auth-card input:focus { box-shadow: 0 0 0 3px rgba(0,168,132,.14); }

/* ==================================================================
   AUTH SCREEN — polish + +91 OTP flow
   ================================================================== */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

.login-gate .auth-card { border-radius: 18px; box-shadow: 0 24px 60px rgba(0,0,0,.28), 0 2px 8px rgba(0,0,0,.12); }
.login-gate .auth-header { padding: 30px 24px 22px; background: linear-gradient(180deg, #ffffff 0%, #f0f2f5 100%); }
.login-gate .auth-header h1 { font-size: 21px; letter-spacing: -.2px; }
.login-gate .auth-body { gap: 14px; }
.login-gate .auth-body input { transition: border-color .15s ease, box-shadow .15s ease; }
.login-gate .auth-body input:focus-visible { outline: none; border-color: var(--wa-green); box-shadow: 0 0 0 3px rgba(0,168,132,.16); }
.login-gate .btn-primary { position: relative; min-height: 48px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; box-shadow: 0 1px 2px rgba(0,105,83,.25); transition: background-color .15s ease, transform .1s ease, box-shadow .15s ease; }
.login-gate .btn-primary:hover:not(:disabled) { box-shadow: 0 3px 10px rgba(0,105,83,.3); }
.login-gate .btn-primary:active:not(:disabled) { transform: translateY(1px); }
.login-gate .btn-primary:focus-visible { outline: 3px solid rgba(0,168,132,.4); outline-offset: 2px; }
.login-gate .btn-primary:disabled { opacity: .7; cursor: not-allowed; }
.login-gate .btn-primary .btn-spinner { display: none; width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.45); border-top-color: #fff; border-radius: 50%; animation: gate-spin .7s linear infinite; }
.login-gate .btn-primary.is-loading .btn-spinner { display: inline-block; }
@keyframes gate-spin { to { transform: rotate(360deg); } }
.login-gate .gate-error { min-height: 18px; display: flex; align-items: flex-start; gap: 6px; line-height: 1.4; }
.login-gate .gate-error:not(:empty)::before { content: "!"; flex: none; width: 16px; height: 16px; border-radius: 50%; background: #d1453b; color: #fff; font-size: 11px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; margin-top: 1px; }
.login-gate .gate-error.is-success { color: var(--wa-green-dark); }
.login-gate .gate-error.is-success::before { content: "✓"; background: var(--wa-green); }

/* step transitions */
.otp-step { animation: gate-fade .18s ease-out; }
@keyframes gate-fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .otp-step, .login-gate .btn-primary .btn-spinner { animation: none; } }

/* +91 | number */
.phone-field { display: flex; width: 100%; border: 1px solid #d8dfe3; border-radius: 12px; overflow: hidden; background: #fff; transition: border-color .15s ease, box-shadow .15s ease; }
.phone-field:focus-within { border-color: var(--wa-green); box-shadow: 0 0 0 3px rgba(0,168,132,.16); }
.phone-field .phone-cc { flex: none; display: inline-flex; align-items: center; gap: 6px; padding: 0 12px 0 14px; background: #f0f2f5; color: #111b21; font-weight: 600; font-size: 15px; border-right: 1px solid #d8dfe3; letter-spacing: .2px; user-select: none; }
.gate-verify .phone-field input,
.login-gate .auth-body .phone-field input { border: none !important; border-radius: 0 !important; box-shadow: none !important; padding: 13px 14px; font-size: 17px; letter-spacing: 1.5px; flex: 1; min-width: 0; font-variant-numeric: tabular-nums; }
.gate-verify .phone-field input:focus { box-shadow: none; }

/* OTP boxes */
.otp-boxes { display: flex; gap: 8px; justify-content: center; width: 100%; }
.gate-verify .otp-boxes input,
.login-gate .auth-body .otp-boxes input { width: 44px; height: 52px; padding: 0; text-align: center; font-size: 22px; font-weight: 600; border-radius: 10px; font-variant-numeric: tabular-nums; caret-color: var(--wa-green); }
.otp-boxes input.is-filled { border-color: var(--wa-green); background: #f2fbf8; }
.otp-boxes input.is-error { border-color: #d1453b; }
.otp-actions { display: flex; align-items: center; justify-content: center; gap: 6px; flex-wrap: wrap; margin-top: 2px; }
.otp-actions .gate-recovery-link { text-decoration: none; font-weight: 600; }
.otp-actions .gate-recovery-link:disabled { color: var(--text-tertiary); cursor: default; font-weight: 500; }
.otp-actions .gate-recovery-link:not(:disabled):hover { text-decoration: underline; }
.otp-actions .gate-recovery-link:focus-visible { outline: 2px solid rgba(0,168,132,.5); outline-offset: 2px; border-radius: 4px; }
.otp-dot { color: var(--text-tertiary); }

@media (max-width: 360px) {
  .login-gate { padding: 12px; }
  .login-gate .auth-header { padding: 22px 18px 16px; }
  .login-gate .auth-body { padding: 18px 16px 16px; }
  .gate-verify .otp-boxes input, .login-gate .auth-body .otp-boxes input { width: 38px; height: 46px; font-size: 19px; }
  .otp-boxes { gap: 6px; }
  .phone-field .phone-cc { padding: 0 10px; font-size: 14px; }
}

/* ==================================================================
   UX POLISH — accessibility, long-text safety, states (additive)
   ================================================================== */
/* Keyboard users get a visible ring; mouse users do not (no :focus noise). */
.icon-btn:focus-visible, .send-btn:focus-visible, .conv-item:focus-visible, .menu-item:focus-visible,
.attach-btn:focus-visible, button:focus-visible { outline: 3px solid rgba(0,168,132,.45); outline-offset: 2px; border-radius: 8px; }
input:focus-visible, textarea:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(0,168,132,.18); }

/* Unbroken strings (long URLs, tokens) must never widen a bubble or the pane. */
.message { min-width: 0; }
.msg-text, .att-caption { overflow-wrap: anywhere; word-break: break-word; }
.msg-text a { color: var(--wa-green-dark); text-decoration: underline; overflow-wrap: anywhere; }
.messages-list, .chat-messages, #messages { overscroll-behavior: contain; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { .messages-list, .chat-messages, #messages { scroll-behavior: auto; } }

/* Consistent disabled + busy affordances */
button:disabled, .btn-primary:disabled, .send-btn:disabled { cursor: not-allowed; }
[aria-busy="true"] { pointer-events: none; opacity: .75; }

/* Lightweight loading skeleton for lists */
.skeleton-row { display: flex; gap: 12px; align-items: center; padding: 12px 16px; }
.skeleton-row .sk-avatar { width: 46px; height: 46px; border-radius: 50%; flex: none; }
.skeleton-row .sk-lines { flex: 1; display: flex; flex-direction: column; gap: 8px; }
.skeleton-row .sk-line { height: 11px; border-radius: 6px; }
.skeleton-row .sk-line.short { width: 55%; }
.sk-avatar, .sk-line { background: linear-gradient(90deg, #eef1f3 25%, #f6f8f9 37%, #eef1f3 63%); background-size: 400% 100%; animation: sk-shimmer 1.3s ease-in-out infinite; }
@keyframes sk-shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }
@media (prefers-reduced-motion: reduce) { .sk-avatar, .sk-line { animation: none; } }

/* Tap targets on phones */
@media (max-width: 480px) {
  .icon-btn, .send-btn { min-width: 44px; min-height: 44px; }
  .message { max-width: 86%; }
}
