/* CR-646: the site menu and the shell around it (ui.js UI.sidebar, sidebar.js). It uses app.css's tokens. Every signed-in pilot has it (CR-653): the .shell,
   .sidebar and .menu-* parts are added to the page by sidebar.js. Signed-out and link pages have no menu.
   Direction A (step 10): from the top, Beacon and the fold button, the group switcher, the open group's rows under task headings, You, Beacon (site
   admins), and at the foot the account row with Tour, Terms and Privacy as small links. Two levels only: a heading and its rows.
   Wide screens (901px and up): the menu is a column beside the page, 260px wide, or a 56px rail of icons when folded, and the page has no header.
   A phone (900px and down): the menu is a drawer behind a Menu button in one slim bar at the top of the page (Menu, the brand, the pilot's initial),
   the account tools drop down from that bar, and buttons, tabs and links are 44px high (CR-646 step 8). The number 900px is also PHONE in sidebar.js. */

/* ---------------------------------------------------------------- the shell */

.shell, header.top.has-menu { --menu-strip-height: 56px; }
.shell { --menu-width: 260px; display: grid; grid-template-columns: var(--menu-width) minmax(0, 1fr); align-items: start; }
.shell.folded { --menu-width: 56px; }
.shell-body { min-width: 0; }
.menu-strip, .menu-button, .account-button, .menu-account { display: none; }

/* No header on a wide screen while the menu is on: the menu has the brand, the account and the small links. */
@media (min-width: 901px) {
  header.top.has-menu { display: none; }
}

/* The debug links at the foot of a page go with the header. An officer keeps the group's, as an officer has no Settings to find it in. */
.shell .dbg-link { display: none; }
.shell.keeps-debug .dbg-link { display: block; }

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

.sidebar { position: sticky; top: 0; align-self: start; height: 100vh; height: 100dvh; z-index: var(--layer-raised); min-width: 0; }
/* A cue that the menu scrolls: a soft shadow shows at an edge while there is more beyond it (the covers scroll with the content and hide it at the end). */
.sidebar-panel {
  display: flex; flex-direction: column; height: 100%; overflow-y: auto; overscroll-behavior: contain;
  background:
    linear-gradient(var(--surface) 30%, transparent) top / 100% 24px local no-repeat,
    linear-gradient(transparent, var(--surface) 70%) bottom / 100% 24px local no-repeat,
    radial-gradient(farthest-side at 50% 0, var(--line-strong), transparent) top / 100% 10px scroll no-repeat,
    radial-gradient(farthest-side at 50% 100%, var(--line-strong), transparent) bottom / 100% 10px scroll no-repeat,
    var(--surface); border-right: 1px solid var(--line); padding: var(--s2) 0 var(--s3);
}
.sidebar-panel:focus { outline: none; }
.sidebar ul { list-style: none; margin: 0; padding: 0; }
.sidebar-bar { display: flex; align-items: center; gap: var(--s1); padding: 0 var(--s2) 0 var(--s4); }
.sidebar-brand {
  display: inline-flex; align-items: center; min-height: 36px; margin-right: auto; color: var(--fg); font-size: var(--text-lg); font-weight: 700; text-decoration: none;
}
.sidebar-fold, .sidebar-close {
  display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; padding: 0; border: 0; border-radius: var(--radius);
  background: transparent; color: var(--muted);
}
.sidebar-fold:hover, .sidebar-close:hover { background: var(--sunk); color: var(--fg); }
.sidebar-close { display: none; }
.sidebar-fold .menu-icon { transition: none; }
.sidebar-heading {
  margin: 0; padding: var(--s3) var(--s4) var(--s1);
}

.sidebar-link {
  position: relative; display: flex; align-items: center; gap: var(--s2); width: 100%; min-height: 40px; padding: var(--s1) var(--s3);
  border: 0; border-left: 3px solid transparent; border-radius: 0; background: transparent; color: var(--fg);
  font: inherit; font-weight: 500; text-align: left; text-decoration: none; cursor: pointer;
}
.sidebar-link:hover { background: var(--sunk); }
.sidebar-link[aria-current="page"] { background: var(--sunk); border-left-color: var(--accent); font-weight: 700; }
.sidebar-link:focus-visible { outline-offset: -2px; }
.sidebar-text { min-width: 0; overflow-wrap: anywhere; }
.sidebar-link > .badge { margin-left: auto; flex: 0 0 auto; }

.sidebar-icon { flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; }
.menu-icon { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
/* A group has no drawing: its icon is its first letter, drawn from data-initial so the words a screen reader reads stay clean. */
.sidebar-initial::before {
  content: attr(data-initial); display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; border-radius: var(--radius-sm);
  background: var(--accent); color: var(--accent-fg); font-size: var(--text-xs); font-weight: 700; line-height: 1;
}

/* ---------------------------------------------------------------- the group switcher */

.sidebar-switch { position: relative; padding: var(--s2) var(--s3) var(--s1); }
.sidebar-switcher {
  display: flex; align-items: center; gap: var(--s2); width: 100%; min-height: 44px; padding: var(--s1) var(--s2);
  border: 1px solid var(--line-strong); border-radius: var(--radius-lg); background: var(--surface); color: var(--fg);
  font: inherit; font-weight: 600; text-align: left;
}
button.sidebar-switcher { cursor: pointer; }
button.sidebar-switcher:hover, button.sidebar-switcher[aria-expanded="true"] { background: var(--sunk); }
.sidebar-switcher-plain { border-color: transparent; }
.sidebar-switcher .sidebar-text { flex: 1 1 auto; }
.sidebar-switcher > .pill, .sidebar-pop-link > .pill { flex: 0 0 auto; font-weight: 400; }
.sidebar-chev { flex: 0 0 auto; display: inline-flex; color: var(--muted); }
.sidebar-chev .menu-icon, .sidebar-tick .menu-icon { width: 16px; height: 16px; }
.sidebar-nogroup { display: flex; align-items: flex-start; gap: var(--s2); padding: var(--s1) var(--s2); }
.sidebar-nogroup > .sidebar-text { display: flex; flex-direction: column; gap: var(--s1); }
.sidebar-nogroup-help { color: var(--muted); font-size: var(--text-sm); }
.sidebar-initial-empty::before { background: var(--sunk); color: var(--muted); }

/* A list that opens from the switcher (under it) or the account row (over it). */
.sidebar-pop {
  position: absolute; left: var(--s3); right: var(--s3); z-index: var(--layer-dropdown); max-height: 70vh; overflow-y: auto; padding: var(--s1) 0;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-lg); box-shadow: var(--shadow-menu);
}
.sidebar-pop[hidden] { display: none; }
.sidebar-groups { top: 100%; }
.sidebar-pop-head {
  margin: 0; padding: var(--s2) var(--s3) var(--s1); color: var(--muted); font-size: var(--text-xs); font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
}
.sidebar-pop-link { display: flex; align-items: center; gap: var(--s2); min-height: 40px; padding: var(--s1) var(--s3); color: var(--fg); text-decoration: none; }
.sidebar-pop-link:hover { background: var(--sunk); }
.sidebar-pop-link[aria-current="true"] { font-weight: 700; }
.sidebar-pop-link .sidebar-text { flex: 1 1 auto; }
.sidebar-tick { flex: 0 0 auto; display: inline-flex; color: var(--accent); }
.sidebar-pop-children .sidebar-pop-link { padding-left: calc(var(--s3) + var(--s5)); }
.sidebar-pop-all { margin-top: var(--s1); border-top: 1px solid var(--line); }

/* ---------------------------------------------------------------- the foot: the account row and the small links */

.sidebar-foot { margin-top: auto; padding: var(--s3) var(--s3) 0; }
.sidebar-account-wrap { position: relative; border-top: 1px solid var(--line); padding-top: var(--s2); }
.sidebar-account {
  display: flex; align-items: center; gap: var(--s2); width: 100%; min-height: 44px; padding: var(--s1) var(--s2); border: 0; border-radius: var(--radius);
  background: transparent; color: var(--fg); font: inherit; font-weight: 600; text-align: left; cursor: pointer;
}
.sidebar-account:hover, .sidebar-account[aria-expanded="true"] { background: var(--sunk); }
.sidebar-account .sidebar-text { flex: 1 1 auto; }
.sidebar-account .sidebar-initial::before, .account-button .sidebar-initial::before { box-sizing: border-box; border-radius: var(--radius-pill); background: var(--sunk); color: var(--fg); border: 1px solid var(--line-strong); }
.sidebar-account-menu { top: auto; bottom: 100%; left: 0; right: 0; padding: var(--s1); }
.sidebar-action {
  display: flex; align-items: center; width: 100%; min-height: 40px; padding: var(--s1) var(--s3); border: 0; border-radius: var(--radius);
  background: transparent; color: var(--fg); font: inherit; text-align: left; text-decoration: none; cursor: pointer;
}
.sidebar-action:hover { background: var(--sunk); }
.sidebar-small { display: flex; flex-wrap: wrap; align-items: center; gap: 0 var(--s3); margin: 0; padding: var(--s2) var(--s2) 0; color: var(--muted); font-size: var(--text-xs); }
.sidebar-small a, .sidebar-small .tour-menu > summary { color: var(--muted); }
.sidebar-small .tour-menu > summary { padding: 0; }
/* The Tour list opens upwards from the foot of the menu. */
.sidebar-small .tour-menu-list { top: auto; bottom: 100%; left: 0; right: auto; width: 228px; font-size: var(--text-md); color: var(--fg); }

/* ---------------------------------------------------------------- a group page: the menu holds its tabs */

.shell.has-sections .room-tabs { display: none; }
/* Bars that stay in view sat under the tab bar; with it gone they sit at the top. */
.shell.has-sections .settings-nav, .shell.has-sections .fo > .note { top: 0; }

/* ---------------------------------------------------------------- the folded rail (wide screens only: a phone's drawer always shows names) */

@media (min-width: 901px) {
  .sidebar.folded .sidebar-bar { justify-content: center; padding: 0; }
  .sidebar.folded .sidebar-brand, .sidebar.folded .sidebar-small, .sidebar.folded .sidebar-chev, .sidebar.folded .sidebar-switcher > .pill { display: none; }
  .sidebar.folded .sidebar-fold .menu-icon { transform: scaleX(-1); }
  .sidebar.folded .sidebar-switch, .sidebar.folded .sidebar-foot { padding-left: var(--s1); padding-right: var(--s1); }
  .sidebar.folded .sidebar-switcher, .sidebar.folded .sidebar-account, .sidebar.folded .sidebar-nogroup { justify-content: center; padding: var(--s1); border-color: transparent; }
  /* The headings are thin rules between the rows. */
  .sidebar.folded .sidebar-heading {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0;
  }
  .sidebar.folded .sidebar-block + .sidebar-block, .sidebar.folded .sidebar-rows + .sidebar-block { border-top: 1px solid var(--line); margin-top: var(--s2); padding-top: var(--s2); }
  .sidebar.folded .sidebar-link { justify-content: center; padding-left: var(--s2); padding-right: var(--s2); }
  /* The words stay in the page for a screen reader. A pointer or the keyboard focus shows them beside the icon. */
  .sidebar.folded .sidebar-link .sidebar-text, .sidebar.folded .sidebar-switcher .sidebar-text, .sidebar.folded .sidebar-account .sidebar-text,
  .sidebar.folded .sidebar-nogroup .sidebar-text {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0;
  }
  .sidebar.folded .sidebar-link:hover .sidebar-text, .sidebar.folded .sidebar-link:focus-visible .sidebar-text,
  .sidebar.folded .sidebar-switcher:not([aria-expanded="true"]):hover .sidebar-text, .sidebar.folded .sidebar-switcher:not([aria-expanded="true"]):focus-visible .sidebar-text,
  .sidebar.folded .sidebar-account:not([aria-expanded="true"]):hover .sidebar-text, .sidebar.folded .sidebar-account:not([aria-expanded="true"]):focus-visible .sidebar-text {
    position: fixed; left: 60px; width: auto; height: auto; margin: 0; padding: var(--s1) var(--s3); clip-path: none; overflow: visible; z-index: var(--layer-dropdown);
    background: var(--surface); color: var(--fg); border: 1px solid var(--line-strong); border-radius: var(--radius); box-shadow: var(--shadow);
    font-weight: 600; pointer-events: none;
  }
  .sidebar.folded .sidebar-link > .badge { position: absolute; top: 0; right: var(--s1); min-width: 16px; height: 16px; padding: 0 var(--s1); margin: 0; }
  /* The lists open beside the rail, where they have room. */
  .sidebar.folded .sidebar-pop { position: fixed; left: 60px; right: auto; width: 260px; }
  .sidebar.folded .sidebar-groups { top: auto; }
  .sidebar.folded .sidebar-account-menu { top: auto; bottom: var(--s2); }
}

/* ---------------------------------------------------------------- a phone: the drawer */

@media (max-width: 900px) {
  .shell { display: block; }
  .shell.folded { --menu-width: 260px; }
  /* CR-681: closed, the drawer is hidden AND moved off the screen, so no engine can leave its header, close button or shadow in view under the top bar
     (it keeps its size, which the tour measures). Open, it covers the whole screen, dynamic toolbar included, above the sticky top bar. */
  .sidebar {
    position: fixed; inset: 0; width: 100%; height: auto; min-height: 100vh; min-height: 100dvh; z-index: var(--layer-overlay); visibility: hidden;
    transform: translate3d(-120%, 0, 0); pointer-events: none; background: var(--backdrop);
  }
  .sidebar.open { visibility: visible; transform: none; pointer-events: auto; }
  .sidebar-panel { width: min(85vw, 320px); max-width: 100%; box-shadow: var(--shadow); }
  .sidebar-bar { padding: var(--s1) var(--s2) var(--s1) var(--s4); }
  .sidebar-brand { min-height: 44px; }
  .sidebar-close { display: inline-flex; width: 44px; height: 44px; }
  .sidebar-fold { display: none; }
  .sidebar-link, .sidebar-pop-link, .sidebar-action { min-height: 44px; }
  .sidebar-small a, .sidebar-small .tour-menu > summary { display: inline-flex; align-items: center; justify-content: center; min-width: 44px; min-height: 44px; }
  body.menu-open { overflow: hidden; }

  .menu-strip {
    position: sticky; top: 0; z-index: var(--layer-sticky); display: flex; align-items: center; height: var(--menu-strip-height);
    padding: 0 var(--s4); background: var(--bg); border-bottom: 1px solid var(--line);
  }
  .menu-button, .account-button { display: inline-flex; align-items: center; gap: var(--s2); min-width: 44px; min-height: 44px; padding: 0 var(--s3); font-weight: 600; }
  .account-button { justify-content: center; padding: 0; }
  .account-button .sidebar-icon { width: 32px; height: 32px; } /* CR-1143: the 32 px avatar fits its box, so it is not clipped */
  .account-button .sidebar-initial::before { width: 32px; height: 32px; font-size: var(--text-sm); }
  /* Bars that stay in view sit under the Menu button, not at the top. */
  .shell .shell-body .settings-nav, .shell .shell-body .dbg-index, .shell.has-sections .fo > .note { top: var(--menu-strip-height); }
}
@media (max-width: 640px) {
  /* tour.css makes the Tour list a sheet across the screen on a phone; from the foot of the drawer it rises from the bottom edge. */
  .sidebar-small .tour-menu-list { position: fixed; left: var(--s2); right: var(--s2); bottom: var(--s2); width: auto; }
}

/* ---------------------------------------------------------------- a phone: the slim bar, the account panel and touch sizes (menu on only)
   Everything here starts at .shell or header.top.has-menu, which are on the page only while the menu is on. With the menu off the phone page is as it was. */

@media (max-width: 900px) {
  /* The page's header is the one slim bar: Menu, the brand, the pilot's initial. It stays in view, and the account tools drop down from it. */
  header.top.has-menu {
    position: sticky; top: 0; z-index: var(--layer-sticky); flex-wrap: nowrap; justify-content: flex-start; gap: var(--s2);
    height: var(--menu-strip-height); padding: 0 var(--s3);
  }
  header.top.has-menu .brand { display: inline-flex; align-items: center; min-height: 44px; padding: 0 var(--s2); }
  header.top.has-menu .account-button { margin-left: auto; }
  header.top.has-menu #who { display: none; }
  header.top.has-menu.account-open .menu-account {
    display: flex; flex-direction: column; flex-wrap: nowrap; align-items: stretch; gap: var(--s1);
    position: absolute; top: 100%; right: 0; width: min(100%, 360px); max-height: calc(100vh - var(--menu-strip-height)); max-height: calc(100dvh - var(--menu-strip-height));
    overflow-y: auto; overscroll-behavior: contain; padding: var(--s2) var(--s3) var(--s3);
    background: var(--surface); border: 1px solid var(--line); border-top: 0; box-shadow: var(--shadow);
  }
  .menu-account .sidebar-action { min-height: 44px; }
  .menu-account-name { margin: 0; padding: var(--s2) var(--s3); font-weight: 700; }

  /* CR-1495: the 44 px touch rows for buttons, folds, link buttons and tick boxes live in app.css under max-width and (pointer: coarse), not on the menu shell. */
  /* "On this page" is a list to read through once, not a bar that follows the page down. */
  .shell .settings-nav { position: static; }

  /* The dashboard's small text is one step larger. */
  .shell-body .dash-top, .shell-body .dash-where, .shell-body .dash-mark { font-size: var(--text-xs); }
  .shell-body .dash-bottom { font-size: var(--text-sm); }
}
@media (max-width: 640px) {
  .shell-body .dash-key, .shell-body .dash-empty, .shell-body .dash-tile, .shell-body .dash-gap { font-size: var(--text-sm); }
}

/* ---------------------------------------------------------------- two columns: they start when the page's column is 1100px wide, not the window */

/* CR-1036: with the menu open the two columns start at 1440px (owner, 3 November); under it they stack. */
@media (min-width: 1100px) and (max-width: 1439px) {
  .shell:not(.folded) .two-col { grid-template-columns: minmax(0, 1fr); }
}


/* ---------------------------------------------------------------- the bands of a long page, under its row (only under the current row) */

.sidebar-parts { list-style: none; margin: 0 0 var(--s2); padding: 0 0 0 var(--s5); }
.sidebar-part { display: block; padding: var(--s1) var(--s3); min-height: 32px; box-sizing: border-box; font-size: var(--text-sm); color: var(--muted); text-decoration: none; border-radius: var(--radius); }
.sidebar-part:hover { color: var(--text); }
.sidebar-part[aria-current="location"] { color: var(--text); font-weight: 700; }
.sidebar.folded .sidebar-parts { display: none; }
@media (max-width: 900px) {
  .sidebar-part { min-height: 44px; display: flex; align-items: center; }
}
