:root {
  --bg: #0e1621;
  --header: #17212b;
  --header-text: #ffffff;
  --sub: #8b9aab;
  --in: #182533;
  --out: #2b5278;
  --accent: #6ab3f3;
  --text: #ffffff;
  --meta: #7ea0be;
  --meta-out: #86b5d6;
  --composer: #17212b;
  --line: #101921;
  --cell: #17212b;
  --danger: #e53935;
  --radius: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overflow: hidden; }
#app, .screen { height: 100%; display: flex; flex-direction: column; }
.hidden { display: none !important; }

.chat-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 2px;
  min-height: 56px;
  padding: calc(6px + var(--safe-top)) 6px 6px 2px;
  background: var(--header);
  color: var(--header-text);
  box-shadow: 0 1px 0 rgba(0,0,0,.35);
  z-index: 5;
}
.settings-header { padding-right: 14px; }
.icon-btn {
  width: 42px; height: 42px; border: 0; background: transparent; color: #fff;
  border-radius: 50%; display: grid; place-items: center; cursor: pointer;
}
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:active { background: rgba(255,255,255,.08); }
.peer {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px;
  border: 0; background: transparent; color: inherit; text-align: left; padding: 4px 6px; border-radius: 10px;
}
.peer:active { background: rgba(255,255,255,.05); }
.avatar {
  width: 42px; height: 42px; border-radius: 50%; flex: 0 0 auto;
  background: #3390ec center/cover no-repeat; display: grid; place-items: center;
  font-weight: 650; font-size: 18px; color: #fff; overflow: hidden;
}
.peer-text { min-width: 0; }
.peer-text.grow { flex: 1; }
.peer-title { display: flex; align-items: center; gap: 4px; font-size: 16px; font-weight: 650; line-height: 1.15; }
.peer-title span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.verified { width: 16px; height: 16px; display: inline-flex; flex: 0 0 auto; }
.verified svg { width: 16px; height: 16px; }
.peer-sub { color: var(--sub); font-size: 13px; margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.chat-body {
  flex: 1; min-height: 0; overflow: auto;
  background-color: var(--bg);
  background-image: url("/assets/wallpaper.svg");
  background-size: 240px 240px;
  overscroll-behavior: contain;
}
.messages { padding: 8px 8px 12px; display: flex; flex-direction: column; gap: 3px; }

.date-pill {
  align-self: center; margin: 8px 0 10px; background: rgba(24, 37, 51, .78);
  color: #dbe6f0; font-size: 13px; font-weight: 500; padding: 4px 12px; border-radius: 12px;
}

.row { display: flex; width: 100%; }
.row.out { justify-content: flex-end; }
.bubble {
  max-width: min(86%, 420px); padding: 6px 8px 4px 9px;
  background: var(--in); border-radius: 12px; position: relative;
  box-shadow: 0 1px 1px rgba(0,0,0,.18);
}
.row.out .bubble { background: var(--out); }
.author { color: var(--accent); font-size: 14px; font-weight: 650; margin-bottom: 2px; }
.msg-photo { display: block; width: 100%; max-height: 280px; object-fit: cover; border-radius: 10px; margin-bottom: 4px; }
.msg-text { font-size: 16px; line-height: 1.35; white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; }
.msg-meta {
  float: right; position: relative; top: 4px; margin: 0 0 -2px 8px;
  display: inline-flex; align-items: center; gap: 4px;
  color: var(--meta); font-size: 12px; line-height: 1; user-select: none;
}
.row.out .msg-meta { color: var(--meta-out); }
.edited { opacity: .9; }
.views { display: inline-flex; align-items: center; gap: 3px; }
.views svg, .checks svg { width: 14px; height: 14px; display: block; }
.checks { color: #70c0f0; }

.tg-emoji { display: inline-block; width: 20px; height: 20px; vertical-align: -4px; }
.tg-emoji img, .tg-emoji video, .tg-emoji canvas, .tg-emoji svg { width: 20px; height: 20px; display: block; }
.tg-emoji.only { width: 34px; height: 34px; vertical-align: -8px; }
.tg-emoji.only img, .tg-emoji.only video, .tg-emoji.only canvas, .tg-emoji.only svg { width: 34px; height: 34px; }
.emoji-fallback { font-size: 18px; line-height: 1; }

.composer {
  flex: 0 0 auto; display: flex; align-items: center; gap: 2px;
  min-height: 48px; padding: 4px 4px calc(6px + var(--safe-bottom));
  background: var(--composer); border-top: 1px solid rgba(0,0,0,.25);
}
.composer-input {
  flex: 1; color: #6d7f8f; font-size: 16px; padding: 8px 4px;
}
.composer-icon { color: #6d7f8f; }
.composer-icon.send { color: var(--accent); }

.settings-scroll { flex: 1; overflow: auto; background: #0e1621; padding: 12px 12px calc(24px + var(--safe-bottom)); }
.group { background: var(--cell); border-radius: 14px; margin-bottom: 14px; overflow: hidden; }
.group h3 {
  margin: 0; padding: 14px 14px 6px; font-size: 13px; font-weight: 650;
  color: var(--accent); text-transform: uppercase; letter-spacing: .04em;
}
.field { display: flex; flex-direction: column; gap: 6px; padding: 10px 14px 12px; }
.field + .field { border-top: 1px solid rgba(255,255,255,.04); }
.field label { font-size: 13px; color: var(--sub); }
.field input, .field select, .field textarea {
  width: 100%; background: #111b24; color: #fff; border: 1px solid #243140;
  border-radius: 10px; padding: 10px 12px; font-size: 16px; outline: none;
}
.field textarea { min-height: 72px; resize: vertical; font-family: inherit; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: #3d6a93; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.check {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px; font-size: 16px;
}
.check input { width: 18px; height: 18px; accent-color: #3390ec; }
.avatar-row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; }
.avatar-row .avatar { width: 56px; height: 56px; font-size: 22px; }
.avatar-row input[type="file"] { font-size: 13px; color: var(--sub); }
.msg-card { padding: 8px 6px 12px; border-top: 1px solid rgba(255,255,255,.05); }
.msg-card:first-of-type { border-top: 0; }
.btn-row { display: flex; gap: 8px; padding: 8px 14px 14px; }
.btn {
  border: 0; border-radius: 10px; padding: 11px 14px; font-size: 15px; font-weight: 650;
  cursor: pointer; color: #fff; background: #2b5278;
}
.btn.ghost { background: #223140; color: #c9d6e2; }
.btn.danger { background: #3a2430; color: #ff8a80; }
.btn:disabled { opacity: .55; cursor: default; }
.hint { padding: 0 14px 14px; color: var(--sub); font-size: 13px; line-height: 1.4; }
.link-box {
  margin: 0 14px 14px; padding: 10px 12px; background: #111b24; border-radius: 10px;
  font-size: 13px; color: var(--accent); word-break: break-all;
}

.menu-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 20;
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  width: 100%; max-width: 520px; background: #17212b; border-radius: 16px 16px 0 0;
  padding: 8px 8px calc(10px + var(--safe-bottom));
}
.sheet button {
  width: 100%; background: transparent; border: 0; color: #fff; text-align: left;
  padding: 14px 16px; font-size: 16px; border-radius: 10px; cursor: pointer;
}
.sheet button:active { background: rgba(255,255,255,.06); }

@media (min-width: 640px) {
  body { display: grid; place-items: center; }
  #app { width: 420px; height: 100%; max-height: 860px; border-radius: 0; overflow: hidden; box-shadow: 0 0 0 1px #101820; }
}
