: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; }
/* Desplegable "Administración" */
.topbar nav .dropdown { position: relative; }
.topbar nav .dropbtn {
  color: #d8e6f5; padding: 8px 14px; border-radius: 6px; font-weight: 500;
  cursor: pointer; display: inline-block; user-select: none;
}
.topbar nav .dropdown:hover .dropbtn { background: rgba(255,255,255,0.12); }
.topbar nav .dropbtn.active { background: var(--azul-claro); color: #fff; }
.topbar nav .dropdown-menu {
  display: none; position: absolute; top: 100%; left: 0; min-width: 180px;
  background: #fff; border-radius: 8px; box-shadow: var(--sombra);
  padding: 6px; z-index: 60;
}
.topbar nav .dropdown:hover .dropdown-menu { display: block; }
.topbar nav .dropdown-menu a {
  display: block; color: var(--azul); padding: 8px 12px; border-radius: 6px;
  font-weight: 500;
}
.topbar nav .dropdown-menu a:hover { background: var(--gris-fondo); text-decoration: none; }
.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;
}
/* Contenedor de nav + usuario (en escritorio ocupa el resto y empuja el usuario a la derecha) */
.topbar .nav-wrap { display: flex; align-items: center; gap: 24px; flex: 1; min-width: 0; }
/* Checkbox oculto pero funcional (truco hamburguesa, compatible con todo navegador) */
.topbar .nav-toggle { position: absolute; opacity: 0; width: 1px; height: 1px;
  margin: -1px; pointer-events: none; }
/* Botón hamburguesa: oculto en escritorio, visible en móvil */
.topbar .hamburger { display: none; }
.topbar .nav-backdrop { display: none; }

/* ---------- 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; }
/* Marca tenue "(filtrado)" cuando los KPIs reflejan filas filtradas */
.kpi-filtrado {
  font-size: 10px; font-weight: 600; text-transform: none; letter-spacing: 0;
  color: var(--naranja); font-style: italic; margin-left: 4px;
}
.kpi-filtrado[hidden] { display: none; }
/* Borde naranja en las tarjetas mientras hay filtro activo */
.kpis.filtrado .kpi { border-left-color: var(--naranja); }
@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; }

/* ---------- Personas que cobran: resaltado verde muy suave ---------- */
/* Fondo verde tenue + borde izquierdo verde, conviviendo con las bandas
   (nth-child even) y con el hover. Las reglas de banda/hover son más
   específicas o posteriores, así que repetimos aquí con la misma
   especificidad para que el verde gane sobre el blanco/azulado. */
#tablaPersonas tbody tr.row-cobra td { background: #eef9f1; }
#tablaPersonas tbody tr.row-cobra:nth-child(even) td { background: #e7f5ec; }
#tablaPersonas tbody tr.row-cobra td:first-child {
  box-shadow: inset 3px 0 0 var(--verde);
}
/* El hover sigue mandando también sobre las filas que cobran */
#tablaPersonas tbody tr.row-cobra:hover td { background: #def0e4; }

/* ---------- Badge "a punto de cobrar" (ámbar) ---------- */
.badge-apunto {
  display: inline-block;
  font-size: 10px; font-weight: 700;
  padding: 1px 7px; border-radius: 10px;
  text-transform: uppercase; letter-spacing: .3px;
  background: #fff4d6; color: #9a6b00;
  border: 1px solid #e8c766;
  vertical-align: middle; white-space: nowrap;
  margin-top: 2px;
}
/* En la columna de % la barra es block; el badge va debajo, centrado */
td.col-pct .badge-apunto { display: block; width: max-content; margin: 2px auto 0; }

/* Contador "N a punto" en ámbar, junto al contador de filas */
.count-pill.apunto { background: #D9A406; color: #3a2b00; }
.count-pill.apunto[hidden] { display: none; }

/* ---------- 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; }

/* ---------- Ranking UUIIs (dos columnas de rankings con barras) ---------- */
.rank-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}
@media (max-width: 900px) {
  .rank-grid { grid-template-columns: 1fr; }
}
.rank-col { min-width: 0; }
.rank-title {
  margin: 0 0 14px; font-size: 15px; font-weight: 700;
  padding-bottom: 8px; border-bottom: 2px solid var(--gris-fondo);
}
.rank-title.cel { color: var(--azul-claro); }
.rank-title.fus { color: var(--naranja); }
.rank-list { display: flex; flex-direction: column; gap: 8px; }
.rank-row {
  display: grid;
  grid-template-columns: 34px minmax(80px, 1.3fr) 2fr minmax(80px, auto);
  align-items: center;
  gap: 10px;
}
.rank-pos {
  font-size: 12px; font-weight: 700; color: var(--gris-texto);
  text-align: right; font-variant-numeric: tabular-nums;
}
.rank-name {
  font-size: 13px; font-weight: 600; color: #243240;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.rank-track {
  position: relative; height: 16px; border-radius: 4px;
  background: #eef2f6; overflow: hidden;
}
.rank-fill {
  position: absolute; left: 0; top: 0; bottom: 0;
  border-radius: 4px; opacity: .9; min-width: 2px;
}
.rank-val {
  font-size: 13px; font-weight: 700; color: var(--azul);
  text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums;
}
.rank-extra { font-size: 11px; font-weight: 600; color: var(--gris-texto); }
.rank-empty {
  color: #9aa7b2; font-size: 14px; padding: 24px; text-align: center;
}

/* ---------- 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; }

/* ============================================================
   MÓVIL / TABLET — menú hamburguesa y ajustes de pantalla pequeña
   ============================================================ */
@media (max-width: 860px) {
  .topbar { gap: 12px; padding: 0 14px; position: sticky; }
  .topbar .brand { font-size: 17px; flex: 1; min-width: 0; }

  /* Hamburguesa visible */
  .topbar .hamburger {
    display: flex; flex-direction: column; justify-content: center; gap: 5px;
    width: 44px; height: 44px; padding: 10px; cursor: pointer; flex: none;
    border-radius: 8px;
  }
  .topbar .hamburger span {
    display: block; height: 2px; width: 100%; background: #fff; border-radius: 2px;
    transition: transform .2s, opacity .2s;
  }
  .topbar .hamburger:hover { background: rgba(255,255,255,.12); }
  /* Animación a "X" cuando está abierto */
  .nav-toggle:checked ~ .hamburger span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
  .nav-toggle:checked ~ .hamburger span:nth-child(2) { opacity: 0; }
  .nav-toggle:checked ~ .hamburger span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

  /* Panel de navegación desplegable */
  .topbar .nav-wrap {
    position: absolute; top: 100%; left: 0; right: 0;
    flex-direction: column; align-items: stretch; gap: 0;
    background: var(--azul); box-shadow: var(--sombra);
    max-height: 0; overflow: hidden; transition: max-height .25s ease;
  }
  .nav-toggle:checked ~ .nav-wrap { max-height: calc(100vh - 60px); overflow-y: auto; }

  .topbar nav { flex-direction: column; align-items: stretch; gap: 2px; width: 100%; padding: 8px; }
  .topbar nav a, .topbar nav .dropbtn {
    display: block; padding: 13px 14px; font-size: 16px; border-radius: 8px;
  }
  /* El desplegable de Administración se muestra desplegado e indentado (sin hover) */
  .topbar nav .dropdown { position: static; }
  .topbar nav .dropdown-menu {
    display: block; position: static; background: rgba(255,255,255,.08);
    box-shadow: none; min-width: 0; padding: 2px 2px 2px 12px; margin: 2px 0;
  }
  .topbar nav .dropdown-menu a { color: #d8e6f5; }
  .topbar nav .dropbtn { color: #fff; opacity: .85; }

  .topbar .spacer { display: none; }
  .topbar .user {
    width: 100%; justify-content: flex-start; gap: 12px;
    padding: 12px 16px; border-top: 1px solid rgba(255,255,255,.18); font-size: 15px;
  }

  /* Fondo oscuro al abrir el menú */
  .nav-toggle:checked ~ .nav-backdrop {
    display: block; position: fixed; inset: 60px 0 0 0;
    background: rgba(0,0,0,.35); z-index: 40;
  }

  .container { padding: 14px; }
  .page-head h1 { font-size: 20px; }
  /* Las tablas anchas hacen scroll horizontal en su contenedor */
  .table-wrap, .table-scroll { -webkit-overflow-scrolling: touch; }
}

/* Red de seguridad: tablas sueltas (baremos, ayuda, desglose) hacen scroll
   horizontal ellas mismas en vez de desbordar la página. NO se aplica a las
   tablas .data dentro de .table-scroll/.table-wrap (que ya tienen cabecera fija). */
@media (max-width: 860px) {
  table.b, table.prima, table.primas, table.bd-table {
    display: block; overflow-x: auto; max-width: 100%;
    -webkit-overflow-scrolling: touch;
  }
  /* Evita scroll horizontal accidental de toda la web */
  html, body { overflow-x: hidden; }
  img, canvas, svg { max-width: 100%; }
}

@media (max-width: 620px) {
  /* La barra de herramientas se apila y los botones de exportar se envuelven */
  .toolbar { flex-direction: column; align-items: stretch; gap: 10px; }
  .toolbar form { flex-wrap: wrap; }
  .export-group {
    flex-wrap: wrap; padding-left: 0; border-left: none;
    padding-top: 10px; border-top: 1px solid var(--borde);
  }
  .export-group .btn { flex: 1 1 auto; text-align: center; }
}

@media (max-width: 520px) {
  .container { padding: 10px; }
  .panel { padding: 13px; }
  .page-head h1 { font-size: 18px; }
  .toolbar, .toolbar form, .table-controls { width: 100%; }
  select, input[type="text"], input[type="search"], input[type="password"] { width: 100%; }
  .toolbar form select { flex: 1 1 auto; }
  .table-controls .grow { flex: 1 1 100%; }
  .btn { padding: 11px 16px; }   /* objetivo táctil cómodo */
}
