/* ==========================================================================
   Variables Globales & Paleta Clara Elegante
   ========================================================================== */
:root {
  /* Anchos de layout */
  --sidebar-width: 220px;
  --sidebar-collapsed-width: 58px;
  --header-height: 48px;
  --footer-height: 36px;

  /* Colores primarios y neutros claros (Contraste HD) */
  --bg-main: #f0f2f5;
  --bg-surface: #ffffff;
  --border-color: #cbd5e1;
  --border-hover: #94a3b8;

  /* Degradado del Sidebar (Slate Corporativo) */
  --sidebar-bg-start: #0f172a;
  --sidebar-bg-end: #1e293b;
  --sidebar-border: rgba(255, 255, 255, 0.08);
  --sidebar-text: #94a3b8;
  --sidebar-text-hover: #ffffff;
  --sidebar-accent: #38bdf8;

  /* Texto */
  --text-main: #1e293b;
  --text-muted: #64748b;
  --text-light: #94a3b8;

  /* Acentos */
  --primary: #2563eb;
  --primary-subtle: #eff6ff;
  --primary-hover: #1d4ed8;

  /* Tipografía compacta */
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-size-base: 13px;
  --font-size-sm: 11px;
  --font-size-xs: 10px;
  --font-size-icon: 18px;

  /* Sombras y Transiciones */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -1px rgba(0, 0, 0, 0.04);
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Base Reset */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  color: var(--text-main);
  background-color: var(--bg-main);
  height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ==========================================================================
   Layout Principal (Flexbox)
   ========================================================================== */
.layout-wrapper {
  display: flex;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

/* ==========================================================================
   Sidebar (Compacto con Degradado Elegante)
   ========================================================================== */

.sidebar {
  width: var(--sidebar-width);
  height: 100vh; /* Se asegura de tomar toda la altura vertical del dispositivo */
  height: 100dvh; /* Soporte para navegadores móviles con barra dinámica */
  background: linear-gradient(180deg, var(--sidebar-bg-start) 0%, var(--sidebar-bg-end) 100%);
  border-right: 1px solid rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
  transition: transform var(--transition), width var(--transition), left var(--transition);
  z-index: 100;
  flex-shrink: 0;
  box-shadow: 2px 0 8px rgba(0, 0, 0, 0.12);
}

/* Sidebar Header */
.sidebar-header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  padding: 0 14px;
  border-bottom: 1px solid var(--sidebar-border);
  gap: 10px;
  overflow: hidden;
  white-space: nowrap;
}

.brand-logo {
  min-width: 28px;
  height: 28px;
  background-color: var(--primary);
  color: #fff;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.brand-info {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: opacity var(--transition);
}

.company-name {
  font-weight: 700;
  font-size: 12px;
  color: #ffffff;
  line-height: 1.2;
  text-overflow: ellipsis;
  overflow: hidden;
  letter-spacing: 0.3px;
}

.company-sub {
  font-size: var(--font-size-xs);
  color: var(--sidebar-text);
}

/* Sidebar Nav */
.sidebar-nav {
  flex: 1;
  padding: 8px;
  overflow-y: auto;
  overflow-x: hidden;
}

.nav-section-label {
  font-size: var(--font-size-xs);
  font-weight: 700;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  padding: 10px 8px 4px 8px;
  white-space: nowrap;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  color: var(--sidebar-text);
  text-decoration: none;
  border-radius: 5px;
  margin-bottom: 2px;
  transition: var(--transition);
  white-space: nowrap;
  height: 32px;
}

.nav-item i {
  font-size: var(--font-size-icon);
  min-width: 20px;
  text-align: center;
  transition: var(--transition);
}

.nav-text {
  font-size: 12.5px;
  font-weight: 500;
}

.nav-item:hover {
  background-color: rgba(255, 255, 255, 0.08);
  color: var(--sidebar-text-hover);
}

.nav-item:hover i {
  color: var(--sidebar-accent);
}

.nav-item.active {
  background: linear-gradient(90deg, rgba(37, 99, 235, 0.35) 0%, rgba(37, 99, 235, 0.12) 100%);
  color: #ffffff;
  font-weight: 600;
  border-left: 3px solid var(--sidebar-accent);
}

.nav-item.active i {
  color: var(--sidebar-accent);
}

/* Sidebar Footer */
.sidebar-footer {
  margin-top: auto; /* Empuja la sección siempre al fondo */
  padding: 8px 12px;
  border-top: 1px solid var(--sidebar-border);
  background-color: rgba(0, 0, 0, 0.15);
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  overflow: hidden;
  flex-shrink: 0; /* IMPIDE QUE EL FOOTER SE APLASTE O DESAPAREZCA */
  min-height: 48px; /* Garantiza espacio suficiente */
}

.user-avatar {
  min-width: 28px;
  height: 28px;
  border-radius: 50%;
  background-color: var(--sidebar-accent);
  color: #0f172a;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.user-details {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

.user-name {
  font-size: 11.5px;
  font-weight: 600;
  color: #ffffff;
  text-overflow: ellipsis;
  overflow: hidden;
}

.user-role {
  font-size: 10px;
  color: var(--sidebar-text);
}

.logout-btn {
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 16px;
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  transition: var(--transition);
}

.logout-btn:hover {
  color: #f87171;
  background-color: rgba(248, 113, 113, 0.1);
}

/* Estado Contraído (Desktop) */
.sidebar.collapsed {
  width: var(--sidebar-collapsed-width);
}

.sidebar.collapsed .brand-info,
.sidebar.collapsed .nav-text,
.sidebar.collapsed .nav-section-label,
.sidebar.collapsed .user-details,
.sidebar.collapsed .logout-btn {
  display: none;
}

.sidebar.collapsed .sidebar-header {
  padding: 0 14px;
  justify-content: center;
}

.sidebar.collapsed .nav-item {
  justify-content: center;
  padding: 6px 0;
  border-left: none;
}

.sidebar.collapsed .sidebar-footer {
  justify-content: center;
}

/* ==========================================================================
   Contenedor Principal (Header, Content, Footer)
   ========================================================================== */
.main-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100%;
  background-color: var(--bg-main);
}

/* Header */
.header {
  height: var(--header-height);
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  box-shadow: var(--shadow-sm);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.toggle-btn {
  background: none;
  border: none;
  font-size: 20px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  transition: var(--transition);
}

.toggle-btn:hover {
  background-color: var(--bg-main);
  color: var(--text-main);
}

.search-box {
  display: flex;
  align-items: center;
  background-color: var(--bg-main);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 4px 8px;
  gap: 6px;
  width: 220px;
}

.search-box i {
  color: var(--text-light);
  font-size: 15px;
}

.search-box input {
  border: none;
  background: none;
  outline: none;
  font-size: 11.5px;
  color: var(--text-main);
  width: 100%;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.action-btn {
  background: none;
  border: none;
  font-size: 18px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 5px;
  border-radius: 4px;
  position: relative;
  display: flex;
  align-items: center;
}

.action-btn:hover {
  background-color: var(--bg-main);
  color: var(--text-main);
}

.action-btn .badge {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 6px;
  height: 6px;
  background-color: #ef4444;
  border-radius: 50%;
}

/* Main Content Workspace */
.content {
  flex: 1;
  padding: 18px 20px;
  overflow-y: auto;
}

.page-header h1 {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: -0.01em;
}

.page-header p {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.grid-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 12px 14px;
  box-shadow: var(--shadow-sm);
}

.card-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
}

.card-value {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-main);
  margin-top: 4px;
}

/* Footer */
.footer {
  height: var(--footer-height);
  background-color: var(--bg-surface);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  font-size: var(--font-size-xs);
  color: var(--text-muted);
}

/* ==========================================================================
   ESTILOS COMPACTOS Y PROFESIONALES PARA TABLAS Y MODALES
   ========================================================================== */
/* CONTENEDOR DE TABLA CON SCROLL HORIZONTAL RESPONSIVO */
.table-container {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  overflow-x: auto; /* Habilita el desplazamiento horizontal en pantallas pequeñas */
  -webkit-overflow-scrolling: touch;
  margin-top: 15px;
  box-shadow: var(--shadow-sm);
  width: 100%;
}

table.data-table {
  width: 100%;
  min-width: 600px; /* Evita que la tabla se aplaste en celulares */
  border-collapse: collapse;
  font-size: 12px;
  text-align: left;
}

table.data-table th, table.data-table td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap; /* Mantiene la información alineada en filas */
}

table.data-table th {
  background: #f8fafc;
  color: var(--text-muted);
  font-weight: 700;
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: 0.5px;
  border-bottom: 2px solid var(--border-color);
}

/* Filas Alternadas (Efecto Zebra Suave) */
table.data-table tbody tr:nth-child(even) {
  background-color: #fafafa;
}

table.data-table tbody tr:hover {
  background-color: #f1f5f9;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 10px;
  font-weight: 600;
  line-height: 1.2;
}

.badge-success { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }
.badge-danger  { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.badge-info    { background: #e0f2fe; color: #0369a1; border: 1px solid #bae6fd; }

.btn-action {
  border: 1px solid transparent;
  background: none;
  cursor: pointer;
  font-size: 16px;
  color: var(--text-muted);
  padding: 2px 5px;
  border-radius: 4px;
  transition: var(--transition);
}

.btn-action:hover {
  color: var(--primary);
  background-color: var(--primary-subtle);
  border-color: rgba(37, 99, 235, 0.2);
}

/* Modales Responsivos */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(2px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 1000;
}

.modal-card {
  background: var(--bg-surface);
  border-radius: 8px;
  border: 1px solid var(--border-color);
  width: 100%;
  max-width: 450px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 20px;
  box-shadow: var(--shadow-md);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-main);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.form-group-full { grid-column: span 2; }

.form-group label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  display: block;
  margin-bottom: 3px;
}

.form-group input, .form-group select {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  font-size: 12px;
  color: var(--text-main);
  background-color: #ffffff;
  outline: none;
  transition: var(--transition);
}

.form-group input:focus, .form-group select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 15px;
  padding-top: 10px;
  border-top: 1px solid var(--border-color);
}

.btn-secondary {
  background: #e2e8f0;
  color: #334155;
  border: 1px solid #cbd5e1;
  padding: 6px 12px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.btn-secondary:hover {
  background: #cbd5e1;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 6px 12px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: 0 1px 3px rgba(37, 99, 235, 0.2);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

/* Matriz de Permisos */
.permisos-matrix {
  max-height: 250px;
  overflow-y: auto;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 10px;
  background-color: #fafafa;
}

.permiso-cat-title {
  font-weight: 700;
  font-size: 10px;
  color: var(--primary);
  margin-top: 8px;
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.permiso-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  margin-bottom: 4px;
}

/* ==========================================================================
   REGLAS MEDIA QUERIES (RESPONSIVIDAD MÓVIL Y TABLET)
   ========================================================================== */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background-color: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(2px);
  z-index: 90;
}

@media (max-width: 768px) {
  /* Sidebar en móvil */
  .sidebar {
    position: fixed;
    left: -100%;
    top: 0;
    bottom: 0;
    width: var(--sidebar-width) !important;
  }

  .sidebar.open {
    left: 0;
  }

  .sidebar-overlay.active {
    display: block;
  }

  .search-box {
    width: 140px;
  }

  /* Encabezado de páginas flexible */
  .page-header {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 10px;
  }

  .page-header button {
    width: 100%;
    justify-content: center;
  }

  /* Formularios de modales pasan a 1 sola columna en móviles */
  .form-grid {
    grid-template-columns: 1fr;
  }

  .form-group-full {
    grid-column: span 1;
  }

  .content {
    padding: 12px;
  }
}

/* ==========================================================================
   BUSCADOR COMPACTO DE TABLAS
   ========================================================================== */
.table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.table-search-box {
  display: flex;
  align-items: center;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 4px 10px;
  gap: 6px;
  width: 260px;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}

.table-search-box:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.table-search-box i {
  color: var(--text-light);
  font-size: 16px;
}

.table-search-box input {
  border: none;
  background: none;
  outline: none;
  font-size: 12px;
  color: var(--text-main);
  width: 100%;
}

@media (max-width: 768px) {
  
  /* 1. SEPARACIÓN Y APILADO DE LA BARRA DE HERRAMIENTAS */
  .table-toolbar {
    display: flex;
    flex-direction: column; /* Pone el buscador arriba y el botón abajo */
    align-items: stretch;
    gap: 10px;              /* Espacio entre el buscador y el botón */
    margin-top: 10px;
    margin-bottom: 12px;
  }

  /* 2. BUSCADOR A ANCHO COMPLETO */
  .table-search-box {
    width: 100% !important;
  }

  .table-search-box input {
    width: 100%;
  }

  /* 3. BOTÓN "NUEVO" A ANCHO COMPLETO */
  .table-toolbar .btn-primary {
    width: 100%;
    justify-content: center;
    padding: 8px 12px; /* Un poco más amplio para facilitar el toque táctil */
  }

  /* ...aquí mantienes tus reglas existentes de .sidebar, .form-grid, etc... */
}
/* Ajustes para SweetAlert2 compacto */
.swal2-compact-toast {
  font-family: var(--font-family) !important;
  font-size: 12px !important;
  padding: 6px 12px !important;
}

.swal2-compact-modal {
  font-family: var(--font-family) !important;
  border-radius: 8px !important;
  padding: 15px !important;
  width: 360px !important;
}

.swal2-compact-modal .swal2-title {
  font-size: 15px !important;
}

.swal2-compact-modal .swal2-html-container {
  font-size: 12px !important;
}

.swal2-compact-modal button {
  font-size: 11.5px !important;
  padding: 6px 12px !important;
}

/* ==========================================================================
   PAGINACIÓN REUTILIZABLE
   ========================================================================== */
.pagination-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-top: none;
  border-bottom-left-radius: 6px;
  border-bottom-right-radius: 6px;
  font-size: 11.5px;
  color: var(--text-muted);
}

.pagination-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pagination-controls {
  display: flex;
  align-items: center;
  gap: 4px;
}

.btn-page {
  background: var(--bg-main);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 11px;
  transition: var(--transition);
}

.btn-page:hover:not(:disabled) {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.btn-page:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-page.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  font-weight: 600;
}

/* Layout Principal */
.prospectos-container {
    padding: 20px;
    font-family: Arial, sans-serif;
}

.table-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    gap: 10px;
}

.filter-group {
    display: flex;
    gap: 10px;
}

/* Tabla */
.custom-table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    border-radius: 8px;
    overflow: hidden;
}

.custom-table th, .custom-table td {
    padding: 12px 15px;
    text-align: left;
    border-bottom: 1px solid #eee;
}

.custom-table th {
    background-color: #1a1a1a;
    color: #fff;
}

/* Badges de Estado */
.badge {
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 0.85rem;
    font-weight: bold;
}
.badge-registrado { background: #e3f2fd; color: #0d47a1; }
.badge-evaluado { background: #fff3cd; color: #856404; }
.badge-activo { background: #d4edda; color: #155724; }

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    display: none;
    justify-content: center;
    align-items: center;
}

.modal-content {
    background: #fff;
    padding: 25px;
    border-radius: 8px;
    width: 400px;
    max-width: 90%;
}