html {
  --ui-surface: #f8f9fb;
  --ui-surface-dim: #d9dadc;
  --ui-surface-bright: #f8f9fb;
  --ui-surface-container-lowest: #ffffff;
  --ui-surface-container-low: #f3f4f6;
  --ui-surface-container: #edeef0;
  --ui-surface-container-high: #e7e8ea;
  --ui-surface-container-highest: #e1e2e4;
  --ui-on-surface: #191c1e;
  --ui-on-surface-variant: #504632;
  --ui-inverse-surface: #2e3132;
  --ui-inverse-on-surface: #f0f1f3;
  --ui-outline: #82765f;
  --ui-outline-variant: #d4c5ab;
  --ui-primary: #003d7a;
  --ui-on-primary: #ffffff;
  --ui-primary-container: #ffc000;
  --ui-on-primary-container: #261a00;
  --ui-secondary: #5f5e5e;
  --ui-on-secondary: #ffffff;
  --ui-secondary-container: #e5e2e1;
  --ui-tertiary: #585f6c;
  --ui-tertiary-container: #c3cada;
  --ui-error: #ba1a1a;
  --ui-error-container: #ffdad6;
  --ui-on-error-container: #93000a;
  --ui-status-st: #dcfce7;
  --ui-status-st-text: #166534;
  --ui-status-mt: #fef0c7;
  --ui-status-mt-text: #b54708;
  --ui-status-lt: #fde8e8;
  --ui-status-lt-text: #b42318;
  --color-app-bg: 248 249 251;
  --color-surface: 255 255 255;
  --color-surface-elevated: 237 238 240;
  --color-surface-muted: 243 244 246;
  --color-text-primary: 25 28 30;
  --color-text-secondary: 95 94 94;
  --color-text-muted: 130 118 95;
  --color-border: 229 231 235;
  --color-brand: 0 61 122;
  --color-brand-hover: 0 43 91;
  --color-brand-soft: 239 246 255;
  --color-accent: 255 192 0;
  --color-success-bg: 220 252 231;
  --color-success-text: 22 101 52;
  --color-danger-bg: 253 232 232;
  --color-danger-text: 180 35 24;
  min-height: 100%;
  margin: 0;
  background: rgb(var(--color-app-bg));
  overscroll-behavior: none;
}

/* Reserve the page scrollbar gutter without turning html into a competing scroll container.
   Body remains the single owner of page scrolling, which keeps sticky sidebar positioning
   reliable on long admin and division pages. */
@media screen {
  html:has(:is([data-admin-roles-page], [data-admin-catalog-page])),
  html:has(:is([data-division-map-page], [data-division-org-chart-page])) {
    scrollbar-gutter: stable;
  }

  /* The document owns Division page scrolling. A body scroll container with overscroll
     disabled traps wheel gestures before they reach the document scrollbar. */
  body:has(:is([data-division-map-page], [data-division-org-chart-page])) {
    overflow-x: clip;
    overflow-y: visible;
  }
}

html.dark {
  --ui-surface: #111315;
  --ui-surface-dim: #0c0e0f;
  --ui-surface-bright: #383a3c;
  --ui-surface-container-lowest: #0b0d0e;
  --ui-surface-container-low: #191c1e;
  --ui-surface-container: #1f2224;
  --ui-surface-container-high: #292c2e;
  --ui-surface-container-highest: #343739;
  --ui-on-surface: #e1e2e4;
  --ui-on-surface-variant: #d4c5ab;
  --ui-inverse-surface: #e1e2e4;
  --ui-inverse-on-surface: #2e3132;
  --ui-outline: #9b8f77;
  --ui-outline-variant: #504632;
  --ui-primary: #fbbd00;
  --ui-on-primary: #3f2e00;
  --ui-primary-container: #5b4300;
  --ui-on-primary-container: #ffdf9e;
  --ui-secondary: #c8c6c5;
  --ui-on-secondary: #303030;
  --ui-secondary-container: #474646;
  --ui-tertiary: #c0c7d6;
  --ui-tertiary-container: #404754;
  --ui-error: #ffb4ab;
  --ui-error-container: #93000a;
  --ui-on-error-container: #ffdad6;
  --ui-status-st: #123d26;
  --ui-status-st-text: #b7f5ca;
  --ui-status-mt: #4b3605;
  --ui-status-mt-text: #ffdf9e;
  --ui-status-lt: #5b2020;
  --ui-status-lt-text: #ffdad6;
  --color-app-bg: 17 19 21;
  --color-surface: 25 28 30;
  --color-surface-elevated: 41 44 46;
  --color-surface-muted: 31 34 36;
  --color-text-primary: 225 226 228;
  --color-text-secondary: 200 198 197;
  --color-text-muted: 155 143 119;
  --color-border: 71 70 70;
  --color-brand: 251 189 0;
  --color-brand-hover: 255 208 64;
  --color-brand-soft: 91 67 0;
  --color-success-bg: 20 83 45;
  --color-success-text: 187 247 208;
  --color-danger-bg: 91 32 32;
  --color-danger-text: 255 218 214;
  color-scheme: dark;
}

body {
  min-height: 100%;
  margin: 0;
  background: rgb(var(--color-app-bg));
  color: rgb(var(--color-text-primary));
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: none;
}

.sidebar-main-section {
  scrollbar-width: none;
}

.sidebar-main-section::-webkit-scrollbar {
  display: none;
}

@media (max-height: 760px) {
  #sidebar .sidebar-main-section {
    gap: 0.4rem;
    padding: 0.65rem 1rem;
  }

  #sidebar .sidebar-logo {
    width: auto;
    height: 2.25rem;
  }

  #sidebar .nav-section-label {
    padding-top: 0.2rem;
    padding-bottom: 0.2rem;
  }

  #sidebar .nav-section-label span:first-child {
    font-size: 0.58rem;
    line-height: 0.75rem;
  }

  #sidebar .nav-item {
    gap: 0.65rem;
    padding: 0.35rem 0.75rem;
    font-size: 0.75rem;
    line-height: 1rem;
  }

  #sidebar .nav-item svg {
    width: 1rem;
    height: 1rem;
  }

  #sidebar .bottom-section {
    gap: 0.35rem;
    padding: 0.6rem 1rem;
  }

  #sidebar .export-btn {
    padding-top: 0.4rem;
    padding-bottom: 0.4rem;
    font-size: 0.72rem;
  }

  #sidebar .bottom-section form button {
    padding-top: 0.35rem;
    padding-bottom: 0.35rem;
    font-size: 0.75rem;
  }
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

#sidebar {
  transition: transform 0.3s ease, width 0.3s ease;
  background: #111315 !important;
  border-color: #2e3132 !important;
  color: #f0f1f3;
}

#sidebar.sidebar-restoring {
  transition: none !important;
}

@media (min-width: 768px) {
  #sidebar.collapsed {
    width: 64px !important;
  }
}

#sidebar .brand-header {
  transition: padding 0.3s ease;
}

#sidebar .logo-text h1 {
  color: #f8f9fb !important;
}

#sidebar .logo-text p,
#sidebar .sidebar-label {
  color: #9ca3af !important;
}

#sidebar .nav-item {
  position: relative;
  color: #c8c6c5;
}

#sidebar .nav-item:hover:not(.active) {
  background: #242729;
  color: #ffffff;
}

#sidebar .nav-item.active {
  border-color: #ffc000;
  background: #ffc000;
  color: #261a00;
  box-shadow: none;
}

#sidebar .nav-item.active::before {
  position: absolute;
  top: 0.45rem;
  bottom: 0.45rem;
  left: -0.55rem;
  width: 4px;
  border-radius: 9999px;
  background: #ffc000;
  content: "";
}

#sidebar .sidebar-footer {
  border-color: #2e3132 !important;
  background: #111315 !important;
}

#sidebar .sidebar-footer > a {
  background: #ffc000;
  color: #261a00;
}

#sidebar .sidebar-footer > button {
  background: #242729;
  color: #f0f1f3;
}

#sidebar .sidebar-footer > button:hover {
  background: #2e3132;
}

#sidebar #sidebarToggleCollapse {
  border-color: #504632;
  background: #191c1e;
  color: #ffc000;
}

#sidebar #sidebarToggleCollapse:hover,
#sidebar #sidebarMobileClose:hover {
  background: #2e3132;
  color: #ffc000;
}

#sidebar.mobile-open {
  transform: translateX(0) !important;
}


.theme-toggle {
  position: relative;
  display: inline-flex;
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 50%;
  background: #ffffff;
  color: #111111;
  cursor: pointer;
  box-shadow: 0 2px 8px rgb(17 17 17 / 0.1);
  isolation: isolate;
  transition: background-color 0.3s ease, color 0.3s ease, box-shadow 0.3s ease;
}

.theme-toggle:hover {
  background: #f3f4f6;
  box-shadow: 0 3px 10px rgb(17 17 17 / 0.16);
}

.theme-toggle:focus-visible {
  outline: 2px solid rgb(var(--color-brand));
  outline-offset: 3px;
}

.theme-icon {
  position: absolute;
  z-index: 1;
  width: 22px;
  height: 22px;
  transition: opacity 0.22s ease, transform 0.3s ease, color 0.3s ease, fill 0.3s ease, stroke 0.3s ease;
}

.theme-icon-sun {
  opacity: 1;
  transform: rotate(0deg) scale(1);
}

.theme-icon-moon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 21px;
  line-height: 1;
  opacity: 0;
  transform: rotate(-90deg) scale(0.7);
}

html.dark .theme-toggle {
  background: #111111;
  color: #ffffff;
  box-shadow: 0 2px 8px rgb(0 0 0 / 0.3);
}

html.dark .theme-toggle:hover {
  background: #242424;
  box-shadow: 0 3px 10px rgb(0 0 0 / 0.4);
}

html.dark .theme-icon-sun {
  opacity: 0;
  transform: rotate(90deg) scale(0.7);
}

html.dark .theme-icon-moon {
  opacity: 1;
  transform: rotate(0deg) scale(1);
}

::view-transition-group(root),
::view-transition-old(root),
::view-transition-new(root) {
  animation: none;
  mix-blend-mode: normal;
}

::view-transition-image-pair(root) {
  isolation: auto;
}

::view-transition-old(root) {
  z-index: 1;
}

::view-transition-new(root) {
  z-index: 9999;
  backface-visibility: hidden;
  transform: translateZ(0);
  will-change: clip-path;
}

html.theme-revealing *,
html.theme-revealing *::before,
html.theme-revealing *::after {
  transition: none !important;
}

html.theme-crossfade,
html.theme-crossfade body,
html.theme-crossfade .app-shell,
html.theme-crossfade header,
html.theme-crossfade main,
html.theme-crossfade section,
html.theme-crossfade article,
html.theme-crossfade .app-card {
  transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

html.dark .app-shell {
  color: rgb(var(--color-text-primary));
}

html.dark [class~="bg-[#F5F7FA]"] {
  background-color: rgb(var(--color-app-bg)) !important;
}

/* Compatibility layer for existing light utility classes and JS-rendered markup. */
html.dark .bg-white,
html.dark [class~="bg-[#FFFFFF]"],
html.dark [class~="bg-[#fff]"],
html.dark [class~="bg-[#F9FAFB]"],
html.dark [class~="bg-[#FAFBFC]"] {
  background-color: rgb(var(--color-surface)) !important;
}

html.dark .bg-slate-50,
html.dark .bg-slate-100,
html.dark .bg-gray-50,
html.dark .bg-gray-100,
html.dark [class~="bg-[#F3F4F6]"],
html.dark [class~="bg-[#F3F3F9]"],
html.dark [class~="bg-[#F5F5F5]"],
html.dark [class~="bg-[#F8F9FB]"],
html.dark [class~="bg-[#F8FAFC]"],
html.dark [class~="bg-[#FBFCFE]"],
html.dark [class~="bg-[#F8FBFF]"],
html.dark [class~="bg-[#FAFAFA]"] {
  background-color: rgb(var(--color-surface-muted)) !important;
}

html.dark .bg-slate-200,
html.dark .bg-gray-200,
html.dark [class~="bg-[#E3E8F2]"],
html.dark [class~="bg-[#EEF2F6]"] {
  background-color: rgb(var(--color-surface-elevated)) !important;
}

html.dark [class~="bg-[#E6E9EF]"] {
  background-color: rgb(var(--color-surface-muted)) !important;
}

html.dark .text-black,
html.dark .text-gray-700,
html.dark .text-gray-800,
html.dark .text-gray-900,
html.dark [class~="text-[#111111]"],
html.dark [class~="text-[#111827]"],
html.dark [class~="text-[#1A1B21]"],
html.dark [class~="text-[#374151]"],
html.dark [class~="text-[#43474E]"],
html.dark [class~="text-[#091426]"] {
  color: rgb(var(--color-text-primary)) !important;
}

html.dark [class~="text-[#1F2937]"] {
  color: rgb(var(--color-text-primary)) !important;
}

html.dark .text-gray-400,
html.dark .text-gray-500,
html.dark .text-gray-600,
html.dark .text-slate-400,
html.dark .text-slate-500,
html.dark .text-slate-600,
html.dark [class~="text-[#5C5F61]"],
html.dark [class~="text-[#6B7280]"],
html.dark [class~="text-[#74777F]"],
html.dark [class~="text-[#9CA3AF]"] {
  color: rgb(var(--color-text-secondary)) !important;
}

html.dark [class~="text-[#4B5563]"],
html.dark [class~="text-[#8A9099]"],
html.dark [class~="text-[#C7CBD1]"],
html.dark [class~="text-[#D1D5DB]"] {
  color: rgb(var(--color-text-secondary)) !important;
}

html.dark .fill-gray-400,
html.dark .fill-gray-500,
html.dark .fill-slate-400,
html.dark .fill-slate-500 {
  fill: rgb(var(--color-text-secondary)) !important;
}

html.dark .border-gray-100,
html.dark .border-gray-200,
html.dark .border-slate-100,
html.dark .border-slate-200,
html.dark [class~="border-[#E0E2EC]"],
html.dark [class~="border-[#E5E7EB]"],
html.dark [class~="border-[#EEF0F5]"] {
  border-color: rgb(var(--color-border)) !important;
}

html.dark [class~="border-[#D1D5DB]"],
html.dark [class~="border-[#D6DBE8]"],
html.dark [class~="border-[#D8E3F0]"],
html.dark [class~="border-[#C8D1E2]"] {
  border-color: rgb(var(--color-border)) !important;
}

html.dark [class~="border-[#BBF7D0]"] {
  border-color: rgb(22 101 52) !important;
}

html.dark [class~="border-[#FECACA]"] {
  border-color: rgb(153 27 27) !important;
}

html.dark .divide-gray-100 > :not([hidden]) ~ :not([hidden]),
html.dark .divide-slate-100 > :not([hidden]) ~ :not([hidden]),
html.dark [class~="divide-[#F3F4F6]"] > :not([hidden]) ~ :not([hidden]) {
  border-color: rgb(var(--color-border)) !important;
}

html.dark .hover\:bg-gray-50:hover,
html.dark .hover\:bg-gray-100:hover,
html.dark .hover\:bg-slate-50:hover,
html.dark .hover\:bg-slate-100:hover,
html.dark [class~="hover:bg-[#F3F4F6]"]:hover,
html.dark [class~="hover:bg-[#F9FAFB]"]:hover,
html.dark [class~="hover:bg-[#E3E8F2]"]:hover {
  background-color: rgb(var(--color-surface-elevated)) !important;
}

html.dark [class~="hover:bg-[#002B5B]"]:hover {
  background-color: rgb(var(--color-brand-hover)) !important;
}

html.dark [class~="hover:bg-[#FFF8E1]"]:hover {
  background-color: rgb(66 32 6) !important;
}

html.dark input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
html.dark select,
html.dark textarea {
  background-color: rgb(var(--color-surface));
  border-color: rgb(var(--color-border));
  color: rgb(var(--color-text-primary));
}

html.dark input::placeholder,
html.dark textarea::placeholder {
  color: rgb(var(--color-text-secondary));
}

html.dark .bg-green-50,
html.dark .bg-green-100,
html.dark [class~="bg-[#F0FDF4]"] {
  background-color: rgb(var(--color-success-bg)) !important;
}

html.dark .text-green-700,
html.dark .text-green-800,
html.dark [class~="text-[#166534]"] {
  color: rgb(var(--color-success-text)) !important;
}

html.dark .bg-red-50,
html.dark .bg-red-100,
html.dark [class~="bg-[#FEF2F2]"] {
  background-color: rgb(var(--color-danger-bg)) !important;
}

html.dark .text-red-700,
html.dark .text-red-800,
html.dark [class~="text-[#9B1C1C]"],
html.dark [class~="text-[#B91C1C]"] {
  color: rgb(var(--color-danger-text)) !important;
}

html.dark .bg-amber-50,
html.dark .bg-amber-100 {
  background-color: var(--ui-status-mt) !important;
}

html.dark .bg-yellow-50,
html.dark .bg-yellow-100,
html.dark .bg-orange-50,
html.dark .bg-orange-100 {
  background-color: var(--ui-status-mt) !important;
}

html.dark .text-amber-800,
html.dark .text-amber-900 {
  color: rgb(253 230 138) !important;
}

html.dark .text-yellow-700,
html.dark .text-yellow-800,
html.dark .text-orange-700,
html.dark .text-orange-800 {
  color: var(--ui-status-mt-text) !important;
}

html.dark .bg-indigo-50,
html.dark .bg-indigo-100,
html.dark .bg-purple-50,
html.dark .bg-purple-100 {
  background-color: rgb(49 46 129) !important;
}

html.dark .text-indigo-600,
html.dark .text-indigo-700,
html.dark .text-purple-600,
html.dark .text-purple-700 {
  color: rgb(199 210 254) !important;
}

html.dark .bg-blue-50,
html.dark .bg-blue-100,
html.dark [class~="bg-[#DCE2F3]"],
html.dark [class~="bg-[#EFF4FF]"] {
  background-color: rgb(var(--color-brand-soft)) !important;
}

html.dark [class~="text-[#003D7A]"] {
  color: rgb(var(--color-brand)) !important;
}

html.dark [class~="bg-[#003D7A]"] {
  background-color: rgb(var(--color-brand)) !important;
}

html.dark .bg-st-bg { background-color: var(--ui-status-st) !important; }
html.dark .text-st-green { color: var(--ui-status-st-text) !important; }
html.dark .bg-mt-bg { background-color: var(--ui-status-mt) !important; }
html.dark .text-mt-orange { color: var(--ui-status-mt-text) !important; }
html.dark .bg-lt-bg { background-color: var(--ui-status-lt) !important; }
html.dark .text-lt-purple { color: var(--ui-status-lt-text) !important; }

html.dark .bg-brand.text-white,
html.dark .app-btn-primary {
  border-color: rgb(var(--color-brand));
  background-color: rgb(var(--color-brand));
  color: #261a00 !important;
  font-weight: 700;
}

html.dark .app-btn-primary:hover:not(:disabled) {
  border-color: rgb(var(--color-brand-hover));
  background-color: rgb(var(--color-brand-hover));
  color: #261a00 !important;
}

html.dark .app-btn-primary:disabled {
  background-color: rgb(var(--color-surface-muted));
  border-color: rgb(var(--color-border));
  color: rgb(var(--color-text-muted)) !important;
  opacity: 0.45;
}

html.dark .app-btn-secondary {
  border-color: rgb(var(--color-border));
  background-color: rgb(var(--color-surface));
  color: rgb(var(--color-text-primary));
}

html.dark .app-btn-secondary:hover:not(:disabled) {
  border-color: rgb(var(--color-brand));
  background-color: rgb(var(--color-surface-elevated));
  color: rgb(var(--color-brand));
}

html.dark .app-btn-secondary:disabled {
  border-color: rgb(var(--color-border));
  background-color: rgb(var(--color-surface-muted));
  color: rgb(var(--color-text-muted));
  opacity: 0.45;
}

html.dark table {
  color: rgb(var(--color-text-primary));
}

html.dark [stroke="#E5E7EB"] {
  stroke: rgb(var(--color-border));
}

html.dark .division-legend-row.highlight,
html.dark .legend-item.highlight,
html.dark .division-legend-row:hover,
html.dark .tooltip-target:hover,
html.dark .legend-item:hover {
  background: rgb(var(--color-surface-elevated));
}

html.dark .custom-scrollbar::-webkit-scrollbar-thumb {
  background-color: rgb(var(--color-border));
}

html.dark .custom-scrollbar::-webkit-scrollbar-thumb:hover {
  background-color: rgb(var(--color-text-muted));
}

html.dark .shadow-sm,
html.dark .shadow-md,
html.dark .shadow-lg,
html.dark .shadow-xl,
html.dark .shadow-2xl {
  --tw-shadow-color: rgb(0 0 0 / 0.28);
}
