:root {
  --sidebar-width: 290px;
  /* --sidebar-bg: #ffffff; Defined in base.html */
  --sidebar-border: #e5e7eb;
  /* --sidebar-text: #111827; Defined in base.html */
  --sidebar-muted: #6b7280;
  --sidebar-hover: #f3f4f6;
  --sidebar-active: #e0e7ff;
  --sidebar-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
  --sidebar-radius: 14px;
  --sidebar-header-bg-start: var(--sidebar-bg, #ffffff);
  --sidebar-header-bg-end: var(--sidebar-bg, #fbfdff);
  --sidebar-profile-bg: var(--sidebar-bg, #ffffff);
}

[data-bs-theme="dark"] {
  /* --sidebar-bg: #1e293b; */
  --sidebar-border: #334155;
  /* --sidebar-text: #f8fafc; */
  --sidebar-muted: #94a3b8;
  --sidebar-hover: #334155;
  --sidebar-active: #334155;
  --sidebar-shadow: none;
  --sidebar-header-bg-start: #1e293b;
  --sidebar-header-bg-end: #1e293b;
  --sidebar-profile-bg: #1e293b;
}

.app-shell {
  display: flex;
  min-height: calc(100vh - var(--navbar-height));
}

.main-content {
  flex: 1 1 auto;
}

.app-sidebar {
  --bs-offcanvas-width: var(--sidebar-width);
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  flex: 0 0 var(--sidebar-width);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  box-shadow: none;
}

.app-sidebar,
.app-sidebar .offcanvas-body,
.app-sidebar-body {
  scrollbar-width: thin;
  scrollbar-color: rgba(100, 116, 139, 0.6) transparent;
}

.app-sidebar::-webkit-scrollbar,
.app-sidebar .offcanvas-body::-webkit-scrollbar,
.app-sidebar-body::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

.app-sidebar::-webkit-scrollbar-thumb,
.app-sidebar .offcanvas-body::-webkit-scrollbar-thumb,
.app-sidebar-body::-webkit-scrollbar-thumb {
  background-color: rgba(100, 116, 139, 0.6);
  border-radius: 999px;
}

.app-sidebar::-webkit-scrollbar-track,
.app-sidebar .offcanvas-body::-webkit-scrollbar-track,
.app-sidebar-body::-webkit-scrollbar-track {
  background: transparent;
}

.app-sidebar::-webkit-scrollbar-thumb:hover,
.app-sidebar .offcanvas-body::-webkit-scrollbar-thumb:hover,
.app-sidebar-body::-webkit-scrollbar-thumb:hover {
  background-color: rgba(71, 85, 105, 0.75);
}

[data-bs-theme="dark"] .app-sidebar,
[data-bs-theme="dark"] .app-sidebar .offcanvas-body,
[data-bs-theme="dark"] .app-sidebar-body {
  scrollbar-color: rgba(148, 163, 184, 0.55) transparent;
}

[data-bs-theme="dark"] .app-sidebar::-webkit-scrollbar-thumb,
[data-bs-theme="dark"] .app-sidebar .offcanvas-body::-webkit-scrollbar-thumb,
[data-bs-theme="dark"] .app-sidebar-body::-webkit-scrollbar-thumb {
  background-color: rgba(148, 163, 184, 0.55);
}

[data-bs-theme="dark"] .app-sidebar::-webkit-scrollbar-thumb:hover,
[data-bs-theme="dark"]
  .app-sidebar
  .offcanvas-body::-webkit-scrollbar-thumb:hover,
[data-bs-theme="dark"] .app-sidebar-body::-webkit-scrollbar-thumb:hover {
  background-color: rgba(148, 163, 184, 0.8);
}

.app-sidebar.offcanvas,
.app-sidebar.offcanvas-lg {
  top: var(--navbar-height);
  height: calc(100vh - var(--navbar-height));
}

.app-sidebar-header {
  padding: 14px 14px 10px 14px;
  border-bottom: 1px solid var(--sidebar-border);
  background: linear-gradient(
    180deg,
    var(--sidebar-header-bg-start),
    var(--sidebar-header-bg-end)
  );
}

.app-sidebar-header-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  color: var(--sidebar-text);
}

.app-sidebar-body {
  display: flex !important;
  flex-direction: column !important;
  align-items: stretch !important;
  padding: 14px;
}

.app-sidebar-profile {
  width: 100%;
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--sidebar-border);
  border-radius: var(--sidebar-radius);
  background: var(--sidebar-profile-bg);
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.06);
  margin-bottom: 14px;
}

.app-sidebar-avatar {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  background: #eef2ff;
  color: #4338ca;
  font-size: 20px;
}

.app-sidebar-name {
  font-weight: 700;
  color: var(--sidebar-text);
  line-height: 1.2;
}

.app-sidebar-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--sidebar-muted);
}

.app-sidebar-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 8px;
  background: var(--sidebar-hover);
  border-radius: 999px;
  color: var(--sidebar-text);
  font-weight: 600;
}

.app-sidebar-dot {
  opacity: 0.7;
}

.app-sidebar-scope {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  font-size: 12px;
  color: var(--sidebar-muted);
}

.app-sidebar-nav {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.app-sidebar-section-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--sidebar-muted);
  margin-bottom: 8px;
  padding: 0 4px;
  font-weight: 700;
}

.app-sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px;
  border-radius: 12px;
  text-decoration: none;
  color: var(--sidebar-text);
  transition:
    background-color 120ms ease,
    color 120ms ease;
}

.app-sidebar-link i {
  width: 18px;
  text-align: center;
  color: var(--sidebar-muted);
}

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

.app-sidebar-group {
  border: 1px solid var(--sidebar-border);
  border-radius: var(--sidebar-radius);
  background: var(--sidebar-profile-bg);
  overflow: hidden;
}

.app-sidebar-group-title {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  font-weight: 700;
  color: var(--sidebar-text);
  position: relative;
  min-height: 44px;
}

.app-sidebar-group-title::-webkit-details-marker {
  display: none;
}

.app-sidebar-group[open] .app-sidebar-group-title {
  background: var(--sidebar-hover);
}

.app-sidebar-group-title i {
  width: 18px;
  text-align: center;
  color: var(--sidebar-muted);
}

.app-sidebar-group-chevron {
  margin-left: auto;
  color: var(--sidebar-muted);
  transition: transform 120ms ease;
}

.app-sidebar-group[open] .app-sidebar-group-chevron {
  transform: rotate(90deg);
}

.app-sidebar-group-links {
  padding: 6px 8px 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.app-sidebar-link[aria-current="page"],
.app-sidebar-link.is-active {
  background: var(--sidebar-active);
  color: var(--sidebar-text);
  border-left: 3px solid #3b82f6;
}

.navbar-sidebar-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--navbar-border);
  background: var(--navbar-bg);
  color: var(--navbar-text);
  transition: all 0.15s ease-in-out;
}

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

@media (min-width: 992px) {
  .app-shell.has-app-sidebar {
    padding-left: var(--sidebar-width);
  }

  .app-sidebar,
  .app-sidebar.offcanvas-lg {
    display: flex;
    flex-direction: column !important;
    position: fixed;
    top: var(--navbar-height);
    left: 0;
    height: calc(100vh - var(--navbar-height));
    overflow-x: hidden;
    overflow-y: auto !important;
    z-index: 1040;
    transform: none;
  }

  .app-sidebar-header,
  .app-sidebar.offcanvas-lg .offcanvas-header {
    flex: 0 0 auto;
    position: sticky;
    top: 0;
    z-index: 2;
  }

  .app-sidebar-body,
  .app-sidebar.offcanvas-lg .offcanvas-body {
    height: auto;
    overflow: visible !important;
    padding-bottom: 18px;
    flex: 0 0 auto !important;
  }

  .app-shell.has-app-sidebar.sidebar-collapsed {
    padding-left: 0;
  }

  .app-shell.has-app-sidebar.sidebar-collapsed .app-sidebar {
    display: none;
  }
}

#clientSidebar {
  --client-sidebar-width: 240px;
  --client-sidebar-collapsed-width: 70px;
  width: var(--client-sidebar-width);
  min-width: var(--client-sidebar-width);
  flex: 0 0 var(--client-sidebar-width);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  transition: width 0.3s ease-in-out;
}

#clientSidebar.client-sidebar-collapsed {
  width: var(--client-sidebar-collapsed-width);
  min-width: var(--client-sidebar-collapsed-width);
  flex: 0 0 var(--client-sidebar-collapsed-width);
}

.client-sidebar-header {
  padding: 20px;
  border-bottom: 1px solid var(--sidebar-border);
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  gap: 12px;
  min-height: 64px;
}

.client-sidebar-header-text {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 100%;
  overflow: visible;
}

.client-sidebar-title {
  font-weight: 700;
  color: var(--sidebar-text);
  line-height: 1.3;
  margin-bottom: 2px;
}

.client-sidebar-student {
  font-size: 15px;
  font-weight: 600;
  color: var(--sidebar-text);
  line-height: 1.3;
  white-space: normal;
  word-break: break-word;
  margin-top: 10px;
}

.client-sidebar-subtitle {
  font-size: 13px;
  color: #6b7280;
  line-height: 1.3;
  white-space: normal;
  word-break: break-word;
  margin-top: 2px;
}

.client-sidebar-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--sidebar-border);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  transition: all 0.15s ease-in-out;
}

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

.client-sidebar-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px;
  border-radius: 12px;
  text-decoration: none;
  color: var(--sidebar-text);
  transition:
    background-color 120ms ease,
    color 120ms ease;
}

.client-sidebar-item i {
  width: 18px;
  text-align: center;
  color: var(--sidebar-muted);
  flex-shrink: 0;
}

.client-sidebar-item:hover {
  background: var(--sidebar-hover);
  color: var(--sidebar-text);
}

.client-sidebar-item.active {
  background: var(--sidebar-active);
  color: var(--sidebar-text);
  border-left: 3px solid #3b82f6;
}

.client-sidebar-text {
  white-space: nowrap;
  opacity: 1;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  transition:
    opacity 0.3s ease-in-out,
    max-width 0.3s ease-in-out;
}

#clientSidebar.client-sidebar-collapsed .client-sidebar-text {
  opacity: 0;
  max-width: 0;
  pointer-events: none;
}

#clientSidebar.client-sidebar-collapsed .client-sidebar-item {
  justify-content: center;
  gap: 0;
}

#clientSidebar.client-sidebar-collapsed .client-sidebar-student,
#clientSidebar.client-sidebar-collapsed .client-sidebar-subtitle {
  opacity: 0;
  max-height: 0;
  margin-top: 0;
  overflow: hidden;
  pointer-events: none;
}

@media (max-width: 767.98px) {
  #clientSidebar {
    display: none;
  }
}
