/* ═════════════════════════════════════════════════════════════════════════════
   LunexPOS — Shell de la aplicación (UI-01)
   Sidebar, topbar, contenedor de página, patrón page_shell (macros de
   layout/_page_shell.html), KPIs y toasts. Antes vivía en línea en
   layout/base.html; ahora consume los tokens de lunexpos-ui.css.
   ═════════════════════════════════════════════════════════════════════════════ */

:root {
  --sidebar-width: var(--lx-sidebar-width);
  --sidebar-collapsed-width: var(--lx-sidebar-collapsed-width);
}

html { overflow-y: scroll; }

body {
  margin: 0;
  background: var(--lx-bg);
  color: var(--lx-text);
  overflow-x: hidden;
}

/* ═════════════════════════════════ Sidebar ═══════════════════════════════ */

.sidebar {
  width: var(--sidebar-width);
  height: 100vh;
  height: 100dvh;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--lx-sidebar-bg);
  border-right: 1px solid var(--lx-sidebar-border);
  box-shadow: 4px 0 24px rgba(11, 23, 54, 0.12);
}
body.sidebar-preload .sidebar,
body.sidebar-preload .sidebar *,
body.sidebar-preload .sidebar *::before,
body.sidebar-preload .sidebar *::after {
  transition: none !important;
  animation: none !important;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: var(--lx-topbar-h);
  padding: 0.85rem 1.1rem;
  color: var(--lx-sidebar-text-strong);
  border-bottom: 1px solid var(--lx-sidebar-border);
}
.sidebar .lunexpos-logo {
  --lunexpos-logo-height: 34px;
  --lunexpos-logo-max-width: 180px;
}

/* Marca del tenant: logo subido por la empresa (o su inicial) + nombre. */
.sidebar-empresa-brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  width: 100%;
  min-width: 0;
  color: var(--lx-sidebar-text-strong);
  text-decoration: none;
  line-height: 1.25;
}
.sidebar-empresa-brand:hover { color: #fff; }
.sidebar-brand-mark {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.sidebar-brand-mark--logo {
  background: #fff;
  padding: 3px;
  box-shadow: 0 0 0 1px var(--lx-sidebar-border);
}
.sidebar-brand-mark--logo img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
.sidebar-brand-mark--inicial {
  background: var(--lx-gradient-brand);
  color: #fff;
  font-family: var(--lx-font-display);
  font-weight: 700;
  font-size: 1rem;
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.3);
}
.sidebar-brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.sidebar-empresa-nombre {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
  font-family: var(--lx-font-display);
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}
body.sidebar-collapsed .sidebar-empresa-nombre {
  font-size: 0.8rem;
  -webkit-line-clamp: 3;
}

.sidebar-nav {
  flex: 1;
  min-height: 0;
  padding: 0.85rem 0 1rem;
  overflow-y: scroll;
  scrollbar-width: thin;
  scrollbar-color: rgba(148, 163, 184, 0.35) transparent;
}
.sidebar-nav::-webkit-scrollbar { width: 8px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.28);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
.sidebar-nav::-webkit-scrollbar-thumb:hover { background-color: rgba(148, 163, 184, 0.45); }

.sidebar-search { padding: 0 0.9rem 0.7rem; }
.sidebar-search .input-group-text,
.sidebar-search .form-control {
  background: var(--lx-sidebar-surface);
  border-color: var(--lx-sidebar-border);
  color: var(--lx-sidebar-text-strong);
  font-size: var(--lx-fs-sm);
  min-height: 34px;
}
.sidebar-search .input-group-text { color: var(--lx-sidebar-muted); }
.sidebar-search .form-control::placeholder { color: var(--lx-sidebar-muted); }
.sidebar-search .form-control:focus {
  background: rgba(255, 255, 255, 0.07);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25);
  border-color: rgba(96, 165, 250, 0.6);
}

.nav-section {
  margin: 0.9rem 0 0.35rem;
  padding: 0 1.4rem;
  color: var(--lx-sidebar-muted);
  font-size: var(--lx-fs-2xs);
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.sidebar .nav-link,
.nav-group-header {
  color: var(--lx-sidebar-text);
  width: calc(100% - 1.5rem);
  margin: 0 0.75rem 0.15rem;
  padding: 0.55rem 0.75rem;
  border-radius: var(--lx-radius);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: var(--lx-fs-base);
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: background-color var(--lx-transition), color var(--lx-transition), border-color var(--lx-transition);
  border: 1px solid transparent;
  background: transparent;
  position: relative;
}
.nav-group-header > span {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}
.sidebar .nav-link { padding-right: 2rem; }
.sidebar .nav-link:hover,
.nav-group-header:hover {
  background: var(--lx-sidebar-hover);
  color: #fff;
}
.nav-group.open .nav-group-header {
  color: #fff;
}
.sidebar .nav-link.active {
  background: var(--lx-sidebar-active-bg);
  color: #fff;
  border-color: var(--lx-sidebar-active-border);
  font-weight: 600;
}
.sidebar .nav-link.active::before {
  content: '';
  position: absolute;
  left: -0.75rem;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 20px;
  border-radius: 0 3px 3px 0;
  background: var(--lx-sidebar-active-bar);
  box-shadow: 0 0 12px rgba(34, 211, 238, 0.6);
}
.nav-group-header {
  color: var(--lx-sidebar-text-strong);
  font-weight: 600;
}
.sidebar .nav-link i,
.nav-group-header i {
  min-width: 1.2rem;
  text-align: center;
  font-size: 1rem;
  opacity: 0.9;
}
.nav-group-header .bi-chevron-down {
  font-size: 0.75rem;
  opacity: 0.6;
}

.bg-submenu {
  display: none;
  flex-direction: column;
  gap: 0.05rem;
  margin: 0.1rem 0.75rem 0.4rem 1.6rem;
  padding: 0.2rem 0 0.2rem 0.55rem;
  background: transparent;
  border: 0;
  border-left: 1px solid var(--lx-sidebar-border);
  border-radius: 0;
  animation: fadeIn 0.2s ease;
}
.nav-group.open .bg-submenu { display: flex; }
.bg-submenu .nav-link {
  width: 100%;
  margin: 0;
  padding: 0.45rem 0.65rem;
  color: var(--lx-sidebar-text);
  font-size: var(--lx-fs-sm);
  font-weight: 500;
}
.bg-submenu .nav-link i { font-size: 0.9rem; }
.bg-submenu .nav-link.active {
  background: var(--lx-brand-600);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.35);
}
.bg-submenu .nav-link.active::before { display: none; }

.menu-badge {
  margin-left: auto;
  font-size: 0.62rem;
  border-radius: 999px;
  padding: 0.12rem 0.4rem;
  background: rgba(34, 211, 238, 0.14);
  color: #a5f3fc;
  border: 1px solid rgba(34, 211, 238, 0.3);
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.fav-toggle {
  position: absolute;
  right: 0.45rem;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--lx-sidebar-muted);
  font-size: 0.7rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity var(--lx-transition), color var(--lx-transition);
  cursor: pointer;
  z-index: 3;
}
.sidebar .nav-link:hover .fav-toggle,
.sidebar .nav-link.favorite .fav-toggle { opacity: 1; }
.sidebar .nav-link.favorite .fav-toggle { color: #fbbf24; }
.sidebar .nav-link.favorite { border-color: rgba(251, 191, 36, 0.2); }
.menu-hidden { display: none !important; }
.fav-empty {
  margin: 0 0.9rem 0.6rem;
  color: var(--lx-sidebar-muted);
  font-size: var(--lx-fs-xs);
  border: 1px dashed rgba(148, 163, 184, 0.25);
  border-radius: var(--lx-radius);
  padding: 0.45rem 0.6rem;
}

.sidebar-footer {
  border-top: 1px solid var(--lx-sidebar-border);
  padding: 0.65rem 1rem 0.75rem;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.app-version-badge {
  font-size: var(--lx-fs-2xs);
  color: var(--lx-sidebar-muted);
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.sidebar-footer-link {
  font-size: var(--lx-fs-2xs);
  color: var(--lx-sidebar-muted);
  text-decoration: none;
}
.sidebar-footer-link:hover { color: var(--lx-sidebar-text-strong); }

.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(11, 23, 54, 0.5);
  backdrop-filter: blur(2px);
  z-index: 980;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
body.mobile-menu-open .sidebar-overlay {
  opacity: 1;
  pointer-events: auto;
}

body.sidebar-collapsed .sidebar { width: var(--sidebar-collapsed-width); }
body.sidebar-collapsed .main { margin-left: var(--sidebar-collapsed-width); }
body.sidebar-collapsed .logo { padding: 0.8rem 0.9rem; }
body.sidebar-collapsed .nav-section { font-size: 0.64rem; letter-spacing: 0.1em; }
body.sidebar-collapsed .sidebar .nav-link,
body.sidebar-collapsed .nav-group-header {
  font-size: var(--lx-fs-sm);
  gap: 0.6rem;
  padding-left: 0.65rem;
  padding-right: 1.8rem;
}

.nav-group.open .bi-chevron-down { transform: rotate(180deg); }
.bi-chevron-down { transition: transform 0.2s; }

/* ══════════════════════════════ Main + topbar ════════════════════════════ */

.main {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  max-width: 100%;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: var(--lx-topbar-h);
  padding: 0.6rem 1.5rem;
  background: var(--lx-topbar-bg);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--lx-border);
}
#topbar-page-title {
  font-family: var(--lx-font-display);
  font-size: 1.02rem;
  font-weight: 700;
  letter-spacing: -0.015em;
  color: var(--lx-gray-900);
}
.user-info {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.user-name {
  font-size: var(--lx-fs-sm);
  font-weight: 600;
  color: var(--lx-text-2);
}
.branch-switcher {
  width: clamp(220px, 24vw, 320px);
  min-width: 220px;
  max-width: 320px;
  flex: 0 0 clamp(220px, 24vw, 320px);
}
.branch-switcher .form-select {
  width: 100%;
  background-color: var(--lx-surface-2);
  font-weight: 500;
}
.branch-switcher.is-loading .form-select { cursor: wait; opacity: 0.8; }
body.branch-switching #topbar-user-info { opacity: 0.88; }
.branch-label {
  font-size: var(--lx-fs-sm);
  color: var(--lx-muted);
  max-width: 160px;
}

.menu-toggle-btn {
  border: 1px solid var(--lx-border);
  background: var(--lx-surface);
  color: var(--lx-gray-600);
  border-radius: var(--lx-radius);
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-right: 0.75rem;
  transition: all var(--lx-transition);
  box-shadow: var(--lx-shadow-xs);
}
.menu-toggle-btn:hover {
  border-color: var(--lx-brand-200);
  color: var(--lx-brand-600);
  background: var(--lx-brand-50);
}

.user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--lx-gradient-brand);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--lx-font-display);
  font-size: var(--lx-fs-sm);
  font-weight: 700;
  box-shadow: 0 0 0 2px var(--lx-surface), 0 0 0 3px var(--lx-brand-200);
}

/* ══════════════════════════════ Contenido ════════════════════════════════ */

.page-content {
  position: relative;
  padding: 1.25rem 1.5rem 1.75rem;
  width: 100%;
  max-width: 100%;
  min-height: min(420px, calc(100vh - 7.5rem));
  overflow-x: auto;
}
.page-content-inner { width: 100%; }
.page-content-inner.page-content-enter { animation: fadeIn 0.32s ease forwards; }
.page-content.is-loading .page-content-inner { pointer-events: none; }
.page-content-loading {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 2.5rem 1.5rem;
  gap: 1.25rem;
  background: rgba(244, 246, 250, 0.92);
  backdrop-filter: blur(2px);
}
.page-content-loading[hidden] { display: none !important; }
.page-content-loading-inner {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--lx-gray-600);
  font-size: 0.9rem;
  font-weight: 500;
}
.page-content-skeleton {
  width: min(520px, 100%);
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}
.page-content-skeleton-line {
  height: 0.85rem;
  border-radius: var(--lx-radius);
  background: linear-gradient(90deg, var(--lx-gray-200) 0%, var(--lx-gray-100) 50%, var(--lx-gray-200) 100%);
  background-size: 200% 100%;
  animation: skeletonShimmer 1.2s ease-in-out infinite;
}
.page-content-skeleton-line.w-50 { width: 50%; }
.page-content-skeleton-line.w-75 { width: 75%; }
.page-content-skeleton-line.w-100 { width: 100%; }
@keyframes skeletonShimmer {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

.table-card {
  background: var(--lx-surface);
  border: 1px solid var(--lx-border);
  border-radius: var(--lx-radius-lg);
  box-shadow: var(--lx-shadow-sm);
  overflow: hidden;
  max-width: 100%;
}

/* ═══════════════ Patrón page_shell (layout/_page_shell.html) ═════════════ */

.page-shell {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.page-shell-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.05rem 1.25rem;
  background: var(--lx-surface);
  border-radius: var(--lx-radius-lg);
  border: 1px solid var(--lx-border);
  box-shadow: var(--lx-shadow-sm);
}
.page-shell-heading {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  min-width: 0;
  flex: 1 1 240px;
}
.page-shell-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--lx-brand-50), var(--lx-brand-100));
  color: var(--lx-brand-600);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  flex-shrink: 0;
  box-shadow: inset 0 0 0 1px rgba(var(--lx-brand-rgb), 0.12);
}
.page-shell-title {
  font-family: var(--lx-font-display);
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0;
  color: var(--lx-gray-900);
  line-height: 1.3;
}
.page-shell-badge {
  display: inline-block;
  margin-left: 0.45rem;
  padding: 0.12rem 0.5rem;
  font-family: var(--lx-font-sans);
  font-size: var(--lx-fs-2xs);
  font-weight: 600;
  letter-spacing: 0.01em;
  border-radius: 999px;
  background: var(--lx-gray-100);
  color: var(--lx-gray-600);
  vertical-align: middle;
  box-shadow: inset 0 0 0 1px var(--lx-border);
}
.page-shell-subtitle {
  margin: 0.2rem 0 0;
  font-size: var(--lx-fs-sm);
  color: var(--lx-muted);
  line-height: 1.4;
}
.page-shell-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  justify-content: flex-end;
}
.page-shell-kpis { margin: 0; }
.page-shell-kpi {
  position: relative;
  background: var(--lx-surface);
  border-radius: var(--lx-radius-lg);
  padding: 0.9rem 1.05rem;
  border: 1px solid var(--lx-border);
  box-shadow: var(--lx-shadow-sm);
  height: 100%;
  overflow: hidden;
}
.page-shell-kpi::after {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--lx-gray-200);
}
.page-shell-kpi:has(.text-primary)::after { background: var(--lx-brand-500); }
.page-shell-kpi:has(.text-success)::after { background: var(--lx-success); }
.page-shell-kpi:has(.text-warning)::after { background: var(--lx-warning); }
.page-shell-kpi:has(.text-danger)::after { background: var(--lx-danger); }
.page-shell-kpi-label {
  font-size: var(--lx-fs-2xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--lx-muted);
  font-weight: 600;
  margin-bottom: 0.3rem;
}
.page-shell-kpi-value {
  font-family: var(--lx-font-display);
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--lx-gray-900);
  line-height: 1.2;
}
.page-shell-kpi-value.text-success { color: var(--lx-success-ink) !important; }
.page-shell-kpi-value.text-warning { color: var(--lx-warning-hover) !important; }
.page-shell-kpi-value.text-primary { color: var(--lx-brand-700) !important; }
.page-shell-kpi-value.text-danger { color: var(--lx-danger) !important; }

.page-shell-toolbar {
  background: var(--lx-surface);
  border-radius: var(--lx-radius-lg);
  border: 1px solid var(--lx-border);
  box-shadow: var(--lx-shadow-xs);
  padding: 0.7rem 0.9rem;
}
.page-shell-toolbar-inner {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}
.page-shell-toolbar .form-control,
.page-shell-toolbar .form-select {
  min-width: 160px;
  max-width: 280px;
  flex: 1 1 180px;
}
.page-shell-data-head { padding: 0.25rem 0.25rem 0.5rem; }
.page-shell-data-title {
  margin: 0;
  font-family: var(--lx-font-sans);
  font-size: var(--lx-fs-2xs);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--lx-muted);
  font-weight: 700;
}
.page-shell-data-body { margin: 0; }

.page-hub-section { margin-bottom: 0.25rem; }
.page-hub-section-head {
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--lx-border);
}
.page-hub-section-title {
  margin: 0;
  font-size: var(--lx-fs-md);
  font-weight: 700;
  color: var(--lx-gray-800);
}
.page-hub-section-desc {
  margin: 0.2rem 0 0;
  font-size: var(--lx-fs-sm);
  color: var(--lx-muted);
}
.page-hub-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.35rem;
  height: 100%;
  padding: 1rem 0.75rem;
  background: var(--lx-surface);
  border-radius: var(--lx-radius-lg);
  border: 1px solid var(--lx-border);
  box-shadow: var(--lx-shadow-xs);
  transition: border-color var(--lx-transition), box-shadow var(--lx-transition), transform var(--lx-transition);
}
.page-hub-tile:hover {
  border-color: var(--lx-brand-200);
  box-shadow: 0 6px 18px rgba(var(--lx-brand-rgb), 0.12);
  transform: translateY(-2px);
}
.page-hub-tile-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--lx-brand-50);
  color: var(--lx-brand-600);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
}
.page-hub-tile-label { font-size: var(--lx-fs-sm); font-weight: 600; color: var(--lx-gray-800); }
.page-hub-tile-desc { font-size: var(--lx-fs-xs); color: var(--lx-subtle); line-height: 1.3; }

.page-report-tile {
  display: block;
  height: 100%;
  padding: 1.1rem 1.15rem;
  background: var(--lx-surface);
  border-radius: var(--lx-radius-lg);
  border: 1px solid var(--lx-border);
  box-shadow: var(--lx-shadow-xs);
  transition: border-color var(--lx-transition), box-shadow var(--lx-transition);
}
.page-report-tile:hover {
  border-color: var(--lx-brand-200);
  box-shadow: 0 6px 18px rgba(var(--lx-brand-rgb), 0.1);
}
.page-report-tile.border-accent-primary { border-left: 3px solid var(--lx-brand-600); }
.page-report-tile-icon { display: block; font-size: 1.5rem; color: var(--lx-brand-600); margin-bottom: 0.5rem; }
.page-report-tile-label { display: block; font-weight: 700; font-size: var(--lx-fs-md); color: var(--lx-gray-900); margin-bottom: 0.25rem; }
.page-report-tile-desc { display: block; font-size: var(--lx-fs-sm); color: var(--lx-muted); line-height: 1.4; }

.row-actions { display: inline-flex; gap: 0.25rem; flex-wrap: nowrap; }
.row-actions .btn { padding: 0.2rem 0.45rem; }

.page-detail-toolbar {
  padding: 0.7rem 0.9rem;
  background: var(--lx-surface);
  border-radius: var(--lx-radius-lg);
  border: 1px solid var(--lx-border);
  box-shadow: var(--lx-shadow-xs);
}

@media print {
  .sidebar, .topbar, .page-detail-toolbar, .no-print { display: none !important; }
  .main { margin-left: 0 !important; }
}

/* ══════════════════════════════ KPI (dashboard) ══════════════════════════ */

.kpi-card {
  background: var(--lx-surface);
  border: 1px solid var(--lx-border);
  border-radius: var(--lx-radius-lg);
  box-shadow: var(--lx-shadow-sm);
  padding: 1.15rem 1.3rem;
}
.row > [class*="col"] > .kpi-card,
.row > [class*="col"] > a:has(> .kpi-card),
.row > [class*="col"] > a > .kpi-card { height: 100%; }
.row > [class*="col"] > a:has(> .kpi-card) { display: block; }
a > .kpi-card { transition: border-color var(--lx-transition), box-shadow var(--lx-transition); }
a:hover > .kpi-card { border-color: var(--lx-brand-200); box-shadow: var(--lx-shadow-md); }
/* Acento de estado: franja fina superior en lugar del borde lateral grueso. */
.kpi-card.border-start {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--lx-border) !important;
}
.kpi-card.border-start::before {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 3px;
  background: var(--lx-gray-300);
}
.kpi-card.border-success::before { background: var(--lx-success); }
.kpi-card.border-danger::before { background: var(--lx-danger); }
.kpi-card.border-warning::before { background: var(--lx-warning); }
.kpi-card.border-info::before { background: var(--lx-info); }
.kpi-card.border-primary::before { background: var(--lx-brand-600); }
.kpi-card .text-muted.small:first-child {
  font-size: var(--lx-fs-xs);
  font-weight: 600;
  letter-spacing: 0.02em;
}
.kpi-card > div:last-child { min-width: 0; }
.kpi-card .fs-5 {
  font-family: var(--lx-font-display);
  font-size: clamp(1.02rem, 1.35vw, 1.22rem) !important;
  white-space: nowrap;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.table-card > .p-3 > h6,
.table-card.p-3 > h6 {
  font-family: var(--lx-font-display);
  font-size: var(--lx-fs-md);
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--lx-gray-900);
}
.kpi-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.45rem;
}
.kpi-badge {
  font-size: 0.66rem;
  min-width: 1.3rem;
  height: 1.3rem;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  padding: 0 0.3rem;
  letter-spacing: 0;
}
.bg-submenu .nav-link .kpi-badge { margin-left: auto; margin-right: 1.3rem; }
.kpi-badge-warn {
  background: rgba(251, 191, 36, 0.16);
  color: #fcd34d;
  border: 1px solid rgba(251, 191, 36, 0.35);
}
.kpi-badge-alert {
  background: rgba(248, 113, 113, 0.16);
  color: #fca5a5;
  border: 1px solid rgba(248, 113, 113, 0.38);
}
.nav-group-header .kpi-badge { margin-right: 0.4rem; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}

/* ══════════════════════════════ Responsive ═══════════════════════════════ */

@media (max-width: 991.98px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: min(86vw, 320px);
    height: 100vh;
    height: 100dvh;
    transform: translateX(-102%);
    transition: transform 0.22s ease;
    z-index: 1001;
  }
  body.mobile-menu-open .sidebar { transform: translateX(0); }
  .main { margin-left: 0; }
  body.sidebar-collapsed .main { margin-left: 0; }
  .topbar { padding: 0.55rem 1rem; }
  .page-content { padding: 0.9rem 1rem 1.2rem; }
}

@media (max-width: 767.98px) {
  /* Fila 1: menú + título | avatar + salir. Fila 2: selector de sucursal. */
  .topbar {
    flex-wrap: wrap;
    gap: 0.5rem 0.45rem;
    min-height: 0;
    padding: 0.5rem 0.8rem;
  }
  .topbar > .d-flex:first-child { flex: 1 1 auto; min-width: 0; }
  #topbar-page-title {
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .user-info { display: contents; }
  .user-name { display: none; }
  .branch-switcher {
    order: 10;
    width: 100%;
    min-width: 0;
    max-width: none;
    flex: 1 1 100%;
  }
  .branch-label { order: 10; flex: 1 1 100%; max-width: none; }
  .page-content { padding: 0.75rem 0.8rem 1rem; }
  .page-shell-header { padding: 0.9rem 1rem; }
  .kpi-card {
    flex-direction: column;
    align-items: flex-start !important;
    gap: 0.6rem !important;
    padding: 0.9rem 0.95rem;
  }
  .kpi-card .kpi-icon { width: 38px; height: 38px; font-size: 1.15rem; border-radius: 10px; }
  .kpi-card .fs-5 { font-size: 1.02rem !important; }
  .page-shell-title { font-size: 1.08rem; }
}

/* ═════════════════════════════ Flash toasts ══════════════════════════════ */

#flash-toast-container {
  position: fixed;
  top: 1.1rem;
  right: 1.1rem;
  z-index: 10500;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  pointer-events: none;
  max-width: 380px;
  width: calc(100vw - 2.2rem);
}
.flash-toast {
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: flex-start;
  gap: 0.7rem;
  padding: 0.75rem 1rem;
  border-radius: var(--lx-radius-md);
  border: 1px solid var(--lx-border);
  border-left: 4px solid transparent;
  background: var(--lx-surface);
  box-shadow: var(--lx-shadow-lg);
  font-size: var(--lx-fs-base);
  font-weight: 500;
  line-height: 1.4;
  pointer-events: all;
  animation: flashToastIn 0.25s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
.flash-toast.leaving { animation: flashToastOut 0.3s ease forwards; }
.flash-toast-icon { font-size: 1.05rem; flex-shrink: 0; margin-top: 0.05rem; }
.flash-toast-body { flex: 1; }
.flash-toast-close {
  background: none;
  border: none;
  cursor: pointer;
  opacity: 0.55;
  font-size: 0.8rem;
  padding: 0;
  flex-shrink: 0;
  line-height: 1;
  margin-top: 0.1rem;
  color: inherit;
}
.flash-toast-close:hover { opacity: 1; }
.flash-toast.success { color: var(--lx-success-ink); border-left-color: var(--lx-success); }
.flash-toast.success .flash-toast-icon { color: var(--lx-success); }
.flash-toast.danger, .flash-toast.error { color: var(--lx-danger-ink); border-left-color: var(--lx-danger); }
.flash-toast.danger .flash-toast-icon, .flash-toast.error .flash-toast-icon { color: var(--lx-danger); }
.flash-toast.warning { color: var(--lx-warning-ink); border-left-color: var(--lx-warning); }
.flash-toast.warning .flash-toast-icon { color: var(--lx-warning-hover); }
.flash-toast.info, .flash-toast.primary { color: var(--lx-brand-900); border-left-color: var(--lx-brand-500); }
.flash-toast.info .flash-toast-icon, .flash-toast.primary .flash-toast-icon { color: var(--lx-brand-600); }
.flash-toast-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 3px;
  border-radius: 0 0 0 8px;
  animation: flashBarShrink linear forwards;
}
.flash-toast.success .flash-toast-bar { background: var(--lx-success); }
.flash-toast.danger .flash-toast-bar, .flash-toast.error .flash-toast-bar { background: var(--lx-danger); }
.flash-toast.warning .flash-toast-bar { background: var(--lx-warning); }
.flash-toast.info .flash-toast-bar, .flash-toast.primary .flash-toast-bar { background: var(--lx-brand-500); }
@keyframes flashToastIn {
  from { opacity: 0; transform: translateX(30px) scale(0.95); }
  to { opacity: 1; transform: translateX(0) scale(1); }
}
@keyframes flashToastOut {
  to { opacity: 0; transform: translateX(30px) scale(0.92); max-height: 0; padding: 0; margin: 0; }
}
@keyframes flashBarShrink {
  from { width: 100%; }
  to { width: 0%; }
}
