.portal-chat-launcher {
  align-items: center;
  background: linear-gradient(135deg, #075da8, #06457c);
  border: 0;
  border-radius: 999px;
  bottom: 22px;
  box-shadow: 0 16px 36px rgba(2, 42, 75, 0.28);
  color: #fff;
  cursor: pointer;
  display: flex;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 850;
  gap: 0.5rem;
  min-height: 50px;
  padding: 0.7rem 1rem;
  position: fixed;
  right: 22px;
  z-index: 8500;
}

.portal-chat-launcher-badge {
  align-items: center;
  background: #ff356f;
  border-radius: 999px;
  display: inline-flex;
  font-size: 0.68rem;
  justify-content: center;
  min-height: 22px;
  min-width: 22px;
  padding: 0 0.35rem;
}

.portal-chat-shell {
  background: #fff;
  border-left: 1px solid #d8e4f0;
  bottom: 0;
  box-shadow: -18px 0 48px rgba(5, 35, 58, 0.18);
  color: #18364d;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  max-width: 100%;
  position: fixed;
  right: 0;
  top: 0;
  transform: translateX(105%);
  transition: transform 0.24s ease;
  width: min(760px, 94vw);
  z-index: 9000;
}

.portal-chat-shell.is-open {
  transform: translateX(0);
}

.portal-chat-header {
  align-items: center;
  background: linear-gradient(135deg, #092b48, #075da8);
  color: #fff;
  display: flex;
  gap: 1rem;
  justify-content: space-between;
  min-height: 76px;
  padding: 0.85rem 1rem;
}

.portal-chat-header div {
  display: grid;
  gap: 0.2rem;
}

.portal-chat-header small {
  opacity: 0.8;
}

.portal-chat-header button,
.portal-chat-conversation-actions button {
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 10px;
  color: inherit;
  cursor: pointer;
  min-height: 40px;
  padding: 0.45rem 0.65rem;
}

.portal-chat-layout {
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr);
  min-height: 0;
}

.portal-chat-list {
  background: #f3f8fc;
  border-right: 1px solid #d8e4f0;
  overflow: auto;
  padding: 0.6rem;
}

.portal-chat-list button {
  background: transparent;
  border: 0;
  border-radius: 12px;
  color: #18364d;
  cursor: pointer;
  display: grid;
  gap: 0.25rem;
  margin-bottom: 0.35rem;
  padding: 0.7rem;
  text-align: left;
  width: 100%;
}

.portal-chat-list button:hover,
.portal-chat-list button.is-active {
  background: #fff;
  box-shadow: 0 7px 18px rgba(5, 35, 58, 0.08);
}

.portal-chat-list button.is-unread strong::after {
  background: #ff356f;
  border-radius: 999px;
  content: "";
  display: inline-block;
  height: 8px;
  margin-left: 7px;
  width: 8px;
}

.portal-chat-list small {
  color: #6b7f8f;
}

.portal-chat-main {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-height: 0;
}

.portal-chat-conversation-header {
  align-items: center;
  border-bottom: 1px solid #d8e4f0;
  display: flex;
  gap: 0.75rem;
  justify-content: space-between;
  min-height: 62px;
  padding: 0.7rem 0.85rem;
}

.portal-chat-conversation-actions {
  display: flex;
  gap: 0.4rem;
}

.portal-chat-conversation-actions button {
  border-color: #d8e4f0;
  color: #476074;
}

.portal-chat-messages {
  background:
    radial-gradient(circle at top right, rgba(32, 208, 164, 0.08), transparent 30%),
    #fbfdff;
  overflow: auto;
  padding: 1rem;
}

.portal-chat-message {
  background: #fff;
  border: 1px solid #d8e4f0;
  border-radius: 6px 16px 16px 16px;
  box-shadow: 0 7px 18px rgba(5, 35, 58, 0.06);
  display: grid;
  gap: 0.35rem;
  margin: 0 0 0.7rem;
  max-width: 86%;
  padding: 0.7rem 0.8rem;
  width: fit-content;
}

.portal-chat-message.is-own {
  background: #e9f5ff;
  border-radius: 16px 6px 16px 16px;
  margin-left: auto;
}

.portal-chat-message.is-system {
  background: #f1f5f8;
  border-radius: 12px;
  color: #5d7384;
  margin-inline: auto;
  max-width: 96%;
  text-align: center;
}

.portal-chat-message p {
  margin: 0;
  white-space: pre-wrap;
}

.portal-chat-message time {
  color: #718596;
  font-size: 0.64rem;
}

.portal-chat-document {
  background: #fff;
  border: 1px solid #cbdbe8;
  border-radius: 14px;
  display: grid;
  gap: 0.6rem;
  margin-top: 0.35rem;
  min-width: min(340px, 70vw);
  padding: 0.8rem;
}

.portal-chat-document header,
.portal-chat-document-total,
.portal-chat-document-actions {
  align-items: center;
  display: flex;
  gap: 0.6rem;
  justify-content: space-between;
}

.portal-chat-document header span {
  background: #edf5ff;
  border-radius: 999px;
  color: #075da8;
  font-size: 0.64rem;
  font-weight: 850;
  padding: 0.35rem 0.5rem;
}

.portal-chat-document-actions {
  flex-wrap: wrap;
  justify-content: flex-start;
}

.portal-chat-document-actions button,
.portal-chat-document-actions a,
.portal-chat-document-actions label {
  background: #edf5ff;
  border: 1px solid #cbdbe8;
  border-radius: 9px;
  color: #075da8;
  cursor: pointer;
  font: inherit;
  font-size: 0.7rem;
  font-weight: 800;
  min-height: 38px;
  padding: 0.48rem 0.62rem;
  text-decoration: none;
}

.portal-chat-document-actions .is-positive {
  background: #ddf8e9;
  border-color: #9fddb9;
  color: #08713c;
}

.portal-chat-attachment-card {
  align-items: center;
  background: rgba(255, 255, 255, 0.76);
  border: 1px solid #cbdbe8;
  border-radius: 12px;
  color: #18364d;
  display: flex;
  gap: 0.65rem;
  max-width: min(330px, 68vw);
  overflow: hidden;
  padding: 0.55rem;
  text-decoration: none;
}

.portal-chat-attachment-card img {
  border-radius: 8px;
  height: 76px;
  object-fit: cover;
  width: 92px;
}

.portal-chat-attachment-card > span:last-child {
  display: grid;
  gap: 0.2rem;
  min-width: 0;
}

.portal-chat-attachment-card strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.portal-chat-attachment-card small {
  color: #718596;
}

.portal-chat-attachment-icon {
  align-items: center;
  background: #fee2e2;
  border-radius: 8px;
  color: #b91c1c;
  display: flex;
  font-size: 0.68rem;
  font-weight: 900;
  height: 46px;
  justify-content: center;
  width: 46px;
}

.portal-chat-composer {
  align-items: end;
  border-top: 1px solid #d8e4f0;
  display: grid;
  gap: 0.55rem;
  grid-template-columns: auto minmax(0, 1fr) auto;
  padding: 0.75rem;
}

.portal-chat-attach {
  align-items: center;
  background: #edf5ff;
  border: 1px solid #cbdbe8;
  border-radius: 11px;
  color: #075da8;
  cursor: pointer;
  display: flex;
  font-size: 1.15rem;
  height: 46px;
  justify-content: center;
  width: 46px;
}

.portal-chat-upload-progress {
  color: #476074;
  grid-column: 1 / -1;
  min-height: 1em;
}

.portal-chat-composer textarea {
  border: 1px solid #cbdbe8;
  border-radius: 12px;
  color: #18364d;
  font: inherit;
  min-height: 46px;
  padding: 0.7rem;
  resize: vertical;
}

.portal-chat-composer button {
  background: #075da8;
  border: 0;
  border-radius: 11px;
  color: #fff;
  cursor: pointer;
  font: inherit;
  font-weight: 850;
  min-height: 46px;
  padding: 0.65rem 0.85rem;
}

.portal-chat-empty,
.portal-chat-loading {
  color: #6b7f8f;
  padding: 1.5rem;
  text-align: center;
}

.portal-chat-dialog-backdrop {
  align-items: center;
  background: rgba(3, 20, 34, 0.66);
  display: flex;
  inset: 0;
  justify-content: center;
  padding: 1rem;
  position: fixed;
  z-index: 9400;
}

.portal-chat-dialog {
  background: #fff;
  border-radius: 18px;
  color: #18364d;
  max-height: 88vh;
  max-width: 620px;
  overflow: auto;
  padding: 1rem;
  width: 100%;
}

.portal-chat-dialog form,
.portal-chat-dialog label {
  display: grid;
  gap: 0.55rem;
}

.portal-chat-dialog select,
.portal-chat-dialog textarea,
.portal-chat-dialog input[type="file"] {
  border: 1px solid #cbdbe8;
  border-radius: 11px;
  color: inherit;
  font: inherit;
  padding: 0.7rem;
}

.portal-chat-dialog label small {
  color: #6b7f8f;
  font-size: 0.76rem;
  line-height: 1.4;
}

.portal-chat-dialog-actions {
  display: flex;
  gap: 0.6rem;
  justify-content: flex-end;
  margin-top: 0.85rem;
}

.portal-chat-dialog-actions button,
.portal-chat-dialog-actions a {
  background: #edf5ff;
  border: 1px solid #cbdbe8;
  border-radius: 10px;
  color: #075da8;
  cursor: pointer;
  font: inherit;
  font-weight: 800;
  min-height: 42px;
  padding: 0.55rem 0.75rem;
  text-decoration: none;
}

.portal-chat-dialog-actions .is-primary {
  background: #075da8;
  color: #fff;
}

html[data-theme="dark"] .portal-chat-shell,
body.admin-dark-mode .portal-chat-shell,
body.platform-dark-mode .portal-chat-shell {
  background: #101e38;
  border-color: rgba(148, 163, 184, 0.24);
  color: #f8fafc;
}

html[data-theme="dark"] .portal-chat-list,
body.admin-dark-mode .portal-chat-list,
body.platform-dark-mode .portal-chat-list {
  background: #0b1730;
  border-color: rgba(148, 163, 184, 0.24);
}

html[data-theme="dark"] .portal-chat-list button,
body.admin-dark-mode .portal-chat-list button,
body.platform-dark-mode .portal-chat-list button {
  color: #f8fafc;
}

html[data-theme="dark"] .portal-chat-list button:hover,
html[data-theme="dark"] .portal-chat-list button.is-active,
body.admin-dark-mode .portal-chat-list button:hover,
body.admin-dark-mode .portal-chat-list button.is-active {
  background: #172945;
}

html[data-theme="dark"] .portal-chat-conversation-header,
html[data-theme="dark"] .portal-chat-composer,
body.admin-dark-mode .portal-chat-conversation-header,
body.admin-dark-mode .portal-chat-composer {
  border-color: rgba(148, 163, 184, 0.24);
}

html[data-theme="dark"] .portal-chat-messages,
body.admin-dark-mode .portal-chat-messages {
  background: #0c192e;
}

html[data-theme="dark"] .portal-chat-message,
body.admin-dark-mode .portal-chat-message {
  background: #172945;
  border-color: rgba(148, 163, 184, 0.24);
}

html[data-theme="dark"] .portal-chat-message.is-own,
body.admin-dark-mode .portal-chat-message.is-own {
  background: #123d60;
}

html[data-theme="dark"] .portal-chat-document,
body.admin-dark-mode .portal-chat-document,
html[data-theme="dark"] .portal-chat-dialog,
body.admin-dark-mode .portal-chat-dialog {
  background: #101e38;
  border-color: rgba(148, 163, 184, 0.24);
  color: #f8fafc;
}

html[data-theme="dark"] .portal-chat-composer textarea,
html[data-theme="dark"] .portal-chat-dialog select,
html[data-theme="dark"] .portal-chat-dialog textarea,
html[data-theme="dark"] .portal-chat-dialog input[type="file"],
body.admin-dark-mode .portal-chat-composer textarea,
body.admin-dark-mode .portal-chat-dialog select,
body.admin-dark-mode .portal-chat-dialog textarea,
body.admin-dark-mode .portal-chat-dialog input[type="file"] {
  background: #0b1730;
  border-color: rgba(148, 163, 184, 0.28);
  color: #f8fafc;
}

html[data-theme="dark"] .portal-chat-dialog label small,
body.admin-dark-mode .portal-chat-dialog label small {
  color: #b8c8dc;
}

@media (max-width: 680px) {
  .portal-chat-launcher {
    bottom: 14px;
    right: 14px;
  }

  .portal-chat-shell {
    width: 100%;
  }

  .portal-chat-layout {
    grid-template-columns: 96px minmax(0, 1fr);
  }

  .portal-chat-list button {
    padding: 0.55rem;
  }

  .portal-chat-list button small {
    display: none;
  }

  .portal-chat-document {
    min-width: 0;
    width: 100%;
  }

  .portal-chat-message {
    max-width: 96%;
  }
}
