:root {
  --bg-deep: #0d0b14;
  --bg-panel: #14111d;
  --bg-panel-2: #1b1628;
  --bg-elevated: #221c33;
  --line: rgba(255, 255, 255, 0.08);
  --line-soft: rgba(255, 255, 255, 0.04);
  --text-primary: #f3f0f8;
  --text-muted: #948da9;
  --text-faint: #635c78;
  --ember: #ff5c7a;
  --ember-soft: rgba(255, 92, 122, 0.15);
  --glow: #7c9eff;
  --glow-soft: rgba(124, 158, 255, 0.15);
  --danger: #ff5c5c;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 9px;
  --font-display: "Fraunces", serif;
  --font-body: "Inter", -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", monospace;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg-deep);
  color: var(--text-primary);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button { font-family: inherit; cursor: pointer; }
input, textarea { font-family: inherit; }

.hidden { display: none !important; }

/* dvh tracks the *actual* visible viewport on mobile (shrinks when the
   keyboard opens) instead of the layout viewport (100vh), which is the
   main cause of the "screen jumps" feeling when the keyboard toggles */
.screen { height: 100vh; height: 100dvh; width: 100vw; }

/* ============ AUTH SCREEN ============ */

#auth-screen {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse 70% 50% at 50% 0%, rgba(255, 92, 122, 0.12), transparent),
    radial-gradient(ellipse 60% 40% at 100% 100%, rgba(124, 158, 255, 0.10), transparent),
    var(--bg-deep);
  overflow: hidden;
}

.ember-field { position: absolute; inset: 0; pointer-events: none; }
.ember-field span {
  position: absolute;
  bottom: -20px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: radial-gradient(circle, #ffb37a 0%, #ff5c7a 60%, transparent 100%);
  opacity: 0;
  animation: rise 9s linear infinite;
  filter: blur(0.3px);
}
.ember-field span:nth-child(1) { left: 8%; animation-delay: 0.5s; }
.ember-field span:nth-child(2) { left: 22%; animation-delay: 3s; width: 3px; height: 3px; }
.ember-field span:nth-child(3) { left: 45%; animation-delay: 1.5s; }
.ember-field span:nth-child(4) { left: 63%; animation-delay: 5s; width: 4px; height: 4px; }
.ember-field span:nth-child(5) { left: 80%; animation-delay: 2.2s; }
.ember-field span:nth-child(6) { left: 92%; animation-delay: 6.5s; width: 3px; height: 3px; }

@keyframes rise {
  0% { transform: translateY(0) translateX(0); opacity: 0; }
  10% { opacity: 0.9; }
  50% { transform: translateY(-45vh) translateX(15px); }
  90% { opacity: 0; }
  100% { transform: translateY(-95vh) translateX(-10px); opacity: 0; }
}

.auth-card {
  position: relative;
  z-index: 1;
  width: 380px;
  max-width: 90vw;
  background: linear-gradient(180deg, var(--bg-panel-2), var(--bg-panel));
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 36px 32px 28px;
  box-shadow: 0 30px 80px -20px rgba(0, 0, 0, 0.6);
}

.brand { text-align: center; margin-bottom: 24px; }
.brand-mark { font-size: 34px; line-height: 1; margin-bottom: 6px; filter: drop-shadow(0 0 14px rgba(255, 92, 122, 0.5)); }
.brand h1 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 30px;
  margin: 0;
  letter-spacing: 0.3px;
}
.tagline { color: var(--text-muted); font-size: 13.5px; margin: 6px 0 0; }

.auth-tabs {
  display: flex;
  background: var(--bg-deep);
  border-radius: 999px;
  padding: 4px;
  margin-bottom: 22px;
  border: 1px solid var(--line);
}
.tab-btn {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 9px 0;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 600;
  transition: all 0.2s ease;
}
.tab-btn.active {
  background: linear-gradient(135deg, var(--ember), #ff8c6a);
  color: #1a0d10;
}

.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12.5px;
  color: var(--text-muted);
  font-weight: 500;
}
.auth-form input {
  background: var(--bg-deep);
  border: 1px solid var(--line);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  font-size: 14.5px;
  outline: none;
  transition: border-color 0.15s ease;
}
.auth-form input:focus { border-color: var(--ember); }

.form-hint { color: var(--text-faint); font-size: 11.5px; margin: -6px 0 0; }
.form-error { color: var(--danger); font-size: 12.5px; margin: -4px 0 0; min-height: 0; }
.form-error:empty { display: none; }

.btn-primary {
  margin-top: 4px;
  border: none;
  background: linear-gradient(135deg, var(--ember), #ff8c6a);
  color: #1a0d10;
  font-weight: 700;
  font-size: 14.5px;
  padding: 12px;
  border-radius: var(--radius-sm);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 8px 20px -6px rgba(255, 92, 122, 0.5); }
.btn-primary:active { transform: translateY(0); }

.auth-footnote {
  text-align: center;
  color: var(--text-faint);
  font-size: 11.5px;
  margin: 22px 0 0;
  line-height: 1.5;
}

/* ============ APP SCREEN ============ */

#app-screen { display: flex; height: 100vh; height: 100dvh; }

.sidebar {
  width: 300px;
  min-width: 300px;
  background: var(--bg-panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--line-soft);
}
.sidebar-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}
.me { display: flex; align-items: center; gap: 10px; min-width: 0; }
.avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: linear-gradient(135deg, var(--ember), var(--glow));
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px; color: #0d0b14;
  flex-shrink: 0;
}
.avatar.small { width: 34px; height: 34px; font-size: 13px; }
.me-name { font-weight: 600; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 140px; }
.me-sub { font-size: 10.5px; color: var(--text-faint); letter-spacing: 0.3px; text-transform: uppercase; }

.icon-btn {
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  color: var(--text-muted);
  width: 32px; height: 32px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px;
  transition: all 0.15s ease;
  flex-shrink: 0;
  /* Ensure icons are visible */
  line-height: 1;
}
.icon-btn::before {
  content: attr(title);
  position: absolute;
  bottom: -20px;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  font-size: 9px;
  color: var(--text-faint);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
}
.icon-btn:hover::before {
  opacity: 1;
}
.icon-btn:hover { color: var(--text-primary); border-color: var(--ember); }
.icon-btn.tiny { width: 22px; height: 22px; font-size: 10px; }

.add-contact { display: flex; gap: 8px; padding: 14px 18px 6px; }
.add-contact input {
  flex: 1;
  background: var(--bg-deep);
  border: 1px solid var(--line);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 13.5px;
  outline: none;
}
.add-contact input:focus { border-color: var(--glow); }
#add-contact-error { padding: 0 18px; margin: 4px 0 0; }

.contact-list { flex: 1; overflow-y: auto; padding: 10px 10px; }
.empty-hint { color: var(--text-faint); font-size: 12.5px; padding: 20px 12px; line-height: 1.6; text-align: center; }

.contact {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background 0.15s ease;
  margin-bottom: 2px;
  position: relative;
}
.contact:hover { background: var(--bg-elevated); }
.contact.active { background: var(--bg-elevated); box-shadow: inset 2px 0 0 var(--ember); }
.contact-name { font-weight: 600; font-size: 13.5px; }
.contact-preview { font-size: 11.5px; color: var(--text-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 170px; }
.contact-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--text-faint);
  position: absolute; right: 14px; top: 14px;
}
.contact-dot.online { background: #4ade80; box-shadow: 0 0 6px #4ade80; }

.avatar-wrap { position: relative; flex-shrink: 0; }
.unread-badge {
  position: absolute; top: -4px; right: -6px;
  background: linear-gradient(135deg, var(--ember), #d9436a);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 999px;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--bg-panel);
  line-height: 1;
}

/* ============ CHAT PANEL ============ */

.chat-panel { flex: 1; display: flex; flex-direction: column; background: var(--bg-deep); min-width: 0; }

.chat-empty {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--text-faint); text-align: center;
}
.ember-big { font-size: 46px; margin-bottom: 10px; opacity: 0.5; }
.chat-empty h2 { font-family: var(--font-display); font-weight: 500; color: var(--text-muted); margin: 0 0 6px; }
.chat-empty p { font-size: 13px; margin: 0; }

.chat-active { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.chat-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-panel);
  flex-shrink: 0;
  max-width: 100%;
}
.chat-header-user { display: flex; align-items: center; gap: 12px; }
.chat-header-name { font-weight: 600; font-size: 15px; }
.chat-header-status { font-size: 11.5px; color: var(--text-faint); }
.chat-header-status.online { color: #4ade80; }
.chat-header-note {
  font-size: 11px; color: var(--text-faint);
  border: 1px solid var(--line); padding: 5px 11px; border-radius: 999px;
}

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

.msg-row { display: flex; margin-bottom: 10px; max-width: 100%; touch-action: pan-y; position: relative; }
.msg-row.mine { justify-content: flex-end; }
.msg-row.theirs { justify-content: flex-start; }

.msg-group { max-width: 62%; display: flex; flex-direction: column; gap: 2px; }
.msg-row.mine .msg-group { align-items: flex-end; }
.msg-row.theirs .msg-group { align-items: flex-start; }

.bubble {
  position: relative;
  padding: 10px 14px 8px;
  border-radius: var(--radius-md);
  font-size: 14px;
  line-height: 1.45;
  word-wrap: break-word;
  white-space: pre-wrap;
  cursor: default;
}
.msg-row.mine .bubble {
  background: linear-gradient(135deg, var(--ember), #d9436a);
  color: #1c0a10;
  border-bottom-right-radius: 4px;
}
.msg-row.theirs .bubble {
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}

.bubble .reply-quote {
  display: block;
  font-size: 12px;
  padding: 6px 9px;
  border-radius: 8px;
  margin-bottom: 6px;
  opacity: 0.85;
  border-left: 2px solid currentColor;
}
.msg-row.mine .reply-quote { background: rgba(0,0,0,0.12); }
.msg-row.theirs .reply-quote { background: rgba(0,0,0,0.2); }
.bubble .reply-quote.clickable { cursor: pointer; transition: opacity 0.15s ease; }
.bubble .reply-quote.clickable:hover { opacity: 1; }

/* flash highlight when jumping to a message via its reply-quote */
@keyframes flashHighlight {
  0%, 55% { box-shadow: 0 0 0 3px var(--glow); }
  100% { box-shadow: 0 0 0 0 transparent; }
}
.bubble.highlight-flash { animation: flashHighlight 1.5s ease; }

/* swipe-to-reply icon: zero-width flex item so it doesn't add spacing at
   rest, revealed as the message bubble (`.msg-group`) translates away from it */
.reply-swipe-icon {
  width: 0;
  flex-shrink: 0;
  overflow: visible;
  white-space: nowrap;
  opacity: 0;
  color: var(--glow);
  font-size: 17px;
  align-self: center;
  pointer-events: none;
}

.bubble .media-wrap { margin: -2px -6px 4px; border-radius: 10px; overflow: hidden; cursor: zoom-in; max-width: 280px; min-width: 160px; min-height: 90px; position: relative; }
.bubble .media-wrap img, .bubble .media-wrap video { display: block; width: 100%; max-height: 320px; object-fit: cover; background: #000; }
.bubble .media-wrap.loading, .bubble .media-wrap.media-error {
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.18);
  cursor: default;
  min-height: 110px;
}

/* video preview: play overlay + native controls (counter-mirrored via CSS) */
.bubble .media-overlay {
  position: absolute; inset: 0; z-index: 2;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(180deg, rgba(0,0,0,0.08) 0%, rgba(0,0,0,0.15) 40%, rgba(0,0,0,0.45) 100%);
  cursor: pointer;
}
.bubble .media-overlay.hidden { display: none; }
.bubble .media-wrap.playing .media-overlay { display: none; }
.bubble .play-btn {
  width: 48px; height: 48px; border-radius: 50%;
  background: rgba(255,255,255,0.95); color: #0d0b14;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.bubble .play-btn svg { margin-left: 2px; }
.bubble .media-overlay:hover .play-btn { transform: scale(1.1); box-shadow: 0 6px 26px rgba(0,0,0,0.55); }
.bubble .media-overlay:active .play-btn { transform: scale(0.95); }
.bubble .video-badge {
  position: absolute; top: 8px; left: 8px;
  background: rgba(0,0,0,0.55); color: #fff; font-size: 10px; font-weight: 600;
  padding: 3px 8px; border-radius: 999px; letter-spacing: 0.3px;
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  pointer-events: none;
}
.bubble .media-duration {
  position: absolute; right: 8px; bottom: 8px;
  background: rgba(0,0,0,0.6); color: #fff; font-size: 10.5px;
  padding: 2px 7px; border-radius: 999px; font-family: var(--font-mono);
  pointer-events: none;
}
.bubble .media-expand {
  position: absolute; top: 8px; right: 8px; z-index: 3;
  width: 26px; height: 26px; border-radius: 50%; border: none;
  background: rgba(0,0,0,0.55); color: #fff; font-size: 13px;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  opacity: 0.9; transition: opacity 0.15s ease;
}
.bubble .media-wrap:hover .media-expand { opacity: 1; }
.bubble .media-wrap.playing .media-expand { opacity: 1; }
/* touch devices */
@media (hover: none) {
  .bubble .media-expand { opacity: 1; }
  .bubble .play-btn { width: 54px; height: 54px; }
  .bubble .play-btn svg { width: 24px; height: 24px; }
}

/* mirror transform — used only for recording preview (front camera self-view) */
.mirrored { transform: scaleX(-1); }

.media-spinner { font-size: 12px; color: var(--text-faint); text-align: center; padding: 10px; }
.media-error .media-spinner { color: var(--danger); }

.audio-player {
  display: flex; align-items: center; gap: 10px;
  min-width: 210px;
}
.audio-player audio { width: 180px; height: 34px; }

.call-log-row { display: flex; justify-content: center; margin: 8px 0; }
.call-log-pill {
  display: flex; align-items: center; gap: 7px;
  background: var(--bg-elevated); border: 1px solid var(--line);
  padding: 7px 14px; border-radius: 999px; font-size: 12px; color: var(--text-muted);
}
.call-log-pill.missed { color: var(--danger); }

.msg-meta {
  display: flex; align-items: center; gap: 5px;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-faint);
  padding: 0 3px;
}
.fuse-ring {
  width: 13px; height: 13px; border-radius: 50%;
  background: conic-gradient(var(--ember) calc(var(--fuse, 1) * 360deg), rgba(255,255,255,0.1) 0deg);
  flex-shrink: 0;
  position: relative;
}
.fuse-ring::after {
  content: ""; position: absolute; inset: 2px; border-radius: 50%; background: var(--bg-deep);
}

.receipt {
  font-size: 11px;
  letter-spacing: -1px;
  color: var(--text-faint);
}
.receipt.seen { color: var(--glow); }
.sending-spinner {
  font-size: 11px;
  color: var(--text-faint);
  animation: spin 1s linear infinite;
  display: inline-block;
}
@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.msg-row:hover .msg-actions { opacity: 1; }
.msg-actions { opacity: 0; transition: opacity 0.15s ease; display: flex; gap: 2px; align-self: center; margin: 0 6px; }
.msg-actions button {
  background: none; border: none; color: var(--text-faint); font-size: 13px; padding: 4px;
}
.msg-actions button:hover { color: var(--glow); }

.day-divider {
  text-align: center; color: var(--text-faint); font-size: 11px; margin: 14px 0 10px;
  text-transform: uppercase; letter-spacing: 0.5px;
}

.typing-indicator { font-size: 12px; color: var(--text-faint); padding: 0 26px 6px; font-style: italic; min-height: 18px; }
.typing-indicator-bottom {
  font-size: 12px; color: var(--text-faint); padding: 8px 26px 4px;
  font-style: italic; display: flex; align-items: center; gap: 6px;
}
.typing-dots {
  animation: typingBounce 1.4s infinite ease-in-out both;
  display: inline-block;
}
@keyframes typingBounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

/* reply preview above composer */
.reply-preview {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 22px;
  background: var(--bg-panel);
  border-top: 1px solid var(--line);
}
.reply-preview-bar { width: 3px; align-self: stretch; background: var(--glow); border-radius: 2px; }
.reply-preview-body { flex: 1; min-width: 0; }
.reply-preview-label { font-size: 11px; color: var(--glow); font-weight: 600; }
.reply-preview-text { font-size: 12.5px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* composer */
.composer {
  display: flex; flex-direction: column; gap: 8px;
  padding: 14px 22px 18px;
  background: var(--bg-panel);
  border-top: 1px solid var(--line-soft);
  position: relative;
}
.composer-input-row {
  display: flex; align-items: flex-end; gap: 6px;
}
.composer-input-row .icon-btn {
  width: 32px; height: 32px; font-size: 13px;
}
.composer textarea {
  flex: 1;
  resize: none;
  background: var(--bg-deep);
  border: 1px solid var(--line);
  color: var(--text-primary);
  border-radius: var(--radius-md);
  padding: 11px 14px;
  font-size: 14px;
  outline: none;
  max-height: 120px;
  line-height: 1.4;
}
.composer textarea:focus { border-color: var(--glow); }

.btn-send {
  background: linear-gradient(135deg, var(--ember), #ff8c6a);
  border: none; color: #1a0d10;
  width: 40px; height: 40px; border-radius: 50%;
  font-size: 15px;
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.15s ease;
  flex-shrink: 0;
}
.btn-send:hover { transform: scale(1.06); }
.btn-send:disabled { opacity: 0.4; cursor: default; transform: none; }

.upload-preview {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-elevated); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 6px 10px; font-size: 12px; color: var(--text-muted);
  align-self: flex-start;
}
.upload-preview span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 300px; }

/* emoji picker */
.emoji-picker {
  position: absolute;
  bottom: 100%;
  left: 0;
  right: 0;
  margin-bottom: 8px;
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  z-index: 100;
  max-height: 260px;
  overflow-y: auto;
  padding: 8px;
}
.emoji-picker-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
}
.emoji-picker-btn {
  background: none;
  border: none;
  border-radius: 6px;
  padding: 6px;
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
  transition: background 0.15s;
  text-align: center;
}
.emoji-picker-btn:hover {
  background: var(--bg-panel-2);
}

#emoji-suggestions {
  position: absolute;
  bottom: 100%;
  margin-bottom: 8px;
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 6px;
  display: flex;
  gap: 4px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  z-index: 100;
  max-height: 170px;
  overflow-y: auto;
  flex-wrap: wrap;
}
.emoji-suggestion-btn {
  background: var(--bg-deep);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
  transition: all 0.15s;
}
.emoji-suggestion-btn:hover {
  transform: scale(1.1);
  background: var(--bg-panel-2);
}
.emoji-suggestion-btn.selected {
  transform: scale(1.1);
  background: var(--bg-panel-2);
  outline: 2px solid var(--glow);
  outline-offset: -2px;
}

/* lightbox */
.lightbox {
  position: fixed; inset: 0; background: rgba(5, 4, 8, 0.92);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.lightbox #lightbox-close { position: absolute; top: 20px; right: 24px; }
#lightbox-content img, #lightbox-content video { max-width: 88vw; max-height: 88vh; border-radius: 10px; }

/* toast */
.toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%);
  background: var(--bg-elevated); border: 1px solid var(--line);
  padding: 11px 18px; border-radius: 999px; font-size: 13px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.4);
  z-index: 200;
}

/* scrollbars */
.messages::-webkit-scrollbar, .contact-list::-webkit-scrollbar { width: 8px; }
.messages::-webkit-scrollbar-thumb, .contact-list::-webkit-scrollbar-thumb {
  background: var(--bg-elevated); border-radius: 4px;
}

/* ============ sidebar tabs (chats / requests) ============ */
.sidebar-tabs { display: flex; gap: 6px; padding: 4px 14px 8px; }
.sidebar-tab {
  flex: 1; background: transparent; border: 1px solid var(--line); color: var(--text-muted);
  padding: 7px 0; border-radius: 999px; font-size: 12.5px; font-weight: 600;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  transition: all 0.15s ease;
}
.sidebar-tab.active { background: var(--bg-elevated); color: var(--text-primary); border-color: var(--glow); }
.tab-badge {
  background: var(--ember); color: #fff; font-size: 10px; font-weight: 700;
  min-width: 16px; height: 16px; border-radius: 999px; padding: 0 4px;
  display: inline-flex; align-items: center; justify-content: center;
}

.request-item { padding: 12px; border-radius: var(--radius-md); background: var(--bg-elevated); margin-bottom: 8px; }
.request-item .req-top { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.request-item .req-preview { font-size: 12px; color: var(--text-muted); margin-bottom: 10px; }
.request-item .req-actions { display: flex; gap: 8px; }

.btn-mini {
  border: none; border-radius: 8px; padding: 7px 12px; font-size: 12.5px; font-weight: 600; flex: 1;
}
.btn-mini.accept { background: linear-gradient(135deg, var(--glow), #5a7fe0); color: #0a0e1c; }
.btn-mini.reject { background: var(--bg-panel); color: var(--text-muted); border: 1px solid var(--line); }

/* ============ chat header extras ============ */
.chat-header { gap: 12px; }
.chat-header-actions { display: flex; align-items: center; gap: 8px; margin-left: 10px; }
.menu-wrap { position: relative; }
.dropdown-menu {
  position: absolute; top: 40px; right: 0; background: var(--bg-elevated); border: 1px solid var(--line);
  border-radius: var(--radius-sm); overflow: hidden; z-index: 20; min-width: 150px;
  box-shadow: 0 12px 30px rgba(0,0,0,0.4);
}
.dropdown-menu button {
  display: block; width: 100%; text-align: left; padding: 10px 14px; background: none; border: none;
  color: var(--text-primary); font-size: 13px;
}
.dropdown-menu button:hover { background: var(--bg-panel); }
.dropdown-menu button.danger { color: var(--danger); }

.request-banner {
  background: var(--ember-soft); border-bottom: 1px solid var(--line);
  padding: 12px 22px; font-size: 12.5px; color: var(--text-primary);
  display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap;
}
.request-banner p { margin: 0; flex: 1; min-width: 200px; }
.request-banner-actions { display: flex; gap: 8px; }

/* ============ recording overlay ============ */
.recording-overlay {
  position: fixed; inset: 0; background: rgba(5,4,8,0.85); z-index: 150;
  display: flex; align-items: center; justify-content: center;
}
.recording-card {
  background: var(--bg-panel-2); border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: 30px; display: flex; flex-direction: column; align-items: center; gap: 20px; min-width: 280px;
}
.recording-visual { display: flex; align-items: center; gap: 10px; font-family: var(--font-mono); font-size: 20px; }
.rec-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--danger); animation: pulse 1s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.3; } }
#recording-video-preview {
  width: min(72vw, 360px); max-height: 50vh; aspect-ratio: 16 / 9; object-fit: cover;
  border-radius: 14px; border: 1px solid var(--line); background: #000;
}
.recording-review {
  width: min(72vw, 360px); max-height: 50vh; border-radius: 14px; border: 1px solid var(--line); background: #000;
}
.recording-controls-row { display: flex; gap: 14px; align-items: center; }
.recording-actions { display: flex; gap: 16px; }

/* subtle beautify for call self-view (legacy, kept for video calls) */
.beauty { filter: brightness(1.07) contrast(1.04) saturate(1.14); }

/* beauty slider */
.beauty-controls {
  display: flex; align-items: center; gap: 8px;
  width: min(72vw, 360px); padding: 0 4px;
}
.beauty-controls.hidden { display: none; }
.beauty-icon { font-size: 14px; flex-shrink: 0; }
.beauty-slider {
  flex: 1; -webkit-appearance: none; appearance: none;
  height: 4px; border-radius: 2px;
  background: var(--line); outline: none;
  transition: background 0.2s;
}
.beauty-slider::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--ember); border: none; cursor: pointer;
  box-shadow: 0 1px 6px rgba(0,0,0,0.3);
  transition: transform 0.15s;
}
.beauty-slider::-webkit-slider-thumb:hover { transform: scale(1.15); }
.beauty-slider::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--ember); border: none; cursor: pointer;
}
.beauty-value {
  font-size: 11px; font-family: var(--font-mono);
  color: var(--text-muted); min-width: 32px; text-align: right;
}

/* active toggle button */
.icon-btn.active { color: var(--ember); border-color: var(--ember); box-shadow: 0 0 0 1px var(--ember-soft); }

/* ============ calls ============ */
.call-modal { position: fixed; inset: 0; background: rgba(5,4,8,0.9); z-index: 200; display: flex; align-items: center; justify-content: center; }
.call-modal-card { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.avatar.big { width: 84px; height: 84px; font-size: 30px; }
.call-modal-name { font-family: var(--font-display); font-size: 22px; font-weight: 600; margin-top: 6px; }
.call-modal-type { color: var(--text-muted); font-size: 13px; margin-bottom: 14px; }
.call-modal-actions, .call-controls { display: flex; gap: 22px; }
.call-btn {
  width: 56px; height: 56px; border-radius: 50%; border: none; font-size: 20px;
  display: flex; align-items: center; justify-content: center; transition: transform 0.15s ease;
}
.call-btn:hover { transform: scale(1.08); }
.call-btn.accept { background: #4ade80; color: #0a1f0f; }
.call-btn.decline { background: var(--danger); color: #2a0808; }
.call-btn.control { background: var(--bg-elevated); color: var(--text-primary); border: 1px solid var(--line); }
.call-btn.control.off { background: var(--danger); color: #fff; }

.call-overlay {
  position: fixed; inset: 0; background: #05040a; z-index: 200;
  display: flex; flex-direction: column; align-items: center; justify-content: space-between; padding: 30px 0;
}
.call-remote-area { flex: 1; width: 100%; display: flex; align-items: center; justify-content: center; position: relative; }
#remote-video { max-width: 100%; max-height: 100%; border-radius: 12px; }
#remote-video.hidden-video { display: none; }
.call-avatar-fallback { display: flex; flex-direction: column; align-items: center; gap: 10px; color: var(--text-primary); }
#call-timer { font-family: var(--font-mono); color: var(--text-muted); font-size: 13px; }
.local-video-pip {
  position: absolute; bottom: 110px; right: 24px; width: 130px; border-radius: 10px; border: 2px solid var(--line);
  z-index: 5;
}

/* ============ admin panel ============ */
.admin-panel { max-width: 720px; margin: 0 auto; padding: 40px 24px; height: 100vh; overflow-y: auto; }
.admin-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.admin-header h2 { font-family: var(--font-display); font-weight: 600; margin: 0; }
.admin-note { color: var(--text-faint); font-size: 12.5px; margin: 0 0 24px; line-height: 1.6; }
.admin-section { margin-bottom: 24px; padding-bottom: 24px; border-bottom: 1px solid var(--line); }
.admin-section h3 { font-size: 14px; font-weight: 600; margin: 0 0 12px; color: var(--text-primary); }
.admin-setting-row { display: flex; align-items: center; gap: 10px; }
.admin-setting-row label { font-size: 13px; color: var(--text-muted); }
.admin-setting-row input {
  width: 80px; background: var(--bg-deep); border: 1px solid var(--line);
  color: var(--text-primary); border-radius: var(--radius-sm); padding: 8px 10px; font-size: 13px;
}
.admin-user-row {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: var(--radius-md);
  background: var(--bg-panel); border: 1px solid var(--line); margin-bottom: 8px;
}
.admin-user-row .u-name { font-weight: 600; flex: 1; }
.admin-user-row .u-tag {
  font-size: 10.5px; padding: 2px 8px; border-radius: 999px; text-transform: uppercase; letter-spacing: 0.3px;
}
.admin-user-row .u-tag.admin { background: var(--glow-soft); color: var(--glow); }
.admin-user-row .u-tag.suspended { background: rgba(255,92,92,0.15); color: var(--danger); }
.admin-user-row .u-actions { display: flex; gap: 6px; }
.admin-user-row button {
  border: 1px solid var(--line); background: var(--bg-elevated); color: var(--text-primary);
  padding: 6px 11px; border-radius: 8px; font-size: 12px;
}
.admin-user-row button.danger { color: var(--danger); border-color: rgba(255,92,92,0.3); }

/* ============ modal overlay ============ */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(5,4,8,0.85); z-index: 300;
  display: flex; align-items: center; justify-content: center;
}
.modal-card {
  background: var(--bg-panel-2); border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: 28px; min-width: 320px; max-width: 90vw;
}
.modal-card h3 { font-family: var(--font-display); font-weight: 600; margin: 0 0 8px; font-size: 18px; }
.modal-note { color: var(--text-muted); font-size: 13px; margin: 0 0 20px; line-height: 1.5; }
.lifetime-input-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.lifetime-input-row input {
  width: 80px; background: var(--bg-deep); border: 1px solid var(--line);
  color: var(--text-primary); border-radius: var(--radius-sm); padding: 10px 12px; font-size: 15px;
}
.lifetime-input-row span { color: var(--text-muted); font-size: 14px; }
.modal-hint { color: var(--text-faint); font-size: 11.5px; margin: 0 0 20px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }
.password-inputs { display: flex; flex-direction: column; gap: 12px; margin-bottom: 20px; }
.password-inputs label { font-size: 12px; color: var(--text-muted); display: flex; flex-direction: column; gap: 6px; }
.password-inputs input {
  background: var(--bg-deep); border: 1px solid var(--line);
  color: var(--text-primary); border-radius: var(--radius-sm); padding: 10px 12px; font-size: 14px;
}

/* responsive */
/* Larger chat message text on desktop */
@media (min-width: 761px) {
  .bubble { font-size: 28px; }
  #message-input { font-size: 28px; }
  .reply-preview-text { font-size: 25px; }
  .reply-preview-label { font-size: 22px; }
  .day-divider { font-size: 22px; }
  .typing-indicator { font-size: 22px; }
}

@media (max-width: 760px) {
  #app-screen { position: relative; }
  .sidebar {
    position: absolute; inset: 0; z-index: 5; width: 100%; min-width: 0;
    transition: transform 0.25s ease;
  }
  .sidebar.collapsed { transform: translateX(-100%); }
  .chat-panel { width: 100%; }
  .msg-group { max-width: 80%; }
  #back-btn { display: inline-flex !important; }
  
  /* Chat header adjustments for mobile */
  .chat-header { padding: 10px 16px; gap: 8px; }
  .chat-header-actions { gap: 4px; margin-left: 8px; }
  .chat-header-actions .icon-btn { width: 28px; height: 28px; font-size: 12px; }
  .chat-header-note { font-size: 10px; padding: 4px 8px; }
  
  /* Composer adjustments for mobile */
  .composer { padding: 10px 16px 14px; }
  .composer-input-row { gap: 4px; }
  .composer-input-row .icon-btn { width: 28px; height: 28px; font-size: 12px; }
  .composer textarea { padding: 10px 12px; font-size: 14px; }
  .btn-send { width: 36px; height: 36px; font-size: 14px; }
  #emoji-btn { display: none; }
  
  /* Upload preview on mobile */
  .upload-preview span { max-width: 180px; }
  
  /* Sidebar header buttons on mobile */
  .sidebar-header { padding: 14px 14px 10px; }
  .sidebar-header .icon-btn { width: 28px; height: 28px; font-size: 12px; }
  .me-name { max-width: 120px; }
}
