:root {
  --brand: #FCD119;          /* amarillo corporativo Factoría */
  --brand-dark: #E9C828;
  --ink: #00091F;            /* azul noche corporativo */
  --bg: #f6f6f4;
  --surface: #ffffff;
  --text: #00091F;
  --muted: #6b6b70;
  --line: #e5e5e2;
  --ok: #1f8a4c;
  --warn: #b26a00;
  --radius: 10px;
  font-family: Montserrat, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; font-size: 14px; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.error { color: #b3261e; min-height: 1em; margin: 0; }

.btn { border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 8px; padding: 8px 14px; font: inherit; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { border-color: #cfcfcb; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--ink); font-weight: 700; }
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: #ececea; }
.btn-danger { color: #b3261e; }

.brand { display: flex; align-items: center; gap: 10px; }
.brand .logo { height: 40px; width: auto; display: block; }
.brand-sub { color: rgba(255,255,255,.75); font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; border-left: 1px solid rgba(255,255,255,.25); padding-left: 12px; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { background: var(--ink); }
.login-card { background: var(--surface); border-radius: 14px; padding: 0 28px 28px; width: 100%; max-width: 380px; display: grid; gap: 14px; overflow: hidden; }
.login-card .brand { background: var(--ink); margin: 0 -28px 8px; padding: 22px 28px; border-bottom: 4px solid var(--brand); }
.login-card h1 { margin: 0; font-size: 20px; font-weight: 800; }
.login-card label, .field { display: grid; gap: 6px; font-weight: 500; }
input, select, textarea { font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); border-color: var(--ink); }

.login-card .link { background: none; border: 0; padding: 0; font: inherit; font-size: 13px; color: var(--muted); text-decoration: underline; cursor: pointer; justify-self: center; }
.login-card .link:hover { color: var(--ink); }
.ok-msg { margin: 0; padding: 10px 12px; border-radius: 8px; background: #dff3e6; color: #14532d; font-size: 13px; line-height: 1.4; }
.login-card .small { margin: 0; font-size: 13px; line-height: 1.45; }

/* Layout */
.topbar { display: flex; justify-content: space-between; align-items: center; padding: 12px 24px; background: var(--ink); border-bottom: 4px solid var(--brand); gap: 12px; flex-wrap: wrap; color: #fff; }
.topbar .btn-ghost { color: #fff; }
.topbar .btn-ghost:hover { background: rgba(255,255,255,.12); }
.topbar .muted { color: rgba(255,255,255,.75); }
.topbar-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
@media (max-width: 760px) { .topbar-right { gap: 2px; } .topbar-right .btn { padding: 6px 8px; } }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; padding: 20px 24px 0; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; text-align: left; font: inherit; cursor: pointer; display: grid; gap: 2px; }
.card:hover { border-color: var(--ink); }
.card.active { border-color: var(--ink); box-shadow: inset 0 -4px 0 var(--brand); }
.card-static { cursor: default; }
.card-static:hover { border-color: var(--line); }
.card-n { font-size: 28px; font-weight: 800; font-variant-numeric: tabular-nums; }
.card-l { color: var(--muted); }

.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 16px 24px; }
.filters input[type=search] { flex: 1 1 260px; }
.fechas { display: inline-flex; gap: 6px; align-items: center; }
.check { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }

.list { padding: 0 24px 32px; }
table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: #fafaf8; font-weight: 600; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: #fffbe6; }
td .sub { display: block; color: var(--muted); font-size: 12px; }
td.need { max-width: 320px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.empty { text-align: center; padding: 40px; color: var(--muted); }
.pager { display: flex; justify-content: center; align-items: center; gap: 12px; padding-top: 12px; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.b-completo { background: var(--brand); color: var(--ink); }
.b-incompleto { background: #eeeeec; color: #555; }
.b-contactado { background: #dff3e6; color: var(--ok); }
.b-descartado { background: #f1f1f1; color: #888; text-decoration: line-through; }
.b-pausa { background: #fff2d6; color: var(--warn); }
.canal { font-size: 12px; color: var(--muted); }

/* Ficha */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.25); }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100vw); background: var(--surface); border-left: 1px solid var(--line); display: flex; flex-direction: column; z-index: 10; }
.drawer-head { display: flex; justify-content: space-between; align-items: flex-start; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.drawer-head { border-bottom: 4px solid var(--brand); }
.drawer-head h2 { margin: 0; font-size: 20px; font-weight: 800; }
.drawer-head p { margin: 4px 0 0; }
.drawer-body { padding: 16px 20px 32px; overflow: auto; display: grid; gap: 14px; align-content: start; }
.drawer-body h3 { margin: 8px 0 0; font-size: 14px; }
.d-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.row { display: flex; align-items: center; gap: 10px; }
.alerta { padding: 10px 12px; border-radius: 8px; background: #fff2d6; color: #6b4300; }
.alerta.bloq { background: #fde2e1; color: #8a1c17; }
.datos { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; margin: 0; }
.datos dt { color: var(--muted); }
.datos dd { margin: 0; white-space: pre-wrap; word-break: break-word; }

.chat { display: grid; gap: 8px; background: #f4f2ee; border-radius: var(--radius); padding: 12px; }
.msg { max-width: 85%; padding: 8px 12px; border-radius: 12px; white-space: pre-wrap; word-break: break-word; line-height: 1.4; }
.msg.usuario { justify-self: end; background: #dcf8c6; }
.msg.bot { justify-self: start; background: #fff; border: 1px solid var(--line); }
.msg small { display: block; font-size: 11px; color: var(--muted); margin-bottom: 2px; }

/* Navegación */
.topbar .nav[aria-current="page"] { box-shadow: inset 0 -3px 0 var(--brand); border-radius: 8px 8px 0 0; }

/* Estadísticas */
.stats { padding: 20px 24px 40px; display: grid; gap: 16px; }
.stats-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.stats-head h2 { margin: 0; font-size: 20px; font-weight: 800; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: grid; gap: 2px; }
.kpi .v { font-size: 28px; font-weight: 800; font-variant-numeric: tabular-nums; }
.kpi .l { color: var(--muted); }
.kpi .s { font-size: 12px; color: var(--muted); }
.charts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.chart { margin: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; min-width: 0; }
.chart.wide { grid-column: 1 / -1; }
.chart figcaption { display: grid; gap: 2px; margin-bottom: 12px; }
.chart figcaption b { font-size: 15px; }
.chart figcaption .muted { font-size: 12px; }
.plot { width: 100%; position: relative; }
.plot svg { display: block; width: 100%; overflow: visible; }
.plot .ax { font-size: 11px; fill: var(--muted); font-family: inherit; }
.plot .grid { stroke: #ececea; stroke-width: 1; }
.plot .hit { fill: transparent; cursor: default; }
.plot .hit:hover + g .bar, .plot g.on .bar { opacity: .8; }
.legend { display: flex; gap: 16px; font-size: 13px; margin-bottom: 8px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.hbars { display: grid; gap: 10px; }
.hbar { display: grid; grid-template-columns: 130px 1fr 92px; gap: 10px; align-items: center; font-size: 13px; }
.hbar .track { height: 14px; background: #f1f1ee; border-radius: 4px; overflow: hidden; }
.hbar .fill { height: 100%; background: #2b4c9b; border-radius: 0 4px 4px 0; min-width: 2px; }
.hbar .val { text-align: right; font-variant-numeric: tabular-nums; }
.hbar .val small { color: var(--muted); margin-left: 4px; }
.tip { position: fixed; z-index: 30; pointer-events: none; background: var(--ink); color: #fff; font-size: 12px; padding: 6px 9px; border-radius: 6px; line-height: 1.4; white-space: nowrap; box-shadow: 0 4px 14px rgba(0,9,31,.25); }
.empty-chart { color: var(--muted); font-size: 13px; padding: 24px 0; text-align: center; }
@media (max-width: 900px) { .charts { grid-template-columns: 1fr; } }
@media (max-width: 760px) { .stats { padding: 16px 12px 32px; } .hbar { grid-template-columns: 100px 1fr 80px; } }

/* Asistente */
.asis { padding: 20px 24px 40px; display: grid; gap: 16px; }
.asis-grid { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(320px, 1fr); gap: 16px; align-items: start; }
.asis-side { display: grid; gap: 16px; }
.pcard { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: grid; gap: 14px; min-width: 0; }
.pcard h3 { margin: 0; font-size: 15px; }
.pcard .row .btn { white-space: nowrap; flex: none; }
.aviso { margin: 0; padding: 10px 12px; border-radius: 8px; background: #fff8d6; border-left: 4px solid var(--brand); font-size: 13px; line-height: 1.45; }
.asis textarea { resize: vertical; line-height: 1.5; font-size: 13px; }
#a-con { min-height: 360px; }
.count { font-size: 12px; color: var(--muted); text-align: right; }
.count.over { color: #b3261e; font-weight: 600; }
.p-chat { min-height: 220px; max-height: 420px; overflow-y: auto; align-content: start; }
.p-chat .vacio { color: var(--muted); font-size: 13px; text-align: center; padding: 30px 10px; }
.p-form { display: flex; gap: 8px; }
.p-form input { flex: 1; min-width: 0; }
.vers { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; max-height: 360px; overflow-y: auto; }
.vers li { display: flex; align-items: center; gap: 8px; padding: 8px 6px; border-bottom: 1px solid var(--line); font-size: 13px; }
.vers li .info { flex: 1; min-width: 0; }
.vers li .info small { display: block; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vers li .btn { padding: 4px 8px; font-size: 12px; }
.vers li.actual { background: #fffbe6; }
.tag { font-size: 11px; font-weight: 700; background: var(--brand); color: var(--ink); border-radius: 999px; padding: 1px 7px; margin-left: 6px; }
@media (max-width: 1000px) { .asis-grid { grid-template-columns: 1fr; } }
@media (max-width: 760px) { .asis { padding: 16px 12px 32px; } }

/* Eliminar */
.col-del { width: 44px; }
td.del { text-align: right; padding: 6px 8px; vertical-align: middle; }
.btn-trash { background: transparent; border: 0; color: #9a9aa0; padding: 6px; border-radius: 8px; line-height: 0; cursor: pointer; }
.btn-trash:hover { background: #fde2e1; color: #b3261e; }
.btn-trash svg { width: 18px; height: 18px; }
.btn-delete { background: #b3261e; border-color: #b3261e; color: #fff; font-weight: 700; }
.btn-delete:hover:not(:disabled) { background: #8f1d17; }
.btn-delete:disabled { opacity: .4; cursor: default; }
#dlg-del p { margin: 0; }
#dlg-del .check { color: var(--text); font-weight: 500; }

/* Diálogos */
.dlg { border: 0; border-radius: 14px; padding: 0; width: min(420px, calc(100vw - 32px)); color: var(--text); border-top: 4px solid var(--brand); }
.dlg-wide { width: min(860px, calc(100vw - 32px)); }
.u-wrap { overflow-x: auto; }
.dlg::backdrop { background: rgba(0, 9, 31, .45); }
.dlg-body { padding: 20px 22px 22px; display: grid; gap: 12px; }
.dlg h2 { margin: 0; font-size: 18px; font-weight: 800; }
.dlg h3 { margin: 8px 0 0; font-size: 14px; }
.row.end { justify-content: flex-end; }
.row.between { justify-content: space-between; }
.small { font-size: 12px; margin: 0; }
.u-tabla { font-size: 13px; }
.u-tabla td { vertical-align: middle; }
.u-tabla td.acc { white-space: nowrap; text-align: right; }
.u-tabla td.acc .btn { padding: 6px 8px; }
.u-tabla tbody tr { cursor: default; }
.u-tabla tr.inactivo td { color: var(--muted); }
.u-tabla select { padding: 4px 6px; }
.u-nuevo { display: flex; flex-wrap: wrap; gap: 8px; }
.u-nuevo input { flex: 1 1 160px; }
.temporal { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 15px; font-weight: 700; background: #fff; padding: 2px 8px; border-radius: 6px; user-select: all; }

@media (max-width: 760px) {
  .u-tabla th:nth-child(2), .u-tabla td:nth-child(2) { display: none; }
  .topbar, .cards, .filters, .list { padding-left: 12px; padding-right: 12px; }
  th:nth-child(3), td:nth-child(3), th:nth-child(5), td:nth-child(5), th:nth-child(6), td:nth-child(6) { display: none; }
  .datos { grid-template-columns: 1fr; }
}
