/* Calls (T8b, §10): incoming screen, call screen, mini window, banner, call messages.
   Colors come from the styles.css tokens (light + dark); person colors via .uc-* (--u / --ut). */

/* Hang-up red and answer green stay the same in light and dark: white icons on them need the
   contrast, and people recognise these two colors on any phone. */
:root { --call-red: #d93a40; --call-green: #1e9a4c; }

.call-host { display: contents; }
.peer-audio { display: none; }

/* ---------------------------------------------------------------- full call screen */
.call-screen {
  position: fixed; left: 0; right: 0; top: var(--app-top, 0px); height: var(--app-h, 100dvh); z-index: 50;
  display: flex; flex-direction: column; color: var(--text);
  background: radial-gradient(120% 70% at 50% 0%, var(--accent-soft) 0%, var(--bg) 62%);
  animation: call-in 0.18s ease-out;
}
@keyframes call-in { from { opacity: 0; transform: scale(0.985); } to { opacity: 1; transform: none; } }

.call-top {
  flex: none; display: flex; align-items: center; gap: 8px;
  padding: calc(var(--safe-t) + 8px) calc(12px + var(--safe-r)) 8px calc(12px + var(--safe-l));
}
.call-top-btn {
  width: 44px; height: 44px; border-radius: 50%; border: 0; display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-1); flex: none;
}
.call-top-btn:hover { background: var(--surface-2); }
.call-title { flex: 1; min-width: 0; text-align: center; }
.call-room { font-weight: 700; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.call-status { font-size: 13.5px; color: var(--text-2); min-height: 20px; font-variant-numeric: tabular-nums; }
.call-count {
  flex: none; min-width: 44px; height: 44px; padding: 0 12px; border-radius: 22px; display: inline-flex; align-items: center; justify-content: center; gap: 5px;
  background: var(--surface); box-shadow: var(--shadow-1); font-weight: 700; font-size: 14px; color: var(--text-2);
}

/* grid: 1 · 2 · 3–4 · 5–9 · more (scrolls) */
.call-grid {
  flex: 1; min-height: 0; display: grid; gap: 10px; padding: 6px calc(12px + var(--safe-r)) 6px calc(12px + var(--safe-l));
  grid-template-columns: 1fr; grid-auto-rows: 1fr; align-content: stretch;
}
.call-grid.n2 { grid-template-rows: 1fr 1fr; }
.call-grid.n4 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.call-grid.n9 { grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); }
.call-grid.nmany { grid-template-columns: repeat(3, 1fr); grid-auto-rows: 132px; overflow-y: auto; overscroll-behavior: contain; align-content: start; }
@media (min-width: 768px) {
  .call-grid { padding: 8px 24px; gap: 14px; }
  .call-grid.n2 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr; }
  .call-grid.n1 { padding-left: max(24px, calc((100% - 960px) / 2)); padding-right: max(24px, calc((100% - 960px) / 2)); }
  .call-grid.n2 { align-content: center; grid-template-rows: minmax(0, min(100%, 560px)); }
  .call-grid.nmany { grid-template-columns: repeat(4, 1fr); grid-auto-rows: 180px; }
}

.call-tile {
  position: relative; min-height: 0; min-width: 0; border-radius: 22px; overflow: hidden;
  background: color-mix(in srgb, var(--u) 12%, var(--surface));
  box-shadow: var(--shadow-1), inset 0 0 0 1px color-mix(in srgb, var(--u) 22%, transparent);
  transition: box-shadow 0.15s ease-out;
}
.call-tile.has-video { background: #0d1215; }
.call-tile.speaking { box-shadow: 0 0 0 3px var(--u), 0 0 22px color-mix(in srgb, var(--u) 55%, transparent); }
.tile-face { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
.tile-ring { display: inline-flex; border-radius: 50%; padding: 5px; box-shadow: 0 0 0 3px color-mix(in srgb, var(--u) 45%, transparent); transition: box-shadow 0.15s; }
.speaking .tile-ring { box-shadow: 0 0 0 4px var(--u), 0 0 0 10px color-mix(in srgb, var(--u) 22%, transparent); }
.tile-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #0d1215; }
.tile-video.contain { object-fit: contain; }
.tile-video.mirror { transform: scaleX(-1); }
.tile-label {
  position: absolute; left: 10px; bottom: 10px; max-width: calc(100% - 20px); display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 999px; background: var(--pill-bg); color: var(--text); font-size: 13.5px; font-weight: 650;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.has-video .tile-label { background: rgba(0, 0, 0, 0.5); color: #fff; }
.tile-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-muted { display: inline-flex; color: var(--danger); flex: none; }
.has-video .tile-muted { color: #ff8a8f; }
.tile-conn {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%); display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  padding: 3px 10px; border-radius: 999px; background: var(--warn-bg); color: var(--warn-text); font-size: 12.5px; font-weight: 600;
}
.call-tile.weak:not(.has-video) .tile-face { opacity: 0.6; }
.n9 .tile-label, .nmany .tile-label { font-size: 12px; left: 6px; bottom: 6px; padding: 2px 8px; }

/* controls */
.call-controls {
  flex: none; display: flex; justify-content: center; align-items: flex-start; gap: 10px; flex-wrap: wrap;
  padding: 12px calc(12px + var(--safe-r)) calc(16px + var(--safe-b)) calc(12px + var(--safe-l));
}
.call-ctrl { border: 0; background: transparent; display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 0; width: 68px; color: var(--text); }
.call-ctrl-btn {
  width: 58px; height: 58px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-2); transition: background 0.15s, color 0.15s, transform 0.1s;
}
.call-ctrl:hover .call-ctrl-btn { background: var(--surface-2); }
.call-ctrl:active .call-ctrl-btn { transform: scale(0.95); }
.call-ctrl.on .call-ctrl-btn { background: var(--text); color: var(--surface); }
.call-ctrl.ctrl-screen.on .call-ctrl-btn { background: var(--accent); color: var(--accent-ink); }
.call-ctrl.danger .call-ctrl-btn { background: var(--call-red); color: #fff; }
.call-ctrl-label { font-size: 12px; font-weight: 600; color: var(--text-2); white-space: nowrap; }
@media (min-width: 768px) { .call-controls { gap: 18px; padding-bottom: 22px; } }

/* ---------------------------------------------------------------- mini window */
.call-mini {
  position: fixed; z-index: 45; border-radius: 20px; overflow: hidden; display: flex; flex-direction: column;
  background: var(--surface); box-shadow: var(--shadow-3), 0 0 0 1px var(--line); touch-action: none; user-select: none; -webkit-user-select: none;
  cursor: grab; animation: call-in 0.16s ease-out;
}
.call-mini:active { cursor: grabbing; }
.call-mini.speaking { box-shadow: var(--shadow-3), 0 0 0 3px var(--u); }
.mini-stage { position: relative; flex: 1; min-height: 0; background: color-mix(in srgb, var(--u) 14%, var(--surface)); }
.mini-face { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding-bottom: 14px; }
.mini-name {
  position: absolute; left: 6px; right: 6px; bottom: 5px; text-align: center; font-size: 12px; font-weight: 650;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text);
}
.mini-stage .tile-video ~ .mini-name { color: #fff; text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7); }
.mini-bar { flex: none; display: flex; align-items: center; gap: 4px; padding: 5px 6px; background: var(--surface); }
.mini-time { flex: 1; font-size: 12.5px; font-weight: 700; color: var(--accent-text); font-variant-numeric: tabular-nums; padding-left: 4px; white-space: nowrap; overflow: hidden; }
.mini-btn {
  width: 36px; height: 36px; border-radius: 50%; border: 0; display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface-2); color: var(--text); flex: none;
}
.mini-btn.on { background: var(--text); color: var(--surface); }
.mini-btn.danger { background: var(--call-red); color: #fff; }

/* ---------------------------------------------------------------- incoming / join */
.call-incoming { position: fixed; z-index: 55; }
.inc-card { position: relative; display: flex; flex-direction: column; align-items: center; text-align: center; color: var(--text); }
.inc-close {
  position: absolute; top: 8px; right: 8px; width: 40px; height: 40px; border-radius: 50%; border: 0; background: transparent; color: var(--text-2);
  display: inline-flex; align-items: center; justify-content: center;
}
.inc-close:hover { background: var(--surface-2); }
.inc-hero { position: relative; display: flex; align-items: center; justify-content: center; }
.inc-pulse { position: absolute; inset: -14px; border-radius: 50%; background: color-mix(in srgb, var(--u) 28%, transparent); }
.ringing .inc-pulse { animation: inc-pulse 1.6s ease-out infinite; }
@keyframes inc-pulse { 0% { transform: scale(0.85); opacity: 0.9; } 100% { transform: scale(1.5); opacity: 0; } }
.inc-avatar { position: relative; box-shadow: var(--shadow-2); }
.inc-title { font-size: 13px; font-weight: 700; color: var(--ut); letter-spacing: 0.04em; }
.inc-room { font-size: 24px; font-weight: 750; line-height: 1.25; margin-top: 2px; word-break: break-word; }
.inc-text { font-size: 15px; color: var(--text-2); margin-top: 4px; }
.inc-sub { font-size: 13px; color: var(--text-3); margin-top: 2px; }
.inc-actions { display: flex; justify-content: center; gap: 22px; }
.inc-btn { border: 0; background: transparent; padding: 0; display: flex; flex-direction: column; align-items: center; gap: 8px; color: var(--text); min-width: 72px; }
.inc-btn-circle {
  width: 66px; height: 66px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: #fff; box-shadow: var(--shadow-2);
  transition: transform 0.1s, filter 0.15s;
}
.inc-btn:hover .inc-btn-circle { filter: brightness(1.06); }
.inc-btn:active .inc-btn-circle { transform: scale(0.94); }
.inc-btn.decline .inc-btn-circle { background: var(--call-red); }
.inc-btn.accept .inc-btn-circle { background: var(--call-green); }
.inc-btn.cancel .inc-btn-circle { background: var(--surface-3); color: var(--text); }
.inc-btn-label { font-size: 13px; font-weight: 650; color: var(--text-2); }
.ringing .inc-btn.accept .inc-btn-circle { animation: inc-nudge 1.6s ease-in-out infinite; }
@keyframes inc-nudge { 0%, 70%, 100% { transform: none; } 78% { transform: rotate(-12deg); } 86% { transform: rotate(12deg); } 94% { transform: rotate(-6deg); } }

/* phones: full screen */
@media (max-width: 767px) {
  .call-incoming {
    left: 0; right: 0; top: var(--app-top, 0px); height: var(--app-h, 100dvh); display: flex;
    animation: call-in 0.18s ease-out;
  }
  .inc-card {
    flex: 1; justify-content: space-between;
    padding: calc(var(--safe-t) + 72px) calc(24px + var(--safe-r)) calc(var(--safe-b) + 48px) calc(24px + var(--safe-l));
    background: linear-gradient(180deg, color-mix(in srgb, var(--u) 26%, var(--bg)) 0%, var(--bg) 70%);
  }
  .inc-close { top: calc(var(--safe-t) + 10px); right: calc(10px + var(--safe-r)); }
  .inc-hero { margin-bottom: 26px; }
  .inc-info { flex: 1; display: flex; flex-direction: column; align-items: center; }
  .inc-hero + .inc-info { margin-top: 0; }
  .inc-card { gap: 0; }
  .inc-card > .inc-hero { margin-top: 24px; }
  .inc-actions { gap: 34px; }
}
/* desktop: floating card at the bottom right */
@media (min-width: 768px) {
  .call-incoming { right: 24px; bottom: 24px; width: 360px; animation: inc-up 0.2s ease-out; }
  .inc-card {
    padding: 26px 22px 22px; gap: 14px; border-radius: 22px; background: var(--surface);
    box-shadow: var(--shadow-3), inset 0 4px 0 var(--u); border: 1px solid var(--line);
  }
  .inc-hero { margin: 8px 0 4px; }
  .inc-room { font-size: 20px; }
  .inc-btn-circle { width: 58px; height: 58px; }
  .inc-actions { gap: 16px; margin-top: 4px; }
}
@keyframes inc-up { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }

/* ---------------------------------------------------------------- ended card */
.call-ended {
  position: fixed; left: 0; right: 0; top: var(--app-top, 0px); height: var(--app-h, 100dvh); z-index: 52;
  display: flex; align-items: center; justify-content: center; background: var(--dim); animation: fade 0.14s ease-out;
}
.call-ended-card {
  display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 26px 34px; border-radius: 22px;
  background: var(--surface); box-shadow: var(--shadow-3); min-width: 220px;
}
.call-ended-title { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; }
.call-ended-title .icon { color: var(--danger); }
.call-ended-time { font-variant-numeric: tabular-nums; color: var(--text-2); font-size: 14px; }

/* ---------------------------------------------------------------- chat: banner, confirm, messages */
.call-banner { cursor: pointer; background: var(--call-green); color: #fff; }
.call-banner:hover { filter: brightness(1.04); }
.call-banner .banner-cta { font-weight: 700; }
.call-banner.mine { background: var(--accent); color: var(--accent-ink); }
.call-banner.mine .banner-cta { background: color-mix(in srgb, var(--accent-ink) 18%, transparent); }

.call-confirm { text-align: center; }
.call-confirm-icon {
  width: 56px; height: 56px; border-radius: 50%; margin: 0 auto 10px; display: flex; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--online) 16%, var(--surface)); color: var(--online);
}
.call-confirm-warn { color: var(--warn-text); font-weight: 600; }
.btn-call { background: var(--call-green); color: #fff; }
.btn-call:hover { background: var(--call-green); filter: brightness(1.06); }

.sys-pill.call-msg { flex-wrap: nowrap; max-width: calc(100% - 8px); }
.call-msg-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.call-msg .icon, .call-msg-cta, .call-msg .sys-time { flex: none; }
button.call-msg { border: 0; font: inherit; cursor: pointer; }
button.call-msg:hover { background: var(--surface); }
.call-msg.missed { color: var(--danger); }
.call-msg-cta {
  font-size: 12px; font-weight: 700; padding: 0 9px; border-radius: 999px; line-height: 20px;
  background: color-mix(in srgb, var(--online) 18%, transparent); color: var(--ok);
}

/* permission help sheet */
.call-perm-lead { margin: 0 0 10px; color: var(--text-2); }
.call-perm-steps { margin: 0; padding-left: 1.4em; display: flex; flex-direction: column; gap: 8px; line-height: 1.5; }
.call-perm-tip { margin: 14px 0 0; padding: 10px 12px; border-radius: 12px; background: var(--surface-2); color: var(--text-2); font-size: 14px; }

@media (prefers-reduced-motion: reduce) {
  .call-screen, .call-mini, .call-incoming, .ringing .inc-pulse, .ringing .inc-btn.accept .inc-btn-circle { animation: none; }
}
