:root {
  --bg: var(--tg-theme-bg-color, #0e1621);
  --bg-sec: var(--tg-theme-secondary-bg-color, #17212b);
  --text: var(--tg-theme-text-color, #f5f7fa);
  --hint: var(--tg-theme-hint-color, #8b9aa7);
  --link: var(--tg-theme-link-color, #6ab3f3);
  --btn: var(--tg-theme-button-color, #5288c1);
  --btn-text: var(--tg-theme-button-text-color, #fff);
  --out: #3e6fa3;
  --in: #182533;
  --sep: rgba(255, 255, 255, 0.055);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
body { overflow: hidden; }

#app { display: flex; flex-direction: column; height: 100%; }

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(10px + var(--safe-top)) 12px 10px;
  background: color-mix(in srgb, var(--bg-sec) 92%, black);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--sep);
  min-height: 56px;
  flex-shrink: 0;
  z-index: 5;
}
.topbar__text { min-width: 0; flex: 1; }
.topbar__title {
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar__sub {
  color: var(--hint);
  font-size: 12px;
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  width: 38px; height: 38px; border: 0; border-radius: 12px;
  background: transparent; color: var(--link);
  display: grid; place-items: center; cursor: pointer; flex-shrink: 0;
}
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:active { background: rgba(255,255,255,0.06); }
.hidden { display: none !important; }

.header-ava {
  width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center;
  font-weight: 700; font-size: 14px; color: #fff; flex-shrink: 0;
}
.pill {
  flex-shrink: 0;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--hint);
  border: 1px solid var(--sep);
  padding: 4px 8px;
  border-radius: 999px;
}

#views { flex: 1; position: relative; min-height: 0; }
.view {
  display: none;
  position: absolute; inset: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.view.active { display: block; animation: fade .22s ease; }
#view-messages.active { display: flex; flex-direction: column; }
@keyframes fade {
  from { opacity: .45; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.row {
  display: flex; gap: 12px; align-items: center;
  padding: 11px 14px;
  border-bottom: 1px solid var(--sep);
  cursor: pointer;
  position: relative;
}
.row:active { background: rgba(255,255,255,0.045); }
.row__chev {
  color: var(--hint); opacity: .45; font-size: 18px; flex-shrink: 0;
}

.avatar {
  width: 52px; height: 52px; border-radius: 50%;
  display: grid; place-items: center;
  font-weight: 700; font-size: 20px; color: #fff; flex-shrink: 0;
  position: relative;
  box-shadow: inset 0 -6px 12px rgba(0,0,0,.18);
}
.avatar.offline { filter: grayscale(.35); opacity: .72; }
.avatar .ring {
  position: absolute; right: 0; bottom: 1px;
  width: 12px; height: 12px; border-radius: 50%;
  background: #31c452; border: 2px solid var(--bg);
}
.avatar .ring.off { background: #6b7680; }

.row__body { min-width: 0; flex: 1; }
.row__top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.row__title {
  font-weight: 650; font-size: 16px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.row__time { color: var(--hint); font-size: 12px; flex-shrink: 0; }
.row__bot { display: flex; justify-content: space-between; gap: 8px; margin-top: 3px; align-items: center; }
.row__preview {
  color: var(--hint); font-size: 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.mgr-stats {
  margin-top: 5px;
  font-size: 12.5px;
  color: var(--hint);
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
}
.mgr-stats b { color: var(--text); font-weight: 700; }
.mgr-stats .ok b { color: #7dcea0; }
.mgr-stats .dot { opacity: .45; }
.mgr-stats.pending { opacity: .7; }
.mgr-stats.off { opacity: .55; }
.stats-bar {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 10px 12px 6px;
}
.stats-bar__cell {
  background: rgba(255,255,255,.04);
  border: 1px solid var(--sep);
  border-radius: 14px;
  padding: 12px 12px 10px;
}
.stats-bar__num {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.1;
}
.stats-bar__num.accent { color: #7dcea0; }
.stats-bar__lbl {
  margin-top: 4px;
  color: var(--hint);
  font-size: 12px;
}
.chip {
  font-size: 10px; font-weight: 700; letter-spacing: .04em;
  text-transform: uppercase; color: var(--hint);
  background: rgba(255,255,255,.05);
  padding: 2px 6px; border-radius: 6px; margin-right: 6px;
}
.badge {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px;
  background: var(--btn); color: var(--btn-text); font-size: 12px; font-weight: 700;
  display: grid; place-items: center; flex-shrink: 0;
}

.empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; min-height: 46%; padding: 40px 24px;
  text-align: center; color: var(--hint); font-size: 15px;
}
.empty b { color: var(--text); font-size: 17px; }
.empty .ico {
  width: 64px; height: 64px; border-radius: 20px;
  display: grid; place-items: center;
  background: rgba(255,255,255,.05); font-size: 28px; margin-bottom: 6px;
}

.loader, .js-more, .js-older {
  padding: 18px 16px; text-align: center; color: var(--hint); font-size: 13px;
}
.sk {
  display: flex; gap: 12px; align-items: center; padding: 12px 14px;
}
.sk-ava, .sk-line {
  background: linear-gradient(90deg, rgba(255,255,255,.04), rgba(255,255,255,.09), rgba(255,255,255,.04));
  background-size: 200% 100%;
  animation: shine 1.1s ease infinite;
}
.sk-ava { width: 52px; height: 52px; border-radius: 50%; flex-shrink: 0; }
.sk-col { flex: 1; display: flex; flex-direction: column; gap: 8px; }
.sk-line { height: 10px; border-radius: 6px; }
.sk-line.w60 { width: 60%; } .sk-line.w80 { width: 80%; }
@keyframes shine { to { background-position: -200% 0; } }

.msgs {
  flex: 1;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 12px 10px 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background-color: var(--bg);
  background-image:
    radial-gradient(ellipse 80% 50% at 10% -10%, rgba(82,136,193,.16), transparent 55%),
    radial-gradient(circle at 20px 20px, rgba(255,255,255,.035) 1.5px, transparent 2px);
  background-size: auto, 28px 28px;
}
.day {
  align-self: center;
  margin: 10px 0 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(0,0,0,.28);
  color: #dbe6ef;
  font-size: 12px; font-weight: 600;
}
.bubble {
  min-width: 0;
  max-width: calc(100% - 8px);
  padding: 5px 9px 6px 10px;
  border-radius: 14px;
  font-size: 15.5px;
  line-height: 1.4;
  box-shadow: 0 1px 1px rgba(0,0,0,.12);
}
.bubble.in {
  align-self: flex-start;
  background: var(--in);
  border-bottom-left-radius: 5px;
}
.bubble.out {
  align-self: flex-end;
  background: var(--out);
  border-bottom-right-radius: 5px;
}
.bubble__from {
  display: block;
  font-size: 12.5px; font-weight: 700;
  color: #79c0ff; margin: 0 0 2px;
  line-height: 1.25;
}
.bubble__text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.bubble::after {
  content: "";
  display: block;
  clear: both;
}
.bubble__meta {
  float: right;
  margin: 4px 0 0 8px;
  color: rgba(255,255,255,.52);
  font-size: 11px;
  line-height: 1.2;
  white-space: nowrap;
}
.media-tag {
  display: block;
  font-size: 12px; color: rgba(255,255,255,.7);
  line-height: 1.25;
  margin-bottom: 2px;
}

.toast {
  position: fixed; left: 50%; bottom: calc(18px + var(--safe-bot));
  transform: translateX(-50%);
  background: rgba(18, 24, 32, 0.94);
  color: #fff;
  padding: 10px 14px; border-radius: 14px; font-size: 13px;
  max-width: 90%; z-index: 20;
  box-shadow: var(--shadow);
  animation: fade .2s ease;
}
