/* The panel shell: sidebar, topbar, content column. */

.panel {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
  transition: grid-template-columns var(--transition);
}

/* Collapsed: the sidebar stays, narrowed to an icon rail. Only the labels go,
 * so navigation is still one click away — which is the point of collapsing
 * rather than hiding.
 *
 * Desktop only. Below 900px the sidebar is a drawer and the same button opens
 * it instead, so these rules must not reach it — hence the min-width. */
@media (min-width: 901px) {
  .panel.is-sidebar-collapsed {
    grid-template-columns: var(--sidebar-w-collapsed) 1fr;
  }

  .panel.is-sidebar-collapsed .sidebar {
    padding-left: var(--s-2);
    padding-right: var(--s-2);
    overflow-x: hidden;
  }

  .panel.is-sidebar-collapsed .sidebar__link {
    justify-content: center;
    padding-left: 0;
    padding-right: 0;
  }

  /* Everything in a link except its icon is the label. */
  .panel.is-sidebar-collapsed .sidebar__link > :not(.sidebar__icon),
  .panel.is-sidebar-collapsed .sidebar__section {
    display: none;
  }
}

/* ----------------------------------------------------------------- scrim */

/* Hidden outright on desktop: there the sidebar is a permanent column, so
 * there is nothing to dim and nothing to close. The [hidden] attribute is
 * managed by static/js/ui.js; this rule is the wide-screen backstop. */
.sidebar-scrim {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 50; /* under .sidebar's 60, over everything else */
  background: var(--c-scrim);
}

/* Locks the page behind an open drawer or modal. A class rather than an
 * inline style, because the CSP in internal/middleware/headers.go blocks
 * style attributes.
 *
 * overflow:hidden alone does not stop touch scrolling on iOS Safari — the
 * page behind the dialog still follows the finger. The fixed body does; the
 * price is that the viewport resets, so ui.js writes the scroll offset into
 * body.top when locking and scrolls back on release. */
body.is-drawer-open {
  overflow: hidden;
  position: fixed;
  left: 0;
  right: 0;
  width: 100%;
}

/* ---------------------------------------------------------------- sidebar */

.sidebar {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  padding: var(--s-4) var(--s-3);
  background: var(--c-surface);
  border-right: 1px solid var(--c-border);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar__nav { display: flex; flex-direction: column; gap: 2px; }

.sidebar__link {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-md);
  color: var(--c-text-soft);
  font-weight: 550;
  transition: background var(--transition), color var(--transition);
}

.sidebar__link:hover {
  background: var(--c-surface-2);
  color: var(--c-text);
  text-decoration: none;
}

.sidebar__link.is-active {
  background: var(--c-accent-soft);
  color: var(--c-accent);
}

/* The logout control is a submit button so it can POST, but it must look
 * like the links above it. No inline style attribute — the CSP in
 * internal/middleware/headers.go sets style-src 'self', which blocks those. */
.sidebar__link--button {
  width: 100%;
  border: 0;
  background: none;
  font: inherit;
  font-weight: 550;
  text-align: left;
  cursor: pointer;
}

.sidebar__icon { font-size: 1.05em; width: 20px; text-align: center; }

.sidebar__section {
  padding: var(--s-4) var(--s-3) var(--s-1);
  font-size: var(--fs-xs);
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--c-text-mute);
}

.sidebar__foot {
  margin-top: auto;
  padding-top: var(--s-3);
  border-top: 1px solid var(--c-border);
}

/* ----------------------------------------------------------------- topbar */

.panel__main { display: flex; flex-direction: column; min-width: 0; }

.topbar {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  height: var(--topbar-h);
  padding: 0 var(--s-5);
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
  position: sticky;
  top: 0;
  z-index: 30;
}

.topbar__title { font-weight: 600; font-size: var(--fs-lg); }

.topbar__actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: var(--s-3);
}

.topbar__user {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  padding-left: var(--s-3);
  border-left: 1px solid var(--c-border);
}

.topbar__user-name { font-weight: 550; font-size: var(--fs-sm); }
.topbar__user-role { font-size: var(--fs-xs); color: var(--c-text-mute); }

.topbar__burger { display: inline-flex; }

/* ---------------------------------------------------------------- content */

/* No max-width: the content fills its grid column, so collapsing the sidebar
 * actually buys width instead of just widening the gap on the right. */
.panel__content {
  flex: 1;
  padding: var(--s-5);
  width: 100%;
}

/* --------------------------------------------------------------- responsive */

@media (max-width: 900px) {
  /* The collapsed class outranks a bare .panel selector, so it has to be named
   * here too or a panel collapsed on desktop keeps its rail after a resize. */
  .panel,
  .panel.is-sidebar-collapsed { grid-template-columns: 1fr; }

  .sidebar {
    position: fixed;
    z-index: 60;
    top: 0;
    left: 0;
    width: var(--sidebar-w);
    transform: translateX(-100%);
    transition: transform var(--transition);
    box-shadow: var(--sh-3);
  }

  .sidebar.is-open { transform: none; }

  /* Shown only when the drawer is out, and only on narrow screens. */
  .sidebar-scrim:not([hidden]) { display: block; }

  .topbar__burger { display: inline-flex; }

  .panel__content { padding: var(--s-4); }
}
