/* ================================ FUENTES E IMPORTS ================================ */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* ================================ VARIABLES CSS ================================ */
:root {
  --primary-color: #ED4251;
  --secondary-color: #556379;
  --background-dark: #151C24;
  --text-color: #ffffff;
  --border-color: rgba(85, 99, 121, 0.2);
  --shadow-color: rgba(0, 0, 0, 0.15);
  /* Variables para solución de fondos grises */
  --prose-background: transparent;
  --container-background: transparent;
}

[data-theme="light"] {
  --background-light: #f8fafc;
  --text-light: #151C24;
  --border-light: rgba(85, 99, 121, 0.15);
  --shadow-light: rgba(0, 0, 0, 0.08);
}

/* ================================ OCULTACIÓN CHAINLIT ================================ */
/* Ocultar logos y referencias de Chainlit */
img[alt*="Chainlit" i],
img[alt*="chainlit" i],
img[src*="chainlit" i],
img[src*="logo" i]:not([src*="cereza"]):not([src*="restec"]),
.chainlit-logo,
.logo:not([class*="cereza"]):not([class*="restec"]),
[class*="logo"]:not([class*="cereza"]):not([class*="restec"]),
.MuiSvgIcon-root[data-testid*="chainlit" i],
svg[data-testid*="chainlit" i],
footer,
.chainlit-footer,
.chainlit-watermark,
.made-with-chainlit,
[class*="footer"],
[class*="watermark"],
a[href*="chainlit"],
a[href*="chainlit.io"] {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
}

/* Ocultar texto "Chainlit" */
.MuiTypography-root:has-text("Chainlit"),
.MuiTypography-h6:has-text("Chainlit"),
h1:contains("Chainlit"),
h2:contains("Chainlit"),
h3:contains("Chainlit"),
span:contains("Chainlit"),
div:contains("Chainlit"):not(:has(div)):not(:has(span)) {
  display: none !important;
  visibility: hidden !important;
}

/* ================================ BRANDING PERSONALIZADO ================================ */
/* Título personalizado "Cereza.ai" */
.MuiToolbar-root .MuiTypography-h6,
.MuiAppBar-root .MuiTypography-h6 {
  font-size: 1.5rem !important;
  font-weight: 700 !important;
}

.MuiToolbar-root .MuiTypography-h6::before,
.MuiAppBar-root .MuiTypography-h6::before {
  content: "☕ Cereza.ai" !important;
  background: linear-gradient(135deg, var(--primary-color) 0%, #ff6b75 100%) !important;
  -webkit-background-clip: text !important;
  -webkit-text-fill-color: transparent !important;
  background-clip: text !important;
}

.MuiToolbar-root .MuiTypography-h6 > *,
.MuiAppBar-root .MuiTypography-h6 > * {
  display: none !important;
}

/* ================================ CONFIGURACIÓN BASE ================================ */
body, html, #root, .MuiCssBaseline-root {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif !important;
  transition: all 0.3s ease !important;
}

/* Temas - Modo oscuro */
[data-theme="dark"] body,
[data-theme="dark"] html,
[data-theme="dark"] #root,
[data-theme="dark"] .MuiCssBaseline-root {
  background: var(--background-dark) !important;
  color: var(--text-color) !important;
}

/* Temas - Modo claro */
[data-theme="light"] body,
[data-theme="light"] html,
[data-theme="light"] #root,
[data-theme="light"] .MuiCssBaseline-root {
  background: var(--background-light) !important;
  color: var(--text-light) !important;
}

/* ================================ HEADER ================================ */
.MuiAppBar-root {
  transition: all 0.3s ease !important;
}

[data-theme="dark"] .MuiAppBar-root {
  background: rgba(21, 28, 36, 0.95) !important;
  border-bottom: 1px solid var(--border-color) !important;
}

[data-theme="light"] .MuiAppBar-root {
  background: rgba(248, 250, 252, 0.95) !important;
  border-bottom: 1px solid var(--border-light) !important;
  backdrop-filter: blur(20px) !important;
}

/* ================================ SOLUCIÓN DEFINITIVA PARA FONDOS GRISES ================================ */
/* Basado en investigación de mejores prácticas para Chainlit y Radix UI */

/* 1. ELIMINAR FONDOS GRISES DE CONTENEDORES PROSE */
.prose.lg\\:prose-xl.flex.flex-col.flex-grow.overflow-y-auto {
  background-color: transparent !important;
  background: transparent !important;
  max-width: none !important;
}

/* 2. SELECTOR ALTERNATIVO SIN ID DINÁMICO */
div[class*="prose"][class*="flex-col"][class*="overflow-y-auto"] {
  background: transparent !important;
  background-color: transparent !important;
}

div[class*="prose"][class*="flex-col"] > div:first-child > div > div {
  background: transparent !important;
  background-color: transparent !important;
  box-shadow: none !important;
  border: none !important;
}

/* 3. SOLUCIÓN PARA IDS DINÁMICOS CON WILDCARD */
[id^="radix-"] > div > div.prose.lg\\:prose-xl.flex.flex-col.flex-grow.overflow-y-auto > div:first-child > div > div {
  background: transparent !important;
  background-color: transparent !important;
  box-shadow: none !important;
  border: none !important;
}

/* 4. SELECTOR MÁS ROBUSTO */
*[id*="radix"] .prose.overflow-y-auto > div:first-child > div > div {
  background: transparent !important;
  background-color: transparent !important;
}

/* 5. SOLUCIÓN CON :IS() Y :WHERE() PARA BROWSERS MODERNOS */
:is([id^="radix-"], [id*="ui-"]) :is(.prose.flex-col, .prose.overflow-y-auto) div:first-child div div {
  background: transparent !important;
  background-color: transparent !important;
}

:where([id^="radix-"]) .prose.overflow-y-auto > div:first-child > div > div {
  background: transparent !important;
  background-color: transparent !important;
}

/* 6. CONFLICTO TAILWIND PROSE + FLEX */
.prose.flex {
  display: flex !important;
  flex-direction: column !important;
  max-width: none !important;
  background: transparent !important;
  background-color: transparent !important;
}

.prose.flex > * {
  background: inherit !important;
}

/* 7. ELIMINACIÓN ESPECÍFICA DE FONDOS GRISES */
.prose *, 
.prose div,
.prose > div,
.prose > div > div,
.prose > div:nth-child(1) > div > div {
  background-color: transparent !important;
  background: transparent !important;
}

/* 8. SELECTOR UNIVERSAL DE RESPALDO */
html body .chainlit-app [id^="radix-"] .prose.overflow-y-auto {
  background: transparent !important;
  background-color: transparent !important;
}

/* 9. ASEGURAR QUE LAS IMÁGENES NO HEREDEN FONDOS */
.prose img {
  background-color: transparent !important;
  background: transparent !important;
  margin: 0 auto !important;
  display: block !important;
}

/* ================================ LOGO RESTEC - FORZAR VISIBILIDAD ================================ */
/* Permitir logo de Restec con máxima prioridad */
img[src*="restec"],
img[src*="logo-restec2"],
img[src*="logo-restec3"],
img[alt*="Logo Dark"],
img[alt*="Logo Light"],
img[alt*="Restec"] {
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
  width: auto !important;
  height: auto !important;
  max-width: 200px !important;
  margin: 20px auto !important;
  position: relative !important;
  z-index: 9999 !important;
  background: transparent !important;
  background-color: transparent !important;
}

/* Contenedor del logo */
div[align="center"] {
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
  text-align: center !important;
  position: relative !important;
  z-index: 9999 !important;
  background: transparent !important;
  background-color: transparent !important;
  padding: 20px 0 !important;
  margin: 20px 0 !important;
  box-shadow: none !important;
  border: none !important;
}

/* ================================ MENSAJES ================================ */
/* Mensajes del usuario */
.message.user .MuiPaper-root {
  background: linear-gradient(135deg, var(--primary-color) 0%, #ff4757 100%) !important;
  color: white !important;
  border-radius: 18px 18px 6px 18px !important;
  margin-left: auto !important;
  max-width: 75% !important;
  transition: all 0.3s ease !important;
}

/* Mensajes del asistente */
.message.assistant .MuiPaper-root {
  border-radius: 18px 18px 18px 6px !important;
  margin-right: auto !important;
  max-width: 75% !important;
  transition: all 0.3s ease !important;
}

[data-theme="dark"] .message.assistant .MuiPaper-root {
  background: linear-gradient(135deg, var(--secondary-color) 0%, #667085 100%) !important;
  color: white !important;
  box-shadow: 0 4px 12px var(--shadow-color) !important;
}

[data-theme="light"] .message.assistant .MuiPaper-root {
  background: linear-gradient(135deg, #f1f5f9 0%, #e2e8f0 100%) !important;
  color: var(--text-light) !important;
  box-shadow: 0 4px 12px var(--shadow-light) !important;
  border: 1px solid var(--border-light) !important;
}

/* ================================ AVATARES ================================ */
.message.assistant .MuiAvatar-root {
  background: var(--primary-color) !important;
  color: white !important;
  font-size: 1.4rem !important;
  width: 40px !important;
  height: 40px !important;
}

.message.user .MuiAvatar-root {
  background: var(--secondary-color) !important;
  color: white !important;
  font-size: 1.4rem !important;
  width: 40px !important;
  height: 40px !important;
}

/* ================================ INPUT Y CONTROLES ================================ */
/* Campo de entrada */
.MuiOutlinedInput-root {
  border-radius: 12px !important;
  transition: all 0.3s ease !important;
}

[data-theme="dark"] .MuiOutlinedInput-root {
  background: rgba(85, 99, 121, 0.2) !important;
}

[data-theme="dark"] .MuiOutlinedInput-root .MuiOutlinedInput-notchedOutline {
  border-color: rgba(85, 99, 121, 0.3) !important;
}

[data-theme="dark"] .MuiOutlinedInput-root:hover .MuiOutlinedInput-notchedOutline {
  border-color: rgba(85, 99, 121, 0.5) !important;
}

[data-theme="dark"] .MuiOutlinedInput-input {
  color: white !important;
}

[data-theme="dark"] .MuiOutlinedInput-input::placeholder {
  color: rgba(255, 255, 255, 0.6) !important;
}

[data-theme="light"] .MuiOutlinedInput-root {
  background: rgba(255, 255, 255, 0.8) !important;
}

[data-theme="light"] .MuiOutlinedInput-root .MuiOutlinedInput-notchedOutline {
  border-color: rgba(85, 99, 121, 0.25) !important;
}

[data-theme="light"] .MuiOutlinedInput-root:hover .MuiOutlinedInput-notchedOutline {
  border-color: rgba(85, 99, 121, 0.4) !important;
}

[data-theme="light"] .MuiOutlinedInput-input {
  color: var(--text-light) !important;
}

[data-theme="light"] .MuiOutlinedInput-input::placeholder {
  color: rgba(21, 28, 36, 0.6) !important;
}

/* Focus state */
.MuiOutlinedInput-root.Mui-focused .MuiOutlinedInput-notchedOutline {
  border-color: var(--primary-color) !important;
  border-width: 2px !important;
}

/* Botón de envío */
.MuiIconButton-root[aria-label="Send"] {
  background: linear-gradient(135deg, var(--primary-color) 0%, #ff6b75 100%) !important;
  color: white !important;
  margin-left: 8px !important;
  transition: all 0.3s ease !important;
}

.MuiIconButton-root[aria-label="Send"]:hover {
  background: linear-gradient(135deg, #d73545 0%, #ff4757 100%) !important;
  transform: scale(1.05) !important;
}

/* ================================ STARTERS Y ELEMENTOS ================================ */
.MuiChip-root {
  border-radius: 12px !important;
  border: 1px solid !important;
  transition: all 0.3s ease !important;
}

[data-theme="dark"] .MuiChip-root {
  background: rgba(85, 99, 121, 0.8) !important;
  color: white !important;
  border-color: rgba(255, 255, 255, 0.1) !important;
}

[data-theme="dark"] .MuiChip-root:hover {
  background: var(--primary-color) !important;
  transform: translateY(-2px) !important;
}

[data-theme="light"] .MuiChip-root {
  background: white !important;
  color: var(--text-light) !important;
  border-color: var(--border-light) !important;
  box-shadow: 0 2px 4px var(--shadow-light) !important;
}

[data-theme="light"] .MuiChip-root:hover {
  background: var(--primary-color) !important;
  color: white !important;
  transform: translateY(-2px) !important;
  box-shadow: 0 4px 12px rgba(237, 66, 81, 0.2) !important;
}

/* ================================ CONTENIDO Y MARKDOWN ================================ */
/* Enlaces */
.MuiPaper-root a {
  color: var(--primary-color) !important;
  text-decoration: none !important;
  font-weight: 500 !important;
}

.MuiPaper-root a:hover {
  text-decoration: underline !important;
}

/* Código en mensajes - PRESERVAR FONDOS NECESARIOS */
[data-theme="dark"] .MuiPaper-root code {
  background: rgba(0, 0, 0, 0.2) !important;
  color: #ff6b75 !important;
  padding: 0.2rem 0.4rem !important;
  border-radius: 4px !important;
}

[data-theme="light"] .MuiPaper-root code {
  background: rgba(21, 28, 36, 0.1) !important;
  color: var(--primary-color) !important;
  padding: 0.2rem 0.4rem !important;
  border-radius: 4px !important;
}

[data-theme="dark"] .MuiPaper-root pre {
  background: rgba(0, 0, 0, 0.3) !important;
  border-radius: 8px !important;
  padding: 1rem !important;
  overflow-x: auto !important;
}

[data-theme="light"] .MuiPaper-root pre {
  background: rgba(21, 28, 36, 0.05) !important;
  border-radius: 8px !important;
  padding: 1rem !important;
  overflow-x: auto !important;
  border: 1px solid var(--border-light) !important;
}

/* Preservar fondos para código en prose también */
.prose pre,
.prose code:not(img + code) {
  background-color: var(--muted, rgba(85, 99, 121, 0.1)) !important;
}

/* ================================ SCROLLBAR ================================ */
::-webkit-scrollbar {
  width: 8px;
}

[data-theme="dark"] ::-webkit-scrollbar-track {
  background: var(--background-dark);
}

[data-theme="dark"] ::-webkit-scrollbar-thumb {
  background: var(--secondary-color);
  border-radius: 4px;
}

[data-theme="light"] ::-webkit-scrollbar-track {
  background: var(--background-light);
}

[data-theme="light"] ::-webkit-scrollbar-thumb {
  background: rgba(85, 99, 121, 0.4);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(85, 99, 121, 0.8);
}

/* ================================ RESPONSIVE Y TRANSICIONES ================================ */
/* Responsive design */
@media (max-width: 768px) {
  .message .MuiPaper-root {
    max-width: 90% !important;
  }
}

/* Transiciones suaves */
* {
  transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease !important;
}