/* Planet Messenger — мобильный тёмный интерфейс */

:root {
  --bg: #0b0f1a;
  --bg-elev: #121829;
  --bg-input: #1a2236;
  --line: #222b40;
  --text: #e7ecf5;
  --text-dim: #8a96ad;
  --accent: #6c8cff;
  --accent-2: #b06cff;
  --me: #2f4bd0;
  --me-2: #5e3bd6;
  --bubble: #1b2236;
  --danger: #ff6b6b;
  --ok: #46d6a0;
  --radius: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-size: 16px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
}

body {
  background:
    radial-gradient(1200px 600px at 50% -10%, #1a2546 0%, transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ---------- Экран входа ---------- */
.login {
  height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login__card {
  width: 100%;
  max-width: 380px;
  text-align: center;
  animation: rise .5s ease;
}
@keyframes rise {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}
.login__logo {
  font-size: 64px;
  filter: drop-shadow(0 8px 24px rgba(108,140,255,.45));
}
.login__title {
  margin: 8px 0 2px;
  font-size: 38px;
  letter-spacing: -0.5px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.login__subtitle { margin: 0 0 28px; color: var(--text-dim); }
.login__form { display: grid; gap: 14px; text-align: left; }
.login__hint { margin-top: 18px; color: var(--text-dim); font-size: 13px; }
.login__error {
  background: rgba(255,107,107,.14);
  border: 1px solid rgba(255,107,107,.5);
  color: #ffc9c9; font-size: 14px;
  padding: 10px 14px; border-radius: 12px; text-align: center;
}
.field__opt { color: var(--text-dim); font-weight: 400; }

.invite {
  display: flex; align-items: center; gap: 8px; justify-content: center;
  background: linear-gradient(90deg, rgba(108,140,255,.18), rgba(176,108,255,.18));
  border: 1px solid rgba(108,140,255,.4);
  color: var(--text); font-size: 14px;
  padding: 10px 14px; border-radius: 14px; margin-bottom: 18px;
}
.invite__icon { font-size: 18px; }
.invite b { color: var(--accent); }

.field { display: grid; gap: 6px; }
.field__label { font-size: 13px; color: var(--text-dim); padding-left: 4px; }
.field__input {
  width: 100%;
  padding: 14px 16px;
  background: var(--bg-input);
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--text);
  font-size: 16px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.field__input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(108,140,255,.18);
}

.btn {
  border: none;
  cursor: pointer;
  font-size: 16px;
  font-weight: 600;
  padding: 15px;
  border-radius: 14px;
  color: #fff;
  transition: transform .08s, filter .15s;
}
.btn:active { transform: scale(.98); }
.btn--primary {
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  box-shadow: 0 8px 24px rgba(108,140,255,.35);
}

/* ---------- Чат ---------- */
.chat {
  height: 100dvh;
  display: flex;
  flex-direction: column;
}
.chat__header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(10px + var(--safe-top)) 12px 10px;
  background: rgba(18,24,41,.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.chat__roominfo { flex: 1; min-width: 0; }
.chat__roomname {
  font-weight: 700;
  font-size: 17px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat__online { font-size: 12px; color: var(--text-dim); margin-top: 1px; }
.chat__status { font-size: 12px; color: var(--text-dim); }
.chat__status.online { color: var(--ok); }
.chat__status.offline { color: var(--danger); }

.iconbtn {
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 28px;
  line-height: 1;
  width: 34px;
  height: 34px;
  cursor: pointer;
  border-radius: 10px;
}
.iconbtn:active { background: var(--bg-input); }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px 6px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}

.msg {
  max-width: 82%;
  padding: 9px 13px;
  border-radius: var(--radius);
  background: var(--bubble);
  border: 1px solid var(--line);
  align-self: flex-start;
  animation: pop .18s ease;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
@keyframes pop {
  from { opacity: 0; transform: translateY(6px) scale(.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.msg--me {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--me), var(--me-2));
  border-color: transparent;
}
.msg__nick {
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 2px;
  color: var(--accent);
}
.msg--me .msg__nick { display: none; }
.msg__text { font-size: 15px; line-height: 1.4; white-space: pre-wrap; }
.msg__time {
  font-size: 10.5px;
  color: var(--text-dim);
  margin-top: 3px;
  text-align: right;
}
.msg--me .msg__time { color: rgba(255,255,255,.7); }

.msg__text a { color: #cdd9ff; }
.msg--me .msg__text a { color: #fff; text-decoration: underline; }

.sys {
  align-self: center;
  font-size: 12px;
  color: var(--text-dim);
  background: var(--bg-elev);
  padding: 4px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
}

.typing {
  min-height: 18px;
  padding: 0 16px 2px;
  font-size: 12px;
  color: var(--text-dim);
  font-style: italic;
}

.composer {
  display: flex;
  gap: 8px;
  padding: 8px 10px calc(8px + var(--safe-bottom));
  background: rgba(18,24,41,.9);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.composer__input {
  flex: 1;
  padding: 12px 16px;
  background: var(--bg-input);
  border: 1px solid var(--line);
  border-radius: 22px;
  color: var(--text);
  font-size: 16px;
  outline: none;
}
.composer__input:focus { border-color: var(--accent); }
.composer__send {
  width: 46px;
  height: 46px;
  flex: 0 0 46px;
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform .08s;
}
.composer__send:active { transform: scale(.92); }
.composer__send:disabled { opacity: .4; }

/* Картинки и файлы в сообщениях */
.msg__img {
  display: block;
  max-width: 240px;
  max-height: 320px;
  border-radius: 12px;
  cursor: pointer;
}
.msg__file {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: inherit;
  min-width: 180px;
}
.msg__fileicon { font-size: 22px; }
.msg__fileinfo { display: flex; flex-direction: column; min-width: 0; }
.msg__filename { font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 200px; }
.msg__filesize { font-size: 11px; color: var(--text-dim); }
.msg--me .msg__filesize { color: rgba(255,255,255,.75); }

.composer__attach {
  width: 44px; height: 44px; flex: 0 0 44px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--bg-input);
  color: var(--text);
  font-size: 24px;
  cursor: pointer;
  display: grid; place-items: center;
}
.composer__attach:active { transform: scale(.92); }

/* Кнопки в шапке */
.chat__header .iconbtn { font-size: 20px; width: 38px; }
#back-btn { font-size: 28px; }

/* Модалки (выбор звонка, входящий) */
.modal {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center;
  background: rgba(4,7,15,.72);
  backdrop-filter: blur(6px);
  padding: 24px;
}
.modal__card {
  width: 100%; max-width: 360px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 24px;
  text-align: center;
  animation: rise .25s ease;
}
.modal__title { margin: 6px 0 4px; font-size: 20px; }
.modal__sub { margin: 0 0 18px; color: var(--text-dim); font-size: 14px; }

.btn--ghost {
  background: var(--bg-input);
  border: 1px solid var(--line);
  width: 100%;
  margin-top: 8px;
}

.calllist { display: grid; gap: 8px; margin: 8px 0 16px; max-height: 50vh; overflow-y: auto; }
.calllist__item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px;
  background: var(--bg-input);
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--text); font-size: 16px; cursor: pointer;
}
.calllist__avatar {
  width: 36px; height: 36px; flex: 0 0 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid; place-items: center; font-weight: 700; text-transform: uppercase;
}
.calllist__call { margin-left: auto; }

/* Входящий звонок */
.incoming__avatar {
  width: 84px; height: 84px; margin: 4px auto 8px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid; place-items: center; font-size: 38px;
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(108,140,255,.5); }
  50% { box-shadow: 0 0 0 16px rgba(108,140,255,0); }
}
.incoming__actions { display: flex; gap: 12px; margin-top: 8px; }
.callbtn {
  flex: 1; padding: 14px; border: none; border-radius: 14px;
  font-size: 16px; font-weight: 600; color: #fff; cursor: pointer;
}
.callbtn--accept { background: var(--ok); }
.callbtn--decline { background: var(--danger); }
.callbtn:active { transform: scale(.97); }

/* Экран звонка */
.callscreen {
  position: fixed; inset: 0; z-index: 60;
  background: #05070d;
  display: flex; flex-direction: column;
}
.callscreen__remote {
  position: absolute; inset: 0;
  width: 100%; height: 100%; object-fit: cover;
  background: #05070d;
}
.callscreen__local {
  position: absolute; top: calc(16px + var(--safe-top)); right: 16px;
  width: 104px; height: 150px; object-fit: cover;
  border-radius: 14px; border: 2px solid rgba(255,255,255,.25);
  z-index: 2; transform: scaleX(-1);
  background: #11162a;
}
.callscreen__top {
  position: relative; z-index: 2;
  padding: calc(18px + var(--safe-top)) 20px 0;
  text-align: center;
  text-shadow: 0 2px 8px rgba(0,0,0,.6);
}
.callscreen__peer { font-size: 20px; font-weight: 700; }
.callscreen__timer { font-size: 14px; color: rgba(255,255,255,.85); margin-top: 2px; }
.callscreen__diag { font-size: 11px; color: rgba(255,255,255,.55); margin-top: 4px; text-shadow: 0 1px 4px rgba(0,0,0,.6); }
.callscreen__controls {
  position: relative; z-index: 2;
  margin-top: auto;
  display: flex; justify-content: center; gap: 22px;
  padding: 24px 0 calc(34px + var(--safe-bottom));
}
.ctrl {
  width: 60px; height: 60px; border: none; border-radius: 50%;
  background: rgba(255,255,255,.16);
  backdrop-filter: blur(8px);
  font-size: 26px; cursor: pointer;
  display: grid; place-items: center;
  transition: transform .08s, background .15s;
}
.ctrl:active { transform: scale(.9); }
.ctrl--off { background: var(--danger); }
.ctrl--hangup { background: var(--danger); }

/* Кнопка-фолбэк «включить звук» (если браузер заблокировал автоплей аудио) */
.unmute {
  position: absolute; z-index: 4;
  left: 50%; top: calc(70px + var(--safe-top)); transform: translateX(-50%);
  background: var(--accent); color: #fff; border: none;
  padding: 12px 20px; border-radius: 999px; font-size: 15px; font-weight: 600;
  cursor: pointer; box-shadow: 0 8px 24px rgba(108,140,255,.45);
  animation: pulse 1.6s ease-in-out infinite;
}

/* Плашка «камера собеседника выключена» поверх большого видео */
.mediaoff {
  position: absolute; inset: 0; z-index: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; background: #0a0e18; text-align: center; padding: 20px;
}
.mediaoff__avatar {
  width: 96px; height: 96px; border-radius: 50%;
  display: grid; place-items: center; font-size: 44px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}
.mediaoff__text { color: var(--text-dim); font-size: 15px; }

/* Плашка на своём маленьком превью, когда своя камера выключена */
.localoff {
  position: absolute; top: calc(16px + var(--safe-top)); right: 16px;
  width: 104px; height: 150px; z-index: 3;
  display: grid; place-items: center;
  border-radius: 14px; border: 2px solid rgba(255,255,255,.25);
  background: #11162a; color: var(--text-dim); font-size: 22px;
}

/* Индикатор «собеседник без звука» под именем */
.callscreen__micoff {
  font-size: 13px; color: #ffd0d0; margin-top: 4px;
  text-shadow: 0 2px 8px rgba(0,0,0,.6);
}

/* Тост */
.toast {
  position: fixed; left: 50%; bottom: calc(90px + var(--safe-bottom));
  transform: translate(-50%, 12px);
  background: var(--bg-elev); color: var(--text);
  border: 1px solid var(--line);
  padding: 10px 18px; border-radius: 999px;
  font-size: 14px; z-index: 80;
  opacity: 0; transition: opacity .25s, transform .25s;
  pointer-events: none; max-width: 86vw; text-align: center;
}
.toast--show { opacity: 1; transform: translate(-50%, 0); }

/* Скроллбар (десктоп) */
.messages::-webkit-scrollbar { width: 8px; }
.messages::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; }
