/* =========================================================
   CRM — tema: morado / azul / lila, fondos claros, tarjetas blancas
   ========================================================= */
:root {
  --brand: #6d28d9;          /* morado */
  --brand-2: #2563eb;        /* azul */
  --lilac: #ede9fe;          /* lila */
  --lilac-2: #f5f3ff;
  --ink: #1e1b4b;
  --muted: #6b7280;
  --bg: #f7f7fb;
  --card: #ffffff;
  --line: #ececf3;
  --ok: #059669; --ok-bg: #ecfdf5;
  --warn: #d97706; --warn-bg: #fffbeb;
  --err: #dc2626; --err-bg: #fef2f2;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(30, 27, 75, .04), 0 4px 16px rgba(30, 27, 75, .04);
  --sidebar-w: 248px;
  --bs-primary: var(--brand);
  --bs-primary-rgb: 109, 40, 217;
  --bs-link-color: var(--brand);
  --bs-link-hover-color: #5b21b6;
  --bs-body-font-family: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --bs-body-color: var(--ink);
  --bs-body-bg: var(--bg);
}
body { font-family: var(--bs-body-font-family); background: var(--bg); color: var(--ink); -webkit-font-smoothing: antialiased; }

/* Botones */
.btn { border-radius: 12px; font-weight: 600; }
.btn-primary {
  --bs-btn-bg: var(--brand); --bs-btn-border-color: var(--brand);
  --bs-btn-hover-bg: #5b21b6; --bs-btn-hover-border-color: #5b21b6;
  --bs-btn-active-bg: #4c1d95; --bs-btn-active-border-color: #4c1d95;
  background-image: linear-gradient(135deg, var(--brand), #7c3aed 60%, var(--brand-2));
  border: 0;
}
.btn-outline-primary { --bs-btn-color: var(--brand); --bs-btn-border-color: #d8ccfb; --bs-btn-hover-bg: var(--brand); --bs-btn-hover-border-color: var(--brand); }
.btn-light { --bs-btn-bg: #fff; --bs-btn-border-color: var(--line); }
.btn-icon { width: 40px; height: 40px; display: inline-grid; place-items: center; border-radius: 12px; border: 1px solid var(--line); background: #fff; font-size: 1.15rem; }
.form-control, .form-select { border-radius: 12px; border-color: #e4e2ee; }
.form-control:focus, .form-select:focus { border-color: #a78bfa; box-shadow: 0 0 0 .25rem rgba(109, 40, 217, .12); }
.form-label { font-weight: 600; font-size: .875rem; }
.form-check-input:checked { background-color: var(--brand); border-color: var(--brand); }

/* Layout */
.app-shell { display: flex; min-height: 100vh; }
.sidebar { width: var(--sidebar-w); background: #fff; border-right: 1px solid var(--line); flex-shrink: 0; }
@media (min-width: 992px) { .sidebar { position: sticky; top: 0; height: 100vh; overflow-y: auto; } }
.sidebar-brand { display: flex; align-items: center; gap: .6rem; padding: 1.25rem 1.25rem 1rem; }
.brand-mark { width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, var(--brand), var(--brand-2)); }
.brand-name { font-weight: 800; letter-spacing: -.01em; }
.sidebar-nav { padding: .25rem .75rem 1.5rem; display: flex; flex-direction: column; gap: 2px; }
.nav-section { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: #a1a1b5; padding: 1rem .75rem .4rem; font-weight: 700; }
.sidebar-nav .nav-link { display: flex; align-items: center; gap: .7rem; padding: .6rem .75rem; border-radius: 12px; color: #3f3d56; font-weight: 500; }
.sidebar-nav .nav-link i { font-size: 1.05rem; color: #8b87a8; }
.sidebar-nav .nav-link:hover { background: var(--lilac-2); color: var(--brand); }
.sidebar-nav .nav-link.active { background: var(--lilac); color: var(--brand); font-weight: 700; }
.sidebar-nav .nav-link.active i { color: var(--brand); }
.sidebar-nav .nav-link.disabled { opacity: .55; }
.badge-soon { margin-left: auto; font-size: .65rem; background: #f1f0f7; color: #8b87a8; border-radius: 999px; padding: .1rem .5rem; font-weight: 600; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.workspace-banner { background: linear-gradient(90deg, var(--brand), var(--brand-2)); color: #fff; padding: .5rem 1.5rem; font-size: .875rem; }
.topbar { display: flex; align-items: center; gap: 1rem; padding: 1rem 2rem; background: rgba(247, 247, 251, .85);
  backdrop-filter: blur(8px); position: sticky; top: 0; z-index: 10; }
.topbar-company { display: flex; align-items: center; gap: .6rem; font-weight: 700; min-width: 0; }
.topbar-company span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.company-logo { height: 32px; width: 32px; object-fit: contain; border-radius: 8px; background: #fff; border: 1px solid var(--line); }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: .5rem; }
.user-chip { display: flex; align-items: center; gap: .5rem; background: #fff; border: 1px solid var(--line); padding: .3rem .7rem .3rem .3rem; }
.avatar { width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; background: var(--lilac); color: var(--brand); font-weight: 800; }
.notif-dot { position: absolute; top: -4px; right: -4px; min-width: 18px; height: 18px; border-radius: 9px; background: var(--brand); color: #fff; font-size: .65rem; font-weight: 700; display: grid; place-items: center; padding: 0 4px; }
.notif-menu { width: 340px; max-width: calc(100vw - 2rem); border-radius: 14px; border: 1px solid var(--line); box-shadow: var(--shadow); overflow: hidden; }
.notif-head { display: flex; justify-content: space-between; align-items: center; padding: .75rem 1rem; border-bottom: 1px solid var(--line); }
.notif-list { max-height: 360px; overflow-y: auto; }
.notif-item { display: block; padding: .75rem 1rem; border-bottom: 1px solid var(--line); color: inherit; text-decoration: none; }
.notif-item.unread { background: var(--lilac-2); }
.notif-item:hover { background: var(--lilac); }

.content { padding: .5rem 2rem 3rem; max-width: 1400px; width: 100%; }
@media (max-width: 991.98px) { .topbar, .content { padding-left: 1rem; padding-right: 1rem; } }

/* Encabezados de página */
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; margin: 1rem 0 1.5rem; flex-wrap: wrap; }
.page-title { font-size: 1.6rem; font-weight: 800; letter-spacing: -.02em; margin: 0; }
.page-sub { color: var(--muted); margin: .25rem 0 0; }

/* Tarjetas */
.card-soft { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { padding: 1.25rem 1.5rem .5rem; }
.card-head h2 { font-size: 1.05rem; font-weight: 700; margin: 0; }
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 1rem; }
.kpi-grid-4 { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.kpi-card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow); }
.kpi-icon { width: 38px; height: 38px; border-radius: 12px; background: var(--lilac); color: var(--brand); display: grid; place-items: center; margin-bottom: .9rem; font-size: 1.1rem; }
.kpi-label { color: var(--muted); font-size: .85rem; font-weight: 500; }
.kpi-value { font-size: 1.75rem; font-weight: 800; letter-spacing: -.02em; margin-top: .15rem; }
.kpi-alert .kpi-icon { background: var(--warn-bg); color: var(--warn); }

/* Tablas */
.table-clean { margin: 0; }
.table-clean thead th { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: #8b87a8; font-weight: 700; border-bottom: 1px solid var(--line); padding: .9rem 1.5rem; background: transparent; }
.table-clean td { padding: .9rem 1.5rem; border-color: var(--line); }
.table-clean tbody tr:last-child td { border-bottom: 0; }
.row-muted td { opacity: .55; }

/* Estados */
.status { display: inline-flex; align-items: center; gap: .35rem; font-size: .78rem; font-weight: 600; padding: .25rem .6rem; border-radius: 999px; white-space: nowrap; }
.status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status-ok { color: var(--ok); background: var(--ok-bg); }
.status-warn { color: var(--warn); background: var(--warn-bg); }
.status-err { color: var(--err); background: var(--err-bg); }
.status-off { color: #6b7280; background: #f3f4f6; }

.alert-soft { border: 0; border-radius: 12px; }
.empty-state { text-align: center; padding: 3rem 1.5rem; color: var(--muted); }
.empty-state i { font-size: 2.2rem; color: #c4b5fd; }
.empty-state h2 { font-size: 1.15rem; color: var(--ink); font-weight: 700; margin: .75rem 0 .35rem; }
.form-narrow { max-width: 860px; }
.steps { padding-left: 1.1rem; margin: 0; display: grid; gap: .5rem; }
.logo-preview { max-height: 72px; max-width: 100%; border-radius: 10px; border: 1px solid var(--line); padding: 6px; background: #fff; }

/* Diagnóstico */
.check-list { list-style: none; margin: 0; padding: .5rem 0; }
.check-list li { display: flex; gap: .9rem; padding: .8rem 1.5rem; border-bottom: 1px solid var(--line); }
.check-list li:last-child { border-bottom: 0; }
.check-icon { font-size: 1.15rem; }
.check-ok { color: var(--ok); } .check-warning { color: var(--warn); } .check-error { color: var(--err); }

/* Skeleton loader */
.skeleton { background: linear-gradient(90deg, #f1f0f7 25%, #e9e7f3 37%, #f1f0f7 63%); background-size: 400% 100%; animation: sk 1.4s ease infinite; border-radius: 8px; min-height: 1em; }
@keyframes sk { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* Login */
.auth-body { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem;
  background: radial-gradient(1200px 600px at 10% -10%, #ede9fe 0, transparent 60%),
              radial-gradient(900px 500px at 110% 110%, #dbeafe 0, transparent 60%), var(--bg); }
.auth-wrap { width: 100%; max-width: 420px; }
.auth-brand { display: flex; align-items: center; justify-content: center; gap: .6rem; margin-bottom: 1.5rem; font-size: 1.1rem; }
.auth-card { background: #fff; border: 1px solid var(--line); border-radius: 20px; padding: 2.25rem 2rem; box-shadow: 0 10px 40px rgba(76, 29, 149, .08); }
.auth-title { font-size: 1.5rem; font-weight: 800; letter-spacing: -.02em; margin-bottom: .35rem; }
.auth-sub { color: var(--muted); margin-bottom: 1.75rem; }
.auth-foot { text-align: center; color: #9ca3af; font-size: .8rem; margin-top: 1.25rem; }
.error-code { font-size: 3.5rem; font-weight: 800; background: linear-gradient(135deg, var(--brand), var(--brand-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }

/* ===== Fases 2–4 ===== */
.kpi-sub { color: var(--muted); font-size: .78rem; margin-top: .2rem; }
.kpi-compact .kpi-value { font-size: 1.35rem; }
.card-title-sm { font-size: 1rem; font-weight: 700; margin-bottom: 1rem; }
.link-ink { color: var(--ink); text-decoration: none; } .link-ink:hover { color: var(--brand); }
.chart-box { position: relative; height: 280px; }
@media (max-width: 575.98px) { .chart-box { height: 220px; } }
.response-pill { background: var(--lilac-2); color: var(--brand); border-radius: 999px; padding: .35rem .8rem; font-size: .82rem; white-space: nowrap; }

/* Selector de fechas */
.date-range { display: flex; align-items: center; gap: .4rem; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: .2rem .4rem .2rem .7rem; }
.date-range i { color: var(--brand); }
.date-range .form-select, .date-range .form-control { border: 0; box-shadow: none; width: auto; }
.custom-dates { display: flex; gap: .3rem; align-items: center; }
@media (max-width: 767.98px) {
  .topbar { flex-wrap: wrap; }
  .topbar-actions { width: 100%; justify-content: space-between; }
  .date-range { flex: 1; flex-wrap: wrap; }
}

/* Avanzadas ocultas por defecto */
.adv, .advanced-block { display: none; }
body.show-advanced .adv { display: table-cell; }
body.show-advanced .advanced-block { display: block; }

/* Embudo */
.funnel { display: grid; gap: .6rem; margin-bottom: 1.25rem; }
.funnel-row { display: grid; grid-template-columns: 1fr 96px; align-items: center; gap: .75rem; }
.funnel-bar { height: 40px; border-radius: 10px; display: flex; align-items: center; padding: 0 .8rem; color: #fff; font-weight: 800; min-width: 44px; width: 6%; transition: width .6s ease; }
.funnel-bar.f1 { background: linear-gradient(90deg, #7c3aed, #8b5cf6); }
.funnel-bar.f2 { background: linear-gradient(90deg, #6366f1, #3b82f6); }
.funnel-bar.f3 { background: linear-gradient(90deg, #2563eb, #0ea5e9); }
.funnel-label { color: var(--muted); font-weight: 600; font-size: .85rem; }
.mini-stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .75rem; }
.mini-stats > div { background: var(--lilac-2); border-radius: 12px; padding: .65rem .8rem; }
.mini-stats span { display: block; color: var(--muted); font-size: .75rem; }
.mini-stats strong { font-size: 1.05rem; }
.mini-stats-6 { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }

/* Badges */
.badge-sale { background: linear-gradient(135deg, #059669, #10b981); color: #fff; font-size: .68rem; font-weight: 800; letter-spacing: .04em; border-radius: 6px; padding: .15rem .45rem; }
.badge-reason { background: #f3f4f6; color: #6b7280; font-size: .68rem; border-radius: 6px; padding: .15rem .45rem; }
.badge-contacted { background: var(--ok-bg); color: var(--ok); border-radius: 6px; padding: 0 .3rem; font-size: .75rem; }
.var { font-weight: 700; font-size: .85rem; white-space: nowrap; }
.var-good { color: var(--ok); } .var-bad { color: var(--err); } .var-na, .var-neutral { color: var(--muted); }

/* Filtros */
.filter-bar { display: flex; flex-wrap: wrap; gap: .5rem; padding: .75rem; margin-bottom: 1rem; align-items: center; }
.filter-bar .form-select { width: auto; min-width: 160px; }
.search-box { position: relative; flex: 1; min-width: 220px; }
.search-box i { position: absolute; left: .8rem; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search-box input { padding-left: 2.2rem; }
.more-filters { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: .5rem; padding-top: .5rem; }
.more-filters .form-select { width: 100%; }

/* Kanban */
.kanban { display: grid; grid-template-columns: repeat(3, minmax(280px, 1fr)); gap: 1rem; align-items: start; }
@media (max-width: 991.98px) {
  .kanban { grid-template-columns: repeat(3, 85vw); overflow-x: auto; scroll-snap-type: x mandatory; padding-bottom: .5rem; }
  .kanban-col { scroll-snap-align: start; }
}
.kanban-col { background: #f1f0f7; border-radius: var(--radius); padding: .75rem; min-height: 200px; }
.kanban-head { display: flex; justify-content: space-between; align-items: center; font-weight: 700; padding: .25rem .4rem .75rem; }
.col-new .kanban-head i { color: var(--brand); } .col-qualified .kanban-head i { color: var(--ok); } .col-unqualified .kanban-head i { color: #9ca3af; }
.kanban-head .count { background: #fff; border-radius: 999px; padding: .05rem .55rem; font-size: .8rem; color: var(--muted); }
.kanban-list { display: flex; flex-direction: column; gap: .6rem; min-height: 120px; border-radius: 12px; transition: background .15s; }
.kanban-list.drag-over { background: var(--lilac); outline: 2px dashed #c4b5fd; }
.kanban-empty { display: none; text-align: center; color: #a1a1b5; font-size: .85rem; padding: 1.5rem 0; }
.kanban-list:not(:has(.lead-card)) .kanban-empty { display: block; }
.lead-card { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: .8rem .9rem; box-shadow: var(--shadow); cursor: grab; position: relative; }
.lead-card:hover { border-color: #d8ccfb; }
.lead-card.dragging { opacity: .5; }
.lead-card.saving { opacity: .6; pointer-events: none; }
.lead-name { font-weight: 700; color: var(--ink); text-decoration: none; }
.lead-line { font-size: .82rem; color: #4b5563; margin-top: .25rem; }
.lead-line i { color: #a1a1b5; margin-right: .2rem; }
.lead-meta { display: flex; justify-content: space-between; align-items: center; gap: .5rem; font-size: .72rem; color: var(--muted); margin-top: .5rem; }
.btn-ghost { border: 0; background: transparent; padding: 0 .3rem; color: var(--muted); }
.card-menu { position: relative; z-index: 2; }
.reason-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.reason-option { display: flex; gap: .5rem; align-items: center; border: 1px solid var(--line); border-radius: 10px; padding: .55rem .7rem; cursor: pointer; }
.reason-option:has(input:checked) { border-color: var(--brand); background: var(--lilac-2); }

/* Detalle de lead */
.quick-actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.btn-wa { background: #25d366; color: #fff; border: 0; } .btn-wa:hover { background: #1ebe5b; color: #fff; }
.contacted-pill { background: var(--ok-bg); color: var(--ok); border-radius: 12px; padding: .45rem .8rem; font-weight: 600; font-size: .85rem; }
.data-list { display: grid; grid-template-columns: minmax(110px, 38%) 1fr; gap: .45rem 1rem; margin: 0; }
.data-list dt { color: var(--muted); font-weight: 500; font-size: .85rem; }
.data-list dd { margin: 0; word-break: break-word; }
.note { border-left: 3px solid #c4b5fd; padding: .4rem .8rem; margin-bottom: .75rem; background: var(--lilac-2); border-radius: 0 10px 10px 0; }
.note-meta { font-size: .75rem; color: var(--muted); margin-bottom: .15rem; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { display: flex; gap: .7rem; padding: .5rem 0; border-bottom: 1px dashed var(--line); }
.timeline li:last-child { border-bottom: 0; }
.timeline i { color: var(--brand); margin-top: .15rem; }
.sale-card { border-color: #a7f3d0; }

/* Admin Meta */
.plain-list { list-style: none; padding: 0; margin: 0; display: grid; gap: .3rem; }
.pick-row { display: flex; gap: .7rem; align-items: flex-start; padding: .55rem .4rem; border-radius: 10px; cursor: pointer; }
.pick-row:hover { background: var(--lilac-2); }
.pick-row small { display: block; color: var(--muted); }
.pick-sub { margin-left: 1.6rem; padding: .3rem .4rem; }
.page-block { border-bottom: 1px solid var(--line); padding: .3rem 0; }
.page-block.is-taken { opacity: .5; }
.danger-zone { border-color: #fecaca; }
.log-msg { max-width: 520px; word-break: break-word; }
.reason-row { display: flex; justify-content: space-between; font-size: .88rem; margin-top: .6rem; }
.reason-bar { height: 6px; background: #f1f0f7; border-radius: 4px; overflow: hidden; margin-top: .25rem; }
.reason-bar div { height: 100%; width: 0; background: linear-gradient(90deg, #a78bfa, #7c3aed); }

/* Páginas públicas */
.public-body { background: var(--bg); }
.public-page { max-width: 760px; margin: 0 auto; padding: 2.5rem 1.25rem 4rem; }
.public-page h1 { font-weight: 800; margin: 1.5rem 0 .5rem; } .public-page h2 { font-size: 1.1rem; font-weight: 700; margin-top: 1.5rem; }

/* Impresión del reporte */
@media print {
  .sidebar, .topbar, .no-print, .workspace-banner { display: none !important; }
  .content { padding: 0; } .card-soft { box-shadow: none; break-inside: avoid; }
  body { background: #fff; }
}

/* Ajustes visuales */
:root { --bs-link-color-rgb: 109, 40, 217; --bs-link-hover-color-rgb: 91, 33, 182; }
.btn-outline-primary { --bs-btn-active-bg: var(--brand); --bs-btn-active-border-color: var(--brand); --bs-btn-active-color: #fff; }
.btn-check:checked + .btn-outline-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.kpi-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.kpi-grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1199.98px) { .kpi-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } .kpi-grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 575.98px) {
  .kpi-grid, .kpi-grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .6rem; }
  .kpi-card { padding: .9rem; }
  .kpi-icon { width: 30px; height: 30px; margin-bottom: .5rem; font-size: .95rem; }
  .kpi-value { font-size: 1.3rem; }
  .page-title { font-size: 1.35rem; }
}
.kpi-grid:has(> :nth-child(8)) { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 575.98px) { .kpi-grid:has(> :nth-child(8)) { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.funnel + .mini-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.table-compact td, .table-compact th { padding: .75rem .9rem; white-space: nowrap; }
.table-compact td:first-child { white-space: normal; min-width: 140px; }
