/* Простой «мессенджер» для просмотра выгруженного дампа. Тёмная тема в духе
   Telegram; верстка под телефон (dvh + safe-area), без зависимостей. */

:root {
  --bg: #0e1621;
  --panel: #17212b;
  --panel-2: #1d2a35;
  --line: #101920;
  --accent: #2b5278;
  --bubble-in: #182533;
  --bubble-out: #2b5278;
  --text: #e9edf0;
  --muted: #7d8e9c;
  --radius: 14px;
}

* { box-sizing: border-box; }

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

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

/* ── Шапка ─────────────────────────────────────────────── */
.top {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex: none;
}
.top h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.icon-btn {
  background: none;
  border: 0;
  color: var(--text);
  font-size: 22px;
  line-height: 1;
  padding: 4px 6px;
  cursor: pointer;
  border-radius: 8px;
}
.icon-btn:active { background: var(--panel-2); }

/* ── Вкладки ───────────────────────────────────────────── */
.tabs {
  display: flex;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex: none;
}
.tab {
  flex: 1;
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  padding: 11px 0;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

/* ── Области ───────────────────────────────────────────── */
.main { flex: 1; min-height: 0; position: relative; }
.view { position: absolute; inset: 0; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; }
[hidden] { display: none !important; }

/* ── Поиск по диалогам ─────────────────────────────────── */
.search {
  display: block;
  width: calc(100% - 20px);
  margin: 10px;
  padding: 8px 12px;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
  outline: none;
}
.search::placeholder { color: var(--muted); }
.search:focus { border-color: var(--accent); }

/* ── Списки (диалоги / контакты) ───────────────────────── */
.rows { list-style: none; margin: 0; padding: 0; }
.row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--line);
}
.row:active { background: var(--panel-2); }
.avatar {
  position: relative;
  flex: none;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--accent);
  display: grid;
  place-items: center;
  font-weight: 600;
  font-size: 18px;
  color: #cfe0f0;
  overflow: hidden;
}
/* Фото перекрывает инициалы целиком; onerror его удаляет → остаются инициалы. */
.avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.row-body { flex: 1; min-width: 0; }
.row-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.row-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-time { color: var(--muted); font-size: 12px; flex: none; }
.row-sub { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub .me { color: #8aa9c9; }
.pin { color: var(--muted); font-size: 12px; }

/* ── Лента сообщений ───────────────────────────────────── */
.messages { display: flex; flex-direction: column; gap: 4px; padding: 12px 10px calc(env(safe-area-inset-bottom) + 14px); }
.bubble {
  max-width: 78%;
  min-width: 0;
  padding: 7px 10px 5px;
  border-radius: var(--radius);
  background: var(--bubble-in);
  align-self: flex-start;
  word-wrap: break-word;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.bubble.out { background: var(--bubble-out); align-self: flex-end; }
.bubble img { display: block; max-width: 100%; border-radius: 10px; margin-bottom: 4px; cursor: zoom-in; }
.bubble .time { font-size: 11px; color: var(--muted); float: right; margin: 4px 0 0 10px; }
.bubble.out .time { color: #bcd4ec; }
.day {
  align-self: center;
  background: rgba(0, 0, 0, 0.3);
  color: var(--muted);
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 10px;
  margin: 8px 0;
}
.earlier {
  display: block;
  margin: 10px auto;
  background: var(--panel-2);
  color: var(--text);
  border: 0;
  border-radius: 14px;
  padding: 7px 16px;
  font-size: 13px;
  cursor: pointer;
}

/* ── Медиа-галерея ─────────────────────────────────────── */
.gallery {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
  padding: 3px;
}
.thumb {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  display: block;
  background: var(--panel-2);
  cursor: zoom-in;
}

/* ── Состояние (загрузка / пусто / ошибка) ─────────────── */
.state {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  text-align: center;
  color: var(--muted);
  padding: 0 24px;
  margin: 0;
}
.state[hidden] { display: none; }

/* ── Лайтбокс ──────────────────────────────────────────── */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 10;
  cursor: zoom-out;
}
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }

@media (prefers-reduced-motion: no-preference) {
  .row, .tab, .bubble { transition: background 120ms ease-out; }
}
