/* ═══ Navigation shell: eight hubs, contextual sidebar, hub pages, command palette, phone bar ═══════════════
   core/nav.js and core/palette.js. Tokens only (light and dark come from base.css); the phone layout starts at 768 px. */

/* ─── Grid: top bar across, the hub's sidebar on the left, page title above the screen ─── */
.app.shell {
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: 48px minmax(0, 1fr);
  grid-template-areas: "top" "work";
}
.app.shell > .topbar { grid-area: top; gap: 6px; padding: 0 10px; position: relative; z-index: 20; min-width: 0; }
.app.shell .top-r { display: contents; } /* the desk lays these out as one group on the right */
.app.shell > .copilot-dock { display: none; grid-area: copilot; min-height: 0; min-width: 0; overflow: hidden; border-left: 1px solid var(--line); background: var(--surface); }
.app.shell.copilot-open {
  grid-template-columns: minmax(0, 1fr) var(--copilot-width, min(40%, 560px));
  grid-template-areas: "top top" "work copilot";
}
.app.shell.copilot-open > .copilot-dock { display: flex; flex-direction: column; min-height: 0; }
.app.shell > .app-workspace {
  grid-area: work;
  display: grid;
  min-height: 0;
  min-width: 0;
  grid-template-columns: 236px minmax(0, 1fr);
  grid-template-rows: 42px minmax(0, 1fr);
  grid-template-areas: "side page" "side main";
}
.app.shell > .app-workspace > .sidebar { grid-area: side; min-height: 0; }
.app.shell > .app-workspace > .pagebar { grid-area: page; }
.app.shell > .app-workspace > .main { grid-area: main; min-height: 0; }
.app.shell > .app-workspace > .bottom-bar { display: none; }
.icon-btn svg, .nav-toggle svg, .search-btn svg, .fav-btn svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ─── Top bar ─── */
.app.shell .nav-toggle { display: none; align-items: center; justify-content: center; width: 34px; height: 34px; border: 0; border-radius: 8px; background: none; color: var(--ink); cursor: pointer; }
.app.shell .nav-toggle:hover { background: var(--surface-2); }
.top-brand { display: flex; align-items: center; gap: 6px; padding: 0 6px 0 2px; flex: none; }
.top-brand .brand-logo { height: 26px; width: auto; display: block; }
.top-brand .brand-icon { display: none; width: 22px; height: 22px; }
.hub-tabs { display: flex; align-items: stretch; align-self: stretch; min-width: 0; flex: 0 1 auto; }
.hub-strip { display: flex; align-items: stretch; min-width: 0; flex: 0 1 auto; overflow: hidden; }
.hub-tab {
  display: inline-flex; align-items: center; gap: 6px; padding: 0 9px; height: 100%; flex: none; white-space: nowrap;
  color: var(--ink-2); font: 500 12.5px var(--font-ui); border: 0; border-bottom: 2px solid transparent; background: none; cursor: pointer;
  transition: color .12s ease, background .12s ease, border-color .12s ease;
}
.hub-tab svg { width: 15px; height: 15px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.hub-tab:hover { color: var(--ink); background: var(--surface-2); }
.hub-tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; background: linear-gradient(180deg, transparent, var(--accent-soft)); }
.hub-n { display: inline-flex; align-items: center; justify-content: center; min-width: 16px; height: 15px; padding: 0 4px; border-radius: 999px; background: var(--surface-3); color: var(--ink-2); font: 600 9.5px var(--font-ui); font-style: normal; }
.hub-n.crit { background: var(--crit); color: #fff; }
.hub-more { position: relative; display: flex; align-items: stretch; flex: none; }
.hub-menu { position: absolute; top: calc(100% + 2px); left: 0; min-width: 190px; padding: 4px; background: var(--surface); border: 1px solid var(--line-2); border-radius: 8px; box-shadow: var(--shadow); z-index: 30; }
.hub-menu a { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-radius: 6px; color: var(--ink-2); }
.hub-menu a:hover, .hub-menu a.active { background: var(--accent-soft); color: var(--accent); }
.hub-menu svg { width: 15px; height: 15px; stroke: currentColor; fill: none; stroke-width: 1.8; }
.search-btn {
  display: inline-flex; align-items: center; gap: 8px; height: 30px; width: 230px; padding: 0 8px 0 10px; flex: 0 1 auto; min-width: 0;
  border: 1px solid var(--line-2); border-radius: 8px; background: var(--surface-2); color: var(--muted); font: 400 12px var(--font-ui); cursor: pointer;
}
.search-btn:hover { border-color: var(--accent-line); color: var(--ink-2); }
.search-btn span { flex: 1; text-align: left; white-space: nowrap; overflow: hidden; }
.search-btn kbd { font: 500 10px var(--font-mono); border: 1px solid var(--line-2); border-radius: 4px; padding: 1px 5px; background: var(--surface); color: var(--muted); }
.app.shell .topbar .icon-btn { width: 30px; justify-content: center; padding: 0; }
.me-chip { display: flex; flex-direction: column; line-height: 1.2; max-width: 190px; min-width: 0; padding: 0 4px; }
.me-chip b, .me-chip span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-chip b { font-size: 11.5px; font-weight: 600; color: var(--ink); }
.me-chip span { font-size: 10px; color: var(--muted); }

/* ─── Page title row: title, pin star, Hub › Section ─── */
.pagebar { display: flex; align-items: center; gap: 8px; padding: 6px 16px 0; min-width: 0; overflow: hidden; background: var(--bg); }
.pagebar h1 { font-size: 16px; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pagebar .crumbs { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
/* classic order: title, star, Hub › Section (the markup puts the crumbs first for the desk's top bar) */
.pagebar h1 { order: 1; } .pagebar .fav-btn { order: 2; } .pagebar .crumbs { order: 3; } .pagebar .page-meta { order: 4; }
.pagebar .page-meta:empty { display: none; }
.fav-btn { display: inline-flex; align-items: center; justify-content: center; width: 26px; height: 26px; flex: none; border: 1px solid transparent; border-radius: 6px; background: none; color: var(--muted); cursor: pointer; }
.fav-btn:hover { border-color: var(--line-2); color: var(--ink); }
.fav-btn.on, .nav-star.on, .pal-star.on { color: var(--warn); }
.fav-btn.on svg, .nav-star.on svg, .pal-star.on svg { fill: var(--warn); stroke: var(--warn); }

/* ─── Contextual sidebar ─── */
.app.shell > .app-workspace > .sidebar { background: var(--surface); }
.app.shell .nav-search { padding: 10px 10px 4px; }
.nav-hub-h { display: flex; align-items: center; gap: 8px; margin: 2px 2px 4px; padding: 6px 8px; border-radius: 6px; color: var(--ink); font: 600 13.5px var(--font-head); letter-spacing: .01em; }
.nav-hub-h:hover { background: var(--surface-2); }
.nav-hub-h svg { width: 16px; height: 16px; stroke: var(--accent); fill: none; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.nav-sec + .nav-sec { margin-top: 2px; }
.app.shell button.nav-group, .app.shell .nav-label {
  width: 100%; border: 0; background: none; text-align: left; padding: 10px 8px 4px; display: flex; align-items: center; gap: 6px;
  font: 600 10.5px var(--font-head); letter-spacing: .06em; text-transform: uppercase; color: var(--muted);
}
.app.shell button.nav-group { cursor: pointer; border-radius: 5px; }
.app.shell .nav-label { cursor: default; }
.app.shell button.nav-group:hover { color: var(--ink-2); }
.app.shell button.nav-group > span:first-child, .app.shell .nav-label > span { flex: 1; display: inline-flex; align-items: center; gap: 6px; }
.app.shell button.nav-group::after { content: ""; width: 5px; height: 5px; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: rotate(45deg) translateY(-2px); transition: transform .12s ease; }
.app.shell button.nav-group[aria-expanded="false"]::after { transform: rotate(-45deg); }
.nav-label svg { width: 11px; height: 11px; stroke: currentColor; fill: none; stroke-width: 2; }
.nav-row { display: flex; align-items: center; gap: 2px; position: relative; }
.nav-row .nav-item, .nav-row .nav-q { flex: 1; min-width: 0; }
.nav-row .nav-item > span:not(.badge), .nav-q > span:not(.badge) { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-star, .pal-star, .nl-link .nav-star {
  display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; flex: none; padding: 0;
  border: 0; border-radius: 5px; background: none; color: var(--muted); cursor: pointer; opacity: 0; transition: opacity .12s ease;
}
.nav-star svg, .pal-star svg { width: 13px; height: 13px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linejoin: round; }
.nav-row:hover .nav-star, .nl-link:hover .nav-star, .nav-star:focus-visible, .nav-star.on, .pal-item:hover .pal-star, .pal-item.sel .pal-star, .pal-star.on { opacity: 1; }
.nav-star:hover, .pal-star:hover { background: var(--surface-2); color: var(--ink); }
.nav-q { display: flex; align-items: center; gap: 9px; padding: 6px 8px; border-radius: 5px; color: var(--ink-2); font-size: 12.5px; }
.nav-q:hover { background: var(--surface-2); color: var(--ink); }
.nav-q svg { width: 15px; height: 15px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav-q > i { width: 8px; height: 8px; border-radius: 50%; flex: none; margin: 0 3px; background: var(--axis); }
.nav-q.sev-crit > i { background: var(--crit); } .nav-q.sev-warn > i { background: var(--warn); } .nav-q.sev-info > i { background: var(--accent); }
.nav-q .badge, .nav-row .nav-item .badge { margin-left: auto; }
.nav-q.all { color: var(--accent); font-size: 11.5px; padding-left: 28px; }
.nav-more { display: flex; align-items: center; gap: 6px; width: 100%; padding: 4px 8px 6px 32px; border: 0; background: none; color: var(--accent); font-size: 11.5px; cursor: pointer; text-align: left; border-radius: 5px; }
.nav-more:hover { background: var(--surface-2); }
.nav-more svg { width: 13px; height: 13px; stroke: currentColor; fill: none; stroke-width: 1.9; flex: none; }
.nav-everywhere { margin-top: 8px; padding-left: 8px; }
.nav-hint { margin: 0; padding: 2px 8px 6px; color: var(--muted); font-size: 11px; }
.app.shell .sidebar-foot { line-height: 1.4; }

/* ─── Hub landing pages, Today and the A–Z list ─── */
.nl-head .actions { flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.nl-head .actions .btn svg { width: 13px; height: 13px; }
.nq-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; margin-bottom: 14px; }
.nq-tile {
  display: flex; flex-direction: column; gap: 2px; padding: 10px 12px 9px; min-width: 0; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-left: 3px solid var(--axis); border-radius: 8px; box-shadow: var(--shadow);
  transition: border-color .12s ease, box-shadow .12s ease, transform .12s ease;
}
.nq-tile:hover { border-color: var(--accent-line); transform: translateY(-1px); }
.nq-tile b { font: 600 22px/1.1 var(--font-head); }
.nq-tile span { font-size: 12px; color: var(--ink-2); }
.nq-tile em { font-style: normal; font-size: 11px; color: var(--accent); margin-top: 2px; }
.nq-tile.sev-crit { border-left-color: var(--crit); } .nq-tile.sev-crit b { color: var(--crit-text); }
.nq-tile.sev-warn { border-left-color: var(--warn); } .nq-tile.sev-warn b { color: var(--warn-text); }
.nq-tile.sev-info { border-left-color: var(--accent); }
.nq-tile.zero b { color: var(--muted); }
.nq-row > p { grid-column: 1 / -1; margin: 0; }
.nl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(320px, 100%), 1fr)); gap: 10px; align-items: start; }
.nl-card .card-h h3 { display: inline-flex; align-items: center; gap: 6px; }
.nl-card .card-h h3 svg { width: 14px; height: 14px; stroke: var(--warn); fill: none; stroke-width: 1.9; }
.nav-focus { border-color: var(--accent-line); box-shadow: 0 0 0 3px var(--accent-soft); }
.nl-links { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(210px, 100%), 1fr)); gap: 2px 8px; }
.nl-link { display: flex; align-items: center; min-width: 0; border-radius: 6px; }
.nl-link a { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 6px; color: var(--ink); }
.nl-link a:hover { background: var(--accent-soft); color: var(--accent); }
.nl-link a > span:not(.badge) { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nl-link a svg { width: 15px; height: 15px; flex: none; stroke: var(--ink-2); fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nl-link a:hover svg { stroke: var(--accent); }
.nl-link .badge { margin-left: auto; }
.nl-link small { margin-left: auto; padding-left: 8px; color: var(--muted); font-size: 10.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 50%; }
.nl-links.az { grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr)); }
.today-block { margin-bottom: 14px; }
.today-h { display: flex; align-items: center; gap: 8px; margin: 0 0 8px; font-size: 13px; }
.today-h svg { width: 15px; height: 15px; stroke: var(--accent); fill: none; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.auto-list { display: flex; flex-direction: column; gap: 6px; }
.auto-row {
  display: grid; grid-template-columns: minmax(0, 2fr) auto minmax(0, 2fr) auto; gap: 4px 12px; align-items: center;
  padding: 8px 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
}
.auto-row .auto-flow b { font-family: var(--font-mono); font-size: 11px; color: var(--accent); margin-right: 4px; }
.auto-row .auto-made { color: var(--ink-2); }
.auto-row .btn svg { width: 12px; height: 12px; }

/* ─── Command palette ─── */
.palette-back { position: fixed; inset: 0; z-index: 80; display: flex; justify-content: center; align-items: flex-start; padding: 10vh 16px 16px; background: rgba(8, 12, 20, .45); }
.palette { width: min(660px, 100%); max-height: min(70vh, 640px); display: flex; flex-direction: column; overflow: hidden; background: var(--surface); border: 1px solid var(--line-2); border-radius: 12px; box-shadow: 0 24px 60px rgba(0, 0, 0, .28); }
.pal-in { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.pal-in svg { width: 18px; height: 18px; stroke: var(--muted); fill: none; stroke-width: 1.9; stroke-linecap: round; flex: none; }
.pal-in input { flex: 1; min-width: 0; height: 30px; border: 0; outline: 0; background: transparent; color: var(--ink); font: 400 15px var(--font-ui); }
.pal-in input::-webkit-search-cancel-button { display: none; }
.pal-in kbd { font: 500 10px var(--font-mono); border: 1px solid var(--line-2); border-radius: 4px; padding: 1px 5px; color: var(--muted); }
.pal-list { overflow-y: auto; padding: 4px 6px 8px; min-height: 0; }
.pal-group { padding: 10px 10px 4px; font: 600 10.5px var(--font-head); letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.pal-item { display: flex; align-items: center; gap: 2px; padding-right: 4px; border-radius: 8px; }
.pal-item a { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; padding: 7px 10px; color: var(--ink); }
.pal-item a > svg { width: 16px; height: 16px; flex: none; stroke: var(--ink-2); fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.pal-item.sel { background: var(--accent-soft); }
.pal-item.sel a, .pal-item.sel a > svg { color: var(--accent); stroke: var(--accent); }
.pal-label { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.pal-sub { margin-left: auto; padding-left: 10px; max-width: 48%; color: var(--muted); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: none; }
.pal-note { padding: 14px 12px; color: var(--muted); font-size: 12px; }
.pal-foot { display: flex; flex-wrap: wrap; gap: 14px; padding: 7px 14px; border-top: 1px solid var(--line); color: var(--muted); font-size: 10.5px; }
body.pal-open { overflow: hidden; }

/* ─── Phone: bottom bar, drawer, "More" sheet (≤ 768 px) ─── */
.nav-scrim { position: fixed; inset: 0; z-index: 71; background: rgba(8, 12, 20, .42); }
.sheet-back { position: fixed; inset: 0; z-index: 75; display: flex; align-items: flex-end; background: rgba(8, 12, 20, .42); }
.sheet-card { width: 100%; max-height: 82vh; overflow-y: auto; padding: 12px 14px calc(16px + env(safe-area-inset-bottom)); background: var(--surface); border-radius: 14px 14px 0 0; box-shadow: 0 -10px 30px rgba(0, 0, 0, .2); }
.sheet-h { display: flex; align-items: center; justify-content: space-between; font: 600 14px var(--font-head); }
.sheet-h .btn svg { width: 12px; height: 12px; }
.sheet-search { display: flex; align-items: center; gap: 8px; width: 100%; height: 40px; margin: 10px 0 12px; padding: 0 12px; border: 1px solid var(--line-2); border-radius: 8px; background: var(--surface-2); color: var(--muted); cursor: pointer; text-align: left; }
.sheet-search svg, .sheet-hub svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.sheet-hubs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.sheet-hub { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 6px; border: 1px solid var(--line); border-radius: 10px; color: var(--ink); text-align: center; font-size: 11.5px; min-width: 0; }
.sheet-hub:hover, .sheet-hub.active { border-color: var(--accent-line); background: var(--accent-soft); color: var(--accent); }
.bb-tab { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-width: 0; padding: 4px 2px; border: 0; background: none; color: var(--ink-2); font: 500 10.5px var(--font-ui); cursor: pointer; }
.bb-tab svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.bb-tab span { max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bb-tab.active { color: var(--accent); }
.bb-tab { position: relative; }
.bb-tab .hub-n { position: absolute; top: 3px; left: calc(50% + 5px); }

/* the eight tabs fit beside the search box down to about 1280 px; narrower, the search box shrinks, then the name goes */
@media (max-width: 1440px) { .search-btn { width: 190px; } }
@media (max-width: 1100px) {
  .me-chip { display: none; }
  .search-btn { width: 170px; }
}
@media (max-width: 768px) {
  .app.shell {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: 48px minmax(0, 1fr);
    grid-template-areas: "top" "work";
    height: 100vh; height: 100dvh;
  }
  .app.shell.copilot-open {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: 48px minmax(34vh, 40%) minmax(0, 1fr);
    grid-template-areas: "top" "copilot" "work";
  }
  .app.shell > .app-workspace {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: 38px minmax(0, 1fr) auto;
    grid-template-areas: "page" "main" "bottom";
  }
  .app.shell > .app-workspace > .sidebar { position: fixed; top: 0; bottom: 0; left: 0; width: min(300px, 86vw); z-index: 72; transform: translateX(-105%); transition: transform .18s ease; box-shadow: none; }
  .app.shell.nav-open > .app-workspace > .sidebar { transform: none; box-shadow: 8px 0 30px rgba(0, 0, 0, .25); }
  .app.shell .nav-toggle { display: inline-flex; }
  .app.shell .hub-tabs, .app.shell .me-chip, .top-brand .brand-logo { display: none; }
  .top-brand .brand-icon { display: block; }
  .search-btn { width: 34px; height: 34px; padding: 0; justify-content: center; flex: none; }
  .search-btn span, .search-btn kbd { display: none; }
  .app.shell > .app-workspace > .bottom-bar { grid-area: bottom; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); height: 56px; padding-bottom: env(safe-area-inset-bottom); background: var(--surface); border-top: 1px solid var(--line); }
  .app.shell.flat > .app-workspace > .bottom-bar { display: none; }
  /* base.css turns the old sidebar into an icon rail below 760 px; the drawer keeps its labels */
  .app.shell .nav-item { justify-content: flex-start; padding: 7px 8px; }
  .app.shell .nav-item > span, .app.shell .sidebar-foot { display: block; }
  .app.shell .nav-item .badge { display: inline-flex; }
  .app.shell .nav-group { display: flex; }
  .app.shell .nav-star { opacity: .45; }
  .pagebar { padding: 4px 12px 0; }
  .pagebar h1 { font-size: 15px; }
  .app.shell > .app-workspace > .main { padding: 10px 12px 20px; }
  .auto-row { grid-template-columns: minmax(0, 1fr) auto; }
  .palette-back { padding: 8px; }
  .palette { max-height: calc(100vh - 16px); }
  .pal-foot { display: none; }
  /* a result's hub, section or record facts go under its name, so neither is cut short */
  .pal-item a { flex-wrap: wrap; row-gap: 1px; }
  .pal-label { flex: 1 1 0; }
  .pal-sub { flex: 0 0 calc(100% - 26px); max-width: none; margin-left: 26px; padding-left: 0; }
}

@media (min-width: 769px) { .sheet-back, .nav-scrim { display: none !important; } }
@media print {
  .pagebar, .bottom-bar, .nav-scrim, .sheet-back, .palette-back { display: none !important; }
}
@media (prefers-reduced-motion: reduce) { .app.shell > .app-workspace > .sidebar, .nq-tile, .hub-tab { transition: none; } }
