/* =========================================
   CrediFast – Custom Styles
   ========================================= */

:root {
  --sidebar-width: 260px;
  --sidebar-collapsed: 70px;
  --brand-primary: #0d6efd;
  --brand-dark: #0a1628;
  --topbar-height: 58px;
  --footer-height: 48px;
}

/* ---- Layout ---- */
html, body {
  height: 100%;
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: #f4f6fb;
}

body {
  min-height: 100vh;
  overflow-x: hidden;
}

#wrapper {
  display: flex;
  min-height: 100vh;
  position: relative;
}

/* ---- Sidebar ---- */
#sidebar {
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--brand-dark);
  color: #c8d3e6;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1040;
  transition: width .25s ease;
  overflow: hidden;
}

#sidebar.collapsed {
  width: var(--sidebar-collapsed);
}

#sidebar .sidebar-brand {
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  padding: 0 1.1rem;
  background: rgba(0,0,0,.25);
  white-space: nowrap;
  overflow: hidden;
}

#sidebar .brand-logo {
  width: 34px;
  height: 34px;
  background: var(--brand-primary);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 1.1rem;
  color: #fff;
}

#sidebar .brand-name {
  font-weight: 700;
  font-size: 1.15rem;
  color: #fff;
  margin-left: .75rem;
  transition: opacity .2s;
}

#sidebar.collapsed .brand-name { opacity: 0; width: 0; }

/* Nav links */
#sidebar .nav-section {
  font-size: .68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #5a7099;
  padding: .9rem 1.1rem .3rem;
  white-space: nowrap;
  overflow: hidden;
}

#sidebar.collapsed .nav-section { opacity: 0; }

#sidebar .nav-link {
  color: #8fa3c4;
  padding: .55rem 1.1rem;
  border-radius: 0;
  display: flex;
  align-items: center;
  gap: .75rem;
  font-size: .88rem;
  white-space: nowrap;
  overflow: hidden;
  transition: background .15s, color .15s;
  position: relative;
}

#sidebar .nav-link i {
  font-size: 1.1rem;
  flex-shrink: 0;
  width: 24px;
  text-align: center;
}

#sidebar .nav-link:hover {
  background: rgba(255,255,255,.06);
  color: #fff;
}

#sidebar .nav-link.active {
  background: rgba(13,110,253,.18);
  color: #60a5fa;
  font-weight: 600;
}

#sidebar .nav-link.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: #60a5fa;
  border-radius: 0 3px 3px 0;
}

#sidebar.collapsed .nav-link span { display: none; }

/* ---- Sub-menu (Paquetes, Solicitudes, etc.) ---- */
#sidebar .nav-group { margin: 0; }

#sidebar .nav-group-toggle {
  width: 100%;
  background: transparent;
  border: 0;
  text-align: left;
}

#sidebar .nav-group-toggle .collapse-icon {
  transition: transform .2s ease;
  font-size: .75rem;
  opacity: .6;
}

#sidebar .nav-group-toggle[aria-expanded="true"] .collapse-icon,
#sidebar .nav-group .collapse.show ~ .nav-group-toggle .collapse-icon {
  transform: rotate(180deg);
}

#sidebar .nav-group .collapse,
#sidebar .nav-group .collapsing { width: 100%; }

#sidebar .nav-sub,
#sidebar div.nav-sub {
  display: flex !important;
  flex-direction: column !important;
  width: 100%;
  padding: .25rem 0 .5rem 0 !important;
  margin: 0 .5rem 0 1.6rem !important;
  border-left: 1px solid rgba(255,255,255,.10);
  background: rgba(0,0,0,.18);
  border-radius: 0 6px 6px 0;
  list-style: none;
}

#sidebar .nav-sub > .nav-sub-link,
#sidebar a.nav-sub-link {
  display: flex !important;
  width: auto !important;
  align-items: center !important;
  gap: .65rem !important;
  color: #a3b3cf !important;
  text-decoration: none !important;
  font-size: .82rem !important;
  padding: .5rem .85rem !important;
  border-radius: 6px !important;
  margin: 2px .35rem !important;
  white-space: nowrap;
  transition: background .15s, color .15s, padding-left .15s;
  position: relative;
  border-bottom: 0 !important;
}

#sidebar .nav-sub-link i {
  font-size: .95rem;
  width: 18px;
  text-align: center;
  flex-shrink: 0;
  color: #6c83a8;
  transition: color .15s;
}

#sidebar .nav-sub-link:hover {
  background: rgba(255,255,255,.06);
  color: #fff !important;
  padding-left: 1.1rem;
}

#sidebar .nav-sub-link:hover i {
  color: #93b8ff;
}

#sidebar .nav-sub-link.active {
  background: rgba(13,110,253,.20);
  color: #93b8ff !important;
  font-weight: 600;
}

#sidebar .nav-sub-link.active i {
  color: #93b8ff;
}

/* Collapsed state: hide chevrons + sub-menus */
#sidebar.collapsed .nav-group-toggle { padding: .55rem 0; justify-content: center; }

/* Sidebar tooltip on collapsed */
#sidebar.collapsed .nav-link[data-bs-toggle="tooltip"] { }

/* ---- Main content ---- */
#main-content {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: margin-left .25s ease;
  min-width: 0;
  width: auto;
}

#main-content.expanded {
  margin-left: var(--sidebar-collapsed);
}

#main-content > main {
  flex: 1;
  padding: 1.25rem 1.5rem;
  overflow-x: hidden;
}

/* Hide sidebar text/sub-menus when collapsed */
#sidebar.collapsed .brand-text,
#sidebar.collapsed .sidebar-footer .flex-grow-1,
#sidebar.collapsed .sidebar-footer a,
#sidebar.collapsed .nav-link span,
#sidebar.collapsed .collapse-icon,
#sidebar.collapsed .nav-sub { display: none !important; }

#sidebar.collapsed .sidebar-brand { justify-content: center; padding: 0 .25rem; }
#sidebar.collapsed .sidebar-brand .brand-icon { margin: 0 !important; }
#sidebar.collapsed #sidebarToggle {
  margin: 0 !important; padding: .15rem .35rem;
}
#sidebar.collapsed .nav-link { justify-content: center; padding: .55rem 0; }
#sidebar.collapsed .sidebar-footer { padding: .75rem 0 !important; text-align: center; }
#sidebar.collapsed .sidebar-footer .user-avatar { margin: 0 auto; }

/* Floating button to re-expand the sidebar (always visible when collapsed) */
#sidebarExpand {
  display: none;
  position: fixed; top: 14px; left: calc(var(--sidebar-collapsed) - 12px);
  z-index: 1050;
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--brand-primary); color: #fff; border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,.3);
  align-items: center; justify-content: center;
  cursor: pointer; padding: 0; font-size: .8rem; line-height: 1;
}
body.sidebar-is-collapsed #sidebarExpand { display: flex; }

/* ---- Topbar ---- */
#topbar {
  height: var(--topbar-height);
  background: #fff;
  border-bottom: 1px solid #e9ecef;
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 100;
}

#topbar .topbar-title {
  font-weight: 600;
  color: #212529;
}

/* ---- Page body ---- */
.page-body {
  padding: 1.5rem;
  flex: 1;
}

/* ---- Stat cards ---- */
.stat-card {
  border: none;
  border-radius: 14px;
  box-shadow: 0 2px 12px rgba(0,0,0,.06);
  padding: 1.2rem 1.4rem;
  background: #fff;
  transition: transform .15s, box-shadow .15s;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0,0,0,.1);
}

/* KPI cards (clicables) */
a > .kpi-card { cursor: pointer; transition: transform .15s, box-shadow .15s, border-color .15s; }
a:hover > .kpi-card {
  transform: translateY(-3px);
  box-shadow: 0 8px 24px rgba(13,110,253,.12);
  border-color: #93b8ff !important;
}
a > .kpi-card * { color: inherit; }
a > .kpi-card .text-muted { color: #6c757d !important; }
a > .kpi-card .text-danger { color: #dc3545 !important; }
a > .kpi-card .text-success { color: #198754 !important; }
a > .kpi-card .text-dark { color: #212529 !important; }

/* Items de "Últimos Pagos" en dashboard */
.pago-item { transition: background .15s; color: inherit !important; }
.pago-item:hover { background: rgba(13,110,253,.05); }
.pago-item .text-dark { color: #212529 !important; }
.pago-item .text-muted { color: #6c757d !important; }
.pago-item .text-success { color: #198754 !important; }

/* Topbar user (clicable → Mi Perfil) */
.topbar-user { padding: .25rem .5rem; border-radius: 8px; transition: background .15s; }
.topbar-user:hover { background: rgba(13,110,253,.06); }
.topbar-user .text-dark { color: #212529 !important; }
.topbar-user .text-muted { color: #6c757d !important; }

/* Sidebar footer link → Mi Perfil */
.sidebar-footer a { transition: opacity .15s; }
.sidebar-footer a:hover { opacity: .85; }

.stat-card .stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
}

.stat-card .stat-value {
  font-size: 1.7rem;
  font-weight: 700;
  line-height: 1.2;
}

.stat-card .stat-label {
  font-size: .8rem;
  color: #6c757d;
}

/* ---- Badges ---- */
.badge { font-weight: 500; }

/* ---- Tables ---- */
.table > :not(caption) > * > * { padding: .6rem .75rem; }

.table thead th {
  font-size: .78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: #6c757d;
}

/* ---- Cards ---- */
.card { border-radius: 12px !important; }

/* ---- Mobile overlay ---- */
#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 1039;
}

#sidebar-overlay.show { display: block; }

/* ---- Alerts / Toasts ---- */
.alert { border-radius: 10px; font-size: .88rem; }

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #c1c9d6; border-radius: 6px; }

/* ---- Login page ---- */
.login-bg {
  min-height: 100vh;
  background: linear-gradient(135deg, #0a1628 0%, #0d6efd 100%);
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  width: 100%;
  max-width: 420px;
  border-radius: 20px !important;
  box-shadow: 0 20px 60px rgba(0,0,0,.3) !important;
}

/* ---- Footer ---- */
#app-footer {
  background: linear-gradient(135deg, var(--brand-dark) 0%, #122040 60%, #0d3b7a 100%);
  border-top: 3px solid var(--brand-primary);
  padding: .9rem 1.5rem;
  font-size: .78rem;
  color: #8fa3c4;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .75rem;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
}

/* Decoración fondo footer */
#app-footer::before {
  content: '';
  position: absolute;
  top: -30px; right: -30px;
  width: 120px; height: 120px;
  border-radius: 50%;
  background: rgba(13,110,253,.12);
  pointer-events: none;
}
#app-footer::after {
  content: '';
  position: absolute;
  bottom: -20px; left: 40%;
  width: 80px; height: 80px;
  border-radius: 50%;
  background: rgba(255,255,255,.04);
  pointer-events: none;
}

#app-footer .footer-left {
  display: flex;
  align-items: center;
  gap: .75rem;
  flex-wrap: wrap;
}

#app-footer .footer-icon-wrap {
  width: 32px; height: 32px;
  background: var(--brand-primary);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(13,110,253,.4);
}

#app-footer .footer-brand {
  font-weight: 700;
  font-size: .9rem;
  color: #fff;
  text-decoration: none;
  letter-spacing: .02em;
  transition: color .15s;
}
#app-footer .footer-brand:hover { color: #60a5fa; }

#app-footer .footer-sep {
  width: 1px; height: 16px;
  background: rgba(255,255,255,.15);
  flex-shrink: 0;
}

#app-footer .footer-copy {
  color: #5a7099;
  font-size: .72rem;
}

#app-footer .footer-links {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-wrap: wrap;
}

#app-footer .footer-links a {
  color: #5a7099;
  text-decoration: none;
  display: flex; align-items: center; gap: .3rem;
  padding: .2rem .55rem;
  border-radius: 6px;
  font-size: .75rem;
  transition: background .15s, color .15s;
  border: 1px solid transparent;
}
#app-footer .footer-links a:hover {
  color: #93b8ff;
  background: rgba(255,255,255,.06);
  border-color: rgba(255,255,255,.08);
}

#app-footer .footer-status {
  display: flex; align-items: center; gap: .35rem;
  font-size: .72rem;
  color: #2dce89;
  background: rgba(45,206,137,.1);
  border: 1px solid rgba(45,206,137,.25);
  border-radius: 20px;
  padding: .2rem .65rem;
  white-space: nowrap;
}

#app-footer .footer-status .dot {
  width: 7px; height: 7px;
  background: #2dce89;
  border-radius: 50%;
  animation: pulse-dot 2s infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: .5; transform: scale(.7); }
}

/* ---- QR por cuota ---- */
.qr-cuota-img {
  border: 3px solid #e9ecef;
  border-radius: 12px;
  padding: .5rem;
  background: #fff;
}

.qr-badge-usado {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%) rotate(-20deg);
  background: rgba(220,53,69,.85);
  color: #fff;
  font-weight: 700;
  font-size: 1.1rem;
  padding: .4rem 1rem;
  border-radius: 6px;
  pointer-events: none;
  letter-spacing: .05em;
}

/* ---- Responsive ---- */

/* Tablet landscape → sidebar colapsa automáticamente */
@media (max-width: 1199.98px) {
  :root { --sidebar-width: 230px; }
}

/* Tablet / móvil → sidebar fuera de pantalla, toggle manual */
@media (max-width: 991.98px) {
  #sidebar {
    left: calc(-1 * var(--sidebar-width));
    transition: left .25s ease, width .25s ease;
    width: var(--sidebar-width) !important;
  }

  #sidebar.mobile-open {
    left: 0;
    box-shadow: 4px 0 20px rgba(0,0,0,.25);
  }

  #main-content {
    margin-left: 0 !important;
    width: 100%;
  }

  #main-content > main {
    padding: 1rem;
  }

  #sidebarExpand { display: none !important; }

  #app-footer {
    padding: .75rem 1rem;
    gap: .5rem;
  }
  #app-footer .footer-copy { font-size: .68rem; }
}

/* Móvil pequeño */
@media (max-width: 575.98px) {
  #topbar { padding: 0 .75rem; gap: .5rem; }

  #main-content > main { padding: .75rem .6rem; }

  .stat-card { padding: .9rem 1rem; }
  .stat-card .stat-value { font-size: 1.35rem; }

  .table-responsive { font-size: .82rem; }

  /* Ocultar columnas secundarias en tablas en móvil */
  .table .d-none-xs { display: none !important; }

  .card { border-radius: 10px !important; }

  /* Formularios a pantalla completa */
  .card[style*="max-width"] { max-width: 100% !important; }
}

/* Mantener topbar sticky al hacer scroll */
#topbar {
  position: sticky;
  top: 0;
  z-index: 100;
}

/* Main content ocupa el ancho restante y permite scroll vertical */
#main-content {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  height: 100vh;
}

#main-content > main {
  flex: 1 0 auto;
}

/* Sidebar scroll interno */
#sidebar .sidebar-nav {
  overflow-y: auto;
  overflow-x: hidden;
  flex: 1 1 0;
  min-height: 0;
  /* Scrollbar delgada pero visible en el sidebar */
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.35) rgba(255,255,255,.06);
}
#sidebar .sidebar-nav::-webkit-scrollbar { width: 8px; }
#sidebar .sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.35); border-radius: 4px; }
#sidebar .sidebar-nav::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,.55); }
#sidebar .sidebar-nav::-webkit-scrollbar-track { background: rgba(255,255,255,.06); }

/* Footer del sidebar siempre visible al fondo */
#sidebar .sidebar-footer {
  flex-shrink: 0;
}

/* =========================================
   Cabecera de tablas coloreada + DataTables
   ========================================= */
.table > thead > tr > th,
.table > thead > tr > td {
  background-color: #1e3a8a !important;   /* azul oscuro */
  color: #ffffff !important;
  border-color: #1e3a8a !important;
  font-weight: 600;
  vertical-align: middle;
  white-space: nowrap;
}
/* Flechas de orden de DataTables visibles sobre el fondo oscuro */
table.dataTable > thead th.sorting:before,  table.dataTable > thead th.sorting:after,
table.dataTable > thead th.sorting_asc:before,  table.dataTable > thead th.sorting_asc:after,
table.dataTable > thead th.sorting_desc:before, table.dataTable > thead th.sorting_desc:after {
  color: #ffffff !important;
  opacity: .55;
}
table.dataTable > thead th.sorting_asc:after,
table.dataTable > thead th.sorting_desc:before { opacity: 1 !important; }

/* Controles (buscar, mostrar N, info, paginación) */
.dataTables_wrapper { padding-top: .25rem; }
.dataTables_wrapper .dataTables_filter input { border-radius: .5rem; }
.dataTables_wrapper .dataTables_length select { border-radius: .5rem; min-width: 4.5rem; }
.dataTables_wrapper .row { align-items: center; margin: 0; }
.dataTables_wrapper .dataTables_paginate .page-item.active .page-link {
  background-color: #1e3a8a; border-color: #1e3a8a;
}
.dataTables_wrapper .dataTables_info { padding-top: .75rem; font-size: .85rem; color: #6c757d; }
