:root {
  --wgt-accent: #0d6efd;
  --wgt-success: #198754;
  --wgt-danger: #dc3545;
  --wgt-bg: #f5f7fb;
  --wgt-card: #ffffff;
  --wgt-text: #111827;
  --wgt-muted: #6b7280;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  color: var(--wgt-text);
  background:
    radial-gradient(1000px 400px at 10% 0%, rgba(13,110,253,0.18), transparent 60%),
    radial-gradient(900px 420px at 90% 100%, rgba(32,201,151,0.16), transparent 55%),
    var(--wgt-bg);
}

a { color: var(--wgt-accent); }

/* --- Auth pages (mobile+desktop login) --- */
.wgt-page {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 22px;
}
.wgt-auth-card {
  width: min(520px, 100%);
  background: var(--wgt-card);
  border: 1px solid rgba(17,24,39,0.08);
  border-radius: 22px;
  overflow: hidden;
  box-shadow: 0 16px 60px rgba(0,0,0,0.10);
}
.wgt-auth-hero {
  width: 100%;
  height: 150px;
  object-fit: cover;
  display: block;
}
.wgt-auth-body { padding: 18px 18px 20px; text-align: center; }
.wgt-brandrow { display:flex; align-items:center; justify-content:center; gap: 10px; margin-bottom: 8px; }
.wgt-logo { width: 40px; height: 40px; }
.wgt-title { margin: 0; font-size: 1.35rem; letter-spacing: .2px; }
.wgt-subtitle { margin: 6px 0 14px; color: var(--wgt-muted); }

.wgt-field { text-align: left; }
.wgt-label { display:block; font-size: .95rem; color: var(--wgt-muted); margin: 0 0 6px; }

/* Input/select styling (mobile + desktop)
   Goal: match the size/shape of the primary action buttons */
.wgt-field { width: 100%; }
.wgt-input {
  width: 100%;
  font-size: 1.05rem;
  padding: 0.95rem 1.1rem;
  border-radius: 16px;
  border: 1px solid rgba(17,24,39,0.14);
  outline: none;
  background: #fff;
}
.wgt-input:focus { border-color: rgba(13,110,253,0.55); box-shadow: 0 0 0 4px rgba(13,110,253,0.12); }

.pin-input {
  width: 100%;
  font-size: 1.7rem;
  padding: 14px 14px;
  border-radius: 16px;
  border: 1px solid rgba(17,24,39,0.14);
  outline: none;
  text-align: center;
  letter-spacing: .30em;
  background: #fff;
}
.pin-input:focus { border-color: rgba(13,110,253,0.55); box-shadow: 0 0 0 4px rgba(13,110,253,0.12); }

.wgt-bigbtn {
  font-size: 1.15rem;
  padding: 0.95rem 1.1rem;
  width: 100%;
  border-radius: 16px;
  border: 0;
  background: linear-gradient(135deg, var(--wgt-accent), #20c997);
  color: #fff;
  font-weight: 800;
  letter-spacing: .4px;
  cursor: pointer;
}
.wgt-bigbtn:hover { filter: brightness(.97); }
.wgt-bigbtn:active { transform: translateY(1px); }
.wgt-bigbtn:disabled {
  opacity: .45;
  cursor: not-allowed;
  filter: saturate(.2);
}
.wgt-btn-muted {
  background: #fff;
  color: var(--wgt-text);
  border: 1px solid rgba(17,24,39,0.14);
}

.wgt-muted { color: var(--wgt-muted); font-size: .95rem; }
.wgt-danger { color: var(--wgt-danger); }

/* --- Mobile main --- */
.wgt-card {
  max-width: 520px;
  margin: 0 auto;
  padding: 18px 18px;
  background: var(--wgt-card);
  border: 1px solid rgba(17,24,39,0.08);
  border-radius: 22px;
  box-shadow: 0 14px 44px rgba(0,0,0,0.08);
}
.wgt-card.wgt-wide{ max-width:none; margin: 0; width:100%; }

/* Spaziatura tra card nel pannello desktop */
.wgt-main .wgt-card{ margin-bottom: 14px; }
.wgt-main .wgt-card:last-child{ margin-bottom: 0; }

/* Card senza padding (rari casi) */
.wgt-card.no-pad{ padding: 0; }
.wgt-filter-grid{ display:grid; gap:10px; align-items:end; grid-template-columns: 2.2fr 1fr 1fr 1fr 1.6fr 1.6fr .9fr .9fr auto; }
/*
  Azioni nei filtri (XLSX / Applica / Reset, ecc.)
  Requisiti:
  - pulsanti allineati verticalmente rispetto ai campi (stessa "riga" degli input)
  - pulsanti allineati a sinistra
*/
.wgt-filter-actions{
  display:flex;
  gap:8px;
  justify-content:flex-start;
  align-items:center;
  /* compensa l'altezza della label sopra i campi (wgt-field-title/wgt-muted) */
  padding-top: 24px;
}
.wgt-filter-actions.right{ justify-content:flex-end; }

/* Controlli e pulsanti: stessa altezza minima per allineamento perfetto */
:root{ --wgt-ctl-minh: 52px; }
.wgt-input{ min-height: var(--wgt-ctl-minh); }
.wgt-filter-actions .btn{ min-height: var(--wgt-ctl-minh); }

/* Etichette standard nei filtri */
.wgt-filter-grid .wgt-muted{ display:block; margin:0 0 6px 4px; }


/* Filter grids: varianti pagina */
.wgt-filter-grid.devices{
  grid-template-columns: 2.4fr 1fr 1fr .9fr .9fr 1fr 1fr .9fr auto;
}

.wgt-filter-grid.utenti{
  grid-template-columns: 2.2fr 1fr 1fr 1fr 1.2fr 1.2fr .9fr auto;
}

@media (max-width: 1400px){
  .wgt-filter-grid.devices{ grid-template-columns: 2fr 1fr 1fr 1fr 1fr 1fr .9fr auto; }
  .wgt-filter-grid.utenti{ grid-template-columns: 2fr 1fr 1fr 1fr 1.2fr .9fr auto; }
}
@media (max-width: 1100px){
  .wgt-filter-grid.devices{ grid-template-columns: 2fr 1fr 1fr 1fr 1fr auto; }
  .wgt-filter-grid.utenti{ grid-template-columns: 2fr 1fr 1fr 1fr auto; }
}
@media (max-width: 760px){
  .wgt-filter-grid.devices{ grid-template-columns: 1fr 1fr; }
  .wgt-filter-grid.devices .wgt-filter-search{ grid-column: span 2; }
  .wgt-filter-grid.utenti{ grid-template-columns: 1fr 1fr; }
  .wgt-filter-grid.utenti .wgt-filter-search{ grid-column: span 2; }
}
@media (max-width: 520px){
  .wgt-filter-grid.devices{ grid-template-columns: 1fr; }
  .wgt-filter-grid.devices .wgt-filter-search{ grid-column: span 1; }
  .wgt-filter-grid.utenti{ grid-template-columns: 1fr; }
  .wgt-filter-grid.utenti .wgt-filter-search{ grid-column: span 1; }
}

/* Allinea pulsanti ai campi nei form filtri */
.wgt-filter-actions .btn{
  padding: 0.95rem 1.1rem;
  border-radius: 16px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}
.wgt-filter-grid .wgt-filter-search{ grid-column: span 2; }
@media (max-width: 1400px){ .wgt-filter-grid{ grid-template-columns: 2fr 1fr 1fr 1fr 1.6fr 1.6fr .9fr auto; } .wgt-filter-grid .wgt-filter-search{ grid-column: span 2; } }
@media (max-width: 1100px){ .wgt-filter-grid{ grid-template-columns: 1fr 1fr 1fr; } .wgt-filter-grid .wgt-filter-search{ grid-column: span 3; } }
@media (max-width: 760px){ .wgt-filter-grid{ grid-template-columns: 1fr 1fr; } .wgt-filter-grid .wgt-filter-search{ grid-column: span 2; } }
@media (max-width: 520px){ .wgt-filter-grid{ grid-template-columns: 1fr; } .wgt-filter-grid .wgt-filter-search{ grid-column: span 1; } }
.wgt-timb-view{ display:grid; grid-template-rows: 1.15fr .85fr; gap:14px; }
.wgt-timb-view #map{ height:100%; }
.wgt-timb-view .wgt-table-scroll{ height:100%; max-height:none; }

/* Reperibilità: selettore dipendente con ricerca */
.wgt-dip-picker{display:flex;flex-direction:column;gap:8px}
.wgt-dip-picker .wgt-input{width:100%}


.wgt-gps-ind { width: 12px; height: 12px; border-radius: 50%; display: inline-block; margin-right: 8px; }
.wgt-ok { background: var(--wgt-success); }
.wgt-ko { background: var(--wgt-danger); }

/* Mobile top bar (ora server + terminale) */
.topbar{
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(17,24,39,0.08);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.topbar .muted{ color: var(--wgt-muted); font-size:.95rem; }

.wgt-term { font-weight: 800; }

.wgt-actions { display:grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 380px){ .wgt-actions{ grid-template-columns: 1fr; } }

.wgt-pill {
  display:inline-flex;
  align-items:center;
  gap:8px;
  padding: 8px 10px;
  border-radius: 999px;
  border: 1px solid rgba(17,24,39,0.10);
  background: rgba(255,255,255,0.7);
}

/* Scrollable table (mobile last punches) */
.wgt-table-scroll{
  max-height: 230px;
  overflow: auto;
  border: 1px solid rgba(17,24,39,0.08);
  border-radius: 16px;
  background: #fff;
}
.wgt-table{
  width: 100%;
  border-collapse: collapse;
  font-size: .95rem;
}
.wgt-table th, .wgt-table td{
  padding: 10px 10px;
  border-bottom: 1px solid rgba(17,24,39,0.06);
  vertical-align: top;
}
.wgt-table th{
  position: sticky;
  top: 0;
  background: #fbfbfc;
  z-index: 1;
  text-transform: uppercase;
  font-size: .75rem;
  letter-spacing: .06em;
  color: var(--wgt-muted);
}

.wgt-row-click{ cursor: pointer; }
.wgt-row-click:hover{ background: rgba(17,24,39,0.04); }
.wgt-row-active{ background: rgba(59,130,246,0.12) !important; }

/* --- Desktop shell --- */
.wgt-shell{ display:flex; min-height:100vh; }
.wgt-sidebar{
  width: 280px;
  border-right: 1px solid rgba(17,24,39,0.08);
  padding: 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(10px);
}
.wgt-brand{ display:flex; align-items:center; gap:10px; font-weight: 900; letter-spacing:.2px; margin-bottom: 14px; }
.wgt-brand img{ width: 34px; height:34px; }
.wgt-nav a{
  display:flex;
  gap:10px;
  align-items:center;
  padding: 10px 10px;
  border-radius: 12px;
  text-decoration:none;
  color: var(--wgt-text);
}
.wgt-nav a:hover{ background: rgba(17,24,39,0.04); }
.wgt-nav .active{ background: rgba(13,110,253,0.10); color: var(--wgt-accent); }
.wgt-main{ flex:1; padding: 18px 22px; }

/* Contenitore centrato (usato in alcune pagine per non arrivare a bordo schermo) */
.wgt-content{ max-width: 1400px; margin: 0 auto; }
.wgt-toprow{ display:flex; align-items:flex-end; justify-content:space-between; gap:12px; margin-bottom:14px; }
.wgt-kpi{ display:grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap:12px; }

/* Card “leggera” interna (es. dashboard, box form) */
.card{
  border:1px solid rgba(17,24,39,0.08);
  border-radius:16px;
  background:#fff;
  box-shadow: 0 10px 30px rgba(0,0,0,0.06);
}
.wgt-kpi .card{ padding:14px; }

.table{ width:100%; border-collapse: collapse; }
.table th, .table td{ border-bottom:1px solid rgba(17,24,39,0.08); padding:10px 8px; text-align:left; font-size:.95rem; }
.table th{ background:#fbfbfc; position:sticky; top:0; z-index:1; }

.badge{ display:inline-block; padding:4px 10px; border-radius:999px; font-size:.85rem; background: rgba(17,24,39,0.05); }
.badge.ok{ background: rgba(25,135,84,0.12); color: #0f5132; }
.badge.ko{ background: rgba(220,53,69,0.12); color: #842029; }

.btn{ display:inline-flex; align-items:center; gap:8px; padding:10px 12px; border-radius:14px; border:1px solid rgba(17,24,39,0.14); text-decoration:none; color: var(--wgt-text); background:#fff; cursor:pointer; }
.btn:hover{ background:#f7f7f7; }
.btn-primary{ border-color: transparent; background: linear-gradient(135deg, var(--wgt-accent), #20c997); color:#fff; }
.btn-primary:hover{ filter: brightness(.97); }

/* Varianti pulsanti usate nel pannello desktop */
.btn-outline{ background:#fff; border:1px solid rgba(17,24,39,0.18); }
.btn-outline:hover{ background: rgba(17,24,39,0.04); }
.btn-danger{ border-color: transparent; background: linear-gradient(135deg, var(--wgt-danger), #ff6b6b); color:#fff; }
.btn-danger:hover{ filter: brightness(.97); }

/* Pulsante “dimensione controllo”: stessa altezza/forma degli input */
.btn-ctl{
  padding: 0.95rem 1.1rem;
  border-radius: 16px;
}

/* Etichetta sopra i campi nei filtri: evita inline-style ripetuti */
.wgt-field-title{ margin:0 0 6px 4px; color: var(--wgt-muted); font-size: .92rem; }

/* Allinea automaticamente eventuali label/descrizioni dentro griglie filtro */
.wgt-filter-grid > div > .wgt-muted{ margin:0 0 6px 4px; }

@media (max-width: 980px){
  .wgt-sidebar{ display:none; }
  .wgt-main{ padding: 14px; }
}

.wgt-hr{ border:0; border-top:1px solid rgba(17,24,39,0.10); margin:14px 0; }

.wgt-alert{ border:1px solid rgba(17,24,39,0.12); padding:10px 12px; border-radius:14px; background:#fff; }
.wgt-alert-danger{ border-color: rgba(220,53,69,0.25); background: rgba(220,53,69,0.08); color:#842029; }

/* --- Heatmap lettori --- */
.wgt-heatmap-wrap{
  overflow: auto;
  border: 1px solid rgba(17,24,39,0.08);
  border-radius: 16px;
  background: #fff;
}
.wgt-heatmap{
  width: max-content;
  min-width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: .85rem;
}
.wgt-heatmap th{
  position: sticky;
  top: 0;
  background: #fbfbfc;
  z-index: 2;
  padding: 10px 8px;
  border-bottom: 1px solid rgba(17,24,39,0.06);
  text-transform: uppercase;
  font-size: .72rem;
  letter-spacing: .06em;
  color: var(--wgt-muted);
}
.wgt-heatmap td{
  padding: 8px 6px;
  border-bottom: 1px solid rgba(17,24,39,0.06);
  border-right: 1px solid rgba(17,24,39,0.05);
  text-align: center;
  min-width: 34px;
}
.wgt-heatmap .sticky-col{
  position: sticky;
  left: 0;
  z-index: 3;
  background: #fff;
  min-width: 280px;
  text-align: left;
  border-right: 1px solid rgba(17,24,39,0.08);
}
.wgt-heatmap .hmcell{ border-radius: 0; }
.wgt-heatmap .hmcell.tot{ background:#fbfbfc; font-weight: 800; }

/* livelli intensità */
.wgt-heatmap .l0{ background: transparent; }
.wgt-heatmap .l1{ background: rgba(13,110,253,0.10); }
.wgt-heatmap .l2{ background: rgba(13,110,253,0.18); }
.wgt-heatmap .l3{ background: rgba(13,110,253,0.28); }
.wgt-heatmap .l4{ background: rgba(13,110,253,0.38); }
.wgt-heatmap .l5{ background: rgba(13,110,253,0.50); color:#fff; font-weight: 800; }

.wgt-hm-legend{ display:inline-flex; align-items:center; gap:6px; margin-left:10px; }
.wgt-hm-legend .hm{ width:14px; height:14px; border-radius:4px; border:1px solid rgba(17,24,39,0.08); display:inline-block; }
.wgt-hm-legend .hm.l0{ background: transparent; }
.wgt-hm-legend .hm.l1{ background: rgba(13,110,253,0.10); }
.wgt-hm-legend .hm.l2{ background: rgba(13,110,253,0.18); }
.wgt-hm-legend .hm.l3{ background: rgba(13,110,253,0.28); }
.wgt-hm-legend .hm.l4{ background: rgba(13,110,253,0.38); }
.wgt-hm-legend .hm.l5{ background: rgba(13,110,253,0.50); }

/* Leaflet - icona "lettore orario" per timbrature */
.wgt-reader-pin{
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: linear-gradient(135deg, rgba(99,102,241,0.96), rgba(59,130,246,0.92));
  border: 2px solid rgba(255,255,255,0.95);
  box-shadow: 0 10px 22px rgba(2,6,23,0.22);
  color: #fff;
  font-size: 18px;
  line-height: 1;
}
.wgt-reader-pin::after{
  content: '';
  position: absolute;
  width: 0;
  height: 0;
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-top: 11px solid rgba(99,102,241,0.96);
  transform: translateY(22px);
  filter: drop-shadow(0 6px 10px rgba(2,6,23,0.18));
}
.wgt-reader-pin.disabled{
  background: linear-gradient(135deg, rgba(148,163,184,0.95), rgba(100,116,139,0.9));
  box-shadow: 0 8px 18px rgba(2,6,23,0.18);
}
.wgt-reader-pin.disabled::after{
  border-top-color: rgba(148,163,184,0.95);
}
.wgt-reader-pin.editing{
  background: linear-gradient(135deg, rgba(245,158,11,0.95), rgba(251,191,36,0.92));
}
.wgt-reader-pin.editing::after{
  border-top-color: rgba(245,158,11,0.95);
}

/* Leaflet - icona "omino" per timbrature (marker diverso dai lettori) */
.wgt-human-pin{
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  border: 2px solid rgba(255,255,255,0.95);
  box-shadow: 0 10px 22px rgba(2,6,23,0.22);
  color: #fff;
  font-size: 18px;
  line-height: 1;
}
.wgt-human-pin::after{
  content: '';
  position: absolute;
  width: 0;
  height: 0;
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  transform: translateY(22px);
  filter: drop-shadow(0 6px 10px rgba(2,6,23,0.18));
}
.wgt-human-pin.in{
  background: linear-gradient(135deg, rgba(34,197,94,0.95), rgba(16,185,129,0.92));
}
.wgt-human-pin.in::after{
  border-top: 11px solid rgba(34,197,94,0.95);
}
.wgt-human-pin.out{
  background: linear-gradient(135deg, rgba(239,68,68,0.95), rgba(244,63,94,0.92));
}
.wgt-human-pin.out::after{
  border-top: 11px solid rgba(239,68,68,0.95);
}

/* --- PIN reveal controls (admin) --- */
.wgt-pincell{display:flex;align-items:center;gap:8px;flex-wrap:nowrap;}
.wgt-pin-mask{letter-spacing:0.25em;}
.wgt-pin-clear{font-family:ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;letter-spacing:0.12em;}
.wgt-iconbtn{border:1px solid rgba(0,0,0,.12);background:#fff;color:var(--wgt-text);padding:0.35rem 0.55rem;border-radius:12px;display:inline-flex;align-items:center;gap:6px;cursor:pointer;}
.wgt-iconbtn:hover{border-color:rgba(0,0,0,.2);background:rgba(0,0,0,.03);}
.wgt-iconbtn:disabled{opacity:.65;cursor:not-allowed;}
