/* === FORM LAYOUT === */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.75rem 1rem;
}

.form-grid.cols-2 {
  grid-template-columns: repeat(2, 1fr);
}

.form-grid-full {
  grid-template-columns: 1fr 1fr;
}

/* Grid a colonne fisse (6-col base per layout precisi) */
.form-row {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.75rem 1rem;
  margin-bottom: 0;
}

/* Span di colonne per larghezze campo */
.field-xs  { grid-column: span 1; }  /* ~16% - Prov, CAP, numeri brevi */
.field-sm  { grid-column: span 1; }  /* ~16% - Telefono, date, codici */
.field-md  { grid-column: span 2; }  /* ~33% - Nome, Cognome, Comune */
.field-lg  { grid-column: span 3; }  /* ~50% - Indirizzo, RagSoc */
.field-xl  { grid-column: span 4; }  /* ~66% - Campi ampi */
.field-full { grid-column: 1 / -1; } /* 100% - Note, textarea */
.col-full  { grid-column: 1 / -1; } /* alias per form-grid cols-2 */

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.form-group.form-full {
  grid-column: 1 / -1;
}

.form-section {
  margin-bottom: 1.25rem;
}

.section-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0 0 0.5rem 0;
  padding-bottom: 0.3rem;
  border-bottom: 1px solid var(--bg-hover);
}

.form-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
  padding-top: 0.75rem;
}

/* === TABELLE DATI === */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.data-table th,
.data-table td {
  padding: 0.4rem 0.6rem;
  text-align: left;
  border-bottom: 1px solid var(--bg-hover);
}

.data-table th {
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.data-table.compact th,
.data-table.compact td {
  padding: 0.25rem 0.4rem;
  font-size: 0.78rem;
}

.form-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.form-static-label {
  display: flex;
  align-items: center;
  height: 36px;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.form-input {
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--input-border);
  border-radius: 6px;
  font-size: 0.9rem;
  background: var(--input-bg);
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  font-family: inherit;
}

.form-input:focus {
  border-color: var(--input-focus);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

.form-input:disabled {
  background: var(--bg-surface-hover);
  color: var(--text-secondary);
  cursor: not-allowed;
}

.form-input[type="number"] {
  text-align: right;
}

textarea.form-input {
  resize: vertical;
  min-height: 60px;
}

select.form-input {
  cursor: pointer;
}

/* Checkbox */
.form-check-group {
  justify-content: center;
}

.form-check-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.88rem;
  cursor: pointer;
  color: var(--text-primary);
}

.form-check-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* Schedule Matrix Table */
.schedule-matrix {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  margin: 0.5rem 0;
}

.schedule-matrix thead th {
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-secondary);
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid var(--input-border);
  letter-spacing: 0.3px;
}

.schedule-matrix tbody tr {
  border-bottom: 1px solid var(--bg-surface-hover);
}

.schedule-matrix tbody tr:last-child {
  border-bottom: none;
}

.schedule-matrix td {
  padding: 0.35rem 0.5rem;
  vertical-align: middle;
}

.schedule-matrix td .form-input {
  padding: 0.35rem 0.5rem;
  font-size: 0.85rem;
  width: 100%;
}

.schedule-matrix td input[type="date"] {
  max-width: 160px;
}

.schedule-matrix td input[type="text"] {
  max-width: 80px;
}

.schedule-matrix .schedule-label {
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  width: 80px;
}

.schedule-matrix .schedule-check {
  width: 40px;
  text-align: center;
}

.schedule-matrix .schedule-check input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* Autocomplete Dropdown */
.prs-dropdown {
  display: none;
  position: absolute;
  z-index: 100;
  background: var(--bg-surface);
  border: 1px solid var(--input-border);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  max-height: 200px;
  overflow-y: auto;
  width: 100%;
}

.form-group {
  position: relative;
}

.prs-dropdown-item {
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  font-size: 0.88rem;
  border-bottom: 1px solid var(--bg-surface-hover);
}

.prs-dropdown-item:last-child {
  border-bottom: none;
}

.prs-dropdown-item:hover {
  background: var(--bg-surface-hover);
}

.prs-dropdown-item small {
  color: var(--text-secondary);
}

/* Time Input */
.time-input {
  max-width: 80px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* Grid a 4 colonne */
.form-grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.75rem 1rem;
}

/* === PAGA QUOTA === */
.pq-importi-grid {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.pq-importi-header {
  display: grid;
  grid-template-columns: 140px 1fr 1fr;
  gap: 0.5rem;
  padding: 0.5rem 0;
  border-bottom: 2px solid var(--border);
}

.pq-importi-header.pq-sub-header {
  border-bottom: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.pq-imp-col-header {
  text-align: center;
  font-weight: 700;
  font-size: 0.85rem;
  text-transform: uppercase;
  color: var(--primary);
}

.pq-imp-sub {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  text-align: center;
  font-weight: 600;
}

.pq-importi-row {
  display: grid;
  grid-template-columns: 140px 1fr 1fr;
  gap: 0.5rem;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--bg-hover);
  align-items: center;
  transition: opacity 0.2s;
}

.pq-importi-row:hover {
  background: var(--bg-hover);
}

.pq-imp-label {
  font-size: 0.8rem;
  padding-left: 0.25rem;
}

.pq-imp-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.pq-imp-pair .pq-segno {
  font-size: 0.78rem;
  padding: 0.3rem 0.4rem;
}

.pq-imp-pair .pq-importo {
  font-size: 0.85rem;
  padding: 0.3rem 0.4rem;
  text-align: right;
}

.pq-riepilogo-empty {
  color: var(--text-secondary);
  text-align: center;
  padding: 1.5rem;
  font-style: italic;
}

.pq-riepilogo-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.pq-riepilogo-table th {
  text-align: center;
  font-weight: 700;
  font-size: 0.72rem;
  text-transform: uppercase;
  color: var(--text-secondary);
  padding: 0.4rem 0.5rem;
  border-bottom: 2px solid var(--border);
}

.pq-riepilogo-table td {
  text-align: center;
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid var(--bg-hover);
}

.pq-riep-label {
  text-align: left !important;
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.pq-riep-diff td {
  font-weight: 600;
  border-bottom: 2px solid var(--border);
}

.pq-riep-separator td {
  height: 0.5rem;
  border: none;
  padding: 0;
}

.pq-riepilogo-table thead th small {
  font-weight: 400;
  font-size: 0.65rem;
  color: var(--text-secondary);
}

/* Responsive */
@media (max-width: 768px) {
  .form-grid-4 {
    grid-template-columns: 1fr;
  }

  .pq-importi-header,
  .pq-importi-row {
    grid-template-columns: 100px 1fr 1fr;
  }

  .pq-imp-pair {
    grid-template-columns: 1fr;
    gap: 0.25rem;
  }
  .form-grid {
    grid-template-columns: 1fr;
  }

  .form-grid-full {
    grid-template-columns: 1fr;
  }

  .form-row {
    grid-template-columns: repeat(2, 1fr);
  }

  .field-xs, .field-sm { grid-column: span 1; }
  .field-md { grid-column: span 1; }
  .field-lg, .field-xl, .field-full { grid-column: 1 / -1; }

  .form-grid-4 {
    grid-template-columns: 1fr 1fr;
  }

  .schedule-matrix td input[type="date"] {
    max-width: 130px;
  }
}

/* === SERVIZI OFFERTI === */
.servizi-offerti-form {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.servizi-offerti-form .collapsible-panel {
  margin-bottom: 1rem;
}

.servizi-offerti-form .color-input {
  height: 38px;
  padding: 2px;
}

/* === MOVIMENTI / PAGAQUOTA === */
.movimenti-form {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.movimenti-form .collapsible-panel {
  margin-bottom: 1rem;
}

/* Riepilogo finanziario */
.pq-riepilogo-grid {
  overflow-x: auto;
}

.pq-riepilogo-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.pq-riepilogo-table th,
.pq-riepilogo-table td {
  padding: 4px 8px;
  text-align: right;
  border: 1px solid var(--border-color);
  white-space: nowrap;
}

.pq-riepilogo-table th {
  background: var(--bg-hover);
  font-weight: 600;
  text-align: center;
  font-size: 0.75rem;
}

.pq-riepilogo-table th small {
  font-weight: 400;
  color: var(--text-secondary);
}

.pq-r-label {
  text-align: left !important;
  font-weight: 600;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.pq-r-bold {
  font-weight: 700;
}

.pq-riepilogo-table tfoot td {
  background: var(--bg-hover);
}

.pq-riepilogo-empty {
  padding: 1rem;
  color: var(--text-secondary);
  font-style: italic;
  text-align: center;
}

/* Griglia importi 2x5 */
.pq-importi-grid {
  overflow-x: auto;
}

.pq-importi-table {
  width: 100%;
  border-collapse: collapse;
}

.pq-importi-table th,
.pq-importi-table td {
  padding: 4px 6px;
  border: 1px solid var(--border-color);
}

.pq-importi-table th {
  background: var(--bg-hover);
  font-weight: 600;
  text-align: center;
  font-size: 0.8rem;
}

.pq-col-asd {
  background: #e8f5e920 !important;
}

.pq-col-odv {
  background: #fff3e020 !important;
}

.pq-imp-label {
  font-weight: 600;
  font-size: 0.82rem;
  white-space: nowrap;
  min-width: 100px;
}

.pq-imp-input {
  width: 110px;
  text-align: right;
}

.pq-imp-segno {
  width: 130px;
  font-size: 0.8rem;
}

.pq-cf-upper input {
  text-transform: uppercase;
}

/* === SERVIZI UTILIZZATI === */
.servizi-utilizzati-form {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.servizi-utilizzati-form .collapsible-panel {
  margin-bottom: 1rem;
}

/* === ISCRIZIONE RAPIDA === */
.iscr-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 1.5rem;
  align-items: start;
}

.iscr-left,
.iscr-right {
  min-width: 0;
}

.iscr-list {
  display: flex;
  flex-direction: column;
}

.iscr-search-results {
  max-height: 250px;
  overflow-y: auto;
  margin-top: 0.5rem;
}

.iscr-list-item {
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--bg-hover);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.iscr-list-item:hover {
  background: var(--bg-hover);
}

.iscr-item-info {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.iscr-list-more {
  padding: 0.4rem 0.6rem;
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-align: center;
}

.iscr-selected {
  padding: 0.6rem;
  background: var(--bg-hover);
  border-radius: 6px;
  color: var(--success, #28a745);
  margin-top: 0.5rem;
}

.iscr-storico {
  max-height: 200px;
  overflow-y: auto;
}

.iscr-storico .data-table {
  font-size: 0.75rem;
}

.iscr-storico .data-table th,
.iscr-storico .data-table td {
  padding: 0.3rem 0.4rem;
}

.iscr-storico-row {
  cursor: pointer;
}

.iscr-storico-row:hover {
  background: var(--bg-hover);
}

@media (max-width: 768px) {
  .iscr-layout {
    grid-template-columns: 1fr;
  }
}

/* === CALENDARIO VISUALE === */
#fullcalendar-container {
  background: var(--bg-card, #fff);
  border-radius: 8px;
  padding: 1rem;
  box-shadow: var(--shadow-sm, 0 1px 3px rgba(0,0,0,0.1));
}

.cal-detail {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.cal-detail-row {
  padding: 0.3rem 0;
  border-bottom: 1px solid var(--bg-hover);
  font-size: 0.85rem;
}

/* === ANAGRAFE SIDE-BY-SIDE (Legami + Storico) === */
.ana-side-by-side {
  display: flex;
  gap: 1rem;
  margin-top: 1rem;
}
.ana-side-by-side > div {
  flex: 1;
  min-width: 0;
}
@media (max-width: 768px) {
  .ana-side-by-side {
    flex-direction: column;
  }
}

/* === SERVIZI OFFERTI: Periodo + Totali affiancati === */
.sof-panels-side {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
}
.sof-panels-side > .card {
  min-width: 0;
}
.sof-panels-side > .card:first-child {
  flex: 55;
}
.sof-panels-side > .card:last-child {
  flex: 45;
}
/* Griglia 3 colonne dentro Totali affiancato */
.sof-totali-compact .form-row {
  grid-template-columns: repeat(3, 1fr);
}
.sof-totali-compact .form-group {
  grid-column: span 1;
}
.sof-totali-compact .form-input {
  max-width: 120px;
  text-align: right;
}
.sof-totali-compact .form-static-label {
  font-weight: 600;
  font-size: 0.82rem;
}
@media (max-width: 1100px) {
  .sof-panels-side {
    flex-direction: column;
  }
  .sof-totali-compact .form-row {
    grid-template-columns: repeat(6, 1fr);
  }
  .sof-totali-compact .form-group {
    grid-column: span 2;
  }
  .sof-totali-compact .form-input {
    max-width: none;
  }
}

/* === SERVIZI UTILIZZATI: sub-header e date row === */
.sut-sub-header {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin: 0 0 0.5rem 0;
  padding-bottom: 0.25rem;
  border-bottom: 1px solid var(--border-color);
}
.sut-dates-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}
.sut-dates-row .form-group {
  flex: 1;
}

/* === UTENTI: Layout 2 colonne Dati + Password === */
.ute-two-columns {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
}
.ute-col-left {
  flex: 1;
  min-width: 0;
}
.ute-col-right {
  flex: 1;
  min-width: 0;
}
@media (max-width: 900px) {
  .ute-two-columns {
    flex-direction: column;
  }
}

/* Grid a 3 colonne */
.form-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem 1rem;
}

/* === AUTOMEZZI: Layout 2 colonne Dati + Manutenzione === */
.auto-two-columns {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
}
.auto-two-columns > .card {
  flex: 1;
  min-width: 0;
}
@media (max-width: 900px) {
  .auto-two-columns {
    flex-direction: column;
  }
  .form-grid-3 {
    grid-template-columns: 1fr;
  }
}
