/* ──────────────────────────────────────────────────────────────────────────
   nav.css — the shared, unified top bar (Hub · Books · Dispatch).
   Phase 2 of the nav unification (see docs/nav-unification-plan.md).

   Styled to match the HUB top bar (hub/css/plenum.css .topbar): a FLAT,
   full-width, sticky bar with a bottom hairline and individually-bordered
   control "chips" (.waffle-btn / .tb-btn / .org) — NOT a floating pill.
   Rendered by js/core/ui/nav.js. Namespaced under `.nd-nav`; colours come only
   from the shared --nd-* tokens (tokens.css) so it flips light/dark with its
   host app and looks identical across all three.
   ────────────────────────────────────────────────────────────────────────── */

.nd-nav {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: var(--sp-3_5);
  height: 58px;
  padding: 0 var(--sp-6);
  background: color-mix(in srgb, var(--nd-bg) 80%, transparent);
  border-bottom: 1px solid var(--nd-hair);
  -webkit-backdrop-filter: blur(14px) saturate(1.4);
  backdrop-filter: blur(14px) saturate(1.4);
  color: var(--nd-text);
  font-family: inherit;
}
.nd-nav * { box-sizing: border-box; }

/* ── Brand ─────────────────────────────────────────────────────── */
.nd-brand {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
  letter-spacing: -.01em;
  color: var(--nd-text);
  white-space: nowrap;
  text-decoration: none;
  flex-shrink: 0;
}
.nd-brand img { width: 26px; height: 26px; border-radius: 6px; display: block; }
.nd-brand-word { font-weight: var(--weight-semibold); letter-spacing: -.01em; }
.nd-brand b { font-weight: var(--weight-bold); color: var(--nd-accent); }

/* ── Shared control chip (waffle / icon buttons / org all share this look) ── */
.nd-apps, .nd-ib, .nd-org {
  height: 33px;
  border: 1px solid var(--nd-hair-2);
  background: var(--nd-card);
  color: var(--nd-text-2);
  box-shadow: 0 1px 1.5px rgba(0,0,0,.05), 0 1px 2px rgba(0,0,0,.03);
  cursor: pointer;
  transition: color var(--dur-2) var(--ease-out), border-color var(--dur-2) var(--ease-out), transform var(--dur-2) var(--ease-standard);
}
.nd-apps:hover, .nd-ib:hover, .nd-org:hover,
.nd-apps[aria-expanded="true"], .nd-ib[aria-expanded="true"], .nd-org[aria-expanded="true"] {
  color: var(--nd-text);
  border-color: var(--nd-muted);
}

/* ── App-switcher (waffle) ─────────────────────────────────────── */
.nd-apps-wrap { position: relative; flex-shrink: 0; }
.nd-apps {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1_5);
  padding: 0 var(--sp-3);
  border-radius: 9px;
  font: inherit;
  font-weight: var(--weight-medium);
  font-size: var(--text-sm);
}
.nd-apps .nd-apps-chev { font-size: 13px; }
.nd-apps > i:first-child { font-size: 15px; }

.nd-apps-menu {
  position: absolute;
  top: calc(100% + var(--sp-2));
  left: 0;
  width: 260px;
  background: var(--nd-surface);
  border: 1px solid var(--nd-hair-2);
  border-radius: 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,.10), 0 22px 50px -14px rgba(0,0,0,.30);
  padding: var(--sp-2);
  z-index: var(--z-dropdown);
}
.nd-apps-menu[hidden] { display: none; }
.nd-apps-cap {
  font-family: var(--mono, ui-monospace, monospace);
  font-size: var(--text-2xs);
  font-weight: var(--weight-semibold);
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--nd-muted);
  padding: var(--sp-1_5) var(--sp-2) var(--sp-2);
}
.nd-app-row {
  display: flex;
  align-items: center;
  gap: var(--sp-2_5);
  padding: var(--sp-2) var(--sp-2);
  border-radius: 9px;
  color: var(--nd-text);
  text-decoration: none;
  cursor: pointer;
  transition: background var(--dur-2) var(--ease-out);
}
.nd-app-row:hover { background: var(--nd-card-hover); }
.nd-app-row > i {
  width: 29px; height: 29px;
  border-radius: 8px;
  background: var(--nd-card);
  border: 1px solid var(--nd-hair);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  color: var(--nd-text-2);
  flex-shrink: 0;
}
.nd-app-row .nd-app-lbl { font-weight: var(--weight-semibold); font-size: var(--text-sm); }
.nd-app-row.is-current { background: var(--nd-accent-soft); }
.nd-app-row.is-current > i { background: var(--nd-accent); border-color: transparent; color: var(--nd-on-accent); }

/* ── "+ New" create button (primary accent chip + dropdown) ──────── */
.nd-new-wrap { position: relative; flex-shrink: 0; }
.nd-new {
  height: 33px;
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1_5);
  padding: 0 var(--sp-3) 0 var(--sp-2_5);
  border: 0;
  border-radius: 9px;
  background: var(--nd-accent);
  color: var(--nd-on-accent);
  font: inherit;
  font-weight: var(--weight-semibold);
  font-size: var(--text-sm);
  box-shadow: 0 1px 1.5px rgba(0,0,0,.05), 0 1px 2px rgba(0,0,0,.03);
  cursor: pointer;
  transition: filter var(--dur-2) var(--ease-out), transform var(--dur-2) var(--ease-standard);
}
.nd-new:hover, .nd-new[aria-expanded="true"] { filter: brightness(1.07); }
.nd-new:active { transform: scale(.96); }
.nd-new > i:first-child { font-size: 15px; }
.nd-new .nd-new-chev { font-size: 13px; opacity: .85; }

.nd-new-menu {
  position: absolute;
  top: calc(100% + var(--sp-2));
  left: 0;
  width: 216px;
  max-width: calc(100vw - 20px);
  background: var(--nd-surface);
  border: 1px solid var(--nd-hair-2);
  border-radius: 14px;
  box-shadow: 0 2px 8px rgba(0,0,0,.10), 0 22px 50px -14px rgba(0,0,0,.30);
  padding: var(--sp-2);
  z-index: var(--z-dropdown);
}
.nd-new-menu[hidden] { display: none; }
.nd-new-row {
  display: flex;
  align-items: center;
  gap: var(--sp-2_5);
  padding: var(--sp-2) var(--sp-2);
  border-radius: 9px;
  color: var(--nd-text-2);
  text-decoration: none;
  font-weight: var(--weight-medium);
  font-size: var(--text-sm);
  cursor: pointer;
  transition: background var(--dur-2) var(--ease-out), color var(--dur-2) var(--ease-out);
}
.nd-new-row:hover { background: var(--nd-card-hover); color: var(--nd-text); }
.nd-new-row > i { font-size: 16px; color: var(--nd-accent); flex-shrink: 0; }

/* ── AI-credit chip + buy popover ────────────────────────────────── */
.nd-credit-wrap { position: relative; flex-shrink: 0; }
.nd-credit-wrap[hidden] { display: none; }
.nd-credit {
  height: 33px;
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1_5);
  padding: 0 var(--sp-2_5);
  border: 1px solid var(--nd-hair-2);
  border-radius: 9px;
  background: var(--nd-card);
  color: var(--nd-text);
  font: inherit;
  font-weight: var(--weight-semibold);
  font-size: var(--text-sm);
  box-shadow: 0 1px 1.5px rgba(0,0,0,.05);
  cursor: pointer;
  transition: border-color var(--dur-2) var(--ease-out);
}
.nd-credit:hover, .nd-credit[aria-expanded="true"] { border-color: var(--nd-muted); }
.nd-credit > i { font-size: 15px; color: var(--nd-accent); }
.nd-credit .nd-credit-n { font-family: var(--mono, ui-monospace, monospace); }
.nd-credit small { color: var(--nd-muted); font-weight: var(--weight-medium); }

.nd-credit-menu {
  position: absolute;
  top: calc(100% + var(--sp-2));
  right: 0;
  width: 290px;
  max-width: calc(100vw - 20px);
  background: var(--nd-surface);
  border: 1px solid var(--nd-hair-2);
  border-radius: 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,.10), 0 22px 50px -14px rgba(0,0,0,.30);
  padding: var(--sp-3_5);
  z-index: var(--z-dropdown);
}
.nd-credit-menu[hidden] { display: none; }
.nd-cm-k { font-family: var(--mono, ui-monospace, monospace); font-size: var(--text-2xs); font-weight: var(--weight-semibold); letter-spacing: .1em; text-transform: uppercase; color: var(--nd-muted); }
.nd-cm-bal { font-size: 25px; font-weight: var(--weight-semibold); letter-spacing: -.02em; margin-top: 2px; }
.nd-cm-bal small { font-size: var(--text-sm); color: var(--nd-muted); font-weight: var(--weight-medium); margin-left: var(--sp-1); }
.nd-cm-meter { height: 7px; border-radius: 5px; background: var(--nd-card); margin: var(--sp-3) 0 var(--sp-1_5); overflow: hidden; }
.nd-cm-meter[hidden] { display: none; }
.nd-cm-meter > i { display: block; height: 100%; width: 0; background: var(--nd-accent); border-radius: 5px; transition: width var(--dur-2) var(--ease-out); }
.nd-cm-sub { font-size: var(--text-xs); color: var(--nd-muted); }
.nd-cm-cap { padding: var(--sp-3_5) 0 var(--sp-2); }
.nd-cm-packs { display: flex; flex-direction: column; gap: var(--sp-1_5); }
.nd-cm-pack {
  display: flex;
  align-items: center;
  gap: var(--sp-2_5);
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--nd-hair-2);
  border-radius: 11px;
  background: var(--nd-card);
  color: var(--nd-text);
  font: inherit;
  cursor: pointer;
  transition: border-color var(--dur-2) var(--ease-out), background var(--dur-2) var(--ease-out);
}
.nd-cm-pack:hover { border-color: var(--nd-muted); }
.nd-cm-pack.is-on { border-color: var(--nd-accent); background: var(--nd-accent-soft); }
.nd-cm-radio { width: 15px; height: 15px; border-radius: 50%; border: 2px solid var(--nd-hair-2); flex-shrink: 0; }
.nd-cm-pack.is-on .nd-cm-radio { border-color: var(--nd-accent); box-shadow: inset 0 0 0 3px var(--nd-accent); }
.nd-cm-amt { flex: 1; font-size: var(--text-sm); font-weight: var(--weight-semibold); }
.nd-cm-price { font-family: var(--mono, ui-monospace, monospace); font-weight: var(--weight-semibold); font-size: var(--text-sm); }
.nd-cm-cta {
  display: flex; align-items: center; justify-content: center; gap: var(--sp-1_5);
  width: 100%; height: 38px; margin-top: var(--sp-3);
  border: 0; border-radius: 10px;
  background: var(--nd-accent); color: var(--nd-on-accent);
  font: inherit; font-weight: var(--weight-semibold); font-size: var(--text-sm);
  cursor: pointer; transition: filter var(--dur-2) var(--ease-out);
}
.nd-cm-cta[hidden] { display: none; }
.nd-cm-cta:hover { filter: brightness(1.07); }
.nd-cm-note { font-size: var(--text-2xs); color: var(--nd-muted); line-height: 1.45; margin-top: var(--sp-2_5); padding-top: var(--sp-2_5); border-top: 1px solid var(--nd-hair); }
.nd-cm-foot { display: block; text-align: center; margin-top: var(--sp-2); font-size: var(--text-xs); font-weight: var(--weight-semibold); color: var(--nd-accent); text-decoration: none; }

/* ── Section tabs (link-tabs for Books, button-tabs for Dispatch) ── */
.nd-tabs {
  display: flex;
  align-items: center;
  gap: var(--sp-0_5);
  padding: var(--sp-0_5);
  border-radius: 10px;
  background: var(--nd-card);
  border: 1px solid var(--nd-hair-2);
  flex-shrink: 0;               /* primary nav — never clip tabs; the search shrinks instead */
}
.nd-tabs:empty { display: none; }
.nd-tab {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1_5);
  padding: var(--sp-1_5) var(--sp-3);
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--nd-text-2);
  font: inherit;
  font-weight: var(--weight-medium);
  font-size: var(--text-sm);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background var(--dur-1) var(--ease-standard), color var(--dur-1) var(--ease-standard);
}
.nd-tab > i { font-size: 16px; }
.nd-tab:hover { color: var(--nd-text); }
.nd-tab.is-active { background: var(--nd-accent-soft); color: var(--nd-accent); font-weight: var(--weight-semibold); }
.nd-tab .nd-badge[hidden] { display: none; }
.nd-tab .nd-badge {
  margin-left: var(--sp-0_5);
  min-width: 17px; height: 17px;
  padding: 0 var(--sp-1_5);
  border-radius: 999px;
  background: var(--nd-accent);
  color: var(--nd-on-accent);
  font-family: var(--mono, ui-monospace, monospace);
  font-size: var(--text-2xs);
  font-weight: var(--weight-bold);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ── Grouped tab (dropdown inside the tab strip) ─────────────────
   Low-traffic sections collapse into one dropdown tab so a crowded row
   doesn't starve the search pill (Books: Suppliers + Purchase orders →
   "Purchasing"). The children stay real .nd-tab anchors inside the panel,
   so badges/data-tab lookups and the mobile page dropdown (which mirrors
   .nd-tabs, skipping the trigger) keep working unchanged. */
.nd-tabgroup { position: relative; display: inline-flex; }
.nd-tabgroup-chev { font-size: 13px; opacity: .65; margin-left: 1px; transition: transform var(--dur-2) var(--ease-out); }
.nd-tabgroup-btn[aria-expanded="true"] .nd-tabgroup-chev { transform: rotate(180deg); }
.nd-tabgroup-menu {
  position: absolute; left: 0; top: calc(100% + var(--sp-2)); z-index: var(--z-dropdown);
  min-width: 185px; padding: var(--sp-1);
  display: flex; flex-direction: column; gap: var(--sp-0_5);
  background: var(--nd-card); border: 1px solid var(--nd-hair-2);
  border-radius: 11px; box-shadow: 0 12px 32px rgba(0,0,0,.25);
}
.nd-tabgroup-menu[hidden] { display: none; }
.nd-tabgroup-menu .nd-tab { display: flex; width: 100%; border-radius: 8px; }

/* ── Mobile page selector (full-width dropdown that replaces the tab strip) ──
   Hidden on desktop; nav.css's responsive block reveals it on phones as its own
   full-width row. The trigger shows the current page; the menu lists them all. */
.nd-tabsel-wrap { display: none; position: relative; }
.nd-tabsel {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  width: 100%;
  height: 38px;
  padding: 0 var(--sp-3);
  border: 1px solid var(--nd-hair-2);
  border-radius: 10px;
  background: var(--nd-card);
  color: var(--nd-text);
  font: inherit;
  font-weight: var(--weight-semibold);
  font-size: var(--text-sm);
  cursor: pointer;
}
.nd-tabsel[aria-expanded="true"] { border-color: var(--nd-muted); }
.nd-tabsel .nd-tabsel-ico { font-size: 16px; color: var(--nd-muted); flex-shrink: 0; }
.nd-tabsel .nd-tabsel-lbl { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: left; }
.nd-tabsel .nd-tabsel-chev { font-size: 15px; color: var(--nd-muted); flex-shrink: 0; transition: transform var(--dur-2) var(--ease-out); }
.nd-tabsel[aria-expanded="true"] .nd-tabsel-chev { transform: rotate(180deg); }
.nd-tabsel-dot { min-width: 8px; height: 8px; border-radius: 999px; background: var(--nd-danger); flex-shrink: 0; }
.nd-tabsel-dot[hidden] { display: none; }

.nd-tabsel-menu {
  position: absolute;
  top: calc(100% + var(--sp-1_5));
  left: 0;
  right: 0;
  background: var(--nd-surface);
  border: 1px solid var(--nd-hair-2);
  border-radius: 14px;
  box-shadow: 0 2px 8px rgba(0,0,0,.10), 0 22px 50px -14px rgba(0,0,0,.30);
  padding: var(--sp-1_5);
  max-height: calc(100vh - 120px);
  overflow-y: auto;
  z-index: var(--z-dropdown);
}
.nd-tabsel-menu[hidden] { display: none; }
.nd-tabsel-row {
  display: flex;
  align-items: center;
  gap: var(--sp-2_5);
  width: 100%;
  padding: var(--sp-2_5) var(--sp-2);
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--nd-text);
  font: inherit;
  font-weight: var(--weight-medium);
  font-size: var(--text-md);
  text-align: left;
  cursor: pointer;
}
.nd-tabsel-row:hover, .nd-tabsel-row:active { background: var(--nd-card-hover); }
.nd-tabsel-row.is-current { background: var(--nd-accent-soft); color: var(--nd-accent); font-weight: var(--weight-semibold); }
.nd-tabsel-row > i { width: 22px; font-size: 18px; color: var(--nd-muted); text-align: center; flex-shrink: 0; }
.nd-tabsel-row.is-current > i { color: var(--nd-accent); }
.nd-tabsel-row > span:not(.nd-tabsel-badge) { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nd-tabsel-noico { width: 22px; flex-shrink: 0; }
.nd-tabsel-chk { margin-left: auto; font-size: 16px; }
.nd-tabsel-badge {
  min-width: 18px; height: 18px;
  padding: 0 var(--sp-1_5);
  border-radius: 999px;
  background: var(--nd-accent);
  color: var(--nd-on-accent);
  font-family: var(--mono, ui-monospace, monospace);
  font-size: var(--text-2xs);
  font-weight: var(--weight-bold);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* ── Over-capacity bar (nav.js .is-tight) ───────────────────────────
   Above the phone breakpoint the strip and the dropdown are mutually
   exclusive: nav.js flips to the dropdown when the strip would push the
   right-hand chips (credits, bell, org) off the edge. Scoped to min-width
   641px so the phone layout below keeps full control of both. */
@media (min-width: 641px) {
  .nd-nav.is-tight .nd-tabs { display: none; }
  .nd-nav.is-tight .nd-tabsel-wrap { display: block; flex: 0 1 auto; min-width: 0; max-width: 200px; }
  /* Match the other control chips rather than the phone dropdown's full-width bar. */
  .nd-nav.is-tight .nd-tabsel { height: 33px; border-radius: 9px; }
  /* The panel is pinned to both edges of its trigger on phones, where that's the
     full screen; here the trigger is a ~180px chip, so let it size to its rows. */
  .nd-nav.is-tight .nd-tabsel-menu { right: auto; min-width: 215px; }

  /* Second rung: the strip is already gone and the bar STILL doesn't fit, so
     trim the two widest chips down to their glyphs — the same trade the phone
     layout makes, taken here on measurement rather than on viewport width. */
  .nd-nav.is-tighter .nd-org { padding: 0; width: 33px; justify-content: center; }
  .nd-nav.is-tighter .nd-org [data-org-name], .nd-nav.is-tighter .nd-org > i { display: none; }
  .nd-nav.is-tighter .nd-credit small { display: none; }

  /* Last rung, for the busiest bars (Dispatch carries an extra action chip):
     + New keeps its accent but drops to the glyph, as it does on phones. */
  .nd-nav.is-tightest .nd-new { padding: 0; width: 33px; justify-content: center; }
  .nd-nav.is-tightest .nd-new .nd-new-lbl, .nd-nav.is-tightest .nd-new .nd-new-chev { display: none; }
}

.nd-spacer { flex: 1 1 auto; min-width: var(--sp-2); }

/* ── Right-side actions ────────────────────────────────────────── */
.nd-search {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  height: 33px;
  padding: 0 var(--sp-2_5);
  flex: 0 1 210px;             /* preferred ~210px; shrinks when the tab row is crowded */
  min-width: 33px;             /* floor = one control chip: the magnifier always has room */
  border-radius: 9px;
  background: var(--nd-card);
  /* The default hairline (.14/.13 alpha) all but vanished against the translucent
     bar on both themes — a text-derived edge keeps the pill legible in light+dark. */
  border: 1px solid color-mix(in srgb, var(--nd-text) 20%, transparent);
  color: var(--nd-muted);
  box-shadow: 0 1px 2px rgba(0,0,0,.06), inset 0 1px 0 rgba(255,255,255,.02);
  cursor: text;
  transition: border-color var(--dur-2) var(--ease-out), box-shadow var(--dur-2) var(--ease-out);
  container-type: inline-size;  /* lets the contents below yield as the pill shrinks */
}
.nd-search:hover { border-color: color-mix(in srgb, var(--nd-text) 32%, transparent); }
.nd-search:focus-within { border-color: var(--nd-accent); box-shadow: 0 0 0 3px var(--nd-accent-soft); }
.nd-search > i { font-size: 15px; color: var(--nd-text-2); }
.nd-search .nd-search-ph { flex: 1; font-size: var(--text-sm); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nd-search input {
  flex: 1;
  min-width: 0;
  border: none;
  padding: 0;                   /* books.css has a page-wide input padding — keep the pill's min-content at 0 */
  background: transparent;
  color: var(--nd-text);
  font: inherit;
  font-size: var(--text-sm);
  outline: none;
}
.nd-search kbd {
  font-family: var(--mono, ui-monospace, monospace);
  font-size: var(--text-2xs);
  background: var(--nd-surface);
  border: 1px solid var(--nd-hair);
  border-radius: 5px;
  padding: var(--sp-0_5) var(--sp-1_5);
  color: var(--nd-text-2);
  white-space: nowrap;   /* off Mac the badge is "Ctrl K" — two words, one cap */
  flex: none;
}
/* A crowded tab row squeezes the pill (flex-basis 210px) below its content — on
   Books' 8-tab set the ⌘K hint spilled out over the bell. Can't clip with
   overflow:hidden (the Books results dropdown is a CHILD of the pill), so shed
   contents instead as the pill narrows: hint first, then the field itself.
   The magnifier NEVER goes — shedding it too (as this used to) left an empty,
   dead-looking pill with no way in. Below typing width nav.js adds .is-compact
   and a click expands the pill over the tab strip (.nd-nav.is-searching). */
@container (max-width: 170px) { .nd-search kbd { display: none; } }
/* "Ctrl K" is the wider badge, so off Mac it has to go a step earlier. */
@container (max-width: 200px) { .nd-notmac .nd-search kbd { display: none; } }

/* Icon-only state. Deliberately does NOT pin the width — the pill keeps its
   flex sizing so it un-compacts by itself as soon as the bar has room again.
   Shedding the field lives HERE rather than in a @container rule: container
   queries resolve against the content box while nav.js measures the border
   box, and the ~22px disagreement left a band where the field was gone but
   the pill wasn't yet clickable — an invisible input you could type into. */
.nd-search.is-compact { padding: 0; justify-content: center; cursor: pointer; }
.nd-search.is-compact input, .nd-search.is-compact .nd-search-ph { display: none; }
.nd-search.is-compact > i { color: var(--nd-text-2); }
.nd-search.is-compact:hover > i { color: var(--nd-text); }

/* Expanded from compact: the tab strip yields for as long as the field is in
   use, so there's always somewhere to type. */
.nd-nav.is-searching .nd-tabs { display: none; }
.nd-nav.is-searching .nd-search { flex: 0 1 320px; }

.nd-actions { display: inline-flex; align-items: center; gap: var(--sp-1_5); flex-shrink: 0; }
.nd-ib {
  position: relative;
  width: 33px;
  border-radius: 9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}
.nd-ib:active { transform: scale(.93); }
.nd-ib .nd-dot {
  position: absolute; top: calc(var(--sp-1) * -1); right: calc(var(--sp-1) * -1);
  min-width: 8px; height: 8px;
  border-radius: 999px;
  background: var(--nd-danger);
  border: 2px solid var(--nd-bg);
}
.nd-ib .nd-dot[hidden] { display: none; }

.nd-clock {
  font-family: var(--mono, 'JetBrains Mono', ui-monospace, monospace);
  font-size: var(--text-sm);
  color: var(--nd-text-2);
  padding: 0 var(--sp-1);
  white-space: nowrap;
}

.nd-org {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 0 var(--sp-1_5) 0 var(--sp-2);
  border-radius: 9px;
  color: var(--nd-text);
  font: inherit;
  font-weight: var(--weight-semibold);
  font-size: var(--text-sm);
}
.nd-org .nd-org-av {
  width: 22px; height: 22px;
  border-radius: 6px;
  background: var(--nd-text);
  color: var(--nd-bg);
  font-size: var(--text-2xs);
  font-weight: var(--weight-semibold);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.nd-org > i { font-size: 14px; color: var(--nd-muted); }

/* ── Org / workspace dropdown (ported from the hub .org-menu) ────── */
.nd-org-wrap { position: relative; flex-shrink: 0; }
.nd-org-menu {
  position: absolute;
  top: calc(100% + var(--sp-2));
  right: 0;
  width: 284px;
  background: var(--nd-surface);
  border: 1px solid var(--nd-hair-2);
  border-radius: 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,.10), 0 22px 50px -14px rgba(0,0,0,.30);
  padding: var(--sp-2_5);
  z-index: var(--z-dropdown);
}
.nd-org-menu[hidden] { display: none; }
.nd-menu-cap {
  font-family: var(--mono, ui-monospace, monospace);
  font-size: var(--text-2xs);
  font-weight: var(--weight-semibold);
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--nd-muted);
  padding: var(--sp-1) var(--sp-2) var(--sp-2);
}
.nd-org-row {
  display: flex;
  align-items: center;
  gap: var(--sp-2_5);
  padding: var(--sp-2) var(--sp-2);
  border-radius: 10px;
}
.nd-org-row.is-current { background: var(--nd-card); }
.nd-org-row .nd-org-row-av {
  width: 29px; height: 29px;
  border-radius: 8px;
  background: var(--nd-text);
  color: var(--nd-bg);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.nd-org-row b { font-size: var(--text-sm); display: block; line-height: 1.25; }
.nd-org-row span { font-size: var(--text-2xs); color: var(--nd-muted); }
.nd-org-row > i { margin-left: auto; color: var(--nd-accent); font-size: 15px; }
.nd-menu-sep { height: 1px; background: var(--nd-hair); margin: var(--sp-1_5) var(--sp-1); }
.nd-menu-links { display: flex; flex-direction: column; gap: var(--sp-px); }
.nd-menu-link {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-2);
  border-radius: 9px;
  cursor: pointer;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--nd-text-2);
  text-decoration: none;
  transition: background var(--dur-2) var(--ease-out), color var(--dur-2) var(--ease-out);
}
.nd-menu-link[hidden] { display: none; }
.nd-menu-link > i { font-size: 16px; color: var(--nd-muted); transition: color var(--dur-2) var(--ease-out); }
.nd-menu-link:hover { background: var(--nd-card-hover); color: var(--nd-text); }
.nd-menu-link:hover > i { color: var(--nd-text-2); }
.nd-menu-link.nd-danger { color: var(--nd-danger); }
.nd-menu-link.nd-danger > i { color: var(--nd-danger); }
.nd-menu-link.nd-danger:hover { background: color-mix(in srgb, var(--nd-danger) 12%, transparent); }

/* ── Notifications bell dropdown (core/ui/notifbell.js) ────────── */
.nd-bell-wrap { position: relative; display: inline-flex; }
.nd-bell-menu {
  width: 340px;
  max-height: min(62vh, 460px);
  overflow-y: auto;
}
.nd-bell-list { display: flex; flex-direction: column; gap: var(--sp-px); }
.nd-bell-item {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-2_5);
  padding: var(--sp-2) var(--sp-2);
  border-radius: 9px;
  color: var(--nd-text-2);
  text-decoration: none;
  transition: background var(--dur-2) var(--ease-out);
}
.nd-bell-item:hover { background: var(--nd-card-hover); }
.nd-bell-item > i {
  font-size: 16px;
  color: var(--nd-muted);
  margin-top: 1px;
  flex-shrink: 0;
}
.nd-bell-item.is-unread > i { color: var(--nd-accent); }
/* Tone tints (books activity items) — same language as the legacy books bell
   the Reconcile page still shows: overdue = amber card, payments/accepted =
   green icon, awaiting a response = blue icon. The amber tint is spelled out
   rather than tokenised because it must match the .warn banner in books.css
   that the legacy panel inherited, down to the alpha. */
.nd-bell-item.tone-warn { background: rgba(245,158,11,.12); border: 1px solid rgba(245,158,11,.30); margin-bottom: var(--sp-2); }
.nd-bell-item.tone-warn:hover { background: rgba(245,158,11,.18); }
.nd-bell-item.tone-warn > i { color: var(--doc-partial); }
.nd-bell-item.tone-good > i { color: var(--doc-paid); }
.nd-bell-item.tone-info > i { color: var(--doc-sent); }
.nd-bell-body { flex: 1; min-width: 0; }
.nd-bell-body b {
  display: block;
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--nd-text);
}
.nd-bell-body span {
  display: block;
  font-size: var(--text-xs);
  color: var(--nd-text-2);
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.nd-bell-item > em {
  font-style: normal;
  font-size: var(--text-2xs);
  color: var(--nd-muted);
  white-space: nowrap;
  margin-top: 2px;
}
.nd-bell-x {
  border: 0;
  background: none;
  color: var(--nd-muted);
  font-size: 14px;
  line-height: 1;
  padding: var(--sp-0_5) var(--sp-1);
  border-radius: 6px;
  cursor: pointer;
  flex-shrink: 0;
}
.nd-bell-x:hover { color: var(--nd-text); background: var(--nd-card); }
.nd-bell-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-6) var(--sp-2);
  font-size: var(--text-sm);
  color: var(--nd-muted);
  text-align: center;
}
.nd-bell-empty i { font-size: 22px; }

/* ── Responsive ────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .nd-nav { padding: 0 var(--sp-4); gap: var(--sp-2); }
  .nd-search .nd-search-ph, .nd-search kbd { display: none; }
  /* Tablet band: keep the page chip narrow — the .is-tighter rung above handles
     the org/credit chips on measurement, so they're not trimmed by width here. */
  .nd-nav.is-tight .nd-tabsel-wrap { max-width: 150px; }
}

/* Phones / small tablets. One row can't hold brand + waffle + a full tab strip
   + search + actions + org, so the bar reflows to TWO rows: a compact control
   row, with the section tabs collapsed into a full-width page dropdown on its
   own row beneath. The trigger shows the current page; tapping opens the full
   list. Applies to every app on the unified bar (Books, Dispatch). */
@media (max-width: 640px) {
  .nd-nav {
    flex-wrap: wrap;
    height: auto;
    min-height: 54px;
    padding: var(--sp-2) var(--sp-3);
    row-gap: var(--sp-2);
  }
  .nd-spacer { display: none; }            /* search flex-grows to fill the control row instead */
  .nd-brand     { order: 1; }
  .nd-apps-wrap { order: 2; }
  .nd-new-wrap    { order: 3; }
  .nd-search      { order: 4; flex: 1 1 120px; }
  .nd-credit-wrap { order: 5; }
  .nd-actions     { order: 5; }
  .nd-org-wrap    { order: 6; }
  /* + New → icon only, like the waffle/org, to keep the control row on one line */
  .nd-new { padding: 0; width: 33px; justify-content: center; }
  .nd-new .nd-new-lbl, .nd-new .nd-new-chev { display: none; }
  .nd-credit small { display: none; }        /* chip → bolt + number only */

  /* Section tabs → a full-width dropdown on its own row spanning the screen. */
  .nd-tabs { display: none; }
  .nd-tabsel-wrap { display: block; order: 7; flex: 0 0 100%; width: 100%; }

  /* Org chip → avatar-only, to keep the control row on one line. */
  .nd-org { padding: 0; width: 33px; justify-content: center; }
  .nd-org [data-org-name], .nd-org > i { display: none; }
  .nd-org-menu { width: min(284px, calc(100vw - 20px)); }
  .nd-bell-menu { width: min(340px, calc(100vw - 20px)); }
}
@media (max-width: 480px) {
  .nd-apps .nd-apps-lbl { display: none; }
  .nd-brand-word { display: none; }        /* logo only — reclaim space in the control row */
  .nd-credit-wrap { display: none; }       /* credits live in the workspace/settings on tiny screens */
}
