/* ==============================================================================
   AlertNicAr - Hoja de Estilos CSS Premium (Vanilla CSS)
   ============================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Outfit:wght@400;500;600;700;800&display=swap');

/* Variables y Sistema de Diseño */
:root {
  /* Modo Oscuro (Por defecto) */
  --bg-color: #0b0f19;
  --bg-gradient: linear-gradient(135deg, #0b0f19 0%, #111827 100%);
  --card-bg: rgba(22, 30, 49, 0.7);
  --card-border: rgba(255, 255, 255, 0.08);
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --border-color: rgba(255, 255, 255, 0.08);
  
  --primary-color: #2563eb;
  --primary-gradient: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
  --accent-color: #7c3aed;
  --accent-gradient: linear-gradient(135deg, #a78bfa 0%, #6d28d9 100%);
  
  --success-color: #10b981;
  --warning-color: #f59e0b;
  --danger-color: #ef4444;
  
  --glow-shadow: 0 0 20px rgba(59, 130, 246, 0.25);
  --card-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.5);
  
  --font-title: 'Outfit', sans-serif;
  --font-body: 'Inter', sans-serif;
  
  --nav-height: 64px;
}

[data-theme="light"] {
  /* Modo Claro */
  --bg-color: #f8fafc;
  --bg-gradient: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
  --card-bg: rgba(255, 255, 255, 0.85);
  --card-border: rgba(0, 0, 0, 0.06);
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --border-color: rgba(0, 0, 0, 0.08);
  
  --primary-color: #1d4ed8;
  --primary-gradient: linear-gradient(135deg, #2563eb 0%, #1e40af 100%);
  --accent-color: #6d28d9;
  --accent-gradient: linear-gradient(135deg, #8b5cf6 0%, #5b21b6 100%);
  
  --glow-shadow: 0 0 20px rgba(37, 99, 235, 0.15);
  --card-shadow: 0 10px 25px -10px rgba(15, 23, 42, 0.08);
}

/* Reset de Estilos */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-body);
  background: var(--bg-gradient);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  line-height: 1.5;
  transition: background 0.3s ease, color 0.3s ease;
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-title);
  font-weight: 700;
  letter-spacing: -0.02em;
}

/* Contenedores y Estructura Principal */
.app-container {
  display: flex;
  min-height: 100vh;
}

/* Sidebar para Escritorio (Oculto en Móviles) */
.sidebar {
  width: 260px;
  background: var(--card-bg);
  border-right: 1px solid var(--card-border);
  backdrop-filter: blur(10px);
  padding: 24px;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 100;
  transition: all 0.3s ease;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 32px;
}

.brand img {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  box-shadow: var(--glow-shadow);
}

.brand-name {
  font-size: 1.35rem;
  font-weight: 800;
  background: linear-gradient(135deg, #3b82f6 0%, #a78bfa 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.nav-links {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.nav-item a {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 16px;
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.95rem;
  border-radius: 12px;
  transition: all 0.2s ease;
}

.nav-item a:hover, 
.nav-item.active a {
  color: var(--text-primary);
  background: rgba(59, 130, 246, 0.1);
}

.nav-item.active a {
  border-left: 3px solid var(--primary-color);
  background: rgba(59, 130, 246, 0.15);
}

/* Barra de Navegación Inferior (Fija en Móviles) */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  background: var(--card-bg);
  border-top: 1px solid var(--card-border);
  backdrop-filter: blur(20px);
  z-index: 100;
  justify-content: space-around;
  align-items: center;
  padding-bottom: env(safe-area-inset-bottom);
}

.bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  text-decoration: none;
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 500;
  transition: all 0.2s ease;
}

.bottom-nav-item i {
  font-size: 1.25rem;
}

.bottom-nav-item.active,
.bottom-nav-item:hover {
  color: var(--primary-color);
  transform: translateY(-2px);
}

/* Área de Contenido Principal */
.main-content {
  flex: 1;
  padding: 32px;
  margin-left: 260px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding-bottom: 48px;
}

/* Vistas de la SPA */
.view-section {
  display: none;
  animation: fadeIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.view-section.active {
  display: block;
}

/* Estilos de Tarjetas (Glassmorphism) */
.card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 20px;
  padding: 24px;
  box-shadow: var(--card-shadow);
  backdrop-filter: blur(10px);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.card:hover {
  box-shadow: 0 15px 35px -12px rgba(0, 0, 0, 0.15);
}

.card-title {
  font-size: 1.15rem;
  margin-bottom: 16px;
  color: var(--text-primary);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* Estilos del Dashboard */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
  margin-bottom: 24px;
}

.kpi-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 130px;
}

.kpi-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.kpi-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
}

.kpi-value {
  font-size: 2.2rem;
  font-weight: 800;
  font-family: var(--font-title);
  color: var(--text-primary);
  line-height: 1.2;
  margin: 10px 0 4px 0;
}

.kpi-subtext {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Gráficos del Dashboard */
.charts-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 24px;
}

/* Explorador de Datos y Custom DataTables */
.table-container {
  overflow-x: auto;
  margin-top: 16px;
}

/* Sobrescribir DataTables para que coincida con la UI Premium */
.dataTables_wrapper {
  color: var(--text-primary) !important;
}

table.dataTable {
  border-collapse: collapse !important;
  width: 100% !important;
  margin-top: 12px !important;
  margin-bottom: 12px !important;
}

table.dataTable thead th {
  background: rgba(59, 130, 246, 0.05) !important;
  border-bottom: 1px solid var(--border-color) !important;
  color: var(--text-primary) !important;
  font-family: var(--font-title);
  font-weight: 600;
  padding: 14px 16px !important;
  text-align: left;
}

table.dataTable tbody td {
  border-bottom: 1px solid var(--border-color) !important;
  padding: 12px 16px !important;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

table.dataTable tbody tr {
  background-color: transparent !important;
}

table.dataTable tbody tr:hover {
  background-color: rgba(255, 255, 255, 0.02) !important;
}

.dataTables_info, .dataTables_paginate {
  color: var(--text-secondary) !important;
  margin-top: 16px;
}

.paginate_button {
  background: transparent !important;
  border: 1px solid var(--card-border) !important;
  color: var(--text-secondary) !important;
  border-radius: 8px !important;
  padding: 6px 12px !important;
  margin: 0 4px !important;
  transition: all 0.2s;
}

.paginate_button:hover, .paginate_button.current {
  background: var(--primary-gradient) !important;
  border-color: transparent !important;
  color: var(--text-primary) !important;
  box-shadow: var(--glow-shadow);
}

.dataTables_filter input, .dataTables_length select {
  background: rgba(255, 255, 255, 0.05) !important;
  border: 1px solid var(--card-border) !important;
  color: var(--text-primary) !important;
  border-radius: 8px;
  padding: 6px 12px;
  outline: none;
}

/* Modales y Diálogos */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(5, 8, 16, 0.75);
  backdrop-filter: blur(5px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-content {
  width: 90%;
  max-width: 500px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 24px;
  box-shadow: var(--card-shadow);
  padding: 32px;
  transform: translateY(20px);
  transition: transform 0.3s ease;
  backdrop-filter: blur(20px);
}

.modal-overlay.active .modal-content {
  transform: translateY(0);
}

/* Formulario e Inputs Modernos */
.form-group {
  margin-bottom: 20px;
}

.form-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.form-control {
  width: 100%;
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 0.95rem;
  outline: none;
  transition: all 0.2s ease;
}

.form-control:focus {
  border-color: var(--primary-color);
  box-shadow: var(--glow-shadow);
  background: rgba(255, 255, 255, 0.08);
}

/* Botones con estilo */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px 24px;
  font-size: 0.95rem;
  font-weight: 600;
  border-radius: 12px;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: var(--font-title);
  width: 100%;
}

.btn-primary {
  background: var(--primary-gradient);
  color: #ffffff;
  box-shadow: var(--glow-shadow);
}

.btn-primary:hover {
  transform: translateY(-2px);
  filter: brightness(1.1);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
  border: 1px solid var(--card-border);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.12);
}

.btn-danger {
  background: var(--danger-color);
  color: white;
}

.btn-danger:hover {
  filter: brightness(1.1);
}

/* Switch de Selección / Toggle Switch */
.switch-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-color);
}

.switch {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 26px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(255, 255, 255, 0.15);
  transition: .3s;
  border-radius: 34px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  transition: .3s;
  border-radius: 50%;
}

input:checked + .slider {
  background: var(--primary-gradient);
}

input:checked + .slider:before {
  transform: translateX(22px);
}

/* Vista de Login dedicada */
.login-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  max-width: 420px;
  width: 100%;
  text-align: center;
}

.login-logo {
  width: 72px;
  height: 72px;
  margin: 0 auto 20px auto;
  border-radius: 18px;
  box-shadow: var(--glow-shadow);
}

/* Estilos de Filtros de Búsqueda Avanzados */
.filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

/* iOS PWA Install Carrusel */
.carousel {
  position: relative;
  overflow: hidden;
  width: 100%;
  margin-top: 16px;
}

.carousel-track-container {
  overflow: hidden;
}

.carousel-track {
  display: flex;
  transition: transform 0.3s ease;
}

.carousel-slide {
  min-width: 100%;
  text-align: center;
  padding: 10px 20px;
}

.carousel-slide img {
  max-height: 150px;
  margin-top: 12px;
  border-radius: 8px;
}

.carousel-nav {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 16px;
}

.carousel-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  border: none;
  cursor: pointer;
}

.carousel-dot.active {
  background: var(--primary-color);
  width: 16px;
  border-radius: 4px;
}

/* Keyframes y Animaciones */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Adaptabilidad para Dispositivos (Responsive) */
@media (max-width: 768px) {
  .app-container {
    max-width: 100vw;
    overflow-x: hidden;
  }

  .sidebar {
    display: none;
  }
  
  .bottom-nav {
    display: flex;
  }
  
  .main-content {
    margin-left: 0;
    padding: 16px;
    padding-bottom: 90px;
    width: 100%;
    min-width: 0; /* Prevenir desborde en flexbox */
    overflow-x: hidden;
  }
  
  .charts-grid {
    grid-template-columns: 1fr;
  }
  
  .view-header {
    margin-top: 10px;
  }

  /* Reducir padding de las tarjetas para ganar espacio en móvil */
  .card {
    padding: 16px !important;
    max-width: 100%;
    overflow: hidden;
  }

  /* Forzar filtros a una sola fila por campo en móviles */
  .filter-grid {
    grid-template-columns: 1fr !important;
    gap: 12px;
  }

  /* Optimización para DataTables en Móviles */
  .table-container {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-top: 12px;
    border-radius: 8px;
  }

  table.dataTable {
    font-size: 0.75rem !important;
    width: 100% !important;
  }

  table.dataTable thead th {
    padding: 8px 6px !important;
    font-size: 0.75rem !important;
  }

  table.dataTable tbody td {
    padding: 8px 6px !important;
    font-size: 0.72rem !important;
    white-space: nowrap;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* Apilar controles de DataTables (búsqueda y paginación) de forma vertical */
  .dataTables_wrapper .dataTables_length,
  .dataTables_wrapper .dataTables_filter,
  .dataTables_wrapper .dataTables_info,
  .dataTables_wrapper .dataTables_paginate {
    float: none !important;
    text-align: center !important;
    width: 100% !important;
    margin: 8px 0 !important;
    font-size: 0.8rem;
  }

  .dataTables_wrapper .dataTables_filter input {
    width: 100% !important;
    margin-left: 0 !important;
    margin-top: 4px;
  }

  /* Ocultar columnas secundarias en móvil para evitar desborde */
  table.dataTable th:nth-child(1), /* ID */
  table.dataTable td:nth-child(1),
  table.dataTable th:nth-child(5), /* Nº Doc */
  table.dataTable td:nth-child(5),
  table.dataTable th:nth-child(6), /* Fecha Registro */
  table.dataTable td:nth-child(6) {
    display: none !important;
  }
}
