:root,
[data-theme="dark"] {
  --bg-outer: #050507;
  --bg-app: #0a0a0c;
  --bg-surface: #121216;
  --bg-elevated: #1b1b21;
  --bg-input: #17171c;
  --border-subtle: rgba(255, 255, 255, 0.08);
  --text-main: #f4f4f5;
  --text-muted: #a1a1aa;
  --text-faint: #71717a;
  --accent: #10b981;
  --accent-strong: #059669;
  --accent-soft: rgba(16, 185, 129, 0.12);
  --bubble-me: #059669;
  --bubble-me-text: #ffffff;
  --bubble-them: #19191f;
  --bubble-them-text: #f4f4f5;
  --quote-me-bg: rgba(0, 0, 0, 0.2);
  --quote-them-bg: rgba(255, 255, 255, 0.05);
  --read-tick: #7dd3fc;
  --sent-tick: rgba(255, 255, 255, 0.7);
  --danger: #ef4444;
  --shadow-shell: 0 24px 60px rgba(0, 0, 0, 0.65);
  --badge-safe-bottom: 0px;
}

[data-theme="light"] {
  --bg-outer: #eaecef;
  --bg-app: #ffffff;
  --bg-surface: #ffffff;
  --bg-elevated: #f4f4f5;
  --bg-input: #f4f4f5;
  --border-subtle: rgba(0, 0, 0, 0.08);
  --text-main: #18181b;
  --text-muted: #71717a;
  --text-faint: #a1a1aa;
  --accent: #059669;
  --accent-strong: #047857;
  --accent-soft: rgba(5, 150, 105, 0.1);
  --bubble-me: #059669;
  --bubble-me-text: #ffffff;
  --bubble-them: #f1f2f4;
  --bubble-them-text: #18181b;
  --quote-me-bg: rgba(0, 0, 0, 0.14);
  --quote-them-bg: rgba(0, 0, 0, 0.05);
  --read-tick: #bae6fd;
  --sent-tick: rgba(255, 255, 255, 0.8);
  --danger: #e11d48;
  --shadow-shell: 0 18px 44px rgba(0, 0, 0, 0.08);
}

/* Automatic bottom clearance on Netlify free tier so floating corner badge never covers Mic/Send */
body.netlify-host {
  --badge-safe-bottom: 44px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-outer);
  color: var(--text-main);
  -webkit-font-smoothing: antialiased;
}

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

.hidden {
  display: none !important;
}

/* ================= APP SHELL ================= */
.app-shell {
  position: relative;
  width: 100%;
  height: 100dvh;
  background: var(--bg-app);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

@media (min-width: 541px) {
  body {
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .app-shell {
    max-width: 440px;
    height: min(92dvh, 860px);
    border-radius: 26px;
    border: 1px solid var(--border-subtle);
    box-shadow: var(--shadow-shell);
  }
  body.netlify-host {
    --badge-safe-bottom: 0px;
  }
}

.screen {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ================= AUTH SCREEN ================= */
.auth-screen {
  background: var(--bg-app);
}

.auth-scroll {
  flex: 1;
  overflow-y: auto;
  padding: calc(24px + env(safe-area-inset-top, 0px)) 22px calc(24px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

.brand-hero {
  margin-top: auto;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.brand-logo {
  width: 68px;
  height: 68px;
  border-radius: 18px;
  margin-bottom: 4px;
}

.brand-title {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.brand-subtitle {
  font-size: 13.5px;
  color: var(--text-muted);
}

.slot-pill {
  margin-top: 6px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
}

.slot-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
}

.slot-dot.full {
  background: #f59e0b;
}

.auth-card {
  margin-bottom: auto;
  width: 100%;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 20px;
  padding: 18px;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--bg-input);
  padding: 3px;
  border-radius: 11px;
  margin-bottom: 16px;
}

.auth-tab {
  border: none;
  background: transparent;
  padding: 9px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
}

.auth-tab.active {
  background: var(--bg-elevated);
  color: var(--text-main);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
}

[data-theme="light"] .auth-tab.active {
  background: #ffffff;
}

.auth-alert {
  padding: 10px 12px;
  border-radius: 11px;
  font-size: 13px;
  margin-bottom: 14px;
  background: rgba(244, 63, 94, 0.12);
  border: 1px solid rgba(244, 63, 94, 0.25);
  color: #fda4af;
  line-height: 1.4;
}

[data-theme="light"] .auth-alert {
  color: #be123c;
}

.auth-form,
.auth-form-inner {
  display: flex;
  flex-direction: column;
  gap: 13px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
}

.field input {
  width: 100%;
  padding: 11px 13px;
  border-radius: 11px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-input);
  font-size: 15px;
  outline: none;
  transition: border-color 0.15s ease;
}

.field input:focus {
  border-color: var(--accent);
}

.password-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.password-wrap input {
  padding-right: 54px;
}

.toggle-pw {
  position: absolute;
  right: 8px;
  border: none;
  background: transparent;
  padding: 4px 6px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.color-swatches {
  display: flex;
  gap: 10px;
  padding: 2px 0;
}

.swatch {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid transparent;
  background: var(--sw);
  cursor: pointer;
  transition: transform 0.12s ease;
}

.swatch.selected {
  transform: scale(1.1);
  border-color: var(--text-main);
}

.btn-primary {
  width: 100%;
  padding: 12px 16px;
  border: none;
  border-radius: 11px;
  background: var(--accent);
  color: #ffffff;
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s ease, transform 0.1s ease;
}

.btn-primary:active {
  transform: scale(0.99);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-secondary {
  margin-top: 6px;
  padding: 9px 15px;
  border-radius: 10px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-elevated);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.locked-notice {
  text-align: center;
  padding: 16px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.locked-notice h3 {
  font-size: 15px;
  font-weight: 600;
}

.locked-notice p {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.45;
}

/* ================= CHAT HEADER ================= */
.chat-header {
  padding: calc(10px + env(safe-area-inset-top, 0px)) 12px 10px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  z-index: 10;
}

.partner-info {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}

.avatar-wrap {
  position: relative;
  flex-shrink: 0;
}

.avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--accent);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 15px;
  text-transform: uppercase;
}

.presence-dot {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid var(--bg-surface);
  background: #71717a;
}

.presence-dot.online {
  background: #22c55e;
}

.partner-meta {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.partner-name {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.partner-status {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.partner-status.typing,
.partner-status.online-text {
  color: var(--accent);
  font-weight: 500;
}

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

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s ease, color 0.15s ease;
}

.icon-btn:hover,
.icon-btn:active {
  background: var(--bg-elevated);
  color: var(--text-main);
}

.icon-btn.danger-hover:hover {
  color: var(--danger);
}

/* ================= WAITING BANNER ================= */
.waiting-banner {
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border-subtle);
  padding: 8px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
  color: var(--text-muted);
}

.btn-mini {
  flex-shrink: 0;
  border: none;
  background: var(--accent);
  color: #ffffff;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 11px;
  border-radius: 8px;
  cursor: pointer;
}

/* ================= MESSAGES VIEWPORT ================= */
.messages-viewport {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 14px 14px 10px;
  background-color: var(--bg-app);
  display: flex;
  flex-direction: column;
  overscroll-behavior-y: contain;
  overflow-anchor: none;
}

.messages-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: auto;
}

.empty-chat {
  margin: auto 20px;
  padding: 24px 18px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.empty-chat h3 {
  font-size: 15px;
  font-weight: 600;
}

.empty-chat p {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.45;
}

.date-divider {
  align-self: center;
  margin: 12px 0 8px;
  padding: 3px 10px;
  border-radius: 999px;
  color: var(--text-faint);
  font-size: 11.5px;
  font-weight: 500;
}

/* ================= MESSAGE ROW, SWIPE TO REPLY & BUBBLE ================= */
.msg-row {
  position: relative;
  display: flex;
  flex-direction: column;
  max-width: 82%;
  margin-bottom: 2px;
  touch-action: pan-y;
}

.msg-row.me {
  align-self: flex-end;
  align-items: flex-end;
}

.msg-row.them {
  align-self: flex-start;
  align-items: flex-start;
}

.msg-row.highlight-flash .bubble {
  animation: flashPulse 1s ease;
}

@keyframes flashPulse {
  0%, 100% { opacity: 1; }
  40% { box-shadow: 0 0 0 2px var(--accent); }
}

.swipe-wrap {
  position: relative;
  display: flex;
  align-items: center;
  max-width: 100%;
}

.swipe-reply-hint {
  position: absolute;
  left: 4px;
  z-index: 0;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transform: scale(0.5);
  pointer-events: none;
  transition: background 0.12s ease, color 0.12s ease;
}

.swipe-reply-hint.ready {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.bubble {
  position: relative;
  z-index: 1;
  padding: 8px 12px 7px;
  border-radius: 18px;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  max-width: 100%;
  user-select: text;
  will-change: transform;
}

.bubble.snap-back {
  transition: transform 0.22s cubic-bezier(0.2, 0.9, 0.3, 1);
}

.msg-row.me .bubble {
  background: var(--bubble-me);
  color: var(--bubble-me-text);
  border-bottom-right-radius: 5px;
}

.msg-row.them .bubble {
  background: var(--bubble-them);
  color: var(--bubble-them-text);
  border-bottom-left-radius: 5px;
}

/* Quoted Reply inside Bubble */
.quoted-box {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 5px 9px;
  margin-bottom: 5px;
  border-radius: 9px;
  border-left: 2.5px solid var(--accent);
  background: var(--quote-them-bg);
  font-size: 12px;
  cursor: pointer;
}

.msg-row.me .quoted-box {
  background: var(--quote-me-bg);
  border-left-color: rgba(255, 255, 255, 0.75);
}

.quoted-author {
  font-weight: 600;
  font-size: 11px;
  opacity: 0.9;
}

.quoted-snippet {
  opacity: 0.82;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Image inside Bubble */
.bubble-img-wrap {
  margin: 2px -4px 5px;
  border-radius: 12px;
  overflow: hidden;
  max-width: 250px;
}

.bubble-img {
  display: block;
  width: 100%;
  max-height: 290px;
  object-fit: cover;
  cursor: zoom-in;
}

/* ================= VOICE NOTE PLAYER (WITH BACKWARD, FORWARD & SCRUBBER) ================= */
.voice-player {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 228px;
  padding: 2px 0 3px;
  touch-action: none;
}

.voice-controls-group {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.voice-skip-btn {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.14);
  color: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 10px;
  font-weight: 700;
  padding: 0;
}

.msg-row.them .voice-skip-btn {
  background: var(--bg-elevated);
  color: var(--text-muted);
}

.voice-skip-btn:active {
  transform: scale(0.9);
}

.voice-play-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.24);
  color: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

.msg-row.them .voice-play-btn {
  background: var(--accent-soft);
  color: var(--accent);
}

.voice-track-col {
  flex: 1;
  min-width: 105px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.voice-scrubber {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 16px;
  background: transparent;
  cursor: pointer;
  outline: none;
  margin: 0;
}

.voice-scrubber::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 999px;
  background: linear-gradient(
    to right,
    #ffffff 0%,
    #ffffff var(--seek-pct, 0%),
    rgba(255, 255, 255, 0.28) var(--seek-pct, 0%),
    rgba(255, 255, 255, 0.28) 100%
  );
}

.msg-row.them .voice-scrubber::-webkit-slider-runnable-track {
  background: linear-gradient(
    to right,
    var(--accent) 0%,
    var(--accent) var(--seek-pct, 0%),
    rgba(161, 161, 170, 0.28) var(--seek-pct, 0%),
    rgba(161, 161, 170, 0.28) 100%
  );
}

.voice-scrubber::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #ffffff;
  margin-top: -4px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}

.msg-row.them .voice-scrubber::-webkit-slider-thumb {
  background: var(--accent);
}

.voice-scrubber::-moz-range-track {
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.28);
}

.voice-scrubber::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border: none;
  border-radius: 50%;
  background: #ffffff;
}

.voice-duration {
  font-size: 10.5px;
  opacity: 0.85;
  font-variant-numeric: tabular-nums;
}

.bubble-text {
  font-size: 14.5px;
  line-height: 1.42;
  white-space: pre-wrap;
}

.bubble-text a {
  color: inherit;
  text-decoration: underline;
}

.bubble-meta {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  float: right;
  margin: 4px 0 -2px 9px;
  font-size: 10.5px;
  opacity: 0.75;
  user-select: none;
}

.msg-row.them .bubble-meta {
  color: var(--text-muted);
}

.tick {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: -2px;
  margin-right: 1px;
}

.tick.sent {
  color: var(--sent-tick);
}

.tick.read {
  color: var(--read-tick);
}

/* Minimal Tap Action (Delete own message) */
.msg-actions {
  margin-top: 4px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px;
  border-radius: 999px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
}

.menu-action-btn {
  border: none;
  background: transparent;
  font-size: 11.5px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  cursor: pointer;
  color: var(--text-muted);
}

.menu-action-btn.del {
  color: var(--danger);
}

/* Typing Row */
.typing-row {
  display: flex;
  align-items: center;
  margin-top: 6px;
}

.typing-bubble {
  background: var(--bubble-them);
  padding: 9px 12px;
  border-radius: 16px;
  border-bottom-left-radius: 5px;
  display: inline-flex;
  gap: 4px;
}

.typing-bubble .dot {
  width: 5.5px;
  height: 5.5px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: bounceDot 1.2s infinite ease-in-out;
}

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

@keyframes bounceDot {
  0%, 80%, 100% { transform: scale(0.7); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* Scroll to Bottom Button */
.scroll-bottom-btn {
  position: absolute;
  right: 16px;
  bottom: calc(76px + var(--badge-safe-bottom));
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-main);
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 12;
}

.unread-pill {
  position: absolute;
  top: -5px;
  right: -4px;
  background: var(--accent);
  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;
}

/* ================= COMPOSER & VOICE RECORDER ================= */
.composer-area {
  background: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
  padding: 8px 10px calc(8px + var(--badge-safe-bottom) + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: 7px;
  z-index: 10;
}

.composer-drawer {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-input);
  border-radius: 12px;
  padding: 7px 10px;
}

.reply-bar-accent {
  width: 3px;
  align-self: stretch;
  border-radius: 3px;
  background: var(--accent);
}

.reply-bar-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.reply-bar-author {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--accent);
}

.reply-bar-text {
  font-size: 12.5px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.photo-preview-thumb {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  object-fit: cover;
}

.photo-bar-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  font-size: 12.5px;
}

.photo-bar-info span {
  font-size: 11px;
  color: var(--text-muted);
}

.drawer-close {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
}

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

.hidden-file-input {
  display: none;
}

.attach-btn,
.mic-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: var(--bg-input);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s ease, color 0.15s ease;
}

.attach-btn:hover,
.attach-btn:active,
.mic-btn:hover,
.mic-btn:active {
  color: var(--text-main);
  background: var(--bg-elevated);
}

.input-pill {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: 20px;
  padding: 8px 14px;
  display: flex;
  align-items: center;
}

.input-pill:focus-within {
  border-color: rgba(16, 185, 129, 0.45);
}

#message-input {
  width: 100%;
  border: none;
  background: transparent;
  resize: none;
  outline: none;
  font-size: 15px;
  line-height: 1.38;
  max-height: 108px;
  overflow-y: auto;
}

.send-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity 0.15s ease, transform 0.1s ease;
}

.send-btn:active {
  transform: scale(0.92);
}

/* Active Voice Recording Bar */
.voice-rec-bar {
  display: flex;
  align-items: center;
  gap: 8px;
}

.rec-cancel-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: rgba(239, 68, 68, 0.14);
  color: var(--danger);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

.rec-status-pill {
  flex: 1;
  height: 38px;
  border-radius: 20px;
  background: var(--bg-input);
  border: 1px solid rgba(239, 68, 68, 0.28);
  padding: 0 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.rec-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
  animation: recBlink 1s infinite ease-in-out;
}

@keyframes recBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.25; }
}

.rec-timer {
  font-size: 13.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  min-width: 36px;
}

.rec-bars {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  height: 18px;
}

.rec-bars span {
  width: 3px;
  height: 5px;
  border-radius: 3px;
  background: var(--accent);
  transition: height 0.08s ease;
}

/* ================= VOICE & VIDEO CALL OVERLAY ================= */
.call-overlay {
  position: absolute;
  inset: 0;
  background: #09090c;
  color: #f4f4f5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: calc(48px + env(safe-area-inset-top, 0px)) 24px calc(52px + env(safe-area-inset-bottom, 0px));
  z-index: 50;
  overflow: hidden;
}

.remote-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000000;
  z-index: 1;
}

.local-video {
  position: absolute;
  top: calc(16px + env(safe-area-inset-top, 0px));
  right: 16px;
  width: 104px;
  height: 148px;
  border-radius: 14px;
  object-fit: cover;
  background: #18181b;
  border: 1.5px solid rgba(255, 255, 255, 0.22);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.5);
  transform: scaleX(-1);
  z-index: 3;
}

.local-video.back-cam {
  transform: none;
}

.call-center-info {
  position: relative;
  z-index: 2;
  margin-top: 8vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.6);
}

.call-overlay.video-connected .call-center-info {
  margin-top: 0;
  align-self: flex-start;
  align-items: flex-start;
  text-align: left;
}

.call-overlay.video-connected .call-avatar-ring {
  display: none;
}

.call-avatar-ring {
  padding: 8px;
  border-radius: 50%;
  background: rgba(16, 185, 129, 0.12);
  animation: callRingPulse 2s infinite ease-out;
}

@keyframes callRingPulse {
  0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.35); }
  70% { box-shadow: 0 0 0 20px rgba(16, 185, 129, 0); }
  100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

.call-avatar {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  background: var(--accent);
  color: #ffffff;
  font-size: 32px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  text-transform: uppercase;
}

.call-partner-name {
  font-size: 22px;
  font-weight: 700;
}

.call-state-text {
  font-size: 14px;
  color: rgba(244, 244, 245, 0.78);
  font-variant-numeric: tabular-nums;
}

.call-audio-badge {
  margin-top: 2px;
  padding: 4px 11px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.14);
  font-size: 11.5px;
  font-weight: 500;
  color: #e4e4e7;
}

/* Speaker Selector Popover (Phone Speaker vs Loud Speaker) */
.speaker-menu {
  position: relative;
  z-index: 4;
  margin-top: auto;
  margin-bottom: 12px;
  width: 220px;
  background: rgba(24, 24, 29, 0.94);
  backdrop-filter: blur(14px);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 16px;
  padding: 5px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
}

.speaker-opt {
  width: 100%;
  border: none;
  background: transparent;
  color: #f4f4f5;
  padding: 10px 12px;
  border-radius: 11px;
  font-size: 13.5px;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
}

.speaker-opt.active {
  background: rgba(16, 185, 129, 0.18);
  color: #34d399;
}

.speaker-opt-left {
  display: inline-flex;
  align-items: center;
  gap: 9px;
}

.speaker-check {
  font-weight: 700;
}

.call-controls {
  position: relative;
  z-index: 3;
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 12px 18px;
  border-radius: 999px;
  background: rgba(24, 24, 27, 0.72);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.speaker-menu:not(.hidden) + .incoming-controls,
.speaker-menu:not(.hidden) ~ .active-controls {
  margin-top: 0;
}

.incoming-controls {
  gap: 44px;
  background: transparent;
  border: none;
  backdrop-filter: none;
}

.call-ctrl-btn {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  border: none;
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease;
}

.call-ctrl-btn:active {
  transform: scale(0.92);
}

.call-ctrl-btn.neutral {
  background: rgba(255, 255, 255, 0.15);
}

.call-ctrl-btn.neutral.off {
  background: #ffffff;
  color: #09090c;
}

.call-ctrl-btn.decline {
  background: #ef4444;
}

.call-ctrl-btn.accept {
  width: 60px;
  height: 60px;
  background: #22c55e;
}

.incoming-controls .call-ctrl-btn.decline {
  width: 60px;
  height: 60px;
}

/* ================= LIGHTBOX & TOAST ================= */
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.82);
  backdrop-filter: blur(6px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 40;
}

.lightbox-topbar {
  position: absolute;
  top: calc(12px + env(safe-area-inset-top, 0px));
  left: 14px;
  right: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.lightbox-caption {
  color: #f4f4f5;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lightbox-actions {
  display: flex;
  gap: 8px;
}

.light-btn {
  background: rgba(255, 255, 255, 0.14);
  color: #ffffff;
}

.lightbox-img {
  max-width: 100%;
  max-height: 82dvh;
  border-radius: 12px;
  object-fit: contain;
}

.toast {
  position: absolute;
  bottom: calc(74px + var(--badge-safe-bottom) + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  background: #18181b;
  color: #f4f4f5;
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 8px 15px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  z-index: 60;
  white-space: nowrap;
}
