/* ===================== */
/* 1. VARIABLES          */
/* ===================== */
:root {
  /* Tipografía */
  --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-reading: 'Merriweather', 'Georgia', serif;
  --font-title: 'Playfair Display', 'Georgia', serif;

  /* Colores y Fondos */
  --bg-body: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --bg-container: #ffffff;
  --bg-header: linear-gradient(135deg, #1e3a5f 0%, #2d5a87 100%);
  --bg-filters: #f8f9fa;
  --text-main: #2d3748;
  --text-muted: #495057;
  --border: #dee2e6;
  --accent: #667eea;
  --highlight-bg: #fff3cd;
  --highlight-text: #856404;
  --card-hover: #f0f4ff;
  --tab-inactive: rgba(255, 255, 255, 0.2);
  --tab-active: rgba(255, 255, 255, 0.95);
  --tab-active-text: #1e3a5f;

  /* Sombras y Efectos */
  --shadow-soft: 0 4px 20px rgba(0, 0, 0, 0.08);
  --shadow-elevated: 0 12px 40px rgba(0, 0, 0, 0.12);
  --glass-bg: rgba(255, 255, 255, 0.85);
  --glass-border: rgba(255, 255, 255, 0.3);

  /* ✨ Espaciado de línea — controlado desde el panel de ajustes */
  --line-height-content: 1.5;
}

[data-theme="dark"] {
  --bg-body: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
  --bg-container: #1e293b;
  --bg-header: linear-gradient(135deg, #020617 0%, #0f172a 100%);
  --bg-filters: #334155;
  --text-main: #f1f5f9;
  --text-muted: #cbd5e0;
  --border: #4a5568;
  --accent: #a5b4fc;
  --highlight-bg: #854d0e;
  --highlight-text: #fef3c7;
  --card-hover: #2d3a4f;
  --tab-inactive: rgba(255, 255, 255, 0.1);
  --tab-active: rgba(255, 255, 255, 0.15);
  --tab-active-text: #e2e8f0;
  
  --shadow-soft: 0 4px 20px rgba(0, 0, 0, 0.3);
  --shadow-elevated: 0 12px 40px rgba(0, 0, 0, 0.4);
  --glass-bg: rgba(30, 41, 59, 0.85);
  --glass-border: rgba(255, 255, 255, 0.1);
}

/* ===================== */
/* 2. RESET Y BASE       */
/* ===================== */
html {
  -webkit-text-size-adjust: 100%;
  -moz-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* Prevención universal contra zoom de teclado en móviles (iOS / Android auto-zoom si font-size < 16px) */
@media (max-width: 820px) {
  input[type="text"],
  input[type="search"],
  input[type="email"],
  input[type="password"],
  input[type="number"],
  select,
  textarea {
    font-size: 16px !important;
  }
}

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

body {
  font-family: var(--font-ui);
  background: var(--bg-body);
  background-attachment: fixed;
  min-height: 100vh;
  padding: 20px;
  color: var(--text-main);
  transition: all 0.3s ease;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Selección de texto elegante ── */
::selection {
  background: var(--accent);
  color: #ffffff;
  text-shadow: none;
}

::-moz-selection {
  background: var(--accent);
  color: #ffffff;
  text-shadow: none;
}

.container {
  max-width: 850px;
  margin: 0 auto;
  background: var(--bg-container);
  border-radius: 18px;
  box-shadow: var(--shadow-elevated, 0 20px 60px rgba(0, 0, 0, 0.3));
  overflow: hidden;
  font-size: var(--font-reading, 1.18rem);
  /* ← TODO hereda */
}

/* ===================== */
/* 7. CONTENIDO          */
/* ===================== */
.content {
  padding: 36px 40px;
  font-size: 1em;
  /* ← hereda del container */
  line-height: var(--line-height-content, 1.5);
  animation: fadeInContent 0.4s ease-out;
}

@keyframes fadeInContent {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.verse {
  margin: 0;
  /* ← sin margen */
  padding: 4px 8px;
  /* ← padding suave para el hover */
  text-align: justify;
  font-family: var(--font-reading);
  line-height: var(--line-height-content, 1.5);
  transition: line-height 0.25s ease, background-color 0.2s ease, border-radius 0.2s ease;
  border-radius: 6px;
}

.verse:hover {
  background-color: var(--card-hover);
}

/* base.css — reemplaza la regla .verse-number existente */
.verse-number {
  color: var(--accent);
}

/* base.css */
.reference {
  padding: 0 32px;
  font-weight: 700;
  font-size: 1em;
  /* ← relativo, hereda */
  color: var(--text-main);
  opacity: 0;
  transition: opacity 0.3s;
}

.reference.visible {
  opacity: 1;
  padding-top: 20px;
}

/* Loading & Error */
.loading,
.placeholder {
  text-align: center;
  color: var(--text-muted);
  font-style: italic;
}

.error {
  text-align: center;
  color: #e53e3e;
}

/* ===================== */
/* TAMAÑO DE FUENTE      */
/* ===================== */
#content,
#content .verse,
#content .comp-cell,
#content .search-result-text,
#content p {
  font-size: var(--font-reading, 1.1rem) !important;
}

#content .verse-number {
  font-size: 0.60em !important;
}

/* ===================== */
/* ESPACIADO DE LÍNEA    */
/* ===================== */
#content .verse,
#content .verse-text,
#content p:not(.placeholder):not(.error):not(.loading),
#content .comp-verse-text,
#content .search-result-text {
  line-height: var(--line-height-content, 1.5) !important;
  transition: line-height 0.25s ease;
}

/* ========================================= */
/* MOBILE — Smartphone Redesign              */
/* ========================================= */
@media (max-width: 600px) {

  body {
    padding: 0;
    background: var(--bg-body);
    background-attachment: fixed;
  }

  .container {
    border-radius: 0;
    box-shadow: none;
    min-height: 100vh;
    max-width: 100%;
  }

  header {
    padding: 14px 16px;
    background: var(--bg-header);
    border-bottom: none;
  }

  #mainTitle {
    font-size: 1.05rem;
    font-weight: 600;
  }

  /* ── Tabs móviles: pill scroll horizontal ── */
  .mode-tabs {
    padding: 8px 10px;
    gap: 6px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    background: var(--bg-header);
  }

  .mode-tabs::-webkit-scrollbar {
    display: none;
  }

  .mode-tab {
    flex: 0 0 auto;
    padding: 8px 14px;
    font-size: 0.78rem;
    font-weight: 500;
    border-radius: 20px;
    white-space: nowrap;
  }

  .mode-tab .tab-text {
    font-size: 0.78rem;
  }

  .custom-tab-img {
    width: 18px;
    height: 18px;
  }

  /* ── Filtros elegantes ── */
  .filters-toggle {
    padding: 10px 16px;
    background: var(--bg-filters);
    border-bottom: 1px solid var(--border);
    font-size: 0.82rem;
  }

  .filters-toggle-ref {
    font-size: 0.85rem;
  }

  .filters {
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    padding: 16px;
  }

  select,
  input[type="text"] {
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 16px !important;
  }

  /* ── Contenido ── */
  .content {
    padding: 20px 16px;
    animation: none;
  }

  .verse {
    font-family: var(--font-reading);
    line-height: 1.75;
    padding: 6px 10px;
    border-radius: 8px;
    margin-bottom: 2px;
  }

  .reference {
    padding: 0 16px;
    font-size: 0.95em;
    font-family: var(--font-ui);
    font-weight: 600;
    letter-spacing: 0.03em;
  }

  .reference.visible {
    padding-top: 16px;
  }

  #content .verse-number {
    font-size: 0.62em !important;
  }

  .placeholder {
    font-size: 1em;
    padding: 24px 16px;
  }

  /* ── FAB en móvil ── */
  .floating-action-button {
    bottom: 20px;
    right: 16px;
    left: 16px;
    width: calc(100% - 32px);
    justify-content: center;
    border-radius: 28px;
    padding: 15px 24px;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
  }

}

/* ── Muy pequeño ── */
@media (max-width: 380px) {
  .content {
    padding: 14px 12px;
  }

  .verse {
    padding: 4px 8px;
  }

  #content,
  #content .verse,
  #content p {
    font-size: var(--font-reading, 0.98rem) !important;
  }
}

/* =========================================================
   1. ESTILOS VISUALES DEL SIDEBAR (Panel Lateral)
   Aplica los colores, fondos y estructura interna
   ========================================================= */
#sidebarPanel {
  background: var(--bg-container);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  overflow: hidden;
  z-index: 100;
  /* Estructura interna */
  display: flex;
  flex-direction: column;
}

/* Darle formato a la cabecera (donde está el icono y la X) */
#sidebarPanel .sidebar-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: var(--bg-filters);
  border-bottom: 1px solid var(--border);
  font-weight: bold;
}

/* Alinear correctamente el icono y el título del panel */
#sidebarPanel .sidebar-title {
  display: flex;
  align-items: center;
  gap: 10px;
  /* Espacio entre el icono del libro y el texto */
  font-size: 1.1rem;
  color: var(--text-main);
}

/* Asegurar que el contenedor de la X se comporte bien */
#sidebarPanel .sidebar-controls {
  display: flex;
  align-items: center;
}

#sidebarPanelClose {
  background: transparent;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  color: var(--text-muted);
  transition: color 0.2s;
}

#sidebarPanelClose:hover {
  color: #e53e3e;
  /* Rojo al pasar el ratón */
}

#sidebarPanelContent {
  padding: 20px;
  overflow-y: auto;
  /* Scroll interno si el contenido es muy largo */
  flex: 1;
  /* Ocupa el resto del espacio */
}


/* =========================================================
   2. COMPORTAMIENTO MÓVIL Y TABLET (< 1180px)
   ========================================================= */
@media (max-width: 1179px) {

  #sidebarPanel,
  .sidebar-panel {
    display: none !important;
    /* MATA el panel. NUNCA debe verse aquí. */
  }
}


/* =========================================================
   3. COMPORTAMIENTO ESCRITORIO (>= 1180px)
   ========================================================= */
@media (min-width: 1180px) {

  /* Por defecto, el panel está oculto */
  #sidebarPanel {
    display: none;
  }

  /* El contenedor principal de la app (.app-layout) */
  .app-layout {
    display: flex;
    justify-content: center;
    /* Centra tu app cuando no hay sidebar */
    width: 100%;
    transition: max-width 0.3s ease;
  }

  /* Cuando el sidebar NORMAL o el de IA están abiertos */
  .app-layout.has-sidebar,
  .app-layout.has-ia-sidebar {
    max-width: 1300px;
    margin: 0 auto;
    gap: 24px;
    align-items: flex-start;
  }

  /* Ajuste del contenedor principal de la Biblia */
  .app-layout.has-sidebar .container,
  .app-layout.has-ia-sidebar .container {
    flex: 1;
    margin: 0;
  }

  /* El panel lateral cuando recibe la clase .open desde JS */
  #sidebarPanel.open {
    display: flex;
    /* Lo hace visible y activa su flex interno */
    flex: 0 0 380px;
    /* Ancho fijo del sidebar: 380px. No crece, no encoge */
    height: calc(100vh - 40px);
    /* Altura igual a la pantalla menos el margen */
    position: sticky;
    top: 20px;
    /* Se queda pegado arriba al hacer scroll */
  }

}

/* ===================================================== */
/* SCROLLBARS PERSONALIZADAS Y DISCRETAS                 */
/* ===================================================== */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(156, 163, 175, 0.5);
  border-radius: 4px;
  transition: background 0.2s ease;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(156, 163, 175, 0.8);
}

[data-theme="dark"] ::-webkit-scrollbar-thumb {
  background: rgba(75, 85, 99, 0.6);
}

[data-theme="dark"] ::-webkit-scrollbar-thumb:hover {
  background: rgba(75, 85, 99, 0.9);
}

/* ===================================================== */
/* TRANSICIÓN DIFUMINADA DE CAPÍTULO (DE-BLUR EDITORIAL) */
/* ===================================================== */
@keyframes chapterContentDeBlur {
  0% {
    opacity: 0;
    filter: blur(8px);
    transform: translateY(6px);
  }
  100% {
    opacity: 1;
    filter: blur(0px);
    transform: translateY(0);
  }
}

.chapter-transition-in {
  animation: chapterContentDeBlur 0.48s cubic-bezier(0.2, 0.8, 0.25, 1) both;
  will-change: opacity, filter, transform;
}

@media (prefers-reduced-motion: reduce) {
  .chapter-transition-in {
    animation: none !important;
    opacity: 1 !important;
    filter: none !important;
    transform: none !important;
  }
}