.chat-thread-shell {
  max-width: 980px;
  margin: 0 auto;
}

.chat-thread-shell--modal {
  display: grid;
  height: min(80vh, 740px);
  max-width: none;
}

#entity-modal .modal-body:has(.chat-thread-shell--modal) {
  display: grid;
  overflow: hidden;
}

.chat-thread-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: min(74vh, 760px);
  overflow: hidden;
  border: 1px solid var(--app-border);
  border-radius: 0.55rem;
  background: #eef3ef;
  box-shadow: var(--app-shadow-sm);
}

.chat-thread-shell--modal .chat-thread-panel {
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100%;
  min-height: 0;
}

.chat-thread-header {
  display: grid;
  gap: 0.45rem;
  border-bottom: 1px solid #cfd9d2;
  background: #ffffff;
  padding: 0.55rem 1rem;
}

.chat-thread-title {
  display: flex;
  align-items: flex-start;
  gap: 0.8rem;
  min-width: 0;
}

.chat-thread-title h1,
.chat-thread-title h2 {
  margin: 0;
  overflow-wrap: anywhere;
}

.chat-thread-title h2 {
  font-size: 1rem;
}

.chat-thread-title p {
  margin: 0.1rem 0 0;
  color: var(--app-muted);
  font-size: 0.85rem;
}

.chat-thread-subline {
  font-size: 0.9rem;
}

.chat-thread-avatar,
.chat-message-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #dce8df;
  color: #214a36;
  font-weight: 800;
  text-transform: uppercase;
}

.chat-thread-avatar {
  width: 2.2rem;
  height: 2.2rem;
  font-size: 0.82rem;
}

.chat-thread-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.chat-thread-actions form {
  margin: 0;
}

.secondary-link {
  display: inline-flex;
  align-items: center;
  min-height: 2.35rem;
  border: 1px solid var(--app-border-strong);
  border-radius: 0.42rem;
  background: #fff;
  color: var(--app-text-soft);
  font-weight: 700;
  padding: 0.42rem 0.75rem;
}

.secondary-link:hover {
  border-color: #9eacc5;
  color: var(--app-text);
}

.chat-thread-closed {
  margin: 0;
  font-size: 0.9rem;
}

.chat-message-list {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  overflow: auto;
  padding: 0.8rem;
  background:
    linear-gradient(rgba(238, 243, 239, 0.92), rgba(238, 243, 239, 0.92)),
    repeating-linear-gradient(45deg, #dfe8e2 0, #dfe8e2 1px, transparent 1px, transparent 18px);
}

.chat-message-row {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  max-width: min(62%, 520px);
}

.chat-message-row--own {
  align-self: flex-end;
  justify-content: flex-end;
}

.chat-message-row--system {
  align-self: center;
  max-width: min(86%, 720px);
}

.chat-message-avatar {
  width: 2rem;
  height: 2rem;
  margin-bottom: 0.2rem;
  font-size: 0.82rem;
}

.chat-message-bubble {
  position: relative;
  min-width: 0;
  border: 1px solid #d8e1dc;
  border-radius: 0.5rem 0.5rem 0.5rem 0.12rem;
  background: #ffffff;
  color: var(--app-text);
  padding: 0.22rem 0.52rem 0.18rem;
  box-shadow: 0 0.08rem 0.35rem rgba(31, 41, 55, 0.08);
}

.chat-message-row--own .chat-message-bubble {
  border-color: #b9dfc4;
  border-radius: 0.5rem 0.5rem 0.12rem 0.5rem;
  background: #dcf8c6;
}

.chat-message-row--system .chat-message-bubble {
  border-color: #cdd7e5;
  border-radius: 999px;
  background: #f8fbff;
  padding: 0.5rem 0.85rem;
  text-align: center;
}

.chat-message-meta {
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
  flex-wrap: wrap;
  margin-bottom: 0.12rem;
  color: var(--app-muted);
  font-size: 0.74rem;
}

.chat-message-meta strong {
  color: #243247;
}

.chat-message-row--own .chat-message-meta {
  justify-content: flex-end;
}

.chat-message-text {
  margin: 0;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.chat-attachment {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 0.35rem;
}

.chat-attachment-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}

.chat-message-time {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0.25rem;
  margin-top: 0.1rem;
  color: var(--app-muted);
  font-size: 0.7rem;
  line-height: 1.2;
}

.chat-time-text {
  opacity: 0.6;
}

.chat-read-tick {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: -0.08em;
  color: #9ca3af;
}

.chat-read-tick--read {
  color: #2563eb;
}

.chat-empty-state {
  align-self: center;
  max-width: 26rem;
  margin: auto;
  border: 1px solid #d8e1dc;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.86);
  color: var(--app-muted);
  padding: 0.55rem 0.85rem;
  text-align: center;
}

.chat-composer {
  border-top: 1px solid #cfd9d2;
  background: #f7faf8;
  padding: 0.55rem 0.9rem 0.65rem;
}

.chat-composer form,
form.chat-new-form {
  display: grid;
  gap: 0.45rem;
}

form.chat-new-form {
  gap: 1rem;
}

.chat-composer label,
.chat-new-form label {
  margin: 0;
  font-size: 0.88rem;
}

.chat-composer textarea,
.chat-new-form textarea {
  min-height: 3.8rem;
  border-radius: 0.7rem;
  resize: vertical;
}

.chat-message-actions {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex-wrap: wrap;
  justify-content: flex-start;
}

.chat-attachment-selected {
  max-width: 16rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.88rem;
}

.chat-composer p {
  margin: 0;
  color: var(--app-muted);
  font-weight: 600;
}

.chat-list-table tbody tr {
  background: #fff;
}

.chat-list-table tbody tr:nth-child(even) {
  background: #fbfdfb;
}

.chat-list-table tbody tr:hover {
  background: #edf7f0;
}

.chat-list-table tbody tr.chat-row-urgency-yellow,
.chat-list-table tbody tr.chat-row-urgency-yellow:nth-child(even) {
  background: #fefce8;
}

.chat-list-table tbody tr.chat-row-urgency-yellow:hover {
  background: #fef9c3;
}

.chat-list-table tbody tr.chat-row-urgency-red,
.chat-list-table tbody tr.chat-row-urgency-red:nth-child(even) {
  background: #fff1f1;
}

.chat-list-table tbody tr.chat-row-urgency-red:hover {
  background: #ffe4e6;
}

.chat-list-person {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 13rem;
}

.chat-list-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.35rem;
  height: 2.35rem;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #dce8df;
  color: #214a36;
  font-size: 0.9rem;
  font-weight: 800;
  text-transform: uppercase;
}

.chat-list-main {
  display: grid;
  gap: 0.08rem;
  min-width: 0;
}

.chat-list-main strong,
.chat-list-subject {
  color: #243247;
  overflow-wrap: anywhere;
}

.chat-list-main span {
  color: var(--app-muted);
  font-size: 0.84rem;
  overflow-wrap: anywhere;
}
