/* Fuente alojada en el propio servidor: sin peticiones a terceros */
@font-face {
  font-family: "Manrope";
  font-style: normal;
  font-display: swap;
  font-weight: 200 800;
  src: url("fonts/manrope-latin-wght-normal.woff2") format("woff2-variations");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Manrope";
  font-style: normal;
  font-display: swap;
  font-weight: 200 800;
  src: url("fonts/manrope-latin-ext-wght-normal.woff2") format("woff2-variations");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  --bg: #EAEFF1;
  --surface: #FFFFFF;
  --ink: #15212B;
  --muted: #5B6770;
  --line: #D3DBDF;
  --teal: #0F5E63;
  --teal-strong: #0B4A4E;
  --on-teal: #FFFFFF;
  --teal-tint: #DCEDEE;
  --marker: #FFC83D;
  --marker-tint: #FFF3CC;
  --marker-ink: #5C4300;
  --rust: #B4462C;
  --shade: rgba(12, 22, 30, .62);

  --font: "Manrope", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0F171D;
    --surface: #17222A;
    --ink: #E3E9EC;
    --muted: #97A5AE;
    --line: #2A3842;
    --teal: #4FB3AE;
    --teal-strong: #6CC7C2;
    --on-teal: #0B1419;
    --teal-tint: #173538;
    --marker-tint: #3A3116;
    --marker-ink: #FFD978;
    --rust: #E58468;
    --shade: rgba(0, 0, 0, .7);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 16px/1.6 var(--font);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--marker); outline-offset: 2px; }
.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

.shell {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 820px;
  margin: 0 auto;
  padding: 0 20px 20px;
}

/* ---------- Cabecera ---------- */
.top {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 0 14px;
}
.mark { width: 34px; height: 34px; color: var(--teal); flex: none; }
.wordmark {
  font-weight: 800;
  font-size: 26px;
  letter-spacing: -0.035em;
  line-height: 1;
}

/* Etiquetas de privacidad: modelos y datos en el propio servidor */
.trust {
  display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px;
  margin: 0 0 0 auto; padding: 0; list-style: none;
}
.trust-tag {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; font-weight: 700; line-height: 1;
  padding: 5px 10px; border-radius: 999px;
  background: var(--teal-tint); color: var(--teal-strong);
  white-space: nowrap; cursor: default;
}
.trust-tag.is-main { background: var(--teal); color: var(--on-teal); }
.trust-tag svg {
  width: 14px; height: 14px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}

/* ---------- Recuadro del chat ---------- */
.stage { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 12px; }
.chat {
  flex: 1; min-height: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  display: flex; flex-direction: column;
}
.messages {
  flex: 1; overflow-y: auto;
  padding: 28px 28px 32px;
  display: flex; flex-direction: column; gap: 26px;
  scroll-behavior: smooth;
}

.msg { max-width: 64ch; }
.msg-user { align-self: flex-end; }
.msg-user .msg-body {
  background: var(--teal);
  color: var(--on-teal);
  padding: 10px 16px;
  border-radius: 16px 16px 4px 16px;
  white-space: pre-wrap; word-break: break-word;
}
.msg-assistant { align-self: stretch; }

.msg-meta { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-size: 13px; color: var(--muted); }
.badge {
  display: inline-block;
  font-size: 12px; font-weight: 700;
  padding: 2px 9px; border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
}
.badge.is-rag { background: var(--marker-tint); border-color: var(--marker); color: var(--marker-ink); }

.msg-assistant .msg-body { padding-left: 16px; border-left: 3px solid var(--line); overflow-wrap: anywhere; }
.msg-assistant.is-rag .msg-body { border-left-color: var(--marker); }
.msg-body > :first-child { margin-top: 0; }
.msg-body > :last-child { margin-bottom: 0; }
.msg-body p, .msg-body ul, .msg-body ol { margin: 0 0 .8em; }
.msg-body ul, .msg-body ol { padding-left: 1.4em; }
.msg-body h3, .msg-body h4, .msg-body h5 { margin: 1.1em 0 .4em; font-size: 1.05em; }
.msg-body code { font-family: var(--mono); font-size: .88em; background: var(--bg); padding: 1px 5px; border-radius: 4px; }
.msg-body pre { background: var(--bg); padding: 12px 14px; border-radius: 8px; overflow-x: auto; }
.msg-body pre code { background: none; padding: 0; }

.typing { display: inline-flex; gap: 5px; padding: 8px 0; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--teal); animation: blink 1.2s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

.msg-error { margin-top: 8px; font-size: 14px; color: var(--rust); }

/* Fuentes consultadas */
.sources { margin: 12px 0 0 19px; font-size: 14px; }
.sources summary { cursor: pointer; color: var(--marker-ink); font-weight: 600; }
.sources summary span { font-weight: 500; color: var(--muted); }
.source { margin-top: 12px; padding: 12px 14px; background: var(--marker-tint); border-radius: 10px; }
.source h4 { margin: 0; font-size: 14px; }
.source .ctx { margin: 2px 0 6px; font-size: 12px; color: var(--muted); }
.source p { margin: 0; white-space: pre-line; line-height: 1.55; }
.sources .boe { display: inline-block; margin-top: 10px; color: var(--teal); font-weight: 600; }

/* Estados vacíos y de preparación */
.empty, .prep { margin: auto; max-width: 46ch; text-align: center; color: var(--muted); }
.empty h2, .prep h2 { margin: 0 0 8px; color: var(--ink); font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
.empty p, .prep p { margin: 0; }
.prep ul { list-style: none; margin: 18px 0 0; padding: 0; text-align: left; display: flex; flex-direction: column; gap: 12px; }
.prep li { display: flex; gap: 10px; align-items: flex-start; }
.prep .dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 8px; background: var(--line); flex: none; }
.prep .is-done .dot { background: var(--teal); }
.prep .is-busy .dot { background: var(--marker); animation: blink 1.2s infinite; }
.prep .is-error .dot { background: var(--rust); }
.prep strong { color: var(--ink); font-weight: 600; }
.prep .bar { height: 5px; background: var(--bg); border-radius: 3px; margin-top: 6px; overflow: hidden; }
.prep .bar span { display: block; height: 100%; background: var(--marker); transition: width .3s ease; }

/* ---------- Entrada de texto ---------- */
.composer {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px 14px 14px;
}
.controls {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-bottom: 10px; flex-wrap: wrap;
}
.model-tag { margin: 0; font-size: 14px; color: var(--muted); }
.model-tag span { color: var(--ink); font-weight: 600; font-family: var(--mono); font-size: 13.5px; }

.rag-check {
  display: inline-flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: 15px;
  cursor: pointer; user-select: none;
  padding: 4px 10px 4px 6px; border-radius: 8px;
}
.rag-check input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.rag-check .box {
  width: 22px; height: 22px; border-radius: 6px;
  border: 2px solid var(--muted);
  display: inline-flex; align-items: center; justify-content: center;
  transition: background .12s ease, border-color .12s ease;
}
.rag-check .box::after {
  content: ""; width: 6px; height: 11px;
  border: solid var(--ink); border-width: 0 3px 3px 0;
  transform: rotate(45deg) translate(-1px, -1px);
  opacity: 0;
}
.rag-check input:checked + .box { background: var(--marker); border-color: var(--marker); }
.rag-check input:checked + .box::after { opacity: 1; border-color: #15212B; }
.rag-check input:focus-visible + .box { outline: 3px solid var(--marker); outline-offset: 2px; }
.rag-check input:disabled ~ * { opacity: .5; }
.rag-check:has(input:disabled) { cursor: not-allowed; color: var(--muted); }
.rag-check:has(input:checked) { background: var(--marker-tint); color: var(--marker-ink); }

.input-row { display: flex; gap: 10px; align-items: flex-end; }
.input-row textarea {
  flex: 1; resize: none;
  border: 1px solid var(--line); border-radius: 12px;
  padding: 11px 14px; background: var(--bg);
  max-height: 180px; line-height: 1.5;
}
.input-row textarea:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px var(--teal-tint); }
.input-row textarea:disabled { opacity: .6; }
.send {
  background: var(--teal); color: var(--on-teal);
  border: 0; border-radius: 12px;
  padding: 11px 20px; font-weight: 700; min-width: 100px;
}
.send:hover:not(:disabled) { background: var(--teal-strong); }
.send.is-stop { background: var(--rust); color: #fff; }
.send:disabled { opacity: .45; cursor: not-allowed; }

.disclaimer { margin: -4px 0 0; text-align: center; font-size: 12px; color: var(--muted); }
.badge.is-guard { background: var(--bg); border-color: var(--muted); color: var(--ink); }

/* ---------- Tutorial ---------- */
.tour[hidden] { display: none; }
.tour-shade { position: fixed; background: var(--shade); z-index: 100; }
.tour-ring {
  position: fixed; z-index: 101; pointer-events: none;
  border: 3px solid var(--marker);
  border-radius: 6px;
  box-shadow: 0 0 0 6px rgba(255, 200, 61, .28);
  transition: top .25s ease, left .25s ease, width .25s ease, height .25s ease;
}
.tour-ring[hidden] { display: none; }
.tour-card {
  position: fixed; z-index: 102;
  width: min(380px, calc(100vw - 24px));
  background: var(--surface);
  border-radius: 14px;
  padding: 18px 20px 16px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .28);
  border-top: 6px solid var(--marker);
}
.tour-step { margin: 0 0 4px; font-size: 13px; font-weight: 700; color: var(--marker-ink); }
.tour-card h2 { margin: 0 0 6px; font-size: 19px; line-height: 1.3; letter-spacing: -0.015em; }
.tour-card p { margin: 0; color: var(--muted); font-size: 15px; }
.tour-card #tourText strong { color: var(--ink); }
.tour-extra:empty { display: none; }
.tour-extra { margin-top: 12px; display: flex; flex-direction: column; gap: 6px; }
.tour-extra .hint { font-size: 14px; font-weight: 600; color: var(--teal); }
.tour-extra .idea {
  text-align: left; background: var(--bg); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 12px; font-size: 14px;
}
.tour-extra .idea:hover { border-color: var(--teal); }
.tour-actions { display: flex; justify-content: space-between; align-items: center; margin-top: 16px; gap: 12px; }
.tour-skip { background: none; border: 0; padding: 6px 0; color: var(--muted); font-size: 14px; text-decoration: underline; text-underline-offset: 3px; }
.tour-next {
  background: var(--ink); color: var(--surface);
  border: 0; border-radius: 10px; padding: 9px 18px; font-weight: 700;
}
.tour-next[hidden] { display: none; }
.tour-next:disabled { opacity: .5; cursor: progress; }

@media (max-width: 600px) {
  .shell { padding: 0 10px 10px; }
  .top { padding: 12px 0 10px; flex-wrap: wrap; }
  .wordmark { font-size: 22px; }
  .trust { width: 100%; margin-left: 0; justify-content: flex-start; }
  .messages { padding: 18px 16px 22px; }
  .send { min-width: 0; padding: 11px 14px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
.tour-skip[hidden] { visibility: hidden; display: inline; }
