/* ==========================================================================
   VARIABLES Y CONFIGURACIÓN BASE
   ========================================================================== */
:root {
  --navy: #0F2340;         
  --gold: #C8960C;         
  --cream: #F5F2EA;        
  --cream-dk: #E8E3D5;     
  --sapphire: #2A4A7F;     
  --olive: #4A7C59;        
  --terracotta: #C0522A;   
  --white: #FFFFFF;        
  --bronze: #8b7355;       
  --text-main: #2C3E50;    
  --sidebar-width: 270px;
  --bg-body: #F5F2EA;
  --bg-card: #FFFFFF;
  --border-color: #e2e8f0;
  --text-secondary: #64748b;
}

/* Dark Mode */
[data-theme="dark"] {
  --navy: #1e293b;
  --gold: #fbbf24;
  --cream: #0f172a;
  --cream-dk: #1e293b;
  --sapphire: #3b82f6;
  --olive: #22c55e;
  --terracotta: #f97316;
  --white: #1e293b;
  --bronze: #94a3b8;
  --text-main: #f1f5f9;
  --bg-body: #0f172a;
  --bg-card: #1e293b;
  --border-color: #334155;
  --text-secondary: #94a3b8;
  --sidebar-width: 270px;
}
/* Refuerzo modo oscuro: evitar texto blanco invisible sobre topbar/sidebar,
   ya que en modo oscuro --white y --navy quedan casi identicos */
[data-theme="dark"] .topbar-brand h1,
[data-theme="dark"] .topbar h1, [data-theme="dark"] .topbar h2,
[data-theme="dark"] .sidebar-logo h2 {
    color: #ffffff !important;
}

[data-theme="dark"] .badge-rgpd-ok { background: #166534; color: #86efac; }
[data-theme="dark"] .badge-rgpd-no { background: #7f1d1d; color: #fca5a5; }
[data-theme="dark"] .bottom-nav { box-shadow: 0 -2px 10px rgba(0,0,0,0.3); }
[data-theme="dark"] .kpi-card { box-shadow: 0 4px 15px rgba(0,0,0,0.15); }
[data-theme="dark"] .card { box-shadow: 0 4px 15px rgba(0,0,0,0.15); }
[data-theme="dark"] .member-item { border-bottom-color: var(--border-color); }
[data-theme="dark"] .evento-fecha { background: var(--bg-card); }
[data-theme="dark"] .member-row { background: var(--bg-card); }
[data-theme="dark"] table th { background: var(--bg-card); color: var(--text-main); border-bottom-color: var(--border-color); }
[data-theme="dark"] table td { border-bottom-color: var(--border-color); color: var(--text-main); }
[data-theme="dark"] .alerta-roja { background: #450a0a; border-color: #7f1d1d; color: #fca5a5; }
[data-theme="dark"] .alerta-azul { background: #0f172a; border-color: #1e40af; color: #93c5fd; }
[data-theme="dark"] .alerta-verde { background: #0a0f0a; border-color: #166534; color: #86efac; }

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Lato', sans-serif;
  background-color: var(--bg-body);
  color: var(--text-main);
  padding-bottom: 85px; 
  transition: padding-left 0.3s ease, background-color 0.3s ease, color 0.3s ease;
  overflow-x: hidden;
}

h1, h2, h3, h4 { font-family: 'Cinzel', serif; color: var(--navy); }

/* ==========================================================================
   BARRA SUPERIOR (TOPBAR)
   ========================================================================== */
.topbar {
  background: var(--navy); 
  color: var(--white); 
  padding: 15px 20px;
  display: flex; 
  justify-content: space-between; 
  align-items: center;
  position: sticky; 
  top: 0; 
  z-index: 100; 
  box-shadow: 0 2px 10px rgba(0,0,0,0.15);
  transition: all 0.3s ease;
}
.topbar-brand { display: flex; align-items: center; gap: 12px; }
.topbar-brand h1 { color: var(--white); font-size: 18px; margin: 0; letter-spacing: 1px; }

/* Refuerzo: cualquier titulo dentro del topbar debe ser blanco, sin importar el tag o clase que use */
.topbar h1, .topbar h2, .topbar h3, .topbar h4, .topbar .page-title, .topbar-brand span, .topbar-brand p {
    color: #ffffff !important;
}

.icon-btn {
    background: none;
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
}

/* ==========================================================================
   MENÚ LATERAL (SIDEBAR) - DISEÑO PROFESIONAL
   ========================================================================== */
.sidebar {
  position: fixed; 
  top: 0; 
  left: 0;
  /* transform evita que la sombra se filtre cuando está cerrado */
  transform: translateX(-100%);
  width: min(var(--sidebar-width), 65vw); /* Nunca más del 82% en móvil */
  height: 100vh;
  background: #0F2340; /* Fijo — independiente del tema */
  color: #ffffff; 
  z-index: 2000;
  transition: transform 0.3s ease; 
  display: flex; 
  flex-direction: column;
  box-shadow: none; /* Solo aparece al abrir */
  overflow-y: auto;
}

/* Clase que activa el JS para abrirlo */
.sidebar.open { 
  transform: translateX(0) !important;
  box-shadow: 4px 0 20px rgba(0,0,0,0.35);
}

.sidebar-logo { 
  padding: 25px 20px; 
  border-bottom: 1px solid rgba(255,255,255,0.1); 
  display: flex;          
  align-items: center;    
  gap: 12px;              
}

.sidebar-logo h2 { color: #ffffff; font-size: 14px; margin: 0; line-height: 1.2; }
.sidebar-logo p { color: #C8960C; font-size: 9px; text-transform: uppercase; margin: 0; }

/* Refuerzo: si el nombre de la iglesia no viene en h2, igual se ve blanco */
.sidebar-logo, .sidebar-logo span, .sidebar-logo strong, .sidebar-logo div {
    color: #ffffff;
}
.sidebar-logo p { color: #C8960C !important; }

/* Títulos de secciones del menú (Ej: MINISTERIOS, ADMINISTRACIÓN) */
.menu-section-title {
    font-size: 10px;
    font-weight: 900;
    color: #C8960C;
    padding: 20px 20px 5px 20px;
    letter-spacing: 1.5px;
    opacity: 0.8;
}

.nav-item { 
  display: flex; 
  align-items: center; 
  padding: 12px 20px; 
  color: #ffffff; 
  text-decoration: none; 
  border-left: 4px solid transparent;
  transition: 0.2s;
  font-size: 14px;
}
.nav-item i { margin-right: 15px; color: #C8960C; width: 20px; text-align: center; font-size: 18px; }
.nav-item:hover, .nav-item.active { 
  background: rgba(255,255,255,0.05); 
  border-left-color: #C8960C;
  color: #C8960C;
}

.drawer-overlay { 
  position: fixed; 
  top: 0; 
  left: 0; 
  width: 100vw; 
  height: 100vh; 
  background: rgba(0,0,0,0.5); 
  z-index: 1500; 
  display: none; 
}
.drawer-overlay.open { display: block; }

/* ==========================================================================
   CONTENIDO Y TARJETAS (PÁGINAS)
   ========================================================================== */
.page { padding: 14px; transition: all 0.3s ease; max-width: 1200px; }
body .page-content { padding: 20px; padding-bottom: 100px; max-width: 1200px; }

/* Dashboard necesita ancho completo para sus grids */
body[data-offline-module="dashboard"] .page { max-width: none; margin: 0; }

.kpi-grid { 
  display: grid; 
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); 
  gap: 15px; 
  margin-bottom: 25px; 
}
.kpi-card { 
  background: var(--bg-card); 
  padding: 20px; 
  border-radius: 12px; 
  box-shadow: 0 4px 15px rgba(0,0,0,0.05); 
  border-bottom: 4px solid var(--gold); 
  text-align: center;
  text-decoration: none;
}
.kpi-value { font-size: 28px; font-weight: bold; color: var(--navy); display: block; }
.kpi-label { font-size: 11px; text-transform: uppercase; color: var(--bronze); font-weight: bold; }

.card { 
  background: var(--bg-card); 
  border-radius: 12px; 
  padding: 20px; 
  box-shadow: 0 4px 15px rgba(0,0,0,0.05); 
  margin-bottom: 20px;
  border: 1px solid var(--border-color);
}

/* ==========================================================================
   LISTADOS (MIEMBROS/VISITANTES)
   ========================================================================== */
.member-item { display: flex; align-items: center; padding: 15px 0; border-bottom: 1px solid var(--cream-dk); }
.member-item:last-child { border-bottom: none; }
.avatar { width: 48px; height: 48px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: bold; color: white; margin-right: 15px; font-size: 15px; flex-shrink: 0; background: var(--sapphire); }
.member-info { flex-grow: 1; }
.member-info strong { display: block; font-size: 16px; color: var(--navy); }
.member-info span { font-size: 13px; color: var(--bronze); }

/* ==========================================================================
   MENÚ INFERIOR (BOTTOM NAV) - SOLO MÓVIL
   ========================================================================== */
.bottom-nav {
  position: fixed; 
  bottom: 0; 
  width: 100%; 
  background: var(--bg-card);
  display: flex; 
  justify-content: space-around; 
  padding: 12px 0 18px 0; 
  box-shadow: 0 -2px 10px rgba(0,0,0,0.08); 
  z-index: 1000;
}
.bottom-nav-item { 
  background: none; 
  border: none; 
  color: var(--text-secondary); 
  display: flex; 
  flex-direction: column; 
  align-items: center; 
  font-size: 11px; 
  cursor: pointer; 
  text-decoration: none; 
}
.bottom-nav-item i { font-size: 22px; margin-bottom: 5px; }
.bottom-nav-item.active { color: var(--sapphire); font-weight: bold; }

/* ==========================================================================
   RESPONSIVE: CONFIGURACIÓN PARA PC
   ========================================================================== */
@media (min-width: 992px) {
  /* El menú se queda siempre a la izquierda */
  .sidebar {
    transform: translateX(0) !important;
    width: var(--sidebar-width); /* En PC ancho completo siempre */
    box-shadow: 4px 0 15px rgba(0,0,0,0.15);
  }

  /* El cuerpo de la página se empuja a la derecha */
  body {
    padding-left: var(--sidebar-width); 
    padding-bottom: 20px; 
  }

  /* Sidebar colapsada en PC */
  body.sidebar-collapsed {
    padding-left: 60px;
  }
  body.sidebar-collapsed .sidebar {
    width: 60px;
  }
  body.sidebar-collapsed .sidebar-logo h2,
  body.sidebar-collapsed .sidebar-logo p,
  body.sidebar-collapsed .nav-item span,
  body.sidebar-collapsed .menu-section-title {
    display: none;
  }
  body.sidebar-collapsed .nav-item {
    justify-content: center;
    padding: 14px 0;
  }
  body.sidebar-collapsed .nav-item i {
    margin-right: 0;
  }

  /* Ocultamos elementos innecesarios en pantalla grande */
  .bottom-nav, 
  .drawer-overlay,
  .icon-btn[onclick="toggleSidebar()"] {
    display: none !important; 
  }

  .topbar {
    width: 100%;
  }
  
  .page {
      padding: 14px 18px;
  }
}

/* ==========================================================================
   SEGURIDAD: Bloquear menú contextual y selección de texto
   ========================================================================== */
body {
  -webkit-touch-callout: none !important;
  -webkit-user-select: none !important;
  user-select: none !important;
}
/* Permitir selección de texto solo en inputs, textareas y debug */
input, textarea, .form-control, .search-bar {
  -webkit-user-select: text !important;
  user-select: text !important;
}

/* ==========================================================================
   MEJORAS RESPONSIVE GLOBALES — MÓVIL
   ========================================================================== */

/* --- Touch targets --- */
@media (pointer: coarse) {
  .nav-item, .bottom-nav-item, button, .btn, .btn-primario, .btn-outline,
  .btn-acceso, .btn-edit, .btn-abrir, .btn-submit, .tab-btn,
  a, .member-link, .icon-btn, .system-card, .kpi-card {
    min-height: 44px;
  }
}

/* --- Móvil --- */
@media (max-width: 768px) {
  /* Tablas — scroll horizontal en móvil */
  .table-responsive, table, div[style*="overflow"] {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    display: block;
    width: 100%;
  }
  table {
    min-width: 600px; /* Forzar scroll si la tabla es ancha */
    font-size: 12px;
  }
  table th, table td {
    white-space: nowrap;
    padding: 8px 10px !important;
  }

  /* Restaurar layout de tablas internas de FullCalendar */
  .fc table {
    min-width: 0 !important;
    display: table !important;
  }

  /* Botones full-width */
  .btn-primario, .btn-outline, .btn-submit, .btn-abrir, button.btn,
  .btn-acceso, .btn-cartel, button.rp-btn {
    width: 100% !important;
    justify-content: center !important;
    margin-bottom: 8px;
  }

  /* Grids a 1 columna */
  .kpi-grid, .grid-accesos, .admin-two-col, .grid-2col, .grid-docs,
  .agenda-contenedor, .caso-body-grid, .acta-body, .dashboard-grid {
    grid-template-columns: 1fr !important;
  }
  .system-kpis { grid-template-columns: 1fr 1fr !important; }
  .system-grid { grid-template-columns: 1fr !important; }

  /* Cards compactas */
  .card, .section-card, .system-card, .caso-card, .acta-card,
  .panel-directorio, .widget-card {
    padding: 14px !important;
  }

  /* Form elements sin zoom iOS */
  input, select, textarea, .form-control, .search-bar {
    font-size: 16px !important;
    padding: 12px !important;
    min-height: 44px;
  }

  /* Modales bottom-sheet */
  .modal-mask {
    align-items: flex-end !important;
    padding: 0 !important;
  }
  .modal-container {
    border-radius: 20px 20px 0 0 !important;
    max-height: 90vh !important;
    animation: slideUpMobile 0.3s ease-out !important;
  }
  .modal-body {
    padding: 16px !important;
    max-height: 70vh !important;
  }
  .modal-header {
    padding: 16px !important;
    border-radius: 20px 20px 0 0 !important;
  }

  /* Header módulos vertical */
  .header-modulo, .header-miembros, .header-sistema,
  .header-confidencial, .header-biblioteca, .header-360 {
    flex-direction: column !important;
    align-items: flex-start !important;
    text-align: left !important;
    padding: 14px !important;
  }

  /* Page spacing */
  .page-content {
    padding: 14px 10px !important;
    padding-bottom: 90px !important;
  }

  /* Prevenir horizontal scroll */
  body, html {
    overflow-x: hidden !important;
    max-width: 100vw;
  }
  .page, .page-content, .admin-page {
    max-width: 100vw !important;
    overflow-x: hidden;
  }

  /* Bottom nav */
  .bottom-nav {
    padding: 8px 0 14px 0 !important;
  }
  .bottom-nav-item {
    font-size: 10px !important;
    padding: 4px 0;
  }
  .bottom-nav-item i {
    font-size: 20px !important;
  }

  /* Topbar compact */
  .topbar {
    padding: 10px 14px !important;
  }
  .topbar-brand h1 {
    font-size: 14px !important;
  }

  /* Tabs scroll horizontal */
  .dir-tab-group, .tab-nav {
    display: flex !important;
    overflow-x: auto !important;
    flex-wrap: nowrap !important;
    gap: 6px !important;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 6px;
  }
  .dir-tab-group::-webkit-scrollbar,
  .tab-nav::-webkit-scrollbar { display: none; }
  .tab-btn, .tab-nav a {
    flex-shrink: 0 !important;
    padding: 10px 16px !important;
    font-size: 11px !important;
    min-height: 44px;
  }
  .tab-divider { display: none !important; }

  /* KPIs compactos */
  .kpi-card {
    padding: 14px !important;
  }
  .kpi-value {
    font-size: 22px !important;
  }

  /* Alertas columna */
  .alerta-pastoral, .admin-alert {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 6px !important;
  }

  /* Listas miembros */
  .miembro-item, .member-item {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 8px !important;
  }
  .member-info {
    width: 100%;
  }
  .user-actions {
    flex-shrink: 0;
  }

  /* Admin tabs — scroll horizontal en móvil */
  .admin-page .tab-nav {
    flex-direction: row !important;
    overflow-x: auto !important;
    flex-wrap: nowrap !important;
    gap: 6px !important;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 6px;
  }
  .admin-page .tab-nav::-webkit-scrollbar { display: none; }
  .admin-page .tab-nav a,
  .admin-page .tab-nav .nav-ext {
    flex-shrink: 0 !important;
    white-space: nowrap !important;
    padding: 10px 16px !important;
    font-size: 11px !important;
    min-height: 44px;
  }
  .admin-page .tab-nav .tab-divider {
    display: none !important;
  }
}

/* ─── Admin: User Cards ─── */
.user-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--bg-card);
  border-radius: 14px;
  border: 1px solid var(--border-color);
  margin-bottom: 8px;
}
.user-info {
  flex: 1;
  min-width: 0;
}
.user-info strong {
  display: block;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-info small {
  display: block;
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 2px;
}
.user-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 16px;
  flex-shrink: 0;
}
.user-actions {
  flex-shrink: 0;
}
.user-actions .btn-edit {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--bg-body);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  text-decoration: none;
  font-size: 15px;
}
.member-link {
  font-size: 11px;
  color: var(--gold) !important;
  margin-top: 2px;
}
.user-badges {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin-top: 6px;
}
.badge-rgpd-ok, .badge-rgpd-no {
  font-size: 9px;
  padding: 2px 8px;
  border-radius: 20px;
  font-weight: 700;
  text-transform: uppercase;
}
.badge-rgpd-ok { background: #dcfce7; color: #166534; }
.badge-rgpd-no { background: #fee2e2; color: #991b1b; }

.user-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

@keyframes slideUpMobile {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

@media (min-width: 769px) {
  .btn-primario, .btn-outline, .btn-submit, .btn-abrir, .btn-acceso {
    width: auto !important;
  }
}

/* Forzar barra superior (topbar) uniforme en toda la web */
body header.topbar {
  background: var(--navy) !important;
  box-shadow: 0 2px 10px rgba(0,0,0,0.15) !important;
}

/* MODO CLARO PARA MODULOS OSCUROS */
[data-theme="light"] body { background: #f8fafc !important; color: #0f172a; }
[data-theme="light"] .section-card, [data-theme="light"] .stat-card, [data-theme="light"] .opcion-card, [data-theme="light"] .panel-header, [data-theme="light"] .widget-header, [data-theme="light"] .member-row, [data-theme="light"] .song-card, [data-theme="light"] .canales-grid > div { background: #ffffff !important; box-shadow: 0 4px 10px rgba(0,0,0,0.05) !important; border-color: #e2e8f0 !important; color: #0f172a; }
[data-theme="light"] .form-control, [data-theme="light"] input, [data-theme="light"] select, [data-theme="light"] textarea { background: #ffffff !important; border: 1px solid #cbd5e1 !important; color: #0f172a; }
[data-theme="light"] .nav-card, [data-theme="light"] .menu-card { background: #ffffff !important; border-color: #e2e8f0 !important; color: #0f172a; }
[data-theme="light"] .nav-card:hover, [data-theme="light"] .menu-card:hover { background: #f1f5f9 !important; }
[data-theme="light"] h1, [data-theme="light"] h2, [data-theme="light"] h3, [data-theme="light"] h4, [data-theme="light"] .section-title { color: #0f172a; }
[data-theme="light"] p, [data-theme="light"] span:not(.badge), [data-theme="light"] .lbl { color: #475569; }
[data-theme="light"] .bloque-tiempo, [data-theme="light"] .guia-box { background: #f8fafc !important; border-color: #cbd5e1 !important; color: #0f172a; }

/* ═══════════════════════════════════════════════════════════════
   FIX FINAL: el titulo del topbar y el logo del sidebar SIEMPRE
   deben ser blancos, sin importar el tema (claro u oscuro).
   Esta regla va al final del archivo y usa mas clases en el
   selector que cualquier otra regla anterior, asi que gana pase
   lo que pase.
   ═══════════════════════════════════════════════════════════════ */
html[data-theme="light"] header.topbar h1,
html[data-theme="light"] .topbar-brand h1,
html[data-theme="light"] .sidebar-logo h2,
[data-theme="light"] header.topbar h1,
[data-theme="light"] .topbar-brand h1,
[data-theme="light"] .sidebar-logo h2 {
    color: #ffffff !important;
}

/* Excepcion: dentro del sidebar y del logo del topbar, los span no deben
   volverse grises en modo claro (la regla de arriba los afecta a todos).
   Deben heredar el color de su contenedor (blanco, dorado, etc.) */
[data-theme="light"] .sidebar span,
[data-theme="light"] .topbar-brand span {
    color: inherit !important;
}
