/* ==========================================================================
   calls.css — voice and video
   --------------------------------------------------------------------------
   The call screen is dark in both themes, on purpose. It is not a page of the
   app, it is a mode you are in: video reads better against dark, and the
   change of ground is what tells you the rest of the interface is on hold.

   It builds that ground from the brand ramp (--leaf-950, --mascot-ink), which
   is declared once and not theme-swapped, so this file needs no dark block.
   ========================================================================== */

.call {
  position: fixed;
  inset: 0;
  z-index: 80;
  /* A column, not a fixed grid template: the screen has picked up a recording
     strip and a captions strip, and a template that lists its rows has to be
     edited every time — and silently stretches whatever it did not expect. */
  display: flex;
  flex-direction: column;
  background: var(--leaf-950);
  color: #eaf3ec;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--duration-base) var(--ease);
}

.call[data-open="true"] { opacity: 1; pointer-events: auto; }
.call[hidden] { display: none !important; }

/* --------------------------------------------------------------------------
   Head
   -------------------------------------------------------------------------- */

.call__head {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
}

.call__who { min-width: 0; flex: 1; line-height: var(--leading-snug); }
.call__name { font-size: var(--text-lg); font-weight: 600; }

.call__status {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: #9db8a5;
  font-variant-numeric: tabular-nums;
}

/* A live call needs a heartbeat somewhere, or a frozen screen looks the same
   as a working one. */
.call__live {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--status-good);
  animation: call-pulse 2s ease-in-out infinite;
}

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

.call__head .btn {
  color: #cfe0d4;
  background: rgba(255, 255, 255, 0.06);
  border-color: transparent;
}

.call__head .btn:hover { background: rgba(255, 255, 255, 0.14); color: #fff; }

/* --------------------------------------------------------------------------
   Stage
   -------------------------------------------------------------------------- */

.call__stage {
  flex: 1;
  display: grid;
  gap: var(--space-3);
  place-content: center;
  align-items: stretch;
  padding: 0 var(--space-5);
  min-height: 0;
  width: 100%;
}

.call__stage[data-count="1"] { grid-template-columns: minmax(0, min(880px, 100%)); }
.call__stage[data-count="2"] { grid-template-columns: repeat(2, minmax(0, min(620px, 45vw))); }
.call__stage[data-count="3"],
.call__stage[data-count="4"] { grid-template-columns: repeat(2, minmax(0, min(500px, 40vw))); }
.call__stage[data-count="5"],
.call__stage[data-count="6"],
.call__stage[data-count="7"],
.call__stage[data-count="8"],
.call__stage[data-count="9"] { grid-template-columns: repeat(3, minmax(0, min(360px, 27vw))); }

/* Someone sharing their screen takes the room; everyone else lines up beside
   it. Nobody joins a screen share to look at faces. */
.call__stage--shared {
  grid-template-columns: minmax(0, 1fr) minmax(0, 200px) !important;
  align-items: start;
  width: min(1200px, 100%);
}

.call__strip { display: grid; gap: var(--space-2); max-height: 100%; overflow-y: auto; }
.call__strip .tile { aspect-ratio: 4 / 3; }

/* --------------------------------------------------------------------------
   A tile
   -------------------------------------------------------------------------- */

.tile {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 16 / 10;
  min-height: 0;
  border-radius: var(--radius-lg);
  background: var(--mascot-ink);
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.07);
}

.tile video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: var(--mascot-ink);
}

/* Your own camera is mirrored — you move left, the picture moves left. Every
   video call does this and it is jarring when one doesn't. Never mirror a
   shared screen: the text would come out backwards. */
.tile--self video { transform: scaleX(-1); }
.tile--screen video { object-fit: contain; transform: none; background: #05100e; }

.tile__avatar {
  display: grid;
  place-items: center;
  width: clamp(56px, 22%, 104px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.10);
  color: #eaf3ec;
  font-size: clamp(var(--text-lg), 6cqw, var(--text-2xl));
  font-weight: 600;
  letter-spacing: 0.02em;
}

.tile__label {
  position: absolute;
  left: var(--space-3);
  bottom: var(--space-3);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  max-width: calc(100% - var(--space-6));
  padding: 3px var(--space-2);
  border-radius: var(--radius-md);
  background: rgba(6, 20, 18, 0.62);
  backdrop-filter: blur(6px);
  font-size: var(--text-xs);
  color: #eaf3ec;
}

.tile__label span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tile__label svg { width: 13px; height: 13px; stroke: currentColor; fill: none; stroke-width: 2; flex-shrink: 0; }
.tile__label .is-muted { color: var(--status-critical); }

.tile__state {
  position: absolute;
  top: var(--space-3);
  right: var(--space-3);
  padding: 2px var(--space-2);
  border-radius: var(--radius-pill);
  background: rgba(6, 20, 18, 0.62);
  font-size: var(--text-2xs);
  color: #9db8a5;
}

/* Who is talking, said with a ring rather than a colour swap — it has to be
   readable at a glance across nine tiles. */
.tile--speaking { box-shadow: inset 0 0 0 3px var(--status-good); }

.tile--ringing .tile__avatar { animation: tile-breathe 1.6s ease-in-out infinite; }

@keyframes tile-breathe {
  0%, 100% { opacity: 0.55; transform: scale(1); }
  50%      { opacity: 1;    transform: scale(1.04); }
}

/* --------------------------------------------------------------------------
   Ringing — outgoing and incoming
   -------------------------------------------------------------------------- */

.call__ring {
  display: grid;
  justify-items: center;
  gap: var(--space-5);
  text-align: center;
  padding: var(--space-6);
}

.call__ring-avatar {
  position: relative;
  display: grid;
  place-items: center;
  width: 132px;
  height: 132px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.10);
  font-size: var(--text-2xl);
  font-weight: 600;
  color: #eaf3ec;
}

/* Two rings, half a cycle apart, so there is always one on its way out. */
.call__ring-avatar::before,
.call__ring-avatar::after {
  content: "";
  position: absolute;
  inset: -10px;
  border-radius: 50%;
  border: 2px solid rgba(139, 204, 125, 0.5);
  animation: ring-out 2.4s ease-out infinite;
}

.call__ring-avatar::after { animation-delay: 1.2s; }

@keyframes ring-out {
  0%   { transform: scale(0.96); opacity: 0.85; }
  100% { transform: scale(1.5);  opacity: 0; }
}

.call__ring-name { font-size: var(--text-xl); font-weight: 600; }
.call__ring-sub { font-size: var(--text-md); color: #9db8a5; }

/* The incoming answer row: decline, answer with voice, answer with video. */
.call__answer { display: flex; gap: var(--space-4); flex-wrap: wrap; justify-content: center; }

/* --------------------------------------------------------------------------
   Recording indicator
   A recording that does not announce itself is a trap. This is a line of its
   own, at the top, in the one colour nothing else on this screen uses.
   -------------------------------------------------------------------------- */

.call__rec {
  align-self: center;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin: 0 var(--space-5) var(--space-3);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-pill);
  background: rgba(214, 58, 52, 0.16);
  box-shadow: inset 0 0 0 1px rgba(214, 58, 52, 0.45);
  font-size: var(--text-sm);
  font-weight: 500;
  color: #ffd9d6;
}

.call__rec[hidden] { display: none !important; }
.call__rec-time { font-variant-numeric: tabular-nums; }
.call__rec-size { color: #d8a5a1; font-size: var(--text-xs); }

.call__rec-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--status-critical);
  animation: rec-blink 1.4s steps(1, end) infinite;
}

@keyframes rec-blink { 0%, 55% { opacity: 1; } 56%, 100% { opacity: 0.25; } }

/* --------------------------------------------------------------------------
   Live captions
   -------------------------------------------------------------------------- */

.call__captions {
  align-self: center;
  width: calc(100% - 2rem);
  max-width: 760px;
  margin: var(--space-3) auto 0;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-lg);
  background: rgba(6, 20, 18, 0.7);
  backdrop-filter: blur(8px);
  text-align: center;
}

.call__captions[hidden] { display: none !important; }

.call__caption {
  font-size: var(--text-md);
  line-height: var(--leading-snug);
  color: #eaf3ec;
}

.call__caption + .call__caption { margin-top: var(--space-1); }
.call__caption b { color: var(--leaf-300); font-weight: 600; }

/* Not yet settled: the recogniser may still change its mind about these
   words, and dimming them says so without a label. */
.call__caption--interim { color: #a8bdae; font-style: italic; }
.call__caption--idle { color: #7f9a88; font-size: var(--text-sm); }

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

.call__controls {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: var(--space-4);
  flex-wrap: wrap;
  padding: var(--space-5) var(--space-5) var(--space-6);
}

.call-btn {
  position: relative;
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  color: #eaf3ec;
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease), color var(--duration-fast) var(--ease);
}

.call-btn:hover { background: rgba(255, 255, 255, 0.2); }
.call-btn svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

/* The loud treatment goes to whichever state you need to notice — a muted
   microphone, a live screen share — which is not the same question as whether
   the feature is on. aria-pressed answers that one. */
.call-btn[data-alert="true"] {
  background: #f3f6f3;
  color: var(--mascot-ink);
}

.call-btn--danger { background: var(--status-critical); color: #fff; width: 62px; }
.call-btn--danger:hover { background: #b3241f; }
.call-btn--accept { background: var(--status-good); color: #06231a; width: 62px; }
.call-btn--accept:hover { background: #2fa14a; }

.call-btn[disabled] { opacity: 0.4; cursor: not-allowed; }

.call-btn__label {
  font-size: var(--text-2xs);
  color: #9db8a5;
  text-align: center;
  max-width: 84px;
  line-height: var(--leading-snug);
  pointer-events: none;
}

.call__controls { padding-bottom: var(--space-8); }

/* The live microphone level, drawn as a ring that fills the mic button. This
   is the honest answer to "can they hear me" — the icon says what you set,
   this says what is getting through. */
.call-btn__level {
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid var(--status-good);
  opacity: 0;
  transform: scale(0.9);
  transition: opacity 90ms linear, transform 90ms linear;
  pointer-events: none;
}

/* --------------------------------------------------------------------------
   Device menu
   -------------------------------------------------------------------------- */

.call__devices {
  position: absolute;
  bottom: calc(100% + var(--space-3));
  left: 50%;
  transform: translateX(-50%);
  width: calc(100vw - 2rem);
  max-width: 320px;
  padding: var(--space-2);
  border-radius: var(--radius-lg);
  background: var(--mascot-ink);
  box-shadow: var(--shadow-lg), inset 0 0 0 1px rgba(255, 255, 255, 0.1);
  text-align: left;
  z-index: 2;
}

.call__devices[hidden] { display: none !important; }

.call__devices p {
  padding: var(--space-2) var(--space-2) var(--space-1);
  font-size: var(--text-2xs);
  font-weight: 600;
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: #7f9a88;
}

.call__devices button {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  padding: var(--space-2);
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: #eaf3ec;
  font-size: var(--text-sm);
  text-align: left;
  cursor: pointer;
}

.call__devices button:hover { background: rgba(255, 255, 255, 0.1); }
.call__devices button[aria-checked="true"] { color: var(--leaf-300); }
.call__devices button svg { width: 15px; height: 15px; flex-shrink: 0; stroke: currentColor; fill: none; stroke-width: 2.2; opacity: 0; }
.call__devices button[aria-checked="true"] svg { opacity: 1; }

/* Button and caption in one column, so the caption is part of the button's
   footprint and the row spaces itself. */
.call-btn-wrap {
  position: relative;
  display: grid;
  justify-items: center;
  align-content: start;
  gap: 6px;
}

/* --------------------------------------------------------------------------
   Banner — say what went wrong instead of showing a black rectangle
   -------------------------------------------------------------------------- */

.call__banner {
  align-self: center;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin: 0 var(--space-5) var(--space-3);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.1);
  font-size: var(--text-sm);
  color: #e5eee7;
}

.call__banner[hidden] { display: none !important; }
.call__banner svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 1.8; flex-shrink: 0; }
.call__banner--warn { background: rgba(214, 158, 46, 0.22); }

/* --------------------------------------------------------------------------
   Minimised — a call you can keep working through
   -------------------------------------------------------------------------- */

@media (max-width: 372px) { .call--mini { max-width: calc(100vw - 2rem); } }

.call--mini {
  inset: auto var(--space-5) var(--space-5) auto;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: var(--space-3);
  width: auto;
  max-width: 340px;
  padding: var(--space-2) var(--space-2) var(--space-2) var(--space-4);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-lg);
  animation: mini-in 220ms var(--ease) both;
}

@keyframes mini-in {
  from { opacity: 0; transform: translateY(12px) scale(0.96); }
  to   { opacity: 1; transform: none; }
}

.call--mini .call__stage,
.call--mini .call__controls,
.call--mini .call__banner { display: none; }

.call--mini .call__head { padding: 0; gap: var(--space-2); }
.call--mini .call__name { font-size: var(--text-sm); }
.call--mini .call__status { font-size: var(--text-xs); }
.call--mini .call-btn { width: 36px; height: 36px; }
.call--mini .call__rec, .call--mini .call__captions { display: none; }
.call--mini .call-btn--danger { width: 42px; }
.call--mini .call-btn svg { width: 17px; height: 17px; }

/* --------------------------------------------------------------------------
   The record a call leaves in the thread
   -------------------------------------------------------------------------- */

.call-card {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  margin-top: var(--space-1);
  padding: var(--space-2) var(--space-4) var(--space-2) var(--space-3);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  background: var(--surface-page);
}

.call-card__icon {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--neutral-bg);
  color: var(--neutral-ink);
  flex-shrink: 0;
}

.call-card__icon svg { width: 15px; height: 15px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.call-card--missed .call-card__icon { background: var(--critical-bg); color: var(--critical-ink); }
.call-card__text { line-height: var(--leading-snug); }
.call-card__what { font-size: var(--text-sm); font-weight: 500; }
.call-card__when { font-size: var(--text-2xs); color: var(--text-muted); }

.call-card__back {
  margin-left: var(--space-2);
  font-size: var(--text-xs);
}

/* --------------------------------------------------------------------------
   What a call left behind, in the thread
   -------------------------------------------------------------------------- */

.capture-card {
  display: grid;
  gap: var(--space-3);
  max-width: 420px;
  margin-top: var(--space-1);
  padding: var(--space-3) var(--space-4) var(--space-4);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  background: var(--surface-page);
}

.capture-card__head { display: flex; align-items: center; gap: var(--space-2); }
.capture-card__icon { width: 16px; height: 16px; stroke: var(--text-danger); fill: none; stroke-width: 1.8; flex-shrink: 0; }

.capture-card__row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
}

.capture-card__row .call-card__text { flex: 1; min-width: 120px; }

.capture-card__player {
  width: 100%;
  max-height: 240px;
  border-radius: var(--radius-md);
  background: var(--mascot-ink);
}

.capture-card__transcript {
  max-height: 240px;
  overflow: auto;
  margin: 0;
  padding: var(--space-3);
  border-radius: var(--radius-md);
  background: var(--surface-sunken);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  line-height: var(--leading-normal);
  color: var(--text-secondary);
  white-space: pre-wrap;
}

.capture-card__transcript[hidden] { display: none !important; }
.capture-card__note { font-size: var(--text-2xs); color: var(--text-muted); }

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */

@media (max-width: 720px) {
  .call__stage { padding: 0 var(--space-3); }
  .call__stage[data-count="2"],
  .call__stage[data-count="3"],
  .call__stage[data-count="4"] { grid-template-columns: minmax(0, 1fr); }
  .call__stage[data-count="5"],
  .call__stage[data-count="6"],
  .call__stage[data-count="7"],
  .call__stage[data-count="8"],
  .call__stage[data-count="9"] { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .call__stage--shared { grid-template-columns: minmax(0, 1fr) !important; }
  .call__strip { grid-auto-flow: column; grid-auto-columns: 120px; overflow-x: auto; }
  .call__controls { gap: var(--space-3); padding-bottom: var(--space-7); }
  .call-btn { width: 46px; height: 46px; }
  .call-btn--danger, .call-btn--accept { width: 56px; }
  .call-btn__label { display: none; }
  .call--mini { inset: auto var(--space-3) var(--space-3) var(--space-3); max-width: none; }
  .call__captions { width: calc(100% - 1.5rem); padding: var(--space-2) var(--space-3); }
  .call__caption { font-size: var(--text-sm); }
}

/* Short windows: the controls matter more than a big picture. */
@media (max-height: 560px) {
  .call__ring-avatar { width: 88px; height: 88px; }
  .call__controls { padding: var(--space-3) var(--space-4) var(--space-4); }
  .call-btn__label { display: none; }
}
