/* ☰ The section menu (navmenu.js): the top bar goes compact when the sections don't fit on one line
   next to the brand and the chips; the chips get smaller a step at a time (data-chips on the bar).
   ☀️ Tasks' lists on a phone use the same panel under their button (.list-menu, at the end). */

/* Measured (navmenu.js runs): the sections stay on one line, or they go into the ☰. */
.topbar.nav-measured .nav { flex-wrap: nowrap; min-width: 0; }
.topbar.nav-measured .nav-btn { flex-shrink: 0; }

/* ---------- compact: the ☰ instead of the sections ---------- */

.nav-menu-btn { display: none; flex-shrink: 0; align-items: center; justify-content: center; width: 2.25rem; height: 2.25rem; padding: 0; border: 0; border-radius: 999px; background: none; color: var(--text-2); cursor: pointer; }
.nav-menu-btn svg { fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; }
.nav-menu-btn:hover { background: var(--surface-2); color: var(--text); }
.nav-menu-btn[aria-expanded="true"] { background: var(--accent-soft); color: var(--accent-text); }
.topbar.nav-compact .nav-menu-btn { display: inline-flex; }
/* The sections are still there to measure, out of sight (and out of reach of Tab and screen readers). */
.topbar.nav-compact .nav { position: absolute; left: 0; top: 0; width: 0; height: 0; overflow: hidden; visibility: hidden; pointer-events: none; }
.topbar.nav-compact .top-tools { margin-left: auto; }
body.logged-out .nav-menu-btn, body.in-setup .nav-menu-btn, body.logged-out .nav-menu, body.in-setup .nav-menu { display: none !important; }

/* ---------- the panel: drops down under the ☰ ---------- */

.nav-menu {
  position: absolute; z-index: 5; top: calc(100% + 6px); left: var(--nav-menu-x, 1rem);
  min-width: 220px; max-width: calc(100vw - 16px); max-height: calc(100vh - 5rem); overflow-y: auto; overscroll-behavior: contain;
  display: flex; flex-direction: column; gap: 2px; padding: .35rem;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  transform-origin: top left;
  animation: nav-menu-in .18s cubic-bezier(.2, .8, .3, 1);
}
.nav-menu.closing { animation: nav-menu-out .14s ease-in forwards; pointer-events: none; }
.nav-menu-item { display: flex; align-items: center; gap: .7rem; width: 100%; padding: .6rem .75rem; border: 0; border-radius: var(--radius-sm); background: none; color: var(--text); font: 600 .95rem var(--font); text-align: left; cursor: pointer; }
.nav-menu-item:hover, .nav-menu-item:focus-visible { background: var(--surface-2); }
.nav-menu-item:focus-visible { outline-offset: -2px; }
.nav-menu-item[aria-current="page"] { background: var(--accent-soft); color: var(--accent-text); }
.nav-menu-item[aria-current="page"]::after { content: '✓'; margin-left: auto; padding-left: .75rem; font-weight: 700; }
.nav-menu-ico { width: 1.4rem; flex-shrink: 0; text-align: center; font-size: 1.05rem; line-height: 1; }
.nav-menu-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@keyframes nav-menu-in { from { opacity: 0; transform: translateY(-6px) scale(.97); } to { opacity: 1; transform: none; } }
@keyframes nav-menu-out { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateY(-4px) scale(.98); } }
@keyframes nav-menu-fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes nav-menu-fade-out { from { opacity: 1; } to { opacity: 0; } }
html[data-fx="subtle"] .nav-menu { animation: nav-menu-fade-in .12s ease-out; }
html[data-fx="subtle"] .nav-menu.closing { animation: nav-menu-fade-out .1s ease-in forwards; }
html[data-fx="off"] .nav-menu, html[data-fx="off"] .nav-menu.closing { animation: none; }

/* ---------- the chips, a step smaller each time they don't fit ---------- */

/* 1: the weather's city and low, the level's title, your name, "Help" */
.topbar[data-chips] .wx-city, .topbar[data-chips] .wx-low, .topbar[data-chips] .lv-title,
.topbar[data-chips] .acct-name, .topbar[data-chips] .help-btn-label { display: none; }
/* 2 (and after): the weather is its icon and the high, the level "Lv 32" */
.topbar[data-chips="2"] .wx-pop, .topbar[data-chips="3"] .wx-pop, .topbar[data-chips="4"] .wx-pop,
.topbar[data-chips="2"] .lv-ring, .topbar[data-chips="3"] .lv-ring, .topbar[data-chips="4"] .lv-ring { display: none; }
.topbar[data-chips="2"] #level-chip, .topbar[data-chips="3"] #level-chip, .topbar[data-chips="4"] #level-chip { padding-left: .5rem; }
.topbar[data-chips="2"] .top-tools, .topbar[data-chips="3"] .top-tools, .topbar[data-chips="4"] .top-tools { gap: .25rem; }
.topbar[data-chips="2"] .top-tools .chip, .topbar[data-chips="3"] .top-tools .chip, .topbar[data-chips="4"] .top-tools .chip { padding-left: .4rem; padding-right: .4rem; }
.topbar[data-chips="2"] .nav-menu-btn, .topbar[data-chips="3"] .nav-menu-btn, .topbar[data-chips="4"] .nav-menu-btn { width: 2rem; }
/* 3: the logo without the name (still there for screen readers), a little closer to the edges */
.topbar[data-chips="3"] { column-gap: .5rem; padding-left: max(.75rem, env(safe-area-inset-left)); padding-right: max(.75rem, env(safe-area-inset-right)); }
.topbar[data-chips="3"] .screen-title { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
/* 4 (the narrowest phones): the chips on a row of their own */
.topbar[data-chips="4"] { flex-wrap: wrap; row-gap: .45rem; }
.topbar[data-chips="4"] .top-tools { flex-basis: 100%; justify-content: flex-end; margin-left: 0; }

/* ---------- phones: the panel across the screen, under the bar ---------- */

@media (max-width: 600px) {
  .topbar { position: relative; } /* (it doesn't stick on phones; the panel hangs from it) */
  .nav-menu {
    top: 100%; left: 0; right: 0; min-width: 0; max-width: none;
    border-width: 0 0 1px; border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    padding: .4rem max(.6rem, env(safe-area-inset-right)) .6rem max(.6rem, env(safe-area-inset-left));
    transform-origin: top center;
  }
  .nav-menu-item { padding: .75rem .8rem; font-size: 1rem; }
}

/* ---------- ☀️ Tasks' lists on a phone: the same panel, across the list under its button ---------- */

.nav-menu.list-menu {
  z-index: 40; top: calc(100% + 6px); left: 0; right: 0; min-width: 0; max-width: none;
  border-width: 1px; border-radius: var(--radius-lg); padding: .35rem; transform-origin: top left;
}
.nav-menu.list-menu.still { animation: none; } /* (drawn again while open: it doesn't drop in again) */
.list-menu-item .list-count { font-size: .85rem; }
.list-menu-item[aria-current] { background: var(--accent-soft); color: var(--accent-text); }
.list-menu-item[aria-current] .list-count { color: inherit; }
/* The list you're on: ✓ at the end (every item keeps its place, so the counts line up). */
.list-menu-item::after { content: ''; flex-shrink: 0; width: 1rem; text-align: center; font-weight: 700; }
.list-menu-item[aria-current]::after { content: '✓'; }
/* 🗑️ Trash: set apart from the lists, as in the sidebar. */
.list-menu-trash { position: relative; margin-top: .45rem; }
.list-menu-trash::before { content: ''; position: absolute; left: .75rem; right: .75rem; top: -.3rem; border-top: 1px solid var(--border); }
@media (min-width: 761px) {
  .nav-menu.list-menu { display: none !important; } /* (wide: the sidebar has them) */
}

@media (prefers-reduced-motion: reduce) {
  .nav-menu, .nav-menu.closing { animation: none; }
}
@media print {
  .nav-menu-btn, .nav-menu { display: none !important; }
}
