:root {
  --rojo: #da291c;
  --rojo-osc: #b21f15;
  --rojo-claro: #fff1f0;
  --gris: #f1f3f6;
  --gris-2: #f7f8fa;
  --borde: #e2e6ec;
  --borde-2: #d3d9e2;
  --texto: #1d2330;
  --texto-2: #5b6577;
  --verde: #1c8a4d;
  --verde-claro: #eaf7ef;
  --azul: #1c5fbf;
  --sombra: 0 1px 3px rgba(20, 30, 50, .06), 0 4px 14px rgba(20, 30, 50, .05);
  --radio: 12px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, "Segoe UI", Roboto, sans-serif;
  color: var(--texto);
  background: var(--gris);
  font-size: 14px;
}

/* ---------- Header ---------- */
header {
  background: linear-gradient(100deg, var(--rojo), var(--rojo-osc));
  color: #fff;
  padding: 16px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  box-shadow: 0 2px 10px rgba(178, 31, 21, .25);
}
header h1 { margin: 0; font-size: 22px; letter-spacing: .3px; }
header .sub { font-size: 13px; opacity: .9; }
.userbar { display: flex; align-items: center; gap: 16px; font-size: 14px; }
.user-chip {
  background: rgba(255, 255, 255, .15); padding: 5px 12px; border-radius: 999px; font-size: 13px;
}
.userbar .link, .link {
  background: none; border: none; color: #fff; cursor: pointer; font-size: 14px;
  text-decoration: underline; padding: 0;
}
.userbar .link:hover { opacity: .85; }
#listaUsuarios .link { color: var(--rojo); }

/* ---------- Login ---------- */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card {
  background: #fff; border: 1px solid var(--borde); border-radius: var(--radio); padding: 30px;
  width: 330px; display: flex; flex-direction: column; gap: 12px; box-shadow: var(--sombra);
}
.login-card h1 { margin: 0; color: var(--rojo); }
.login-card .sub { margin: -8px 0 8px; color: var(--texto-2); font-size: 13px; }
.login-card label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--texto-2); }
.login-card input { padding: 10px; border: 1px solid var(--borde-2); border-radius: 8px; font-size: 15px; }
.login-card button, #formUsuario button {
  background: var(--rojo); color: #fff; border: none; padding: 11px; border-radius: 8px;
  font-size: 15px; cursor: pointer; transition: background .15s;
}
.login-card button:hover, #formUsuario button:hover { background: var(--rojo-osc); }

/* ---------- Layout ---------- */
main { max-width: 1240px; margin: 22px auto; padding: 0 18px; }

.card {
  background: #fff;
  border: 1px solid var(--borde);
  border-radius: var(--radio);
  padding: 18px 20px;
  margin-bottom: 18px;
  box-shadow: var(--sombra);
}
.card h2 {
  margin: 0 0 16px; font-size: 15px; color: var(--texto);
  display: flex; align-items: center; gap: 8px;
  padding-bottom: 10px; border-bottom: 1px solid var(--borde);
}
.card h2 .ico { font-size: 16px; }

/* ---------- Dropzone ---------- */
.dropzone {
  border: 2px dashed var(--borde-2);
  border-radius: 10px;
  padding: 16px 18px;
  text-align: center;
  color: var(--texto-2);
  cursor: pointer;
  transition: .15s;
  background: var(--gris-2);
  font-size: 13px;
}
.dropzone p strong { font-size: 14px; }
.dropzone:hover { border-color: var(--rojo); }
.dropzone.hover { border-color: var(--rojo); background: var(--rojo-claro); color: var(--rojo); }
.dropzone p { margin: 0; }

.excel-migra { margin-top: 16px; padding-top: 12px; border-top: 1px dashed var(--borde); font-size: 13px; }
.excel-migra summary { cursor: pointer; color: var(--texto-2); width: fit-content; list-style-position: inside; }
.excel-migra summary:hover { color: var(--rojo); }
.excel-migra .hint { color: var(--texto-2); font-size: 13px; }
.zona-riesgo { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--borde); font-size: 13px; }
.zona-riesgo summary { cursor: pointer; color: var(--rojo); width: fit-content; list-style-position: inside; }
.zona-riesgo .hint { color: var(--texto-2); font-size: 13px; }
.boton.peligro { border-color: var(--rojo); color: #fff; background: var(--rojo); }
.boton.peligro:hover { background: var(--rojo-osc); border-color: var(--rojo-osc); }
#formUsuario { margin-top: 12px; }
#formUsuario button { align-self: end; }

.msg { margin-top: 12px; font-size: 14px; }
.msg.ok { color: var(--verde); }
.msg.err { color: var(--rojo); }
.msg.load { color: var(--texto-2); }

/* ---------- Filtros ---------- */
.filtros { display: flex; flex-wrap: wrap; gap: 16px; align-items: end; }
.filtros label { display: flex; flex-direction: column; font-size: 12px; gap: 5px; color: var(--texto-2); font-weight: 600; }
.filtros select, .filtros input {
  padding: 8px 10px; border: 1px solid var(--borde-2); border-radius: 8px; font-size: 14px; min-width: 160px;
  background: #fff; color: var(--texto); font-weight: 400;
}
.filtros select:focus, .filtros input:focus { outline: none; border-color: var(--rojo); box-shadow: 0 0 0 3px var(--rojo-claro); }

/* Multi-selector de meses */
.multi { position: relative; }
.multi-btn {
  min-width: 180px; text-align: left; padding: 8px 10px; border: 1px solid var(--borde-2);
  border-radius: 8px; font-size: 14px; background: #fff; cursor: pointer; color: var(--texto);
}
.multi-btn::after { content: "▾"; float: right; color: var(--texto-2); }
.multi-btn.activo { border-color: var(--rojo); color: var(--rojo); font-weight: 600; }
.multi-pop {
  position: absolute; top: calc(100% + 4px); left: 0; z-index: 20;
  background: #fff; border: 1px solid var(--borde-2); border-radius: 10px; box-shadow: var(--sombra);
  padding: 6px; min-width: 200px; max-height: 280px; overflow-y: auto;
}
.ms-item {
  display: flex; align-items: center; gap: 8px; padding: 7px 9px; border-radius: 7px;
  font-size: 14px; font-weight: 400; color: var(--texto); cursor: pointer;
}
.ms-item:hover { background: var(--gris); }
.filtros #fLineaTxt { min-width: 260px; }
#acLineaPop { width: 100%; }
.ms-vacio { padding: 10px; color: var(--texto-2); font-size: 13px; }

/* Barra de acciones (vistas + export) */
.barra-acciones {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  flex-wrap: wrap; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--borde);
}
.vista-toggle { display: inline-flex; background: var(--gris); border-radius: 9px; padding: 3px; gap: 3px; }
.vista-toggle button {
  border: none; background: transparent; padding: 7px 16px; border-radius: 7px; cursor: pointer;
  font-size: 14px; color: var(--texto-2); font-weight: 600; transition: .12s;
}
.vista-toggle button.activo { background: #fff; color: var(--rojo); box-shadow: var(--sombra); }
.export { display: flex; gap: 8px; align-items: center; }
.boton, button.secundario {
  border: 1px solid var(--borde-2); background: #fff; padding: 8px 13px; border-radius: 8px;
  cursor: pointer; font-size: 14px; text-decoration: none; color: var(--texto); transition: .12s;
}
.boton:hover, button.secundario:hover { background: var(--gris); border-color: var(--borde-2); }
.iva { font-size: 13px; color: var(--texto-2); display: flex; align-items: center; gap: 5px; }

/* ---------- Resumen (cifras destacadas) ---------- */
.resumen { margin-bottom: 16px; }
.stats { display: flex; flex-wrap: wrap; gap: 12px; }
.stat {
  background: var(--gris-2); border: 1px solid var(--borde); border-radius: 10px;
  padding: 12px 16px; min-width: 150px; display: flex; flex-direction: column; gap: 3px;
}
.stat-lbl { font-size: 12px; color: var(--texto-2); font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }
.stat-val { font-size: 20px; font-weight: 700; color: var(--texto); }
.stat-total { background: var(--rojo-claro); border-color: #f3c9c5; }
.stat-total .stat-val { color: var(--rojo-osc); }
.resumen-extra { margin-top: 12px; font-size: 14px; }
.resumen-extra .link { color: var(--rojo); }

/* ---------- Aumentos destacados ---------- */
.alertas { border-left: 4px solid var(--rojo); }
.alertas h2 { color: var(--rojo-osc); }
.alertas-hint { margin: -8px 0 14px; color: var(--texto-2); font-size: 13px; }
.alertas-lista { display: flex; flex-direction: column; gap: 8px; }
.alerta-item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  flex-wrap: wrap; padding: 11px 14px; border: 1px solid #f3c9c5; border-radius: 10px;
  background: var(--rojo-claro);
}
.alerta-quien { display: flex; flex-direction: column; gap: 2px; }
.alerta-usuario { font-weight: 700; color: var(--texto); }
.alerta-linea { font-size: 12px; color: var(--texto-2); }
.alerta-detalle { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.alerta-extra { font-size: 18px; font-weight: 800; color: var(--rojo-osc); }
.alerta-pct { font-weight: 700; color: var(--rojo); }
.alerta-meses { font-size: 12px; color: var(--texto-2); }

/* ---------- Tablas ---------- */
/* Barra de scroll horizontal arriba de la tabla (espejo de la de abajo). */
.scroll-top { overflow-x: auto; overflow-y: hidden; margin-bottom: 6px; }
.scroll-top > div { height: 1px; }
.tabla-wrap { overflow-x: auto; border: 1px solid var(--borde); border-radius: 10px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 9px 11px; border-bottom: 1px solid var(--borde); text-align: right; white-space: nowrap; }
th {
  background: var(--gris-2); position: sticky; top: 0; text-align: right; z-index: 1;
  font-size: 12px; text-transform: uppercase; letter-spacing: .3px; color: var(--texto-2);
}
th:first-child, td:first-child, th:nth-child(2), td.txt { text-align: left; }
td.txt { text-align: left; }
tbody tr:hover td { background: var(--gris-2); }
.neg { color: var(--rojo); }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--gris); font-weight: 600; }
.badge.pdf { background: #e7f0ff; color: var(--azul); }
.badge.excel { background: var(--verde-claro); color: var(--verde); }
.total-row td { font-weight: 700; background: var(--rojo-claro); border-top: 2px solid var(--rojo); }
.vacio { padding: 36px; text-align: center; color: var(--texto-2); }

/* ---------- Vista por mes (filas resumen tipo planilla) ---------- */
.pivote thead th:first-child { left: 0; z-index: 2; }
.pivote .linea-col { color: var(--texto-2); }
.pivote .sum td { background: #fbfcfe; }
.pivote .sum td.txt { font-weight: 700; color: var(--texto-2); text-transform: uppercase; font-size: 11px; letter-spacing: .4px; }
.pivote .total-row td { background: var(--rojo-claro); border-top: 2px solid var(--rojo); border-bottom: 1px solid #f3c9c5; }
.pivote .total-row td.txt { color: var(--rojo-osc); }
.pivote .tc-row td { border-bottom: none; }
/* Botón ✕ para borrar un mes (solo editores), en el encabezado de la columna. */
.pivote .th-del {
  margin-left: 6px; border: none; background: none; cursor: pointer; color: var(--texto-2);
  font-size: 12px; padding: 0 3px; border-radius: 5px; line-height: 1;
}
.pivote .th-del:hover { background: var(--rojo); color: #fff; }
.pivote .tc-cell input {
  width: 92px; padding: 5px 7px; border: 1px solid var(--borde-2); border-radius: 7px;
  font-size: 13px; text-align: right; background: #fff;
}
.pivote .tc-cell input:disabled { background: transparent; border-color: transparent; color: var(--texto); }
.pivote .usd-row td { color: var(--texto-2); font-style: italic; }
.pivote .dif-row td { font-weight: 700; }
.pivote .dif-up { color: var(--rojo); }      /* subió respecto al mes anterior */
.pivote .dif-down { color: var(--verde); }    /* bajó respecto al mes anterior */
.pivote .pct-linea { font-size: 11px; font-weight: 600; margin-top: 2px; color: var(--texto-2); }
.pivote .pct-linea.dif-up { color: var(--rojo); }
.pivote .pct-linea.dif-down { color: var(--verde); }
.pivote .dif-row td { border-bottom: 2px solid var(--borde-2); }

@media (max-width: 720px) {
  .barra-acciones { flex-direction: column; align-items: stretch; }
  .export { justify-content: space-between; }
  header { flex-direction: column; align-items: flex-start; gap: 8px; }
}

/* ---------- Cambios de plan ---------- */
#cambiosPlan summary { cursor: pointer; list-style: none; }
#cambiosPlan summary::-webkit-details-marker { display: none; }
#cambiosPlan summary h2 { margin-bottom: 0; }
#cambiosPlan summary h2::after { content: "▸"; margin-left: auto; color: var(--texto-2); }
#cambiosPlanDet[open] summary h2 { margin-bottom: 16px; }
#cambiosPlanDet[open] summary h2::after { content: "▾"; }
.filtros #cpLineaTxt { min-width: 240px; }
#acCpLineaPop { width: 100%; }
.filtros .cp-motivo { flex: 1 1 280px; }
.filtros .cp-motivo input { width: 100%; box-sizing: border-box; }
.cp-lista { margin-top: 16px; overflow-x: auto; }
.cp-lista .hint { color: var(--texto-2); font-size: 13px; }
.cp-motivo-txt { white-space: normal; min-width: 220px; }
.cp-dir { font-size: 12px; font-weight: 600; white-space: nowrap; }
.cp-dir.sube { color: var(--rojo); }
.cp-dir.baja { color: var(--verde); }
.cp-nuevo { font-size: 12px; font-weight: 700; white-space: nowrap; cursor: help; color: var(--texto-2); }
.cp-nuevo.sube { color: var(--rojo); }
.cp-nuevo.baja { color: var(--verde); }
