:root {
  --sidebar-expanded-width: 252px;
  --sidebar-collapsed-width: 76px;
  --sidebar-surface: #0f172a;
  --sidebar-border: rgba(148, 163, 184, 0.16);
  --sidebar-text: #a8b3c7;
  --sidebar-text-strong: #f8fafc;
  --sidebar-hover: rgba(148, 163, 184, 0.09);
  --sidebar-active: rgba(59, 130, 246, 0.12);
  --sidebar-accent: #818cf8;
  --sidebar-focus: #818cf8;
  --sidebar-badge-bg: rgba(124, 58, 237, 0.18);
  --sidebar-badge-text: #c4b5fd;
  --sidebar-badge-border: rgba(167, 139, 250, 0.35);
}

[data-theme="light"] {
  --sidebar-surface: #f8fafc;
  --sidebar-border: #dce3ec;
  --sidebar-text: #52627a;
  --sidebar-text-strong: #172033;
  --sidebar-hover: #f0f4f9;
  --sidebar-active: #eef4ff;
  --sidebar-accent: #4f46e5;
  --sidebar-focus: #6366f1;
  --sidebar-badge-bg: #ede9fe;
  --sidebar-badge-text: #6d28d9;
  --sidebar-badge-border: #ddd6fe;
}

/* Shared visual layer for the three sidebar structures used by static sections. */
.section-sidebar,
.section-home-sidebar,
.app-layout > .sidebar {
  box-sizing: border-box;
  background: var(--sidebar-surface) !important;
  border-right: 1px solid var(--sidebar-border) !important;
  scrollbar-color: var(--sidebar-border) transparent;
}

.app-layout {
  --section-sidebar-width: var(--sidebar-collapsed-width) !important;
}

.app-layout:has(.section-sidebar:hover),
.app-layout:has(> .sidebar:hover) {
  --section-sidebar-width: var(--sidebar-expanded-width) !important;
}

body {
  --home-sidebar-width: var(--sidebar-collapsed-width) !important;
}

body:has(.section-home-sidebar:hover) {
  --home-sidebar-width: var(--sidebar-expanded-width) !important;
}

.sidebar-brand,
.section-home-brand,
.app-layout > .sidebar .brand {
  min-height: 56px !important;
  padding: 7px 10px !important;
  gap: 12px !important;
  color: var(--sidebar-text-strong) !important;
  text-decoration: none;
}

.sidebar-brand img,
.section-home-brand img,
.app-layout > .sidebar .brand img {
  width: 40px !important;
  height: 40px !important;
  flex: 0 0 40px;
  border-radius: 11px !important;
  object-fit: cover;
}

.sidebar-brand-text,
.section-home-brand-text,
.app-layout > .sidebar .brand-label {
  color: var(--sidebar-text-strong) !important;
  font-size: 18px !important;
  font-weight: 700 !important;
  line-height: 1.15;
  white-space: nowrap;
}

.section-nav,
.section-home-nav,
.app-layout > .sidebar .nav {
  display: flex;
  flex-direction: column;
  gap: 5px !important;
  padding: 12px 10px !important;
}

.section-link,
.section-home-link,
.app-layout > .sidebar .nav-link {
  position: relative;
  box-sizing: border-box;
  overflow: visible !important;
  min-height: 50px !important;
  height: 50px !important;
  padding: 0 14px !important;
  gap: 12px !important;
  border: 0 !important;
  border-radius: 11px !important;
  background: transparent !important;
  color: var(--sidebar-text) !important;
  font-size: 15px !important;
  font-weight: 650 !important;
  line-height: 1;
  text-decoration: none;
  transition: background-color 150ms ease, color 150ms ease, border-color 150ms ease !important;
}

.section-link::before,
.section-home-link::before,
.app-layout > .sidebar .nav-link::before {
  content: "";
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 999px;
  background: linear-gradient(180deg, #2563eb 0%, #7c3aed 100%);
  opacity: 0;
}

.section-link:hover,
.section-home-link:hover,
.app-layout > .sidebar .nav-link:hover {
  background: var(--sidebar-hover) !important;
  color: var(--sidebar-text-strong) !important;
  transform: none !important;
  box-shadow: none !important;
}

.section-link.active,
.section-home-link.active,
.app-layout > .sidebar .nav-link.active,
.section-link[aria-current="page"],
.section-home-link[aria-current="page"],
.app-layout > .sidebar .nav-link[aria-current="page"] {
  background: var(--sidebar-active) !important;
  color: var(--sidebar-text-strong) !important;
  box-shadow: none !important;
}

.section-link.active::before,
.section-home-link.active::before,
.app-layout > .sidebar .nav-link.active::before,
.section-link[aria-current="page"]::before,
.section-home-link[aria-current="page"]::before,
.app-layout > .sidebar .nav-link[aria-current="page"]::before {
  opacity: 1;
}

.section-link:focus-visible,
.section-home-link:focus-visible,
.app-layout > .sidebar .nav-link:focus-visible,
.sidebar-brand:focus-visible,
.section-home-brand:focus-visible,
.app-layout > .sidebar .brand:focus-visible {
  outline: 2px solid var(--sidebar-focus) !important;
  outline-offset: 2px;
}

.section-icon,
.section-home-icon,
.app-layout > .sidebar .nav-icon {
  position: relative;
  display: inline-flex !important;
  width: 24px !important;
  height: 24px !important;
  flex: 0 0 24px;
  align-items: center;
  justify-content: center;
  overflow: visible !important;
  color: currentColor !important;
  font-size: 0 !important;
}

.section-icon svg,
.section-home-icon svg,
.app-layout > .sidebar .nav-icon svg {
  display: block;
  width: 19px;
  height: 19px;
  overflow: visible;
  stroke: currentColor;
}

.section-link.active .section-icon,
.section-home-link.active .section-home-icon,
.app-layout > .sidebar .nav-link.active .nav-icon,
[aria-current="page"] > .section-icon,
[aria-current="page"] > .section-home-icon,
[aria-current="page"] > .nav-icon {
  color: var(--sidebar-accent) !important;
}

.shared-nav-label {
  display: inline-flex;
  min-width: 0;
  flex: 1 1 auto;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  white-space: nowrap;
}

.shared-nav-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 2px 6px;
  border: 1px solid var(--sidebar-badge-border);
  border-radius: 999px;
  background: var(--sidebar-badge-bg);
  color: var(--sidebar-badge-text);
  font-size: 10px;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: 0.04em;
}

.shared-nav-new-dot {
  position: absolute;
  top: 0;
  right: 0;
  display: none;
  width: 7px;
  height: 7px;
  box-sizing: border-box;
  border: 1px solid var(--sidebar-surface);
  border-radius: 999px;
  background: #7c3aed;
  box-shadow: 0 0 0 1px rgba(124, 58, 237, 0.14);
  pointer-events: none;
}

/* Existing collapsed mode: preserve the icon rail and expose full labels on hover. */
.app-layout:has(.section-sidebar):not(:has(.section-sidebar:hover)) .shared-nav-badge,
.app-layout:has(> .sidebar):not(:has(> .sidebar:hover)) .shared-nav-badge,
body:has(.section-home-sidebar):not(:has(.section-home-sidebar:hover)) .shared-nav-badge {
  display: none;
}

.app-layout:has(.section-sidebar):not(:has(.section-sidebar:hover)) .shared-nav-new-dot,
.app-layout:has(> .sidebar):not(:has(> .sidebar:hover)) .shared-nav-new-dot,
body:has(.section-home-sidebar):not(:has(.section-home-sidebar:hover)) .shared-nav-new-dot {
  display: block;
}

/* Keep every desktop icon rail on the same geometry regardless of legacy page CSS. */
.app-layout:has(.section-sidebar):not(:has(.section-sidebar:hover)) .section-link,
.app-layout:has(> .sidebar):not(:has(> .sidebar:hover)) > .sidebar .nav-link,
body:has(.section-home-sidebar):not(:has(.section-home-sidebar:hover)) .section-home-link,
body.with-sidebar:not(:has(.section-sidebar:hover)) .section-link {
  width: 44px !important;
  min-width: 44px !important;
  max-width: 44px !important;
  padding: 0 !important;
  gap: 0 !important;
  justify-content: center !important;
}

.app-layout:has(.section-sidebar):not(:has(.section-sidebar:hover)) .section-link .shared-nav-label,
.app-layout:has(> .sidebar):not(:has(> .sidebar:hover)) > .sidebar .nav-link .shared-nav-label,
body:has(.section-home-sidebar):not(:has(.section-home-sidebar:hover)) .section-home-link .shared-nav-label,
body.with-sidebar:not(:has(.section-sidebar:hover)) .section-link .shared-nav-label {
  width: 0 !important;
  min-width: 0 !important;
  flex: 0 0 0 !important;
  opacity: 0 !important;
  overflow: hidden !important;
  pointer-events: none !important;
}

/* Keep the collapsed brand inside the same 44px rail without legacy-page clipping. */
.app-layout:has(.section-sidebar):not(:has(.section-sidebar:hover)) .sidebar-brand,
.app-layout:has(> .sidebar):not(:has(> .sidebar:hover)) > .sidebar .brand,
body:has(.section-home-sidebar):not(:has(.section-home-sidebar:hover)) .section-home-brand,
body.with-sidebar:not(:has(.section-sidebar:hover)) .sidebar-brand {
  box-sizing: border-box !important;
  width: 44px !important;
  min-width: 44px !important;
  max-width: 44px !important;
  margin-inline: auto !important;
  padding: 2px !important;
  gap: 0 !important;
  justify-content: center !important;
  overflow: visible !important;
}

.app-layout:has(.section-sidebar):not(:has(.section-sidebar:hover)) .sidebar-brand img,
.app-layout:has(> .sidebar):not(:has(> .sidebar:hover)) > .sidebar .brand img,
body:has(.section-home-sidebar):not(:has(.section-home-sidebar:hover)) .section-home-brand img,
body.with-sidebar:not(:has(.section-sidebar:hover)) .sidebar-brand img {
  display: block !important;
  width: 40px !important;
  height: 40px !important;
  max-width: 40px !important;
  flex: 0 0 40px !important;
}

.section-link:nth-child(2),
.section-home-link:nth-child(2),
.app-layout > .sidebar .nav-link:nth-child(2),
.section-link:nth-child(5),
.section-home-link:nth-child(5),
.app-layout > .sidebar .nav-link:nth-child(5) {
  margin-bottom: 7px;
}

@media (max-width: 1180px) {
  .app-layout,
  body {
    --section-sidebar-width: 100% !important;
    --home-sidebar-width: 100% !important;
  }

  .section-sidebar,
  .section-home-sidebar,
  .app-layout > .sidebar {
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
    width: 100% !important;
    padding: 8px 10px !important;
    overflow: hidden !important;
    border-right: 0 !important;
    border-bottom: 1px solid var(--sidebar-border) !important;
  }

  .sidebar-brand,
  .section-home-brand,
  .app-layout > .sidebar .brand {
    width: 190px !important;
    min-width: 190px !important;
    flex: 0 0 190px !important;
    overflow: visible !important;
  }

  .section-nav,
  .section-home-nav,
  .app-layout > .sidebar .nav {
    width: auto !important;
    min-width: 0 !important;
    flex: 1 1 auto !important;
    flex-direction: row;
    gap: 5px !important;
    padding: 5px 8px 9px !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    scrollbar-width: thin;
  }

  .section-link,
  .section-home-link,
  .app-layout > .sidebar .nav-link {
    width: max-content !important;
    min-width: max-content;
    max-width: none !important;
    flex: 0 0 auto !important;
    height: 44px !important;
    min-height: 44px !important;
    padding: 0 12px !important;
    white-space: nowrap !important;
  }

  .shared-nav-label {
    width: auto !important;
    min-width: max-content !important;
    flex: 1 1 auto !important;
    opacity: 1 !important;
    overflow: visible !important;
    pointer-events: auto !important;
  }

  .section-link::before,
  .section-home-link::before,
  .app-layout > .sidebar .nav-link::before {
    left: 12px;
    right: 12px;
    top: auto;
    bottom: 2px;
    width: auto;
    height: 3px;
  }

  .section-link:nth-child(2),
  .section-home-link:nth-child(2),
  .app-layout > .sidebar .nav-link:nth-child(2),
  .section-link:nth-child(5),
  .section-home-link:nth-child(5),
  .app-layout > .sidebar .nav-link:nth-child(5) {
    margin-bottom: 0;
    margin-right: 7px;
  }

  .shared-nav-badge {
    display: inline-flex !important;
  }

  .shared-nav-new-dot {
    display: none !important;
  }
}

@media (max-width: 640px) {
  .sidebar-brand,
  .section-home-brand,
  .app-layout > .sidebar .brand {
    min-height: 50px !important;
  }

  .sidebar-brand img,
  .section-home-brand img,
  .app-layout > .sidebar .brand img {
    width: 36px !important;
    height: 36px !important;
    flex-basis: 36px;
  }

  .sidebar-brand-text,
  .section-home-brand-text,
  .app-layout > .sidebar .brand-label {
    font-size: 17px !important;
  }

  .sidebar-brand,
  .section-home-brand,
  .app-layout > .sidebar .brand {
    width: 174px !important;
    min-width: 174px !important;
    flex-basis: 174px !important;
  }
}
