/* Asistentes InicIA · identidad de metodoinicia.com (azul InicIA + Inter) */
:root {
  --ink: #0f172a;
  --body: #334155;
  --muted: #5e6876;
  --line: #e2e8f0;
  --subtle: #f1f5f9;
  --off: #f8fafb;
  --white: #ffffff;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #dbeafe;
  --accent-tint: #eff6ff;
  --danger: #b91c1c;
  --radius-s: 8px;
  --radius-m: 14px;
  --radius-l: 22px;
  --font: 'Inter', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--body);
  background: var(--white);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
button { font: inherit; cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent-soft); outline-offset: 2px; border-radius: 6px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ── Marca ─────────────────────────────────────────── */
.brand { display: inline-flex; align-items: baseline; gap: 8px; text-decoration: none; color: var(--ink); }
.brand-mark { font-weight: 800; font-size: 1.125rem; letter-spacing: -0.02em; }
.brand-mark span { color: var(--accent); }
.brand-sub { font-size: 0.875rem; color: var(--muted); font-weight: 500; }

/* ── Botones ───────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 22px; border-radius: 999px; border: 0;
  background: var(--accent); color: var(--white); font-weight: 600; font-size: 1rem;
  text-decoration: none; transition: background 0.15s;
}
.btn:hover { background: var(--accent-hover); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn-ghost {
  display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--white);
  color: var(--body); font-size: 0.875rem; font-weight: 500; text-decoration: none;
}
.btn-ghost:hover { background: var(--subtle); }

/* ── Login ─────────────────────────────────────────── */
.login {
  min-height: 100dvh; display: grid; place-items: center; padding: 24px;
  background: var(--off);
}
.login-card {
  width: 100%; max-width: 400px; background: var(--white);
  border: 1px solid var(--line); border-radius: var(--radius-l); padding: 32px 28px;
}
.login-card h1 { margin: 20px 0 6px; color: var(--ink); font-size: 1.5rem; line-height: 1.25; letter-spacing: -0.02em; }
.login-card p { margin: 0 0 22px; color: var(--muted); font-size: 0.9375rem; }
.field { display: block; font-size: 0.875rem; font-weight: 600; color: var(--ink); margin-bottom: 8px; }
.input {
  width: 100%; min-height: 50px; padding: 0 16px; border-radius: var(--radius-m);
  border: 1px solid var(--line); font: inherit; font-size: 16px; color: var(--ink); background: var(--white);
}
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.login-card .btn { width: 100%; margin-top: 14px; }
.form-error { color: var(--danger); font-size: 0.875rem; margin: 10px 0 0; min-height: 1.3em; }

/* ── Portada ───────────────────────────────────────── */
.home { max-width: 760px; margin: 0 auto; padding: 28px 20px 64px; }
.home-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.home-intro { margin: 44px 0 40px; }
.home-intro h1 {
  margin: 0 0 14px; color: var(--ink); font-size: clamp(2rem, 7vw, 3rem);
  line-height: 1.08; letter-spacing: -0.035em; font-weight: 800;
}
.home-intro p { margin: 0; max-width: 34em; font-size: 1.0625rem; color: var(--body); }

.module + .module { margin-top: 36px; }
.module-title {
  display: flex; align-items: baseline; gap: 10px; margin: 0 0 6px;
  font-size: 0.9375rem; color: var(--muted); font-weight: 600;
}
.module-title strong { color: var(--ink); font-size: 1.125rem; letter-spacing: -0.01em; }

/* La ruta: una línea vertical que une las lecciones en orden */
.route { list-style: none; margin: 0; padding: 0; position: relative; }
.route::before {
  content: ''; position: absolute; left: 27px; top: 34px; bottom: 34px;
  width: 2px; background: var(--accent-soft);
}
.route li { position: relative; }
.stop {
  display: grid; grid-template-columns: 56px 1fr auto; align-items: center; gap: 16px;
  padding: 14px 12px 14px 0; border-radius: var(--radius-m);
  text-decoration: none; color: inherit;
}
.stop-node {
  position: relative; z-index: 1; width: 56px; height: 56px; border-radius: 50%;
  display: grid; place-items: center; background: var(--white);
  border: 2px solid var(--accent-soft); font-size: 1.625rem; line-height: 1;
}
.stop-lesson {
  display: block; font-size: 0.8125rem; font-weight: 600; color: var(--accent);
  font-variant-numeric: tabular-nums; margin-bottom: 2px;
}
.stop-name { display: block; color: var(--ink); font-weight: 700; font-size: 1.0625rem; line-height: 1.3; letter-spacing: -0.01em; }
.stop-desc { display: block; color: var(--muted); font-size: 0.9375rem; line-height: 1.5; margin-top: 3px; }
.stop-go {
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent-tint); color: var(--accent);
}
a.stop:hover .stop-node { border-color: var(--accent); }
a.stop:hover .stop-name { color: var(--accent); }
a.stop:hover .stop-go { background: var(--accent); color: var(--white); }
.stop.is-soon { cursor: default; }
.stop.is-soon .stop-node { filter: grayscale(1); opacity: 0.6; border-color: var(--line); }
.stop.is-soon .stop-name { color: var(--muted); }
.soon-tag { font-size: 0.75rem; font-weight: 600; color: var(--muted); background: var(--subtle); padding: 4px 10px; border-radius: 999px; white-space: nowrap; }


@media (max-width: 480px) {
  .stop { grid-template-columns: 48px 1fr; gap: 14px; }
  .stop-node { width: 48px; height: 48px; font-size: 1.375rem; }
  .route::before { left: 23px; }
  .stop-go { display: none; }
  .soon-tag { grid-column: 2; justify-self: start; margin-top: -4px; }
}

/* ── Chat ──────────────────────────────────────────── */
.chat { display: flex; flex-direction: column; height: 100dvh; }
.chat-top {
  flex: none; display: flex; align-items: center; gap: 10px; padding: 10px 16px;
  border-bottom: 1px solid var(--line); background: var(--white);
}
.chat-back { display: inline-flex; align-items: center; gap: 4px; min-height: 40px; padding: 0 8px 0 4px; color: var(--body); text-decoration: none; font-size: 0.875rem; font-weight: 500; border-radius: 999px; }
.chat-back:hover { background: var(--subtle); }
.chat-title { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--ink); font-size: 0.9375rem; }
.chat-title span:last-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.chat-scroll { flex: 1; overflow-y: auto; overscroll-behavior: contain; }
.chat-inner { max-width: 760px; margin: 0 auto; padding: 24px 20px 12px; }

.welcome { text-align: center; padding: 6vh 0 24px; }
.welcome-emoji {
  width: 88px; height: 88px; margin: 0 auto 18px; border-radius: 50%;
  display: grid; place-items: center; font-size: 2.75rem; background: var(--accent-tint);
  border: 2px solid var(--accent-soft);
}
.welcome-lesson { font-size: 0.875rem; font-weight: 600; color: var(--accent); margin: 0 0 6px; }
.welcome h1 { margin: 0 0 10px; color: var(--ink); font-size: clamp(1.625rem, 5.5vw, 2.125rem); line-height: 1.15; letter-spacing: -0.03em; }
.welcome p { margin: 0 auto 28px; max-width: 30em; color: var(--muted); }
.starter {
  display: block; width: 100%; max-width: 520px; margin: 0 auto; text-align: left;
  padding: 16px 20px; border-radius: var(--radius-m); border: 1px solid var(--line);
  background: var(--white); color: var(--ink); font-size: 1rem; line-height: 1.45; font-weight: 500;
  transition: border-color 0.15s, background 0.15s;
}
.starter:hover { border-color: var(--accent); background: var(--accent-tint); }

.msg { margin: 0 0 22px; }
.msg-user { display: flex; justify-content: flex-end; }
.msg-user .bubble {
  max-width: 85%; background: var(--accent-tint); color: var(--ink);
  padding: 12px 16px; border-radius: var(--radius-l) var(--radius-l) 6px var(--radius-l);
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.bubble.is-long { max-height: 260px; overflow: hidden; position: relative; }
.bubble.is-long::after { content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 60px; background: linear-gradient(transparent, var(--accent-tint)); }
.expand { display: block; margin: 6px 0 0 auto; background: none; border: 0; color: var(--accent); font-size: 0.875rem; font-weight: 600; padding: 6px 4px; }

.msg-assistant { color: var(--body); overflow-wrap: anywhere; }
.prose > :first-child { margin-top: 0; }
.prose > :last-child { margin-bottom: 0; }
.prose p, .prose ul, .prose ol { margin: 0 0 0.85em; }
.prose ul, .prose ol { padding-left: 1.4em; }
.prose li { margin: 0.25em 0; }
.prose li > p { margin: 0; }
.prose h1, .prose h2, .prose h3, .prose h4 { color: var(--ink); line-height: 1.3; letter-spacing: -0.015em; margin: 1.3em 0 0.5em; }
.prose h1 { font-size: 1.375rem; } .prose h2 { font-size: 1.25rem; } .prose h3 { font-size: 1.125rem; } .prose h4 { font-size: 1rem; }
.prose strong { color: var(--ink); }
.prose hr { border: 0; border-top: 1px solid var(--line); margin: 1.4em 0; }
.prose blockquote { margin: 0 0 0.85em; padding-left: 14px; border-left: 3px solid var(--accent-soft); color: var(--muted); }
.prose code { background: var(--subtle); padding: 1px 6px; border-radius: 5px; font-size: 0.9em; }
.prose pre { background: var(--subtle); padding: 12px 14px; border-radius: var(--radius-s); overflow-x: auto; }
.prose pre code { background: none; padding: 0; }
.prose table { border-collapse: collapse; width: 100%; display: block; overflow-x: auto; font-size: 0.9375rem; margin: 0 0 0.85em; }
.prose th, .prose td { border: 1px solid var(--line); padding: 8px 10px; text-align: left; vertical-align: top; }
.prose th { background: var(--off); color: var(--ink); }

.msg-actions { display: flex; gap: 6px; margin-top: 8px; }
.icon-btn {
  display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 10px;
  border-radius: 999px; border: 1px solid transparent; background: none; color: var(--muted);
  font-size: 0.8125rem; font-weight: 500;
}
.icon-btn:hover { background: var(--subtle); color: var(--ink); }
.icon-btn.is-done { color: var(--accent); }

/* Mapa de Demanda y Valor (1.4) */
.dv-chart { margin: 16px 0; padding: 16px 14px 12px; border: 1px solid var(--line); border-radius: var(--radius-m); background: var(--white); }
.dv-plot { display: grid; grid-template-columns: 22px 1fr; gap: 6px; }
.dv-y { writing-mode: vertical-rl; transform: rotate(180deg); text-align: center; font-weight: 700; color: var(--ink); font-size: 0.8125rem; }
.dv-grid { display: grid; grid-template-columns: 1fr 1fr; grid-auto-rows: minmax(120px, auto); border-left: 2px solid var(--ink); border-bottom: 2px solid var(--ink); }
.dv-q { padding: 10px; display: flex; flex-direction: column; gap: 8px; border: 1px solid var(--white); }
.dv-premium { background: var(--accent-tint); }
.dv-oro { background: var(--accent-soft); }
.dv-ong { background: var(--off); }
.dv-consumo { background: var(--subtle); }
.dv-qname { font-weight: 700; font-size: 0.8125rem; color: var(--muted); }
.dv-oro .dv-qname { color: var(--accent); }
.dv-idea { display: flex; gap: 8px; align-items: flex-start; padding: 8px; background: var(--white); border-radius: var(--radius-s); box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08); font-size: 0.8125rem; line-height: 1.35; }
.dv-idea strong { display: block; color: var(--ink); font-weight: 600; }
.dv-idea small { display: block; margin-top: 3px; color: var(--muted); font-size: 0.75rem; }
.dv-num { flex: none; width: 22px; height: 22px; border-radius: 50%; background: var(--accent); color: var(--white); font-size: 0.75rem; font-weight: 700; display: grid; place-items: center; }
.dv-x { margin: 6px 0 0 28px; text-align: center; font-weight: 700; color: var(--ink); font-size: 0.8125rem; }
.dv-x::after { content: ' →'; }
.dv-loading { color: var(--muted); font-style: italic; }
@media (max-width: 480px) {
  .dv-chart { padding: 12px 8px 10px; margin-left: -4px; margin-right: -4px; }
  .dv-q { padding: 6px; }
  .dv-idea { flex-direction: column; gap: 4px; padding: 6px; }
}

.copy-all { display: flex; justify-content: center; margin: 8px 0 4px; }
.copy-all .icon-btn { border-color: var(--line); color: var(--body); }

/* Historial */
.history {
  width: min(560px, calc(100vw - 24px)); max-height: min(78dvh, 640px); padding: 0;
  border: 1px solid var(--line); border-radius: var(--radius-m); color: var(--body);
  box-shadow: 0 24px 60px -20px rgba(15, 23, 42, 0.35);
}
.history[open] { display: flex; flex-direction: column; }
.history::backdrop { background: rgba(15, 23, 42, 0.4); }
.history-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 12px 4px 20px; }
.history-head h2 { margin: 0; font-size: 1.0625rem; color: var(--ink); }
.history-close { width: 40px; height: 40px; padding: 0; justify-content: center; }
.history-note { margin: 0; padding: 0 20px 12px; font-size: 0.8125rem; color: var(--muted); }
.history-list { list-style: none; margin: 0; padding: 0 8px 10px; overflow-y: auto; }
.history-item { display: flex; align-items: center; gap: 4px; border-radius: var(--radius-s); }
.history-item:hover { background: var(--off); }
.history-open {
  flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; padding: 10px 12px;
  border: 0; background: none; text-align: left; font: inherit; color: inherit; cursor: pointer; border-radius: var(--radius-s);
}
.history-title { color: var(--ink); font-weight: 600; font-size: 0.9375rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-meta { color: var(--muted); font-size: 0.8125rem; }
.history-now { color: var(--accent); font-weight: 600; }
.history-delete { width: 44px; height: 44px; padding: 0; justify-content: center; flex: none; }
.history-delete:hover { color: var(--danger); }

.status { color: var(--muted); font-size: 0.9375rem; display: flex; align-items: center; gap: 10px; }
.dots { display: inline-flex; gap: 4px; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); opacity: 0.35; animation: pulse 1.2s infinite; }
.dots i:nth-child(2) { animation-delay: 0.2s; } .dots i:nth-child(3) { animation-delay: 0.4s; }
@keyframes pulse { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }

.chat-error {
  margin: 0 0 22px; padding: 12px 14px; border-radius: var(--radius-m);
  background: #fef2f2; color: var(--danger); font-size: 0.9375rem;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
}
.chat-error button { background: none; border: 1px solid #fecaca; color: var(--danger); border-radius: 999px; padding: 6px 12px; font-size: 0.8125rem; font-weight: 600; white-space: nowrap; }

.composer-wrap { flex: none; background: var(--white); padding: 8px 16px calc(10px + env(safe-area-inset-bottom)); }
.composer {
  max-width: 760px; margin: 0 auto; display: flex; align-items: flex-end; gap: 8px;
  border: 1px solid var(--line); border-radius: var(--radius-l); padding: 8px 8px 8px 16px; background: var(--white);
}
.composer:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.composer textarea {
  flex: 1; border: 0; outline: none; resize: none; font: inherit; font-size: 16px; line-height: 1.5;
  color: var(--ink); background: transparent; padding: 8px 0; max-height: 40vh; min-height: 24px;
}
.send {
  flex: none; width: 44px; height: 44px; border-radius: 50%; border: 0;
  display: grid; place-items: center; background: var(--accent); color: var(--white);
}
.send:hover { background: var(--accent-hover); }
.send:disabled { background: var(--line); color: var(--muted); cursor: default; }
.send.is-stop { background: var(--ink); }

@media (max-width: 480px) {
  .chat-top { padding: 8px 10px; }
  .chat-inner { padding: 18px 16px 8px; }
  .head-label, .back-label { display: none; }
  .head-btn { width: 44px; height: 44px; padding: 0; justify-content: center; }
  .chat-back { min-height: 44px; min-width: 44px; justify-content: center; padding: 0; }
  .chat-top { gap: 6px; }
  .msg-user .bubble { max-width: 92%; }
  .composer-wrap { padding-left: 10px; padding-right: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
