:root {
  --bg: #0b0d12;
  --bg-2: #11141c;
  --card: rgba(255, 255, 255, 0.04);
  --stroke: rgba(255, 255, 255, 0.09);
  --text: #eef1f6;
  --muted: #8b93a7;
  --accent: #5b8cff;
  --accent-2: #7c6bff;
  --danger: #ff4d5e;
  --ok: #2ee6a6;
  --radius: 18px;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background:
    radial-gradient(1200px 800px at 15% -10%, rgba(91, 140, 255, 0.18), transparent 55%),
    radial-gradient(1000px 700px at 110% 110%, rgba(124, 107, 255, 0.16), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

.hidden { display: none !important; }

/* ---------- Lobby ---------- */
.lobby {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.lobby-card {
  width: 100%;
  max-width: 420px;
  background: var(--card);
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  padding: 34px 30px;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: var(--shadow);
  animation: rise 0.5s cubic-bezier(0.2, 0.8, 0.2, 1);
}

@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-size: 15px;
  color: var(--muted);
  margin-bottom: 22px;
}
.brand i { font-style: normal; color: var(--text); }
.brand .dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(91, 140, 255, 0.18);
}

.lobby-card h1 {
  font-size: 30px;
  letter-spacing: -0.03em;
  margin-bottom: 26px;
}
.sub { color: var(--muted); font-size: 14.5px; line-height: 1.5; margin-bottom: 26px; }

.field { display: block; margin-bottom: 18px; }
.field span {
  display: block;
  font-size: 12.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 8px;
}
.field input {
  width: 100%;
  padding: 14px 16px;
  font-size: 16px;
  color: var(--text);
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--stroke);
  border-radius: 12px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(91, 140, 255, 0.15);
}

.lobby-actions { display: flex; gap: 10px; align-items: stretch; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border: 0;
  cursor: pointer;
  font-size: 15px;
  font-weight: 600;
  border-radius: 12px;
  padding: 14px 18px;
  transition: transform 0.12s, filter 0.2s, background 0.2s;
  color: #fff;
}
.btn:active { transform: scale(0.97); }
.btn svg { width: 18px; height: 18px; fill: currentColor; }

.btn-primary {
  flex: 1;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 10px 24px rgba(91, 140, 255, 0.3);
}
.btn-primary:hover { filter: brightness(1.08); }

.btn-ghost {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--stroke);
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}
.btn-ghost:hover { color: var(--text); }

.hint { margin-top: 20px; font-size: 12.5px; color: var(--muted); line-height: 1.5; }
.hint.error { color: var(--danger); }

.lobby-foot { margin-top: 22px; color: rgba(139, 147, 167, 0.6); font-size: 12px; }

/* ---------- Home ---------- */
.home-lead { color: var(--muted); font-size: 14.5px; line-height: 1.5; margin: 8px 0 24px; }
.home-cards { display: flex; flex-direction: column; gap: 12px; }
.home-card {
  display: flex; align-items: center; gap: 14px;
  width: 100%; text-align: left;
  padding: 16px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--stroke);
  color: var(--text);
  cursor: pointer;
  transition: background 0.18s, transform 0.12s, border-color 0.18s;
}
.home-card:hover { background: rgba(255, 255, 255, 0.07); border-color: rgba(91, 140, 255, 0.4); }
.home-card:active { transform: scale(0.99); }
.home-ico {
  width: 46px; height: 46px; flex-shrink: 0;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}
.home-ico svg { width: 24px; height: 24px; fill: #fff; }
.home-txt { display: flex; flex-direction: column; flex: 1; }
.home-txt b { font-size: 16px; }
.home-txt i { font-style: normal; font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.home-arrow { color: var(--muted); font-size: 22px; }

.back-link {
  background: none; border: 0; color: var(--muted);
  font-size: 13px; cursor: pointer; padding: 0 0 16px; margin: 0;
}
.back-link:hover { color: var(--text); }

/* ---------- Chat list ---------- */
.chats-card { display: flex; flex-direction: column; }
.chat-list { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; max-height: 50vh; overflow-y: auto; }
.chat-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 10px; border-radius: 11px; cursor: pointer;
  transition: background 0.15s;
}
.chat-item:hover { background: rgba(255, 255, 255, 0.05); }
.chat-ava {
  width: 42px; height: 42px; flex-shrink: 0;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 16px; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  position: relative;
}
.chat-ava .dot-online {
  position: absolute; right: -1px; bottom: -1px;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--muted); border: 2px solid #11141c;
}
.chat-item.online .dot-online { background: var(--ok); }
.chat-meta { flex: 1; min-width: 0; }
.chat-meta .nm { font-weight: 600; font-size: 15px; }
.chat-meta .pv { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item .tm { font-size: 11px; color: var(--muted); flex-shrink: 0; }
.chat-del {
  flex-shrink: 0;
  width: 32px; height: 32px;
  border: 0; border-radius: 8px; cursor: pointer;
  background: none; color: var(--muted);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity 0.15s, background 0.15s, color 0.15s;
}
.chat-item:hover .chat-del { opacity: 1; }
.chat-del:hover { background: rgba(255, 77, 94, 0.14); color: var(--danger); }
.chat-del svg { width: 17px; height: 17px; fill: currentColor; }
@media (hover: none) { .chat-del { opacity: 0.7; } }

/* ---------- Single chat ---------- */
.chat-view { position: fixed; inset: 0; display: flex; flex-direction: column; background: var(--bg); }
.chat-head {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; padding-top: max(12px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--stroke);
  background: var(--bg-2);
}
.chat-back {
  background: none; border: 0; color: var(--text);
  font-size: 28px; line-height: 1; cursor: pointer; padding: 0 4px;
}
.chat-head-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.chat-head-info b { font-size: 16px; }
.chat-presence { font-size: 12px; color: var(--muted); }
.chat-presence.online { color: var(--ok); }
.chat-call {
  width: 42px; height: 42px; border-radius: 50%;
  border: 0; cursor: pointer; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255, 255, 255, 0.08); color: var(--text);
  transition: background 0.18s;
}
.chat-call:hover:not([disabled]) { background: var(--ok); color: #fff; }
.chat-call svg { width: 20px; height: 20px; fill: currentColor; }
.chat-call[disabled] { opacity: 0.35; cursor: default; }

.chat-messages {
  flex: 1; overflow-y: auto;
  padding: 16px;
  display: flex; flex-direction: column; gap: 8px;
  position: relative; /* so offsetTop of children is relative to this box */
}
.chat-unread {
  align-self: stretch;
  display: flex; align-items: center; gap: 10px;
  font-size: 11.5px; color: var(--accent);
  margin: 4px 0;
}
.chat-unread::before, .chat-unread::after {
  content: ''; flex: 1; height: 1px; background: rgba(91, 140, 255, 0.3);
}
.msg {
  max-width: 76%;
  padding: 9px 13px; border-radius: 16px;
  font-size: 14.5px; line-height: 1.4;
  word-wrap: break-word; white-space: pre-wrap;
}
.msg.out { align-self: flex-end; background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; border-bottom-right-radius: 5px; }
.msg.in { align-self: flex-start; background: rgba(255, 255, 255, 0.07); border: 1px solid var(--stroke); border-bottom-left-radius: 5px; }
.msg .t { font-size: 10.5px; opacity: 0.65; margin-left: 8px; float: right; margin-top: 4px; }
.msg .tick { display: inline-flex; vertical-align: middle; margin-left: 4px; }
.msg .tick svg { width: 16px; height: 16px; fill: rgba(255, 255, 255, 0.75); }
.msg .tick.read svg { fill: #bfe3ff; }
.msg-call {
  align-self: center; max-width: 90%;
  display: flex; align-items: center; gap: 8px;
  padding: 7px 14px; border-radius: 999px;
  background: rgba(255, 255, 255, 0.05); border: 1px solid var(--stroke);
  font-size: 12.5px; color: var(--muted);
}
.msg-call svg { width: 15px; height: 15px; fill: var(--muted); flex-shrink: 0; }
.msg-call.missed { color: var(--danger); }
.msg-call.missed svg { fill: var(--danger); }
.chat-day { align-self: center; font-size: 11.5px; color: var(--muted); padding: 4px 0; }

.chat-input-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; padding-bottom: max(12px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--stroke); background: var(--bg-2);
}
.chat-input-bar input {
  flex: 1; padding: 12px 16px; font-size: 15px;
  color: var(--text); background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--stroke); border-radius: 22px; outline: none;
}
.chat-input-bar input:focus { border-color: var(--accent); }
.chat-input-bar input:disabled { opacity: 0.5; }
.chat-send {
  width: 44px; height: 44px; flex-shrink: 0;
  border-radius: 50%; border: 0; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}
.chat-send svg { width: 20px; height: 20px; fill: #fff; }
.chat-send[disabled] { opacity: 0.4; cursor: default; }
.chat-attach {
  width: 42px; height: 42px; flex-shrink: 0;
  border-radius: 50%; border: 0; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255, 255, 255, 0.08); color: var(--muted);
  transition: background 0.18s, color 0.18s;
}
.chat-attach:hover:not([disabled]) { background: rgba(255, 255, 255, 0.14); color: var(--text); }
.chat-attach svg { width: 21px; height: 21px; fill: currentColor; }
.chat-attach[disabled] { opacity: 0.4; cursor: default; }

.msg-img { padding: 4px; max-width: 260px; }
.msg-img img {
  display: block; width: 100%; border-radius: 12px; cursor: pointer;
}
.msg-img .t { float: none; display: block; text-align: right; margin: 3px 4px 1px; }

.lightbox {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
  padding: 24px; background: rgba(0, 0, 0, 0.9);
  cursor: zoom-out;
}
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 24px;
  background: rgba(5, 6, 10, 0.7); backdrop-filter: blur(10px);
}
.modal-card {
  width: 100%; max-width: 400px;
  background: var(--bg-2); border: 1px solid var(--stroke);
  border-radius: var(--radius); padding: 26px;
  box-shadow: var(--shadow); animation: rise 0.25s ease;
}
.modal-card h2 { font-size: 21px; margin-bottom: 18px; }
.img-preview-wrap {
  display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.3); border: 1px solid var(--stroke);
  border-radius: 12px; padding: 8px; margin-bottom: 18px;
}
.img-preview-wrap img { max-width: 100%; max-height: 46vh; border-radius: 8px; }

/* ---------- Call ---------- */
.call { position: fixed; inset: 0; display: flex; flex-direction: column; }

.stage {
  position: relative;
  flex: 1;
  overflow: hidden;
  background: #05060a;
}

#remote-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #05060a;
}

.placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  text-align: center;
  color: var(--muted);
  background:
    radial-gradient(700px 500px at 50% 40%, rgba(91, 140, 255, 0.12), transparent 60%),
    #05060a;
}
.placeholder p { font-size: 15px; }
.room-tag { font-size: 13px; color: rgba(139, 147, 167, 0.7); }
.room-tag b { color: var(--text); }

.spinner {
  width: 42px; height: 42px;
  border: 3px solid rgba(255, 255, 255, 0.12);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.remote-cam-off {
  position: absolute;
  inset: 0;
  z-index: 2; /* above remote video, below local PiP / topbar / controls */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background:
    radial-gradient(700px 500px at 50% 42%, rgba(91, 140, 255, 0.1), transparent 60%),
    #07090e;
  color: var(--muted);
}
.remote-cam-off p { font-size: 15px; }
.cam-off-icon {
  width: 88px; height: 88px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--stroke);
}
.cam-off-icon svg { width: 40px; height: 40px; fill: var(--muted); }

.local-wrap {
  position: absolute;
  right: 18px;
  bottom: 18px;
  width: 168px;
  aspect-ratio: 3 / 4;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--stroke);
  box-shadow: var(--shadow);
  background: #0b0d12;
  transition: transform 0.2s, opacity 0.2s;
  z-index: 5;
}
.local-wrap:hover { transform: scale(1.02); }
#local-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1); /* mirror self-view */
}
.local-wrap.cam-off #local-video { opacity: 0; }
.local-wrap.cam-off::after {
  content: "Камера выкл.";
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; color: var(--muted);
}
.local-label {
  position: absolute;
  left: 8px; bottom: 8px;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 7px;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(6px);
}

.topbar {
  position: absolute;
  top: 16px; left: 0; right: 0;
  display: flex;
  justify-content: center;
  gap: 10px;
  z-index: 6;
  pointer-events: none;
}
.pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  font-weight: 600;
  padding: 8px 13px;
  border-radius: 999px;
  background: rgba(10, 12, 18, 0.6);
  border: 1px solid var(--stroke);
  backdrop-filter: blur(14px);
  color: var(--text);
}
.conn-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--muted);
  transition: background 0.3s;
}
.pill.connecting .conn-dot { background: #f5a623; animation: pulse 1.2s infinite; }
.pill.connected .conn-dot { background: var(--ok); }
.pill.failed .conn-dot { background: var(--danger); }
@keyframes pulse { 50% { opacity: 0.3; } }

.controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 20px;
  padding-bottom: max(20px, env(safe-area-inset-bottom));
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.4));
  position: absolute;
  bottom: 0; left: 0; right: 0;
  z-index: 6;
}

.ctrl {
  width: 58px; height: 58px;
  border-radius: 50%;
  border: 1px solid var(--stroke);
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(14px);
  transition: transform 0.12s, background 0.2s;
}
.ctrl:active { transform: scale(0.92); }
.ctrl:hover { background: rgba(255, 255, 255, 0.16); }
.ctrl svg { width: 24px; height: 24px; fill: currentColor; }

.ctrl .i-off { display: none; }
.ctrl.off { background: rgba(255, 255, 255, 0.04); color: var(--muted); }
.ctrl.off .i-on { display: none; }
.ctrl.off .i-off { display: block; }

.ctrl.active {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent;
  color: #fff;
  box-shadow: 0 8px 20px rgba(91, 140, 255, 0.35);
}
.ctrl.active .i-on { display: none; }
.ctrl.active .i-off { display: block; }
.ctrl[disabled] { opacity: 0.4; pointer-events: none; }

.ctrl-end { background: var(--danger); border-color: transparent; width: 64px; height: 64px; }
.ctrl-end:hover { background: #ff3548; }

/* Devices button carries a small chevron badge over the mic glyph. */
#devices-btn { position: relative; }
#devices-btn .chev {
  position: absolute;
  width: 14px; height: 14px;
  right: 7px; bottom: 7px;
  padding: 1px;
  border-radius: 50%;
  background: var(--bg-2);
}
#devices-btn.active { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border-color: transparent; }

/* Microphone picker popover */
.device-menu {
  position: absolute;
  bottom: calc(100% + 12px);
  left: 50%;
  transform: translateX(-50%);
  width: min(320px, calc(100vw - 32px));
  background: rgba(14, 17, 24, 0.96);
  border: 1px solid var(--stroke);
  border-radius: 14px;
  padding: 10px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  animation: rise 0.2s ease;
  z-index: 20;
}
.device-menu-title {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  padding: 4px 10px 8px;
}
.device-list { display: flex; flex-direction: column; gap: 2px; max-height: 240px; overflow-y: auto; }
.device-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 10px;
  border-radius: 9px;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  background: none;
  border: 0;
  width: 100%;
  transition: background 0.15s;
}
.device-item:hover { background: rgba(255, 255, 255, 0.06); }
.device-item .check {
  width: 18px; height: 18px;
  flex-shrink: 0;
  fill: var(--accent);
  opacity: 0;
}
.device-item.selected .check { opacity: 1; }
.device-item .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.device-empty { padding: 10px; font-size: 13px; color: var(--muted); }
.device-menu-sep { height: 1px; background: var(--stroke); margin: 8px 4px; }

/* Toggle switch */
.toggle {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 8px 10px;
  cursor: pointer;
  user-select: none;
}
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle-track {
  flex-shrink: 0;
  width: 40px; height: 23px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  transition: background 0.2s;
  position: relative;
}
.toggle-thumb {
  position: absolute;
  top: 2px; left: 2px;
  width: 19px; height: 19px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}
.toggle input:checked + .toggle-track { background: var(--accent); }
.toggle input:checked + .toggle-track .toggle-thumb { transform: translateX(17px); }
.toggle-text { font-size: 14px; color: var(--text); line-height: 1.3; }
.toggle-text i { display: block; font-style: normal; font-size: 11.5px; color: var(--muted); margin-top: 2px; }

/* Self-view shows the shared screen un-mirrored, fit to frame. */
.local-wrap.sharing { aspect-ratio: 16 / 9; width: 220px; }
.local-wrap.sharing #local-video { transform: none; object-fit: contain; background: #000; }
.local-wrap.sharing .local-label::after { content: " · экран"; }
@media (max-width: 520px) {
  .local-wrap.sharing { width: 150px; }
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 110px;
  transform: translateX(-50%);
  background: rgba(10, 12, 18, 0.92);
  border: 1px solid var(--stroke);
  color: var(--text);
  padding: 12px 18px;
  border-radius: 12px;
  font-size: 14px;
  backdrop-filter: blur(14px);
  z-index: 50;
  box-shadow: var(--shadow);
  animation: rise 0.25s ease;
}

@media (max-width: 520px) {
  .local-wrap { width: 116px; right: 12px; bottom: 12px; }
  .ctrl { width: 54px; height: 54px; }
  .ctrl-end { width: 60px; height: 60px; }
}
