/* =========================================================
   Rasta Pets – Reportes CSS (Premium Soft UI & Print)
   ========================================================= */

.reports-page {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding: 28px 36px;
  gap: 26px;
  background:
    radial-gradient(circle at top right, rgba(34, 199, 169, 0.08), transparent 30%),
    var(--color-bg, #f6f9fc);
  color: var(--color-text, #102a56);
  overflow-y: auto;
}

/* ------------------ Encabezado ------------------ */
.reports-page .topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
}

.reports-page .title-wrap {
  flex: 1;
}

.reports-page .title {
  margin: 0 0 7px;
  color: var(--color-text, #102a56);
  font-size: 32px;
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.04em;
}

.reports-page .subtitle {
  margin: 0;
  color: var(--color-muted, #7b8ba8);
  font-size: 14px;
  font-weight: 500;
}

/* ------------------ Tarjeta de Filtros ------------------ */
.reports-page .filters-card {
  position: relative;
  z-index: 50;
  padding: 22px 28px;
  background: #ffffff;
  border: 1px solid var(--color-border-soft, #eef3f8);
  border-radius: 20px;
  box-shadow: 0 10px 30px rgba(16, 42, 86, 0.04);
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

.reports-page .filters-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 20px;
  align-items: flex-end;
  width: 100%;
}

.reports-page .filter-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.reports-page .filter-group label {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--color-text, #102a56);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.reports-page .filter-group .form-control {
  height: 44px;
  padding: 10px 16px;
  border: 1.5px solid #dce4ef;
  border-radius: 12px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text, #102a56);
  background-color: #ffffff;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.reports-page .filter-group .form-control:focus {
  border-color: var(--color-primary, #22c7a9);
  box-shadow: 0 0 0 3px rgba(34, 199, 169, 0.12);
}

.reports-page .filter-actions-group {
  display: flex;
  align-items: flex-end;
}

.reports-page .filter-actions-group .btn {
  height: 44px;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ------------------ Tarjetas KPI ------------------ */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
}

.kpi-card {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 20px 24px;
  background: #ffffff;
  border: 1px solid var(--color-border-soft, #eef3f8);
  border-radius: 20px;
  box-shadow: 0 10px 30px rgba(16, 42, 86, 0.04);
}

.kpi-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  border-radius: 16px;
  font-size: 22px;
  flex-shrink: 0;
}

.kpi-icon.sales {
  background: rgba(34, 199, 169, 0.12);
  color: #10b981;
}

.kpi-icon.services {
  background: rgba(59, 130, 246, 0.12);
  color: #3b82f6;
}

.kpi-icon.ticket {
  background: rgba(245, 158, 11, 0.12);
  color: #f59e0b;
}

.kpi-icon.clients {
  background: rgba(168, 85, 247, 0.12);
  color: #a855f7;
}

.kpi-icon svg {
  width: 24px;
  height: 24px;
}

.kpi-content {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.kpi-label {
  font-size: 13px;
  font-weight: 600;
  color: #7b8ba8;
}

.kpi-value {
  margin: 0;
  font-size: 22px;
  font-weight: 800;
  color: var(--color-text, #102a56);
  letter-spacing: -0.02em;
}

/* ------------------ Pestañas y Paneles ------------------ */
.reports-page .tabs {
  display: flex;
  border-bottom: 2px solid #e2e8f0;
  gap: 16px;
}

.reports-page .tab {
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  padding: 12px 24px;
  font-size: 15px;
  font-weight: 700;
  color: #64748b;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 8px;
}

.reports-page .tab:hover {
  color: var(--color-primary, #22c7a9);
}

.reports-page .tab.active {
  color: var(--color-primary, #22c7a9);
  border-bottom-color: var(--color-primary, #22c7a9);
}

.panel {
  display: block;
}

.panel.hidden {
  display: none !important;
}

.cat-section.hidden {
  display: none !important;
}

/* ------------------ Grid de reportes y tarjetas ------------------ */
.reports-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
  gap: 24px;
}

.report-card {
  background: #ffffff;
  border: 1px solid var(--color-border-soft, #eef3f8);
  border-radius: 24px;
  padding: 24px;
  box-shadow: 0 14px 35px rgba(16, 42, 86, 0.05);
  display: flex;
  flex-direction: column;
  min-height: 380px;
}

.report-card.full-width {
  grid-column: 1 / -1;
}

.report-card .card-header {
  margin-bottom: 18px;
  padding-bottom: 12px;
  border-bottom: 1px solid #f1f5f9;
}

.report-card .card-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 800;
  color: var(--color-text, #102a56);
}

.report-card .card-header .card-subtitle {
  margin: 4px 0 0;
  font-size: 12.5px;
  color: #7b8ba8;
}

.report-card .card-body {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 280px;
}

/* ------------------ Documentación y Tablas ------------------ */
.doc-actions-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 16px;
}

.doc-section-title {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
  color: var(--color-text, #102a56);
}

.doc-actions-buttons {
  display: flex;
  gap: 12px;
}

.report-table-card {
  background: #ffffff;
  border: 1px solid var(--color-border-soft, #eef3f8);
  border-radius: 20px;
  padding: 24px;
  box-shadow: 0 10px 30px rgba(16, 42, 86, 0.04);
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
  margin-top: 14px;
  border-radius: 12px;
  border: 1px solid #e2e8f0;
}

.reports-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 13.5px;
}

.reports-table th {
  background-color: #f8fafc;
  color: #475569;
  font-weight: 700;
  padding: 12px 16px;
  border-bottom: 1.5px solid #cbd5e1;
  white-space: nowrap;
}

.reports-table td {
  padding: 12px 16px;
  border-bottom: 1px solid #e2e8f0;
  color: #334155;
}

.reports-table tr:nth-child(even) td {
  background-color: #f8fafc;
}

.reports-table tr:hover td {
  background-color: #f1f5f9;
}

.reports-table .text-right {
  text-align: right;
}

.reports-table .text-center {
  text-align: center;
}

.table-totals-row td {
  background-color: #f1f5f9 !important;
  font-weight: 800;
  color: var(--color-text, #102a56) !important;
  border-top: 2px solid #cbd5e1;
  border-bottom: 2px solid #cbd5e1;
}

.badge {
  display: inline-block;
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 700;
  border-radius: 6px;
  text-transform: uppercase;
}

.badge.pendiente {
  background: #fef3c7;
  color: #d97706;
}

.badge.pagado {
  background: #d1fae5;
  color: #059669;
}

.badge.anulado {
  background: #fee2e2;
  color: #dc2626;
}

/* ------------------ Botones ------------------ */
.btn-excel:hover {
  background: #166534 !important;
  border-color: #14532d !important;
}

/* ------------------ Impresión (@media print) ------------------ */
@media print {
  body {
    background: #ffffff !important;
    color: #000000 !important;
    font-size: 10pt;
  }

  /* Ocultar barra lateral, barra de navegación, botones y filtros */
  #sidebar-container,
  .sidebar,
  .topbar,
  .filters-card,
  .tabs,
  .doc-actions-bar,
  #btnRefreshReports,
  #mobile-menu-toggle {
    display: none !important;
  }

  .reports-page {
    padding: 0 !important;
    background: transparent !important;
    overflow: visible !important;
    height: auto !important;
    min-height: auto !important;
  }

  .panel.hidden {
    display: none !important;
  }

  #panel-documentacion {
    display: block !important;
  }

  .report-table-card {
    border: none !important;
    padding: 0 !important;
    box-shadow: none !important;
    margin-bottom: 30px !important;
  }

  .table-responsive {
    border: none !important;
    overflow: visible !important;
  }

  .reports-table {
    font-size: 9pt;
  }

  .reports-table th, 
  .reports-table td {
    padding: 6px 8px !important;
    border: 1px solid #000000 !important;
  }

  .reports-table th {
    background-color: #e2e8f0 !important;
    color: #000000 !important;
  }

  .reports-table tr:nth-child(even) td {
    background-color: transparent !important;
  }

  /* Título de impresión */
  .reports-page::before {
    content: "RASTA PETS - REPORTE CONTABLE DE SERVICIOS Y CAJA";
    display: block;
    font-size: 16pt;
    font-weight: bold;
    text-align: center;
    margin-bottom: 20px;
    border-bottom: 2px solid #000000;
    padding-bottom: 10px;
  }
}

/* ------------------ Responsive ------------------ */
@media (max-width: 900px) {
  .reports-page {
    padding: 20px 16px;
  }

  .reports-grid {
    grid-template-columns: 1fr;
  }

  .doc-actions-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .doc-actions-buttons {
    flex-direction: column;
  }

  .doc-actions-buttons .btn {
    width: 100%;
  }
}

@media (max-width: 600px) {
  .reports-page .filters-grid {
    grid-template-columns: 1fr;
  }

  .reports-page .filter-actions-group .btn {
    width: 100%;
  }
}

/* =========================================================
   Nuevos estilos: Corrección de Scroll, Ordenamiento y Carga
   ========================================================= */

/* Evitar que los gráficos de ApexCharts bloqueen el scroll vertical */
.apexcharts-canvas,
.apexcharts-canvas svg,
.report-card .card-body > div,
.report-card .card-body {
  touch-action: pan-y !important;
}

/* Encabezados de tabla ordenables */
.reports-table th.sortable {
  position: relative;
  cursor: pointer;
  padding-right: 28px !important;
  user-select: none;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.reports-table th.sortable:hover {
  background-color: #f1f5f9 !important;
  color: var(--color-primary, #22c7a9) !important;
}

.reports-table th.sortable::after {
  content: " ↕";
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: #94a3b8;
  font-size: 11px;
  opacity: 0.6;
  font-weight: normal;
}

.reports-table th.sortable.sort-asc::after {
  content: " ▲";
  color: var(--color-primary, #22c7a9);
  opacity: 1;
}

.reports-table th.sortable.sort-desc::after {
  content: " ▼";
  color: var(--color-primary, #22c7a9);
  opacity: 1;
}

/* Spinner animado para la carga de las tablas */
.loading-spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(34, 199, 169, 0.2);
  border-radius: 50%;
  border-top-color: var(--color-primary, #22c7a9);
  animation: spin-report-table 0.8s linear infinite;
  vertical-align: middle;
  margin-right: 10px;
}

@keyframes spin-report-table {
  to { transform: rotate(360deg); }
}