:root {
  --bg: #eef4fb;
  --panel: #ffffff;
  --panel-soft: #f6f9fd;
  --panel-strong: #f9fbff;
  --line: rgba(20, 44, 74, 0.10);
  --text: #162536;
  --muted: #6e8196;
  --accent: #4aa7ff;
  --accent-2: #2e8cff;
  --ok: #1aa47a;
  --warn: #d8902f;
  --danger: #dc5f6f;
  color: var(--text);
  font-family: "Avenir Next", "SF Pro Display", "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(74, 167, 255, 0.18), transparent 24%),
    radial-gradient(circle at bottom right, rgba(96, 199, 255, 0.14), transparent 22%),
    linear-gradient(180deg, #f9fbff, var(--bg));
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(74, 167, 255, 0.12), transparent 24%),
    linear-gradient(180deg, #fbfdff, var(--bg));
}

button,
input,
textarea {
  font: inherit;
}

.messenger-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 390px 1fr;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px;
  border-right: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(252, 254, 255, 0.96), rgba(242, 247, 252, 0.98));
}

.chat-stage {
  min-width: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background:
    radial-gradient(circle at top right, rgba(79, 176, 255, 0.12), transparent 24%),
    linear-gradient(180deg, rgba(252, 254, 255, 0.96), rgba(244, 248, 253, 0.98));
}

.sidebar-head,
.profile-card,
.search-row,
.filter-tabs,
.action-row,
.section-head,
.chat-head,
.chat-head-main,
.chat-head-actions,
.message-bubble-head,
.chat-row-top,
.chat-row-bottom,
.chat-row,
.directory-row,
.brand-lockup {
  display: flex;
  align-items: center;
}

.sidebar-head,
.section-head,
.chat-head {
  justify-content: space-between;
}

.sidebar-head {
  gap: 14px;
}

.brand-lockup {
  gap: 12px;
}

.brand-mark,
.avatar {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #ffffff;
  background: linear-gradient(135deg, #3ca6ff, #64d2ff);
  font-weight: 700;
}

.avatar-large {
  width: 52px;
  height: 52px;
  font-size: 1.1rem;
}

.brand-name {
  font-size: 1.08rem;
  font-weight: 700;
}

.brand-subline,
.profile-handle,
.chat-subtitle,
.section-title,
.empty-hint,
.message-time,
.message-author,
.chat-row-preview,
.chat-row-time,
.directory-handle {
  color: var(--muted);
}

.brand-subline,
.section-title {
  font-size: 0.88rem;
}

.connection-chip,
.count-pill,
.unread-pill {
  min-height: 30px;
  padding: 0 12px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(36, 82, 125, 0.08);
}

.connection-chip.live {
  color: var(--ok);
  background: rgba(26, 164, 122, 0.12);
}

.connection-chip.warn {
  color: var(--warn);
  background: rgba(216, 144, 47, 0.12);
}

.connection-chip.offline {
  color: #8a9aac;
}

.profile-card,
.profile-editor-card,
.auth-card,
.toolbar-card,
.directory-card,
.contacts-card,
.chat-list-card {
  border-radius: 24px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 18px 44px rgba(36, 67, 104, 0.08);
}

.profile-card {
  gap: 14px;
  padding: 16px;
}

.profile-meta {
  min-width: 0;
  flex: 1;
}

.profile-name,
.chat-title,
.directory-title,
.chat-row-title {
  font-weight: 700;
}

.auth-card,
.profile-editor-card,
.toolbar-card,
.directory-card,
.contacts-card,
.chat-list-card {
  padding: 16px;
}

.auth-form,
.profile-form,
.group-form {
  margin-top: 12px;
  display: grid;
  gap: 12px;
}

.auth-form label,
.profile-form label {
  display: grid;
  gap: 6px;
}

.auth-form span,
.profile-form span {
  color: var(--muted);
  font-size: 0.9rem;
}

.auth-form input,
.profile-form input,
.search-input,
.group-form input,
.composer textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel-strong);
  color: var(--text);
  padding: 13px 15px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

.search-row,
.filter-tabs,
.action-row {
  gap: 10px;
}

.search-row {
  justify-content: stretch;
}

.search-input {
  flex: 1;
}

.filter-tabs {
  margin-top: 12px;
}

.action-row {
  margin-top: 12px;
}

.primary-button,
.ghost-button,
.tab-button,
.composer-utility {
  border: 0;
  border-radius: 16px;
  cursor: pointer;
}

.primary-button,
.ghost-button,
.tab-button {
  padding: 12px 16px;
}

.primary-button {
  color: #ffffff;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 12px 28px rgba(46, 140, 255, 0.22);
}

.ghost-button,
.tab-button,
.composer-utility {
  color: var(--text);
  background: rgba(35, 79, 123, 0.08);
}

.tab-button.active {
  color: #ffffff;
  font-weight: 700;
  background: linear-gradient(135deg, #66bbff, #3396ff);
}

.directory-list,
.contacts-list,
.chat-list,
.messages-feed {
  min-height: 0;
  display: grid;
  gap: 10px;
  overflow: auto;
}

.directory-list,
.contacts-list,
.chat-list {
  margin-top: 12px;
}

.chat-list-card {
  min-height: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.chat-row,
.directory-row,
.contact-row {
  gap: 12px;
  width: 100%;
  padding: 12px;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.92);
}

.chat-row.active {
  border-color: rgba(74, 167, 255, 0.34);
  background: rgba(74, 167, 255, 0.14);
}

.contact-row.active {
  border-color: rgba(26, 164, 122, 0.34);
  background: rgba(26, 164, 122, 0.10);
}

.chat-row-main,
.directory-main,
.contact-main {
  min-width: 0;
  flex: 1;
}

.chat-row-top,
.chat-row-bottom {
  justify-content: space-between;
  gap: 10px;
}

.chat-row-bottom {
  margin-top: 6px;
}

.chat-row-title,
.chat-row-preview,
.directory-title,
.directory-handle,
.contact-title,
.contact-handle {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.contact-title {
  font-weight: 700;
}

.contact-handle {
  margin-top: 4px;
}

.profile-note {
  color: var(--muted);
  line-height: 1.5;
}

.unread-pill {
  min-width: 28px;
  min-height: 28px;
  padding: 0 10px;
  color: #ffffff;
  font-weight: 700;
  background: linear-gradient(135deg, #61b7ff, #3294ff);
}

.chat-head {
  gap: 18px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.80);
  backdrop-filter: blur(20px);
}

.chat-head-main {
  gap: 14px;
  min-width: 0;
}

.chat-head-actions {
  gap: 10px;
}

.timeline-wrap {
  min-height: 0;
  padding: 24px;
}

.messages-feed {
  height: 100%;
  align-content: start;
}

.timeline-empty,
.empty-hint {
  display: grid;
  place-items: center;
  text-align: center;
  border-radius: 22px;
  border: 1px dashed var(--line);
  padding: 28px;
}

.timeline-empty h2 {
  margin: 0;
  font-size: 1.4rem;
}

.timeline-empty p {
  margin: 10px 0 0;
  color: var(--muted);
  max-width: 34ch;
}

.message-bubble {
  max-width: min(720px, 100%);
  padding: 14px 16px;
  border-radius: 22px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
}

.message-bubble.mine {
  margin-left: auto;
  background: linear-gradient(180deg, rgba(110, 194, 255, 0.22), rgba(74, 167, 255, 0.18));
  border-color: rgba(74, 167, 255, 0.28);
}

.message-bubble-head {
  justify-content: space-between;
  gap: 12px;
}

.message-author,
.message-time {
  font-size: 0.84rem;
}

.message-text {
  margin-top: 8px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.composer-wrap {
  padding: 18px 22px 22px;
  border-top: 1px solid var(--line);
}

.composer {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: end;
}

.composer textarea {
  min-height: 56px;
  max-height: 180px;
  resize: none;
}

.composer-utility {
  width: 48px;
  height: 48px;
  font-size: 1.4rem;
}

.composer-send {
  min-width: 110px;
}

.status-banner {
  border-radius: 18px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.88);
  color: var(--text);
}

.status-banner.ok {
  color: var(--ok);
  background: rgba(26, 164, 122, 0.10);
}

.status-banner.error {
  color: var(--danger);
  background: rgba(220, 95, 111, 0.10);
}

.status-banner.info {
  color: var(--accent);
  background: rgba(74, 167, 255, 0.10);
}

.hidden {
  display: none !important;
}

@media (max-width: 1120px) {
  .messenger-shell {
    grid-template-columns: 340px 1fr;
  }
}

@media (max-width: 920px) {
  .messenger-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
}

@media (max-width: 640px) {
  .sidebar,
  .timeline-wrap,
  .composer-wrap,
  .chat-head {
    padding: 14px;
  }

  .filter-tabs,
  .action-row,
  .chat-head {
    flex-wrap: wrap;
  }

  .composer {
    grid-template-columns: 1fr;
  }

  .composer-send,
  .composer-utility {
    width: 100%;
  }
}
