.chats-layout {
  --chat-bg: #eef3fb;
  --chat-border: #d2deef;
  --chat-ink: #10233f;
  --chat-muted: #5f718b;
  --chat-brand: #1f66e5;
  --chat-brand-soft: #e7f0ff;
  --chat-in: #ffffff;
  --chat-out: #d9f6e7;
  --chat-out-border: #97dbbe;
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 16px;
}

.chats-layout .card {
  border-radius: 16px;
  border: 1px solid var(--chat-border);
  background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
  box-shadow: 0 8px 24px rgba(16, 35, 63, 0.06);
}

.chats-layout .card .card__header {
  align-items: center;
}

.chat-header-actions {
  display: flex;
  gap: 8px;
}

.card .card__header h3 {
  margin: 0;
}

.chat-owner {
  margin: 4px 0 10px;
  color: var(--chat-muted);
  font-size: 13px;
}

.chat-wisp {
  margin: 0 0 10px;
  padding: 10px 12px;
  border: 1px solid var(--chat-border);
  background: #f7faff;
  border-radius: 12px;
  color: #29405f;
  font-size: 13px;
}

.chat-wisp strong,
.chat-wisp small {
  display: block;
}

.chat-wisp-actions {
  margin: 0 0 10px;
}

.chat-wisp strong {
  font-size: 13px;
}

.chat-wisp small {
  margin-top: 2px;
  color: var(--chat-muted);
}

.chat-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

.chat-item {
  width: 100%;
  text-align: left;
  border: 1px solid var(--chat-border);
  border-radius: 14px;
  padding: 12px;
  background: #fff;
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.2s, background-color 0.2s;
}

.chat-item:hover {
  border-color: #b8ccec;
  box-shadow: 0 10px 22px rgba(16, 35, 63, 0.08);
  transform: translateY(-1px);
}

.chat-item.is-active {
  border-color: var(--chat-brand);
  background: linear-gradient(180deg, #f3f8ff 0%, var(--chat-brand-soft) 100%);
  box-shadow: 0 12px 24px rgba(31, 102, 229, 0.2);
}

.chat-item strong,
.chat-item small {
  display: block;
}

.chat-item strong {
  color: var(--chat-ink);
  font-size: 16px;
  font-weight: 700;
}

.chat-item small {
  color: var(--chat-muted);
  line-height: 1.25;
  font-size: 13px;
}

#chatTitle {
  display: block;
  max-width: 84%;
  color: var(--chat-ink);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.chat-messages {
  height: 460px;
  overflow: auto;
  border: 1px solid var(--chat-border);
  border-radius: 16px;
  padding: 14px;
  background:
    radial-gradient(circle at 0 0, rgba(31, 102, 229, 0.06) 0%, transparent 38%),
    radial-gradient(circle at 100% 100%, rgba(16, 185, 129, 0.08) 0%, transparent 42%),
    var(--chat-bg);
}

.chat-messages::-webkit-scrollbar {
  width: 10px;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: #b9c7dd;
  border-radius: 999px;
  border: 2px solid #edf2fb;
}

.msg {
  margin-bottom: 12px;
  max-width: 80%;
}

.msg p {
  margin: 0;
  padding: 10px 13px;
  border-radius: 14px;
  font-size: 15px;
  line-height: 1.35;
  color: #172b45;
}

.msg small {
  color: var(--chat-muted);
  font-size: 12px;
  margin-top: 5px;
  display: block;
}

.msg__media {
  display: block;
  max-width: 100%;
  border-radius: 12px;
  border: 1px solid #cbd8ea;
  background: #fff;
}

.msg__media--image,
.msg__media--video {
  width: min(320px, 100%);
}

.msg__media--audio {
  width: min(320px, 100%);
}

.msg__media--sticker {
  width: 120px;
  height: 120px;
  object-fit: contain;
  border: none;
  background: transparent;
}

.msg__file {
  display: inline-block;
  color: #1f66e5;
  text-decoration: none;
  font-weight: 600;
  padding: 6px 0;
}

.msg--in p {
  background: var(--chat-in);
  border: 1px solid #cad8eb;
  border-top-left-radius: 6px;
}

.msg--out {
  margin-left: auto;
  text-align: right;
}

.msg--out p {
  background: var(--chat-out);
  border: 1px solid var(--chat-out-border);
  border-top-right-radius: 6px;
}

.chat-form {
  margin-top: 12px;
  display: flex;
  gap: 8px;
  align-items: center;
}

.chat-file-input {
  display: none;
}

.chat-tool-btn {
  width: 40px;
  height: 40px;
  border: 1px solid #c6d4ea;
  border-radius: 12px;
  background: #fff;
  color: #486486;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s, color 0.2s, background-color 0.2s;
}

.chat-tool-btn:hover {
  border-color: #8eb1e8;
  color: #1f66e5;
  box-shadow: 0 0 0 3px rgba(31, 102, 229, 0.12);
}

.chat-tool-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
}

.chat-tool-btn svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.chat-tool-btn--mic.is-recording {
  color: #fff;
  background: #ef4444;
  border-color: #ef4444;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.2);
}

.chat-record-state {
  min-width: 0;
  font-size: 12px;
  color: #ef4444;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 0;
  transition: max-width 0.2s ease;
}

.chat-record-state.is-visible {
  max-width: 120px;
}

.chat-form input {
  flex: 1;
  border-radius: 12px;
  border: 1px solid #c6d4ea;
  padding: 11px 13px;
  background: #fff;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.chat-form input:focus {
  outline: none;
  border-color: #7ea8ee;
  box-shadow: 0 0 0 3px rgba(31, 102, 229, 0.16);
}

.msg-skel {
  margin-bottom: 10px;
  max-width: 80%;
}

.msg-skel span {
  display: block;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(90deg, #dbe5f4 25%, #edf3fc 37%, #dbe5f4 63%);
  background-size: 400% 100%;
  animation: skelPulse 1.15s ease infinite;
}

.msg-skel--out {
  margin-left: auto;
}

.modal {
  position: fixed;
  inset: 0;
  display: none;
  z-index: 90;
}

.modal.is-open {
  display: block;
}

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
}

.modal__dialog {
  position: relative;
  width: min(700px, calc(100vw - 32px));
  margin: 8vh auto 0;
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 20px 50px rgba(2, 6, 23, 0.3);
  padding: 16px;
}

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.modal__header h3 {
  margin: 0;
}

.modal__close {
  border: 1px solid #cbd5e1;
  background: #fff;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
}

.chat-cliente-grid {
  display: grid;
  gap: 10px;
}

.chat-cliente-grid .field {
  display: grid;
  gap: 6px;
}

.chat-cliente-grid select {
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  padding: 9px 10px;
  background: #fff;
}

.chat-cliente-item {
  border: 1px solid var(--chat-border);
  background: #f9fbff;
  border-radius: 10px;
  padding: 10px 12px;
}

.chat-cliente-item strong,
.chat-cliente-item span {
  display: block;
}

.chat-cliente-item strong {
  color: #0f2f57;
  font-size: 12px;
  margin-bottom: 2px;
}

.chat-cliente-item span {
  color: #334155;
  white-space: pre-wrap;
}

@keyframes skelPulse {
  0% { background-position: 100% 0; }
  100% { background-position: 0 0; }
}

@media (max-width: 900px) {
  .chats-layout {
    grid-template-columns: 1fr;
  }

  .chat-header-actions {
    width: 100%;
    justify-content: flex-end;
    flex-wrap: wrap;
  }

  .chat-messages {
    height: 420px;
  }
}
