/* ==========================================================================
   BASE & TYPOGRAPHY - Alta densidad, fuente legible técnica
   ========================================================================== */
body {
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, sans-serif;
  font-size: 13px;
  background-color: #f1f5f9;
  color: #334155;
}

body.saas-template {
  padding: 20px;
}

body.saas-side-template {
  padding: 20px 4px;
  background: #f1f5f9;
}

h1,
h2,
h3,
h4,
h5,
h6 {
  color: #0f172a;
  font-weight: 600;
}

.pageTitle {
  background-color: transparent !important;
  border-bottom: 1px solid #cbd5e1 !important;
  margin-bottom: 15px !important;
}

.pageTitle .title_nm {
  color: #0f172a !important;
  font-size: 18px !important;
  font-weight: 600 !important;
  padding-bottom: 10px !important;
}

/* Utilidades de Flexbox */
.flex-row {
  display: flex;
}
.flex-col {
  display: flex;
  flex-direction: column;
}
.items-center {
  align-items: center;
}
.justify-between {
  justify-content: space-between;
}
.gap-10 {
  gap: 10px;
}
.gap-15 {
  gap: 15px;
}

/* ==========================================================================
   PANELES / TARJETAS - Agrupación de contenido
   ========================================================================== */
.saas-panel {
  background-color: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  margin-bottom: 12px;
}

.saas-panel-header {
  padding: 12px 16px;
  border-bottom: 1px solid #e2e8f0;
  background-color: #f8fafc;
  border-radius: 6px 6px 0 0;
  font-size: 14px;
  font-weight: 600;
  color: #0f172a;
}

.saas-panel-body {
  padding: 16px;
}

/* ==========================================================================
   FORMULARIOS - Optimizados para poco espacio y lectura rápida
   ========================================================================== */
.saas-form-group {
  margin-bottom: 12px;
}

.saas-label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.saas-muted-text {
  color: #64748b;
  font-size: 13px;
}

/* SAAS Toggle Switch */
.saas-switch {
  position: relative;
  display: inline-block;
  width: 42px;
  height: 22px;
  margin: 0;
}

.saas-switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.saas-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #e2e8f0;
  transition: 0.2s;
  border-radius: 999px;
  box-shadow: inset 0 0 0 1px #cbd5e1;
}

.saas-slider:before {
  position: absolute;
  content: "";
  height: 16px;
  width: 16px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  border-radius: 50%;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
  transition: 0.2s;
}

.saas-switch input:checked + .saas-slider {
  background-color: #5b48ff;
  box-shadow: inset 0 0 0 1px #4f46e5;
}

.saas-switch input:focus + .saas-slider {
  box-shadow:
    inset 0 0 0 1px #4f46e5,
    0 0 0 2px rgba(91, 72, 255, 0.2);
}

.saas-switch input:checked + .saas-slider:before {
  transform: translateX(19px);
}

.saas-control {
  display: block;
  width: 100%;
  height: 30px;
  padding: 4px 8px;
  font-size: 13px;
  line-height: 1.4;
  color: #334155;
  background-color: #fff;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  box-shadow: none;
  transition: all 0.2s ease-in-out;
}

.saas-control:focus {
  border-color: #3b82f6;
  outline: 0;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.saas-control[disabled],
.saas-control[readonly] {
  background-color: #f8fafc;
  cursor: not-allowed;
  color: #94a3b8;
}

/* Fix para selects nativos */
select.saas-control {
  padding-top: 2px;
  padding-bottom: 2px;
}

/* ==========================================================================
   COMPONENTES DE TERCEROS - Select2 & DatePicker
   ========================================================================== */
.select2-container--default .select2-selection--single {
  height: 30px !important;
  padding: 4px 8px !important;
  font-size: 13px !important;
  border: 1px solid #cbd5e1 !important;
  border-radius: 4px !important;
  display: flex !important;
  align-items: center !important;
  background-color: #fff !important;
}

.select2-container--default
  .select2-selection--single
  .select2-selection__rendered {
  line-height: 20px !important;
  padding-left: 0 !important;
  color: #334155 !important;
}

.select2-container--default
  .select2-selection--single
  .select2-selection__arrow {
  height: 28px !important;
}

.select2-container--default .select2-results__option {
  font-size: 13px;
  padding: 6px 10px;
}

.date_picker {
  height: 30px !important;
  border-radius: 4px !important;
  border: 1px solid #cbd5e1 !important;
  padding: 4px 8px !important;
  font-size: 13px !important;
  width: 100% !important;
  box-sizing: border-box !important;
  color: #334155 !important;
}

.date_picker:focus {
  border-color: #3b82f6 !important;
  outline: 0 !important;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15) !important;
}

/* ==========================================================================
   INPUT GROUPS (Botones pegados al input)
   ========================================================================== */
.saas-input-group {
  display: flex;
  align-items: stretch;
  width: 100%;
  height: 30px;
}

.saas-input-group .saas-control {
  flex: 1;
  height: 30px;
  margin: 0;
}

.saas-input-group > * {
  border-radius: 0;
}

.saas-input-group > :first-child {
  border-top-left-radius: 4px;
  border-bottom-left-radius: 4px;
}

.saas-input-group > :last-child {
  border-top-right-radius: 4px;
  border-bottom-right-radius: 4px;
}

.saas-input-group .btn-saas {
  margin-left: -1px;
  z-index: 1;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
}

.saas-input-group .btn-saas:hover,
.saas-input-group .btn-saas:focus {
  z-index: 2;
}

.saas-input-group .btn-saas:not(:last-child) {
  border-radius: 0;
}

/* ==========================================================================
   BOTONES - Sobrios y funcionales
   ========================================================================== */
.btn-saas {
  display: inline-block;
  font-weight: 500;
  text-align: center;
  vertical-align: middle;
  cursor: pointer;
  border: 1px solid transparent;
  padding: 5px 12px;
  font-size: 13px;
  line-height: 1.5;
  border-radius: 4px;
  transition: all 0.15s ease-in-out;
  text-decoration: none;
  align-items: center;
}

.btn-saas:hover {
  text-decoration: none;
}

.btn-saas-primary {
  color: #ffffff;
  background-color: #0f172a;
  border-color: #0f172a;
}
.btn-saas-primary:hover {
  background-color: #1e293b;
  border-color: #1e293b;
  color: #ffffff;
}

.btn-saas-default {
  color: #334155;
  background-color: #ffffff;
  border-color: #cbd5e1;
}
.btn-saas-default:hover {
  background-color: #f1f5f9;
  border-color: #94a3b8;
  color: #334155;
}

.btn-saas-success {
  color: #ffffff;
  background-color: #16a34a;
  border-color: #15803d;
}
.btn-saas-success:hover {
  background-color: #15803d;
  border-color: #166534;
  color: #ffffff;
}

.btn-saas-danger {
  color: #ffffff;
  background-color: #dc2626;
  border-color: #b91c1c;
}
.btn-saas-danger:hover {
  background-color: #b91c1c;
  border-color: #991b1b;
  color: #ffffff;
}

.btn-saas-sm {
  padding: 3px 8px;
  font-size: 12px;
  border-radius: 3px;
}

/* ==========================================================================
   TABLAS (GRILLAS) - Compactas y legibles
   ========================================================================== */
.saas-table-wrapper {
  overflow-x: auto;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
}

.saas-table {
  width: 100%;
  margin-bottom: 0;
  border-collapse: collapse;
  background-color: #fff;
}

.saas-table th,
.saas-table td {
  padding: 6px 12px;
  vertical-align: middle;
  border-bottom: 1px solid #e2e8f0;
  white-space: nowrap;
}

.saas-table th {
  background-color: #f8fafc;
  color: #475569;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom-width: 2px;
  border-bottom-color: #cbd5e1;
}

.saas-table tbody tr:hover {
  background-color: #f1f5f9;
}

.saas-table tbody tr:last-child td {
  border-bottom: none;
}

/* ==========================================================================
   ALERTAS / FEEDBACK - Colores planos y claros
   ========================================================================== */
.saas-alert {
  padding: 12px 16px;
  margin-bottom: 15px;
  border: 1px solid transparent;
  border-radius: 4px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.saas-alert-success {
  color: #166534;
  background-color: #f0fdf4;
  border-color: #bbf7d0;
}

.saas-alert-danger {
  color: #991b1b;
  background-color: #fef2f2;
  border-color: #fecaca;
}

.saas-alert-warning {
  color: #854d0e;
  background-color: #fefce8;
  border-color: #fde047;
}

.saas-alert-info {
  color: #1e40af;
  background-color: #eff6ff;
  border-color: #bfdbfe;
}

/* Badges de estado */
.saas-badge {
  display: inline-block;
  padding: 2px 6px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 10px;
  text-transform: uppercase;
  align-content: center;
}
.saas-badge-success {
  background: #dcfce7;
  color: #166534;
}
.saas-badge-warning {
  background: #fef3c7;
  color: #854d0e;
}
.saas-badge-danger {
  background: #fee2e2;
  color: #991b1b;
}
.saas-badge-neutral {
  background: #f1f5f9;
  color: #475569;
}

/* ==========================================================================
   LAYOUT Y HEADERS
   ========================================================================== */
.saas-page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.saas-page-header h2 {
  margin-bottom: 4px;
  display: flex;
  align-items: center;
}

.saas-page-header h2 i {
  color: #64748b;
  margin-right: 8px;
}

.p-0 {
  padding: 0 !important;
}

/* ==========================================================================
   DASHBOARD - Tarjetas indicadoras y utilidades
   ========================================================================== */
.saas-dashboard-card {
  min-height: 132px;
  cursor: pointer;
  transition: all 0.2s ease;
}
.saas-dashboard-card:hover {
  border-color: #cbd5e1;
  box-shadow: 0 4px 6px rgba(0,0,0,0.08);
  transform: translateY(-2px);
}
.saas-dashboard-title {
  color: #64748b;
  font-size: 12px;
  text-transform: uppercase;
  font-weight: 600;
  margin-bottom: 10px;
}
.saas-dashboard-value {
  font-size: 24px;
  font-weight: bold;
  color: #0f172a;
  margin-bottom: 5px;
}
.saas-dashboard-sub {
  font-size: 12px;
  color: #94a3b8;
}

.accent-green { color: #16a34a; }
.accent-red { color: #dc2626; }
.accent-yellow { color: #ca8a04; }
.accent-blue { color: #2563eb; }

/* ==========================================================================
   MODAL SAAS
   ========================================================================== */
.saas-modal-content {
  border-radius: 6px !important;
  border: 1px solid #94a3b8 !important;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1) !important;
  background-color: #ffffff !important;
  overflow: visible !important; /* Permitimos tooltips fuera del cuerpo */
}
.saas-modal-header {
  background-color: #0f172a !important;
  color: white !important;
  border-bottom: none !important;
  border-radius: 5px 5px 0 0 !important;
  padding: 12px 16px !important;
  display: flex !important;
  justify-content: space-between !important;
  align-items: center !important;
}
.saas-modal-title {
  color: #ffffff !important;
  font-size: 14px !important;
  font-weight: 600 !important;
  margin: 0 !important;
  display: flex !important;
  align-items: center !important;
  gap: 8px !important;
}
.saas-modal-title i {
  color: #94a3b8 !important;
}
.saas-modal-close {
  color: #94a3b8 !important;
  cursor: pointer !important;
  background: transparent !important;
  border: none !important;
  font-size: 14px !important;
  padding: 0 !important;
  margin: 0 !important;
  opacity: 1 !important;
  outline: none !important;
}
.saas-modal-close:hover {
  color: #ffffff !important;
  opacity: 1 !important;
}
.saas-modal-body {
  padding: 16px !important;
  max-height: 70vh !important;
  overflow-y: auto !important;
  background-color: #ffffff !important;
  position: relative;
}
.saas-modal-footer {
  border-top: 1px solid #e2e8f0 !important;
  padding: 15px !important;
  background-color: #ffffff !important;
  border-radius: 0 0 5px 5px !important;
  display: flex !important;
  justify-content: flex-end !important;
  gap: 10px !important;
  margin: 0 !important; /* Resetea margenes de bootstrap */
}

/* Alineación para diálogos bootbox con className 'saas-modal' */
.saas-modal .modal-content {
  border-radius: 6px !important;
  border: 1px solid #94a3b8 !important;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1) !important;
  background-color: #ffffff !important;
  overflow: visible !important;
}
.saas-modal .modal-header {
  background-color: #0f172a !important;
  color: white !important;
  border-bottom: none !important;
  border-radius: 5px 5px 0 0 !important;
  padding: 12px 16px !important;
  display: flex !important;
  justify-content: space-between !important;
  align-items: center !important;
}
.saas-modal .modal-title {
  color: #ffffff !important;
  font-size: 14px !important;
  font-weight: 600 !important;
  margin: 0 !important;
  display: flex !important;
  align-items: center !important;
  gap: 8px !important;
  line-height: 1.4 !important;
  order: 1 !important;
}
.saas-modal .modal-header .close {
  color: #94a3b8 !important;
  cursor: pointer !important;
  background: transparent !important;
  border: none !important;
  font-size: 14px !important;
  padding: 0 !important;
  margin: 0 !important;
  opacity: 1 !important;
  outline: none !important;
  float: none !important;
  text-shadow: none !important;
  line-height: 1 !important;
  order: 2 !important;
}
.saas-modal .modal-header .close:hover,
.saas-modal .modal-header .close:focus {
  color: #ffffff !important;
  opacity: 1 !important;
}
.saas-modal .modal-body {
  padding: 16px !important;
  max-height: 70vh !important;
  overflow-y: auto !important;
  background-color: #ffffff !important;
  position: relative;
}
.saas-modal .modal-footer {
  border-top: 1px solid #e2e8f0 !important;
  padding: 15px !important;
  background-color: #ffffff !important;
  border-radius: 0 0 5px 5px !important;
  display: flex !important;
  justify-content: flex-end !important;
  gap: 10px !important;
  margin: 0 !important;
}

@media (min-width: 992px) {
  .saas-modal-wide {
    width: 90%;
  }
}

/* ==========================================================================
   TOOLTIPS SAAS (CSS PURO)
   ========================================================================== */
.saas-tooltip {
  position: relative;
  display: inline-flex;
  align-items: center;
  cursor: help;
}

.saas-tooltip::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  background-color: #1e293b;
  color: #f8fafc;
  padding: 6px 10px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
  white-space: normal;
  width: max-content;
  max-width: 250px;
  text-align: center;
  line-height: 1.4;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  z-index: 3000;
  pointer-events: none;
}

/* Flechita del tooltip */
.saas-tooltip::before {
  content: '';
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  border-width: 6px;
  border-style: solid;
  border-color: #1e293b transparent transparent transparent;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s;
  z-index: 3000;
  pointer-events: none;
}

.saas-tooltip:hover::after {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(-4px);
}

.saas-tooltip:hover::before {
  opacity: 1;
  visibility: visible;
}

/* Evitar recorte de tooltips en tablas estrechas */
.saas-table-wrapper {
  overflow: visible;
}

.saas-table {
  overflow: visible;
  position: relative;
}

.saas-table th,
.saas-table td {
  overflow: visible;
  position: relative;
}

/* Triggers de ayuda en tablas */
.help-metric {
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

/* Modal de ayuda sobre modal principal */
.modal.modal-help {
  z-index: 2050;
}

.modal-backdrop.modal-backdrop-help {
  z-index: 2040;
}

/* ==========================================================================
   MENU LATERAL - Arbolado jerárquico
   ========================================================================== */
body.saas-side-template {
  background: #f1f5f9;
}
.saas-tree-wrapper {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
  /* padding: 12px; */
}
.saas-tree-toolbar {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
.saas-tree-container {
  max-height: 480px;
  overflow-y: auto;
}
.saas-tree-toggle {
  background: none;
  border: none;
  padding: 0 6px 0 0;
  color: #64748b;
  cursor: pointer;
}
.saas-tree-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  border-radius: 4px;
  color: #0f172a;
}
.saas-tree-item:hover {
  background: #f8fafc;
}
.saas-tree-link {
  color: inherit;
  text-decoration: none;
}
.saas-tree-link:hover {
  text-decoration: underline;
}
.saas-treeview {
  list-style: none;
  padding-left: 0;
  margin: 0;
}
.saas-treeview ul {
  list-style: none;
  margin: 0 0 0 16px;
  padding-left: 8px;
  display: none;
}
.saas-treeview ul.open {
  display: block;
}
.saas-treeview ul {
  position: relative;
}
.saas-treeview ul::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 8px;
  border-left: 1px dashed #cbd5e1;
}
.saas-treeview li {
  margin: 2px 0;
  position: relative;
  padding-left: 8px;
}
.saas-tree-icon {
  width: 14px;
  text-align: center;
  color: #fbbf24;
}
.saas-tree-leaf {
  color: #94a3b8;
  font-size: 6px;
}
