/* ==========================================================================
   app.css — Wilki Platform custom styles
   Bootstrap 5 base; dark sidebar + light content layout
   ========================================================================== */

/* --------------------------------------------------------------------------
   CSS Custom Properties
   -------------------------------------------------------------------------- */
:root {
  --sidebar-width: 250px;

  /* Sidebar — light mode (default) */
  --sidebar-bg: #ffffff;
  --sidebar-border: rgba(0, 0, 0, 0.08);
  --sidebar-text: #5c6470;
  --sidebar-text-hover: #212529;
  --sidebar-active-bg: rgba(13, 110, 253, 0.09);
  --sidebar-active-text: #0d6efd;
  --sidebar-brand-color: #212529;
  --sidebar-section-label: rgba(0, 0, 0, 0.32);
  --sidebar-hover-bg: rgba(0, 0, 0, 0.05);
  --sidebar-divider: rgba(0, 0, 0, 0.07);
  --sidebar-ctrl-border: rgba(0, 0, 0, 0.10);
  --sidebar-ctrl-hover-bg: rgba(0, 0, 0, 0.05);
  --sidebar-user-name: #212529;
  --sidebar-logo-filter: none;

  --content-bg: #f8f9fa;
  --content-padding: 30px;
  --border-radius-card: 0.625rem;
  --transition-speed: 0.2s;
}

/* Sidebar — dark mode overrides */
[data-theme="dark"] {
  --sidebar-bg: #0e1012;
  --sidebar-border: rgba(255, 255, 255, 0.05);
  --sidebar-text: #adb5bd;
  --sidebar-text-hover: #ffffff;
  --sidebar-active-bg: rgba(255, 255, 255, 0.08);
  --sidebar-active-text: #ffffff;
  --sidebar-brand-color: #ffffff;
  --sidebar-section-label: rgba(255, 255, 255, 0.28);
  --sidebar-hover-bg: rgba(255, 255, 255, 0.07);
  --sidebar-divider: rgba(255, 255, 255, 0.07);
  --sidebar-ctrl-border: rgba(255, 255, 255, 0.10);
  --sidebar-ctrl-hover-bg: rgba(255, 255, 255, 0.08);
  --sidebar-user-name: #ffffff;
  --sidebar-logo-filter: brightness(0) invert(1);
}

/* --------------------------------------------------------------------------
   Base
   -------------------------------------------------------------------------- */
html,
body {
  height: 100%;
}

body {
  background-color: var(--content-bg);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: 0.9rem;
  color: #343a40;
}

/* --------------------------------------------------------------------------
   Sidebar
   -------------------------------------------------------------------------- */
#sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background-color: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  z-index: 1040;
  overflow-y: auto;
  overflow-x: hidden;
  transition: width 0.25s ease, transform var(--transition-speed) ease-in-out;
}

/* Brand / Logo */
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 20px 18px;
  border-bottom: 1px solid var(--sidebar-divider);
  text-decoration: none;
  flex-shrink: 0;
}

.sidebar-brand-icon {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, #0d6efd 0%, #0a58ca 100%);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1rem;
  color: #fff;
  flex-shrink: 0;
}

.sidebar-brand-text {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--sidebar-brand-color);
  letter-spacing: 0.5px;
  line-height: 1;
}

.sidebar-brand-sub {
  font-size: 0.65rem;
  color: var(--sidebar-text);
  letter-spacing: 1px;
  text-transform: uppercase;
  line-height: 1;
  margin-top: 2px;
}

/* Nav */
.sidebar-nav {
  flex: 1;
  padding: 12px 0;
  list-style: none;
  margin: 0;
}

.sidebar-nav .nav-section-label {
  padding: 14px 20px 6px;
  font-size: 0.67rem;
  font-weight: 600;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--sidebar-section-label);
  cursor: default;
  user-select: none;
}

/* Sidebar sub-nav (used by connector sub-nav and cross-connector nav).
   Kept here so non-connector pages that render cross-connector items
   (dashboard, profile, etc.) get the same styling. */
.sidebar-nav .nav-sub-section {
  font-size: .6rem;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--bs-secondary-color);
  padding: .45rem 1rem .15rem 2.4rem;
  font-weight: 700;
  pointer-events: none;
  display: block;
}
.sidebar-nav .nav-sub-link {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .3rem 1rem .3rem 2.4rem;
  font-size: .82rem;
  color: var(--bs-body-color);
  text-decoration: none;
  cursor: pointer;
  border-radius: .3rem;
  transition: background .15s;
}
.sidebar-nav .nav-sub-link:hover  { background: var(--bs-tertiary-bg); }
.sidebar-nav .nav-sub-link.active { color: var(--bs-primary); font-weight: 600; background: var(--bs-primary-bg-subtle); }
body.sidebar-collapsed .sidebar-nav .nav-sub-section,
body.sidebar-collapsed .sidebar-nav .nav-sub-link span { display: none; }
body.sidebar-collapsed .sidebar-nav .nav-sub-link { padding-left: 1rem; justify-content: center; }

.sidebar-nav .nav-item {
  margin: 1px 8px;
}

.sidebar-nav .nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  color: var(--sidebar-text);
  text-decoration: none;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  transition: background-color var(--transition-speed),
              color var(--transition-speed);
}

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

.sidebar-nav .nav-link:hover {
  background-color: var(--sidebar-hover-bg);
  color: var(--sidebar-text-hover);
}

.sidebar-nav .nav-link.active {
  background-color: var(--sidebar-active-bg);
  color: var(--sidebar-active-text);
}

.sidebar-nav .nav-link.active i {
  color: #0d6efd;
}

/* User info at bottom */
.sidebar-user {
  border-top: 1px solid var(--sidebar-divider);
  padding: 14px 16px;
  flex-shrink: 0;
}

.sidebar-user-name {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--sidebar-user-name);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-role {
  font-size: 0.72rem;
  color: var(--sidebar-text);
  margin-top: 1px;
}

.sidebar-logout-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  margin-top: 8px;
  background: transparent;
  border: 1px solid var(--sidebar-ctrl-border);
  border-radius: 6px;
  color: var(--sidebar-text);
  font-size: 0.82rem;
  cursor: pointer;
  transition: background-color var(--transition-speed),
              color var(--transition-speed),
              border-color var(--transition-speed);
}

.sidebar-logout-btn:hover {
  background-color: rgba(220, 53, 69, 0.10);
  border-color: rgba(220, 53, 69, 0.35);
  color: #dc3545;
}

.sidebar-controls,
.sidebar-user,
#sidebar .nav-section-label[data-i18n="nav.account"],
#sidebar a[href="profile.html"],
.mobile-logout-btn {
  display: none !important;
}

/* --------------------------------------------------------------------------
   Global user menu
   -------------------------------------------------------------------------- */
.page-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.page-topbar-context {
  min-width: 0;
  flex: 1;
}

.page-topbar-title {
  font-size: 1.45rem;
  font-weight: 700;
  color: #212529;
  line-height: 1.15;
}

.page-topbar-subtitle {
  margin-top: 4px;
  font-size: 0.9rem;
}

.page-user-menu {
  position: relative;
  z-index: 10;
}

.page-user-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 196px;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: transparent;
  color: #212529;
  box-shadow: none;
  backdrop-filter: none;
}

.page-user-btn:hover,
.page-user-btn:focus,
.page-user-btn.show {
  background: rgba(13, 110, 253, 0.08);
  color: #212529;
  border-color: transparent;
}

.page-user-btn::after {
  margin-left: auto;
}

.page-user-btn-icon {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(13, 110, 253, 0.12);
  color: #0d6efd;
  flex-shrink: 0;
}

.page-user-btn-icon i {
  font-size: 1.05rem;
}

.page-user-btn-copy {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-width: 0;
  line-height: 1.15;
}

.page-user-btn-name,
.user-menu-name {
  font-weight: 600;
  color: #212529;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.page-user-btn-role,
.user-menu-role {
  font-size: 0.74rem;
  color: #6c757d;
}

.user-menu-dropdown {
  min-width: 240px;
  border-radius: 14px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  padding: 8px;
  margin-top: 10px !important;
}

.user-menu-header {
  padding: 8px 10px 10px;
}

.user-menu-dropdown .dropdown-item {
  display: flex;
  align-items: center;
  border-radius: 10px;
  padding: 9px 10px;
  font-size: 0.9rem;
}

.page-topbar-source-hidden {
  display: none !important;
}

[data-theme="dark"] .page-user-btn {
  background: transparent;
  border-color: transparent;
  color: #f8f9fa;
  box-shadow: none;
}

[data-theme="dark"] .page-user-btn:hover,
[data-theme="dark"] .page-user-btn:focus,
[data-theme="dark"] .page-user-btn.show {
  background: rgba(255, 255, 255, 0.08);
  color: #f8f9fa;
  border-color: transparent;
}

[data-theme="dark"] .page-user-btn-name,
[data-theme="dark"] .user-menu-name {
  color: #f8f9fa;
}

[data-theme="dark"] .page-user-btn-role,
[data-theme="dark"] .user-menu-role {
  color: rgba(255, 255, 255, 0.65);
}

[data-theme="dark"] .page-topbar-title {
  color: #f8f9fa;
}

[data-theme="dark"] .page-topbar-subtitle {
  color: rgba(255, 255, 255, 0.7) !important;
}

[data-theme="dark"] .user-menu-dropdown {
  background: #17191c;
  border-color: rgba(255, 255, 255, 0.08);
}

/* --------------------------------------------------------------------------
   Main content wrapper
   -------------------------------------------------------------------------- */
#main-content {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  padding: var(--content-padding);
  background-color: var(--content-bg);
  transition: margin-left var(--transition-speed) ease-in-out;
}

/* --------------------------------------------------------------------------
   Page header / title
   -------------------------------------------------------------------------- */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}

.page-title {
  font-size: 1.45rem;
  font-weight: 700;
  color: #212529;
  margin: 0;
}

.page-subtitle {
  font-size: 0.85rem;
  color: #6c757d;
  margin: 2px 0 0;
}

/* --------------------------------------------------------------------------
   Cards
   -------------------------------------------------------------------------- */
.card {
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: var(--border-radius-card);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
  transition: box-shadow var(--transition-speed);
}

.card:hover {
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.08);
}

.card-header {
  background-color: #fff;
  border-bottom: 1px solid rgba(0, 0, 0, 0.07);
  font-weight: 600;
  font-size: 0.95rem;
  padding: 14px 20px;
  border-radius: var(--border-radius-card) var(--border-radius-card) 0 0 !important;
}

.card-body {
  padding: 20px;
}

/* Stat cards */
.stat-card {
  border-left: 4px solid transparent;
}

.stat-card.stat-primary  { border-left-color: #0d6efd; }
.stat-card.stat-success  { border-left-color: #198754; }
.stat-card.stat-warning  { border-left-color: #ffc107; }
.stat-card.stat-info     { border-left-color: #0dcaf0; }

.stat-card .stat-value {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1;
  color: #212529;
}

.stat-card .stat-label {
  font-size: 0.8rem;
  color: #6c757d;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  font-weight: 500;
  margin-top: 4px;
}

.stat-card .stat-icon {
  font-size: 2.2rem;
  opacity: 0.12;
}

/* --------------------------------------------------------------------------
   Tables
   -------------------------------------------------------------------------- */
.table-container {
  border-radius: var(--border-radius-card);
  overflow: hidden;
  border: 1px solid rgba(0, 0, 0, 0.08);
  background: #fff;
}

.table {
  margin-bottom: 0;
  font-size: 0.875rem;
}

.table thead th {
  background-color: #f8f9fa;
  border-bottom: 2px solid #dee2e6;
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: #495057;
  padding: 12px 16px;
  white-space: nowrap;
}

.table tbody td {
  padding: 12px 16px;
  vertical-align: middle;
  border-bottom: 1px solid #f0f0f0;
  color: #343a40;
}

.table tbody tr:last-child td {
  border-bottom: none;
}

.table tbody tr:hover td {
  background-color: #f8fbff;
}

/* Action column */
td.actions-col {
  white-space: nowrap;
  text-align: right;
}

td.actions-col .btn {
  padding: 4px 10px;
  font-size: 0.8rem;
}

/* Empty state row */
.table-empty-row td {
  text-align: center;
  padding: 40px 16px;
  color: #adb5bd;
  font-size: 0.9rem;
}

/* --------------------------------------------------------------------------
   Role / Status Badges
   -------------------------------------------------------------------------- */
.badge-role-superadmin {
  background-color: #dc3545;
  color: #fff;
}

.badge-role-admin {
  background-color: #ffc107;
  color: #212529;
}

.badge-role-user {
  background-color: #6c757d;
  color: #fff;
}

.badge-status-active {
  background-color: #198754;
  color: #fff;
}

.badge-status-inactive {
  background-color: #dc3545;
  color: #fff;
}

.role-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.4px;
  text-transform: capitalize;
}

/* --------------------------------------------------------------------------
   Loading spinner overlay
   -------------------------------------------------------------------------- */
#loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  flex-direction: column;
  gap: 14px;
  backdrop-filter: blur(2px);
}

#loading-overlay.hidden {
  display: none;
}

.loading-text {
  font-size: 0.9rem;
  color: #6c757d;
  font-weight: 500;
}

/* Inline table spinner */
.table-spinner {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 0;
  color: #6c757d;
  gap: 10px;
}

/* --------------------------------------------------------------------------
   Wilki spinner — overrides Bootstrap's .spinner-border site-wide.
   The isotipo is injected as inline SVG by assets/js/spinner.js and the
   drawing animation lives in CSS here on the host document. Because CSS
   animations stop while an ancestor has display:none, showing a previously
   hidden spinner restarts the drawing from frame 0 every time.
   -------------------------------------------------------------------------- */
.spinner-border {
  border: 0 !important;
  animation: none !important;
  padding: 0;
  background: transparent !important;
  border-radius: 0 !important;
  line-height: 0;
}

.spinner-border .wilki-spinner-svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.spinner-border .wilki-bird-bg {
  fill: none;
  stroke: currentColor;
  stroke-width: 175.21;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.10;
}

.spinner-border .wilki-eye-bg {
  fill: currentColor;
  opacity: 0.10;
}

.spinner-border .wilki-bird {
  fill: none;
  stroke: currentColor;
  stroke-width: 175.21;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 420 580;
  stroke-dashoffset: 0;
  animation: wilki-draw-bird 2.4s linear infinite;
}

.spinner-border .wilki-eye {
  fill: currentColor;
  opacity: 0.25;
  animation: wilki-show-eye 2.4s ease-in-out infinite;
}

@keyframes wilki-draw-bird {
  from { stroke-dashoffset: 1000; }
  to   { stroke-dashoffset: 0; }
}

@keyframes wilki-show-eye {
  0%, 100% { opacity: 0.25; }
  50%      { opacity: 1; }
}

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */
.btn {
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: 6px;
}

.btn-sm {
  font-size: 0.8rem;
}

/* --------------------------------------------------------------------------
   Modals
   -------------------------------------------------------------------------- */
.modal-header {
  border-bottom: 1px solid #dee2e6;
  background-color: #f8f9fa;
}

.modal-title {
  font-weight: 700;
  font-size: 1rem;
}

.modal-footer {
  border-top: 1px solid #dee2e6;
  background-color: #f8f9fa;
}

/* --------------------------------------------------------------------------
   Alerts
   -------------------------------------------------------------------------- */
.alert {
  border-radius: 8px;
  font-size: 0.875rem;
}

/* --------------------------------------------------------------------------
   Form improvements
   -------------------------------------------------------------------------- */
.form-label {
  font-weight: 500;
  font-size: 0.85rem;
  margin-bottom: 5px;
  color: #495057;
}

.form-control,
.form-select {
  font-size: 0.875rem;
  border-radius: 6px;
  border-color: #ced4da;
  transition: border-color var(--transition-speed),
              box-shadow var(--transition-speed);
}

.form-control:focus,
.form-select:focus {
  border-color: #86b7fe;
  box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.15);
}

/* --------------------------------------------------------------------------
   Welcome card
   -------------------------------------------------------------------------- */
.welcome-card {
  background: linear-gradient(135deg, #0d6efd 0%, #0a58ca 100%);
  color: #fff;
  border: none;
}

.welcome-card .card-body {
  padding: 28px;
}

.welcome-title {
  font-size: 1.6rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.welcome-subtitle {
  opacity: 0.85;
  font-size: 0.9rem;
}

/* --------------------------------------------------------------------------
   Back button / breadcrumb style
   -------------------------------------------------------------------------- */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: #6c757d;
  text-decoration: none;
  margin-bottom: 8px;
  transition: color var(--transition-speed);
}

.back-link:hover {
  color: #0d6efd;
}

/* --------------------------------------------------------------------------
   Integrations list
   -------------------------------------------------------------------------- */
.integrations-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.integration-tag {
  display: inline-block;
  padding: 2px 9px;
  background-color: #e7f1ff;
  color: #0a58ca;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

/* --------------------------------------------------------------------------
   Mobile / Responsive
   -------------------------------------------------------------------------- */
/* Mobile top bar — hidden on desktop */
.mobile-topbar {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 52px;
  background-color: var(--sidebar-bg);
  border-bottom: 1px solid var(--sidebar-divider);
  align-items: center;
  padding: 0 14px;
  gap: 12px;
  z-index: 1050;
}

.sidebar-toggle {
  background: transparent;
  color: var(--sidebar-text);
  border: none;
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 1.25rem;
  cursor: pointer;
  line-height: 1;
  flex-shrink: 0;
}

.sidebar-toggle:hover {
  color: var(--sidebar-text-hover);
}

.mobile-brand-logo {
  width: 28px;
  height: 28px;
  object-fit: contain;
  filter: var(--sidebar-logo-filter);
  opacity: 0.88;
}

.mobile-logout-btn {
  margin-left: auto;
  background: transparent;
  border: 1px solid var(--sidebar-ctrl-border);
  border-radius: 6px;
  color: var(--sidebar-text);
  padding: 5px 9px;
  font-size: 1rem;
  cursor: pointer;
  line-height: 1;
  display: flex;
  align-items: center;
  gap: 5px;
}

.mobile-logout-btn:hover {
  background-color: rgba(220, 53, 69, 0.10);
  border-color: rgba(220, 53, 69, 0.35);
  color: #dc3545;
}

@media (max-width: 767.98px) {
  .mobile-topbar {
    display: flex;
  }

  .page-topbar {
    justify-content: space-between;
    margin-bottom: 14px;
    padding-right: 44px;
    gap: 12px;
    align-items: flex-start;
  }

  .page-topbar-title {
    font-size: 1.1rem;
  }

  .page-topbar-subtitle {
    font-size: 0.82rem;
  }

  .page-user-btn {
    min-width: auto;
    padding: 6px 10px;
  }

  .page-user-btn-copy {
    display: none;
  }

  #sidebar {
    transform: translateX(calc(-1 * var(--sidebar-width)));
  }

  #sidebar.sidebar-open {
    transform: translateX(0);
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.4);
  }

  #main-content {
    margin-left: 0;
    padding: 20px 16px;
    padding-top: 72px; /* room for mobile topbar */
  }

  .page-title {
    font-size: 1.2rem;
  }

  .stat-card .stat-value {
    font-size: 1.6rem;
  }
}

/* Backdrop for mobile sidebar */
#sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1039;
}

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

/* --------------------------------------------------------------------------
   Utility
   -------------------------------------------------------------------------- */
.cursor-pointer {
  cursor: pointer;
}

.text-truncate-cell {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --------------------------------------------------------------------------
   Sidebar logo
   -------------------------------------------------------------------------- */
.sidebar-logo-full {
  max-width: 130px;
  height: auto;
  display: block;
  filter: var(--sidebar-logo-filter);
  opacity: 0.92;
}

/* Keep old class as alias for backwards compat */
.sidebar-logo {
  max-width: 130px;
  height: auto;
  display: block;
  filter: var(--sidebar-logo-filter);
  opacity: 0.92;
}

.sidebar-logo-icon {
  display: none;
  width: 30px;
  height: 30px;
  object-fit: contain;
  filter: var(--sidebar-logo-filter);
  opacity: 0.88;
  flex-shrink: 0;
}

.sidebar-brand {
  padding: 18px 20px 16px;
}

/* --------------------------------------------------------------------------
   Sidebar controls (theme + language toggles)
   -------------------------------------------------------------------------- */
.sidebar-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 12px;
  border-top: 1px solid var(--sidebar-divider);
}

.sidebar-ctrl-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  flex: 1;
  padding: 6px 8px;
  background: transparent;
  border: 1px solid var(--sidebar-ctrl-border);
  border-radius: 6px;
  color: var(--sidebar-text);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: background-color var(--transition-speed),
              color var(--transition-speed),
              border-color var(--transition-speed);
  white-space: nowrap;
  line-height: 1;
}

.sidebar-ctrl-btn:hover {
  background-color: var(--sidebar-ctrl-hover-bg);
  color: var(--sidebar-text-hover);
  border-color: var(--sidebar-ctrl-border);
}

.sidebar-ctrl-btn i {
  font-size: 0.82rem;
}

/* --------------------------------------------------------------------------
   Floating page controls (login page — no sidebar)
   -------------------------------------------------------------------------- */
/* Language selector dropdown wrapper */
.lang-selector-wrapper {
  flex: 1;
  display: flex;
  position: relative;
}

.lang-selector-wrapper .sidebar-ctrl-btn {
  flex: 1;
}

.lang-selector-page {
  position: relative;
}

.lang-opt-label {
  display: inline-block;
  min-width: 1.8rem;
  font-weight: 600;
  font-size: 0.72rem;
  opacity: 0.65;
}

/* --------------------------------------------------------------------------
   Floating page controls (login page — no sidebar)
   -------------------------------------------------------------------------- */
.page-controls {
  position: fixed;
  top: 16px;
  right: 16px;
  display: flex;
  gap: 8px;
  z-index: 1100;
}

.page-ctrl-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(0, 0, 0, 0.10);
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition-speed);
  backdrop-filter: blur(6px);
  color: #495057;
  line-height: 1;
}

.page-ctrl-btn:hover {
  background: rgba(255, 255, 255, 0.97);
  color: #212529;
}

[data-theme="dark"] .page-ctrl-btn {
  background: rgba(36, 40, 48, 0.88);
  border-color: rgba(255, 255, 255, 0.12);
  color: #adb5bd;
}

[data-theme="dark"] .page-ctrl-btn:hover {
  background: rgba(50, 55, 65, 0.97);
  color: #fff;
}

/* --------------------------------------------------------------------------
   Dark mode — custom overrides
   (Bootstrap handles cards, forms, modals via data-bs-theme="dark")
   -------------------------------------------------------------------------- */
[data-theme="dark"] body,
[data-theme="dark"] #main-content {
  background-color: #16181c;
}

[data-theme="dark"] #loading-overlay {
  background: rgba(22, 24, 28, 0.92);
}

[data-theme="dark"] .loading-text {
  color: #8d96a0;
}

[data-theme="dark"] .page-title {
  color: #e9ecef;
}

[data-theme="dark"] .page-subtitle {
  color: #6c757d;
}

[data-theme="dark"] .stat-card .stat-value {
  color: #e9ecef;
}

[data-theme="dark"] .stat-card .stat-label {
  color: #8d96a0;
}

[data-theme="dark"] .integration-tag {
  background-color: rgba(13, 110, 253, 0.18);
  color: #74b3fe;
}

[data-theme="dark"] .back-link {
  color: #8d96a0;
}

[data-theme="dark"] .back-link:hover {
  color: #74b3fe;
}

/* Login page dark mode */
[data-theme="dark"] .login-page-bg {
  background: linear-gradient(145deg, #16181c 0%, #1c1f26 50%, #1a1d22 100%);
}

[data-theme="dark"] .login-logo-img {
  filter: brightness(0) invert(1);
  opacity: 0.9;
}

/* Splash dark mode */
[data-theme="dark"] .splash-logo-img {
  filter: brightness(0) invert(1);
  opacity: 0.9;
}

/* Sidebar toggle button dark mode */
[data-theme="dark"] .sidebar-toggle {
  background-color: #0e1012;
}

@media (max-width: 767.98px) {
  [data-theme="dark"] #sidebar.sidebar-open {
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.7);
  }
}

/* --------------------------------------------------------------------------
   Dark mode — Tables
   -------------------------------------------------------------------------- */
[data-theme="dark"] .table-container {
  background: #1c2028;
  border-color: rgba(255, 255, 255, 0.07);
}

[data-theme="dark"] .table {
  color: #cdd1d6;
}

[data-theme="dark"] .table thead th {
  background-color: #1a1e26;
  border-bottom-color: rgba(255, 255, 255, 0.10);
  color: #7e8fa4;
}

[data-theme="dark"] .table tbody td {
  border-bottom-color: rgba(255, 255, 255, 0.05);
  color: #cdd1d6;
}

[data-theme="dark"] .table tbody tr:last-child td {
  border-bottom: none;
}

[data-theme="dark"] .table tbody tr:hover td {
  background-color: rgba(255, 255, 255, 0.04);
}

[data-theme="dark"] .table-empty-row td {
  color: #4e5762;
}

/* --------------------------------------------------------------------------
   Dark mode — Cards
   -------------------------------------------------------------------------- */
[data-theme="dark"] .card {
  background-color: #1c2028;
  border-color: rgba(255, 255, 255, 0.07);
}

[data-theme="dark"] .card-header {
  background-color: #191d24;
  border-bottom-color: rgba(255, 255, 255, 0.08);
  color: #cdd1d6;
}

[data-theme="dark"] .card-body {
  color: #cdd1d6;
}

/* Welcome card stays blue — override the dark card bg */
[data-theme="dark"] .welcome-card {
  background: linear-gradient(135deg, #0a58ca 0%, #073fa3 100%);
}

[data-theme="dark"] .stat-card .stat-icon {
  opacity: 0.15;
}

/* --------------------------------------------------------------------------
   Dark mode — Modals
   -------------------------------------------------------------------------- */
[data-theme="dark"] .modal-content {
  background-color: #1c2028;
  border-color: rgba(255, 255, 255, 0.10);
  color: #cdd1d6;
}

[data-theme="dark"] .modal-header {
  background-color: #191d24;
  border-bottom-color: rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .modal-footer {
  background-color: #191d24;
  border-top-color: rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .modal-title {
  color: #e2e6ea;
}

[data-theme="dark"] .btn-close {
  filter: invert(1) grayscale(1) brightness(1.5);
}

/* --------------------------------------------------------------------------
   Dark mode — Forms
   -------------------------------------------------------------------------- */
[data-theme="dark"] .form-label {
  color: #9ea6b0;
}

[data-theme="dark"] .form-control,
[data-theme="dark"] .form-select {
  background-color: #13161b;
  border-color: rgba(255, 255, 255, 0.12);
  color: #cdd1d6;
}

[data-theme="dark"] .form-control:focus,
[data-theme="dark"] .form-select:focus {
  background-color: #13161b;
  border-color: #4d8cf5;
  box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.20);
  color: #e2e6ea;
}

[data-theme="dark"] .form-control:read-only {
  background-color: #1a1e26;
  color: #6c757d;
}

[data-theme="dark"] .form-control::placeholder,
[data-theme="dark"] .form-select::placeholder {
  color: #4e5762;
}

[data-theme="dark"] .form-text {
  color: #5c6470;
}

[data-theme="dark"] .form-check-input {
  background-color: #13161b;
  border-color: rgba(255, 255, 255, 0.20);
}

[data-theme="dark"] .form-check-input:checked {
  background-color: #0d6efd;
  border-color: #0d6efd;
}

[data-theme="dark"] .form-check-label {
  color: #9ea6b0;
}

/* --------------------------------------------------------------------------
   Dark mode — Alerts & misc
   -------------------------------------------------------------------------- */
[data-theme="dark"] .text-muted {
  color: #5c6470 !important;
}

[data-theme="dark"] .border,
[data-theme="dark"] .border-bottom {
  border-color: rgba(255, 255, 255, 0.08) !important;
}

[data-theme="dark"] .table-spinner {
  color: #5c6470;
}

.audit-user-picker tbody tr {
  cursor: pointer;
}

.audit-user-picker tbody tr.table-active > * {
  background-color: rgba(13, 110, 253, 0.08);
}

[data-theme="dark"] .audit-user-picker tbody tr.table-active > * {
  background-color: rgba(255, 255, 255, 0.08);
}

.audit-user-picker tbody tr.audit-row-disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.audit-user-picker tbody tr.audit-row-disabled:hover > * {
  background-color: transparent;
}

/* ==========================================================================
   Collapsible Sidebar (desktop)
   ========================================================================== */

:root {
  --sidebar-collapsed-width: 64px;
}

/* Suppress all transitions instantly (used during page-load state restore) */
.no-transition * {
  transition: none !important;
}

/* ---- Collapse toggle button -------------------------------------------- */
/* Floats on the right edge of the sidebar, half in / half out */
#sidebar-collapse-btn {
  position: fixed;
  top: 22px;
  left: calc(var(--sidebar-width) - 12px);
  width: 24px;
  height: 24px;
  background: #e9ecef;
  border: 2px solid var(--content-bg);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #6c757d;
  font-size: 0.6rem;
  z-index: 1042;
  padding: 0;
  line-height: 1;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.15);
  transition: left 0.25s ease, background 0.15s, color 0.15s, border-color 0.15s;
}

#sidebar-collapse-btn:hover {
  background: #0d6efd;
  color: #fff;
  border-color: #0d6efd;
}

[data-theme="dark"] #sidebar-collapse-btn {
  background: #252830;
  border-color: #16181c;
  color: #adb5bd;
}

[data-theme="dark"] #sidebar-collapse-btn:hover {
  background: #0d6efd;
  border-color: #0d6efd;
  color: #fff;
}

/* Hide on mobile (mobile has its own hamburger toggle) */
@media (max-width: 767.98px) {
  #sidebar-collapse-btn { display: none; }
}

/* ---- Collapsed nav-link tooltip (CSS-only, no JS lib needed) ------------ */
.sidebar-nav .nav-link {
  position: relative;
}

.sidebar-nav .nav-link::after {
  content: attr(data-tooltip);
  position: absolute;
  left: calc(100% + 10px);
  top: 50%;
  transform: translateY(-50%);
  background: #1a1a2e;
  color: #e9ecef;
  padding: 5px 11px;
  border-radius: 6px;
  font-size: 0.8rem;
  white-space: nowrap;
  pointer-events: none;
  z-index: 9999;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.12s, visibility 0.12s;
}

/* Small arrow on the tooltip */
.sidebar-nav .nav-link::before {
  content: '';
  position: absolute;
  left: calc(100% + 5px);
  top: 50%;
  transform: translateY(-50%);
  border: 5px solid transparent;
  border-right-color: #1a1a2e;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  z-index: 9999;
  transition: opacity 0.12s, visibility 0.12s;
}

/* Only show tooltip when sidebar is collapsed */
body.sidebar-collapsed .sidebar-nav .nav-link[data-tooltip]:hover::after,
body.sidebar-collapsed .sidebar-nav .nav-link[data-tooltip]:hover::before {
  opacity: 1;
  visibility: visible;
}

/* ---- COLLAPSED STATE ---------------------------------------------------- */
body.sidebar-collapsed #sidebar {
  width: var(--sidebar-collapsed-width);
}

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

body.sidebar-collapsed #sidebar-collapse-btn {
  left: calc(var(--sidebar-collapsed-width) - 12px);
}

/* Logo: swap full → small isotipo */
body.sidebar-collapsed .sidebar-logo-full { display: none; }
body.sidebar-collapsed .sidebar-logo-icon { display: block; }

/* Center brand area */
body.sidebar-collapsed .sidebar-brand {
  justify-content: center;
  padding: 18px 0 16px;
}

/* Nav items: center icon, hide label text */
body.sidebar-collapsed .sidebar-nav .nav-item {
  margin: 2px 6px;
}

body.sidebar-collapsed .sidebar-nav .nav-link {
  justify-content: center;
  padding: 10px 0;
  gap: 0;
}

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

body.sidebar-collapsed .sidebar-nav .nav-link i {
  font-size: 1.1rem;
  width: auto;
}

/* Section labels: hidden when collapsed */
body.sidebar-collapsed .sidebar-nav .nav-section-label {
  display: none;
}

/* Controls: stack vertically, icon only */
body.sidebar-collapsed .sidebar-controls {
  flex-direction: column;
  gap: 4px;
  padding: 8px 6px;
}

body.sidebar-collapsed .sidebar-ctrl-btn {
  justify-content: center;
  padding: 8px 6px;
  gap: 0;
}

body.sidebar-collapsed .sidebar-ctrl-btn span {
  display: none;
}

/* User area: icon-only compact */
body.sidebar-collapsed .sidebar-user {
  padding: 10px 8px;
  text-align: center;
}

body.sidebar-collapsed .sidebar-user-name,
body.sidebar-collapsed .sidebar-user-role {
  display: none;
}

body.sidebar-collapsed .sidebar-logout-btn {
  justify-content: center;
  padding: 8px;
  gap: 0;
}

body.sidebar-collapsed .sidebar-logout-btn span {
  display: none;
}

/* Spinning icon for async actions (force-sync button) */
@keyframes wilki-spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}
.spin {
  display: inline-block;
  animation: wilki-spin 0.8s linear infinite;
}

/* Unified pagination bar — used via renderPaginationBar() helper.
   padding-right leaves room for the chat FAB (56px @ right:20px) so the
   controls on the right edge (next button) don't sit under the widget. */
.pagination-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1rem;
  padding-right: 6rem;
  border-top: 1px solid var(--bs-border-color);
  font-size: .82rem;
}
.pagination-controls {
  display: inline-flex;
  align-items: center;
  gap: .75rem;
}
.pagination-indicator {
  padding: 0 .25rem;
  color: var(--bs-secondary-color);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  font-weight: 400;
}
.pagination-info {
  color: var(--bs-secondary-color);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  font-weight: 400;
}
@media (max-width: 575.98px) {
  .pagination-bar { padding-right: 1rem; }
}
