/* ==============================================================================
   TRACCIATO STUDIO OS - MODULO COMMESSE (CSS SWISS MINIMAL)
   ==============================================================================
   Stili dedicati per:
   - Header modulo, badge contatori e selettore visualizzazione (Griglia / Kanban)
   - Barra di ricerca istantanea e filtri rapidi a pillola (Edilizia, Catasto, ecc.)
   - Griglia Tecnica "Excel di Lusso" (tabella densa ad alta leggibilità)
   - Tabellone Kanban a 5 Colonne (In Corso, Attesa SUE, Approvata, Completata, Archiviata)
   - Badge semantici, micro-progress bar e avatar responsabili
   ============================================================================== */

/* --- 1. CONTENITORE PRINCIPALE VISTA COMMESSE --- */
.commesse-view {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  padding-bottom: 3rem;
}

/* --- 2. HEADER MODULO & CONTROLLI SUPERIORI --- */
.commesse-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1.5rem;
  flex-wrap: wrap;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border-subtle);
}

.commesse-header-info {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.commesse-eyebrow-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.commesse-title {
  font-size: var(--text-2xl);
  font-weight: 700;
  letter-spacing: -0.025em;
  color: var(--text-primary);
  margin: 0;
  line-height: 1.2;
}

.commesse-subtitle {
  font-size: var(--text-sm);
  color: var(--text-body);
  margin: 0;
}

.commesse-header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* Toggle Selettore Vista: Griglia / Kanban */
.view-mode-toggle {
  display: inline-flex;
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 2px;
}

.btn-view-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 4px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.btn-view-toggle svg {
  width: 14px;
  height: 14px;
}

.btn-view-toggle:hover {
  color: var(--text-primary);
}

.btn-view-toggle.is-active {
  background: var(--surface-3);
  color: var(--text-primary);
  box-shadow: var(--shadow-subtle);
  border: 1px solid var(--border-subtle);
}

/* Pulsante Primario + Nuova Commessa */
.btn-primary-action {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 1rem;
  background: var(--blue);
  border: 1px solid var(--blue-hover);
  border-radius: var(--radius-sm);
  color: #FFFFFF;
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(59, 130, 246, 0.35);
  transition: all var(--transition-fast);
}

.btn-primary-action:hover {
  background: var(--blue-hover);
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.45);
  transform: translateY(-1px);
}

.btn-primary-action:active {
  transform: translateY(0);
}


/* --- 3. BARRA DI CONTROLLO ISTANTANEA (SEARCH & FILTERS) --- */
.commesse-filter-bar {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  background: var(--surface-1);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  padding: 0.85rem 1rem;
}

.filter-bar-top {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.commesse-search-box {
  position: relative;
  flex: 1;
  min-width: 260px;
}

.commesse-search-icon {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
  width: 15px;
  height: 15px;
}

.commesse-search-input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem 0.5rem 2.25rem;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  transition: all var(--transition-fast);
}

.commesse-search-input:focus {
  outline: none;
  border-color: var(--border-focus);
  background: var(--surface-3);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}

.commesse-search-input::placeholder {
  color: var(--text-muted);
}

.filter-select {
  background: var(--surface-2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.85rem;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.filter-select:focus {
  outline: none;
  border-color: var(--border-focus);
  color: var(--text-primary);
}

/* Pulsante Toggle Nascondi Ultimate */
.btn-hide-completed {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0.5rem 0.85rem;
  background: var(--surface-2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
  user-select: none;
}

.btn-hide-completed:hover {
  background: var(--surface-3);
  color: var(--text-primary);
  border-color: var(--border-medium);
}

.btn-hide-completed.is-active {
  background: var(--blue-subtle);
  border-color: var(--blue-border);
  color: var(--blue);
  font-weight: 600;
}

.toggle-switch-icon {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  border: 1.5px solid currentColor;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.btn-hide-completed.is-active .toggle-switch-icon {
  background: var(--blue);
  border-color: var(--blue);
}

.btn-hide-completed.is-active .toggle-switch-icon::after {
  content: "";
  width: 4px;
  height: 7px;
  border: solid #FFFFFF;
  border-width: 0 1.5px 1.5px 0;
  transform: rotate(45deg) translate(-0.5px, -0.5px);
}

/* Pillole Filtro Tipologia */
.commesse-pills-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}

.commesse-pills-row::-webkit-scrollbar {
  display: none;
}

.filter-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-subtle);
  background: var(--surface-2);
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.filter-pill:hover {
  color: var(--text-primary);
  border-color: var(--border-medium);
  background: var(--surface-3);
}

.filter-pill.is-active {
  background: var(--blue-subtle);
  border-color: var(--blue-border);
  color: var(--blue);
  font-weight: 600;
}

.pill-count {
  font-family: var(--font-mono);
  font-size: 11px;
  opacity: 0.75;
}

.filter-summary-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: var(--text-xs);
  color: var(--text-muted);
  padding-top: 0.25rem;
  border-top: 1px solid var(--border-subtle);
}

.btn-reset-filters {
  background: none;
  border: none;
  color: var(--blue);
  font-size: var(--text-xs);
  font-weight: 500;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
}

.btn-reset-filters:hover {
  color: var(--blue-hover);
}


/* --- 4. VISTA 1: GRIGLIA TECNICA (EXCEL DI LUSSO) --- */
.commesse-table-container {
  background: var(--surface-1);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  overflow-x: auto;
  box-shadow: var(--shadow-subtle);
}

.commesse-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: var(--text-sm);
  white-space: nowrap;
}

.commesse-table thead {
  background: var(--surface-2);
  border-bottom: 1px solid var(--border-medium);
}

.commesse-table th {
  padding: 0.65rem 1rem;
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  user-select: none;
}

.commesse-table tbody tr {
  border-bottom: 1px solid var(--border-subtle);
  transition: background-color var(--transition-fast);
  cursor: pointer;
}

.commesse-table tbody tr:hover {
  background: var(--surface-2);
}

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

.commesse-table td {
  padding: 0.75rem 1rem;
  vertical-align: middle;
}

/* Colonna 1: Codice & Icona Tipo */
.col-codice {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: var(--text-xs);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.col-codice .type-icon {
  font-size: 13px;
}

/* Colonna 2: Titolo & Indirizzo */
.col-titolo-cell {
  min-width: 420px;
  max-width: 650px;
  white-space: normal;
}

.commessa-grid-title {
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
  margin-bottom: 2px;
}

.commessa-grid-address {
  font-size: var(--text-xs);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Colonna 3: Committente */
.commessa-grid-client {
  font-weight: 500;
  color: var(--text-secondary);
}

.commessa-grid-client-type {
  font-size: 11px;
  color: var(--text-muted);
}

/* Colonna 4: Comune & Dati Catastali */
.commessa-grid-comune {
  font-weight: 500;
  color: var(--text-secondary);
}

.commessa-grid-catasto {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 3px;
  display: inline-block;
  margin-top: 2px;
}

/* Colonna 5: Badge Stato Semantico */
.badge-status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.badge-status::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.status-in-corso {
  background: var(--amber-subtle);
  color: #FBBF24;
  border: 1px solid var(--amber-border);
}
.status-in-corso::before { background: #F59E0B; }

.status-attesa-sue {
  background: rgba(147, 51, 234, 0.12);
  color: #C084FC;
  border: 1px solid rgba(147, 51, 234, 0.28);
}
.status-attesa-sue::before { background: #A855F7; }

.status-approvata {
  background: var(--emerald-subtle);
  color: #34D399;
  border: 1px solid var(--emerald-border);
}
.status-approvata::before { background: #10B981; }

.status-completata {
  background: rgba(59, 130, 246, 0.10);
  color: #60A5FA;
  border: 1px solid var(--blue-border);
}
.status-completata::before { background: #3B82F6; }

.status-archiviata {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-muted);
  border: 1px solid var(--border-subtle);
}
.status-archiviata::before { background: var(--text-dim); }

/* Colonna 6: Tecnico Responsabile */
.responsabile-cell {
  display: flex;
  align-items: center;
  gap: 7px;
}

.avatar-initials {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--surface-3);
  border: 1px solid var(--border-medium);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  color: var(--text-secondary);
}

/* Colonna 7: Ore Lavorate */
.hours-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-primary);
  background: var(--surface-2);
  padding: 3px 7px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
}

.hours-badge svg {
  width: 12px;
  height: 12px;
  color: var(--text-muted);
}

/* Colonna 8: Micro Progress Bar Compiti */
.progress-cell {
  min-width: 110px;
}

.progress-label-row {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-muted);
  margin-bottom: 3px;
}

.commessa-progress-track {
  width: 100%;
  height: 5px;
  background: var(--surface-3);
  border-radius: var(--radius-pill);
  overflow: hidden;
}

.commessa-progress-fill {
  height: 100%;
  background: var(--emerald);
  border-radius: var(--radius-pill);
  transition: width 0.3s ease;
}

/* Colonna 9: Azioni */
.btn-grid-action {
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  font-size: var(--text-xs);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.commesse-table tbody tr:hover .btn-grid-action {
  color: var(--text-primary);
  border-color: var(--border-medium);
  background: var(--surface-3);
}


/* --- 5. VISTA 2: TABELLONE KANBAN (5 COLONNE) --- */
.kanban-board-container {
  overflow-x: auto;
  padding-bottom: 1rem;
}

.kanban-board {
  display: grid;
  grid-template-columns: repeat(5, minmax(280px, 1fr));
  gap: 1rem;
  min-width: 1440px;
  align-items: flex-start;
}

.kanban-column {
  background: var(--surface-1);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 220px);
}

.kanban-column-header {
  padding: 0.75rem 0.85rem;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface-2);
  border-top-left-radius: var(--radius-md);
  border-top-right-radius: var(--radius-md);
}

.kanban-col-title-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.kanban-col-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.col-indicator-in-corso { background: #F59E0B; }
.col-indicator-attesa-sue { background: #A855F7; }
.col-indicator-approvata { background: #10B981; }
.col-indicator-completata { background: #3B82F6; }
.col-indicator-archiviata { background: var(--text-dim); }

.kanban-col-title {
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-primary);
}

.kanban-col-badge {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: var(--radius-pill);
  background: var(--surface-3);
  color: var(--text-muted);
  border: 1px solid var(--border-subtle);
}

.kanban-column-cards {
  padding: 0.65rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  overflow-y: auto;
}

/* Card Kanban Singola */
.kanban-card {
  background: var(--surface-2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  cursor: pointer;
  box-shadow: var(--shadow-subtle);
  transition: all var(--transition-fast);
}

.kanban-card:hover {
  background: var(--surface-3);
  border-color: var(--border-strong);
  transform: translateY(-2px);
  box-shadow: var(--shadow-card);
}

.kanban-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.kanban-code {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  color: var(--text-primary);
}

.kanban-type-pill {
  font-size: 10px;
  font-weight: 600;
  padding: 1px 5px;
  border-radius: 3px;
  background: var(--surface-1);
  color: var(--text-muted);
  border: 1px solid var(--border-subtle);
}

.kanban-card-title {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.35;
  margin: 0;
}

.kanban-card-client {
  font-size: var(--text-xs);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 4px;
}

.kanban-card-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-muted);
}

.kanban-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border-subtle);
}

.kanban-footer-left {
  display: flex;
  align-items: center;
  gap: 6px;
}

.kanban-tasks-count {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
}


/* --- 6. STATI DI CARICAMENTO E NESSUN RISULTATO --- */
.commesse-empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  background: var(--surface-1);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

.commesse-empty-icon {
  font-size: 2.25rem;
  opacity: 0.6;
}

.commesse-empty-title {
  font-size: var(--text-md);
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

.commesse-empty-text {
  font-size: var(--text-sm);
  color: var(--text-muted);
  max-width: 400px;
  margin: 0;
}

/* Skeleton Loading */
.skeleton-row {
  height: 48px;
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 4px;
  margin-bottom: 6px;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}


/* --- 7. RESPONSIVE MOBILE --- */
@media (max-width: 768px) {
  .commesse-header {
    flex-direction: column;
    align-items: stretch;
    gap: 1rem;
  }

  .commesse-header-actions {
    justify-content: space-between;
  }

  .filter-bar-top {
    flex-direction: column;
    align-items: stretch;
  }

  .commesse-search-box {
    width: 100%;
  }

  .filter-select {
    width: 100%;
  }
}
