/* Opkald (call.js): knapperne i topbjælken, banneret i kanalen, opkaldsvinduet, ringning og gruppeopkald.
   Farverne kommer fra temaet; scenen er altid mørk, så video ser ens ud i alle temaer. */
:root { --call-red: #e5484d; --call-green: #2fb36d; --call-hand: #ffcf5c; --call-stage: color-mix(in srgb, var(--ground) 55%, #050706); }

/* Topbjælken: grøn puls, når der er et opkald i kanalen; markeret, når man selv er med */
.call-btn.live { color: var(--acc); animation: callPulse 1.8s ease-in-out infinite; }
.call-btn.on { color: var(--acc); background: var(--acc-ghost); }
@keyframes callPulse { 0%, 100% { box-shadow: 0 0 0 0 transparent; } 50% { box-shadow: 0 0 0 4px color-mix(in srgb, var(--acc) 35%, transparent); } }

/* Banneret i kanalen ("Videoopkald i gang · 3 deltagere · Deltag") */
.call-bar {
  display: flex; align-items: center; gap: 10px; margin: 8px 16px 0; padding: 7px 8px 7px 12px; border-radius: 14px;
  border: 1px solid color-mix(in srgb, var(--acc) 45%, var(--line)); background: color-mix(in srgb, var(--acc) 10%, var(--panel));
  font-size: 13px;
}
.call-bar .cb-ic { flex: none; width: 20px; height: 20px; color: var(--acc); }
.cb-avs { display: flex; flex: none; }
.cb-avs .avatar { width: 24px; height: 24px; border-radius: 50%; box-shadow: 0 0 0 2px var(--panel); }
.cb-avs .avatar + .avatar { margin-left: -7px; }
.cb-txt { flex: 1; min-width: 0; overflow: hidden; color: var(--muted); text-overflow: ellipsis; white-space: nowrap; }
.cb-txt b { color: var(--plain); }
.cb-join {
  display: inline-flex; flex: none; align-items: center; gap: 6px; min-height: 32px; padding: 0 12px; border: 0; border-radius: 999px;
  background: var(--acc); color: var(--ground); font-size: 12.5px; font-weight: 700;
}
.cb-join.alt { border: 1px solid var(--line-hi); background: transparent; color: var(--plain); }
.cb-join .ic { width: 16px; height: 16px; }

/* ---------- Opkaldsvinduet ---------- */
.call-win {
  position: fixed; inset: 0; z-index: 240; display: grid; grid-template-rows: auto minmax(0, 1fr) auto;
  background: var(--call-stage); color: var(--plain);
}
.cw-top { display: flex; align-items: center; gap: 12px; min-width: 0; padding: 10px 14px; padding-top: max(10px, env(safe-area-inset-top)); }
.cw-title { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 14px; }
.cw-title > .ic { flex: none; width: 18px; height: 18px; color: var(--acc); }
.cw-title b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cw-time, .cw-count { flex: none; color: var(--muted); font-variant-numeric: tabular-nums; }
.cw-count::before { content: "·"; margin-right: 6px; }
.cw-lock { display: flex; align-items: center; gap: 6px; min-width: 0; color: var(--muted); font-size: 12px; }
.cw-lock > .ic { flex: none; width: 14px; height: 14px; color: var(--acc); }
.cw-lock > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cw-topbtns { display: flex; gap: 6px; margin-left: auto; }

.cw-btn {
  display: grid; place-items: center; width: 46px; height: 46px; padding: 0; border: 0; border-radius: 50%;
  background: color-mix(in srgb, var(--plain) 13%, transparent); color: var(--plain); transition: background .12s, transform .12s;
}
.cw-btn:hover { background: color-mix(in srgb, var(--plain) 22%, transparent); }
.cw-btn:active { transform: scale(.94); }
.cw-btn .ic { width: 22px; height: 22px; }
.cw-btn.off { background: color-mix(in srgb, var(--call-red) 85%, transparent); color: #fff; }
.cw-btn.on { background: var(--acc); color: var(--ground); }
.cw-btn.leave { width: 66px; border-radius: 23px; background: var(--call-red); color: #fff; }
.cw-btn.leave:hover { background: color-mix(in srgb, var(--call-red) 85%, #fff); }
.cw-topbtns .cw-btn { width: 36px; height: 36px; }
.cw-topbtns .cw-btn .ic { width: 18px; height: 18px; }
.cw-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 10px; padding: 12px 14px; padding-bottom: max(14px, env(safe-area-inset-bottom)); }
#cwExpand { display: none; }

/* Scenen: gitter (galleri), taler (stor + række) eller to (den anden stor, mig i hjørnet) */
.cw-stage { position: relative; display: flex; flex-direction: column; gap: 8px; min-height: 0; padding: 4px 14px 0; }
.cw-main {
  flex: 1; min-height: 0; display: grid; gap: 8px; align-content: center;
  grid-template-columns: repeat(var(--cols, 1), minmax(0, 1fr)); grid-auto-rows: minmax(0, 1fr);
}
.cw-strip { display: none; }
.cw-stage.spot .cw-main, .cw-stage.duo .cw-main { grid-template-columns: minmax(0, 1fr); }
.cw-stage.spot .cw-strip { display: flex; flex: none; gap: 8px; height: 112px; overflow-x: auto; scrollbar-width: thin; }
.cw-stage.spot .cw-strip .ct { flex: none; width: 190px; height: 100%; }
.ct.corner {
  position: absolute; right: 26px; bottom: 12px; z-index: 2; width: min(24%, 260px); aspect-ratio: 16 / 9;
  box-shadow: 0 10px 28px rgb(0 0 0 / .5);
}

/* En flise */
.ct {
  position: relative; min-width: 0; min-height: 0; overflow: hidden; border-radius: 14px;
  background: color-mix(in srgb, var(--panel) 65%, #000); outline: 3px solid transparent; outline-offset: -3px; transition: outline-color .15s;
}
.ct video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; }
.ct.scr video { object-fit: contain; }
.ct.mirror video { transform: scaleX(-1); }
.ct.novideo video { opacity: 0; }
.ct-av { position: absolute; inset: 0; display: none; place-items: center; }
.ct.novideo .ct-av { display: grid; }
.ct-av .avatar { width: clamp(52px, 24%, 132px); height: auto; aspect-ratio: 1; border-radius: 50%; }
.ct.speaking { outline-color: var(--acc); }
.ct.speaking .ct-av .avatar { box-shadow: 0 0 0 4px color-mix(in srgb, var(--acc) 60%, transparent); }
.ct.hand { outline-color: var(--call-hand); }
.ct-tag {
  position: absolute; left: 8px; bottom: 8px; display: flex; align-items: center; gap: 6px; max-width: calc(100% - 44px);
  padding: 3px 8px; border-radius: 8px; background: rgb(0 0 0 / .58); color: #fff; font-size: 12.5px;
}
.ct-tag span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ct-tag .ic { flex: none; width: 14px; height: 14px; }
.ct-tag .off { color: #ff8f8f; }
.ct-tag .hand { color: var(--call-hand); }
/* Forbindelsens kvalitet: øverst til venstre (nederst til højre dækker mit eget billede i hjørnet) */
.ct-q { position: absolute; top: 10px; left: 10px; display: flex; align-items: flex-end; gap: 2px; height: 12px; padding: 3px 4px; border-radius: 6px; background: rgb(0 0 0 / .45); box-sizing: content-box; }
.ct-q:not([data-q]), .ct-q[data-q=""] { display: none; }
.ct-q i { width: 3px; border-radius: 1px; background: rgb(255 255 255 / .35); }
.ct-q i:nth-child(1) { height: 4px; } .ct-q i:nth-child(2) { height: 8px; } .ct-q i:nth-child(3) { height: 12px; }
.ct-q[data-q="3"] i { background: #3ddc84; }
.ct-q[data-q="2"] i:nth-child(-n+2) { background: #f5c542; }
.ct-q[data-q="1"] i:nth-child(1) { background: #ff6b6b; }
.ct-state { position: absolute; inset: 0; display: grid; place-items: center; padding: 8px; background: rgb(0 0 0 / .45); color: #fff; font-size: 13px; text-align: center; }
.ct-state:empty { display: none; }
.ct-pin {
  position: absolute; top: 8px; right: 8px; display: grid; place-items: center; width: 30px; height: 30px; padding: 0; border: 0;
  border-radius: 50%; background: rgb(0 0 0 / .55); color: #fff; opacity: 0; transition: opacity .12s;
}
.ct-pin .ic { width: 16px; height: 16px; }
.ct:hover .ct-pin, .ct.pinned .ct-pin, .ct-pin:focus-visible { opacity: 1; }
.ct.pinned .ct-pin { background: var(--acc); color: var(--ground); }
.cw-float { position: absolute; bottom: 18%; z-index: 3; font-size: 42px; line-height: 1; pointer-events: none; animation: cwFloat 2.6s ease-out forwards; }
.cw-float .emo { width: 1em; height: 1em; }
@keyframes cwFloat { 0% { opacity: 0; transform: translateY(0) scale(.6); } 15% { opacity: 1; transform: translateY(-24px) scale(1.15); } 100% { opacity: 0; transform: translateY(-170px) scale(1); } }

/* Besked midt i opkaldet ("X rækker hånden op") */
.cw-note {
  position: absolute; left: 50%; top: 62px; z-index: 5; display: flex; align-items: center; gap: 8px; max-width: calc(100% - 32px);
  padding: 8px 14px; border-radius: 999px; background: rgb(0 0 0 / .72); color: #fff; font-size: 13px; transform: translateX(-50%);
}
.cw-note .ic { flex: none; width: 16px; height: 16px; color: var(--acc); }

/* Panelet til højre: deltagere og indstillinger */
.cw-side {
  position: absolute; top: 56px; right: 12px; bottom: 86px; z-index: 6; width: min(340px, calc(100% - 24px)); overflow-y: auto;
  padding: 12px; border: 1px solid var(--line); border-radius: 16px; background: var(--panel); box-shadow: 0 16px 44px rgb(0 0 0 / .45);
}
.cw-sidehead { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.cw-sidehead > .ic { width: 18px; height: 18px; color: var(--acc); }
.cw-sidehead b { flex: 1; }
.cw-people { display: grid; gap: 2px; margin: 0 0 12px; padding: 0; list-style: none; }
.cw-people li { display: flex; align-items: center; gap: 8px; min-height: 36px; padding: 4px 6px; border-radius: 10px; }
.cw-people li:hover { background: var(--raise); }
.cw-people .avatar.sm { width: 26px; height: 26px; border-radius: 50%; }
.cw-people .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cw-people .ic { flex: none; width: 16px; height: 16px; color: var(--muted); }
.cw-people .ic.off { color: var(--call-red); }
.cw-people .ic.hand { color: #d99a00; }
.cw-sub { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 10px 0 6px; color: var(--muted); font-size: 12px; }
.cw-field { display: grid; gap: 4px; margin-bottom: 12px; color: var(--muted); font-size: 12.5px; }
.cw-field select { min-height: 36px; padding: 0 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--ground); color: var(--plain); font: inherit; font-size: 13px; }
.cw-check { display: flex; align-items: center; gap: 8px; margin: 10px 0; font-size: 13px; }
.cw-hint { margin: 14px 0 0; color: var(--muted); font-size: 12px; }
.cw-pop {
  position: absolute; z-index: 7; display: flex; gap: 2px; padding: 6px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--panel); box-shadow: 0 12px 30px rgb(0 0 0 / .4);
}
.cw-emo { display: grid; place-items: center; width: 42px; height: 42px; padding: 0; border: 0; border-radius: 50%; background: transparent; font-size: 24px; }
.cw-emo:hover { background: var(--raise); }
.cw-emo .emo { width: 28px; height: 28px; margin: 0; }

/* Det lille vindue: man kan skrive i chatten imens (kan trækkes rundt i toppen) */
.call-win.mini {
  inset: auto 16px 150px auto; width: min(360px, calc(100vw - 32px)); grid-template-rows: auto auto auto; overflow: hidden;
  border: 1px solid var(--line-hi); border-radius: 16px; box-shadow: 0 18px 50px rgb(0 0 0 / .5);
}
.call-win.mini .cw-top { padding: 8px 46px 6px 12px; cursor: grab; touch-action: none; }
.call-win.mini .cw-lock, .call-win.mini .cw-topbtns, .call-win.mini .cw-strip, .call-win.mini .cw-side, .call-win.mini .cw-count { display: none; }
.call-win.mini .cw-stage { padding: 0 8px; }
.call-win.mini .cw-main { aspect-ratio: 16 / 9; flex: none; }
.call-win.mini .cw-note { top: 40px; font-size: 12px; }
.call-win.mini .cw-bar { gap: 8px; padding: 8px; }
.call-win.mini .cw-btn { width: 38px; height: 38px; }
.call-win.mini .cw-btn .ic { width: 18px; height: 18px; }
.call-win.mini .cw-btn.leave { width: 52px; }
.call-win.mini .cw-bar .cw-btn:not(#cwMic):not(#cwCam):not(#cwLeave) { display: none; }
.call-win.mini #cwExpand { position: absolute; top: 5px; right: 6px; display: grid; width: 32px; height: 32px; }
.call-win.mini .ct.corner { position: relative; right: auto; bottom: auto; }

/* Telefonen */
@media (max-width: 760px) {
  .cw-lock > span { display: none; }
  .cw-stage { padding: 4px 8px 0; }
  .cw-bar { gap: 8px; padding-inline: 8px; }
  .cw-btn { width: 48px; height: 48px; }
  .ct.corner { right: 14px; bottom: 10px; width: 30%; aspect-ratio: 3 / 4; }
  .cw-stage.spot .cw-strip { height: 92px; }
  .cw-stage.spot .cw-strip .ct { width: 140px; }
  .cw-side { top: 50px; right: 8px; bottom: 82px; }
  .call-win.mini { right: 10px; bottom: 140px; width: min(220px, calc(100vw - 20px)); }
  .call-win.mini .cw-title b { display: none; }
}

/* ---------- Nogen ringer (privat chat eller "ring til" i et rum) ---------- */
.call-ring {
  position: fixed; top: max(18px, env(safe-area-inset-top)); left: 50%; z-index: 280; display: grid; grid-template-columns: auto 1fr;
  align-items: center; gap: 12px 14px; width: min(430px, calc(100vw - 24px)); padding: 16px; transform: translateX(-50%);
  border: 1px solid var(--line-hi); border-radius: 20px; background: var(--panel); animation: ringIn .3s ease-out;
  box-shadow: 0 0 0 100vmax rgb(0 0 0 / .35), 0 24px 60px rgb(0 0 0 / .5);
}
.cr-av .avatar { width: 56px; height: 56px; border-radius: 50%; animation: ringPulse 1.4s ease-out infinite; }
.cr-who { display: grid; gap: 2px; min-width: 0; }
.cr-who b { overflow: hidden; font-size: 16px; text-overflow: ellipsis; white-space: nowrap; }
.cr-who span { color: var(--muted); font-size: 13px; }
.cr-btns { grid-column: 1 / -1; display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.cr-btns button { display: inline-flex; align-items: center; gap: 6px; min-height: 42px; padding: 0 14px; border: 0; border-radius: 999px; font-weight: 700; }
.cr-btns .ic { width: 18px; height: 18px; }
.cr-no { background: var(--call-red); color: #fff; }
.cr-yes { background: var(--call-green); color: #fff; }
.cr-yes.alt { background: var(--raise); color: var(--plain); }
@keyframes ringIn { from { opacity: 0; transform: translate(-50%, -12px); } }
@keyframes ringPulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--call-green) 55%, transparent); } 100% { box-shadow: 0 0 0 14px transparent; } }

/* ---------- Gruppeopkald: vælg, hvem der ringes op ---------- */
.call-pick { width: min(440px, calc(100vw - 24px)); padding: 16px; border: 1px solid var(--line-hi); border-radius: 18px; background: var(--panel); color: var(--plain); }
.call-pick::backdrop { background: rgb(0 0 0 / .45); }
.cp-kind { display: flex; gap: 6px; margin: 4px 0 8px; }
.call-pick .chip { display: inline-flex; align-items: center; gap: 6px; }
.call-pick .chip .ic { width: 15px; height: 15px; }
.call-pick .chip.on { border-color: var(--acc); background: var(--acc-ghost); }
.cp-list { display: grid; gap: 2px; max-height: min(52vh, 420px); margin: 6px 0 14px; overflow-y: auto; }
.cp-row { display: flex; align-items: center; gap: 10px; min-height: 40px; padding: 4px 8px; border-radius: 10px; cursor: pointer; }
.cp-row:hover { background: var(--raise); }
.cp-row .avatar.sm { width: 26px; height: 26px; border-radius: 50%; }
.cp-row span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cp-row small { color: var(--muted); font-size: 11.5px; }
.cp-row small.on { color: var(--acc); }
.call-pick .row-btns { justify-content: flex-end; }

/* Rolig / reduceret bevægelse */
@media (prefers-reduced-motion: reduce) { .call-btn.live, .cw-float, .call-ring, .cr-av .avatar { animation: none; } }
:root[data-calm] .call-btn.live, :root[data-calm] .cr-av .avatar { animation: none; }
