/* Navigation tray, shared by the web app (/assets/tray.css) and the operator console (/static/tray.css); behaviour in
   tray.js. Uses each surface's own tokens (--ink, --paper, --surface, --raised, --line, --muted, --accent, --accent-ink,
   --accent-soft, --radius), so light and dark follow prefers-color-scheme like the rest of the page.
   < 64rem: off-canvas drawer from the left with a scrim (JS), or a :target panel (no JS).
   >= 64rem: the same tray docked beside the content (pushes it over, no scrim); html.tray-closed narrows it to an icon rail
   (--rail-w) with tooltips (JS, remembered). Every target is at least 44px.
   Also here, because every app and console page loads this file: the themed thin scrollbars (--sb-* tokens). */

:root { --tray-w: 16.5rem; --rail-w: 4rem; --top-h: 3.75rem; }
html { scroll-padding-top: calc(var(--top-h) + 0.5rem); }
.tray-sr { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ───────── app bar ───────── */
.appbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 0.5rem; box-sizing: border-box;
  height: var(--top-h); padding: 0 0.75rem; background: var(--appbar-bg, var(--paper)); border-bottom: 1px solid var(--line);
}
.tray-btn {
  display: inline-flex; align-items: center; justify-content: center; flex: none; box-sizing: border-box; width: 44px; height: 44px;
  min-width: 44px; min-height: 44px; margin: 0; padding: 0; border: 1px solid transparent; border-radius: var(--radius); background: transparent;
  color: var(--ink); font: inherit; cursor: pointer; text-decoration: none;
}
.tray-btn:hover { border-color: var(--line); background: var(--surface); }
.tray-btn .icon { width: 22px; height: 22px; }
html.js .tray-btn-link, html:not(.js) [data-tray-toggle], html.js .tray-x-link, html:not(.js) [data-tray-close] { display: none !important; }

/* ───────── drawer (narrow) ───────── */
.shell-main { min-width: 0; }
.tray {
  position: fixed; z-index: 40; top: 0; bottom: 0; left: 0; box-sizing: border-box; width: min(20rem, calc(100vw - 3.5rem));
  display: flex; flex-direction: column; background: var(--tray-bg, var(--paper)); border-right: 1px solid var(--line);
  box-shadow: 0 0 2rem rgb(0 0 0 / 0.28); transform: translateX(-100%); visibility: hidden;
}
html.tray-open .tray, html:not(.js) .tray:target { transform: none; visibility: visible; }
.tray-scrim { position: fixed; inset: 0; z-index: 30; background: rgb(8 12 10 / 0.5); opacity: 0; visibility: hidden; }
html.tray-open .tray-scrim { opacity: 1; visibility: visible; }
html.tray-open, html.tray-open body { overflow: hidden; }
@media (prefers-reduced-motion: no-preference) {
  html.tray-ready .tray { transition: transform 200ms ease, visibility 0s linear 200ms; }
  html.tray-ready.tray-open .tray { transition: transform 200ms ease, visibility 0s; }
  html.tray-ready .tray-scrim { transition: opacity 200ms ease, visibility 0s linear 200ms; }
  html.tray-ready.tray-open .tray-scrim { transition: opacity 200ms ease, visibility 0s; }
  html.tray-ready .shell { transition: grid-template-columns 180ms ease; }
  html.tray-ready .shell::before { transition: width 180ms ease; }
}

.tray-head { display: flex; align-items: center; gap: 0.5rem; box-sizing: border-box; min-height: var(--top-h); padding: 0.375rem 0.5rem 0.375rem 0.75rem; border-bottom: 1px solid var(--line); }
.tray-who { display: flex; align-items: center; gap: 0.6rem; flex: 1 1 auto; min-width: 0; }
.tray-who > .icon { color: var(--muted); flex: none; }
.tray-who-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.tray-who .company { font-weight: 650; font-size: 0.95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tray-who .person { color: var(--muted); font-size: 0.8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.tray-nav { flex: 1 1 auto; overflow-y: auto; overscroll-behavior: contain; padding: 0.25rem 0.5rem 0.75rem; }
.tray-nav ul { list-style: none; margin: 0; padding: 0; }
.tray-group.plain { margin-top: 0.5rem; padding-top: 0.5rem; border-top: 1px solid var(--line); }
.tray-h { display: block; padding: 0.75rem 0.75rem 0.25rem; font-size: 0.72rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.tray-nav a, .tray-act {
  position: relative; display: flex; align-items: center; gap: 0.75rem; box-sizing: border-box; width: 100%; min-height: 44px; margin: 0;
  padding: 0 0.75rem; border: 0; border-radius: 8px; background: transparent; color: var(--ink); font: inherit; font-weight: 550;
  text-align: left; text-decoration: none; cursor: pointer;
}
.tray-nav a:hover, .tray-act:hover { background: var(--surface); color: var(--accent); }
.tray-nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 700; box-shadow: inset 3px 0 0 var(--accent); }
.tray-nav a:focus-visible, .tray-act:focus-visible { outline-offset: -3px; }
.tray-label { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tray-nav .count { flex: none; margin-left: auto; }
.tray-foot { display: flex; flex-direction: column; gap: 0.25rem; padding: 0.5rem; border-top: 1px solid var(--line); }
.tray-foot form { margin: 0; }

/* ───────── docked tray (wide) ───────── */
@media (min-width: 64rem) {
  html:not(.js) .tray-btn-link { display: none !important; }   /* without JS the tray is simply always docked */
  .shell { display: grid; grid-template-columns: var(--tray-w) minmax(0, 1fr); align-items: start; position: relative; min-height: calc(100vh - var(--top-h)); min-height: calc(100dvh - var(--top-h)); }
  /* The tray's column is painted by the shell itself, top to bottom: the docked tray is sticky and only viewport-tall, so on a
     page taller than the window its own background used to stop (FC4.1; seen on a full-page capture of the close dashboard at
     1280). Absolutely positioned, so it takes no grid cell; it follows the column width (tray or rail). */
  .shell::before {
    content: ""; position: absolute; top: 0; bottom: 0; left: 0; z-index: 0; width: var(--tray-w); box-sizing: border-box; pointer-events: none;
    background: var(--tray-bg-wide, var(--surface)); border-right: 1px solid var(--line);
  }
  html.tray-closed .shell::before { width: var(--rail-w); }
  .tray {
    position: sticky; top: var(--top-h); z-index: 10; width: auto; min-width: 0; height: calc(100vh - var(--top-h)); height: calc(100dvh - var(--top-h));
    overflow: hidden; transform: none; visibility: visible; box-shadow: none; background: var(--tray-bg-wide, var(--surface)); transition: none !important;
  }
  .tray > * { min-width: calc(var(--tray-w) - 1px); }   /* the content keeps its width while the column slides */
  .tray-scrim, .tray-x, .tray-x-link { display: none !important; }
  /* Desktop: who is signed in, and where, moves to the app bar (.top-who); the tray starts directly with the nav. The
     drawer on phones keeps its head (operator request 2026-10-11). */
  .tray-head, .tray-foot .tray-switch { display: none; }

  /* Closed: an icon rail. Icons keep their x position (8px nav padding + 12px item padding in both states), so only the
     column width animates. Labels and section headings stay in the accessibility tree (visually hidden); groups get a thin
     divider; the pending count becomes a badge on the icon; tooltips come from tray.js. The left nav padding only, so a
     classic (non-overlay) thin scrollbar still leaves 44px targets. */
  html.tray-closed .shell { grid-template-columns: var(--rail-w) minmax(0, 1fr); }
  html.tray-closed .tray > * { min-width: calc(var(--rail-w) - 1px); }
  html.tray-closed .tray-head, html.tray-closed .tray-h, html.tray-closed .tray-label {
    position: absolute; width: 1px; height: 1px; min-width: 0; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
  }
  html.tray-closed .tray-nav { padding: 0.5rem 0 0.5rem 0.5rem; overflow-x: hidden; scrollbar-gutter: stable; }
  html.tray-closed .tray-group + .tray-group { margin-top: 0.25rem; padding-top: 0.25rem; border-top: 1px solid var(--line); }
  html.tray-closed .tray-group.plain { margin-top: 0.25rem; padding-top: 0.25rem; }
  html.tray-closed .tray-nav a, html.tray-closed .tray-act { min-width: 44px; gap: 0; }
  html.tray-closed .tray-nav .count {
    position: absolute; top: 3px; left: 23px; min-width: 1.125rem; height: 1.125rem; margin: 0; padding: 0 0.25rem; font-size: 0.68rem; line-height: 1;
    box-shadow: 0 0 0 2px var(--tray-bg-wide, var(--surface));
  }
  html.tray-closed .tray-nav a[aria-current="page"] .count { box-shadow: 0 0 0 2px var(--accent-soft); }
  html.tray-closed .tray-foot { padding: 0.5rem; }
}

/* ───────── rail tooltips (tray.js; one shared element appended to <body>) ───────── */
.tray-tip {
  position: fixed; z-index: 60; top: 0; left: 0; max-width: calc(100vw - 1rem); padding: 0.375rem 0.625rem; border-radius: 6px;
  background: var(--ink); color: var(--paper); font-size: 0.85rem; font-weight: 600; line-height: 1.35; white-space: nowrap;
  box-shadow: 0 4px 14px rgb(0 0 0 / 0.22); pointer-events: auto;
}
@media (prefers-reduced-motion: no-preference) {
  .tray-tip { animation: tray-tip-in 120ms ease-out; }
  @keyframes tray-tip-in { from { opacity: 0; transform: translateX(-4px); } to { opacity: 1; transform: none; } }
}

/* ───────── scrollbars (app and console; the marketing site and docs carry the same rules) ─────────
   Thin, a subtle thumb on a transparent track, stronger on hover. Thumb vs. every page/tray/code background is at least
   3:1 in both themes (light #7b8580: 3.8:1 on paper, 3.3:1 on the darkest light surface; dark #6b7671: 3.8:1 on paper,
   3.3:1 on raised). Standard properties for Firefox and Chromium 121+; ::-webkit-scrollbar for Safari and older
   Chromium (Chromium ignores it wherever scrollbar-color applies). Scrolling itself (keys, wheel, touch) is unchanged. */
:root { --sb-thumb: #7b8580; --sb-thumb-hover: #5c6762; --sb-track: transparent; }
@media (prefers-color-scheme: dark) { :root { --sb-thumb: #6b7671; --sb-thumb-hover: #8a9590; } }
html { scrollbar-width: thin; scrollbar-color: var(--sb-thumb) var(--sb-track); }
.tray-nav, pre, .table-scroll, .scroll-x, [data-scroll] { scrollbar-width: thin; }
.tray-nav:hover, pre:hover, .table-scroll:hover, .scroll-x:hover, [data-scroll]:hover { scrollbar-color: var(--sb-thumb-hover) var(--sb-track); }
::-webkit-scrollbar { width: 8px; height: 8px; background: var(--sb-track); }
::-webkit-scrollbar-track, ::-webkit-scrollbar-corner { background: var(--sb-track); }
::-webkit-scrollbar-thumb { background: var(--sb-thumb); background-clip: padding-box; border: 2px solid transparent; border-radius: 8px; min-height: 2rem; }
::-webkit-scrollbar-thumb:hover { background: var(--sb-thumb-hover); background-clip: padding-box; border: 2px solid transparent; }

/* ───────── who is signed in, in the app bar (desktop) ─────────
   Company (or console operator) and person/role beside the logo, with comfortable vertical padding; for a firm member inside
   a client a small disclosure menu (native <details>: a button with expanded state, no script needed) holds Switch client.
   Phones keep the block inside the drawer (.tray-head). */
.top-who { display: none; }
@media (min-width: 64rem) {
  .top-who { display: flex; align-items: center; flex: 0 1 auto; min-width: 0; margin-left: 0.5rem; padding-left: 0.75rem; border-left: 1px solid var(--line); }
}
.who-id { display: flex; align-items: center; gap: 0.6rem; box-sizing: border-box; min-width: 0; min-height: 44px; padding: 0.375rem 0.625rem; border-radius: var(--radius); }
.who-id > .icon { flex: none; color: var(--muted); }
.who-text { display: flex; flex-direction: column; gap: 0.125rem; min-width: 0; line-height: 1.3; }
.who-text .company { font-weight: 650; font-size: 0.95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 22rem; }
.who-text .person { color: var(--muted); font-size: 0.8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 22rem; }
.who-menu { position: relative; min-width: 0; }
.who-menu > summary { list-style: none; cursor: pointer; border: 1px solid transparent; }
.who-menu > summary::-webkit-details-marker { display: none; }
.who-menu > summary:hover, .who-menu[open] > summary { border-color: var(--line); background: var(--surface); }
.who-menu > summary .chev { display: inline-flex; flex: none; color: var(--muted); }
.who-menu > summary .chev .icon { width: 16px; height: 16px; }
.who-menu[open] > summary .chev { transform: rotate(180deg); }
.who-pop { position: absolute; z-index: 30; top: calc(100% + 0.25rem); left: 0; min-width: 14rem; margin: 0; padding: 0.25rem; list-style: none;
  background: var(--raised, var(--paper)); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 0.5rem 1.5rem rgb(0 0 0 / 0.18); }
.who-pop a { display: flex; align-items: center; gap: 0.6rem; min-height: 44px; padding: 0 0.75rem; border-radius: 8px; color: var(--ink); font-weight: 550; text-decoration: none; }
.who-pop a:hover { background: var(--surface); color: var(--accent); }
