/* Конфиденциальный мессенджер — строгий бело-синий дизайн. */
:root {
  --bg: #f1f5fb;
  --panel: #ffffff;
  --panel-2: #f8fafc;
  --border: #e2e8f0;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #eff4ff;
  --text: #0f172a;
  --muted: #64748b;
  --bubble-out: #2563eb;
  --bubble-in: #eef2f8;
  --online: #22c55e;
  --danger: #ef4444;
  --danger-dark: #dc2626;
  --shadow: 0 10px 30px rgba(37, 99, 235, .10);
  --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}
.screen { position: fixed; inset: 0; }
[hidden] { display: none !important; }
button { cursor: pointer; font-family: inherit; }
input, select { font-family: inherit; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 8px; }

/* ---------- Общие элементы ---------- */
.field { margin-bottom: 12px; text-align: left; }
.field label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 5px; font-weight: 600; }
input, select {
  width: 100%; padding: 12px 13px; border: 1px solid var(--border); border-radius: 10px;
  background: #fff; color: var(--text); font-size: 15px; outline: none; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
.btn {
  border: none; border-radius: 10px; padding: 12px 18px; font-size: 15px; font-weight: 600;
  background: var(--panel-2); color: var(--text); transition: background .15s, transform .05s;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.block { width: 100%; }
.btn.ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn.small { padding: 8px 12px; font-size: 13px; }
.btn.danger { background: #fee2e2; color: var(--danger-dark); }
.btn.danger:hover { background: #fecaca; }
.alert { border-radius: 10px; padding: 10px 12px; font-size: 14px; margin-bottom: 12px; }
.alert.error { background: #fef2f2; color: var(--danger-dark); border: 1px solid #fecaca; }
.avatar {
  width: 44px; height: 44px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #60a5fa);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: #fff; font-size: 16px; flex-shrink: 0;
}
.avatar.big { width: 104px; height: 104px; font-size: 40px; }
.name { font-weight: 600; font-size: 15px; }
.status { font-size: 12.5px; color: var(--muted); }
.status.online { color: var(--online); }
.icon-btn {
  background: transparent; border: none; color: var(--muted);
  font-size: 20px; padding: 8px; border-radius: 10px; line-height: 1;
}
.icon-btn:hover { background: var(--panel-2); color: var(--text); }

/* ---------- Вход ---------- */
.auth {
  display: flex; align-items: center; justify-content: center; padding: 20px;
  background: radial-gradient(1000px 500px at 50% -10%, #dbe7ff, var(--bg));
}
.auth-card {
  width: 100%; max-width: 380px; background: var(--panel);
  border: 1px solid var(--border); border-radius: 20px; padding: 30px 26px;
  box-shadow: var(--shadow); text-align: center;
}
.brand-logo {
  width: 66px; height: 66px; margin: 0 auto 12px; border-radius: 18px;
  background: linear-gradient(135deg, var(--primary), #60a5fa);
  display: flex; align-items: center; justify-content: center; font-size: 34px;
  box-shadow: var(--shadow);
}
.brand h1 { font-size: 21px; margin: 6px 0 4px; }
.subtitle { color: var(--muted); margin: 0 0 22px; font-size: 13.5px; }
.hint { color: var(--muted); font-size: 12.5px; margin-top: 14px; }

/* ---------- Основной экран ---------- */
#main { display: flex; }
#sidebar {
  width: 350px; max-width: 40%; min-width: 300px; background: var(--panel);
  border-right: 1px solid var(--border); display: flex; flex-direction: column;
}
.side-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.me { display: flex; align-items: center; gap: 11px; min-width: 0; }
.me-meta { min-width: 0; }
.side-actions { display: flex; gap: 2px; }
.side-title {
  padding: 12px 16px 6px; font-size: 12px; font-weight: 700; letter-spacing: .04em;
  text-transform: uppercase; color: var(--muted);
}
.chats { overflow-y: auto; flex: 1; padding-bottom: 10px; }
.chat-item {
  display: flex; align-items: center; gap: 12px; padding: 11px 16px;
  cursor: pointer; border-left: 3px solid transparent;
}
.chat-item:hover { background: var(--panel-2); }
.chat-item.active { background: var(--primary-light); border-left-color: var(--primary); }
.chat-item .meta { flex: 1; min-width: 0; }
.chat-item .preview { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item .row1 { display: flex; justify-content: space-between; gap: 8px; }
.chat-item .time { font-size: 11px; color: var(--muted); flex-shrink: 0; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: #cbd5e1; flex-shrink: 0; }
.dot.online { background: var(--online); }
.empty-note { padding: 24px 16px; color: var(--muted); font-size: 14px; text-align: center; }

/* ---------- Чат ---------- */
.chat { flex: 1; display: flex; flex-direction: column; background: var(--bg); position: relative; }
.placeholder { margin: auto; text-align: center; color: var(--muted); }
.placeholder-logo {
  width: 84px; height: 84px; margin: 0 auto 14px; border-radius: 24px; font-size: 40px;
  background: var(--panel); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
}
#chat-view { display: flex; flex-direction: column; height: 100%; }
.chat-header {
  display: flex; align-items: center; gap: 11px; padding: 10px 14px;
  background: var(--panel); border-bottom: 1px solid var(--border);
}
.chat-header .back { display: none; font-size: 26px; }
.peer-meta { flex: 1; min-width: 0; }
.call-buttons { display: flex; gap: 2px; }
.call-buttons .icon-btn { color: var(--primary); font-size: 19px; }
.messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 4px; }
.msg { max-width: 74%; padding: 8px 12px; border-radius: 14px; font-size: 14.5px; line-height: 1.4; word-wrap: break-word; box-shadow: 0 1px 1px rgba(15,23,42,.04); }
.msg.in { background: var(--bubble-in); color: var(--text); align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.out { background: var(--bubble-out); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
.msg .sender { font-size: 12px; color: var(--primary-dark); font-weight: 700; margin-bottom: 2px; }
.msg .time { font-size: 10.5px; opacity: .7; text-align: right; margin-top: 3px; }
.composer { display: flex; gap: 9px; padding: 12px 14px; background: var(--panel); border-top: 1px solid var(--border); }
.composer input { flex: 1; border-radius: 22px; background: var(--panel-2); }
.composer .send {
  width: 46px; height: 46px; border-radius: 50%; border: none;
  background: var(--primary); color: #fff; font-size: 17px; flex-shrink: 0;
}
.composer .send:hover { background: var(--primary-dark); }

/* ---------- Админ-панель ---------- */
.admin { background: var(--bg); overflow-y: auto; }
.admin-header {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px;
  padding: 14px 18px; background: var(--panel); border-bottom: 1px solid var(--border);
}
.admin-header h2 { font-size: 18px; margin: 0; }
.admin-header .back { font-size: 26px; }
.tabs { display: flex; gap: 6px; padding: 14px 18px 0; max-width: 860px; margin: 0 auto; }
.tab {
  border: 1px solid var(--border); background: var(--panel); color: var(--muted);
  padding: 9px 18px; border-radius: 10px; font-weight: 600; font-size: 14px;
}
.tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.tab-content { max-width: 860px; margin: 0 auto; padding: 16px 18px 60px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; box-shadow: 0 1px 2px rgba(15,23,42,.03); }
.card h3 { margin: 0 0 14px; font-size: 16px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.form-actions { display: flex; gap: 10px; }
.members-pick { display: flex; flex-wrap: wrap; gap: 8px; }
.member-chip {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--panel-2); cursor: pointer; font-size: 14px; user-select: none;
}
.member-chip input { width: auto; }
.member-chip.checked { background: var(--primary-light); border-color: var(--primary); color: var(--primary-dark); font-weight: 600; }
.list { display: flex; flex-direction: column; gap: 8px; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 12px; border: 1px solid var(--border); border-radius: 12px; }
.list-item .meta { flex: 1; min-width: 0; }
.list-item .sub { font-size: 13px; color: var(--muted); }
.badge { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--primary-light); color: var(--primary-dark); }
.badge.admin { background: #fef3c7; color: #92400e; }
.list-item .actions { display: flex; gap: 6px; flex-shrink: 0; }

/* ---------- Звонок ---------- */
.call-overlay { position: fixed; inset: 0; background: #0b1220; z-index: 50; display: flex; flex-direction: column; }
.call-top { position: absolute; top: 18px; left: 0; right: 0; text-align: center; z-index: 3; color: #fff; text-shadow: 0 1px 6px rgba(0,0,0,.5); }
.call-name { font-size: 20px; font-weight: 600; }
.call-status { color: #cbd5e1; margin-top: 3px; font-size: 13px; }
.call-stage {
  flex: 1; display: grid; gap: 6px; padding: 6px;
  grid-template-columns: repeat(auto-fit, minmax(45%, 1fr)); align-content: center;
}
.call-stage.solo { grid-template-columns: 1fr; }
.tile { position: relative; background: #111827; border-radius: 12px; overflow: hidden; display: flex; align-items: center; justify-content: center; min-height: 0; }
.tile video { width: 100%; height: 100%; object-fit: cover; }
.tile .tile-avatar {
  position: absolute; width: 86px; height: 86px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #60a5fa);
  display: flex; align-items: center; justify-content: center; color: #fff; font-size: 34px; font-weight: 700;
}
.tile.has-video .tile-avatar { display: none; }
.tile .tile-name { position: absolute; bottom: 8px; left: 10px; color: #fff; font-size: 13px; background: rgba(0,0,0,.45); padding: 3px 8px; border-radius: 6px; }
#local-video { position: absolute; bottom: 96px; right: 16px; width: 108px; height: 150px; object-fit: cover; border-radius: 12px; border: 2px solid rgba(255,255,255,.35); background: #222; z-index: 4; }
.call-controls { position: relative; z-index: 5; display: flex; justify-content: center; gap: 22px; padding: 22px 0 30px; }
.round { width: 62px; height: 62px; border-radius: 50%; border: none; background: rgba(255,255,255,.16); color: #fff; font-size: 24px; display: flex; align-items: center; justify-content: center; }
.round:hover { background: rgba(255,255,255,.26); }
.round.danger { background: var(--danger); }
.round.danger:hover { background: var(--danger-dark); }
.round.accept { background: var(--online); }
.round.off { background: #fff; color: #0b1220; }

/* ---------- Входящий звонок ---------- */
.incoming { position: fixed; inset: 0; background: rgba(11,18,32,.92); z-index: 60; display: flex; align-items: center; justify-content: center; }
.incoming-card { text-align: center; color: #fff; }
.incoming-card .avatar { margin: 0 auto 16px; }
.incoming-card .name { font-size: 24px; }
.incoming-card .status { color: #cbd5e1; }
.incoming-actions { display: flex; gap: 50px; justify-content: center; margin-top: 40px; }
.incoming-actions .round { width: 72px; height: 72px; font-size: 28px; }

/* ---------- Мобильная адаптация ---------- */
@media (max-width: 760px) {
  #sidebar { width: 100%; max-width: 100%; min-width: 0; }
  .chat { position: fixed; inset: 0; z-index: 10; }
  .chat.empty { display: none; }
  #main.chat-open #sidebar { display: none; }
  .chat-header .back { display: block; }
  .grid2 { grid-template-columns: 1fr; }
  #local-video { width: 92px; height: 128px; }
  .call-stage { grid-template-columns: 1fr; }
}
