/* ==========================================================================
   App view: the same pages with a sidebar instead of the header, like the
   Claude interface. Desktop only (wide screen and a mouse); everywhere else
   this file does nothing and the classic view is all there is.

   html[data-view="app"] is set before the first paint (see the inline script
   in <head>): the visitor's stored choice, otherwise open from 1280px wide; js/app-view.js builds the sidebar and
   the button in the header, and switches between the two views.

   Figma: "Sidebar nav" (node 442:24805), 240px wide, designed at 1440x800.
   ========================================================================== */

:root {
  --sb-width: 240px;
  --sb-bg: #1a1a1a;
  --sb-line: #292929;
  --sb-active: #292929;
  --sb-hover: #222222;
  --sb-card: #1f1f1f;
  --sb-text: #ffffff;
  --sb-muted: rgba(255, 255, 255, 0.5);
}

/* Not designed in Figma: derived from the light page colours. */
:root[data-theme="light"] {
  --sb-bg: #f6f2ec;
  --sb-line: #e6e0d6;
  --sb-active: #ebe5db;
  --sb-hover: #f1ece5;
  --sb-card: #fbf8f4;
  --sb-text: #000000;
  --sb-muted: rgba(0, 0, 0, 0.5);
}

.app-sidebar,
.view-toggle {
  display: none;
}

@media (min-width: 1024px) and (hover: hover) and (pointer: fine) {
  /* --- The switch in the classic header, to the left of the name --- */
  .site-header__start {
    display: flex;
    align-items: center;
    gap: 4px;
  }

  .view-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: none;
    width: 32px;
    height: 32px;
    margin-left: -8px;
    border-radius: 8px;
    color: var(--color-heading);
  }

  /* --- Switching views ---
     The sidebar slides in from the left while the content moves over to make
     room and the header fades out; closing plays it in reverse. The header
     stays in the page (just invisible), so nothing jumps up or down. */
  body {
    transition: padding-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  }

  .site-header {
    transition: opacity 0.2s ease, visibility 0s linear 0s;
  }

  html[data-view="app"] .site-header {
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0s linear 0.2s;
  }

  html[data-view="app"] body {
    padding-left: var(--sb-width);
  }

  /* The 404 page's fixed background starts next to the sidebar, like the content. */
  html[data-view="app"] .not-found__backdrop {
    left: var(--sb-width);
  }

  /* --- Sidebar --- */
  .app-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    width: var(--sb-width);
    background: var(--sb-bg);
    /* Lines are inset shadows, like Figma's inside strokes: they take no room. */
    box-shadow: inset -1px 0 0 var(--sb-line);
    color: var(--sb-text);
    font-size: 14px;
    font-weight: var(--fw-medium);
    line-height: 16px;
    letter-spacing: -0.14px;
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), visibility 0s linear 0.3s;
  }

  html[data-view="app"] .app-sidebar {
    transform: none;
    visibility: visible;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), visibility 0s linear 0s;
  }

  /* Both theme toggles are rendered now (one of them invisible), and only one
     element may carry the view-transition name of the theme switch. */
  .app-sidebar .theme-toggle,
  html[data-view="app"] .site-header .theme-toggle {
    view-transition-name: none;
  }

  html[data-view="app"] .app-sidebar .theme-toggle {
    view-transition-name: theme-toggle;
  }
}

@media (min-width: 1024px) and (hover: hover) and (pointer: fine) and (prefers-reduced-motion: reduce) {
  body,
  .site-header,
  html[data-view="app"] .site-header,
  .app-sidebar,
  html[data-view="app"] .app-sidebar {
    transition: none;
  }
}

/* Icons are the Figma ones at 16px, drawn in currentColor. They rest at 50%
   and go to 100% on hover and keyboard focus. */
.app-icon {
  display: block;
  flex: none;
  width: 16px;
  height: 16px;
  opacity: 0.5;
  transition: opacity 0.15s ease;
}

.view-toggle:hover .app-icon,
.view-toggle:focus-visible .app-icon,
.app-sidebar__button:hover .app-icon,
.app-sidebar__button:focus-visible .app-icon,
.app-nav__item:hover .app-icon,
.app-nav__item:focus-visible .app-icon,
.app-group__head:hover .app-icon,
.app-group__head:focus-visible .app-icon {
  opacity: 1;
}

/* Heading: title and the button that closes the sidebar. */
.app-sidebar__head {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: space-between;
  height: 48px;
  padding: 0 10px 0 20px;
  box-shadow: inset 0 -1px 0 var(--sb-line);
}

.app-sidebar__title {
  color: var(--sb-text);
  white-space: nowrap;
}

.app-sidebar__button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  color: var(--sb-text);
}

.app-sidebar__button:hover {
  background: var(--sb-hover);
}

/* Navigation and project groups scroll between the fixed top and bottom. */
.app-sidebar__scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 12px;
  scrollbar-width: thin;
  scrollbar-color: var(--sb-line) transparent;
}

.app-nav {
  margin: 0;
  padding: 0;
  list-style: none;
}

/* 32px per row: 2px above and below the 28px item (padding, so it can't
   collapse the way margins would). */
.app-nav > li {
  padding: 2px 0;
}

.app-nav__item {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 6px 8px;
  border-radius: 8px;
  color: var(--sb-text);
  letter-spacing: -0.1px;
  white-space: nowrap;
  transition: background-color 0.15s ease;
}

/* Hover sits between the sidebar and the active item: clearly there, but
   quieter than the item you're on. */
.app-nav__item:not([aria-current]):hover {
  background: var(--sb-hover);
}

.app-nav__item[aria-current] {
  background: var(--sb-active);
}

.app-nav__label {
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-group {
  margin-top: 8px;
}

.app-group__head {
  display: flex;
  align-items: center;
  gap: 4px;
  width: 100%;
  height: 20px;
  padding: 2px 8px;
  border-radius: 8px;
  color: var(--sb-muted);
  font-size: 12px;
  letter-spacing: -0.1px;
  text-align: left;
}

.app-group__head:hover {
  color: var(--sb-text);
}

.app-group__head .app-icon {
  width: 14px;
  height: 14px;
  transition: opacity 0.15s ease, transform 0.24s cubic-bezier(0.4, 0, 0.2, 1);
}

.app-group__label {
  padding: 0 2px;
}

.app-group__head[aria-expanded="false"] .app-icon {
  transform: rotate(180deg);
}

/* Opening and closing: the list grows and shrinks between 0 and its own
   height (a grid row going between 0fr and 1fr), so everything below moves
   along and the items slide up behind the heading. Same curve as the sidebar
   itself; js/app-view.js sets .app-group--moving while it plays. */
.app-group__body {
  display: grid;
  grid-template-rows: 1fr;
  transition: grid-template-rows 0.24s cubic-bezier(0.4, 0, 0.2, 1), visibility 0s linear 0s;
}

.app-group__body > .app-nav {
  min-height: 0;
}

.app-group__body li {
  transition: opacity 0.18s ease, transform 0.24s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Closed: hidden as well once it has slid shut, so Tab skips the links. */
.app-group__head[aria-expanded="false"] + .app-group__body {
  grid-template-rows: 0fr;
  visibility: hidden;
  transition: grid-template-rows 0.24s cubic-bezier(0.4, 0, 0.2, 1), visibility 0s linear 0.24s;
}

.app-group__head[aria-expanded="false"] + .app-group__body li {
  opacity: 0;
  transform: translateY(-6px);
}

/* Clipped only while closed or moving: open, focus rings may stick out. */
.app-group__head[aria-expanded="false"] + .app-group__body > .app-nav,
.app-group--moving .app-group__body > .app-nav {
  overflow: hidden;
}

/* Laying the groups out on load or when the window changes: no sliding.
   (As specific as the closed rule above, and later, so it wins.) */
.app-sidebar--instant .app-group__head .app-icon,
.app-sidebar--instant .app-group__head + .app-group__body,
.app-sidebar--instant .app-group__body li {
  transition: none;
}

@media (prefers-reduced-motion: reduce) {
  .app-group__head[aria-expanded] + .app-group__body {
    transition: none;
  }
}

/* Bottom: the contact card (always shown) and the profile row with the theme
   toggle. When the window is too low for everything, js/app-view.js keeps
   only one of the two groups open instead. */
.app-sidebar__bottom {
  flex: none;
}

.app-contact {
  padding: 16px 20px 20px;
}

.app-contact__card {
  padding: 12px;
  border-radius: 8px;
  background: var(--sb-card);
  box-shadow: inset 0 0 0 1px var(--sb-line);
}

.app-contact__title {
  margin: 0;
  color: var(--sb-text);
  font-weight: var(--fw-semibold);
}

.app-contact__text {
  margin: 4px 0 8px;
  color: var(--sb-muted);
  line-height: 20px;
  letter-spacing: -0.28px;
}

.app-contact .link-accent {
  font-weight: var(--fw-semibold);
  line-height: 20px;
  letter-spacing: 0;
}

.app-user {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
  padding: 16px 16px 20px 20px;
  box-shadow: inset 0 1px 0 var(--sb-line);
}

.app-user__who {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  letter-spacing: -0.14px;
}

.app-user__avatar {
  flex: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  object-fit: cover;
  object-position: 50% 20%;
}

.app-user__role {
  color: var(--sb-muted);
  font-size: 12px;
}

.app-user__sep {
  margin: 0 4px;
  color: var(--sb-muted);
  font-size: 14px;
  font-weight: var(--fw-semibold);
}
