/* Chat paciente ↔ profissional */

.chat-page {
  max-width: none !important;
  width: 100%;
  height: calc(100vh - 8.5rem);
  min-height: 28rem;
}

.chat-layout {
  display: grid;
  grid-template-columns: minmax(240px, 320px) 1fr;
  gap: 0;
  height: 100%;
  border: 1px solid var(--lm-border);
  border-radius: 1rem;
  overflow: hidden;
  background: var(--lm-surface);
}

.chat-sidebar {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--lm-border);
  background: color-mix(in srgb, var(--lm-surface) 92%, var(--lm-bg));
  min-height: 0;
}

.chat-sidebar-head {
  padding: 1rem 1.1rem 0.75rem;
  border-bottom: 1px solid var(--lm-border);
}

.chat-sidebar-head .pro-title {
  font-size: 1.15rem;
}

.chat-search-wrap {
  position: relative;
  display: block;
  margin-top: 0.75rem;
}

.chat-search-wrap > i {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--lm-muted);
  pointer-events: none;
  font-size: 0.9rem;
}

.chat-search {
  width: 100%;
  padding-left: 2.15rem;
  font-size: 0.9rem;
}

.chat-list-empty,
.chat-thread-empty {
  text-align: center;
  padding: 1.5rem 1rem;
  color: var(--lm-muted);
}

.chat-list-empty > i,
.chat-thread-empty > i {
  display: block;
  font-size: 1.5rem;
  opacity: 0.55;
  margin-bottom: 0.4rem;
}

.chat-list-empty p,
.chat-thread-empty p {
  margin: 0.2rem 0;
}

.chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
  min-height: 0;
}

.chat-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  padding: 0.7rem 0.75rem;
  border-radius: 0.85rem;
  cursor: pointer;
  color: inherit;
  font: inherit;
  transition: background 0.15s ease;
}

.chat-item:hover {
  background: color-mix(in srgb, var(--lm-accent) 10%, transparent);
}

.chat-item.is-active {
  background: color-mix(in srgb, var(--lm-accent) 16%, transparent);
}

.chat-item-avatar,
.chat-peer-avatar {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  background: color-mix(in srgb, var(--lm-accent) 18%, var(--lm-surface));
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--lm-text);
}

.chat-item-avatar img,
.chat-peer-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.chat-item-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.chat-item-body strong {
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-item-preview {
  font-size: 0.8rem;
  color: var(--lm-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-item-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.25rem;
  flex-shrink: 0;
}

.chat-item-time {
  font-size: 0.7rem;
  color: var(--lm-muted);
}

.chat-unread-badge {
  min-width: 1.15rem;
  height: 1.15rem;
  padding: 0 0.3rem;
  border-radius: 999px;
  background: var(--lm-danger, #dc2626);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 1.15rem;
  text-align: center;
}

.chat-thread {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  background:
    radial-gradient(ellipse at top right, color-mix(in srgb, var(--lm-accent) 8%, transparent), transparent 55%),
    var(--lm-bg);
}

.chat-thread-head {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--lm-border);
  background: var(--lm-surface);
}

.chat-back {
  display: none;
  padding: 0.35rem 0.55rem;
}

.chat-peer-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-peer-meta strong {
  font-size: 1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-peer-meta span {
  font-size: 0.8rem;
  color: var(--lm-muted);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  min-height: 0;
}

.chat-bubble {
  max-width: min(78%, 36rem);
  padding: 0.65rem 0.85rem;
  border-radius: 1rem;
  font-size: 0.92rem;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
}

.chat-bubble.is-mine {
  align-self: flex-end;
  background: color-mix(in srgb, var(--lm-accent) 22%, var(--lm-surface));
  border-bottom-right-radius: 0.35rem;
}

.chat-bubble.is-theirs {
  align-self: flex-start;
  background: var(--lm-surface);
  border: 1px solid var(--lm-border);
  border-bottom-left-radius: 0.35rem;
}

.chat-bubble-time {
  display: block;
  margin-top: 0.3rem;
  font-size: 0.68rem;
  color: var(--lm-muted);
  text-align: right;
}

.chat-bubble-text {
  white-space: pre-wrap;
}

.chat-bubble.has-attach {
  max-width: min(85%, 22rem);
  padding: 0.55rem 0.65rem;
}

.chat-attach-image {
  display: block;
  width: 100%;
  margin-bottom: 0.35rem;
  padding: 0;
  border: 0;
  border-radius: 0.65rem;
  overflow: hidden;
  background: transparent;
  cursor: zoom-in;
}

.chat-attach-image img {
  display: block;
  max-width: 100%;
  max-height: 240px;
  width: 100%;
  object-fit: cover;
}

.chat-lightbox {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: grid;
  place-items: center;
  padding: 1.25rem;
  background: rgba(0, 0, 0, 0.72);
}

.chat-lightbox[hidden] {
  display: none !important;
}

.chat-lightbox-dialog {
  position: relative;
  max-width: min(96vw, 960px);
  max-height: 90vh;
}

.chat-lightbox-dialog img {
  display: block;
  max-width: 96vw;
  max-height: 90vh;
  border-radius: 0.75rem;
  object-fit: contain;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}

.chat-lightbox-close {
  position: absolute;
  top: -0.5rem;
  right: -0.5rem;
  z-index: 1;
  width: 2.25rem;
  height: 2.25rem;
  border: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  cursor: pointer;
  background: var(--lm-surface);
  color: var(--lm-text);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}

.chat-lightbox-close:hover {
  color: var(--lm-primary);
}

.chat-attach-file {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.55rem 0.65rem;
  margin-bottom: 0.35rem;
  border-radius: 0.65rem;
  text-decoration: none;
  color: inherit;
  background: color-mix(in srgb, var(--lm-bg) 55%, transparent);
  border: 1px solid var(--lm-border);
}

.chat-attach-file i {
  font-size: 1.35rem;
  color: var(--lm-primary);
}

.chat-attach-file span {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
}

.chat-attach-file strong {
  font-size: 0.88rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-attach-file small {
  color: var(--lm-muted);
  font-size: 0.75rem;
}

.chat-attach-preview {
  padding: 0.55rem 1rem 0;
  border-top: 1px solid var(--lm-border);
  background: var(--lm-surface);
}

.chat-attach-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  max-width: 100%;
  padding: 0.4rem 0.55rem;
  border-radius: 0.75rem;
  border: 1px solid var(--lm-border);
  background: color-mix(in srgb, var(--lm-primary) 8%, var(--lm-surface));
  font-size: 0.85rem;
}

.chat-attach-chip img {
  width: 2rem;
  height: 2rem;
  object-fit: cover;
  border-radius: 0.4rem;
}

.chat-attach-chip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-attach-clear {
  border: 0;
  background: transparent;
  color: var(--lm-muted);
  cursor: pointer;
  padding: 0.15rem;
  line-height: 1;
}

.chat-attach-clear:hover {
  color: var(--lm-danger, #dc2626);
}

.chat-composer {
  display: flex;
  gap: 0.55rem;
  align-items: flex-end;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--lm-border);
  background: var(--lm-surface);
}

.chat-attach-btn {
  flex-shrink: 0;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 50%;
  display: grid;
  place-items: center;
  cursor: pointer;
  color: var(--lm-muted);
  border: 1px solid var(--lm-border);
  background: transparent;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.chat-attach-btn:hover {
  color: var(--lm-primary);
  border-color: var(--lm-primary);
}

.chat-attach-btn i {
  font-size: 1.15rem;
}

.chat-input {
  flex: 1;
  resize: none;
  min-height: 2.6rem;
  max-height: 8rem;
  line-height: 1.35;
  padding-top: 0.65rem;
  padding-bottom: 0.65rem;
}

.chat-send {
  flex-shrink: 0;
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
}

.chat-empty {
  display: grid;
  place-items: center;
  gap: 0.5rem;
  color: var(--lm-muted);
  padding: 2rem;
  text-align: center;
}

.chat-empty i {
  font-size: 2rem;
  opacity: 0.55;
}

.chat-empty p {
  margin: 0;
}

.app-nav a {
  position: relative;
}

.app-nav .app-notif-badge,
.app-nav .chat-nav-badge {
  position: absolute;
  top: 0.45rem;
  right: 0.55rem;
  min-width: 1.05rem;
  height: 1.05rem;
  padding: 0 0.22rem;
  border-radius: 999px;
  background: var(--lm-danger, #dc2626);
  color: #fff;
  font-size: 0.62rem;
  font-weight: 700;
  line-height: 1.05rem;
  text-align: center;
}

@media (max-width: 820px) {
  .chat-page {
    height: calc(100vh - 10rem);
  }

  .chat-layout {
    grid-template-columns: 1fr;
  }

  .chat-sidebar {
    border-right: 0;
  }

  .chat-layout.is-thread-open .chat-sidebar,
  .chat-layout.is-thread-open .chat-empty {
    display: none;
  }

  .chat-layout:not(.is-thread-open) .chat-thread {
    display: none;
  }

  .chat-back {
    display: inline-flex;
  }

  .chat-empty {
    display: none;
  }
}
