:root {
  --morado: #520F95;
  --morado-profundo: #2A0850;
  --morado-hover: #3D0B70;
  --lila: #F4EFFA;
  --lila-borde: #E2D6F0;
  --blanco: #FFFFFF;
  --fondo: #FAF8FC;
  --texto: #1C1526;
  --texto-2: #5B5366;
  --dorado: #F5B82E;
  --whatsapp: #128C4A;
  --error: #B42318;
  --error-suave: #FDECEA;
  --ok: #067647;
  --ok-suave: #E6F4EC;
  --aviso: #8A5A00;
  --aviso-suave: #FFF4D6;
  --sombra: 0 8px 24px rgba(82, 15, 149, 0.08);
  --ease: cubic-bezier(0.23, 1, 0.32, 1);
  --titulos: 'Sora', system-ui, sans-serif;
  --cuerpo: 'Manrope', system-ui, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--fondo); color: var(--texto); font-family: var(--cuerpo); font-size: 15px; line-height: 1.5; }
a { color: var(--morado); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--morado); outline-offset: 2px; }
h1, h2, h3 { font-family: var(--titulos); color: var(--morado-profundo); letter-spacing: -0.01em; }
.muted { color: var(--texto-2); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- Estructura ---------- */
.app { display: grid; grid-template-columns: 1fr; min-height: 100vh; }
.lateral { display: none; }
.cuerpo { min-width: 0; padding: 16px 16px 96px; }
.barra-sup { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.barra-sup h1 { margin: 0; font-size: 22px; }
.marca { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--blanco); font-family: var(--titulos); font-weight: 600; }
.marca img { width: 36px; height: 36px; border-radius: 50%; box-shadow: 0 0 0 2px var(--blanco); }
.nav-movil { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: grid; grid-template-columns: repeat(5, 1fr); background: var(--blanco); border-top: 1.5px solid var(--lila-borde); padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px)); }
.nav-movil a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 2px; font-size: 11px; font-weight: 700; color: var(--texto-2); text-decoration: none; border-radius: 10px; }
.nav-movil a.activo { color: var(--morado); background: var(--lila); }
.nav-movil svg, .lateral nav svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
@media (min-width: 1000px) {
  .app { grid-template-columns: 240px 1fr; }
  .lateral { display: flex; flex-direction: column; gap: 24px; position: sticky; top: 0; height: 100vh; background: var(--morado-profundo); color: var(--blanco); padding: 20px 14px; }
  .lateral nav { display: flex; flex-direction: column; gap: 4px; }
  .lateral nav a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; color: var(--lila-borde); text-decoration: none; font-weight: 600; }
  .lateral nav a:hover { background: var(--morado-hover); color: var(--blanco); }
  .lateral nav a.activo { background: var(--blanco); color: var(--morado-profundo); }
  .lateral .usuario { margin-top: auto; font-size: 13px; color: var(--lila-borde); }
  .lateral .usuario button { margin-top: 8px; background: none; border: 1.5px solid var(--morado-hover); color: var(--blanco); border-radius: 10px; padding: 6px 12px; cursor: pointer; }
  .nav-movil { display: none; }
  .cuerpo { padding: 28px 32px 48px; }
  .barra-sup h1 { font-size: 26px; }
}

/* ---------- Componentes ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 42px; padding: 0 16px; border-radius: 12px; border: 0; font-weight: 700; font-size: 15px; cursor: pointer; text-decoration: none; transition: background 160ms ease, transform 120ms var(--ease); white-space: nowrap; }
.btn:active { transform: scale(0.97); }
.btn[disabled] { opacity: 0.6; cursor: progress; }
.btn-1 { background: var(--morado); color: var(--blanco); }
.btn-1:hover { background: var(--morado-hover); color: var(--blanco); }
.btn-2 { background: var(--blanco); color: var(--morado); border: 1.5px solid var(--morado); }
.btn-2:hover { background: var(--lila); }
.btn-3 { background: var(--lila); color: var(--morado-profundo); }
.btn-3:hover { background: var(--lila-borde); }
.btn-wa { background: var(--whatsapp); color: var(--blanco); }
.btn-wa:hover { background: #0E7A40; color: var(--blanco); }
.btn-peligro { background: var(--blanco); color: var(--error); border: 1.5px solid var(--error); }
.btn-chico { min-height: 34px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn-wa svg { fill: currentColor; stroke: none; }

.tarjeta { background: var(--blanco); border: 1.5px solid var(--lila-borde); border-radius: 14px; box-shadow: var(--sombra); padding: 18px; }
.tarjeta h2 { margin: 0 0 12px; font-size: 17px; }
.rejilla { display: grid; gap: 16px; }
.rejilla-2 { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 360px), 1fr)); align-items: start; }
.kpis { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.kpi { background: var(--blanco); border: 1.5px solid var(--lila-borde); border-radius: 14px; padding: 14px 16px; }
.kpi small { display: block; font-size: 13px; color: var(--texto-2); font-weight: 600; }
.kpi strong { display: block; margin-top: 4px; font-family: var(--titulos); font-size: 26px; color: var(--morado-profundo); font-variant-numeric: tabular-nums; }
.kpi span { font-size: 13px; color: var(--texto-2); }

.etiqueta { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 700; white-space: nowrap; background: var(--lila); color: var(--morado-profundo); }
.etiqueta i { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.e-nuevo { background: #EDE7FB; color: #3D0B70; }
.e-contactado { background: #E8F0FE; color: #1E4FA8; }
.e-interesado { background: #E0F4F7; color: #0B5F6B; }
.e-pago_pendiente { background: var(--aviso-suave); color: var(--aviso); }
.e-pagado { background: var(--ok-suave); color: var(--ok); }
.e-cita_agendada { background: #F0E6FA; color: var(--morado); }
.e-asesoria_realizada { background: #E3F0E8; color: #05603A; }
.e-contrato { background: var(--morado); color: var(--blanco); }
.e-no_contesta, .e-no_interesado { background: #EEECEF; color: #4A4452; }
.vencido { color: var(--error); font-weight: 700; }

.lista { list-style: none; margin: 0; padding: 0; }
.lista > li { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1.5px solid var(--lila-borde); }
.lista > li:last-child { border-bottom: 0; }
.lista .principal { min-width: 0; }
.lista .principal b { display: block; color: var(--morado-profundo); }
.lista .principal span { font-size: 13px; color: var(--texto-2); }
.vacio { padding: 18px; text-align: center; color: var(--texto-2); background: var(--lila); border-radius: 12px; }

/* Tabla */
.tabla-caja { overflow-x: auto; background: var(--blanco); border: 1.5px solid var(--lila-borde); border-radius: 14px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--lila-borde); white-space: nowrap; }
th { background: var(--lila); color: var(--morado-profundo); font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.04em; position: sticky; top: 0; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: #FBF9FD; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Filtros y formularios */
.filtros { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; align-items: center; }
.filtros input, .filtros select { min-height: 40px; }
.campo { display: flex; flex-direction: column; gap: 6px; }
.campo label, .campo .rotulo { font-size: 13px; font-weight: 700; color: var(--texto); }
input[type=text], input[type=password], input[type=tel], input[type=email], input[type=number], input[type=date], input[type=datetime-local], input[type=search], select, textarea {
  min-height: 42px; padding: 8px 12px; background: var(--blanco); border: 1.5px solid var(--lila-borde); border-radius: 10px; font-size: 15px; outline: none; width: 100%;
}
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--morado); box-shadow: 0 0 0 3px rgba(82, 15, 149, 0.15); }
.form { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); }
.form .ancho { grid-column: 1 / -1; }
.acciones { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; grid-column: 1 / -1; }
.check { display: flex; gap: 10px; align-items: center; font-weight: 600; }
.check input { width: 18px; height: 18px; accent-color: var(--morado); }

/* Pestañas */
.pestanas { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1.5px solid var(--lila-borde); margin-bottom: 16px; }
.pestanas button { background: none; border: 0; padding: 10px 14px; font-weight: 700; color: var(--texto-2); cursor: pointer; border-bottom: 3px solid transparent; margin-bottom: -1.5px; white-space: nowrap; }
.pestanas button.activo { color: var(--morado); border-bottom-color: var(--morado); }

/* Ficha de persona */
.ficha-cabeza { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-start; justify-content: space-between; margin-bottom: 16px; }
.ficha-cabeza h1 { margin: 0; font-size: 24px; }
.ficha-datos { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 6px; font-size: 14px; color: var(--texto-2); }
.ficha-botones { display: flex; flex-wrap: wrap; gap: 8px; }
.volver { display: inline-flex; align-items: center; gap: 6px; margin-bottom: 10px; font-weight: 700; text-decoration: none; font-size: 14px; }

.linea-tiempo { list-style: none; margin: 0; padding: 0; position: relative; }
.linea-tiempo li { position: relative; padding: 0 0 16px 28px; }
.linea-tiempo li::before { content: ''; position: absolute; left: 7px; top: 6px; bottom: -6px; width: 2px; background: var(--lila-borde); }
.linea-tiempo li:last-child::before { display: none; }
.linea-tiempo li::after { content: ''; position: absolute; left: 2px; top: 4px; width: 12px; height: 12px; border-radius: 50%; background: var(--morado); box-shadow: 0 0 0 3px var(--lila); }
.linea-tiempo li.t-etapa::after, .linea-tiempo li.t-sistema::after { background: var(--dorado); }
.linea-tiempo li.t-pago::after { background: var(--ok); }
.linea-tiempo li.t-whatsapp::after { background: var(--whatsapp); }
.linea-tiempo .meta { font-size: 12.5px; color: var(--texto-2); }
.linea-tiempo .texto { white-space: pre-wrap; }

/* Embudo */
.embudo { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(250px, 1fr); gap: 12px; overflow-x: auto; padding-bottom: 12px; align-items: start; }
.columna { background: var(--lila); border-radius: 14px; padding: 10px; min-height: 140px; }
.columna.sobre { outline: 2px dashed var(--morado); }
.columna h3 { margin: 4px 4px 10px; font-size: 14px; display: flex; justify-content: space-between; }
.columna h3 span { color: var(--texto-2); }
.carta { background: var(--blanco); border: 1.5px solid var(--lila-borde); border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; cursor: grab; }
.carta:active { cursor: grabbing; }
.carta b { display: block; color: var(--morado-profundo); font-size: 14px; }
.carta span { font-size: 12.5px; color: var(--texto-2); }
.carta select { margin-top: 8px; min-height: 34px; font-size: 13px; padding: 4px 8px; }

/* Agenda */
.agenda-cab { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.agenda-cab strong { font-family: var(--titulos); color: var(--morado-profundo); margin: 0 8px; }
.semana { display: grid; grid-template-columns: 64px repeat(var(--dias, 6), minmax(130px, 1fr)); overflow-x: auto; background: var(--blanco); border: 1.5px solid var(--lila-borde); border-radius: 14px; }
.semana > div { border-bottom: 1px solid var(--lila-borde); border-right: 1px solid var(--lila-borde); padding: 6px; min-height: 64px; }
.semana .dia-cab { min-height: 0; background: var(--lila); font-weight: 700; font-size: 13px; color: var(--morado-profundo); text-align: center; position: sticky; top: 0; }
.semana .dia-cab.hoy { background: var(--morado); color: var(--blanco); }
.semana .hora { font-size: 12.5px; font-weight: 700; color: var(--texto-2); background: #FBF9FD; }
.hueco { display: flex; flex-direction: column; gap: 4px; }
.hueco button.libre { width: 100%; min-height: 30px; border: 1.5px dashed var(--lila-borde); background: none; border-radius: 8px; color: var(--texto-2); font-size: 12.5px; cursor: pointer; opacity: 0.7; }
.hueco button.libre:hover { border-color: var(--morado); color: var(--morado); opacity: 1; }
.cita { display: block; width: 100%; text-align: left; border: 0; border-left: 4px solid var(--morado); background: var(--lila); border-radius: 8px; padding: 6px 8px; font-size: 12.5px; cursor: pointer; }
.cita b { display: block; color: var(--morado-profundo); font-size: 13px; }
.cita.c-realizada { border-left-color: var(--ok); background: var(--ok-suave); }
.cita.c-confirmada { border-left-color: var(--dorado); }
.cita.c-no_asistio, .cita.c-cancelada { border-left-color: #8A8392; background: #F2F1F3; text-decoration: line-through; }

/* Barras de resultados */
.barras { display: grid; gap: 8px; }
.barra-fila { display: grid; grid-template-columns: minmax(110px, 160px) 1fr 52px; gap: 10px; align-items: center; font-size: 14px; }
.barra-fila .pista { height: 12px; background: var(--lila); border-radius: 999px; overflow: hidden; }
.barra-fila .relleno { height: 100%; background: var(--morado); border-radius: 999px; }
.barra-fila b { text-align: right; font-variant-numeric: tabular-nums; }

/* Modal */
.modal-fondo { position: fixed; inset: 0; z-index: 50; background: rgba(42, 8, 80, 0.5); display: flex; align-items: flex-end; justify-content: center; }
.modal { width: 100%; max-width: 620px; max-height: 92dvh; overflow-y: auto; background: var(--blanco); border-radius: 18px 18px 0 0; padding: 20px 20px calc(20px + env(safe-area-inset-bottom, 0px)); box-shadow: 0 24px 64px rgba(42, 8, 80, 0.28); }
.modal h2 { margin: 0 0 16px; font-size: 20px; padding-right: 40px; }
.modal-cerrar { float: right; width: 36px; height: 36px; border-radius: 50%; border: 0; background: var(--lila); cursor: pointer; font-size: 18px; color: var(--morado-profundo); }
@media (min-width: 700px) { .modal-fondo { align-items: center; padding: 24px; } .modal { border-radius: 16px; } }

.aviso { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); z-index: 70; background: var(--morado-profundo); color: var(--blanco); padding: 10px 18px; border-radius: 12px; font-weight: 600; box-shadow: var(--sombra); max-width: calc(100% - 32px); }
.aviso.error { background: var(--error); }
@media (min-width: 1000px) { .aviso { bottom: 28px; } }

.buscador-res { max-height: 220px; overflow-y: auto; border: 1.5px solid var(--lila-borde); border-radius: 10px; margin-top: 6px; }
.buscador-res button { display: block; width: 100%; text-align: left; padding: 8px 12px; background: none; border: 0; border-bottom: 1px solid var(--lila-borde); cursor: pointer; }
.buscador-res button:hover, .buscador-res button.sel { background: var(--lila); }

/* Login */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; background: var(--morado-profundo); }
.login-caja { width: 100%; max-width: 400px; background: var(--blanco); border-radius: 18px; padding: 28px 24px; box-shadow: 0 24px 64px rgba(0, 0, 0, 0.3); }
.login-caja img { width: 72px; height: 72px; border-radius: 50%; display: block; margin: 0 auto 12px; }
.login-caja h1 { text-align: center; margin: 0 0 4px; font-size: 22px; }
.login-caja p { text-align: center; margin: 0 0 20px; color: var(--texto-2); }
.login-caja form { display: grid; gap: 14px; }
.cargando { display: flex; align-items: center; justify-content: center; min-height: 60vh; color: var(--texto-2); }
