/* PHASE6: экран звонка, мини-плашка, карточки звонков в чате, раздел «Звонки» */
.call-ui {
  position: fixed; inset: 0; z-index: 9000; overflow: hidden;
  display: flex; flex-direction: column; align-items: center;
  color: #fff; background: #07140d;
  padding: max(14px, env(safe-area-inset-top)) 16px max(22px, env(safe-area-inset-bottom));
  user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent;
}
.call-ui[hidden], .call-mini[hidden], .call-act[hidden] { display: none !important; }
.call-bg {
  position: absolute; inset: -40px; z-index: 0;
  background: radial-gradient(120% 80% at 50% 0%, hsl(var(--h, 150) 45% 26%) 0%, #0a1a12 55%, #050c08 100%);
  background-size: cover; background-position: center;
}
.call-bg[style*="url("] { filter: blur(38px) brightness(.45) saturate(1.2); }
.call-remote {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; z-index: 1;
  opacity: 0; transition: opacity .35s ease; background: #000; pointer-events: none;
}
.call-ui.has-remote-video .call-remote { opacity: 1; }
.call-ui.has-remote-video .call-peer { transform: translateY(-34vh) scale(.62); opacity: .95; }
.call-ui.has-remote-video .call-av { display: none; }
.call-top, .call-peer, .call-bar, .call-local { position: relative; z-index: 2; }
.call-top { width: 100%; max-width: 720px; display: flex; align-items: center; justify-content: space-between; }
.call-min {
  width: 42px; height: 42px; border-radius: 50%; border: 0; display: grid; place-items: center;
  background: rgba(255,255,255,.12); color: #fff; cursor: pointer; backdrop-filter: blur(8px);
}
.call-enc { display: inline-flex; gap: 6px; align-items: center; font-size: 12.5px; opacity: .75; }
.call-peer {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  transition: transform .4s cubic-bezier(.2,.8,.2,1), opacity .3s; text-shadow: 0 1px 8px rgba(0,0,0,.4);
}
.call-av { position: relative; width: 132px; height: 132px; display: grid; place-items: center; margin-bottom: 14px; }
.call-avin { position: relative; z-index: 2; }
.call-avin .av { width: 124px !important; height: 124px !important; font-size: 44px !important; margin: 0 !important; box-shadow: 0 10px 40px rgba(0,0,0,.45); }
.call-ring { position: absolute; inset: 0; border-radius: 50%; border: 2px solid rgba(34,197,94,.55); opacity: 0; }
.call-name { font-size: 27px; font-weight: 650; letter-spacing: .2px; text-align: center; max-width: 92vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.call-status { font-size: 16px; opacity: .82; font-variant-numeric: tabular-nums; min-height: 20px; }
.call-local {
  position: absolute; z-index: 3; right: 16px; top: max(70px, calc(env(safe-area-inset-top) + 58px));
  width: 112px; height: 160px; object-fit: cover; border-radius: 16px; background: #111;
  box-shadow: 0 8px 30px rgba(0,0,0,.5); border: 1px solid rgba(255,255,255,.18);
  opacity: 0; transform: scale(.8); pointer-events: none; transition: opacity .25s, transform .3s cubic-bezier(.2,.8,.2,1);
}
.call-local.mirror { transform: scale(.8) scaleX(-1); }
.call-ui.has-local-video .call-local { opacity: 1; transform: none; pointer-events: auto; cursor: pointer; }
.call-ui.has-local-video .call-local.mirror { transform: scaleX(-1); }
.call-ui.swap.has-local-video.has-remote-video .call-local { inset: 0; width: 100%; height: 100%; border-radius: 0; z-index: 1; }
.call-ui.swap.has-local-video.has-remote-video .call-remote { inset: auto 16px auto auto; top: max(70px, calc(env(safe-area-inset-top) + 58px)); width: 112px; height: 160px; border-radius: 16px; z-index: 3; }
.call-bar {
  display: flex; justify-content: center; align-items: flex-start; gap: clamp(10px, 4vw, 26px);
  width: 100%; max-width: 560px; padding: 14px 6px 4px; border-radius: 28px;
}
.call-ui.has-remote-video .call-bar { background: rgba(0,0,0,.32); backdrop-filter: blur(14px); }
.call-act { display: flex; flex-direction: column; align-items: center; gap: 7px; font-size: 12px; opacity: .92; min-width: 58px; }
.call-btn {
  width: 60px; height: 60px; border-radius: 50%; border: 0; display: grid; place-items: center; cursor: pointer;
  color: #fff; transition: transform .15s ease, background .2s, color .2s; -webkit-tap-highlight-color: transparent;
}
.call-btn:active { transform: scale(.88); }
.call-btn.glass { background: rgba(255,255,255,.16); backdrop-filter: blur(10px); }
.call-btn.glass.on { background: #fff; color: #0b1a12; }
.call-btn.red { background: #ef4444; box-shadow: 0 6px 20px rgba(239,68,68,.45); }
.call-btn.green { background: #22c55e; box-shadow: 0 6px 20px rgba(34,197,94,.45); }
.call-ui[data-stage="incoming"] .call-in-actions .call-btn { width: 68px; height: 68px; }
.call-in-actions { justify-content: space-around; max-width: 420px; }
.call-controls, .call-in-actions { display: none; }
.call-ui[data-stage="incoming"] .call-in-actions { display: flex; }
.call-ui[data-stage="outgoing"] .call-controls,
.call-ui[data-stage="connecting"] .call-controls,
.call-ui[data-stage="active"] .call-controls,
.call-ui[data-stage="ended"] .call-controls { display: flex; }
.call-ui[data-stage="ended"] .call-controls { opacity: .35; pointer-events: none; }

/* мини-плашка свернутого звонка */
.call-mini {
  position: fixed; z-index: 8990; left: 50%; top: max(8px, env(safe-area-inset-top)); transform: translateX(-50%);
  display: flex; align-items: center; gap: 9px; max-width: min(92vw, 420px);
  padding: 9px 16px; border: 0; border-radius: 999px; cursor: pointer;
  background: #16a34a; color: #fff; font: 600 14px/1.2 inherit; box-shadow: 0 8px 24px rgba(0,0,0,.35);
}
.call-mini.ringing { background: #2563eb; }
.call-mini .cm-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.call-mini .cm-time { opacity: .85; font-variant-numeric: tabular-nums; }
.call-mini .cm-dot { width: 9px; height: 9px; border-radius: 50%; background: #fff; flex: none; }

/* кнопки звонка в шапке чата видны и на телефоне */
@media (max-width: 860px) {
  .head-actions .icon-btn.call-btn:not([hidden]) { display: grid !important; }
}
.head-actions .call-btn[hidden], .profile-actions .call-btn[hidden] { display: none !important; }

/* карточка звонка в переписке */
.msg.call-msg .call-bubble { display: flex; align-items: center; gap: 11px; padding: 9px 14px 9px 9px; min-width: 210px; }
.call-bubble .cm-again {
  width: 40px; height: 40px; flex: none; border-radius: 50%; border: 0; display: grid; place-items: center; cursor: pointer;
  background: rgba(34,197,94,.16); color: #22c55e;
}
.call-bubble.missed .cm-again { background: rgba(239,68,68,.14); color: #ef4444; }
.call-bubble .cm-again svg { width: 20px; height: 20px; }
.call-bubble .cm-body { display: flex; flex-direction: column; gap: 3px; }
.call-bubble .cm-body b { font-weight: 600; }
.call-bubble .cm-body small { opacity: .7; display: inline-flex; align-items: center; gap: 4px; font-size: 12.5px; }
.cm-arrow { display: inline-flex; color: #22c55e; font-style: normal; }
.call-bubble.missed .cm-arrow, .cl-row.missed .cm-arrow { color: #ef4444; }

/* раздел «Звонки» */
.cl-tabs { display: flex; gap: 6px; padding: 4px 14px 8px; }
.cl-row { display: flex; align-items: center; gap: 12px; padding: 9px 14px; cursor: pointer; border-radius: 12px; }
.cl-row:hover { background: rgba(127,127,127,.08); }
.cl-row .ct-body { flex: 1; min-width: 0; }
.cl-row .ct-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cl-row.missed .ct-name { color: #ef4444; }
.cl-row .ct-sub { display: flex; align-items: center; gap: 4px; font-size: 13px; opacity: .7; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cl-again { flex: none; color: #22c55e; }
.cl-empty { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; padding: 48px 26px; opacity: .8; }
.cl-empty span { font-size: 13.5px; opacity: .75; max-width: 280px; }
.cl-empty-ico { width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; background: rgba(34,197,94,.14); color: #22c55e; margin-bottom: 6px; }

@media (prefers-reduced-motion: no-preference) {
  .call-ui.opening { animation: p6-call-in .34s cubic-bezier(.2,.8,.2,1) both; }
  .call-ui.closing { animation: p6-call-out .2s ease both; }
  .call-ui.opening .call-act { animation: p6-pop .38s cubic-bezier(.2,.9,.3,1.3) both; }
  .call-ui.opening .call-act:nth-child(2) { animation-delay: .04s; }
  .call-ui.opening .call-act:nth-child(3) { animation-delay: .08s; }
  .call-ui.opening .call-act:nth-child(4) { animation-delay: .12s; }
  .call-ui.opening .call-act:nth-child(5) { animation-delay: .16s; }
  .call-ui[data-stage="incoming"] .call-ring,
  .call-ui[data-stage="outgoing"] .call-ring { animation: p6-ring 2.2s ease-out infinite; }
  .call-ui .call-ring.r2 { animation-delay: 1.1s !important; }
  .call-ui[data-stage="incoming"] .call-btn.pulse { animation: p6-shake 1.6s ease-in-out infinite; }
  .call-mini { animation: p6-drop .28s cubic-bezier(.2,.8,.2,1) both; }
  .call-mini .cm-dot { animation: p6-blink 1.2s ease-in-out infinite; }
  .cl-row.p6-in { animation: p6-row .3s ease both; }
  .msg.call-msg .call-bubble { animation: p6-row .25s ease both; }
}
@keyframes p6-call-in { from { opacity: 0; transform: scale(1.06); } to { opacity: 1; transform: none; } }
@keyframes p6-call-out { from { opacity: 1; } to { opacity: 0; transform: scale(.97); } }
@keyframes p6-pop { from { opacity: 0; transform: translateY(24px) scale(.7); } to { opacity: 1; transform: none; } }
@keyframes p6-ring { 0% { opacity: .9; transform: scale(.95); } 100% { opacity: 0; transform: scale(1.75); } }
@keyframes p6-shake { 0%, 60%, 100% { transform: rotate(0); } 65% { transform: rotate(-14deg); } 72% { transform: rotate(14deg); } 79% { transform: rotate(-10deg); } 86% { transform: rotate(8deg); } }
@keyframes p6-drop { from { opacity: 0; transform: translate(-50%, -20px); } to { opacity: 1; transform: translate(-50%, 0); } }
@keyframes p6-blink { 50% { opacity: .35; } }
@keyframes p6-row { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* узкие телефоны: в шапке чата теперь и кнопки звонков — делаем иконки компактнее, чтобы имя не обрезалось */
@media (max-width: 480px) {
  #thread .head-actions { gap: 0; }
  #thread .head-actions .icon-btn { width: 36px !important; height: 40px; }
}
