/* ─────────────────────────────────────────────────────────────────────────
   Global top bar (Phase NAV, ported from SBA's static/css/topbar.css).
   Loaded by base.html on every page; the bar itself renders only for
   authenticated users (body.has-topbar).

   Navy skin reuses DLB's --primary (#1B4F8A, static/style.css :root); the
   existing variables are read, never redefined. DLB has no dark mode outside
   POS, so none is added here. z-index layering:
     top bar           50    (sticky top). Above page sticky elements (they
                             go up to ~11, e.g. table headers) and BELOW
                             every fixed panel / modal scrim (the lowest is
                             60), so a drill panel's close button or a
                             modal's header is never painted under the bar,
                             and scrims dim the bar like the rest of the page.
                             tests/test_nav_topbar.py pins this ordering.
     hub dropdowns     950   (inside the bar's stacking context, so they
                             still sit above page content)
     drawer/overlay    1000+ (outside the bar; below the 10000 View As banner)
   ────────────────────────────────────────────────────────────────────── */

:root {
  --tb-navy: var(--primary, #1B4F8A);
  --tb-navy-hi: #23609f;
  --tb-accent: #8fc1ff;
  /* --tb-h: how much of the viewport top the app chrome covers — the sticky
     bar (52px = .sba-topbar height) plus the 30px View As banner when an
     owner is impersonating. Page sticky offsets, fixed side panels and
     "fill the rest of the viewport" heights use it instead of hard-coding
     the retired 56px per-page header. 0 on pages without the bar (login,
     public RA form). tests/test_nav_page_chrome.py pins it to the bar. */
  --tb-h: 0px;
}

/* The bar sits in normal flow (sticky), so content needs no offset. */
body.has-topbar { margin-left: 0; --tb-h: 52px; }
/* View As: base.html adds .tb-viewing-as with the fixed 30px banner; the
   bar then sticks under the banner instead of sliding beneath it. */
body.has-topbar.tb-viewing-as { --tb-h: 82px; }
body.tb-viewing-as .sba-topbar { top: 30px; }

/* ── Page toolbar ─────────────────────────────────────────────────────────
   The one shared pattern for a page's own controls / breadcrumb that used
   to sit in its per-page <nav class="top-nav"> header (retired: the top
   bar carries the logo and the user menu carries Logout). It lives in the
   page body, at the top of the page's own container so it lines up with
   the content:
     <div class="page-toolbar">
       <nav class="pt-crumbs" aria-label="Breadcrumb">
         <a href="…">Parent</a><span class="pt-sep">/</span>
         <span class="pt-current">This page</span>
       </nav>
       <button class="pt-end" …>Action</button>
     </div>
   Spacing sits on the children, so a toolbar whose only control is hidden
   (restock planner's Ask Claude before a run) collapses to 0px instead of
   leaving an empty strip. .pt-accent is a full-width coloured session bar
   (the pick screens). */
.page-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  column-gap: 12px;
  font-size: 13px;
  color: var(--text-secondary, #666);
  line-height: 1.4;
}
.page-toolbar > * { margin-bottom: 12px; }
.page-toolbar .pt-crumbs { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; min-width: 0; }
.page-toolbar .pt-crumbs a { color: var(--secondary, #2E75B6); text-decoration: none; }
.page-toolbar .pt-crumbs a:hover { color: var(--primary, #1B4F8A); text-decoration: underline; }
.page-toolbar .pt-sep { color: #94a3b8; }
.page-toolbar .pt-current { font-weight: 600; color: var(--text, #1A1A1A); }
.page-toolbar .pt-end { margin-left: auto; }

.page-toolbar.pt-accent {
  background: var(--primary, #1B4F8A);
  color: #fff;
  padding: 8px 16px;
  min-height: 44px;
  box-sizing: border-box;
}
.page-toolbar.pt-accent > * { margin-bottom: 0; }
.page-toolbar.pt-accent .pt-current { color: #fff; font-size: 15px; font-weight: 700; }
.page-toolbar.pt-accent a { color: #fff; text-decoration: none; font-size: 15px; }
.page-toolbar.pt-accent .pt-btn {
  background: none;
  border: 1px solid rgba(255,255,255,0.4);
  color: #fff;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
}

/* Printing: the app chrome never belongs on paper. */
@media print {
  .sba-topbar, .tb-drawer, .tb-overlay, .page-toolbar { display: none !important; }
}

/* Quick Capture folds into the user menu: the bar stays hidden until the
   user-menu item or Ctrl+K reveals it (base.html window.DLB_QC_OPEN). */
body.has-topbar .sba-topbar .qc-wrapper { display: none; }
body.has-topbar .sba-topbar .qc-wrapper.qc-force-open { display: flex; align-self: center; }

/* ── The bar ── */
.sba-topbar {
  background: var(--tb-navy);
  color: #fff;
  display: flex;
  align-items: stretch;
  height: 52px;
  padding: 0 16px;
  position: sticky;
  top: 0;
  z-index: 50;
  /* Never wider than the viewport: if the hubs cannot fit, the hub row
     clips (see .tb-hubs) rather than the page scrolling sideways. */
  width: 100%;
  box-sizing: border-box;
  min-width: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
.sba-topbar .nav-left { display: flex; align-items: stretch; min-width: 0; flex: 0 1 auto; }
.sba-topbar .nav-right {
  margin-left: auto;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding-left: 12px;
}
.sba-topbar .tb-search-slot {
  margin-left: auto;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  padding-left: 12px;
}
.sba-topbar .tb-search-slot + .nav-right { margin-left: 0; }

/* ── Mobile hamburger + mobile search icon (hidden on desktop) ── */
.sba-topbar .tb-burger {
  display: none;               /* → inline-flex ≤900px */
  align-self: center;
  background: none;
  border: none;
  color: #fff;
  font-size: 17px;
  padding: 8px 10px;
  margin-right: 2px;
  cursor: pointer;
  line-height: 1;
}
.sba-topbar .tb-search-mobile {
  display: none;               /* → inline-flex ≤900px */
  align-items: center;
  justify-content: center;
  color: #fff;
  opacity: .9;
  padding: 8px 8px;
  font-size: 15px;
  text-decoration: none;
}

/* ── Brand (BBDL logo) ── */
.sba-topbar .tb-brand {
  display: flex;
  align-items: center;
  padding-right: 14px;
  text-decoration: none;
}
.sba-topbar .tb-logo { height: 26px; width: auto; display: block; }

/* ── Hubs ── */
/* The hub row is the one part of the bar allowed to shrink: when the
   viewport is too narrow it clips its rightmost hubs (overflow:hidden)
   instead of widening the page. The dropdowns are NOT clipped with it:
   .tb-hub is position:static, so each .tb-dd's containing block is the
   sticky bar itself, which sits outside .tb-hubs. topbar.html's
   placeDropdown() sets each panel's left edge under its hub and keeps it
   inside the bar. */
.sba-topbar .tb-hubs { display: flex; align-items: stretch; min-width: 0; overflow: hidden; }
.sba-topbar .tb-hub { position: static; display: flex; align-items: stretch; flex-shrink: 0; }
.sba-topbar .tb-brand { flex-shrink: 0; }
.sba-topbar .tb-hub-label {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 12px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: rgba(255,255,255,0.92);
  text-decoration: none;
  font: inherit;
  font-size: 13.5px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
}
.sba-topbar .tb-hub-label:focus-visible { outline: 2px solid #fff; outline-offset: -2px; }
.sba-topbar .tb-hub:hover > .tb-hub-label,
.sba-topbar .tb-hub.tb-open > .tb-hub-label { background: var(--tb-navy-hi); }
/* Active trail: the hub holding the current page. */
.sba-topbar .tb-hub.tb-active > .tb-hub-label { border-bottom-color: rgba(255,255,255,0.75); color: #fff; }
.sba-topbar .tb-caret { font-size: 8.5px; opacity: .6; margin-top: 1px; }

/* ── Dropdowns ── */
.sba-topbar .tb-dd {
  display: none;
  position: absolute;
  top: 52px;
  left: 0;
  background: #fff;
  color: #1f2937;
  min-width: 236px;
  border: 1px solid #e5e7eb;
  box-shadow: 0 12px 30px rgba(15,35,60,.16);
  border-radius: 0 0 10px 10px;
  padding: 8px 0;
  z-index: 950;
}
/* Hover-open. The panel's top edge (top:52px) is flush with the 52px bar, so
   there is no dead gap for the pointer to cross. */
.sba-topbar .tb-hub:hover .tb-dd,
.sba-topbar .tb-hub.tb-open .tb-dd { display: block; }
.sba-topbar .tb-dd.mega { width: 480px; }
.sba-topbar .tb-hub:hover .tb-dd.mega,
.sba-topbar .tb-hub.tb-open .tb-dd.mega {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 10px;
}
.sba-topbar .tb-dd a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7.5px 18px;
  font-size: 13px;
  color: #334155;
  text-decoration: none;
  white-space: nowrap;
}
.sba-topbar .tb-dd a:hover { background: #f1f5fb; color: var(--tb-navy); }
.sba-topbar .tb-dd a:focus-visible { outline: 2px solid var(--tb-navy); outline-offset: -2px; }
.sba-topbar .tb-dd a i { width: 16px; text-align: center; font-size: 12px; color: #94a3b8; }
.sba-topbar .tb-dd a:hover i { color: var(--tb-navy); }
.sba-topbar .tb-dd a.land { font-weight: 600; color: var(--tb-navy); }
.sba-topbar .tb-dd a.active { background: #eaf1fa; color: var(--tb-navy); font-weight: 600; }
.sba-topbar .tb-dd a.active i { color: var(--tb-navy); }
.sba-topbar .tb-grp,
.tb-drawer .tb-grp {
  padding: 9px 18px 4px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .8px;
  color: #94a3b8;
  text-transform: uppercase;
}
.sba-topbar .tb-rule { border-top: 1px solid #e5e7eb; margin: 6px 14px; }
.sba-topbar .tb-build-info,
.tb-drawer .tb-build-info {
  padding: 6px 18px 2px;
  font-size: 10px;
  color: #94a3b8;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}

/* ── Search ── */
.sba-topbar .tb-search {
  display: flex;
  align-items: center;
  gap: 9px;
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 8px;
  padding: 5px 12px;
  width: 210px;
}
.sba-topbar .tb-search:focus-within { background: rgba(255,255,255,0.18); border-color: rgba(255,255,255,0.4); }
.sba-topbar .tb-search-icon { font-size: 11px; color: #c8d6e8; }
.sba-topbar .tb-search-input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  outline: none;
  color: #fff;
  font-size: 12.5px;
}
.sba-topbar .tb-search-input::placeholder { color: #c8d6e8; }
.sba-topbar .tb-search-kbd {
  font-size: 10px;
  background: rgba(255,255,255,0.15);
  padding: 1px 6px;
  border-radius: 4px;
  color: #dbe6f4;
  font-family: inherit;
}

/* The injected bell / user dropdown / QC inbox live in .nav-right. */
.sba-topbar .nav-right .notif-bell { color: #fff; margin-right: 4px; }
.sba-topbar .nav-right .nav-user-trigger { color: #fff; opacity: .95; font-size: 13px; white-space: nowrap; }
/* The name is its own span (components/user_dropdown.html) so narrow
   widths shorten or hide it rather than clipping the whole trigger. */
.sba-topbar .nav-right .nav-user-name { display: inline-block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: middle; }
.nav-user-dropdown .nav-user-rule { border-top: 1px solid #eef1f5; margin: 4px 10px; }
/* The opened menu never squeezes its items onto two lines ("User /
   Administration"); right:0 (style.css) keeps it anchored to the right
   edge, so a 200px menu stays on-screen even at 390px. */
.sba-topbar #user-dropdown { min-width: 200px; max-width: calc(100vw - 16px); }
.sba-topbar #user-dropdown .nav-user-dropdown__item { white-space: nowrap; }

/* ── Drawer — overlay + left slide-in panel. In the DOM at all widths but
   off-screen until .open; the burger that opens it shows only ≤900px. ── */
.tb-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10,20,35,.45);
  z-index: 1000;
  opacity: 0;
  transition: opacity .18s ease;
}
.tb-overlay.visible { opacity: 1; }
.tb-overlay[hidden] { display: none; }

.tb-drawer {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: 305px;
  max-width: 86vw;
  background: #fff;
  color: #1f2937;
  z-index: 1001;
  box-shadow: 8px 0 30px rgba(0,0,0,.25);
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  visibility: hidden;
  transition: transform .2s ease, visibility 0s linear .2s;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
/* visibility keeps the closed drawer's links out of the tab order. */
.tb-drawer.open { transform: translateX(0); visibility: visible; transition: transform .2s ease, visibility 0s linear 0s; }

.tb-drawer-head {
  background: var(--tb-navy);
  color: #fff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.tb-drawer-head .tb-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--tb-accent);
  color: var(--tb-navy);
  font-weight: 700;
  font-size: 11px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.tb-drawer-id { min-width: 0; }
.tb-drawer-name { font-size: 13px; font-weight: 600; }
.tb-drawer-x {
  margin-left: auto;
  background: none;
  border: none;
  color: #fff;
  opacity: .8;
  font-size: 17px;
  cursor: pointer;
  padding: 4px 6px;
  line-height: 1;
}
.tb-drawer-x:hover { opacity: 1; }

.tb-drawer-body { overflow-y: auto; flex: 1; padding: 6px 0 16px; }

/* Accordions */
.tb-drawer .acc { border-bottom: 1px solid #f1f5f9; }
.tb-drawer .acc > .h,
.tb-drawer .acc > .acc-home {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 18px;
  font-size: 14px;
  font-weight: 600;
  color: #1f2937;
  cursor: pointer;
  text-decoration: none;
}
.tb-drawer .acc > .h i.lead,
.tb-drawer .acc > .acc-home i.lead { width: 18px; text-align: center; color: #64748b; font-size: 13px; }
.tb-drawer .acc > .h i.chev { margin-left: auto; font-size: 10px; color: #94a3b8; transition: transform .15s ease; }
.tb-drawer .acc.open > .h i.chev { transform: rotate(180deg); }
.tb-drawer .acc .items { display: none; padding: 2px 0 10px; }
.tb-drawer .acc.open .items { display: block; }
.tb-drawer .acc .items .tb-grp { padding-left: 48px; }
.tb-drawer .acc .items .tb-build-info { padding-left: 48px; }
.tb-drawer .acc .items .tb-rule { border-top: 1px solid #f1f5f9; margin: 6px 18px 6px 48px; }
.tb-drawer .acc .items a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 18px 9px 48px;
  font-size: 13px;
  color: #334155;
  text-decoration: none;
}
.tb-drawer .acc .items a:hover { background: #f1f5fb; }
.tb-drawer .acc .items a.land { font-weight: 600; color: var(--tb-navy); }
.tb-drawer .acc .items a.active { background: #eaf1fa; color: var(--tb-navy); font-weight: 600; }
.tb-drawer .acc .items a i { width: 15px; text-align: center; font-size: 11px; color: #94a3b8; }
.tb-drawer .acc .items a.land i { color: var(--tb-navy); }

/* ── "+ New Order" (left of the search box; Sales users only) ── */
.sba-topbar .tb-new-order {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-right: 10px;
  padding: 5px 12px;
  border-radius: 8px;
  background: #0d9488;
  border: 1px solid rgba(255,255,255,0.25);
  color: #fff;
  font-size: 12.5px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}
.sba-topbar .tb-new-order:hover { background: #0f766e; }
.sba-topbar .tb-new-order i { font-size: 11px; }

/* Lock body scroll while the drawer is open. */
body.tb-drawer-open { overflow: hidden; }

/* ── Narrow desktop: tighten so eight hubs + search + icons fit. ── */
@media (max-width: 1400px) {
  .sba-topbar .tb-hub-label { padding: 0 10px; font-size: 13px; }
  .sba-topbar .tb-search { width: 170px; }
  .sba-topbar .tb-search-kbd { display: none; }
}
/* Below 1240px the search box collapses to its icon (→ Stock Lookup), the
   same as on a phone, so the eight hubs keep their room. */
@media (max-width: 1240px) {
  .sba-topbar .tb-search { display: none; }
  .sba-topbar .tb-search-mobile { display: inline-flex; }
  /* New Order folds to its "+" with the search box (still a 32px target). */
  .sba-topbar .tb-new-order-label { display: none; }
  .sba-topbar .tb-new-order { padding: 0; width: 32px; height: 32px; justify-content: center; margin-right: 4px; }
  .sba-topbar .tb-new-order i { font-size: 14px; }
  .sba-topbar .tb-hub-label { padding: 0 8px; }
  .sba-topbar .nav-right .nav-user-name { max-width: 84px; }
}
/* Quick Capture open below 1240px: the user menu folds to its icon so the
   capture input gets the room (body.qc-open is set by base.html's
   window.DLB_QC_OPEN and cleared when the bar folds away again). */
@media (max-width: 1240px) {
  body.qc-open .sba-topbar .nav-right .nav-user-name,
  body.qc-open .sba-topbar .nav-right .nav-user-caret { display: none; }
}
@media (max-width: 1100px) {
  .sba-topbar { padding: 0 10px; }
  .sba-topbar .tb-logo { height: 22px; }
  .sba-topbar .tb-brand { padding-right: 8px; }
  .sba-topbar .tb-hub-label { padding: 0 6px; font-size: 12.5px; gap: 4px; }
  .sba-topbar .nav-right { gap: 4px; padding-left: 6px; }
  .sba-topbar .nav-right .nav-user-name { max-width: 56px; }
}

/* ── Phone/tablet: below 900px swap the hubs and search box for the
   hamburger + a search icon. The injected bell / user icons stay. ── */
@media (max-width: 900px) {
  .sba-topbar .tb-hubs { display: none; }
  .sba-topbar .tb-search { display: none; }
  .sba-topbar .tb-burger { display: inline-flex; align-items: center; }
  .sba-topbar .tb-search-mobile { display: inline-flex; }
  .sba-topbar .tb-brand { padding-right: 8px; }
}
/* Phones: the right-hand icons (search, inbox, View As, bell, user menu)
   must fit beside the burger + logo, so the user menu folds to its icon
   (the name is in the drawer header) and the icon gaps tighten. */
@media (max-width: 600px) {
  .sba-topbar { padding: 0 8px; }
  .sba-topbar .tb-search-slot { padding-left: 4px; }
  .sba-topbar .tb-burger { padding: 8px 6px; }
  .sba-topbar .tb-logo { height: 20px; }
  .sba-topbar .nav-right { gap: 2px; padding-left: 4px; }
  .sba-topbar .nav-right .qc-inbox-link { margin-right: 4px; }
  /* Icon only: the name and caret are hidden (not clipped, so no stray
     ellipsis), and the icon keeps a 36x36 tap target. */
  .sba-topbar .nav-right .nav-user-name,
  .sba-topbar .nav-right .nav-user-caret { display: none; }
  .sba-topbar .nav-right .nav-user-trigger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    min-height: 36px;
    font-size: 16px;
  }
}
