/* ============================================
   SIDEBAR — BEM naming reference
   ============================================
   .app-shell              — page layout (sidebar + main)
   .sidebar                 — aside container
   .sidebar__header         — logo row + collapse toggle
   .sidebar__brand          — logo wordmark link
   .sidebar__logo           — brand home link
   .sidebar__toggle         — collapse button
   .sidebar__toggle-icon     — chevron inside toggle

   .sidebar-nav             — primary navigation
   .sidebar-nav__group      — menu section
   .sidebar-nav__group--folded    — section links hidden (localStorage)
   .sidebar-nav__group--animated  — enable expand/collapse transition
   .sidebar-nav__title      — collapsible section heading
   .sidebar-nav__title-label — title text (first letter shown when sidebar collapsed)
   .sidebar-nav__chevron    — chevron in section heading
   .sidebar-nav__body       — animated wrapper for section links
   .sidebar-nav__inner      — inner clip container
   .sidebar-nav__divider    — horizontal rule between link groups
   .sidebar-nav__link       — nav item (pairs with .active from route helper)
   .sidebar-nav__icon       — SVG icon in nav link
   .sidebar-nav__label      — text label in nav link

   .sidebar-user            — user card in sidebar
   .sidebar-user--trigger   — opens profile popup
   .sidebar-user__avatar    — initials circle
   .sidebar-user__meta      — name / casino / role column
   .sidebar-user__name
   .sidebar-user__casino
   .sidebar-user__role
   .sidebar-user__switcher  — casino switcher wrapper
   .sidebar-user__switcher--badge
   .sidebar-user__switcher--selector

   .sidebar-user-menu       — profile popup content
   .sidebar-user-menu__action
   .sidebar-user-menu__action--danger
   .sidebar-user-menu__icon

   .app-bar                 — mobile top bar (hamburger + logo), hidden ≥1024px
   .app-bar__menu           — opens the off-canvas sidebar
   .app-bar__logo
   .app-bar__user           — compact profile trigger (right side)
   .sidebar-backdrop        — dim overlay while drawer is open
   .sidebar__close          — close drawer (visible only in drawer mode)

   html.sidebar-collapsed   — narrow sidebar (localStorage or auto below 1280px)
   html.sidebar-drawer-mode — off-canvas layout (JS, not a width media query)
   html.sidebar-drawer-open — off-canvas sidebar visible
   data-sidebar-tip        — tooltip text when sidebar collapsed (#sidebar-tip-bubble)
   ============================================ */

/* --- Tokens (shared: sidebar + user profile popup) --- */
:root {
  --sidebar-width-expanded: 263px;
  --sidebar-width-collapsed: 72px;
  --sidebar-item-radius: 12px;
  --sidebar-item-padding-x: 16px;
  --sidebar-icon-size: 24px;
  --sidebar-icon-gap: 12px;
}

.sidebar {
  --sidebar-width: var(--sidebar-width-expanded);
}

/* Suppress width/opacity transitions until slon-sidebar.js finishes first sync. */
html:not(.sidebar-hydrated) .sidebar,
html:not(.sidebar-hydrated) .sidebar-nav__body,
html:not(.sidebar-hydrated) .sidebar-nav__inner,
html:not(.sidebar-hydrated) .sidebar__toggle-icon,
html:not(.sidebar-hydrated) .sidebar-nav__chevron,
html:not(.sidebar-hydrated) .sidebar-backdrop,
html.sidebar-layout-sync .sidebar,
html.sidebar-layout-sync .sidebar-nav__body,
html.sidebar-layout-sync .sidebar-nav__inner,
html.sidebar-layout-sync .sidebar__toggle-icon,
html.sidebar-layout-sync .sidebar-nav__chevron,
html.sidebar-layout-sync .sidebar-backdrop {
  transition: none !important;
}

/* --- App shell --- */
.app-shell {
  align-items: stretch;
  max-width: 2000px;
  margin: 0 auto;
  width: 100%;
  flex-direction: row;
  display: flex;
  gap: 1rem;
  padding: 1rem;
  box-sizing: border-box;
  min-height: 100vh;
}

/* --- Sidebar container --- */
.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  align-self: stretch;
  max-height: 100dvh;
  width: var(--sidebar-width);
  max-width: var(--sidebar-width);
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface-primary);
  flex-shrink: 0;
  transition: width 0.2s ease-out, max-width 0.2s ease-out;
  scrollbar-width: thin;
  scrollbar-color: var(--neutral-700) transparent;
}

.sidebar::-webkit-scrollbar {
  width: 6px;
}

.sidebar::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar::-webkit-scrollbar-thumb {
  background: var(--neutral-700);
  border-radius: 3px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
  background: var(--neutral-600);
}

/* --- Header --- */
.sidebar__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.sidebar__brand {
  display: flex;
  align-items: center;
  padding: 0 12px 0 16px;
  flex: 1;
  min-width: 0;
}

.sidebar__logo {
  display: block;
  color: var(--text-primary);
  text-decoration: none;
  line-height: 0;
  min-width: 0;
}

.sidebar__logo:hover {
  text-decoration: none;
}

.sidebar__logo-image {
  display: block;
  height: 28px;
  width: auto;
  max-width: 100%;
}

.sidebar__logo-accent {
  fill: var(--accent-primary);
}

.sidebar__toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border: none;
  border-radius: 50%;
  background: var(--surface-secondary);
  color: #ffffff;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, transform 0.15s ease;
}

.sidebar__toggle:hover {
  background: var(--surface-tertiary);
  color: #ffffff;
}

[data-theme="light"] .sidebar__toggle {
  background: var(--neutral-950);
}

[data-theme="light"] .sidebar__toggle:hover {
  background: var(--neutral-900);
}

.sidebar__toggle:active {
  transform: scale(0.97);
}

.sidebar__close {
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border: none;
  border-radius: 50%;
  background: var(--surface-secondary);
  color: var(--text-primary);
  cursor: pointer;
  transition: background 0.15s ease, transform 0.15s ease;
}

.sidebar__close:hover {
  background: var(--surface-tertiary);
}

.sidebar__close:active {
  transform: scale(0.97);
}

.sidebar__toggle-icon {
  display: block;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  stroke: currentColor;
  transition: transform 0.2s ease-out;
}

/* --- Navigation --- */
.sidebar-nav {
  width: 100%;
  flex: 1;
  min-height: 0;
  flex-shrink: 0;
  font-family: Inter, "Inter Fallback", ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
  -webkit-font-smoothing: antialiased;
  box-sizing: border-box;
  gap: 1rem;
}

.sidebar-nav__group {
  margin-bottom: 4px;
}

.sidebar-nav__title {
  display: flex !important;
  align-items: center;
  justify-content: space-between;
  color: var(--text-primary);
  font-weight: 600;
  font-size: var(--font-size-sm);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 16px var(--sidebar-item-padding-x) 8px;
  cursor: pointer;
  transition: color 150ms ease;
  user-select: none;
}

.sidebar-nav__title:hover {
  color: var(--text-secondary) !important;
}

.sidebar-nav__title-label {
  min-width: 0;
}

.sidebar-nav__chevron {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  transition: transform 200ms ease-out;
  flex-shrink: 0;
  margin-left: 8px;
}

.sidebar-nav__group--folded .sidebar-nav__chevron {
  transform: rotate(-90deg);
}

.sidebar-nav__body {
  display: grid;
  grid-template-rows: 1fr;
}

.sidebar-nav__group--folded .sidebar-nav__body {
  grid-template-rows: 0fr;
}

.sidebar-nav__inner {
  min-height: 0;
  overflow: hidden;
  opacity: 1;
}

.sidebar-nav__group--folded .sidebar-nav__inner {
  opacity: 0;
}

.sidebar-nav__group--animated .sidebar-nav__body {
  transition: grid-template-rows 200ms ease-out;
}

.sidebar-nav__group--animated .sidebar-nav__inner {
  transition: opacity 180ms ease-out;
}

.sidebar-nav__divider {
  margin: 8px 0;
  border-bottom: 1px solid var(--border-light);
}

.sidebar-nav__link {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  color: var(--text-secondary);
  white-space: nowrap;
  font-size: var(--font-size-lg);
  font-weight: 500;
  line-height: 24px;
  padding: 14px var(--sidebar-item-padding-x);
  border-radius: var(--sidebar-item-radius);
  text-decoration: none;
  transition: color 150ms ease, background-color 150ms ease;
  cursor: pointer;
  position: relative;
  margin-bottom: 2px;
}

.sidebar-nav__link:hover {
  color: var(--text-primary);
  background: var(--surface-secondary);
  text-decoration: none;
}

.sidebar-nav__link.active {
  color: var(--text-primary);
  background: var(--surface-secondary);
  font-weight: 500;
}

.sidebar-nav__link.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 24px;
  background: var(--accent-primary);
  border-radius: 0 3px 3px 0;
}

.sidebar-nav__icon {
  width: var(--sidebar-icon-size);
  height: var(--sidebar-icon-size);
  margin-right: var(--sidebar-icon-gap);
  flex-shrink: 0;
  stroke: currentColor;
  transition: stroke 0.15s ease;
}

.sidebar-nav__label {
  flex: 1;
}

/* --- User card --- */
.sidebar-user--trigger {
  background: none;
  border: none;
  cursor: pointer;
}

.sidebar-user {
  display: flex;
  align-items: center;
  padding: 12px var(--sidebar-item-padding-x);
  gap: 12px;
  border-radius: var(--sidebar-item-radius);
  /* border: 1px solid var(--border-medium); */
  background: var(--surface-secondary);
}

.sidebar-user__avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent-primary);
  color: var(--btn-on-color);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: var(--font-size-lg);
  text-transform: uppercase;
  flex-shrink: 0;
}

.sidebar-user__meta {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

.sidebar-user__name {
  color: var(--text-primary);
  font-weight: 500;
  font-size: var(--font-size-md);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user__role,
.sidebar-user__casino {
  color: var(--text-secondary);
  font-size: var(--font-size-xs);
  font-weight: 400;
}

.sidebar-user__casino {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: var(--line1);
}

.sidebar-user__switcher--badge {
  min-width: 0;
  overflow: hidden;
}

.sidebar-user__switcher--badge .sidebar-user__casino {
  display: block;
  max-width: 100%;
}

.sidebar-user__switcher--selector {
  width: 100%;
}

.sidebar-user__switcher--selector .sidebar-user__casino {
  display: block;
  font-size: var(--font-size-md);
  font-weight: 500;
  color: var(--text-primary);
  white-space: normal;
  overflow: visible;
  text-overflow: unset;
}

.sidebar-user__switcher--selector select {
  width: 100%;
}

.sidebar-user-menu__label {
  flex: 1;
}

/* --- User popup --- */
.sidebar-user-menu {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 260px;
}

.sidebar-user-menu__action {
  display: flex;
  align-items: center;
  padding: 12px var(--sidebar-item-padding-x);
  border-radius: var(--sidebar-item-radius);
  transition: color 0.15s ease, background-color 0.15s ease;
  cursor: pointer;
  gap: 12px;
  text-decoration: none;
  color: var(--text-secondary);
}

.sidebar-user-menu__action:hover {
  color: var(--text-primary);
  background: var(--surface-secondary);
  text-decoration: none;
}

.sidebar-user-menu__action--danger {
  justify-content: flex-start;
  color: var(--red-600);
  border: 1px solid var(--red-400);
  min-height: 44px;
  outline: none;
}

.sidebar-user-menu__action--danger:hover {
  color: var(--red-600);
  background: rgba(239, 68, 68, 0.1);
}

.sidebar-user-menu__icon {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  flex-shrink: 0;
}

/* --- Collapsed sidebar (desktop) — scoped to .sidebar so popup is unaffected --- */
html.sidebar-collapsed .sidebar {
  --sidebar-width: var(--sidebar-width-collapsed);
}

html.sidebar-collapsed .sidebar .sidebar__toggle-icon {
  transform: rotate(180deg);
}

html.sidebar-collapsed .sidebar .sidebar__header {
  flex-direction: column;
  padding: 0 12px;
  gap: 12px;
}

html.sidebar-collapsed .sidebar .sidebar__brand {
  display: none;
}

html.sidebar-collapsed .sidebar .sidebar__logo {
  display: none;
}

html.sidebar-collapsed .sidebar .sidebar-user__meta {
  display: none;
}

html.sidebar-collapsed .sidebar .sidebar-user--trigger {
  justify-content: center;
  padding: 12px 8px;
}

html.sidebar-collapsed .sidebar .sidebar-nav__title {
  flex-direction: row;
  justify-content: center;
  align-items: center;
  gap: 4px;
  padding: 10px 8px;
  letter-spacing: 0;
  margin-bottom: 4px;
  border-radius: var(--sidebar-item-radius);
  background: var(--table-bg);
}

html.sidebar-collapsed .sidebar .sidebar-nav__title:hover {
  background: var(--surface-secondary);
  border-color: var(--border-medium);
}

html.sidebar-collapsed .sidebar .sidebar-nav__title-label {
  display: block;
  line-height: 1;
  flex-shrink: 0;
}

html.sidebar-collapsed .sidebar .sidebar-nav__chevron {
  width: 12px;
  height: 12px;
  margin-left: 0;
  flex-shrink: 0;
  opacity: 0.75;
}

html.sidebar-collapsed .sidebar .sidebar-nav__link {
  justify-content: center;
  padding-left: var(--sidebar-item-padding-x);
  padding-right: var(--sidebar-item-padding-x);
}

html.sidebar-collapsed .sidebar .sidebar-nav__icon {
  margin-right: 0;
}

html.sidebar-collapsed .sidebar .sidebar-nav__label {
  display: none;
}

/* Sidebar tooltip bubble styles — base in main.css (#sidebar-tip-bubble) */
html.sidebar-collapsed .sidebar [data-sidebar-tip] {
  cursor: pointer;
}

/* --- Mobile top bar (drawer trigger) --- */
.app-bar {
  display: none;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 30;
  min-height: 52px;
  margin: 0 -1rem;
  padding: 8px 1rem;
  background: var(--surface-primary);
  border-bottom: 1px solid var(--border-light);
}

.app-bar__menu {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  flex-shrink: 0;
  border: none;
  border-radius: 50%;
  background: var(--surface-secondary);
  color: var(--text-primary);
  cursor: pointer;
  overflow: visible;
  transition: background 0.15s ease, transform 0.15s ease;
}

.app-bar__menu:hover {
  background: var(--surface-tertiary);
  border-color: transparent;
}

.app-bar__menu:active {
  transform: scale(0.97);
}

.app-bar__menu svg {
  display: block;
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  fill: currentColor;
}

.app-bar__logo {
  display: block;
  color: var(--text-primary);
  text-decoration: none;
  line-height: 0;
  min-width: 0;
}

.app-bar__logo:hover {
  text-decoration: none;
}

.app-bar__logo .sidebar__logo-image {
  height: 24px;
}

.app-bar__user {
  margin-left: auto;
  max-width: min(280px, 52%);
  padding: 0;
  gap: 8px;
  min-width: 0;
  background: none;
  border-radius: 0;
  flex-direction: row-reverse;
}

.app-bar__user .sidebar-user__avatar {
  width: 32px;
  height: 32px;
  font-size: var(--font-size-md);
}

.app-bar__user .sidebar-user__meta {
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  text-align: right;
}

.app-bar__user .sidebar-user__meta > .flex-row {
  justify-content: flex-end;
}

.app-bar__user .sidebar-user__name,
.app-bar__user .sidebar-user__role,
.app-bar__user .sidebar-user__casino {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.app-bar__user .sidebar-user__casino {
  width: auto;
}

.sidebar-backdrop {
  display: none;
}

/* --- Accessibility --- */
@media (prefers-reduced-motion: reduce) {
  .sidebar,
  .sidebar__toggle-icon,
  .sidebar-nav__body,
  .sidebar-nav__inner,
  .sidebar-nav__chevron,
  .sidebar-backdrop {
    transition: none;
  }
}

/* --- Drawer: driven by html.sidebar-drawer-mode (not a width query).
   Capture node screenshot briefly changes innerWidth and would hide the
   sidebar if this stayed in a viewport width query. --- */
html.sidebar-drawer-mode .app-shell {
  flex-direction: column;
  padding-top: 0px;
}

html.sidebar-drawer-mode .app-bar {
  display: flex;
}

html.sidebar-drawer-mode .sidebar-backdrop {
  display: block;
  position: fixed;
  inset: 0;
  z-index: 190;
  background: var(--popup-backdrop, #000);
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease-out;
}

html.sidebar-drawer-mode.sidebar-drawer-open .sidebar-backdrop {
  opacity: 0.4;
  pointer-events: auto;
}

html.sidebar-drawer-mode.sidebar-drawer-open {
  overflow: hidden;
}

html.sidebar-drawer-mode .sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 200;
  width: var(--sidebar-width-expanded);
  max-width: min(var(--sidebar-width-expanded), 86vw);
  min-height: 100dvh;
  max-height: 100dvh;
  overflow-y: auto;
  transform: translateX(-100%);
  transition: transform 200ms ease-out;
  padding: 1rem;
}

html.sidebar-drawer-mode.sidebar-drawer-open .sidebar {
  transform: translateX(0);
  box-shadow:
    0 1px 2px rgba(17, 24, 39, 0.06),
    0 8px 24px rgba(17, 24, 39, 0.12);
}

html.sidebar-drawer-mode .sidebar__toggle {
  display: none;
}

html.sidebar-drawer-mode .sidebar__close {
  display: flex;
}

html.sidebar-drawer-mode.sidebar-collapsed .sidebar {
  --sidebar-width: var(--sidebar-width-expanded);
}

html.sidebar-drawer-mode.sidebar-collapsed .sidebar .sidebar__brand {
  display: flex;
}

html.sidebar-drawer-mode.sidebar-collapsed .sidebar .sidebar__logo {
  display: block;
}

html.sidebar-drawer-mode.sidebar-collapsed .sidebar .sidebar-user__meta {
  display: flex;
}

html.sidebar-drawer-mode.sidebar-collapsed .sidebar .sidebar-user--trigger {
  justify-content: flex-start;
  padding: 12px var(--sidebar-item-padding-x);
}

html.sidebar-drawer-mode.sidebar-collapsed .sidebar .sidebar-nav__title {
  flex-direction: row;
  justify-content: space-between;
  padding: 16px var(--sidebar-item-padding-x) 8px;
  letter-spacing: 0.08em;
  margin: 0;
  background: transparent;
  border: none;
}

html.sidebar-drawer-mode.sidebar-collapsed .sidebar .sidebar-nav__title-label {
  text-align: left;
  line-height: inherit;
}

html.sidebar-drawer-mode.sidebar-collapsed .sidebar .sidebar-nav__chevron {
  width: 16px;
  height: 16px;
  margin-left: 8px;
  opacity: 1;
}

html.sidebar-drawer-mode.sidebar-collapsed .sidebar .sidebar-nav__group--folded .sidebar-nav__body {
  grid-template-rows: 0fr;
}

html.sidebar-drawer-mode.sidebar-collapsed .sidebar .sidebar-nav__group--folded .sidebar-nav__inner {
  opacity: 0;
}

html.sidebar-drawer-mode.sidebar-collapsed .sidebar .sidebar-nav__link {
  justify-content: flex-start;
}

html.sidebar-drawer-mode.sidebar-collapsed .sidebar .sidebar-nav__icon {
  margin-right: var(--sidebar-icon-gap);
}

html.sidebar-drawer-mode.sidebar-collapsed .sidebar .sidebar-nav__label {
  display: block;
}
