/**
 * Chat IA global — drawer lateral derecho
 * @author Aris Mota <soy@aris.do>
 * @version 3.82.0
 */

.crm-chat-root {
  --crm-chat-navy: #004481;
  --crm-chat-cyan: #00a9e0;
  --crm-chat-bg: #f4f7f9;
  --crm-chat-surface: #ffffff;
  --crm-chat-text: #1a2b3c;
  --crm-chat-muted: #6b7c8f;
  --crm-chat-width: min(420px, 100vw);
  font-family: Inter, system-ui, sans-serif;
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 1080;
}

.crm-chat-root.is-open {
  pointer-events: auto;
}

.crm-chat-overlay {
  position: absolute;
  inset: 0;
  background: rgba(15, 25, 35, 0.35);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.crm-chat-root.is-open .crm-chat-overlay {
  opacity: 1;
}

.crm-chat-drawer {
  position: absolute;
  top: 0;
  right: 0;
  width: var(--crm-chat-width);
  height: 100vh;
  height: 100dvh;
  background: var(--crm-chat-surface);
  color: var(--crm-chat-text);
  display: flex;
  flex-direction: column;
  box-shadow: -8px 0 32px rgba(0, 68, 129, 0.12);
  transform: translateX(100%);
  transition: transform 0.22s ease;
}

.crm-chat-root.is-open .crm-chat-drawer {
  transform: translateX(0);
}

.crm-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  background: linear-gradient(135deg, var(--crm-chat-navy) 0%, #005c9e 100%);
  color: #fff;
  flex-shrink: 0;
}

.crm-chat-header-main {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}

.crm-chat-header-main h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.crm-chat-header-main .ti {
  font-size: 1.35rem;
  opacity: 0.95;
}

.crm-chat-header-actions {
  display: flex;
  gap: 0.25rem;
}

.crm-chat-btn-icon {
  appearance: none;
  border: 0;
  background: transparent;
  color: #fff;
  width: 2rem;
  height: 2rem;
  border-radius: 0.35rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0.9;
}

.crm-chat-btn-icon:hover,
.crm-chat-btn-icon:focus {
  background: rgba(255, 255, 255, 0.15);
  opacity: 1;
  outline: none;
}

.crm-chat-ctx {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  background: var(--crm-chat-bg);
  border-bottom: 1px solid #e2e8f0;
  font-size: 0.78rem;
  flex-shrink: 0;
}

.crm-chat-ctx[hidden] {
  display: none !important;
}

.crm-chat-ctx-label {
  color: var(--crm-chat-cyan);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.68rem;
}

.crm-chat-ctx-text {
  color: var(--crm-chat-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.crm-chat-messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 1rem;
  background: var(--crm-chat-bg);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.crm-chat-msg {
  max-width: 100%;
  font-size: 0.9rem;
  line-height: 1.45;
}

.crm-chat-msg--user {
  align-self: flex-end;
  background: var(--crm-chat-navy);
  color: #fff;
  padding: 0.65rem 0.85rem;
  border-radius: 0.85rem 0.85rem 0.2rem 0.85rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.crm-chat-msg--assistant {
  align-self: stretch;
  background: var(--crm-chat-surface);
  border: 1px solid #e2e8f0;
  padding: 0.75rem 0.9rem;
  border-radius: 0.2rem 0.85rem 0.85rem 0.85rem;
  word-break: break-word;
}

.crm-chat-msg--assistant p {
  margin: 0 0 0.5rem;
}

.crm-chat-msg--assistant p:last-child {
  margin-bottom: 0;
}

.crm-chat-msg--assistant ul,
.crm-chat-msg--assistant ol {
  margin: 0.35rem 0 0.5rem 1.1rem;
  padding: 0;
}

.crm-chat-msg--system {
  align-self: center;
  color: var(--crm-chat-muted);
  font-size: 0.8rem;
  text-align: center;
}

.crm-chat-msg--thinking {
  color: var(--crm-chat-muted);
  font-style: italic;
  font-size: 0.85rem;
}

.crm-chat-actions {
  margin-top: 0.75rem;
  padding-top: 0.65rem;
  border-top: 1px solid #e8eef4;
}

.crm-chat-actions-title {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--crm-chat-navy);
  margin-bottom: 0.4rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.crm-chat-action-item {
  font-size: 0.82rem;
  padding: 0.4rem 0;
  border-bottom: 1px solid #f0f4f8;
  color: var(--crm-chat-text);
}

.crm-chat-action-item:last-of-type {
  border-bottom: 0;
}

.crm-chat-action-tipo {
  display: inline-block;
  font-weight: 600;
  color: var(--crm-chat-cyan);
  margin-right: 0.35rem;
}

.crm-chat-action-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.65rem;
}

.crm-chat-action-btns button {
  appearance: none;
  border: 1px solid #d0dae6;
  background: #fff;
  color: var(--crm-chat-navy);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.35rem 0.7rem;
  border-radius: 0.35rem;
  cursor: pointer;
}

.crm-chat-action-btns button.crm-chat-btn-yes {
  background: var(--crm-chat-navy);
  border-color: var(--crm-chat-navy);
  color: #fff;
}

.crm-chat-action-btns button.crm-chat-btn-no {
  color: #8a3b3b;
  border-color: #e8c4c4;
}

.crm-chat-action-btns button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.crm-chat-edit-wrap {
  margin-top: 0.5rem;
}

.crm-chat-edit-wrap textarea {
  width: 100%;
  min-height: 120px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.75rem;
  border: 1px solid #d0dae6;
  border-radius: 0.35rem;
  padding: 0.5rem;
  resize: vertical;
}

.crm-chat-form {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.75rem 1rem 1rem;
  border-top: 1px solid #e2e8f0;
  background: var(--crm-chat-surface);
  flex-shrink: 0;
}

.crm-chat-input {
  flex: 1 1 auto;
  border: 1px solid #d0dae6;
  border-radius: 0.5rem;
  padding: 0.55rem 0.7rem;
  font-size: 0.9rem;
  resize: none;
  min-height: 2.6rem;
  max-height: 8rem;
  font-family: inherit;
  color: var(--crm-chat-text);
  background: var(--crm-chat-bg);
}

.crm-chat-input:focus {
  outline: none;
  border-color: var(--crm-chat-cyan);
  box-shadow: 0 0 0 2px rgba(0, 169, 224, 0.2);
}

.crm-chat-send {
  appearance: none;
  border: 0;
  background: var(--crm-chat-cyan);
  color: #fff;
  width: 2.6rem;
  height: 2.6rem;
  border-radius: 0.5rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

.crm-chat-send:hover {
  filter: brightness(1.05);
}

.crm-chat-send:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.crm-chat-send .ti {
  font-size: 1.15rem;
}

.crm-chat-msg a {
  color: var(--crm-chat-cyan);
  font-weight: 600;
}

body.crm-chat-open {
  overflow: hidden;
}

#crm-chat-toggle.nav-link {
  color: inherit;
}

#crm-chat-toggle .ti {
  font-size: 1.15rem;
  vertical-align: -0.1em;
}

@media (max-width: 550px) {
  .crm-chat-drawer {
    width: 100vw;
  }
}
