:root {
  --primary: #2563eb; --primary-dark: #1d4ed8; --primary-light: #dbeafe;
  --bg: #f3f4f6; --card: #ffffff; --text: #111827; --text-secondary: #6b7280;
  --border: #e5e7eb; --success: #10b981; --success-bg: #d1fae5;
  --danger: #ef4444; --danger-bg: #fee2e2; --warning: #f59e0b; --warning-bg: #fef3c7;
  --sidebar: 256px; --radius: 12px;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg); color: var(--text); line-height: 1.5; -webkit-font-smoothing: antialiased;
}
#loader {
  position: fixed; inset: 0; background: var(--bg); z-index: 9999;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  transition: opacity 0.3s;
}
#loader.hidden { opacity: 0; pointer-events: none; }
.spinner {
  width: 48px; height: 48px; border: 4px solid var(--border);
  border-top-color: var(--primary); border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.app-layout { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar); background: #111827; color: #fff;
  position: fixed; inset: 0 auto 0 0; z-index: 50;
  display: flex; flex-direction: column; transition: transform 0.3s;
}
.sidebar-header { padding: 1rem; border-bottom: 1px solid #1f2937; display: flex; align-items: center; gap: 0.75rem; }
.sidebar-logo { width: 40px; height: 40px; background: var(--primary); border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 1.25rem; }
.sidebar-brand h1 { font-size: 1.1rem; font-weight: 700; letter-spacing: -0.02em; }
.sidebar-brand p { font-size: 0.7rem; color: #9ca3af; }
.sidebar-nav { flex: 1; padding: 1rem; display: flex; flex-direction: column; gap: 0.25rem; }
.sidebar-nav a { display: flex; align-items: center; gap: 0.75rem; padding: 0.75rem 1rem; border-radius: 8px; color: #d1d5db; text-decoration: none; font-size: 0.9rem; font-weight: 500; transition: all 0.15s; }
.sidebar-nav a:hover { background: #1f2937; color: #fff; }
.sidebar-nav a.active { background: #1f2937; color: #fff; border-left: 3px solid var(--primary); }
.sidebar-footer { padding: 1rem; border-top: 1px solid #1f2937; font-size: 0.7rem; color: #6b7280; text-align: center; }
.main-area { flex: 1; margin-left: var(--sidebar); min-width: 0; display: flex; flex-direction: column; }
.topbar { height: 64px; background: var(--card); border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; padding: 0 1.5rem; position: sticky; top: 0; z-index: 40; }
.topbar-search { flex: 1; max-width: 500px; position: relative; }
.topbar-search input { width: 100%; padding: 0.5rem 1rem 0.5rem 2.5rem; border-radius: 999px; border: 1px solid transparent; background: #f3f4f6; font-size: 0.875rem; outline: none; transition: all 0.2s; }
.topbar-search input:focus { background: #fff; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.1); }
.topbar-search svg { position: absolute; left: 0.75rem; top: 50%; transform: translateY(-50%); color: #9ca3af; width: 18px; height: 18px; }
.search-results { position: absolute; top: calc(100% + 8px); left: 0; right: 0; background: #fff; border-radius: var(--radius); box-shadow: 0 10px 25px rgba(0,0,0,0.1); border: 1px solid var(--border); z-index: 60; overflow: hidden; display: none; }
.search-results.active { display: block; }
.search-result-item { display: flex; align-items: center; gap: 0.75rem; padding: 0.75rem 1rem; text-decoration: none; color: inherit; border-bottom: 1px solid #f3f4f6; cursor: pointer; }
.search-result-item:hover { background: #f9fafb; }
.search-result-item:last-child { border-bottom: none; }
.user-menu { position: relative; }
.user-trigger { display: flex; align-items: center; gap: 0.75rem; padding: 0.4rem 0.75rem; border-radius: 8px; cursor: pointer; border: none; background: none; }
.user-trigger:hover { background: #f3f4f6; }
.user-avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 0.8rem; font-weight: 700; }
.user-info { text-align: left; }
.user-info .name { font-size: 0.85rem; font-weight: 600; }
.user-info .role { font-size: 0.7rem; color: var(--text-secondary); text-transform: capitalize; }
.user-dropdown { position: absolute; right: 0; top: calc(100% + 8px); width: 220px; background: #fff; border-radius: var(--radius); box-shadow: 0 10px 25px rgba(0,0,0,0.1); border: 1px solid var(--border); z-index: 60; overflow: hidden; display: none; }
.user-dropdown.active { display: block; }
.user-dropdown-header { padding: 0.75rem 1rem; border-bottom: 1px solid var(--border); }
.user-dropdown-header .name { font-size: 0.85rem; font-weight: 600; }
.user-dropdown-header .email { font-size: 0.75rem; color: var(--text-secondary); }
.user-dropdown button { width: 100%; padding: 0.75rem 1rem; text-align: left; border: none; background: none; cursor: pointer; display: flex; align-items: center; gap: 0.5rem; font-size: 0.85rem; color: var(--danger); }
.user-dropdown button:hover { background: var(--danger-bg); }
.content { padding: 1.5rem; flex: 1; overflow-y: auto; }
.page-title { font-size: 1.75rem; font-weight: 700; letter-spacing: -0.02em; margin-bottom: 0.25rem; }
.page-subtitle { color: var(--text-secondary); font-size: 0.9rem; margin-bottom: 1.5rem; }
.grid-kpi { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1.25rem; margin-bottom: 1.5rem; }
.kpi-card { background: var(--card); padding: 1.5rem; border-radius: var(--radius); box-shadow: 0 1px 3px rgba(0,0,0,0.08); border: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; transition: box-shadow 0.2s; }
.kpi-card:hover { box-shadow: 0 10px 25px rgba(0,0,0,0.1); }
.kpi-content h3 { font-size: 0.8rem; font-weight: 500; color: var(--text-secondary); margin-bottom: 0.25rem; }
.kpi-content .value { font-size: 1.75rem; font-weight: 700; }
.kpi-content .trend { font-size: 0.75rem; display: flex; align-items: center; gap: 0.25rem; margin-top: 0.25rem; }
.kpi-content .trend.up { color: var(--success); }
.kpi-content .trend.down { color: var(--danger); }
.kpi-icon { width: 48px; height: 48px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 1.5rem; }
.kpi-icon.blue { background: var(--primary-light); color: var(--primary); }
.kpi-icon.green { background: var(--success-bg); color: var(--success); }
.kpi-icon.amber { background: var(--warning-bg); color: var(--warning); }
.kpi-icon.red { background: var(--danger-bg); color: var(--danger); }
.card { background: var(--card); border-radius: var(--radius); box-shadow: 0 1px 3px rgba(0,0,0,0.08); border: 1px solid var(--border); overflow: hidden; }
.card-header { padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 0.5rem; }
.card-header h2 { font-size: 1rem; font-weight: 600; }
.card-body { padding: 1rem 1.25rem; }
.badge { display: inline-flex; align-items: center; padding: 0.25rem 0.75rem; border-radius: 999px; font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; }
.badge.activo { background: var(--success-bg); color: #065f46; }
.badge.inactivo { background: var(--danger-bg); color: #991b1b; }
.badge.visitante { background: #dbeafe; color: #1e40af; }
.badge.nuevo_creyente { background: var(--warning-bg); color: #92400e; }
.alert-item { display: flex; align-items: flex-start; gap: 1rem; padding: 1rem 1.25rem; border-bottom: 1px solid #f3f4f6; transition: background 0.15s; }
.alert-item:hover { background: #f9fafb; }
.alert-item:last-child { border-bottom: none; }
.alert-icon { width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 1.1rem; flex-shrink: 0; }
.alert-icon.desercion { background: var(--danger-bg); color: var(--danger); }
.alert-icon.nuevo { background: var(--success-bg); color: var(--success); }
.alert-content h4 { font-size: 0.9rem; font-weight: 600; margin-bottom: 0.15rem; }
.alert-content p { font-size: 0.85rem; color: var(--text-secondary); }
.alert-content .badge { margin-top: 0.5rem; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; text-align: left; font-size: 0.875rem; }
thead { background: #f9fafb; color: #6b7280; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; }
th, td { padding: 0.875rem 1.25rem; }
tbody tr { border-bottom: 1px solid #f3f4f6; transition: background 0.15s; }
tbody tr:hover { background: #f9fafb; }
tbody tr:last-child { border-bottom: none; }
.table-avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--primary-light); color: var(--primary); display: flex; align-items: center; justify-content: center; font-size: 0.75rem; font-weight: 700; }
.table-user { display: flex; align-items: center; gap: 0.75rem; }
.table-user .name { font-weight: 600; }
.table-user .email { font-size: 0.8rem; color: var(--text-secondary); }
.btn { display: inline-flex; align-items: center; gap: 0.5rem; padding: 0.6rem 1rem; border-radius: 8px; font-size: 0.875rem; font-weight: 500; cursor: pointer; border: none; text-decoration: none; transition: all 0.15s; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-sm { padding: 0.4rem 0.75rem; font-size: 0.8rem; }
.profile-header { background: linear-gradient(135deg, #eff6ff, #e0e7ff); padding: 2rem; border-radius: var(--radius) var(--radius) 0 0; border-bottom: 1px solid var(--border); }
.profile-header-inner { display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap; }
.profile-avatar { width: 96px; height: 96px; border-radius: 50%; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 2rem; font-weight: 700; flex-shrink: 0; box-shadow: 0 4px 12px rgba(37,99,235,0.3); }
.profile-info h1 { font-size: 1.75rem; font-weight: 700; margin-bottom: 0.5rem; display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.profile-meta { display: flex; flex-wrap: wrap; gap: 1rem; font-size: 0.875rem; color: var(--text-secondary); }
.profile-meta span { display: flex; align-items: center; gap: 0.35rem; }
.tabs-nav { display: flex; border-bottom: 1px solid var(--border); gap: 0.25rem; margin-bottom: 1.5rem; overflow-x: auto; }
.tab-btn { padding: 0.75rem 1.25rem; border: none; background: none; font-size: 0.875rem; font-weight: 500; color: var(--text-secondary); cursor: pointer; position: relative; white-space: nowrap; transition: color 0.15s; }
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--primary); }
.tab-btn.active::after { content: ""; position: absolute; bottom: 0; left: 0; right: 0; height: 2px; background: var(--primary); border-radius: 2px 2px 0 0; }
.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fadeIn 0.3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 3rem; text-align: center; }
.empty-state-icon { font-size: 3rem; margin-bottom: 1rem; opacity: 0.3; }
.empty-state h3 { font-size: 1.1rem; font-weight: 600; margin-bottom: 0.25rem; }
.empty-state p { color: var(--text-secondary); font-size: 0.875rem; max-width: 320px; }
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #f3f4f6, #e5e7eb); padding: 1rem; }
.login-card { width: 100%; max-width: 400px; background: #fff; border-radius: var(--radius); box-shadow: 0 10px 25px rgba(0,0,0,0.1); padding: 2rem; border: 1px solid var(--border); }
.login-logo { width: 64px; height: 64px; background: var(--primary); border-radius: 16px; display: flex; align-items: center; justify-content: center; font-size: 1.75rem; margin: 0 auto 1rem; color: #fff; }
.login-title { text-align: center; margin-bottom: 1.5rem; }
.login-title h1 { font-size: 1.5rem; font-weight: 700; }
.login-title p { color: var(--text-secondary); font-size: 0.875rem; margin-top: 0.25rem; }
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: 0.875rem; font-weight: 500; margin-bottom: 0.35rem; }
.form-group input { width: 100%; padding: 0.6rem 0.875rem; border: 1px solid var(--border); border-radius: 8px; background: #f9fafb; font-size: 0.9rem; outline: none; transition: all 0.2s; }
.form-group input:focus { background: #fff; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.1); }
.btn-full { width: 100%; justify-content: center; }
.error-msg { background: var(--danger-bg); color: var(--danger); padding: 0.75rem; border-radius: 8px; font-size: 0.85rem; margin-bottom: 1rem; border: 1px solid #fecaca; }
.skeleton { background: #e5e7eb; border-radius: 6px; animation: pulse 2s cubic-bezier(0.4,0,0.6,1) infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.5; } }
.mobile-toggle { display: none; position: fixed; top: 1rem; left: 1rem; z-index: 60; background: #111827; color: #fff; border: none; border-radius: 8px; padding: 0.5rem; cursor: pointer; }
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 45; }
@media (max-width: 768px) {
  .mobile-toggle { display: block; }
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.active { display: block; }
  .main-area { margin-left: 0; }
  .grid-kpi { grid-template-columns: 1fr; }
  .topbar-search { display: none; }
  .profile-header-inner { flex-direction: column; text-align: center; }
}
