/* ── Reset & vars ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:         #0f0f10;
  --bg2:        #17171a;
  --surface:    #1e1e23;
  --surface2:   #26262d;
  --border:     #2c2c35;
  --accent:     #6c8fff;
  --accent-dim: #3a52b0;
  --danger:     #ff5c5c;
  --text:       #e9e9ec;
  --text-2:     #9898a8;
  --text-3:     #5c5c6e;
  --bubble-me:  #1e3566;
  --bubble-you: #232328;
  --r:          14px;
  --sidebar-w:  300px;
}

[data-theme="light"] {
  --bg:         #f0f2f5;
  --bg2:        #ffffff;
  --surface:    #ffffff;
  --surface2:   #f0f2f5;
  --border:     #dde1e7;
  --accent:     #4a6cf7;
  --accent-dim: #3a5ad9;
  --danger:     #e53e3e;
  --text:       #1a1a2e;
  --text-2:     #6b7280;
  --text-3:     #9ca3af;
  --bubble-me:  #d6e4ff;
  --bubble-you: #ffffff;
}

html, body { height: 100%; background: var(--bg); color: var(--text);
             font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
             font-size: 15px; line-height: 1.45; overflow: hidden; }
/* Smooth theme transition */
body, #app, #sidebar, #chat-area, .chat-header, .chat-footer,
.conv-item, .bubble:not(.msg-pending), #action-sheet-panel, .modal-inner {
  transition: background-color .25s ease, border-color .25s ease, color .25s ease;
}

.hidden { display: none !important; }

/* ── Scrollbar ───────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ── Avatar ──────────────────────────────────────────────────────────────── */
.avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px; color: #fff;
  flex-shrink: 0; user-select: none;
}

/* ── Auth ────────────────────────────────────────────────────────────────── */
#auth-screen {
  display: flex; align-items: center; justify-content: center;
  height: 100%; padding: 20px;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 40px 32px 36px;
  width: 100%; max-width: 380px;
  text-align: center;
}

.auth-logo { font-size: 2.8rem; margin-bottom: 6px; }
.auth-card h1 { font-size: 1.8rem; font-weight: 800; letter-spacing: -.5px; }
.auth-sub { color: var(--text-2); margin: 6px 0 24px; font-size: 14px; }

.tabs {
  display: flex; background: var(--bg2); border-radius: 10px;
  padding: 3px; margin-bottom: 20px;
}
.tab {
  flex: 1; border: none; background: none; color: var(--text-2);
  padding: 8px; border-radius: 8px; cursor: pointer;
  font-size: 14px; font-weight: 500; transition: all .18s;
}
.tab.active { background: var(--surface2); color: var(--text); }

.field {
  display: block; width: 100%;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 10px; padding: 11px 14px;
  color: var(--text); font-size: 15px; outline: none;
  margin-bottom: 10px; transition: border-color .2s;
}
.field:focus { border-color: var(--accent); }

.pw-wrap { position: relative; }
.pw-wrap .field { padding-right: 42px; }
.pw-eye {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  background: none; border: none; padding: 4px; cursor: pointer;
  color: var(--text-2); line-height: 0;
  transition: color .15s;
}
.pw-eye:hover { color: var(--text); }

.auth-error {
  background: rgba(255,92,92,.12); border: 1px solid rgba(255,92,92,.3);
  color: #ff8585; border-radius: 8px;
  font-size: 13px; padding: 8px 12px; margin-bottom: 10px; text-align: left;
}

.btn-primary {
  display: block; width: 100%;
  background: var(--accent); color: #fff;
  border: none; border-radius: 10px;
  padding: 12px; font-size: 15px; font-weight: 600;
  cursor: pointer; transition: background .18s, transform .1s;
}
.btn-primary:hover  { background: var(--accent-dim); }
.btn-primary:active { transform: scale(.98); }

/* ── App layout ──────────────────────────────────────────────────────────── */
#app {
  display: flex;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 100dvh; /* JS overrides this via visualViewport on keyboard open */
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  flex-shrink: 0;
}

.sidebar-header {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 14px 12px;
  border-bottom: 1px solid var(--border);
}
.sidebar-header span { flex: 1; font-weight: 600; font-size: 15px; }

.icon-btn {
  background: none; border: none; color: var(--text-2);
  cursor: pointer; padding: 8px; border-radius: 8px;
  line-height: 1; transition: color .15s, background .15s, transform .1s;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; min-width: 36px; min-height: 36px;
}
.icon-btn:hover { color: var(--text); background: var(--surface2); }
.icon-btn:active { transform: scale(.88); background: var(--surface2); color: var(--text); }
.icon-btn svg { display: block; }
@media (max-width: 640px) { .icon-btn { min-width: 44px; min-height: 44px; } }

.search-wrap { padding: 10px 12px; position: relative; }
#user-search {
  width: 100%;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 12px;
  color: var(--text); font-size: 14px; outline: none;
  transition: border-color .2s;
}
#user-search:focus { border-color: var(--accent); }

.search-dropdown {
  position: absolute; top: calc(100% - 6px); left: 12px; right: 12px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; overflow-y: auto; max-height: 60vh;
  box-shadow: 0 8px 24px rgba(0,0,0,.4); z-index: 50;
}
.search-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; cursor: pointer; transition: background .12s;
}
.search-item:hover { background: var(--surface2); }
.search-item .username { font-size: 14px; font-weight: 500; }
.search-no-result { padding: 12px 14px; color: var(--text-2); font-size: 13px; }

#conv-list { flex: 1; overflow-y: auto; }

.conv-swipe-wrap {
  position: relative; overflow: hidden;
}
.conv-delete-reveal {
  position: absolute; right: 0; top: 0; bottom: 0; width: 80px;
  background: #e53935; color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600; cursor: pointer;
  user-select: none;
}
.conv-item {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 14px; cursor: pointer;
  transition: background .12s, transform .2s ease; position: relative;
  z-index: 1; /* always above the delete button */
  background: var(--bg2);
}
.conv-item:hover   { background: var(--surface2); }
.conv-item:hover .conv-del-btn { opacity: 1; }

/* Delete chat (×) button — desktop only (hover-capable devices) */
.conv-del-btn { display: none; }
@media (hover: hover) {
  .conv-del-btn {
    display: flex; position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
    width: 24px; height: 24px; border-radius: 50%;
    background: rgba(255,255,255,.08); border: none;
    color: var(--text-2); align-items: center; justify-content: center;
    cursor: pointer; opacity: 0; transition: opacity .15s, background .12s;
    flex-shrink: 0; z-index: 2;
  }
  .conv-del-btn:hover { background: #e53935; color: #fff; }
}

/* active: use pseudo-element overlay so solid bg2 base stays opaque */
.conv-item.active  { background: var(--bg2); }
.conv-item.active::after {
  content: ''; position: absolute; inset: 0;
  background: rgba(108,143,255,.12); pointer-events: none; z-index: 0;
}

.conv-info { flex: 1; min-width: 0; }
.conv-name { font-size: 14px; font-weight: 600; }
.conv-preview {
  font-size: 13px; color: var(--text-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-top: 1px;
}
.conv-draft-label {
  color: #e53935; font-weight: 600; font-size: 12px;
}
.conv-meta {
  display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0;
}
.conv-time { font-size: 11px; color: var(--text-3); }

.unread-badge {
  min-width: 18px; height: 18px; border-radius: 9px;
  background: var(--accent); color: #fff;
  font-size: 11px; font-weight: 700; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  padding: 0 5px;
}

/* ── Chat area ───────────────────────────────────────────────────────────── */
#chat-area {
  flex: 1; display: flex; flex-direction: column; min-width: 0;
  background: var(--bg);
}

#chat-empty {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 12px;
  color: var(--text-3);
}
.empty-icon { font-size: 3.5rem; opacity: .4; }
#chat-empty p { font-size: 15px; }

#chat-view {
  display: flex; flex-direction: column; flex: 1; min-height: 0; overflow: hidden;
  position: relative;
}

.chat-header {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 16px; border-bottom: 1px solid var(--border);
  background: var(--bg2); flex-shrink: 0;
}
.chat-header-info { flex: 1; min-width: 0; }
.chat-header-info > div:first-child { font-size: 15px; font-weight: 600; }
.chat-status { font-size: 12px; color: var(--text-2); margin-top: 1px; min-height: 16px; }
#back-btn { display: none; }

/* ── Messages ────────────────────────────────────────────────────────────── */
#messages {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  padding: 16px 16px 8px;
  display: flex; flex-direction: column; gap: 2px;
}

.msg-group { display: flex; flex-direction: column; margin-bottom: 8px; }
.msg-group.mine  { align-items: flex-end; }
.msg-group.yours { align-items: flex-start; }

.msg-author-label {
  font-size: 11px; color: var(--accent); font-weight: 600;
  margin: 0 4px 3px;
}

.bubble {
  max-width: 68%; min-width: 60px;
  padding: 9px 13px;
  border-radius: 18px;
  word-break: break-word; position: relative;
  line-height: 1.45; font-size: 15px;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.mine .bubble  { background: var(--bubble-me);  border-bottom-right-radius: 5px; }
.yours .bubble { background: var(--bubble-you); border-bottom-left-radius: 5px; }

.bubble + .bubble { margin-top: 2px; }
.mine  .bubble + .bubble { border-radius: 18px; border-bottom-right-radius: 5px; }
.yours .bubble + .bubble { border-radius: 18px; border-bottom-left-radius: 5px; }

.bubble img, .bubble video {
  display: block; max-width: 260px; max-height: 260px;
  border-radius: 10px; cursor: zoom-in;
}
.bubble video { cursor: default; }

/* ⋮ button on image/voice bubbles */
.bubble-more-btn {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--bg-2); border: none;
  color: var(--text-2); display: flex; align-items: center; justify-content: center;
  cursor: pointer; opacity: 0; transition: opacity .15s;
  flex-shrink: 0;
}
/* incoming: button outside to the right; outgoing: outside to the left */
.yours .bubble .bubble-more-btn { right: -34px; }
.mine  .bubble .bubble-more-btn { left:  -34px; right: auto; }
/* pseudo-element bridges the gap so mouse can reach the button */
.bubble-more-btn::before {
  content: ''; position: absolute; inset: -6px 0;
}
.bubble-more-btn--voice {
  position: static; transform: none; background: transparent;
  color: var(--text-2); opacity: 1; margin-left: 4px;
}
.bubble-more-btn--voice::before { display: none; }
.bubble:hover .bubble-more-btn,
.bubble-more-btn:hover { opacity: 1; }
.mine .bubble-more-btn--voice { color: rgba(255,255,255,.6); }
/* ── Custom voice player ─────────────────────────────────────────────────── */
.voice-player {
  display: flex; align-items: center; gap: 8px;
  width: 220px; max-width: calc(100vw - 120px);
  padding: 2px 0;
}
.vp-play {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--accent); border: none; color: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0;
  transition: background .15s;
}
.vp-play:hover { background: var(--accent-dim); }
.vp-body { flex: 1; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.vp-track {
  position: relative; height: 3px; border-radius: 2px;
  background: rgba(255,255,255,.15); cursor: pointer;
}
.vp-fill {
  position: absolute; left: 0; top: 0; bottom: 0;
  border-radius: 2px; background: var(--accent);
  pointer-events: none; transition: width .1s linear;
}
.vp-meta { display: flex; align-items: center; justify-content: space-between; }
.vp-time { font-size: 11px; color: var(--text-3); }
.vp-speed {
  font-size: 11px; font-weight: 600; color: var(--text-2);
  background: none; border: 1px solid var(--border);
  border-radius: 4px; padding: 1px 5px; cursor: pointer;
  transition: color .1s, border-color .1s;
}
.vp-speed:hover { color: var(--accent); border-color: var(--accent); }
.bubble .mp3-link {
  display: flex; align-items: center; gap: 8px;
  color: var(--accent); font-size: 14px;
  background: none; border: none; padding: 0; cursor: pointer; text-align: left;
}
.bubble .mp3-link:hover { text-decoration: underline; }

.msg-time {
  font-size: 11px; color: var(--text-3);
  margin: 3px 4px 0; align-self: flex-end;
}
.mine .msg-time { align-self: flex-end; }

.day-divider {
  align-self: center; font-size: 12px; color: var(--text-3);
  background: var(--surface); border-radius: 20px;
  padding: 3px 14px; margin: 10px 0;
}

/* ── Typing ───────────────────────────────────────────────────────────────── */
#typing-bar {
  padding: 2px 20px 2px;
  font-size: 12px; color: var(--text-2);
  flex-shrink: 0; display: flex; align-items: center; gap: 2px; min-height: 18px;
}
.typing-dots { display: inline-flex; gap: 3px; margin-left: 3px; align-items: center; }
.typing-dots span {
  width: 5px; height: 5px; border-radius: 50%; background: var(--text-2);
  animation: td-bounce 1.4s ease-in-out infinite;
}
.typing-dots span:nth-child(2) { animation-delay: .2s; }
.typing-dots span:nth-child(3) { animation-delay: .4s; }
@keyframes td-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .4; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* ── Footer ──────────────────────────────────────────────────────────────── */
.chat-footer {
  padding: 10px 12px calc(28px + env(safe-area-inset-bottom, 0px));
  background: var(--bg2);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  position: relative;
}

.footer-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 0 0 10px;
}
.rec-cancel { color: var(--danger) !important; }
.rec-info { display: flex; align-items: center; gap: 6px; color: #ff7070; font-size: 13px; }
.rec-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #ff5c5c; animation: blink 1s step-start infinite; flex-shrink: 0;
}
@keyframes blink { 50% { opacity: 0; } }
.rec-hint { flex: 1; font-size: 12px; color: var(--text-3); text-align: center; }

/* Preview bar player */
.pp-wrap { flex: 1; display: flex; align-items: center; gap: 8px; min-width: 0; }
.pp-track {
  flex: 1; height: 3px; border-radius: 2px;
  background: rgba(255,255,255,.15); cursor: pointer; position: relative;
}
.pp-fill {
  position: absolute; left: 0; top: 0; bottom: 0;
  border-radius: 2px; background: var(--accent);
  pointer-events: none;
}
.pp-time { font-size: 12px; color: var(--text-2); white-space: nowrap; }

#input-row {
  display: flex; align-items: center; gap: 8px;
}

/* Send-btn recording state */
#send-btn.recording {
  background: #ff5c5c !important;
  transform: scale(1.12);
  box-shadow: 0 0 0 6px rgba(255,92,92,.2);
}

#msg-input {
  flex: 1;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 22px; padding: 10px 16px;
  color: var(--text); font-size: 16px; outline: none; /* 16px prevents iOS auto-zoom on focus */
  transition: border-color .2s;
  cursor: text; word-break: break-word; white-space: pre-wrap;
  max-height: 40vh; overflow-y: auto;
  line-height: 1.4;
}
#msg-input:focus { border-color: var(--accent); }
#msg-input:empty::before {
  content: attr(data-placeholder);
  color: var(--text-2);
  pointer-events: none;
}

.send-btn {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--accent); border: none; color: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0;
  transition: background .15s, transform .1s;
}
.send-btn:hover  { background: var(--accent-dim); }
.send-btn:active { transform: scale(.92); }

#send-btn { transition: background .15s, transform .15s, box-shadow .15s; touch-action: none; user-select: none; -webkit-user-select: none; }

/* ── Lightbox ────────────────────────────────────────────────────────────── */
#lightbox {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.85);
  display: flex; align-items: center; justify-content: center;
  z-index: 200; cursor: zoom-out;
}
#lightbox img {
  max-width: 95vw; max-height: 95vh;
  border-radius: 8px; pointer-events: none;
}

/* ── Avatar with photo ───────────────────────────────────────────────────── */
.avatar-lg { width: 72px; height: 72px; font-size: 26px; }
.avatar-clickable { cursor: zoom-in; }

/* ── Settings modal ──────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 200; padding: 20px;
}
.modal-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; width: 100%; max-width: 360px;
  padding: 0 0 24px;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px 14px; border-bottom: 1px solid var(--border);
  font-weight: 700; font-size: 16px;
}
.settings-avatar-wrap {
  display: flex; flex-direction: column; align-items: center;
  gap: 10px; padding: 24px 20px 20px;
  border-bottom: 1px solid var(--border);
}
.btn-avatar-change {
  background: none; border: 1px solid var(--border); color: var(--accent);
  border-radius: 8px; padding: 6px 16px; font-size: 13px; cursor: pointer;
}
.btn-avatar-change:hover { background: var(--surface2); }
.settings-section { padding: 20px 20px 0; }
.settings-label { font-size: 13px; color: var(--text-2); margin-bottom: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }
.settings-version { padding: 16px 20px; font-size: 12px; color: var(--text-2); opacity: .5; text-align: center; }

/* ── Forgot password ─────────────────────────────────────────────────────── */
.btn-forgot {
  background: none; border: none; color: var(--text-2);
  font-size: 13px; cursor: pointer; margin-top: 6px;
  padding: 4px 0; display: block; width: 100%; text-align: center;
}
.btn-forgot:hover { color: var(--accent); }
#recover-panel { margin-top: 12px; border-top: 1px solid var(--border); padding-top: 12px; }
.recover-ok {
  background: rgba(60,190,139,.12); border: 1px solid rgba(60,190,139,.3);
  color: #3bbe8b; border-radius: 8px;
  font-size: 13px; padding: 8px 12px; margin-bottom: 10px; text-align: left;
}

/* ── Mobile ──────────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  #sidebar {
    width: 100%; position: absolute; inset: 0; z-index: 10;
  }
  #app.chat-active #sidebar {
    display: none;
  }
  #app.swipe-back #sidebar {
    display: block;
  }
  #chat-area {
    width: 100%; position: absolute; inset: 0; z-index: 20;
    display: none;
  }
  #chat-area.chat-open {
    display: flex;
  }
  #back-btn { display: flex !important; }
  .bubble { max-width: 86%; }
  .bubble img { max-width: 200px; }
}
/* Keyboard-open: prevent input from taking more than 20% of the cramped viewport */
@media (max-height: 500px) {
  #msg-input { max-height: 20vh; }
}

/* ── Group chips (selected members) ──────────────────────────────────────── */
.group-add-section { position: relative; margin-bottom: 8px; }
#group-selected-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 0 8px; min-height: 0; }
.member-chip {
  display: flex; align-items: center; gap: 5px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 20px; padding: 4px 10px 4px 6px;
  font-size: 13px; cursor: pointer;
}
.member-chip:active { background: var(--danger); color: #fff; border-color: var(--danger); }
.member-chip .avatar { width: 22px; height: 22px; font-size: 9px; }

/* ── Group member list in info modal ──────────────────────────────────────── */
#group-info-members { max-height: 45vh; overflow-y: auto; margin-bottom: 12px; }
.group-member-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 0; border-bottom: 1px solid var(--border);
}
.group-member-row:last-child { border-bottom: none; }
.group-member-name { flex: 1; font-size: 15px; }
.group-member-online { font-size: 11px; color: #3bbe8b; }

.group-rename-row {
  display: flex; gap: 8px; padding: 0 20px 12px; align-items: center;
}
.group-rename-row .field { margin: 0; flex: 1; }
.group-rename-row .btn-primary { width: auto; padding: 11px 16px; white-space: nowrap; }

.btn-danger {
  width: 100%; padding: 11px; background: none; border: 1px solid var(--danger);
  color: var(--danger); border-radius: 10px; font-size: 14px;
  font-weight: 600; cursor: pointer; margin-top: 8px;
}
.btn-danger:active { background: var(--danger); color: #fff; }

/* ── Online status ────────────────────────────────────────────────────────── */
.status-online { color: #3bbe8b; font-size: 12px; }
.status-offline { color: var(--text-3); font-size: 12px; }

/* ── Read receipts ────────────────────────────────────────────────────────── */
.msg-time { display: flex; align-items: center; gap: 3px; }
.read-tick { font-size: 11px; color: var(--text-3); line-height: 1; }
.read-tick.read { color: var(--accent); }

/* ── Deleted / edited message ────────────────────────────────────────────── */
/* .bubble.deleted — removed: deleted messages are fully removed from DOM */
.edited-label { font-size: 10px; color: var(--text-3); margin-left: 4px; }

/* ── Reply quote inside bubble ────────────────────────────────────────────── */
.reply-quote {
  border-left: 3px solid var(--accent);
  padding: 4px 8px; margin-bottom: 6px;
  border-radius: 4px; background: rgba(108,143,255,.1);
  font-size: 12px; cursor: pointer;
}
.reply-quote-name { font-weight: 600; color: var(--accent); margin-bottom: 2px; }
.reply-quote-text { color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── Reply bar above input ────────────────────────────────────────────────── */
#reply-bar, #edit-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px; background: var(--surface2);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
#reply-bar { border-left: 3px solid var(--accent); }
#edit-bar  { border-left: 3px solid #e08c3b; color: #e08c3b; }
.reply-bar-inner { flex: 1; overflow: hidden; }
.reply-bar-name { font-weight: 600; color: var(--accent); margin-right: 6px; }
.reply-bar-text { color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }

/* ── Reactions ────────────────────────────────────────────────────────────── */
.reactions-row { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
@keyframes reaction-pop {
  0%   { transform: scale(0.5); opacity: 0; }
  65%  { transform: scale(1.25); }
  100% { transform: scale(1); opacity: 1; }
}
.reaction-badge {
  display: flex; align-items: center; gap: 3px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 12px; padding: 2px 7px; font-size: 13px; cursor: pointer;
  transition: background .15s;
  animation: reaction-pop .28s cubic-bezier(.34,1.56,.64,1);
}
.reaction-badge.mine { background: rgba(108,143,255,.2); border-color: var(--accent); }
.reaction-badge:active { background: var(--surface); }
.reaction-count { font-size: 12px; color: var(--text-2); }
.reaction-avatar {
  width: 16px; height: 16px; border-radius: 50%;
  font-size: 7px; flex-shrink: 0;
  background-size: cover; background-position: center;
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700;
  margin-left: 2px;
}

/* ── Action sheet ─────────────────────────────────────────────────────────── */
#action-sheet { position: fixed; inset: 0; z-index: 200; }
#action-sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.5); }
#action-sheet-panel {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: var(--surface); border-radius: 20px 20px 0 0;
  padding: 12px 0 max(16px, env(safe-area-inset-bottom));
  transform: translateY(100%);
  transition: transform .25s cubic-bezier(.32,1,.32,1);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
#action-sheet.open #action-sheet-panel { transform: translateY(0); }
#action-sheet-emoji {
  display: flex; flex-wrap: nowrap; overflow-x: auto;
  justify-content: space-around;
  padding: 8px 12px 12px; border-bottom: 1px solid var(--border);
  gap: 2px; scrollbar-width: none;
}
#action-sheet-emoji::-webkit-scrollbar { display: none; }
.emoji-btn { font-size: 26px; background: none; border: none; cursor: pointer;
             padding: 4px 6px; border-radius: 8px; transition: transform .1s; flex-shrink: 0; }
.emoji-btn:active { transform: scale(1.3); }
.emoji-btn.active { background: rgba(90,111,240,.22); }
/* ── Link preview card ────────────────────────────────────────────────────── */
.link-preview {
  display: flex; flex-direction: column;
  margin-top: 8px; border-radius: 10px; overflow: hidden;
  border: 1px solid var(--border);
  background: var(--bg2); color: inherit; text-decoration: none;
  max-width: 260px;
}
.link-preview img {
  width: 100%; max-height: 140px; object-fit: cover;
  display: block; border-radius: 0;
}
.lp-text { display: flex; flex-direction: column; gap: 3px; padding: 8px 10px; }
.lp-site  { font-size: 11px; color: var(--accent); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.lp-title { font-size: 13px; font-weight: 600; color: var(--text); line-height: 1.3;
            display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.lp-desc  { font-size: 12px; color: var(--text-2); line-height: 1.35;
            display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
#action-sheet-btns button {
  display: flex; align-items: center; gap: 12px;
  width: 100%; padding: 14px 20px; background: none; border: none;
  color: var(--text); font-size: 16px; cursor: pointer; text-align: left;
}
#action-sheet-btns button:active { background: var(--surface2); }
#action-sheet-btns button.danger { color: var(--danger); }
#action-sheet-btns button svg { flex-shrink: 0; opacity: .7; }

/* ── Scroll-to-bottom button ──────────────────────────────────────────────── */
#scroll-down-btn {
  position: absolute; right: 12px; bottom: calc(72px + env(safe-area-inset-bottom, 0px)); z-index: 10;
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text); display: flex; align-items: center; justify-content: center;
  cursor: pointer; box-shadow: 0 2px 12px rgba(0,0,0,.35);
  transition: opacity .2s, transform .15s;
}
#scroll-down-btn:active { transform: scale(.9); }
#scroll-down-btn.hidden { display: none; }
.scroll-badge {
  position: absolute; top: -5px; right: -5px;
  min-width: 16px; height: 16px; border-radius: 8px;
  background: var(--accent); color: #fff;
  font-size: 9px; font-weight: 700; padding: 0 3px;
  display: flex; align-items: center; justify-content: center;
  line-height: 1; pointer-events: none;
}

/* ── Chat search bar ──────────────────────────────────────────────────────── */
#chat-search-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; background: var(--bg2);
  border-bottom: 1px solid var(--border);
}
#chat-search-input {
  flex: 1; background: var(--surface2); border: 1px solid var(--border);
  border-radius: 20px; padding: 7px 14px; color: var(--text);
  font-size: 14px; outline: none;
}
#chat-search-input:focus { border-color: var(--accent); }
.search-result-item {
  padding: 10px 16px; cursor: pointer; border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.search-result-item:active { background: var(--surface2); }
.search-result-item mark { background: rgba(108,143,255,.35); color: var(--text); border-radius: 2px; }
.search-result-time { font-size: 11px; color: var(--text-3); margin-top: 2px; }
#search-results-list { max-height: 60vh; overflow-y: auto; }

/* ── Forward modal list ───────────────────────────────────────────────────── */
#forward-list { max-height: 60vh; overflow-y: auto; }
.forward-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; cursor: pointer;
}
.forward-item:active { background: var(--surface2); }

/* ── Light theme adjustments ──────────────────────────────────────────────── */
.bubble.search-highlight { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── Splash screen ────────────────────────────────────────────────────────── */
#splash-screen {
  position: fixed; inset: 0; z-index: 9999;
  background: var(--bg);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 28px;
  transition: opacity .5s ease;
}
#splash-screen.fade-out { opacity: 0; pointer-events: none; }

.splash-logo {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
}
.splash-title {
  font-size: 28px; font-weight: 800; letter-spacing: 3px;
  color: var(--text);
}

.splash-bubble {
  background: var(--surface2);
  border-radius: 18px 18px 18px 4px;
  padding: 14px 20px;
  min-width: 120px; min-height: 48px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; color: var(--text);
  max-width: 280px;
}

/* Typing dots */
.splash-dots { display: flex; gap: 6px; align-items: center; }
.splash-dots span {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-2);
  animation: splash-bounce 1.1s infinite ease-in-out;
}
.splash-dots span:nth-child(1) { animation-delay: 0s; }
.splash-dots span:nth-child(2) { animation-delay: .18s; }
.splash-dots span:nth-child(3) { animation-delay: .36s; }

@keyframes splash-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .5; }
  30%            { transform: translateY(-7px); opacity: 1; }
}

.splash-text {
  line-height: 1.4; text-align: left;
}
.splash-cursor {
  display: inline-block; width: 2px; height: 1em;
  background: var(--accent); margin-left: 2px;
  vertical-align: middle;
  animation: blink .7s infinite;
}
@keyframes blink { 0%,49% { opacity:1 } 50%,100% { opacity:0 } }

/* ── Video circle recording modal ────────────────────────────────────────── */
#video-rec-modal {
  position: fixed; inset: 0; z-index: 400;
  background: rgba(0,0,0,.92);
  display: flex; align-items: center; justify-content: center;
}
#video-rec-inner {
  display: flex; flex-direction: column; align-items: center; gap: 20px;
}
#video-rec-frame {
  width: 260px; height: 260px; border-radius: 50%;
  overflow: hidden; position: relative; flex-shrink: 0;
  background: #111;
}
#video-rec-frame video {
  width: 100%; height: 100%; object-fit: cover;
  transform: scaleX(-1); /* mirror front camera */
  display: block;
}
#video-rec-frame.vrf-preview video { transform: none; }
#video-ring-svg {
  position: absolute; inset: -3px; width: calc(100% + 6px); height: calc(100% + 6px);
  transform: rotate(-90deg); pointer-events: none;
}
.video-rec-timer {
  font-size: 20px; font-weight: 700; color: #fff; letter-spacing: 1px;
  font-variant-numeric: tabular-nums;
}
.video-ctrls-row {
  display: flex; align-items: center; gap: 32px;
}
.video-ctrl-btn {
  width: 56px; height: 56px; border-radius: 50%;
  border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,.15); color: #fff;
  transition: transform .1s, background .15s;
}
.video-ctrl-btn:active { transform: scale(.9); }
.video-ctrl-stop { background: #ff5c5c; }
.video-ctrl-stop:hover { background: #e04040; }
.video-ctrl-play { background: rgba(255,255,255,.25); }
.video-ctrl-send { background: var(--accent); }
.video-ctrl-send:hover { background: var(--accent-dim); }

/* ── Video circle in messages ─────────────────────────────────────────────── */
.bubble-video {
  background: transparent !important;
  padding: 0 !important;
  min-width: unset !important;
  border-radius: 50% !important;
  overflow: visible !important;
}
.video-msg-wrap {
  width: 200px; height: 200px;
  border-radius: 50%; overflow: hidden;
  position: relative; cursor: pointer; flex-shrink: 0;
  background: #111;
}
@media (max-width: 640px) {
  .video-msg-wrap { width: 170px; height: 170px; }
}
.video-msg-vid {
  width: 100%; height: 100%; object-fit: cover; display: block;
}
.video-msg-overlay {
  position: absolute; inset: 0; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.28);
  transition: background .2s;
}
.video-msg-overlay.vmo-playing { background: rgba(0,0,0,.05); }
.video-msg-play-icon {
  width: 52px; height: 52px; border-radius: 50%;
  background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
  transition: opacity .2s;
  padding-left: 4px; /* optical center for play triangle */
}
.video-msg-overlay.vmo-playing .video-msg-play-icon { opacity: 0; }
.video-msg-dur {
  position: absolute; bottom: 10px; left: 50%;
  transform: translateX(-50%);
  font-size: 11px; font-weight: 600; color: rgba(255,255,255,.9);
  background: rgba(0,0,0,.4); border-radius: 6px; padding: 1px 6px;
  pointer-events: none; transition: opacity .2s;
  white-space: nowrap;
}

/* ── Toast ────────────────────────────────────────────────────────────────── */
@keyframes toast-in  { from { opacity: 0; transform: translateX(-50%) translateY(8px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }
#toast {
  position: fixed; bottom: 80px; left: 50%; z-index: 600;
  transform: translateX(-50%) translateY(8px);
  background: rgba(28,28,33,.97); color: var(--text);
  border: 1px solid rgba(108,143,255,.2);
  border-radius: 20px; padding: 8px 18px;
  font-size: 13px; font-weight: 500;
  pointer-events: none; white-space: nowrap;
  opacity: 0; backdrop-filter: blur(8px);
}
#toast.show { animation: toast-in .22s cubic-bezier(.32,1.1,.32,1) forwards; }

/* ── Settings link section ────────────────────────────────────────────────── */
.settings-link-section { padding-bottom: 4px; }
.settings-link-row {
  display: flex; align-items: center; gap: 8px; margin-top: 6px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 10px;
}
.settings-link-text {
  flex: 1; min-width: 0;
  font-size: 13px; color: var(--accent);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  user-select: all; cursor: text;
}

/* ── In-app notification banner ───────────────────────────────────────────── */
@keyframes nb-slide-in  { from { transform: translateY(-110%); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes nb-slide-out { from { transform: translateY(0); opacity: 1; } to { transform: translateY(-110%); opacity: 0; } }
#notif-banner {
  position: fixed; top: max(12px, env(safe-area-inset-top, 12px)); left: 50%; z-index: 500;
  transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 10px 16px 10px 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,.5);
  max-width: min(360px, calc(100vw - 32px));
  cursor: pointer;
  animation: nb-slide-in .3s cubic-bezier(.32,1,.32,1);
}
#notif-banner.nb-hide { animation: nb-slide-out .3s ease forwards; }
#notif-banner-body { min-width: 0; }
#notif-banner-name { font-size: 13px; font-weight: 700; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#notif-banner-text { font-size: 13px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }

/* ── Pin bar ──────────────────────────────────────────────────────────────── */
#pin-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 12px 7px 14px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  cursor: pointer; flex-shrink: 0;
}
#pin-bar svg { color: var(--accent); flex-shrink: 0; }
#pin-bar-text {
  flex: 1; min-width: 0;
  font-size: 13px; color: var(--text-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#pin-bar::before {
  content: ''; width: 3px; height: 28px; border-radius: 2px;
  background: var(--accent); flex-shrink: 0; margin-right: 2px;
}

/* ── Forwarded message header ────────────────────────────────────────────── */
.fwd-header {
  display: flex; align-items: center; gap: 5px;
  font-size: 12px; color: var(--accent); font-weight: 600;
  margin-bottom: 4px;
}
.fwd-header svg { opacity: .8; }

/* ── Image caption ───────────────────────────────────────────────────────── */
.img-caption {
  font-size: 13px; color: var(--text); margin-top: 5px;
  line-height: 1.4; word-break: break-word;
}

/* ── Caption modal ───────────────────────────────────────────────────────── */
#caption-modal {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(0,0,0,.7);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 0 0 env(safe-area-inset-bottom, 0);
}
#caption-inner {
  position: relative;
  background: var(--surface); border-radius: 18px 18px 0 0;
  width: 100%; max-width: 520px; padding: 16px 16px 20px;
}
#caption-previews {
  display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px;
  max-height: 200px; overflow-y: auto;
}
#caption-previews img {
  height: 120px; width: auto; max-width: 160px;
  border-radius: 10px; object-fit: cover;
}
#caption-input-row {
  display: flex; gap: 8px; align-items: center;
}
#caption-input {
  flex: 1; background: var(--surface2); border: 1px solid var(--border);
  border-radius: 20px; padding: 8px 14px; color: var(--text);
  font-size: 14px; outline: none;
}
#caption-input::placeholder { color: var(--text-3); }

/* ── Voice waveform bars ─────────────────────────────────────────────────── */
.vp-waveform {
  flex: 1; display: flex; align-items: center; gap: 2px;
  height: 32px; cursor: pointer; overflow: hidden;
}
.vp-bar {
  flex-shrink: 0; width: 3px; border-radius: 2px;
  background: var(--text-3); transition: background .1s;
  min-height: 3px;
}
.vp-bar.played { background: var(--accent); }

/* ── Lightbox carousel ───────────────────────────────────────────────────── */
#lightbox-prev, #lightbox-next {
  position: absolute; top: 50%; transform: translateY(-50%);
  background: rgba(0,0,0,.5); border: none; color: #fff;
  border-radius: 50%; width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: 20px; z-index: 1;
}
#lightbox-prev { left: 16px; }
#lightbox-next { right: 16px; }
#lightbox-counter {
  position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%);
  color: #fff; font-size: 13px; background: rgba(0,0,0,.5);
  border-radius: 12px; padding: 3px 10px;
}

/* ── GIF picker ──────────────────────────────────────────────────────────── */
#gif-modal {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(0,0,0,.7);
  display: flex; align-items: flex-end; justify-content: center;
}
#gif-inner {
  background: var(--surface); border-radius: 18px 18px 0 0;
  width: 100%; max-width: 520px; height: 60vh;
  display: flex; flex-direction: column; padding: 12px;
}
#gif-search-row {
  display: flex; gap: 8px; margin-bottom: 10px;
}
#gif-search {
  flex: 1; background: var(--surface2); border: 1px solid var(--border);
  border-radius: 20px; padding: 8px 14px; color: var(--text);
  font-size: 14px; outline: none;
}
#gif-search::placeholder { color: var(--text-3); }
#gif-results {
  flex: 1; overflow-y: auto;
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px;
}
#gif-results img {
  width: 100%; border-radius: 8px; cursor: pointer;
  object-fit: cover; aspect-ratio: 1;
}

/* ── Offline queue indicator ─────────────────────────────────────────────── */
.msg-pending { opacity: .6; }
.msg-pending .read-tick { color: var(--text-3); }

/* ── Message skeleton loader ────────────────────────────────────────────── */
.msg-skeleton { display: flex; flex-direction: column; gap: 10px; padding: 16px; flex: 1; }
.sk-row { display: flex; }
.sk-row.sk-r { justify-content: flex-end; }
.sk-row.sk-l { justify-content: flex-start; }
.sk-bub {
  height: 38px; width: 160px; border-radius: 18px;
  background: linear-gradient(90deg, var(--surface2) 25%, var(--surface) 50%, var(--surface2) 75%);
  background-size: 300% 100%; animation: sk-shimmer 1.4s ease-in-out infinite;
}
.sk-bub.sk-short { width: 90px; }
.sk-bub.sk-long  { width: 220px; }
@keyframes sk-shimmer {
  0%   { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

[data-theme="light"] .bubble.mine { color: #1a1a2e; }
[data-theme="light"] #lightbox { background: rgba(0,0,0,.7); }
[data-theme="light"] ::-webkit-scrollbar-thumb { background: #c5c9d0; }
[data-theme="light"] .vp-track { background: rgba(0,0,0,.12); }
[data-theme="light"] .pp-track { background: rgba(0,0,0,.12); }
[data-theme="light"] .reply-quote { background: rgba(74,108,247,.08); }
[data-theme="light"] .day-divider { background: rgba(0,0,0,.06); }
[data-theme="light"] #pin-bar { background: var(--bg2); }
[data-theme="light"] #caption-input { background: var(--surface2); }
[data-theme="light"] .vp-bar { background: rgba(0,0,0,.2); }

/* ── Animated GIF in chat ───────────────────────────────────────────────── */
.chat-gif {
  max-width: 260px; max-height: 260px; width: auto; height: auto;
  border-radius: 12px; display: block; cursor: zoom-in;
}

/* ── Clickable links ────────────────────────────────────────────────────── */
.bubble a {
  color: var(--accent); text-decoration: underline;
  word-break: break-all;
}
.bubble a:hover { opacity: .8; }

/* ── @mention ───────────────────────────────────────────────────────────── */
.mention {
  color: var(--accent); font-weight: 600; cursor: default;
}
.mention-me {
  background: rgba(74,108,247,.18); border-radius: 4px;
  padding: 0 3px;
}
.msg-group.mention-highlight {
  background: rgba(74,108,247,.06);
  border-radius: 12px;
  margin-inline: -6px; padding-inline: 6px;
}
[data-theme="light"] .msg-group.mention-highlight { background: rgba(74,108,247,.08); }
[data-theme="light"] .mention-me { background: rgba(74,108,247,.15); }

/* ── @mention autocomplete dropdown ────────────────────────────────────── */
#mention-dropdown {
  position: absolute; bottom: calc(100% + 4px); left: 0; right: 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; overflow: hidden; z-index: 50;
  box-shadow: 0 4px 20px rgba(0,0,0,.3);
  max-height: 220px; overflow-y: auto;
}
.mention-item {
  padding: 10px 16px; cursor: pointer;
  font-size: 14px; color: var(--text);
  display: flex; align-items: center; gap: 4px;
  transition: background .1s;
}
.mention-item:hover, .mention-item.active { background: var(--surface2); }
.mention-at { color: var(--accent); font-weight: 700; }
[data-theme="light"] #mention-dropdown { box-shadow: 0 4px 20px rgba(0,0,0,.15); }


/* ── Mobile polish ───────────────────────────────────────────────────────── */
/* Very small screens (Galaxy Fold closed, old iPhones) */
@media (max-width: 320px) {
  .bubble { max-width: calc(100vw - 72px); }
  .conv-item { padding: 8px 10px; }
  .chat-header { padding: 8px 8px; }
}
/* Landscape tiny screens (keyboard open on small phones) */
@media (max-height: 400px) {
  .chat-header { padding: 6px 12px; min-height: 44px; }
  #messages { padding: 6px 16px 4px; }
  .chat-footer { padding: 6px 12px calc(4px + env(safe-area-inset-bottom, 0px)); }
}
/* Side safe areas for landscape iPad / foldables */
@media (orientation: landscape) {
  #sidebar { padding-left: env(safe-area-inset-left, 0); }
  .chat-footer { padding-right: calc(12px + env(safe-area-inset-right, 0)); }
  #scroll-down-btn { right: calc(12px + env(safe-area-inset-right, 0)); }
}

/* ═══════════════════════════════════════════════════════════════════════════
   AUDIO CALLS
═══════════════════════════════════════════════════════════════════════════ */

/* ── Incoming call overlay ─────────────────────────────────────────────── */
#call-incoming {
  position: fixed; inset: 0; z-index: 700;
  background: rgba(0,0,0,.75);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
#call-incoming-box {
  background: var(--surface);
  border-radius: 28px;
  padding: 40px 36px 32px;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  min-width: 280px; max-width: 340px; width: 100%;
  position: relative; overflow: hidden;
  box-shadow: 0 24px 64px rgba(0,0,0,.5);
}
/* Pulse ring around avatar */
.call-pulse-ring {
  position: absolute; top: 40px; left: 50%; transform: translateX(-50%);
  width: 72px; height: 72px; border-radius: 50%;
  border: 3px solid var(--accent); opacity: 0;
  animation: call-ring 1.8s ease-out infinite;
}
.call-pulse-ring::after {
  content: ''; position: absolute; inset: -12px; border-radius: 50%;
  border: 2px solid var(--accent); opacity: 0;
  animation: call-ring 1.8s ease-out .5s infinite;
}
@keyframes call-ring {
  0%   { transform: translateX(-50%) scale(1); opacity: .7; }
  100% { transform: translateX(-50%) scale(1.9); opacity: 0; }
}
.call-in-name {
  font-size: 22px; font-weight: 700; color: var(--text);
  margin-top: 6px; text-align: center;
}
.call-in-label { font-size: 13px; color: var(--text-3); margin-bottom: 8px; }
.call-in-actions { display: flex; gap: 36px; margin-top: 8px; }
.call-fab {
  width: 64px; height: 64px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  border: none; cursor: pointer;
  transition: transform .15s, box-shadow .15s;
  box-shadow: 0 4px 16px rgba(0,0,0,.25);
}
.call-fab:active { transform: scale(.88); }
.call-fab-red   { background: #ff3b30; color: #fff; }
.call-fab-green { background: #34c759; color: #fff; }
.call-fab-red:hover   { background: #ff5540; }
.call-fab-green:hover { background: #44d769; }

/* ── Active call bar (top strip) ───────────────────────────────────────── */
#call-active {
  position: fixed; top: 0; left: 0; right: 0; z-index: 650;
  background: linear-gradient(135deg, #1c2b4a 0%, #2d1b4e 100%);
  color: #fff;
  display: flex; align-items: center; gap: 10px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 14px 10px;
  box-shadow: 0 4px 20px rgba(0,0,0,.4);
  transition: opacity .2s;
}
[data-call-state="calling"] #call-active { animation: call-blink 1.4s ease-in-out infinite; }
@keyframes call-blink { 0%,100% { opacity:1; } 50% { opacity:.7; } }
.call-active-info {
  flex: 1; display: flex; align-items: center; gap: 8px;
  overflow: hidden;
  font-size: 14px;
}
#call-active-name {
  font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.call-timer-text {
  font-size: 12px; color: rgba(255,255,255,.65); flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}
.call-active-controls { display: flex; align-items: center; gap: 6px; }
.call-ctrl-btn {
  width: 36px; height: 36px; border-radius: 50%;
  background: rgba(255,255,255,.18); border: none;
  color: #fff; display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: background .15s, transform .1s;
}
.call-ctrl-btn:hover   { background: rgba(255,255,255,.28); }
.call-ctrl-btn:active  { transform: scale(.88); }
.call-ctrl-btn.call-ctrl-red { background: #ff3b30; }
.call-ctrl-btn.call-ctrl-red:hover { background: #ff5540; }
.call-ctrl-muted { background: rgba(255,255,255,.4) !important; }

/* Push chat-view down when call bar is visible */
#call-active:not(.hidden) ~ * { /* can't use ~ easily, use JS or padding */ }
/* JS adds .call-active-open to body */
body.call-active-open #app { padding-top: 56px; }

/* ── Light theme ────────────────────────────────────────────────────────── */
[data-theme="light"] #call-incoming { background: rgba(0,0,0,.6); }
[data-theme="light"] #call-incoming-box { box-shadow: 0 24px 64px rgba(0,0,0,.25); }

/* ── Update banner ──────────────────────────────────────────────────────── */
#update-bar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 9999;
  display: flex; align-items: center; justify-content: center; gap: 12px;
  padding: 10px 16px;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 2px 12px rgba(0,0,0,.4);
}
#update-bar.hidden { display: none; }
#update-reload-btn {
  padding: 4px 14px; border-radius: 20px;
  background: rgba(255,255,255,.25); border: 1px solid rgba(255,255,255,.5);
  color: #fff; font-size: 13px; font-weight: 600; cursor: pointer;
}
#update-reload-btn:hover { background: rgba(255,255,255,.4); }

/* ── Offline banner ──────────────────────────────────────────────────────── */
#offline-banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 9999;
  background: #e53935; color: #fff;
  text-align: center; font-size: 13px; font-weight: 600;
  padding: 6px 16px; letter-spacing: .02em;
  pointer-events: none;
}
#offline-banner.hidden { display: none; }
