/* ══════════════════════════════════════════════════════════════════
   HEADER
   ══════════════════════════════════════════════════════════════════ */

header {
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: var(--sp-3) var(--sp-6) var(--sp-3) var(--sp-4);
  display: flex;
  align-items: center;
  gap: var(--sp-4);
}

.logo {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-weight: 700;
  font-size: var(--fs-lg);
  letter-spacing: -0.01em;
  color: var(--ink);
  white-space: nowrap;
}

.hdr-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  cursor: pointer;
  transition:
    background-color var(--dur-1) var(--ease-out),
    border-color var(--dur-1) var(--ease-out),
    color var(--dur-1) var(--ease-out);
}
.hdr-icon-btn svg {
  width: 17px;
  height: 17px;
}
.hdr-icon-btn:hover {
  background: var(--surface-2);
  border-color: var(--muted);
  color: var(--ink);
}
/* The hamburger is mobile-only — the desktop sidebar opens on hover instead. */
#btn-menu {
  display: none;
}

/* ══════════════════════════════════════════════════════════════════
   SIDEBAR NAV — desktop: collapsed to an icon rail; hover flies it open,
   the pin button keeps it open. Mobile: off-canvas drawer opened by the
   hamburger button, closed by the backdrop or picking a nav item.
   ══════════════════════════════════════════════════════════════════ */

.app-body {
  display: flex;
  align-items: flex-start;
  position: relative;
}

#sidebar-backdrop {
  display: none;
}

.sidebar {
  position: sticky;
  top: var(--header-h, 57px);
  align-self: flex-start;
  flex-shrink: 0;
  z-index: var(--z-sidebar);
  width: var(--rail-w);
  height: calc(100vh - var(--header-h, 57px));
  transition: width var(--dur-2) var(--ease-out);
}
.sidebar.pinned {
  width: var(--panel-w);
}
.sidebar-panel {
  position: absolute;
  inset: 0;
  width: var(--rail-w);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  padding: var(--sp-2);
  background: var(--surface);
  border-right: 1px solid var(--line);
  transition:
    width var(--dur-2) var(--ease-out),
    box-shadow var(--dur-2) var(--ease-out);
}
.sidebar.pinned .sidebar-panel {
  width: var(--panel-w);
}
.sidebar:not(.pinned):hover .sidebar-panel,
.sidebar:not(.pinned):focus-within .sidebar-panel {
  width: var(--panel-w);
  box-shadow: var(--sh-3);
  border-right-color: var(--line-strong);
}

.nav-item,
.sidebar-pin,
.signout-btn {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  width: 100%;
  min-height: 40px;
  padding: var(--sp-2);
  border: none;
  background: none;
  border-radius: var(--r-md);
  font: inherit;
  font-size: var(--fs-md);
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  text-align: left;
  transition:
    background-color var(--dur-1) var(--ease-out),
    color var(--dur-1) var(--ease-out);
}
.nav-icon {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
}
.nav-label {
  flex: 1;
  overflow: hidden;
  opacity: 0;
  transition: opacity var(--dur-1) var(--ease-out);
}
.sidebar.pinned .nav-label,
.sidebar:hover .nav-label,
.sidebar:focus-within .nav-label {
  opacity: 1;
}

.nav-item:hover {
  background: var(--surface-3);
  color: var(--ink);
}
.nav-item:focus-visible {
  outline-offset: -2px;
}
.nav-item.active {
  position: relative;
  background: var(--line);
  color: var(--ink);
  font-weight: 700;
}
.nav-item.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 20px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
}

.sidebar-pin {
  color: var(--muted);
  margin-bottom: var(--sp-1);
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  padding-bottom: var(--sp-3);
}
.sidebar-pin:hover {
  color: var(--ink);
}
.sidebar-pin[aria-pressed="true"] {
  color: var(--accent);
}

.sidebar-nav {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-user {
  flex-shrink: 0;
  margin-top: var(--sp-1);
  padding-top: var(--sp-2);
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
}
.sidebar-user .user-chip {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2);
  min-height: 40px;
}
.avatar {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  border-radius: var(--r-full);
  background: var(--ink);
  color: var(--accent-ink);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: var(--fs-sm);
}
.user-meta {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  opacity: 0;
  transition: opacity var(--dur-1) var(--ease-out);
}
.sidebar.pinned .user-meta,
.sidebar:hover .user-meta,
.sidebar:focus-within .user-meta {
  opacity: 1;
}
.user-line {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  white-space: nowrap;
}
.user-line b {
  min-width: 0;
  color: var(--ink);
  font-size: var(--fs-sm);
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-meta .role {
  color: var(--muted);
  font-size: var(--fs-xs);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.signout-btn:hover {
  background: color-mix(in srgb, var(--danger) 10%, var(--surface));
  color: var(--danger);
}

/* ── Mobile: off-canvas drawer instead of the hover rail ─────────────
   No hover on touch, so the sidebar is hidden entirely off-screen and
   opens only via the hamburger button (see js/shell.js wireSidebar()). */
@media (max-width: 768px) {
  #btn-menu {
    display: inline-flex;
  }
  .sidebar-pin {
    display: none;
  }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--panel-w);
    height: 100vh;
    transform: translateX(-100%);
    transition: transform var(--dur-2) var(--ease-out);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .sidebar-panel {
    width: 100%;
  }
  /* On the drawer, labels are always visible (no fade — the panel is
     either fully open or fully off-screen, never a narrow rail). */
  .nav-label,
  .user-meta {
    opacity: 1;
  }
  #sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.4);
    z-index: calc(var(--z-sidebar) - 1);
  }
  #sidebar-backdrop.show {
    display: block;
  }
}

/* ══════════════════════════════════════════════════════════════════
   LAYOUT
   ══════════════════════════════════════════════════════════════════ */

main {
  flex: 1;
  min-width: 0;
  padding: var(--sp-6) var(--sp-6) var(--sp-10);
}
.view {
  display: none;
}
.view.active {
  display: block;
  animation: view-in var(--dur-3) var(--ease-out);
}
@keyframes view-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
}

.toolbar {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin: var(--sp-4) 0;
  flex-wrap: wrap;
}
