.messages-page {
  height: 100vh;
  overflow: hidden;
  background:
    radial-gradient(circle at 18% 12%, rgba(36, 181, 255, 0.18), transparent 30%),
    radial-gradient(circle at 86% 18%, rgba(139, 66, 255, 0.16), transparent 28%),
    #070b14;
  color: var(--text);
}

.messages-page .dashboard-shell {
  height: 100vh;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.messages-page .site-header {
  flex: 0 0 auto;
}

.messages-page .main-wrap {
  flex: 1 1 auto;
  min-height: 0;
  padding: 0 !important;
  display: flex;
}

.messages-page .main-wrap > .container {
  width: min(1480px, calc(100vw - 32px));
  max-width: none;
  height: 100%;
  min-height: 0;
  padding: 14px 0;
  display: flex;
}

.messages-page .nav-row {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.messages-page .brand {
  min-width: 0;
}

.messages-page .brand-text {
  min-width: 0;
}

.messages-page .nav-actions {
  width: auto;
  margin-left: auto;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: nowrap;
  gap: 8px;
}

.messages-page .nav-actions > *,
.messages-page .nav-actions .user-chip {
  width: auto;
  flex: 0 0 auto;
}

.messages-page .nav-actions .user-chip {
  min-width: 0;
  max-width: 176px;
}

.messages-page .user-name {
  min-width: 0;
  max-width: 96px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.messages-header-icon-btn {
  width: auto;
  min-width: 44px;
  height: 44px;
  padding: 0 12px;
  border: 1px solid rgba(160, 178, 214, 0.18);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.055);
  color: #dce8ff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  font-size: 0.84rem;
  font-weight: 900;
  white-space: nowrap;
  transition: background 0.18s ease, border-color 0.18s ease;
}

.messages-header-icon-btn:hover {
  border-color: rgba(36, 181, 255, 0.5);
  background: rgba(36, 181, 255, 0.1);
}

.messages-header-icon-btn svg {
  width: 24px;
  height: 24px;
  display: block;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.messages-header-icon-btn svg use {
  stroke: currentColor;
}

.messages-header-icon-btn#logoutBtn {
  width: 44px;
  min-width: 44px;
  padding: 0;
}

.messages-header-icon-btn--icon-only {
  width: 44px;
  min-width: 44px;
  padding: 0;
}

.messages-layout {
  width: 100%;
  flex: 1 1 auto;
  height: auto;
  min-height: 0;
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  overflow: hidden;
  border: 1px solid rgba(160, 178, 214, 0.16);
  border-radius: 18px;
  background: rgba(9, 14, 27, 0.86);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.28);
}

.messages-sidebar {
  min-width: 0;
  display: grid;
  grid-template-rows: auto auto auto 1fr;
  border-right: 1px solid rgba(160, 178, 214, 0.14);
  background: rgba(255, 255, 255, 0.035);
}

.messages-sidebar-head {
  min-height: 86px;
  padding: 22px 18px 14px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.messages-kicker {
  display: block;
  margin-bottom: 5px;
  color: #7dd3fc;
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.messages-sidebar-head h1 {
  margin: 0;
  font-size: 1.55rem;
  line-height: 1;
}

.messages-icon-btn {
  width: 38px;
  height: 38px;
  border: 1px solid rgba(160, 178, 214, 0.18);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.055);
  color: #dce8ff;
  display: inline-grid;
  place-items: center;
  cursor: pointer;
}

.messages-icon-btn:hover {
  border-color: rgba(36, 181, 255, 0.55);
  background: rgba(36, 181, 255, 0.1);
}

.messages-icon-btn svg,
.messages-search svg,
.messages-send-btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.messages-search {
  margin: 0 14px 12px;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid rgba(160, 178, 214, 0.16);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.055);
  color: #9fb2d1;
  display: flex;
  align-items: center;
  gap: 9px;
}

.messages-search input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: #edf5ff;
  font: inherit;
  font-size: 0.92rem;
}

.messages-search input::placeholder {
  color: #72839f;
}

.messages-filter-row {
  padding: 0 14px 12px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.messages-filter {
  min-height: 34px;
  border: 1px solid rgba(160, 178, 214, 0.14);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  color: #aab9d2;
  font-weight: 850;
  cursor: pointer;
}

.messages-filter.is-active {
  color: #06111f;
  border-color: transparent;
  background: linear-gradient(135deg, #24b5ff, #7dd3fc);
}

.messages-room-list {
  min-height: 0;
  overflow-y: auto;
  display: grid;
  align-content: start;
  gap: 6px;
  padding: 0 10px 14px;
}

.messages-room-list,
.messages-thread {
  scrollbar-width: thin;
  scrollbar-color: rgba(125, 211, 252, 0.48) rgba(255, 255, 255, 0.045);
}

.messages-room-list::-webkit-scrollbar,
.messages-thread::-webkit-scrollbar {
  width: 8px;
}

.messages-room-list::-webkit-scrollbar-track,
.messages-thread::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.035);
  border-radius: 999px;
}

.messages-room-list::-webkit-scrollbar-thumb,
.messages-thread::-webkit-scrollbar-thumb {
  border: 2px solid rgba(9, 14, 27, 0.86);
  border-radius: 999px;
  background: linear-gradient(180deg, #24b5ff, #8b42ff);
}

.messages-room-list::-webkit-scrollbar-thumb:hover,
.messages-thread::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(180deg, #7dd3fc, #a879ff);
}

.room-item {
  width: 100%;
  min-height: 78px;
  padding: 12px;
  border: 1px solid transparent;
  border-radius: 14px;
  background: transparent;
  color: #e7eefc;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  gap: 10px;
  text-align: left;
  cursor: pointer;
  transition: background 0.18s ease, border-color 0.18s ease;
}

.room-item:hover {
  background: rgba(255, 255, 255, 0.055);
}

.room-item.is-active {
  border-color: rgba(36, 181, 255, 0.34);
  background: rgba(36, 181, 255, 0.1);
}

.room-avatar,
.messages-peer-avatar {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  display: inline-grid;
  place-items: center;
  color: #fff;
  font-weight: 950;
  background: linear-gradient(135deg, #24b5ff, #8b42ff);
  box-shadow: 0 12px 26px rgba(36, 181, 255, 0.16);
}

.room-main {
  min-width: 0;
}

.room-line {
  display: flex;
  align-items: center;
  gap: 8px;
}

.room-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 900;
  font-size: 0.94rem;
}

.room-preview {
  margin-top: 5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #8494af;
  font-size: 0.82rem;
  line-height: 1.3;
}

.room-item.has-unread .room-name,
.room-item.has-unread .room-preview {
  color: #fff;
}

.room-side {
  display: grid;
  justify-items: end;
  align-content: start;
  gap: 8px;
}

.room-time {
  color: #7c8ba4;
  font-size: 0.72rem;
  white-space: nowrap;
}

.room-unread {
  min-width: 19px;
  height: 19px;
  padding: 0 6px;
  border-radius: 999px;
  background: #ff2f3f;
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.68rem;
  font-weight: 950;
  box-shadow: 0 10px 18px rgba(255, 47, 63, 0.28);
}

.messages-main {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.045), transparent 22%),
    rgba(6, 10, 20, 0.5);
}

.messages-main-head {
  min-height: 78px;
  padding: 14px 18px;
  border-bottom: 1px solid rgba(160, 178, 214, 0.14);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.messages-peer {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.messages-back-btn {
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: #dce8ff;
  display: none;
  place-items: center;
  cursor: pointer;
}

.messages-back-btn:hover {
  background: rgba(255, 255, 255, 0.07);
}

.messages-back-btn svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.messages-main-head h2 {
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 1.05rem;
}

.messages-main-head p {
  margin: 4px 0 0;
  color: #8fa0bd;
  font-size: 0.83rem;
}

.messages-presence {
  min-width: max-content;
  padding: 6px 9px;
  border: 1px solid rgba(125, 211, 252, 0.24);
  border-radius: 999px;
  color: #bdefff;
  background: rgba(36, 181, 255, 0.08);
  font-size: 0.76rem;
  font-weight: 850;
}

.messages-thread {
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 18px;
}

.message-row {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
}

.message-day {
  align-self: center;
  margin: 6px 0;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.065);
  color: #91a5c4;
  font-size: 0.72rem;
  font-weight: 850;
}

.message-row.mine {
  align-items: flex-end;
}

.message-bubble {
  max-width: min(620px, 74%);
  padding: 10px 13px;
  border: 1px solid rgba(160, 178, 214, 0.12);
  border-radius: 16px 16px 16px 5px;
  background: rgba(255, 255, 255, 0.075);
  color: #edf5ff;
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.12);
}

.message-row.mine .message-bubble {
  border-color: transparent;
  border-radius: 16px 16px 5px 16px;
  color: #06111f;
  background: linear-gradient(135deg, #7dd3fc, #24b5ff);
}

.message-text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 0.94rem;
  line-height: 1.42;
}

.message-meta {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #72839f;
  font-size: 0.72rem;
}

.message-row.mine .message-meta {
  color: #91a5c4;
}

.message-receipt {
  font-weight: 850;
}

.message-receipt.is-read {
  color: #7dd3fc;
}

.messages-compose {
  padding: 12px 16px 16px;
  border-top: 1px solid rgba(160, 178, 214, 0.14);
  background: rgba(6, 10, 20, 0.82);
  display: grid;
  gap: 8px;
}

.messages-typing {
  min-height: 18px;
  color: #9fb2d1;
  font-size: 0.78rem;
  font-weight: 750;
}

.messages-compose textarea {
  width: 100%;
  max-height: 150px;
  min-height: 46px;
  resize: none;
  border: 1px solid rgba(160, 178, 214, 0.18);
  border-radius: 14px;
  outline: 0;
  background: rgba(255, 255, 255, 0.07);
  color: #fff;
  padding: 13px 14px;
  font: inherit;
  font-size: 0.94rem;
  line-height: 1.35;
}

.messages-compose textarea:focus {
  border-color: rgba(36, 181, 255, 0.62);
  box-shadow: 0 0 0 3px rgba(36, 181, 255, 0.12);
}

.messages-compose textarea:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.messages-compose-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.compose-hint {
  color: #72839f;
  font-size: 0.76rem;
}

.messages-send-btn {
  min-height: 38px;
  padding: 0 13px 0 15px;
  border: 0;
  border-radius: 12px;
  background: linear-gradient(135deg, #24b5ff, #8b42ff);
  color: #fff;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 14px 28px rgba(36, 181, 255, 0.18);
}

.messages-send-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.messages-empty,
.empty-state {
  margin: auto;
  max-width: 360px;
  padding: 24px;
  border: 1px dashed rgba(160, 178, 214, 0.2);
  border-radius: 18px;
  color: #8fa0bd;
  background: rgba(255, 255, 255, 0.035);
  text-align: center;
}

.messages-empty-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 14px;
  display: grid;
  place-items: center;
}

.messages-empty-icon svg {
  width: 58px;
  height: 58px;
}

.messages-empty h2 {
  margin: 0 0 7px;
  color: #edf5ff;
  font-size: 1.05rem;
}

.messages-empty p {
  margin: 0;
  line-height: 1.5;
}

.messages-status {
  margin-top: 12px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 980px) {
  .messages-page {
    height: 100dvh;
    overflow: hidden;
  }

  .messages-page .dashboard-shell {
    height: 100dvh;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .messages-page .site-header {
    position: sticky;
    top: 0;
    flex: 0 0 auto;
  }

  .messages-page .nav-row {
    min-height: 62px;
    padding: 8px 10px;
    flex-direction: row;
    align-items: center;
    gap: 8px;
  }

  .messages-page .nav-actions {
    width: auto;
    display: flex;
    grid-template-columns: none;
    gap: 6px;
  }

  .messages-page .nav-actions > *,
  .messages-page .nav-actions .user-chip,
  .messages-page .nav-actions .messages-header-icon-btn {
    width: auto;
    min-height: 42px;
  }

  .messages-page .messages-header-icon-btn {
    height: 42px;
    min-width: 42px;
    padding: 0 10px;
  }

  .messages-page .messages-header-icon-btn svg {
    width: 24px;
    height: 24px;
  }

  .messages-page .messages-header-icon-btn#logoutBtn,
  .messages-page .messages-header-icon-btn--icon-only {
    width: 42px;
    min-width: 42px;
    padding: 0;
  }

  .messages-page .nav-actions .user-chip {
    max-width: 42px;
    padding: 4px;
    justify-content: center;
  }

  .messages-page .user-name {
    display: none;
  }

  .messages-page .main-wrap {
    flex: 1 1 auto;
    min-height: 0;
    padding: 0 !important;
    display: flex;
  }

  .messages-page .main-wrap > .container {
    width: 100%;
    height: 100%;
    min-height: 0;
    padding: 0;
  }

  .messages-footer {
    display: none;
  }

  .messages-layout {
    height: 100%;
    min-height: 0;
    grid-template-columns: 1fr;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
  }

  .messages-sidebar {
    min-height: 0;
    max-height: none;
    border-right: 0;
  }

  .messages-main {
    height: 100%;
    min-height: 0;
    display: none;
  }

  .messages-layout.is-chat-open .messages-sidebar {
    display: none;
  }

  .messages-layout.is-chat-open .messages-main {
    display: grid;
  }

  .messages-back-btn {
    display: inline-grid;
  }

  .messages-thread {
    min-height: 0;
    max-height: none;
    padding-bottom: 12px;
  }

  .message-bubble {
    max-width: 86%;
  }
}

@media (max-width: 560px) {
  .messages-page .brand {
    gap: 8px;
  }

  .messages-page .brand-logo {
    width: 34px;
    height: 34px;
  }

  .messages-page .brand-text strong {
    font-size: 0.94rem;
  }

  .messages-page .brand-text > span {
    display: none;
  }

  .messages-layout {
    border-radius: 12px;
  }

  .messages-page .messages-layout {
    border-radius: 0;
  }

  .messages-main-head {
    min-height: 68px;
  }

  .messages-compose {
    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }

  .messages-sidebar-head,
  .messages-main-head,
  .messages-thread,
  .messages-compose {
    padding-left: 12px;
    padding-right: 12px;
  }

  .compose-hint {
    display: none;
  }
}

@media (max-width: 390px) {
  .messages-page .brand-text {
    display: none;
  }

  .messages-page .nav-row {
    gap: 6px;
  }

  .messages-page .messages-header-icon-btn,
  .messages-page .nav-actions .user-chip {
    height: 38px;
    min-height: 38px;
  }

  .messages-page .messages-header-icon-btn svg {
    width: 22px;
    height: 22px;
  }

  .messages-page .messages-header-icon-btn span {
    display: none;
  }

  .messages-page .messages-header-icon-btn {
    width: 38px;
    min-width: 38px;
    padding: 0;
  }

  .messages-page .user-avatar {
    width: 26px;
    height: 26px;
  }
}
