/* ===========================================================
   OptimaTech — Asistente Directiva 2006/42/CE
   Paleta y tipografía coherentes con optimatech.es
   =========================================================== */

:root {
  /* Paleta OptimaTech */
  --primary:        #0a2540;
  --primary-soft:   #122e4d;
  --accent:         #00d4ff;
  --accent-dark:    #0077b6;
  --accent-glow:    rgba(0, 212, 255, 0.18);

  --text:           #1a1a1a;
  --text-light:     #555;
  --text-muted:     #889099;

  --bg:             #ffffff;
  --bg-soft:        #f7f9fc;
  --bg-grad-1:      #f7f9fc;
  --bg-grad-2:      #e8f4f8;

  --border:         #e1e8ed;
  --border-strong:  #cfd8df;

  --radius-sm:      8px;
  --radius:         12px;
  --radius-lg:      16px;

  --shadow-sm:      0 1px 3px rgba(10, 37, 64, 0.05);
  --shadow:         0 10px 40px rgba(10, 37, 64, 0.08);
  --shadow-lg:      0 20px 60px rgba(10, 37, 64, 0.12);

  --font-sans:      'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-display:   'Fraunces', Georgia, serif;
  --font-mono:      'JetBrains Mono', ui-monospace, monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; }

body {
  font-family: var(--font-sans);
  color: var(--text);
  background: var(--bg);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 24px;
}

/* ── NAV ────────────────────────────────────────────────── */

.topbar {
  position: sticky;
  top: 0;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  z-index: 100;
}

.nav-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 0;
}

.logo {
  font-family: var(--font-sans);
  font-weight: 700;
  font-size: 20px;
  color: var(--primary);
  text-decoration: none;
  letter-spacing: -0.01em;
}

.logo span { color: var(--accent-dark); }

.nav-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--text-light);
}

.nav-meta-text {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.02em;
}

.status-dot {
  width: 8px;
  height: 8px;
  background: #4ade80;
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgba(74, 222, 128, 0.18);
  animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { box-shadow: 0 0 0 4px rgba(74, 222, 128, 0.18); }
  50%      { box-shadow: 0 0 0 7px rgba(74, 222, 128, 0.05); }
}

/* ── PAGE ──────────────────────────────────────────────── */

.page {
  min-height: calc(100vh - 65px);
  background: linear-gradient(135deg, var(--bg-grad-1) 0%, var(--bg-grad-2) 100%);
  padding: 56px 0 40px;
}

/* ── HERO ──────────────────────────────────────────────── */

.hero {
  max-width: 760px;
  margin: 0 auto 40px;
  text-align: center;
  animation: fade-up 700ms cubic-bezier(.2,.7,.3,1) both;
}

.eyebrow {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent-dark);
  margin-bottom: 14px;
}

.hero h1 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(34px, 5vw, 52px);
  line-height: 1.08;
  color: var(--primary);
  letter-spacing: -0.02em;
  margin-bottom: 18px;
}

.hero h1 em {
  font-style: italic;
  color: var(--accent-dark);
  font-weight: 600;
}

.hero .subtitle {
  font-size: 17px;
  color: var(--text-light);
  max-width: 640px;
  margin: 0 auto;
  line-height: 1.6;
}

.hero .subtitle strong {
  color: var(--primary);
  font-weight: 600;
}

.hero-pills {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 22px;
}

.hero-pill {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.02em;
  padding: 7px 14px;
  background: white;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

@keyframes fade-up {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── CHAT CARD ─────────────────────────────────────────── */

.chat-card {
  max-width: 820px;
  margin: 0 auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
  animation: fade-up 800ms cubic-bezier(.2,.7,.3,1) 80ms both;
}

.chat-header {
  background: var(--primary);
  color: white;
  padding: 18px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.chat-header-left {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.chat-header-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.session-timer {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: rgba(255, 255, 255, 0.55);
  padding: 5px 10px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  opacity: 0;
  transition: opacity 200ms ease, color 200ms, border-color 200ms, background 200ms;
  white-space: nowrap;
}

.session-timer.visible {
  opacity: 1;
}

.session-timer.warning {
  color: #ffd166;
  border-color: rgba(255, 209, 102, 0.4);
  background: rgba(255, 209, 102, 0.08);
}

.chat-title {
  font-weight: 600;
  font-size: 15px;
  line-height: 1.3;
}

.chat-subtitle {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.65);
  margin-top: 2px;
}

.reset-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: rgba(255, 255, 255, 0.85);
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  padding: 7px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 150ms ease;
  white-space: nowrap;
}

.reset-btn:hover {
  background: rgba(255, 255, 255, 0.14);
  color: white;
}

/* ── CHAT BODY ─────────────────────────────────────────── */

.chat-body {
  background: var(--bg-soft);
  padding: 24px 26px;
  min-height: 220px;
  max-height: 540px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

.chat-body::-webkit-scrollbar         { width: 8px; }
.chat-body::-webkit-scrollbar-track   { background: transparent; }
.chat-body::-webkit-scrollbar-thumb   { background: var(--border-strong); border-radius: 4px; }
.chat-body::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

.msg {
  display: flex;
  flex-direction: column;
  max-width: 88%;
  animation: msg-in 320ms ease-out both;
}

.msg.user      { align-self: flex-end;  align-items: flex-end; }
.msg.assistant { align-self: flex-start; align-items: flex-start; }

.msg-bubble {
  padding: 14px 18px;
  border-radius: 14px;
  font-size: 15px;
  line-height: 1.6;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

.msg.user .msg-bubble {
  background: var(--primary);
  color: white;
  border-bottom-right-radius: 4px;
}

.msg.assistant .msg-bubble {
  background: white;
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow-sm);
}

/* Markdown ligero dentro de las respuestas */
.msg-bubble strong { font-weight: 600; color: var(--primary); }
.msg.user .msg-bubble strong { color: white; }

.msg-bubble code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: rgba(10, 37, 64, 0.06);
  padding: 1px 6px;
  border-radius: 4px;
}

.msg.user .msg-bubble code {
  background: rgba(255, 255, 255, 0.18);
}

.msg-bubble ul, .msg-bubble ol {
  padding-left: 22px;
  margin: 6px 0;
}

.msg-bubble li { margin: 3px 0; }
.msg-bubble p + p { margin-top: 8px; }

.msg-sources {
  margin-top: 8px;
  padding-left: 4px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.01em;
}

.msg-sources span {
  display: inline-block;
  padding: 3px 8px;
  margin-right: 6px;
  margin-top: 4px;
  background: rgba(0, 119, 182, 0.08);
  border: 1px solid rgba(0, 119, 182, 0.18);
  border-radius: 999px;
  color: var(--accent-dark);
}

@keyframes msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Typing indicator */
.msg.typing .msg-bubble {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 16px 18px;
}

.typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-dark);
  opacity: 0.4;
  animation: typing-bounce 1.2s infinite ease-in-out;
}
.typing-dot:nth-child(2) { animation-delay: 0.15s; }
.typing-dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes typing-bounce {
  0%, 80%, 100% { transform: translateY(0);   opacity: 0.4; }
  40%           { transform: translateY(-5px); opacity: 1; }
}

/* ── SUGGESTIONS (chips) ───────────────────────────────── */

.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 14px 26px 0;
  background: var(--bg-soft);
  transition: opacity 250ms, max-height 250ms;
}

.suggestions.hidden {
  opacity: 0;
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  overflow: hidden;
  pointer-events: none;
}

.chip {
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  background: white;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 160ms ease;
  white-space: nowrap;
}

.chip:hover {
  border-color: var(--accent-dark);
  color: var(--accent-dark);
  background: rgba(0, 119, 182, 0.04);
  transform: translateY(-1px);
}

.chip:active { transform: translateY(0); }

/* Variante comercial: leve acento cian, para distinguir de las normativas */
.chip-commercial {
  background: rgba(0, 119, 182, 0.06);
  border-color: rgba(0, 119, 182, 0.25);
  color: var(--accent-dark);
}

.chip-commercial:hover {
  background: rgba(0, 119, 182, 0.12);
  border-color: var(--accent-dark);
}

/* ── COMPOSER ──────────────────────────────────────────── */

.composer {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  padding: 18px 26px 18px;
  background: var(--bg-soft);
  border-top: 1px solid var(--border);
}

.composer-input {
  flex: 1;
  font: inherit;
  font-size: 15px;
  line-height: 1.5;
  padding: 12px 16px;
  background: white;
  border: 1px solid var(--border);
  border-radius: 12px;
  resize: none;
  outline: none;
  max-height: 140px;
  transition: border-color 150ms, box-shadow 150ms;
  font-family: var(--font-sans);
}

.composer-input:focus {
  border-color: var(--accent-dark);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.composer-input:disabled {
  background: rgba(0, 0, 0, 0.03);
  cursor: not-allowed;
}

.composer-send {
  width: 46px;
  height: 46px;
  border: none;
  border-radius: 12px;
  background: var(--primary);
  color: white;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 150ms, transform 100ms;
}

.composer-send:hover:not(:disabled)  { background: var(--accent-dark); }
.composer-send:active:not(:disabled) { transform: scale(0.96); }
.composer-send:disabled              { opacity: 0.45; cursor: not-allowed; }

.composer-send svg { width: 18px; height: 18px; }

/* ── CHAT FOOTER ───────────────────────────────────────── */

.chat-footer {
  background: white;
  border-top: 1px solid var(--border);
  padding: 12px 26px;
}

.disclaimer {
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.4;
}

/* ── PAGE FOOTER ───────────────────────────────────────── */

.page-footer {
  text-align: center;
  margin-top: 32px;
  font-size: 13px;
  color: var(--text-muted);
}

.page-footer a {
  color: var(--accent-dark);
  text-decoration: none;
  font-weight: 500;
}

.page-footer a:hover { text-decoration: underline; }

/* ── ERROR MESSAGE ─────────────────────────────────────── */

.msg.error .msg-bubble {
  background: #fef2f2;
  border-color: #fecaca;
  color: #b91c1c;
}

.msg.expired .msg-bubble {
  background: linear-gradient(135deg, #fff8e1, #fff3c4);
  border-color: #f5d56b;
  color: #6b5300;
}

.msg.expired .msg-bubble strong {
  color: #6b5300;
}

/* ── RESPONSIVE ────────────────────────────────────────── */

@media (max-width: 640px) {
  .container          { padding: 0 16px; }
  .page               { padding: 32px 0 24px; }
  .hero               { margin-bottom: 28px; }
  .hero .subtitle     { font-size: 15px; }
  .hero-pill          { font-size: 11px; padding: 6px 10px; }

  .chat-header        { padding: 14px 18px; }
  .chat-title         { font-size: 14px; }
  .chat-subtitle      { display: none; }
  .session-timer      { display: none; }
  .reset-btn span     { display: none; }
  .reset-btn          { padding: 7px 9px; }

  .chat-body          { padding: 18px; min-height: 320px; max-height: 60vh; }
  .msg-bubble         { font-size: 14px; padding: 12px 15px; }

  .suggestions        { padding: 10px 18px 0; }
  .chip               { font-size: 12px; padding: 7px 12px; }

  .composer           { padding: 14px 18px; }
  .composer-input     { font-size: 14px; padding: 10px 14px; }

  .nav-meta-text      { display: none; }
}

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

/* ── MODO EMBEBIDO ─────────────────────────────────────────
   Cuando la página se carga dentro de un iframe (típicamente
   integrada como demo en optimatech.es), ocultamos el chrome
   redundante (nav, hero, footer, página padre) y mostramos
   SOLO la tarjeta del chat ocupando todo el alto disponible.
   El JS añade la clase .embedded al <body> cuando window.self
   !== window.top.
   ────────────────────────────────────────────────────────── */
body.embedded .topbar,
body.embedded .hero,
body.embedded .page-footer {
  display: none !important;
}

body.embedded .page {
  min-height: 100vh;
  padding: 0;
  background: transparent;
}

body.embedded .container {
  padding: 0;
  max-width: 100%;
}

body.embedded .chat-card {
  margin: 0;
  max-width: 100%;
  border-radius: 0;
  border: 0;
  box-shadow: none;
  height: 100vh;
  display: flex;
  flex-direction: column;
  animation: none;
}

body.embedded .chat-body {
  flex: 1;
  max-height: none;
  min-height: 0;
}

body.embedded .chat-footer .disclaimer {
  font-size: 11px;
}
