/*
 * Sprint Sidebar Universal — estilos del sidebar lateral global.
 *
 * Sustituye los prefijos .erp-shell / .erp-sidebar* / .erp-offcanvas* que
 * vivían exclusivamente en layouts.erp. Ahora cubre toda la app autenticada
 * (paths whitelisted por Helper::isAppPanelRoute).
 *
 * Las CSS custom properties --tapyns-navbar-h y --tapyns-sticky-offset se
 * definen en includes/css_general.blade.php — heredamos sin redeclarar.
 *
 * Convenciones:
 *   .app-shell                — wrapper full-height con flex row
 *   .app-sidebar-col          — columna fija 260px desktop (≥992px)
 *   .app-sidebar-sticky       — el contenedor sticky scrollable
 *   .app-sidebar              — el <nav> interno (cards + links)
 *   .app-sidebar-card         — agrupa items por sección
 *   .app-sidebar-card-header  — label uppercase de la sección
 *   .app-sidebar-link         — cada item navegable
 *   .app-sidebar-badge        — contador opcional al final del link
 *   .app-sidebar-offcanvas    — drawer mobile (<992px)
 *   .app-sidebar-backdrop     — overlay del drawer mobile
 *   .app-sidebar-toggle       — botón hamburger que abre el drawer
 */

/* =====================================================================
 *  Shell unificado
 * ===================================================================== */

.app-shell {
  min-height: calc(100vh - var(--tapyns-navbar-h, 80px));
}

.app-shell-row {
  display: flex;
  flex-wrap: nowrap;
  min-height: calc(100vh - var(--tapyns-navbar-h, 80px));
  margin: 0;
}

.app-sidebar-col {
  width: 260px;
  flex: 0 0 260px;
  border-right: 1px solid #e8eaf2;
  background: #fafbfd;
  padding: 0;
}

.app-sidebar-sticky {
  position: sticky;
  top: var(--tapyns-sticky-offset, 90px);
  max-height: calc(100vh - var(--tapyns-sticky-offset, 90px));
  overflow-y: auto;
  padding: 16px 12px 24px;
}

.app-sidebar-sticky::-webkit-scrollbar { width: 5px; }
.app-sidebar-sticky::-webkit-scrollbar-thumb { background-color: #cfd4e3; border-radius: 3px; }

.app-main-col {
  flex: 1 1 auto;
  min-width: 0;
  padding: 0;
}

.app-main-inner {
  padding: 20px 24px 40px;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

@media (max-width: 991.98px) {
  .app-sidebar-col { display: none; }
  .app-main-inner { padding: 12px 14px 32px; }
}

/* =====================================================================
 *  Sidebar — cards + items
 * ===================================================================== */

.app-sidebar .app-sidebar-card {
  background: #fff;
  border: 1px solid #e8eaf2;
  border-radius: 12px;
  margin-bottom: 14px;
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.app-sidebar .app-sidebar-card-header {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: #9aa1b4;
  font-weight: 700;
  padding: 10px 14px 6px;
  border-bottom: 1px solid #f1f3f9;
  background: #fcfcfd;
}

.app-sidebar .app-sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  color: #303642;
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  border-bottom: 1px solid #f4f5fa;
  transition: background 0.12s, color 0.12s;
}

.app-sidebar .app-sidebar-link:last-child { border-bottom: 0; }

.app-sidebar .app-sidebar-link i {
  font-size: 16px;
  line-height: 1;
  width: 18px;
  text-align: center;
  color: #6c7383;
  flex-shrink: 0;
}

.app-sidebar .app-sidebar-link:hover {
  background: #f4f8ff;
  color: #0d6efd;
  text-decoration: none;
}
.app-sidebar .app-sidebar-link:hover i { color: #0d6efd; }

.app-sidebar .app-sidebar-link.active {
  background: #0d6efd;
  color: #fff;
  font-weight: 600;
}
.app-sidebar .app-sidebar-link.active i { color: #fff; }

.app-sidebar .app-sidebar-link .app-sidebar-label {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-sidebar .app-sidebar-link .app-sidebar-badge {
  margin-left: auto;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  background: #eef0f7;
  color: #586075;
  font-weight: 700;
}
.app-sidebar .app-sidebar-link.active .app-sidebar-badge {
  background: rgba(255, 255, 255, 0.25);
  color: #fff;
}

/* =====================================================================
 *  Header del main (botón hamburger en mobile)
 * ===================================================================== */

.app-main-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.app-sidebar-toggle {
  display: none;
  background: #fff;
  border: 1px solid #e8eaf2;
  border-radius: 10px;
  padding: 6px 12px;
  color: #586075;
  font-size: 18px;
  cursor: pointer;
}

@media (max-width: 991.98px) {
  .app-sidebar-toggle { display: inline-flex; }
}

/* =====================================================================
 *  Offcanvas drawer mobile (<992px)
 * ===================================================================== */

.app-sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 1050;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.18s ease, visibility 0.18s ease;
}
.app-sidebar-backdrop.open {
  opacity: 1;
  visibility: visible;
}

.app-sidebar-offcanvas {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 280px;
  max-width: 85vw;
  background: #fff;
  z-index: 1051;
  transform: translateX(-100%);
  transition: transform 0.22s ease;
  overflow-y: auto;
  box-shadow: 4px 0 20px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
}
.app-sidebar-offcanvas.open {
  transform: translateX(0);
}

.app-sidebar-offcanvas-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid #e8eaf2;
  background: #fafbfd;
}
.app-sidebar-offcanvas-header h5 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: #212529;
}
.app-sidebar-offcanvas-close {
  background: transparent;
  border: 0;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  color: #586075;
  padding: 0 4px;
}
.app-sidebar-offcanvas-body {
  padding: 14px 12px 24px;
  flex: 1;
}

/* Solo aplica el offcanvas en <992px — en desktop usamos el sidebar fijo. */
@media (min-width: 992px) {
  .app-sidebar-offcanvas,
  .app-sidebar-backdrop {
    display: none !important;
  }
}

/* =====================================================================
 *  Dark mode
 * ===================================================================== */

[data-bs-theme="dark"] .app-sidebar-col {
  background: #14171f;
  border-right-color: #1f2330;
}
[data-bs-theme="dark"] .app-sidebar .app-sidebar-card {
  background: #1a1e29;
  border-color: #1f2330;
  box-shadow: none;
}
[data-bs-theme="dark"] .app-sidebar .app-sidebar-card-header {
  background: #181b25;
  color: #6b7287;
  border-bottom-color: #1f2330;
}
[data-bs-theme="dark"] .app-sidebar .app-sidebar-link {
  color: #cfd2db;
  border-bottom-color: #1f2330;
}
[data-bs-theme="dark"] .app-sidebar .app-sidebar-link i { color: #7d8298; }
[data-bs-theme="dark"] .app-sidebar .app-sidebar-link:hover {
  background: #1f263a;
  color: #6ea8fe;
}
[data-bs-theme="dark"] .app-sidebar .app-sidebar-link:hover i { color: #6ea8fe; }
[data-bs-theme="dark"] .app-sidebar .app-sidebar-link.active {
  background: #0d6efd;
  color: #fff;
}
[data-bs-theme="dark"] .app-sidebar-offcanvas { background: #14171f; }
[data-bs-theme="dark"] .app-sidebar-offcanvas-header {
  background: #181b25;
  border-bottom-color: #1f2330;
}
[data-bs-theme="dark"] .app-sidebar-offcanvas-header h5 { color: #f1f1f1; }
[data-bs-theme="dark"] .app-sidebar-toggle {
  background: #1a1e29;
  border-color: #1f2330;
  color: #cfd2db;
}
