/* Twipe 2.0.5–2.0.6: звонок на весь экран и мини-окно */

/* Полный экран: на ПК звонок занимает всё окно под верхней полосой, а не только колонку чата. */
html.twipe-client-desktop #callSheet.call-sheet:not(.call-sheet--mini),
html.layout-desktop #callSheet.call-sheet:not(.call-sheet--mini) {
  inset: var(--desktop-topstrip-h, 0px) 0 0 0 !important;
  left: 0 !important;
  right: 0 !important;
  top: var(--desktop-topstrip-h, 0px) !important;
  bottom: 0 !important;
  border-radius: 0 !important;
}

/* Кнопка «свернуть» */
#callSheet .call-min-btn {
  position: absolute;
  top: calc(14px + env(safe-area-inset-top));
  left: 14px;
  z-index: 20;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 12px;
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
  cursor: pointer;
  transition: background 0.15s ease, transform 0.15s ease;
}
#callSheet .call-min-btn:hover { background: rgba(255, 255, 255, 0.18); }
#callSheet .call-min-btn:active { transform: scale(0.94); }
#callSheet .call-screen { position: relative; }

/* Мини-окно */
#callSheet .call-mini { display: none; }
#callSheet.call-sheet--mini {
  inset: auto !important;
  top: auto !important;
  left: auto !important;
  right: 16px !important;
  bottom: 16px !important;
  width: 320px !important;
  height: auto !important;
  min-height: 0 !important;
  padding: 0 !important;
  border-radius: 18px !important;
  overflow: hidden;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35), 0 0 0 1px rgba(255, 255, 255, 0.08);
  z-index: 2147482600 !important;
  touch-action: none;
  cursor: grab;
}
#callSheet.call-sheet--mini.cm-dragging { cursor: grabbing; transition: none !important; }
#callSheet.call-sheet--mini[data-cm-corner="bl"] { left: 16px !important; right: auto !important; }
#callSheet.call-sheet--mini[data-cm-corner="tr"] { top: calc(var(--desktop-topstrip-h, 0px) + 16px + env(safe-area-inset-top)) !important; bottom: auto !important; }
#callSheet.call-sheet--mini[data-cm-corner="tl"] { top: calc(var(--desktop-topstrip-h, 0px) + 16px + env(safe-area-inset-top)) !important; bottom: auto !important; left: 16px !important; right: auto !important; }

#callSheet.call-sheet--mini .call-screen > :not(.call-stage),
#callSheet.call-sheet--mini .call-min-btn,
#callSheet.call-sheet--mini .call-drawer,
#callSheet.call-sheet--mini .call-peer-flags { display: none !important; }
#callSheet.call-sheet--mini .call-screen { position: static; padding: 0 !important; min-height: 0; height: auto; }
#callSheet.call-sheet--mini .call-stage { position: relative !important; inset: auto !important; height: 0; margin: 0 !important; overflow: hidden; }
#callSheet.call-sheet--mini.has-remote-video .call-stage { height: 180px; }
#callSheet.call-sheet--mini .call-video-local { width: 72px !important; top: 8px !important; right: 8px !important; left: auto !important; bottom: auto !important; border-radius: 10px !important; }

#callSheet.call-sheet--mini .call-mini {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 12px 12px 14px;
  color: #fff;
  background: linear-gradient(135deg, #2a2340, #1b1a2a);
}
.call-mini .cm-ava-btn { position: relative; width: 44px; height: 44px; flex: none; padding: 0; border: 0; background: none; cursor: pointer; }
.call-mini .cm-ava {
  position: absolute; inset: 0; border-radius: 50%;
  display: grid; place-items: center;
  font-weight: 700; font-size: 15px; color: #fff;
  background: linear-gradient(135deg, #6a8cff, #8b5cf6) center / cover no-repeat;
}
.call-mini .cm-ring {
  position: absolute; inset: -4px; border-radius: 50%;
  border: 2px solid #4ade80;
  opacity: 0; transform: scale(0.92);
  transition: opacity 0.18s ease, transform 0.12s ease;
}
.call-mini.is-talking .cm-ring { opacity: 1; transform: scale(calc(1 + var(--cm-level, 0) * 0.12)); }
.call-mini .cm-info { flex: 1; min-width: 0; cursor: pointer; }
.call-mini .cm-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.call-mini .cm-sub { font-size: 12px; opacity: 0.7; font-variant-numeric: tabular-nums; }
.call-mini .cm-actions { display: flex; gap: 6px; }
.call-mini .cm-btn {
  width: 36px; height: 36px; display: grid; place-items: center;
  border: 0; border-radius: 50%; color: #fff; cursor: pointer;
  background: rgba(255, 255, 255, 0.12);
  transition: background 0.15s ease, transform 0.15s ease;
}
.call-mini .cm-btn:hover { background: rgba(255, 255, 255, 0.2); }
.call-mini .cm-btn:active { transform: scale(0.92); }
.call-mini .cm-btn .cm-slash { display: none; }
.call-mini .cm-btn.is-off { background: #fff; color: #1b1a2a; }
.call-mini .cm-btn.is-off .cm-slash { display: inline; }
.call-mini .cm-btn--end { background: #ef4444; }
.call-mini .cm-btn--end:hover { background: #dc2626; }

/* Плавный переход между режимами */
#callSheet.cm-anim { animation: cmPop 0.28s cubic-bezier(0.22, 1, 0.36, 1); }
@keyframes cmPop { from { opacity: 0.4; transform: scale(0.96); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { #callSheet.cm-anim { animation: none; } }

@media (max-width: 720px) {
  #callSheet.call-sheet--mini { width: calc(100vw - 24px) !important; right: 12px !important; bottom: calc(76px + env(safe-area-inset-bottom)) !important; }
  #callSheet.call-sheet--mini[data-cm-corner="bl"], #callSheet.call-sheet--mini[data-cm-corner="tl"] { left: 12px !important; }
}
#callSheet:not(.call-sheet--mini) .call-screen { max-width: none !important; width: 100% !important; border-radius: 0 !important; margin: 0 !important; }
.call-voice-monitor {
  grid-column: 1 / -1;
  margin-top: 6px;
  padding: 10px 14px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
  color: inherit;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.call-voice-monitor.is-on { background: rgba(74, 222, 128, 0.18); border-color: rgba(74, 222, 128, 0.5); }

/* ===== Групповой звонок ===== */
.gc-sheet {
  position: fixed;
  inset: var(--desktop-topstrip-h, 0px) 0 0 0;
  z-index: 2147482550;
  display: flex;
  flex-direction: column;
  color: #fff;
  overflow: hidden;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}
.gc-sheet.hidden { display: none; }
.gc-bg {
  position: absolute; inset: 0; z-index: -1;
  background:
    radial-gradient(circle at 18% 12%, rgba(99, 102, 241, 0.35), transparent 45%),
    radial-gradient(circle at 85% 90%, rgba(236, 72, 153, 0.22), transparent 45%),
    #14131f;
}
.gc-head { display: flex; align-items: center; gap: 12px; padding: 14px 16px; }
.gc-title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.gc-title b { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gc-title span { font-size: 12px; opacity: 0.65; font-variant-numeric: tabular-nums; }
.gc-lock { font-size: 12px; padding: 6px 10px; border-radius: 999px; background: rgba(255, 255, 255, 0.08); white-space: nowrap; }
.gc-icon-btn { width: 40px; height: 40px; display: grid; place-items: center; border: 0; border-radius: 12px; color: #fff; background: rgba(255, 255, 255, 0.1); cursor: pointer; }
.gc-icon-btn:hover { background: rgba(255, 255, 255, 0.18); }

.gc-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  gap: 10px;
  padding: 6px 16px 12px;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr));
  grid-auto-rows: minmax(0, 1fr);
  align-content: center;
}
.gc-grid[data-count="1"] { grid-template-columns: minmax(0, 640px); justify-content: center; }
.gc-grid[data-count="2"] { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 720px) {
  .gc-grid[data-count="2"] { grid-template-columns: 1fr; }
  .gc-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.gc-tile {
  position: relative;
  min-height: 140px;
  border-radius: 18px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.06);
  display: grid;
  place-items: center;
  outline: 2px solid transparent;
  outline-offset: -2px;
  transition: outline-color 0.15s ease, background 0.2s ease;
  animation: gcIn 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes gcIn { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: none; } }
.gc-tile.is-talking { outline-color: #4ade80; background: rgba(74, 222, 128, 0.08); }
.gc-tile video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: none; }
.gc-tile.has-video video { display: block; }
.gc-tile.has-video .gc-tile-ava { display: none; }
.gc-tile[data-gc-tile="me"] video { transform: scaleX(-1); }
.gc-tile audio { display: none; }
.gc-ava {
  width: 84px; height: 84px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 28px; font-weight: 700;
  background: linear-gradient(135deg, #6a8cff, #8b5cf6) center / cover no-repeat;
}
.gc-tile.is-talking .gc-ava { box-shadow: 0 0 0 4px rgba(74, 222, 128, 0.55); }
.gc-tile-name {
  position: absolute; left: 10px; bottom: 10px;
  max-width: calc(100% - 20px);
  padding: 4px 10px; border-radius: 999px;
  font-size: 13px; background: rgba(0, 0, 0, 0.45);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  display: flex; align-items: center; gap: 6px;
}
.gc-tile-name small { opacity: 0.7; }
.gc-muted { width: 14px; height: 14px; display: inline-block; background: #f87171; -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round'%3E%3Crect x='9' y='3' width='6' height='11' rx='3'/%3E%3Cpath d='M5 11a7 7 0 0 0 14 0M4 4l16 16'/%3E%3C/svg%3E") center / contain no-repeat; mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round'%3E%3Crect x='9' y='3' width='6' height='11' rx='3'/%3E%3Cpath d='M5 11a7 7 0 0 0 14 0M4 4l16 16'/%3E%3C/svg%3E") center / contain no-repeat; }

.gc-dock { display: flex; justify-content: center; gap: 12px; padding: 10px 16px 18px; }
.gc-btn {
  width: 56px; height: 56px; border-radius: 50%;
  display: grid; place-items: center;
  border: 0; color: #fff; cursor: pointer;
  background: rgba(255, 255, 255, 0.12);
  transition: background 0.15s ease, transform 0.12s ease;
}
.gc-btn:hover { background: rgba(255, 255, 255, 0.2); }
.gc-btn:active { transform: scale(0.93); }
.gc-btn .gc-slash, .gc-mini-btn .gc-slash { display: none; }
.gc-btn.is-off, .gc-mini-btn.is-off { background: #fff; color: #14131f; }
.gc-btn.is-off .gc-slash, .gc-mini-btn.is-off .gc-slash { display: inline; }
.gc-btn.is-on { background: #6366f1; }
.gc-btn--end { background: #ef4444; width: 64px; }
.gc-btn--end:hover { background: #dc2626; }

/* мини-режим группового звонка */
.gc-mini { display: none; }
.gc-sheet.gc-sheet--mini {
  inset: auto 16px 16px auto;
  width: 340px;
  border-radius: 18px;
  padding: 0;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35), 0 0 0 1px rgba(255, 255, 255, 0.08);
}
.gc-sheet--mini .gc-head, .gc-sheet--mini .gc-grid, .gc-sheet--mini .gc-dock { display: none; }
.gc-sheet--mini .gc-grid { display: block; position: absolute; width: 0; height: 0; overflow: hidden; }
.gc-sheet--mini .gc-mini { display: flex; align-items: center; gap: 10px; padding: 12px; background: linear-gradient(135deg, #2a2340, #1b1a2a); }
.gc-mini-avas { display: flex; cursor: pointer; }
.gc-mini-avas .gc-ava { width: 36px; height: 36px; font-size: 13px; border: 2px solid #1b1a2a; }
.gc-mini-avas .gc-ava + .gc-ava { margin-left: -12px; }
.gc-mini-avas .gc-ava:first-child { box-shadow: 0 0 0 2px #4ade80; }
.gc-mini-info { flex: 1; min-width: 0; display: flex; flex-direction: column; cursor: pointer; }
.gc-mini-info b { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gc-mini-info span { font-size: 12px; opacity: 0.7; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gc-mini-btn { width: 34px; height: 34px; flex: none; border-radius: 50%; display: grid; place-items: center; border: 0; color: #fff; cursor: pointer; background: rgba(255, 255, 255, 0.12); }
.gc-mini-btn svg { width: 18px; height: 18px; }
.gc-mini-btn--end { background: #ef4444; }
.gc-sheet.gc-anim { animation: cmPop 0.28s cubic-bezier(0.22, 1, 0.36, 1); }
@media (max-width: 720px) {
  .gc-sheet.gc-sheet--mini { inset: auto 12px calc(76px + env(safe-area-inset-bottom)) 12px; width: auto; }
}

/* плашка «Идёт звонок» в группе */
.gc-banner {
  position: relative; z-index: 3;
  display: flex; align-items: center; gap: 10px;
  margin: 6px 12px 0; padding: 10px 14px;
  border: 0; border-radius: 14px; cursor: pointer;
  font: inherit; font-size: 13px; text-align: left;
  color: var(--text, #111);
  background: color-mix(in srgb, #22c55e 14%, var(--bg-elevated, #fff));
}
.gc-banner span:nth-child(2) { flex: 1; }
.gc-banner b { color: #16a34a; }
.gc-banner-dot { width: 8px; height: 8px; border-radius: 50%; background: #22c55e; animation: gcPulse 1.4s ease-in-out infinite; }
@keyframes gcPulse { 50% { opacity: 0.35; } }

/* карта: понятное сообщение вместо пустого поля */
.tmap-fail { position: absolute; inset: 0; z-index: 30; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 24px; text-align: center; background: color-mix(in srgb, var(--bg, #fff) 88%, transparent); font-size: 13px; }
.tmap-fail b { font-size: 15px; }
.tmap-fail span { opacity: .7; max-width: 280px; }
.tmap-fail button { margin-top: 8px; padding: 8px 16px; border: 0; border-radius: 10px; background: var(--primary, #3b82f6); color: #fff; font: inherit; cursor: pointer; }

/* 2.0.7: статусы сообщений */
.msg-ack { margin-left: 4px; gap: 0; }
.msg-ack-svg--double { width: 18px !important; height: 11px !important; }
.msg-ack--read { color: var(--primary, #38bdf8); }
.msg-ack-clock { display: block; opacity: 0.8; }
.msg-ack-clock-hand { transform-origin: 6px 6px; animation: msgAckSpin 1.6s linear infinite; }
.msg-ack--failed { color: #ef4444; }
.msg-ack--read-in .msg-ack-svg--double path:last-child { stroke-dasharray: 14; stroke-dashoffset: 14; animation: ackDraw 0.32s ease-out forwards; }
@keyframes ackDraw { to { stroke-dashoffset: 0; } }
@media (prefers-reduced-motion: reduce) { .msg-ack-clock-hand, .msg-ack--read-in .msg-ack-svg--double path:last-child { animation: none; stroke-dashoffset: 0; } }

/* ===== 2.0.7: chat list context menu ===== */
.clm{position:fixed;z-index:9000;min-width:236px;max-width:300px;padding:6px;border-radius:14px;
  background:var(--bg-elevated,#1e1f24);color:var(--text,#fff);border:1px solid var(--line,rgba(255,255,255,.08));
  box-shadow:0 12px 40px rgba(0,0,0,.35),0 2px 8px rgba(0,0,0,.2);
  -webkit-backdrop-filter:blur(18px) saturate(1.4);backdrop-filter:blur(18px) saturate(1.4);
  animation:clmIn .16s cubic-bezier(.2,.9,.3,1.2);user-select:none;max-height:calc(100vh - 16px);overflow:auto}
@keyframes clmIn{from{opacity:0;transform:scale(.92)}to{opacity:1;transform:none}}
.clm-item,.clm-back{display:flex;align-items:center;gap:12px;width:100%;padding:9px 10px;border:0;border-radius:9px;
  background:transparent;color:inherit;font:inherit;font-size:var(--fs-14,14px);text-align:left;cursor:pointer;outline:none}
.clm-item:hover,.clm-item:focus-visible,.clm-back:hover,.clm-back:focus-visible{background:var(--bg-soft,rgba(255,255,255,.07))}
.clm-ico{width:20px;height:20px;flex:0 0 20px;display:grid;place-items:center;color:var(--muted,#9aa)}
.clm-ico svg,.clm-chev svg,.clm-back svg{width:18px;height:18px}
.clm-label{flex:1;min-width:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.clm-hint{font-size:var(--fs-12,12px);color:var(--muted,#9aa)}
.clm-chev{display:grid;color:var(--muted,#9aa);opacity:.8}
.clm-item.is-danger,.clm-item.is-danger .clm-ico{color:#ff5a5f}
.clm-item.is-danger:hover{background:rgba(255,90,95,.12)}
.clm-sep{height:1px;margin:5px 8px;background:var(--line,rgba(255,255,255,.08))}
.clm-back{font-weight:600;color:var(--primary,#5b8cff);margin-bottom:2px}
.clm-back svg{transform:rotate(180deg)}
@media (pointer:coarse){.clm-item,.clm-back{padding:12px 12px;font-size:15px}}

/* ===== 2.0.7: пинг звонка ===== */
.call-ping-mount{display:flex;justify-content:center;min-height:0;margin-top:4px}
.call-ping{display:inline-flex;align-items:flex-end;gap:2px;padding:3px 8px 3px 7px;border-radius:999px;background:rgba(0,0,0,.35);
  color:#fff;font-size:12px;line-height:1;font-variant-numeric:tabular-nums;-webkit-backdrop-filter:blur(8px);backdrop-filter:blur(8px)}
.call-ping i{display:block;width:3px;border-radius:1px;background:currentColor;opacity:.35}
.call-ping i:nth-child(1){height:5px}.call-ping i:nth-child(2){height:8px}.call-ping i:nth-child(3){height:11px}
.call-ping b{font-weight:600;margin-left:5px}
.call-ping--good{color:#4ade80}.call-ping--good i{opacity:1}
.call-ping--mid{color:#facc15}.call-ping--mid i:nth-child(-n+2){opacity:1}
.call-ping--bad{color:#f87171}.call-ping--bad i:nth-child(1){opacity:1}
.call-ping b{color:#fff}
.cm-ping .call-ping{background:transparent;padding:0 0 0 6px;font-size:11px}
.gc-tile-ping{position:absolute;top:8px;right:8px;z-index:2;pointer-events:none}
#callMiniBar .cm-sub{display:flex;align-items:center;white-space:nowrap;overflow:hidden}

/* 2.0.7: галочки в своих пузырях берут цвет текста пузыря (на синем были серыми и терялись) */
.msg.out .msg-bubble .msg-ack { color: inherit; opacity: 0.72; }
.msg.out .msg-bubble .msg-ack--read { color: inherit; opacity: 1; }
.msg.out .msg-bubble .msg-ack--failed { color: #fff; opacity: 1; background: #ef4444; border-radius: 999px; padding: 0 4px; }

/* 2.0.7: на телефоне сквозь поле ввода и панели (вложения, эмодзи) просвечивали сообщения и обои.
   Делаем их плотными. */
html:not(.layout-desktop) #chatSheet .sheet-chat-footer,
html:not(.layout-desktop) #chatSheet.sheet-chat--wallpaper .sheet-chat-footer {
  background: var(--bg-elevated, #fff) !important;
  -webkit-backdrop-filter: none !important; backdrop-filter: none !important;
}
html:not(.layout-desktop) .sheet-chat--wallpaper .composer-tg { background: transparent !important; -webkit-backdrop-filter: none; backdrop-filter: none; }
.composer-media-panel, .composer-fun-panel {
  background: var(--bg-elevated, #fff) !important;
  -webkit-backdrop-filter: none !important; backdrop-filter: none !important;
}
