/* ==========================================================================
   ESTILOS GENERALES Y VARIABLES DE TEMA
   ========================================================================== */
:root {
  --font-display: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-body: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  
  --bg: #f4f7fc;
  --bg-gradient: linear-gradient(180deg, #eef4fe 0%, #f4f7fc 100%);
  --surface: #ffffff;
  --surface2: #f8fafc;
  --surface-translucent: rgba(255, 255, 255, 0.82);
  --text: #0f172a;
  --text-secondary: #475569;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-glow: rgba(37, 99, 235, 0.25);
  --secondary: #7c3aed;
  --accent: #06b6d4;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --border: #e2e8f0;
  --border-focus: #3b82f6;
  --shadow-sm: 0 2px 6px rgba(15, 23, 42, 0.04);
  --shadow: 0 10px 30px -5px rgba(15, 23, 42, 0.08), 0 4px 12px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 20px 40px -10px rgba(15, 23, 42, 0.12);
  --r: 20px;
  --r-sm: 12px;
  
  --hero-bg: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #1d4ed8 100%);
  --hero-text: #ffffff;
  --hero-card-bg: rgba(255, 255, 255, 0.1);
  --hero-card-border: rgba(255, 255, 255, 0.18);

  --font-scale: 1;
}

/* ---------------- TEMA DARK ---------------- */
body.dark {
  --bg: #090d16;
  --bg-gradient: linear-gradient(180deg, #090d16 0%, #0d1322 100%);
  --surface: #111827;
  --surface2: #182234;
  --surface-translucent: rgba(17, 24, 39, 0.88);
  --text: #f1f5f9;
  --text-secondary: #cbd5e1;
  --muted: #94a3b8;
  --primary: #3b82f6;
  --primary-glow: rgba(59, 130, 246, 0.35);
  --secondary: #8b5cf6;
  --accent: #38bdf8;
  --border: #1e293b;
  --border-focus: #60a5fa;
  --shadow: 0 14px 40px rgba(0, 0, 0, 0.45);
  --hero-bg: linear-gradient(135deg, #030712 0%, #0f172a 60%, #1e3a8a 100%);
}

/* ---------------- TEMA EDITORIAL ---------------- */
body.editorial {
  --font-display: 'Georgia', 'Times New Roman', serif;
  --bg: #faf7f2;
  --bg-gradient: linear-gradient(180deg, #f5efe6 0%, #faf7f2 100%);
  --surface: #ffffff;
  --surface2: #f7f3ec;
  --surface-translucent: rgba(255, 255, 255, 0.9);
  --text: #2c221e;
  --text-secondary: #5a4b44;
  --muted: #7d6b63;
  --primary: #854d0e;
  --primary-glow: rgba(133, 77, 14, 0.2);
  --secondary: #b45309;
  --accent: #c2410c;
  --border: #e7dfd5;
  --border-focus: #b45309;
  --hero-bg: linear-gradient(135deg, #2c1810 0%, #452615 60%, #854d0e 100%);
}

/* ---------------- TEMA GLASSMORPHISM ---------------- */
body.glass {
  --bg: #e0e7ff;
  --bg-gradient: linear-gradient(135deg, #e0e7ff 0%, #ede9fe 50%, #fae8ff 100%);
  --surface: rgba(255, 255, 255, 0.72);
  --surface2: rgba(255, 255, 255, 0.52);
  --surface-translucent: rgba(255, 255, 255, 0.8);
  --text: #0f172a;
  --text-secondary: #334155;
  --muted: #64748b;
  --primary: #4f46e5;
  --primary-glow: rgba(79, 70, 229, 0.3);
  --secondary: #9333ea;
  --border: rgba(255, 255, 255, 0.7);
  --shadow: 0 16px 36px rgba(79, 70, 229, 0.08);
  --hero-bg: linear-gradient(135deg, rgba(30, 27, 75, 0.95) 0%, rgba(67, 56, 202, 0.9) 100%);
}
body.glass .panel {
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

/* ---------------- TEMA BRUTALISMO ---------------- */
body.brutal {
  --bg: #f5f5f5;
  --surface: #ffffff;
  --surface2: #f0f0f0;
  --text: #000000;
  --text-secondary: #222222;
  --muted: #555555;
  --primary: #ff4800;
  --primary-glow: transparent;
  --secondary: #000000;
  --border: #000000;
  --r: 0px;
  --r-sm: 0px;
  --shadow: 6px 6px 0 #000000;
  --hero-bg: #000000;
}
body.brutal button, body.brutal .panel, body.brutal .tag, body.brutal .card {
  border-width: 2px !important;
}

/* ---------------- TEMA CYBERPUNK ---------------- */
body.cyber {
  --bg: #070913;
  --bg-gradient: linear-gradient(180deg, #070913 0%, #0e1124 100%);
  --surface: #101428;
  --surface2: #161c38;
  --text: #00f0ff;
  --text-secondary: #e2e8f0;
  --muted: #7b8ebb;
  --primary: #00f0ff;
  --primary-glow: rgba(0, 240, 255, 0.4);
  --secondary: #ff0077;
  --border: #232d56;
  --border-focus: #ff0077;
  --shadow: 0 10px 30px rgba(0, 240, 255, 0.15);
  --hero-bg: linear-gradient(135deg, #090918 0%, #171033 60%, #ff0077 150%);
}

/* ---------------- TEMA ORGÁNICO ---------------- */
body.organic {
  --bg: #f2f7f2;
  --bg-gradient: linear-gradient(180deg, #e8f3e8 0%, #f2f7f2 100%);
  --surface: #ffffff;
  --surface2: #f4f8f4;
  --text: #143521;
  --text-secondary: #31533e;
  --muted: #587965;
  --primary: #166534;
  --primary-glow: rgba(22, 101, 52, 0.25);
  --secondary: #15803d;
  --border: #cfe2d0;
  --hero-bg: linear-gradient(135deg, #0a2613 0%, #143e21 60%, #166534 100%);
}

/* ---------------- TEMA VIBRANTE ---------------- */
body.vibrant {
  --bg: #fffbf5;
  --bg-gradient: linear-gradient(180deg, #fff3e6 0%, #fffbf5 100%);
  --surface: #ffffff;
  --surface2: #fff5eb;
  --text: #1f1d2b;
  --text-secondary: #4a455a;
  --muted: #7b758e;
  --primary: #ea580c;
  --primary-glow: rgba(234, 88, 12, 0.3);
  --secondary: #db2777;
  --accent: #f59e0b;
  --border: #fed7aa;
  --hero-bg: linear-gradient(135deg, #431407 0%, #9a3412 60%, #ea580c 100%);
}

/* ==========================================================================
   RESET Y BASE
   ========================================================================== */
*, *::before, *::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  font-size: calc(16px * var(--font-scale));
}

body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--bg-gradient);
  background-attachment: fixed;
  color: var(--text);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  color: var(--text);
  margin: 0;
  font-weight: 700;
  line-height: 1.25;
}

p {
  margin: 0 0 1rem;
}

p:last-child {
  margin-bottom: 0;
}

a {
  color: var(--primary);
  text-decoration: none;
  transition: color 0.15s ease;
}

a:hover {
  text-decoration: underline;
}

.wrap {
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px 18px 60px;
}

.hidden {
  display: none !important;
}

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ==========================================================================
   COMPONENTES: PANELES, BOTONES Y FORMULARIOS
   ========================================================================== */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  position: relative;
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
}

button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: var(--r-sm);
  padding: 11px 18px;
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

button:hover, .btn:hover {
  transform: translateY(-2px);
}

button:active, .btn:active {
  transform: translateY(0);
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none !important;
}

.primary {
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: #ffffff;
  box-shadow: 0 4px 14px var(--primary-glow);
}

.primary:hover {
  box-shadow: 0 6px 20px var(--primary-glow);
}

.secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}

.secondary:hover {
  border-color: var(--primary);
}

.ghost {
  background: transparent;
  color: var(--primary);
  border: 1px dashed var(--border);
}

.ghost:hover {
  background: var(--surface2);
  border-style: solid;
}

.btn-large {
  padding: 14px 28px;
  font-size: 1.05rem;
}

.btn-sm {
  padding: 7px 12px;
  font-size: 0.85rem;
  border-radius: 8px;
}

.field label {
  display: block;
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 7px;
}

.field input, .field select {
  width: 100%;
  padding: 11px 14px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.93rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field input:focus, .field select:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

/* ==========================================================================
   PANEL SETUP (CONFIGURACIÓN Y DROPZONE)
   ========================================================================== */
.setup {
  padding: 36px;
  margin-bottom: 24px;
}

.setup-head {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-bottom: 16px;
}

.setup-logo {
  width: 72px;
  height: 72px;
  flex-shrink: 0;
}

.setup-logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.setup-titles {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.setup-pill {
  display: inline-flex;
  align-self: flex-start;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface2);
  color: var(--primary);
  border: 1px solid var(--border);
}

#setup-title {
  font-size: clamp(1.8rem, 3.2vw, 2.5rem);
  letter-spacing: -0.02em;
}

#setup-desc {
  font-size: 1.05rem;
  color: var(--text-secondary);
  max-width: 80ch;
  margin-bottom: 28px;
}

.grid {
  display: grid;
  grid-template-columns: 1.1fr 1.4fr;
  gap: 24px;
  margin-bottom: 24px;
}

.grid-sub {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.field-full {
  grid-column: 1 / -1;
}

.input-with-btn {
  display: flex;
  gap: 8px;
}

/* Dropzone de PDF */
.file-dropzone {
  position: relative;
  border: 2px dashed var(--border);
  border-radius: var(--r-sm);
  background: var(--surface2);
  padding: 32px 20px;
  text-align: center;
  transition: border-color 0.2s, background-color 0.2s;
  cursor: pointer;
}

.file-dropzone:hover, .file-dropzone.dragover {
  border-color: var(--primary);
  background: rgba(37, 99, 235, 0.04);
}

.file-dropzone input[type="file"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.dropzone-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.dropzone-icon {
  font-size: 2.4rem;
}

.dropzone-text {
  font-weight: 700;
  font-size: 0.98rem;
  color: var(--text);
}

.dropzone-sub {
  font-size: 0.82rem;
  color: var(--muted);
}

/* Barra de progreso de generación */
.progress-box {
  margin: 20px 0;
  padding: 16px 20px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
}

.progress-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.92rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.progress-bar-wrap {
  width: 100%;
  height: 10px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--secondary), var(--accent));
  background-size: 200% 100%;
  animation: shimmerProgress 2s linear infinite;
  transition: width 0.4s ease;
}

@keyframes shimmerProgress {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

.progress-sub {
  font-size: 0.82rem;
  color: var(--muted);
  margin-top: 6px;
}

.action-btns {
  display: flex;
  gap: 14px;
  align-items: center;
}

/* ==========================================================================
   BARRA DE HERRAMIENTAS STICKY (TOOLBAR)
   ========================================================================== */
.app-toolbar {
  position: sticky;
  top: 14px;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  margin-bottom: 20px;
  background: var(--surface-translucent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.toolbar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 200px;
}

.toolbar-logo {
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
}

.toolbar-logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.toolbar-doc-info strong {
  display: block;
  font-size: 0.92rem;
  max-width: 220px;
}

.toolbar-pill {
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface2);
  color: var(--muted);
  border: 1px solid var(--border);
}

.toolbar-search {
  position: relative;
  flex: 1;
  max-width: 440px;
}

.toolbar-search input {
  width: 100%;
  padding: 9px 36px 9px 36px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.88rem;
}

.toolbar-search .search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.9rem;
  pointer-events: none;
  opacity: 0.6;
}

.toolbar-search .clear-search {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 4px;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.font-sizer {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  overflow: hidden;
}

.font-sizer button {
  background: var(--surface2);
  border: none;
  border-radius: 0;
  padding: 7px 10px;
  font-size: 0.8rem;
  color: var(--text);
}

.font-sizer button:first-child {
  border-right: 1px solid var(--border);
}

#live-style-select {
  padding: 7px 10px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 0.85rem;
}

/* ==========================================================================
   SECCIÓN HERO
   ========================================================================== */
.hero {
  background: var(--hero-bg);
  color: var(--hero-text);
  padding: 36px;
  overflow: hidden;
  position: relative;
  margin-bottom: 24px;
}

.hero-bg-shapes {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 90% 10%, rgba(255, 255, 255, 0.15), transparent 45%),
              radial-gradient(circle at 10% 90%, rgba(255, 255, 255, 0.08), transparent 50%);
  pointer-events: none;
}

.hero-top {
  display: grid;
  grid-template-columns: 1.35fr 0.9fr;
  gap: 32px;
  position: relative;
  z-index: 2;
}

.hero-badges-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 0.78rem;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.22);
  color: #ffffff;
  backdrop-filter: blur(8px);
}

#hero-title {
  color: #ffffff;
  font-size: clamp(2.2rem, 4vw, 3.4rem);
  letter-spacing: -0.02em;
  margin-bottom: 8px;
}

.hero-subtitle-text {
  font-size: 1.15rem;
  color: rgba(255, 255, 255, 0.88);
  margin-bottom: 18px;
}

.hero-summary-card {
  background: var(--hero-card-bg);
  border: 1px solid var(--hero-card-border);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-radius: var(--r-sm);
  padding: 16px 20px;
  margin-bottom: 18px;
}

.summary-card-head {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.95);
  margin-bottom: 8px;
}

#hero-summary-text {
  font-size: 0.95rem;
  color: rgba(255, 255, 255, 0.9);
  line-height: 1.6;
}

.hero-meta-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 0.82rem;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: #ffffff;
}

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.nav a {
  text-decoration: none;
  color: #ffffff;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.22);
  font-size: 0.85rem;
  font-weight: 600;
  transition: background 0.15s, transform 0.15s;
}

.nav a:hover {
  background: rgba(255, 255, 255, 0.28);
  transform: translateY(-2px);
  text-decoration: none;
}

/* Panel de métricas del hero */
.stats-panel {
  background: var(--hero-card-bg);
  border: 1px solid var(--hero-card-border);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-radius: var(--r);
  padding: 24px;
  display: flex;
  flex-direction: column;
}

.stats-panel-title {
  color: #ffffff;
  font-size: 1.05rem;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.mini-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  flex: 1;
}

.mini {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: var(--r-sm);
  padding: 14px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  transition: transform 0.2s ease, background-color 0.2s ease;
}

.mini:hover {
  transform: translateY(-2px);
  background: rgba(255, 255, 255, 0.14);
}

.mini strong {
  font-size: 1.4rem;
  color: #ffffff;
  line-height: 1.1;
  margin-bottom: 4px;
}

.mini span {
  font-size: 0.82rem;
  color: rgba(255, 255, 255, 0.85);
  font-weight: 600;
}

.mini .mini-note {
  font-size: 0.74rem;
  color: rgba(255, 255, 255, 0.65);
  margin-top: 4px;
}

/* ==========================================================================
   BARRA DE FILTROS TEMÁTICOS GLOBALES
   ========================================================================== */
.filter-strip {
  padding: 14px 20px;
  margin-bottom: 24px;
}

.filter-strip-inner {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.filter-label-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip, .chip-sm {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 6px 14px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.chip:hover, .chip-sm:hover {
  border-color: var(--primary);
  background: var(--surface);
}

.chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
  box-shadow: 0 2px 8px var(--primary-glow);
}

.chip-sm {
  padding: 4px 10px;
  font-size: 0.78rem;
}

/* ==========================================================================
   MÓDULOS DE CONTENIDO
   ========================================================================== */
.main-content-flow {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.content-section {
  padding: 28px;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.section-title-wrap {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.section-badge {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--primary);
}

.section-head h2 {
  font-size: 1.6rem;
}

.section-hint {
  font-size: 0.86rem;
  color: var(--muted);
}

.section-intro {
  font-size: 1rem;
  color: var(--text-secondary);
  margin-bottom: 20px;
}

/* 1. HIGHLIGHTS & DESTACADOS */
.highlights-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}

.highlight-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
}

.highlight-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow);
  border-color: var(--primary);
}

.highlight-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.highlight-icon {
  font-size: 1.5rem;
}

.highlight-card h4 {
  font-size: 1.1rem;
  color: var(--text);
}

.highlight-card p {
  color: var(--text-secondary);
  font-size: 0.94rem;
  flex: 1;
}

.highlight-card-tags {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 6px;
}

/* 2. DESARROLLO Y CAPÍTULOS */
.article-chapters {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.chapter-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  overflow: hidden;
  transition: border-color 0.2s;
}

.chapter-card:hover {
  border-color: var(--border-focus);
}

.chapter-summary {
  padding: 16px 20px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
  font-size: 1.15rem;
  user-select: none;
  list-style: none;
  background: var(--surface);
  border-bottom: 1px solid transparent;
}

.chapter-summary::-webkit-details-marker {
  display: none;
}

.chapter-summary-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chapter-num-badge {
  background: var(--primary-glow);
  color: var(--primary);
  font-size: 0.8rem;
  padding: 2px 8px;
  border-radius: 6px;
}

.chapter-toggle-icon {
  font-size: 0.9rem;
  color: var(--muted);
  transition: transform 0.2s ease;
}

details[open] > .chapter-summary {
  border-bottom-color: var(--border);
}

details[open] > .chapter-summary .chapter-toggle-icon {
  transform: rotate(180deg);
}

.chapter-body {
  padding: 22px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chapter-lead {
  font-size: 1.05rem;
  color: var(--text);
  font-weight: 500;
  line-height: 1.6;
}

.chapter-paragraph {
  color: var(--text-secondary);
  font-size: 0.98rem;
  line-height: 1.7;
}

.chapter-callout {
  background: var(--surface);
  border-left: 4px solid var(--primary);
  padding: 14px 18px;
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  font-style: italic;
  color: var(--text);
}

.chapter-list {
  margin: 0;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  color: var(--text-secondary);
}

.chapter-list li {
  line-height: 1.6;
}

.chapter-keypoints {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 14px 18px;
}

.chapter-keypoints strong {
  display: block;
  font-size: 0.88rem;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 8px;
}

/* 3. CUESTIONARIO INTERACTIVO (QUIZ) */
.quiz-container {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.quiz-score-pill {
  background: var(--surface2);
  border: 1px solid var(--border);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 0.88rem;
}

.quiz-score-pill strong {
  color: var(--primary);
}

.quiz-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 20px;
}

.quiz-question-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.quiz-num {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
  flex-shrink: 0;
}

.quiz-question-head h4 {
  font-size: 1.05rem;
}

.quiz-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 14px;
}

.quiz-option-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 12px 16px;
  text-align: left;
  justify-content: flex-start;
  font-weight: 500;
  color: var(--text);
  transition: all 0.15s ease;
  width: 100%;
}

.quiz-option-btn:hover:not(:disabled) {
  border-color: var(--primary);
  background: var(--surface2);
}

.quiz-option-btn.correct {
  background: rgba(16, 185, 129, 0.12) !important;
  border-color: var(--success) !important;
  color: var(--success) !important;
  font-weight: 700;
}

.quiz-option-btn.incorrect {
  background: rgba(239, 68, 68, 0.12) !important;
  border-color: var(--danger) !important;
  color: var(--danger) !important;
  font-weight: 700;
}

.quiz-feedback {
  padding: 12px 16px;
  border-radius: var(--r-sm);
  font-size: 0.9rem;
  line-height: 1.5;
}

.quiz-feedback.correct {
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid var(--success);
  color: var(--text);
}

.quiz-feedback.incorrect {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid var(--danger);
  color: var(--text);
}

/* 4. GLOSARIO */
.glossary-search-wrap input {
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.88rem;
  width: 240px;
}

.glossary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
}

.glossary-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 16px 18px;
  transition: transform 0.15s, border-color 0.15s;
}

.glossary-card:hover {
  transform: translateY(-2px);
  border-color: var(--primary);
}

.glossary-card dt {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--primary);
  margin-bottom: 6px;
}

.glossary-card dd {
  margin: 0;
  font-size: 0.92rem;
  color: var(--text-secondary);
}

/* 5. GALERÍA VISUAL */
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 18px;
}

.img-card {
  border-radius: var(--r-sm);
  background: var(--surface2);
  border: 1px solid var(--border);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform 0.2s, box-shadow 0.2s;
}

.img-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow);
}

.img-card-media {
  position: relative;
  aspect-ratio: 4 / 3;
  width: 100%;
  overflow: hidden;
  background: var(--border);
  cursor: pointer;
}

.img-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.3s ease;
}

.img-card:hover img {
  transform: scale(1.04);
}

.img-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
  text-align: center;
  background: var(--surface2);
  color: var(--muted);
  gap: 8px;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.img-card .body {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.img-card .body strong {
  font-size: 1.02rem;
  color: var(--text);
}

.img-card .body p {
  font-size: 0.86rem;
  color: var(--muted);
  line-height: 1.4;
  flex: 1;
}

.img-card-footer {
  margin-top: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.img-card-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

.img-card-model-wrap {
  display: flex;
  align-items: center;
}

.card-model-select {
  padding: 4px 8px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.76rem;
  max-width: 155px;
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s;
}

.card-model-select:focus, .card-model-select:hover {
  border-color: var(--primary);
}

.img-error-box {
  padding: 16px 12px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: rgba(239, 68, 68, 0.06);
  border: 1px dashed var(--danger);
  border-radius: var(--r-sm);
  height: 100%;
  color: var(--text);
}

.img-error-box strong {
  font-size: 0.88rem;
  color: var(--danger);
}

.img-error-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 8px;
}

/* 6. FAQ LIST */
.faq-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.faq-item {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  overflow: hidden;
}

.faq-summary {
  padding: 16px 20px;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.faq-summary::-webkit-details-marker {
  display: none;
}

.faq-content {
  padding: 0 20px 16px;
  color: var(--text-secondary);
  font-size: 0.95rem;
  line-height: 1.6;
}

/* ==========================================================================
   FOOTER
   ========================================================================== */
.footer {
  padding: 24px 32px;
  margin-top: 24px;
}

.footer-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 20px;
}

.footer-brand {
  display: flex;
  align-items: center;
  gap: 16px;
}

.footer-logo {
  width: 48px;
  height: 48px;
  object-fit: contain;
}

.footer-brand strong {
  display: block;
  font-size: 0.95rem;
}

.footer-brand p {
  font-size: 0.85rem;
  color: var(--muted);
}

.footer-credits, .setup-credits {
  margin-top: 10px;
  font-size: 0.86rem;
  color: var(--text-secondary);
  border-top: 1px dashed var(--border);
  padding-top: 8px;
}

.footer-credits strong, .setup-credits strong {
  color: var(--primary);
  font-weight: 700;
}

.setup-credits {
  margin-top: 18px;
  text-align: center;
}

.footer-actions {
  display: flex;
  gap: 10px;
}

/* ==========================================================================
   LIGHTBOX MODAL PARA IMÁGENES
   ========================================================================== */
.lightbox-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
}

.lightbox-content {
  position: relative;
  z-index: 2;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--shadow-lg);
  max-width: 800px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.lightbox-close {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 3;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.6);
  color: #ffffff;
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lightbox-img-wrap {
  width: 100%;
  max-height: 55vh;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.lightbox-img-wrap img {
  max-width: 100%;
  max-height: 55vh;
  object-fit: contain;
  display: block;
}

.lightbox-caption {
  padding: 24px;
}

.lightbox-caption h3 {
  font-size: 1.3rem;
  margin-bottom: 8px;
}

.lightbox-caption p {
  color: var(--text-secondary);
  font-size: 0.95rem;
  margin-bottom: 14px;
}

.lightbox-prompt-box {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 12px;
  margin-bottom: 16px;
}

.lightbox-prompt-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 4px;
}

.lightbox-prompt-box code {
  font-family: monospace;
  font-size: 0.85rem;
  color: var(--text);
  word-break: break-word;
}

/* ==========================================================================
   TOAST NOTIFICACIONES
   ========================================================================== */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  padding: 12px 18px;
  border-radius: var(--r-sm);
  box-shadow: var(--shadow-lg);
  font-size: 0.9rem;
  font-weight: 600;
  pointer-events: auto;
  animation: slideInRight 0.25s ease-out;
}

.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.info { border-left-color: var(--accent); }

@keyframes slideInRight {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ==========================================================================
   RESPONSIVE Y PRINT
   ========================================================================== */
@media (max-width: 960px) {
  .grid {
    grid-template-columns: 1fr;
  }
  .hero-top {
    grid-template-columns: 1fr;
  }
  .app-toolbar {
    flex-wrap: wrap;
  }
  .toolbar-search {
    order: 3;
    max-width: 100%;
    width: 100%;
  }
}

@media (max-width: 640px) {
  .setup {
    padding: 20px;
  }
  .hero {
    padding: 24px 18px;
  }
  .content-section {
    padding: 20px 16px;
  }
  .grid-sub {
    grid-template-columns: 1fr;
  }
  .mini-grid {
    grid-template-columns: 1fr;
  }
  .setup-head {
    flex-direction: column;
    align-items: flex-start;
  }
}

@media print {
  .app-toolbar, .filter-strip, .quiz-section, .btns, .setup, #edit-config-btn, #export-html-btn {
    display: none !important;
  }
  body {
    background: #fff;
    color: #000;
  }
  .panel {
    box-shadow: none;
    border: 1px solid #ccc;
  }
  .hero {
    background: #eee !important;
    color: #000 !important;
  }
  .hero h1, .hero p, .hero strong {
    color: #000 !important;
  }
}

.audio-button { padding: 7px 11px; font-size: .78rem; background: rgba(255,255,255,.15); color: inherit; border: 1px solid rgba(255,255,255,.26); }
.summary-card-head { flex-wrap: wrap; }
.summary-card-head .audio-button { margin-left: auto; }
.metric-track, .mastery-track { height: 5px; border-radius: 99px; overflow: hidden; background: rgba(255,255,255,.2); margin-top: 10px; }
.metric-track span, .mastery-track span { display: block; height: 100%; width: var(--progress, 0%); border-radius: inherit; background: linear-gradient(90deg, #67e8f9, #a7f3d0); animation: progressIn .9s ease both; }
@keyframes progressIn { from { width: 0; } to { width: var(--progress); } }
.charts-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: 18px; }
.chart-card { min-width: 0; padding: 20px; border: 1px solid var(--border); border-radius: var(--r-sm); background: var(--surface2); }
.chart-card h3 { font-size: 1.08rem; margin-bottom: 12px; }
.data-chart { width: 100%; height: auto; overflow: visible; }
.chart-label, .chart-value { fill: var(--text-secondary); font: 12px var(--font-body); }
.chart-value { font-weight: 700; }
.chart-bar { fill: var(--primary); cursor: pointer; transition: opacity .2s, filter .2s; }
.chart-bar:hover, .chart-mark:hover, .chart-bar.selected, .chart-mark.selected { filter: brightness(1.18); opacity: .72; }
.chart-mark { fill: var(--secondary); stroke: var(--surface); stroke-width: 3; cursor: pointer; }
.chart-hint { color: var(--muted); font-size: .76rem; margin-top: 8px; }
.matrix-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.matrix-card { padding: 20px; border: 1px solid var(--border); border-left: 5px solid var(--primary); border-radius: var(--r-sm); background: var(--surface2); }
.matrix-card > span { font-size: .73rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--primary); }
.matrix-card h3 { margin: 5px 0 8px; font-size: 1.08rem; }
.matrix-card p { color: var(--text-secondary); }
.matrix-strength, .matrix-opportunity, .matrix-solution, .matrix-advantage { border-left-color: #16a34a; }
.matrix-strength > span, .matrix-opportunity > span, .matrix-solution > span, .matrix-advantage > span { color: #15803d; }
.matrix-weakness, .matrix-threat, .matrix-disadvantage { border-left-color: #ef4444; }
.matrix-weakness > span, .matrix-threat > span, .matrix-disadvantage > span { color: #dc2626; }
.matrix-challenge { border-left-color: #f59e0b; }
.matrix-challenge > span { color: #b45309; }
.mastery-head { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 3px 12px; padding: 0 2px 8px; color: var(--text-secondary); font-size: .88rem; }
.mastery-head strong { color: var(--primary); font-size: 1.1rem; }
.mastery-track { grid-column: 1 / -1; margin: 0; background: var(--border); }
.mastery-track span { width: 0; background: linear-gradient(90deg, #34d399, #059669); transition: width .35s ease; }
.glossary-card { min-height: 210px; height: 210px; padding: 0; perspective: 900px; background: transparent; border: 0; }
.glossary-card:hover { transform: none; border-color: transparent; }
.flashcard-inner { position: relative; height: 100%; transform-style: preserve-3d; transition: transform .55s cubic-bezier(.2,.7,.2,1); }
.glossary-card.flipped .flashcard-inner { transform: rotateY(180deg); }
.flashcard-face { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: flex-start; justify-content: center; gap: 12px; padding: 20px; border: 1px solid var(--border); border-radius: var(--r-sm); background: var(--surface2); backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.flashcard-front { align-items: center; text-align: center; }
.flashcard-front h3 { color: var(--primary); font-size: 1.15rem; }
.flashcard-kicker { color: var(--muted); font-size: .72rem; letter-spacing: .1em; text-transform: uppercase; }
.flashcard-back { transform: rotateY(180deg); justify-content: space-between; }
.flashcard-back p { color: var(--text-secondary); font-size: .9rem; }
.flashcard-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.flashcard-actions button { padding: 7px 10px; font-size: .76rem; }
.mastery-known { background: rgba(16,185,129,.14); color: #047857; }
.mastery-review { background: rgba(245,158,11,.15); color: #b45309; }
.glossary-card.mastered .flashcard-face { border-color: #10b981; }
.glossary-card.needs-review .flashcard-face { border-color: #f59e0b; }
.term-hover { position: relative; border-radius: 3px; background: color-mix(in srgb, var(--warning) 22%, transparent); color: inherit; cursor: help; text-decoration: underline dotted var(--warning); text-underline-offset: 3px; }
.term-hover::after { content: attr(data-def); position: absolute; z-index: 50; left: 50%; bottom: calc(100% + 9px); width: min(280px, 80vw); padding: 10px 12px; border-radius: 9px; background: var(--text); color: var(--surface); font-size: .78rem; font-weight: 400; line-height: 1.45; box-shadow: var(--shadow-lg); opacity: 0; visibility: hidden; transform: translate(-50%, 4px); transition: .16s ease; pointer-events: none; }
.term-hover:hover::after, .term-hover:focus::after, .term-hover:active::after { opacity: 1; visibility: visible; transform: translate(-50%, 0); }
.reading-progress { position: fixed; z-index: 300; inset: 0 0 auto; height: 3px; pointer-events: none; }
.reading-progress span { display: block; width: 0; height: 100%; background: linear-gradient(90deg, var(--accent), var(--primary), var(--secondary)); box-shadow: 0 0 10px var(--primary-glow); }
.floating-toc { position: fixed; z-index: 90; top: 50%; right: 14px; width: 160px; max-height: 56vh; overflow: auto; padding: 14px 12px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface-translucent); backdrop-filter: blur(12px); box-shadow: var(--shadow); transform: translateY(-50%); }
.floating-toc > strong { display: block; margin: 0 5px 8px; color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; }
.floating-toc nav { display: flex; flex-direction: column; gap: 3px; }
.floating-toc a { padding: 6px 7px; border-left: 2px solid transparent; border-radius: 0 6px 6px 0; color: var(--text-secondary); font-size: .75rem; line-height: 1.35; }
.floating-toc a.active { border-color: var(--primary); background: var(--primary-glow); color: var(--primary); font-weight: 700; }
.slide-deck { position: fixed; z-index: 500; inset: 0; display: flex; flex-direction: column; justify-content: center; padding: clamp(28px, 8vw, 120px); background: var(--bg); color: var(--text); }
.slide-deck.hidden { display: none; }
.slide-deck h1 { max-width: 1050px; margin: 16px 0 28px; font-size: clamp(2rem, 6vw, 5.6rem); letter-spacing: -.04em; }
.slide-count { color: var(--primary); font-weight: 800; letter-spacing: .12em; }
.slide-body { max-width: 980px; max-height: 48vh; overflow: auto; white-space: pre-line; color: var(--text-secondary); font-size: clamp(1rem, 2vw, 1.4rem); line-height: 1.8; }
.slide-controls { display: flex; gap: 12px; margin-top: 34px; }
.slide-close { position: absolute; top: 24px; right: 28px; padding: 4px 12px; background: transparent; color: var(--text); font-size: 2.4rem; }
.slide-hint { margin-top: 15px; color: var(--muted); font-size: .8rem; }
body.presentation-active { overflow: hidden; }
@media (max-width: 1600px) { .floating-toc { display: none; } }
@media (max-width: 960px) { .toolbar-actions { flex-wrap: wrap; justify-content: flex-start; width: 100%; } }
@media (max-width: 640px) { .matrix-grid { grid-template-columns: 1fr; } .summary-card-head .audio-button { margin-left: 0; } .slide-controls button { flex: 1; } }
