/* ClientsChat dev-тест-клиент — стиль. Ванильный CSS, без зависимостей.
   Тёмная тема, минимум декора: это QA-инструмент, не продакшн-UI. */

:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e222b;
  --line: #2a2f3a;
  --text: #e6e9ef;
  --muted: #8b93a3;
  --primary: #6366f1;     /* индиго */
  --primary-2: #818cf8;
  --danger: #ef4444;
  --ok: #22c55e;
  --mine: #2b3553;
  --theirs: #232733;
  --system: #3a2f12;
  --radius: 12px;
  font-synthesis: none;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
}

.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }
code {
  background: var(--panel-2);
  padding: 1px 5px;
  border-radius: 5px;
  font-size: 12px;
}

/* ---- topbar ---- */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; }
.who { margin-left: auto; font-weight: 600; }
.conn { display: flex; align-items: center; gap: 6px; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot-on { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.dot-off { background: #555; }

/* ---- screens ---- */
.screen { height: calc(100% - 49px); }

/* ---- login ---- */
.login {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.card {
  width: 100%;
  max-width: 460px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
}
.card h1 { margin: 0 0 8px; font-size: 20px; }
.field { display: flex; flex-direction: column; gap: 6px; margin: 14px 0; }
.field > span { font-size: 12px; color: var(--muted); }
.row { display: flex; gap: 10px; align-items: flex-end; }
.grow { flex: 1; }
.hint { margin: -6px 0 8px; }

input, select {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  outline: none;
}
input:focus, select:focus { border-color: var(--primary); }

button {
  cursor: pointer;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 14px;
  color: var(--text);
  background: var(--panel-2);
  transition: background .12s, border-color .12s, opacity .12s;
}
button:hover { border-color: var(--primary); }
button:disabled { opacity: .45; cursor: not-allowed; }
.primary {
  background: linear-gradient(180deg, var(--primary-2), var(--primary));
  border-color: transparent;
  font-weight: 600;
  width: 100%;
  margin-top: 6px;
}
.danger { background: var(--danger); border-color: transparent; font-weight: 600; }
.ghost { background: transparent; }
.ghost.small { padding: 6px 10px; font-size: 12px; }
.error { color: var(--danger); min-height: 18px; margin: 10px 0 0; font-size: 13px; }
.picker { margin-top: 8px; }

/* ---- chat layout ---- */
.chat { display: grid; grid-template-columns: 280px 1fr; }

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.sidebar-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; border-bottom: 1px solid var(--line); font-weight: 600;
}
.conv-list { list-style: none; margin: 0; padding: 6px; }
.sidebar-scroll { flex: 1; overflow-y: auto; min-height: 0; }
.sidebar-subhead {
  padding: 10px 14px 4px; font-size: 11px; color: var(--muted);
  text-transform: uppercase; letter-spacing: .04em;
  border-top: 1px solid var(--line); margin-top: 6px;
}
.conv-item {
  padding: 10px 12px; border-radius: 8px; cursor: pointer; margin-bottom: 2px;
}
.conv-item:hover { background: var(--panel-2); }
.conv-item.active { background: var(--mine); }
.conv-name { font-weight: 600; }
.logout { margin: 8px; }

/* ---- thread ---- */
.thread { display: flex; flex-direction: column; min-height: 0; }
.thread-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 18px; border-bottom: 1px solid var(--line);
}
.thread-title { font-weight: 700; font-size: 16px; }
.call-btn {
  background: linear-gradient(180deg, var(--primary-2), var(--primary));
  border-color: transparent; font-weight: 600;
}

.messages { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 8px; }
.msg { display: flex; flex-direction: column; max-width: 70%; }
.msg.mine { align-self: flex-end; align-items: flex-end; }
.msg.theirs { align-self: flex-start; align-items: flex-start; }
.msg.system { align-self: center; align-items: center; max-width: 80%; }
.bubble {
  padding: 9px 13px; border-radius: 14px; line-height: 1.35; word-break: break-word;
}
.msg.mine .bubble { background: var(--mine); border-bottom-right-radius: 4px; }
.msg.theirs .bubble { background: var(--theirs); border-bottom-left-radius: 4px; }
.msg.system .bubble { background: var(--system); color: #f0d9a0; font-size: 12px; }
.meta { display: flex; gap: 8px; font-size: 10px; color: var(--muted); margin-top: 2px; }
.seq { opacity: .7; }
.status.sending { color: var(--muted); }
.status.failed { color: var(--danger); }
.status.sent { color: var(--ok); }

.typing { padding: 0 18px 4px; height: 16px; }

.composer { display: flex; gap: 10px; padding: 12px 18px; border-top: 1px solid var(--line); align-items: flex-end; }
/* поле ввода — авто-растущая textarea (растёт при переносе строк до лимита) */
.composer textarea {
  flex: 1; resize: none; min-height: 40px; max-height: 120px; overflow-y: auto;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 18px; padding: 9px 14px; font-size: 14px; line-height: 1.35;
  font-family: inherit; outline: none;
}
.composer textarea:focus { border-color: var(--primary); }
.composer .primary { width: auto; margin: 0; padding: 10px 20px; }
/* единая кнопка режима (кружок/голос); при записи — крупнее и красная */
.mode-btn { padding: 9px 12px; font-size: 20px; flex: none; transition: transform .12s, color .12s; touch-action: none; user-select: none; }
.mode-btn.recording { transform: scale(1.3); color: var(--danger); }
.rec-bar.cancel { color: var(--danger); }
.rec-bar.cancel .rec-dot { background: var(--danger); }

/* ---- call overlay (ПОЛНОЭКРАННО, как у топ-мессенджеров) ---- */
.call-overlay { position: fixed; inset: 0; z-index: 50; background: #000; }
.call-box {
  position: absolute; inset: 0; width: 100%; height: 100%;
  background: #000; border: none; border-radius: 0; padding: 0;
}
.videos { position: absolute; inset: 0; background: #000; overflow: hidden; }
.videos .remote { width: 100%; height: 100%; object-fit: cover; background: #000; }
.videos .local {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 14px); right: 14px;
  width: 32%; max-width: 150px; aspect-ratio: 3 / 4;
  object-fit: cover; border-radius: 14px; border: 2px solid rgba(255,255,255,.25);
  background: #111; transform: scaleX(-1); z-index: 3;
  box-shadow: 0 4px 18px rgba(0,0,0,.5);
}
.call-status {
  position: absolute; left: 0; right: 0;
  top: calc(env(safe-area-inset-top) + 18px);
  z-index: 2; text-align: center; font-size: 18px; font-weight: 700;
  padding: 0 16px; text-shadow: 0 1px 6px rgba(0,0,0,.7);
}
.call-controls {
  position: absolute; left: 0; right: 0;
  bottom: calc(env(safe-area-inset-bottom) + 28px);
  z-index: 2; display: flex; gap: 14px; justify-content: center; flex-wrap: wrap;
  padding: 0 16px;
}
.call-controls button {
  min-width: 64px; border-radius: 999px; padding: 14px 22px; font-size: 16px;
  background: rgba(255,255,255,.14); border-color: transparent; backdrop-filter: blur(6px);
}
.call-controls .primary { background: linear-gradient(180deg, var(--primary-2), var(--primary)); }
.call-controls .danger { background: var(--danger); }
.call-controls .off { opacity: .5; text-decoration: line-through; }
.call-diag {
  position: absolute; left: 0; right: 0; bottom: calc(env(safe-area-inset-bottom) + 4px);
  z-index: 2; text-align: center; font-size: 10px; opacity: .5;
}

/* ---- log ---- */
.log-panel {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--panel); border-top: 1px solid var(--line);
  max-height: 40vh; z-index: 20;
}
.log-panel summary { padding: 6px 12px; cursor: pointer; color: var(--muted); font-size: 12px; }
.log {
  margin: 0; padding: 8px 12px; max-height: 32vh; overflow-y: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px; color: #9fb0c8; white-space: pre-wrap;
}

/* ---- login polish ---- */
.card .logo { font-size: 44px; text-align: center; margin-bottom: 6px; }
.card h1 { text-align: center; }
#stepPhone > p.muted, #stepCode > p.muted { text-align: center; margin: 0 0 18px; }
#codeInput { letter-spacing: .35em; text-align: center; font-size: 22px; font-weight: 600; }
.hint { text-align: center; }
#backBtn { width: 100%; margin-top: 8px; }

.thread-head-info { display: flex; align-items: center; gap: 10px; min-width: 0; }
.back-mobile { display: none; }
.composer .primary { width: auto; min-width: 52px; margin: 0; padding: 10px 18px; font-size: 16px; }

/* узкие экраны / мобила */
@media (max-width: 720px) {
  .chat { grid-template-columns: 1fr; }
  .chat .sidebar { display: flex; }            /* список чатов — главный экран */
  .chat .thread { display: none; }
  .chat.show-thread .sidebar { display: none; }
  .chat.show-thread .thread { display: flex; }
  .back-mobile { display: inline-flex; align-items: center; }
  .login { padding: 16px; align-items: flex-start; padding-top: 8vh; }
  .card { border: none; background: transparent; padding: 10px; }
  .messages { padding: 14px; }
  .composer { padding: 10px 12px; padding-bottom: max(12px, env(safe-area-inset-bottom)); }
  .topbar { padding: 10px 14px; gap: 10px; }
}

/* ---- модалка: контакты / новый чат ---- */
.sidebar-head-actions { display: flex; gap: 6px; }
.modal-overlay {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(8,10,14,.72);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal-box {
  width: 100%; max-width: 460px; max-height: 80vh;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  display: flex; flex-direction: column; overflow: hidden;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--line); font-weight: 600;
}
.modal-box .conv-list { overflow-y: auto; flex: 1; }
@media (max-width: 720px) {
  .modal-overlay { padding: 0; align-items: stretch; }
  .modal-box { max-width: none; max-height: none; height: 100dvh; border: none; border-radius: 0; }
}

/* ---- вложения (фото/видео/файл) ---- */
.attach-btn { padding: 9px 12px; font-size: 18px; flex: none; }
.bubble.has-media { padding: 3px; background: transparent !important; }
.att-image { max-width: 240px; max-height: 300px; border-radius: 10px; display: block; cursor: pointer; }
.att-video { max-width: 280px; max-height: 320px; border-radius: 10px; display: block; background: #000; }
.att-file {
  display: inline-flex; gap: 6px; align-items: center;
  padding: 10px 14px; background: var(--panel-2); border-radius: 12px;
  color: var(--text); text-decoration: none;
}
.att-cap { margin-top: 4px; padding: 0 4px; }

/* ---- голосовые ---- */
.mic-btn { padding: 9px 12px; font-size: 18px; flex: none; }
.rec-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 18px; border-top: 1px solid var(--line);
}
.rec-bar .rec-hint { flex: 1; }
.rec-bar .primary { width: auto; margin: 0; padding: 10px 18px; }
.rec-dot {
  width: 12px; height: 12px; border-radius: 50%; background: var(--danger);
  animation: recpulse 1s infinite; flex: none;
}
@keyframes recpulse { 0%,100% { opacity: 1; } 50% { opacity: .25; } }
.rec-timer { font-variant-numeric: tabular-nums; font-weight: 600; }
.att-audio { height: 40px; max-width: 240px; vertical-align: middle; }
.voice-dur { margin-left: 6px; }

/* ---- видео-кружки ---- */
.circle-btn { padding: 9px 12px; font-size: 18px; flex: none; }
.circle-wrap { position: relative; width: 220px; height: 220px; cursor: pointer; }
.att-circle {
  width: 220px; height: 220px; border-radius: 50%;
  object-fit: cover; background: #000; display: block;
}
/* кольцо прогресса по краю кружка */
.circle-ring { position: absolute; inset: -3px; width: 226px; height: 226px; transform: rotate(-90deg); pointer-events: none; }
.circle-ring .ring-bg { fill: none; stroke: rgba(255,255,255,.18); stroke-width: 3; }
.circle-ring .ring-fg { fill: none; stroke: var(--primary-2); stroke-width: 3; stroke-linecap: round; transition: stroke-dashoffset .12s linear; }
/* большой ▶ когда на паузе; прячется во время проигрывания */
.circle-play {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 46px; color: rgba(255,255,255,.92); pointer-events: none; text-shadow: 0 2px 10px rgba(0,0,0,.6);
}
.circle-wrap.playing .circle-play { display: none; }
.circle-overlay {
  position: fixed; inset: 0; z-index: 55;
  background: rgba(8,10,14,.92);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.circle-rec-box { display: flex; flex-direction: column; align-items: center; gap: 18px; }
.circle-preview {
  width: 280px; height: 280px; border-radius: 50%;
  object-fit: cover; background: #000; border: 3px solid var(--primary);
  transform: scaleX(-1);  /* зеркалим превью как селфи (запись не зеркалится) */
}
.circle-rec-info { display: flex; align-items: center; gap: 8px; font-weight: 600; font-variant-numeric: tabular-nums; }
.circle-rec-controls { display: flex; gap: 14px; }
.circle-rec-controls .primary { width: auto; margin: 0; }

/* ---- группы ---- */
.modal-body { padding: 14px 16px; overflow-y: auto; flex: 1; }
.modal-foot { padding: 12px 16px; border-top: 1px solid var(--line); }
.modal-foot .primary { width: 100%; margin: 0; }
.group-users { padding: 4px 0; }
.group-user label { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px; cursor: pointer; }
.group-user label:hover { background: var(--panel-2); }
.group-user input { width: auto; }
.sender-name { font-size: 11px; color: var(--primary-2); font-weight: 600; margin: 0 4px 2px; }

/* ---- групповой видео-созвон (Zoom-style) ---- */
.groupcall-overlay { position: fixed; inset: 0; z-index: 56; background: #0b0d12; display: flex; flex-direction: column; }
.groupcall-head { display: flex; align-items: center; gap: 12px; padding: calc(env(safe-area-inset-top) + 12px) 18px 12px; color: #fff; }
.groupcall-title { font-weight: 700; font-size: 16px; }
.group-grid {
  flex: 1; display: grid; gap: 8px; padding: 8px; overflow: auto; align-content: center;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}
.gtile { position: relative; background: #000; border-radius: 12px; overflow: hidden; aspect-ratio: 4 / 3; min-height: 140px; }
.gtile video { width: 100%; height: 100%; object-fit: cover; background: #000; }
.gtile-local video { transform: scaleX(-1); }
.gname {
  position: absolute; left: 8px; bottom: 8px; max-width: 80%;
  background: rgba(0,0,0,.55); color: #fff; font-size: 12px; padding: 3px 8px; border-radius: 8px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.groupcall-controls { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; padding: 14px 16px calc(env(safe-area-inset-bottom) + 18px); }
.groupcall-controls button { min-width: 60px; border-radius: 999px; padding: 14px 22px; font-size: 16px; background: rgba(255,255,255,.14); border-color: transparent; color: #fff; }
.groupcall-controls .danger { background: var(--danger); }
.groupcall-controls .off { opacity: .5; text-decoration: line-through; }

/* ---- управление группой ---- */
.gs-wide { width: 100%; margin: 0; }
.gs-member { display: flex; align-items: center; gap: 8px; padding: 9px 12px; }
.gs-member .conv-name { flex: 1; font-weight: 500; }
.gs-badge { font-size: 10px; background: var(--mine); color: var(--primary-2); padding: 2px 7px; border-radius: 8px; }
.gs-remove { color: var(--danger); flex: none; }
#gsAddBtn { margin-top: 6px; }
