:root {
  --bg: #0e1621;
  --sidebar: #17212b;
  --header: #17212b;
  --chat-bg: #0e1621;
  --bubble-in: #182533;
  --bubble-out: #2b5278;
  --text: #f5f5f5;
  --muted: #8b9aab;
  --line: rgba(255, 255, 255, 0.06);
  --accent: #6ab3f3;
  --good: #4fae4e;
  --bad: #e75a5a;
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body {
  height: 100%;
  overflow: hidden;
}
body {
  margin: 0;
  font-family: "Segoe UI", "Roboto", "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}

.hidden { display: none !important; }
.hint { color: var(--muted); margin: 0 0 12px; font-size: 14px; }
.error { margin: 8px 0 0; color: var(--bad); font-size: 13px; }
h1 { margin: 0 0 6px; font-size: 24px; font-weight: 600; }
h2 { margin: 0; font-size: 16px; font-weight: 600; }
.sub { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

.auth-wrap {
  min-height: 100%;
  height: 100%;
  overflow: auto;
  display: grid;
  place-items: center;
  background:
    radial-gradient(800px 400px at 20% 0%, rgba(43, 82, 120, 0.45), transparent 60%),
    var(--bg);
}
.auth-card {
  width: min(400px, calc(100% - 28px));
  padding: 32px 24px;
  background: var(--sidebar);
  border-radius: 16px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
}
.auth-logo {
  width: 88px;
  height: 88px;
  margin: 0 auto 14px;
  border-radius: 22%;
  overflow: hidden;
  background: transparent;
}
.auth-logo img {
  width: 100%;
  height: 100%;
  display: block;
}
.auth-form { display: grid; gap: 10px; }
label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
input, textarea {
  width: 100%;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: #242f3d;
  color: var(--text);
  outline: none;
  font: inherit;
}
textarea { resize: none; min-height: 44px; max-height: 120px; }
input:focus, textarea:focus { border-color: rgba(106, 179, 243, 0.5); }

button {
  border: 0;
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
  color: var(--text);
  background: #242f3d;
  font: inherit;
}
button:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: #2b5278; }
.btn-danger, .icon-btn.danger { color: #ffb4b4; }
.btn-ghost { background: transparent; }
.btn-send-wide {
  background: #2b5278;
  padding: 12px;
  font-weight: 600;
}

.app {
  height: 100%;
  width: 100%;
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  overflow: hidden;
}

.sidebar {
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}
.sidebar-head, .chat-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  min-height: 56px;
  background: var(--header);
  flex-shrink: 0;
}
.me-block {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}
#me-label {
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-actions { display: flex; gap: 2px; flex-shrink: 0; }
.icon-btn {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 50%;
  background: transparent;
  font-size: 18px;
  line-height: 1;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.06); }

.search-wrap { padding: 8px 12px 10px; }
.search-wrap input {
  border-radius: 22px;
  background: #242f3d;
  padding: 9px 14px;
}

.user-list {
  overflow: auto;
  flex: 1;
}
.chat-item {
  display: grid;
  grid-template-columns: 48px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 8px 12px;
  cursor: pointer;
  border: 0;
  width: 100%;
  text-align: left;
  background: transparent;
  border-radius: 0;
}
.chat-item:hover { background: rgba(255, 255, 255, 0.04); }
.chat-item.active { background: #2b5278; }
.chat-item-main { min-width: 0; }
.chat-item-name {
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-item-preview {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}
.chat-item.active .chat-item-preview { color: rgba(255, 255, 255, 0.78); }
.chat-item-meta {
  display: grid;
  justify-items: end;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: transparent;
}
.dot.online { background: var(--good); }

.avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 16px;
  color: #fff;
  flex-shrink: 0;
  text-transform: uppercase;
  overflow: hidden;
  position: relative;
}
.avatar img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.avatar.sm { width: 36px; height: 36px; font-size: 14px; }
.avatar.lg { width: 88px; height: 88px; font-size: 32px; }
.avatar-h0 { background: #e17076; }
.avatar-h1 { background: #7bc862; }
.avatar-h2 { background: #e5ca18; }
.avatar-h3 { background: #65aadd; }
.avatar-h4 { background: #a695e7; }
.avatar-h5 { background: #ee7aae; }
.avatar-h6 { background: #6ec9cb; }
.avatar-h7 { background: #faa357; }

.chat {
  background:
    radial-gradient(circle at 20% 10%, rgba(43, 82, 120, 0.18), transparent 40%),
    repeating-linear-gradient(-32deg, rgba(255,255,255,0.015) 0 2px, transparent 2px 12px),
    var(--chat-bg);
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}
.chat-empty {
  flex: 1;
  display: grid;
  place-items: center;
  color: var(--muted);
}
.chat-empty p {
  background: rgba(24, 37, 51, 0.85);
  padding: 8px 14px;
  border-radius: 20px;
}
.chat-active {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.chat-info-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
  background: transparent;
  text-align: left;
  padding: 4px 6px;
  border-radius: 10px;
}
.chat-info-btn:hover { background: rgba(255, 255, 255, 0.05); }
.chat-head-text { flex: 1; min-width: 0; }
.chat-head-text h2 {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.back-btn {
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.back-btn svg { display: block; }

.messages {
  flex: 1;
  overflow: auto;
  padding: 12px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.msg {
  max-width: min(78%, 520px);
  padding: 6px 10px 4px;
  border-radius: 12px 12px 12px 4px;
  background: var(--bubble-in);
  align-self: flex-start;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.25);
}
.msg.me {
  align-self: flex-end;
  background: var(--bubble-out);
  border-radius: 12px 12px 4px 12px;
}
.msg .who {
  color: #6ab3f3;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 2px;
}
.msg .body { white-space: pre-wrap; word-wrap: break-word; font-size: 15px; line-height: 1.35; }
.msg a { color: #9cdcfe; }
.msg .meta {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 2px;
  color: rgba(255, 255, 255, 0.55);
  font-size: 11px;
}
.msg.me .meta { color: rgba(255, 255, 255, 0.7); }

.composer {
  display: flex;
  gap: 8px;
  padding: 8px 10px 10px;
  align-items: flex-end;
  background: var(--header);
}
.file-btn { font-size: 18px; }
.send-fab {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #2b5278;
  font-size: 16px;
  flex-shrink: 0;
}
.composer textarea {
  background: #242f3d;
  border-radius: 22px;
  padding: 10px 14px;
}

.call-actions { display: flex; gap: 4px; }
.incoming-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.62);
}
.incoming-card {
  width: min(420px, 100%);
  padding: 24px 20px;
  border-radius: 16px;
  background: #17212b;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  text-align: center;
}
.incoming-card p {
  margin: 0 0 18px;
  font-size: 18px;
  font-weight: 600;
}
.incoming-actions {
  display: flex;
  gap: 10px;
}
.incoming-actions .btn-primary,
.incoming-actions .btn-ghost {
  flex: 1;
  padding: 12px;
  font-weight: 600;
}
.incoming-actions .btn-primary { background: #4fae4e; }
.incoming-actions .btn-ghost { background: #c44b4b; }

.call-screen {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: #000;
  color: #fff;
  overflow: hidden;
}
.call-vid {
  position: absolute;
  background: #111;
  object-fit: cover;
}
.call-remote {
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  border-radius: 0;
}
.call-local {
  top: max(14px, env(safe-area-inset-top));
  right: 14px;
  width: 108px;
  height: 152px;
  z-index: 2;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.22);
  transform: scaleX(-1);
}
.call-off-layer {
  display: grid;
  place-items: center;
  z-index: 3;
  transform: none;
  background: #1c1c1e;
  color: #cfcfcf;
  font-size: 12px;
  text-align: center;
  padding: 8px;
}
.call-screen.swapped .call-remote {
  top: max(14px, env(safe-area-inset-top));
  right: 14px;
  left: auto;
  bottom: auto;
  width: 108px;
  height: 152px;
  z-index: 2;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}
.call-screen.swapped .call-local {
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}
.call-screen.swapped .call-off-layer {
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  border: 0;
  border-radius: 0;
  font-size: 18px;
}
.call-pip-hit {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  right: 14px;
  width: 108px;
  height: 152px;
  z-index: 4;
  padding: 0;
  border: 0;
  border-radius: 14px;
  background: transparent;
}
.call-top {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  z-index: 5;
  padding: max(16px, env(safe-area-inset-top)) 140px 12px 18px;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.55), transparent);
  pointer-events: none;
}
.call-peer-name {
  font-size: 20px;
  font-weight: 700;
}
.call-status {
  margin-top: 4px;
  color: rgba(255, 255, 255, 0.75);
  font-size: 14px;
}
.call-waiting {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: grid;
  place-content: center;
  gap: 8px;
  text-align: center;
  background: #111;
}
.call-waiting.hidden { display: none !important; }
.call-waiting-name {
  font-size: 28px;
  font-weight: 700;
}
.call-waiting-sub { color: rgba(255, 255, 255, 0.7); }
.call-controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 6;
  display: flex;
  justify-content: center;
  gap: 22px;
  padding: 18px 16px max(28px, env(safe-area-inset-bottom));
  background: linear-gradient(to top, rgba(0, 0, 0, 0.62), transparent);
}
.call-ctrl {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  padding: 0;
  display: grid;
  place-items: center;
  background: rgba(60, 60, 67, 0.82);
  color: #fff;
}
.call-ctrl.off { background: #fff; color: #1c1c1e; }
.call-ctrl.hang { background: #e53935; }
.call-ctrl.hang:hover { background: #c62828; }
.call-ctrl:disabled { opacity: 0.45; }

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  padding: 14px;
  background: rgba(0, 0, 0, 0.55);
  overflow: auto;
}
.modal-card, .admin-panel {
  width: min(560px, 100%);
  margin: 6vh auto;
  padding: 16px;
  background: var(--sidebar);
  border-radius: 14px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
}
.admin-panel { width: min(860px, 100%); }
.admin-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.group-form { display: grid; gap: 10px; }
.group-info { display: grid; gap: 12px; justify-items: center; }
.group-avatar-edit { cursor: pointer; }
.group-rename {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  width: 100%;
}
.group-info .member-pick,
.group-info .hint,
.group-info .error,
.group-info .btn-danger { width: 100%; }
.member-pick {
  max-height: 42vh;
  overflow: auto;
  display: grid;
  gap: 4px;
}
.member-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 10px;
}
.member-row:hover { background: rgba(255, 255, 255, 0.04); }
.member-row input { width: auto; }
.member-row .grow { flex: 1; min-width: 0; }
.member-row .btn-tiny {
  padding: 6px 10px;
  font-size: 12px;
  flex-shrink: 0;
}
.admin-create {
  display: grid;
  grid-template-columns: 1fr 1fr auto auto;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
}
.admin-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}
.admin-check input { width: auto; }
.admin-user-list { display: grid; gap: 8px; }
.admin-user {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 12px;
  border-radius: 12px;
  background: #242f3d;
}
.admin-user .meta { color: var(--muted); font-size: 12px; margin-top: 4px; }
.admin-user-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
}
.admin-user-actions input {
  width: min(180px, 40vw);
  padding: 8px 10px;
}

@media (max-width: 860px) {
  .admin-create { grid-template-columns: 1fr; }
  .admin-user { grid-template-columns: 1fr; }
  .admin-user-actions { justify-content: stretch; }
  .admin-user-actions input { width: 100%; }
}

/* Только телефоны: список или чат. На ПК список всегда слева. */
@media (max-width: 860px) and (pointer: coarse) {
  .app { grid-template-columns: 1fr; }
  .chat { display: none; }
  .app.show-chat .sidebar { display: none; }
  .app.show-chat .chat { display: flex; }
}
