/* ===========================================================================
   Identidad visual ESI — Escuela de Salud Integrativa
   =========================================================================== */

:root {
  --esi-teal: #2E7D85;
  --esi-teal-dark: #256068;
  --esi-orange: #E8862A;
  --esi-navy: #0F1B2A;
  --esi-bg: #F5F7F8;
  --esi-surface: #FFFFFF;
  --esi-muted: #5B6B78;
  --esi-border: #E2E8EB;

  --radius-pill: 999px;
  --radius-card: 20px;
  --radius-bubble: 18px;

  --shadow-card: 0 6px 24px rgba(15, 27, 42, 0.06);
  --shadow-soft: 0 2px 8px rgba(15, 27, 42, 0.05);

  --font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--font);
  color: var(--esi-navy);
  background: var(--esi-bg);
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

/* ----------------------------- Botones / campos ----------------------------- */

.btn {
  font: inherit;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-pill);
  cursor: pointer;
  padding: 0.7rem 1.3rem;
  transition: background-color .15s ease, opacity .15s ease, transform .05s ease;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn--primary { background: var(--esi-teal); color: #fff; }
.btn--primary:hover:not(:disabled) { background: var(--esi-teal-dark); }
.btn--block { width: 100%; }

.btn--ghost {
  background: transparent;
  color: #fff;
  border: 1.5px solid rgba(255, 255, 255, .55);
  padding: 0.4rem 0.9rem;
}
.btn--ghost:hover { background: rgba(255, 255, 255, .14); }

.field, .select {
  font: inherit;
  width: 100%;
  padding: 0.85rem 1.1rem;
  border: 1.5px solid var(--esi-border);
  border-radius: var(--radius-pill);
  background: var(--esi-surface);
  color: var(--esi-navy);
  outline: none;
}
.field:focus, .select:focus { border-color: var(--esi-teal); }
.field::placeholder { color: #9AA8B2; }

/* ----------------------------- Login ----------------------------- */

.login-view {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--esi-surface);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 2.2rem 1.8rem;
  text-align: center;
}
.login-logo { height: 56px; margin-bottom: 1rem; }
.login-title { margin: 0; font-size: 1.5rem; font-weight: 800; }
.login-subtitle { margin: .25rem 0 1.6rem; color: var(--esi-muted); font-size: .95rem; }
.login-form { display: flex; flex-direction: column; gap: 0.8rem; }
.form-error { color: #C0392B; font-size: .9rem; min-height: 1.1em; margin: .2rem 0 0; }

/* ----------------------------- Chat: layout ----------------------------- */

.chat-view {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

.chat-header {
  background: var(--esi-teal);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1rem;
  padding-top: max(0.75rem, env(safe-area-inset-top));
}
.chat-header__brand { display: flex; align-items: center; gap: .6rem; min-width: 0; }
.chat-header__logo { height: 30px; }
.chat-header__title { font-weight: 800; font-size: 1.05rem; }
.chat-header__controls { display: flex; align-items: center; gap: .5rem; }
.chat-header__controls .select {
  width: auto;
  max-width: 42vw;
  padding: 0.4rem 0.8rem;
  border-color: transparent;
  font-size: .9rem;
}

/* ----------------------------- Mensajes ----------------------------- */

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.2rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
}

.system-note {
  align-self: center;
  text-align: center;
  color: var(--esi-muted);
  font-size: .9rem;
  background: var(--esi-surface);
  border: 1px solid var(--esi-border);
  border-radius: var(--radius-card);
  padding: .7rem 1rem;
  max-width: 90%;
}

.msg-row { display: flex; }
.msg-row--user { justify-content: flex-end; }
.msg-row--assistant { justify-content: flex-start; }

.bubble {
  max-width: 85%;
  padding: 0.8rem 1.05rem;
  border-radius: var(--radius-bubble);
  line-height: 1.5;
  word-wrap: break-word;
}
.bubble--user {
  background: var(--esi-teal);
  color: #fff;
  border-bottom-right-radius: 6px;
}
.bubble--assistant {
  background: var(--esi-surface);
  color: var(--esi-navy);
  border: 1px solid var(--esi-border);
  border-bottom-left-radius: 6px;
  box-shadow: var(--shadow-soft);
}
.bubble--error { color: #C0392B; }

/* Markdown dentro de la respuesta */
.markdown > *:first-child { margin-top: 0; }
.markdown > *:last-child { margin-bottom: 0; }
.markdown p { margin: 0 0 .6rem; }
.markdown ul, .markdown ol { margin: .3rem 0 .6rem; padding-left: 1.3rem; }
.markdown li { margin: .2rem 0; }
.markdown strong { font-weight: 700; }
.markdown code {
  background: var(--esi-bg);
  padding: .1rem .35rem;
  border-radius: 6px;
  font-size: .9em;
}
.markdown a { color: var(--esi-teal); }

/* Citas */
.citations {
  display: flex;
  flex-wrap: wrap;
  gap: .45rem;
  margin-top: .75rem;
  padding-top: .65rem;
  border-top: 1px dashed var(--esi-border);
}
.citation-chip {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  font-size: .8rem;
  color: var(--esi-teal-dark);
  background: rgba(46, 125, 133, 0.07);
  border: 1.5px solid rgba(46, 125, 133, 0.35);
  border-radius: var(--radius-pill);
  padding: .25rem .7rem;
}
.citation-chip__icon { filter: saturate(0); }
.citation-chip__sep { color: var(--esi-muted); }
.citation-chip__min { color: var(--esi-orange); font-weight: 600; }

/* Indicador "escribiendo" */
.typing { display: inline-flex; gap: .3rem; }
.typing span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--esi-muted);
  animation: typing-bounce 1.2s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: .15s; }
.typing span:nth-child(3) { animation-delay: .3s; }
@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* ----------------------------- Composer ----------------------------- */

.composer {
  display: flex;
  gap: .6rem;
  align-items: center;
  padding: 0.75rem 1rem;
  padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
  background: var(--esi-surface);
  border-top: 1px solid var(--esi-border);
}
.composer__input {
  flex: 1;
  font: inherit;
  padding: 0.8rem 1.1rem;
  border: 1.5px solid var(--esi-border);
  border-radius: var(--radius-pill);
  outline: none;
  background: var(--esi-bg);
}
.composer__input:focus { border-color: var(--esi-teal); background: #fff; }
.composer__input:disabled { opacity: .6; }

.btn--send {
  flex: 0 0 auto;
  width: 46px; height: 46px;
  border-radius: 50%;
  background: var(--esi-teal);
  color: #fff;
  font-size: 1.2rem;
  line-height: 1;
  display: grid;
  place-items: center;
}
.btn--send:hover:not(:disabled) { background: var(--esi-teal-dark); }

/* ----------------------------- Responsive ----------------------------- */

@media (max-width: 480px) {
  .bubble { max-width: 90%; }
  .chat-header__title { display: none; } /* en móvil, solo el logo para ganar espacio */
  .chat-header__controls .select { max-width: 38vw; }
}
