/* ── Telefonica Sans ──────────────────────────────────────────── */
@font-face { font-family: 'Telefonica Sans'; font-weight: 100; font-style: normal;
  src: url('/assets/fonts/Telefonica_Sans_Hairline.woff2') format('woff2'); }
@font-face { font-family: 'Telefonica Sans'; font-weight: 200; font-style: normal;
  src: url('/assets/fonts/Telefonica_Sans_ExtraLight.woff2') format('woff2'); }
@font-face { font-family: 'Telefonica Sans'; font-weight: 300; font-style: normal;
  src: url('/assets/fonts/Telefonica_Sans_Light.woff2') format('woff2'); }
@font-face { font-family: 'Telefonica Sans'; font-weight: 350; font-style: normal;
  src: url('/assets/fonts/Telefonica_Sans_Thin.woff2') format('woff2'); }
@font-face { font-family: 'Telefonica Sans'; font-weight: 400; font-style: normal;
  src: url('/assets/fonts/Telefonica_Sans_Regular.woff2') format('woff2'); }
@font-face { font-family: 'Telefonica Sans'; font-weight: 500; font-style: normal;
  src: url('/assets/fonts/Telefonica_Sans_Medium.woff2') format('woff2'); }
@font-face { font-family: 'Telefonica Sans'; font-weight: 600; font-style: normal;
  src: url('/assets/fonts/Telefonica_Sans_DemiBold.woff2') format('woff2'); }
@font-face { font-family: 'Telefonica Sans'; font-weight: 700; font-style: normal;
  src: url('/assets/fonts/Telefonica_Sans_Bold.woff2') format('woff2'); }
@font-face { font-family: 'Telefonica Sans'; font-weight: 800; font-style: normal;
  src: url('/assets/fonts/Telefonica_Sans_ExtraBold.woff2') format('woff2'); }
@font-face { font-family: 'Telefonica Sans'; font-weight: 900; font-style: normal;
  src: url('/assets/fonts/Telefonica_Sans_Black.woff2') format('woff2'); }

@font-face { font-family: 'Playfair Display'; font-weight: 400 700; font-style: normal;
  src: url('/assets/fonts/PlayfairDisplay.woff2') format('woff2'); }

/* ── Variables ───────────────────────────────────────────────── */
:root {
  --bg:           #0e1521;
  --bg-elev:      #131920;
  --bg-header:    rgba(10, 14, 22, 0.95);
  --ink:          #f0f4f8;
  --ink-dim:      rgba(240, 244, 248, 0.65);
  --ink-faint:    rgba(240, 244, 248, 0.35);
  --accent:       #0066ff;
  --accent-glow:  rgba(1, 157, 244, 0.35);
  --rule:         rgba(240, 244, 248, 0.08);
  --shadow:       0 8px 32px rgba(0, 0, 0, 0.5);

  --font-serif: 'Playfair Display', Georgia, serif;
  --font-sans:  'Telefonica Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --ease: cubic-bezier(.2, .7, .2, 1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { width: 100%; height: 100%; overflow: hidden; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
button:focus-visible, textarea:focus-visible {
  outline: 1px solid var(--accent-glow); outline-offset: 2px;
}

/* ── Layout ──────────────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* ── Header ──────────────────────────────────────────────────── */
#header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  background: var(--bg-header);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--rule);
  z-index: 10;
}
.header-logo { display: flex; align-items: center; text-decoration: none; }
.header-logo img { height: 40px; }
.logo-fallback { font-weight: 600; font-size: 15px; }
.header-title {
  flex: 1;
  font-size: 14px;
  font-weight: 500;
  color: var(--ink);
  letter-spacing: 0.04em;
}
.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}
.header-actions button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  border-radius: 8px;
  color: var(--ink-dim);
  font-size: 13px;
  transition: color .2s var(--ease), background .2s var(--ease);
}
.header-actions button:hover { color: var(--ink); background: rgba(255,255,255,0.05); }
.header-actions svg { width: 16px; height: 16px; flex-shrink: 0; }

/* ── Progreso ────────────────────────────────────────────────── */
#progreso-bar {
  flex-shrink: 0;
  position: relative;
  height: 3px;
  background: var(--rule);
  opacity: 0;
  transition: opacity .4s var(--ease);
  overflow: visible;
}
#progreso-bar.visible { opacity: 1; }
#progreso-inner {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), rgba(1,157,244,0.7));
  box-shadow: 0 0 10px var(--accent-glow);
  transition: width .6s var(--ease);
  width: 0%;
}
#progreso-label {
  position: absolute;
  top: 5px; right: 8px;
  font-size: 10px;
  color: var(--ink-faint);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
}

/* ── Área de chat ────────────────────────────────────────────── */
#chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scrollbar-width: thin;
  scrollbar-color: var(--ink-faint) transparent;
}
#messages::-webkit-scrollbar { width: 6px; }
#messages::-webkit-scrollbar-thumb { background: var(--ink-faint); border-radius: 3px; }

/* Welcome hint */
#welcome-hint {
  margin: auto;
  text-align: center;
  padding: 48px 20px;
  transition: opacity .4s var(--ease);
}
#welcome-hint.hidden { display: none; }
.wh-line {
  font-family: var(--font-serif);
  font-size: clamp(20px, 2.8vw, 28px);
  color: var(--ink-dim);
  font-weight: 400;
  margin-bottom: 10px;
}
.wh-sub {
  font-size: 12px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

/* ── Burbujas de chat ────────────────────────────────────────── */
.msg {
  max-width: min(680px, 88%);
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.6;
  animation: msg-in .25s var(--ease) both;
}
@keyframes msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}
.msg-user {
  align-self: flex-end;
  background: rgba(0, 102, 255, 0.15);
  border: 1px solid rgba(0, 102, 255, 0.25);
  color: var(--ink);
  border-bottom-right-radius: 4px;
}
.msg-assistant {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--rule);
  color: var(--ink);
  border-bottom-left-radius: 4px;
  font-family: var(--font-sans);
}
.msg-assistant p { margin-bottom: 0.5em; }
.msg-assistant p:last-child { margin-bottom: 0; }
.msg-assistant strong { color: var(--ink); font-weight: 600; }
.msg-assistant em { color: var(--ink-dim); }
.msg-assistant ul, .msg-assistant ol {
  padding-left: 20px;
  margin: 0.4em 0;
}
.msg-assistant li { margin-bottom: 0.2em; }
.msg-assistant h1, .msg-assistant h2, .msg-assistant h3 {
  font-size: 0.95em;
  font-weight: 600;
  color: var(--accent);
  margin: 0.6em 0 0.3em;
}
/* Label visible en el mensaje de bienvenida */
.msg-label {
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 6px;
  font-weight: 500;
}
.msg-body p { margin-bottom: 0.5em; }
.msg-body p:last-child { margin-bottom: 0; }
.msg-body strong { font-weight: 600; }

.msg-tool {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--ink-faint);
  padding: 6px 12px;
  background: none;
  border: none;
  animation: msg-in .2s var(--ease) both;
}
.tool-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse-dot 1.4s ease-in-out infinite;
}
@keyframes pulse-dot {
  0%,100% { opacity: 0.3; transform: scale(1); }
  50%     { opacity: 1;   transform: scale(1.4); }
}

/* Cursor de streaming */
.caret {
  display: inline-block;
  width: 0.5ch;
  margin-left: 0.1ch;
  border-right: 2px solid var(--accent);
  animation: blink 1s steps(2) infinite;
  vertical-align: middle;
  height: 0.9em;
}
@keyframes blink { 50% { border-color: transparent; } }

/* ── Capa de UI del seguro (inline) ─────────────────────────── */
#seguro-ui-layer {
  flex-shrink: 0;
  padding: 0 20px 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ── Tarjeta de presupuesto ─────────────────────────────────── */
.seguro-resultado {
  background: var(--bg-elev);
  border: 1px solid var(--rule);
  border-radius: 16px;
  padding: 20px;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity .5s var(--ease), transform .5s var(--ease);
  box-shadow: var(--shadow);
}
.seguro-resultado.visible { opacity: 1; transform: none; }
.resultado-titulo {
  font-size: 11px; color: var(--ink-faint);
  text-transform: uppercase; letter-spacing: 0.1em; margin-bottom: 12px;
}
.resultado-prima { display: flex; flex-direction: column; gap: 2px; margin-bottom: 16px; }
.prima-label { font-size: 11px; color: var(--ink-dim); }
.prima-valor { font-size: 30px; font-weight: 300; color: var(--ink); letter-spacing: -0.02em; }
.prima-mensual { font-size: 13px; color: var(--ink-dim); }
.resultado-garantias {
  list-style: none; display: flex; flex-direction: column; gap: 6px;
  margin-bottom: 12px; padding: 0;
}
.resultado-garantias li { display: flex; justify-content: space-between; font-size: 12px; }
.g-nombre { color: var(--ink-dim); }
.g-capital { color: var(--ink); font-weight: 500; }
.resultado-nota {
  font-size: 11px; color: var(--ink-faint); line-height: 1.5;
  border-top: 1px solid var(--rule); padding-top: 10px;
}

/* ── Tarjeta de póliza ───────────────────────────────────────── */
.seguro-poliza {
  background: linear-gradient(135deg, rgba(0,102,255,0.12) 0%, var(--bg-elev) 100%);
  border: 1px solid rgba(0,102,255,0.3);
  border-radius: 16px;
  padding: 24px;
  text-align: center;
  opacity: 0;
  transform: translateY(12px) scale(0.98);
  transition: opacity .5s var(--ease), transform .5s var(--ease);
  box-shadow: var(--shadow), 0 0 40px rgba(0,102,255,0.1);
}
.seguro-poliza.visible { opacity: 1; transform: none; }
.poliza-icono { width: 48px; height: 48px; margin: 0 auto 12px; color: var(--accent); }
.poliza-icono svg { width: 100%; height: 100%; }
.poliza-titulo { font-size: 12px; color: var(--ink-faint); text-transform: uppercase; letter-spacing: 0.1em; margin-bottom: 6px; }
.poliza-numero { font-size: 22px; font-weight: 300; color: var(--ink); margin-bottom: 4px; }
.poliza-empresa { font-size: 14px; color: var(--ink-dim); margin-bottom: 8px; }
.poliza-fecha, .poliza-prima { font-size: 13px; color: var(--ink-dim); margin-bottom: 4px; }
.poliza-nota {
  font-size: 11px; color: var(--ink-faint); line-height: 1.55;
  margin-top: 14px; border-top: 1px solid var(--rule); padding-top: 12px;
}

/* ── Input bar ───────────────────────────────────────────────── */
#input-bar {
  flex-shrink: 0;
  padding: 8px 20px 12px;
  background: var(--bg-header);
  border-top: 1px solid var(--rule);
}

#opciones-chips {
  padding-bottom: 8px;
  display: none;
}
#opciones-chips.open { display: block; }
.opciones-titulo {
  font-size: 11px; color: var(--ink-faint);
  text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 8px;
}
.opciones-list { display: flex; flex-wrap: wrap; gap: 8px; }
.opcion-chip {
  font-family: var(--font-sans);
  font-size: 13px;
  color: var(--ink-dim);
  background: rgba(0, 102, 255, 0.08);
  border: 1px solid rgba(0, 102, 255, 0.25);
  border-radius: 20px;
  padding: 6px 14px;
  cursor: pointer;
  transition: background .2s var(--ease), color .2s var(--ease), border-color .2s var(--ease);
}
.opcion-chip:hover {
  background: rgba(0, 102, 255, 0.18);
  color: var(--ink);
  border-color: var(--accent);
}

#input-form {
  display: flex;
  flex-direction: column;
  background: rgba(13, 17, 23, 0.72);
  backdrop-filter: blur(18px);
  border: 1px solid var(--rule);
  border-radius: 14px;
  padding: 8px 12px;
  transition: border-color .25s var(--ease), box-shadow .25s var(--ease);
}
#input-form:focus-within {
  border-color: rgba(1, 157, 244, 0.4);
  box-shadow: 0 0 0 4px rgba(1, 157, 244, 0.08);
}
#input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}
#input-field {
  flex: 1;
  background: transparent;
  border: 0;
  resize: none;
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  max-height: 160px;
  padding: 6px 0;
  overflow: hidden;
}
#input-field::placeholder { color: var(--ink-faint); }
#input-field:focus { outline: none; }

#btn-send {
  width: 36px; height: 36px;
  border-radius: 50%;
  color: var(--ink-dim);
  display: inline-flex; align-items: center; justify-content: center;
  transition: color .2s var(--ease), background .2s var(--ease);
}
#btn-send:hover { color: var(--ink); background: rgba(255,255,255,0.06); }
#btn-send:disabled { opacity: 0.4; cursor: not-allowed; }
#btn-send svg { width: 17px; height: 17px; }
#btn-send.sending .icon-send { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#btn-send .icon-stop { display: none; }
#btn-send.streaming { color: #fff; background: var(--accent); }
#btn-send.streaming .icon-send { display: none; }
#btn-send.streaming .icon-stop { display: inline-block; }

#input-hint {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-top: 6px;
  text-align: center;
}

/* ── Drawers ─────────────────────────────────────────────────── */
#history-drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(420px, 92vw);
  background: var(--bg-elev);
  border-left: 1px solid var(--rule);
  transform: translateX(100%);
  transition: transform .35s var(--ease);
  z-index: 40;
  display: flex; flex-direction: column;
}
#history-drawer.open { transform: translateX(0); }
#history-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
  opacity: 0; pointer-events: none;
  transition: opacity .3s var(--ease);
  z-index: 39;
}
#history-backdrop.open { opacity: 1; pointer-events: auto; }
.drawer-head {
  padding: 18px 20px;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--rule);
  flex-shrink: 0;
}
.drawer-head h2 {
  font-family: var(--font-serif); font-weight: 500; font-size: 18px;
}
.drawer-head button {
  width: 30px; height: 30px; border-radius: 50%; color: var(--ink-dim);
  display: inline-flex; align-items: center; justify-content: center;
}
.drawer-head button:hover { color: var(--ink); background: rgba(255,255,255,0.06); }
.drawer-head svg { width: 15px; height: 15px; }
.drawer-body {
  flex: 1; padding: 18px 20px 32px; overflow-y: auto;
}
.hist-msg { margin-bottom: 16px; padding-bottom: 16px; border-bottom: 1px solid var(--rule); }
.hist-msg:last-child { border-bottom: 0; }
.hist-msg .role {
  font-size: 10px; letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--ink-faint); margin-bottom: 5px;
}
.hist-msg.user .role { color: var(--accent); }
.hist-msg .body { font-size: 13px; line-height: 1.55; color: var(--ink); }
.hist-empty {
  font-size: 13px; color: var(--ink-faint); text-align: center;
  padding: 40px 20px; font-style: italic;
}

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 600px) {
  #header { padding: 10px 14px; }
  .header-actions button span { display: none; }
  #messages { padding: 16px 14px 12px; }
  #input-bar { padding: 8px 14px 10px; }
  #seguro-ui-layer { padding: 0 14px 6px; }
}

@media (prefers-reduced-motion: reduce) {
  *, ::before, ::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
