.nav-chat-link {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
}

.nav-chat-badge,
.chat-contact-unread {
  display: inline-flex;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  color: #ffffff;
  background: var(--red);
  font-size: 0.72rem;
  font-weight: 900;
  line-height: 1;
  box-shadow: 0 6px 16px rgba(255, 85, 111, 0.3);
}

.nav-chat-badge[hidden],
.chat-notification-toast[hidden],
.chat-contact-unread[hidden],
.chat-new-messages[hidden],
.chat-search-empty[hidden],
.chat-load-older[hidden],
.chat-remove-attachment[hidden],
.chat-empty-history[hidden],
.chat-contact[hidden],
.chat-sidebar-empty[hidden] {
  display: none;
}

.chat-notification-toast {
  position: fixed;
  right: auto;
  bottom: 24px;
  left: 24px;
  z-index: 80;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  width: min(390px, calc(100vw - 32px));
  overflow: hidden;
  border: 1px solid rgba(75, 141, 255, 0.48);
  border-radius: 12px;
  background: rgba(7, 15, 28, 0.98);
  box-shadow: 0 22px 65px rgba(0, 0, 0, 0.48);
}

.chat-notification-toast > a {
  display: grid;
  min-width: 0;
  padding: 15px 17px;
  gap: 5px;
}

.chat-notification-toast strong {
  color: #ffffff;
}

.chat-notification-toast span {
  overflow: hidden;
  color: var(--muted);
  font-size: 0.88rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-notification-toast button {
  width: 46px;
  border: 0;
  border-right: 1px solid var(--border);
  color: var(--muted);
  background: transparent;
  font: inherit;
  font-size: 1.35rem;
  cursor: pointer;
}

.chat-notification-toast button:hover,
.chat-notification-toast button:focus-visible {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.06);
}

.chat-shell {
  max-width: 1380px;
  min-height: 76vh;
}

.chat-hero,
.chat-panel-header,
.chat-compose-meta,
.chat-attachment-row {
  display: flex;
  align-items: center;
}

.chat-hero {
  justify-content: space-between;
  padding: 6px 0 24px;
  gap: 24px;
}

.chat-hero h1,
.chat-panel-header h2,
.chat-sidebar-section h2,
.chat-welcome h2 {
  margin: 0;
}

.chat-hero p:not(.section-kicker),
.chat-panel-header p,
.chat-welcome p {
  margin: 7px 0 0;
  color: var(--muted);
}

.chat-live-indicator {
  display: inline-flex;
  flex: 0 0 auto;
  padding: 8px 12px;
  align-items: center;
  border: 1px solid rgba(33, 220, 139, 0.32);
  border-radius: 999px;
  color: #caffea;
  background: rgba(10, 64, 44, 0.48);
  gap: 8px;
  font-size: 0.83rem;
  font-weight: 800;
}

.chat-live-indicator span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(33, 220, 139, 0.13);
}

.chat-layout {
  display: grid;
  grid-template-columns: minmax(260px, 330px) minmax(0, 1fr);
  min-height: 680px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: rgba(5, 12, 24, 0.82);
  box-shadow: var(--shadow);
}

.chat-sidebar {
  min-width: 0;
  max-height: 760px;
  padding: 20px 16px;
  overflow-y: auto;
  border-left: 1px solid var(--border);
  background: rgba(8, 17, 31, 0.86);
}

.chat-search-label {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.chat-contact-search,
.chat-compose textarea {
  width: 100%;
  border: 1px solid var(--border);
  outline: 0;
  color: var(--text);
  background: rgba(2, 8, 17, 0.72);
  font: inherit;
}

.chat-contact-search {
  height: 42px;
  padding: 0 12px;
  border-radius: 10px;
}

.chat-contact-search:focus,
.chat-compose textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(75, 141, 255, 0.13);
}

.chat-sidebar-section {
  margin-top: 22px;
}

.chat-sidebar-section h2 {
  margin-bottom: 9px;
  color: var(--muted);
  font-size: 0.8rem;
  letter-spacing: 0.02em;
}

.chat-contact-list {
  display: grid;
  gap: 5px;
}

.chat-contact {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) auto;
  min-width: 0;
  padding: 9px;
  align-items: center;
  border: 1px solid transparent;
  border-radius: 11px;
  gap: 10px;
  transition: border-color 150ms ease, background 150ms ease;
}

.chat-contact:hover,
.chat-contact:focus-visible,
.chat-contact.active {
  border-color: rgba(75, 141, 255, 0.34);
  background: rgba(75, 141, 255, 0.11);
}

.chat-contact-compact {
  grid-template-columns: 36px minmax(0, 1fr);
}

.chat-avatar {
  display: inline-flex;
  width: 40px;
  height: 40px;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(75, 141, 255, 0.32);
  border-radius: 50%;
  color: #dce9ff;
  background: linear-gradient(145deg, rgba(75, 141, 255, 0.22), rgba(129, 88, 255, 0.24));
  font-weight: 900;
}

.chat-contact-compact .chat-avatar {
  width: 36px;
  height: 36px;
}

.chat-avatar-large {
  width: 48px;
  height: 48px;
  font-size: 1.05rem;
}

.chat-contact-copy {
  display: grid;
  min-width: 0;
  gap: 3px;
}

.chat-contact-copy strong,
.chat-contact-compact strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-contact-copy span {
  overflow: hidden;
  color: var(--soft);
  font-size: 0.78rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-sidebar-empty,
.chat-search-empty {
  margin: 8px 4px;
  color: var(--soft);
  font-size: 0.84rem;
  line-height: 1.55;
}

.chat-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 680px;
  background:
    radial-gradient(circle at 10% 10%, rgba(75, 141, 255, 0.08), transparent 32%),
    rgba(4, 11, 22, 0.68);
}

.chat-panel-header {
  min-height: 78px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}

.chat-panel-header h2 {
  font-size: 1.08rem;
}

.chat-panel-header p {
  font-size: 0.8rem;
}

.chat-self-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid rgba(50, 91, 126, 0.16);
  background: rgba(237, 247, 255, 0.7);
}

.chat-self-controls form {
  margin: 0;
}

.chat-message-delete {
  border: 0;
  padding: 0;
  color: #a72b2b;
  background: transparent;
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
}

.chat-history-wrap {
  position: relative;
  display: grid;
  min-height: 0;
  overflow: hidden;
}

.chat-message-log {
  display: flex;
  min-height: 0;
  max-height: 540px;
  padding: 20px;
  overflow-y: auto;
  flex-direction: column;
  gap: 11px;
  scroll-behavior: smooth;
}

.chat-load-older,
.chat-new-messages {
  z-index: 2;
  justify-self: center;
  border: 1px solid rgba(75, 141, 255, 0.36);
  border-radius: 999px;
  color: #dbe8ff;
  background: rgba(10, 25, 48, 0.96);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 800;
  cursor: pointer;
}

.chat-load-older {
  position: absolute;
  top: 10px;
  padding: 7px 12px;
}

.chat-new-messages {
  position: absolute;
  bottom: 12px;
  padding: 8px 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.34);
}

.chat-message {
  width: fit-content;
  max-width: min(72%, 650px);
  padding: 11px 13px 8px;
  border: 1px solid var(--border);
  border-radius: 14px 14px 4px 14px;
  background: rgba(12, 22, 38, 0.96);
  overflow-wrap: anywhere;
}

.chat-message-mine {
  align-self: flex-start;
  border-color: rgba(75, 141, 255, 0.34);
  border-radius: 14px 14px 14px 4px;
  background: linear-gradient(145deg, rgba(52, 106, 197, 0.74), rgba(67, 52, 142, 0.76));
}

.chat-message-theirs {
  align-self: flex-end;
}

.chat-message header {
  margin-bottom: 4px;
  color: #dfe9fb;
  font-size: 0.74rem;
}

.chat-message p {
  margin: 0;
  color: #f5f7fb;
  line-height: 1.62;
  white-space: pre-wrap;
}

.chat-message footer {
  display: flex;
  padding-top: 5px;
  justify-content: flex-end;
  color: rgba(225, 233, 247, 0.7);
  gap: 8px;
  font-size: 0.68rem;
}

.chat-media-link,
.chat-message-video,
.chat-message [data-chat-message-media]:not(:empty) {
  display: block;
  margin-top: 9px;
}

.chat-media-link img,
.chat-message-video,
.chat-message [data-chat-message-media] img,
.chat-message [data-chat-message-media] video {
  display: block;
  width: min(100%, 420px);
  max-height: 300px;
  border-radius: 10px;
  object-fit: contain;
  background: #000000;
}

.chat-empty-history {
  margin: auto;
  color: var(--soft);
  text-align: center;
}

.chat-compose {
  display: grid;
  padding: 14px 18px 17px;
  border-top: 1px solid var(--border);
  background: rgba(7, 15, 28, 0.92);
  gap: 8px;
}

.chat-compose > label {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.chat-compose textarea {
  min-height: 76px;
  max-height: 180px;
  padding: 10px 12px;
  border-radius: 10px;
  line-height: 1.55;
  resize: vertical;
}

.chat-compose-meta {
  justify-content: space-between;
  color: var(--soft);
  gap: 14px;
  font-size: 0.72rem;
}

.chat-attachment-row {
  flex-wrap: wrap;
  gap: 8px;
}

.chat-file-button,
.chat-remove-attachment {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: #dbe6f8;
  background: rgba(8, 17, 31, 0.84);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 800;
  cursor: pointer;
}

.chat-file-button:hover,
.chat-file-button:focus-within {
  border-color: rgba(75, 141, 255, 0.56);
}

.chat-remove-attachment {
  color: #ffd5dd;
  border-color: rgba(255, 85, 111, 0.34);
}

.chat-attachment-help,
.chat-compose-status {
  min-height: 1.2em;
  margin: 0;
  color: var(--soft);
  font-size: 0.72rem;
  line-height: 1.45;
}

.chat-compose-status[data-state="error"] {
  color: #ffc7d1;
}

.chat-compose-status[data-state="success"] {
  color: #baffdf;
}

.chat-send-button {
  justify-self: end;
  min-width: 126px;
  padding: 0 22px;
  border: 0;
  color: #ffffff;
  font: inherit;
  cursor: pointer;
}

.chat-send-button:disabled,
.chat-load-older:disabled {
  cursor: wait;
  opacity: 0.62;
}

.chat-welcome {
  grid-row: 1 / -1;
  max-width: 520px;
  padding: 40px;
  margin: auto;
  color: var(--muted);
  text-align: center;
}

.chat-welcome-icon {
  display: inline-flex;
  width: 66px;
  height: 66px;
  margin-bottom: 18px;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(75, 141, 255, 0.34);
  border-radius: 50%;
  color: var(--cyan);
  background: rgba(75, 141, 255, 0.12);
  font-size: 1.8rem;
}

@media (max-width: 900px) {
  .chat-layout {
    grid-template-columns: 1fr;
  }

  .chat-sidebar {
    max-height: 330px;
    border-bottom: 1px solid var(--border);
    border-left: 0;
  }

  .chat-panel,
  .chat-layout {
    min-height: 600px;
  }
}

@media (max-width: 620px) {
  .chat-shell {
    padding-right: 12px;
    padding-left: 12px;
  }

  .chat-hero {
    align-items: flex-start;
    flex-direction: column;
  }

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

  .chat-sidebar {
    padding: 16px 12px;
  }

  .chat-message-log {
    padding: 16px 10px;
  }

  .chat-message {
    max-width: 88%;
  }

  .chat-compose {
    padding: 12px;
  }

  .chat-compose-meta {
    align-items: flex-start;
    flex-direction: column;
    gap: 3px;
  }

  .chat-send-button {
    width: 100%;
    justify-self: stretch;
  }

  .chat-notification-toast {
    right: 16px;
    bottom: 16px;
    left: 16px;
    width: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .chat-message-log {
    scroll-behavior: auto;
  }
}
