/* style.css */

/* 1) BODY E FONT */
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap');

body {
  margin: 0;
  font-family: 'Poppins', sans-serif;
  background-color: #fafafa;
  color: #333;
}

/* HEADER NEUTRO SCURO */
header {
  background: linear-gradient(90deg, #202124, #263238);  /* antracite -> blu/grigio scuro */
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 30px;
}

.logo img {
  height: 50px;
}

nav a {
  text-decoration: none;
  color: #f5f5f5;      /* testo chiaro */
  font-weight: 500;
  margin-left: 20px;
  transition: color 0.3s;
}

nav a:hover {
  color: #a5d6a7;      /* accento verde chiaro in hover */
}

/* 3) FLASH MESSAGES */
.flash-messages {
  margin: 20px auto;
  max-width: 900px;
}
.flash-messages ul {
  list-style: none;
  padding: 0;
  margin: 0;
}
.flash-messages li {
  background: #ffeeba;
  border-left: 4px solid #ffc107;
  padding: 10px;
  margin: 10px 0;
  border-radius: 4px;
}
.flash-messages li strong {
  margin-right: 5px;
}

/* 4) MAIN CONTAINER */
main {
  margin: 20px auto;
  max-width: 900px;
  background-color: #fff;
  padding: 20px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
  border-radius: 4px;
}

/* 5) FORM GENERALE */
.form-group {
  margin-bottom: 15px;
  display: flex;
  flex-direction: column;
}

.form-group label {
  font-weight: 500;
  margin-bottom: 5px;
}

.form-control {
  padding: 8px;
  border-radius: 4px;
  border: 1px solid #ccc;
}

.form-control:focus {
  outline: none;
  border-color: #388e3c; /* verde */
}

/* Bottoni generici (form) */
.btn-submit,
.btn-default {
  padding: 10px 20px;
  background: #388e3c;      /* verde principale */
  color: #fff;
  font-weight: 600;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.btn-submit:hover,
.btn-default:hover {
  background: #2e7d32;      /* verde più scuro in hover */
}

/* 6) TABELLE */
.table-users {
  width: 100%;
  border-collapse: collapse;
  margin-top: 20px;
  background-color: #fff;
  font-size: 0.95rem;
}

.table-users thead {
  background: #e8f5e9; /* verde chiarissimo */
}

.table-users th,
.table-users td {
  padding: 12px 15px;
  border-bottom: 1px solid #eee;
  text-align: left;
}

.table-users tbody tr:hover {
  background: #f9f9f9;
}

/* 7) MENÙ PRINCIPALE */
.menu-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 15px;
  margin-top: 20px;
}

.menu-button {
  flex: 0 0 200px;
  text-align: center;
  padding: 12px 20px;
  background: #388e3c;
  color: #fff;
  text-decoration: none;
  font-weight: 600;
  border-radius: 6px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  transition: background 0.2s, transform 0.1s, box-shadow 0.2s;
}

.menu-button:hover {
  background: #2e7d32;
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.link-button {
  border: none;
  background: none;
  padding: 0;
  font: inherit;
  color: #007acc;
  cursor: pointer;
  text-decoration: underline;
}

.link-button:hover {
  color: #005fab;
}

/* Barra filtri rapportini */
.filter-form {
  margin-bottom: 10px;
}

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.filter-left {
  display: flex;
  align-items: center;
  gap: 15px;
}

.filter-inline {
  display: flex;
  align-items: center;
  gap: 5px;
}

.filter-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Filtri avanzati */
.filter-advanced {
  margin-right: 10px;
}

.filter-advanced > summary {
  cursor: pointer;
  font-weight: 500;
}

.filter-advanced-body {
  margin-top: 8px;
  padding: 10px;
  border-radius: 4px;
  background: #f5f5f5;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}

/* Rapportino: tabella utenti */
#tab_utenti .col-utente {
  width: 220px;
}

#tab_utenti .col-ore-viaggio {
  width: 100px;
}

#tab_utenti td.col-ore-viaggio .form-control {
  max-width: 80px;
}
.btn-cancel {
  padding: 10px 20px;
  background: #d9534f;
  color: #fff;
  font-weight: 600;
  border-radius: 4px;
  text-decoration: none;
  border: none;
  display: inline-block;
  margin-left: 10px;
}
.btn-cancel:hover {
  background: #c9302c;
}
/* Input più piccoli nei form */
.small-input {
  max-width: 110px;
}

.very-small-input {
  max-width: 70px;   /* usato per Ore viaggio */
}

/* Bottoni piccoli (es. X e filtri) */
.btn-small {
  padding: 5px 10px;
  font-size: 0.85rem;
}

/* Layout filtri lista rapportini */
.filters-form {
  margin-bottom: 15px;
}

.filters-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.filter-inline {
  display: flex;
  align-items: center;
  gap: 5px;
}

.advanced-filters {
  display: none;
  margin-top: 10px;
}

.advanced-filters.visible {
  display: block;
}

/* 2 colonne: (Commessa+Collaboratore) / (Date) */
.filters-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 20px;
}

.filters-grid .form-control {
  width: 100%;
}

/* Date un po' più strette */
.filters-grid input[type="date"] {
  max-width: 160px;
}

.nowrap {
  white-space: nowrap !important;
  word-break: normal;
}

/* =========================
   MOBILE RESPONSIVE OVERRIDES
   (solo telefono / schermi piccoli)
   ========================= */

/* =========================
   RESPONSIVE (pulito)
   ========================= */
* { box-sizing: border-box; }
img { max-width: 100%; height: auto; }

/* X rossa sempre */
.btn-reset{
  background: #cc3333 !important;
  color: #fff !important;
  width: 40px;
  height: 32px;
  padding: 0 !important;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  font-weight: 800;
  line-height: 1;
  text-decoration: none;
}
.btn-reset:hover{ background: #b52b2b !important; }

/* Nuovo rapportino sotto e centrato SEMPRE */
.btn-new-rapportino{
  order: 99;
  flex-basis: 100%;
  margin-top: 12px;
  width: fit-content;
  margin-left: auto;
  margin-right: auto;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  padding: 10px 18px;
  border-radius: 10px;
}

@media (max-width: 768px){

  /* HEADER mobile: logo sx, nav dx */
  header{
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    flex-wrap: nowrap;
    gap: 10px;
    padding: 12px 16px;
  }
  .logo img{ height: 42px; }

  nav{
    width: auto;
    margin-left: auto;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
  }
  nav a{
    margin-left: 0;
    padding: 6px 8px;
    border-radius: 8px;
    background: rgba(255,255,255,0.06);
    font-size: 0.95rem;
  }

  /* contenitore */
  .flash-messages{ margin: 12px; max-width: 100%; }

  main{
    margin: 12px;
    max-width: 100%;
    padding: 14px;
    border-radius: 10px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .form-group{ min-width: 0 !important; }
  input, select, textarea, button{ font-size: 16px; }
  .form-control{ width: 100%; }

  .menu-button{ flex: 1 0 100%; }

  .filters-grid{ grid-template-columns: 1fr; }

  /* =========================
     RAPPORTINI -> CARD VIEW
     ========================= */
  table.table-users.table-rapportini{
    width: 100%;
    min-width: 0;
    border-collapse: separate;
    border-spacing: 0 12px;
    background: transparent;
  }

  table.table-users.table-rapportini thead{ display:none; }

  table.table-users.table-rapportini tbody tr{
    display:block;
    position: relative;
    border-radius: 14px;
    border: 1px solid rgba(0,0,0,0.10);
    box-shadow: 0 2px 10px rgba(0,0,0,0.06);
    overflow:hidden;
    margin-bottom: 14px;
    background: linear-gradient(180deg, #ffffff, #fbfbfb);
  }

  table.table-users.table-rapportini tbody tr::before{
    content:"";
    position:absolute;
    left:0; top:0; bottom:0;
    width:6px;
    background: rgba(0,0,0,0.15);
  }

  /* colori per stato (coerenti) */
  table.table-users.table-rapportini tbody tr[data-stato="CHIUSO"]{
    background: linear-gradient(180deg, rgba(56,142,60,0.08), #ffffff);
  }
  table.table-users.table-rapportini tbody tr[data-stato="CHIUSO"]::before{ background:#388e3c; }

  table.table-users.table-rapportini tbody tr[data-stato="APERTO"]{
    background: linear-gradient(180deg, rgba(255,193,7,0.14), #ffffff);
  }
  table.table-users.table-rapportini tbody tr[data-stato="APERTO"]::before{ background:#ffb300; }

  table.table-users.table-rapportini tbody tr[data-stato="INVIATO"]{
    background: linear-gradient(180deg, rgba(33,150,243,0.12), #ffffff);
  }
  table.table-users.table-rapportini tbody tr[data-stato="INVIATO"]::before{ background:#2196f3; }

  table.table-users.table-rapportini tbody td{
    display:flex;
    align-items:flex-start;
    justify-content:space-between;
    gap:12px;
    padding:10px 12px;
    border:0;
    border-bottom:1px solid rgba(0,0,0,0.06);
    white-space: normal;
    word-break: break-word;
  }
  table.table-users.table-rapportini tbody td:last-child{ border-bottom:0; }

  table.table-users.table-rapportini tbody td::before{
    content: attr(data-label);
    font-weight: 700;
    opacity: .75;
    min-width: 92px;
    flex: 0 0 92px;
  }

  table.table-users.table-rapportini td[data-label="Stato"]{ font-weight: 800; }
  
  /* COMMESSA: label sopra, valore sotto e full width */
  table.table-users.table-rapportini td[data-label="Commessa"]{
    display: block;                 /* invece di flex */
    padding: 10px 12px;
  }

  table.table-users.table-rapportini td[data-label="Commessa"]::before{
    display: block;
    margin-bottom: 6px;
    min-width: 0;
    flex: none;
  }

  /* il testo della commessa va a capo bene */
  table.table-users.table-rapportini td[data-label="Commessa"]{
    white-space: normal;
    word-break: break-word;
  }
  
  /* AZIONI: solo bottoni centrati in fondo */
  table.table-users.table-rapportini td[data-label="Azioni"]{
    justify-content: center;
    gap: 10px;
    padding: 12px;
    background: rgba(0,0,0,0.02);
  }
  table.table-users.table-rapportini td[data-label="Azioni"]::before{
    content:"";
    display:none;
  }
  table.table-users.table-rapportini td[data-label="Azioni"] a,
  table.table-users.table-rapportini td[data-label="Azioni"] .link-button{
    padding: 10px 12px;
    border-radius: 12px;
    min-width: 120px;
    display:inline-flex;
    justify-content:center;
    align-items:center;
    font-weight: 800;
    text-decoration:none;
  }
  table.table-users.table-rapportini td[data-label="Azioni"] a{
    background: rgba(56,142,60,0.12);
    color: #1f6f24;
  }
  table.table-users.table-rapportini td[data-label="Azioni"] .link-button{
    background: rgba(204,51,51,0.12);
    color: #b52b2b;
    border:none;
    cursor:pointer;
  }

  /* data nowrap non serve in card */
  table.table-users.table-rapportini .nowrap{ white-space: normal !important; }
}
@media (max-width: 768px){

  /* =========================
     UTENTI E ORE -> CARD
     ========================= */
  #utenti-table.table-users{
    width: 100% !important;
    min-width: 0 !important;
    border-collapse: separate;
    border-spacing: 0 12px;
    background: transparent;
  }

  #utenti-table thead{ display:none; }

  #utenti-table tbody tr{
    display: grid;
    grid-template-columns: 1fr 1fr;   /* 2 colonne: Da/A affiancati */
    gap: 10px;
    padding: 12px;
    border: 1px solid rgba(0,0,0,0.10);
    border-radius: 14px;
    background: linear-gradient(180deg, #ffffff, #fbfbfb);
    box-shadow: 0 2px 10px rgba(0,0,0,0.06);
  }

  /* evita che l'hover desktop rovini il background delle card */
  #utenti-table tbody tr:hover{ background: linear-gradient(180deg, #ffffff, #fbfbfb); }

  #utenti-table tbody td{
    padding: 0;
    border: 0;
  }

  /* Utente a tutta riga */
  #utenti-table tbody td:nth-child(1){
    grid-column: 1 / -1;
  }

  /* Celle orari: label sopra + widget sotto */
  #utenti-table tbody td:nth-child(2),
  #utenti-table tbody td:nth-child(3),
  #utenti-table tbody td:nth-child(4),
  #utenti-table tbody td:nth-child(5){
    display: flex;
    flex-direction: column;
    gap: 6px;
  }

  #utenti-table tbody td:nth-child(2)::before{ content:"Da 1"; font-weight:700; opacity:.75; }
  #utenti-table tbody td:nth-child(3)::before{ content:"A 1";  font-weight:700; opacity:.75; }
  #utenti-table tbody td:nth-child(4)::before{ content:"Da 2"; font-weight:700; opacity:.75; }
  #utenti-table tbody td:nth-child(5)::before{ content:"A 2";  font-weight:700; opacity:.75; }

  /* Ora/minuto comodi su mobile */
  #utenti-table .time-ui{
    gap: 8px !important;
  }
  #utenti-table .time-ui select{
    width: 100%;
    min-width: 0;
  }
  #utenti-table .small-input{ max-width: none; } /* override: niente max-width su mobile */

  /* Bottone X centrato in fondo */
  #utenti-table tbody td:last-child{
    grid-column: 1 / -1;
    display: flex;
    justify-content: center;
    margin-top: 2px;
  }
  #utenti-table tbody td:last-child .btn-default{
    width: auto;
    padding: 10px 14px;
    border-radius: 12px;
    background: #cc3333;
  }
  #utenti-table tbody td:last-child .btn-default:hover{
    background: #b52b2b;
  }


  /* =========================
     MATERIALI GREZZA -> CARD
     ========================= */
  #materiali-table.table-users{
    width: 100% !important;
    min-width: 0 !important;
    border-collapse: separate;
    border-spacing: 0 12px;
    background: transparent;
    margin-top: 0;
  }

  #materiali-table thead{ display:none; }

  #materiali-table tbody tr{
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    padding: 12px;
    border: 1px solid rgba(0,0,0,0.10);
    border-radius: 14px;
    background: linear-gradient(180deg, #ffffff, #fbfbfb);
    box-shadow: 0 2px 10px rgba(0,0,0,0.06);
  }
  #materiali-table tbody tr:hover{ background: linear-gradient(180deg, #ffffff, #fbfbfb); }

  #materiali-table tbody td{
    padding: 0;
    border: 0;
  }

  /* Descrizione full width e label sopra */
  #materiali-table tbody td:nth-child(1){
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    gap: 6px;
  }
  #materiali-table tbody td:nth-child(1)::before{
    content: "Descrizione";
    font-weight: 700;
    opacity: .75;
  }

  /* Qtà e UM con label sopra */
  #materiali-table tbody td:nth-child(2),
  #materiali-table tbody td:nth-child(3){
    display: flex;
    flex-direction: column;
    gap: 6px;
  }
  #materiali-table tbody td:nth-child(2)::before{ content:"Qtà"; font-weight:700; opacity:.75; }
  #materiali-table tbody td:nth-child(3)::before{ content:"UM";  font-weight:700; opacity:.75; }

  /* input full width */
  #materiali-table .form-control{ width: 100%; }
  #materiali-table .small-input{ max-width: none; }

  /* bottone X centrato in fondo */
  #materiali-table tbody td:nth-child(4){
    grid-column: 1 / -1;
    display: flex;
    justify-content: center;
  }
  #materiali-table tbody td:nth-child(4) .btn-default{
    width: auto;
    padding: 10px 14px;
    border-radius: 12px;
    background: #cc3333;
  }
  #materiali-table tbody td:nth-child(4) .btn-default:hover{
    background: #b52b2b;
  }
  /* se è disabilitato, resta neutro */
  #materiali-table tbody td:nth-child(4) .btn-default:disabled{
    background: rgba(0,0,0,0.08);
    color: rgba(0,0,0,0.35);
    cursor: not-allowed;
  }
}
@media (max-width: 768px){

  /* più spazio verticale per textarea (descrizione / note) */
  textarea.form-control{
    min-height: 140px;     /* puoi salire a 160/180 se vuoi */
    padding: 12px 12px;
    line-height: 1.35;
    resize: vertical;      /* l’utente può allungare */
  }

  /* un filo più di aria tra i gruppi */
  .form-group{
    margin-bottom: 18px;
  }
}
/* nasconde i select “di servizio” (restano nel DOM per submit e data-*) */
.combo-hidden{ display:none !important; }

@media (max-width: 768px){
  /* Commessa sopra, Cliente sotto */
  .cc-wrap{
    flex-direction: column !important;
  }
  .cc-wrap > .form-group{
    min-width: 0 !important;
  }
}
/* select nascosti “di servizio” */
.combo-hidden{ display:none !important; }

/* combo custom */
.combo{ position: relative; }
.combo-menu{
  position: absolute;
  left: 0; right: 0;
  top: calc(100% + 6px);
  background: #fff;
  border: 1px solid rgba(0,0,0,0.12);
  border-radius: 12px;
  box-shadow: 0 10px 22px rgba(0,0,0,0.12);
  max-height: 42vh;
  overflow: auto;
  display: none;
  z-index: 9999;
  -webkit-overflow-scrolling: touch;
}
.combo-menu.open{ display:block; }

.combo-item{
  padding: 10px 12px;
  cursor: pointer;
  border-bottom: 1px solid rgba(0,0,0,0.06);
  line-height: 1.25;
}
.combo-item:last-child{ border-bottom: 0; }
.combo-item:hover{ background: rgba(56,142,60,0.10); }
.combo-item.active{ background: rgba(56,142,60,0.16); }

.combo-empty{
  padding: 10px 12px;
  opacity: .7;
}

/* mobile: commessa e cliente in colonna */
@media (max-width: 768px){
  .cc-wrap{ flex-direction: column !important; }
  .cc-wrap > .form-group{ min-width: 0 !important; }
}
/* Commessa + Cliente (combo) -> full width su desktop */
.cc-wrap .combo{
  width: 100%;
}

.cc-wrap .combo .combo-input{
  width: 100%;
  display: block;
}
/* I due box si dividono bene la riga */
.cc-wrap > .form-group{
  flex: 1 1 0 !important;
}
