:root {
  --azul: #1F4E78;
  --azul-claro: #2E75B6;
  --naranja: #ED7D31;
  --verde: #2E9E5B;
  --gris-fondo: #F4F6F8;
  --gris-texto: #5b6770;
  --borde: #d9dee3;
  --sombra: 0 2px 8px rgba(31, 78, 120, 0.10);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--gris-fondo);
  color: #243240;
  font-size: 15px;
}

a { color: var(--azul-claro); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Cabecera ---------- */
.topbar {
  background: var(--azul);
  color: #fff;
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 24px;
  height: 60px;
  box-shadow: var(--sombra);
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar .brand {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.3px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.topbar .brand .dot {
  width: 12px; height: 12px; border-radius: 3px;
  background: var(--naranja);
  display: inline-block;
}
.topbar nav { display: flex; gap: 6px; }
.topbar nav a {
  color: #d8e6f5;
  padding: 8px 14px;
  border-radius: 6px;
  font-weight: 500;
}
.topbar nav a:hover { background: rgba(255,255,255,0.12); text-decoration: none; }
.topbar nav a.active { background: var(--azul-claro); color: #fff; }
.topbar .spacer { flex: 1; }
.topbar .user {
  display: flex; align-items: center; gap: 12px;
  font-size: 14px;
}
.topbar .user .uname { font-weight: 600; }
.topbar .user .role {
  font-size: 11px; text-transform: uppercase; letter-spacing: .5px;
  background: rgba(255,255,255,0.18); padding: 2px 8px; border-radius: 10px;
}

/* ---------- Botones ---------- */
.btn {
  display: inline-block;
  background: var(--naranja);
  color: #fff;
  border: none;
  padding: 9px 16px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.btn:hover { background: #d96e25; text-decoration: none; color: #fff; }
.btn.secondary { background: var(--azul-claro); }
.btn.secondary:hover { background: #256099; }
.btn.ghost {
  background: transparent; color: #fff; border: 1px solid rgba(255,255,255,.5);
}
.btn.ghost:hover { background: rgba(255,255,255,0.12); }
.btn.small { padding: 6px 12px; font-size: 13px; }

/* ---------- Layout ---------- */
.container { max-width: min(1760px, 96vw); margin: 0 auto; padding: 24px; }

.page-head {
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
  margin-bottom: 20px;
}
.page-head h1 { margin: 0; font-size: 24px; color: var(--azul); }
.page-head .spacer { flex: 1; }

.toolbar { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.toolbar label { font-size: 13px; color: var(--gris-texto); font-weight: 600; }
.toolbar form { display: flex; align-items: center; gap: 8px; margin: 0; }
/* Grupo de exportación con separador visual del selector de mes */
.export-group {
  display: flex; align-items: center; gap: 8px;
  padding-left: 14px; border-left: 1px solid var(--borde);
}
.export-group .lbl { font-size: 12px; color: var(--gris-texto); font-weight: 600; }
/* Nota "vs <mes anterior>" junto al selector de mes (base de las flechas) */
.cmp-note {
  font-size: 12px; color: var(--gris-texto); font-weight: 600;
  background: var(--gris-fondo); border: 1px solid var(--borde);
  padding: 4px 10px; border-radius: 12px; white-space: nowrap;
}
select, input[type="text"], input[type="search"], input[type="password"], input[type="file"] {
  padding: 8px 10px;
  border: 1px solid var(--borde);
  border-radius: 6px;
  font-size: 14px;
  background: #fff;
}
select:focus, input:focus { outline: 2px solid var(--azul-claro); outline-offset: -1px; }

/* ---------- Tarjetas KPI (compactas, una sola fila) ---------- */
.kpis {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}
.kpi {
  background: #fff;
  border-radius: 10px;
  padding: 12px 14px;
  box-shadow: var(--sombra);
  border-left: 4px solid var(--azul-claro);
}
.kpi.accent { border-left-color: var(--naranja); }
.kpi.green { border-left-color: var(--verde); }
.kpi .label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--gris-texto); font-weight: 600;
}
.kpi .value { font-size: 24px; font-weight: 700; color: var(--azul); margin-top: 2px; line-height: 1.1; }
.kpi .sub { font-size: 11px; color: var(--gris-texto); margin-top: 2px; }
@media (max-width: 980px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 520px) {
  .kpis { grid-template-columns: 1fr; }
}

/* ---------- Paneles / gráficos ---------- */
.panel {
  background: #fff;
  border-radius: 10px;
  box-shadow: var(--sombra);
  padding: 18px;
  margin-bottom: 22px;
}
.panel h2 {
  margin: 0 0 14px; font-size: 16px; color: var(--azul);
  border-bottom: 2px solid var(--gris-fondo); padding-bottom: 8px;
}
.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 22px;
}
.chart-box { background: #fff; border-radius: 10px; box-shadow: var(--sombra); padding: 18px; }
.chart-box h2 { margin: 0 0 12px; font-size: 15px; color: var(--azul); }
.chart-wrap { position: relative; height: 280px; }

/* ---------- Sección de gráficos colapsable (secundaria) ---------- */
.charts-section {
  background: #fff;
  border-radius: 10px;
  box-shadow: var(--sombra);
  margin-bottom: 16px;
  overflow: hidden;
}
.charts-section > summary {
  list-style: none;
  cursor: pointer;
  padding: 12px 18px;
  font-size: 15px; font-weight: 600; color: var(--azul);
  display: flex; align-items: center; gap: 10px;
  user-select: none;
}
.charts-section > summary::-webkit-details-marker { display: none; }
.charts-section > summary::before {
  content: "▸";
  font-size: 13px; color: var(--naranja);
  transition: transform .15s;
}
.charts-section[open] > summary::before { transform: rotate(90deg); }
.charts-section > summary:hover { background: var(--gris-fondo); }
.charts-section .charts-body { padding: 0 18px 18px; }
/* En la sección secundaria los gráficos son más bajos para no robar espacio */
.charts-section .chart-wrap { height: 200px; }
.charts-section .charts-row {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr;
  gap: 18px;
  align-items: start;
}
.charts-section .charts-row > div h3 {
  margin: 0 0 8px; font-size: 13px; color: var(--azul); font-weight: 600;
}
@media (max-width: 900px) {
  .charts-section .charts-row { grid-template-columns: 1fr; }
}

/* ---------- Subida (admin) ---------- */
.upload-panel { border-left: 4px solid var(--naranja); }
.upload-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin-bottom: 14px;
}
.upload-field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; color: var(--gris-texto); }
.upload-field input[type=file] { width: 100%; }

/* ---------- Tabla ---------- */
.table-controls {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
  margin-bottom: 14px;
  background: var(--gris-fondo);
  border: 1px solid var(--borde);
  border-radius: 8px;
  padding: 10px 12px;
}
.table-controls .grow { flex: 1 1 240px; min-width: 200px; }
.table-controls .chk {
  display: flex; align-items: center; gap: 6px; font-size: 14px;
  white-space: nowrap; cursor: pointer;
}
.table-controls .sep { flex: 1; }   /* empuja el contador al extremo */
.count-pill {
  font-size: 13px; color: #fff; font-weight: 700;
  background: var(--azul-claro); padding: 4px 12px; border-radius: 12px;
  white-space: nowrap;
}
/* Botón para limpiar todos los filtros */
.btn-clear {
  background: #fff; color: var(--gris-texto);
  border: 1px solid var(--borde); border-radius: 6px;
  padding: 7px 12px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.btn-clear:hover { background: #fff0e8; color: var(--naranja); border-color: var(--naranja); }

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

/* Contenedor de la tabla con scroll vertical propio: el thead sticky
   se ancla al borde superior de ESTE contenedor, no de la página, así
   nunca se solapa con las tarjetas ni con la barra superior. */
.table-scroll {
  max-height: 62vh;
  overflow: auto;
  border: 1px solid var(--borde);
  border-radius: 8px;
}
table.data {
  width: 100%;
  border-collapse: separate;   /* separate => sticky th no deja huecos */
  border-spacing: 0;
  font-size: 14px;
}
/* Solo las tablas con <colgroup> usan anchos fijos para que la cabecera
   quede perfectamente alineada con sus celdas. */
#tablaPersonas, #tablaEquipos, #tablaCoord, #tablaCeladores { table-layout: fixed; }
#tablaPersonas th, #tablaPersonas td,
#tablaEquipos th, #tablaEquipos td,
#tablaCoord th, #tablaCoord td,
#tablaCeladores th, #tablaCeladores td {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
table.data thead th {
  background: var(--azul);      /* fondo SÓLIDO opaco (no transparente) */
  color: #fff;
  text-align: left;
  padding: 10px 12px;
  font-weight: 600;
  position: sticky;
  top: 0;                       /* relativo al .table-scroll */
  z-index: 5;                   /* por encima de las filas al hacer scroll */
  cursor: pointer;
  white-space: nowrap;
  box-shadow: inset 0 -1px 0 rgba(255,255,255,.15);
}
table.data thead th:hover { background: var(--azul-claro); }
/* Indicador de orden activo */
table.data thead th.sorted-asc::after  { content: " ▲"; font-size: 10px; opacity: .9; }
table.data thead th.sorted-desc::after { content: " ▼"; font-size: 10px; opacity: .9; }
/* Las columnas numéricas alinean cabecera Y celda a la derecha por igual */
table.data thead th.num { text-align: right; }
table.data tbody td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--borde);
  background: #fff;            /* opaco para que el sticky no transparente */
  vertical-align: middle;
}
table.data tbody tr:nth-child(even) td { background: #f7fafd; }
table.data tbody tr:hover td { background: #eaf2fb; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---- Anchos de columna tabla PERSONAS (suman 100%) ---- */
#tablaPersonas col.c-id     { width: 4%;  }
#tablaPersonas col.c-nombre { width: 15%; }
#tablaPersonas col.c-equipo { width: 6%;  }
#tablaPersonas col.c-perfil { width: 12%; }
#tablaPersonas col.c-prov   { width: 9%;  }
#tablaPersonas col.c-resp   { width: 14%; }
#tablaPersonas col.c-dias   { width: 5%;  }
#tablaPersonas col.c-pct    { width: 11%; }
#tablaPersonas col.c-grat   { width: 8%;  }
#tablaPersonas col.c-nota   { width: 16%; }

/* La columna Nota muestra el texto COMPLETO (puede ocupar 2 líneas) */
#tablaPersonas td.nota-cell {
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
  line-height: 1.25;
}

/* ---- Anchos de columna tabla EQUIPOS ---- */
#tablaEquipos col.c-equipo { width: 44%; }
#tablaEquipos col.c-tipo   { width: 28%; }
#tablaEquipos col.c-dias   { width: 12%; }
#tablaEquipos col.c-pct    { width: 16%; }

/* ---- Anchos de columna tabla COORDINADORES ---- */
#tablaCoord col.c-coord { width: 28%; }
#tablaCoord col.c-np    { width: 13%; }
#tablaCoord col.c-ne    { width: 13%; }
#tablaCoord col.c-pct   { width: 16%; }
#tablaCoord col.c-cob   { width: 13%; }
#tablaCoord col.c-imp   { width: 17%; }

/* ---- Anchos de columna tabla CELADORES (suman 100%) ---- */
#tablaCeladores col.c-equipo { width: 22%; }
#tablaCeladores col.c-m      { width: 8.5%; }   /* 7 métricas en metros */
#tablaCeladores col.c-dias   { width: 7%; }
#tablaCeladores col.c-pct    { width: 11.5%; }

/* ---- Tabla FUSIONADORES: muchas columnas -> ancho mínimo + scroll horizontal ---- */
/* No usa table-layout: fixed; deja que el navegador dimensione y que el
   contenedor .table-scroll aporte el scroll horizontal cuando no quepa. */
#tablaFusionadores { min-width: 1180px; }
#tablaFusionadores th, #tablaFusionadores td { white-space: nowrap; }

/* La columna de % no debe descuadrarse: la barra ocupa el ancho útil
   y va alineada a la derecha como el resto de columnas numéricas. */
td.col-pct { text-align: right; }

/* ---------- Indicadores de tendencia (vs mes anterior) ---------- */
.trend {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
  margin-left: 4px;
  vertical-align: middle;
  font-variant-numeric: tabular-nums;
}
.trend.up   { color: #2E9E5B; }   /* sube  - verde */
.trend.down { color: #c0392b; }   /* baja  - rojo  */
.trend.eq   { color: #9aa7b2; }   /* igual - gris  */
/* En la columna % la barra es block: el delta va debajo, centrado */
td.col-pct .trend { display: block; margin-left: 0; margin-top: 2px; text-align: center; }

/* ---------- Filas de personas clicables (-> ficha) ---------- */
#tablaPersonas tbody tr.row-link { cursor: pointer; }

/* ---------- Pestañas (Personas / Equipos) ---------- */
.tabs {
  display: flex; gap: 4px;
  border-bottom: 2px solid var(--gris-fondo);
  margin-bottom: 16px;
}
.tabs .tab {
  background: transparent; border: none;
  padding: 10px 18px; font-size: 15px; font-weight: 600;
  color: var(--gris-texto); cursor: pointer;
  border-bottom: 3px solid transparent; margin-bottom: -2px;
  border-radius: 6px 6px 0 0;
}
.tabs .tab:hover { background: var(--gris-fondo); }
.tabs .tab.active { color: var(--azul); border-bottom-color: var(--naranja); }
.tab-pane[hidden] { display: none; }

/* ---------- Badges por subtipo / perfil ---------- */
.badge {
  display: inline-block; font-size: 10px; font-weight: 700;
  padding: 2px 7px; border-radius: 6px;
  text-transform: uppercase; letter-spacing: .3px;
  vertical-align: middle;
  white-space: nowrap;
}
.badge.rd    { background: #e3eefb; color: #1F4E78; }   /* RD            - azul    */
.badge.ra    { background: #fdebdd; color: #c2641f; }   /* RA            - naranja */
.badge.mant  { background: #e4f6ea; color: #1d7a45; }   /* Mantenimiento - verde   */
.badge.perm  { background: #f3e8fb; color: #7a3aa6; }   /* Permisos      - morado  */
.badge.fase2 { background: #fff4d6; color: #9a6b00; }   /* Fase 2        - ámbar   */
.badge.coord { background: #e6e9ef; color: #3a4a5e; }   /* Coordinador   - gris azulado */
.badge.otro  { background: #eef0f2; color: var(--gris-texto); }
/* El perfil se muestra como SOLO badge: texto completo dentro del badge */
.perfil-cell {
  display: inline-flex; align-items: center; gap: 6px;
  min-width: 0;
}
.perfil-cell .perfil-txt {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.nota-cell { color: var(--gris-texto); font-size: 13px; }

/* Barra de % — ocupa el ancho útil de su columna y queda cuadrada */
.pctbar {
  position: relative;
  display: inline-block;
  background: #eef2f6;
  border-radius: 4px;
  height: 18px;
  width: 100%;
  max-width: 130px;
  overflow: hidden;
  vertical-align: middle;
  text-align: left;
}
.pctbar > span.fill {
  position: absolute; left: 0; top: 0; bottom: 0;
  border-radius: 4px;
}
.pctbar .lbl {
  position: relative; z-index: 1;
  font-size: 12px; font-weight: 600; color: #1c2b38;
  display: block; text-align: center; line-height: 18px;
  font-variant-numeric: tabular-nums;
}

.grat-400 { color: var(--verde); font-weight: 700; }
.grat-var { color: var(--gris-texto); font-style: italic; }
.grat-zero { color: #b3bcc4; }

.tag {
  display: inline-block; font-size: 12px; font-weight: 600;
  padding: 2px 8px; border-radius: 10px;
}
.tag.cel { background: #e3eefb; color: var(--azul); }
.tag.fus { background: #fdebdd; color: #c2641f; }
.tag.none { background: #eef0f2; color: var(--gris-texto); }

/* ---------- Estado vacío ---------- */
.empty {
  background: #fff;
  border-radius: 12px;
  box-shadow: var(--sombra);
  padding: 60px 30px;
  text-align: center;
  border: 2px dashed var(--borde);
}
.empty .icon { font-size: 48px; }
.empty h2 { color: var(--azul); margin: 12px 0 8px; }
.empty p { color: var(--gris-texto); max-width: 480px; margin: 0 auto 20px; }

/* ---------- Login ---------- */
.login-bg {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #1F4E78 0%, #2E75B6 100%);
  padding: 20px;
}
.login-card {
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0,0,0,.25);
  width: 100%; max-width: 380px;
  padding: 34px 32px;
}
.login-card .brand {
  text-align: center; margin-bottom: 22px;
}
.login-card .brand .dot {
  width: 16px; height: 16px; border-radius: 4px; background: var(--naranja);
  display: inline-block; margin-right: 8px; vertical-align: middle;
}
.login-card .brand h1 { display: inline; font-size: 22px; color: var(--azul); }
.login-card label { display: block; font-size: 13px; font-weight: 600; margin: 12px 0 5px; color: var(--gris-texto); }
.login-card input { width: 100%; }
.login-card .btn { width: 100%; margin-top: 20px; padding: 11px; }
.login-error {
  background: #fdecea; color: #b3261e; border: 1px solid #f5c6c2;
  padding: 10px 12px; border-radius: 6px; font-size: 14px; margin-bottom: 6px;
}

.section-title { margin: 8px 0 14px; color: var(--azul); font-size: 18px; }

@media (max-width: 640px) {
  .topbar { gap: 12px; padding: 0 14px; }
  .topbar .brand { font-size: 16px; }
  .container { padding: 14px; }
}
