.messages-page {
  height: calc(100vh - 132px);
  margin-bottom: 0;
  overflow: hidden;
}

.messages-shell {
  display: grid;
  grid-template-columns: minmax(280px, 30%) minmax(0, 70%);
  height: 100%;
  min-height: 0;
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.messages-list-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: #ffffff;
  border-right: 1px solid #e5e7eb;
}

.message-list-view {
  display: flex;
  flex: 1;
  min-height: 0;
  flex-direction: column;
}

.messages-list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px;
  border-bottom: 1px solid #e5e7eb;
}

.message-search {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 14px 14px 10px;
  padding: 0 12px;
  min-height: 42px;
  color: #6b7280;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
}

.message-search input {
  width: 100%;
  min-width: 0;
  color: #111827;
  background: transparent;
  border: 0;
  outline: 0;
  font-size: 13px;
  font-weight: 650;
}

.message-users {
  --scrollbar-thumb-visible: rgba(220, 38, 38, 0.28);
  --scrollbar-thumb-active: rgba(220, 38, 38, 0.7);
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 4px 10px 12px;
}

.message-user {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  width: 100%;
  padding: 10px;
  color: #374151;
  background: transparent;
  border: 0;
  border-radius: 8px;
  text-align: left;
}

.message-user:hover {
  background: #fee2e2;
}

.message-user.active {
  background: #dc2626;
  color: #ffffff;
}

.message-avatar {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  color: #dc2626;
  background: #fee2e2;
  border: 1px solid #fecaca;
  border-radius: 50%;
  font-size: 12px;
  font-weight: 900;
}

.message-avatar.large {
  width: 50px;
  height: 50px;
  flex-basis: 50px;
  color: #ffffff;
  background: #dc2626;
}

.message-user.active .message-avatar {
  color: #dc2626;
  background: #ffffff;
  border-color: rgba(255, 255, 255, 0.38);
}

.message-user-copy {
  display: grid;
  min-width: 0;
}

.message-user-copy strong,
.message-user-copy small,
.message-user-copy em {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message-user-copy strong {
  color: inherit;
  font-size: 13px;
  font-style: normal;
  font-weight: 850;
}

.message-user-copy em {
  margin-top: 2px;
  color: #6b7280;
  font-size: 11px;
  font-style: normal;
  font-weight: 750;
}

.message-user-copy small {
  margin-top: 5px;
  color: #6b7280;
  font-size: 12px;
}

.message-user.active .message-user-copy em,
.message-user.active .message-user-copy small {
  color: rgba(255, 255, 255, 0.78);
}

.message-user-meta {
  display: grid;
  justify-items: end;
  gap: 7px;
  align-self: stretch;
  color: #6b7280;
  font-size: 11px;
  font-weight: 800;
}

.message-user-meta b {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  color: #ffffff;
  background: #dc2626;
  border-radius: 999px;
  font-size: 10px;
  line-height: 1;
}

.message-user.active .message-user-meta {
  color: rgba(255, 255, 255, 0.82);
}

.message-user.active .message-user-meta b {
  color: #dc2626;
  background: #ffffff;
}

.message-settings {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: flex-start;
  min-height: 48px;
  margin: 0 14px 14px;
  padding: 10px 12px;
  color: #374151;
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 850;
}

.message-profile-card {
  display: grid;
  justify-items: start;
  gap: 10px;
}

.message-settings:hover {
  color: #dc2626;
  background: #f9fafb;
}

.message-thread-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: #f9fafb;
}

.message-chat-view {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  flex: 1;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

.message-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: inherit;
}

.message-thread-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px;
  background: #ffffff;
  border-bottom: 1px solid #e5e7eb;
}

.message-thread-user {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.message-back {
  display: none;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  color: #dc2626;
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 999px;
}

.message-back.inline {
  display: inline-flex;
  flex: 0 0 38px;
}

.message-panel-view {
  --scrollbar-thumb-visible: rgba(220, 38, 38, 0.28);
  --scrollbar-thumb-active: rgba(220, 38, 38, 0.7);
  min-height: 0;
  height: 100%;
  max-height: 100%;
  overflow-y: auto;
  padding: 18px;
  background: #ffffff;
}

.message-panel-view[hidden] {
  display: none;
}

.message-panel-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.message-self-card,
.message-user-profile {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 6px;
  padding: 18px;
  margin-bottom: 16px;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  text-align: center;
}

.message-self-card h4,
.message-user-profile h4,
.message-setting-group h4 {
  margin: 0;
  color: #111827;
  font-size: 14px;
  font-weight: 900;
}

.message-self-card p,
.message-user-profile p {
  margin: 0;
  color: #6b7280;
  font-size: 12px;
  font-weight: 750;
}

.message-photo-add {
  position: absolute;
  right: calc(50% - 42px);
  top: 54px;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  color: #ffffff;
  background: #dc2626;
  border: 2px solid #ffffff;
  border-radius: 999px;
  font-size: 18px;
  font-weight: 900;
  line-height: 1;
}

.message-setting-group {
  display: grid;
  gap: 10px;
  padding: 14px;
  margin-bottom: 14px;
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
}

.message-setting-group label {
  display: grid;
  gap: 6px;
  color: #374151;
  font-size: 12px;
  font-weight: 850;
}

.message-file-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 9px;
  align-items: center;
  min-height: 42px;
  padding: 9px 10px;
  color: #374151;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 850;
  text-align: left;
}

.message-file-row span {
  color: #6b7280;
  font-size: 11px;
}

.message-thread-user h3 {
  margin: 0;
  color: #111827;
  font-size: 16px;
  font-weight: 900;
}

.message-thread-user p {
  margin: 3px 0 0;
  color: #6b7280;
  font-size: 12px;
  font-weight: 750;
}

.message-thread-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.message-chat-search {
  position: absolute;
  top: 58px;
  right: 14px;
  z-index: 8;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  width: min(360px, calc(100% - 28px));
  min-height: 48px;
  padding: 8px 10px;
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
}

.message-chat-search[hidden] {
  display: none;
}

.message-chat-search input {
  width: 100%;
  min-width: 0;
  min-height: 34px;
  color: #111827;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 999px;
  outline: 0;
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 650;
}

.message-chat-search button {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  color: #6b7280;
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 999px;
}

.message-thread {
  --scrollbar-thumb-visible: rgba(220, 38, 38, 0.28);
  --scrollbar-thumb-active: rgba(220, 38, 38, 0.7);
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 22px;
}

.message-day {
  width: max-content;
  margin: 0 auto 18px;
  padding: 5px 12px;
  color: #6b7280;
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 850;
}

.message-bubble {
  width: min(68%, 620px);
  margin-bottom: 12px;
  padding: 12px 14px;
  border-radius: 8px;
  box-shadow: var(--shadow-sm);
}

.message-bubble.is-hidden {
  display: none;
}

.message-user.is-hidden {
  display: none;
}

.message-bubble p {
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
}

.message-bubble time {
  display: block;
  margin-top: 7px;
  font-size: 10px;
  font-weight: 800;
}

.message-bubble.incoming {
  color: #374151;
  background: #ffffff;
  border: 1px solid #e5e7eb;
}

.message-bubble.incoming time {
  color: #6b7280;
}

.message-bubble.outgoing {
  margin-left: auto;
  color: #ffffff;
  background: #dc2626;
}

.message-bubble.outgoing time {
  color: rgba(255, 255, 255, 0.78);
}

.message-composer {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 14px;
  background: #ffffff;
  border-top: 1px solid #e5e7eb;
}

.composer-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  min-height: 46px;
  padding: 0 6px 0 14px;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 999px;
}

.composer-field input {
  min-width: 0;
  color: #111827;
  background: transparent;
  border: 0;
  outline: 0;
  font-size: 13px;
  font-weight: 650;
}

.composer-icon,
.send-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 999px;
}

.composer-icon {
  color: #6b7280;
  background: #ffffff;
  border: 1px solid #e5e7eb;
}

.composer-icon:hover {
  color: #dc2626;
  background: #fee2e2;
  border-color: #fecaca;
}

.send-button {
  color: #ffffff;
  background: #dc2626;
  border: 1px solid #dc2626;
}

.send-button:hover {
  background: #991b1b;
  border-color: #991b1b;
}

body.dark-mode .messages-shell,
body.dark-mode .messages-list-panel,
body.dark-mode .message-thread-header,
body.dark-mode .message-composer,
body.dark-mode .message-chat-search {
  background: var(--white);
  border-color: var(--slate-200);
}

body.dark-mode .message-thread-panel {
  background: var(--slate-50);
}

body.dark-mode .message-search,
body.dark-mode .composer-field {
  background: var(--slate-50);
  border-color: var(--slate-200);
}

body.dark-mode .message-bubble.incoming,
body.dark-mode .message-day,
body.dark-mode .composer-icon,
body.dark-mode .message-settings,
body.dark-mode .message-panel-view,
body.dark-mode .message-setting-group,
body.dark-mode .message-self-card,
body.dark-mode .message-user-profile {
  background: var(--white);
  border-color: var(--slate-200);
}

@media (max-width: 960px) {
  .messages-page {
    height: calc(100dvh - 96px);
  }

  .messages-shell {
    display: block;
    height: 100%;
    min-height: 0;
  }

  .messages-list-panel {
    height: 100%;
    border-right: 0;
  }

  .message-users {
    max-height: none;
  }

  .message-thread-panel {
    display: none;
    height: 100%;
    min-height: 0;
  }

  .messages-shell.is-thread-open .messages-list-panel {
    display: none;
  }

  .messages-shell.is-thread-open .message-thread-panel {
    display: grid;
  }

  .message-back {
    display: inline-flex;
  }
}

@media (max-width: 640px) {
  .messages-list-head,
  .message-thread-header {
    align-items: center;
    flex-direction: row;
  }

  .message-user {
    grid-template-columns: 40px minmax(0, 1fr);
  }

  .message-user-meta {
    grid-column: 2;
    justify-items: start;
    grid-auto-flow: column;
    justify-content: start;
  }

  .message-bubble {
    width: 92%;
  }

  .message-thread {
    padding: 14px;
  }

  .message-composer {
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 7px;
    padding: 10px;
  }

  .composer-icon,
  .send-button {
    width: 38px;
    height: 38px;
  }
}
  flex: 0 0 auto;
  flex: 0 0 auto;
