/* Shared application shell and sidebar navigation. */

.skip-navigation {
  position: absolute;
  top: 12px;
  left: -10000px;
  z-index: 300;
  padding: 8px 12px;
  color: var(--text-primary);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  text-decoration: none;
}

.skip-navigation:focus {
  left: var(--page-gutter);
}

.app-shell {
  flex: 1;
  min-height: 100vh;
  min-height: 100dvh;
}

.app-frame {
  display: flex;
  min-height: 100vh;
  min-height: 100dvh;
  width: 100%;
}

.app-content {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
  min-height: 100vh;
  min-height: 100dvh;
}

.sidebar-sticky {
  display: flex;
  flex: 0 0 auto;
  position: sticky;
  top: 0;
  z-index: 100;
  height: 100vh;
  height: 100dvh;
}

.desktop-sidebar {
  width: var(--sidebar-collapsed-width);
  height: 100%;
  overflow: hidden;
  color: var(--text-primary);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  transition: width 220ms var(--ease);
}

.desktop-sidebar[data-sidebar-state="expanded"] {
  width: var(--sidebar-width);
}

.desktop-sidebar[data-sidebar-state="expanded"] [data-sidebar-target="desktopCollapsed"],
.desktop-sidebar[data-sidebar-state="collapsed"] [data-sidebar-target="desktopExpanded"] {
  display: none;
}

/* The head script sets this attribute before the body is painted. It lets
   legacy localStorage preferences match the server-rendered sidebar state
   during the first paint, before Stimulus syncs the preference cookie. */
html[data-sidebar-state="expanded"] .desktop-sidebar {
  width: var(--sidebar-width);
}

html[data-sidebar-state="expanded"] .desktop-sidebar [data-sidebar-target="desktopExpanded"] {
  display: block;
}

html[data-sidebar-state="expanded"] .desktop-sidebar [data-sidebar-target="desktopCollapsed"] {
  display: none;
}

html[data-sidebar-state="collapsed"] .desktop-sidebar {
  width: var(--sidebar-collapsed-width);
}

html[data-sidebar-state="collapsed"] .desktop-sidebar [data-sidebar-target="desktopExpanded"] {
  display: none;
}

html[data-sidebar-state="collapsed"] .desktop-sidebar [data-sidebar-target="desktopCollapsed"] {
  display: block;
}

@media (prefers-reduced-motion: reduce) {
  .desktop-sidebar {
    transition: none;
  }
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 10px 8px;
  user-select: none;
}

.sidebar-nav--collapsed {
  align-items: center;
  padding-inline: 6px;
}

.sidebar-nav-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  gap: 8px;
  min-height: 42px;
  padding: 0 2px 10px;
}

.sidebar-nav--collapsed .sidebar-nav-header {
  justify-content: center;
  height: 42px;
  min-height: 42px;
  gap: 0;
}

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

.sidebar-brand {
  display: inline-flex;
  align-items: center;
  min-width: 0;
  gap: 9px;
  color: var(--text-primary);
  text-decoration: none;
}

.sidebar-brand:hover {
  color: var(--text-primary);
}

.sidebar-brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 29px;
  height: 29px;
  color: var(--bg);
  background: var(--accent);
  border-radius: 8px;
  font-family: var(--font-display);
  font-size: 18px;
  line-height: 1;
}

.sidebar-brand-name {
  overflow: hidden;
  font-family: var(--font-display);
  font-size: 19px;
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-brand--collapsed {
  justify-content: center;
}

.sidebar-icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  padding: 0;
  color: var(--text-secondary);
  background: transparent;
  border: 0;
  border-radius: var(--radius);
  appearance: none;
  cursor: pointer;
  outline: none;
  transition: color 160ms var(--ease), background 160ms var(--ease);
}

.sidebar-icon-button:hover,
.sidebar-icon-button:focus-visible {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.icon {
  display: block;
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
}

.sidebar-nav-body {
  flex: 1;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 4px 0 12px;
}

.sidebar-nav-heading {
  height: 24px;
  overflow: hidden;
  padding: 6px 10px;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  line-height: 1.2;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.sidebar-nav-divider {
  position: relative;
  width: 28px;
  height: 24px;
  margin: 0 auto;
}

.sidebar-nav-divider::before {
  position: absolute;
  top: 50%;
  right: 0;
  left: 0;
  border-top: 1px solid var(--border);
  content: "";
}

.sidebar-nav-divider--large {
  height: 48px;
}

.sidebar-link {
  display: flex;
  align-items: center;
  width: 100%;
  min-width: 0;
  color: var(--text-secondary);
  background: transparent;
  border: 0;
  border-radius: var(--radius);
  appearance: none;
  font-family: var(--font-sans);
  font-size: 13.5px;
  font-weight: 500;
  line-height: 1.2;
  text-align: left;
  text-decoration: none;
  outline: none;
  transition: color 160ms var(--ease), background 160ms var(--ease);
}

.sidebar-link:hover,
.sidebar-link:focus-visible {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.sidebar-link.is-active,
.sidebar-link.is-active:hover,
.sidebar-link.is-active:focus-visible {
  color: var(--accent-dim);
  background: var(--accent-soft);
}

.sidebar-nav:not(.sidebar-nav--collapsed) .sidebar-link {
  min-height: 36px;
  gap: 10px;
  padding: 8px 10px;
}

.sidebar-nav--collapsed .sidebar-link {
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
}

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

.sidebar-nav--collapsed .icon {
  width: 19px;
  height: 19px;
}

.sidebar-link-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-footer {
  flex: 0 0 auto;
  padding-top: 8px;
  border-top: 1px solid var(--border-subtle);
}

.sidebar-account {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 9px;
  height: 45px;
  padding: 7px 8px 10px;
}

.sidebar-account--collapsed {
  justify-content: center;
  padding: 7px 0 10px;
}

.sidebar-account-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  color: var(--accent-dim);
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  border-radius: 8px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.sidebar-account-copy {
  display: flex;
  flex-direction: column;
  min-width: 0;
  gap: 2px;
}

.sidebar-account-email,
.sidebar-account-role {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-account-email {
  color: var(--text-primary);
  font-size: 11px;
  font-weight: 600;
}

.sidebar-account-role {
  color: var(--text-muted);
  font-size: 10px;
}

.sidebar-form {
  margin: 0;
}

.sidebar-form .sidebar-link {
  min-height: 36px;
  padding: 8px 10px;
  color: var(--text-secondary);
  background: transparent;
  border: 0;
  box-shadow: none;
  cursor: pointer;
}

.sidebar-nav--collapsed .sidebar-form .sidebar-link {
  width: 36px;
  height: 36px;
  padding: 0;
}

.sidebar-form .sidebar-link:hover,
.sidebar-form .sidebar-link:focus-visible {
  color: var(--text-primary);
  background: var(--bg-hover);
  box-shadow: none;
}

.sidebar-form .sidebar-link.is-active,
.sidebar-form .sidebar-link:active {
  box-shadow: none;
  transform: none;
}

.public-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--nav-height);
  background: var(--nav-bg);
  backdrop-filter: blur(16px) saturate(180%);
  -webkit-backdrop-filter: blur(16px) saturate(180%);
  border-bottom: 1px solid var(--nav-border);
}

.public-nav-container {
  display: flex;
  align-items: center;
  max-width: 1280px;
  height: 100%;
  margin: 0 auto;
  padding: 0 var(--page-gutter);
}

.public-nav .nav-brand {
  display: flex;
  align-items: center;
  color: var(--text-primary);
  text-decoration: none;
}

.public-nav .brand-text {
  font-family: var(--font-display);
  font-size: 18px;
  line-height: 1;
}

.mobile-menu-bar {
  display: none;
}

.mobile-sidebar {
  position: fixed;
  inset: 0;
  z-index: 250;
}

.mobile-sidebar-backdrop {
  position: absolute;
  inset: 0;
  background: var(--overlay-bg);
  opacity: 0;
  transition: opacity 180ms var(--ease);
}

.mobile-sidebar-panel {
  position: absolute;
  inset: 0 auto 0 0;
  width: min(var(--sidebar-width), 85vw);
  overflow-y: auto;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  box-shadow: var(--overlay-shadow);
  transform: translateX(-100%);
  transition: transform 220ms var(--ease);
}

.mobile-sidebar.is-open .mobile-sidebar-backdrop {
  opacity: 1;
}

.mobile-sidebar.is-open .mobile-sidebar-panel {
  transform: translateX(0);
}

body.sidebar-open {
  overflow: hidden;
}

@media (prefers-reduced-motion: reduce) {
  .mobile-sidebar-backdrop,
  .mobile-sidebar-panel {
    transition: none;
  }
}

@media (max-width: 767px) {
  .sidebar-sticky,
  .desktop-sidebar {
    display: none;
  }

  .mobile-menu-bar {
    display: flex;
    align-items: center;
    flex: 0 0 var(--mobile-header-height);
    gap: 10px;
    height: var(--mobile-header-height);
    padding: 0 var(--page-gutter);
    background: var(--nav-bg);
    border-bottom: 1px solid var(--nav-border);
  }

  .mobile-brand {
    color: var(--text-primary);
    font-family: var(--font-display);
    font-size: 18px;
    text-decoration: none;
  }

  .mobile-menu-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    padding: 0;
    color: var(--text-secondary);
    background: transparent;
    border: 0;
    border-radius: var(--radius);
    appearance: none;
    cursor: pointer;
    outline: none;
  }

  .mobile-menu-button:hover,
  .mobile-menu-button:focus-visible {
    color: var(--text-primary);
    background: var(--bg-hover);
  }
}
