:root {
  --navy: #2B4A8C;
  --medium-blue: #3D5FA0;
  --purple: #7B5BB6;
  --bg: #f4f6fb;
  --card-bg: #ffffff;
  --text: #1c2333;
  --text-muted: #6b7280;
  --rojo: #d9432e;
  --naranja: #e08a2c;
  --amarillo: #e0c22c;
  --verde: #2ca86a;
  --border: #e2e6f0;
  --rojo-perdido: #a5281c; /* mas profundo que --rojo, para diferenciarse del naranja */
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Verdana, Geneva, sans-serif;
  background: var(--bg);
  color: var(--text);
}

header {
  background: linear-gradient(135deg, var(--navy), var(--purple));
  color: white;
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.header-marca {
  display: flex;
  align-items: center;
  gap: 14px;
}

.logo-header {
  height: 40px;
  width: auto;
  background: white;
  border-radius: 6px;
  padding: 4px 8px;
}

header h1 {
  font-size: 18px;
  margin: 0;
}

header .subtitulo {
  font-size: 12px;
  opacity: 0.85;
}

.header-acciones {
  display: flex;
  gap: 8px;
  align-items: center;
}

button.btn-actualizar {
  background: white;
  color: var(--navy);
  border: none;
  border-radius: 6px;
  padding: 8px 14px;
  font-weight: bold;
  cursor: pointer;
  font-size: 13px;
}
button.btn-actualizar:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

button.btn-logout {
  background: transparent;
  color: white;
  border: 1px solid rgba(255,255,255,0.6);
  border-radius: 6px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
}
button.btn-logout:hover {
  background: rgba(255,255,255,0.15);
}

main {
  padding: 16px;
  max-width: 1200px;
  margin: 0 auto;
}

.tarjetas {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.tarjeta {
  background: var(--card-bg);
  border-radius: 10px;
  padding: 14px;
  border: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.tarjeta .label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.tarjeta .valor {
  font-size: 22px;
  font-weight: bold;
  color: var(--navy);
  margin-top: 4px;
}

.buckets {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 20px;
}
.bucket-card {
  border-radius: 8px;
  padding: 10px 12px;
  color: white;
  cursor: pointer;
}
.bucket-card.no_vencido { background: var(--verde); }
.bucket-card.b1-15 { background: var(--amarillo); color: #3a3000; }
.bucket-card.b16-30 { background: var(--naranja); }
.bucket-card.b31-45 { background: #cc5a20; }
.bucket-card.b46 { background: var(--rojo); }
.bucket-card .label { font-size: 12px; opacity: 0.9; }
.bucket-card .valor { font-size: 18px; font-weight: bold; }

.filtros {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  background: var(--card-bg);
  padding: 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
}
.filtros select, .filtros input {
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  font-family: inherit;
  font-size: 13px;
}

.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
}
.tabs button {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 13px;
}
.tabs button.activo {
  background: var(--navy);
  color: white;
  border-color: var(--navy);
}

.tab-monitoreo {
  color: var(--rojo);
  border-color: var(--rojo) !important;
  font-weight: bold;
}
.tab-monitoreo.activo {
  background: var(--rojo);
  color: white;
}

.titulo-seccion {
  font-size: 15px;
  color: var(--navy);
  margin: 0 0 4px;
}
.descripcion-seccion {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0 0 10px;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card-bg);
  border-radius: 8px;
  overflow: hidden;
  font-size: 13px;
}
th, td {
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
th {
  background: #eef1f9;
  font-size: 11px;
  text-transform: uppercase;
  color: var(--text-muted);
}
tr:hover { background: #f8f9fd; }

.fila-rojo { background: rgba(217, 67, 46, 0.10); }
.fila-rojo:hover { background: rgba(217, 67, 46, 0.18); }
.fila-amarillo { background: rgba(224, 194, 44, 0.16); }
.fila-amarillo:hover { background: rgba(224, 194, 44, 0.26); }
.fila-verde { background: rgba(44, 168, 106, 0.08); }
.fila-verde:hover { background: rgba(44, 168, 106, 0.16); }

.semaforo {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 6px;
}
.semaforo.no_vencido { background: var(--verde); }
.semaforo.b1-15 { background: var(--amarillo); }
.semaforo.b16-30 { background: var(--naranja); }
.semaforo.b31-45 { background: #cc5a20; }
.semaforo.b46 { background: var(--rojo); }

.excede-limite { color: var(--rojo); font-weight: bold; }

.badge-gob {
  display: inline-block;
  background: #444;
  color: white;
  font-size: 10px;
  font-weight: bold;
  padding: 1px 5px;
  border-radius: 4px;
  margin-left: 4px;
  vertical-align: middle;
}


.table-wrap { overflow-x: auto; }

footer {
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
  padding: 20px;
}

.toast {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: white;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  z-index: 100;
}

th[data-sort] { cursor: pointer; user-select: none; }
th[data-sort]:hover { color: var(--navy); }
th.sort-activo { color: var(--navy); }

.falta-positiva { color: var(--rojo); font-weight: bold; }
.falta-negativa { color: var(--verde); font-weight: bold; }

tr.fila-clickeable { cursor: pointer; }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(28, 35, 51, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 16px;
}
.modal-caja {
  background: var(--card-bg);
  border-radius: 10px;
  max-width: 900px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  padding: 16px;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.modal-header h3 {
  margin: 0;
  color: var(--navy);
  font-size: 16px;
}
.btn-cerrar-modal {
  background: none;
  border: none;
  font-size: 16px;
  cursor: pointer;
  color: var(--text-muted);
}

.campo-whatsapp {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 220px;
}
.campo-whatsapp label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.leyenda-color {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin: 0 4px 0 10px;
  vertical-align: middle;
}
.leyenda-color:first-child { margin-left: 0; }
.leyenda-recompra { background: var(--verde); }
.leyenda-abandono { background: var(--naranja); }
.leyenda-anterior { background: var(--rojo-perdido); }
.leyenda-nuevo { background: var(--purple); }
.leyenda-fila { line-height: 1.9; }

.fila-recompra { background: rgba(44, 168, 106, 0.10); }
.fila-recompra:hover { background: rgba(44, 168, 106, 0.18); }
.fila-abandono { background: rgba(224, 138, 44, 0.14); }
.fila-abandono:hover { background: rgba(224, 138, 44, 0.22); }
.fila-anterior { background: rgba(165, 40, 28, 0.16); border-left: 3px solid var(--rojo-perdido); }
.fila-anterior:hover { background: rgba(165, 40, 28, 0.24); }
.fila-nuevo { background: rgba(123, 91, 182, 0.12); }
.fila-nuevo:hover { background: rgba(123, 91, 182, 0.20); }

/* Botones de la pagina de detalle de cliente */
.btn-volver {
  background: white;
  color: var(--navy);
  border: none;
  border-radius: 6px;
  padding: 8px 16px;
  font-weight: bold;
  font-size: 13px;
  text-decoration: none;
  display: inline-block;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}
.btn-volver:hover {
  transform: translateY(-1px);
  box-shadow: 0 3px 8px rgba(0,0,0,0.2);
}

.btn-primario {
  background: var(--navy);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 9px 18px;
  font-weight: bold;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
}
.btn-primario:hover { background: var(--medium-blue); }
.btn-primario:disabled { opacity: 0.6; cursor: not-allowed; }

.acciones-whatsapp {
  display: flex;
  align-items: center;
  gap: 12px;
  align-self: flex-end;
}

.btn-icono-whatsapp {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #25D366;
  color: white;
  border-radius: 20px;
  padding: 8px 14px;
  text-decoration: none;
  font-size: 13px;
  font-weight: bold;
}
.btn-icono-whatsapp:hover { background: #1ebe57; }
