:root {
  --primary-color: #198754;
  --primary-dark: #0d6e42;
  --primary-light: #28a369;
  --accent-color: #ffc107;
  --text-color: #333;
  --text-light: #6c757d;
  --card-shadow: 0 4px 12px rgba(0,0,0,0.08);
  --transition-speed: 0.3s;
}

/* Font e spaziatura generale */
body {
  font-family: 'Poppins', sans-serif;
  padding-bottom: 20px;
  color: var(--text-color);
  line-height: 1.6;
}

/* Headings */
h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
}

/* Stile per le card con ombreggiatura leggera */
.card {
  margin-bottom: 2rem;
  border: none;
  border-radius: 12px;
  box-shadow: var(--card-shadow);
  overflow: visible; /* Cambiato da hidden a visible per permettere la visualizzazione completa delle tabelle */
  position: relative;
  z-index: 1020;
}

/* Le card con tabelle devono permettere overflow (compatibilità con browser più vecchi) */
.card table,
.card .table-responsive,
.card .table-wrapper {
  overflow: visible;
}

.card-header {
  background-color: rgba(25, 135, 84, 0.03);
  border-bottom: 1px solid rgba(25, 135, 84, 0.1);
  font-weight: 600;
  padding: 1rem 1.5rem;
}

.card-body {
  padding: 1.5rem;
}

/* Stile per la lista dei risultati di ricerca */
.results {
  position: absolute;
  width: 100%;
  max-height: 200px;
  overflow-y: auto;
  z-index: 1040 !important; /* Ridotto per non interferire con i modal */
  background-color: #fff;
  border: none;
  border-radius: 10px;
  box-shadow: var(--card-shadow);
  display: none;
}

/* Stile specifico per i suggerimenti dei clienti */
#client-suggestions {
  z-index: 1050 !important;
  background-color: white !important;
  border: 1px solid #dee2e6 !important;
  border-radius: 0.375rem !important;
  box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15) !important;
  position: fixed !important;
  max-height: 200px !important;
  overflow-y: auto !important;
}

.results .list-group-item {
  cursor: pointer;
  border-radius: 5px;
  margin: 2px 0;
  transition: all 0.2s ease;
}

.results .list-group-item:hover {
  background-color: rgba(25, 135, 84, 0.07);
  transform: translateX(3px);
}

/* Stili per gli elementi dei suggerimenti clienti */
#client-suggestions .list-group-item {
  cursor: pointer;
  border-radius: 5px;
  margin: 2px 0;
  transition: all 0.2s ease;
  border: none;
  padding: 0.75rem 1rem;
}

#client-suggestions .list-group-item:hover {
  background-color: rgba(25, 135, 84, 0.1);
  transform: translateX(3px);
}

#client-suggestions .list-group-item:first-child {
  border-top-left-radius: 0.375rem;
  border-top-right-radius: 0.375rem;
}

#client-suggestions .list-group-item:last-child {
  border-bottom-left-radius: 0.375rem;
  border-bottom-right-radius: 0.375rem;
}

/* Assicura che i select e i form abbiano dimensioni adeguate */
.wide-select {
  min-width: 150px;
}

/* Pulsanti migliorati */
.btn {
  border-radius: 8px;
  font-weight: 500;
  transition: all 0.25s ease;
  border: none;
  box-shadow: 0 2px 5px rgba(0,0,0,0.08);
  position: relative;
  z-index: 1021; /* Assicura che i pulsanti siano sopra il contenuto */
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0,0,0,0.12);
}

.btn-success {
  background-color: var(--primary-color);
}

.btn-success:hover {
  background-color: var(--primary-dark);
}

.btn-outline-success {
  border: 1px solid var(--primary-color);
  color: var(--primary-color);
}

/* Assicura che i gruppi di pulsanti siano visibili */
.btn-group {
  position: relative;
  z-index: 1021;
}

/* Assicura che i container principali siano visibili */
.container, .container-fluid {
  position: relative;
  z-index: 1020;
  margin-top: 0; /* Rimosso margine eccessivo */
}

/* Dropdown menu */
.dropdown-menu {
  border: none;
  box-shadow: var(--card-shadow);
  border-radius: 8px;
  padding: 8px;
  z-index: 1040 !important;
  pointer-events: auto !important;
}

.dropdown-item {
  border-radius: 5px;
  padding: 8px 15px;
  transition: all 0.2s ease;
}

.dropdown-item:hover {
  background-color: rgba(25, 135, 84, 0.1);
  transform: translateX(3px);
}

/* Form migliorati */
.form-control, .form-select {
  border-radius: 8px;
  padding: 0.6rem 1rem;
  border: 1px solid rgba(0,0,0,0.1);
  transition: all var(--transition-speed) ease;
}

.form-control:focus, .form-select:focus {
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(25, 135, 84, 0.15);
}

/* Tabelle migliorate */
.table {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
}

.table thead th {
  background-color: rgba(25, 135, 84, 0.06);
  border-bottom: 2px solid rgba(25, 135, 84, 0.1);
  font-weight: 600;
  color: var(--primary-dark);
}

.table tbody tr {
  transition: all 0.2s ease;
}

.table tbody tr:hover {
  background-color: rgba(25, 135, 84, 0.03);
}

/* Ridurre lo spazio nelle tabelle */
table.table th,
table.table td {
  padding: 0.35rem 0.5rem;
}

/* Assicura che i pulsanti nelle tabelle siano visibili */
table.table .btn {
  position: relative;
  z-index: 1022;
}

/* Assicura che i pulsanti nelle card siano visibili */
.card .btn {
  position: relative;
  z-index: 1022;
}

/* Assicura che i pulsanti nei container siano visibili */
.container .btn, .container-fluid .btn {
  position: relative;
  z-index: 1022;
}

/* Assicura spazio extra per i pulsanti nella parte superiore delle pagine */
.row.mb-4:first-child {
  margin-top: 10px !important; /* Ridotto */
}

/* Stile specifico per i pulsanti di azione principali */
.btn-primary.btn:first-of-type {
  margin-top: 5px; /* Ridotto */
}

/* Regola specifica per evitare che il contenuto sia coperto dal navbar */
.container-fluid > .row:first-child {
  margin-top: 10px !important; /* Ridotto drasticamente */
  padding-top: 5px !important; /* Ridotto drasticamente */
}

/* Footer in fondo alla pagina */
.footer {
  background-color: #f8f9fa;
  padding: 1rem;
  text-align: center;
  box-shadow: 0 -2px 10px rgba(0,0,0,0.05);
}

/* ===== REGOLE CSS PER RESPONSIVITÀ ===== */
/* Rimossa regola display: block sulle tabelle per evitare problemi di visualizzazione */
table {
  width: 100%;
  max-width: 100%;
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  position: relative;
  z-index: 1020;
  display: block;
}

/* Wrapper scrollabile per tabelle con molti risultati */
.table-wrapper {
  max-height: none;
  overflow-y: visible;
  overflow-x: auto;
}

/* Assicura che le tabelle nelle card siano completamente visibili */
.card table,
.card .table-responsive {
  overflow: visible;
}

.card .table-wrapper {
  overflow-y: visible;
  overflow-x: auto;
}

@media (max-width: 576px) {
  body {
    padding-top: 100px !important; /* Ridotto per mobile */
  }
  .container {
    padding-left: 10px;
    padding-right: 10px;
  }
  table {
    font-size: 0.85rem;
  }
  table td, table th {
    padding: 0.5rem;
    white-space: nowrap;
  }
  table .btn {
    padding: 0.2rem 0.5rem;
    font-size: 0.75rem;
  }
  table td form {
    min-width: auto !important;
    width: auto !important;
  }
  .dropdown-menu {
    font-size: 0.9rem;
  }
  input, select, textarea {
    max-width: 100%;
  }
  .btn-group-sm > .btn, .btn-sm {
    padding: 0.25rem 0.4rem;
    font-size: 0.75rem;
  }
}

@media (max-width: 991.98px) {
  .navbar-nav .dropdown-menu {
    border: none;
    padding-left: 1rem;
    background-color: transparent;
  }
  .navbar-nav .dropdown-item {
    color: rgba(255, 255, 255, 0.85);
  }
  .navbar-nav .dropdown-item:hover {
    background-color: rgba(255, 255, 255, 0.1);
    color: white;
  }
}

/* Stili per le notifiche */
.notification-item.unread {
  background-color: rgba(25, 135, 84, 0.05);
  border-left: 3px solid #198754;
}

.notification-item {
  border-left: 3px solid transparent;
  transition: background-color 0.3s ease;
}

.notification-item:hover {
  background-color: rgba(0, 0, 0, 0.03);
}

.notification-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background-color: rgba(25, 135, 84, 0.1);
  border-radius: 50%;
}

.notification-actions {
  opacity: 0.2;
  transition: opacity 0.3s ease;
}

.notification-item:hover .notification-actions {
  opacity: 1;
}

#notification-badge {
  font-size: 0.65rem;
  transform: translate(-50%, -50%) !important;
  box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

/* Animazioni */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.content-fade-in {
  animation: fadeIn 0.4s ease forwards;
}

/* Stili per la dashboard */
.dashboard-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.stat-card {
  background: white;
  border-radius: 12px;
  padding: 1.5rem;
  box-shadow: var(--card-shadow);
  transition: transform 0.2s ease;
}

.stat-card:hover {
  transform: translateY(-5px);
}

.stat-card h3 {
  color: var(--text-light);
  font-size: 0.9rem;
  text-transform: uppercase;
  margin-bottom: 0.5rem;
}

.stat-card .value {
  font-size: 2rem;
  font-weight: 600;
  color: var(--primary-color);
}

.performance-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 1.5rem;
  margin-top: 2rem;
}

.performance-card {
  background: white;
  border-radius: 12px;
  padding: 1.5rem;
  box-shadow: var(--card-shadow);
}

.performance-card h4 {
  color: var(--text-color);
  margin-bottom: 1rem;
  font-size: 1.1rem;
}

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

.performance-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 0;
  border-bottom: 1px solid rgba(0,0,0,0.05);
}

.performance-item:last-child {
  border-bottom: none;
}

.performance-item .label {
  color: var(--text-light);
}

.performance-item .value {
  font-weight: 500;
  color: var(--primary-color);
}

.badge {
  font-weight: 500;
  border-radius: 6px;
  padding: 0.35em 0.65em;
}

/* Stili specifici per i badge delle quantità nel magazzino */
.badge-danger {
  background-color: #dc3545 !important;
  color: white !important;
  font-weight: 600 !important;
  text-shadow: 0 1px 2px rgba(0,0,0,0.3) !important;
}

.badge-warning {
  background-color: #ffc107 !important;
  color: #212529 !important;
  font-weight: 600 !important;
  text-shadow: 0 1px 2px rgba(255,255,255,0.5) !important;
}

.badge-success {
  background-color: #198754 !important;
  color: white !important;
  font-weight: 600 !important;
  text-shadow: 0 1px 2px rgba(0,0,0,0.3) !important;
}

.badge-primary {
  background-color: #0d6efd !important;
  color: white !important;
  font-weight: 600 !important;
  text-shadow: 0 1px 2px rgba(0,0,0,0.3) !important;
}

/* Stili per i badge nelle tabelle */
.table .badge {
  font-size: 0.85rem;
  padding: 0.4em 0.7em;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* Stili specifici per le quantità nel magazzino */
.warehouse-quantity {
  font-weight: 700;
  font-size: 1rem;
  padding: 0.5em 0.8em;
  border-radius: 10px;
  border: 2px solid;
  box-shadow: 0 3px 6px rgba(0,0,0,0.15);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.warehouse-quantity.badge-danger {
  background-color: #dc3545 !important;
  color: white !important;
  border-color: #c82333 !important;
  text-shadow: 0 2px 4px rgba(0,0,0,0.4) !important;
}

.warehouse-quantity.badge-warning {
  background-color: #ffc107 !important;
  color: #212529 !important;
  border-color: #e0a800 !important;
  text-shadow: 0 2px 4px rgba(255,255,255,0.6) !important;
}

.warehouse-quantity.badge-success {
  background-color: #198754 !important;
  color: white !important;
  border-color: #146c43 !important;
  text-shadow: 0 2px 4px rgba(0,0,0,0.4) !important;
}

/* ===== CORREZIONI FINALI PER IL LAYOUT ===== */

/* Regola di emergenza per assicurare che il contenuto delle pagine sia sempre visibile */
body.modal-open {
  padding-right: 0 !important; /* Evita problemi con le scrollbar nei modal */
}

/* Regola specifica per evitare sovrapposizioni del navbar */
.navbar.fixed-top + .container,
.navbar.fixed-top + .container-fluid,
.navbar.fixed-top ~ .container,
.navbar.fixed-top ~ .container-fluid {
  margin-top: 0 !important;
  padding-top: 0 !important; /* Rimosso padding eccessivo */
}

/* Rimuovi il margine Bootstrap che interferisce */
.container.mt-3,
.container-fluid.mt-3 {
  margin-top: 0 !important;
}

/* Regola di emergenza per il contenuto principale */
.content-fade-in {
  margin-top: 0.5rem !important;
  padding-top: 0 !important; /* Rimosso padding eccessivo */
}

/* Ottimizzazioni aggiuntive per la navbar ultra-compatta */
.navbar-nav .nav-item {
  margin: 0 1px;
}

.dropdown-item {
  padding: 0.25rem 0.6rem;
  font-size: 0.7rem;
}

.dropdown-item i {
  font-size: 0.65rem;
  width: 14px;
}

.badge {
  font-size: 0.55rem;
  padding: 0.15em 0.3em;
}

/* ===== CORREZIONI DRAMMATICHE PER IL CONTAINER ===== */

/* Forza l'altezza del container a essere minima */
.container-fluid.px-2 {
  max-height: 35px !important;
  min-height: auto !important;
  height: auto !important;
  line-height: 1 !important;
  padding: 0.05rem 0.5rem !important;
  margin: 0 !important;
  overflow: visible !important;
  display: flex !important;
  align-items: center !important;
  flex-wrap: nowrap !important;
}

/* Assicura che tutti gli elementi della navbar siano ultra-compatti */
.navbar > .container-fluid.px-2 > * {
  max-height: 30px !important;
  min-height: auto !important;
  height: auto !important;
  line-height: 1 !important;
  margin: 0 !important;
  padding: 0.05rem 0.25rem !important;
}

/* Forza la compattezza su tutti i dispositivi */
@media (max-width: 1400px) {
  .container-fluid.px-2 {
    max-height: 32px !important;
  }
}

@media (max-width: 1200px) {
  .container-fluid.px-2 {
    max-height: 30px !important;
  }
}

@media (max-width: 991.98px) {
  .container-fluid.px-2 {
    max-height: 28px !important;
  }
}