/* Sidebar layout */
:root {
  --th-sidebar-text: #7d84ab;
  --th-sidebar-text-strong: #dee2ec;
  --th-sidebar-bg: #0c1e35;
  --th-sidebar-bg-2: #0b1a2c;
  --th-sidebar-border: rgba(83, 93, 125, 0.3);
  --th-sidebar-header-h: 100px;
  --th-sidebar-footer-h: 230px;
}

.sidebar {
  grid-column: 1;
  position: sticky;
  top: 0;
  width: 260px;
  min-width: 260px;
  max-width: 260px;
  height: calc(100vh - 24px - var(--page-top-gap));
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px 12px 12px;
  overflow-y: auto;
  overflow-x: hidden !important;
  color: var(--th-sidebar-text);
  background: linear-gradient(180deg, rgba(20, 29, 51, 0.92), rgba(12, 18, 32, 0.94));
  border: 1px solid var(--th-sidebar-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: width 0.2s ease, padding 0.2s ease;
  scrollbar-width: thin;
  scrollbar-color: transparent var(--th-sidebar-bg);
  overscroll-behavior: contain;
}

.sidebar::-webkit-scrollbar {
  width: 6px;
  height: 6px;
  background: var(--th-sidebar-bg);
}

.sidebar::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: transparent;
}

.sidebar:hover::-webkit-scrollbar-thumb {
  background: rgba(78, 168, 222, 0.35);
}

body.sidebar-collapsed .app-shell {
  grid-template-columns: 86px 1fr;
}

body.sidebar-collapsed .sidebar {
  width: 86px;
  min-width: 86px;
  max-width: 86px;
  padding: 16px 10px;
}

body.sidebar-collapsed .brand {
  justify-content: center;
  padding-bottom: 10px;
  min-height: auto;
}

body.sidebar-collapsed .brand > div:last-child {
  display: none;
}

body.sidebar-collapsed .nav {
  gap: 6px;
}

body.sidebar-collapsed .nav-section {
  display: none;
}

body.sidebar-collapsed .nav-group {
  display: grid;
  gap: 6px;
}

body.sidebar-collapsed .nav-group.is-collapsed {
  display: grid;
}

body.sidebar-collapsed .nav-link {
  justify-content: center;
  gap: 0;
  min-height: 42px;
  padding: 8px 0;
  position: relative;
}

body.sidebar-collapsed .nav-text,
body.sidebar-collapsed .nav-badge {
  display: none;
}

body.sidebar-collapsed .sidebar-card {
  display: none;
}

body.sidebar-collapsed .nav-link::after {
  content: attr(data-label);
  position: absolute;
  left: calc(100% + 12px);
  top: 50%;
  transform: translateY(-50%);
  background: rgba(10, 17, 30, 0.96);
  color: var(--th-sidebar-text-strong);
  border: 1px solid rgba(78, 168, 222, 0.4);
  border-radius: 8px;
  padding: 6px 9px;
  white-space: nowrap;
  font-size: 0.78rem;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.16s ease;
  z-index: 30;
}

body.sidebar-collapsed .nav-link:hover::after {
  opacity: 1;
  visibility: visible;
}

body[data-theme="alt"] .sidebar {
  background: linear-gradient(180deg, rgba(248, 250, 253, 0.95), rgba(234, 240, 249, 0.95));
  border-color: rgba(148, 163, 184, 0.5);
  color: #5b6487;
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.12);
}

body[data-theme="alt"] .brand {
  border-bottom-color: rgba(148, 163, 184, 0.45);
}

.sidebar-toggle {
  position: fixed;
  top: 26px;
  left: calc(24px + 260px - 12px);
  width: 24px;
  height: 24px;
  border-radius: 999px;
  border: 1px solid rgba(35, 50, 82, 0.7);
  background: rgba(12, 18, 32, 0.9);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  z-index: 80;
  cursor: pointer;
  box-shadow: 0 6px 14px rgba(6, 10, 20, 0.35);
}

body.sidebar-collapsed .sidebar-toggle {
  left: calc(24px + 86px - 12px);
}

body[data-theme="alt"] .sidebar-toggle {
  background: #eef3fb;
  border-color: rgba(148, 163, 184, 0.5);
}

.sidebar-toggle-bar {
  width: 12px;
  height: 2px;
  border-radius: 999px;
  background: #e2e8f0;
  display: block;
}

body[data-theme="alt"] .sidebar-toggle-bar {
  background: #1f2a44;
}

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(6, 10, 20, 0.55);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease;
  z-index: 55;
}

body[data-theme="alt"] .sidebar-backdrop {
  background: rgba(15, 23, 42, 0.2);
}

body.sidebar-open .sidebar-backdrop {
  opacity: 1;
  visibility: visible;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--th-sidebar-header-h);
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(35, 50, 82, 0.6);
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  min-width: 0;
  overflow: hidden;
}

.brand:hover {
  text-decoration: none;
}

.brand:focus {
  outline: none;
  box-shadow: 0 0 0 4px rgba(78, 168, 222, 0.08);
  border-radius: 8px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: linear-gradient(135deg, #4ea8de, #2dd4bf);
  color: #0b1220;
  font-weight: 700;
  display: grid;
  place-items: center;
}

.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.brand-name {
  font-weight: 600;
  letter-spacing: 0.3px;
}

.brand-sub {
  font-size: 0.75rem;
  color: var(--muted);
}

.nav {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  gap: 2px;
  padding: 8px 0;
}

.nav-section {
  margin-top: 6px;
  display: block;
}

.nav-section-toggle {
  width: 100%;
  background: transparent;
  border: none;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1.4px;
  font-size: 0.7rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 2px;
  cursor: pointer;
  opacity: 0.72;
  transition: opacity 0.2s ease;
}

.nav-section-toggle:hover {
  opacity: 1;
}

body[data-theme="alt"] .nav-section-toggle {
  color: #5c6c86;
}

.nav-section-toggle::after {
  content: "";
  width: 8px;
  height: 8px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  transition: transform 0.2s ease;
  opacity: 0.7;
}

.nav-section-toggle.is-collapsed::after {
  transform: rotate(-45deg);
}

.nav-group {
  display: grid;
  gap: 4px;
  margin-bottom: 2px;
  min-width: 0;
}

.nav-group.is-collapsed {
  display: none;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  min-width: 0;
  padding: 0 10px;
  border-radius: 10px;
  color: var(--muted);
  text-decoration: none;
  background: transparent;
  border: 1px solid transparent;
  overflow: hidden;
  transition: all 0.2s ease;
}

.nav-icon {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: rgba(11, 26, 44, 0.9);
  border: 1px solid rgba(35, 50, 82, 0.6);
  color: var(--text);
  flex-shrink: 0;
  transition: color 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}

.nav-icon svg {
  width: 16px;
  height: 16px;
}

.nav-text {
  flex: 1;
  min-width: 0;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--th-sidebar-text);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  transition: color 0.2s ease;
}

.nav-badge {
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border: 1px solid rgba(35, 50, 82, 0.8);
  background: rgba(12, 18, 32, 0.8);
  color: var(--muted);
  margin-left: auto;
  flex-shrink: 0;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

body[data-theme="alt"] .nav-badge {
  background: #eef3fb;
  border-color: rgba(148, 163, 184, 0.45);
  color: #4b5b75;
}

.nav-badge.warning {
  color: var(--warning);
  border-color: rgba(245, 158, 11, 0.4);
}

.nav-link:hover,
.nav-link.active {
  color: var(--th-sidebar-text-strong);
  background: rgba(78, 168, 222, 0.22);
  border-color: rgba(78, 168, 222, 0.45);
}

.nav-link:hover .nav-icon,
.nav-link.active .nav-icon {
  border-color: rgba(78, 168, 222, 0.6);
  color: var(--th-sidebar-text-strong);
  transform: translateY(-1px);
}

.nav-link:hover .nav-text,
.nav-link.active .nav-text {
  color: var(--th-sidebar-text-strong);
}

body[data-theme="alt"] .nav-icon {
  background: #eef3fb;
  border-color: rgba(148, 163, 184, 0.5);
  color: #1f2a44;
}

body[data-theme="alt"] .nav-link {
  color: #4b5b75;
}

body[data-theme="alt"] .nav-link:hover,
body[data-theme="alt"] .nav-link.active {
  color: #1f2a44;
  background: rgba(78, 168, 222, 0.15);
  border-color: rgba(78, 168, 222, 0.35);
}

@keyframes sidebar-swing {
  0%,
  100% {
    transform: rotate(0deg);
  }
  25% {
    transform: rotate(8deg);
  }
  75% {
    transform: rotate(-8deg);
  }
}

.nav-link:hover .nav-icon svg {
  animation: sidebar-swing 0.45s ease-in-out 1;
}

.sidebar-card {
  margin-top: 10px;
  min-height: var(--th-sidebar-footer-h);
  padding: 16px;
  background: var(--card-soft);
  border-radius: 10px;
  border: 1px solid rgba(35, 50, 82, 0.6);
  min-width: 0;
  overflow: hidden;
}

body[data-theme="alt"] .sidebar-card {
  background: #f4f7fb;
  border-color: rgba(148, 163, 184, 0.45);
  box-shadow: 0 12px 24px rgba(15, 23, 42, 0.08);
}

.sidebar-title {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 12px;
  letter-spacing: 0.3px;
}

.sidebar-list {
  padding-left: 16px;
  margin: 0;
  color: var(--text);
  font-size: 0.85rem;
  line-height: 1.4;
  overflow: hidden;
  overflow-wrap: anywhere;
}

@media (max-width: 980px) {
  body.sidebar-collapsed .app-shell {
    grid-template-columns: 86px 1fr;
  }

  .app-shell {
    grid-template-columns: 240px 1fr;
    gap: 16px;
    padding: var(--page-top-gap) 16px 16px 16px;
  }

  body.sidebar-open {
    overflow: auto;
  }

  .sidebar {
    width: 240px;
    min-width: 240px;
    max-width: 240px;
    height: calc(100vh - 16px - var(--page-top-gap));
    border-radius: var(--radius);
  }

  body.sidebar-open .sidebar {
    transform: none;
  }

  .sidebar-toggle {
    left: calc(16px + 240px - 12px);
  }

  body.sidebar-collapsed .sidebar-toggle {
    left: calc(16px + 86px - 12px);
  }

  .sidebar-backdrop {
    display: none;
  }
}
