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

:root {
  --bg: #000000; --surface: #121214; --surface-hover: #27272a;
  --text: #f4f4f5; --text-dim: #a1a1aa; --accent: #6366f1;
  --mine-grad: linear-gradient(135deg, #6366f1, #8b5cf6);
  --border: #27272a; --header-bg: rgba(0, 0, 0, 0.7);
  --modal-bg: rgba(18, 18, 20, 0.95); --reply-bg: rgba(0, 0, 0, 0.6);
  --quote-bg: rgba(0, 0, 0, 0.2); --quote-alt: rgba(255, 255, 255, 0.05);
  --backdrop: rgba(0, 0, 0, 0.6);
}

body.light-theme {
  --bg: #f4f4f5; --surface: #ffffff; --surface-hover: #e4e4e7;
  --text: #18181b; --text-dim: #71717a; --border: #d4d4d8;
  --header-bg: rgba(244, 244, 245, 0.85); --modal-bg: rgba(255, 255, 255, 0.98);
  --reply-bg: rgba(255, 255, 255, 0.85); --quote-bg: rgba(0, 0, 0, 0.05);
  --quote-alt: rgba(0, 0, 0, 0.04); --backdrop: rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--text); font-family: 'Inter', sans-serif; overflow: hidden; transition: background 0.3s, color 0.3s; }
#app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; max-width: 700px; margin: 0 auto; position: relative; background: var(--bg); border-left: 1px solid var(--border); border-right: 1px solid var(--border); transition: background 0.3s, border-color 0.3s; }

/* HEADER */
header { padding: 16px 20px; background: var(--header-bg); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; position: absolute; top: 0; width: 100%; z-index: 10; transition: background 0.3s, border-color 0.3s; }
header .brand { font-size: 16px; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; background: var(--mine-grad); background-clip: text; -webkit-background-clip: text; -webkit-text-fill-color: transparent; user-select: none; display: flex; align-items: center; gap: 12px; }
#backBtn { background: transparent; border: none; color: var(--text); font-size: 20px; cursor: pointer; padding: 0 5px; display: flex; align-items: center; }
.header-right { display: flex; align-items: center; gap: 12px; }
header .room { font-size: 12px; font-weight: 500; color: var(--text-dim); background: var(--surface); padding: 5px 12px; border-radius: 12px; }
.theme-btn { background: transparent; border: none; color: var(--text-dim); cursor: pointer; display: flex; align-items: center; justify-content: center; padding: 6px; border-radius: 50%; transition: color 0.2s, background 0.2s; }
.theme-btn:hover { color: var(--text); background: var(--surface); }
.theme-btn svg { width: 18px; height: 18px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 600; color: #ffffff; flex-shrink: 0; user-select: none; text-shadow: 0px 1px 2px rgba(0,0,0,0.2); }

/* SCREEN MANAGEMENT & LOADER */
.screen { display: none; flex-direction: column; flex: 1; margin-top: 60px; padding: 20px; overflow-y: auto; }
.screen.show { display: flex; }

.spinner {
  width: 44px; height: 44px; border: 3px solid var(--border);
  border-top: 3px solid var(--accent); border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* AUTH & SETUP */
#auth-screen, #setup-screen { align-items: center; justify-content: center; text-align: center; gap: 12px; }
#auth-screen h2, #setup-screen h2 { margin: 0; font-size: 24px; }
#auth-screen p, #setup-screen p { color: var(--text-dim); font-size: 14px; margin-bottom: 20px; }
.auth-btn, .primary-btn { width: 100%; max-width: 280px; padding: 14px; border-radius: 12px; font-size: 15px; font-weight: 600; cursor: pointer; border: none; display: flex; align-items: center; justify-content: center; gap: 10px; transition: opacity 0.2s; }
.auth-btn:hover, .primary-btn:hover { opacity: 0.9; }
.auth-btn.google { background: #fff; color: #000; }
.auth-btn.google img { width: 18px; }
.primary-btn { background: var(--mine-grad); color: white; font-family: inherit; }
.text-btn { background: transparent; border: none; color: var(--text-dim); font-weight: 500; cursor: pointer; padding: 10px; }
.divider { text-align: center; margin: 16px 0; position: relative; width: 100%; max-width: 280px; }
.divider span { background: var(--bg); padding: 0 12px; font-size: 12px; font-weight: 600; color: var(--text-dim); position: relative; z-index: 1; }
.divider::before { content: ""; position: absolute; top: 50%; left: 0; right: 0; border-top: 1px solid var(--border); z-index: 0; }

.phone-auth-box input, .setup-box input, .modal-content input, .search-bar input { background: var(--surface); border: 1px solid var(--border); color: var(--text); padding: 14px 16px; font-family: inherit; font-size: 15px; width: 100%; max-width: 280px; border-radius: 12px; outline: none; margin-bottom: 10px; }
.phone-auth-box input:focus, .setup-box input:focus, .search-bar input:focus { border-color: var(--accent); }

.setup-box { display: flex; align-items: center; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; max-width: 280px; width: 100%; overflow: hidden; }
.setup-box .input-prefix { padding: 14px 0 14px 16px; color: var(--text-dim); font-weight: 600; }
.setup-box input { border: none; border-radius: 0; background: transparent; margin: 0; max-width: 100%; }

/* INBOX */
.search-bar { display: flex; gap: 8px; padding: 16px; border-bottom: 1px solid var(--border); }
.search-bar input { margin: 0; max-width: 100%; border-radius: 20px; padding: 10px 16px; }
.search-bar button { background: var(--surface-hover); color: var(--text); border: none; border-radius: 20px; padding: 0 16px; font-weight: 600; cursor: pointer; }

#inboxSelectionBar, #chatSelectionBar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--surface); animation: slideDown 0.2s ease; }
#chatSelectionBar { position: fixed; top: 0; left: 0; width: 100%; z-index: 60; box-sizing: border-box; background: var(--accent); border-bottom: none; box-shadow: 0 2px 10px rgba(0,0,0,0.25); }
#chatSelectionBar #msgSelectedCountText { color: #fff; }
#chatSelectionBar .text-btn { color: rgba(255,255,255,0.85); }
#chatSelectionBar .delete-selected-btn { background: #fff; color: #ef4444; }
@keyframes slideDown { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }
#selectedCountText, #msgSelectedCountText { font-size: 13px; font-weight: 600; color: var(--text-dim); }
.delete-selected-btn { background: #ef4444; color: #fff; border: none; border-radius: 20px; padding: 8px 18px; font-weight: 600; font-size: 13px; cursor: pointer; transition: opacity 0.2s, transform 0.1s; }
.delete-selected-btn:disabled { opacity: 0.4; cursor: default; }
.delete-selected-btn:not(:disabled):active { transform: scale(0.96); }

#inboxList { flex: 1; overflow-y: auto; }
.inbox-item { display: flex; align-items: center; gap: 14px; padding: 16px; border-bottom: 1px solid var(--border); cursor: pointer; transition: background 0.2s; user-select: none; -webkit-user-select: none; }
.inbox-item:hover { background: var(--surface-hover); }
.inbox-item.selected { background: color-mix(in srgb, var(--accent) 12%, transparent); }

.msg-wrapper.msg-selected .bubble { background: color-mix(in srgb, var(--accent) 30%, var(--surface)); box-shadow: 0 0 0 2px var(--accent); }
#messages.msg-select-mode .msg-wrapper { cursor: pointer; opacity: 0.5; transition: opacity 0.15s ease; }
#messages.msg-select-mode .msg-wrapper.msg-selected { opacity: 1; }
#messages.msg-select-mode .bubble { position: relative; padding-right: 36px; }
#messages.msg-select-mode .bubble::after {
  content: '';
  position: absolute;
  top: 8px; right: 8px;
  width: 20px; height: 20px;
  border-radius: 50%;
  border: 2px solid rgba(140,140,140,0.7);
  background: rgba(120,120,120,0.15);
  z-index: 5;
  box-sizing: border-box;
}
.msg-wrapper.msg-selected .bubble::after {
  content: '\2713';
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.inbox-checkbox { flex-shrink: 0; width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--border); display: none; align-items: center; justify-content: center; transition: background 0.15s, border-color 0.15s; }
#inboxList.select-mode .inbox-checkbox { display: flex; }
.inbox-item.selected .inbox-checkbox { background: var(--accent); border-color: var(--accent); }
.inbox-checkbox svg { width: 13px; height: 13px; opacity: 0; transition: opacity 0.15s; }
.inbox-item.selected .inbox-checkbox svg { opacity: 1; }
#inboxList.select-mode .avatar { display: none; }
.inbox-details { flex: 1; display: flex; flex-direction: column; gap: 4px; overflow: hidden; }
.inbox-header { display: flex; justify-content: space-between; align-items: baseline; }
.inbox-name { font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.inbox-time { font-size: 11px; color: var(--text-dim); }
.inbox-last-msg { font-size: 13px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* FLOATING ACTION BUTTON */
.fab { position: absolute; bottom: 24px; right: 24px; background: var(--mine-grad); color: white; width: 60px; height: 60px; border-radius: 50%; border: none; font-weight: 600; font-size: 13px; box-shadow: 0 4px 16px rgba(99, 102, 241, 0.4); cursor: pointer; display: flex; align-items: center; justify-content: center; z-index: 20; transition: transform 0.2s; }
.fab:active { transform: scale(0.95); }

/* MODALS */
.modal-overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: var(--backdrop); z-index: 100; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal-content { background: var(--surface); padding: 24px; border-radius: 16px; border: 1px solid var(--border); width: 100%; max-width: 320px; display: flex; flex-direction: column; gap: 12px; }
.modal-content h3 { margin: 0 0 8px 0; font-size: 18px; }
.modal-content input { max-width: 100%; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

/* CHAT AREA */
#chat-screen { padding: 0; margin-top: 0; overflow: hidden; position: relative; }
#messages { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 80px 16px 20px 16px; display: flex; flex-direction: column; gap: 20px; }
.unread-divider { text-align: center; margin: 10px 0; position: relative; width: 100%; }
.unread-divider span { background: var(--bg); padding: 0 12px; font-size: 11px; font-weight: 600; color: var(--accent); position: relative; z-index: 1; text-transform: uppercase; letter-spacing: 0.05em; }
.unread-divider::before { content: ""; position: absolute; top: 50%; left: 0; right: 0; border-top: 1px solid var(--accent); opacity: 0.3; z-index: 0; }
@keyframes slideIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.msg-wrapper { display: flex; gap: 12px; align-items: flex-end; max-width: 88%; animation: slideIn 0.3s cubic-bezier(0.25, 1, 0.5, 1) forwards; cursor: pointer; position: relative; }
.msg-wrapper.mine { align-self: flex-end; flex-direction: row-reverse; }
.msg-wrapper.mine .avatar { display: none; } 
.msg-content { display: flex; flex-direction: column; gap: 4px; width: 100%; }
.meta { font-size: 12px; font-weight: 600; display: flex; align-items: baseline; gap: 6px; padding: 0 4px; }
.msg-wrapper.mine .meta { justify-content: flex-end; flex-direction: row-reverse; } 
.time { font-size: 10px; color: var(--text-dim); font-weight: 400; }
.bubble { background: var(--surface); padding: 12px 16px; font-size: 15px; line-height: 1.4; white-space: pre-wrap; word-break: break-word; user-select: none; border-radius: 18px 18px 18px 4px; color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,0.05); transition: background 0.3s, color 0.3s; }
.msg-wrapper.mine .bubble { background: var(--mine-grad); border-radius: 18px 18px 4px 18px; color: #fff; box-shadow: 0 4px 12px rgba(99, 102, 241, 0.2); }
.msg-wrapper.mine.msg-selected .bubble { background: linear-gradient(135deg, color-mix(in srgb, #6366f1 65%, black), color-mix(in srgb, #8b5cf6 65%, black)); box-shadow: 0 0 0 2px #fff, 0 4px 12px rgba(99, 102, 241, 0.2); }
.quote-block { background: var(--quote-bg); border-left: 3px solid; padding: 8px 10px; font-size: 13px; margin-bottom: 8px; border-radius: 4px 8px 8px 4px; color: rgba(255,255,255,0.8); }
.msg-wrapper:not(.mine) .quote-block { background: var(--quote-alt); color: var(--text-dim); }
.quote-block strong { font-size: 12px; display: block; margin-bottom: 2px; }

/* COMPOSER */
#composer-wrapper { display: flex; flex-direction: column; background: var(--bg); border-top: 1px solid var(--border); z-index: 10; transition: background 0.3s, border-color 0.3s; }
#requestBar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; background: var(--bg); border-top: 1px solid var(--border); z-index: 10; }
#requestBarText { color: var(--text-dim); font-size: 14px; flex: 1; }
.inbox-section-header { padding: 10px 16px 4px; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-dim); }
#btnBlockToggle.blocked-active { color: #ef4444; }
#replyPreview { display: none; padding: 12px 16px; background: var(--reply-bg); backdrop-filter: blur(8px); border-left: 4px solid var(--accent); font-size: 13px; color: var(--text-dim); justify-content: space-between; align-items: center; }
#replyPreview.show { display: flex; }
#replyPreviewText { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 90%; }
#replyPreview strong { color: var(--text); font-weight: 600; }
#cancelReply { cursor: pointer; color: var(--text); font-size: 20px; font-weight: 400; padding: 0 5px; }
.input-row { display: flex; gap: 10px; padding: 12px 16px; align-items: flex-end; }
#msgInput { flex: 1; resize: none; background: var(--surface); border: 1px solid var(--border); color: var(--text); font-family: inherit; font-size: 15px; padding: 12px 16px; outline: none; height: 46px; max-height: 120px; border-radius: 24px; line-height: 1.4; transition: background 0.3s, border-color 0.2s, color 0.3s; overflow-y: hidden; }
#msgInput:focus { border-color: var(--accent); }
.send-btn { background: var(--mine-grad); border: none; color: white; width: 46px; height: 46px; border-radius: 50%; display: flex; align-items: center; justify-content: center; cursor: pointer; flex-shrink: 0; box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3); transition: transform 0.1s; }
.send-btn:active { transform: scale(0.95); }
.send-btn svg { width: 20px; height: 20px; margin-left: -2px; margin-top: 2px; }
#empty { color: var(--text-dim); font-size: 14px; text-align: center; margin-top: 40px; font-weight: 500; width: 100%; }
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-thumb { background: var(--surface-hover); border-radius: 10px; }
#msgInput::-webkit-scrollbar { display: none; }

/* DELETE MODAL */
#deleteModal, #bulkDeleteModal { position: absolute; bottom: -100%; left: 0; width: 100%; background: var(--modal-bg); backdrop-filter: blur(10px); border-top-left-radius: 20px; border-top-right-radius: 20px; border-top: 1px solid var(--border); transition: bottom 0.3s cubic-bezier(0.25, 1, 0.5, 1); display: flex; flex-direction: column; z-index: 100; padding-bottom: 20px; box-shadow: 0 -10px 40px rgba(0,0,0,0.2); }
#deleteModal.show, #bulkDeleteModal.show { bottom: 0; }
.modal-handle { width: 40px; height: 4px; background: var(--border); border-radius: 4px; margin: 12px auto; }
.modal-title { padding: 0 24px 8px; font-size: 13px; color: var(--text-dim); text-align: center; }
.modal-btn { padding: 18px 24px; background: transparent; border: none; color: var(--text); font-family: inherit; font-size: 16px; font-weight: 500; cursor: pointer; text-align: left; transition: background 0.2s; }
.modal-btn:hover { background: var(--surface-hover); }
.modal-btn.danger { color: #ef4444; }
#modalBackdrop { display: none; position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: var(--backdrop); z-index: 99; transition: opacity 0.3s; }
#modalBackdrop.show { display: block; }

/* WHATSAPP SWIPE REPLY ICON */
.swipe-reply-icon { position: fixed; width: 32px; height: 32px; border-radius: 50%; background: var(--surface-hover); display: flex; align-items: center; justify-content: center; opacity: 0; transform: scale(0.5); z-index: 5; pointer-events: none; transition: background 0.2s, opacity 0.1s, transform 0.1s; box-shadow: 0 2px 8px rgba(0,0,0,0.2); }
.swipe-reply-icon svg { width: 16px; height: 16px; color: var(--text); }

/* --- PHASE 2: BADGES & REACTIONS --- */
.unread-badge { background: #22c55e; color: #fff; font-size: 11px; font-weight: bold; padding: 2px 8px; border-radius: 12px; margin-top: 4px; display: inline-block; box-shadow: 0 2px 5px rgba(34, 197, 94, 0.4); }

.reaction-menu { position: absolute; background: var(--surface); border: 1px solid var(--border); border-radius: 30px; padding: 8px 16px; display: flex; gap: 16px; font-size: 24px; box-shadow: 0 10px 25px rgba(0,0,0,0.4); z-index: 150; transition: transform 0.2s, opacity 0.2s; opacity: 0; pointer-events: none; transform: scale(0.8) translateY(10px); }
.reaction-menu.show { opacity: 1; pointer-events: auto; transform: scale(1) translateY(0); }
.reaction-menu span { cursor: pointer; transition: transform 0.1s; user-select: none; }
.reaction-menu span:hover, .reaction-menu span:active { transform: scale(1.3) translateY(-4px); }

.msg-reactions { position: absolute; bottom: -12px; right: 10px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 2px 6px; font-size: 13px; display: flex; gap: 2px; box-shadow: 0 2px 5px rgba(0,0,0,0.1); z-index: 2; }
.msg-wrapper.mine .msg-reactions { right: auto; left: 10px; }

/* --- PHASE 3: PRESENCE & MEDIA --- */
.status-dot { width: 10px; height: 10px; border-radius: 50%; background: #22c55e; display: none; margin-left: 6px; box-shadow: 0 0 8px rgba(34,197,94,0.6); }
.status-dot.online { display: inline-block; }
.attach-btn { background: transparent; border: none; color: var(--text-dim); padding: 10px; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: color 0.2s, transform 0.1s; }
.attach-btn:hover { color: var(--text); }
.attach-btn:active { transform: scale(0.9); }
.attach-btn svg { width: 22px; height: 22px; }

/* Voice button: the visible icon stays the same size, but the actual
   touch target is padded out well beyond it so a thumb pressing nearby
   still registers — and doesn't need to sit precisely on a small icon. */
.voice-btn-hitzone { display: flex; align-items: center; justify-content: center; padding: 6px; margin: -6px; touch-action: none; }
#voiceBtn { transition: color 0.2s, transform 0.15s, background 0.15s; border-radius: 50%; }
#voiceBtn.recording {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.12);
  transform: scale(1.35);
  box-shadow: 0 0 0 6px rgba(239, 68, 68, 0.12);
}
#voiceBtn.cancel-zone {
  color: #fff;
  background: #ef4444;
  box-shadow: 0 0 0 6px rgba(239, 68, 68, 0.25);
}

.voice-recording-overlay {
  position: absolute;
  bottom: 78px;
  left: 50%;
  transform: translateX(-50%) translateY(8px) scale(0.94);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  background: rgba(20, 20, 20, 0.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-radius: 30px;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease, transform 0.15s ease;
  z-index: 20;
}
.voice-recording-overlay.visible { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
.voice-recording-overlay.cancel-zone { background: rgba(239, 68, 68, 0.92); }
.voice-rec-pulse { display: flex; align-items: center; justify-content: center; }
.voice-rec-dot { width: 10px; height: 10px; border-radius: 50%; background: #ef4444; animation: voiceRecPulse 1s infinite ease-in-out; }
.voice-recording-overlay.cancel-zone .voice-rec-dot { background: #fff; animation: none; }
@keyframes voiceRecPulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: 0.4; transform: scale(0.8); } }
.voice-rec-hint { opacity: 0.75; font-weight: 500; }
.voice-recording-overlay.cancel-zone .voice-rec-hint { opacity: 1; font-weight: 700; }
.media-preview { max-width: 100%; border-radius: 12px; margin-top: 4px; cursor: pointer; border: 1px solid var(--border); box-shadow: 0 4px 12px rgba(0,0,0,0.1); }
.media-loading { padding: 8px 4px; font-size: 13px; color: var(--text-dim); font-style: italic; }

.voice-player { display: flex; align-items: center; gap: 10px; min-width: 190px; max-width: 240px; padding: 4px 0; }
.voice-play-toggle { flex-shrink: 0; width: 34px; height: 34px; border-radius: 50%; border: none; cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 13px; line-height: 1; background: var(--accent); color: #fff; transition: transform 0.1s, background 0.2s; }
.voice-play-toggle:active { transform: scale(0.92); }
.voice-track { flex: 1; height: 5px; border-radius: 3px; background: var(--surface-hover); cursor: pointer; position: relative; overflow: hidden; }
.voice-progress { height: 100%; width: 0%; border-radius: 3px; background: var(--accent); transition: width 0.1s linear; }
.voice-time { flex-shrink: 0; font-size: 11px; color: var(--text-dim); font-variant-numeric: tabular-nums; min-width: 30px; text-align: right; }
.voice-player.playing .voice-play-toggle { background: var(--accent); }

/* Inside the sender's own colored/gradient bubble, swap to translucent white so it still reads clearly */
.msg-wrapper.mine .voice-play-toggle { background: rgba(255,255,255,0.28); color: #fff; }
.msg-wrapper.mine .voice-track { background: rgba(255,255,255,0.28); }
.msg-wrapper.mine .voice-progress { background: #fff; }
.msg-wrapper.mine .voice-time { color: rgba(255,255,255,0.85); }

/* --- PHASE 4: TYPING INDICATORS & AUDIO --- */
.typing-indicator {
  display: none;
  align-items: center;
  gap: 8px;
  width: fit-content;
  margin: 0 16px 10px;
  padding: 10px 14px;
  background: var(--surface);
  border-radius: 18px 18px 18px 4px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
  opacity: 0;
  transform: translateY(6px) scale(0.96);
  transform-origin: bottom left;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.typing-indicator.visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.typing-indicator .typing-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  white-space: nowrap;
}

.typing-dots {
  display: flex;
  align-items: center;
  gap: 3px;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-dim);
  animation: typingBounce 1.2s infinite ease-in-out;
}

.typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

audio {
  filter: sepia(20%) saturate(70%) grayscale(1) contrast(99%) invert(12%);
  border-radius: 20px;
}
body.light-theme audio {
  filter: none;
}

/* --- CALL CONTROLS --- */
#callControlsBar {
  position: absolute;
  bottom: 34px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  background: rgba(20, 20, 20, 0.55);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-radius: 40px;
  border: 1px solid rgba(255,255,255,0.08);
}

.call-icon-btn {
  background: rgba(255,255,255,0.12);
  color: #fff;
  border: none;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, transform 0.1s;
  flex-shrink: 0;
}
.call-icon-btn svg { width: 22px; height: 22px; }
.call-icon-btn:active { transform: scale(0.9); }
.call-icon-btn:hover { background: rgba(255,255,255,0.2); }
.call-icon-btn.off-state { background: #fff; color: #111; }
.call-icon-btn.active-state { background: #3b82f6; }
.call-icon-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.call-icon-btn.end {
  background: #ef4444;
  width: 58px;
  height: 58px;
}
.call-icon-btn.end svg { width: 24px; height: 24px; }
.call-icon-btn.end:hover { background: #dc2626; }
.call-icon-btn.end:active { transform: scale(0.9); }

.call-corner-btn {
  position: absolute;
  top: 20px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(20, 20, 20, 0.55);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.08);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  z-index: 2;
}
.call-corner-btn svg { width: 18px; height: 18px; }
.call-corner-btn:active { transform: scale(0.9); }
.call-corner-btn:hover { background: rgba(40,40,40,0.7); }
.call-corner-btn.top-left { left: 16px; }
.call-corner-btn.top-right { right: 16px; }

#localVideo.screen-preview { object-fit: contain; background: #111; }

@media (max-width: 380px) {
  .call-icon-btn { width: 46px; height: 46px; }
  .call-icon-btn svg { width: 19px; height: 19px; }
  .call-icon-btn.end { width: 52px; height: 52px; }
  #callControlsBar { gap: 10px; padding: 10px 14px; bottom: 24px; }
}

/* --- DESKTOP 3-DOT MENU --- */
.bubble-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Reverse the flex direction for the sender's messages */
.msg-wrapper.mine .bubble-row {
  flex-direction: row-reverse;
}

.msg-options-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 50%;
  opacity: 0; 
  transition: opacity 0.2s, background 0.2s, transform 0.1s;
}

.msg-options-btn:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.msg-options-btn:active {
  transform: scale(0.9);
}

/* Only show the 3-dot menu on devices with a mouse/trackpad */
@media (pointer: fine) {
  .msg-wrapper:hover .msg-options-btn {
    opacity: 1;
  }
}
