:root {
  --bg: var(--tg-theme-bg-color, #0f0f12);
  --card: var(--tg-theme-secondary-bg-color, #17171c);
  --card-2: #1e1e25;
  --text: var(--tg-theme-text-color, #f0eeee);
  --muted: var(--tg-theme-hint-color, #8b8b95);
  --line: #2a2a33;
  --accent: #e01e2b;
  --accent-soft: rgba(224, 30, 43, 0.14);
  --danger: #ff5a5a;
  --warn: #f2b03a;
  --eye: #9a7bff;
  --ok: #43c463;
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  padding-bottom: 24px;
  -webkit-tap-highlight-color: transparent;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px calc(12px + env(safe-area-inset-top));
  padding-top: max(12px, env(safe-area-inset-top));
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; letter-spacing: 0.02em; }
.brand .mark { width: 22px; height: 22px; fill: var(--text); }
.brand .mark path:first-child, .brand .mark path:nth-child(2) { stroke: var(--accent); stroke-width: 1; }

.ghost {
  background: none;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 999px;
  font-family: var(--font);
}

.tabs {
  position: sticky;
  top: 0;
  z-index: 4;
  display: flex;
  gap: 4px;
  padding: 10px 12px;
  background: var(--bg);
}
.tabs button {
  flex: 1;
  padding: 9px 0;
  border: none;
  border-radius: 10px;
  background: var(--card);
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font);
}
.tabs button.active { background: var(--accent); color: #fff; }

main { padding: 4px 12px 0; max-width: 720px; margin: 0 auto; }

.muted { color: var(--muted); }
.center { text-align: center; padding: 48px 20px; color: var(--muted); }
.center h3 { color: var(--text); margin: 0 0 8px; }

.list { display: flex; flex-direction: column; gap: 8px; }

.chat-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid transparent;
  width: 100%;
  text-align: left;
  color: inherit;
  font-family: var(--font);
}
.chat-row:active { border-color: var(--line); }
.avatar {
  width: 44px;
  height: 44px;
  flex: none;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 700;
  color: #fff;
  font-size: 17px;
}
.chat-main { min-width: 0; flex: 1; }
.chat-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.chat-badges { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 6px; }

.badge {
  font-size: 11.5px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--card-2);
  color: var(--muted);
}
.badge.del { color: var(--danger); background: rgba(255, 90, 90, 0.12); }
.badge.ed { color: var(--warn); background: rgba(242, 176, 58, 0.12); }
.badge.one { color: var(--eye); background: rgba(154, 123, 255, 0.14); }
.badge.md { color: var(--muted); }

.chatview-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 2px 12px;
}
.back {
  background: var(--card);
  border: none;
  color: var(--text);
  width: 34px;
  height: 34px;
  border-radius: 10px;
  font-size: 18px;
  flex: none;
}

.thread { display: flex; flex-direction: column; gap: 10px; padding-bottom: 20px; }

.msg {
  max-width: 82%;
  padding: 9px 12px;
  border-radius: 14px;
  background: var(--card);
  border: 1px solid transparent;
  position: relative;
  align-self: flex-start;
}
.msg.out { align-self: flex-end; background: var(--accent-soft); }
.msg.deleted { border-color: rgba(255, 90, 90, 0.5); }
.msg-meta { display: flex; gap: 8px; align-items: baseline; margin-bottom: 3px; }
.msg-from { font-size: 12.5px; font-weight: 700; color: var(--accent); }
.msg.out .msg-from { color: var(--warn); }
.msg-time { font-size: 11px; color: var(--muted); }
.msg-text { white-space: pre-wrap; word-break: break-word; }
.msg-chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.chip {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
}
.chip.del { color: var(--danger); background: rgba(255, 90, 90, 0.14); }
.chip.ed { color: var(--warn); background: rgba(242, 176, 58, 0.14); }
.chip.one { color: var(--eye); background: rgba(154, 123, 255, 0.16); }

.media { margin-top: 6px; border-radius: 10px; overflow: hidden; }
.media img, .media video { display: block; width: 100%; max-width: 260px; border-radius: 10px; }
.media.round img, .media.round video { width: 200px; height: 200px; object-fit: cover; border-radius: 50%; }
.media audio { width: 240px; max-width: 100%; }
.file-link {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  padding: 8px 12px;
  background: var(--card-2);
  border-radius: 10px;
  color: var(--text);
  text-decoration: none;
  font-size: 13px;
  margin-top: 6px;
}

.edits {
  margin-top: 8px;
  padding: 8px 10px;
  background: var(--card-2);
  border-radius: 10px;
  font-size: 13px;
}
.edits .row { padding: 3px 0; }
.edits .k { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; }
.edits del { color: var(--muted); text-decoration: line-through; }

.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.tile {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
}
.tile .n { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; }
.tile .l { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.tile.accent .n { color: var(--accent); }
.tile.del .n { color: var(--danger); }
.tile.ed .n { color: var(--warn); }
.tile.one .n { color: var(--eye); }

.panel {
  margin-top: 14px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
}
.panel h3 { margin: 0 0 12px; font-size: 14px; }
.chart { display: flex; align-items: flex-end; gap: 3px; height: 96px; }
.bar { flex: 1; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 2px; opacity: 0.85; }

.event {
  display: flex;
  gap: 10px;
  padding: 11px 12px;
  background: var(--card);
  border-radius: var(--radius);
}
.event .ic { font-size: 18px; flex: none; }
.event .body { min-width: 0; flex: 1; }
.event .t { font-size: 12px; color: var(--muted); margin-top: 3px; }
.event .who { font-weight: 600; }

.banner {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: 14px;
  background: var(--accent);
  color: #fff;
  padding: 12px 14px;
  border-radius: 12px;
  font-size: 13.5px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.skeleton { animation: pulse 1.2s infinite; }
@keyframes pulse { 0%,100% { opacity: 0.5; } 50% { opacity: 0.9; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } }
