/* =========================================================================
   Cantieri-Web - Foglio stile
   Ottimizzato per l'utilizzo da smartphone/tablet lato capo cantiere.
   ========================================================================= */

:root {
  --cw-primary: #0d6efd;
  --cw-bottom-nav-h: 64px;
  --cw-safe-bottom: env(safe-area-inset-bottom, 0px);
}

body {
  background:#f5f7fa;
  font-family: "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;   /* evita ingrandimenti automatici iOS */
  -webkit-tap-highlight-color: transparent;
}

/* ---------- KPI card (dashboard) ---------- */
.kpi-card { border-left: 4px solid var(--cw-primary); }
.kpi-card .value { font-size: 1.6rem; font-weight: 700; }
.kpi-card .label { color:#6c757d; font-size:.85rem; text-transform:uppercase; letter-spacing:.5px; }

.progress { height: 22px; }
.progress-bar { font-weight:600; }

.voce-row td { vertical-align: middle; }
.voce-row input[type=number] { max-width: 140px; }

/* ---------- Sticky save button ---------- */
.sticky-save {
  position: sticky;
  bottom: calc(var(--cw-safe-bottom) + 0px);
  background: #fff;
  padding: 12px;
  border-top: 1px solid #dee2e6;
  z-index: 1000;
  box-shadow: 0 -2px 8px rgba(0,0,0,0.08);
}

.badge-stato { font-size:.8rem; padding:.4em .6em; }

/* =========================================================================
   AREA CAPO CANTIERE: bottom navigation + touch-friendly controls
   ========================================================================= */

/* Bottom navigation fissa: compare solo lato capo cantiere */
.capo-bottom-nav {
  display: none;
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: calc(var(--cw-bottom-nav-h) + var(--cw-safe-bottom));
  padding-bottom: var(--cw-safe-bottom);
  background: #fff;
  border-top: 1px solid #dee2e6;
  box-shadow: 0 -2px 6px rgba(0,0,0,0.05);
  z-index: 1040;
}
.capo-bottom-nav .nav-item-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  color: #6c757d;
  font-size: .72rem;
  gap: 2px;
  padding: 6px 2px;
  position: relative;
}
.capo-bottom-nav .nav-item-btn i {
  font-size: 1.35rem;
  line-height: 1;
}
.capo-bottom-nav .nav-item-btn.active,
.capo-bottom-nav .nav-item-btn:active {
  color: var(--cw-primary);
  font-weight: 600;
}
.capo-bottom-nav .nav-item-btn .pill-dot {
  position: absolute;
  top: 4px;
  right: calc(50% - 18px);
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 16px;
  background: #dc3545;
  color: #fff;
  font-size: .65rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

/* Attiva la bottom nav e reserva spazio in basso solo lato capo cantiere */
body.capo-mode .capo-bottom-nav { display: flex; }
body.capo-mode main {
  padding-bottom: calc(var(--cw-bottom-nav-h) + var(--cw-safe-bottom) + 16px) !important;
}

/* FAB: bottone d'azione principale (es. nuovo rapportino) */
.fab-primary {
  position: fixed;
  right: 16px;
  bottom: calc(var(--cw-bottom-nav-h) + var(--cw-safe-bottom) + 12px);
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--cw-primary);
  color: #fff !important;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  box-shadow: 0 4px 12px rgba(13,110,253,.35);
  z-index: 1050;
  border: 0;
  text-decoration: none;
  transition: transform .15s ease;
}
.fab-primary:hover { transform: scale(1.05); color: #fff; }
.fab-primary:active { transform: scale(.95); }

/* Card "tile" per lista rapportini su mobile */
.rap-card {
  display: block;
  color: inherit;
  text-decoration: none;
  border-radius: .6rem;
  border: 1px solid #e2e6ea;
  background: #fff;
  padding: .75rem .85rem;
  margin-bottom: .6rem;
  box-shadow: 0 1px 2px rgba(0,0,0,0.03);
  transition: box-shadow .15s;
}
.rap-card:hover { box-shadow: 0 3px 8px rgba(0,0,0,0.08); color: inherit; text-decoration:none; }
.rap-card .rap-date {
  font-weight: 700;
  font-size: 1.05rem;
}
.rap-card .rap-meta {
  color:#6c757d;
  font-size:.82rem;
}

/* Quick-action buttons grid per dashboard capo */
.quick-actions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: .65rem;
}
.quick-actions .qa-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .25rem;
  padding: 1rem .5rem;
  border-radius: .75rem;
  background: #fff;
  border: 1px solid #e2e6ea;
  color: #212529;
  text-decoration: none;
  min-height: 88px;
  transition: all .15s;
  position: relative;
  box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}
.quick-actions .qa-btn:hover {
  box-shadow: 0 3px 8px rgba(0,0,0,0.08);
  text-decoration: none;
  color:#212529;
}
.quick-actions .qa-btn i { font-size: 1.75rem; color: var(--cw-primary); }
.quick-actions .qa-btn .qa-label { font-size: .85rem; font-weight: 600; text-align: center; line-height: 1.1; }
.quick-actions .qa-btn .qa-badge {
  position: absolute;
  top: 6px; right: 6px;
  background: #dc3545;
  color: #fff;
  border-radius: 999px;
  padding: 0 7px;
  font-size: .7rem;
  min-width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}
.quick-actions .qa-btn.qa-primary {
  background: var(--cw-primary);
  color: #fff;
  border-color: var(--cw-primary);
}
.quick-actions .qa-btn.qa-primary i { color: #fff; }

/* Card lavorazione nel form rapportino (mobile-first) */
.voce-card {
  background: #fff;
  border: 1px solid #e2e6ea;
  border-radius: .55rem;
  padding: .7rem .85rem;
  margin-bottom: .6rem;
  transition: background .15s;
}
.voce-card.active {
  background: #e7f1ff;
  border-color: #7fb0ff;
}
.voce-card .voce-codice {
  font-family: monospace;
  font-size: .8rem;
  color:#6c757d;
}
.voce-card .voce-desc {
  font-weight: 600;
  font-size: .95rem;
  margin: .15rem 0 .35rem;
}
.voce-card .voce-meta {
  color:#6c757d;
  font-size: .78rem;
}

/* Stepper input +/- */
.num-stepper {
  display: flex;
  align-items: stretch;
}
.num-stepper .btn {
  width: 42px;
  padding: 0;
  font-size: 1.2rem;
  line-height: 1;
  flex: 0 0 42px;
}
.num-stepper input {
  text-align: center;
  font-weight: 600;
  font-size: 1.05rem;
  border-left: 0;
  border-right: 0;
}

/* Foto upload zone: grande e tappabile */
.foto-upload-zone {
  display: block;
  border: 2px dashed #adb5bd;
  border-radius: .6rem;
  padding: 1.25rem .75rem;
  background: #fafbfc;
  text-align: center;
  color: #495057;
  cursor: pointer;
  transition: all .15s;
}
.foto-upload-zone:hover { border-color: var(--cw-primary); color: var(--cw-primary); background:#eef5ff; }
.foto-upload-zone i { font-size: 2.2rem; display: block; margin-bottom: .35rem; }
.foto-upload-zone input[type=file] { display: none; }

.foto-preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: .4rem;
  margin-top: .6rem;
}
.foto-preview-grid img {
  width: 100%;
  aspect-ratio: 1/1;
  object-fit: cover;
  border-radius: .4rem;
}

/* Foto thumbnail (detail rapportino) */
.foto-thumb {
  width: 100%;
  height: 140px;
  object-fit: cover;
  border-radius: .375rem;
  cursor: pointer;
}

/* Sezione "riga manodopera/mezzo" nel form */
.row-manodopera, .row-mezzo {
  border: 1px solid #dee2e6;
  border-radius: .5rem;
  padding: .75rem;
  margin-bottom: .55rem;
  background: #fff;
}

/* =========================================================================
   Responsive: mobile first tweaks
   ========================================================================= */
@media (max-width: 767.98px) {
  /* Tap targets piu' grandi */
  .form-control,
  .form-select {
    min-height: 44px;
    font-size: 1rem;
  }
  .btn {
    min-height: 40px;
  }
  .btn-lg {
    min-height: 52px;
    font-size: 1.05rem;
  }
  .form-control-lg, .form-select-lg {
    min-height: 52px;
    font-size: 1.1rem;
  }

  /* Container meno "vuoto" sui bordi */
  main.container-fluid {
    padding-left: .75rem;
    padding-right: .75rem;
  }

  /* Titoli leggermente piu' compatti */
  h1, .h1 { font-size: 1.35rem; }
  h2, .h2 { font-size: 1.15rem; }
  h4, .h4 { font-size: 1.1rem; }

  /* Card un po' meno "ombreggiate" */
  .card { border-radius: .55rem; }

  /* KPI piu' grandi e impattanti */
  .kpi-card .value { font-size: 1.35rem; }
  .kpi-card .label { font-size: .72rem; }

  /* Rende piu' evidente il bordo sinistro colorato */
  .kpi-card { border-left-width: 5px; }

  /* Tabelle: font leggermente ridotto, padding compatto */
  .table-sm td, .table-sm th { padding: .45rem .35rem; font-size: .85rem; }

  /* Nascondi nav top per capo cantiere: usiamo bottom-nav */
  body.capo-mode .navbar.navbar-expand-lg { display: none; }
  body.capo-mode main { padding-top: 6px !important; }

  /* Header ricorrenti: flex verticale */
  .page-header-stack { flex-direction: column; align-items: stretch !important; gap: .5rem; }

  /* Banner "avanzamento fase": Gantt a volte inutile su mobile, tabella scrolla */
  .gantt-capo { min-width: 640px; }
}

/* Su tablet piccoli: margini piu' generosi ma ancora touch-friendly */
@media (min-width: 768px) and (max-width: 991.98px) {
  .fab-primary { width: 62px; height: 62px; }
}

/* Scrollbar piu' discreta (desktop) */
@media (min-width: 992px) {
  .capo-bottom-nav { box-shadow: 0 -1px 3px rgba(0,0,0,0.03); }
}

/* Stampe: nascondi UI di navigazione */
@media print {
  .capo-bottom-nav, .fab-primary, .sticky-save { display: none !important; }
  .page-code-badge { display: none !important; }
}

/* Codice pagina (riferimento per segnalazioni / supporto)
   Piccolo badge discreto in alto a destra del main, visibile su tutte le
   pagine e per tutti i ruoli (admin/DT/capocantiere/anon).
   L'utente puo' copiarlo/citarlo quando segnala un bug o richiede una
   modifica, in modo da sapere esattamente a che pagina si riferisce. */
.page-code-badge {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 4px;
  margin-bottom: 6px;
  font-size: 0.72rem;
  line-height: 1;
  color: #868e96;
  user-select: text;  /* selezionabile per il copy/paste */
}
.page-code-badge .page-code-label {
  opacity: 0.75;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.page-code-badge .page-code-value {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: #f1f3f5;
  color: #495057;
  padding: 2px 7px;
  border-radius: 4px;
  border: 1px solid #e9ecef;
  font-size: 0.72rem;
  cursor: text;
}
.page-code-badge .page-code-value:hover {
  background: #e7f5ff;
  border-color: #a5d8ff;
  color: #1864ab;
}

/* ======================================================================
   PERSONALE IN CANTIERE - griglia di card selezionabili
   Usata in rapportino_form.html: il capo cantiere spunta le persone
   presenti oggi ed imposta le ore. Ogni card contiene checkbox, info
   (nome + mansione) ed input numerico per le ore.
   ====================================================================== */
.persone-grid {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr;
}
@media (min-width: 576px) {
  .persone-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 992px) {
  .persone-grid { grid-template-columns: repeat(3, 1fr); }
}
.persona-card {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1.5px solid #dee2e6;
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
  user-select: none;
  margin-bottom: 0;
  transition: all .15s ease;
}
.persona-card:hover {
  border-color: #adb5bd;
  background: #f8f9fa;
}
.persona-card.active {
  border-color: var(--cw-primary, #0d6efd);
  background: #e7f1ff;
  box-shadow: 0 2px 6px rgba(13,110,253,.12);
}
.persona-card .persona-check input[type="checkbox"] {
  width: 1.35rem;
  height: 1.35rem;
  margin: 0;
  cursor: pointer;
}
.persona-card .persona-info {
  min-width: 0;
  line-height: 1.2;
}
.persona-card .persona-nome {
  font-size: .95rem;
  color: #212529;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.persona-card .persona-mansione {
  font-size: .78rem;
}
.persona-card .persona-ore {
  display: flex;
  align-items: center;
  gap: 4px;
}
.persona-card .persona-ore input {
  width: 70px;
  text-align: right;
  padding: .25rem .4rem;
}
/* Touch target mobile: card piu' alte per evitare mis-tap */
@media (max-width: 575px) {
  .persona-card { padding: 12px 10px; }
  .persona-card .persona-ore input { width: 62px; }
}
