:root {
  color-scheme: light;
  --bc-page: #eef2f6;
  --bc-ink: #18212f;
  --bc-muted: #617083;
  --bc-border: #d2dbe6;
  --bc-subtle-border: #e2e8f0;
  --bc-surface: #f8fafc;
  --bc-surface-soft: #f1f5f9;
  --bc-topbar-bg: rgba(248, 250, 252, 0.94);
  --bc-command-bg: rgba(248, 250, 252, 0.96);
  --bc-floating-bg: rgba(248, 250, 252, 0.98);
  --bc-link-text: #39475b;
  --bc-link-hover-bg: #eef4fb;
  --bc-link-active: #0c65b8;
  --bc-accent-border: #8eb5dc;
  --bc-shadow-soft: rgba(24, 33, 47, 0.06);
  --bc-shadow-lift: rgba(24, 33, 47, 0.08);
  --bc-shadow-strong: rgba(24, 33, 47, 0.1);
  --bc-modal-backdrop: rgba(24, 33, 47, 0.46);
  --bc-autosave-dirty: #a16207;
  --bc-autosave-saving: #0d6efd;
  --bc-autosave-saved: #198754;
  --bc-autosave-error: #dc3545;
  --bc-autosave-dirty-glow: rgba(255, 193, 7, 0.22);
  --bc-autosave-saving-glow: rgba(13, 110, 253, 0.2);
  --bc-autosave-saved-glow: rgba(25, 135, 84, 0.2);
  --bc-autosave-error-glow: rgba(220, 53, 69, 0.2);
  --bs-body-bg: var(--bc-page);
  --bs-body-color: var(--bc-ink);
  --bs-card-bg: var(--bc-surface);
  --bs-tertiary-bg: var(--bc-surface-soft);
  --bs-secondary-bg: #e9eef5;
  --bs-border-color: var(--bc-border);
}

[data-bs-theme="dark"] {
  color-scheme: dark;
  --bc-page: #10151d;
  --bc-ink: #eef3f8;
  --bc-muted: #9daabd;
  --bc-border: #2d3948;
  --bc-subtle-border: #263241;
  --bc-surface: #171e28;
  --bc-surface-soft: #1d2632;
  --bc-topbar-bg: rgba(23, 30, 40, 0.92);
  --bc-command-bg: rgba(23, 30, 40, 0.94);
  --bc-floating-bg: rgba(23, 30, 40, 0.96);
  --bc-link-text: #c8d2df;
  --bc-link-hover-bg: #21364d;
  --bc-link-active: #76b8ff;
  --bc-accent-border: #3e6f9f;
  --bc-shadow-soft: rgba(0, 0, 0, 0.22);
  --bc-shadow-lift: rgba(0, 0, 0, 0.26);
  --bc-shadow-strong: rgba(0, 0, 0, 0.32);
  --bc-modal-backdrop: rgba(0, 0, 0, 0.62);
  --bc-autosave-dirty: #f4c430;
  --bc-autosave-saving: #74b4ff;
  --bc-autosave-saved: #58d68d;
  --bc-autosave-error: #ff7b86;
  --bc-autosave-dirty-glow: rgba(244, 196, 48, 0.2);
  --bc-autosave-saving-glow: rgba(116, 180, 255, 0.18);
  --bc-autosave-saved-glow: rgba(88, 214, 141, 0.18);
  --bc-autosave-error-glow: rgba(255, 123, 134, 0.18);
}

body {
  min-height: 100vh;
  background: var(--bc-page);
  color: var(--bc-ink);
}

.app-layout {
  display: flex;
  min-height: 100vh;
}

.app-sidebar {
  position: sticky;
  top: 0;
  flex: 0 0 260px;
  height: 100vh;
  flex-direction: column;
  gap: 1rem;
  border-right: 1px solid var(--bc-border);
  background: var(--bc-surface);
  padding: 1rem;
  transition: flex-basis 0.18s ease, padding 0.18s ease;
}

.app-main {
  min-width: 0;
  flex: 1;
}

.app-topbar {
  min-height: 56px;
  border-bottom: 1px solid var(--bc-border);
  background: var(--bc-topbar-bg);
  backdrop-filter: blur(14px);
}

.brand-mark {
  color: var(--bc-ink);
  font-weight: 800;
  text-decoration: none;
}

.brand-short,
.nav-short {
  display: none;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.sidebar-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
}

.sidebar-toggle-icon {
  width: 0.68rem;
  height: 0.68rem;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(135deg);
  transition: transform 0.16s ease;
}

.sidebar-accordion .accordion-item {
  border: 0;
}

.sidebar-accordion .accordion-button {
  border-radius: 6px !important;
  background: transparent;
  box-shadow: none;
  font-size: 0.9rem;
  font-weight: 700;
}

.sidebar-accordion .accordion-body {
  display: grid;
  gap: 0.25rem;
  padding: 0.35rem 0.25rem 0.65rem;
}

.sidebar-direct-nav {
  display: grid;
  gap: 0.25rem;
}

.sidebar-footer {
  display: flex;
  justify-content: flex-end;
  margin-top: auto;
  padding-top: 0.75rem;
}

.side-link {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  border-radius: 6px;
  color: var(--bc-link-text);
  padding: 0.45rem 0.65rem;
  text-decoration: none;
}

.side-link:hover,
.side-link.active {
  background: var(--bc-link-hover-bg);
  color: var(--bc-link-active);
  text-decoration: none;
}

.action-menu-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
}

.action-menu-icon {
  display: grid;
  gap: 3px;
  width: 14px;
}

.action-menu-icon span {
  display: block;
  height: 2px;
  border-radius: 999px;
  background: currentColor;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
}

.theme-icon {
  position: relative;
  width: 1rem;
  height: 1rem;
  border: 2px solid currentColor;
  border-radius: 50%;
  transition: transform 0.18s ease, background 0.18s ease, box-shadow 0.18s ease;
}

.theme-icon::after {
  content: "";
  position: absolute;
  inset: -5px;
  border-radius: 50%;
  box-shadow: 0 -7px 0 -5px currentColor, 0 7px 0 -5px currentColor, 7px 0 0 -5px currentColor, -7px 0 0 -5px currentColor;
}

[data-bs-theme="dark"] .theme-icon {
  background: currentColor;
  box-shadow: inset -5px 0 0 var(--bc-surface);
  transform: rotate(-18deg);
}

[data-bs-theme="dark"] .theme-icon::after {
  box-shadow: none;
}

.theme-menu-icon {
  flex: 0 0 auto;
  width: 0.9rem;
  height: 0.9rem;
}

.user-menu-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
}

.user-menu-button::after {
  display: none;
}

.user-icon {
  position: relative;
  width: 1rem;
  height: 1rem;
}

.user-icon::before,
.user-icon::after {
  content: "";
  position: absolute;
  left: 50%;
  border: 2px solid currentColor;
  transform: translateX(-50%);
}

.user-icon::before {
  top: 0;
  width: 0.52rem;
  height: 0.52rem;
  border-radius: 50%;
}

.user-icon::after {
  bottom: 0;
  width: 0.9rem;
  height: 0.48rem;
  border-radius: 999px 999px 0 0;
  border-bottom: 0;
}

.user-menu-dropdown {
  min-width: 240px;
}

.menu-button .navbar-toggler-icon {
  width: 1rem;
  height: 1rem;
}

@media (min-width: 992px) {
  .sidebar-collapsed .app-sidebar {
    flex-basis: 76px;
    gap: 0.6rem;
    padding: 0.75rem;
  }

  .sidebar-collapsed .sidebar-brand {
    display: grid;
    justify-items: center;
    gap: 0.5rem;
  }

  .sidebar-collapsed .sidebar-footer {
    justify-content: center;
    padding-top: 0.5rem;
  }

  .sidebar-collapsed .brand-long,
  .sidebar-collapsed .sidebar-accordion .accordion-header {
    display: none;
  }

  .sidebar-collapsed .brand-short,
  .sidebar-collapsed .nav-short {
    display: inline-flex;
  }

  .sidebar-collapsed .brand-short {
    align-items: center;
    justify-content: center;
    width: 2.2rem;
    height: 2.2rem;
    border: 1px solid var(--bc-border);
    border-radius: 8px;
  }

  .sidebar-collapsed .sidebar-accordion .accordion-collapse {
    display: block !important;
    height: auto !important;
    visibility: visible !important;
  }

  .sidebar-collapsed .sidebar-accordion .accordion-body {
    padding: 0;
  }

  .sidebar-collapsed .sidebar-direct-nav {
    gap: 0.25rem;
  }

  .sidebar-collapsed .nav-label {
    display: none;
  }

  .sidebar-collapsed .side-link {
    justify-content: center;
    min-height: 2.35rem;
    padding: 0.45rem;
  }

  .sidebar-collapsed .nav-short {
    align-items: center;
    justify-content: center;
    width: 100%;
    color: inherit;
    font-size: 0.72rem;
    font-weight: 800;
    text-transform: uppercase;
  }

  .sidebar-collapsed .sidebar-toggle-icon {
    transform: rotate(-45deg);
  }

  .sidebar-collapsed .side-link[title="Groups"] .nav-short,
  .sidebar-collapsed .side-link[title="Sites"] .nav-short {
    position: relative;
    width: 1.35rem;
    height: 1rem;
    font-size: 0;
  }

  .sidebar-collapsed .side-link[title="Groups"] .nav-short::before,
  .sidebar-collapsed .side-link[title="Sites"] .nav-short::before {
    content: "";
    position: absolute;
    left: 0.08rem;
    top: 0.35rem;
    width: 1.2rem;
    height: 0.58rem;
    border: 2px solid currentColor;
    border-radius: 0.16rem;
    background: transparent;
  }

  .sidebar-collapsed .side-link[title="Groups"] .nav-short::after,
  .sidebar-collapsed .side-link[title="Sites"] .nav-short::after {
    content: "";
    position: absolute;
    left: 0.18rem;
    top: 0.18rem;
    width: 0.56rem;
    height: 0.32rem;
    border: 2px solid currentColor;
    border-bottom: 0;
    border-radius: 0.16rem 0.16rem 0 0;
  }
}

.page-shell {
  max-width: 1380px;
  padding: 1.5rem;
}

.command-bar {
  position: sticky;
  top: 64px;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  border: 1px solid var(--bc-border);
  border-radius: 8px;
  background: var(--bc-command-bg);
  padding: 0.85rem 1rem;
  box-shadow: 0 0.35rem 1.1rem var(--bc-shadow-soft);
  backdrop-filter: blur(12px);
}

.flash-stack {
  display: grid;
  gap: 0.65rem;
  margin-bottom: 1rem;
}

.login-shell {
  display: grid;
  min-height: calc(100vh - 120px);
  place-items: center;
}

.login-card {
  width: min(100%, 420px);
}

.form-card {
  max-width: 820px;
}

.form-card-wide {
  max-width: 1080px;
}

.autosave-form {
  position: relative;
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

.autosave-panel {
  border: 1px solid var(--bc-border);
  border-radius: 8px;
  background: var(--bc-surface);
  padding: 1rem;
}

.autosave-form[data-autosave-state="dirty"] {
  border-color: var(--bc-autosave-dirty);
  box-shadow: 0 0 0 0.22rem var(--bc-autosave-dirty-glow), 0 0.75rem 1.7rem var(--bc-shadow-lift);
}

.autosave-form[data-autosave-state="saving"] {
  border-color: var(--bc-autosave-saving);
  box-shadow: 0 0 0 0.22rem var(--bc-autosave-saving-glow), 0 0.75rem 1.7rem var(--bc-shadow-lift);
}

.autosave-form[data-autosave-state="saved"] {
  border-color: var(--bc-autosave-saved);
  box-shadow: 0 0 0 0.22rem var(--bc-autosave-saved-glow), 0 0.75rem 1.7rem var(--bc-shadow-lift);
}

.autosave-form[data-autosave-state="error"] {
  border-color: var(--bc-autosave-error);
  box-shadow: 0 0 0 0.22rem var(--bc-autosave-error-glow), 0 0.75rem 1.7rem var(--bc-shadow-lift);
}

.autosave-status {
  align-self: center;
  min-width: 6.25rem;
  color: var(--bc-muted);
  font-size: 0.82rem;
  font-weight: 700;
  white-space: nowrap;
}

.autosave-form[data-autosave-state="dirty"] .autosave-status {
  color: var(--bc-autosave-dirty);
}

.autosave-form[data-autosave-state="saving"] .autosave-status {
  color: var(--bc-autosave-saving);
}

.autosave-form[data-autosave-state="saved"] .autosave-status {
  color: var(--bc-autosave-saved);
}

.autosave-form[data-autosave-state="error"] .autosave-status {
  color: var(--bc-autosave-error);
}

.group-card {
  transition: border-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
}

.group-card:hover {
  border-color: var(--bc-accent-border);
  box-shadow: 0 0.75rem 1.7rem var(--bc-shadow-lift);
  transform: translateY(-1px);
}

.metric-tile {
  display: grid;
  gap: 0.25rem;
  border: 1px solid var(--bc-border);
  border-radius: 8px;
  background: var(--bc-surface-soft);
  padding: 0.75rem;
}

.metric-tile span {
  display: block;
  color: var(--bc-muted);
  font-size: 0.82rem;
}

.metric-tile strong {
  display: block;
  font-size: 1.35rem;
}

.metric-chart-tile {
  min-height: 168px;
}

.metric-chart {
  margin-top: 0.35rem;
}

.sparkline {
  display: block;
  width: 100%;
  border: 1px solid var(--bc-border);
  border-radius: 8px;
  background: var(--bc-surface);
}

.security-summary-card {
  border-color: rgba(220, 53, 69, 0.35);
}

.security-user-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 0.6rem;
}

.security-user-card {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  border: 1px solid var(--bc-border);
  border-radius: 8px;
  background: var(--bc-surface-soft);
  color: var(--bc-ink);
  padding: 0.7rem;
  text-decoration: none;
}

.security-user-card:hover {
  border-color: rgba(220, 53, 69, 0.55);
  color: var(--bc-ink);
}

.security-badge-stack {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.25rem;
}

.compact-accordion {
  --bs-accordion-border-color: var(--bc-border);
  --bs-accordion-btn-padding-y: 0.75rem;
  --bs-accordion-btn-padding-x: 0.9rem;
  --bs-accordion-body-padding-y: 0.85rem;
  --bs-accordion-body-padding-x: 0.9rem;
}

.sticky-actions {
  position: sticky;
  bottom: 0.75rem;
  display: flex;
  gap: 0.5rem;
  width: max-content;
  max-width: 100%;
  margin-top: 1rem;
  border: 1px solid var(--bc-border);
  border-radius: 8px;
  background: var(--bc-floating-bg);
  padding: 0.5rem;
  box-shadow: 0 0.5rem 1.2rem var(--bc-shadow-strong);
  backdrop-filter: blur(12px);
}

.access-box {
  display: grid;
  gap: 0.65rem;
  border: 1px solid var(--bc-border);
  border-radius: 8px;
  margin: 0;
  padding: 0.9rem;
}

.access-box legend {
  float: none;
  width: auto;
  margin: 0;
  padding: 0 0.35rem;
  color: var(--bc-link-text);
  font-size: 0.95rem;
  font-weight: 700;
}

.membership-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(150px, 200px);
  gap: 0.65rem;
  align-items: center;
}

.access-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.65rem;
}

.permission-card {
  display: grid;
  gap: 0.55rem;
  border: 1px solid var(--bc-subtle-border);
  border-radius: 8px;
  padding: 0.65rem;
}

.site-group {
  display: grid;
  gap: 0.5rem;
}

.site-group h3 {
  margin: 0;
  color: var(--bc-link-text);
  font-size: 0.95rem;
}

.dropdown-menu {
  z-index: 1080;
}

@media (min-width: 761px) {
  .dropdown-overflow-host,
  .dropdown-overflow-host table,
  .dropdown-overflow-host tbody,
  .dropdown-overflow-host tr,
  .dropdown-overflow-host td {
    overflow: visible;
  }
}

.site-check-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 0.5rem;
}

.site-check {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  border: 1px solid var(--bc-subtle-border);
  border-radius: 6px;
  padding: 0.55rem;
}

.site-check strong,
.site-check span span {
  display: block;
}

.site-check span span {
  color: var(--bc-muted);
  font-size: 0.88rem;
}

.details-card {
  max-width: 760px;
}

.payload-code {
  display: block;
  max-width: 560px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.site-viewer-modal .modal-content {
  min-height: 100vh;
}

.site-viewer-modal .modal-body {
  min-height: 0;
}

.site-viewer-frame {
  display: block;
  width: 100%;
  height: 100%;
  min-height: calc(100vh - 49px);
  border: 0;
  background: #10151d;
}

.viewer-body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: #2e333b;
}

.viewer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 42px;
  padding: 0 0.75rem;
  background: #18212f;
  color: #fff;
}

.viewer-screen {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.viewer-connected .viewer-screen {
  cursor: none !important;
}

.viewer-connected .viewer-screen canvas {
  cursor: none !important;
}

.viewer-connected .viewer-screen,
.viewer-connected .viewer-screen * {
  cursor: none !important;
}

.cursor-dot {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 2147483647;
  width: 56px;
  height: 56px;
  border: 4px solid #fff;
  border-radius: 50%;
  background: rgba(13, 110, 253, 0.28);
  box-shadow: 0 0 0 4px rgba(13, 110, 253, 0.85), 0 0 18px rgba(0, 0, 0, 0.45);
  pointer-events: none;
  transform: translate3d(-100px, -100px, 0);
  will-change: transform;
}

.cursor-dot::before,
.cursor-dot::after {
  content: "";
  position: absolute;
  background: #fff;
  box-shadow: 0 0 0 1px rgba(13, 110, 253, 0.7);
}

.cursor-dot::before {
  top: 50%;
  left: 10px;
  right: 10px;
  height: 4px;
  transform: translateY(-50%);
}

.cursor-dot::after {
  top: 10px;
  bottom: 10px;
  left: 50%;
  width: 4px;
  transform: translateX(-50%);
}

.hidden {
  display: none !important;
}

.idle-modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--bc-modal-backdrop);
}

.modal-panel {
  width: min(92vw, 420px);
  border-radius: 8px;
  background: var(--bc-surface);
  padding: 1.25rem;
}

.error-panel {
  display: grid;
  justify-items: start;
  max-width: 720px;
  border: 1px solid var(--bc-border);
  border-radius: 8px;
  background: var(--bc-surface);
  padding: clamp(1.25rem, 4vw, 2rem);
  box-shadow: 0 10px 28px var(--bc-shadow-soft);
}

.error-code {
  color: var(--bc-link-active);
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0;
}

.pagination-bar {
  border-top: 1px solid var(--bc-border);
  background: var(--bc-surface-soft);
  padding: 0.75rem 1rem;
}

@media (max-width: 760px) {
  .page-shell {
    padding: 1rem;
  }

  .command-bar {
    position: static;
    display: grid;
  }

  .membership-row {
    grid-template-columns: 1fr;
  }

}
