.table-compact .table > :not(caption) > * > * {
  padding: 0.35rem 0.5rem;
}

.table-compact .table {
  font-size: 0.85rem;
}

.alert-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  background: #dc3545;
  position: absolute;
  top: 8px;
  right: 8px;
}

.topbar .nav-icon {
  position: relative;
}

.alert-badge:empty {
  display: none;
}

.topbar-role {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(13, 110, 253, 0.15);
  color: #9ec5fe;
  border: 1px solid rgba(13, 110, 253, 0.3);
}

.topbar-perms {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(25, 135, 84, 0.15);
  color: #a3cfbb;
  border: 1px solid rgba(25, 135, 84, 0.3);
}

.empty-state {
  padding: 18px 12px;
  text-align: center;
  color: var(--bs-secondary-color);
  font-size: 0.9rem;
}

/* ---------------------------------------------------------
   Global UI Polish (aplica a todas las ventanas)
   --------------------------------------------------------- */
:root {
  --ui-radius-sm: 0.55rem;
  --ui-radius-md: 0.8rem;
  --ui-radius-lg: 1rem;
}

body[data-bs-theme="dark"] {
  background:
    radial-gradient(1100px 500px at -10% -15%, rgba(73, 145, 255, 0.09), transparent 58%),
    radial-gradient(900px 460px at 105% 5%, rgba(51, 208, 186, 0.08), transparent 58%),
    #0f1424;
}

body[data-bs-theme="light"] {
  background:
    radial-gradient(1100px 500px at -10% -15%, rgba(73, 145, 255, 0.08), transparent 58%),
    radial-gradient(900px 460px at 105% 5%, rgba(51, 208, 186, 0.07), transparent 58%),
    #f3f6fb;
}

.topbar {
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid rgba(145, 158, 181, 0.12);
  position: fixed;
  z-index: 1105;
  left: var(--bs-startbar-width);
  width: calc(100% - var(--bs-startbar-width));
  overflow: visible;
}

/* Evita que el overlay del sidebar tape los dropdowns del topbar. */
.startbar-overlay {
  z-index: 1000;
}

/* Asegura que notificaciones/perfil del topbar no queden detrás de la barra. */
.topbar .topbar-custom {
  overflow: visible;
}

.topbar .dropdown-menu {
  z-index: 1206;
}

/* Override robusto para evitar que el menú del topbar quede recortado detrás. */
.topbar,
.topbar .container-fluid,
.topbar .topbar-custom,
.topbar .topbar-custom .topbar-item,
.topbar .topbar-custom .dropdown {
  overflow: visible !important;
}

.topbar .topbar-custom .dropdown-menu {
  z-index: 1206 !important;
}

/* Las alertas (toasts), incluyendo desconexiones, deben quedar debajo del topbar. */
#toast-container {
  top: calc(var(--bs-topbar-height) + 0.5rem) !important;
  z-index: 1104 !important;
  pointer-events: none;
}

#toast-container .toast {
  pointer-events: auto;
}

/* Cuando el sidebar está colapsado en desktop, ajusta el offset del topbar. */
body[data-sidebar-size="collapsed"] .topbar {
  left: var(--bs-startbar-collapsed-width);
  width: calc(100% - var(--bs-startbar-collapsed-width));
}

/* En mobile/tablet el sidebar es off-canvas, topbar debe ocupar todo el ancho. */
@media (max-width: 1199.98px) {
  .topbar {
    left: 0;
    width: 100%;
  }
}

.startbar {
  border-right: 1px solid rgba(145, 158, 181, 0.12);
}

.startbar .navbar-nav .nav-link {
  border-radius: var(--ui-radius-sm);
  transition: all 0.18s ease;
}

.startbar .navbar-nav .nav-link:hover {
  transform: translateX(2px);
  background: rgba(73, 145, 255, 0.12);
}

.startbar .navbar-nav .nav-link.active {
  background: linear-gradient(90deg, rgba(73, 145, 255, 0.24), rgba(73, 145, 255, 0.08));
  border: 1px solid rgba(73, 145, 255, 0.35);
}

.page-title {
  letter-spacing: 0.01em;
}

.card {
  border-radius: var(--ui-radius-lg);
  border: 1px solid rgba(145, 158, 181, 0.14);
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.12);
  overflow: hidden;
}

.card-header {
  border-bottom: 1px solid rgba(145, 158, 181, 0.14);
  background: linear-gradient(
    to right,
    rgba(89, 118, 165, 0.07),
    rgba(89, 118, 165, 0.02)
  );
}

.card-title {
  font-weight: 650;
  letter-spacing: 0.01em;
}

.table {
  border-collapse: separate;
  border-spacing: 0;
}

.table > :not(caption) > * > * {
  border-bottom-color: rgba(145, 158, 181, 0.16);
}

.table thead th {
  font-weight: 650;
  letter-spacing: 0.01em;
}

.table tbody tr:hover {
  background: rgba(73, 145, 255, 0.07);
}

.form-control,
.form-select {
  border-radius: var(--ui-radius-md);
  border-color: rgba(145, 158, 181, 0.35);
  transition: all 0.18s ease;
}

.form-control:focus,
.form-select:focus {
  box-shadow: 0 0 0 0.22rem rgba(73, 145, 255, 0.2);
  border-color: rgba(73, 145, 255, 0.65);
}

.btn {
  border-radius: var(--ui-radius-md);
  font-weight: 600;
  letter-spacing: 0.01em;
  transition: transform 0.15s ease, box-shadow 0.2s ease, opacity 0.15s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

.btn-primary {
  box-shadow: 0 8px 18px rgba(13, 110, 253, 0.28);
}

.btn-outline-primary:hover,
.btn-outline-secondary:hover {
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.16);
}

.badge {
  border-radius: 999px;
  padding-top: 0.38em;
  padding-bottom: 0.38em;
}

.dropdown-menu {
  border-radius: var(--ui-radius-md);
  border: 1px solid rgba(145, 158, 181, 0.2);
  box-shadow: 0 16px 28px rgba(0, 0, 0, 0.22);
}

.modal-content {
  border-radius: var(--ui-radius-lg);
  border: 1px solid rgba(145, 158, 181, 0.18);
}

.modal-header,
.modal-footer {
  border-color: rgba(145, 158, 181, 0.14);
}

.footer .card {
  border-top-left-radius: var(--ui-radius-lg);
  border-top-right-radius: var(--ui-radius-lg);
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
}

.footer .text-muted.mb-0 {
  font-weight: 500;
  letter-spacing: 0.01em;
}

.auth-header-box {
  background:
    radial-gradient(circle at 80% 20%, rgba(73, 145, 255, 0.35), transparent 45%),
    linear-gradient(135deg, #14213d 0%, #1b2f54 50%, #12355b 100%) !important;
  border-bottom: 1px solid rgba(145, 158, 181, 0.2);
}

.auth-header-box h1 {
  letter-spacing: 0.08em;
}

#errorMsg {
  min-height: 1.25rem;
  font-weight: 600;
}

@media (max-width: 991.98px) {
  .page-title-box {
    gap: 0.65rem;
    align-items: flex-start !important;
  }

  .page-content .container-fluid {
    padding-left: 0.85rem;
    padding-right: 0.85rem;
  }

  .topbar .dropdown-menu.dropdown-lg {
    width: min(94vw, 360px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .btn,
  .form-control,
  .form-select,
  .startbar .navbar-nav .nav-link {
    transition: none !important;
  }
}
