/* Мини-приложение «Удалённые диалоги». Цвета берутся из темы Telegram (--tg-theme-*),
   запасные — для открытия в обычном браузере. */
:root {
  --fb-bg: #eef0f4; --fb-card: #ffffff; --fb-text: #0f1114; --fb-hint: #858b94; --fb-link: #2481cc;
  --fb-accent: #2f8ae5; --fb-accent-text: #ffffff; --fb-line: rgba(15, 17, 20, .08); --fb-danger: #e0453a;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fb-bg: #0f1114; --fb-card: #1c1f24; --fb-text: #f2f3f5; --fb-hint: #8a9099; --fb-link: #6ab3f3;
    --fb-accent: #3a8fe6; --fb-line: rgba(255, 255, 255, .08); --fb-danger: #ff6b60;
  }
}
:root {
  --bg: var(--tg-theme-secondary-bg-color, var(--fb-bg));
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, var(--fb-card)));
  --text: var(--tg-theme-text-color, var(--fb-text));
  --hint: var(--tg-theme-hint-color, var(--fb-hint));
  --link: var(--tg-theme-link-color, var(--fb-link));
  --accent: var(--tg-theme-button-color, var(--fb-accent));
  --accent-text: var(--tg-theme-button-text-color, var(--fb-accent-text));
  --line: var(--tg-theme-section-separator-color, var(--fb-line));
  --danger: var(--tg-theme-destructive-text-color, var(--fb-danger));
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased; -webkit-text-size-adjust: 100%;
  overflow-wrap: anywhere;
}
button { font: inherit; color: inherit; border: 0; background: none; padding: 0; margin: 0; cursor: pointer; }
#app { max-width: 640px; margin: 0 auto; min-height: 100vh; padding-bottom: calc(20px + env(safe-area-inset-bottom)); }

/* ── список диалогов ── */
.top { padding: 22px 20px 14px; }
.top h1 { margin: 0; font-size: 26px; line-height: 1.15; font-weight: 700; letter-spacing: -.01em; }
.top p { margin: 6px 0 0; color: var(--hint); font-size: 14.5px; }

.list { margin: 0 12px; background: var(--card); border-radius: 16px; overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 14px; text-align: left; position: relative; }
.row:active { background: var(--line); }
.row + .row::before { content: ""; position: absolute; top: 0; left: 72px; right: 0; height: 1px; background: var(--line); }
.avatar {
  flex: none; width: 46px; height: 46px; border-radius: 50%; color: #fff; font-weight: 600; font-size: 18px;
  display: flex; align-items: center; justify-content: center; text-transform: uppercase; letter-spacing: .01em;
}
.avatar.small { width: 36px; height: 36px; font-size: 14.5px; }
.who { flex: 1; min-width: 0; }
.line { display: flex; align-items: baseline; gap: 8px; }
.line + .line { margin-top: 2px; align-items: center; }
.name { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.when { flex: none; color: var(--hint); font-size: 13px; }
.preview { flex: 1; min-width: 0; color: var(--hint); font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill {
  flex: none; min-width: 22px; height: 22px; padding: 0 7px; border-radius: 11px; background: var(--danger); color: #fff;
  font-size: 12.5px; font-weight: 600; line-height: 22px; text-align: center;
}
.foot { margin: 14px 24px 0; color: var(--hint); font-size: 13px; line-height: 1.4; text-align: center; }

/* ── пустой экран, ошибки, загрузка ── */
.blank { min-height: 78vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px 32px; text-align: center; }
.blank .icon { font-size: 56px; line-height: 1; margin-bottom: 14px; }
.blank h2 { margin: 0; font-size: 20px; font-weight: 700; }
.blank p { margin: 8px 0 0; color: var(--hint); font-size: 15px; max-width: 320px; }
.blank .act { margin-top: 20px; padding: 11px 22px; border-radius: 12px; background: var(--accent); color: var(--accent-text); font-weight: 600; }
.blank .act:active { opacity: .8; }
.spin { width: 30px; height: 30px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── диалог ── */
.bar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px; padding: 8px 12px 8px 4px;
  background: var(--bg); border-bottom: 1px solid var(--line);
}
.back { flex: none; width: 40px; height: 40px; border-radius: 50%; color: var(--link); font-size: 30px; line-height: 36px; }
.back:active { background: var(--line); }
.bar .who { line-height: 1.2; }
.bar .name { display: block; }
.bar .sub { display: block; margin-top: 2px; color: var(--hint); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.chat { padding: 4px 10px 0; display: flex; flex-direction: column; }
.batch {
  align-self: center; margin: 14px 0 8px; padding: 4px 11px; border-radius: 12px; font-size: 12.5px; font-weight: 600;
  background: rgba(128, 128, 128, .18); background: color-mix(in srgb, var(--hint) 20%, transparent);
}
.msg { display: flex; margin: 2px 0; }
.msg.out { justify-content: flex-end; }
.bubble {
  max-width: 84%; min-width: 64px; padding: 7px 11px 6px; border-radius: 17px; background: var(--card);
  font-size: 15.5px; line-height: 1.34; user-select: text; -webkit-user-select: text;
}
.msg.in .bubble { border-bottom-left-radius: 6px; }
.msg.out .bubble {
  border-bottom-right-radius: 6px; background: var(--card);
  background: color-mix(in srgb, var(--accent) 26%, var(--card));
}
.text { white-space: pre-wrap; }
.text.none { color: var(--hint); font-style: italic; }
.text code, .text pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .92em; }
.text pre { margin: 4px 0; padding: 7px 9px; border-radius: 8px; background: var(--line); white-space: pre-wrap; }
.text blockquote { margin: 3px 0; padding: 2px 0 2px 9px; border-left: 3px solid var(--accent); }
.text .link { color: var(--link); text-decoration: none; cursor: pointer; }
.text .spoiler { border-radius: 4px; background: var(--hint); color: transparent; cursor: pointer; transition: background .15s, color .15s; }
.text .spoiler.open { background: var(--line); color: inherit; }
.meta { margin-top: 2px; text-align: right; color: var(--hint); font-size: 11.5px; user-select: none; -webkit-user-select: none; }

.media {
  display: flex; align-items: center; gap: 10px; width: 100%; min-width: 210px; margin: 1px 0 5px; padding: 10px 12px;
  border-radius: 12px; background: var(--line); text-align: left;
}
.media:active { opacity: .75; }
.media.still { cursor: default; }
.media.still:active { opacity: 1; }
.media .glyph { flex: none; font-size: 26px; line-height: 1; }
.media .label { min-width: 0; }
.media .what { display: block; font-weight: 600; font-size: 15px; }
.media .hint { display: block; margin-top: 1px; color: var(--hint); font-size: 13px; }
.shot, .clip { display: block; width: 100%; max-height: 70vh; margin: 1px 0 5px; border-radius: 12px; background: var(--line); object-fit: contain; }
.shot { cursor: zoom-in; }
.clip.round { width: 220px; height: 220px; border-radius: 50%; object-fit: cover; }
.sound { display: block; width: 240px; max-width: 100%; margin: 2px 0 5px; }
.send { display: inline-block; margin: 0 0 3px; padding: 5px 11px; border-radius: 10px; background: var(--line); color: var(--link); font-size: 13.5px; font-weight: 600; }
.send:active { opacity: .7; }
.send[disabled] { opacity: .5; cursor: default; }

.zoom { position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; background: rgba(0, 0, 0, .92); cursor: zoom-out; }
.zoom img { max-width: 100%; max-height: 100%; object-fit: contain; }

#toast {
  position: fixed; left: 50%; bottom: calc(22px + env(safe-area-inset-bottom)); z-index: 30; transform: translateX(-50%);
  max-width: 86%; padding: 10px 16px; border-radius: 14px; background: rgba(20, 22, 26, .92); color: #fff;
  font-size: 14.5px; text-align: center; box-shadow: 0 6px 24px rgba(0, 0, 0, .25);
}
