:root {
  --f-texto: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --f-titulo: "Plus Jakarta Sans", "Inter", system-ui, sans-serif;
  --rojo: #d6301c;
  --rojo-osc: #a8230f;
  --naranja: #f07d1a;
  --amarillo: #fbbf24;
  --tinta: #1d1a17;
  --gris: #6b645d;
  --borde: #ebe4dc;
  --fondo: #faf7f3;
  --tarjeta: #ffffff;
  --sidebar: #1d1a17;
  --llama: linear-gradient(135deg, #d6301c 0%, #f07d1a 60%, #fbbf24 100%);
}

* { box-sizing: border-box; }
body {
  font-family: var(--f-texto);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  letter-spacing: -.005em;
  background: var(--fondo);
  color: var(--tinta);
  font-size: 15px;
}
h1, h2, h3, h4, .serif { font-family: var(--f-titulo); font-weight: 700; letter-spacing: -.01em; word-spacing: .04em; }
h1 { letter-spacing: -.02em; }
h1 { font-size: 1.75rem; font-weight: 800; }
a { color: var(--rojo); }
a:hover { color: var(--rojo-osc); }

/* ---------- layout ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 250px; flex-shrink: 0; background: var(--sidebar); color: #e9e2da;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar .marca { padding: 22px 18px 16px; display: flex; gap: 12px; align-items: center; border-bottom: 1px solid #2f2a25; }
.sidebar .marca img { width: 48px; height: 48px; border-radius: 50%; background: #fff; }
.sidebar .marca .t1 { font-family: var(--f-titulo); font-weight: 700; font-size: 1rem; letter-spacing: -.01em; line-height: 1.05; color: #fff; }
.sidebar .marca .t2 { font-size: .72rem; color: #b8aea3; text-transform: uppercase; letter-spacing: .12em; }
.sidebar nav { padding: 12px 10px; flex: 1; }
.sidebar .grupo { font-size: .68rem; text-transform: uppercase; letter-spacing: .14em; color: #8a8077; margin: 16px 10px 6px; }
.sidebar nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px;
  color: #e9e2da; text-decoration: none; font-size: .94rem;
}
.sidebar nav a i { font-size: 1.05rem; opacity: .85; }
.sidebar nav a:hover { background: #2b2621; color: #fff; }
.sidebar nav a.activo { background: var(--llama); color: #fff; font-weight: 600; }
.sidebar .usuario { padding: 14px 18px; border-top: 1px solid #2f2a25; font-size: .85rem; }
.sidebar .usuario .rol { color: var(--amarillo); font-size: .75rem; }

.contenido { flex: 1; min-width: 0; }
.topbar {
  display: none; background: var(--sidebar); color: #fff; padding: 10px 16px; align-items: center; gap: 12px;
  position: sticky; top: 0; z-index: 1030;
}
.topbar img { width: 34px; height: 34px; border-radius: 50%; background: #fff; }
.pagina { padding: 28px 32px 48px; max-width: 1400px; }

.encabezado { display: flex; flex-wrap: wrap; gap: 12px; justify-content: space-between; align-items: flex-end; margin-bottom: 22px; }
.encabezado h1 { margin: 0; }
.encabezado .sub { color: var(--gris); margin-top: 2px; }
.franja { height: 4px; width: 64px; background: var(--llama); border-radius: 4px; margin-bottom: 10px; }

/* ---------- componentes ---------- */
.tarjeta { background: var(--tarjeta); border: 1px solid var(--borde); border-radius: 14px; padding: 20px; }
.tarjeta h2, .tarjeta h3 { font-size: 1.1rem; margin-bottom: 12px; }
.kpi { background: var(--tarjeta); border: 1px solid var(--borde); border-radius: 14px; padding: 16px 18px; height: 100%; position: relative; overflow: hidden; }
.kpi::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--llama); }
.kpi .v { font-family: var(--f-titulo); font-size: 1.9rem; font-weight: 800; line-height: 1; letter-spacing: -.03em; }
.kpi .l { color: var(--gris); font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; margin-top: 8px; }

.btn-llama { background: var(--llama); color: #fff; border: 0; font-weight: 600; }
.btn-llama:hover { color: #fff; filter: brightness(1.05); }
.btn-outline-rojo { border: 1px solid var(--rojo); color: var(--rojo); background: transparent; }
.btn-outline-rojo:hover { background: var(--rojo); color: #fff; }
.btn { border-radius: 8px; }

.table { --bs-table-bg: transparent; margin-bottom: 0; }
.table thead th { font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--gris); border-bottom: 2px solid var(--borde); font-weight: 600; white-space: nowrap; }
.table td { vertical-align: middle; border-color: var(--borde); }
.table-hover tbody tr:hover { background: #fff6ee; }

.badge-miembro { background: #fde3dc; color: var(--rojo-osc); }
.badge-invitado { background: #fff1d1; color: #8a5a00; }
.badge-estado-programada { background: #e7eef9; color: #234c8a; }
.badge-estado-reagendada { background: #fff1d1; color: #8a5a00; }
.badge-estado-realizada { background: #dff3e5; color: #1d6b37; }
.badge-estado-cancelada { background: #eee; color: #666; text-decoration: line-through; }
.badge { font-weight: 600; padding: .4em .65em; border-radius: 6px; }

.form-label { font-weight: 600; font-size: .88rem; }
.form-control, .form-select { border-radius: 8px; border-color: #ddd3c8; }
.form-control:focus, .form-select:focus, .form-check-input:focus { border-color: var(--naranja); box-shadow: 0 0 0 .2rem rgba(240,125,26,.18); }
.form-check-input:checked { background-color: var(--rojo); border-color: var(--rojo); }
.filtros { background: var(--tarjeta); border: 1px solid var(--borde); border-radius: 12px; padding: 14px; margin-bottom: 18px; }

/* calendario */
.cal { width: 100%; table-layout: fixed; border-collapse: separate; border-spacing: 4px; }
.cal th { text-align: center; font-size: .78rem; text-transform: uppercase; color: var(--gris); padding: 6px 0; }
.cal td { background: var(--tarjeta); border: 1px solid var(--borde); border-radius: 10px; height: 118px; vertical-align: top; padding: 6px; }
.cal td.fuera { background: transparent; opacity: .5; }
.cal td.hoy { border: 2px solid var(--naranja); }
.cal .num { font-weight: 700; font-size: .85rem; display: flex; justify-content: space-between; }
.cal .num a { color: var(--gris); text-decoration: none; opacity: 0; }
.cal td:hover .num a { opacity: 1; }
.ev { display: block; font-size: .74rem; padding: 2px 6px; border-radius: 5px; margin-top: 3px; text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ev-celula { background: #fff1e4; color: #8a3d00; border-left: 3px solid var(--naranja); }
.ev-miercoles { background: #fde3dc; color: var(--rojo-osc); border-left: 3px solid var(--rojo); }
.ev-sabado { background: #fff6d6; color: #7a5800; border-left: 3px solid var(--amarillo); }
.ev.cancelada { text-decoration: line-through; opacity: .55; }
.ev.realizada::after { content: " ✓"; }

/* asistencia */
.seccion-cab { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; padding: 14px 16px 10px; border-bottom: 1px solid var(--borde); }
.seccion-cab h3 { font-size: 1.1rem; }
.sticky-filtros { position: sticky; top: 0; z-index: 6; }
.fila-persona { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--borde); flex-wrap: wrap; }
.fila-persona:last-child { border-bottom: 0; }
.fila-persona.marcado { background: #f6fbec; }
.fila-persona.dado-baja { background: #f4f2ef; opacity: .75; }
.fila-persona.dado-baja .nombre .fw-semibold { text-decoration: line-through; }
.fila-persona .nombre { flex: 1 1 220px; min-width: 0; }
.fila-persona .controles { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.slot-accion { width: 150px; display: flex; justify-content: flex-end; }
.slot-accion:empty { visibility: hidden; }
.nota-otra { font-size: .8rem; color: #234c8a; background: #e7eef9; border-radius: 6px; padding: 3px 8px; margin-top: 4px; display: inline-block; }
.nota-baja { font-size: .8rem; color: #6b645d; margin-top: 4px; }
.badge-visita { background: #e7eef9; color: #234c8a; }

/* interruptor tipo switch (verde = asistió) */
.sw { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; margin: 0; }
.sw input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.sw-track { width: 54px; height: 30px; border-radius: 999px; border: 3px solid #c9c2ba; background: #fff; position: relative; transition: border-color .15s; flex-shrink: 0; }
.sw-knob { position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #c9c2ba; transition: transform .15s, background .15s; }
.sw input:checked + .sw-track { border-color: #6aa307; }
.sw input:checked + .sw-track .sw-knob { transform: translateX(24px); background: #6aa307; }
.sw input:focus-visible + .sw-track { box-shadow: 0 0 0 3px rgba(106,163,7,.3); }
.sw-label { font-weight: 600; font-size: .88rem; min-width: 94px; color: #a8230f; }
.sw input:checked ~ .sw-label { color: #3f6b00; }
.sw-ofrenda .sw-track { width: 44px; height: 24px; border-width: 2px; }
.sw-ofrenda .sw-knob { width: 14px; height: 14px; top: 3px; left: 3px; }
.sw-ofrenda input:checked + .sw-track { border-color: var(--naranja); }
.sw-ofrenda input:checked + .sw-track .sw-knob { transform: translateX(20px); background: var(--naranja); }
.sw-ofrenda .sw-label { min-width: 0; color: var(--gris); font-weight: 400; }
.sw-ofrenda input:checked ~ .sw-label { color: #a14d00; font-weight: 600; }
.sw input:disabled + .sw-track { opacity: .35; }
.sw input:disabled ~ .sw-label { opacity: .5; }

.resultados { position: absolute; z-index: 20; left: 16px; right: 16px; max-width: 520px; background: #fff; border: 1px solid var(--borde); border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.12); max-height: 300px; overflow-y: auto; bottom: 100%; }
.resultado { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 9px 12px; border-bottom: 1px solid var(--borde); }
.resultado:hover:not(:disabled) { background: #fff6ee; }
.resultado:disabled { opacity: .5; }
.contador-flotante { position: sticky; bottom: 0; background: var(--tarjeta); border-top: 1px solid var(--borde); padding: 12px 16px; z-index: 5; box-shadow: 0 -6px 16px rgba(0,0,0,.05); }
@media (max-width: 575px) {
  .fila-persona .controles { width: 100%; justify-content: space-between; }
  .sw-label { min-width: 104px; }
  .sw-ofrenda .sw-label { min-width: 0; }
  .slot-accion { width: auto; }
  .slot-accion:empty { display: none; }
}

.chart-box { position: relative; height: 280px; }
.vacio { color: var(--gris); text-align: center; padding: 30px; }

.print-header { display: none; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; background: radial-gradient(circle at 20% 10%, #fff1e4 0, var(--fondo) 45%), var(--fondo); padding: 20px; }
.login-card { width: 100%; max-width: 400px; background: #fff; border-radius: 18px; border: 1px solid var(--borde); padding: 34px 30px; box-shadow: 0 20px 50px rgba(120,60,10,.08); }
.login-card img { width: 120px; display: block; margin: 0 auto 12px; }

/* ---------- responsive ---------- */
@media (max-width: 991px) {
  .sidebar { position: fixed; left: -260px; z-index: 1040; transition: left .2s; }
  .sidebar.abierto { left: 0; box-shadow: 0 0 40px rgba(0,0,0,.4); }
  .topbar { display: flex; }
  .pagina { padding: 18px 16px 40px; }
  .cal td { height: 80px; }
  .ev { font-size: .66rem; }
}

/* ---------- impresión ---------- */
@media print {
  @page { margin: 1.2cm; }
  body { background: #fff; font-size: 11px; }
  .sidebar, .topbar, .no-print, .btn, .filtros, .flash { display: none !important; }
  .pagina { padding: 0; max-width: none; }
  .print-header { display: flex !important; align-items: center; gap: 14px; border-bottom: 2px solid var(--naranja); padding-bottom: 8px; margin-bottom: 14px; }
  .print-header img { width: 60px; height: 60px; }
  .tarjeta, .kpi { border: 1px solid #ccc; break-inside: avoid; }
  .chart-box { height: 220px; }
  a { color: inherit; text-decoration: none; }
  .table { font-size: 10px; }
  .cal td { height: 80px; }
  .col-print-6 { width: 50% !important; float: left; }
}
