/**
 * KC7 Sidebar — consolidated styling
 *
 * Replaces:
 *   - components/sidebar-layout.css
 *   - components/sidebar-hover.css
 *   - components/tenant-sidebar.css
 *   - custom/mobile-sidebar.css
 *
 * Layered on top of SB Admin 2. Do not edit sb-admin-2.min.css.
 */

/* ============================================================
 * Tokens
 * ============================================================ */
:root {
  --sidebar-width-expanded: 14rem;       /* matches SB Admin 2 default 224px */
  --sidebar-width-collapsed: 4.5rem;     /* YouTube-style icon + label rail */
  --sidebar-flyout-width: 14rem;
  --sidebar-collapsed-item-padding-y: 0.5rem;
  --sidebar-collapsed-icon-size: 1.1rem;
  --sidebar-collapsed-label-size: 0.625rem;

  /* Sidebar background comes from SB Admin 2's customized .bg-primary
     (#012950) — same navy in every context, light and dark theme. */
  --sidebar-fg: #d8e6f2;
  --sidebar-fg-muted: rgba(216, 230, 242, 0.65);

  --sidebar-accent: #ff5702;   /* KC7 orange — status dots and badges only */
  --sidebar-active-bg: rgba(255, 255, 255, 0.14);
  --sidebar-active-fg: #ffffff;
  --sidebar-hover-bg: rgba(255, 255, 255, 0.08);
  --sidebar-focus-ring: #ffd28a;

  --sidebar-item-radius: 0.5rem;
  --sidebar-item-padding-y: 0.625rem;
  --sidebar-item-padding-x: 0.75rem;
  --sidebar-item-margin-x: 0.5rem;

  --sidebar-text-size: 0.95rem;
  --sidebar-heading-size: 0.7rem;

  --sidebar-divider: rgba(255, 255, 255, 0.12);
  --sidebar-z: 100;
  --sidebar-flyout-z: 110;
  --sidebar-drawer-z: 1100;        /* above topbar (1000) when open on mobile */
  --sidebar-scrim-z: 1099;
  --sidebar-scrim: rgba(0, 0, 0, 0.5);
  --sidebar-tooltip-bg: #111827;
  --sidebar-tooltip-fg: #ffffff;
}

/* ============================================================
 * Layout (desktop)
 * ============================================================ */
.sidebar {
  position: fixed !important;
  top: 0;
  left: 0;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  z-index: var(--sidebar-z);
}

.sidebar::-webkit-scrollbar { width: 8px; }
.sidebar::-webkit-scrollbar-track { background: rgba(255, 255, 255, 0.1); }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.3); border-radius: 4px; }
.sidebar::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.5); }

#content-wrapper {
  margin-left: var(--sidebar-width-expanded);
  width: calc(100% - var(--sidebar-width-expanded));
  transition: margin-left 0.2s ease-in-out, width 0.2s ease-in-out;
  position: relative;
}

@media (min-width: 768px) {
  .sidebar.toggled {
    width: var(--sidebar-width-collapsed) !important;
    overflow-y: auto !important;
    overflow-x: visible !important; /* allow flyout to escape */
  }
  body.sidebar-toggled #content-wrapper {
    margin-left: var(--sidebar-width-collapsed);
    width: calc(100% - var(--sidebar-width-collapsed));
  }
}

/* Topbar must sit above the fixed sidebar, but below the flyout? No — topbar above all */
.topbar { position: relative; z-index: 1000; }

/* Vault filter sidebar coexistence (preserved from old sidebar-layout.css) */
.filter-sidebar { position: sticky !important; z-index: 50; }

/* ============================================================
 * Items: hover, active, focus
 * Single source of truth for active state — filled pill.
 * ============================================================ */
.sidebar .nav-item .nav-link {
  display: flex;
  align-items: center;
  gap: var(--sidebar-item-padding-x);
  margin: 0 var(--sidebar-item-margin-x);
  padding: var(--sidebar-item-padding-y) var(--sidebar-item-padding-x);
  border-radius: var(--sidebar-item-radius);
  font-size: var(--sidebar-text-size);
  transition: background-color 0.15s ease-in-out, color 0.15s ease-in-out;
}

.sidebar .nav-item .nav-link:hover {
  background-color: var(--sidebar-hover-bg);
}

.sidebar .nav-item .nav-link:focus-visible {
  outline: 2px solid var(--sidebar-focus-ring);
  outline-offset: 2px;
}

/* Subtle active state: soft overlay pill only (no layout shift), applied
   uniformly across regular and tenant modes */
.sidebar .nav-item.active > .nav-link,
.sidebar .nav-item .nav-link[aria-current="page"] {
  background-color: var(--sidebar-active-bg);
  color: var(--sidebar-active-fg);
  font-weight: 600;
}
.sidebar .nav-item.active > .nav-link:hover {
  background-color: rgba(255, 255, 255, 0.2);
}

/* Collapse-item (sub-link) hover — these sit on light (themed) panels,
   so they get a neutral overlay rather than the sidebar's white one */
.sidebar .collapse .collapse-item:hover {
  background-color: rgba(0, 0, 0, 0.04);
}
.sidebar .collapse .collapse-item.active {
  background-color: rgba(0, 0, 0, 0.06);
  font-weight: 600;
}

/* ============================================================
 * Headings
 * ============================================================ */
.sidebar .sidebar-heading {
  font-size: var(--sidebar-heading-size);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--sidebar-fg-muted);
  padding: 0.5rem var(--sidebar-item-padding-x);
  margin: 0.5rem var(--sidebar-item-margin-x) 0;
}

/* Exit-tenant link: a quiet utility action, NOT a highlight — the active nav
   item is the sidebar's only lit-up element. Hover comes from the generic
   .nav-link:hover rule. */
.sidebar-exit-tenant {
  color: var(--sidebar-fg-muted);
  margin: 0 var(--sidebar-item-margin-x) !important;
}

/* ============================================================
 * Collapsed rail: hide labels, center icons
 * SB Admin 2 already hides .nav-link span when .toggled — keep,
 * but make sure flyout reveals them.
 * ============================================================ */
@media (min-width: 768px) {
  .sidebar.toggled .sidebar-heading {
    display: none;
  }
  .sidebar.toggled .nav-item .nav-link {
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.2rem;
    margin: 0;
    padding: var(--sidebar-collapsed-item-padding-y) 0.15rem;
    border-radius: 0;
    width: 100%;
    text-align: center;
  }
  .sidebar.toggled .nav-item .nav-link i,
  .sidebar.toggled .nav-item .nav-link .fa,
  .sidebar.toggled .nav-item .nav-link .fas,
  .sidebar.toggled .nav-item .nav-link .far,
  .sidebar.toggled .nav-item .nav-link .fab {
    font-size: var(--sidebar-collapsed-icon-size);
    width: 1.25rem;
    text-align: center;
    margin: 0;
  }
  /* YouTube-style mini-label under each icon */
  .sidebar.toggled .nav-item .nav-link span:not(.claim-badge) {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    overflow: hidden;
    font-size: var(--sidebar-collapsed-label-size);
    line-height: 1.15;
    font-weight: 500;
    letter-spacing: 0.01em;
    max-width: 100%;
    word-break: break-word;
    text-transform: none;
  }
  /* Flyouts replace the inline accordion when the rail is collapsed */
  .sidebar.toggled .nav-item > .collapse,
  .sidebar.toggled .nav-item > .collapsing {
    display: none !important;
  }
  .sidebar.toggled hr.sidebar-divider { margin: 0.25rem 0.5rem; }
  .sidebar.toggled .sidebar-brand { padding: 0.5rem 0; }
  .sidebar.toggled .sidebar-brand .sidebar-brand-text { display: none; }
}

/* ============================================================
 * Flyout (collapsed mode, desktop)
 * Rendered inline by sidebar.js as a sibling of the trigger
 * ============================================================ */
.sidebar-flyout {
  position: fixed;            /* positioned by JS to align with trigger */
  z-index: var(--sidebar-flyout-z);
  min-width: var(--sidebar-flyout-width);
  background: var(--color-surface);
  color: var(--color-text-primary);
  border-radius: var(--sidebar-item-radius);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
  padding: 0.5rem 0;
  display: none;
}
.sidebar-flyout.is-open { display: block; }
.sidebar-flyout .sidebar-flyout-title {
  padding: 0.25rem 0.875rem 0.5rem;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-secondary);
  border-bottom: 1px solid #f1f5f9;
  margin-bottom: 0.25rem;
}
.sidebar-flyout a {
  display: block;
  padding: 0.5rem 0.875rem;
  color: var(--color-text-primary);
  text-decoration: none;
  font-size: 0.9rem;
}
.sidebar-flyout a:hover,
.sidebar-flyout a:focus-visible {
  background-color: var(--color-bg);
  color: var(--color-text-primary);
  outline: none;
}
.sidebar-flyout a.active {
  background-color: var(--color-bg);
  color: var(--color-text-primary);
  font-weight: 600;
}

/* ============================================================
 * Tooltips for collapsed icons
 * Lightweight CSS-only tooltip; appears on hover and on
 * keyboard focus of the .nav-link.
 * ============================================================ */
/* ============================================================
 * Tooltip for collapsed rail
 * Rendered as a single `.sidebar-tooltip` element appended to
 * <body> by sidebar.js so it isn't clipped by the sidebar's
 * scroll container (overflow-y: auto coerces overflow-x to clip).
 * ============================================================ */
.sidebar-tooltip {
  position: fixed;
  z-index: var(--sidebar-flyout-z);
  background: var(--sidebar-tooltip-bg);
  color: var(--sidebar-tooltip-fg);
  padding: 0.35rem 0.6rem;
  border-radius: 0.3rem;
  font-size: 0.78rem;
  line-height: 1.2;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transform: translateY(-50%);
  transition: opacity 0.12s ease-in-out;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}
.sidebar-tooltip[data-visible="true"] {
  opacity: 1;
}
.sidebar-tooltip::before {
  content: "";
  position: absolute;
  top: 50%;
  left: -4px;
  width: 8px;
  height: 8px;
  background: var(--sidebar-tooltip-bg);
  transform: translateY(-50%) rotate(45deg);
}
@media (max-width: 767.98px) {
  .sidebar-tooltip { display: none !important; }
}

/* ============================================================
 * Mobile: offcanvas drawer with scrim and focus trap
 * Below 768px the sidebar slides in over content.
 * ============================================================ */
@media (max-width: 767.98px) {
  .sidebar {
    position: fixed !important;
    left: calc(var(--sidebar-width-expanded) * -1);
    width: var(--sidebar-width-expanded) !important;
    transition: left 0.25s ease-in-out, visibility 0s linear 0.25s;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.3);
    visibility: hidden;
    z-index: var(--sidebar-drawer-z);
  }
  body.sidebar-open .sidebar {
    left: 0;
    visibility: visible;
    transition: left 0.25s ease-in-out, visibility 0s linear 0s;
  }
  /* Force labels visible on mobile regardless of toggled state */
  .sidebar .nav-item .nav-link span,
  .sidebar.toggled .nav-item .nav-link span { display: inline !important; }
  .sidebar .sidebar-heading,
  .sidebar.toggled .sidebar-heading { display: block !important; }
  .sidebar .nav-item .nav-link { justify-content: flex-start; }
  /* Restore inline accordion behaviour on mobile (no flyouts on touch) */
  .sidebar.toggled .nav-item > .collapse,
  .sidebar.toggled .nav-item > .collapsing { display: block !important; }

  #content-wrapper,
  body.sidebar-toggled #content-wrapper {
    margin-left: 0 !important;
    width: 100% !important;
  }

  /* Hide the desktop collapse toggler on mobile */
  .sidebar #sidebarToggle { display: none; }
}

.sidebar-scrim {
  position: fixed;
  inset: 0;
  background: var(--sidebar-scrim);
  z-index: var(--sidebar-scrim-z);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease-in-out;
}
body.sidebar-open .sidebar-scrim {
  opacity: 1;
  pointer-events: auto;
}

/* Hamburger trigger fallback (rendered into topbar by sidebar.js when no
 * existing #sidebarToggleTop is present). */
.sidebar-mobile-toggle {
  display: none;
  background: transparent;
  border: 0;
  font-size: 1.25rem;
  padding: 0.5rem 0.75rem;
  color: inherit;
  cursor: pointer;
}
@media (max-width: 767.98px) {
  .sidebar-mobile-toggle { display: inline-flex; align-items: center; }
}
.sidebar-mobile-toggle:focus-visible {
  outline: 2px solid var(--sidebar-focus-ring);
  outline-offset: 2px;
  border-radius: 0.25rem;
}

/* ============================================================
 * Badge inside nav-link (e.g. org count pill)
 * ============================================================ */
.sidebar .nav-item .nav-link .badge {
  margin-left: auto;
  font-size: 0.7rem;
  padding: 0.25em 0.55em;
}
/* Hide badge pill when sidebar is collapsed to keep the icon rail clean */
@media (min-width: 768px) {
  .sidebar.toggled .nav-item .nav-link .badge { display: none; }
}

/* ============================================================
 * Attention dot inside nav-link (e.g. Daily7 unplayed today)
 * Sidebar background is the same navy in both themes, so
 * --sidebar-accent reads correctly in light and dark.
 * ============================================================ */
.sidebar .nav-item .nav-link .sidebar-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--sidebar-accent);
  margin-left: auto;
  flex-shrink: 0;
  animation: sidebar-dot-pulse 2s ease-in-out infinite;
}
@keyframes sidebar-dot-pulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--sidebar-accent) 55%, transparent); }
  50% { box-shadow: 0 0 0 4px color-mix(in srgb, var(--sidebar-accent) 0%, transparent); }
}
@media (prefers-reduced-motion: reduce) {
  .sidebar .nav-item .nav-link .sidebar-dot { animation: none; }
}
/* Collapsed rail: pin the dot to the icon's top-right corner so it
   survives the column layout (label sits under the icon there). */
@media (min-width: 768px) {
  .sidebar.toggled .nav-item .nav-link:has(.sidebar-dot) { position: relative; }
  .sidebar.toggled .nav-item .nav-link .sidebar-dot {
    position: absolute;
    top: 0.35rem;
    right: 0.9rem;
    margin-left: 0;
  }
}

/* ============================================================
 * Workspace switcher (tenant org name in the sidebar)
 * ============================================================ */
.tenant-switcher {
  position: relative;
  margin: var(--space-8, 0.5rem) var(--sidebar-item-margin-x) 0;
}

.tenant-switcher-trigger {
  display: flex;
  align-items: center;
  gap: var(--space-8, 0.5rem);
  width: 100%;
  padding: var(--space-8, 0.5rem) var(--space-10, 0.625rem);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #fff;
  border-radius: var(--radius-md, 6px);
  font-size: var(--font-size-sm, 0.875rem);
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background-color 150ms ease, border-color 150ms ease;
}

.tenant-switcher-trigger:hover,
.tenant-switcher-trigger[aria-expanded="true"] {
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.22);
}

.tenant-switcher-icon {
  flex-shrink: 0;
  opacity: 0.9;
}

.tenant-switcher-name {
  flex: 1 1 auto;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tenant-switcher-chevron {
  flex-shrink: 0;
  font-size: 0.65rem;
  opacity: 0.75;
  transition: transform 150ms ease;
}

.tenant-switcher-trigger[aria-expanded="true"] .tenant-switcher-chevron {
  transform: rotate(180deg);
}

.tenant-switcher-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 1200;
  background: var(--color-surface);
  color: var(--color-text-primary);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md, 6px);
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.18);
  padding: var(--space-4, 0.25rem) 0;
  max-height: 320px;
  overflow-y: auto;
}

.tenant-switcher-menu[hidden] {
  display: none;
}

.tenant-switcher-loading,
.tenant-switcher-empty {
  padding: var(--space-12, 0.75rem);
  font-size: var(--font-size-sm, 0.875rem);
  color: var(--color-text-muted);
  text-align: center;
}

.tenant-switcher-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.tenant-switcher-item {
  display: flex;
  align-items: center;
  gap: var(--space-8, 0.5rem);
  padding: var(--space-8, 0.5rem) var(--space-12, 0.75rem);
  font-size: var(--font-size-sm, 0.875rem);
  color: var(--color-text-primary);
  text-decoration: none;
  cursor: pointer;
  border: 0;
  background: none;
  width: 100%;
  text-align: left;
  transition: background-color 120ms ease;
}

.tenant-switcher-item:hover,
.tenant-switcher-item:focus-visible {
  background: var(--color-surface-raised);
  outline: none;
}

.tenant-switcher-item-name {
  flex: 1 1 auto;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tenant-switcher-item-role {
  font-size: var(--font-size-xs, 0.75rem);
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.tenant-switcher-item-check {
  color: var(--color-accent);
  font-size: 0.75rem;
  width: 12px;
  text-align: center;
}

.tenant-switcher-item.is-current .tenant-switcher-item-name {
  color: var(--color-accent);
}

.tenant-switcher-action {
  display: flex;
  align-items: center;
  gap: var(--space-8, 0.5rem);
  padding: var(--space-8, 0.5rem) var(--space-12, 0.75rem);
  margin-top: var(--space-4, 0.25rem);
  border-top: 1px solid var(--color-border-subtle);
  font-size: var(--font-size-sm, 0.875rem);
  color: var(--color-accent);
  text-decoration: none;
}

.tenant-switcher-action:hover {
  background: var(--color-accent-light);
  color: var(--color-accent-hover);
  text-decoration: none;
}

/* Collapsed sidebar: hide the switcher chrome, keep only the icon */
@media (min-width: 768px) {
  .sidebar.toggled .tenant-switcher {
    margin: var(--space-8, 0.5rem) 0 0;
    padding: 0 var(--space-4, 0.25rem);
  }
  .sidebar.toggled .tenant-switcher-trigger {
    justify-content: center;
    padding: var(--space-8, 0.5rem) 0;
  }
  .sidebar.toggled .tenant-switcher-name,
  .sidebar.toggled .tenant-switcher-chevron {
    display: none;
  }
  .sidebar.toggled .tenant-switcher-menu {
    left: calc(100% + 4px);
    right: auto;
    top: 0;
    min-width: 220px;
  }
}
