:root {
  --sidebar-width: 260px;
  --topbar-height: 64px;
  --primary: #6366f1;
  --primary-light: #818cf8;
  --primary-dark: #4f46e5;
  --sidebar-bg-start: #0f172a;
  --sidebar-bg-end: #1e1b4b;
  --sidebar-surface: rgba(255, 255, 255, 0.04);
  --sidebar-surface-hover: rgba(255, 255, 255, 0.08);
  --sidebar-surface-active: rgba(99, 102, 241, 0.22);
  --sidebar-border: rgba(255, 255, 255, 0.06);
  --sidebar-text: #94a3b8;
  --sidebar-text-active: #f8fafc;
  --sidebar-label: #6366f1;
  --body-bg: #f1f5f9;
  --card-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

[data-bs-theme="dark"] {
  --body-bg: #0f172a;
}

* {
  box-sizing: border-box;
}

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--body-bg);
  margin: 0;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: linear-gradient(180deg, var(--sidebar-bg-start) 0%, var(--sidebar-bg-end) 100%);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  z-index: 1040;
  transition: transform 0.3s ease;
  border-right: 1px solid var(--sidebar-border);
  box-shadow: 4px 0 24px rgba(15, 23, 42, 0.15);
}

.sidebar::before {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  width: 1px;
  height: 100%;
  background: linear-gradient(180deg, transparent, rgba(99, 102, 241, 0.4), transparent);
  pointer-events: none;
}

.sidebar-brand {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1.35rem 1.5rem;
  font-size: 1.2rem;
  font-weight: 700;
  color: #fff;
  border-bottom: 1px solid var(--sidebar-border);
  background: rgba(0, 0, 0, 0.15);
  letter-spacing: -0.02em;
}

.sidebar-brand i {
  font-size: 1.5rem;
  color: var(--primary-light);
  filter: drop-shadow(0 0 8px rgba(99, 102, 241, 0.6));
}

.sidebar-nav {
  flex: 1;
  min-height: 0;
  padding: 1rem 0.75rem;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
}

.sidebar-nav::-webkit-scrollbar {
  width: 5px;
}

.sidebar-nav::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar-nav::-webkit-scrollbar-thumb {
  background: rgba(99, 102, 241, 0.35);
  border-radius: 4px;
}

.sidebar-nav::-webkit-scrollbar-thumb:hover {
  background: rgba(99, 102, 241, 0.55);
}

.sidebar-nav .nav-link,
.sidebar-footer .nav-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 1rem;
  color: var(--sidebar-text);
  text-decoration: none;
  border-radius: 0.5rem;
  margin-bottom: 0.2rem;
  transition: background 0.2s ease, color 0.2s ease, transform 0.15s ease;
  border: 1px solid transparent;
}

.sidebar-nav .nav-link i,
.sidebar-footer .nav-link i {
  font-size: 1.1rem;
  width: 1.5rem;
  text-align: center;
  transition: color 0.2s ease;
}

.sidebar-nav .nav-link:hover,
.sidebar-footer .nav-link:hover {
  background: var(--sidebar-surface-hover);
  color: var(--sidebar-text-active);
  border-color: rgba(255, 255, 255, 0.05);
}

.sidebar-nav .nav-link:hover i {
  color: var(--primary-light);
}

.sidebar-nav .nav-link.active {
  background: linear-gradient(90deg, var(--sidebar-surface-active) 0%, rgba(99, 102, 241, 0.08) 100%);
  color: var(--sidebar-text-active);
  border-color: rgba(99, 102, 241, 0.25);
  box-shadow: inset 3px 0 0 var(--primary-light);
  font-weight: 500;
}

.sidebar-nav .nav-link.active i {
  color: var(--primary-light);
}

/* Sidebar section label */
.sidebar-section-label {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--sidebar-label);
  padding: 1.1rem 1rem 0.45rem;
  margin-top: 0.35rem;
  opacity: 0.9;
}

/* Collapsible menu groups */
.nav-group {
  margin-bottom: 0.25rem;
}

.nav-group-toggle {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  padding: 0.6rem 1rem;
  border: 1px solid transparent;
  background: var(--sidebar-surface);
  color: var(--sidebar-text-active);
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: 0.5rem;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
  text-align: left;
}

.nav-group-toggle:hover {
  background: var(--sidebar-surface-hover);
  border-color: rgba(255, 255, 255, 0.06);
}

.nav-group.open > .nav-group-toggle {
  background: linear-gradient(90deg, rgba(99, 102, 241, 0.18) 0%, var(--sidebar-surface) 100%);
  border-color: rgba(99, 102, 241, 0.2);
  box-shadow: inset 3px 0 0 var(--primary);
}

.nav-group-icon {
  font-size: 1rem;
  width: 1.25rem;
  text-align: center;
  color: var(--primary-light);
  opacity: 0.95;
}

.nav-chevron {
  margin-left: auto;
  font-size: 0.75rem;
  transition: transform 0.25s ease;
  opacity: 0.6;
}

.nav-group.open .nav-chevron {
  transform: rotate(0deg);
}

.nav-group:not(.open) .nav-chevron {
  transform: rotate(-90deg);
}

.nav-submenu {
  list-style: none;
  margin: 0;
  padding: 0.35rem 0 0.5rem 0;
  display: none;
}

.nav-group.open .nav-submenu {
  display: block;
}

/* Nested submenu (e.g. Authentication > Basic) */
.nav-subgroup {
  list-style: none;
}

.nav-subgroup-toggle {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  width: calc(100% - 0.7rem);
  margin: 0 0.35rem;
  padding: 0.4rem 1rem 0.4rem 2.25rem;
  border: none;
  background: transparent;
  color: var(--sidebar-text);
  font-size: 0.8125rem;
  font-weight: 500;
  border-radius: 0.35rem;
  cursor: pointer;
  transition: color 0.2s, background 0.2s;
  text-align: left;
}

.nav-subgroup-toggle:hover {
  color: var(--sidebar-text-active);
  background: var(--sidebar-surface-hover);
}

.nav-subgroup.open > .nav-subgroup-toggle {
  color: var(--sidebar-text-active);
  background: rgba(99, 102, 241, 0.12);
}

.nav-subgroup-bullet {
  width: 6px;
  height: 6px;
  border: 1.5px solid currentColor;
  border-radius: 50%;
  flex-shrink: 0;
  opacity: 0.7;
}

.nav-subgroup.open > .nav-subgroup-toggle .nav-subgroup-bullet {
  background: currentColor;
  opacity: 1;
}

.nav-subgroup .nav-chevron {
  margin-left: auto;
  font-size: 0.65rem;
}

.nav-subgroup.open .nav-chevron {
  transform: rotate(0deg);
}

.nav-subgroup:not(.open) .nav-chevron {
  transform: rotate(-90deg);
}

.nav-submenu-nested {
  list-style: none;
  margin: 0;
  padding: 0.2rem 0 0.35rem 0;
  display: none;
}

.nav-subgroup.open .nav-submenu-nested {
  display: block;
}

.nav-submenu-nested .nav-sublink {
  padding-left: 3.1rem;
}

.nav-sublink,
.sidebar-nav > .nav-link {
  scroll-margin-block: 80px;
}

.nav-sublink {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.4rem 1rem 0.4rem 2.25rem;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 0.8125rem;
  transition: color 0.2s, background 0.2s;
  border-radius: 0.35rem;
  margin: 0 0.35rem;
}

.nav-sublink:hover {
  background: var(--sidebar-surface-hover);
  border: 1px solid rgba(255, 255, 255, 0.04);
}

.nav-sublink.active {
  background: linear-gradient(90deg, var(--sidebar-surface-active) 0%, rgba(99, 102, 241, 0.06) 100%);
  color: var(--sidebar-text-active);
  font-weight: 500;
  box-shadow: inset 3px 0 0 var(--primary-light);
  border: 1px solid rgba(99, 102, 241, 0.15);
}

.nav-sublink::before {
  content: "";
  width: 6px;
  height: 6px;
  border: 1.5px solid currentColor;
  border-radius: 50%;
  flex-shrink: 0;
  opacity: 0.7;
}

.nav-sublink:hover,
.nav-sublink.active {
  color: var(--sidebar-text-active);
}

.nav-sublink.active::before {
  background: currentColor;
  opacity: 1;
}

.sidebar-footer {
  padding: 1rem 0.75rem;
  border-top: 1px solid var(--sidebar-border);
  background: rgba(0, 0, 0, 0.2);
}

.sidebar-footer .nav-link.text-danger {
  color: #f87171 !important;
}

.sidebar-footer .nav-link.text-danger:hover {
  background: rgba(248, 113, 113, 0.12);
  border-color: rgba(248, 113, 113, 0.2);
}

/* Main wrapper */
.main-wrapper {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: margin-left 0.3s ease;
}

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  height: var(--topbar-height);
  background: #fff;
  border-bottom: 1px solid #e2e8f0;
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  gap: 1rem;
  z-index: 1030;
}

[data-bs-theme="dark"] .topbar {
  background: #1e293b;
  border-color: #334155;
}

.sidebar-toggle {
  color: inherit;
  padding: 0.25rem;
}

.topbar-search {
  position: relative;
  max-width: 360px;
  flex: 1;
}

.topbar-search i {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: #94a3b8;
}

.topbar-search .form-control {
  padding-left: 2.25rem;
  border-radius: 2rem;
  background: var(--body-bg);
  border: none;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.topbar-actions .btn-link {
  color: inherit;
}

.notification-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  font-size: 0.6rem;
  padding: 0.2em 0.45em;
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
}

/* Page content */
.page-content {
  padding: 1.5rem;
  flex: 1;
}

.page-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.page-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

/* Cards */
.card {
  border: none;
  border-radius: 0.75rem;
  box-shadow: var(--card-shadow);
}

.card-header {
  background: transparent;
  border-bottom: 1px solid #e2e8f0;
  padding: 1rem 1.25rem;
}

[data-bs-theme="dark"] .card-header {
  border-color: #334155;
}

/* Stat cards */
.stat-card .card-body {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1.25rem;
}

.stat-icon {
  width: 52px;
  height: 52px;
  border-radius: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
  flex-shrink: 0;
}

.stat-label {
  font-size: 0.85rem;
  color: #64748b;
  margin-bottom: 0.15rem;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 0.15rem;
}

.stat-change {
  font-size: 0.8rem;
  font-weight: 500;
}

/* Activity list */
.activity-list .activity-item {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid #e2e8f0;
}

[data-bs-theme="dark"] .activity-list .activity-item {
  border-color: #334155;
}

.activity-list .activity-item:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.activity-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* Table */
.table th {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #64748b;
  font-weight: 600;
  border-bottom-width: 1px;
  padding: 0.85rem 1.25rem;
}

.table td {
  padding: 0.85rem 1.25rem;
  font-size: 0.9rem;
}

/* Footer */
.footer {
  padding: 1rem 1.5rem;
  text-align: center;
  font-size: 0.85rem;
}

/* Sidebar overlay */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1035;
}

/* Responsive */
@media (max-width: 991.98px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.show {
    transform: translateX(0);
  }

  .sidebar-overlay.show {
    display: block;
  }

  .main-wrapper {
    margin-left: 0;
  }
}

/* Users page extras */
.user-card .card-body {
  text-align: center;
  padding: 1.5rem;
}

.user-card .avatar-lg {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  margin-bottom: 0.75rem;
}

/* Settings */
.settings-section {
  margin-bottom: 2rem;
}

.settings-section h6 {
  font-weight: 600;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid #e2e8f0;
}

[data-bs-theme="dark"] .settings-section h6 {
  border-color: #334155;
}
