/* ============================================
   VARIABLES Y RESET
   ============================================ */
:root {
  --primary: #667eea;
  --primary-dark: #5568d3;
  --secondary: #764ba2;

  --bg-main: #f7f9fc;
  --bg-card: #ffffff;

  --text-primary: #1a202c;
  --text-secondary: #718096;
  --text-light: #a0aec0;

  --border: #e2e8f0;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 10px 40px rgba(0,0,0,0.12);

  --radius: 12px;
  --radius-sm: 8px;

  --spacing: 1rem;
  --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  padding: 1rem;
}

/* Utilidades accesibilidad */
.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

/* ============================================
   HEADER (incluye H1)
   ============================================ */
.header {
  text-align: center;
  margin-bottom: 1.75rem;
  animation: fadeInDown 0.6s ease-out;
}

.logo {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--bg-card);
  padding: 0.75rem 1.5rem;
  border-radius: 999px;
  box-shadow: var(--shadow-lg);
  margin-bottom: 0.75rem;
}

.brand {
  font-size: 1.25rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero-title {
  color: #fff;
  font-size: clamp(1.25rem, 2.6vw, 2rem);
  line-height: 1.15;
  font-weight: 800;
  letter-spacing: -0.02em;
  text-shadow: 0 10px 30px rgba(0,0,0,0.18);
  margin: 0.25rem auto 0.5rem;
  max-width: 900px;
}

.subtitle {
  color: rgba(255,255,255,0.92);
  font-size: 0.98rem;
  font-weight: 500;
  text-shadow: 0 2px 8px rgba(0,0,0,0.15);
  max-width: 900px;
  margin: 0 auto;
}

/* ============================================
   CONTAINER Y LAYOUT
   ============================================ */
.container {
  max-width: 1400px;
  margin: 0 auto;
}

.layout {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 1.5rem;
  align-items: start;
}

.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: fadeInUp 0.6s ease-out;
}

/* ============================================
   BLOQUE SEO (cómo funciona)
   ============================================ */
.seo-block {
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.25rem;
}

.seo-block h2 {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 0.75rem;
}

.seo-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.9rem;
}

.seo-item {
  background: linear-gradient(to bottom, #fafbff 0%, #ffffff 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.9rem 1rem;
  box-shadow: var(--shadow-sm);
}

.seo-item h3 {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 0.35rem;
}

.seo-item p {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.seo-note {
  margin-top: 0.9rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* ============================================
   CHAT CONTAINER
   ============================================ */
.chat-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 220px);
  max-height: 760px;
}

.chat {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  background: linear-gradient(to bottom, #fafbfc 0%, #ffffff 100%);
}

.chat::-webkit-scrollbar { width: 6px; }
.chat::-webkit-scrollbar-track { background: transparent; }
.chat::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }
.chat::-webkit-scrollbar-thumb:hover { background: var(--text-light); }

/* ============================================
   MENSAJES
   ============================================ */
.msg {
  max-width: 75%;
  padding: 1rem 1.25rem;
  border-radius: var(--radius);
  line-height: 1.5;
  font-size: 0.95rem;
  animation: messageSlide 0.3s ease-out;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.msg.bot {
  align-self: flex-start;
  background: linear-gradient(135deg, #f0f4ff 0%, #e9edff 100%);
  color: var(--text-primary);
  border: 1px solid #d9e2ff;
  box-shadow: var(--shadow-sm);
}

.msg.user {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: #fff;
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

/* ============================================
   QUICK REPLIES (CHIPS)
   ============================================ */
.quick {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0 1.5rem 1rem;
  border-top: 1px solid var(--border);
  background: #fff;
  min-height: 60px;
  align-items: center;
}

.chip {
  padding: 0.5rem 1rem;
  background: #fff;
  border: 2px solid var(--border);
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
  user-select: none;
}

.chip:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: #f0f4ff;
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.chip:active { transform: scale(0.97); }

.chip:focus-visible,
button:focus-visible,
#input:focus-visible,
#promptOut:focus-visible,
details summary:focus-visible {
  outline: 3px solid rgba(102, 126, 234, 0.35);
  outline-offset: 2px;
}

/* ============================================
   COMPOSER (INPUT)
   ============================================ */
.composer {
  display: flex;
  gap: 0.75rem;
  padding: 1.25rem 1.5rem;
  border-top: 2px solid var(--border);
  background: #fff;
}

#input {
  flex: 1;
  padding: 0.8rem 1rem;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: inherit;
  transition: var(--transition);
  background: var(--bg-main);
}

#input:focus {
  outline: none;
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.12);
}

#send {
  padding: 0.75rem 1.25rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 52px;
}

/* ============================================
   SIDEBAR
   ============================================ */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  padding: 1.5rem;
  max-height: calc(100vh - 220px);
  overflow-y: auto;
  position: sticky;
  top: 1rem;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.h3,
.sidebar-header h2,
.sidebar-header h3 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
}

.badge {
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: #fff;
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.summary-box {
  background: var(--bg-main);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.8;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace;
  max-height: 220px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.divider { height: 1px; background: var(--border); }

#promptOut {
  width: 100%;
  padding: 1rem;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace;
  line-height: 1.6;
  resize: vertical;
  min-height: 220px;
  background: var(--bg-main);
  color: var(--text-primary);
  transition: var(--transition);
}

#promptOut:focus {
  outline: none;
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.12);
}

#promptOut:disabled { opacity: 0.6; cursor: not-allowed; }

/* ============================================
   BOTONES
   ============================================ */
.actions { display: flex; gap: 0.75rem; }

button {
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  justify-content: center;
  border-radius: var(--radius-sm);
  user-select: none;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: #fff;
  padding: 0.75rem 1.25rem;
  font-size: 0.9rem;
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
  flex: 1;
}

.btn-primary:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

.btn-primary:active:not(:disabled) { transform: translateY(0); }

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  padding: 0.75rem 1.25rem;
  border: 2px solid var(--border);
  font-size: 0.9rem;
  flex: 1;
}

.btn-ghost:hover {
  background: var(--bg-main);
  border-color: var(--text-light);
  color: var(--text-primary);
}

/* ============================================
   HELP BOX
   ============================================ */
.help-box {
  background: linear-gradient(135deg, #fff4e6 0%, #ffe5cc 100%);
  border: 1px solid #ffd699;
  border-radius: var(--radius-sm);
  padding: 1rem;
  font-size: 0.85rem;
  color: #8b5a00;
  line-height: 1.5;
}

.help-box strong { color: #704800; }

/* ============================================
   FAQ
   ============================================ */
.faq {
  margin-top: 1.25rem;
  padding: 1.25rem 1.5rem;
}

.faq h2 {
  font-size: 1.05rem;
  font-weight: 800;
  margin-bottom: 0.75rem;
}

.faq-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.85rem 1rem;
  background: linear-gradient(to bottom, #ffffff 0%, #fbfcff 100%);
  box-shadow: var(--shadow-sm);
}

.faq-item + .faq-item { margin-top: 0.75rem; }

.faq-item summary {
  cursor: pointer;
  list-style: none;
  color: var(--text-primary);
}

.faq-item summary::-webkit-details-marker { display: none; }

.faq-item p {
  margin-top: 0.6rem;
  color: var(--text-secondary);
  font-size: 0.92rem;
}

/* ============================================
   FOOTER
   ============================================ */
.footer {
  text-align: center;
  margin: 1.25rem 0 0.25rem;
  color: rgba(255,255,255,0.88);
  text-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.footer small { font-size: 0.85rem; }

/* ============================================
   ANIMACIONES
   ============================================ */
@keyframes fadeInDown {
  from { opacity: 0; transform: translateY(-20px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes messageSlide {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Respeto a usuarios con reducción de movimiento */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 1024px) {
  .layout { grid-template-columns: 1fr; }

  .sidebar {
    position: relative;
    top: 0;
    max-height: none;
  }

  .chat-container { max-height: 560px; height: auto; }

  .seo-grid { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  body { padding: 0.5rem; }

  .header { margin-bottom: 1rem; }
  .logo { padding: 0.5rem 1rem; }
  .brand { font-size: 1rem; }

  .subtitle { font-size: 0.88rem; padding: 0 0.25rem; }

  .layout { gap: 1rem; }

  .msg {
    max-width: 88%;
    padding: 0.75rem 1rem;
    font-size: 0.92rem;
  }

  .composer { padding: 1rem; gap: 0.5rem; }

  #input { font-size: 0.92rem; }

  .quick { padding: 0 1rem 0.75rem; gap: 0.4rem; }

  .chip { padding: 0.4rem 0.75rem; font-size: 0.82rem; }

  .seo-block, .faq { padding: 1rem; }
}
