/* Lanbrogio — sidebar navigation (app/templates/base.html, app/static/nav.js): the selector «Organization › Project»,
   the project group in runs, collapsible groups, user menu, rail mode (desktop ≥ 1024px), palette button of the top bar.
   Only the variables of app.css: both themes come for free. */

:root { --rail-w: 60px; --z-navpop: 75; }

/* .visually-hidden: defined once with .sr and .sr-only in app.css */

/* ---------- layout of the sidebar: fixed head and foot, scrolling body ---------- */
.sidebar { overflow: visible; padding-bottom: 10px; }
/* the sidebar is sticky (own stacking context): above the page so that its popovers cover the content */
/* the navy column runs to the bottom of long pages (the sidebar itself is sticky, 100vh) */
@media (min-width: 901px) { .shell { background: linear-gradient(90deg, var(--nav-bg) var(--sidebar-w), transparent var(--sidebar-w)); } }
@media (min-width: 1024px) { html.nav-rail .shell { background: linear-gradient(90deg, var(--nav-bg) var(--rail-w), transparent var(--rail-w)); } }
@media (min-width: 901px) {
  .sidebar { z-index: calc(var(--z-sticky) + 5); }
  .topbar .menu-btn { display: none; }   /* .btn (display:inline-flex) came after .menu-btn{display:none} */
}
.sb-head { display: flex; align-items: center; gap: 4px; padding-bottom: 8px; }
.sb-head .brand { padding-bottom: 4px; flex: 1; min-width: 0; }
/* the logo M1 with its white wordmark on the navy sidebar (F-160); the mark alone in rail mode */
.sb-head .brand-logo { display: block; height: 28px; width: auto; }
.sb-head .brand-mark { display: none; }
.rail-btn { display: none; color: var(--muted); }
.rail-btn svg.i { transition: transform .15s ease; }
.sb-body { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; margin: 0 -10px; padding: 0 10px 8px; scrollbar-width: thin; }
.nav a { min-width: 0; }
.nav a .nav-text { overflow: hidden; white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
                   line-height: 1.25; overflow-wrap: break-word; hyphens: auto; }   /* R-153: two lines instead of «Conformità ed esposiz…» */
/* 2.3.2 (u1, A10/232:D12): a long word goes to the next line with a hyphen in the language of the page («Organisations-
   einstellungen»), not cut anywhere; break-word only for a word the dictionary cannot split */

/* ---------- the selector «Organization › Project» (2.3.2, u1: one selector instead of two) ---------- */
.psw { position: relative; margin: 6px 0 4px; }
.osw-opt { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.3; }
.osw-role { font-size: var(--fs-2xs); color: var(--muted); font-weight: var(--fw-medium); }
.psw-btn { display: flex; align-items: center; gap: 9px; width: 100%; min-height: 44px; padding: 5px 8px 5px 10px; text-align: left;
           background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r); color: var(--text); font: inherit; cursor: pointer; }
.psw-btn:hover { border-color: var(--border-strong); }
.psw.is-open .psw-btn { border-color: var(--focus); }
.psw-ic { position: relative; display: inline-flex; color: var(--muted); flex: none; }
.psw-ic .dot { position: absolute; right: -3px; bottom: -2px; width: 7px; height: 7px; box-shadow: 0 0 0 2px var(--surface-2); }
.psw-main { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.25; }
.psw-k { font-size: var(--fs-2xs); text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: var(--fw-semi);
         display: flex; align-items: center; gap: 6px; }
.psw-k .badge { text-transform: none; letter-spacing: 0; height: 16px; font-size: var(--fs-2xs); flex: none; }
/* 2.3.2 (u1): the organization small (its name as written), the project large; «ORGANIZATION»/«PROJECT» as a kind */
.psw-k:not(.is-kind) { text-transform: none; letter-spacing: 0; font-size: var(--fs-xs); font-weight: var(--fw-medium); }
.psw-k > .truncate { min-width: 0; }
.psw-name { font-weight: var(--fw-semi); }
.psw-chev { color: var(--muted); display: inline-flex; transform: rotate(90deg); transition: transform .15s ease; }
.psw.is-open .psw-chev { transform: rotate(-90deg); }

.psw-pop, .umenu-pop {
  position: absolute; z-index: var(--z-navpop); background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--r); box-shadow: var(--shadow-lg); padding: 6px;
}
.psw-pop[hidden], .umenu-pop[hidden] { display: none; }
.psw-pop { left: 0; right: 0; top: calc(100% + 4px); display: flex; flex-direction: column; gap: 6px; max-height: min(420px, 70vh); }
/* R-164 (1.7.0): names on two lines with their title (two customers with the same prefix); the popup stays the
   width of the sidebar (a wider one was cut by it and scrolled it, review-p13 C1) */
.psw-opt > a .truncate { white-space: normal; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
/* R-151 (decision 25): projects of the selector grouped by organization; 2.3.2 (u1): each organization a link to its
   overview (app/tenancy/switcher.rows), a plain heading for an organization the user cannot open */
.psw-grp { padding: 8px 8px 2px; font-size: var(--fs-2xs); font-weight: var(--fw-semi); text-transform: uppercase; letter-spacing: .05em;
           color: var(--muted); overflow-wrap: anywhere; }
.psw-grp[hidden] { display: none; }
.psw-org { display: block; font-size: var(--fs-2xs); color: var(--muted); font-weight: var(--fw-medium); }
.psw-pname { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.3; }
.psw-list:not(.is-filtered) .psw-opt:not(.is-recent) .psw-org { display: none; }   /* under its heading the name is enough */
/* 2.3.2 (u1): an organization of the selector, its projects indented below it */
.psw-orgrow > a { color: var(--text); font-weight: var(--fw-semi); }
.psw-orgrow > a > svg.i { color: var(--muted); flex: none; }
.psw-orgrow:not(:first-child) { margin-top: 4px; }
.psw-list:not(.is-filtered) .psw-orgrow ~ .psw-opt:not(.psw-orgrow) > a { padding-left: 30px; }
.psw-input { width: 100%; height: var(--control-h); }
.psw-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; min-height: 0; flex: 1; }
.psw-opt > a { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: var(--r-sm);
               color: var(--text-2); min-height: 32px; text-decoration: none; }
.psw-opt > a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.psw-opt > a .truncate { flex: 1; min-width: 0; }
.psw-opt > a[aria-current] { color: var(--accent); font-weight: var(--fw-semi); }
.psw-opt > a:focus-visible { background: var(--accent-soft); color: var(--text); }
.psw-list:not(.is-filtered) .psw-opt.last-recent { margin-bottom: 5px; position: relative; }
.psw-list:not(.is-filtered) .psw-opt.last-recent::after { content: ""; position: absolute; left: 8px; right: 8px; bottom: -3px; border-bottom: 1px solid var(--border); }
.psw-empty, .psw-more { margin: 0; padding: 4px 8px; }
.psw-foot { display: flex; gap: 4px; flex-wrap: wrap; border-top: 1px solid var(--border); padding-top: 6px; }
.psw-foot a { display: inline-flex; align-items: center; gap: 6px; padding: 5px 8px; border-radius: var(--r-sm); color: var(--text-2);
              font-size: var(--fs-sm); font-weight: var(--fw-medium); }
.psw-foot a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }

/* ---------- the project group: no headings, its runs split by thin lines (2.3.2, u1); one line per item ---------- */
.nav-proj { margin-top: 2px; }
/* 2.3.2 (u1): compact rows on the desktop, so that at 1366×768 the whole project group (with the entries of the
   organization in the one-project presentation) and the closed «Organization» and «System» are in sight; the menu of
   the phone keeps rows of 32 px for the finger */
.nav-sep { height: 1px; background: var(--border); margin: 4px 10px; }
@media (min-width: 901px) {
  .nav-top a, .nav-proj a, .nav-group .nav a { min-height: 28px; padding-top: 3px; padding-bottom: 3px; }
  .sb-head { padding-bottom: 4px; }
}

/* ---------- collapsible groups: «Organization», «System» (2.3.2, u1) ---------- */
.nav-group { margin-top: 4px; }
.nav-group > .nav-toggle { padding-top: 8px; padding-bottom: 5px; }   /* 2.3.2 (u1): a lower head, same rhythm */
.nav-toggle { width: 100%; background: none; border: 0; cursor: pointer; font-family: inherit; border-radius: var(--r-sm); text-align: left; }
.nav-toggle:hover { color: var(--text); }
.nav-toggle[aria-disabled="true"] { cursor: default; }
.nav-toggle .chev { transition: transform .15s ease; }
.nav-toggle[aria-expanded="true"] .chev { transform: rotate(90deg); }
.nav-group:not(.has-active) > .nav { display: none; }
html[data-nav-open~="org"] .nav-group[data-nav-group="org"] > .nav,
html[data-nav-open~="system"] .nav-group[data-nav-group="system"] > .nav { display: block; }
html[data-nav-open~="org"] .nav-group[data-nav-group="org"] .chev,
html[data-nav-open~="system"] .nav-group[data-nav-group="system"] .chev,
.nav-group.has-active .chev { transform: rotate(90deg); }

/* ---------- user menu (sidebar footer) ---------- */
.sidebar-foot { padding-top: 8px; }
.umenu { position: relative; flex: 1; min-width: 0; }
.umenu-btn { display: flex; align-items: center; gap: 9px; width: 100%; padding: 6px 8px; border: 0; background: none; border-radius: var(--r-sm);
             color: var(--text-2); font: inherit; cursor: pointer; text-align: left; min-height: 40px; }
.umenu-btn:hover, .umenu.is-open .umenu-btn { background: var(--surface-2); color: var(--text); }
.umenu-btn.has-active .avatar { box-shadow: 0 0 0 2px var(--accent); }
.avatar { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; flex: none; font-size: var(--fs-xs);
          font-weight: var(--fw-bold); background: var(--accent-soft); color: var(--accent); }
.umenu-who { display: flex; align-items: center; gap: 6px; min-width: 0; flex: 1; font-size: var(--fs-sm); font-weight: var(--fw-medium); }
/* R-133 (1.7.0): name above, role below, both inside the button («Amministratore dell'organizzazione» left the bar) */
.umenu-who { flex-direction: column; align-items: flex-start; gap: 2px; }
.umenu-who > .truncate { max-width: 100%; }
.umenu-who .badge { flex: initial; }
.umenu-chev { display: inline-flex; color: var(--muted); transform: rotate(-90deg); }
.umenu-pop { left: 0; right: 0; bottom: calc(100% + 6px); min-width: 210px; display: flex; flex-direction: column; gap: 1px; }
.umenu-pop [role=menuitem] { display: flex; align-items: center; gap: 9px; width: 100%; padding: 6px 10px; min-height: 32px; border: 0; background: none;
                             border-radius: var(--r-sm); color: var(--text-2); font: inherit; font-weight: var(--fw-medium); cursor: pointer; text-align: left; }
.umenu-pop [role=menuitem]:hover, .umenu-pop [role=menuitem]:focus { background: var(--surface-2); color: var(--text); text-decoration: none; outline: none; }
.umenu-pop [role=menuitem]:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.umenu-pop [role=menuitem].active { color: var(--accent); }
.umenu-pop form { margin: 0; }
.umenu-sep { height: 1px; background: var(--border); margin: 4px 2px; }
.umenu-langs { display: flex; align-items: center; gap: 2px; padding: 2px 4px 2px 10px; color: var(--muted); flex-wrap: wrap; }
.umenu-langs > svg.i { margin-right: 5px; }
.umenu-pop .umenu-langs [role=menuitem] { width: auto; min-height: 28px; padding: 3px 7px; font-size: var(--fs-2xs); font-weight: var(--fw-semi); letter-spacing: .04em; }
.umenu-pop .umenu-langs [role=menuitem].active { background: var(--accent-soft); color: var(--accent); }
.umenu-pop .theme-toggle svg.i { display: none; }
.umenu-pop .theme-toggle[data-mode="auto"] svg.m-auto, .umenu-pop .theme-toggle:not([data-mode]) svg.m-auto,
.umenu-pop .theme-toggle[data-mode="light"] svg.m-light, .umenu-pop .theme-toggle[data-mode="dark"] svg.m-dark { display: inline-block; }

/* ---------- top bar: palette button ---------- */
.palette-btn { gap: 8px; color: var(--muted); border-color: var(--border); padding: 0 6px 0 10px; flex: none; }
.palette-btn .palette-ic { display: none; }
.palette-btn kbd { font-size: var(--fs-2xs); line-height: 16px; white-space: nowrap; }
@media (max-width: 900px) {
  .palette-btn { width: var(--btn-h); padding: 0; justify-content: center; }
  .palette-btn .palette-ic { display: inline-flex; }
  .palette-btn .palette-text, .palette-btn kbd { display: none; }
}
/* phones (F-151): the search field becomes an icon (the search page has the field), the page name gets the room */
.search-btn { display: none; }
@media (max-width: 640px) {
  .gsearch { display: none; }
  .search-btn { display: inline-flex; }
  .topbar { gap: 4px; }
  .topbar-actions { gap: 2px; }
  .crumbs { font-size: var(--fs-base); }
}

/* ---------- rail mode: desktop only; on mobile the sidebar stays the drawer ---------- */
@media (min-width: 1024px) {
  .rail-btn { display: inline-flex; }
  html.nav-rail .shell { grid-template-columns: var(--rail-w) minmax(0, 1fr); }
  html.nav-rail .sidebar { padding-left: 8px; padding-right: 8px; align-items: stretch; }
  html.nav-rail .sb-head { flex-direction: column; gap: 6px; }
  html.nav-rail .sb-head .brand { padding: 4px 0; justify-content: center; flex: none; }
  html.nav-rail .sb-head .brand-mark { display: block; }
  html.nav-rail .rail-btn svg.i { transform: rotate(180deg); }
  html.nav-rail .sb-body { margin: 0 -8px; padding: 0 8px 8px; }
  html.nav-rail .sidebar .nav-text { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0);
                                     clip-path: inset(50%); white-space: nowrap; }
  html.nav-rail .nav a { justify-content: center; padding: 7px 0; gap: 0; }
  html.nav-rail .nav a .count, html.nav-rail .nav a .dot { display: none; }
  html.nav-rail .psw-btn { justify-content: center; padding: 8px 0; min-height: 40px; }
  html.nav-rail .nav-group > .nav { display: block; }
  html.nav-rail .nav-toggle { display: none; }
  html.nav-rail .nav-group { border-top: 1px solid var(--border); margin: 10px 4px 0; padding-top: 8px; }
  html.nav-rail .nav-group > .nav { margin: 0 -4px; }
  html.nav-rail .umenu-btn { justify-content: center; padding: 6px 0; }
  html.nav-rail .psw-pop, html.nav-rail .umenu-pop { position: fixed; right: auto; width: 280px; }
  html.nav-rail .psw-pop { top: 60px; }
  html.nav-rail .umenu-pop { bottom: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  .rail-btn svg.i, .psw-chev, .nav-toggle .chev { transition: none; }
}
@media print { .psw-pop, .umenu-pop { display: none !important; } }
