/* ==========================================================================
   GHOSTWIRE SPECIALIZED COMPONENTS STYLESHEET
   - Message Bubbles (Text, Media, Voice Notes, Waveform Scrubbers)
   - Real-time WebRTC Call Overlays (Fullscreen Video, PiP, Controls HUD)
   - Incoming Call Modal with Procedural Audio Ring Pulsing
   - Live Voice Recording Canvas Waveform
   - Settings, Profile, QR Scanner, and Lightbox Modals
   ========================================================================== */

/* --- MESSAGE BUBBLES --- */
.message-row {
  display: flex;
  width: 100%;
  animation: bubblePop 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.message-row.sent {
  justify-content: flex-end;
}

.message-row.received {
  justify-content: flex-start;
}

.message-bubble {
  max-width: 72%;
  min-width: 120px;
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  position: relative;
  word-break: break-word;
  line-height: 1.45;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.message-row.sent .message-bubble {
  background: linear-gradient(135deg, rgba(0, 240, 255, 0.15), rgba(15, 20, 32, 0.9));
  border: 1px solid rgba(0, 240, 255, 0.28);
  border-bottom-right-radius: 4px;
}

.message-row.received .message-bubble {
  background: var(--bg-glass-card);
  border: 1px solid var(--border-subtle);
  border-bottom-left-radius: 4px;
}

.message-text {
  font-size: 14.5px;
  color: var(--text-main);
  white-space: pre-wrap;
  user-select: text;
}

.message-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 2px;
}

.message-time {
  font-size: 10.5px;
  font-family: var(--font-mono);
  color: var(--text-muted);
}

.message-status-ticks {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  color: var(--text-muted);
}

.message-status-ticks.read {
  color: var(--cyan);
}

/* Media Attachment Message */
.media-attachment-container {
  border-radius: var(--radius-md);
  overflow: hidden;
  position: relative;
  max-width: 320px;
  background: rgba(0, 0, 0, 0.4);
  cursor: pointer;
  border: 1px solid var(--border-subtle);
}

.media-thumbnail {
  width: 100%;
  max-height: 280px;
  object-fit: cover;
  display: block;
  transition: transform var(--transition-fast);
}

.media-attachment-container:hover .media-thumbnail {
  transform: scale(1.02);
}

.media-video-player {
  width: 100%;
  max-height: 300px;
  border-radius: var(--radius-md);
  outline: none;
}

.transfer-progress-overlay {
  position: absolute;
  inset: 0;
  background: rgba(6, 9, 15, 0.82);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px;
}

.progress-bar-bg {
  width: 100%;
  height: 6px;
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--cyan), var(--emerald));
  transition: width 0.15s ease;
}

.progress-text {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--cyan);
}

/* Voice Note Bubble & Waveform Player */
.voice-player {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 0;
  min-width: 230px;
}

.voice-play-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--cyan);
  border: none;
  color: #06090f;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  box-shadow: 0 0 10px rgba(0, 240, 255, 0.3);
  transition: var(--transition-fast);
}

.voice-play-btn:hover {
  transform: scale(1.06);
  box-shadow: 0 0 16px rgba(0, 240, 255, 0.5);
}

.waveform-scrubber-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.waveform-bars {
  display: flex;
  align-items: center;
  gap: 2.5px;
  height: 28px;
  cursor: pointer;
}

.waveform-bar {
  flex: 1;
  min-width: 2px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 2px;
  transition: background var(--transition-fast), height 0.1s ease;
}

.waveform-bar.played {
  background: var(--cyan);
}

.voice-meta-row {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-muted);
}

/* Call Log Bubble */
.call-log-bubble {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-subtle);
  margin: 6px auto;
  font-size: 12px;
  color: var(--text-secondary);
}

.call-log-bubble .icon {
  color: var(--cyan);
}

/* --- LIVE VOICE RECORDING TRAY --- */
.voice-recording-tray {
  position: absolute;
  inset: 0;
  background: var(--bg-secondary);
  border-radius: var(--radius-xl);
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 15;
  border: 1px solid var(--cyan);
  box-shadow: 0 0 20px rgba(0, 240, 255, 0.2);
  animation: slideUp 0.2s ease;
}

.voice-recording-tray.active {
  display: flex;
}

.recording-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
}

.recording-pulse-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--crimson);
  box-shadow: 0 0 10px var(--crimson);
  animation: pulse 1.2s infinite;
}

.recording-timer {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 700;
  color: var(--crimson);
}

.recording-canvas {
  flex: 1;
  height: 36px;
  margin: 0 16px;
}

.recording-tray-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-cancel-recording {
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  background: rgba(255, 51, 102, 0.15);
  border: 1px solid rgba(255, 51, 102, 0.3);
  color: var(--crimson);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
}

.btn-send-recording {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--emerald);
  border: none;
  color: #06090f;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 0 12px var(--emerald);
}

/* --- WEBRTC CALL OVERLAY --- */
.call-overlay {
  position: fixed;
  inset: 0;
  z-index: 900;
  background: #06080d;
  display: none;
  flex-direction: column;
  animation: fadeIn 0.3s ease;
}

.call-overlay.active {
  display: flex;
}

.call-video-stage {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.remote-video-element {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.local-video-pip {
  position: absolute;
  top: 24px;
  right: 24px;
  width: 160px;
  height: 220px;
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 2px solid var(--cyan);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.8), 0 0 20px rgba(0, 240, 255, 0.3);
  z-index: 20;
  background: #0a0d14;
  cursor: grab;
  transition: transform 0.1s ease;
}

.local-video-element {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1); /* Mirror local selfie feed */
}

.call-header-hud {
  position: absolute;
  top: 24px;
  left: 24px;
  display: flex;
  align-items: center;
  gap: 14px;
  z-index: 15;
  background: rgba(10, 13, 20, 0.75);
  backdrop-filter: var(--blur-glass);
  padding: 8px 16px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-subtle);
}

.call-peer-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-main);
}

.call-duration-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--emerald);
}

.call-audio-avatar-stage {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  z-index: 10;
  background: radial-gradient(circle at center, #151b2a, #06080d);
}

.call-avatar-pulsar {
  position: relative;
  width: 130px;
  height: 130px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pulsar-ring {
  position: absolute;
  inset: -12px;
  border-radius: 50%;
  border: 2px solid var(--emerald);
  animation: ringPulse 2s infinite;
}

.call-controls-hud {
  position: absolute;
  bottom: 36px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 24px;
  border-radius: var(--radius-pill);
  background: rgba(15, 20, 32, 0.85);
  backdrop-filter: var(--blur-glass);
  border: 1px solid var(--border-glow);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.7);
  z-index: 25;
}

.call-hud-btn {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition-fast);
}

.call-hud-btn:hover {
  background: rgba(255, 255, 255, 0.16);
  transform: translateY(-2px);
}

.call-hud-btn.active {
  background: rgba(255, 51, 102, 0.2);
  border-color: var(--crimson);
  color: var(--crimson);
}

.call-hud-btn.hangup {
  width: 58px;
  height: 58px;
  background: var(--crimson);
  color: #fff;
  border: none;
  box-shadow: 0 0 20px var(--crimson-glow);
}

.call-hud-btn.hangup:hover {
  transform: scale(1.08);
  box-shadow: 0 0 30px var(--crimson-glow);
}

/* --- INCOMING CALL MODAL --- */
.incoming-call-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(6, 8, 13, 0.88);
  backdrop-filter: var(--blur-glass);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.3s ease;
}

.incoming-call-modal.active {
  display: flex;
}

.incoming-call-card {
  width: 100%;
  max-width: 360px;
  background: var(--bg-glass-card);
  border: 1px solid var(--border-glow);
  border-radius: var(--radius-xl);
  padding: 32px 24px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.8), 0 0 35px rgba(0, 240, 255, 0.18);
}

.incoming-caller-avatar-wrap {
  position: relative;
  width: 96px;
  height: 96px;
  border-radius: 50%;
  overflow: hidden;
  border: 2px solid var(--cyan);
  box-shadow: 0 0 20px rgba(0, 240, 255, 0.4);
}

.incoming-call-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-main);
}

.incoming-call-type {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--cyan);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.incoming-call-actions {
  display: flex;
  align-items: center;
  gap: 24px;
  margin-top: 12px;
}

.btn-reject-call {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--crimson);
  border: none;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 0 18px var(--crimson-glow);
  transition: var(--transition-fast);
}

.btn-reject-call:hover {
  transform: scale(1.08);
}

.btn-accept-call {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--emerald);
  border: none;
  color: #06090f;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 0 20px var(--emerald-glow);
  animation: ringPulse 1.6s infinite;
  transition: var(--transition-fast);
}

.btn-accept-call:hover {
  transform: scale(1.08);
}

/* --- GENERAL MODALS (Settings, Profile, Add Contact, Lightbox) --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: rgba(6, 8, 13, 0.8);
  backdrop-filter: var(--blur-glass);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.2s ease;
}

.modal-overlay.active {
  display: flex;
}

.modal-box {
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--bg-glass-card);
  border: 1px solid var(--border-glow);
  border-radius: var(--radius-xl);
  padding: 28px;
  box-shadow: var(--shadow-md);
  position: relative;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-subtle);
}

.modal-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-main);
}

.modal-close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 20px;
  transition: color var(--transition-fast);
}

.modal-close-btn:hover {
  color: var(--crimson);
}

/* QR Code Display & Scanner */
.qr-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 16px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-subtle);
}

.qr-box {
  padding: 14px;
  background: #fff;
  border-radius: var(--radius-md);
  box-shadow: 0 0 20px rgba(0, 240, 255, 0.2);
}

.qr-svg {
  display: block;
}

/* Lightbox Modal */
.lightbox-modal {
  position: fixed;
  inset: 0;
  z-index: 1100;
  background: rgba(4, 6, 10, 0.95);
  backdrop-filter: blur(25px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 30px;
}

.lightbox-modal.active {
  display: flex;
}

.lightbox-img {
  max-width: 90vw;
  max-height: 85vh;
  object-fit: contain;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.9);
}

.lightbox-close-btn {
  position: absolute;
  top: 24px;
  right: 24px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--border-subtle);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 20px;
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 1200;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast {
  padding: 12px 18px;
  border-radius: var(--radius-md);
  background: var(--bg-glass-card);
  backdrop-filter: var(--blur-glass);
  border: 1px solid var(--border-glow);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
  color: var(--text-main);
  font-size: 13.5px;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: toastSlide 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: auto;
}

.toast.success {
  border-color: var(--emerald);
}

.toast.error {
  border-color: var(--crimson);
}

@keyframes bubblePop {
  0% { transform: scale(0.95); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes slideUp {
  from { transform: translateY(100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@keyframes toastSlide {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
