/* === Unobits Call UI (lib-jitsi) ========================================= */
.ub-call .ub-call-body {
  display: flex;
  flex-direction: column;
  gap: .5rem;
}

.ub-call-grid,
.ub-call-full-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 8px;
}

.ub-call-tabbar {
  position: fixed;
  bottom: 20px;
  /* thumb reach */
  display: flex;
  gap: 8px;
  justify-content: center;
  background: color-mix(in oklab, var(--surface) 75%, transparent);
  padding: 8px 10px;
  border-radius: 16px;
  box-shadow: var(--btn-shadow);
  backdrop-filter: blur(6px);
}

.ub-call-full {
  position: fixed;
  inset: 0;
  background: var(--surface);
  z-index: 9999;
  display: grid;
  grid-template-rows: 1fr auto;
}

.ub-call-hostbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border-top: var(--line);
  background: var(--surface);
}

.ub-participant {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  background: var(--muted);
  border: 1px solid var(--panel-2, var(--muted));
}

.ub-participant video,
.ub-participant audio {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.ub-participant .meta {
  position: absolute;
  left: 6px;
  bottom: 6px;
  font-size: 12px;
  padding: 2px 6px;
  border-radius: 12px;
  background: color-mix(in oklab, var(--surface) 60%, transparent);
}

.ub-participant:hover {
  z-index: 9;
  transform: scale(1.02);
  transition: transform .12s ease;
}

/* VAD glow classes */
.is-speaking-self {
  outline: 2px solid var(--primary);
  box-shadow: 0 0 10px 2px var(--primary);
}

.is-speaking-remote {
  outline: 2px solid rgba(200, 200, 200, 0.5);
  box-shadow: 0 0 10px 2px rgba(200, 200, 200, 0.5);
}

/* Blob (Picture-in-Picture) */
.ub-call-blob {
  position: fixed;
  right: 16px;
  bottom: 16px;
  width: 240px;
  height: 160px;
  display: grid;
  place-items: center;
  border-radius: 16px;
  z-index: 10000;
  background: color-mix(in oklab, var(--surface) 75%, transparent);
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow);
  cursor: grab;
  opacity: .9;
}

.ub-call-blob[hidden] {
  display: none
}

.ub-call-blob.slim {
  width: 260px;
  height: 56px;
  border-radius: 28px;
}

.ub-call-blob .ub-call-timer {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.ub-blob-controls {
  display: flex;
  gap: 6px;
  position: absolute;
  right: 8px;
  top: 8px;
}

/* Perf mode: reduce animations, pause non-essential motion */
body.perf-mode * {
  animation: none !important;
  transition-duration: 0s !important;
}

/* === Calls: VAD speaking glow ============================================== */
/* Local user speaking: primary color ring */
.ub-participant.is-speaking-self {
  outline: 2px solid var(--primary);
  box-shadow: 0 0 0 2px var(--primary), 0 0 20px var(--primary);
}

.ub-call-blob.is-speaking-self {
  outline: 2px solid var(--primary);
  box-shadow: 0 0 0 2px var(--primary), 0 0 20px var(--primary);
}

/* Remote user speaking: light grey ring (per spec) */
.ub-participant.is-speaking-remote {
  outline: 2px solid rgba(200, 200, 200, 0.5);
  box-shadow: 0 0 0 2px rgba(200, 200, 200, 0.5), 0 0 16px rgba(200, 200, 200, 0.5);
}

.ub-call-blob.is-speaking-remote {
  outline: 2px solid rgba(200, 200, 200, 0.5);
  box-shadow: 0 0 0 2px rgba(200, 200, 200, 0.5), 0 0 16px rgba(200, 200, 200, 0.5);
}

/* keep native look & perf-mode already defined above */

/* ==========================================================================
   Unified Calling Overhaul (Custom controls + External Jitsi)
   ========================================================================== */

/* Ensure dropdowns / context menus always appear above the call window */
menu,
.menu,
.context-menu,
.ctx-menu,
.chat-header .menu {
  z-index: 7000 !important;
}

/* Ongoing Call pill (in chat header) */
.ongoing-call-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid color-mix(in oklab, var(--primary) 70%, white);
  background: color-mix(in oklab, var(--primary-faded) 70%, transparent);
  color: var(--text);
  cursor: pointer;
  user-select: none;
  box-shadow: 0 0 0 rgba(0, 0, 0, 0);
  transition: transform .12s ease, box-shadow .2s ease;
}

.ongoing-call-pill:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 26px rgba(0, 0, 0, .25);
}

.ongoing-call-pill[hidden] {
  display: none
}

.ongoing-call-pill .glow-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--primary);
  box-shadow: 0 0 10px var(--primary), 0 0 18px color-mix(in oklab, var(--primary) 70%, transparent);
  animation: ubGlowPulse 1.2s infinite ease-in-out;
}

@keyframes ubGlowPulse {
  0% {
    transform: scale(.95);
    opacity: .65;
  }

  50% {
    transform: scale(1.15);
    opacity: 1;
  }

  100% {
    transform: scale(.95);
    opacity: .65;
  }
}

/* Call overlay (NOT a <dialog>) so other modals/menus can stack above it */
.ub-call-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(0, 0, 0, .35);
  backdrop-filter: blur(10px);
  z-index: 4500;
  /* below app modals (typically 5000+), and below toast-bar (9999) */
}

.ub-call-overlay[hidden] {
  display: none;
}

.ub-call-window {
  width: min(980px, calc(100vw - 32px));
  height: min(640px, calc(100vh - 32px));
  background: color-mix(in oklab, var(--surface) 92%, transparent);
  border: var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  overflow: hidden;
  display: grid;
  grid-template-rows: auto 1fr auto;
  position: relative;
}

/* Window modes */
.ub-call-window.mode-full {
  width: 100vw;
  height: 100vh;
  border-radius: 0;
}

.ub-call-window.mode-voice-tiny {
  width: min(520px, calc(100vw - 32px));
  height: auto;
  min-height: 260px;
}

/* Header */
.ub-call-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: var(--line);
  background: color-mix(in oklab, var(--surface) 85%, transparent);
}

.ub-call-header-left {
  display: grid;
  gap: 2px;
}

.ub-call-header-right {
  display: flex;
  align-items: center;
  gap: 8px
}

.ub-call-header-title {
  font-weight: 800;
  letter-spacing: .2px;
}

.ub-call-header-sub {
  font-size: 12px;
  opacity: .75;
}

/* Main area */
.ub-call-main {
  position: relative;
  display: grid;
  grid-template-columns: 1fr;
  height: 100%;
  overflow: hidden;
}

.ub-call-video-stage {
  position: relative;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, .35);
}

.ub-call-jitsi-mount {
  width: 100%;
  height: 100%;
}

.ub-call-jitsi-mount iframe {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}

/* --------------------------------------------------------------------------
   Cloudflare RealtimeKit stage (rendered inside the existing call mount)
----------------------------------------------------------------------------*/

.ub-call-jitsi-mount .ub-rtk-stage {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.ub-call-jitsi-mount .ub-rtk-grid {
  position: absolute;
  inset: 0;
  padding: 14px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  align-content: stretch;
}

.ub-call-jitsi-mount .ub-rtk-tile {
  position: relative;
  border-radius: 16px;
  overflow: hidden;
  background: rgba(255, 255, 255, .06);
  border: 1px solid rgba(255, 255, 255, .08);
}

.ub-call-jitsi-mount .ub-rtk-tile video {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.ub-call-jitsi-mount .ub-rtk-tile .ub-rtk-label {
  position: absolute;
  left: 10px;
  bottom: 10px;
  max-width: calc(100% - 20px);
  padding: 6px 10px;
  border-radius: 12px;
  font-size: 12px;
  line-height: 1.1;
  color: rgba(255, 255, 255, .95);
  background: rgba(0, 0, 0, .45);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  backdrop-filter: blur(6px);
}

.ub-call-jitsi-mount .ub-rtk-tile.speaking {
  box-shadow:
    0 0 0 2px color-mix(in oklab, var(--primary) 55%, rgba(255, 255, 255, .15)) inset,
    0 10px 40px rgba(0, 0, 0, .22);
}

.ub-call-jitsi-mount .ub-rtk-tile.screenshare {
  grid-column: 1 / -1;
  min-height: 280px;
}

.ub-call-jitsi-mount .ub-rtk-tile.no-video {
  display: grid;
  place-items: center;
}

.ub-call-jitsi-mount .ub-rtk-tile.no-video .ub-rtk-avatar {
  width: 68px;
  height: 68px;
  border-radius: 999px;
  border: 1px solid color-mix(in oklab, var(--primary) 35%, rgba(255, 255, 255, .15));
  background: rgba(255, 255, 255, .06);
  display: grid;
  place-items: center;
  font-weight: 900;
  font-size: 22px;
  opacity: .95;
}

/* Hide the embedded iframe while connecting (prevents any pre-join UI flashes) */
.ub-call-window.jitsi-hidden .ub-call-jitsi-mount {
  opacity: 0;
  pointer-events: none;
}

/* Hide the video stage in voice calls (voice UI uses a separate stage) */
.ub-call-window.is-voice-call .ub-call-jitsi-mount {
  opacity: 0;
  pointer-events: none;
}

/* Allow temporary technical view to reveal the stage */
.ub-call-window.is-voice-call.tech-mode .ub-call-jitsi-mount {
  opacity: 1;
  pointer-events: auto;
}

/* Voice-only stage */
.ub-call-voice-stage {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 10px;
  padding: 16px;
  background: var(--surface);
  pointer-events: auto;
}

.ub-voice-top {
  font-weight: 700;
  opacity: .9;
}

.ub-voice-avatars {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 14px;
  justify-items: center;
}

.ub-voice-avatar {
  width: 86px;
  height: 86px;
  border-radius: 999px;
  border: 1px solid color-mix(in oklab, var(--primary) 35%, rgba(255, 255, 255, .15));
  background: rgba(255, 255, 255, .06);
  display: grid;
  place-items: center;
  overflow: hidden;
}

.ub-voice-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.ub-voice-avatar .initial {
  font-weight: 900;
  font-size: 30px;
  opacity: .9;
}

.ub-voice-avatar.is-waiting {
  animation: ubWaitingPulse 1.2s infinite ease-in-out;
}

.ub-voice-avatar.is-speaking {
  box-shadow:
    0 0 0 2px color-mix(in oklab, var(--primary) 55%, rgba(255, 255, 255, .15)) inset,
    0 10px 40px rgba(0, 0, 0, .22);
}

@keyframes ubWaitingPulse {
  0% {
    opacity: .35;
  }

  50% {
    opacity: 1;
  }

  100% {
    opacity: .35;
  }
}

/* Dot line animation (15 dots flowing left->right) */
.ub-voice-dots {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 2px;
}

.ub-voice-dots span {
  width: 4px;
  height: 4px;
  border-radius: 999px;
  background: color-mix(in oklab, var(--primary) 80%, white);
  opacity: .18;
  transform: translateY(0);
  animation: ubDotFlow 1.05s infinite ease-in-out;
}

@keyframes ubDotFlow {
  0% {
    opacity: .16;
    transform: translateY(0);
  }

  25% {
    opacity: 1;
    transform: translateY(-2px);
  }

  55% {
    opacity: .16;
    transform: translateY(0);
  }

  100% {
    opacity: .16;
    transform: translateY(0);
  }
}

/* Footer controls */
.ub-call-footer {
  padding: 12px 14px;
  border-top: var(--line);
  background: color-mix(in oklab, var(--surface) 85%, transparent);
}

.ub-call-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* Primary border call buttons */
.icon-btn.call-ctrl {
  border: 1px solid color-mix(in oklab, var(--primary) 70%, rgba(255, 255, 255, .25)) !important;
  background: rgba(0, 0, 0, .10);
  color: var(--text);
}

.icon-btn.call-ctrl:hover {
  background: rgba(0, 0, 0, .18);
}

.icon-btn.call-ctrl.is-active {
  background: color-mix(in oklab, var(--primary-faded) 70%, rgba(0, 0, 0, .10));
  box-shadow: 0 0 0 2px color-mix(in oklab, var(--primary) 25%, transparent);
}

.icon-btn.call-ctrl.danger {
  border-color: #b00020 !important;
  background: #b00020;
  color: #fff;
}

.icon-btn.call-ctrl.danger:hover {
  filter: brightness(1.05);
}

/* Chat panel (group video calls only) */
.ub-call-chat-panel {
  position: absolute;
  top: 12px;
  right: 12px;
  width: min(360px, calc(100% - 24px));
  height: calc(100% - 24px);
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, .14);
  background: rgba(0, 0, 0, .28);
  backdrop-filter: blur(14px);
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
}

.ub-call-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, .12);
}

.ub-call-chat-title {
  font-weight: 800;
  font-size: 13px;
}

.ub-call-chat-body {
  padding: 10px 12px;
  overflow: auto;
}

.ub-call-chat-footer {
  display: flex;
  gap: 10px;
  padding: 10px 12px;
  border-top: 1px solid rgba(255, 255, 255, .12);
}

.ub-call-chat-footer input {
  flex: 1;
  min-width: 0;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, .16);
  background: rgba(0, 0, 0, .18);
  color: var(--text);
  padding: 10px 12px;
}

/* Minimized chat pill */
.ub-call-chat-panel.is-minimized {
  height: auto;
  width: min(360px, calc(100% - 24px));
  grid-template-rows: auto;
}

.ub-call-chat-panel.is-minimized .ub-call-chat-body,
.ub-call-chat-panel.is-minimized .ub-call-chat-footer {
  display: none;
}

/* Settings panel */
.ub-call-settings-panel {
  position: absolute;
  inset: 12px;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, .14);
  background: rgba(0, 0, 0, .32);
  backdrop-filter: blur(14px);
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
  z-index: 2;
}

.ub-call-settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, .12);
}

.ub-call-chat-panel[hidden],
.ub-call-settings-panel[hidden],
.ub-call-controls[hidden] {
  display: none
}

.ub-call-settings-title {
  font-weight: 900;
  font-size: 13px;
}

.ub-call-settings-body {
  padding: 12px;
  overflow: auto;
  display: grid;
  gap: 12px;
}

.ub-call-settings-body .row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, .10);
  background: rgba(0, 0, 0, .16);
}

.ub-call-settings-body .row .label {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.ub-call-settings-body .row .label .t {
  font-weight: 800;
  font-size: 13px;
}

.ub-call-settings-body .row .label .d {
  opacity: .7;
  font-size: 12px;
}

.ub-call-settings-body .row .actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

#supportFab[hidden] {
  display: none
}

/* Minimized call bar */
.ub-call-minibar {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, .16);
  background: rgba(0, 0, 0, .35);
  backdrop-filter: blur(12px);
  box-shadow: 0 0 18px rgba(0, 0, 0, .35), 0 0 22px color-mix(in oklab, var(--primary) 24%, transparent);
  z-index: 4600;
  /* above overlay, still below most modals/toasts */
}

.ub-call-minibar[hidden] {
  display: none;
}

.ub-call-minibar-left {
  font-weight: 900;
  letter-spacing: .3px;
  min-width: 58px;
  text-align: center;
}

.ub-call-mini-btns {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
  /* no-wrap */
}

.ub-call-mini-btns[hidden] {
  display: none
}
