/* App shell (src/shell.js): app bar, side menu, phone drawer, Home.
   Theme tokens only (docs/theme.md). Light by default; data-theme on <html>. */
:root {
  --appbar-h: calc(56px + env(safe-area-inset-top));
  --nav-w: 248px;
  --page-gutter: 40px;
}

/* ── app bar ── */
.appbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 50;
  height: var(--appbar-h); padding: env(safe-area-inset-top) 8px 0 8px;
  display: flex; align-items: center; gap: 4px;
  background: var(--md-sys-color-surface-container-lowest);
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
}
.appbar .brand { color: var(--md-sys-color-primary); text-decoration: none; padding: 0 8px; }
.has-shell #app-screen { padding-top: var(--appbar-h); }
.has-shell .dropdown { z-index: 55; top: calc(var(--appbar-h) + 4px); }

/* ── side menu ── */
.sidenav {
  position: fixed; top: var(--appbar-h); bottom: 0; left: 0; width: var(--nav-w); z-index: 45;
  display: flex; flex-direction: column; gap: 2px; padding: 12px 10px calc(12px + env(safe-area-inset-bottom));
  background: var(--md-sys-color-surface-container-lowest);
  border-right: 1px solid var(--md-sys-color-outline-variant); overflow-y: auto;
}
.nav-item {
  position: relative; display: flex; align-items: center; gap: 14px; width: 100%;
  min-height: 48px; padding: 0 14px; border: 0; border-radius: var(--md-sys-shape-corner-full, 999px);
  background: transparent; color: var(--md-sys-color-on-surface-variant);
  font: 500 15px/1.2 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  text-decoration: none; text-align: left; cursor: pointer;
}
.nav-item svg { flex: none; width: 22px; height: 22px; }
.nav-item:hover { background: var(--md-sys-color-surface-container); color: var(--md-sys-color-on-surface); }
.nav-item.is-active { background: var(--md-sys-color-secondary-container); color: var(--md-sys-color-on-secondary-container); }
.nav-item:focus-visible { outline: 2px solid var(--md-sys-color-primary); outline-offset: -2px; }
.nav-item .badge-count { position: static; display: inline-flex; margin-left: auto; }
.nav-item .badge-count:empty { display: none; }
.nav-sep { height: 1px; margin: 8px 6px; background: var(--md-sys-color-outline-variant); }
.nav-label { margin: 4px 14px 2px; font-size: 12px; font-weight: 600; letter-spacing: .4px; text-transform: uppercase;
  color: var(--md-sys-color-on-surface-variant); }
.nav-fold > summary { list-style: none; }
.nav-fold > summary::-webkit-details-marker { display: none; }
.nav-fold-chevron { margin-left: auto; transition: transform .15s; }
.nav-fold[open] .nav-fold-chevron { transform: rotate(180deg); }
.nav-fold a.nav-item, .nav-fold button.nav-item { min-height: 40px; padding-left: 22px; font-size: 14px; }
.nav-fold a.nav-item svg, .nav-fold button.nav-item svg { width: 18px; height: 18px; }
.nav-fold .nav-label { margin: 8px 22px 2px; }
.nav-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding-top: 12px;
  border-top: 1px solid var(--md-sys-color-outline-variant); }
.nav-foot .user-chip { margin: 0 6px; flex-wrap: wrap; color: var(--md-sys-color-on-surface); }
.nav-theme { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 0 6px;
  font-size: 13px; color: var(--md-sys-color-on-surface-variant); }
.theme-seg { display: inline-flex; padding: 2px; gap: 2px; border-radius: 999px;
  border: 1px solid var(--md-sys-color-outline-variant); }
.theme-seg button { border: 0; border-radius: 999px; padding: 4px 10px; min-height: 28px; cursor: pointer;
  background: transparent; color: var(--md-sys-color-on-surface-variant); font: 500 12px/1 system-ui, -apple-system, sans-serif; }
.theme-seg button:hover { color: var(--md-sys-color-on-surface); }
.theme-seg button[aria-pressed="true"] { background: var(--md-sys-color-secondary-container); color: var(--md-sys-color-on-secondary-container); }
.theme-seg button:focus-visible { outline: 2px solid var(--md-sys-color-primary); outline-offset: 1px; }
.nav-version { margin: 0 8px; }
.nav-toggle { display: none; }
.nav-scrim { position: fixed; inset: 0; z-index: 58; background: var(--md-sys-color-scrim); }

/* Desktop: the menu sits beside everything. */
@media (min-width: 961px) {
  .has-shell #app-screen { padding-left: var(--nav-w); }
  .has-shell .hb { top: var(--appbar-h); left: var(--nav-w); }
}
/* Desktop: pages start at the left with room off the menu, not centered. */
@media screen and (min-width: 961px) {
  .has-shell .home-wrap, .has-shell .hb-wrap, .has-shell .m3-content, .has-shell .board { margin-left: 0; padding-left: var(--page-gutter); }
  .has-shell .surfacebar, .has-shell .toolbar, .has-shell .hb-head, .has-shell .hb-tabs,
  .has-shell .m3-top-app-bar, .has-shell .trn-tabs { padding-left: var(--page-gutter); padding-right: var(--page-gutter); }
  /* Pages fill the window. The one-at-a-time approval page and the new-doc form keep a comfortable width. */
  .has-shell .home-wrap, .has-shell .hb-wrap:not(.hb-approve-page, .hb-wf-new),
  .has-shell .m3-content:not(.m3-content--narrow), .has-shell .td, .has-shell .board { max-width: none; padding-right: var(--page-gutter); }
}
/* Phones and tablets: ☰ slides the menu in over the page. */
@media (max-width: 960px) {
  .nav-toggle { display: inline-flex; }
  .sidenav {
    top: 0; z-index: 60; width: min(300px, 86vw); padding-top: calc(16px + env(safe-area-inset-top));
    transform: translateX(-100%); transition: transform .2s ease; box-shadow: none;
  }
  body.nav-open .sidenav { transform: none; box-shadow: var(--e3); }
  .has-shell .hb { top: var(--appbar-h); }
}
@media (prefers-reduced-motion: reduce) { .sidenav { transition: none; } }

/* Pages that used to sit under the old top bar. */
.has-shell .surfacebar { top: var(--appbar-h); }
.has-shell .toolbar { top: calc(var(--appbar-h) + 54px); }
/* Pages under the app bar don't need room for the phone's status bar: the app
   bar already took it. Their headers were built for full screen. */
.has-shell .hb .hb-head { padding-top: 8px; }
.has-shell .hb .m3-top-app-bar { height: 56px; padding-top: 0; }
.has-shell #training .m3-top-app-bar:has(.trn-head-actions) { min-height: 56px; }
.has-shell .trn-tabs { top: 56px; }
/* With the menu always there, a page's own Close button just goes Home. */
.has-shell .hb [data-act="close"], .has-shell .hb [data-act="trn-close"], .has-shell .hb [data-act="td-close"] { display: none; }

/* ── Home ── */
.home { min-height: calc(100dvh - var(--appbar-h)); }
.home-wrap { max-width: 1040px; margin: 0 auto; padding: 20px 16px calc(40px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 18px; }
.home-hello { margin: 4px 0 0; font-size: 26px; font-weight: 600; color: var(--md-sys-color-on-surface); }
.home-links { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.home-link {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; padding: 10px 4px;
  border-radius: var(--md-sys-shape-corner-medium, 12px); text-decoration: none;
  background: var(--md-sys-color-primary-container); color: var(--md-sys-color-on-primary-container);
  font-weight: 600; font-size: 13px; min-height: 64px;
}
.home-link:hover { filter: brightness(.97); }
.home-link:focus-visible { outline: 2px solid var(--md-sys-color-primary); outline-offset: 2px; }
.home-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr)); gap: 16px; align-items: start; }
.home-card { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.home-card[hidden] { display: none; }
.home-card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.home-card-head .m3-card-title { margin: 0; }
.home-more { font-size: 13px; font-weight: 500; color: var(--md-sys-color-primary); text-decoration: none; white-space: nowrap; }
.home-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.home-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%;
  padding: 10px 2px; border: 0; border-top: 1px solid var(--md-sys-color-outline-variant);
  background: none; color: var(--md-sys-color-on-surface); font: inherit; text-align: left; text-decoration: none; cursor: pointer;
}
.home-list li:first-child .home-row { border-top: 0; }
.home-row:hover .home-row-title { color: var(--md-sys-color-primary); }
.home-row-title { min-width: 0; font-weight: 500; }
.home-now { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px;
  color: var(--md-sys-color-primary); margin-right: 4px; }
.home-due { flex: none; font-size: 12px; color: var(--md-sys-color-on-surface-variant); white-space: nowrap; }
.home-due.is-late { color: var(--md-sys-color-error); font-weight: 600; }
.home-stats { display: flex; gap: 12px; flex-wrap: wrap; }
.home-stat { flex: 1 1 90px; padding: 10px 12px; border-radius: var(--md-sys-shape-corner-medium, 12px);
  background: var(--md-sys-color-surface-container); }
.home-stat-n { font-size: 26px; font-weight: 600; color: var(--md-sys-color-on-surface); }
.home-stat-l { font-size: 12px; color: var(--md-sys-color-on-surface-variant); }
.home-stat.is-late .home-stat-n { color: var(--md-sys-color-error); }

@media print { .appbar, .sidenav, .nav-scrim { display: none !important; } }
.home-tool svg { flex: none; width: 18px; height: 18px; color: var(--md-sys-color-on-surface-variant); }
.home-tool-note { display: block; font-size: 13px; font-weight: 400; color: var(--md-sys-color-on-surface-variant); }
.home-card:has(> .home-oneline) { padding-top: 6px; padding-bottom: 6px; }
.home-oneline { border-top: 0; }
