/* =========================================
   1. GLOBAL VARIABLES & RESET
   ========================================= */
:root {
  --primary-color: #1f295b;
  --secondary-color: #bca75b;
  --accent-color: #11998e;
  --sidebar-width: 260px;
  --sidebar-bg: #0f1624;
  --sidebar-hover: rgba(255,255,255,0.07);
  --sidebar-active: rgba(31,41,91,0.9);
  --text-main: #2c3e50;
  --text-secondary: #7f8c8d;
  --bg-body: #f0f2f8;
  --bg-card: #ffffff;
  --shadow-soft: 0 4px 24px rgba(0,0,0,0.07);
  --shadow-hover: 0 12px 40px rgba(0,0,0,0.13);
  --border-radius: 16px;
  --transition-fast: 0.2s ease;
  --transition-smooth: 0.35s cubic-bezier(0.165, 0.84, 0.44, 1);
}

*, *::before, *::after { box-sizing: border-box; }

html {
  background-color: var(--sidebar-bg);
}

html, body {
  overflow-x: hidden !important;
  width: 100% !important;
  max-width: 100% !important;
  margin: 0 !important;
  padding: 0 !important;
}

body {
  font-family: "Poppins", sans-serif;
  background: var(--sidebar-bg); /* Usar fondo oscuro para proteger rebote de scroll en móviles */
  color: var(--text-main);
  min-height: 100dvh;
}

/* =========================================
   2. SIDEBAR
   ========================================= */
.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  height: 100dvh; /* Altura dinámica para evitar recortes en navegadores móviles */
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  z-index: 1040;
  overflow-y: auto;
  overflow-x: hidden;
  transition: transform var(--transition-smooth);
  scrollbar-width: none;
}
.sidebar::-webkit-scrollbar { display: none; }

/* Logo */
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 28px 24px 20px;
  color: #fff;
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  flex-shrink: 0;
}
.sidebar-logo i {
  color: var(--secondary-color);
  font-size: 1.6rem;
}
.sidebar-logo-text { line-height: 1; }

/* User Card */
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px 16px;
  background: rgba(255,255,255,0.04);
  margin: 0 12px;
  border-radius: 14px;
  flex-shrink: 0;
}
.sidebar-avatar {
  width: 42px; height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary-color), #2c5364);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 1.1rem;
  flex-shrink: 0;
  border: 2px solid rgba(255,255,255,0.15);
}
.sidebar-user-info { overflow: hidden; }
.sidebar-user-name {
  color: #fff;
  font-weight: 600;
  font-size: 0.9rem;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-user-role {
  color: rgba(255,255,255,0.45);
  font-size: 0.72rem;
  text-transform: capitalize;
}

/* Divider */
.sidebar-divider {
  height: 1px;
  background: rgba(255,255,255,0.07);
  margin: 14px 20px;
  flex-shrink: 0;
}

/* Nav */
.sidebar-nav {
  padding: 0 12px;
  flex: 1;
}
.sidebar-section-label {
  color: rgba(255,255,255,0.3);
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  font-weight: 600;
  padding: 10px 12px 4px;
  margin: 0;
}

/* Links */
.sidebar-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 10px;
  color: rgba(255,255,255,0.65);
  text-decoration: none;
  font-size: 0.878rem;
  font-weight: 500;
  transition: all var(--transition-fast);
  margin-bottom: 2px;
  position: relative;
}
.sidebar-link i {
  width: 20px;
  text-align: center;
  font-size: 1rem;
  flex-shrink: 0;
}
.sidebar-link:hover {
  background: var(--sidebar-hover);
  color: #fff;
  text-decoration: none;
}
.sidebar-link.active {
  background: linear-gradient(135deg, var(--primary-color), #2c5364);
  color: #fff;
  box-shadow: 0 4px 15px rgba(31, 41, 91, 0.4);
}
.sidebar-link-cta {
  background: linear-gradient(135deg, #11998e, #38ef7d);
  color: #fff !important;
  margin-top: 6px;
  font-weight: 600;
}
.sidebar-link-cta:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(17, 153, 142, 0.4);
}
.sidebar-link-danger { color: rgba(255,100,100,0.75) !important; }
.sidebar-link-danger:hover { background: rgba(220,53,69,0.15) !important; color: #ff6464 !important; }

/* Badge */
.sidebar-badge {
  background: #e74c3c;
  color: white;
  border-radius: 50px;
  padding: 2px 7px;
  font-size: 0.65rem;
  font-weight: 700;
  margin-left: auto;
  min-width: 20px;
  text-align: center;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Bottom */
.sidebar-bottom {
  padding: 0 12px 24px;
  flex-shrink: 0;
}

/* Overlay (mobile) */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 1030;
  transition: opacity 0.3s;
  opacity: 0;
}
.sidebar-overlay.visible { display: block; opacity: 1; }

/* =========================================
   3. MOBILE TOPBAR
   ========================================= */
.mobile-topbar {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 60px;
  background: var(--sidebar-bg);
  z-index: 1035;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.2);
}
.mobile-brand {
  color: #fff;
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: 1.5px;
}
.mobile-menu-btn {
  background: none;
  border: none;
  color: #fff;
  font-size: 1.3rem;
  cursor: pointer;
  padding: 6px;
}

/* =========================================
   4. PAGE WRAPPER (Content area)
   ========================================= */
.page-wrapper {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  width: calc(100% - var(--sidebar-width));
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  overflow-x: hidden;
  background: var(--bg-body); /* Asignar explícitamente el fondo claro del sistema aquí */
}
.page-content {
  flex: 1;
  width: 100%;
  padding: 28px 32px 20px;
  box-sizing: border-box;
}

/* Slim footer */
.slim-footer {
  background: var(--sidebar-bg);
  color: rgba(255,255,255,0.4);
  font-size: 0.78rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 36px;
  margin-top: auto;
  flex-wrap: wrap;
  gap: 6px;
}

/* =========================================
   5. DASHBOARD HEADER (welcome banner)
   ========================================= */
.dashboard-header {
  background: linear-gradient(135deg, #1f295b 0%, #2c5364 60%, #11998e 100%);
  border-radius: 20px;
  padding: 32px 36px;
  color: white;
  box-shadow: 0 8px 32px rgba(31,41,91,0.35);
  position: relative;
  overflow: hidden;
}
.dashboard-header::before {
  content: '';
  position: absolute;
  top: -40px; right: -40px;
  width: 200px; height: 200px;
  background: rgba(255,255,255,0.05);
  border-radius: 50%;
}
.dashboard-header::after {
  content: '';
  position: absolute;
  bottom: -60px; right: 80px;
  width: 300px; height: 300px;
  background: rgba(255,255,255,0.03);
  border-radius: 50%;
}
.dashboard-header h2 { font-size: clamp(1.3rem, 2.5vw, 1.8rem); font-weight: 700; }
.dashboard-header-content { position: relative; z-index: 1; width: 100%; }
.dashboard-header-content .avatar-light { flex-shrink: 0; }


/* =========================================
   6. CARDS
   ========================================= */
.card {
  border: none;
  border-radius: var(--border-radius);
  background: var(--bg-card);
  box-shadow: var(--shadow-soft);
  transition: var(--transition-smooth);
  overflow: hidden;
}

/* Hover lift for interactive cards */
.hover-lift {
  transition: all var(--transition-smooth);
}
.hover-lift:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-hover);
}

/* Glass KPI cards */
.glass-panel {
  background: #fff !important;
  border-radius: 18px !important;
  box-shadow: var(--shadow-soft) !important;
  border: 1px solid rgba(0,0,0,0.04) !important;
}

/* Stat values */
.stat-value {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.1;
  color: var(--primary-color);
}
.stat-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-weight: 500;
  margin-top: 2px;
}

/* =========================================
   7. AVATAR CIRCLE
   ========================================= */
.avatar-circle {
  width: 44px; height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1rem;
  flex-shrink: 0;
}
.avatar-light {
  background: rgba(255,255,255,0.2);
  color: #fff;
}

/* =========================================
   8. TIMELINE
   ========================================= */
.timeline { position: relative; }

.timeline-item {
  position: relative;
  padding: 14px 14px 14px 44px;
  border-radius: 12px;
  margin-bottom: 10px;
  background: #f8fafc;
  border-left: 3px solid var(--primary-color);
  transition: background var(--transition-fast);
}
.timeline-item:hover { background: #f1f5f9; }
.timeline-item::before {
  content: '';
  position: absolute;
  left: 14px; top: 50%;
  transform: translateY(-50%);
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--primary-color);
}
.timeline-item.success { border-left-color: #11998e; }
.timeline-item.success::before { background: #11998e; }
.timeline-item.warning { border-left-color: #f2c94c; }
.timeline-item.warning::before { background: #f2c94c; }

/* =========================================
   9. BUTTONS
   ========================================= */
.btn-primary {
  background: linear-gradient(135deg, var(--primary-color), #2c5364);
  border: none;
  border-radius: 10px;
  font-weight: 600;
  transition: all var(--transition-fast);
}
.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(31,41,91,0.4);
  background: linear-gradient(135deg, #1f295b, #11998e);
}

/* =========================================
   10. TABLES
   ========================================= */
.table-responsive { border-radius: 12px; overflow: hidden; }
.table thead th {
  background: #f8fafc;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-secondary);
  font-weight: 600;
  border: none;
}
.table tbody tr { transition: background var(--transition-fast); }
.table tbody tr:hover { background: #f8fafc; }

/* =========================================
   11. FORM CONTROLS
   ========================================= */
.form-control, .form-select {
  border: 1.5px solid #e2e8f0;
  border-radius: 10px;
  padding: 10px 14px;
  font-family: "Poppins", sans-serif;
  font-size: 0.9rem;
  transition: all var(--transition-fast);
}
.form-control:focus, .form-select:focus {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(31,41,91,0.12);
}

/* =========================================
   12. ANIMATIONS
   ========================================= */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}
.fade-in-up { animation: fadeInUp 0.5s ease both; }

/* =========================================
   13. RESPONSIVE (Mobile)
   ========================================= */
@media (max-width: 991px) {
  .sidebar {
    transform: translateX(-100%);
    height: 100vh;
    height: 100dvh; /* Altura dinámica en móviles */
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .sidebar-bottom {
    padding-bottom: calc(40px + env(safe-area-inset-bottom, 20px)) !important; /* Espacio adicional inferior para evitar recortes por la barra de navegación del teléfono */
  }
  .mobile-topbar {
    display: flex;
  }
  .page-wrapper {
    margin-left: 0 !important;
    width: 100% !important;
    padding-top: 60px;
  }
  .page-content {
    padding: 20px 16px 16px;
  }
  .slim-footer {
    padding: 14px 16px;
  }
}

/* =========================================
   14. MISC UTILITIES
   ========================================= */
.ls-1 { letter-spacing: 1px; }
.ls-2 { letter-spacing: 1.5px; }
.text-gradient {
  background: linear-gradient(135deg, var(--primary-color), #11998e);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.rounded-20 { border-radius: 20px !important; }
.shadow-custom { box-shadow: var(--shadow-soft) !important; }

/* Legacy compat */
.main-content { padding: 0; width: 100%; }
.container.pe-lg-4 { max-width: 100% !important; padding-right: 0 !important; padding-left: 0 !important; }

/* Ensure rows don't overflow */
.page-content .row { margin-right: 0; margin-left: 0; }
.page-content > .row { width: 100%; }
