/* Asistente IA para Notarías · estilos
   Colores principales configurables: --nia-primary (cabecera, mensajes del visitante)
   y --nia-accent (botón de enviar, enlaces). */

#nia-root {
  --nia-primary: #1C2B45;
  --nia-accent: #7B2230;
  --nia-gold: #B8955A;
  --nia-paper: #FBF8F2;
  --nia-ink: #1F1D1A;
  --nia-muted: #5B5750;
  --nia-line: #E3DACB;
  --nia-offset: 20px;
  --nia-serif: "Cormorant Garamond", "Cormorant", Garamond, Georgia, serif;
  --nia-sans: "Source Sans 3", "Source Sans Pro", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  position: fixed;
  bottom: calc(var(--nia-offset) + env(safe-area-inset-bottom, 0px));
  z-index: 99990;
  font-family: var(--nia-sans);
  font-size: 16px;
  line-height: 1.5;
  color: var(--nia-ink);
  -webkit-font-smoothing: antialiased;
}
#nia-root.nia-pos-right { right: 20px; }
#nia-root.nia-pos-left { left: 20px; }
#nia-root *, #nia-root *::before, #nia-root *::after { box-sizing: border-box; }
#nia-root button { font-family: inherit; }

/* ---------- Botón de apertura ---------- */
#nia-root .nia-launcher {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  padding: 12px 20px 12px 14px;
  border: 0;
  border-radius: 999px;
  background: var(--nia-primary);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: .01em;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 0 0 1px rgba(184, 149, 90, .55) inset, 0 10px 28px -10px rgba(28, 43, 69, .55);
  transition: transform .18s ease, box-shadow .18s ease;
}
#nia-root .nia-launcher:hover { transform: translateY(-2px); }
#nia-root .nia-launcher:focus-visible,
#nia-root button:focus-visible,
#nia-root a:focus-visible { outline: 2px solid var(--nia-gold); outline-offset: 3px; }
#nia-root .nia-form:focus-within { border-color: var(--nia-gold); box-shadow: 0 0 0 1px var(--nia-gold); }
#nia-root .nia-launcher-ico {
  display: grid; place-items: center;
  width: 30px; height: 30px; border-radius: 50%;
  background: rgba(255, 255, 255, .1);
  color: #E9D9B8;
}
#nia-root .nia-launcher-ico svg { width: 19px; height: 19px; }
#nia-root.nia-is-open .nia-launcher { display: none; }

/* ---------- Panel ---------- */
#nia-root .nia-panel {
  position: absolute;
  bottom: 0;
  width: 392px;
  max-width: calc(100vw - 32px);
  height: min(620px, calc(100vh - var(--nia-offset) - 40px));
  height: min(620px, calc(100dvh - var(--nia-offset) - 40px));
  display: flex;
  flex-direction: column;
  background: var(--nia-paper);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 0 0 1px rgba(28, 43, 69, .12), 0 24px 60px -18px rgba(28, 43, 69, .45);
  animation: nia-in .2s ease-out;
}
#nia-root .nia-panel[hidden] { display: none; }
#nia-root.nia-pos-right .nia-panel { right: 0; }
#nia-root.nia-pos-left .nia-panel { left: 0; }
@keyframes nia-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

#nia-root .nia-head {
  display: flex;
  align-items: flex-start;
  gap: 4px;
  padding: 16px 12px 14px 20px;
  background: var(--nia-primary);
  color: #fff;
  border-bottom: 2px solid var(--nia-gold);
}
#nia-root .nia-head-txt { flex: 1; min-width: 0; }
#nia-root .nia-title {
  margin: 0; padding: 0;
  font-family: var(--nia-serif);
  font-size: 23px; font-weight: 600; line-height: 1.15;
  color: #fff; letter-spacing: 0; text-transform: none;
}
#nia-root .nia-sub { margin: 3px 0 0; padding: 0; font-size: 13.5px; line-height: 1.35; color: #D5DBE5; }
#nia-root .nia-icon-btn {
  flex: none; display: grid; place-items: center;
  width: 36px; height: 36px; margin: 0; padding: 0;
  border: 0; border-radius: 8px; background: transparent;
  color: #E3E8F0; cursor: pointer;
}
#nia-root .nia-icon-btn:hover { background: rgba(255, 255, 255, .1); color: #fff; }
#nia-root .nia-icon-btn svg { width: 20px; height: 20px; }

/* ---------- Conversación ---------- */
#nia-root .nia-log {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px 18px 8px;
  scroll-behavior: smooth;
}
#nia-root .nia-msg { max-width: 92%; margin: 0 0 14px; font-size: 15.5px; line-height: 1.55; word-wrap: break-word; overflow-wrap: anywhere; }
#nia-root .nia-msg p { margin: 0 0 8px; padding: 0; font-size: inherit; line-height: inherit; color: inherit; }
#nia-root .nia-msg p:last-child { margin-bottom: 0; }
#nia-root .nia-msg ul, #nia-root .nia-msg ol { margin: 4px 0 8px; padding: 0 0 0 20px; }
#nia-root .nia-msg li { margin: 0 0 4px; padding: 0; list-style-position: outside; }
#nia-root .nia-msg ul li { list-style-type: disc; }
#nia-root .nia-msg ol li { list-style-type: decimal; }
#nia-root .nia-msg li::marker { color: var(--nia-gold); }
#nia-root .nia-msg strong { font-weight: 700; color: var(--nia-primary); }
#nia-root .nia-msg .nia-h { font-weight: 700; color: var(--nia-primary); margin-top: 6px; }
#nia-root .nia-msg a { color: var(--nia-accent); font-weight: 600; text-decoration: underline; text-underline-offset: 2px; }

#nia-root .nia-bot { padding: 2px 0 2px 14px; border-left: 2px solid var(--nia-gold); color: var(--nia-ink); }
#nia-root .nia-user {
  margin-left: auto;
  padding: 10px 14px;
  border-radius: 14px 14px 4px 14px;
  background: var(--nia-primary);
  color: #fff;
  width: fit-content;
}
#nia-root .nia-user p { color: #fff; }
#nia-root .nia-error {
  padding: 10px 14px; border-radius: 10px;
  background: #F6E9EA; color: #5E1A24; border: 1px solid #E5C7CB;
}
#nia-root .nia-error a { color: #5E1A24; }

#nia-root .nia-chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 2px 0 16px 16px; }
#nia-root .nia-chip {
  margin: 0; padding: 7px 13px;
  border: 1px solid var(--nia-line); border-radius: 999px;
  background: #fff; color: var(--nia-primary);
  font-size: 14px; font-weight: 600; line-height: 1.3; text-align: left;
  cursor: pointer;
}
#nia-root .nia-chip:hover { border-color: var(--nia-accent); color: var(--nia-accent); }

#nia-root .nia-typing { display: flex; gap: 5px; align-items: center; height: 26px; }
#nia-root .nia-typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--nia-gold); animation: nia-dot 1.1s infinite ease-in-out; }
#nia-root .nia-typing span:nth-child(2) { animation-delay: .15s; }
#nia-root .nia-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes nia-dot { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

#nia-root .nia-ts { display: none; padding: 0 18px; }
#nia-root .nia-ts.nia-ts-on { display: block; }

/* ---------- Formulario ---------- */
#nia-root .nia-form {
  display: flex; align-items: flex-end; gap: 8px;
  margin: 8px 14px 0; padding: 6px 6px 6px 14px;
  background: #fff;
  border: 1px solid var(--nia-line);
  border-radius: 12px;
}
#nia-root .nia-input {
  flex: 1; min-width: 0;
  margin: 0; padding: 8px 0;
  border: 0; outline: 0; resize: none; background: transparent;
  font-family: inherit; font-size: 16px; line-height: 1.4; color: var(--nia-ink);
  max-height: 132px; box-shadow: none;
}
#nia-root .nia-input:focus, #nia-root .nia-input:focus-visible { outline: none; box-shadow: none; border: 0; }
#nia-root .nia-input::placeholder { color: #8C867C; opacity: 1; }
#nia-root .nia-send {
  flex: none; display: grid; place-items: center;
  width: 40px; height: 40px; margin: 0; padding: 0;
  border: 0; border-radius: 10px;
  background: var(--nia-accent); color: #fff; cursor: pointer;
}
#nia-root .nia-send:disabled { opacity: .5; cursor: default; }
#nia-root .nia-send svg { width: 20px; height: 20px; }
#nia-root .nia-legal {
  margin: 8px 16px 12px; padding: 0;
  font-size: 12px; line-height: 1.4; color: var(--nia-muted);
}
#nia-root .nia-legal a { color: var(--nia-muted); text-decoration: underline; }
#nia-root .nia-sr { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Móvil ---------- */
@media (max-width: 600px) {
  #nia-root.nia-pos-right { right: 14px; }
  #nia-root.nia-pos-left { left: 14px; }
  #nia-root .nia-launcher { padding: 0; width: 58px; height: 58px; justify-content: center; }
  #nia-root .nia-launcher-txt { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  #nia-root .nia-launcher-ico { width: 58px; height: 58px; background: transparent; }
  #nia-root .nia-launcher-ico svg { width: 26px; height: 26px; }
  #nia-root.nia-is-open { inset: 0; bottom: 0; right: 0; left: 0; }
  #nia-root.nia-is-open .nia-panel {
    position: fixed; inset: 0;
    width: 100%; max-width: none; height: 100%;
    border-radius: 0;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  #nia-root .nia-head { padding-top: calc(14px + env(safe-area-inset-top, 0px)); }
  #nia-root .nia-msg { max-width: 96%; }
  html.nia-open, html.nia-open body { overflow: hidden !important; }
}

@media (prefers-reduced-motion: reduce) {
  #nia-root .nia-panel { animation: none; }
  #nia-root .nia-launcher { transition: none; }
  #nia-root .nia-launcher:hover { transform: none; }
  #nia-root .nia-typing span { animation: none; opacity: .7; }
  #nia-root .nia-log { scroll-behavior: auto; }
}

/* ---------- Voz (micrófono y lectura en voz alta) ---------- */
#nia-root .nia-mic {
  flex: none; display: grid; place-items: center;
  width: 40px; height: 40px; margin: 0 6px 0 4px; padding: 0;
  border: 1px solid var(--nia-line); border-radius: 10px;
  background: #fff; color: var(--nia-primary); cursor: pointer;
  transition: background-color .2s ease, border-color .2s ease, color .2s ease;
}
#nia-root .nia-mic svg { width: 20px; height: 20px; }
#nia-root .nia-mic:hover, #nia-root .nia-mic:focus-visible { border-color: var(--nia-primary); }
#nia-root .nia-mic.nia-listening { background: #C62828; border-color: #C62828; color: #fff; animation: nia-pulse 1.3s ease-in-out infinite; }
@keyframes nia-pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(198, 40, 40, .45); } 50% { box-shadow: 0 0 0 7px rgba(198, 40, 40, 0); } }
#nia-root .nia-speak[aria-pressed="true"] { background: rgba(255, 255, 255, .22); }
@media (prefers-reduced-motion: reduce) { #nia-root .nia-mic.nia-listening { animation: none; } }

@media print { #nia-root { display: none !important; } }
