/*
 * Calls (specs/005 US3, contracts/ui-meet.md "Call stage" and "Call bar"): the stage,
 * its tiles and controls, who is in a call, and the call bar shown on every page while
 * in one. Palette tokens only; the speaking glow is --anim-avatar-speaking.
 */

/* ---- Round controls ---- */

.call-control {
  position: relative;
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  color: var(--color-foreground);
  background-color: var(--color-card-raised);
  border: 0;
  border-radius: var(--radius-circle);
  cursor: pointer;
  list-style: none;
  transition: background-color 120ms ease, color 120ms ease;
}

.call-control::-webkit-details-marker {
  display: none;
}

.call-control:hover {
  background-color: var(--color-selection);
}

.call-control:focus-visible {
  outline: none;
  box-shadow: var(--glow-purple);
}

.call-control:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.call-control--sm {
  width: 32px;
  height: 32px;
}

/* Two icons, the second shown while pressed (mic → mic off). */
.call-control__on,
.call-control[aria-pressed="true"] .call-control__off {
  display: none;
}

.call-control__off,
.call-control[aria-pressed="true"] .call-control__on {
  display: inline-flex;
}

/* Red while muted or deafened, green while the camera or a share is on. */
.call-control--alert[aria-pressed="true"] {
  color: var(--color-foreground);
  background-color: var(--color-red);
}

.call-control--live[aria-pressed="true"] {
  color: var(--color-night);
  background-color: var(--color-green);
}

.call-control--leave {
  color: var(--color-foreground);
  background-color: var(--color-red);
}

.call-control--leave:hover {
  background-color: var(--color-red);
  filter: brightness(1.1);
}

/* ---- Who is in a call (panel and lobby) ---- */

.call-presence:empty,
.call-presence[data-count="0"] {
  display: none;
}

/* Room enough around each picture for the speaking glow (animations.css), so it doesn't
   run into the room's name above or the next person. */
.call-presence__list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin: var(--space-2) 0 0;
  padding: 0 0 var(--space-2) var(--space-5);
  list-style: none;
}

.call-presence__person {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
  font-size: var(--text-md);
  color: var(--color-comment);
}

.call-presence__avatar {
  flex: 0 0 auto;
}

.call-presence__name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.call-presence__icon {
  display: inline-flex;
  color: var(--color-red);
}

.call-presence__icon--live {
  color: var(--color-green);
}

/* ---- The stage ---- */

.call-stage {
  position: relative;
  display: flex;
  flex: 1;
  min-height: 0;
  background-color: var(--color-deep-night);
}

.call-stage__lobby {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
}

.call-stage__lobby-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  max-width: 360px;
  padding: var(--space-5);
  text-align: center;
  background-color: var(--color-card);
  border-radius: var(--radius-comfortable);
}

.call-stage__lobby-icon {
  color: var(--color-green);
}

.call-stage__lobby-title {
  margin: 0;
  font-size: var(--text-xl);
  font-weight: var(--weight-bold);
}

.call-stage__lobby-card .call-presence__list {
  padding: 0;
  text-align: left;
}

.call-stage__join {
  width: 100%;
}

.call-stage__hint {
  margin: 0;
  font-size: var(--text-sm);
  color: var(--color-comment);
}

.call-stage__live {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: var(--space-3);
  min-width: 0;
  min-height: 0;
  padding: var(--space-3);
}

.call-stage__live[hidden],
.call-stage__lobby[hidden],
.call-stage__chat[hidden] {
  display: none;
}

.call-stage__grid {
  display: grid;
  flex: 1;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
  grid-auto-rows: auto;
  gap: var(--space-2);
  min-height: 0;
  overflow-y: auto;
  align-content: center;
}

.call-stage__grid[data-count="1"] {
  grid-template-columns: minmax(0, 640px);
  justify-content: center;
}

.call-stage__screens:empty {
  display: none;
}

/* While someone shares: the screen large on top, people in a strip below. */
.call-stage--sharing .call-stage__screens {
  display: flex;
  flex: 3;
  gap: var(--space-2);
  min-height: 0;
}

.call-stage--sharing .call-stage__grid {
  flex: 0 0 auto;
  grid-template-columns: none;
  grid-auto-flow: column;
  grid-auto-columns: 160px;
  grid-auto-rows: 90px;
  overflow-x: auto;
  overflow-y: hidden;
  justify-content: start;
}

.call-screen {
  position: relative;
  flex: 1;
  min-width: 0;
  margin: 0;
  overflow: hidden;
  background-color: var(--color-night);
  border-radius: var(--radius-standard);
}

.call-screen__video {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.call-screen__label {
  position: absolute;
  left: var(--space-2);
  bottom: var(--space-2);
  padding: 2px var(--space-2);
  font-size: var(--text-sm);
  background-color: var(--color-deep-night);
  border-radius: var(--radius-subtle);
}

/* ---- Tiles ---- */

.call-tile {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 16 / 9;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background-color: var(--color-card);
  border-radius: var(--radius-standard);
}

.call-tile__video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.call-tile[data-self] .call-tile__video {
  transform: scaleX(-1);
}

.call-tile[data-camera] .call-tile__face {
  visibility: hidden;
}

.call-tile__face .avatar {
  width: 72px;
  height: 72px;
  font-size: var(--text-xl);
  border-radius: var(--radius-circle);
  object-fit: cover;
}

.call-tile__initials {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* A picture or initials, never both (the display above would beat [hidden]). */
.call-tile__face [hidden] {
  display: none;
}

.call-tile__label {
  position: absolute;
  left: var(--space-2);
  bottom: var(--space-2);
  display: flex;
  align-items: center;
  gap: var(--space-1);
  max-width: calc(100% - var(--space-4));
  margin: 0;
  padding: 2px var(--space-2);
  font-size: var(--text-sm);
  background-color: var(--color-deep-night);
  border-radius: var(--radius-subtle);
}

.call-tile__name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.call-tile__muted,
.call-tile__deafened {
  display: inline-flex;
  color: var(--color-red);
}

.call-tile__muted[hidden],
.call-tile__deafened[hidden] {
  display: none;
}

.call-tile__reconnecting {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  margin: 0;
  font-weight: var(--weight-semibold);
  background-color: color-mix(in srgb, var(--color-deep-night) 70%, transparent);
}

.call-tile[data-connection-state="reconnecting"] .call-tile__reconnecting,
.call-tile[data-connection-state="failed"] .call-tile__reconnecting {
  display: flex;
}

.call-tile__menu {
  position: absolute;
  top: var(--space-1);
  right: var(--space-1);
}

.call-tile__menu > summary {
  list-style: none;
  width: 32px;
  background-color: var(--color-deep-night);
}

.call-tile__menu > summary::-webkit-details-marker {
  display: none;
}

.call-tile__menu-list {
  position: absolute;
  top: calc(100% + var(--space-1));
  right: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 220px;
  padding: var(--space-2);
  background-color: var(--color-card-raised);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-standard);
  box-shadow: var(--shadow-card);
}

.call-tile__volume {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-1);
  font-size: var(--text-md);
}

.call-tile__volume span {
  display: flex;
  justify-content: space-between;
}

.call-tile__volume input {
  width: 100%;
  accent-color: var(--color-purple);
}

.call-tile__menu-item {
  padding: var(--space-2);
  font: inherit;
  font-size: var(--text-md);
  color: var(--color-foreground);
  text-align: left;
  background: none;
  border: 0;
  border-radius: var(--radius-subtle);
  cursor: pointer;
}

.call-tile__menu-item:hover {
  background-color: var(--color-selection);
}

.call-tile__menu-item--danger {
  color: var(--color-red);
}

.call-tile__moderation {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-top: var(--space-1);
  border-top: 1px solid var(--color-border-subtle);
}

/* ---- Controls bar ---- */

.call-controls {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
}

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

.call-devices {
  position: relative;
}

.call-devices__menu {
  position: absolute;
  bottom: calc(100% + var(--space-2));
  left: 50%;
  z-index: 5;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  width: min(280px, calc(100vw - var(--space-6)));
  padding: var(--space-3);
  background-color: var(--color-card-raised);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-standard);
  box-shadow: var(--shadow-card);
  transform: translateX(-50%);
}

.call-devices__field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

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

/* ---- The call chat ---- */

.call-stage__chat {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background-color: var(--color-night);
}

.call-stage__chat-header {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2) var(--space-2) var(--space-2) var(--space-4);
  border-bottom: 1px solid var(--color-border-subtle);
}

.call-stage__chat-title {
  margin: 0;
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
}

@media (min-width: 1024px) {
  .call-stage__chat {
    position: static;
    flex: 0 0 340px;
    border-left: 1px solid var(--color-border-subtle);
  }
}

/* ---- The call bar (every page while in a call) ---- */

.call-bar {
  position: fixed;
  right: var(--space-2);
  bottom: calc(56px + var(--space-2) + env(safe-area-inset-bottom));
  left: var(--space-2);
  z-index: 26;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background-color: var(--color-card-raised);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-comfortable);
  box-shadow: var(--shadow-card);
}

.call-bar[hidden],
body:has(.call-stage--live) .call-bar {
  display: none;
}

.call-bar__dot {
  flex: 0 0 auto;
  width: 10px;
  height: 10px;
  background-color: var(--color-green);
  border-radius: var(--radius-circle);
  animation: call-bar-pulse 1.6s ease-in-out infinite;
}

@keyframes call-bar-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

@media (prefers-reduced-motion: reduce) {
  .call-bar__dot { animation: none; }
}

.call-bar__text {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
}

.call-bar__name {
  overflow: hidden;
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
  color: var(--color-green);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.call-bar__time {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--color-comment);
}

.call-bar__return {
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
}

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

.call-dock__notice {
  position: fixed;
  right: var(--space-2);
  bottom: calc(56px + var(--space-2) + env(safe-area-inset-bottom));
  left: var(--space-2);
  z-index: 27;
  margin: 0;
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-md);
  background-color: var(--color-card-raised);
  border: 1px solid var(--color-orange);
  border-radius: var(--radius-comfortable);
}

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

/* Phones: room for the bar above the tab bar while in a call; the friends button moves
   above it. */
@media (max-width: 639px) {
  body:has(.call-dock[data-in-call]) .shell__main {
    padding-bottom: calc(56px + 64px);
  }

  body:has(.call-dock[data-in-call]) .shell__friends-fab {
    bottom: calc(56px + 64px + var(--space-2) + env(safe-area-inset-bottom));
  }
}

@media (min-width: 640px) {
  .call-bar,
  .call-dock__notice {
    right: auto;
    bottom: var(--space-4);
    left: calc(72px + var(--space-4));
    width: 300px;
  }

  /* In Meet: above the panel's user strip, like Discord. */
  .page-meet .call-bar,
  .page-meet .call-dock__notice {
    bottom: 64px;
    left: calc(72px + 72px + var(--space-2));
    width: calc(240px - var(--space-4));
  }
}

/* Beside the full-width sidebar (260px) where pages have it. */
@media (min-width: 1024px) {
  .shell:not(.shell--compact) .call-bar,
  .shell:not(.shell--compact) .call-dock__notice {
    left: calc(260px + var(--space-4));
  }
}

/* ---- Standalone calls (specs/005 US7): the share strip, the lobby, End call ---- */

.call-share {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border-bottom: 1px solid var(--color-border-subtle);
}

.call-share__url {
  flex: 1;
  min-width: 0;
  font-size: var(--text-sm);
}

.call-share .btn {
  flex: 0 0 auto;
  width: auto;
}

.meet-room-header .call-end {
  width: auto;
  white-space: nowrap;
}

/* Guests asking to join (FR-051); gone while nobody waits. */
.call-lobby {
  padding: var(--space-2) var(--space-4);
  background-color: color-mix(in srgb, var(--color-yellow) 10%, var(--color-night));
  border-bottom: 1px solid var(--color-border-subtle);
}

.call-lobby:not(:has(.call-lobby__request)) {
  display: none;
}

.call-lobby__list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin: 0;
  padding: 0;
  list-style: none;
}

.call-lobby__request {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

.call-lobby__text {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-size: var(--text-md);
  overflow-wrap: anywhere;
}

.call-lobby__actions {
  display: flex;
  gap: var(--space-2);
}

.call-lobby__actions .btn {
  width: auto;
}

/* The call bar's count of guests waiting, for a standalone call's owner. */
.call-bar__lobby {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px var(--space-2);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--color-deep-night);
  background-color: var(--color-yellow);
  border-radius: var(--radius-pill);
}

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

/* ---- The guest door (layouts/call): no shell, only the call ---- */

.page-call-door {
  min-height: 100dvh;
  margin: 0;
  color: var(--color-foreground);
  background-color: var(--color-deep-night);
}

.call-door {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: var(--space-4);
}

.call-door:has(.call-door__call) {
  align-items: stretch;
  justify-content: stretch;
  height: 100dvh;
  padding: 0;
}

.call-door__card {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  width: 100%;
  max-width: 420px;
  padding: var(--space-5);
  background-color: var(--color-card);
  border-radius: var(--radius-comfortable);
  box-shadow: var(--shadow-card);
}

.call-door__card--status {
  align-items: center;
  text-align: center;
}

.call-door__eyebrow {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  margin: 0;
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-badge);
  color: var(--color-comment);
  text-transform: uppercase;
}

.call-door__title {
  margin: 0;
  font-size: var(--text-xl);
  font-weight: var(--weight-bold);
  overflow-wrap: anywhere;
}

.call-door__with,
.call-door__hint {
  margin: 0;
  font-size: var(--text-md);
  color: var(--color-comment);
}

.call-door__status {
  margin: 0;
  font-size: var(--text-base);
}

.call-door__icon {
  color: var(--color-comment);
}

.call-door__form {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.call-door__submit {
  width: 100%;
}

/* Waiting: a calm, slow pulse (none under reduced motion). */
.call-door__pulse {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  color: var(--color-green);
  background-color: color-mix(in srgb, var(--color-green) 14%, transparent);
  border-radius: var(--radius-circle);
  animation: call-door-pulse 2.4s ease-in-out infinite;
}

@keyframes call-door-pulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--color-green) 30%, transparent); }
  50% { box-shadow: 0 0 0 14px transparent; }
}

@media (prefers-reduced-motion: reduce) {
  .call-door__pulse { animation: none; }
}

/* In the call: the stage fills the page. */
.call-door__call {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  background-color: var(--color-night);
}

.call-door__call .call-stage {
  min-height: 0;
}

/* Guests don't reply, react, edit or open profiles. */
.call-door .message .message__actions,
.call-door .message:is(:hover, :focus-within) .message__actions {
  display: none;
}

.call-door .message a[data-turbo-frame="profile_drawer"] {
  pointer-events: none;
}

.page-call-door .call-bar,
.page-call-door .call-dock__notice {
  bottom: var(--space-2);
  left: var(--space-2);
}

/* The device check (device-check): preview, level meter, toggles. */
.device-check {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.device-check__preview {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  color: var(--color-comment);
  background-color: var(--color-deep-night);
  border-radius: var(--radius-standard);
}

.device-check__video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}

.device-check__video[hidden],
.device-check__placeholder[hidden],
.device-check__note[hidden] {
  display: none;
}

.device-check__meter {
  height: 6px;
  overflow: hidden;
  background-color: var(--color-card-raised);
  border-radius: var(--radius-pill);
}

.device-check__level {
  display: block;
  width: 0;
  height: 100%;
  background-color: var(--color-green);
  transition: width 80ms linear;
}

.device-check__toggles {
  display: flex;
  justify-content: center;
  gap: var(--space-3);
}

.device-check__note {
  margin: 0;
  font-size: var(--text-sm);
  color: var(--color-orange);
}
