/*
 * The signed-in shell. The sidebar frames every page: the mark, the sections,
 * then Help and, at the foot, the organization and the person signed in, which
 * opens a menu for switching organizations, Profile and Sign out. Pages start
 * with their own title; there is no header on wide screens. On phones a bar
 * with Menu opens the sidebar as a drawer. Loaded after portal.css and
 * app.css, whose tokens it uses.
 */

.shell {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  min-height: 100vh;
}

.mobile-bar,
.scrim {
  display: none;
}

/* Quiet linen; the only highlight is the section you're in. */
.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  padding: var(--space-6) var(--space-4) var(--space-4);
  overflow-x: hidden;
  overflow-y: auto;
  background: var(--cream-2);
  box-shadow: inset -1px 0 0 rgba(44, 44, 42, 0.06);
}

/* Icons sit 12px inside each row; labels start 12px after them. */
.sidebar-brand {
  align-self: flex-start;
  margin: 0 var(--space-3) var(--space-6);
  font-size: 1.75rem;
}

.sidebar nav {
  margin-bottom: var(--space-5);
}

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

.nav a,
.sidebar-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 40px;
  padding: 0 var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--ink-mid);
  font-weight: 500;
  text-decoration: none;
  transition: background-color 120ms ease, color 120ms ease;
}

.nav a {
  margin-bottom: 2px;
}

.nav .icon,
.sidebar-link .icon {
  width: 18px;
  height: 18px;
  color: var(--ink-dim);
  transition: color 120ms ease;
}

.nav a:hover,
.sidebar-link:hover {
  background: rgba(253, 250, 245, 0.45);
  color: var(--ink);
  text-decoration: none;
}

.nav a:hover .icon,
.sidebar-link:hover .icon {
  color: var(--ink-mid);
}

/* The section you're in: a flat lighter ground and the icon in teal. */
.nav a[aria-current="page"] {
  background: rgba(253, 250, 245, 0.8);
  color: var(--ink);
  font-weight: 600;
}

.nav a[aria-current="page"] .icon {
  color: var(--teal);
}

/* Admins' own pages, under the organization's word. */
.nav-section {
  margin: var(--space-5) 0 var(--space-2);
  padding: 0 var(--space-3);
  color: var(--ink-dim);
  font-size: var(--text-2xs);
  font-weight: 600;
  letter-spacing: 0.12em;
  line-height: var(--leading-small);
  text-transform: uppercase;
}

.nav-count {
  min-width: 22px;
  margin-left: auto;
  padding: 0 7px;
  border-radius: 999px;
  background: rgba(200, 168, 122, 0.3);
  color: var(--warning-ink);
  font-size: var(--text-xs);
  font-weight: 600;
  line-height: 20px;
  text-align: center;
}

/* The foot: Help, then the organization and the person signed in. The
   organization's initial, on the sage-to-teal mark, is centred under the
   section icons. */
.sidebar-foot {
  display: grid;
  gap: 2px;
  margin-top: auto;
  padding-top: var(--space-3);
  border-top: 1px solid var(--line);
}

.org-mark {
  display: inline-grid;
  flex: none;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(150deg, var(--sage) 0%, var(--teal) 55%, var(--teal-dark) 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25);
  color: var(--white);
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 500;
  line-height: 1;
}

.org-mark-small {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  font-size: 1rem;
}

.account-menu {
  position: relative;
}

.account-menu summary {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: var(--space-2) 6px var(--space-2) 5px;
  border-radius: var(--radius-sm);
  color: var(--ink);
  list-style: none;
  cursor: pointer;
  transition: background-color 120ms ease;
}

.account-menu summary:hover,
.account-menu[open] summary {
  background: rgba(253, 250, 245, 0.45);
}

.account-menu summary .org-mark {
  width: 32px;
  height: 32px;
  font-size: 1.1875rem;
}

.account-menu summary::-webkit-details-marker {
  display: none;
}

.account-text {
  display: grid;
  min-width: 0;
}

.org-role,
.account-who strong,
.account-email {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* A long organization name takes a second line rather than an ellipsis. */
.org-name {
  display: -webkit-box;
  overflow: hidden;
  font-weight: 600;
  line-height: var(--leading-heading);
  overflow-wrap: anywhere;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.org-role {
  color: var(--ink-mid);
  font-size: var(--text-xs);
  line-height: var(--leading-small);
}

.account-chevron {
  flex: none;
  width: 14px;
  height: 14px;
  margin-left: auto;
  color: var(--ink-dim);
}

/* Opens upward from the foot, as wide as the sidebar: anything wider would
   be clipped by the sidebar's scrolling. */
.account-panel {
  position: absolute;
  bottom: calc(100% + var(--space-2));
  left: 0;
  right: 0;
  z-index: 10;
  display: grid;
  gap: 2px;
  padding: var(--space-2);
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  box-shadow: 0 12px 32px rgba(44, 44, 42, 0.14);
}

.account-panel form {
  margin: 0;
}

.account-who {
  display: grid;
  margin-bottom: var(--space-1);
  padding: var(--space-2) var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--line);
}

.account-who strong {
  font-weight: 600;
  line-height: var(--leading-heading);
}

.account-email {
  color: var(--ink-mid);
  font-size: var(--text-xs);
  line-height: var(--leading-small);
}

.account-label {
  margin: var(--space-2) var(--space-2) var(--space-1);
  color: var(--ink-dim);
  font-size: var(--text-2xs);
  font-weight: 600;
  letter-spacing: 0.12em;
  line-height: var(--leading-small);
  text-transform: uppercase;
}

.account-rule {
  margin: var(--space-1) 0;
  border: 0;
  border-top: 1px solid var(--line);
}

.menu-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  min-height: 40px;
  padding: 0 var(--space-2);
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--ink);
  font: inherit;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.menu-item:hover {
  background: var(--cream);
  color: var(--ink);
  text-decoration: none;
}

.menu-item .icon {
  width: 18px;
  height: 18px;
  color: var(--ink-mid);
}

.org-option[aria-current="true"] {
  font-weight: 600;
}

.org-option-name {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}

.org-check {
  width: 16px;
  height: 16px;
  color: var(--teal);
}

.main {
  min-width: 0;
}

.content {
  width: 100%;
  max-width: 1160px;
  padding: var(--space-6) var(--space-6) var(--space-7);
}

@media (max-width: 900px) {
  .shell {
    display: block;
  }

  /* Menu on the left, the mark in the middle. */
  .mobile-bar {
    position: sticky;
    top: 0;
    z-index: 15;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    height: 60px;
    padding: 0 var(--space-4);
    background: var(--cream);
    border-bottom: 1px solid var(--line);
  }

  .mobile-bar .wordmark {
    margin: 0;
    font-size: 1.5rem;
  }

  .menu-button {
    display: inline-flex;
    align-items: center;
    justify-self: start;
    gap: var(--space-3);
    min-height: 44px;
    margin-left: calc(-1 * var(--space-3));
    padding: 0 var(--space-3);
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--ink);
    font: inherit;
    font-size: var(--text-sm);
    font-weight: 600;
    cursor: pointer;
  }

  .menu-button:hover {
    background: var(--cream-2);
  }

  /* Three lines: the span is the middle one. */
  .menu-icon,
  .menu-icon::before,
  .menu-icon::after {
    display: block;
    width: 18px;
    height: 2px;
    border-radius: 1px;
    background: currentColor;
  }

  .menu-icon {
    position: relative;
  }

  .menu-icon::before,
  .menu-icon::after {
    content: "";
    position: absolute;
    left: 0;
  }

  .menu-icon::before {
    top: -6px;
  }

  .menu-icon::after {
    top: 6px;
  }

  /* Closed, the drawer is out of view and out of the tab order. */
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 30;
    width: min(300px, 86vw);
    height: auto;
    padding-top: var(--space-5);
    visibility: hidden;
    transform: translateX(-100%);
    transition: transform 200ms ease, visibility 0s linear 200ms;
  }

  .sidebar.is-open {
    visibility: visible;
    transform: none;
    box-shadow: 0 0 32px rgba(44, 44, 42, 0.18);
    transition: transform 200ms ease;
  }

  .scrim {
    position: fixed;
    inset: 0;
    z-index: 25;
    display: block;
    background: rgba(44, 44, 42, 0.32);
  }

  .content {
    padding: var(--space-5) var(--space-4) var(--space-6);
  }
}

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