/*
 * The L1 navigation rail.
 *
 * Simple Shell, so every item is a direct link to a page: no groups, no
 * chevrons, no L2 flyout (see ptag_app.css for why). Everything else is the
 * full Glacier rail -- three states, the signature active indicator, tooltips
 * when collapsed, and the footer toggle.
 *
 * The active indicator is a 3px left border in PTAG blue over a
 * `--ptag-blue-50` tint. Glacier names this the one visual that must be
 * identical in every PTAG app and forbids variations: no underline, no
 * background-only. It is why this app no longer has the underlined top tabs it
 * shipped with.
 */

.ptag-sidebar {
  position: sticky;
  top: calc(var(--header-height) + var(--accent-line-height));
  z-index: var(--z-sidebar);
  display: flex;
  flex-direction: column;
  width: var(--sidebar-width-expanded);
  min-width: var(--sidebar-width-expanded);
  height: calc(100dvh - var(--header-height) - var(--accent-line-height));
  flex-shrink: 0;
  background: var(--surface-secondary);
  border-right: 1px solid var(--border-primary);
  overflow-y: auto;
  overflow-x: hidden;
  transition: width var(--duration-normal) var(--ease-in-out),
              min-width var(--duration-normal) var(--ease-in-out);
}

.ptag-sidebar::-webkit-scrollbar { width: 6px; }
.ptag-sidebar::-webkit-scrollbar-track { background: transparent; }
.ptag-sidebar::-webkit-scrollbar-thumb {
  background: var(--border-secondary);
  border-radius: 3px;
}

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

.ptag-sidebar[data-state="hidden"] {
  width: 0;
  min-width: 0;
  border-right: none;
  overflow: hidden;
}

/* --- menu ---------------------------------------------------------------- */

.ptag-sidebar__menu {
  flex: 1;
  list-style: none;
  margin: 0;
  padding: var(--space-1) var(--space-2);
}

/* A section of the rail: Glacier's optional section label for an L1-only
   shell (CLAUDE-CODE-GUIDE 4.5) above a nested list of direct links. The
   label names the list for assistive tech (aria-labelledby), so it is content
   and takes --text-tertiary: --text-muted is for disabled and decorative text
   only, and fails the 4.5:1 floor at this size. */
.ptag-sidebar__group {
  list-style: none;
  margin: 0;
  padding: 0;
}

.ptag-sidebar__section-label {
  display: block;
  padding: var(--space-5) var(--space-3) 6px;
  font-size: var(--text-caption);
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
  overflow: hidden;
}

.ptag-sidebar[data-state="collapsed"] .ptag-sidebar__section-label {
  opacity: 0;
  height: 0;
  padding: 0;
  margin: 0;
}

/* --- items --------------------------------------------------------------- */

.ptag-sidebar__item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  height: 44px;
  margin: 2px 0;
  padding: 0 var(--space-3);
  border: none;
  /* Reserved for the active state, so an item does not shift by 3px when it
     becomes current. */
  border-left: 3px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: var(--text-body-sm);
  font-weight: 400;
  text-align: left;
  text-decoration: none;
  white-space: nowrap;
  position: relative;
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.ptag-sidebar__item:hover {
  background: var(--surface-tertiary);
  text-decoration: none;
}

/* THE signature active state. Do not restyle per-app. */
.ptag-sidebar__item.is-active {
  border-left-color: var(--ptag-blue);
  background: var(--ptag-blue-50);
  color: var(--ptag-blue);
  font-weight: 600;
}

.ptag-sidebar__item.is-active .ptag-sidebar__icon {
  color: var(--ptag-blue);
}

.ptag-sidebar__item.is-active:hover {
  background: var(--ptag-blue-light);
}

.ptag-sidebar__icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  color: var(--text-muted);
}

.ptag-sidebar__label {
  overflow: hidden;
  opacity: 1;
  transition: opacity var(--duration-fast) ease-in-out 50ms;
}

/* --- collapsed ----------------------------------------------------------- */

.ptag-sidebar[data-state="collapsed"] .ptag-sidebar__label {
  width: 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity 50ms ease-in-out;
}

.ptag-sidebar[data-state="collapsed"] .ptag-sidebar__item {
  justify-content: center;
  padding: 0;
}

/* In collapsed mode the icon *is* the navigation, so the label has to come
   back on hover or the rail is a column of guesses. */
.ptag-sidebar[data-state="collapsed"] .ptag-sidebar__item::after {
  content: attr(data-tooltip);
  position: absolute;
  left: calc(100% + 12px);
  top: 50%;
  transform: translateY(-50%);
  z-index: var(--z-sidebar-tooltip);
  padding: 6px 10px;
  background: var(--neutral-800);
  color: var(--neutral-0);
  font-size: 0.8125rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 150ms ease-in-out;
}

.ptag-sidebar[data-state="collapsed"] .ptag-sidebar__item:hover::after,
.ptag-sidebar[data-state="collapsed"] .ptag-sidebar__item:focus-visible::after {
  opacity: 1;
}

/* The tooltip escapes the rail, so the rail cannot clip its own overflow while
   collapsed. Vertical scrolling is kept; seven items fit without it. */
.ptag-sidebar[data-state="collapsed"] {
  overflow: visible;
}

/* --- footer -------------------------------------------------------------- */

.ptag-sidebar__footer {
  margin-top: auto;
  padding: 6px var(--space-2);
  border-top: 1px solid var(--border-primary);
}

.ptag-sidebar__toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  margin: 0 auto;
  padding: 0;
  border: none;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.ptag-sidebar__toggle:hover {
  background: var(--surface-tertiary);
  color: var(--text-secondary);
}

/* Which chevron shows is derived from the rail's own `data-state`, so the
   arrow can never point the wrong way -- there is no second copy of the state
   for it to drift from. */
.ptag-sidebar__toggle-icon {
  display: none;
}

.ptag-sidebar[data-state="expanded"] .ptag-sidebar__toggle-icon--collapse,
.ptag-sidebar[data-state="collapsed"] .ptag-sidebar__toggle-icon--expand {
  display: flex;
}

/* --- mobile -------------------------------------------------------------- */

@media (max-width: 1023px) {
  .ptag-sidebar {
    position: fixed;
    left: 0;
    width: 280px;
    min-width: 280px;
    z-index: var(--z-mobile-sidebar);
    background: var(--surface-primary);
    transform: translateX(-100%);
    transition: transform 250ms var(--ease-out);
  }

  .ptag-sidebar[data-state="expanded"] {
    transform: translateX(0);
  }

  /* On a phone the rail is either over the content or off-screen; there is no
     64px middle state to collapse into, and the footer chevron would have
     nothing to do. */
  .ptag-sidebar[data-state="collapsed"] {
    width: 280px;
    min-width: 280px;
    transform: translateX(-100%);
  }

  .ptag-sidebar[data-state="hidden"] {
    width: 280px;
    min-width: 280px;
    border-right: 1px solid var(--border-primary);
    overflow-y: auto;
  }

  .ptag-sidebar__footer {
    display: none;
  }
}
