:root {
  --blue: #1f6fb2;
  --orange: #e08a1e;
  --grey: #555;
  --border: #d7dbe0;
  --bg: #f4f6f8;
  --danger: #c0392b;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Segoe UI', Arial, sans-serif;
  background: var(--bg);
  color: #222;
}

.topbar {
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.topbar .brand {
  font-weight: 700;
  font-size: 20px;
  display: flex;
  align-items: center;
}
.topbar .brand .igonet { color: var(--blue); }
.topbar .brand .it { color: var(--orange); font-weight: 400; font-size: 14px; margin-left: 6px; }
.brand-logo { height: 34px; width: auto; display: block; }

.topbar .user-area { display: flex; align-items: center; gap: 12px; font-size: 14px; color: var(--grey); }

.container { max-width: 1100px; margin: 24px auto; padding: 0 16px; }

/* ---------- Login ---------- */
.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 36px 40px;
  width: 340px;
  box-shadow: 0 4px 18px rgba(0,0,0,0.06);
  text-align: center;
}
.login-card h1 { font-size: 22px; margin-bottom: 4px; }
.login-card h1 .igonet { color: var(--blue); }
.login-card h1 .it { color: var(--orange); }
.login-logo { width: 100%; max-width: 220px; height: auto; margin-bottom: 16px; }
.login-card p.subtitle { color: var(--grey); font-size: 13px; margin-top: 0; margin-bottom: 24px; }
.login-card label { display:block; text-align:left; font-size: 13px; margin-bottom: 4px; color: var(--grey); }
.login-card input { width: 100%; padding: 9px 10px; margin-bottom: 16px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px; }
.login-card button { width: 100%; }
.error-msg { color: var(--danger); font-size: 13px; margin-bottom: 12px; min-height: 16px; }

/* ---------- Buttons ---------- */
button, .btn {
  cursor: pointer;
  border: none;
  border-radius: 6px;
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 600;
  background: var(--blue);
  color: #fff;
  transition: background .15s;
}
button:hover, .btn:hover { background: #185b93; }
button.secondary, .btn.secondary { background: #eef1f4; color: #333; }
button.secondary:hover { background: #e2e6ea; }
button.orange { background: var(--orange); }
button.orange:hover { background: #c67816; }
button.danger { background: var(--danger); }
button:disabled { opacity: 0.6; cursor: not-allowed; }

/* ---------- Dashboard ---------- */
.dash-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
  flex-wrap: wrap;
  gap: 10px;
}
.dash-header h2 { margin: 0; }

.filters {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  background: #fff;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.filters input { padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; }
.filters .field { display: flex; flex-direction: column; gap: 4px; }
.filters .field label { font-size: 11px; color: var(--grey); }

table.reports-table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
table.reports-table th, table.reports-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
  text-align: left;
}
table.reports-table th { background: #f0f3f6; color: var(--grey); font-weight: 600; }
table.reports-table tr:hover td { background: #fafcfe; }
table.reports-table .actions { display: flex; gap: 6px; }
table.reports-table .actions button { padding: 6px 10px; font-size: 12px; }

.empty-state { text-align: center; color: var(--grey); padding: 40px 0; }

.truncate-name {
  display: inline-block;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: middle;
  cursor: pointer;
}
.truncate-name.expanded {
  max-width: none;
  white-space: normal;
  word-break: break-word;
}

.stato-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 12px;
  border: 1px solid;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.stato-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: -6px 0 20px;
}
.stato-bar label { font-size: 12px; color: var(--grey); font-weight: 600; }
.stato-bar select {
  padding: 6px 10px;
  border-radius: 6px;
  border: 1.5px solid var(--border);
  font-size: 13px;
  font-weight: 600;
  background: #fff;
}

.fab-new {
  position: fixed;
  bottom: 30px;
  right: 30px;
  padding: 14px 22px;
  border-radius: 30px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.2);
  font-size: 15px;
}

/* ---------- Report form ---------- */
.report-sheet {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 28px 32px;
}
.report-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  border-bottom: 3px solid var(--orange);
  padding-bottom: 12px;
  margin-bottom: 18px;
}
.report-header .logo { font-size: 24px; font-weight: 700; }
.report-header .logo img { width: 170px; height: auto; display: block; }
.report-header .coords { font-size: 11px; color: var(--grey); text-align: right; line-height: 1.5; }
.report-title { text-align: center; font-size: 20px; margin: 6px 0 24px; }

.grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 20px; margin-bottom: 18px; }
.field-row { margin-bottom: 12px; }
.field-row label { display: block; font-size: 12px; color: var(--grey); margin-bottom: 4px; font-weight: 600; }
.field-row input, .field-row textarea, .field-row select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13.5px;
  font-family: inherit;
}
.field-row textarea { resize: vertical; }

.cliente-autocomplete-wrap { position: relative; }
.cliente-suggestions {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 50;
  background: #fff;
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 6px 6px;
  max-height: 220px;
  overflow-y: auto;
  box-shadow: 0 6px 14px rgba(0,0,0,0.12);
}
.cliente-suggestions.hidden { display: none; }
.cliente-suggestions .suggestion-item {
  padding: 8px 10px;
  font-size: 13.5px;
  cursor: pointer;
}
.cliente-suggestions .suggestion-item:hover,
.cliente-suggestions .suggestion-item.active {
  background: var(--bg-alt, #f2f4f7);
}

.box {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 18px;
}
.box h3 { margin: 0 0 10px; font-size: 14px; color: var(--blue); }

.inline-fields { display: flex; gap: 12px; }
.inline-fields .field-row { flex: 1; }

.checkbox-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 16px; margin-bottom: 10px; }
.checkbox-grid label { display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 400; color: #222; }
.checkbox-grid input { width: auto; }

.radio-row { display: flex; gap: 20px; align-items: center; }
.radio-row label { display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 400; }
.radio-row input { width: auto; }

.materiali-table { width: 100%; border-collapse: collapse; margin-bottom: 10px; table-layout: fixed; }
.materiali-table th { font-size: 11px; color: var(--grey); text-align: left; padding: 4px 6px; }
.materiali-table td { padding: 4px 6px; }
.materiali-table input { padding: 6px 8px; font-size: 13px; width: 100%; box-sizing: border-box; }
/* Larghezze colonne tabella Materiali: modifica i valori px qui sotto
   per cambiare le proporzioni. Con table-layout:fixed i valori vengono
   scalati proporzionalmente per riempire il 100% della tabella, quindi
   contano gli uni rispetto agli altri, non il valore assoluto. */
.materiali-table th.col-tipo, .materiali-table td.col-tipo { width: 8%; }   /* Tipo */
.materiali-table th.col-qta, .materiali-table td.col-qta { width: 8%; }    /* Qta */
.materiali-table td.col-tipo select { padding: 4px 2px; }
.materiali-table td.col-qta input { padding: 4px 2px; text-align: start; }
.materiali-table th.col-remove, .materiali-table td.col-remove { width: 34px; overflow: hidden; } /* Rimuovi */
.materiali-table td.col-remove button { width: 100%; padding: 6px 0; font-size: 13px; box-sizing: border-box; white-space: nowrap; overflow: hidden; }
.materiali-table td.col-remove .btn-label { display: none; }
.materiali-table th:nth-child(3), .materiali-table td:nth-child(3) { width: 300px; } /* Descrizione */
.materiali-table th:nth-child(4), .materiali-table td:nth-child(4) { width: 110px; } /* Matricola / Seriale */
.materiali-table th:nth-child(5), .materiali-table td:nth-child(5) { width: 100px; } /* Codice DANEA */

.totals-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; }
.totals-grid .box { margin-bottom: 0; }

.form-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 24px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 10px;
}
.form-actions .left-actions, .form-actions .right-actions { display: flex; gap: 10px; }

.save-status { font-size: 13px; color: var(--grey); }
.save-status.ok { color: #1e8a3e; }
.save-status.error { color: var(--danger); }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center; z-index: 50;
  padding: 16px;
  overflow-y: auto;
}
.modal {
  background: #fff; border-radius: 10px; padding: 24px; width: 360px;
  max-width: 100%;
}
.modal h3 { margin-top: 0; }
.modal .modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.hidden { display: none !important; }

/* ---------- Firma cliente ---------- */
.signature-field {
  position: relative;
  border: 1px dashed var(--border);
  border-radius: 6px;
  background: #fafbfc;
  height: 90px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.signature-field:hover { border-color: var(--blue); }
.signature-field canvas { width: 100%; height: 100%; display: block; }
.signature-placeholder {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: #9aa2ab; font-size: 13px; pointer-events: none;
}
.signature-field.has-signature .signature-placeholder { display: none; }
.signature-clear {
  position: absolute; top: 4px; right: 4px;
  width: 22px; height: 22px; padding: 0;
  border-radius: 50%; font-size: 12px; line-height: 1;
  background: #fff; color: var(--danger); border: 1px solid var(--border);
  display: none; align-items: center; justify-content: center;
}
.signature-field.has-signature .signature-clear { display: flex; }
.signature-clear:hover { background: #fdecea; }

.signature-modal {
  background: #fff; border-radius: 10px;
  width: 100%; max-width: 640px;
  padding: 18px 20px;
  display: flex; flex-direction: column;
}
.signature-modal-header h3 { margin: 0 0 4px; }
.signature-modal-header p { margin: 0 0 12px; font-size: 13px; color: var(--grey); }
.signature-canvas-wrap {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  touch-action: none;
  height: 300px;
}
.signature-canvas-wrap canvas {
  width: 100%; height: 100%; display: block;
  cursor: crosshair;
}

/* =========================================================
   RESPONSIVE — tablet e smartphone
   ========================================================= */

/* Tablet e schermi medi */
@media (max-width: 900px) {
  .container { margin: 16px auto; padding: 0 12px; }

  .grid-2 { grid-template-columns: 1fr; gap: 14px; }
  .totals-grid { grid-template-columns: 1fr; gap: 14px; }

  .report-sheet { padding: 20px 18px; }

  .report-header { flex-direction: column; gap: 10px; }
  .report-header .coords { text-align: left; }

    /* Tabella materiali: su mobile diventa un elenco di card impilate,
     una per riga materiale, con etichetta visibile sopra ogni campo
     invece di colonne strette illeggibili. */
  .materiali-table { display: block; width: 100%; border: none; }
  .materiali-table thead { display: none; }
  .materiali-table tbody { display: block; width: 100%; }
  .materiali-table tr {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    width: 100%;
    margin-bottom: 12px;
    padding: 10px;
    background: #f7f9fb;
    border: 1px solid var(--border);
    border-radius: 8px;
    box-sizing: border-box;
  }
  .materiali-table td {
    display: block;
    width: 100%;
    padding: 0;
    box-sizing: border-box;
  }
  .materiali-table td.col-tipo { width: calc(35% - 4px); }
  .materiali-table td.col-qta { width: calc(65% - 4px); }
  .materiali-table td[data-label]::before {
    content: attr(data-label);
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: var(--grey);
    margin-bottom: 4px;
  }
  .materiali-table td input,
  .materiali-table td select { width: 100%; box-sizing: border-box; }
  .materiali-table td.col-remove { width: 100%; margin-top: 2px; }
  .materiali-table td.col-remove button { width: 100%; padding: 8px; overflow: visible; white-space: normal; }
  .materiali-table td.col-remove .btn-label { display: inline; }

  .form-actions { flex-direction: column; align-items: stretch; }
  .form-actions .left-actions, .form-actions .right-actions {
    width: 100%; justify-content: center; flex-wrap: wrap;
  }
  .form-actions button { flex: 1; min-width: 120px; }

  .modal { width: 100%; }

  #signatureModal { padding: 0; }
  .signature-modal {
    max-width: 100%;
    height: 100%;
    border-radius: 0;
    justify-content: center;
  }
  .signature-canvas-wrap { height: 55vh; }


  .materiali-table th:nth-child(3), .materiali-table td:nth-child(3) { width: 100%; } /* Descrizione */
.materiali-table th:nth-child(4), .materiali-table td:nth-child(4) { width: 100%; } /* Matricola / Seriale */
.materiali-table th:nth-child(5), .materiali-table td:nth-child(5) { width: 100%; } /* Codice DANEA */

}

/* Smartphone */
@media (max-width: 600px) {
  .topbar { padding: 10px 14px; flex-wrap: wrap; gap: 8px; }
  .topbar .user-area { font-size: 13px; gap: 8px; }
  .brand-logo { height: 28px; }

  .login-card { width: 100%; padding: 28px 22px; }

  .dash-header { flex-direction: column; align-items: flex-start; }

  .filters { flex-direction: column; padding: 12px; }
  .filters .field { width: 100%; }
  .filters .field input { width: 100% !important; }

  /* Margine extra in fondo così i pulsanti fissi (Nuovo rapporto /
     Importa scansione) non coprono le ultime righe della tabella
     mentre si scorre la pagina. */
  .container { padding-bottom: 140px; }

  /* Tabella rapporti: scroll orizzontale/verticale senza rompere il layout */
  #tableWrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-height: 65vh;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 8px;
  }
  table.reports-table { min-width: 520px; border: none; border-radius: 0; }
  table.reports-table thead th {
    position: sticky;
    top: 0;
    z-index: 1;
  }

  /* Nome cliente più stretto su schermi piccoli, per lasciare spazio
     alle altre colonne senza dover scorrere troppo in orizzontale */
  .truncate-name { max-width: 110px; }

  .fab-new {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: 16px;
    width: auto;
    text-align: center;
    font-size: 14px;
    padding: 12px 16px;
  }
  /* Quando ci sono due pulsanti fissi (Nuovo Rapporto + Importa scansione),
     li impiliamo uno sopra l'altro invece di affiancarli. */
  #importScanBtn.fab-new {
    right: 12px !important;
    bottom: 70px;
  }

  .report-sheet { padding: 16px 12px; }
  .report-title { font-size: 17px; }

  .box { padding: 10px; }
  .inline-fields { flex-direction: column; gap: 0; }

  .checkbox-grid { grid-template-columns: 1fr; }

  /* Tabella materiali: su mobile diventa un elenco di card impilate,
     una per riga materiale, con etichetta visibile sopra ogni campo
     invece di colonne strette illeggibili. */
  .materiali-table { display: block; width: 100%; border: none; }
  .materiali-table thead { display: none; }
  .materiali-table tbody { display: block; width: 100%; }
  .materiali-table tr {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    width: 100%;
    margin-bottom: 12px;
    padding: 10px;
    background: #f7f9fb;
    border: 1px solid var(--border);
    border-radius: 8px;
    box-sizing: border-box;
  }
  .materiali-table td {
    display: block;
    width: 100%;
    padding: 0;
    box-sizing: border-box;
  }
  .materiali-table td.col-tipo { width: calc(35% - 4px); }
  .materiali-table td.col-qta { width: calc(65% - 4px); }
  .materiali-table td[data-label]::before {
    content: attr(data-label);
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: var(--grey);
    margin-bottom: 4px;
  }
  .materiali-table td input,
  .materiali-table td select { width: 100%; box-sizing: border-box; }
  .materiali-table td.col-remove { width: 100%; margin-top: 2px; }
  .materiali-table td.col-remove button { width: 100%; padding: 8px; overflow: visible; white-space: normal; }
  .materiali-table td.col-remove .btn-label { display: inline; }

  .form-actions { flex-direction: column; align-items: stretch; }
  .form-actions .left-actions, .form-actions .right-actions {
    width: 100%; justify-content: center; flex-wrap: wrap;
  }
  .form-actions button { flex: 1; min-width: 120px; }

  .modal { width: 100%; }

  #signatureModal { padding: 0; }
  .signature-modal {
    max-width: 100%;
    height: 100%;
    border-radius: 0;
    justify-content: center;
  }
  .signature-canvas-wrap { height: 55vh; }

.materiali-table th:nth-child(3), .materiali-table td:nth-child(3) { width: 100%; } /* Descrizione */
.materiali-table th:nth-child(4), .materiali-table td:nth-child(4) { width: 100%; } /* Matricola / Seriale */
.materiali-table th:nth-child(5), .materiali-table td:nth-child(5) { width: 100%; } /* Codice DANEA */

}
