/* =====================================================
   Chat IA Municipal - CSS Moderno y Profesional
   Inspirado en ChatGPT, Intercom, Crisp, Drift
   ===================================================== */

.ai-agent-root,
.ai-agent-root * {
  box-sizing: border-box;
}

.ai-agent-hidden {
  display: none !important;
}

/* =========================
   Floating toggle button
========================= */
.ai-agent-toggle-button {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: 62px;
  height: 62px;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  z-index: 999999;
  background: linear-gradient(135deg, #2f855a, #38a169);
  color: #fff;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.22);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .2s ease, box-shadow .2s ease, opacity .2s ease;
  font-size: 0;
  padding: 0;
  line-height: 1;
}

.ai-agent-toggle-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 16px 34px rgba(0, 0, 0, 0.26);
}

.ai-agent-toggle-button:active {
  transform: translateY(0);
}

.ai-agent-toggle-button svg,
.ai-agent-toggle-button i {
  width: 26px;
  height: 26px;
  stroke: currentColor;
}

/* Ocultar botón cuando el widget está abierto */
.ai-agent-widget.ai-agent-open ~ .ai-agent-toggle-button {
  opacity: 0;
  pointer-events: none;
}

/* =========================
   Floating chat window
========================= */
.ai-agent-widget {
  position: fixed;
  right: 20px;
  bottom: 96px;
  width: 390px;
  max-width: calc(100vw - 24px);
  height: 620px;
  max-height: calc(100vh - 120px);
  z-index: 999998;
  border-radius: 20px;
  overflow: hidden;
  background: #ffffff;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.22);
  border: 1px solid rgba(15, 23, 42, 0.08);
  display: flex;
  flex-direction: column;
  transform: translateY(16px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
}

.ai-agent-widget.ai-agent-open {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
}

/* =========================
   Modal overlay + window
========================= */
.ai-agent-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 999999;
  background: rgba(15, 23, 42, 0.42);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease;
}

.ai-agent-modal-overlay.ai-agent-open {
  opacity: 1;
  pointer-events: auto;
}

.ai-agent-modal {
  width: 1024px;
  max-width: 100%;
  height: 680px;
  max-height: calc(100vh - 40px);
  border-radius: 22px;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(15, 23, 42, 0.08);
  display: flex;
  flex-direction: column;
  transform: translateY(10px) scale(.98);
  transition: transform .25s ease;
}

.ai-agent-modal-overlay.ai-agent-open .ai-agent-modal {
  transform: translateY(0) scale(1);
}

/* =========================
   Shared chat window parts
========================= */
.ai-agent-window {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: #ffffff;
}

.ai-agent-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid rgba(15, 23, 42, 0.08);
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
}

.ai-agent-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.ai-agent-avatar {
  width: 42px;
  height: 42px;
  border-radius: 999px;
  background: linear-gradient(135deg, #2f855a, #68d391);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 8px 22px rgba(47, 133, 90, 0.25);
  font-weight: 700;
  font-size: 18px;
}

.ai-agent-title-wrap {
  min-width: 0;
}

.ai-agent-title {
  margin: 0;
  font-size: 15px;
  line-height: 1.2;
  font-weight: 700;
  color: #0f172a;
}

.ai-agent-subtitle {
  margin-top: 2px;
  font-size: 12px;
  color: #64748b;
}

.ai-agent-close {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: #475569;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background .2s ease, color .2s ease;
  font-size: 0;
  padding: 0;
  line-height: 1;
}

.ai-agent-close:hover {
  background: rgba(15, 23, 42, 0.06);
  color: #0f172a;
}

.ai-agent-close svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
}

.ai-agent-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  background:
    radial-gradient(circle at top, rgba(56, 161, 105, 0.04), transparent 30%),
    #f8fafc;
  scroll-behavior: smooth;
}

/* Scrollbar personalizado */
.ai-agent-body::-webkit-scrollbar {
  width: 6px;
}

.ai-agent-body::-webkit-scrollbar-track {
  background: transparent;
}

.ai-agent-body::-webkit-scrollbar-thumb {
  background: rgba(15, 23, 42, 0.12);
  border-radius: 3px;
}

.ai-agent-body::-webkit-scrollbar-thumb:hover {
  background: rgba(15, 23, 42, 0.18);
}

.ai-agent-messages {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 100%;
}

.ai-agent-row {
  display: flex;
  width: 100%;
}

.ai-agent-row-user {
  justify-content: flex-end;
}

.ai-agent-row-assistant {
  justify-content: flex-start;
}

.ai-agent-message {
  max-width: 82%;
  padding: 12px 14px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.55;
  word-break: break-word;
  white-space: pre-wrap;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.04);
  animation: ai-agent-fade-up .22s ease;
}

.ai-agent-message-user {
  background: linear-gradient(135deg, #2f855a, #38a169);
  color: #ffffff;
  border-bottom-right-radius: 6px;
}

.ai-agent-message-assistant {
  background: #ffffff;
  color: #0f172a;
  border: 1px solid rgba(15, 23, 42, 0.08);
  border-bottom-left-radius: 6px;
}

.ai-agent-message-assistant .ai-agent-markdown {
  white-space: normal;
}

.ai-agent-message-assistant .ai-agent-markdown > *:first-child {
  margin-top: 0;
}

.ai-agent-message-assistant .ai-agent-markdown > *:last-child {
  margin-bottom: 0;
}

.ai-agent-message-assistant .ai-agent-markdown p,
.ai-agent-message-assistant .ai-agent-markdown ul,
.ai-agent-message-assistant .ai-agent-markdown ol,
.ai-agent-message-assistant .ai-agent-markdown blockquote,
.ai-agent-message-assistant .ai-agent-markdown pre,
.ai-agent-message-assistant .ai-agent-markdown .ai-agent-markdown-table-wrap {
  margin: 0 0 10px;
}

.ai-agent-message-assistant .ai-agent-markdown .ai-agent-markdown-table-wrap {
  overflow-x: auto;
}

.ai-agent-message-assistant .ai-agent-markdown table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  border: 1px solid rgba(15, 23, 42, 0.12);
  border-radius: 10px;
  overflow: hidden;
}

.ai-agent-message-assistant .ai-agent-markdown thead {
  background: #e2e8f0;
}

.ai-agent-message-assistant .ai-agent-markdown th,
.ai-agent-message-assistant .ai-agent-markdown td {
  border-bottom: 1px solid rgba(15, 23, 42, 0.1);
  border-right: 1px solid rgba(15, 23, 42, 0.08);
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
}

.ai-agent-message-assistant .ai-agent-markdown th:last-child,
.ai-agent-message-assistant .ai-agent-markdown td:last-child {
  border-right: none;
}

.ai-agent-message-assistant .ai-agent-markdown tbody tr:nth-child(even) {
  background: #f8fafc;
}

.ai-agent-message-assistant .ai-agent-markdown tbody tr:last-child td {
  border-bottom: none;
}

.ai-agent-message-assistant .ai-agent-markdown h1,
.ai-agent-message-assistant .ai-agent-markdown h2,
.ai-agent-message-assistant .ai-agent-markdown h3,
.ai-agent-message-assistant .ai-agent-markdown h4,
.ai-agent-message-assistant .ai-agent-markdown h5,
.ai-agent-message-assistant .ai-agent-markdown h6 {
  margin: 0 0 8px;
  line-height: 1.25;
  color: #0b1220;
}

.ai-agent-message-assistant .ai-agent-markdown h1 { font-size: 1.18em; }
.ai-agent-message-assistant .ai-agent-markdown h2 { font-size: 1.12em; }
.ai-agent-message-assistant .ai-agent-markdown h3 { font-size: 1.06em; }

.ai-agent-message-assistant .ai-agent-markdown ul,
.ai-agent-message-assistant .ai-agent-markdown ol {
  padding-left: 20px;
}

.ai-agent-message-assistant .ai-agent-markdown li + li {
  margin-top: 4px;
}

.ai-agent-message-assistant .ai-agent-markdown a {
  color: #1d4ed8;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.ai-agent-message-assistant .ai-agent-markdown code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace;
  font-size: 12px;
  background: #f1f5f9;
  color: #0f172a;
  border: 1px solid rgba(15, 23, 42, 0.1);
  border-radius: 7px;
  padding: 2px 6px;
}

.ai-agent-message-assistant .ai-agent-markdown blockquote {
  border-left: 3px solid #93c5fd;
  background: #eff6ff;
  margin-left: 0;
  margin-right: 0;
  padding: 8px 10px;
  border-radius: 8px;
  color: #1e3a8a;
}

.ai-agent-code-block {
  position: relative;
  margin: 0 0 12px;
}

.ai-agent-code-block pre {
  margin: 0;
  padding: 12px 12px 12px;
  border-radius: 12px;
  overflow-x: auto;
  background: #0f172a;
  border: 1px solid rgba(148, 163, 184, 0.35);
}

.ai-agent-code-block pre code {
  background: transparent;
  border: none;
  color: #e2e8f0;
  padding: 0;
  font-size: 12px;
  line-height: 1.55;
  white-space: pre;
}

.ai-agent-copy-code {
  position: absolute;
  top: 8px;
  right: 8px;
  border: 1px solid rgba(148, 163, 184, 0.45);
  background: rgba(15, 23, 42, 0.72);
  color: #e2e8f0;
  border-radius: 8px;
  font-size: 11px;
  line-height: 1;
  padding: 7px 9px;
  cursor: pointer;
}

.ai-agent-copy-code:hover {
  background: rgba(15, 23, 42, 0.9);
}

.ai-agent-message-assistant .katex-display {
  margin: 0.4em 0 0.7em;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 2px;
}

.ai-agent-message-assistant .katex {
  font-size: 1.02em;
}

.ai-agent-footer {
  padding: 14px 16px 16px;
  border-top: 1px solid rgba(15, 23, 42, 0.08);
  background: #ffffff;
}

.ai-agent-input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: #f8fafc;
  border: 1px solid rgba(15, 23, 42, 0.10);
  border-radius: 18px;
  padding: 10px;
  transition: border-color .2s ease, box-shadow .2s ease, background .2s ease;
}

.ai-agent-input-wrap:focus-within {
  border-color: rgba(47, 133, 90, 0.45);
  box-shadow: 0 0 0 4px rgba(47, 133, 90, 0.10);
  background: #ffffff;
}

.ai-agent-input {
  flex: 1;
  min-height: 42px;
  max-height: 140px;
  resize: none;
  border: none;
  outline: none;
  background: transparent;
  font-size: 14px;
  line-height: 1.5;
  color: #0f172a;
  padding: 8px 6px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
}

.ai-agent-input::placeholder {
  color: #94a3b8;
}

.ai-agent-send-button {
  border: none;
  outline: none;
  width: 44px;
  height: 44px;
  border-radius: 14px;
  cursor: pointer;
  flex-shrink: 0;
  background: linear-gradient(135deg, #2f855a, #38a169);
  color: #ffffff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform .2s ease, box-shadow .2s ease, opacity .2s ease;
  box-shadow: 0 10px 22px rgba(47, 133, 90, 0.22);
  font-size: 0;
  padding: 0;
  line-height: 1;
}

.ai-agent-send-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 14px 28px rgba(47, 133, 90, 0.28);
}

.ai-agent-send-button:disabled {
  opacity: .55;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.ai-agent-send-button svg,
.ai-agent-send-button i {
  width: 18px;
  height: 18px;
  stroke: currentColor;
}

/* =========================
   Typing indicator
========================= */
.ai-agent-typing {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 12px;
  border-radius: 16px;
  background: #ffffff;
  border: 1px solid rgba(15, 23, 42, 0.08);
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.04);
}

.ai-agent-typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: #94a3b8;
  animation: ai-agent-bounce 1.2s infinite ease-in-out;
}

.ai-agent-typing-dot:nth-child(2) {
  animation-delay: .15s;
}

.ai-agent-typing-dot:nth-child(3) {
  animation-delay: .3s;
}

/* =========================
   Utility
========================= */
.ai-agent-empty {
  color: #64748b;
  font-size: 13px;
  text-align: center;
  padding: 18px;
}

.ai-agent-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

/* =========================
   Animations
========================= */
@keyframes ai-agent-bounce {
  0%, 80%, 100% {
    transform: scale(.75);
    opacity: .45;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes ai-agent-fade-up {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* =========================
   Mobile
========================= */
@media (max-width: 640px) {
  .ai-agent-widget {
    right: 12px;
    bottom: 84px;
    width: calc(100vw - 24px);
    height: min(78vh, 640px);
    border-radius: 18px;
  }

  .ai-agent-modal-overlay {
    padding: 10px;
  }

  .ai-agent-modal {
    width: 100%;
    height: calc(100vh - 20px);
    max-height: calc(100vh - 20px);
    border-radius: 18px;
  }

  .ai-agent-toggle-button {
    right: 12px;
    bottom: 12px;
  }

  .ai-agent-message {
    max-width: 90%;
  }

  .ai-agent-header,
  .ai-agent-body,
  .ai-agent-footer {
    padding-left: 14px;
    padding-right: 14px;
  }
}

@media (max-width: 480px) {
	#ai-agent-root.ai-agent-floating_agent {
		bottom: 10px;
		right: 10px;
	}

	.ai-agent-chat-container {
		width: calc(100vw - 16px);
		bottom: 70px;
	}

	.ai-agent-btn-toggle {
		width: 48px;
		height: 48px;
	}

	.ai-agent-btn-toggle svg {
		width: 20px;
		height: 20px;
	}

	.ai-agent-message-content {
		max-width: 95%;
	}
}

/* ============================================
   Dark Mode Support (if available)
   ============================================ */

@media (prefers-color-scheme: dark) {
	#ai-agent-root {
		--ai-agent-text: #f0f0f0;
		--ai-agent-text-light: #a0a0a0;
		--ai-agent-border: #333333;
		--ai-agent-background: #1a1a1a;
		--ai-agent-background-light: #2a2a2a;
	}

	.ai-agent-message-user .ai-agent-message-content {
		background: var(--ai-agent-primary);
	}

	.ai-agent-message-assistant .ai-agent-message-content,
	.ai-agent-message-welcome .ai-agent-message-content {
		background: #2a2a2a;
		color: #f0f0f0;
	}

	.ai-agent-input {
		background: #2a2a2a;
		color: #f0f0f0;
	}
}

/* ============================================
   Accessibility
   ============================================ */

@media (prefers-reduced-motion: reduce) {
	#ai-agent-root,
	#ai-agent-root *,
	.ai-agent-btn-toggle,
	.ai-agent-chat-container,
	.ai-agent-message,
	.ai-agent-typing span {
		animation: none !important;
		transition: none !important;
	}
}

/* Ensure good contrast for accessibility */
.ai-agent-btn-toggle:focus,
.ai-agent-btn-close:focus,
.ai-agent-input:focus,
.ai-agent-btn-send:focus {
	outline: 2px solid var(--ai-agent-primary);
	outline-offset: 2px;
}
