/* ResuelveYa · estilos de componentes.
   Tailwind (CDN) resuelve la mayoría del layout; aquí viven el chat, las
   tarjetas, las animaciones y los fallbacks para conexiones lentas. */

:root {
  --brand: #0f766e;
  --brand-dark: #0b4f4a;
  --brand-soft: #d7f3ee;
  --ink: #14201d;
  --cream: #f7f7f2;
  --line: #e4e7dd;
  --muted: #64736d;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--cream);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.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;
}
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

/* Fallback de layout si el CDN de Tailwind tarda o está bloqueado. */
.app-shell {
  width: 100%;
  max-width: 48rem;
  height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#view-chat { flex: 1; min-height: 0; display: flex; flex-direction: column; }
#view-admin { flex: 1; min-height: 0; overflow-y: auto; }

/* ---------------- Pestañas ---------------- */
.tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: #52605b;
  font-size: 13px;
  font-weight: 700;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.tab:hover { background: rgba(15, 118, 110, .07); color: var(--brand-dark); }
.tab-active {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
  box-shadow: 0 6px 16px rgba(15, 118, 110, .22);
}
.tab-active:hover { background: var(--brand-dark); color: #fff; }
.tab:focus-visible, .quick:focus-visible, .chip:focus-visible,
.btn-primary:focus-visible, .zona-opcion:focus-visible {
  outline: 3px solid rgba(15, 118, 110, .28);
  outline-offset: 2px;
}

/* ---------------- Inicio / accesos rápidos ---------------- */
.quick {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 12px;
  text-align: left;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 1px 2px rgba(20, 32, 29, .04);
  transition: transform .12s ease, border-color .15s ease, box-shadow .15s ease;
}
.quick:hover { border-color: #a7d6c9; box-shadow: 0 6px 16px rgba(20, 32, 29, .07); }
.quick:active { transform: scale(.985); }
.quick-icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: none;
  border-radius: 12px;
  background: var(--brand-soft);
  font-size: 20px;
}

/* ---------------- Conversación ---------------- */
.chat-scroll {
  display: flex;
  flex-direction: column;
  scroll-behavior: smooth;
  min-height: 0;
}
#bienvenida { margin: auto 0; animation: subir .3s ease both; }
.mensajes {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: auto;
}
.mensajes:empty { display: none; }

.msg {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  animation: subir .2s ease both;
}
.msg-user { justify-content: flex-end; }
.avatar {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  flex: none;
  border-radius: 9px;
  background: var(--brand);
  color: #fff;
  font-size: 10.5px;
  font-weight: 800;
}
.bubble {
  max-width: min(86%, 540px);
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 18px 18px 18px 5px;
  background: #fff;
  box-shadow: 0 8px 24px rgba(20, 32, 29, .07);
  font-size: 14.5px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}
.msg-user .bubble {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
  border-radius: 18px 18px 5px 18px;
  box-shadow: none;
}
.bubble strong { font-weight: 700; }
.bubble em { color: var(--muted); font-size: 13px; }
.msg-user .bubble em { color: #cceee8; }
.bubble .line { display: block; }
.bubble .bullet { display: block; padding-left: 14px; text-indent: -14px; }
.meta {
  display: block;
  margin-top: 6px;
  font-size: 10.5px;
  color: var(--muted);
}
.msg-user .meta { color: #cfeee8; }

/* Tarjetas de resultados dentro del chat */
.cards-row {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  padding: 2px 2px 6px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
}
.cards-row::-webkit-scrollbar { display: none; }
.result-card {
  flex: 0 0 auto;
  width: 208px;
  padding: 10px 11px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: #fbfcf8;
  scroll-snap-align: start;
}
.card-label {
  display: inline-block;
  margin-bottom: 5px;
  padding: 2px 6px;
  border-radius: 5px;
  background: var(--brand-soft);
  color: var(--brand-dark);
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: .5px;
  text-transform: uppercase;
}
.card-top { display: flex; align-items: baseline; justify-content: space-between; gap: 6px; }
.card-title { margin: 0; font-size: 12.5px; font-weight: 700; line-height: 1.25; }
.card-price { color: var(--brand); font-size: 16px; font-weight: 800; letter-spacing: -.4px; white-space: nowrap; }
.card-sub { margin: 4px 0 0; font-size: 11.5px; line-height: 1.35; color: var(--muted); }
.card-detail { margin: 5px 0 0; font-size: 11px; line-height: 1.35; color: var(--brand-dark); }

/* Indicador escribiendo */
.typing { display: inline-flex; align-items: center; gap: 4px; padding: 4px 2px; }
.typing i {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--muted); opacity: .3;
  animation: pulso 1.1s infinite ease-in-out;
}
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }

/* Sugerencias */
.chip {
  flex: none;
  padding: 7px 11px;
  border: 1px solid #bfdcd4;
  border-radius: 999px;
  background: rgba(215, 243, 238, .6);
  color: var(--brand-dark);
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
}
.chip:hover { background: var(--brand-soft); }
.no-scrollbar { scrollbar-width: none; }
.no-scrollbar::-webkit-scrollbar { display: none; }

/* ---------------- Resultado del panel ---------------- */
.result-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.result-title { margin: 0; font-size: 16px; font-weight: 800; letter-spacing: -.2px; }
.result-motor {
  padding: 3px 8px; border-radius: 999px; background: #ecfdf5; color: #047857;
  font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .5px;
}
.result-motor.demo { background: #fef3c7; color: #92400e; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; }
.stat { padding: 10px; border: 1px solid var(--line); border-radius: 12px; background: #fafbf7; }
.stat b { display: block; font-size: 20px; line-height: 1; color: var(--brand-dark); }
.stat span { display: block; margin-top: 4px; font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.result-list { margin: 12px 0 0; padding: 0; list-style: none; display: grid; gap: 5px; }
.result-list li {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 7px 0; border-bottom: 1px solid #eef0e8; font-size: 12.5px;
}
.result-list li:last-child { border-bottom: 0; }
.badge-create { color: #047857; background: #ecfdf5; border: 1px solid #a7f3d0; }
.badge-update { color: #1d4ed8; background: #eff6ff; border: 1px solid #bfdbfe; }
.badge-create, .badge-update { padding: 2px 6px; border-radius: 5px; font-size: 9.5px; font-weight: 800; text-transform: uppercase; }
.warnings { margin: 12px 0 0; padding: 10px 12px; border: 1px solid #fde68a; border-radius: 10px; background: #fffbeb; color: #92400e; font-size: 11.5px; line-height: 1.5; }
.error-box { border-color: #fecaca; background: #fef2f2; color: #991b1b; }
.raw-json { margin-top: 12px; }
.raw-json pre {
  max-height: 240px; overflow: auto; padding: 10px; border-radius: 10px;
  background: #f8fafc; color: #334155; font-size: 11px; line-height: 1.45;
}

/* ---------------- Modal ---------------- */
.zona-dialog {
  width: min(92vw, 420px);
  max-width: 420px;
  padding: 0;
  border: 0;
  border-radius: 24px;
  background: transparent;
  color: var(--ink);
}
.zona-dialog::backdrop { background: rgba(20, 32, 29, .45); backdrop-filter: blur(2px); }
.zona-opcion {
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fafbf7;
  font-size: 13px;
  font-weight: 600;
}
.zona-opcion:hover { border-color: #8ec9bd; background: var(--brand-soft); }

/* ---------------- Toast ---------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 96px;
  z-index: 50;
  max-width: calc(100vw - 32px);
  transform: translateX(-50%);
  padding: 9px 14px;
  border-radius: 10px;
  background: var(--ink);
  color: #fff;
  font-size: 13px;
  text-align: center;
  box-shadow: 0 12px 30px rgba(20, 32, 29, .25);
}

/* ---------------- Animaciones y ajustes ---------------- */
@keyframes subir { from { opacity: 0; transform: translateY(7px); } to { opacity: 1; transform: none; } }
@keyframes pulso { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: .9; transform: translateY(-2px); } }

.composer textarea { resize: none; }
textarea:focus { outline: none; }

@media (min-width: 640px) {
  #bienvenida { padding-top: 18px; padding-bottom: 18px; }
  .quick { align-items: flex-start; flex-direction: column; gap: 9px; }
  .result-card { width: 220px; }
}
@media (max-width: 480px) {
  #demoBadge { display: none !important; }
  #zonaBtn { max-width: 34vw; }
  .tab { font-size: 10.5px; padding-left: 4px; padding-right: 4px; gap: 4px; }
  .tab svg { width: 14px; height: 14px; }
}
.quick-chip {
  border: 1px solid #d9e0d7;
  background: #fff;
  color: #42514b;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 11px;
  font-weight: 700;
}
@media (max-width: 380px) {
  .tab { font-size: 12px; padding-left: 8px; padding-right: 8px; }
  .bubble { max-width: 90%; }
  .brand-text small { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
