/* CRM-Style Vertical Sidebar Navigation - Modern & Elegant */
/* Layout/color tokens: brand-tokens.css (--sidebar-*, --banner-offset, --topbar-height). */

@property --sidebar-visual-width {
  syntax: '<length>';
  inherits: true;
  initial-value: 280px;
}

body {
  --sidebar-top: calc(var(--banner-offset) + var(--topbar-height));
}

/* Fixed alert banners — single offset chain for topbar + sidebar */
body.is-impersonating {
  --banner-offset: var(--impersonation-banner-height);
}

body.has-billing-alert {
  --banner-offset: var(--billing-banner-height);
}

body.is-impersonating.has-billing-alert {
  --banner-offset: calc(var(--impersonation-banner-height) + var(--billing-banner-height));
}

body.is-impersonating,
body.has-billing-alert {
  padding-top: var(--banner-offset);
}

body.is-impersonating .billing-alert-banner {
  top: var(--impersonation-banner-height);
}

/* Billing banner: fixed height so --billing-banner-height matches layout offsets */
.billing-alert-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1999;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: nowrap;
  gap: 0.5rem 1rem;
  height: var(--billing-banner-height);
  padding: 0 1rem;
  color: var(--color-surface);
  font-size: var(--font-size-sm);
  font-weight: 500;
  box-shadow: var(--shadow-card);
  font-family: 'Inter', 'Poppins', system-ui, sans-serif;
  overflow: hidden;
}

body.has-billing-alert:not(.is-frozen-billing) .billing-alert-banner {
  background: var(--color-warning-ink-strong);
}

body.is-frozen-billing .billing-alert-banner {
  background: var(--color-danger-ink);
}

.billing-alert-banner .billing-alert-message {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  flex: 1 1 auto;
  text-align: center;
}

.billing-alert-banner a.billing-alert-cta {
  flex-shrink: 0;
  background: var(--color-surface);
  color: var(--color-warning-deep);
  border-radius: var(--radius-pill);
  padding: 0.35rem 0.85rem;
  font-weight: 700;
  font-size: var(--font-size-caption);
  text-decoration: none;
}

body.is-frozen-billing .billing-alert-banner a.billing-alert-cta {
  color: var(--color-danger-ink-bright);
}

@media (max-width: 576px) {
  .billing-alert-banner {
    font-size: var(--font-size-xs);
    padding: 0 0.5rem;
    gap: 0.4rem;
  }

  .billing-alert-banner a.billing-alert-cta {
    padding: 0.15rem 0.45rem;
    font-size: var(--font-size-xs);
  }
}

/* Main layout structure - Sticky Footer
   Global styles.css sets html,body{height:100%} which can create a second vertical
   scroll chain when content is taller than the viewport. Grow the document instead.
   Unconditional html override (no :has) so older Firefox/Safari still get a single scroll root. */
html {
  height: auto;
  min-height: 100%;
}

body.with-sidebar {
  display: flex;
  flex-direction: column;
  height: auto;
  min-height: 100vh;
  background: var(--color-surface);
  margin: 0;
  padding-left: 0;
  padding-right: 0;
  padding-bottom: 0;
}

body.with-sidebar > .topbar-modern {
  flex-shrink: 0;
  z-index: 980;
}

body.with-sidebar > .app-wrapper {
  display: flex;
  min-height: calc(100vh - var(--sidebar-top));
}

body.with-sidebar > .site-footer {
  /* Hide marketing site-footer inside the authenticated app shell.
     The bottom tab bar remains; this footer breaks PWA feel and can steal
     focus/scroll when modals open. */
  display: none !important;
}

/* Top navbar - elevated and elegant */
.topbar-modern {
  height: var(--topbar-height);
  background: var(--color-surface);
  border-bottom: 1px solid var(--sidebar-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2.5rem;
  position: sticky;
  top: var(--banner-offset);
  z-index: 990;
  box-shadow: var(--shadow-card);
  transition: box-shadow var(--transition-speed) ease;
}

.topbar-modern:hover {
  box-shadow: var(--shadow-card);
}

.topbar-brand {
  font-size: var(--font-size-2xl);
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  letter-spacing: -0.5px;
}

.topbar-brand .brand-carla {
  color: var(--sidebar-section-header-color);
  font-weight: 800;
}

.topbar-brand .brand-ai {
  color: var(--sidebar-active-color);
  font-weight: 800;
}

.topbar-brand a {
  text-decoration: none;
  display: flex;
  align-items: center;
  transition: opacity var(--transition-speed) ease;
}

.topbar-brand a:hover {
  opacity: 0.8;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.topbar-user {
  font-size: var(--font-size-caption);
  color: var(--sidebar-text-light);
  cursor: pointer;
  padding: 0.625rem 1.25rem;
  border-radius: var(--radius-sm);
  transition: background-color var(--transition-speed) ease, color var(--transition-speed) ease;
  font-weight: 500;
  background: transparent;
  border: none;
}

.topbar-user:hover {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active-color);
  font-weight: 600;
}

/* Container wrapper for sidebar + content */
.app-wrapper {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* Sidebar */
.app-sidebar {
  width: var(--sidebar-visual-width);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  overflow-y: auto;
  overflow-x: hidden;
  padding: 2rem 0;
  position: fixed;
  top: var(--sidebar-top);
  bottom: 0;
  left: 0;
  box-shadow: var(--shadow-card);
  transition: width var(--transition-speed) ease, transform var(--transition-speed) ease, box-shadow var(--transition-speed) ease;
  /* One visible page scrollbar: keep scroll, hide track (wheel / touch still work) */
  scrollbar-width: none;
  -ms-overflow-style: none;
  /* Must paint above .app-content so icon-rail flyouts are reachable.
     Keep below the topbar (980 on with-sidebar pages) so topbar dropdowns
     are not clipped; mobile drawer overrides this to 1000. */
  z-index: 970;
}

.app-sidebar::-webkit-scrollbar {
  width: 0;
  height: 0;
  display: none;
}

body.with-sidebar .app-content::-webkit-scrollbar-thumb {
  background: var(--color-sidebar-muted);
  border-radius: var(--radius-xs);
  transition: background var(--transition-speed) ease;
}

body.with-sidebar .app-content::-webkit-scrollbar-thumb:hover {
  background: var(--color-sidebar-faint);
}

.sidebar-nav {
  list-style: none;
  margin: 0;
  padding: 0;
}

.sidebar-nav-item {
  margin: 0;
  padding: 0;
}

.sidebar-nav-link {
  display: flex;
  align-items: center;
  gap: 0.875rem;
  padding: 0.875rem 1.75rem;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: var(--font-size-md);
  font-weight: 500;
  transition: background-color var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
  border-left: 3px solid transparent;
  margin: 0;
  position: relative;
}

.sidebar-nav-link::before {
  content: '';
  position: absolute;
  inset: 0;
  background: transparent;
  transition: background var(--transition-speed) ease;
  pointer-events: none;
}

.sidebar-nav-link:hover {
  background: var(--sidebar-hover-bg);
  color: var(--sidebar-active-color);
  border-left-color: var(--sidebar-active-color);
  padding-left: calc(1.75rem + 2px);
}

.sidebar-nav-link.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active-color);
  border-left-color: var(--sidebar-active-color);
  font-weight: 700;
  padding-left: calc(1.75rem + 2px);
}

.sidebar-nav-link i {
  font-size: var(--font-size-base);
  min-width: 22px;
  text-align: center;
  opacity: 0.8;
  transition: opacity var(--transition-speed) ease;
}

.sidebar-nav-link:hover i,
.sidebar-nav-link.active i {
  opacity: 1;
}

/* Main content area — document scrolls; keep horizontal clip for wide tables */
body.with-sidebar .app-content {
  flex: 1;
  margin-left: var(--sidebar-layout-width);
  overflow-x: hidden;
  background: var(--color-bg-app);
}

/* Main content area without sidebar */
body:not(.with-sidebar) .app-content {
  flex: 1;
  margin-left: 0;
  overflow-x: hidden;
  background: var(--color-bg-app);
}

/* Signed-in footer at the bottom of the window on short pages: the page
   container grows, the legal strip wrapper (base.html) keeps its height.
   The id beats the page-level !important padding/flex on the container. */
body.with-sidebar .app-content {
  display: flex;
  flex-direction: column;
}

body.with-sidebar #main > .app-content-container:not(.app-legal-strip-wrap) {
  flex: 1 0 auto;
}

#main > .app-legal-strip-wrap {
  flex: 0 0 auto !important;
  min-height: 0 !important;
  padding-top: 0 !important;
  padding-bottom: var(--space-4) !important;
}

#main > .app-legal-strip-wrap > .app-legal-strip {
  margin-top: 0;
}

body.with-sidebar .app-content::-webkit-scrollbar {
  width: 8px;
}

.app-content::-webkit-scrollbar-track {
  background: transparent;
}

.app-content::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: var(--radius-xs);
}

.app-content::-webkit-scrollbar-thumb:hover {
  background: var(--color-sidebar-muted);
}

.app-content-container {
  padding: 2.5rem 3rem;
  max-width: 1600px;
  margin: 0 auto;
  width: 100%;
}

/* Responsive design */
@media (max-width: 992px) {
  .app-content-container {
    padding: 2rem 2.5rem;
  }
}

@media (max-width: 768px) {
  .site-footer {
    margin-left: 0;
  }

  .topbar-modern {
    padding: 0 1.5rem;
  }

  .topbar-brand {
    font-size: var(--font-size-xl);
  }

  .topbar-user {
    font-size: var(--font-size-xs);
    padding: 0.5rem 1rem;
  }

  .app-sidebar {
    transform: translateX(-100%);
    transition: transform var(--transition-speed) ease;
    z-index: 1000;
    width: 260px;
    box-shadow: var(--shadow-card);
  }

  .app-sidebar.show {
    transform: translateX(0);
  }

  .app-content {
    margin-left: 0;
    width: 100%;
  }

  .sidebar-toggle-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: var(--sidebar-hover-bg);
    border: none;
    border-radius: var(--radius-sm);
    font-size: var(--font-size-xl);
    color: var(--sidebar-text);
    cursor: pointer;
    padding: 0;
    transition: background-color var(--transition-speed) ease, color var(--transition-speed) ease;
  }

  .sidebar-toggle-btn:hover {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-active-color);
    transform: scale(1.05);
  }

  .app-content-container {
    padding: 1.5rem;
  }
}

@media (max-width: 576px) {
  .topbar-modern {
    padding: 0 0.75rem;
    height: var(--topbar-height);
  }

  /* Staff carry more top-bar items than a phone is wide: tighten the row (Esci is icon-only here). */
  .topbar-modern .topbar-actions {
    gap: 0.25rem;
  }

  .site-footer {
    margin-left: 0;
    padding: 2rem 1rem;
  }

  .topbar-brand {
    font-size: var(--font-size-xl);
  }

  .topbar-actions {
    gap: 1rem;
  }

  .topbar-user {
    display: none;
  }

  .app-sidebar {
    width: 100%;
    max-width: 100vw;
    box-shadow: var(--shadow-popover);
  }

  .sidebar-nav-link {
    padding: 0.875rem 1.5rem;
  }

  .app-content-container {
    padding: 1rem;
  }
}

/* Smooth transitions */
* {
  transition: background-color 0.2s ease, color 0.2s ease;
}

/* Footer Styles - At the end of page content */
.site-footer {
  background: var(--color-surface);
  border-top: 1px solid var(--sidebar-border);
  padding: 3rem 2.5rem;
  box-shadow: var(--shadow-card);
  position: relative;
  z-index: 10;
}

.site-footer .container {
  max-width: 1400px;
  margin: 0 auto;
}

.site-footer .footer-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 2rem;
  margin-bottom: 2rem;
}

.site-footer .footer-brand {
  font-size: var(--font-size-xl);
  font-weight: 800;
  color: var(--sidebar-section-header-color);
  margin-bottom: 0.5rem;
}

.site-footer .footer-powered-by {
  margin-top: 1rem;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.site-footer .footer-powered-by-label {
  font-size: var(--font-size-sm);
  color: var(--color-text-faint);
}

.site-footer .footer-powered-by-logo {
  max-height: 42px;
  height: auto;
  width: auto;
  vertical-align: middle;
}

.site-footer .footer-heading {
  font-size: var(--font-size-md);
  font-weight: 700;
  color: var(--sidebar-section-header-color);
  margin-bottom: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  opacity: 0.85;
}

.site-footer .footer-link {
  display: block;
  font-size: var(--font-size-md);
  color: var(--sidebar-text-light);
  text-decoration: none;
  margin-bottom: 0.75rem;
  transition: color var(--transition-speed) ease, padding-left var(--transition-speed) ease;
}

.site-footer .footer-link:hover {
  color: var(--sidebar-active-color);
  padding-left: 0.25rem;
}

.site-footer .footer-bottom {
  border-top: 1px solid var(--sidebar-border);
  padding-top: 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: var(--font-size-caption);
  color: var(--sidebar-text-light);
}

/* Print styles */
@media print {
  .topbar-modern,
  .app-sidebar,
  .sidebar-toggle-btn,
  .site-footer {
    display: none;
  }

  .app-wrapper {
    display: flex;
    flex-direction: column;
  }

  .app-content {
    margin-left: 0;
    height: auto;
  }

  .app-content-container {
    padding: 0;
  }
}

/* Dark mode support disabled - site designed for light mode only
@media (prefers-color-scheme: dark) {
  :root {
    --sidebar-bg: var(--sidebar-section-header-color);
    --sidebar-text: var(--color-border);
    --sidebar-text-light: var(--color-sidebar-muted);
    --sidebar-border: var(--color-heading);
    --sidebar-hover-bg: var(--color-heading);
    --sidebar-active-bg: var(--color-sidebar-dark-active-bg);
    --sidebar-active-color: var(--color-sidebar-dark-active-ink);
    --sidebar-section-header-color: var(--color-gray-50);
  }

  body.with-sidebar {
    background: var(--color-sidebar-dark-page);
  }

  .topbar-modern {
    background: var(--sidebar-section-header-color);
    border-bottom-color: var(--sidebar-border);
  }

  .app-content {
    background: var(--color-sidebar-dark-page);
  }

  .app-sidebar {
    background: var(--sidebar-bg);
    box-shadow: 2px 0 12px rgba(0, 0, 0, 0.3);
  }

  .site-footer {
    background: var(--sidebar-section-header-color);
    border-top-color: var(--sidebar-border);
    box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.3);
  }

  .site-footer .footer-bottom {
    border-top-color: var(--sidebar-border);
  }
}
*/

/* High contrast mode support */
@media (prefers-contrast: more) {
  .topbar-modern {
    border-bottom-width: 2px;
  }

  .app-sidebar {
    border-right-width: 2px;
  }

  .sidebar-nav-link.active {
    border-left-width: 4px;
  }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  .topbar-modern,
  .topbar-user,
  .sidebar-nav-link,
  .app-sidebar,
  .sidebar-toggle-btn,
  body.with-sidebar,
  body.with-sidebar .app-content {
    transition: none !important;
  }

}

/* ── Sidebar tree (web/_partials/sidebar_tree.html) ───────────────────────
   Collapsible <details> groups, shared by the staff nav
   (admin/_admin_sidebar.html) and the customer nav
   (customer/_customer_sidebar.html). */
.sidebar-tree {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}

.sidebar-group[data-sidebar-group="configurazione"],
.sidebar-group[data-sidebar-group="profilo"] {
  margin-top: 0.375rem;
  padding-top: 0.375rem;
  border-top: 1px solid var(--sidebar-border);
}

.sidebar-nav--tail {
  margin-top: 0.375rem;
  padding-top: 0.375rem;
  border-top: 1px solid var(--sidebar-border);
}

/* Flat top-level rows (Dashboard) read as peers of a group header, so they
   carry the same weight as .sidebar-group-toggle. */
.sidebar-nav--root > .sidebar-nav-item > .sidebar-nav-link {
  font-weight: 600;
}

.sidebar-group {
  margin: 0;
}

.sidebar-group-toggle {
  display: flex;
  align-items: center;
  gap: 0.875rem;
  padding: 0.875rem 1.75rem;
  color: var(--sidebar-text);
  font-size: var(--font-size-md);
  font-weight: 600;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background var(--transition-speed) ease, color var(--transition-speed) ease;
  /* Strip the native disclosure triangle: the chevron on the right is ours. */
  list-style: none;
}

.sidebar-group-toggle::-webkit-details-marker,
.sidebar-group-toggle::marker {
  display: none;
  content: '';
}

.sidebar-group-toggle:hover {
  background: var(--sidebar-hover-bg);
  color: var(--sidebar-active-color);
}

.sidebar-group-toggle:focus-visible {
  outline: 2px solid var(--sidebar-active-color);
  outline-offset: -2px;
}

.sidebar-group-icon {
  font-size: var(--font-size-base);
  min-width: 22px;
  text-align: center;
  opacity: 0.8;
}

.sidebar-group-label {
  flex: 1 1 auto;
  min-width: 0;
}

.sidebar-group-caret {
  font-size: var(--font-size-xs);
  opacity: 0.5;
  flex-shrink: 0;
  transition: transform var(--transition-speed) ease;
}

/* Unread team chat on a group title: sits beside the caret, not pushed away by it. */
.sidebar-group-toggle .sidebar-nav-link__pending-dot {
  margin-left: 0;
}

.sidebar-group[open] > .sidebar-group-toggle > .sidebar-group-caret {
  transform: rotate(180deg);
}

.sidebar-group[open] > .sidebar-group-toggle > .sidebar-group-icon {
  opacity: 1;
}

/* Collapsed group holding the current page: keep the "you are here" signal
   visible without forcing the group open. */
.sidebar-group.has-active:not([open]) > .sidebar-group-toggle {
  color: var(--sidebar-active-color);
  border-left-color: var(--sidebar-active-color);
  font-weight: 700;
}

.sidebar-group.has-active:not([open]) > .sidebar-group-toggle > .sidebar-group-icon,
.sidebar-group.has-active:not([open]) > .sidebar-group-toggle > .sidebar-group-caret {
  opacity: 1;
}

/* A child's pending dot (Messaggi awaiting approval) is out of sight while its
   group is collapsed or the sidebar is an icon rail: repeat it on the group
   icon. base.html toggles .has-pending together with the child dot. */
.sidebar-group.has-pending:not([open]) > .sidebar-group-toggle > .sidebar-group-icon {
  position: relative;
  opacity: 1;
}

.sidebar-group.has-pending:not([open]) > .sidebar-group-toggle > .sidebar-group-icon::after {
  content: '';
  position: absolute;
  top: -3px;
  right: -1px;
  width: 8px;
  height: 8px;
  border-radius: var(--radius-round);
  background: var(--category-coral);
  border: 2px solid var(--sidebar-bg);
  box-sizing: content-box;
}

/* Children: indented under the group icon, with a guide rail down the set. */
.sidebar-subnav {
  position: relative;
  padding-bottom: 0.375rem;
}

.sidebar-subnav::before {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0.375rem;
  /* +3px for the transparent border-left on .sidebar-group-toggle, so the
     rail lines up with the centre of the group icon above it. */
  left: calc(1.75rem + 14px);
  width: 1px;
  background: var(--sidebar-border);
}

.sidebar-nav-link--child {
  padding: 0.625rem 1.75rem 0.625rem 3.5rem;
  font-size: var(--font-size-sm);
  font-weight: 500;
}

.sidebar-nav-link--child:hover,
.sidebar-nav-link--child.active {
  padding-left: calc(3.5rem + 2px);
}

.sidebar-nav-link--child i {
  font-size: var(--font-size-md);
  min-width: 18px;
}

@media (max-width: 576px) {
  .sidebar-group-toggle {
    padding: 0.875rem 1.5rem;
  }

  .sidebar-subnav::before {
    left: calc(1.5rem + 14px);
  }

  .sidebar-nav-link--child {
    padding: 0.625rem 1.5rem 0.625rem 3.25rem;
  }

  .sidebar-nav-link--child:hover,
  .sidebar-nav-link--child.active {
    padding-left: calc(3.25rem + 2px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar-group-toggle,
  .sidebar-group-caret {
    transition: none !important;
  }
}

@keyframes sidebarCopyIn {
  from { opacity: 0; transform: translateX(-6px); }
  to { opacity: 1; transform: none; }
}

@keyframes sidebarCopyFade {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ── Desktop icon-rail collapse + full-page lists ───────────────────────── */
.sidebar-nav-label {
  min-width: 0;
}

.sidebar-toggle-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: var(--sidebar-hover-bg);
  border: none;
  border-radius: var(--radius-sm);
  font-size: var(--font-size-xl);
  color: var(--sidebar-text);
  cursor: pointer;
  padding: 0;
  transition: background var(--transition-speed) ease, color var(--transition-speed) ease;
}

.sidebar-toggle-btn:hover {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active-color);
}

.sidebar-chrome {
  display: none;
}

.sidebar-panel-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--sidebar-text-light);
  cursor: pointer;
}

.sidebar-panel-btn:hover,
.sidebar-panel-btn:focus-visible,
.sidebar-panel-btn.is-pinned {
  background: var(--sidebar-hover-bg);
  color: var(--sidebar-text);
}

.sidebar-panel-btn i {
  display: block;
  font-size: var(--font-size-lg);
  transition: transform 180ms ease;
}

.sidebar-panel-btn:not(.is-pinned) i {
  transform: rotate(-12deg);
}

.sidebar-panel-btn.is-pinned i {
  transform: rotate(0deg);
}

body.page-fullwidth .app-content-container {
  max-width: none;
  padding-left: 1.25rem;
  padding-right: 1.25rem;
}

@media (min-width: 769px) {
  body.with-sidebar .topbar-actions .sidebar-toggle-btn {
    display: none;
  }

  .sidebar-chrome {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    position: absolute;
    top: 2rem;
    right: 0.5rem;
    z-index: 3;
    padding: 0;
    height: calc(1.75rem + 1.0625rem);
  }

  .sidebar-nav--root > .sidebar-nav-item > .sidebar-nav-link,
  .sidebar-group:first-child > .sidebar-group-toggle {
    padding-right: 2.75rem;
  }

  body.with-sidebar.sidebar-collapsed {
    --sidebar-layout-width: var(--sidebar-width-collapsed);
    --sidebar-visual-width: var(--sidebar-width-collapsed);
  }

  body.with-sidebar:not(.sidebar-collapsed) {
    --sidebar-layout-width: var(--sidebar-width);
    --sidebar-visual-width: var(--sidebar-width);
  }

  /* Hover expand: panel grows over the page; main content keeps the rail offset. */
  body.with-sidebar.sidebar-collapsed.sidebar-hover-open {
    --sidebar-visual-width: var(--sidebar-width);
  }

  /* Only width + shadow animate; padding snaps while the panel is still narrow. */
  body.with-sidebar .app-sidebar {
    transition:
      width var(--sidebar-expand-duration-open) var(--sidebar-expand-easing),
      box-shadow var(--sidebar-expand-duration-open) var(--sidebar-expand-easing);
  }

  body.with-sidebar.sidebar-collapsed.sidebar-hover-closing .app-sidebar {
    transition:
      width var(--sidebar-expand-duration-close) var(--sidebar-expand-easing),
      box-shadow var(--sidebar-expand-duration-close) var(--sidebar-expand-easing);
  }

  body.with-sidebar.sidebar-collapsed.sidebar-hover-open .app-sidebar {
    box-shadow: var(--shadow-popover);
  }

  body.with-sidebar:not(.sidebar-collapsed) .app-content,
  body.with-sidebar:not(.sidebar-collapsed) .site-footer,
  body.with-sidebar.sidebar-toggling .app-content,
  body.with-sidebar.sidebar-toggling .site-footer {
    transition: margin-left var(--sidebar-expand-duration-open) var(--sidebar-expand-easing);
  }

  body.sidebar-collapsed:not(.sidebar-hover-reveal) .sidebar-chrome {
    display: none;
  }

  body.sidebar-collapsed:not(.sidebar-hover-open) .app-sidebar {
    overflow: visible;
    padding-top: 1.25rem;
    padding-bottom: 1.25rem;
  }

  /* Keep icon-rail layout while the panel width animates; reveal copy at full width. */
  body.sidebar-collapsed:not(.sidebar-hover-reveal) .sidebar-nav-label,
  body.sidebar-collapsed:not(.sidebar-hover-reveal) .sidebar-group-label,
  body.sidebar-collapsed:not(.sidebar-hover-reveal) .sidebar-group-caret {
    display: none;
  }

  body.sidebar-collapsed:not(.sidebar-hover-reveal) .sidebar-group.is-flyout-open .sidebar-nav-label {
    display: inline;
  }

  /* Group title + subsection links appear together when copy is revealed. */
  body.sidebar-collapsed.sidebar-hover-open:not(.sidebar-hover-reveal) .sidebar-group > .sidebar-subnav {
    display: none;
  }

  body.sidebar-collapsed.sidebar-hover-reveal .sidebar-nav-label,
  body.sidebar-collapsed.sidebar-hover-reveal .sidebar-group-label,
  body.sidebar-collapsed.sidebar-hover-reveal .sidebar-group-caret {
    opacity: 1;
  }

  /* Copy fades/slides in once the panel is wide enough, instead of popping
     (skipped under reduced motion). fill-mode backwards: the caret keeps its
     own rotate transform afterwards. */
  @media (prefers-reduced-motion: no-preference) {
    body.sidebar-collapsed.sidebar-hover-reveal .sidebar-nav-label,
    body.sidebar-collapsed.sidebar-hover-reveal .sidebar-group-label {
      animation: sidebarCopyIn var(--sidebar-copy-fade-duration) ease-out backwards;
    }

    body.sidebar-collapsed.sidebar-hover-reveal .sidebar-group-caret,
    body.sidebar-collapsed.sidebar-hover-reveal .sidebar-chrome,
    body.sidebar-collapsed.sidebar-hover-reveal .sidebar-group > .sidebar-subnav {
      animation: sidebarCopyFade var(--sidebar-copy-fade-duration) ease-out backwards;
    }
  }

  body.sidebar-collapsed.sidebar-hover-open:not(.sidebar-hover-reveal) .sidebar-nav-link,
  body.sidebar-collapsed.sidebar-hover-open:not(.sidebar-hover-reveal) .sidebar-group-toggle {
    justify-content: center;
    gap: 0;
    padding-left: 0;
    padding-right: 0;
  }

  body.sidebar-collapsed:not(.sidebar-hover-open) .sidebar-nav-link,
  body.sidebar-collapsed:not(.sidebar-hover-open) .sidebar-group-toggle {
    justify-content: center;
    gap: 0;
    padding-left: 0;
    padding-right: 0;
  }

  body.sidebar-collapsed:not(.sidebar-hover-open) .sidebar-nav-link:hover,
  body.sidebar-collapsed:not(.sidebar-hover-open) .sidebar-nav-link.active {
    padding-left: 0;
  }

  body.sidebar-collapsed:not(.sidebar-hover-open) .sidebar-nav-link--child:hover,
  body.sidebar-collapsed:not(.sidebar-hover-open) .sidebar-nav-link--child.active {
    padding-left: 0.75rem;
  }

  body.sidebar-collapsed:not(.sidebar-hover-open) .sidebar-subnav::before {
    display: none;
  }

  body.sidebar-collapsed:not(.sidebar-hover-open) .sidebar-nav--tail {
    margin-top: 0.25rem;
    padding-top: 0.25rem;
  }

  body.sidebar-collapsed:not(.sidebar-hover-open) .sidebar-group {
    position: relative;
  }

  body.sidebar-collapsed:not(.sidebar-hover-open) .sidebar-group > .sidebar-subnav {
    display: none;
  }

  body.sidebar-collapsed:not(.sidebar-hover-open) .sidebar-group.is-flyout-open > .sidebar-subnav,
  body.sidebar-collapsed:not(.sidebar-hover-open) .sidebar-group[open].is-flyout-open > .sidebar-subnav {
    display: block;
    position: absolute;
    left: 100%;
    top: 0;
    min-width: 220px;
    max-height: min(70vh, 28rem);
    overflow-y: auto;
    margin: 0;
    padding: 0.375rem 0;
    background: var(--sidebar-bg);
    border: 1px solid var(--sidebar-border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-popover);
    z-index: 1200;
  }

  body.sidebar-collapsed:not(.sidebar-hover-open) .sidebar-group.is-flyout-open .sidebar-nav-label {
    display: inline;
  }

  body.sidebar-collapsed:not(.sidebar-hover-open) .sidebar-group.is-flyout-open .sidebar-nav-link--child {
    justify-content: flex-start;
    gap: 0.75rem;
    padding: 0.625rem 1rem;
  }
}

/* Dev Impostazioni side menu (base.html, sections.py layout='side'). */
.dev-side-nav .nav-link { white-space: nowrap; }
.nav.dev-side-nav { justify-content: flex-start; }
@media (min-width: 992px) {
  .dev-side-nav { position: sticky; top: 1rem; }
}
.dev-side-nav__group {
  font-size: var(--font-size-3xs);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--neutral-500);
  padding: 0.75rem 0.75rem 0.25rem;
}
.dev-side-nav__group:first-child { padding-top: 0; }
@media (max-width: 992px) {
  .dev-side-nav__group { flex-basis: 100%; padding: 0.5rem 0 0; }
}

/* Dev area trail and the second tab row (admin/_partials/dev_section_nav.html). */
.dev-trail { --bs-breadcrumb-divider: '›'; }
.dev-trail a { color: var(--neutral-500); text-decoration: none; }
.dev-trail a:hover { color: var(--brand-green-strong); text-decoration: underline; }
.nav.dev-subnav { gap: 0.25rem; justify-content: flex-start; border-bottom: 1px solid var(--neutral-200); }
.dev-subnav .nav-link {
  color: var(--neutral-600);
  padding: 0.35rem 0.75rem;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  font-size: var(--font-size-sm);
}
.dev-subnav .nav-link.active { color: var(--neutral-800); border-bottom-color: var(--brand-green); font-weight: 600; }
