/* ======================= VARIABLES ======================= */
:root {
  /* ---------------- DIMENSIONI ---------------- */
  --topbar-height: 50px;
  --logo-height: 50px;
  --sidebar-width: 250px;
  --icon-size: 22px;
  --font-size-menu: 0.95rem;
  --footer-padding: 12px 20px;
  --link-padding: 10px 20px;
  --link-gap: 15px;
  --offline-banner-height: 46px;

  /* ---------------- COLORI ---------------- */
  --color-topbar-bg: #182f4d;
  --color-sidebar-bg-start: #183253;
  --color-sidebar-bg-end: #3f5a8a;
  --color-border: #263238;
  --color-link-text: white;
  --color-link-hover-bg: #1c313a;
  --color-link-hover-text: #bbdefb;
  --color-button-primary: #2b8bd3;
  --color-button-success: #2e7d32;
  --color-button-danger: #c62828;
  --color-divider: rgba(41, 31, 67, 0.15);
  --color-footer-text: #b0bec5;
  --color-help-icon: white;
  --color-main-bg: #f6f7f9;
  --color-page-header-bg: rgb(219, 219, 219);
}

html,
body {
  height: 100%;
}

body,
main.container {
  overflow-x: hidden;
}

/* ======================= GENERIC CLASSES ======================= */
.flex-center {
  display: flex;
  align-items: center;
  justify-content: center;
}

.flex-row,
.flex-row-base {
  display: flex;
  align-items: center;
}

.flex-row {
  gap: var(--link-gap);
}

.flex-wrap {
  flex-wrap: wrap;
}

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

.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.justify-start { justify-content: flex-start; }

.items-center { align-items: center; }
.items-start { align-items: flex-start; }

.gap-sm { gap: 8px; }
.gap-md { gap: 15px; }
.gap-lg { gap: 24px; }

.py-md { padding: 20px 0; }
.p-sm { padding: 10px; }

.m-0 { margin: 0; }
.mt-xs { margin-top: 4px; }
.mt-sm { margin-top: 8px; }
.mt-md { margin-top: 12px; }
.mt-lg { margin-top: 15px; }
.mt-xl { margin-top: 20px; }

.mb-sm { margin-bottom: 8px; }
.mb-md { margin-bottom: 15px; }
.mb-lg { margin-bottom: 20px; }

.desktop-only {
  display: none !important;
}

.ml-xs { margin-left: 4px; }

.text-primary { color: #0f1724; }
.text-muted { color: #6b7280; }
.text-xs { font-size: 0.8rem; }
.text-sm { font-size: 0.85rem; }
.text-md { font-size: 1.05rem; }

.font-bold { font-weight: 700; }

@media (max-width: 900px) {
  .stack-md {
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-start !important;
  }
}

.user-info span + span {
  font-size: 0.85rem;
  display: block;
}

.icon { font-size: var(--icon-size); }

.divider {
  border-top: 1px solid var(--color-divider);
  margin: 4px auto;
  width: 95%;
}

/* ======================= FINANCE DASHBOARD HELPERS ======================= */
.finance-summary {
  --card-modern-grid-gap: 16px;
  margin-bottom: 1.5rem;
}

.finance-summary .card-modern.metric {
  align-items: flex-start;
  padding: 1.25rem;
  text-align: left;
}

.finance-summary .card-title {
  margin-bottom: 6px;
  font-size: 0.9rem;
  color: #6b7280;
}

.finance-summary .card-value {
  font-size: 1.8rem;
}

.finance-summary .card-note {
  margin-top: 4px;
  font-size: 0.85rem;
}

.finance-chart {
  margin-bottom: 1.5rem;
}

.status-badge {
  display: inline-flex;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
}

.status-badge.pending { background: #e0e7ff; color: #3730a3; }
.status-badge.awaiting_event { background: #f3e8ff; color: #7e22ce; }
.status-badge.partial { background: #fef3c7; color: #b45309; }
.status-badge.paid { background: #dcfce7; color: #15803d; }
.status-badge.overdue { background: #fee2e2; color: #b91c1c; }

.product-margins-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.product-margins-item {
  border: 1px solid #edf0f7;
  border-radius: 12px;
  padding: 0.85rem 1rem;
  background: #f8fafc;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

@media (max-width: 640px) {
  .finance-summary .card-modern.metric {
    padding: 1rem;
  }

  .finance-summary .card-value {
    font-size: 1.5rem;
  }
}

/* ======================= AUTH LAYOUT ======================= */
.auth-page {
  min-height: calc(100vh - var(--topbar-height));
  padding: calc(var(--topbar-height) + 32px) 16px 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-main-bg);
}

.auth-card {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
}

.auth-card--wide {
  max-width: 620px;
}

.auth-card--xl {
  max-width: 720px;
}

@media (max-width: 600px) {
  .auth-page {
    padding: calc(var(--topbar-height) + 16px) 16px 24px;
    align-items: flex-start;
  }
  .auth-card,
  .auth-card--wide,
  .auth-card--xl {
    max-width: 100%;
  }
}

/* ======================= TOPBAR ======================= */
.topbar {
  display: flex;
  align-items: center;
  width: 100%;
  height: var(--topbar-height);
  background: var(--color-topbar-bg);
  color: var(--color-link-text);
  border-bottom: 1px solid var(--color-border);
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1000;
}

.logo-area {
  width: var(--sidebar-width);
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding-left: 0.5rem;
  gap: 0.35rem;
}

.logo-area__brand {
  height: var(--logo-height);
  max-width: 150px;
  width: auto;
}

.topbar-icon-btn {
  border: none;
  background: transparent;
  color: var(--color-link-text);
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  padding: 0;
  transition: background 0.2s ease, color 0.2s ease;
}

.topbar-icon-btn:hover,
.topbar-icon-btn:focus {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
}

.topbar-icon-btn:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.6);
  outline-offset: 2px;
}

.topbar-search-toggle {
  display: none;
}

.topbar-center {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
}

#topbar-search-form input {
  height: 32px;        
  width: 300px;
  padding: 0 12px;
  border-radius: 20px;
  border: none;
  outline: none;
  background: rgba(255,255,255,0.15);
  margin: 0;
  color: white;
  transition: width 0.3s ease;
}

#topbar-search-form input::placeholder,
#topbar-mobile-search-input::placeholder {
  color: rgba(255, 255, 255, 0.7);
}

#topbar-search-form input:focus {
  width: 400px;
  background: rgba(255,255,255,0.2);
}

.topbar-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
}

.topbar-logo img {
  height: var(--logo-height);
  width: auto;
}

.topbar-logo--mobile {
  display: none;
}

.topbar-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.8rem;
  padding-right: 0.5rem;
}

.topbar-right--step {
  min-width: 220px;
  gap: 0.6rem;
}

.clickable-icon,
.catalog-file-label {
  cursor: pointer;
}

.notification-trigger {
  position: relative;
}

.topbar-message__title {
  font-weight: 600;
}

.topbar-link {
  color: var(--color-link-text);
  text-decoration: none;
}

.topbar-link:hover {
  color: var(--color-link-hover-text);
}

.topbar .material-icons {
  color: var(--color-link-text);
}

.topbar-search-overlay {
  position: fixed;
  top: var(--topbar-height);
  left: 0;
  right: 0;
  background: rgba(24, 47, 77, 0.95);
  padding: 12px 16px;
  transform: translateY(-100%);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.25s ease, opacity 0.25s ease;
  z-index: 999;
}

.topbar-search-overlay.is-open {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
}

.topbar-search-overlay__content {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-search-overlay__icon {
  color: #fff;
}

#topbar-mobile-search-form {
  flex: 1;
}

#topbar-mobile-search-input {
  width: 100%;
  height: 42px;
  border-radius: 999px;
  border: none;
  padding: 0 18px;
  font-size: 1rem;
  background: #fff;
  color: #0f172a;
}

@media (min-width: 769px) {
  .topbar-search-overlay {
    display: none;
  }
}

.app-offline-banner {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: #c62828;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px calc(12px + env(safe-area-inset-bottom, 0px));
  gap: 12px;
  z-index: 1300;
  transform: translateY(100%);
  transition: transform 0.25s ease-in-out, opacity 0.2s ease-in-out;
  box-shadow: 0 -6px 16px rgba(198, 40, 40, 0.3);
  opacity: 0;
  visibility: hidden;
}

.app-offline-banner.is-visible {
  transform: translateY(0);
  opacity: 1;
  visibility: visible;
}

.app-offline-banner__content {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 0.95rem;
}

.app-offline-banner__dismiss {
  background: transparent;
  color: inherit;
  border: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
}

.app-offline-banner__dismiss:hover,
.app-offline-banner__dismiss:focus-visible {
  background: rgba(255, 255, 255, 0.25);
}

.app-offline-banner__icon {
  font-size: 20px;
}

.pwa-install-toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  max-width: 340px;
  width: calc(100% - 32px);
  background: #0f172a;
  color: #fff;
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.35);
  display: flex;
  flex-direction: column;
  gap: 12px;
  z-index: 1250;
  opacity: 0;
  transform: translateY(120%);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.pwa-install-toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.pwa-install-toast__content {
  display: flex;
  gap: 12px;
  align-items: center;
}

.pwa-install-toast__content span {
  display: block;
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.85);
}

.pwa-install-toast__actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

.pwa-install-toast__btn {
  border: none;
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.2s ease;
}

.pwa-install-toast__btn--ghost {
  background: transparent;
  color: rgba(255, 255, 255, 0.75);
}

.pwa-install-toast__btn--ghost:hover,
.pwa-install-toast__btn--ghost:focus-visible {
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
}

.pwa-install-toast__btn--primary {
  background: #2b8bd3;
  color: #fff;
}

.pwa-install-toast__btn--primary:hover,
.pwa-install-toast__btn--primary:focus-visible {
  background: #1f6da6;
}

body.app-is-offline .pwa-install-toast {
  bottom: calc(var(--offline-banner-height) + 24px);
}

.ios-install-modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(15, 23, 42, 0.55);
  z-index: 1400;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.ios-install-modal.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.ios-install-modal__dialog {
  position: relative;
  width: min(420px, 100%);
  background: #fff;
  color: #0f172a;
  border-radius: 24px;
  padding: 32px 28px;
  box-shadow: 0 20px 60px rgba(15, 23, 42, 0.35);
  transform: translateY(10px);
  transition: transform 0.25s ease;
}

.ios-install-modal.is-visible .ios-install-modal__dialog {
  transform: translateY(0);
}

.ios-install-modal__close {
  position: absolute;
  top: 16px;
  right: 16px;
  border: none;
  background: transparent;
  color: #64748b;
  width: 36px;
  height: 36px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s ease;
}

.ios-install-modal__close:hover,
.ios-install-modal__close:focus-visible {
  background: rgba(100, 116, 139, 0.15);
}

.ios-install-modal__icon {
  width: 64px;
  height: 64px;
  border-radius: 18px;
  background: #e0ecfb;
  color: #1d4ed8;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
  font-size: 32px;
}

.ios-install-modal__steps {
  margin: 0 0 24px 0;
  padding-left: 18px;
  color: #475569;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ios-install-modal__steps li {
  line-height: 1.35;
}

.ios-install-modal__steps i.material-icons {
  font-size: 18px;
  vertical-align: middle;
  margin-left: 4px;
}

.ios-install-modal__primary {
  width: 100%;
  border: none;
  border-radius: 999px;
  padding: 12px 18px;
  font-size: 1rem;
  color: #fff;
  background: #2b8bd3;
  cursor: pointer;
  transition: background 0.2s ease;
}

.ios-install-modal__primary:hover,
.ios-install-modal__primary:focus-visible {
  background: #1f6da6;
}

.ios-install-modal__backdrop {
  position: absolute;
  inset: 0;
}

@media (max-width: 600px) {
  .ios-install-modal {
    padding: 24px 16px;
  }
  .ios-install-modal__dialog {
    padding: 28px 22px 24px;
  }
}


/* ======================= SIDEBAR ======================= */
.sidebar {
  position: fixed;
  top: var(--topbar-height);
  left: 0;
  width: var(--sidebar-width);
  height: calc(100vh - var(--topbar-height));
  background: linear-gradient(180deg, var(--color-sidebar-bg-start), var(--color-sidebar-bg-end));
  color: var(--color-link-text);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding-top: 10px;
  box-sizing: border-box;
  transition: transform 0.3s ease;
}

.sidebar.collapsed { transform: translateX(-100%); }

.sidebar-menu {
  flex-grow: 1;
  padding-top: 10px;
}

.sidebar-menu li a {
  display: flex;
  align-items: center;
  padding: var(--link-padding);
  font-size: var(--font-size-menu);
  color: var(--color-link-text);
  gap: var(--link-gap);
  transition: background-color 0.3s ease;
}

.sidebar-menu li a:hover,
.sidebar-menu li a.active {
  background-color: var(--color-link-hover-bg);
  color: var(--color-link-hover-text);
}

.sidebar-menu li a i.material-icons {
  font-size: var(--icon-size);
}

.sidebar-footer {
  color: var(--color-footer-text);
  font-weight: 600;
  border-top: 1px solid rgba(255,255,255,0.15);
  padding: var(--footer-padding);
  text-align: center;
}

/* ======================= MAIN CONTENT ======================= */
body {
  margin: 0;
  background: var(--color-main-bg);
}

.app-main {
  margin-top: var(--topbar-height);
  min-height: calc(100vh - var(--topbar-height));
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
}

body.app-is-offline .app-main {
  padding-bottom: calc(var(--offline-banner-height) + 32px);
}

.main-footer {
  margin-top: auto;
  padding-top: 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.inline-form {
  display: inline;
}

.text-center {
  text-align: center;
}

.helper-text--muted {
  font-size: 0.9em;
  color: #555;
}

.is-hidden {
  display: none !important;
}

.dropdown-placeholder {
  display: block;
  padding: 10px;
}

.is-offline-disabled {
  pointer-events: none;
  opacity: 0.6;
}

/* Stato normale con sidebar */
main.container.with-sidebar {
  margin-top: var(--topbar-height);
  margin-left: var(--sidebar-width); /* lascia spazio alla sidebar */
  padding: 20px;
  box-sizing: border-box;
  background: var(--color-main-bg);
  width: calc(100% - var(--sidebar-width)); /* aggiunto width */
  max-width: 100%; /* evita max-width di Materialize */
  transition: margin-left 0.3s ease, width 0.3s ease;
}

/* Sidebar chiusa */
main.container.with-sidebar.collapsed {
  margin-left: 0;
  margin-right: 0;
  width: 100%; /* espande il container al 100% */
}

.page-header {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: 4px;
  padding: 10px 20px 0;
  position: sticky;
  top: var(--topbar-height);
  background: var(--color-page-header-bg);
  z-index: 998;
  border-bottom: 1px solid rgba(0,0,0,0.08);
  box-shadow: 0 4px 14px -10px rgba(0, 0, 0, 0.25);
  min-height: 56px;
  margin-left: var(--sidebar-width);
  width: calc(100% - var(--sidebar-width));
  transition: background 0.3s ease, box-shadow 0.3s ease, margin-left 0.3s ease, width 0.3s ease;
}

.page-header__breadcrumbs {
  min-width: 0;
  display: flex;
  align-items: center;
  flex: 1;
}

.page-header--centered {
  justify-content: center;
  padding: 10px 20px;
  gap: 0;
}

.page-header--with-anchors {
  padding-bottom: 0;
}

.page-header--centered .page-filters {
  display: none !important;
}

.page-header__top {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  width: 100%;
  min-height: 36px;
}

.page-header__actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.page-header__actions:empty {
  display: none;
}

.page-mobile-toolbar { display: none; }

body.app-is-offline .page-mobile-toolbar {
  bottom: calc(var(--offline-banner-height) + 12px);
}

.page-filters {
  display: flex;
  align-items: center;
  gap: 16px;
  row-gap: 2px;
  flex-wrap: wrap;
  margin-top: 0;
  padding: 0;
  position: relative;
}

.page-filters:empty {
  display: none;
}

.page-filters--single {
  justify-content: center;
}

.page-filters a {
  position: relative;
  display: inline-flex;
  align-items: center;
  padding: 4px 0;
  text-decoration: none;
  font-weight: 600;
  text-transform: uppercase;
  color: rgba(0, 0, 0, 0.6);
  transition: color 0.15s ease;
}

.page-filters a:hover,
.page-filters a:focus {
  color: rgba(0, 0, 0, 0.85);
}

.page-filters a.active {
  color: #182f4d;
}

.page-filters__indicator {
  position: absolute;
  left: 0;
  bottom: -1px;
  height: 3px;
  border-radius: 999px;
  background: #78c6f4;
  width: 0;
  transform: translateX(0);
  opacity: 0;
  transition: transform 0.22s ease, width 0.22s ease, opacity 0.22s ease;
  will-change: transform, width;
}

.page-breadcrumbs {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  font-size: 0.95rem;
  color: rgba(0, 0, 0, 0.6);
}

.page-breadcrumbs__item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: inherit;
  text-decoration: none;
}

.page-breadcrumbs__item + .page-breadcrumbs__item::before {
  content: "/";
  margin: 0 6px;
  color: rgba(0, 0, 0, 0.4);
}

.page-breadcrumbs__item i.material-icons {
  font-size: 18px;
}

.page-breadcrumbs__item:not(.page-breadcrumbs__item--current):hover,
.page-breadcrumbs__item:not(.page-breadcrumbs__item--current):focus {
  color: rgba(0, 0, 0, 0.75);
}

.page-breadcrumbs__item--current {
  font-weight: 600;
  color: rgba(0, 0, 0, 0.85);
}

.catalog-actions {
  display: flex;
  justify-content: space-between;
  width: 100%;
  gap: 16px;
  flex-wrap: wrap;
}

.catalog-actions > * {
  display: flex;
  align-items: center;
  gap: 12px;
}

.catalog-actions form.inline-form {
  display: inline;
}

.btn {
  font-weight: 600;
  text-transform: uppercase;
  border-radius: 6px;
  padding: 0 0.875rem;
  height: 34px;
  line-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease;
  background-color: var(--color-button-primary) !important;
  color: #fff !important;
  border: none;
}

.btn:hover,
.btn:focus {
  filter: brightness(1.08);
}

.btn i.material-icons.left { margin-right: 6px; }
.btn i.material-icons.right { margin-left: 6px; }

.btn-action {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-radius: 6px;
  padding: 0 0.875rem;
  height: 34px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.015em;
  box-shadow: none;
}

.btn-action .material-icons {
  font-size: 20px;
  margin: 0;
}

.btn-primary {
  background-color: var(--color-button-primary) !important;
  color: #fff !important;
}

.btn-primary:hover,
.btn-primary:focus {
  background-color: #217ac0 !important;
  color: #fff !important;
}

.btn-secondary,
.page-header__actions .btn.btn-secondary {
  background-color: var(--color-button-primary) !important;
  color: #fff !important;
  border: 1px solid var(--color-button-primary) !important;
}

.btn-secondary:hover,
.btn-secondary:focus,
.page-header__actions .btn.btn-secondary:hover,
.page-header__actions .btn.btn-secondary:focus {
  background-color: #217ac0 !important;
  color: #fff !important;
  border-color: #217ac0 !important;
}

.btn-danger {
  background-color: var(--color-button-danger) !important;
  color: #fff !important;
}

.btn-danger:hover,
.btn-danger:focus {
  background-color: #b71c1c !important;
  color: #fff !important;
}

.btn-success {
  background-color: var(--color-button-success) !important;
  color: #fff !important;
}

.btn-success:hover,
.btn-success:focus {
  background-color: #245924 !important;
  color: #fff !important;
}

.btn-flat {
  background-color: transparent !important;
  color: var(--color-button-primary) !important;
  border: 1px solid rgba(33, 150, 243, 0.35) !important;
  height: 36px;
  line-height: 34px;
}

.btn-flat:hover,
.btn-flat:focus {
  background-color: rgba(33, 150, 243, 0.08) !important;
  color: var(--color-button-primary) !important;
}

/* Dashboard layout */
.container-dashboard {
  padding: 20px 18px;
  width: 100%;
  max-width: none;
  margin: 0;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

@media (max-width: 640px) {
  .container-dashboard {
    padding: 16px 12px;
    gap: 16px;
  }
}

.header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.header-row h4 {
  margin: 0;
  font-size: 1.25rem;
  letter-spacing: 0.2px;
}

.range-filters {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  row-gap: 8px;
}

.range-filters a {
  padding: 8px 12px;
  border-radius: 8px;
  text-decoration: none;
  background: transparent;
  color: var(--card-surface-muted, #6b7280);
  font-weight: 600;
  font-size: 0.9rem;
  border: 1px solid transparent;
  flex: 0 0 auto;
}

.range-filters a.active {
  background: var(--card-modern-primary, #2b8bd3);
  color: #fff;
  border-color: rgba(0, 0, 0, 0.04);
}

@media (max-width: 600px) {
  .range-filters {
    width: 100%;
    justify-content: space-between;
  }

  .range-filters a {
    flex: 1 1 calc(50% - 8px);
    text-align: center;
  }
}

.container-dashboard .row {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 0;
}

.dashboard-panels {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
  width: 100%;
}

@media (max-width: 640px) {
  .dashboard-panels {
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
  }
}

.container-dashboard .row.metrics-grid,
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--card-modern-grid-gap, 16px);
  align-items: stretch;
}

.metrics-grid .card-modern.metric {
  width: 100%;
  min-width: 0;
}

@media (max-width: 600px) {
  .metrics-grid {
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
  }
}

.plot-container {
  width: 100%;
  box-sizing: border-box;
  min-height: 240px;
  overflow-x: hidden;
}

.plotly-graph-div {
  width: 100% !important;
  max-width: 100% !important;
  overflow: hidden;
}

.plotly-graph-div .main-svg,
.plotly-graph-div svg {
  max-width: 100% !important;
}

.chartjs-render-monitor,
.card-modern canvas {
  max-width: 100% !important;
  width: 100% !important;
}

.card-title {
  font-size: 1.5rem;
  font-weight: 400;
  text-transform: uppercase;
}

.card-title {
  margin: 10px 0 6px 0;
}

.tranche-controls {
  align-items: center;
}

.tranche-toggle {
  display: inline-flex;
  border: 1px solid #cfd8f6;
  border-radius: 999px;
  overflow: hidden;
}

.tranche-toggle__btn {
  min-width: 42px;
  height: 38px;
  border-radius: 0;
  font-weight: 700;
  font-size: 1rem;
  line-height: 1;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #f8fafc;
  border: none;
  color: #475569;
  transition: background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}

.tranche-toggle__btn:first-child {
  border-right: 1px solid #cfd8f6;
}

.tranche-toggle__btn.is-active {
  background: #1d4ed8;
  color: #fff;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.3);
}

.tranche-toggle__btn:not(.is-active) {
  opacity: 0.65;
}

.tranche-toggle__btn:focus-visible {
  outline: 2px solid #1d4ed8;
  outline-offset: 2px;
}

.page-header.collapsed {
  margin-left: 0;
  width: 100%;
}


.option-badge {
  display: inline-block;
  padding: 2px 6px;
  margin-right: 4px;
  margin-bottom: 2px;
  font-size: 0.85em;
  color: #333;
  background-color: #eee;
  border: 1px solid #ddd;
  border-radius: 4px;
}

.btn.teal { background-color: #00897b !important; color: white !important; }
.btn.red { background-color: var(--color-button-danger) !important; color: white !important; }
.btn.green { background-color: var(--color-button-success) !important; color: white !important; }

.ml-1 { margin-left: 0.25rem; }
.ml-2 { margin-left: 0.5rem; }
.ml-3 { margin-left: 1rem; }

.product-thumb {
  object-fit: contain;
  justify-content: center;
  align-items: center;
}

/* ======================= USER MANAGEMENT ======================= */
.user-management-grid {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.user-management-page .subuser-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1050;
}

.user-management-page .subuser-modal-overlay.is-open {
  display: flex;
}

.user-management-page .subuser-modal {
  background: #fff;
  border-radius: 18px;
  width: min(520px, calc(100% - 2rem));
  max-height: calc(100vh - 4rem);
  overflow-y: auto;
  box-shadow: 0 25px 45px rgba(15, 23, 42, 0.35);
  padding: 28px;
}

.user-management-page .subuser-modal__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.user-management-page .subuser-modal__close {
  border: 0;
  background: transparent;
  cursor: pointer;
  padding: 4px;
}

.user-management-page .sub-users-table td[data-label] {
  position: relative;
}

.user-management-page .subuser-modal .flex-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.user-management-page .card-content {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.user-management-page .helper-text {
  margin-bottom: 0;
}

.user-management-page .app-form .input-field {
  margin-bottom: 18px;
}

.permission-table-wrapper {
  overflow-x: auto;
}

.permissions-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 480px;
}

.permissions-table th,
.permissions-table td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid #e2e8f0;
}

.permissions-table th {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #475569;
}

.permissions-table td:first-child {
  font-weight: 600;
  color: #0f172a;
}

.permission-toggle {
  text-align: center;
}

.permission-toggle .toggle-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
}

.form-actions {
  margin-top: 16px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* ======================= MEDIA QUERIES ======================= */
@media (max-width: 768px) {
  .topbar {
    padding: 0 8px;
  }

  .logo-area {
    width: auto;
    flex: 0 0 auto;
    padding-left: 0;
  }

  .logo-area__brand {
    display: none;
  }

  .topbar-search-toggle {
    display: inline-flex;
  }

  .topbar-center {
    order: 2;
    flex: 1 1 auto;
  }

  #topbar-search-form {
    display: none;
  }

  .topbar-logo--mobile {
    display: flex;
  }

  .topbar-right {
    order: 3;
    flex: 0 0 auto;
    gap: 0.5rem;
    padding-right: 0;
  }

  /* Sidebar mobile */
  .sidebar { left: -100%; z-index: 1100; }
  .sidebar.mobile-show { left: 0; }

  main.container.with-sidebar,
  .page-header {
    margin-left: 0;
    width: 100%;
  }

  main.container.with-sidebar {
    padding-bottom: 118px;
  }

  .page-header {
    padding: 4px 14px 2px;
    gap: 2px;
    box-shadow: none;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
  }

  .page-header__top {
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
  }

  .page-header--centered .page-header__top {
    align-items: flex-start;
  }

  .page-header__actions {
    display: none;
  }

  .page-filters {
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
    margin-top: 8px;
    padding-bottom: 6px;
    gap: 20px;
    row-gap: 0;
    scrollbar-width: none;
    touch-action: pan-x;
    overscroll-behavior-x: contain;
    overscroll-behavior-y: none;
  }

  .page-filters::-webkit-scrollbar {
    display: none;
  }

  .page-filters a {
    flex: 0 0 auto;
    font-size: 0.82rem;
  }

  .page-breadcrumbs {
    font-size: 0.82rem;
    line-height: 1.25;
  }

  .page-mobile-toolbar {
    display: block;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 8px 16px calc(8px + env(safe-area-inset-bottom));
    z-index: 1200;
    background: var(--color-page-header-bg, #f6f7fb);
    border-top: 1px solid rgba(15, 23, 42, 0.1);
    box-shadow: 0 -8px 24px rgba(15, 23, 42, 0.12);
    opacity: 0;
    transform: translateY(100%);
    transition: transform 0.25s ease, opacity 0.25s ease;
  }

  .page-mobile-toolbar.is-visible {
    opacity: 1;
    transform: translateY(0);
  }

  .page-mobile-toolbar__inner {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }

  .page-mobile-toolbar__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
  }

  .page-mobile-toolbar__actions > .page-header__actions {
    display: flex !important;
    width: 100%;
    margin: 0;
    gap: 8px;
    justify-content: stretch;
    flex-wrap: wrap;
  }

  .page-mobile-toolbar__actions .btn,
  .page-mobile-toolbar__actions .dropdown-trigger,
  .page-mobile-toolbar__actions button {
    flex: 1 1 calc(50% - 8px);
    min-height: 40px;
    border-radius: 10px;
    font-size: 0.9rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    justify-content: center;
  }

  .page-mobile-toolbar__actions .btn-flat {
    border: 1px solid rgba(15, 23, 42, 0.12);
    background: rgba(15, 23, 42, 0.04);
  }

  .topbar .user-info,
  .topbar .user-btn .right {
    display: none !important;
  }

  .mobile-only { display: block; }
}

@media (max-width: 720px) {
  .user-management-grid {
    gap: 16px;
  }

  .user-management-page .subuser-modal {
    width: calc(100% - 1.5rem);
    max-height: calc(100vh - 1.5rem);
    border-radius: 14px;
    padding: 20px;
  }

  .user-management-page .sub-users-table thead {
    display: none;
  }

  .user-management-page .sub-users-table tbody {
    display: flex;
    flex-direction: column;
    gap: 12px;
  }

  .user-management-page .sub-users-table tr {
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 12px 14px;
    background: #fff;
  }

  .user-management-page .sub-users-table td {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    border: none;
    font-size: 0.95rem;
  }

  .user-management-page .sub-users-table td::before {
    content: attr(data-label);
    font-size: 0.75rem;
    font-weight: 600;
    color: #64748b;
    margin-right: 12px;
  }

  .user-management-page .sub-users-table td.actions {
    justify-content: flex-end;
    padding-top: 10px;
  }

  .permissions-table {
    min-width: 0;
  }

  .permissions-table thead {
    display: none;
  }

  .permissions-table tbody {
    display: flex;
    flex-direction: column;
    gap: 12px;
  }

  .permissions-table tr {
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 12px;
    background: #fff;
  }

  .permissions-table td {
    border: none;
    padding: 6px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .permissions-table td::before {
    content: attr(data-label);
    font-size: 0.78rem;
    font-weight: 600;
    color: #475569;
    margin-right: 12px;
  }

  .permission-toggle {
    justify-content: flex-end;
  }
}

@media (min-width: 769px) {
  .mobile-only { display: none !important; }
  .desktop-only {
    display: flex !important;
    flex-direction: column;
    line-height: 1.1;
  }
}

/* ---------------- SIDEBAR ANIMATION ---------------- */
.sidebar {
  transition: transform 0.3s ease; /* già presente */
}

.sidebar.collapsed {
  transform: translateX(-100%);
}


.notification-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  background: red;
  color: white;
  font-size: 0.75rem;
  font-weight: bold;
  border-radius: 50%;
  padding: 2px 6px;
  line-height: 1;
}


/* ======================================= settings.css ======================================= */
.table-action-cell { width: 100px; }


/* ======================================= table helpers ======================================= */
.table-modern__wrapper {
  width: 100%;
  overflow: hidden;
  overflow-x: auto;
  border-radius: 16px;
  background: #fff;
  box-shadow: inset 0 0 0 1px #e3e8f4;
}

.table-modern {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  min-width: 100%;
}

.table-modern thead th {
  background: #edf2fb;
  color: #495064;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
  padding: 12px 16px;
  border-bottom: 1px solid #d8e1f1;
}

.table-modern tbody td {
  padding: 10px 16px;
  border-bottom: 1px solid #ecf0f8;
  color: #1f2a3d;
  vertical-align: middle;
}

.table-modern tbody tr:nth-child(even) {
  background: #f8faff;
}

.table-modern tbody tr:last-child td {
  border-bottom: none;
}

.table-modern tbody tr:hover {
  background: #f1f4fb;
}

.table-modern--compact thead th,
.table-modern--compact tbody td {
  padding: 10px 14px;
}

.table-modern td.actions {
  text-align: right;
}

.table-modern td .btn {
  margin: 0;
}

.table-modern tbody input[type="text"],
.table-modern tbody input[type="number"],
.table-modern tbody input[type="date"],
.table-modern tbody input[type="email"],
.table-modern tbody input[type="tel"],
.table-modern tbody input[type="search"],
.table-modern tbody select,
.table-modern tbody textarea {
  width: 100%;
  box-sizing: border-box;
}

@media (max-width: 720px) {
  #tranche-defaults-table,
  #tranches-table {
    min-width: 100%;
  }

  #tranche-defaults-table thead,
  #tranches-table thead {
    display: none;
  }

  #tranche-defaults-table tbody tr,
  #tranches-table tbody tr {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    padding: 12px 8px;
    border-bottom: 1px solid #ecf0f8;
  }

  #tranche-defaults-table tbody td,
  #tranches-table tbody td {
    flex: 1 1 100%;
    padding: 0;
    border: none;
  }

  #tranche-defaults-table tbody td:nth-child(1),
  #tranche-defaults-table tbody td:nth-child(2),
  #tranches-table tbody td:nth-child(1),
  #tranches-table tbody td:nth-child(2) {
    flex-basis: 100%;
  }

  #tranche-defaults-table tbody td:nth-child(3),
  #tranches-table tbody td:nth-child(3),
  #tranches-table tbody td:nth-child(4) {
    flex: 1 1 calc(50% - 6px);
  }

  #tranche-defaults-table tbody td.actions,
  #tranches-table tbody td.actions {
    flex: 1 1 100%;
    text-align: right;
    margin-top: 4px;
  }

  #tranche-defaults-table tbody tr:nth-child(even),
  #tranches-table tbody tr:nth-child(even) {
    background: transparent;
  }
}

/* ======================================= badges & alerts ======================================= */
.tag {
  display: inline-flex;
  align-items: center;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 4px 10px;
  border-radius: 999px;
  background: #e5edff;
  color: #1d4ed8;
}

.tag--percent {
  background: #e0f4ff;
  color: #0369a1;
}

.tag--fixed {
  background: #fff2d6;
  color: #b45309;
}

.alert {
  display: none;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 12px;
}

.alert--warning {
  display: none;
  background: #fff7db;
  color: #9a6b05;
  border: 1px solid rgba(234, 179, 8, 0.4);
}

.alert--error {
  display: block;
  background: #fde8e7;
  color: #9b1c1c;
  border: 1px solid rgba(220, 38, 38, 0.35);
}
