/* VoIP web overlay — modal-style fullscreen call UI.
   Активен когда data-state != 'idle'. */

#voip-overlay {
  position: fixed;
  inset: 0;
  background: linear-gradient(180deg, var(--c-brand) 0%, var(--c-brand-hover) 100%);
  color: var(--c-on-brand);
  z-index: 10000;
  display: none;
  flex-direction: column;
  align-items: stretch;
  justify-content: space-between;
}
#voip-overlay.is-active { display: flex; }

.voip-video-stage {
  position: relative;
  flex: 1;
  background: #000;
  overflow: hidden;
}
#voip-remote-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
}
.voip-local-pip {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 120px;
  height: 160px;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 18px rgba(0,0,0,.4);
  background: #000;
}
#voip-local-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);  /* mirror — для front camera */
}

/* Когда incoming или audio-only — скрываем video-stage, показываем плашку. */
#voip-overlay[data-state="ringing-in"] .voip-video-stage,
#voip-overlay[data-state="connecting"] .voip-video-stage {
  flex: 0 0 0;
  height: 0;
}

.voip-info {
  text-align: center;
  padding: 48px 24px 16px;
}
.voip-info__avatar {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  background: rgba(255,255,255,.18);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  font-weight: 600;
  margin-bottom: 14px;
}
.voip-info__name {
  font-size: 26px;
  font-weight: 600;
  margin: 0 0 4px;
}
.voip-info__status {
  font-size: 15px;
  opacity: 0.85;
  margin: 0;
}
.voip-info__duration {
  display: block;
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
  opacity: 0.7;
}

.voip-controls {
  display: flex;
  justify-content: space-evenly;
  align-items: center;
  padding: 24px 16px 36px;
  gap: 12px;
}
.voip-btn {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  border: none;
  background: transparent;
  color: var(--c-on-brand);
  cursor: pointer;
  font: inherit;
  padding: 0;
}
.voip-btn__circle {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: rgba(255,255,255,.18);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background .15s;
}
.voip-btn__circle svg,
.voip-btn__circle .material-symbols-outlined {
  font-size: 28px;
  color: var(--c-on-brand);
}
.voip-btn:hover .voip-btn__circle { background: rgba(255,255,255,.28); }
.voip-btn--danger .voip-btn__circle { background: var(--md-sys-color-error); }
.voip-btn--accept .voip-btn__circle { background: var(--c-brand); }
.voip-btn.is-on .voip-btn__circle { background: #ffb74d; color: var(--c-text); }
.voip-btn.is-on .voip-btn__circle svg { color: var(--c-text); }
.voip-btn__label { font-size: 12px; opacity: 0.85; }

/* ringing-in: показываем только Accept/Decline */
#voip-overlay[data-state="ringing-in"] .voip-controls-active,
#voip-overlay[data-state="ringing-in"] .voip-controls-video,
#voip-overlay[data-state="connecting"] .voip-controls-incoming,
#voip-overlay[data-state="connecting"] .voip-controls-video,
#voip-overlay[data-state="connected"] .voip-controls-incoming {
  display: none;
}
#voip-overlay[data-state="ringing-in"] .voip-controls-incoming,
#voip-overlay[data-state="connecting"] .voip-controls-active,
#voip-overlay[data-state="connected"] .voip-controls-active {
  display: flex;
}
.voip-controls-video { display: none; }
/* Включается JS если _isVideoCall=true */

/* Кнопки звонка в карточке объявления */
.detail-call-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}
.detail-call-actions .btn {
  flex: 1 1 0;
}
.btn--call {
  border: 1.5px solid var(--c-brand);
  color: var(--md-sys-color-success);
  background: rgba(76,175,80,0.05);
}
.btn--call:hover { background: rgba(76,175,80,0.15); }

/* Toggle VoIP в header — chip */
.header-voip-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.3);
  background: rgba(255,255,255,0.06);
  color: inherit;
  font-size: 13px;
  cursor: pointer;
}
.header-voip-toggle[data-enabled="1"] {
  background: rgba(30,166,81,.15);
  border-color: rgba(30,166,81,.6);
  color: var(--c-brand);
}

/* Mobile */
@media (max-width: 639.98px) {
  .voip-info { padding-top: 32px; }
  .voip-info__avatar { width: 78px; height: 78px; font-size: 32px; }
  .voip-info__name { font-size: 20px; }
  .voip-local-pip { width: 96px; height: 130px; top: 12px; right: 12px; }
}

/* Full-screen режим (toggle через кнопку voip-toggle-fullscreen). */
.voip-toggle-fullscreen {
  position: absolute; top: 12px; right: 12px;
  background: rgba(0,0,0,0.5); color: var(--c-on-brand);
  border: none; border-radius: 50%; width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; z-index: 2;
}
.voip-toggle-fullscreen:hover { background: rgba(0,0,0,0.7); }
#voip-overlay.voip-overlay--fullscreen {
  inset: 0 !important;
  width: 100vw !important; height: 100vh !important;
  max-width: 100vw !important; max-height: 100vh !important;
  border-radius: 0 !important;
  z-index: 10000;
}
#voip-overlay.voip-overlay--fullscreen .voip-video-stage {
  flex: 1; min-height: 0;
}
#voip-overlay.voip-overlay--fullscreen #voip-remote-video {
  width: 100% !important; height: 100% !important; object-fit: cover;
}
#voip-overlay.voip-overlay--fullscreen .voip-local-pip {
  position: absolute; top: 80px; right: 16px;
  width: 140px; height: 200px;
}
#voip-overlay.voip-overlay--fullscreen .voip-controls {
  padding: 24px; gap: 20px;
}
#voip-overlay.voip-overlay--fullscreen .voip-btn__circle {
  width: 64px !important; height: 64px !important;
}

/* ===== Плашка «звонки только в мобильном приложении» =====================
   Показывается вместо исходящего звонка (см. `_voip_overlay.html`:
   window.VoipMobileOnly). Веб лишь включает приём звонков на телефоне.
   Снизу по центру, над нижним баром мобильной вёрстки. */
.voip-mobile-only {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  transform: translate(-50%, 12px);
  z-index: 10001;                 /* выше оверлея звонка (10000) */
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: min(92vw, 460px);
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--c-text);
  color: var(--c-on-brand);
  font-size: 14px;
  line-height: 1.35;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .28);
  opacity: 0;
  transition: opacity .25s ease, transform .25s ease;
  pointer-events: none;           /* до появления не перехватывает клики */
}

.voip-mobile-only.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
  pointer-events: auto;
}

.voip-mobile-only__cta {
  flex: 0 0 auto;
  color: #7BD98F;                 /* светлее primary — читается на тёмном */
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

.voip-mobile-only__cta:hover,
.voip-mobile-only__cta:focus-visible {
  text-decoration: underline;
}

/* На узких экранах ссылка уезжает под текст, иначе строка не помещается. */
@media (max-width: 380px) {
  .voip-mobile-only {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .voip-mobile-only { transition: none; }
}
