/* ---------- schermi più larghi ---------- */
@media (min-width: 768px) {
  .topbar { grid-template-columns: minmax(0, auto) 1fr auto; grid-template-areas: "brand badge more"; padding-inline: 24px; }
  #mode-badge { display: inline-flex; grid-area: badge; justify-self: end; }
  .topbar .brand { width: clamp(260px, 30vw, 360px); }
  .btn-icon { width: auto; padding: 0 12px; }
  .bk-day { width: 58px; }
  .drawer-panel { inset: 0 0 0 auto; width: 440px; max-height: none; border-radius: 0; }
}
@media (min-width: 1024px) {
  .view { max-width: 1240px; margin: 0 auto; padding-inline: 24px; }
  .mode-note { max-width: 1192px; margin: 14px auto 0; }
  .layout { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 20px; align-items: start; }
  .sidebar {
    display: block; position: sticky; top: 84px; max-height: calc(100dvh - 100px); overflow-y: auto;
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); padding: 8px;
  }
  /* col mouse le righe dell'elenco possono essere più basse */
  .sidebar .cat-nav a { min-height: 36px; font-size: 0.875rem; }
  .sidebar .cat-nav li[data-depth="2"] > a { font-size: 0.8125rem; }
  .catjump { display: none; }
  #sections > [id^="sec-"] { scroll-margin-top: calc(var(--topbar-h, 65px) + 16px); }
}

/* ---------- albero categorie: elenco a sinistra e pannello dal basso ----------
   Stessa gerarchia della vista Categorie: principali in grassetto e separate da una linea,
   sottocategorie rientrate con una linea guida, terzo livello più piccolo e chiaro. */
.cat-nav { list-style: none; margin: 0; padding: 0; }
.cat-nav li[data-depth="0"]:not(:first-child) { margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--line); }
.cat-nav a {
  position: relative; display: flex; justify-content: space-between; align-items: center; gap: 8px;
  min-height: var(--tap); padding: 0 10px; border-radius: 8px;
  color: var(--text-2); text-decoration: none; font-size: 0.9375rem;
}
.cat-nav-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-nav a:hover { background: var(--surface-2); color: var(--text); }
.cat-nav a:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: -1px; }
.cat-nav a[aria-current="true"] { background: var(--accent-soft); color: var(--accent); }
.cat-nav a[aria-current="true"] .nav-count { background: var(--surface); }
.cat-nav li[data-depth="0"] > a { font-weight: 700; color: var(--text); }
.cat-nav li[data-depth="0"] > a[aria-current="true"] { color: var(--accent); }
.cat-nav li[data-depth="1"] > a { padding-left: 28px; font-weight: 500; }
.cat-nav li[data-depth="2"] > a { padding-left: 46px; font-size: 0.875rem; color: var(--muted); }
.cat-nav li[data-depth="2"] > a[aria-current="true"] { color: var(--accent); }
/* linee guida verticali, una per livello */
.cat-nav li[data-depth="1"] > a::before,
.cat-nav li[data-depth="2"] > a::before,
.cat-nav li[data-depth="2"] > a::after { content: ''; position: absolute; top: 0; bottom: 0; border-left: 1.5px solid var(--line-strong); }
.cat-nav li[data-depth="1"] > a::before, .cat-nav li[data-depth="2"] > a::before { left: 14px; }
.cat-nav li[data-depth="2"] > a::after { left: 32px; }

/* ---------- pannelli dal basso ---------- */
.sheet { position: fixed; inset: 0; z-index: 60; display: grid; align-items: end; }
.sheet[hidden] { display: none; }
.sheet-backdrop { position: absolute; inset: 0; background: rgb(15 23 42 / 45%); animation: sheet-fade .2s ease-out; }
.sheet-panel {
  position: relative; display: flex; flex-direction: column; max-height: 85dvh;
  background: var(--surface); border-radius: 20px 20px 0 0; box-shadow: var(--shadow-lg);
  padding-bottom: var(--sa-b); animation: sheet-up .24s cubic-bezier(.2, .8, .2, 1);
}
/* maniglia: segnala che è un pannello */
.sheet-panel::before { content: ''; align-self: center; width: 40px; height: 4px; margin-top: 8px; border-radius: 4px; background: var(--line-strong); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 12px 8px 20px; }
.sheet-head h2 { margin: 0; font-size: 1.125rem; }
.sheet-body { overflow-y: auto; overscroll-behavior: contain; padding: 4px 12px 16px; }
@keyframes sheet-up { from { transform: translateY(24px); opacity: 0; } }
@keyframes sheet-fade { from { opacity: 0; } }
@media (min-width: 768px) {
  .sheet { align-items: center; justify-items: center; padding: 24px; }
  .sheet-panel { width: min(480px, 100%); max-height: min(80dvh, 720px); border-radius: 18px; }
  .sheet-panel::before { display: none; }
  .sheet-head { padding-top: 14px; }
}
@media (prefers-reduced-motion: reduce) { .sheet-panel, .sheet-backdrop { animation: none; } }
/* menu "Altro": voci grandi con icona ed etichetta */
.menu-list { display: grid; gap: 2px; }
.menu-item {
  display: flex; align-items: center; gap: 14px; width: 100%; min-height: 52px; padding: 0 12px;
  border: 0; border-radius: 12px; background: transparent; color: var(--text); font: inherit; font-size: max(16px, 1rem); font-weight: 500;
  text-align: left; cursor: pointer;
}
button.menu-item:hover { background: var(--surface-2); }
.menu-item[hidden] { display: none; }
.menu-item > svg { width: 22px; height: 22px; flex: none; fill: none; stroke: var(--muted); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.menu-item .count { margin-left: auto; }
.menu-danger { color: var(--danger); }
.menu-danger > svg { stroke: currentColor; }

.seg { display: inline-flex; gap: 2px; padding: 3px; border-radius: 11px; background: var(--surface-2); border: 1px solid var(--line); }
.seg button {
  min-height: 40px; padding: 0 12px; border: 0; border-radius: 8px; background: transparent;
  color: var(--muted); font: inherit; font-size: 0.875rem; font-weight: 600; cursor: pointer;
}
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

/* rientro per livello (niente stili in linea: la CSP li blocca) */
[data-depth="0"] { --depth: 0; }
[data-depth="1"] { --depth: 1; }
[data-depth="2"] { --depth: 2; }
[data-depth="3"] { --depth: 3; }
[data-depth="4"] { --depth: 4; }
