:root {
  --bg: #0f1117;
  --panel: #171a23;
  --panel-2: #1c2029;
  --line: #2a2f3d;
  --line-soft: #232734;
  --txt: #e7e9ee;
  --muted: #8a90a2;
  --dim: #5c6275;
  --accent: #6c5ce7;
  --accent-2: #8b7bff;
  --ok: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --info: #38bdf8;
  --radius: 14px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg); color: var(--txt); min-height: 100vh; font-size: 15px;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; cursor: pointer; }
input, select, textarea {
  font: inherit; background: var(--panel-2); color: var(--txt);
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
textarea { resize: vertical; min-height: 74px; }
label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 5px; font-weight: 600; }
.hidden { display: none !important; }

/* ---------- Login ---------- */
#login {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px;
}
#login .card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 34px 30px; }
#login .brand { display: flex; align-items: center; gap: 12px; margin-bottom: 26px; }
#login .brand .dot { width: 42px; height: 42px; border-radius: 12px; background: linear-gradient(135deg, var(--accent), var(--accent-2)); display: flex; align-items: center; justify-content: center; font-size: 20px; }
#login h1 { font-size: 19px; }
#login .sub { font-size: 12.5px; color: var(--dim); }
#login .field { margin-bottom: 14px; }

/* ---------- Layout ---------- */
header.top {
  position: sticky; top: 0; z-index: 40; background: rgba(15,17,23,.92);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.top-in { max-width: 1480px; margin: 0 auto; padding: 12px 20px; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.logo { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: -.3px; }
.logo .dot { width: 32px; height: 32px; border-radius: 9px; background: linear-gradient(135deg, var(--accent), var(--accent-2)); display: flex; align-items: center; justify-content: center; font-size: 15px; }
nav.tabs { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
nav.tabs button {
  background: transparent; border: 1px solid transparent; color: var(--muted);
  padding: 7px 14px; border-radius: 9px; font-size: 14px; font-weight: 600;
}
nav.tabs button:hover { color: var(--txt); background: var(--panel-2); }
nav.tabs button.on { color: var(--txt); background: var(--panel-2); border-color: var(--line); }
.top-right { display: flex; align-items: center; gap: 10px; }
.whoami { font-size: 12.5px; color: var(--muted); text-align: right; line-height: 1.35; }
.whoami b { color: var(--txt); display: block; }

main { max-width: 1480px; margin: 0 auto; padding: 20px; }

/* ---------- Botones ---------- */
.btn {
  background: var(--panel-2); color: var(--txt); border: 1px solid var(--line);
  padding: 8px 14px; border-radius: 10px; font-size: 13.5px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 7px; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { background: transparent; border-color: #57303a; color: #ff8b8b; }
.btn.danger:hover { background: rgba(239,68,68,.12); border-color: var(--danger); }
.btn.ok { background: transparent; border-color: #2b5a3b; color: #6ee7a0; }
.btn.ok:hover { background: rgba(34,197,94,.12); border-color: var(--ok); }
.btn.sm { padding: 5px 10px; font-size: 12.5px; border-radius: 8px; }
.btn.ghost { background: transparent; border-color: var(--line-soft); color: var(--muted); }

/* ---------- Resumen ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.kpi .n { font-size: 26px; font-weight: 700; letter-spacing: -.5px; }
.kpi .l { font-size: 12px; color: var(--muted); margin-top: 2px; text-transform: uppercase; letter-spacing: .4px; }
.kpi.ok .n { color: var(--ok); } .kpi.warn .n { color: var(--warn); }
.kpi.danger .n { color: var(--danger); } .kpi.info .n { color: var(--info); }
.kpi.money .n { font-size: 22px; }

/* ---------- Filtros ---------- */
.bar {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 16px; display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end;
}
.bar .f { min-width: 150px; flex: 1 1 150px; }
.bar .f.wide { flex: 2 1 260px; }
.bar .actions { display: flex; gap: 8px; align-items: center; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--muted);
  padding: 6px 12px; border-radius: 20px; font-size: 12.5px; font-weight: 600;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------- Tabla ---------- */
.tablewrap { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.scroll-x { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th {
  text-align: left; padding: 11px 14px; color: var(--muted); font-size: 11.5px;
  text-transform: uppercase; letter-spacing: .5px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
td { padding: 11px 14px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: rgba(108,92,231,.06); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.cliente-cell b { display: block; font-size: 14px; }
.cliente-cell span { font-size: 12px; color: var(--dim); }
.rowacts { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 20px;
  font-size: 11.5px; font-weight: 700; white-space: nowrap; border: 1px solid transparent;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.b-activa { background: rgba(34,197,94,.13); color: #6ee7a0; border-color: rgba(34,197,94,.3); }
.b-proxima_vencer { background: rgba(245,158,11,.13); color: #fbbf24; border-color: rgba(245,158,11,.3); }
.b-vencida { background: rgba(245,158,11,.2); color: #fdba74; border-color: rgba(245,158,11,.45); }
.b-bloqueada { background: rgba(239,68,68,.13); color: #ff8b8b; border-color: rgba(239,68,68,.32); }
.b-suspendido { background: rgba(168,85,247,.16); color: #d8b4fe; border-color: rgba(168,85,247,.35); }
.b-sin_respuesta { background: rgba(120,130,150,.14); color: #9aa3b5; border-color: rgba(120,130,150,.3); }
.b-sin_suscripcion { background: rgba(56,189,248,.12); color: #7dd3fc; border-color: rgba(56,189,248,.3); }
.b-desconocido { background: rgba(120,130,150,.1); color: var(--dim); border-color: var(--line); }
.dias { font-weight: 700; font-variant-numeric: tabular-nums; }
.dias.neg { color: #ff8b8b; } .dias.low { color: #fbbf24; } .dias.ok { color: #6ee7a0; }
.tag { font-size: 11px; color: var(--dim); background: var(--panel-2); border: 1px solid var(--line-soft); padding: 2px 7px; border-radius: 6px; }

/* ---------- Modales ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(6,8,12,.72); backdrop-filter: blur(3px);
  z-index: 90; display: flex; align-items: flex-start; justify-content: center; padding: 24px; overflow-y: auto;
}
.modal {
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px;
  width: 100%; max-width: 560px; margin: auto; overflow: hidden;
}
.modal.wide { max-width: 860px; }
.modal-head { padding: 18px 22px; border-bottom: 1px solid var(--line); display: flex; align-items: flex-start; gap: 12px; }
.modal-head h3 { font-size: 17px; }
.modal-head p { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.modal-head .x { margin-left: auto; background: transparent; border: none; color: var(--dim); font-size: 22px; line-height: 1; padding: 0 4px; }
.modal-body { padding: 20px 22px; max-height: 68vh; overflow-y: auto; }
.modal-foot { padding: 14px 22px; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: flex-end; background: var(--panel-2); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.field { margin-bottom: 14px; }
.hint { font-size: 12px; color: var(--dim); margin-top: 5px; line-height: 1.45; }
.req::after { content: ' *'; color: #ff8b8b; }

.opt {
  display: flex; gap: 11px; align-items: flex-start; padding: 12px 14px; border: 1px solid var(--line);
  border-radius: 12px; margin-bottom: 9px; cursor: pointer; background: var(--panel-2);
}
.opt:hover { border-color: var(--accent); }
.opt.on { border-color: var(--accent); background: rgba(108,92,231,.1); }
.opt input { width: auto; margin-top: 3px; accent-color: var(--accent); }
.opt b { display: block; font-size: 14px; margin-bottom: 2px; }
.opt span { font-size: 12.5px; color: var(--muted); line-height: 1.45; }

.alert { border-radius: 11px; padding: 12px 14px; font-size: 13px; line-height: 1.5; margin-bottom: 15px; border: 1px solid; }
.alert.warn { background: rgba(245,158,11,.1); border-color: rgba(245,158,11,.35); color: #fcd34d; }
.alert.danger { background: rgba(239,68,68,.1); border-color: rgba(239,68,68,.35); color: #ff9d9d; }
.alert.info { background: rgba(56,189,248,.09); border-color: rgba(56,189,248,.3); color: #9ad9f8; }
.alert.ok { background: rgba(34,197,94,.1); border-color: rgba(34,197,94,.32); color: #86efac; }

/* ---------- Comprobante ---------- */
.dropzone {
  border: 2px dashed var(--line); border-radius: 12px; padding: 22px; text-align: center;
  color: var(--muted); font-size: 13px; cursor: pointer; background: var(--panel-2);
}
.dropzone:hover, .dropzone.hot { border-color: var(--accent); color: var(--txt); }
.dropzone.filled { padding: 10px; border-style: solid; }
.dropzone img { max-height: 190px; max-width: 100%; border-radius: 9px; display: block; margin: 0 auto; }
.thumb { width: 38px; height: 38px; object-fit: cover; border-radius: 7px; border: 1px solid var(--line); cursor: pointer; }

/* ---------- Barras ---------- */
.barrow { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; margin-bottom: 9px; }
.barrow .track { height: 8px; background: var(--panel-2); border-radius: 5px; overflow: hidden; margin-top: 5px; }
.barrow .fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: 5px; }
.barrow .lbl { font-size: 13px; }
.barrow .val { font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; }

.section { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.section h3 { font-size: 15px; margin-bottom: 14px; display: flex; align-items: center; gap: 8px; }
.section h3 .tag { margin-left: auto; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }

/* ---------- Grupos plegables ---------- */
.grupo { margin-bottom: 14px; }
.grupo-head {
  width: 100%; display: flex; align-items: center; gap: 11px; text-align: left;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 13px 16px; color: var(--txt); margin-bottom: 8px;
}
.grupo-head:hover { border-color: var(--accent); }
.grupo-head .caret { color: var(--muted); font-size: 13px; transition: transform .16s; display: inline-block; }
.grupo-head .caret.abierto { transform: rotate(90deg); }
.grupo-tit { font-weight: 700; font-size: 15px; }
.grupo-sub { display: block; font-weight: 400; font-size: 12px; color: var(--dim); margin-top: 1px; }
.grupo-nums { margin-left: auto; display: flex; align-items: center; gap: 7px; flex-wrap: wrap; justify-content: flex-end; }

/* ---------- Meses del año ---------- */
.meses { display: grid; grid-template-columns: repeat(12, 1fr); gap: 6px; }
.mes {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 11px;
  padding: 10px 6px; color: var(--txt); min-height: 132px;
}
.mes:hover { border-color: var(--accent); }
.mes.on { border-color: var(--accent); background: rgba(108,92,231,.14); }
.mes.vacio { opacity: .5; }
.mes-n { font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); }
.mes-bar { flex: 1; width: 22px; display: flex; align-items: flex-end; background: rgba(255,255,255,.03); border-radius: 4px; overflow: hidden; }
.mes-bar span { width: 100%; background: linear-gradient(180deg, var(--accent-2), var(--accent)); border-radius: 4px 4px 0 0; }
.mes-t { font-size: 11px; font-weight: 700; text-align: center; line-height: 1.3; font-variant-numeric: tabular-nums; }
.mes-c { font-size: 10.5px; color: var(--dim); }
@media (max-width: 900px) { .meses { grid-template-columns: repeat(6, 1fr); } }
@media (max-width: 480px) { .meses { grid-template-columns: repeat(3, 1fr); } }

.empty { padding: 44px 20px; text-align: center; color: var(--dim); font-size: 14px; }
.spin { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: sp .7s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }

#toasts { position: fixed; right: 18px; bottom: 18px; z-index: 120; display: flex; flex-direction: column; gap: 9px; max-width: 380px; }
.toast {
  background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--accent);
  border-radius: 11px; padding: 12px 15px; font-size: 13.5px; line-height: 1.45; box-shadow: 0 10px 30px rgba(0,0,0,.5);
  animation: slide .22s ease;
}
.toast.ok { border-left-color: var(--ok); }
.toast.err { border-left-color: var(--danger); }
@keyframes slide { from { transform: translateX(20px); opacity: 0; } }

@media (max-width: 900px) {
  .cols { grid-template-columns: 1fr; }
  .grid3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 620px) {
  main { padding: 14px; }
  .top-in { padding: 10px 14px; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .kpi .n { font-size: 22px; }
  th, td { padding: 9px 10px; }
  .modal-body { max-height: 62vh; }
}
