/* ==========================================================================
   modules/talento-humano.css - Modulo: Talento Humano (Fase 3.x)
   Ficha/estado trabajador, foto, crear-editar, flujo persona->contrato,
   tabla personal, hijos, ausentismos, evaluaciones, nuevo ingreso guiado.
   Fase 1: movido TAL CUAL (orden preservado => cascada identica).
   OJO Fase 3: contiene la seccion "3.9 tablas/scroll GLOBAL" (reglas no-TH)
   pendiente de reclasificar a components/tables.css. Ver colisiones globales.
   ========================================================================== */
/* Colores propios de Talento Humano sin token oficial: valor claro (el de siempre) y su par
   para el modo oscuro. Van también en body porque los temas de usuario redefinen ahí
   --primary y --tqc-header. Todo lo demás del módulo usa los tokens de tokens.css. */
:root, body {
  --th-contrato: var(--primary);        /* tarjeta del contrato vigente con foto (texto blanco encima) */
  --th-titulo: var(--tqc-header);       /* títulos de los bloques de la ficha */
  --th-paso-hecho: #0f766e;             /* nuevo ingreso: título del paso terminado */
  --th-borde-fuerte: #b9c9df;           /* borde al pasar el puntero en botones de icono */
  --th-rojo-linea: #ffd6dc;             /* borde de botones de eliminar/quitar */
  --th-rojo-linea-2: #f8a9b7;           /* el mismo borde al pasar el puntero */
  --th-tenue: #94a3b8;                  /* subtítulos y textos muy apagados */
  --th-foco: #93c5fd;                   /* contorno de foco del teclado en las fichas de tipo */
  --th-ambar: #f59e0b;                  /* borde de "falta el soporte" */
  --th-aviso-linea: #f6d78a;            /* borde del aviso de salidas */
  --th-naranja-linea: #fdba74;          /* borde del aviso "el documento ya existe" */
}
:root[data-scheme="oscuro"],
:root[data-scheme="oscuro"] body {
  --th-contrato: #1b3d78;
  --th-titulo: var(--text);
  --th-paso-hecho: #4fd1bf;
  --th-borde-fuerte: #4a5b7e;
  --th-rojo-linea: #5c2a31;
  --th-rojo-linea-2: #8a3a46;
  --th-tenue: #8796b0;
  --th-foco: #4f86d9;
  --th-ambar: #c98a1f;
  --th-aviso-linea: #5e4b1c;
  --th-naranja-linea: #7a4a22;
}

/* ===== Ajustes Fase 3.1: estado completo y foto del trabajador ===== */
.status {
  white-space: nowrap;
  word-break: keep-all;
  overflow-wrap: normal;
  flex-shrink: 0;
}

.profile-header-with-photo {
  align-items: stretch;
}
.profile-main {
  flex: 1 1 auto;
  min-width: 0;
}
.profile-side {
  display: grid;
  grid-template-columns: 210px minmax(250px, 320px);
  gap: 16px;
  align-items: stretch;
}
.photo-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  padding: 14px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.photo-frame {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--soft-blue);
  border: 1px solid var(--card-line);
}
.photo-frame img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.photo-placeholder {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--soft-blue) 0%, var(--sem-azul-bg) 100%);
  color: var(--primary);
  font-weight: 700;
  font-size: 64px;
}
.photo-form {
  display: grid;
  gap: 8px;
}
.photo-form label {
  font-size: var(--text-xs);
  font-weight: 800;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.photo-form input[type="file"] {
  padding: 9px;
  font-size: var(--text-xs);
}
.photo-form button {
  width: 100%;
}
.photo-note {
  margin: 0;
  font-size: var(--text-xs);
  text-align: center;
}

@media (max-width: 1100px) {
  .profile-side {
    grid-template-columns: 190px minmax(230px, 1fr);
  }
}
@media (max-width: 900px) {
  .profile-side {
    width: 100%;
    grid-template-columns: 1fr;
  }
  .photo-card {
    max-width: 260px;
  }
}

/* ===== Ajuste Fase 3.2: foto integrada al contrato y sin carga en ficha ===== */
.profile-side {
  display: block;
  min-width: min(100%, 430px);
}
.current-contract.current-contract-with-photo {
  min-width: 410px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 150px;
  gap: 16px;
  align-items: center;
  padding: 16px;
  background: linear-gradient(135deg, var(--th-contrato) 0%, var(--tqc-header) 100%);
  overflow: hidden;
}
.current-contract-info {
  min-width: 0;
}
.current-contract-with-photo span {
  font-size: var(--text-xs);
  font-weight: 800;
  letter-spacing: .03em;
  text-transform: uppercase;
}
.current-contract-with-photo strong {
  font-size: var(--text-2xl);
  line-height: 1.05;
  margin: 7px 0 6px;
  overflow-wrap: anywhere;
}
.current-contract-with-photo small {
  font-size: var(--text-xs);
  line-height: 1.3;
  opacity: .88;
}
.current-contract-with-photo .contract-state {
  display: inline-flex;
  width: fit-content;
  margin-top: 8px;
  padding: 5px 9px;
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, .14);
  color: #ffffff;
  font-weight: 700;
  letter-spacing: .03em;
  opacity: 1;
}
.current-contract-photo {
  width: 150px;
  height: 190px;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: rgba(255, 255, 255, .14);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .22);
}
.current-contract-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.photo-placeholder.compact {
  height: 100%;
  font-size: 62px;
  background: linear-gradient(135deg, color-mix(in srgb, var(--card) 90%, transparent) 0%, color-mix(in srgb, var(--soft-blue) 92%, transparent) 100%);
}

@media (max-width: 900px) {
  .profile-side { width: 100%; min-width: 0; }
  .current-contract.current-contract-with-photo {
    min-width: 0;
    width: 100%;
    grid-template-columns: minmax(0, 1fr) 120px;
  }
  .current-contract-photo {
    width: 120px;
    height: 155px;
  }
}
@media (max-width: 520px) {
  .current-contract.current-contract-with-photo {
    grid-template-columns: 1fr;
  }
  .current-contract-photo {
    width: 100%;
    max-width: 210px;
    height: 230px;
    justify-self: center;
  }
}

/* ===== Fase 3.3: módulo crear / editar trabajador ===== */
.action-heading {
  align-items: center;
}
.personal-heading-side {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}
.personal-counter {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}
.personal-counter span {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--card);
  color: var(--muted);
  font-size: var(--text-xs);
  font-weight: 700;
  white-space: nowrap;
}
.personal-counter strong {
  color: var(--primary);
  font-size: var(--text-md);
  font-variant-numeric: tabular-nums;
}
.hero-actions,
.profile-actions,
.action-cell {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.person-form {
  display: grid;
  gap: 16px;
}
.form-layout {
  display: grid;
  grid-template-columns: minmax(230px, 300px) minmax(0, 1fr);
  gap: 16px;
  align-items: stretch;
}
.form-section-grid {
  align-items: start;
}
.form-photo-card,
.form-card {
  min-width: 0;
}
.form-photo-preview {
  width: 100%;
  aspect-ratio: 4 / 5;
  border-radius: var(--radius-xl);
  overflow: hidden;
  background: var(--soft-blue);
  border: 1px solid var(--line);
  margin-bottom: 14px;
}
.form-photo-preview img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}
.th-form-compact.form-grid { align-items: start; gap: var(--space-3); }
.th-form-compact .checkbox-field { display: block; }
.th-vacacion-grid [data-field="contrato"],
.th-vacacion-grid [data-field="observaciones"],
.th-vacacion-grid [data-field="soporte"],
.th-vacacion-grid [data-field="soporte_url"] { grid-column: 1 / -1; }
.th-vacacion-grid [data-field="periodo_inicial"],
.th-vacacion-grid [data-field="fecha_inicio_vacaciones"] { grid-column: 1; }

.form-actions-sticky {
  position: sticky;
  bottom: 0;
  z-index: 8;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}
@media (max-width: 980px) {
  .form-layout,
  .grid-2.form-section-grid {
    grid-template-columns: 1fr;
  }
  .form-photo-card {
    max-width: 360px;
  }
}
@media (max-width: 620px) {
  .form-actions-sticky {
    flex-direction: column-reverse;
  }
  .form-actions-sticky button,
  .form-actions-sticky a {
    width: 100%;
    text-align: center;
  }
}

/* ===== Fase 3.5: flujo persona -> contrato y alineación de botones ===== */
.profile-actions,
.hero-actions,
.action-cell,
.form-actions-sticky-flow,
.section-title-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.profile-actions-single {
  margin-top: 16px;
  flex-wrap: nowrap;
}
.action-cell {
  flex-wrap: nowrap;
  min-width: max-content;
}
.action-cell .btn,
.section-title-actions .btn,
.profile-actions .btn {
  white-space: nowrap;
  flex: 0 0 auto;
}
.form-actions-sticky-flow {
  flex-wrap: wrap;
}
.section-title-actions {
  justify-content: space-between;
  flex-wrap: wrap;
}
@media (max-width: 620px) {
  .action-cell {
    flex-wrap: wrap;
    min-width: 0;
  }
}

/* ===== Fase 3.6: tabla personal y panel contratos próximos ===== */
.nowrap,
.doc-cell,
td.nowrap,
th.nowrap {
  white-space: nowrap !important;
  word-break: keep-all !important;
  overflow-wrap: normal !important;
}

/* Evita cortes feos en documento, estado y nombres de entidades */
.doc-cell,
.nowrap,
td.nowrap,
th.nowrap,
td[class*="estado"],
th[class*="estado"] {
  white-space: nowrap !important;
  word-break: keep-all !important;
}

/* ===== Ajuste flujo contrato -> seguridad social y checkbox alineado ===== */
.form-actions-flow {
  gap: 10px;
  flex-wrap: wrap;
}
.seguridad-social-form .checkbox-field {
  align-self: center;
}

/* ===== Fase 3.10: nuevo ingreso guiado ===== */
.heading-actions,
.hero-actions,
.wizard-inline-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.wizard-progress {
  display: grid;
  grid-template-columns: minmax(170px, 1fr) 44px minmax(170px, 1fr) 44px minmax(170px, 1fr) 44px minmax(190px, 1fr);
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
}

.wizard-step {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.wizard-step > span {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-pill);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: var(--primary);
  background: var(--sem-gris-bg);
  border: 1px solid var(--line);
  flex: 0 0 auto;
}

.wizard-step strong,
.wizard-step small {
  display: block;
  white-space: nowrap;
}

.wizard-step small {
  color: var(--muted);
  margin-top: 2px;
}

.wizard-step.active > span,
.wizard-step.done > span {
  background: var(--tqc-yellow);
  border-color: var(--tqc-yellow);
  color: var(--tqc-header);
}

.wizard-step.done strong {
  color: var(--th-paso-hecho);
}

.wizard-step.locked {
  opacity: .58;
}

.wizard-line {
  height: 3px;
  border-radius: var(--radius-pill);
  background: linear-gradient(90deg, var(--line), var(--line-2));
}

.wizard-section {
  margin-bottom: 18px;
  border-left: 5px solid transparent;
}

.wizard-section.current {
  border-left-color: var(--tqc-yellow);
}

.wizard-section.completed {
  border-left-color: #22c55e;
}

.locked-section {
  opacity: .74;
}

.wizard-summary-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(140px, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.wizard-summary-grid > div {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 12px;
  min-width: 0;
}

.wizard-summary-grid small {
  display: block;
  color: var(--muted);
  font-weight: 700;
  margin-bottom: 4px;
}

.wizard-summary-grid strong {
  display: block;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.wizard-form {
  margin-top: 14px;
}

.wizard-person-layout {
  align-items: stretch;
  gap: 18px;
}

.wizard-photo-card,
.inner-form-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: none;
}

.wizard-fields-stack {
  display: grid;
  gap: 16px;
  min-width: 0;
}

.wizard-subgrid {
  margin-top: 16px;
}

.wizard-section .form-actions-sticky {
  position: sticky;
  bottom: 12px;
  margin-top: 16px;
  z-index: 3;
}

@media (max-width: 980px) {
  .wizard-progress {
    grid-template-columns: 1fr;
  }
  .wizard-line {
    display: none;
  }
  .wizard-summary-grid {
    grid-template-columns: repeat(2, minmax(140px, 1fr));
  }
}

@media (max-width: 640px) {
  .wizard-summary-grid {
    grid-template-columns: 1fr;
  }
  .wizard-step strong,
  .wizard-step small {
    white-space: normal;
  }
}

.wizard-progress-4 {
  grid-template-columns: minmax(170px, 1fr) 44px minmax(170px, 1fr) 44px minmax(170px, 1fr) 44px minmax(190px, 1fr);
}

.wizard-child-table {
  margin-top: 12px;
  margin-bottom: 16px;
}

.hijo-form .form-actions-flow {
  flex-wrap: wrap;
}

.hijo-form .form-actions-flow button {
  white-space: nowrap;
}

/* ===== Ajuste Fase 3: gestión individual de hijos y tablas más anchas ===== */
.container {
  max-width: 1500px;
}

.section-title-actions {
  flex-wrap: wrap;
}

/* Ajustes fase Beneficios */
.wizard-progress-5 {
  grid-template-columns: minmax(150px, 1fr) 34px minmax(140px, 1fr) 34px minmax(150px, 1fr) 34px minmax(170px, 1fr) 34px minmax(150px, 1fr);
}

.wizard-benefit-table {
  margin-top: 12px;
  margin-bottom: 16px;
}

.beneficio-form .form-actions-flow {
  flex-wrap: wrap;
}

.beneficio-form .form-actions-flow button,
.beneficio-form .form-actions-flow a {
  white-space: nowrap;
}

@media (max-width: 1100px) {
  .wizard-progress-5 {
    grid-template-columns: 1fr;
  }
}

/* Control visual para soportes: archivo local + enlace externo */
.support-links, td .btn-sm + .btn-sm {
  margin-left: 0.35rem;
}
.form-card input[type="url"] {
  min-width: 0;
}

/* Reportes */
.report-header {
  align-items: flex-start;
}

.report-header-actions {
  width: 100%;
  justify-content: flex-start;
  flex-wrap: wrap;
}

.report-result-card {
  /* La tabla vive contenida dentro de la tarjeta (no se sale de los bordes). */
  overflow: hidden;
}

.empty-state {
  padding: 22px;
  border: 1px dashed var(--line-2);
  border-radius: var(--radius-md);
  background: var(--surface-2);
}

/* Componentes comunes usados por reportes */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  background: linear-gradient(135deg, var(--card) 0%, var(--soft-blue) 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius-2xl);
  padding: 26px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}

/* Encabezados operativos: mantienen el contexto sin desplazar el trabajo. */
.hero,
.page-heading,
.profile-header,
.page-header {
  min-height: 0;
  padding: 14px 18px;
  border-radius: var(--radius-lg);
  margin-bottom: 14px;
}

.hero h1,
.page-heading h1,
.profile-header h1,
.page-header h1 {
  font-size: clamp(20px, 2vw, 28px);
  line-height: 1.15;
}

.hero p,
.page-heading p,
.profile-header p,
.page-header p {
  margin: 4px 0 0;
  font-size: var(--text-sm);
  line-height: 1.35;
}

.actions-row {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.muted { color: var(--muted); }

.section-title-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  margin-bottom: 14px;
}

.filters-grid {
  display: grid;
  gap: 12px;
}

.filters-grid label {
  color: var(--muted);
  font-size: var(--text-xs);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.filters-grid input,
.filters-grid select {
  margin-top: 6px;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 600;
}

@media (max-width: 900px) {
  .page-header {
    flex-direction: column;
    align-items: flex-start;
  }
  .actions-row {
    justify-content: flex-start;
  }
}

.audit-table .audit-description {
  min-width: 420px;
  max-width: 780px;
  white-space: normal;
  overflow-wrap: anywhere;
}

.usuarios-actions-cell {
  width: 92px;
}

.usuarios-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.usuarios-actions form {
  display: inline-flex;
  margin: 0;
}

.usuario-icon-action {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--card-line);
  background: var(--surface-2);
  color: var(--primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
  text-decoration: none;
}

.usuario-icon-action svg {
  width: 17px;
  height: 17px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.usuario-icon-action:hover {
  background: var(--row-hover);
  border-color: var(--th-borde-fuerte);
}

.usuario-delete-action {
  color: var(--danger);
  background: var(--danger-bg);
  border-color: var(--th-rojo-linea);
}

.usuario-delete-action:hover {
  background: var(--sem-rojo-bg);
  border-color: var(--th-rojo-linea-2);
}

.roles-permission-matrix,
.role-assignment-matrix {
  display: grid;
  grid-template-columns: minmax(150px, 1.1fr) repeat(5, minmax(86px, .7fr));
  align-items: stretch;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--card);
}

.role-matrix-head,
.role-assignment-head {
  padding: 9px 10px;
  background: var(--surface-3);
  border-bottom: 1px solid var(--line);
  color: var(--primary);
  font-size: var(--text-xs);
  font-weight: 700;
  line-height: 1.15;
}

.role-process-row,
.role-assignment-process,
.role-level-cell,
.role-assignment-cell {
  min-height: 40px;
  border-bottom: 1px solid var(--row-line);
  padding: 7px 10px;
  display: flex;
  align-items: center;
}

.role-process-row,
.role-assignment-process {
  background: var(--row-alt);
}

.role-process-row strong,
.role-assignment-process strong {
  font-size: var(--text-xs);
  line-height: 1.2;
}

.role-level-cell,
.role-assignment-cell {
  justify-content: center;
  border-left: 1px solid var(--row-line);
}

.role-assignment-cell {
  gap: 6px;
  cursor: pointer;
  font-size: var(--text-2xs);
  font-weight: 700;
  color: var(--primary);
}

.role-assignment-cell input {
  width: 16px;
  height: 16px;
  margin: 0;
}

@media (max-width: 900px) {
  .roles-permission-matrix,
  .role-assignment-matrix {
    grid-template-columns: minmax(130px, 1fr) repeat(5, minmax(74px, .7fr));
    overflow-x: auto;
  }
}

@media (max-width: 620px) {
  .roles-permission-matrix,
  .role-assignment-matrix {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }
}

.usuario-form-card .form-grid {
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.permissions-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin: 18px 0;
  padding: 14px;
  border-radius: var(--radius-lg);
  background: var(--surface-2);
  border: 1px solid var(--line);
}

.nice-check-row {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  line-height: 1;
  font-weight: 700;
}

.nice-check-row input {
  width: 18px;
  height: 18px;
  margin: 0;
}

.roles-selector {
  margin-top: 18px;
  border-top: 1px solid var(--line);
  padding-top: 18px;
}

.roles-category-stack {
  display: grid;
  gap: 16px;
  margin-top: 14px;
}

.roles-category {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 14px;
  background: var(--surface-2);
}

.roles-category h3 {
  margin: 0;
  font-size: var(--text-md);
  color: var(--primary);
}

.roles-checkbox-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.role-check {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  background: var(--card);
  font-weight: 700;
}

.role-check input {
  width: 18px;
  height: 18px;
  margin: 0;
}

.error-card {
  border-left: 5px solid var(--danger);
}

.error-card ul {
  margin-bottom: 0;
}

/* Atajos de plazo de la prórroga (3, 6, 12 meses) bajo la nueva fecha de terminación. */
.plazo-rapido { display: flex; gap: .3rem; margin-top: .35rem; }
