:root {
  --bg: #0f1115;
  --bg-elevated: #171a21;
  --bg-input: #1e222b;
  --border: #262b36;
  --text: #e8eaed;
  --text-dim: #8b93a1;
  --accent: #5b8def;
  --accent-soft: #2a3a5c;
  --bubble-in: #1e222b;
  --bubble-out: #2f5ca8;
  --danger: #e5534b;
  --radius: 18px;
  --header-h: 60px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

.hidden { display: none !important; }

svg { width: 22px; height: 22px; fill: currentColor; }

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
}

.screen { height: 100dvh; display: flex; flex-direction: column; }

/* --------------------------------------------------------------- логин */

.login-screen { align-items: center; justify-content: center; padding: 24px; }

.login-card {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 32px 28px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 20px;
  text-align: center;
}

.login-logo { font-size: 44px; line-height: 1; }
.login-card h1 { margin: 4px 0 0; font-size: 24px; font-weight: 650; letter-spacing: -0.3px; }
.login-sub { margin: 0 0 12px; color: var(--text-dim); font-size: 14px; }

.login-card input {
  padding: 12px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color .15s;
}
.login-card input:focus { border-color: var(--accent); }

.login-card button[type="submit"] {
  margin-top: 6px;
  padding: 12px;
  background: var(--accent);
  border-radius: 12px;
  font-weight: 600;
  transition: filter .15s;
}
.login-card button[type="submit"]:hover:not(:disabled) { filter: brightness(1.1); }
.login-card button[type="submit"]:disabled { opacity: .55; cursor: default; }

.login-error { min-height: 18px; color: var(--danger); font-size: 13px; }

/* ---------------------------------------------------------------- чат */

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--header-h);
  padding: 0 12px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}

.avatar {
  width: 40px; height: 40px;
  flex: 0 0 auto;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--accent);
  font-weight: 600;
  text-transform: uppercase;
}

.peer-info { flex: 1; min-width: 0; }
.peer-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.peer-status { font-size: 12.5px; color: var(--text-dim); }
.peer-status.online { color: var(--accent); }

.icon-btn {
  display: grid; place-items: center;
  width: 40px; height: 40px;
  flex: 0 0 auto;
  position: relative;
  color: var(--text-dim);
  border-radius: 50%;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--bg-input); color: var(--text); }
.icon-btn.active { color: var(--accent); }
.icon-btn.small { width: 32px; height: 32px; }
.icon-btn.small svg { width: 18px; height: 18px; }

.timer-badge {
  position: absolute;
  right: 2px; bottom: 2px;
  min-width: 16px; height: 16px;
  padding: 0 3px;
  display: grid; place-items: center;
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  font-size: 9px;
  font-weight: 700;
}

.connection-banner {
  padding: 6px;
  background: #4a3a12;
  color: #f0d18a;
  font-size: 13px;
  text-align: center;
}

/* ------------------------------------------------------------ лента */

.message-list {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 12px 4px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  scrollbar-width: thin;
}

.load-more { padding: 10px; color: var(--text-dim); font-size: 13px; text-align: center; }

.day-sep {
  align-self: center;
  margin: 12px 0 6px;
  padding: 3px 12px;
  background: var(--bg-input);
  border-radius: 12px;
  color: var(--text-dim);
  font-size: 12px;
}

.row { display: flex; max-width: 100%; }
.row.out { justify-content: flex-end; }
.row + .row.grouped { margin-top: 0; }
.row:not(.grouped) { margin-top: 8px; }

.bubble {
  position: relative;
  max-width: min(72%, 560px);
  padding: 7px 11px 6px;
  border-radius: var(--radius);
  background: var(--bubble-in);
  word-wrap: break-word;
  overflow-wrap: anywhere;
  cursor: default;
  transition: background .15s;
}
.row.out .bubble { background: var(--bubble-out); }
.bubble.highlight { animation: flash 1.2s; }
@keyframes flash { 0%, 40% { background: var(--accent-soft); } }

.bubble.media-only { padding: 4px; }
.bubble.gone { background: transparent; border: 1px dashed var(--border); color: var(--text-dim); font-style: italic; }
.bubble.round { padding: 0; background: none; border-radius: 50%; }

.reply-quote {
  display: block;
  margin-bottom: 5px;
  padding: 4px 8px;
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  background: rgba(255, 255, 255, .07);
  font-size: 13px;
  cursor: pointer;
  text-align: left;
  width: 100%;
}
.reply-quote .reply-author { color: var(--accent); font-weight: 600; }
.row.out .reply-quote .reply-author { color: #cfe0ff; }
.reply-quote .reply-text {
  color: var(--text-dim);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.row.out .reply-quote .reply-text { color: #d5dff2; }

.bubble-text { white-space: pre-wrap; }
.bubble-text a { color: #8fb8ff; }
.row.out .bubble-text a { color: #dbe8ff; }

.meta {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  float: right;
  margin: 6px 0 -2px 10px;
  color: var(--text-dim);
  font-size: 11px;
  user-select: none;
}
.row.out .meta { color: #c3d4f0; }
.meta .edited { font-style: italic; }
.meta .ticks { letter-spacing: -3px; }
.meta .ticks.read { color: #7fd4ff; }
.meta .burn { color: #ffb26b; }

.bubble.media-only .meta {
  position: absolute;
  right: 10px; bottom: 9px;
  margin: 0;
  padding: 2px 7px;
  background: rgba(0, 0, 0, .5);
  border-radius: 10px;
  color: #fff;
}

/* --------------------------------------------------------- вложения */

.media-photo, .media-video {
  display: block;
  max-width: 100%;
  max-height: 380px;
  border-radius: 14px;
  cursor: pointer;
  background: #000;
}

.media-round {
  width: 220px; height: 220px;
  border-radius: 50%;
  object-fit: cover;
  background: #000;
  cursor: pointer;
}

.sealed {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 190px;
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, .06);
  cursor: pointer;
}
.sealed .sealed-icon {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--accent);
  font-size: 18px;
}
.sealed .sealed-label { font-size: 14px; }
.sealed .sealed-hint { color: var(--text-dim); font-size: 12px; }
.row.out .sealed .sealed-hint { color: #cfdcf2; }

.file-card {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 200px;
  padding: 4px 2px;
  text-decoration: none;
  color: inherit;
}
.file-card .file-icon {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--accent);
  font-size: 18px;
  flex: 0 0 auto;
}
.file-card .file-name { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-card .file-size { color: var(--text-dim); font-size: 12px; }
.row.out .file-card .file-size { color: #cfdcf2; }

/* голосовое */
.voice {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 210px;
  padding: 2px 0;
}
.voice-play {
  width: 38px; height: 38px;
  flex: 0 0 auto;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
}
.row.out .voice-play { background: rgba(255, 255, 255, .9); color: var(--bubble-out); }
.voice-body { flex: 1; min-width: 0; }
.voice-wave {
  display: flex;
  align-items: center;
  gap: 2px;
  height: 26px;
  cursor: pointer;
}
.voice-wave i {
  flex: 1;
  min-width: 2px;
  background: currentColor;
  border-radius: 2px;
  opacity: .35;
  transition: opacity .1s;
}
.voice-wave i.played { opacity: 1; }
.voice-time { color: var(--text-dim); font-size: 12px; }
.row.out .voice-time { color: #cfdcf2; }

/* --------------------------------------------------------- композер */

.typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 20px 4px;
  color: var(--text-dim);
  font-size: 12.5px;
}
.typing-indicator .dot {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--text-dim);
  animation: bounce 1.2s infinite;
}
.typing-indicator .dot:nth-child(2) { animation-delay: .15s; }
.typing-indicator .dot:nth-child(3) { animation-delay: .3s; margin-right: 4px; }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .4; } 30% { transform: translateY(-4px); opacity: 1; } }

.composer {
  flex: 0 0 auto;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
}

.context-bar, .recorder-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  padding: 6px 8px;
  background: var(--bg-input);
  border-radius: 12px;
}
.context-accent { width: 3px; align-self: stretch; border-radius: 2px; background: var(--accent); }
.context-body { flex: 1; min-width: 0; }
.context-title { color: var(--accent); font-size: 13px; font-weight: 600; }
.context-preview {
  color: var(--text-dim);
  font-size: 13px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.rec-dot {
  width: 9px; height: 9px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--danger);
  animation: pulse 1.2s infinite;
}
@keyframes pulse { 50% { opacity: .25; } }
.recorder-time { font-variant-numeric: tabular-nums; font-size: 13px; min-width: 38px; }
.recorder-wave { flex: 1; height: 32px; min-width: 0; }

.composer-main { display: flex; align-items: flex-end; gap: 4px; }

.input-wrap {
  flex: 1;
  min-width: 0;
  background: var(--bg-input);
  border-radius: 20px;
  padding: 8px 14px;
}
#text-input {
  width: 100%;
  max-height: 140px;
  background: none;
  border: 0;
  outline: none;
  color: var(--text);
  font: inherit;
  resize: none;
  line-height: 1.4;
}
#text-input::placeholder { color: var(--text-dim); }

.send-btn {
  width: 40px; height: 40px;
  flex: 0 0 auto;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  transition: filter .15s;
}
.send-btn:hover { filter: brightness(1.1); }

/* ---------------------------------------------------------- попапы */

.popup {
  position: fixed;
  z-index: 40;
  min-width: 170px;
  padding: 6px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, .5);
  display: flex;
  flex-direction: column;
}
.popup button {
  padding: 9px 12px;
  border-radius: 8px;
  text-align: left;
  font-size: 14px;
  white-space: nowrap;
}
.popup button:hover { background: var(--bg-input); }
.popup button.danger { color: var(--danger); }
.popup button.checked { color: var(--accent); font-weight: 600; }

/* --------------------------------------------------------- просмотр */

.viewer {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: rgba(0, 0, 0, .93);
  padding: 24px;
}
.viewer-content { max-width: 100%; max-height: 82vh; display: grid; place-items: center; }
.viewer-content img, .viewer-content video { max-width: 100%; max-height: 82vh; border-radius: 8px; }
.viewer-close {
  position: absolute;
  top: 16px; right: 20px;
  width: 40px; height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .12);
  font-size: 18px;
}
.viewer-timer {
  position: absolute;
  top: 20px; left: 50%;
  transform: translateX(-50%);
  padding: 6px 14px;
  background: rgba(255, 140, 60, .2);
  border: 1px solid rgba(255, 160, 80, .5);
  border-radius: 14px;
  color: #ffb26b;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------- видеосообщение */

.vn-stage { position: relative; width: min(78vw, 320px); aspect-ratio: 1; }
.vn-preview {
  width: 100%; height: 100%;
  border-radius: 50%;
  object-fit: cover;
  background: #000;
  transform: scaleX(-1);
}
.vn-ring {
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 3px solid transparent;
  transition: border-color .2s;
}
.vn-ring.recording { border-color: var(--danger); animation: pulse 1.2s infinite; }
.vn-time { font-variant-numeric: tabular-nums; font-size: 16px; color: var(--text-dim); }
.vn-actions { display: flex; gap: 12px; }
.vn-btn {
  padding: 11px 26px;
  border-radius: 22px;
  background: rgba(255, 255, 255, .12);
  font-weight: 600;
}
.vn-btn.primary { background: var(--accent); }

/* ----------------------------------------------------------- тост */

.toast {
  position: fixed;
  left: 50%;
  bottom: 90px;
  z-index: 80;
  transform: translateX(-50%);
  max-width: 88vw;
  padding: 10px 18px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 22px;
  font-size: 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .5);
}

@media (max-width: 600px) {
  .bubble { max-width: 84%; }
  .media-round { width: 180px; height: 180px; }
}
