* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #f4f6f8;
  min-height: 100vh;
  overflow-x: hidden;
}

/* LAYOUT APP */
.app-container {
  display: flex;
  min-height: 100vh;
}

/* SIDEBAR */
.sidebar {
  width: 260px;
  background: white;
  box-shadow: 2px 0 15px rgba(0, 0, 0, 0.05);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform 0.3s ease;
}

.sidebar-header {
  padding: 20px;
  background: linear-gradient(135deg, #f5a623 0%, #f7b733 100%);
  color: white;
  text-align: center;
}

.sidebar-header .logo {
  width: 60px;
  height: 60px;
  background: white;
  color: #f5a623;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 20px;
  margin: 0 auto 10px;
}

.sidebar-nav {
  flex: 1;
  padding: 20px 0;
  display: flex;
  flex-direction: column;
}

.sidebar-nav a {
  padding: 15px 25px;
  color: #555;
  text-decoration: none;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 15px;
  border-left: 4px solid transparent;
  transition: all 0.2s;
}

.sidebar-nav a:hover {
  background: #fdfaf5;
  color: #f5a623;
}

.sidebar-nav a.active {
  background: #fff3e0;
  color: #f5a623;
  border-left-color: #f5a623;
}

.sidebar.collapsed-pc {
  margin-left: -260px;
}

/* MOBILE OVERLAY & TOGGLE */
.mobile-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 90;
}

.mobile-toggle {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 60px;
  height: 60px;
  background: #bd7400;
  color: white;
  border-radius: 50%;
  border: 3px solid #573600;
  font-size: 24px;
  box-shadow: 0 4px 15px rgba(245, 166, 35, 0.4);
  z-index: 101;
  cursor: pointer;
}

/* MAIN CONTENT */
.main-content {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  background: linear-gradient(135deg, #f5a623 0%, #f7b733 100%);
}

.content-wrapper {
  margin: 0 auto;
}

.tab-content {
  display: none;
  animation: fadeIn 0.3s;
}

.tab-content.active {
  display: block;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* HEADER INTERNO */
header {
  background: white;
  padding: 15px 25px;
  border-radius: 12px;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
  margin-bottom: 20px;
}

header h2 {
  color: #1a1a1a;
  font-size: 22px;
}

header p {
  color: #666;
  font-size: 13px;
}

/* WIDGETS E CARD ESISTENTI */
.dashboard {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 15px;
  margin-bottom: 20px;
}

.stat-card {
  background: white;
  padding: 20px;
  border-radius: 12px;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.stat-card h3 {
  font-size: 14px;
  color: #666;
  margin-bottom: 10px;
  text-transform: uppercase;
}

.stat-number {
  font-size: 36px;
  font-weight: bold;
  color: #f5a623;
  margin-bottom: 5px;
}

.stat-detail {
  font-size: 12px;
  color: #999;
}

.course-progress {
  margin-top: 15px;
}

.course-item {
  margin-bottom: 12px;
}

.course-name {
  font-size: 13px;
  font-weight: 600;
  color: #333;
  margin-bottom: 5px;
  display: flex;
  justify-content: space-between;
}

.progress-bar {
  height: 8px;
  background: #e0e0e0;
  border-radius: 10px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #f5a623, #f7b733);
  transition: width 0.3s ease;
}

.waiting-tables-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 15px;
  margin-bottom: 25px;
}

.waiting-tables {
  background: white;
  padding: 20px;
  border-radius: 12px;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.waiting-tables h3 {
  font-size: 14px;
  color: #666;
  margin-bottom: 15px;
  text-transform: uppercase;
}

.waiting-scroll-container {
  max-height: 250px;
  overflow-y: auto;
  padding-right: 5px;
}

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 10px;
}

::-webkit-scrollbar-thumb {
  background: #f5a623;
  border-radius: 10px;
}

.waiting-table-item {
  padding: 12px;
  background: #fff3e0;
  border-left: 4px solid #f5a623;
  border-radius: 6px;
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.wait-time-badge {
  font-weight: bold;
  color: #dc3545;
  font-size: 12px;
  background: #ffebee;
  padding: 3px 8px;
  border-radius: 10px;
}

.no-waiting {
  color: #28a745;
  font-weight: 600;
  text-align: center;
  padding: 20px;
}

.setup-section {
  background: white;
  padding: 25px;
  border-radius: 12px;
  margin-bottom: 20px;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.setup-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  border-bottom: 1px solid #eee;
  padding-bottom: 10px;
  flex-wrap: wrap;
  gap: 10px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 15px;
  margin-bottom: 20px;
}

.form-group {
  display: flex;
  flex-direction: column;
}

label {
  font-size: 14px;
  font-weight: 600;
  color: #555;
  margin-bottom: 5px;
}

input,
select {
  padding: 12px;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  font-size: 15px;
}

input:focus,
select:focus {
  outline: none;
  border-color: #f5a623;
}

button {
  padding: 10px 20px;
  background: linear-gradient(135deg, #f5a623, #f7b733);
  color: white;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-secondary {
  background: #6c757d;
}

.btn-success {
  background: #28a745;
}

.btn-outline {
  background: transparent;
  border: 2px solid #f5a623;
  color: #f5a623;
}

/* GRIGLIA TAVOLI */
.unassigned-tables {
  background: white;
  padding: 20px;
  border-radius: 12px;
  margin-bottom: 20px;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.unassigned-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.badge {
  background: #dc3545;
  color: white;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 12px;
}

.unassigned-list {
  display: none;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 15px;
  padding-top: 15px;
  border-top: 1px dashed #eee;
}

.unassigned-list.visible {
  display: flex;
}

.draggable-table {
  background: #f8f9fa;
  padding: 10px 15px;
  border-radius: 8px;
  cursor: move;
  border: 2px solid #e0e0e0;
  font-size: 14px;
  user-select: none;
}

.draggable-table.selected-for-drop {
  background: #fff3e0;
  border-color: #f5a623;
  transform: scale(1.05);
}

.grid-wrapper {
  width: 100%;
  overflow-x: auto;
  padding-bottom: 10px;
}

.tables-container {
  display: flex;
  flex-direction: column;
  gap: 15px;
  padding: 20px;
  background: white;
  border-radius: 12px;
  min-height: 400px;
  min-width: max-content;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.grid-row {
  display: grid;
  gap: 15px;
}

.grid-cell {
  border: 2px dashed #e0e0e0;
  border-radius: 8px;
  min-height: 120px;
  display: flex;
  align-items: stretch;
  justify-content: center;
  cursor: pointer;
}

.grid-cell:hover {
  background: #fdfaf5;
  border-color: #f5a623;
}

.grid-cell.occupied {
  border: none;
  padding: 0;
  background: transparent;
  cursor: default;
}

.table-card {
  background: white;
  border-radius: 10px;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.1);
  width: 100%;
  min-width: 160px;
  overflow: hidden;
  border: 1px solid #e0e0e0;
  cursor: pointer;
}

.table-header {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  border-bottom: 2px solid #e0e0e0;
}

.table-name-cell {
  padding: 10px 12px;
  font-size: 15px;
  font-weight: 700;
  border-right: 1px solid #e0e0e0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
  user-select: none;
}

.table-count-cell {
  padding: 8px 10px;
  text-align: center;
  border-right: 1px solid #e0e0e0;
  min-width: 40px;
  cursor: pointer;
}

.count-label {
  font-size: 10px;
  color: #999;
  display: block;
}

.count-value {
  font-size: 15px;
  font-weight: 700;
  color: #1a1a1a;
}

.table-next-step {
  padding: 7px 12px;
  font-size: 12px;
  color: #555;
  background: #fafafa;
}

.courses-list {
  display: none;
  flex-direction: column;
}

.table-card.expanded .courses-list {
  display: flex;
}

.course-checkbox {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  border-top: 1px solid #f0f0f0;
  font-size: 13px;
}

.course-checkbox.served {
  background: #f0faf3;
  border-left: 3px solid #28a745;
}

.course-checkbox.partial {
  background: #fffbf0;
  border-left: 3px solid #ffc107;
}

/* STATS PAGE STYLES */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 20px;
  margin-bottom: 20px;
}

.big-stat-box {
  background: white;
  padding: 25px;
  border-radius: 12px;
  text-align: center;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.big-stat-box h4 {
  color: #666;
  font-size: 15px;
  margin-bottom: 10px;
}

.big-stat-box .value {
  font-size: 40px;
  color: #f5a623;
  font-weight: 800;
}

.big-stat-box .sub-value {
  font-size: 13px;
  color: #999;
  margin-top: 5px;
}

/* MODALS */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100dvh;
  background: rgba(0, 0, 0, 0.6);
  z-index: 1000;
  justify-content: center;
  align-items: center;
  padding: 15px;
}

.modal.active {
  display: flex;
}

.modal-content {
  background: white;
  padding: 25px;
  border-radius: 15px;
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.close-btn {
  background: none;
  border: none;
  font-size: 28px;
  color: #666;
  cursor: pointer;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

.course-list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px;
  background: #f8f9fa;
  border: 1px solid #eee;
  border-radius: 8px;
  margin-bottom: 8px;
}

.btn-icon {
  padding: 5px 8px;
  font-size: 12px;
  background: #e9ecef;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

@media (max-width: 768px) {
  .waiting-tables-container {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: -260px;
    height: 100%;
  }

  .sidebar.active {
    left: 0;
  }

  .mobile-overlay.active {
    display: block;
  }

  .mobile-toggle {
    display: block;
  }
}

/* --- STILI AGGIUNTIVI PER MASTER CARD E GRIGLIA RIGHE --- */

.master-card {
  border: 2px solid #343a40; /* Bordo più scuro per evidenziare la gerarchia */
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.master-card .courses-list {
  /* Nella master card le portate calcolate in JS sono sempre visibili */
  display: flex !important;
  flex-direction: column;
}

.master-summary {
  background: #343a40 !important;
  color: #fff !important;
  text-transform: uppercase;
  font-size: 11px !important;
}

/* 
  Sticky: Fa in modo che la prima colonna (Master) rimanga fissa
  a sinistra mentre si scorre la griglia orizzontalmente da mobile
*/
.master-cell {
  position: sticky;
  left: 0;
  z-index: 10;
  background: white; /* Nasconde le celle che passano sotto in scroll */
  border-radius: 10px;
}

/* Limita la larghezza massima a 130px e adatta i testi */
.table-card {
  min-width: unset; /* Rimuove i 160px originali */
  max-width: 130px; /* Forza la card a 130px massimi */
}

.master-card {
  max-width: none; /* La master-card (quella a sinistra) deve rimanere larga */
}

/* Permette al nome di andare a capo e riduce leggermente i padding */
.table-name-cell {
  padding: 8px 6px;
  font-size: 13px;
  white-space: normal;
  -webkit-line-clamp: 3; /* Fino a 3 righe per il nome */
}

.table-count-cell {
  min-width: 32px; /* Ridotto leggermente per far spazio al nome */
  padding: 6px;
}

.course-checkbox {
  padding: 6px 8px; /* Ottimizza gli spazi del menù */
}

/* Transizioni per l'effetto focus sulla Riga */
.grid-row {
  transition: opacity 0.55s ease-in-out;
}

/* Quando è attiva la modalità focus, opacizza tutte le righe... */
.tables-container.dim-others-active .grid-row {
  opacity: 0.55;
}

/* ...Tranne quella esplicitamente attiva */
.tables-container.dim-others-active .grid-row.is-active-row {
  opacity: 1;
}
