/* ==========================================================================
   SIDE MENU - built by js/shell/nav.js from GET /api/nav.

   Wide screens (700px and up): a 76px icon rail. .nav-open (hover, focus or
   a tap) widens it to 236px over the page; .nav-pinned keeps it at 236px and
   moves the page over to make room. Phones: a drawer (.nav-drawer) opened
   from the top bar's menu button, plus the bottom tab bar.

   Each module sets --mod, --mod-text, --mod-soft, --mod-fill, --on-mod on
   its own element (its theme colour slot), so badges and the open tab's
   bar wear the module's colour.

   Settings > Appearance options, as attributes on <html>:
     data-nav-heading  large | medium | same    module heading size
     data-nav-tab      bar | bold | highlight   how the open tab is marked
   ========================================================================== */
:root {
  --rail-w: 76px;
  --menu-w: 236px;
  --menu-ease: 200ms ease;
  --nav-heading: 15px;
}
:root[data-nav-heading='medium'] { --nav-heading: 14px; }
:root[data-nav-heading='same']   { --nav-heading: 13.5px; }

/* --- The panel ------------------------------------------------------------- */
.sidebar {
  position: fixed; z-index: 50; left: 0; top: var(--decor-strip, 0px); bottom: 0;
  width: var(--menu-w); display: flex; flex-direction: column;
  background: var(--panel); border-right: 1px solid var(--line);
  overflow: hidden;
}
.sb-head { display: flex; align-items: center; gap: 6px; padding: 16px 12px 12px 18px; min-height: 72px; }
.sb-head .brandmark { flex: 1; min-width: 0; }
.sb-head .brandmark .bm-name { font-size: 15px; white-space: normal; }   /* a long name wraps rather than hiding under the pin */
.sb-pin { flex: none; }
.sb-pin[aria-pressed='true'] { color: var(--brand-quiet); background: var(--brand-wash); }
.sb-pin svg { width: 18px; height: 18px; }

.sb-nav { flex: 1 1 auto; min-height: 0; overflow-y: auto; overflow-x: hidden; padding: 0 12px 10px; display: flex; flex-direction: column; scrollbar-width: thin; }
.sb-group { display: flex; flex-direction: column; gap: 2px; }
.sb-top { padding-bottom: 6px; }

/* Shared row: an icon slot of rail width, then the label. */
.sb-item, .sb-mod-head, .sb-tab {
  position: relative; display: flex; align-items: center; gap: 12px; width: 100%;
  min-height: var(--touch); padding: 0 10px 0 0; border: 0; border-radius: var(--radius-sm);
  background: none; color: var(--ink2); text-align: left; font: inherit;
}
.sb-item:hover, .sb-mod-head:hover, .sb-tab:hover { background: var(--hover); color: var(--ink); }
.sb-ico { position: relative; flex: none; width: 40px; height: 40px; margin-left: 6px; display: grid; place-items: center; }
.sb-ico svg { width: 21px; height: 21px; }
.sb-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-item .sb-label { font-size: 14px; font-weight: 500; }
.sb-item[aria-current='page'], .sb-item.is-current { color: var(--ink); background: var(--hover); }
.sb-item[aria-current='page'] .sb-label, .sb-item.is-current .sb-label { font-weight: 600; }
.sb-item.is-current .sb-ico { color: var(--mod-text); }

/* Count badges: on the icon in the rail, at the end of the row when open. */
.sb-ico .badge, .sb-tab .badge, .sb-ib .badge {
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--warn-fill); color: var(--on-warn);
  font-family: var(--font-mono); font-size: 10.5px; font-weight: 700; line-height: 18px; text-align: center;
}
.sb-ico .badge { position: absolute; top: 1px; right: -2px; box-shadow: 0 0 0 2px var(--panel); }
.sb-tab .badge { margin-left: auto; }
.sb-ib .badge { position: absolute; top: 2px; right: 0; box-shadow: 0 0 0 2px var(--panel); }

/* --- A module: heading with its badge, tabs on a guide line --------------- */
.sb-mod { padding: 8px 0; border-top: 1px solid var(--line); }
.sb-sections .sb-mod:first-child { border-top-color: transparent; }
.sb-mod-row { display: flex; align-items: center; gap: 2px; }
.sb-mod-head { min-height: 44px; color: var(--ink); flex: 1; min-width: 0; }
.sb-fold {
  flex: none; width: 36px; height: 36px; display: grid; place-items: center; padding: 0;
  border: 0; border-radius: var(--radius-sm); background: none; color: var(--muted); cursor: pointer;
}
.sb-fold:hover { background: var(--hover); color: var(--ink); }
.sb-fold svg { width: 16px; height: 16px; transition: transform var(--menu-ease); }
.sb-mod.is-folded .sb-fold svg { transform: rotate(-90deg); }
/* Folded: only the open tab (if it is in this module) stays. */
.sb-mod.is-folded .sb-tab:not([aria-current='page']) { display: none; }
.sb-mod.is-folded .sb-tabs:not(:has([aria-current='page'])) { display: none; }
.sb-badge {
  flex: none; width: 32px; height: 32px; margin-left: 10px; border-radius: 50%;
  display: grid; place-items: center; border: 2px solid var(--mod); color: var(--mod-text); background: var(--panel);
  font-family: var(--font-heading); font-weight: 700; font-size: 11.5px; letter-spacing: .02em;
  transition: background var(--menu-ease), color var(--menu-ease);
}
.sb-mod-name { font-family: var(--font-heading); font-size: var(--nav-heading); font-weight: 600; letter-spacing: -0.01em; }
.sb-mod.is-current .sb-badge { background: var(--mod-fill); color: var(--on-mod); border-color: var(--mod-fill); }

.sb-tabs { display: flex; flex-direction: column; gap: 1px; margin: 2px 0 2px 25px; padding-left: 12px; border-left: 1.5px solid var(--line); }
.sb-tab { min-height: 34px; padding-left: 12px; color: var(--muted); font-size: 13.5px; }
.sb-tab[aria-current='page'] { color: var(--ink); font-weight: 600; }
/* Open tab style (Settings > Appearance): bold with a colour bar (default), bold only, or a highlight. */
:root:not([data-nav-tab='bold']) .sb-tab[aria-current='page'] { background: color-mix(in srgb, var(--mod-soft) 70%, var(--panel)); }
:root:not([data-nav-tab='highlight']):not([data-nav-tab='bold']) .sb-tab[aria-current='page']::before {
  content: ''; position: absolute; left: -13.5px; top: 7px; bottom: 7px; width: 3px; border-radius: 2px; background: var(--mod);
}

/* --- Footer: one row of icons --------------------------------------------- */
/* Inbox, Settings, light/dark, theme (admins) and the person's initials. The
   palette and the initials open a small menu (.sb-pop) above the row. */
.sb-foot { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 2px; padding: 10px 8px 12px; border-top: 1px solid var(--line); }
.sb-icons { display: contents; }
.sb-ib {
  position: relative; flex: none; width: 40px; height: 40px; padding: 0; display: grid; place-items: center;
  border: 0; border-radius: var(--radius-sm); background: none; color: var(--muted); cursor: pointer;
}
.sb-ib:hover, .sb-ib[aria-expanded='true'] { background: var(--hover); color: var(--ink); }
.sb-ib.is-current, .sb-ib[aria-current='page'] { background: var(--brand-wash); color: var(--brand-quiet); }
.sb-ib svg { width: 21px; height: 21px; }
.sb-ib .avatar, .sb-who .avatar {
  width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  background: var(--brand-wash); color: var(--brand-quiet); font-family: var(--font-heading); font-weight: 700; font-size: 12.5px;
}
.sb-me:hover, .sb-me[aria-expanded='true'] { background: none; }
.sb-me[aria-expanded='true'] .avatar, .sb-me:hover .avatar { box-shadow: 0 0 0 2px var(--brand); }
.sb-pop { left: 8px; right: 8px; top: auto; bottom: 66px; min-width: 0; z-index: 2; }
.sb-pop-head { padding: 6px 10px 4px; color: var(--muted); font-size: 12px; }
.sb-pop-note { padding: 6px 10px 8px; color: var(--muted); font-size: 13px; }
.sb-pop button svg { width: 17px; height: 17px; color: var(--muted); flex: none; }
.sb-pop .sb-tick { margin-left: auto; color: var(--brand); }
.sb-sw { width: 15px; height: 15px; border-radius: 50%; flex: none; border: 1px solid var(--line); }
.sb-who { display: flex; align-items: center; gap: 10px; padding: 6px 8px 4px; }
.sb-who-text { min-width: 0; display: flex; flex-direction: column; }
.sb-who .u-name { font-weight: 600; font-size: 13.5px; line-height: 1.2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-who .u-role { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; }

/* --- Settings' own sub-menu inside the page ------------------------------- */
.subnav { display: flex; gap: 6px; overflow-x: auto; padding: 12px 14px 0; scrollbar-width: thin; }
.subnav-title { display: none; }
.subnav-link {
  flex: none; display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 99px; background: var(--panel); color: var(--ink2); font: inherit; font-size: 13.5px; font-weight: 500;
}
.subnav-link svg { width: 17px; height: 17px; }
.subnav-link[aria-current='page'] { border-color: var(--ink); color: var(--ink); font-weight: 700; }
.subnav-link .badge { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--warn-fill); color: var(--on-warn); font-family: var(--font-mono); font-size: 10.5px; line-height: 18px; }

/* --- Phones: a drawer ------------------------------------------------------ */
.sb-scrim { display: none; }
@media (max-width: 699px) {
  .sidebar { width: min(300px, 86vw); transform: translateX(-102%); transition: transform var(--menu-ease); box-shadow: none; }
  .app.nav-drawer .sidebar { transform: none; box-shadow: var(--shadow-pop); }
  .app.nav-drawer .sb-scrim { display: block; position: fixed; inset: 0; z-index: 45; background: var(--scrim); }
  .sb-pin { display: none; }
  .topbar .brandmark { flex: 1; }
}

/* --- Wide screens: the rail ------------------------------------------------ */
@media (min-width: 700px) {
  .app { padding-left: var(--rail-w); }
  .app.nav-pinned { padding-left: var(--menu-w); }
  .topbar, .tabbar { display: none; }
  .main { padding-bottom: 32px; }
  .view { padding: 26px 28px 8px; }
  .view-head h1 { font-size: 26px; }

  .sidebar { transition: width var(--menu-ease), box-shadow var(--menu-ease); }
  .app.nav-rail .sidebar { width: var(--rail-w); }
  .app.nav-rail.nav-open .sidebar { width: var(--menu-w); box-shadow: var(--shadow-pop); }

  /* Folded: icons only. Hidden labels and tabs leave the tab order too. */
  .sb-label, .sb-pin, .sb-head .bm-text { transition: opacity var(--menu-ease), visibility var(--menu-ease); }
  .app.nav-rail:not(.nav-open) :is(.sb-label, .sb-pin, .sb-head .bm-text) { opacity: 0; visibility: hidden; }
  .app.nav-rail:not(.nav-open) :is(.sb-tabs, .sb-fold, .sb-pop) { display: none; }
  .app.nav-rail:not(.nav-open) .sb-head { padding-left: 18px; }
  /* Folded footer: just the Inbox bell and the initials, stacked. */
  .app.nav-rail:not(.nav-open) .sb-foot { flex-direction: column; justify-content: flex-start; padding: 8px 0 12px; }
  .app.nav-rail:not(.nav-open) .sb-foot .sb-ib:not([data-mod-item='inbox'], .sb-me) { display: none; }
  .app.nav-rail:not(.nav-open) .sb-mod { padding: 4px 0; }
  .app.nav-rail:not(.nav-open) .sb-nav { overflow-y: hidden; }

  /* Settings pages: the sub-menu as a column on the left. */
  .main.has-subnav { display: grid; grid-template-columns: 210px minmax(0, 1fr); align-items: start; }
  .main.has-subnav > .view { grid-column: 2; grid-row: 1; }
  .subnav {
    grid-column: 1; grid-row: 1; position: sticky; top: var(--decor-strip, 0px);
    flex-direction: column; gap: 2px; overflow: visible; padding: 26px 0 16px 18px;
  }
  .subnav-title { display: block; padding: 0 12px 10px; font-family: var(--font-display); font-size: 19px; font-weight: 600; }
  .subnav-link { border: 0; border-radius: var(--radius-sm); background: none; padding: 0 12px; min-height: 40px; }
  .subnav-link:hover { background: var(--hover); color: var(--ink); }
  .subnav-link[aria-current='page'] { background: var(--panel); color: var(--ink); box-shadow: inset 3px 0 0 var(--ink), var(--shadow-card); }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar, .sb-label, .sb-pin, .sb-head .bm-text, .sb-badge, .sb-fold svg { transition: none !important; }
}

/* --- Sheets: section label (phone "More") ---------------------------------- */
.sheet-label {
  padding: 8px 10px 4px; color: var(--muted);
  font-size: 11px; font-weight: 700; letter-spacing: 0.09em; text-transform: uppercase;
}
.sheet-list button[aria-current='true'] { background: var(--brand-wash); color: var(--brand-quiet); font-weight: 600; }
.sheet-list button[aria-current='true'] svg { color: var(--brand-quiet); }

/* Generic view body for module pages that build their own section. */
.vh-actions { display: flex; gap: 9px; flex-wrap: wrap; }
.vh-actions:empty { display: none; }
