/* Phone bottom bar (≤720px): "floating bubble" tab bar.
   One accent bubble sits half above the bar over the current page and slides
   between items (nav-bubble-v1.js). The bar, the five buttons, their routes,
   click handlers and aria-current are untouched; this is look and motion only.
   Tokens: --green is the accent (DESIGN.md), --paper the page background,
   --cs-nav-bar / --cs-nav-idle the bar (nav-redesign-v30.css). */

@media (max-width: 720px) {
  :root {
    --cs-nav-bar-height: 56px;
    --cs-nav-bubble-size: 54px;
    --cs-nav-bubble-rise: 22px;
    --cs-nav-spring: cubic-bezier(.34, 1.56, .64, 1);
    /* Everything that clears the bar (page padding, Quick Add, the Calendar
       day bar, the More panel) also clears the bubble sticking up above it. */
    --cs-nav-bubble-ring: 6px;
    /* The bar floats this far above the safe area (iOS 26 Safari's address bar,
       the home indicator), like the system Liquid Glass tab bar. */
    --cs-nav-float-gap: 8px;
    --cs-bottom-nav-height: calc(var(--cs-nav-bar-height) + var(--cs-nav-bubble-rise) + var(--cs-nav-bubble-ring) + var(--cs-nav-float-gap));
    /* Accent label on the dark bar: the raw accent is ~3.1:1 on #0f1b3d, so
       it is lightened toward white (≈7:1; midnight ≈8.5:1). */
    --cs-nav-bubble-label: color-mix(in srgb, var(--green) 55%, #fff);
  }

  /* A floating, rounded bar inside the safe area. Full-width to the screen edge,
     it ran under iOS 26 Safari's floating address bar as a dark slab. */
  #mainNavigation .nav-primary {
    left: 8px;
    right: 8px;
    bottom: calc(env(safe-area-inset-bottom, 0px) + var(--cs-nav-float-gap));
    width: auto;
    min-height: var(--cs-nav-bar-height);
    padding: 4px 2px;
    border-top: 0;
    border-radius: 20px;
    box-shadow: 0 10px 28px rgba(7, 20, 54, .30), 0 0 0 1px rgba(132, 160, 225, .18);
  }

  /* Quick Add stays where it was on screen: the float gap is already empty
     space under the bar, so it sits 12px above the bubble minus that gap (4px
     plus the 6px ring). Raising it 8px covered Available on 568px-tall phones. */
  body .sidebar .add-button,
  body[data-theme] .sidebar .add-button {
    bottom: calc(var(--cs-bottom-nav-height) - var(--cs-nav-float-gap) + env(safe-area-inset-bottom, 0px) + 12px) !important;
  }

  body[data-theme="midnight"] #mainNavigation .nav-primary {
    box-shadow: 0 10px 28px rgba(0, 0, 0, .5), 0 0 0 1px rgba(132, 160, 225, .14);
  }

  /* Flat items: icon over label, muted; no pill behind the active icon. */
  #mainNavigation .nav-primary .nav-item-icon,
  #mainNavigation .nav-more-trigger .nav-item-icon,
  #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,
  body[data-theme="midnight"] #mainNavigation .nav-primary .nav-item.active .nav-item-icon,
  body[data-theme="midnight"] #mainNavigation .nav-primary .nav-item[aria-current="page"] .nav-item-icon,
  body[data-theme="midnight"] #mainNavigation .nav-more-trigger.is-current .nav-item-icon,
  body[data-theme="midnight"] #mainNavigation .nav-more-trigger[aria-current="page"] .nav-item-icon {
    position: relative;
    background: transparent;
    box-shadow: none;
    transition: opacity .2s ease-out, transform .3s var(--cs-nav-spring), color .16s ease-out;
  }

  #mainNavigation .nav-primary .nav-item-label,
  #mainNavigation .nav-more-trigger .nav-item-label {
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }

  /* The current item's own icon lifts away: the same icon is in the bubble. */
  #mainNavigation .nav-primary.has-bubble .nav-item[aria-current="page"] .nav-item-icon,
  #mainNavigation .nav-primary.has-bubble .nav-more-trigger[aria-current="page"] .nav-item-icon {
    opacity: 0;
    transform: translateY(-14px);
  }

  #mainNavigation .nav-primary .nav-item[aria-current="page"] .nav-item-label,
  #mainNavigation .nav-more-trigger[aria-current="page"] .nav-item-label {
    color: var(--cs-nav-bubble-label) !important;
    font-weight: 700;
  }

  /* The bubble: never takes a grid cell, never takes a tap. */
  #mainNavigation .nav-bubble {
    position: absolute;
    z-index: 1;
    top: calc(-1 * var(--cs-nav-bubble-rise));
    left: 0;
    display: grid;
    place-items: center;
    width: var(--cs-nav-bubble-size);
    height: var(--cs-nav-bubble-size);
    border-radius: 50%;
    background: var(--green);
    color: #fff;
    /* Ring in the page colour so it reads as cut out of the bar, plus a glow. */
    box-shadow:
      0 0 0 var(--cs-nav-bubble-ring) var(--paper, #f3f6ff),
      0 8px 20px color-mix(in srgb, var(--green) 45%, transparent);
    pointer-events: none;
    transition: transform 550ms var(--cs-nav-spring), opacity .2s ease-out;
    will-change: transform;
  }

  #mainNavigation .nav-bubble[hidden] {
    display: none;
  }

  #mainNavigation .nav-bubble.is-instant {
    transition: none;
  }

  #mainNavigation .nav-bubble-icon {
    position: relative;
    display: grid;
    place-items: center;
    width: 24px;
    height: 24px;
    font-size: 20px;
    line-height: 1;
  }

  #mainNavigation .nav-bubble-icon .nav-svg {
    width: 24px;
    height: 24px;
  }

  #mainNavigation .nav-bubble-icon.is-popping {
    animation: cs-nav-bubble-pop 450ms var(--cs-nav-spring) both;
  }

  /* Badges and dots stay on their icon, in the bar or in the bubble. */
  #mainNavigation .nav-bubble-icon .nav-badge,
  #mainNavigation .nav-bubble-icon .nav-dot,
  #mainNavigation .nav-bubble-icon [data-nav-badge] {
    position: absolute;
    top: -6px;
    right: -8px;
  }

  #mainNavigation .nav-primary.has-bubble [aria-current="page"] > .nav-badge,
  #mainNavigation .nav-primary.has-bubble [aria-current="page"] > .nav-dot,
  #mainNavigation .nav-primary.has-bubble [aria-current="page"] > [data-nav-badge] {
    visibility: hidden;
  }
}

@keyframes cs-nav-bubble-pop {
  from { transform: scale(.4) rotate(-20deg); }
  to { transform: scale(1) rotate(0deg); }
}

@media (max-width: 720px) and (prefers-reduced-motion: reduce) {
  #mainNavigation .nav-bubble,
  #mainNavigation .nav-primary .nav-item-icon,
  #mainNavigation .nav-more-trigger .nav-item-icon {
    transition: none !important;
  }

  #mainNavigation .nav-bubble-icon.is-popping {
    animation: none;
  }
}

/* Small phones: keep the same label room as the old full-width bar (352px of
   cells at 360px) so "Transactions" stays on one line, untruncated. */
@media (max-width: 380px) {
  #mainNavigation .nav-primary {
    left: 4px;
    right: 4px;
    padding-left: 0;
    padding-right: 0;
  }
}
