/* =========================================================
   Módulo Prestaciones — capa de presentación profesional.
   Refina sobre el framework del sistema (Bootstrap 4 + wirevet-layout)
   sin tocar markup ni JS: todo scopeado a #pantalla_prestaciones /
   #modal_prestaciones. Dirección: refinamiento clínico (acento verde
   veterinario del sistema, profundidad sutil, micro-interacciones).
   ========================================================= */

/* ---- Tokens del módulo (scopeados) ---- */
#pantalla_prestaciones,
#modal_prestaciones {
  --pres-ink: #1f2a33;
  --pres-muted: #7b8794;
  --pres-accent: #21955a;
  --pres-accent-2: #28a745;
  --pres-accent-soft: rgba(40, 167, 69, 0.10);
  --pres-accent-ring: rgba(40, 167, 69, 0.22);
  --pres-line: #eef1f4;
  --pres-line-2: #e6eaee;
  --pres-shadow-sm: 0 1px 2px rgba(16, 38, 27, 0.06);
  --pres-shadow-md: 0 8px 24px rgba(16, 38, 27, 0.10);
  --pres-radius: 14px;
}

/* =========================================================
   1. Encabezado del módulo
   ========================================================= */
#pantalla_prestaciones .wirevet-layout {
  position: relative;
  border: 1px solid var(--pres-line);
}

#pantalla_prestaciones > .wirevet-layout:first-child h5 {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--pres-ink);
}

/* Ícono del header convertido en "chip" con acento */
#pantalla_prestaciones > .wirevet-layout:first-child h5 > i {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  font-size: 17px;
  color: var(--pres-accent);
  background: var(--pres-accent-soft);
  border-radius: 11px;
  box-shadow: inset 0 0 0 1px rgba(40, 167, 69, 0.16);
}

#pantalla_prestaciones > .wirevet-layout:first-child p.text-muted {
  font-size: 0.86rem;
  line-height: 1.45;
  max-width: 60ch;
}

#pantalla_prestaciones > .wirevet-layout:first-child p.text-muted strong {
  color: var(--pres-ink);
  font-weight: 600;
}

/* =========================================================
   1b. Tarjetas de estadísticas
   ========================================================= */
.pres-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(165px, 1fr));
  gap: 14px;
  margin: 0.9rem 5px 0;
}
.pres-stat {
  display: flex;
  align-items: center;
  gap: 13px;
  background: #fff;
  border: 1px solid var(--pres-line);
  border-radius: var(--pres-radius);
  padding: 14px 16px;
  box-shadow: var(--pres-shadow-sm);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.pres-stat:hover {
  transform: translateY(-2px);
  box-shadow: var(--pres-shadow-md);
}
.pres-stat__icon {
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  display: inline-grid;
  place-items: center;
  border-radius: 12px;
  font-size: 18px;
}
.pres-stat__body {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
  min-width: 0;
}
.pres-stat__value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--pres-ink);
  letter-spacing: -0.02em;
}
.pres-stat__label {
  font-size: 0.71rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.045em;
  color: var(--pres-muted);
}
.pres-stat--total .pres-stat__icon {
  background: var(--pres-accent-soft);
  color: var(--pres-accent);
}
.pres-stat--on .pres-stat__icon {
  background: rgba(40, 167, 69, 0.12);
  color: #1d8a4a;
}
.pres-stat--off .pres-stat__icon {
  background: #eef1f4;
  color: #5b6671;
}
.pres-stat--af .pres-stat__icon {
  background: var(--pres-accent-soft);
  color: var(--pres-accent);
}
.pres-stat--ex .pres-stat__icon {
  background: rgba(23, 162, 184, 0.12);
  color: #117a8b;
}
.pres-stat--warn .pres-stat__icon {
  background: rgba(255, 193, 7, 0.18);
  color: #997404;
}
/* Resalte solo cuando hay prestaciones sin clasificar (lo activa el JS) */
.pres-stat--alerta {
  border-color: rgba(255, 193, 7, 0.55);
  background: linear-gradient(180deg, rgba(255, 193, 7, 0.07), #fff 62%);
}
.pres-stat--alerta .pres-stat__value {
  color: #b8860b;
}

/* Tarjetas clicables como filtro del listado */
.pres-stat {
  position: relative;
}
.pres-stat--click {
  cursor: pointer;
  user-select: none;
}
.pres-stat--click:focus-visible {
  outline: none;
  box-shadow: 0 0 0 0.18rem var(--pres-accent-ring);
}
.pres-stat--activo {
  border-color: var(--pres-accent);
  box-shadow: 0 0 0 1px var(--pres-accent), var(--pres-shadow-md);
}
.pres-stat--activo::after {
  content: "×";
  position: absolute;
  top: 4px;
  right: 11px;
  font-size: 16px;
  line-height: 1;
  color: var(--pres-muted);
}

/* Overlay de carga al filtrar (feedback visual) */
#pres-list-card {
  position: relative;
}
.pres-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.66);
  backdrop-filter: blur(1px);
  z-index: 6;
  border-radius: inherit;
}
.pres-loading__box {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: #fff;
  border: 1px solid var(--pres-line-2);
  border-radius: 10px;
  box-shadow: var(--pres-shadow-md);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--pres-muted);
}
.pres-loading__spinner {
  width: 18px;
  height: 18px;
  border: 2.5px solid var(--pres-accent-soft);
  border-top-color: var(--pres-accent);
  border-radius: 50%;
  animation: pres-spin 0.6s linear infinite;
}
@keyframes pres-spin {
  to {
    transform: rotate(360deg);
  }
}

/* =========================================================
   1c. Bloque de Recientes (agregadas / editadas)
   ========================================================= */
.pres-recientes {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 10px;
  margin: 0.85rem 5px 0;
  padding: 10px 14px;
  background: #fff;
  border: 1px dashed var(--pres-line-2);
  border-radius: var(--pres-radius);
}
.pres-recientes__label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--pres-muted);
  white-space: nowrap;
}
.pres-recientes__label i {
  margin-right: 4px;
}
.pres-recientes__body {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.pres-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 240px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 600;
  border: 1px solid transparent;
  white-space: nowrap;
}
.pres-chip i {
  font-size: 0.66rem;
}
.pres-chip__txt {
  overflow: hidden;
  text-overflow: ellipsis;
}
.pres-chip--add {
  background: var(--pres-accent-soft);
  color: var(--pres-accent);
  border-color: rgba(40, 167, 69, 0.22);
}
.pres-chip--edit {
  background: rgba(23, 162, 184, 0.10);
  color: #117a8b;
  border-color: rgba(23, 162, 184, 0.20);
}
.pres-chip--del .pres-chip__txt {
  text-decoration: line-through;
  opacity: 0.7;
}

/* =========================================================
   2. Toolbar de la tabla
   ========================================================= */
.pres-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 1.1rem;
  padding-bottom: 0.9rem;
  border-bottom: 1px solid var(--pres-line);
}

.pres-bloque-titulo {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 0;
}

.pres-bloque-titulo h6 {
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--pres-ink);
}

.pres-bloque-titulo .fas,
.pres-bloque-titulo .bi {
  color: var(--pres-accent);
}

/* Botón "Agregar": acento sólido con profundidad y lift */
#btn_add_prestacion.btn-success {
  background: linear-gradient(180deg, #2bb35e 0%, var(--pres-accent) 100%);
  border: none;
  font-weight: 600;
  letter-spacing: 0.01em;
  padding: 0.42rem 1rem;
  border-radius: 9px;
  box-shadow: 0 2px 6px rgba(33, 149, 90, 0.30);
  transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
}
#btn_add_prestacion.btn-success:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(33, 149, 90, 0.34);
  filter: brightness(1.03);
}
#btn_add_prestacion.btn-success:active {
  transform: translateY(0);
  box-shadow: 0 2px 6px rgba(33, 149, 90, 0.30);
}

/* =========================================================
   3. Tabla (DataTable)
   ========================================================= */
#tabla_prestaciones thead th {
  vertical-align: middle;
  border-top: none;
  border-bottom: 2px solid var(--pres-line-2);
  text-transform: uppercase;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--pres-muted);
  padding-top: 0.7rem;
  padding-bottom: 0.7rem;
  white-space: nowrap;
}

#tabla_prestaciones tbody td {
  vertical-align: middle;
  border-top: 1px solid var(--pres-line);
  padding-top: 0.6rem;
  padding-bottom: 0.6rem;
  color: #36424c;
}

#tabla_prestaciones tbody tr:hover {
  background-color: var(--pres-accent-soft) !important;
}

/* Contener la tabla ancha DENTRO de la tarjeta: el sistema fuerza
   .table-responsive{overflow:visible !important} (parche dropdowns), lo que
   hace desbordar la página y produce el "tiritar" al scrollear. Aquí no hay
   dropdowns dentro de la tabla, así que la contenemos con scroll horizontal. */
#pantalla_prestaciones .table-responsive {
  overflow-x: auto !important;
}

/* Badges refinados (pills con tinte suave) dentro de la tabla */
#tabla_prestaciones .badge {
  border-radius: 999px;
  padding: 0.36em 0.7em;
  font-weight: 600;
  font-size: 0.7rem;
  letter-spacing: 0.02em;
  border: 1px solid transparent;
}
#tabla_prestaciones .badge-success {
  background: rgba(40, 167, 69, 0.12);
  color: #1d8a4a;
  border-color: rgba(40, 167, 69, 0.22);
}
#tabla_prestaciones .badge-secondary {
  background: #eef1f4;
  color: #5b6671;
  border-color: #e0e5ea;
}
#tabla_prestaciones .badge-info {
  background: rgba(23, 162, 184, 0.12);
  color: #138496;
  border-color: rgba(23, 162, 184, 0.22);
}
#tabla_prestaciones .badge-warning {
  background: rgba(255, 193, 7, 0.16);
  color: #997404;
  border-color: rgba(255, 193, 7, 0.30);
}

/* Botones de acción: set cohesivo de icon-buttons (tinte suave → se rellena al hover) */
/* Grupo de acciones: fila flex que NUNCA se apila */
#tabla_prestaciones td .pres-acciones {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
#tabla_prestaciones td .btn-sm {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  margin: 0 !important;
  flex: 0 0 auto;
  border-radius: 8px;
  border: 1px solid transparent;
  box-shadow: none;
  font-size: 0.8rem;
  line-height: 1;
  transition: background-color 0.14s ease, color 0.14s ease, border-color 0.14s ease;
}

/* Editar (btn-info) */
#tabla_prestaciones td .btn-info {
  background: rgba(23, 162, 184, 0.12);
  color: #117a8b;
  border-color: rgba(23, 162, 184, 0.22);
}
#tabla_prestaciones td .btn-info:hover {
  background: #17a2b8;
  color: #fff;
  border-color: #17a2b8;
}

/* Deshabilitar (btn-warning) */
#tabla_prestaciones td .btn-warning {
  background: rgba(255, 193, 7, 0.16);
  color: #997404;
  border-color: rgba(255, 193, 7, 0.30);
}
#tabla_prestaciones td .btn-warning:hover {
  background: #ffc107;
  color: #3d3000;
  border-color: #ffc107;
}

/* Habilitar (btn-light) → acento verde */
#tabla_prestaciones td .btn-light {
  background: var(--pres-accent-soft);
  color: var(--pres-accent);
  border-color: rgba(40, 167, 69, 0.22);
}
#tabla_prestaciones td .btn-light:hover {
  background: var(--pres-accent);
  color: #fff;
  border-color: var(--pres-accent);
}

/* Eliminar (btn-danger) */
#tabla_prestaciones td .btn-danger {
  background: rgba(220, 53, 69, 0.10);
  color: #c82333;
  border-color: rgba(220, 53, 69, 0.22);
}
#tabla_prestaciones td .btn-danger:hover {
  background: #dc3545;
  color: #fff;
  border-color: #dc3545;
}

/* Barra de controles del DataTable (botones export + buscador) como toolbar limpia */
#pantalla_prestaciones .dataTables_wrapper .dt-buttons {
  margin-bottom: 0.9rem;
}
#pantalla_prestaciones .dataTables_filter {
  margin-bottom: 0.9rem;
}
#pantalla_prestaciones .dataTables_filter label {
  font-size: 0.82rem;
  color: var(--pres-muted);
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 0;
}

/* Controles del DataTable (buscador, length, botones export, paginación) */
#pantalla_prestaciones .dataTables_filter input,
#pantalla_prestaciones .dataTables_length select {
  border: 1px solid var(--pres-line-2);
  border-radius: 8px;
  padding: 0.34rem 0.7rem;
  max-width: 100%;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
#pantalla_prestaciones .dataTables_filter input:focus,
#pantalla_prestaciones .dataTables_length select:focus {
  outline: none;
  border-color: var(--pres-accent-2);
  box-shadow: 0 0 0 0.18rem var(--pres-accent-ring);
}
#pantalla_prestaciones .dt-buttons .btn {
  border-radius: 8px;
  font-weight: 600;
}
#pantalla_prestaciones .dataTables_paginate .paginate_button.current {
  border-radius: 8px !important;
  background: var(--pres-accent) !important;
  border-color: var(--pres-accent) !important;
  color: #fff !important;
}
#pantalla_prestaciones .dataTables_info {
  color: var(--pres-muted);
  font-size: 0.82rem;
}

/* =========================================================
   4. Modal agregar / editar
   ========================================================= */
#modal_prestaciones .modal-content {
  border: none;
  border-radius: 18px;
  overflow: hidden;
  box-shadow: var(--pres-shadow-md);
}

/* Entrada suave (escala + leve subida) */
#modal_prestaciones.fade .modal-dialog {
  transition: transform 0.22s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.22s ease;
  transform: translateY(14px) scale(0.985);
}
#modal_prestaciones.show .modal-dialog {
  transform: none;
}

#modal_prestaciones .modal-header {
  align-items: center;
  padding: 1rem 1.4rem;
  border-bottom: 1px solid var(--pres-line);
  background:
    linear-gradient(180deg, rgba(40, 167, 69, 0.05), rgba(40, 167, 69, 0) 70%);
}
#modal_prestaciones .modal-title {
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--pres-ink);
  position: relative;
  padding-left: 0.85rem;
}
#modal_prestaciones .modal-title::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 1.05em;
  border-radius: 4px;
  background: var(--pres-accent);
}
#modal_prestaciones .modal-header .close {
  opacity: 0.5;
  transition: opacity 0.15s ease, transform 0.15s ease;
  text-shadow: none;
}
#modal_prestaciones .modal-header .close:hover {
  opacity: 1;
  transform: rotate(90deg);
}

#modal_prestaciones .modal-body {
  padding: 1.3rem 1.4rem;
}

/* Secciones del formulario */
.pres-form-seccion + .pres-form-seccion {
  margin-top: 1.25rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--pres-line);
}
.pres-form-seccion-label {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--pres-muted);
  margin-bottom: 0.75rem;
}
.pres-form-seccion-label::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--pres-accent);
  flex: 0 0 auto;
}

/* Labels de campo */
#modal_prestaciones .form-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: #4a5560;
}
#modal_prestaciones .form-label > i {
  color: var(--pres-muted);
  margin-right: 2px;
}

/* Inputs / selects refinados con foco de acento */
#modal_prestaciones .form-control,
#modal_prestaciones select.form-control {
  border: 1px solid var(--pres-line-2);
  border-radius: 9px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}
#modal_prestaciones .form-control:focus,
#modal_prestaciones select.form-control:focus {
  border-color: var(--pres-accent-2);
  box-shadow: 0 0 0 0.18rem var(--pres-accent-ring);
}

/* Código automático: claramente de solo lectura */
#input_codigo[disabled] {
  background-color: #f4f6f8;
  color: #97a2ae;
  font-style: italic;
  border-style: dashed;
}

/* =========================================================
   5. Toggle de Tipo de facturación
   El JS marca el radio por .checked (no toca la clase .active de BS),
   por eso el estado activo se resuelve con CSS puro vía :checked.
   ========================================================= */
.pres-toggle-fact {
  display: inline-flex;
  background: #f4f6f8;
  padding: 4px;
  border-radius: 11px;
  box-shadow: inset 0 0 0 1px var(--pres-line-2);
}
.pres-toggle-fact .pres-fact-opcion {
  min-width: 138px;
  cursor: pointer;
  margin-bottom: 0;
  display: flex;
}
.pres-toggle-fact .pres-fact-cara {
  width: 100%;
  margin: 0;
  border: none !important;
  background: transparent;
  color: #5b6671;
  border-radius: 8px !important;
  padding: 0.4rem 0.6rem;
  line-height: 1.15;
  transition: background-color 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;
}
.pres-toggle-fact .pres-fact-opcion + .pres-fact-opcion .pres-fact-cara {
  margin-left: 0;
}
.pres-toggle-fact .pres-fact-opcion input {
  position: absolute;
  clip: rect(0, 0, 0, 0);
  pointer-events: none;
}
.pres-toggle-fact .pres-fact-cara small {
  display: block;
  font-size: 0.66rem;
  opacity: 0.85;
  font-weight: 400;
}
.pres-toggle-fact .pres-fact-opcion:hover .pres-fact-cara {
  color: var(--pres-ink);
}
/* Activo: pastilla blanca elevada (look "segmented control" iOS/SaaS) */
.pres-toggle-fact .pres-fact-opcion input:checked ~ .pres-fact-cara {
  background: #ffffff;
  color: var(--pres-accent);
  box-shadow: var(--pres-shadow-sm), 0 0 0 1px rgba(40, 167, 69, 0.18);
  font-weight: 600;
}
.pres-toggle-fact .pres-fact-opcion input:focus-visible ~ .pres-fact-cara {
  box-shadow: 0 0 0 0.2rem var(--pres-accent-ring);
}

/* =========================================================
   6. Footer del modal
   ========================================================= */
#modal_prestaciones .modal-footer {
  padding: 0.9rem 1.4rem;
  border-top: 1px solid var(--pres-line);
  background: #fbfcfd;
}
#modal_prestaciones .modal-footer .btn {
  border-radius: 9px;
  font-weight: 600;
  letter-spacing: 0.01em;
  transition: transform 0.14s ease, box-shadow 0.14s ease, filter 0.14s ease;
}
#modal_prestaciones .modal-footer .btn-primary {
  background: linear-gradient(180deg, #2bb35e 0%, var(--pres-accent) 100%);
  border: none;
  box-shadow: 0 2px 6px rgba(33, 149, 90, 0.30);
}
#modal_prestaciones .modal-footer .btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(33, 149, 90, 0.34);
  filter: brightness(1.03);
}
#modal_prestaciones .modal-footer .btn-secondary {
  background: #fff;
  color: #5b6671;
  border: 1px solid var(--pres-line-2);
}
#modal_prestaciones .modal-footer .btn-secondary:hover {
  background: #f4f6f8;
  color: var(--pres-ink);
}

/* =========================================================
   7. Bloqueo del scroll de fondo cuando hay un modal abierto
   El scroll del template vive en .main-panel / .container-scroller
   (NO en body), por eso el body.modal-open de Bootstrap no alcanza.
   ========================================================= */
body.modal-open {
  overflow: hidden !important;
}
body.modal-open .container-scroller,
body.modal-open .page-body-wrapper,
body.modal-open .main-panel,
body.modal-open .content-wrapper {
  overflow: hidden !important;
}

/* =========================================================
   8. Responsive
   ========================================================= */
@media (max-width: 575.98px) {
  .pres-toolbar {
    align-items: stretch;
  }
  #btn_add_prestacion.btn-success {
    width: 100%;
  }
  .pres-toggle-fact {
    width: 100%;
  }
  .pres-toggle-fact .pres-fact-opcion {
    flex: 1;
    min-width: 0;
  }
  #modal_prestaciones .modal-body {
    padding: 1rem;
  }
}

/* Respeta usuarios con motion reducido */
@media (prefers-reduced-motion: reduce) {
  #pantalla_prestaciones *,
  #modal_prestaciones * {
    transition: none !important;
  }
}
