/* ═══════════════════════════════════════════════════════
   FOGLIO LAVORAZIONE
   ═══════════════════════════════════════════════════════ */

.foglio-page {
  padding: 16px 20px;
  font-family: 'DM Sans', sans-serif;
  color: #1c1c1e;
}

.foglio-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  padding: 10px 14px;
  background: #fff;
  border: 1px solid #e7e3da;
  border-radius: 8px;
}

.foglio-toolbar-left, .foglio-toolbar-right {
  display: flex;
  gap: 8px;
  align-items: center;
}

.foglio-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 13px;
}

.foglio-label input[type="date"] {
  padding: 6px 10px;
  border: 1px solid #d4cfc4;
  border-radius: 6px;
  font-size: 14px;
}

/* ── Summary cards ───────────────────────────────── */

.foglio-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.foglio-card {
  background: #fff;
  border: 1px solid #e7e3da;
  border-radius: 8px;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
}

.foglio-card-label {
  font-size: 11px;
  text-transform: uppercase;
  color: #6b7280;
  letter-spacing: 0.04em;
  font-weight: 600;
}

.foglio-card-value {
  font-family: 'Syne', sans-serif;
  font-size: 22px;
  font-weight: 700;
  color: #1c1c1e;
  margin: 2px 0;
}

.foglio-card-sub {
  font-size: 11px;
  color: #6b7280;
}

.foglio-card-pos { border-left: 4px solid #16a34a; }
.foglio-card-neg { border-left: 4px solid #dc2626; }
.foglio-card-zero { border-left: 4px solid #9ca3af; }

/* ── Tabella ─────────────────────────────────────── */

.foglio-table-wrap {
  background: #fff;
  border: 1px solid #e7e3da;
  border-radius: 8px;
  overflow: auto;
  max-height: calc(100vh - 280px);
}

.foglio-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
  min-width: 1500px;
}

.foglio-table thead th {
  position: sticky;
  top: 0;
  background: #1b4332;
  color: #fff;
  text-align: left;
  padding: 8px 6px;
  font-weight: 700;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-bottom: 2px solid #2d6a4f;
  z-index: 1;
  white-space: nowrap;
}

.foglio-table tbody td {
  padding: 4px 6px;
  border-bottom: 1px solid #f0ece4;
  vertical-align: middle;
}

.foglio-table tbody tr:hover {
  background: #f9f7f1;
}

.foglio-pratica {
  font-weight: 700;
  color: #1b4332;
  white-space: nowrap;
  font-family: 'Syne', sans-serif;
}

.foglio-table input[type="text"],
.foglio-table input[type="number"],
.foglio-table select {
  width: 100%;
  padding: 4px 6px;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 4px;
  font-size: 12.5px;
  font-family: inherit;
  box-sizing: border-box;
}

.foglio-table input:focus,
.foglio-table select:focus {
  border-color: #2d6a4f;
  background: #fff;
  outline: none;
}

.foglio-table input[type="number"] {
  text-align: right;
  -moz-appearance: textfield;
}

.foglio-table input[type="number"]::-webkit-outer-spin-button,
.foglio-table input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.foglio-kpi {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: #374151;
  white-space: nowrap;
}

.foglio-profitto-pos { color: #16a34a; background: rgba(22,163,74,.06); }
.foglio-profitto-neg { color: #dc2626; background: rgba(220,38,38,.08); }
.foglio-profitto-zero { color: #6b7280; }

.foglio-kpi small.muted { color: #9ca3af; font-weight: 400; margin-left: 4px; }

.foglio-kpi-note {
  display: inline-block;
  margin-left: 4px;
  color: #d4a017;
  cursor: help;
}

.foglio-empty {
  text-align: center;
  padding: 40px;
  color: #6b7280;
  font-style: italic;
}

.foglio-row-completato { background: rgba(22,163,74,.04); }
.foglio-row-annullato  { opacity: 0.55; }
.foglio-row-in_corso   { background: rgba(234,88,12,.04); }

.foglio-flash-ok { animation: foglio-flash-ok 0.8s ease; }
.foglio-flash-err { animation: foglio-flash-err 0.8s ease; }

@keyframes foglio-flash-ok {
  0%, 100% { background-color: transparent; }
  50% { background-color: rgba(22,163,74,.18); }
}
@keyframes foglio-flash-err {
  0%, 100% { background-color: transparent; }
  50% { background-color: rgba(220,38,38,.18); }
}

.foglio-del {
  background: transparent;
  border: 1px solid transparent;
  color: #dc2626;
  cursor: pointer;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 14px;
}

.foglio-del:hover {
  background: rgba(220,38,38,.08);
  border-color: #dc2626;
}

/* ── Modale aggiunta riga ────────────────────────── */

.foglio-modal {
  position: fixed;
  inset: 0;
  background: rgba(28, 28, 30, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.foglio-modal-content {
  background: #fff;
  border-radius: 12px;
  padding: 24px;
  width: 480px;
  max-width: 90vw;
  box-shadow: 0 12px 40px rgba(0,0,0,0.25);
}

.foglio-modal-content h3 {
  font-family: 'Syne', sans-serif;
  margin: 0 0 8px 0;
  color: #1b4332;
}

.foglio-modal-hint {
  font-size: 13px;
  color: #6b7280;
  margin: 0 0 16px 0;
}

.foglio-modal-content code {
  background: #f0ece4;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 12px;
}

.foglio-modal-content label {
  display: block;
  margin-bottom: 14px;
  font-weight: 600;
  font-size: 13px;
  color: #374151;
}

.foglio-modal-content label input {
  display: block;
  width: 100%;
  padding: 8px 12px;
  margin-top: 4px;
  border: 1px solid #d4cfc4;
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  box-sizing: border-box;
}

.foglio-suggest {
  position: relative;
  margin-top: 4px;
  background: #fff;
  border: 1px solid #d4cfc4;
  border-radius: 6px;
  max-height: 220px;
  overflow-y: auto;
  z-index: 10;
}

.foglio-suggest-item {
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: 8px;
  padding: 6px 10px;
  cursor: pointer;
  border-bottom: 1px solid #f0ece4;
  font-size: 12.5px;
  align-items: center;
}

.foglio-suggest-item:hover {
  background: #f9f7f1;
}

.foglio-suggest-item small {
  grid-column: 2;
  color: #9ca3af;
  font-size: 11px;
}

.foglio-anagrafica {
  background: #f9f7f1;
  padding: 10px 12px;
  border-radius: 6px;
  margin-bottom: 14px;
  font-size: 12.5px;
  color: #374151;
  border-left: 3px solid #2d6a4f;
}

.foglio-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
}

/* ── Cella numero motore + bottone MI stats ──────── */
.foglio-cell-motore { position: relative; }
.foglio-cell-motore input { padding-right: 28px; }
.foglio-mi-btn {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  font-size: 1rem;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  opacity: 0.55;
  transition: opacity 0.15s, background 0.15s;
}
.foglio-mi-btn:hover {
  opacity: 1;
  background: #e0f2fe;
}

/* ── Print ───────────────────────────────────────── */

@media print {
  .foglio-toolbar, .foglio-modal,
  .foglio-del, th:last-child, td:last-child {
    display: none !important;
  }
  .foglio-table-wrap { max-height: none; overflow: visible; border: none; }
  .foglio-table { font-size: 10.5px; min-width: 0; }
  .foglio-table thead th { background: #fff !important; color: #000 !important; border: 1px solid #000; }
  .foglio-table tbody td { border: 1px solid #ccc; }
  .foglio-page { padding: 0; }
}
