.chat-page {
  background: #040e13;
}
/* Lock chat to viewport — groups members list must not stretch the page */
.chat-page-shell {
  max-width: none;
  margin: 0;
  padding: 12px 18px 14px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  height: calc(100dvh - 60px);
  max-height: calc(100dvh - 60px);
  overflow: hidden;
}
.chat-page-head {
  flex: 0 0 auto;
  margin-bottom: 10px;
}
.chat-kicker {
  margin: 0 0 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: #12f9ef;
}
.chat-page-head h1 {
  margin: 0 0 4px;
  font-size: clamp(22px, 2.4vw, 28px);
  line-height: 1.1;
  letter-spacing: -0.4px;
  color: #fff;
}
.chat-sub {
  margin: 0;
  font-size: 13px;
  color: #8fa3b3;
}

.chat-layout {
  display: grid;
  /* Thread widest — list / thread / members like mock */
  grid-template-columns: 252px minmax(0, 1fr) 228px;
  gap: 14px;
  flex: 1 1 auto;
  min-height: 0;
  height: 100%;
  max-height: 100%;
  align-items: stretch;
  overflow: hidden;
}

/* —— Panels —— */
.chat-list-panel,
.chat-thread,
.chat-details {
  border: 1px solid #1c2a33;
  border-radius: 14px;
  background: #0a141b;
  min-height: 0;
  max-height: 100%;
  height: 100%;
  overflow: hidden;
}

/* —— List panel —— */
.chat-list-panel {
  display: flex;
  flex-direction: column;
  padding: 14px 12px;
  overflow: hidden;
}
.chat-list-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
  padding: 0 2px;
}
.chat-scope-tabs {
  display: flex;
  gap: 22px;
}
.chat-scope-tabs button {
  appearance: none;
  border: 0;
  background: none;
  padding: 6px 2px 10px;
  color: #8fa3b3;
  font: 700 14px/1 inherit;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.chat-scope-tabs button[aria-selected="true"] {
  color: #f7f9fc;
  border-bottom-color: #d0ff00;
}
.chat-compose {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 1px solid #2a3b47;
  border-radius: 9px;
  background: #0c1921;
  color: #c3d4df;
  cursor: pointer;
}
.chat-compose:hover {
  border-color: #d0ff00;
  color: #d0ff00;
}
.chat-search {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  padding: 0 14px;
  margin: 0 2px 12px;
  border: 1px solid #2a3b47;
  border-radius: 11px;
  background: #061015;
  color: #8fa3b3;
}
.chat-search input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  color: #f7f9fc;
  font: 500 13px/1 inherit;
  outline: none;
}
.chat-convo-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow: auto;
  display: grid;
  gap: 2px;
  flex: 1;
  align-content: start;
}
.chat-convo {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 11px 12px 11px 14px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: inherit;
  text-align: left;
  width: 100%;
  cursor: pointer;
  position: relative;
}
.chat-convo:hover {
  background: #0e1a22;
}
.chat-convo.active {
  background: #12202a;
}
.chat-convo.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 12px;
  bottom: 12px;
  width: 3px;
  border-radius: 3px;
  background: #d0ff00;
  box-shadow: 0 0 10px #d0ff0066;
}
.chat-convo-thumb {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  object-fit: cover;
  background: #12202a;
}
.chat-convo-copy strong {
  display: block;
  font-size: 14px;
  color: #f7f9fc;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-convo-copy span {
  display: block;
  font-size: 12px;
  color: #8fa3b3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-convo-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  min-width: 44px;
}
.chat-convo-meta time {
  font-size: 11px;
  color: #6f8494;
  white-space: nowrap;
}
.chat-badge {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: #d0ff00;
  color: #080e00;
  font-size: 11px;
  font-weight: 800;
  box-shadow: 0 0 10px #d0ff0044;
}
.chat-badge-spacer {
  width: 20px;
  height: 20px;
}

/* —— Thread —— */
.chat-thread {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.chat-thread-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid #1c2a33;
}
.chat-thread-head img {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  object-fit: cover;
}
.chat-thread-head .chat-thread-copy {
  flex: 1;
  min-width: 0;
}
.chat-thread-head strong {
  display: block;
  font-size: 16px;
  color: #fff;
  margin-bottom: 2px;
}
.chat-thread-head span {
  font-size: 12px;
  color: #8fa3b3;
}
.chat-thread-menu {
  appearance: none;
  border: 0;
  background: transparent;
  color: #8fa3b3;
  font-size: 20px;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 8px;
  line-height: 1;
}
.chat-thread-menu:hover {
  color: #fff;
  background: #12202a;
}

.chat-messages {
  flex: 1;
  overflow: auto;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.chat-msg {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}
.chat-msg-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  object-fit: cover;
  background: #12202a;
}
.chat-msg-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 6px;
}
.chat-msg-head strong {
  font-size: 13px;
  color: #fff;
}
.chat-msg-head time {
  font-size: 11px;
  color: #6f8494;
}
.chat-bubble {
  display: inline-block;
  max-width: 100%;
  padding: 11px 14px;
  border-radius: 12px;
  background: #12202a;
  color: #d7e3ec;
  font-size: 14px;
  line-height: 1.45;
}

.chat-invite-card {
  margin-top: 6px;
  border: 1px solid #1c2a33;
  border-radius: 14px;
  overflow: hidden;
  background: #0c1921;
  max-width: 460px;
}
.chat-invite-card img {
  width: 100%;
  height: 168px;
  object-fit: cover;
  display: block;
}
.chat-invite-body {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 16px;
}
.chat-invite-body .chat-invite-tag {
  display: block;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.1em;
  color: #d0ff00;
  margin-bottom: 5px;
}
.chat-invite-body strong {
  display: block;
  font-size: 16px;
  color: #fff;
  margin-bottom: 3px;
}
.chat-invite-body span {
  display: block;
  font-size: 12px;
  color: #8fa3b3;
}
.chat-invite-note {
  display: block;
  margin-top: 4px;
  font-size: 12px;
  font-style: normal;
  color: #a8b8c4;
}
.chat-join {
  appearance: none;
  border: 0;
  border-radius: 9px;
  min-height: 38px;
  padding: 0 16px;
  background: #d0ff00;
  color: #080e00;
  font: 700 13px/1 inherit;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}
.chat-join:hover {
  filter: brightness(1.05);
}

.chat-composer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 16px;
  border-top: 1px solid #1c2a33;
  position: relative;
}
.chat-composer-tools {
  display: flex;
  align-items: center;
  gap: 2px;
  position: relative;
}
.chat-icon-btn {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: #8fa3b3;
  cursor: pointer;
  font-size: 16px;
}
.chat-icon-btn:hover,
.chat-icon-btn[aria-expanded="true"] {
  color: #d0ff00;
  background: #12202a;
}
.chat-emoji-picker {
  position: absolute;
  left: 0;
  bottom: calc(100% + 8px);
  z-index: 20;
  box-shadow: 0 16px 40px #000a;
  border-radius: 12px;
  overflow: hidden;
}
.chat-emoji-picker[hidden] {
  display: none !important;
}
.chat-emoji-picker-el {
  --background: #0b161d;
  --border-color: #2a3c48;
  --button-active-background: #12202a;
  --button-hover-background: #12202a;
  --category-emoji-padding: 0.3rem;
  --category-font-color: #8fa3b3;
  --indicator-color: #d0ff00;
  --input-border-color: #2a3c48;
  --input-font-color: #e8f0f6;
  --input-placeholder-color: #6f8494;
  --outline-color: #d0ff00;
  --secondary-background: #071117;
  height: 360px;
  width: min(352px, 82vw);
}
.chat-composer #chat-input {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid #2a3b47;
  border-radius: 999px;
  background: #061015;
  color: #f7f9fc;
  font: 500 14px/1 inherit;
  outline: none;
}
.chat-composer #chat-input:focus {
  border-color: #3a4d5a;
}
.chat-bubble-media {
  padding: 6px !important;
  max-width: min(280px, 70%);
}
.chat-bubble-media img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 10px;
  background: #0c1921;
  min-height: 48px;
}
.chat-bubble-media.is-broken {
  padding: 12px 14px !important;
  background: #12202a;
  border: 1px solid #2a3b47;
}
.chat-media-missing {
  margin: 0;
  font-size: 13px;
  color: #8fa3b3;
  font-weight: 600;
}
.chat-composer .chat-send:disabled {
  opacity: 0.65;
  cursor: wait;
}
.chat-send {
  appearance: none;
  border: 0;
  border-radius: 10px;
  min-height: 44px;
  padding: 0 20px;
  background: #d0ff00;
  color: #080e00;
  font: 700 14px/1 inherit;
  cursor: pointer;
}
.chat-send:hover {
  filter: brightness(1.05);
}

/* —— Details (groups) —— */
.chat-details {
  padding: 14px 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow: hidden;
}
.chat-details-block {
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.chat-details-block:first-child {
  flex: 1 1 auto;
  overflow: hidden;
}
.chat-details-block:last-child {
  flex: 0 0 auto;
}
.chat-details-block h2 {
  margin: 0 0 12px;
  font-size: 14px;
  font-weight: 700;
  color: #f7f9fc;
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}
.chat-details-block h2 i {
  color: #8fa3b3;
  font-size: 13px;
}
.chat-members {
  list-style: none;
  margin: 0 0 12px;
  padding: 0;
  display: grid;
  gap: 12px;
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  align-content: start;
}
.chat-members li {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) auto;
  gap: 11px;
  align-items: center;
}
.chat-members img {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  object-fit: cover;
  background: #12202a;
}
.chat-member-name {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 13px;
  font-weight: 700;
  color: #f7f9fc;
}
.chat-member-name .fa-crown {
  color: #f0c84a;
  font-size: 11px;
}
.chat-admin-tag {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #f0c84a;
  background: #2a2410;
  border-radius: 999px;
  padding: 2px 7px;
}
.chat-member-status {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 3px;
  font-size: 11px;
  color: #8fa3b3;
}
.chat-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #6f8494;
  flex-shrink: 0;
}
.chat-status-dot.offline {
  background: #5a6a75;
  box-shadow: none;
}
.chat-status-dot.online {
  background: #3dff6a;
  box-shadow: 0 0 8px #3dff6aaa;
}
.chat-member-more {
  appearance: none;
  border: 0;
  background: transparent;
  color: #6f8494;
  cursor: pointer;
  padding: 4px;
  font-size: 16px;
}
.chat-invite {
  width: 100%;
  appearance: none;
  border: 0;
  border-radius: 11px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: #d0ff00;
  color: #080e00;
  font: 700 14px/1 inherit;
  cursor: pointer;
  flex: 0 0 auto;
  margin-top: auto;
}
.chat-invite:hover {
  filter: brightness(1.05);
}

.chat-setting {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 0;
  border-bottom: 1px solid #15222b;
  cursor: pointer;
  color: #d7e3ec;
  font-size: 13px;
}
.chat-setting > span:first-child {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}
.chat-setting > span:first-child i {
  color: #8fa3b3;
  width: 16px;
}
.chat-setting input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.chat-switch {
  width: 42px;
  height: 24px;
  border-radius: 999px;
  background: #2a3b47;
  position: relative;
  flex-shrink: 0;
  transition: background 0.15s ease;
}
.chat-switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #c3d4df;
  transition: transform 0.15s ease;
}
.chat-setting input:checked + .chat-switch {
  background: #d0ff00;
}
.chat-setting input:checked + .chat-switch::after {
  transform: translateX(18px);
  background: #080e00;
}
.chat-setting-link {
  width: 100%;
  appearance: none;
  border: 0;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 0 0;
  color: #d7e3ec;
  font-size: 13px;
  cursor: pointer;
}
.chat-setting-link span {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}
.chat-setting-link i:first-child {
  color: #8fa3b3;
  width: 16px;
}
.chat-setting-link > i {
  color: #6f8494;
  font-size: 12px;
}

.chat-empty,
.chat-empty-msg {
  margin: 0;
  padding: 28px 16px;
  color: #8ea3b3;
  font-size: 14px;
  line-height: 1.45;
  list-style: none;
  text-align: center;
}
.chat-messages > .chat-empty-msg {
  margin: auto;
}
.chat-compose-form {
  display: grid;
  gap: 12px;
}
.chat-compose-form label {
  display: grid;
  gap: 6px;
  color: #d7e3ec;
  font-size: 14px;
}
.chat-compose-form input[type="search"],
.chat-compose-form input[type="text"],
.chat-compose-form textarea {
  width: 100%;
  border: 1px solid #2a3c48;
  border-radius: 10px;
  background: #0b141a;
  color: #e8eef3;
  padding: 10px 12px;
  font: inherit;
}
.chat-compose-form textarea {
  min-height: 96px;
  resize: vertical;
}
.chat-compose-results {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
  max-height: 220px;
  overflow: auto;
}
.chat-compose-results button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid #2a3c48;
  border-radius: 10px;
  background: #101b22;
  color: #e8eef3;
  padding: 8px 10px;
  cursor: pointer;
  text-align: left;
  font: inherit;
}
.chat-compose-results button small {
  color: #8ea3b3;
}
.chat-compose-results img {
  border-radius: 50%;
}
.chat-compose-status {
  min-height: 1.2em;
  margin: 0;
  color: #9ec9ff;
  font-size: 13px;
}
@media (max-width: 1100px) {
  .chat-layout {
    grid-template-columns: 236px minmax(0, 1fr) 210px;
    gap: 12px;
  }
}
@media (max-width: 860px) {
  .chat-layout {
    grid-template-columns: 230px minmax(0, 1fr);
  }
  .chat-details {
    display: none;
  }
}
.chat-back {
  display: none;
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  place-items: center;
  border: 1px solid #2a3b47;
  border-radius: 10px;
  background: #0c1921;
  color: #c3d4df;
  cursor: pointer;
  padding: 0;
  min-height: 40px;
}
.chat-back:hover {
  border-color: #d0ff00;
  color: #d0ff00;
}

@media (max-width: 700px) {
  .chat-page-shell {
    padding: 10px 10px calc(12px + env(safe-area-inset-bottom, 0px));
    height: calc(100dvh - 60px);
    max-height: calc(100dvh - 60px);
  }
  .chat-page-head {
    margin-bottom: 8px;
  }
  .chat-page-head h1 {
    font-size: 24px;
  }
  .chat-layout {
    grid-template-columns: 1fr;
    gap: 0;
    min-height: 0;
  }
  .chat-list-panel,
  .chat-thread {
    min-height: 0;
    max-height: 100%;
    height: 100%;
  }
  /* List ↔ thread swap (WhatsApp-style) */
  .chat-layout:not(.is-thread-open) .chat-thread,
  .chat-layout:not(.is-thread-open) .chat-details {
    display: none;
  }
  .chat-layout.is-thread-open .chat-list-panel {
    display: none;
  }
  .chat-layout.is-thread-open .chat-thread {
    display: flex;
    flex-direction: column;
  }
  .chat-back {
    display: grid;
  }
  .chat-compose,
  .chat-icon-btn,
  .chat-send,
  .chat-convo {
    min-height: 44px;
  }
  .chat-search input,
  .chat-composer input {
    font-size: 16px;
    min-height: 44px;
  }
  .chat-messages {
    flex: 1;
    min-height: 0;
  }
}
