:root {
  color-scheme: dark;
  --bg: #07111f;
  --bg-soft: #0b1627;
  --panel: rgba(10, 23, 39, 0.82);
  --panel-2: rgba(17, 33, 56, 0.86);
  --border: rgba(120, 167, 255, 0.13);
  --border-strong: rgba(120, 167, 255, 0.2);
  --text: #eef4ff;
  --muted: #8fa6c8;
  --accent: #4ca7ff;
  --accent-2: #76f3d5;
  --accent-glow: rgba(76, 167, 255, 0.24);
  --incoming: #101c31;
  --outgoing: linear-gradient(180deg, #163f67, #0f3357);
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: 'Inter', Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top right, rgba(76, 167, 255, 0.18), transparent 28%),
    radial-gradient(circle at bottom left, rgba(118, 243, 213, 0.12), transparent 24%),
    linear-gradient(180deg, #06101b 0%, #091426 100%);
}
a { color: #8ec9ff; text-decoration: none; }
a:hover { color: #d6ebff; }
main { padding: 28px; }
.site-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 28px; position: sticky; top: 0; z-index: 10;
  backdrop-filter: blur(18px);
  background: rgba(4, 10, 19, 0.56);
  border-bottom: 1px solid var(--border);
}
.brand-lockup { display: flex; align-items: center; gap: 14px; color: var(--text); }
.brand-lockup small { display: block; color: var(--muted); margin-top: 2px; }
.brand-mark, .avatar-sim.brand, .empty-state-mark, .rail-brand {
  display: inline-flex; align-items: center; justify-content: center;
  width: 42px; height: 42px; border-radius: 14px;
  background: linear-gradient(180deg, #64b8ff, #2f71ff);
  color: white; font-weight: 800; box-shadow: 0 10px 30px rgba(76, 167, 255, 0.35);
}
.site-nav { display: flex; gap: 18px; align-items: center; }
.eyebrow {
  text-transform: uppercase; letter-spacing: 0.16em; font-size: 11px; color: var(--accent-2);
  margin-bottom: 10px;
}
.glass-card, .glass-panel, .auth-card, .panel, .subtle-card {
  background: var(--panel);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  backdrop-filter: blur(24px);
}
.hero-shell, .auth-shell {
  min-height: calc(100vh - 120px);
  display: grid; grid-template-columns: 1.05fr .95fr; gap: 28px; align-items: center;
}
.hero-copy, .hero-preview, .auth-copy, .auth-card { border-radius: 28px; padding: 36px; }
.hero-copy h1, .auth-copy h1 { font-size: clamp(2.4rem, 5vw, 4.5rem); line-height: 1.02; margin: 0 0 16px; }
.hero-copy h1 span { color: #9dd2ff; }
.hero-lead, .auth-copy p { color: var(--muted); font-size: 1.05rem; line-height: 1.7; max-width: 62ch; }
.hero-actions { display: flex; gap: 14px; margin: 26px 0; }
.primary-btn, .secondary-btn, .icon-btn, button {
  appearance: none; border: 0; color: var(--text); cursor: pointer; transition: .18s ease;
}
.primary-btn {
  background: linear-gradient(180deg, #58b4ff, #266bff);
  padding: 14px 22px; border-radius: 16px; box-shadow: 0 12px 28px var(--accent-glow); font-weight: 700;
}
.primary-btn:hover { transform: translateY(-1px); filter: brightness(1.05); }
.secondary-btn {
  background: rgba(255,255,255,0.04); border: 1px solid var(--border-strong);
  padding: 14px 22px; border-radius: 16px; font-weight: 600;
}
.secondary-btn:hover, .icon-btn:hover { background: rgba(255,255,255,0.08); }
.hero-pills { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; }
.hero-pills span {
  padding: 10px 14px; border-radius: 999px; background: rgba(255,255,255,0.04);
  border: 1px solid var(--border); color: #cfe5ff; font-size: 13px;
}
.preview-top, .chat-list-top, .workspace-top, .chat-row-top, .chat-row-bottom, .search-box, .workspace-actions, .feature-list { display: flex; }
.preview-top, .chat-list-top, .workspace-top { justify-content: space-between; align-items: center; }
.preview-chat-list { display: grid; gap: 12px; margin: 22px 0; }
.preview-chat, .tg-chat-item {
  display: flex; gap: 14px; align-items: center; border-radius: 18px; padding: 14px;
  border: 1px solid transparent; background: rgba(255,255,255,0.03);
}
.preview-chat.active, .tg-chat-item.active, .tg-chat-item:hover {
  background: rgba(76, 167, 255, 0.13); border-color: rgba(76, 167, 255, 0.2);
}
.preview-chat p, .chat-row-bottom, .muted { color: var(--muted); }
.preview-message-box {
  padding: 20px; border-radius: 24px; background: linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0.04));
  border: 1px solid var(--border);
}
.bubble {
  width: fit-content; max-width: 85%; padding: 12px 16px; border-radius: 18px; margin-bottom: 12px;
  background: var(--incoming); color: #dcecff;
}
.bubble.outgoing { margin-left: auto; background: var(--outgoing); }
.status-dot { width: 12px; height: 12px; border-radius: 50%; background: #7affc1; box-shadow: 0 0 18px rgba(122,255,193,.8); }
.auth-shell { max-width: 1280px; margin: 0 auto; }
.auth-card-premium { max-width: 520px; justify-self: end; width: 100%; }
.auth-form { display: grid; gap: 12px; }
label { display: block; color: #d5e7ff; font-size: 14px; font-weight: 600; margin-top: 4px; }
input, textarea {
  width: 100%; border: 1px solid var(--border); background: rgba(10, 20, 34, 0.88); color: var(--text);
  border-radius: 16px; padding: 14px 16px; font: inherit; outline: none;
}
input:focus, textarea:focus { border-color: rgba(76, 167, 255, 0.48); box-shadow: 0 0 0 4px rgba(76, 167, 255, 0.1); }
.feature-list { flex-direction: column; gap: 12px; padding-left: 18px; color: #dbe9ff; }
.app-shell {
  min-height: 100vh; padding: 18px; display: grid; gap: 16px;
  grid-template-columns: 74px 360px minmax(0, 1fr);
}
.left-rail, .chat-list-panel, .chat-workspace { border-radius: 28px; }
.left-rail {
  display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 14px 10px;
}
.rail-btn, .icon-btn {
  width: 44px; height: 44px; border-radius: 14px; display: inline-flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,0.04); border: 1px solid var(--border); font-size: 18px;
}
.rail-btn.active { background: linear-gradient(180deg, #132a47, #0d1d35); border-color: rgba(76, 167, 255, 0.22); }
.rail-logout { margin-top: auto; }
.chat-list-panel { padding: 18px; display: flex; flex-direction: column; }
.search-box { gap: 10px; margin: 16px 0; }
.search-box input { flex: 1; }
.search-results { max-height: 220px; overflow: auto; display: grid; gap: 8px; }
.list-section-title { font-size: 12px; text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted); margin: 8px 0 12px; }
.telegram-list { display: grid; gap: 10px; overflow: auto; padding-right: 2px; }
.tg-chat-item { width: 100%; text-align: left; cursor: pointer; }
.chat-avatar, .avatar-sim {
  width: 48px; height: 48px; border-radius: 50%; background: linear-gradient(180deg, #173250, #0b1f36);
  display: inline-flex; align-items: center; justify-content: center; color: #cfe5ff; font-weight: 700;
}
.avatar-sim.large { width: 52px; height: 52px; border-radius: 18px; }
.chat-meta { min-width: 0; flex: 1; }
.chat-row-top strong, .workspace-title h2, .chat-list-top h2 { font-size: 1rem; margin: 0; }
.chat-row-top { justify-content: space-between; gap: 8px; }
.chat-row-bottom { font-size: 13px; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.group-builder { margin-top: 16px; padding: 16px; border-radius: 22px; display: grid; gap: 10px; }
.chat-workspace {
  padding: 14px; display: grid; grid-template-rows: auto 1fr auto; min-height: calc(100vh - 36px);
}
.workspace-top { padding: 6px 10px 18px; border-bottom: 1px solid var(--border); }
.workspace-title { display: flex; gap: 14px; align-items: center; }
.workspace-title p { margin: 4px 0 0; color: var(--muted); }
.messages {
  min-height: 0; overflow-y: auto; padding: 26px 16px; display: flex; flex-direction: column; gap: 14px;
  background:
    radial-gradient(circle at top, rgba(76, 167, 255, 0.08), transparent 30%),
    linear-gradient(180deg, rgba(255,255,255,0.015), rgba(255,255,255,0.01));
  border-radius: 22px;
}
.messages.welcome-empty { justify-content: center; align-items: center; }
.empty-state { text-align: center; max-width: 460px; color: var(--muted); }
.empty-state h3 { color: var(--text); font-size: 1.6rem; margin: 14px 0 10px; }
.msg {
  max-width: min(74%, 760px); padding: 12px 14px; border-radius: 22px; background: var(--incoming);
  border: 1px solid rgba(255,255,255,0.04); align-self: flex-start;
}
.msg.self {
  align-self: flex-end; background: var(--outgoing); border-bottom-right-radius: 10px;
}
.msg:not(.self) { border-bottom-left-radius: 10px; }
.msg-head { display: flex; justify-content: space-between; gap: 14px; align-items: center; margin-bottom: 6px; }
.msg-content { white-space: pre-wrap; line-height: 1.55; }
.msg-attachment { margin-top: 10px; }
.badge { display: inline-flex; align-items: center; padding: 6px 10px; border-radius: 999px; background: rgba(255,255,255,0.08); margin-right: 6px; font-size: 12px; }
.message-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.message-actions button {
  width: auto; padding: 7px 10px; border-radius: 12px; background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.05);
}
.composer-telegram {
  display: grid; grid-template-columns: auto 1fr auto auto; gap: 10px; align-items: end; margin-top: 14px;
  background: rgba(8, 16, 27, 0.78); border: 1px solid var(--border); border-radius: 22px; padding: 12px;
}
.file-chip {
  width: 46px; height: 46px; border-radius: 16px; display: inline-flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,0.04); border: 1px solid var(--border); cursor: pointer;
}
#messageInput { resize: none; max-height: 160px; min-height: 48px; }
.send-btn { min-width: 128px; }
@media (max-width: 1200px) {
  .hero-shell, .auth-shell { grid-template-columns: 1fr; }
  .auth-card-premium { justify-self: stretch; }
}
@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; }
  .left-rail { display: none; }
  .chat-list-panel { max-height: 44vh; }
  .chat-workspace { min-height: auto; }
  .msg { max-width: 92%; }
}
@media (max-width: 640px) {
  main { padding: 18px; }
  .site-header { padding: 14px 18px; }
  .site-nav { display: none; }
  .hero-copy, .hero-preview, .auth-copy, .auth-card { padding: 24px; border-radius: 24px; }
  .composer-telegram { grid-template-columns: auto 1fr auto; }
  .send-btn { grid-column: 1 / -1; width: 100%; }
}


/* v2.0.3 UI refresh */

.tg-chat-item, .rail-btn, .icon-btn, .primary-btn, .secondary-btn, .upload-btn, .file-chip, .chat-item, .msg button {
  transition: transform .22s ease, box-shadow .22s ease, background-color .22s ease, border-color .22s ease, opacity .22s ease;
}
.tg-chat-item:hover, .rail-btn:hover, .icon-btn:hover, .primary-btn:hover, .secondary-btn:hover, .upload-btn:hover, .file-chip:hover {
  transform: translateY(-2px) scale(1.01);
  box-shadow: 0 18px 36px rgba(2, 10, 30, 0.32);
}
.rail-btn:hover, .icon-btn:hover { border-color: var(--border-strong); }
.messages.center-empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100%;
}
.messages.center-empty-state .empty-state {
  margin: 0 auto;
  text-align: center;
  max-width: 420px;
}
.empty-state h3 { font-size: 2rem; margin-bottom: 10px; }
.empty-state p { color: var(--muted); line-height: 1.6; }
.profile-panel {
  width: 390px;
  border-radius: 28px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  transform: translateX(28px);
  opacity: 0;
  pointer-events: none;
}
.profile-panel.open {
  transform: translateX(0);
  opacity: 1;
  pointer-events: auto;
}
.profile-top, .profile-status-line, .profile-avatar-wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.profile-card, .profile-form {
  background: rgba(255,255,255,0.02);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 18px;
}
.profile-form {
  display: grid;
  gap: 10px;
}
.profile-form input, .profile-form textarea, .group-builder input, .search-box input, #messageInput {
  background: rgba(8, 17, 31, 0.82);
  border: 1px solid rgba(126, 174, 255, 0.14);
  color: var(--text);
  border-radius: 16px;
  padding: 14px 16px;
  outline: none;
}
.profile-form input:focus, .profile-form textarea:focus, .group-builder input:focus, .search-box input:focus, #messageInput:focus {
  border-color: rgba(118, 243, 213, 0.42);
  box-shadow: 0 0 0 4px rgba(76, 167, 255, 0.12);
}
.profile-avatar, .profile-avatar-wrap .profile-avatar {
  width: 96px;
  height: 96px;
  border-radius: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #64b8ff, #2f71ff);
  font-size: 2rem;
  font-weight: 800;
  box-shadow: 0 12px 28px rgba(76, 167, 255, 0.25);
}
.image-avatar {
  object-fit: cover;
  overflow: hidden;
}
.profile-status-line {
  justify-content: flex-start;
  gap: 10px;
  color: #d8eaff;
}
.status-dot.live {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: #4af29f;
  box-shadow: 0 0 0 6px rgba(74, 242, 159, 0.12);
}
.profile-meta-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 8px 0 10px;
}
.meta-chip {
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px;
}
.meta-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
}
.upload-btn {
  display: inline-flex;
  justify-content: center;
  align-items: center;
}
.workspace-actions .icon-btn, .micro-btn {
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
}
.chat-row-bottom {
  color: var(--muted);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.chat-avatar.image-avatar, #chatAvatar.image-avatar {
  border-radius: 18px;
}
.chat-workspace {
  display: grid;
  grid-template-rows: auto 1fr auto;
}
.messages {
  min-height: 0;
}
.search-user-card .message-actions button, .msg button {
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 12px;
  padding: 10px 14px;
}
.msg button:hover {
  transform: translateY(-1px);
  border-color: var(--border-strong);
}
@media (max-width: 1440px) {
  .profile-panel {
    position: fixed;
    top: 24px;
    right: 24px;
    bottom: 24px;
    z-index: 40;
  }
}
@media (max-width: 1120px) {
  .app-shell {
    grid-template-columns: 80px 320px 1fr;
  }
  .profile-panel {
    width: min(92vw, 420px);
  }
}


/* v2.0.4 layout polish */
.chat-page { overflow: hidden; }
.app-shell {
  position: relative;
  min-height: 100vh;
  height: 100vh;
  grid-template-columns: 74px 360px minmax(0, 1fr);
  align-items: stretch;
}
.chat-list-panel, .chat-workspace {
  min-height: 0;
  overflow: hidden;
}
.chat-list-panel { gap: 12px; }
.telegram-list { min-height: 0; flex: 1; padding-right: 4px; }
.chat-list-top h2 { margin: 0; }
.chat-list-top .icon-btn-labeled,
.workspace-actions .header-action-btn,
.search-submit {
  width: 48px;
  height: 48px;
  border-radius: 16px;
}
.search-box {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 48px;
  align-items: stretch;
}
.search-box input,
.search-submit {
  height: 48px;
}
.search-submit { font-size: 17px; }
.chat-avatar-wrap {
  position: relative;
  flex: 0 0 auto;
}
.presence-pill {
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 12px;
  height: 12px;
  border-radius: 999px;
  border: 2px solid rgba(10, 23, 39, 0.95);
  box-shadow: 0 0 0 4px rgba(7, 17, 31, 0.18);
}
.presence-pill.online { background: #3ae27a; }
.presence-pill.offline { background: #f45d6b; }
.chat-row-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.chat-row-top strong {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-row-bottom {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tg-chat-item {
  align-items: center;
  min-height: 72px;
}
.chat-workspace {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  padding: 18px;
}
.workspace-top {
  min-height: 82px;
}
.workspace-actions { gap: 10px; }
.header-action-btn,
.icon-btn-labeled {
  background: linear-gradient(180deg, rgba(20, 39, 67, 0.96), rgba(9, 24, 42, 0.96));
  border: 1px solid rgba(120, 167, 255, 0.18);
}
.header-action-btn span,
.icon-btn-labeled span {
  font-size: 18px;
}
.messages {
  min-height: 0;
  height: 100%;
  justify-content: flex-start;
}
.messages.center-empty-state {
  justify-content: center;
}
.composer-telegram {
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: end;
}
.composer-main {
  min-width: 0;
}
.composer-actions {
  display: flex;
  align-items: end;
  gap: 10px;
}
#messageInput {
  width: 100%;
}
.sticker-wrap {
  position: relative;
}
.sticker-menu {
  position: absolute;
  right: 0;
  bottom: calc(100% + 12px);
  width: 248px;
  padding: 12px;
  border-radius: 20px;
  background: rgba(7, 18, 33, 0.96);
  border: 1px solid rgba(120, 167, 255, 0.14);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.36);
  display: none;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  z-index: 40;
}
.sticker-menu.open {
  display: grid;
}
.sticker-chip {
  width: 48px;
  height: 48px;
  border-radius: 16px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(120, 167, 255, 0.12);
  font-size: 22px;
}
.sticker-chip:hover {
  transform: translateY(-2px);
  background: rgba(76, 167, 255, 0.14);
}
.profile-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 11, 19, 0.42);
  backdrop-filter: blur(8px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .24s ease;
  z-index: 25;
}
.profile-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}
.profile-panel {
  position: fixed;
  top: 20px;
  right: 20px;
  bottom: 20px;
  width: min(420px, calc(100vw - 32px));
  max-height: calc(100vh - 40px);
  overflow: auto;
  z-index: 30;
  transform: translateX(26px) scale(.98);
}
.profile-panel.open {
  transform: translateX(0) scale(1);
}
.profile-avatar-wrap {
  justify-content: center;
}
.profile-card {
  display: grid;
  gap: 14px;
}
.profile-status-line {
  justify-content: flex-start;
  gap: 10px;
}
.toast-stack {
  position: fixed;
  right: 24px;
  bottom: 24px;
  display: grid;
  gap: 12px;
  z-index: 60;
}
.toast {
  min-width: 280px;
  max-width: 360px;
  padding: 16px 18px;
  border-radius: 18px;
  color: var(--text);
  background: rgba(10, 23, 39, 0.92);
  border: 1px solid rgba(120, 167, 255, 0.16);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
  transform: translateY(14px);
  opacity: 0;
  transition: transform .24s ease, opacity .24s ease;
}
.toast.show {
  transform: translateY(0);
  opacity: 1;
}
.toast.success {
  border-color: rgba(68, 224, 133, 0.3);
  box-shadow: 0 18px 40px rgba(14, 55, 34, 0.28);
}
.toast.error {
  border-color: rgba(244, 93, 107, 0.28);
}
.toast-title {
  font-weight: 700;
  margin-bottom: 4px;
}
.toast-body {
  color: var(--muted);
  line-height: 1.5;
}
.rail-btn, .icon-btn, .primary-btn, .secondary-btn, .upload-btn, .tg-chat-item, .sticker-chip, .file-chip {
  transition: transform .18s ease, box-shadow .18s ease, background .18s ease, border-color .18s ease, opacity .18s ease;
}
.rail-btn:hover, .icon-btn:hover, .primary-btn:hover, .secondary-btn:hover, .upload-btn:hover, .tg-chat-item:hover, .sticker-chip:hover, .file-chip:hover {
  transform: translateY(-2px);
  box-shadow: 0 18px 34px rgba(3, 13, 32, 0.3);
}
@media (max-width: 980px) {
  .chat-page { overflow: auto; }
  .app-shell {
    height: auto;
    min-height: 100vh;
  }
  .chat-list-panel, .chat-workspace {
    min-height: 420px;
  }
  .profile-panel {
    top: 12px;
    right: 12px;
    left: 12px;
    width: auto;
    bottom: 12px;
    max-height: calc(100vh - 24px);
  }
}
