/* Primary + More nav redesign: collapsible desktop sidebar + mobile bottom bar.
   Loaded after mobile-menu-v20 / shell-nav-v28 / sidebar-flyout-v29 so it wins. */

:root {
  --cs-nav-expanded-width: 220px;
  --cs-nav-collapsed-width: 72px;
  --cs-bottom-nav-height: 56px;
  --cs-bottom-nav-pad: 8px;
  --cs-nav-ink: #e8eefc;
  --cs-nav-muted: rgba(183, 198, 232, .82);
  --cs-nav-active: #6fe6ff;
  --cs-nav-surface: linear-gradient(180deg, #0b1735, #101f42 68%, #11254c);
  --cs-nav-panel: linear-gradient(165deg, #0c152c 0%, #142246 55%, #101a36 100%);
  --cs-nav-border: rgba(132, 160, 225, .28);
  --cs-nav-z-bottom: 55;
  --cs-nav-z-more: 60;
  --cs-nav-z-scrim: 50;
  --cs-dock-gap: 10px;
}

/* Kill legacy Menu FAB + flyout chrome when primary-more mode is active. */
body #mobileMenuToggle,
body #mobileMenuScrim,
body .mobile-menu-toggle,
body .mobile-menu-scrim {
  display: none !important;
  pointer-events: none !important;
  visibility: hidden !important;
}

#navFlyoutPortal {
  display: none !important;
}

/* ---------- Desktop / tablet sidebar ---------- */
@media (min-width: 721px) {
  body .shell,
  body[data-theme] .shell {
    display: grid !important;
    grid-template-columns: var(--cs-nav-expanded-width) minmax(0, 1fr) !important;
    transition: none;
  }

  body[data-nav-collapsed="true"] .shell,
  body[data-theme][data-nav-collapsed="true"] .shell {
    grid-template-columns: var(--cs-nav-collapsed-width) minmax(0, 1fr) !important;
  }

  body .sidebar,
  body[data-theme] .sidebar {
    position: sticky !important;
    inset: auto !important;
    top: 0 !important;
    width: auto !important;
    max-width: none !important;
    height: 100vh !important;
    padding: 20px 12px 16px !important;
    display: flex !important;
    flex-direction: column !important;
    gap: 0;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    min-height: 0 !important;
    pointer-events: auto !important;
    background: var(--cs-nav-surface) !important;
    box-shadow: none !important;
    border-right: 1px solid rgba(255, 255, 255, .06);
    z-index: 5;
  }

  /* Rail above scrim so logo/More/+ stay clickable in one click while More is open.
     Keep overflow-y:auto so short rails can still scroll to + Add. The flyout is
     portaled to body (position:fixed), so this overflow no longer clips it. */
  body.nav-more-open .sidebar,
  body[data-theme].nav-more-open .sidebar {
    z-index: 220;
  }

  body.nav-more-open .nav-more-scrim:not([hidden]) {
    z-index: 205;
  }

  body.nav-more-open .nav-more-panel {
    z-index: 210;
  }

  body.nav-more-open .sidebar .brand,
  body.nav-more-open .nav-collapse-toggle,
  body.nav-more-open #navPrimary,
  body.nav-more-open .sidebar .add-button,
  body.nav-more-open .sidebar .app-legal-links,
  body.nav-more-open .sidebar .sidebar-dock {
    position: relative;
    z-index: 2;
  }

  /* While More is open, only show legal links in the panel (not also in the sidebar footer). */
  body.nav-more-open .sidebar .app-legal-links {
    visibility: hidden !important;
    pointer-events: none !important;
  }

  body[data-nav-collapsed="true"] .sidebar,
  body[data-theme][data-nav-collapsed="true"] .sidebar {
    padding: 16px 8px !important;
    align-items: center;
  }

  .nav-collapse-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    align-self: flex-end;
    width: 36px;
    height: 36px;
    min-width: 36px;
    min-height: 36px;
    margin: 4px 0 8px;
    padding: 0;
    border: 1px solid rgba(132, 160, 225, .28);
    border-radius: 10px;
    background: rgba(255, 255, 255, .06);
    color: var(--cs-nav-active);
    font: 700 18px/1 "DM Sans", sans-serif;
    cursor: pointer;
  }

  .nav-collapse-toggle:focus-visible {
    outline: 2px solid var(--cs-nav-active);
    outline-offset: 2px;
  }

  body[data-nav-collapsed="true"] .nav-collapse-toggle {
    align-self: center;
    transform: scaleX(-1);
  }

  /* Collapsed brand: icon only — never clip the wordmark. Hide instantly (no width tween). */
  body[data-nav-collapsed="true"] .sidebar .brand-name,
  body[data-theme][data-nav-collapsed="true"] .sidebar .brand-name {
    display: none !important;
    visibility: hidden !important;
    width: 0 !important;
    max-width: 0 !important;
    height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    opacity: 0 !important;
    position: absolute !important;
    clip: rect(0, 0, 0, 0) !important;
  }

  body[data-nav-collapsed="true"] .privacy-note,
  body[data-nav-collapsed="true"] .sidebar .app-legal-links,
  body[data-nav-collapsed="true"] .sidebar-dock .privacy-note,
  body[data-nav-collapsed="true"] .sidebar-dock .app-legal-links,
  body[data-nav-collapsed="true"] .sidebar-dock .build-version-button,
  body[data-nav-collapsed="true"] .nav-primary .nav-item-label,
  body[data-nav-collapsed="true"] .nav-more-trigger .nav-item-label {
    display: none !important;
  }

  body[data-nav-collapsed="true"] .nav-more-panel .nav-item-label {
    display: block !important;
  }

  body .sidebar .brand,
  body[data-theme] .sidebar .brand {
    display: flex !important;
    align-items: center;
    gap: 8px;
    width: 100%;
    min-width: 0;
    overflow: visible;
  }

  body[data-nav-collapsed="true"] .sidebar .brand,
  body[data-theme][data-nav-collapsed="true"] .sidebar .brand {
    justify-content: center;
    width: 100%;
    max-width: 100%;
    overflow: visible !important;
  }

  body[data-nav-collapsed="true"] .sidebar .brand img,
  body[data-theme][data-nav-collapsed="true"] .sidebar .brand img {
    width: 36px;
    height: 38px;
    flex: 0 0 auto;
    display: block;
  }

  #mainNavigation {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 12px 0 8px !important;
    width: 100%;
    flex: 0 1 auto;
    min-height: min-content;
    overflow-x: hidden;
    overflow-y: auto;
  }

  /* Dock sits at the bottom of the rail. The auto margin resolves to 0 once the
     column overflows, so a short rail scrolls instead of overlapping the nav. */
  .sidebar-dock {
    display: flex;
    flex-direction: column;
    flex: 0 0 auto;
    align-items: center;
    gap: var(--cs-dock-gap);
    width: 100%;
    min-width: 0;
    margin-top: auto;
    padding-top: 0;
  }

  /* One gap owns every dock seam: + Add, the session note, the legal row and
     the version line. Zero the legacy margins those parts ship with — the legal
     row is a <nav>, so shell-nav's `body .sidebar nav` !important margin lands
     on it too and has to be beaten here. */
  body .sidebar .sidebar-dock .privacy-note,
  body[data-theme] .sidebar .sidebar-dock .privacy-note {
    margin: 0 auto !important;
  }

  body .sidebar .sidebar-dock .app-legal-links,
  body[data-theme] .sidebar .sidebar-dock .app-legal-links {
    margin: 0 !important;
    padding: 0 !important;
  }

  body .sidebar .sidebar-dock .build-version-button,
  body .sidebar .sidebar-dock #sidebarBuildVersion,
  body[data-theme] .sidebar .sidebar-dock #sidebarBuildVersion {
    margin: 0 !important;
    padding: 0 6px !important;
    text-align: center;
  }

  .nav-primary {
    display: grid;
    gap: 6px;
    width: 100%;
  }

  #mainNavigation .nav-item,
  #mainNavigation .nav-more-trigger {
    display: grid;
    grid-template-columns: 28px minmax(0, 1fr);
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 44px;
    margin: 0;
    padding: 10px 12px;
    border: 1px solid transparent;
    border-radius: 11px;
    background: transparent;
    color: var(--cs-nav-muted);
    font: 700 14px/1.2 "DM Sans", sans-serif;
    text-align: left;
    cursor: pointer;
  }

  /* S8: beat shell-nav `span { width:28px }` for rail labels. */
  #mainNavigation .nav-item > .nav-item-label,
  #mainNavigation .nav-more-trigger > .nav-item-label,
  body .sidebar #mainNavigation .nav-item > span.nav-item-label,
  body .sidebar #mainNavigation .nav-more-trigger > span.nav-item-label {
    width: auto !important;
    max-width: none !important;
    min-width: 0 !important;
  }

  /* Collapsed primary rail: centre glyphs on the same axis as logo / toggle / + . */
  body[data-nav-collapsed="true"] #mainNavigation .nav-primary,
  body[data-nav-collapsed="true"] #mainNavigation {
    width: 100%;
    align-items: center;
  }

  body[data-nav-collapsed="true"] #mainNavigation .nav-primary .nav-item,
  body[data-nav-collapsed="true"] #mainNavigation .nav-more-trigger {
    display: grid !important;
    grid-template-columns: 1fr !important;
    justify-items: center !important;
    align-items: center !important;
    width: 44px !important;
    min-width: 44px !important;
    max-width: 44px !important;
    margin-inline: auto !important;
    padding: 0 !important;
  }

  body[data-nav-collapsed="true"] #mainNavigation .nav-primary .nav-item-icon,
  body[data-nav-collapsed="true"] #mainNavigation .nav-more-trigger .nav-item-icon,
  body[data-nav-collapsed="true"] .sidebar #mainNavigation .nav-primary .nav-item > span.nav-item-icon,
  body[data-nav-collapsed="true"] .sidebar #mainNavigation .nav-more-trigger > span.nav-item-icon {
    width: auto !important;
    min-width: 0 !important;
    max-width: none !important;
    margin: 0 !important;
    text-align: center !important;
    justify-self: center !important;
  }

  #mainNavigation .nav-item-icon {
    width: 28px;
    text-align: center;
    color: #72def4;
    font-size: 18px;
  }

  #mainNavigation .nav-item:hover,
  #mainNavigation .nav-item:focus-visible,
  #mainNavigation .nav-more-trigger:hover,
  #mainNavigation .nav-more-trigger:focus-visible {
    color: #fff;
    background: rgba(255, 255, 255, .07);
    outline: none;
  }

  #mainNavigation .nav-item:focus-visible,
  #mainNavigation .nav-more-trigger:focus-visible,
  body > .nav-more-panel .nav-item:focus-visible,
  .add-button:focus-visible,
  .nav-more-close:focus-visible {
    outline: 2px solid var(--cs-nav-active);
    outline-offset: 2px;
  }

  /* Active page (current destination) — only filled item: stronger accent tint + bar. */
  #mainNavigation .nav-item.active,
  #mainNavigation .nav-item[aria-current="page"],
  #mainNavigation .nav-more-trigger.is-current,
  #mainNavigation .nav-more-trigger[aria-current="page"] {
    color: #fff;
    background: linear-gradient(90deg, rgba(111, 230, 255, .28), rgba(91, 116, 178, .38));
    box-shadow: inset 3px 0 0 var(--cs-nav-active);
  }

  body[data-nav-collapsed="true"] #mainNavigation .nav-item.active,
  body[data-nav-collapsed="true"] #mainNavigation .nav-item[aria-current="page"],
  body[data-nav-collapsed="true"] #mainNavigation .nav-more-trigger.is-current,
  body[data-nav-collapsed="true"] #mainNavigation .nav-more-trigger[aria-current="page"] {
    box-shadow: inset 0 -2px 0 var(--cs-nav-active);
  }

  /* Open More — no fill; full ink + aria-expanded only. */
  #mainNavigation .nav-more-trigger[aria-expanded="true"]:not(.is-current):not([aria-current="page"]) {
    color: var(--cs-nav-ink);
    border-color: transparent;
    background: transparent;
    box-shadow: none;
  }

  #mainNavigation .nav-more-trigger[aria-expanded="true"]:not(.is-current):not([aria-current="page"]) .nav-item-icon,
  #mainNavigation .nav-more-trigger[aria-expanded="true"]:not(.is-current):not([aria-current="page"]) .nav-item-label {
    color: var(--cs-nav-ink);
  }

  #mainNavigation .nav-more-trigger[aria-expanded="true"].is-current,
  #mainNavigation .nav-more-trigger[aria-expanded="true"][aria-current="page"] {
    /* Current More destination keeps active fill; open is implied by panel. */
    border-color: transparent;
  }

  /* Desktop More: fixed adjacent panel (sizing refined below with row overrides). */
  .nav-more-panel[hidden] {
    display: none !important;
  }

  .nav-more-scrim[hidden] {
    display: none !important;
  }

  .nav-more-scrim:not([hidden]) {
    display: block !important;
    position: fixed;
    inset: 0;
    z-index: 205;
    border: 0;
    background: rgba(8, 18, 43, .28);
    cursor: pointer;
  }

  .nav-more-panel-title {
    margin: 0;
    color: #f2f6ff;
    font: 800 12px/1 Manrope, sans-serif;
    letter-spacing: .1em;
    text-transform: uppercase;
  }

  .nav-more-close {
    min-height: 36px;
    padding: 0 10px;
    border: 1px solid rgba(132, 160, 225, .24);
    border-radius: 8px;
    background: transparent;
    color: var(--cs-nav-muted);
    font: 700 12px/1 "DM Sans", sans-serif;
    cursor: pointer;
  }

  /* Desktop More rows: beat shell-nav-v28 `span { width:28px }` so labels stay one line.
     Also beat collapsed primary centering so panel rows stay icon+label left-aligned. */
  body > .nav-more-panel .nav-item,
  #mainNavigation .nav-more-panel .nav-item,
  body .sidebar .nav-more-panel .nav-item,
  body[data-theme] .sidebar .nav-more-panel .nav-item,
  body[data-nav-collapsed="true"] #mainNavigation .nav-more-panel .nav-item,
  body[data-nav-collapsed="true"] .sidebar .nav-more-panel .nav-item {
    display: grid !important;
    grid-template-columns: 28px minmax(0, 1fr) max-content !important;
    align-items: center !important;
    justify-items: stretch !important;
    gap: 10px !important;
    width: 100% !important;
    min-height: 40px !important;
    margin: 0 !important;
    padding: 6px 8px !important;
    border: 0 !important;
    border-radius: 8px !important;
    background: transparent !important;
    color: #e7edfb !important;
    font: 600 14px/1.25 "DM Sans", sans-serif !important;
    text-align: left !important;
    overflow: hidden !important;
  }

  body > .nav-more-panel .nav-item:hover,
  body > .nav-more-panel .nav-item:focus-visible,
  #mainNavigation .nav-more-panel .nav-item:hover,
  #mainNavigation .nav-more-panel .nav-item:focus-visible {
    background: rgba(255, 255, 255, .06) !important;
  }

  body > .nav-more-panel .nav-item.active,
  body > .nav-more-panel .nav-item[aria-current="page"],
  #mainNavigation .nav-more-panel .nav-item.active,
  #mainNavigation .nav-more-panel .nav-item[aria-current="page"] {
    background: rgba(103, 225, 247, .12) !important;
  }

  /* Icon span keeps 28px; label span must NOT inherit shell-nav width:28px. */
  body > .nav-more-panel .nav-item > .nav-item-icon,
  body > .nav-more-panel .nav-item > span.nav-item-icon,
  #mainNavigation .nav-more-panel .nav-item > .nav-item-icon,
  body .sidebar .nav-more-panel .nav-item > .nav-item-icon,
  body .sidebar .nav-more-panel .nav-item > span.nav-item-icon,
  body[data-theme] .sidebar .nav-more-panel .nav-item > span.nav-item-icon {
    width: 28px !important;
    min-width: 28px !important;
    max-width: 28px !important;
    font-size: 16px !important;
    text-align: center !important;
    color: #72def4 !important;
    justify-self: center !important;
  }

  body > .nav-more-panel .nav-item > .nav-item-label,
  body > .nav-more-panel .nav-item > span.nav-item-label,
  #mainNavigation .nav-more-panel .nav-item > .nav-item-label,
  body .sidebar .nav-more-panel .nav-item > .nav-item-label,
  body .sidebar .nav-more-panel .nav-item > span.nav-item-label,
  body[data-theme] .sidebar .nav-more-panel .nav-item > span.nav-item-label,
  body[data-nav-collapsed="true"] .sidebar .nav-more-panel .nav-item > span.nav-item-label,
  body[data-nav-collapsed="true"] #mainNavigation .nav-more-panel .nav-item > .nav-item-label {
    display: block !important;
    width: auto !important;
    min-width: 0 !important;
    max-width: none !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
    font: 600 14px/1.25 "DM Sans", sans-serif !important;
    color: #e7edfb !important;
    text-align: left !important;
    justify-self: stretch !important;
  }

  body > .nav-more-panel .nav-item > .nav-sync-badge,
  #mainNavigation .nav-more-panel .nav-item > .nav-sync-badge {
    position: static !important;
    width: max-content !important;
  }

  /* Compact desktop More panel so Sync Health + legal fit without scroll at 1024×768. */
  .nav-more-panel {
    position: fixed;
    left: calc(var(--cs-nav-expanded-width) + 8px);
    top: 56px;
    z-index: 210;
    display: grid;
    gap: 4px;
    width: min(300px, calc(100vw - var(--cs-nav-expanded-width) - 24px));
    max-height: min(calc(100vh - 72px), 680px);
    margin: 0;
    padding: 10px;
    border: 1px solid var(--cs-nav-border);
    border-radius: 14px;
    background: var(--cs-nav-panel);
    box-shadow: 0 12px 28px rgba(6, 14, 36, .28);
    overflow: auto;
    overscroll-behavior: contain;
  }

  body[data-nav-collapsed="true"] .nav-more-panel {
    left: calc(var(--cs-nav-collapsed-width) + 8px);
    width: min(300px, calc(100vw - var(--cs-nav-collapsed-width) - 24px));
  }

  .nav-more-section {
    display: grid;
    gap: 1px;
  }

  .nav-more-heading {
    margin: 2px 2px 0;
    width: auto !important;
    max-width: none !important;
    color: rgba(183, 201, 193, .78);
    font: 800 10px/1.2 Manrope, sans-serif;
    letter-spacing: .12em;
    text-transform: uppercase;
  }

  .nav-more-panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 2px;
  }

  .nav-more-panel .mobile-menu-links {
    display: flex !important;
    justify-content: space-evenly;
    align-items: center;
    gap: 4px;
    width: 100%;
    margin: 2px 0 0;
    padding: 2px 0 0;
    border-top: 1px solid rgba(157, 177, 224, .18);
  }

  .nav-more-panel .mobile-menu-links a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: auto !important;
    min-width: 0 !important;
    min-height: 44px;
    padding: 0 8px;
    color: #c7d2ea;
    font-size: 12px;
    font-weight: 650;
    text-decoration: none;
    white-space: nowrap;
  }

  /* Sidebar footer legal links also need ≥44px targets (override shell-nav 32px). */
  body .sidebar .app-legal-links a,
  body[data-theme] .sidebar .app-legal-links a {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    width: auto !important;
    min-width: 0 !important;
    min-height: 44px !important;
    padding: 0 4px !important;
    font-size: 12px !important;
  }

  /* Fine pointers can use the WCAG 2.5.8 24px floor. 28px cuts the ink gap
     under the session note without shrinking coarse/touch targets. */
  @media (pointer: fine) {
    body .sidebar .app-legal-links a,
    body[data-theme] .sidebar .app-legal-links a {
      min-height: 28px !important;
    }
  }

  /* Expanded: labelled + Add. Collapsed: compact 44px +. */
  body .sidebar .add-button,
  body[data-theme] .sidebar .add-button {
    position: static !important;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    align-self: center;
    gap: 8px;
    width: fit-content;
    min-width: 44px;
    min-height: 44px;
    height: 44px;
    margin: 0;
    padding: 0 16px;
    border: 2px solid rgba(255, 255, 255, .88);
    border-radius: 12px !important;
    background: linear-gradient(145deg, #73ddf5, #55c4e7);
    color: #10214c;
    font: 800 15px/1 Manrope, sans-serif;
    letter-spacing: .01em;
    box-shadow: none;
    left: auto !important;
    right: auto !important;
    bottom: auto !important;
    white-space: nowrap;
  }

  body .sidebar .add-button .add-button-glyph {
    font-size: 20px;
    line-height: 1;
    font-weight: 800;
  }

  body .sidebar .add-button .add-button-label {
    display: inline;
    font: inherit;
  }

  body[data-nav-collapsed="true"] .sidebar .add-button {
    width: 44px;
    min-width: 44px;
    max-width: 44px;
    padding: 0;
    gap: 0;
  }

  body[data-nav-collapsed="true"] .sidebar .add-button .add-button-label {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  .nav-primary .mobile-menu-links {
    display: none;
  }
}

/* ---------- Mobile bottom bar ---------- */
@media (max-width: 720px) {
  :root {
    --cs-mobile-safe-bottom: calc(
      var(--cs-bottom-nav-height) + var(--cs-bottom-nav-pad) + env(safe-area-inset-bottom, 0px)
    );
  }

  body .shell,
  body[data-theme] .shell {
    display: block !important;
  }

  body main,
  body[data-theme] main {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 auto !important;
    padding-bottom: var(--cs-mobile-safe-bottom) !important;
  }

  .nav-collapse-toggle {
    display: none !important;
  }

  body .sidebar,
  body[data-theme] .sidebar {
    position: static !important;
    inset: auto !important;
    width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    overflow: visible !important;
    display: block !important;
    pointer-events: none;
  }

  .sidebar .brand,
  .sidebar .privacy-note,
  body .sidebar .app-legal-links,
  body[data-theme] .sidebar .app-legal-links,
  .sidebar .sidebar-dock .privacy-note,
  .sidebar .sidebar-dock .app-legal-links,
  .sidebar .sidebar-dock .build-version-button,
  #menuTrustAccounts {
    display: none !important;
  }

  #mainNavigation,
  body .sidebar nav,
  body[data-theme] .sidebar nav {
    position: static !important;
    inset: auto !important;
    left: auto !important;
    right: auto !important;
    bottom: auto !important;
    top: auto !important;
    width: auto !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    border-radius: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    overflow: visible !important;
    opacity: 1 !important;
    visibility: visible !important;
    transform: none !important;
    pointer-events: none !important;
    display: block !important;
  }

  .nav-primary {
    position: fixed;
    z-index: var(--cs-nav-z-bottom);
    left: 0;
    right: 0;
    bottom: 0;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    align-items: stretch;
    gap: 0;
    width: 100%;
    min-height: calc(var(--cs-bottom-nav-height) + env(safe-area-inset-bottom, 0px));
    padding: 4px 4px calc(4px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid rgba(132, 160, 225, .28);
    background: linear-gradient(180deg, #101a39, #0b1735);
    box-shadow: 0 -10px 28px rgba(7, 20, 54, .28);
    pointer-events: auto;
  }

  #mainNavigation .nav-item[data-view="dashboard"],
  #mainNavigation .nav-item[data-view="calendar"],
  #mainNavigation .nav-item[data-view="transactions"],
  #mainNavigation .nav-item[data-view="insights"],
  #mainNavigation .nav-more-trigger {
    display: grid !important;
    grid-template-columns: 1fr !important;
    grid-template-rows: auto auto !important;
    justify-items: center;
    align-content: center;
    gap: 2px;
    width: 100%;
    max-width: 100%;
    min-height: 44px;
    min-width: 0;
    margin: 0;
    padding: 4px 1px;
    border: 0 !important;
    border-radius: 10px;
    background: transparent;
    color: var(--cs-nav-muted);
    font: 700 11px/1.05 Manrope, sans-serif;
    letter-spacing: 0;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    overflow: visible;
    box-sizing: border-box;
  }

  #mainNavigation .nav-item-icon {
    width: auto !important;
    font-size: 16px;
    color: #72def4;
    line-height: 1;
  }

  #mainNavigation .nav-primary .nav-item-label,
  #mainNavigation .nav-more-trigger .nav-item-label {
    display: block !important;
    width: auto !important;
    max-width: 100%;
    overflow: visible;
    text-overflow: clip;
    white-space: nowrap;
    text-align: center;
    font-size: 11px;
    line-height: 1.1;
  }

  /* Active page on bottom bar — only filled item: stronger accent + top bar. */
  #mainNavigation .nav-primary .nav-item.active,
  #mainNavigation .nav-primary .nav-item[aria-current="page"],
  #mainNavigation .nav-more-trigger.is-current,
  #mainNavigation .nav-more-trigger[aria-current="page"] {
    color: #fff;
    background: rgba(103, 225, 247, .26);
    box-shadow: inset 0 2px 0 var(--cs-nav-active);
    border-color: transparent;
  }

  #mainNavigation .nav-primary .nav-item.active .nav-item-icon,
  #mainNavigation .nav-primary .nav-item[aria-current="page"] .nav-item-icon,
  #mainNavigation .nav-more-trigger.is-current .nav-item-icon,
  #mainNavigation .nav-more-trigger[aria-current="page"] .nav-item-icon,
  #mainNavigation .nav-primary .nav-item.active .nav-item-label,
  #mainNavigation .nav-primary .nav-item[aria-current="page"] .nav-item-label,
  #mainNavigation .nav-more-trigger.is-current .nav-item-label,
  #mainNavigation .nav-more-trigger[aria-current="page"] .nav-item-label {
    color: var(--cs-nav-active);
  }

  /* Open More — no fill; full ink + aria-expanded only. */
  #mainNavigation .nav-more-trigger[aria-expanded="true"]:not(.is-current):not([aria-current="page"]) {
    color: var(--cs-nav-ink);
    background: transparent;
    border-color: transparent;
    box-shadow: none;
  }

  #mainNavigation .nav-more-trigger[aria-expanded="true"]:not(.is-current):not([aria-current="page"]) .nav-item-icon,
  #mainNavigation .nav-more-trigger[aria-expanded="true"]:not(.is-current):not([aria-current="page"]) .nav-item-label {
    color: var(--cs-nav-ink);
  }

  #mainNavigation .nav-item:focus-visible,
  #mainNavigation .nav-more-trigger:focus-visible {
    outline: 2px solid var(--cs-nav-active);
    outline-offset: -2px;
  }

  .nav-more-scrim:not([hidden]) {
    display: block !important;
    position: fixed;
    inset: 0;
    z-index: var(--cs-nav-z-scrim);
    border: 0;
    background: rgba(8, 18, 43, .42);
    backdrop-filter: blur(2px);
    pointer-events: auto;
    cursor: pointer;
  }

  .nav-more-scrim[hidden] {
    display: none !important;
  }

  .nav-more-panel {
    position: fixed;
    z-index: var(--cs-nav-z-more);
    left: 10px;
    right: 10px;
    bottom: calc(var(--cs-bottom-nav-height) + env(safe-area-inset-bottom, 0px) + 8px);
    display: grid;
    gap: 4px;
    max-height: min(78dvh, calc(100dvh - var(--cs-bottom-nav-height) - env(safe-area-inset-bottom, 0px) - 20px));
    padding: 10px 10px 8px;
    border: 1px solid var(--cs-nav-border);
    border-radius: 16px;
    background: var(--cs-nav-panel);
    box-shadow: 0 18px 48px rgba(6, 14, 36, .4);
    overflow: auto;
    overscroll-behavior: contain;
    pointer-events: auto;
  }

  .nav-more-panel[hidden] {
    display: none !important;
  }

  .nav-more-panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  .nav-more-panel-title {
    margin: 0;
    color: #f2f6ff;
    font: 800 11px/1 Manrope, sans-serif;
    letter-spacing: .1em;
    text-transform: uppercase;
  }

  .nav-more-close {
    min-height: 44px;
    min-width: 44px;
    padding: 0 12px;
    border: 1px solid rgba(132, 160, 225, .24);
    border-radius: 10px;
    background: transparent;
    color: var(--cs-nav-muted);
    font: 700 13px/1 "DM Sans", sans-serif;
    cursor: pointer;
  }

  .nav-more-section {
    display: grid;
    gap: 1px;
  }

  .nav-more-heading {
    margin: 4px 4px 0;
    color: rgba(183, 201, 193, .78);
    font: 800 10px/1.2 Manrope, sans-serif;
    letter-spacing: .12em;
    text-transform: uppercase;
  }

  /* Compact More rows: normal body text, icon + label, ≥44px.
     Override legacy mobile-menu card chrome with !important. */
  #mainNavigation .nav-more-panel .nav-item,
  body .sidebar .nav-more-panel .nav-item,
  body[data-theme] .sidebar .nav-more-panel .nav-item {
    display: grid !important;
    grid-template-columns: 24px minmax(0, 1fr) max-content !important;
    grid-template-rows: auto !important;
    align-items: center !important;
    justify-items: stretch !important;
    gap: 10px !important;
    width: 100% !important;
    min-height: 44px !important;
    height: auto !important;
    margin: 0 !important;
    padding: 7px 8px !important;
    border: 0 !important;
    border-radius: 8px !important;
    background: transparent !important;
    box-shadow: none !important;
    color: #e7edfb !important;
    font: 600 15px/1.25 "DM Sans", sans-serif !important;
    text-align: left !important;
    overflow: hidden !important;
  }

  #mainNavigation .nav-more-panel .nav-item:hover,
  #mainNavigation .nav-more-panel .nav-item:focus-visible {
    background: rgba(255, 255, 255, .06) !important;
  }

  #mainNavigation .nav-more-panel .nav-item.active,
  #mainNavigation .nav-more-panel .nav-item[aria-current="page"] {
    background: rgba(103, 225, 247, .12) !important;
  }

  #mainNavigation .nav-more-panel .nav-item-icon,
  body .sidebar .nav-more-panel .nav-item-icon {
    width: 24px !important;
    font-size: 15px !important;
    text-align: center !important;
    color: #72def4 !important;
  }

  #mainNavigation .nav-more-panel .nav-item-label,
  body .sidebar .nav-more-panel .nav-item-label {
    display: -webkit-box !important;
    width: auto !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: normal !important;
    -webkit-box-orient: vertical !important;
    -webkit-line-clamp: 2 !important;
    line-clamp: 2 !important;
    font: 600 15px/1.25 "DM Sans", sans-serif !important;
    color: #e7edfb !important;
    text-align: left !important;
  }

  /* Reinforce active vs open so legacy chrome cannot re-apply accent rings. */
  #mainNavigation .nav-primary .nav-item.active,
  #mainNavigation .nav-primary .nav-item[aria-current="page"],
  #mainNavigation .nav-more-trigger.is-current,
  #mainNavigation .nav-more-trigger[aria-current="page"] {
    color: #fff !important;
    background: rgba(103, 225, 247, .26) !important;
    border-color: transparent !important;
    box-shadow: inset 0 2px 0 var(--cs-nav-active) !important;
  }

  #mainNavigation .nav-more-trigger[aria-expanded="true"]:not(.is-current):not([aria-current="page"]) {
    color: var(--cs-nav-ink) !important;
    background: transparent !important;
    border-color: transparent !important;
    box-shadow: none !important;
    outline: none;
  }

  /* Compact sticky footer row so Privacy/Terms/Support stay reachable. */
  #mainNavigation .nav-more-panel .mobile-menu-links,
  .nav-more-panel .mobile-menu-links {
    display: flex !important;
    justify-content: space-evenly;
    align-items: center;
    gap: 4px;
    width: 100%;
    margin: 2px 0 0;
    padding: 6px 2px 2px;
    border-top: 1px solid rgba(157, 177, 224, .18);
    position: sticky;
    bottom: 0;
    z-index: 2;
    background: linear-gradient(180deg, rgba(12, 21, 44, .92), #0c152c 40%);
  }

  .nav-more-panel .mobile-menu-links a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 0 8px;
    color: #c7d2ea;
    font-size: 12px;
    font-weight: 650;
    text-decoration: none;
    white-space: nowrap;
  }

  body .sidebar .add-button,
  body[data-theme] .sidebar .add-button {
    position: fixed !important;
    z-index: 35;
    left: auto !important;
    right: 14px !important;
    bottom: calc(var(--cs-bottom-nav-height) + env(safe-area-inset-bottom, 0px) + 12px) !important;
    top: auto !important;
    display: grid !important;
    place-items: center;
    width: 48px !important;
    height: 48px !important;
    min-width: 44px;
    min-height: 44px;
    margin: 0;
    padding: 0;
    gap: 0;
    border: 2px solid rgba(255, 255, 255, .92);
    border-radius: 16px !important;
    background: linear-gradient(145deg, #73ddf5, #55c4e7);
    color: #10214c;
    font: 800 24px/1 Manrope, sans-serif;
    box-shadow: 0 10px 24px rgba(9, 26, 65, .28);
    pointer-events: auto;
    touch-action: manipulation;
  }

  body .sidebar .add-button .add-button-glyph {
    font-size: 24px;
    line-height: 1;
  }

  body .sidebar .add-button .add-button-label {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  body .sidebar .add-button::before,
  body .sidebar .add-button::after {
    content: none !important;
  }

  /* Clear bottom bar (56) + gap (12) + FAB (48) + buffer so content isn't covered. */
  body main,
  body[data-theme] main {
    padding-bottom: calc(
      var(--cs-bottom-nav-height) + 12px + 48px + 16px + env(safe-area-inset-bottom, 0px)
    ) !important;
  }

  .mobile-legal-links {
    display: none !important;
  }
}

/* Themes */
body[data-theme="cloud"] .nav-more-panel,
body[data-theme="midnight"] .nav-more-panel {
  border-color: rgba(132, 160, 225, .3);
}

/* Midnight bottom bar only — never paint a block behind desktop primary icons. */
@media (max-width: 720px) {
  body[data-theme="midnight"] .nav-primary {
    background: linear-gradient(180deg, #12172a, #0a0e1c);
  }
}

@media (min-width: 721px) {
  body[data-theme="midnight"] .nav-primary,
  body[data-theme="midnight"] #mainNavigation,
  body[data-theme="cloud"] .nav-primary,
  body[data-theme="cloud"] #mainNavigation {
    background: transparent !important;
  }
}

body[data-theme="midnight"] #mainNavigation .nav-item.active,
body[data-theme="midnight"] #mainNavigation .nav-item[aria-current="page"],
body[data-theme="midnight"] #mainNavigation .nav-more-trigger.is-current,
body[data-theme="midnight"] #mainNavigation .nav-more-trigger[aria-current="page"] {
  background: rgba(116, 71, 237, .22);
  box-shadow: inset 0 2px 0 #a78bfa;
}

body[data-theme="midnight"] #mainNavigation .nav-more-trigger[aria-expanded="true"]:not(.is-current):not([aria-current="page"]) {
  color: var(--cs-nav-ink);
  background: transparent;
  border-color: transparent;
  box-shadow: none;
}

@media (min-width: 721px) {
  body[data-theme="midnight"] #mainNavigation .nav-item.active,
  body[data-theme="midnight"] #mainNavigation .nav-item[aria-current="page"],
  body[data-theme="midnight"] #mainNavigation .nav-more-trigger.is-current,
  body[data-theme="midnight"] #mainNavigation .nav-more-trigger[aria-current="page"] {
    box-shadow: inset 3px 0 0 #a78bfa;
  }

  body[data-nav-collapsed="true"][data-theme="midnight"] #mainNavigation .nav-item.active,
  body[data-nav-collapsed="true"][data-theme="midnight"] #mainNavigation .nav-item[aria-current="page"],
  body[data-nav-collapsed="true"][data-theme="midnight"] #mainNavigation .nav-more-trigger.is-current,
  body[data-nav-collapsed="true"][data-theme="midnight"] #mainNavigation .nav-more-trigger[aria-current="page"] {
    box-shadow: inset 0 -2px 0 #a78bfa;
  }
}

body.nav-more-open {
  /* Desktop: do not lock body scroll — it breaks sticky rail positioning. */
}

@media (max-width: 720px) {
  body.nav-more-open {
    overflow: hidden;
  }
}

/* focusPageLandmark() moves focus to the page heading on every route change,
   including mouse navigation, so the default ring painted a black rectangle
   around "Recurring" after a click. The focus move stays — screen readers still
   land on the new heading — and only the ring becomes keyboard-only. */
#pageTitle[tabindex="-1"]:focus,
main[tabindex="-1"]:focus {
  outline: none;
}

#pageTitle[tabindex="-1"]:focus-visible,
main[tabindex="-1"]:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--green) 55%, var(--ink));
  outline-offset: 4px;
  border-radius: 6px;
}
