/* =============================================================================
   1. ADMIN - VARIABLES Y ESTILOS GLOBALES
   ============================================================================= */
:root {
  --primary-color: #8b0000;
  --accent-glow: rgba(139, 0, 0, 0.5);
  --background-dark: #121212;
  --background-card: #1e1e1e;
  --text-primary: #eaeaea;
  --text-secondary: #a0a0a0;
  --border-color: #333333;
  --success-color: #10b981;
  --error-color: #ef4444;
  --warning-color: #f59e0b;
  --cancel-color: #5a5a5a;
}

body.admin-page,
body.login-page-body {
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, sans-serif;
  background-color: var(--background-dark);
  color: var(--text-primary);
  margin: 0;
  line-height: 1.6;
}

/* --- MEJORA MODERNA: Scrollbar Personalizado --- */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: var(--background-dark);
}
::-webkit-scrollbar-thumb {
  background: #444;
  border-radius: 4px;
}

/* =============================================================================
   2. ADMIN - LAYOUT PRINCIPAL
   ============================================================================= */
.admin-grid-container {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

/* =============================================================================
   3. ADMIN - BARRA LATERAL
   ============================================================================= */
.admin-sidebar {
  background-color: var(--background-dark);
  display: flex;
  flex-direction: column;
  padding: 1.5rem 0;
  border-right: 1px solid var(--border-color);
}
.sidebar-header {
  text-align: center;
  padding: 0 1rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
}
.sidebar-header h3 {
  font-size: 1.6rem;
  color: var(--text-primary);
  font-weight: 700;
}
.sidebar-header span {
  color: var(--primary-color);
}
.sidebar-nav {
  flex-grow: 1;
  margin-top: 1.5rem;
}
.sidebar-nav ul {
  list-style: none;
  padding: 0;
  margin: 0;
}
.sidebar-nav a {
  display: flex;
  align-items: center;
  padding: 0.9rem 1.5rem;
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 500;
  transition: all 0.2s ease;
  border-left: 4px solid transparent;
}
.sidebar-nav a:hover {
  background-color: var(--background-card);
  color: var(--text-primary);
}
.sidebar-nav .active a {
  background-color: var(--primary-color);
  color: var(--text-primary);
  border-left-color: #ff4d4d;
}
.sidebar-nav i.fa-fw {
  margin-right: 12px;
  font-size: 1.1rem;
}
.sidebar-footer {
  display: none;
} /* OCULTADO: El botón ahora es flotante */

/* =============================================================================
   4. ADMIN - CONTENIDO PRINCIPAL
   ============================================================================= */
.admin-main-content {
  padding: 2.5rem;
  overflow-y: auto;
  background-color: var(--background-dark);
}
.section-heading {
  margin-bottom: 2.5rem;
}
.section-heading h2 {
  font-size: 2.2rem;
  font-weight: 700;
  color: var(--text-primary);
}
.section-heading .divider {
  width: 50px;
  height: 3px;
  background-color: var(--primary-color);
  margin: 0.5rem 0 1rem;
  border-radius: 1.5px;
}
.section-heading p {
  color: var(--text-secondary);
  font-size: 1.1rem;
}

/* =============================================================================
   5. ADMIN - TARJETAS KPI (MODIFICADO)
   ============================================================================= */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr); /* Rejilla 3x3 */
  gap: 1.25rem; /* Espaciado reducido */
  margin-bottom: 2.5rem;
}
.kpi-card {
  background-color: var(--background-card);
  border-radius: 8px;
  padding: 1rem; /* Padding reducido para menor altura */
  display: flex;
  align-items: center;
  border: 1px solid var(--border-color);
  transition:
    transform 0.3s ease,
    box-shadow 0.3s ease,
    border-color 0.3s;
}
.kpi-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.4);
  border-color: var(--primary-color);
}
.kpi-icon {
  font-size: 1.6rem; /* Icono más pequeño */
  width: 48px; /* Contenedor de icono más pequeño */
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 1rem; /* Margen reducido */
  flex-shrink: 0;
  background-color: rgba(255, 255, 255, 0.05);
}
.kpi-icon.ingresos {
  color: var(--success-color);
}
.kpi-icon.gastos {
  color: var(--error-color);
}
.kpi-icon.clientes {
  color: #3b82f6;
}
.kpi-icon.deuda {
  color: var(--warning-color);
}
.kpi-icon.inventario {
  color: #8b5cf6;
}
.kpi-icon.balance {
  color: #6366f1;
}
.kpi-info h3 {
  font-size: 0.8rem; /* Título más pequeño */
  color: var(--text-secondary);
  font-weight: 500;
  margin-bottom: 0.1rem; /* Espacio reducido */
  text-transform: uppercase;
}
.kpi-info p {
  font-size: 1.4rem; /* Valor numérico más pequeño */
  font-weight: 700;
  color: var(--text-primary);
}

/* =============================================================================
   6. ADMIN - GRÁFICOS Y TABLAS
   ============================================================================= */
.card,
.card-table,
.card-form {
  background-color: var(--background-card);
  border-radius: 8px;
  padding: 2rem;
  border: 1px solid var(--border-color);
  margin-bottom: 2rem;
}
.card h3,
.card-table h3,
.card-form h3 {
  font-size: 1.4rem;
  color: var(--text-primary);
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 1rem;
}
.chart-container,
.chart-container-medium {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  max-height: 450px;
}
.recent-activity-grid,
.report-grid-bottom,
.charts-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
  margin-bottom: 2rem;
}
.table-responsive {
  overflow-x: auto;
}
table {
  width: 100%;
  border-collapse: collapse;
}
td,
th {
  padding: 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}
th {
  background-color: #111;
  color: var(--text-secondary);
  font-size: 0.9rem;
  text-transform: uppercase;
  font-weight: 600;
}
tbody tr:hover {
  background-color: #2a2a2a;
}

/* =============================================================================
   7. ADMIN - BOTONES
   ============================================================================= */
.btn,
.btn-primary,
.btn-secondary,
.btn-submit,
.btn-cancel {
  padding: 0.85rem 1.5rem;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}
.btn i,
.btn-primary i,
.btn-secondary i,
.btn-submit i,
.btn-cancel i {
  margin-right: 8px;
}
.btn-primary,
.btn-submit {
  background: linear-gradient(135deg, var(--primary-color), #600000);
  color: white;
  border: none;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
}
.btn-primary:hover,
.btn-submit:hover {
  background: linear-gradient(135deg, #a00000, #700000);
  transform: translateY(-2px);
  box-shadow: 0 6px 12px rgba(139, 0, 0, 0.4);
}
.btn-secondary {
  background-color: var(--cancel-color);
  color: var(--text-primary);
  border: none;
}
.btn-secondary:hover {
  background-color: #4a4a4a;
}
.btn-cancel {
  background-color: transparent;
  border: 1px solid var(--cancel-color);
  color: var(--text-secondary);
}
.btn-cancel:hover {
  background-color: var(--cancel-color);
  color: var(--text-primary);
}

/* =============================================================================
   8. ADMIN - FORMULARIOS Y FILTROS
   ============================================================================= */
.form-layout {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 2.5rem;
  align-items: start;
}
.form-container,
.report-filters {
  background-color: var(--background-card);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 2rem;
}
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}
.form-group {
  margin-bottom: 1.5rem;
}
.form-group.full-width {
  grid-column: 1 / -1;
}
.form-group label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 0.9rem;
}
.form-group input,
.form-group select,
.form-group textarea {
  box-sizing: border-box;
  width: 100%;
  padding: 0.85rem;
  background-color: var(--background-dark);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 1rem;
  transition:
    border-color 0.2s,
    box-shadow 0.2s;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.form-actions {
  margin-top: 1rem;
  display: flex;
  justify-content: flex-end;
  gap: 1rem;
}
.form-sidebar .info-box {
  background-color: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--border-color);
  border-left: 3px solid var(--primary-color);
  border-radius: 6px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}
.form-sidebar .info-box h3 {
  font-size: 1.1rem;
  color: var(--text-primary);
  margin-top: 0;
  margin-bottom: 0.75rem;
}
.form-sidebar .info-box h3 i {
  margin-right: 10px;
  color: var(--primary-color);
}
.form-sidebar .info-box p {
  font-size: 0.95rem;
  color: var(--text-secondary);
  line-height: 1.6;
  margin: 0;
}
.report-filters {
  margin-bottom: 2rem;
}
.filter-controls {
  display: grid;
  grid-template-columns: 1fr 1fr 2fr;
  align-items: flex-end;
  gap: 1.5rem;
}
.filter-buttons {
  justify-self: flex-end;
}

/* =============================================================================
   9. ADMIN - INVENTARIO Y MODALES
   ============================================================================= */
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
}
.search-bar {
  position: relative;
  width: 350px;
}
.search-bar i {
  position: absolute;
  left: 15px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-secondary);
}
.search-bar input {
  width: 100%;
  padding: 0.85rem 0.85rem 0.85rem 40px;
  background-color: var(--background-card);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 1rem;
}
.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(5px);
}
.modal-content {
  background-color: var(--background-card);
  margin: 5vh auto;
  border: 1px solid var(--border-color);
  width: 90%;
  max-width: 700px;
  border-radius: 8px;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
  animation: slide-down 0.3s ease-out;
  display: flex;
  flex-direction: column;
  max-height: 90vh;
}
.modal-header {
  padding: 1rem 2rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-header h3 {
  margin: 0;
  font-size: 1.5rem;
}
.close-button {
  color: var(--text-secondary);
  font-size: 28px;
  font-weight: bold;
  cursor: pointer;
  transition: color 0.2s;
}
.close-button:hover,
.close-button:focus {
  color: var(--text-primary);
}
.modal-body {
  padding: 2rem;
  overflow-y: auto;
}
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}
.form-row .form-group {
  margin-bottom: 0;
}
.form-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 1rem;
  margin-top: 2rem;
  border-top: 1px solid var(--border-color);
  padding-top: 1.5rem;
}
td.actions {
  text-align: center;
}
.btn-edit,
.btn-delete {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 5px;
  margin: 0 5px;
  font-size: 1.1rem;
  color: var(--text-secondary);
  transition: color 0.2s;
}
.btn-edit:hover {
  color: var(--warning-color);
}
.btn-delete:hover {
  color: var(--error-color);
}
@keyframes slide-down {
  from {
    transform: translateY(-50px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* =============================================================================
   10. ADMIN - PÁGINA DE LOGIN
   ============================================================================= */
.login-page-body {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  flex-direction: column; /* Para alinear verticalmente el contenido */
}

.login-container {
  width: 100%;
  max-width: 420px;
  padding: 2.5rem;
  background-color: var(--background-card);
  border-radius: 8px;
  border: 1px solid var(--border-color);
  box-shadow: 0 0 30px rgba(0, 0, 0, 0.5);
  margin-top: 1.5rem; /* Espacio para el enlace superior */
}

.login-logo {
  text-align: center;
  margin-bottom: 1.5rem;
}

.login-logo h1 {
  font-size: 2.2rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
}

.login-logo span {
  color: var(--primary-color);
}

#login-error {
  background-color: rgba(239, 68, 68, 0.1);
  color: var(--error-color);
  padding: 1rem;
  border-radius: 6px;
  text-align: center;
  margin-bottom: 1.5rem;
  border: 1px solid var(--error-color);
}

.back-to-home {
  position: absolute;
  top: 2rem;
  left: 2rem;
}

.back-to-home a {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.9rem;
  transition: color 0.2s;
  background-color: var(--background-card);
  padding: 0.75rem 1.25rem;
  border-radius: 6px;
  border: 1px solid var(--border-color);
}

.back-to-home a:hover {
  color: var(--primary-color);
  border-color: var(--primary-color);
}

/* =============================================================================
   11. ADMIN - OVERLAY DE CARGA
   ============================================================================= */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.7);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 9999;
  color: var(--text-primary);
  backdrop-filter: blur(5px);
}
.spinner {
  border: 4px solid rgba(255, 255, 255, 0.2);
  border-left-color: var(--primary-color);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  animation: spin 1s linear infinite;
  margin-bottom: 1rem;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* =============================================================================
   12. ADMIN - ESTILOS RESPONSIVE
   ============================================================================= */
@media (max-width: 1200px) {
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .recent-activity-grid,
  .form-layout,
  .charts-container,
  .report-grid-bottom {
    grid-template-columns: 1fr;
  }
}
@media (max-width: 992px) {
  .admin-grid-container {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
  .admin-sidebar {
    display: flex;
    flex-direction: row;
    align-items: center;
    padding: 0.5rem;
    border-right: none;
    border-bottom: 1px solid var(--border-color);
    overflow-x: auto;
    white-space: nowrap;
    scrollbar-width: none; /* Firefox: Ocultar scrollbar pero permitir scroll */
  }
  .admin-sidebar::-webkit-scrollbar {
    display: none; /* Chrome/Safari: Ocultar scrollbar */
  }
  .sidebar-header {
    padding: 0 1rem;
    border-bottom: none;
    margin-bottom: 0;
  }
  .sidebar-header h3 {
    font-size: 1.2rem;
    margin: 0;
  }
  .sidebar-nav {
    margin-top: 0;
  }
  .sidebar-nav ul {
    display: flex;
    flex-direction: row;
    gap: 5px;
  }
  .sidebar-nav a {
    padding: 0.5rem 0.8rem;
    border-left: none;
    border-radius: 4px;
  }
  .sidebar-nav .active a {
    border-left: none;
    background-color: var(--primary-color);
  }
  .filter-controls {
    grid-template-columns: 1fr;
  }
  .filter-buttons {
    justify-self: stretch;
    display: flex;
    flex-direction: column;
    gap: 1rem;
  }
  .toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 1.5rem;
  }
  .search-bar {
    width: 100%;
  }
}
@media (max-width: 768px) {
  .admin-main-content {
    padding: 1.5rem;
  }
  .sidebar-header {
    display: none;
  }
  .kpi-grid {
    grid-template-columns: 1fr;
  } /* MODIFICADO: 1 columna en móvil */
  .form-grid,
  .form-row {
    grid-template-columns: 1fr;
  }
  .form-row {
    margin-bottom: 0;
  }
  .form-row .form-group {
    margin-bottom: 1.5rem;
  }
  .modal-content {
    margin: 5% auto;
  }
  .back-to-home {
    position: static;
    text-align: center;
    margin-bottom: 1.5rem;
  } /* Se integra en el flujo */
}

/* =============================================================================
   13. ADMIN - CORRECCIONES Y ESTADOS
   ============================================================================= */
.report-chart-card {
  position: relative;
  height: 350px;
}
.report-chart-card canvas {
  max-height: 100%;
  width: auto !important;
  margin: 0 auto;
}
.status.pagado {
  background-color: var(--success-color);
  color: white;
  padding: 5px 10px;
  border-radius: 15px;
  font-weight: bold;
  display: inline-block;
}
.status.pendiente {
  background-color: var(--error-color);
  color: white;
  padding: 5px 10px;
  border-radius: 15px;
  font-weight: bold;
  display: inline-block;
}

/* =============================================================================
   14. ADMIN - COMPONENTES REUTILIZABLES
   ============================================================================= */

/* --- Estilo unificado para tablas modernas (Inventario, Reportes) --- */
.card-table.modern-table {
  padding: 1.5rem;
}
.modern-table table {
  border-collapse: separate;
  border-spacing: 0 6px;
}
.modern-table thead th {
  border: none;
  background: var(
    --background-card
  ); /* Fondo sólido para que no se vea el texto al hacer scroll */
  position: sticky; /* Cabecera fija moderna */
  top: 0;
  z-index: 5;
}
.modern-table tbody tr {
  background-color: #ffffff;
  border-radius: 8px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
  transition:
    box-shadow 0.2s,
    transform 0.2s;
}
.modern-table tbody tr:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  transform: translateY(-2px);
}
.modern-table td,
.modern-table th {
  border: none;
  padding: 1rem 1.25rem;
}
.modern-table tbody td {
  color: #333;
} /* FIX: Texto oscuro para legibilidad */

/* --- Modal de Abono (Reportes) --- */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(3px);
}
.modal-content.abono-modal {
  background: #ffffff;
  padding: 25px;
  border-radius: 8px;
  width: 90%;
  max-width: 400px;
  position: relative;
  color: #333;
  box-shadow: 0 5px 20px rgba(0, 0, 0, 0.3);
}
.modal-close {
  position: absolute;
  top: 10px;
  right: 15px;
  font-size: 24px;
  font-weight: bold;
  cursor: pointer;
  color: #aaa;
  transition: color 0.2s;
}
.modal-close:hover {
  color: #333;
}
#abono-details {
  margin-bottom: 15px;
  padding-bottom: 10px;
  border-bottom: 1px solid #eee;
  line-height: 1.5;
}

/* --- Toggle Switch (Reportes) --- */
.toggle-group {
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
}
.toggle-label {
  color: var(--text-secondary);
}
.switch {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 28px;
}
.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #4a4a4a;
  transition: 0.4s;
}
.slider.round {
  border-radius: 28px;
}
.slider.round:before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  transition: 0.4s;
  border-radius: 50%;
}
input:checked + .slider {
  background-color: var(--success-color);
}
input:checked + .slider:before {
  transform: translateX(22px);
}

/* =============================================================================
   15. ADMIN - BOTONES FLOTANTES
   ============================================================================= */
.floating-buttons-container {
  position: fixed;
  bottom: 25px;
  right: 25px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn-flotante {
  border: none;
  outline: none;
  cursor: pointer;
  border-radius: 50%;
  width: 50px;
  height: 50px;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  transition:
    transform 0.3s,
    background-color 0.3s;
}

.btn-flotante:hover {
  transform: translateY(-3px);
}

.btn-flotante-top {
  background-color: var(--primary-color);
  display: none; /* Gestionado por JS */
}

.btn-flotante-top:hover {
  background-color: #6d0000;
}

.btn-flotante-logout {
  background-color: var(--error-color);
}

.btn-flotante-logout:hover {
  background-color: #c53030;
}
