/* ═══════════════════════════════════════════════════════
   PRESENZE CAM — Foglio di stile principale
   ═══════════════════════════════════════════════════════ */

/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --c-bg:          #ffffff;
  --c-bg-2:        #f5f5f4;
  --c-bg-3:        #f0efed;
  --c-border:      rgba(0,0,0,.10);
  --c-border-md:   rgba(0,0,0,.16);
  --c-text:        #1a1a18;
  --c-text-muted:  #6b6b66;
  --c-text-hint:   #9b9b95;
  --c-primary:     #185FA5;
  --c-primary-dk:  #0C447C;
  --c-primary-lt:  #E6F1FB;
  --c-success:     #27500A;
  --c-success-bg:  #EAF3DE;
  --c-success-bd:  #C0DD97;
  --c-warn-bg:     #FAEEDA;
  --c-warn-bd:     #FAC775;
  --c-warn-text:   #633806;
  --c-danger:      #791F1F;
  --c-danger-bg:   #FCEBEB;
  --c-danger-bd:   #F7C1C1;
  --c-radius-sm:   6px;
  --c-radius:      8px;
  --c-radius-lg:   12px;
  --sidebar-w:     200px;
  --topbar-h:      48px;
  --font:          -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --c-bg:          #1c1c1a;
    --c-bg-2:        #252523;
    --c-bg-3:        #2c2c2a;
    --c-border:      rgba(255,255,255,.10);
    --c-border-md:   rgba(255,255,255,.18);
    --c-text:        #ededea;
    --c-text-muted:  #a0a09a;
    --c-text-hint:   #6b6b65;
    --c-primary-lt:  #042C53;
    --c-success:     #C0DD97;
    --c-success-bg:  #173404;
    --c-success-bd:  #27500A;
    --c-warn-bg:     #412402;
    --c-warn-bd:     #854F0B;
    --c-warn-text:   #FAC775;
    --c-danger:      #F7C1C1;
    --c-danger-bg:   #501313;
    --c-danger-bd:   #791F1F;
  }
}

html, body { height: 100%; }
body {
  font-family: var(--font);
  font-size: 14px;
  color: var(--c-text);
  background: var(--c-bg-3);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Screen switching ── */
.screen { display: none; }
.screen.active { display: block; }

/* ═══════════════════════════════════════════
   LOGIN
═══════════════════════════════════════════ */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--c-bg-3);
  padding: 1.5rem;
}

.login-card {
  background: var(--c-bg);
  border: 0.5px solid var(--c-border);
  border-radius: var(--c-radius-lg);
  padding: 2rem 2.5rem;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}

.login-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 2rem;
}
.logo-mark {
  width: 38px;
  height: 38px;
  background: var(--c-primary);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 18px;
  flex-shrink: 0;
}
.logo-name { font-size: 16px; font-weight: 600; color: var(--c-text); }
.logo-sub  { font-size: 12px; color: var(--c-text-muted); }

.field { margin-bottom: 1rem; }
.field label {
  display: block;
  font-size: 12px;
  color: var(--c-text-muted);
  margin-bottom: 5px;
  font-weight: 500;
}
.field input {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  border: 0.5px solid var(--c-border-md);
  border-radius: var(--c-radius);
  font-size: 14px;
  color: var(--c-text);
  background: var(--c-bg);
  transition: box-shadow .15s;
}
.field input:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(24,95,165,.20);
  border-color: var(--c-primary);
}

.pass-wrap { position: relative; }
.pass-wrap input { padding-right: 40px; }
.pass-eye {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--c-text-muted);
  cursor: pointer;
  font-size: 16px;
  padding: 0;
  line-height: 1;
}
.pass-eye:hover { color: var(--c-text); }

.err-msg {
  display: none;
  font-size: 13px;
  color: var(--c-danger);
  background: var(--c-danger-bg);
  border: 0.5px solid var(--c-danger-bd);
  border-radius: var(--c-radius);
  padding: 7px 12px;
  margin-bottom: 10px;
  align-items: center;
  gap: 6px;
}
.err-msg.visible { display: flex; }

.loading-msg {
  display: none;
  font-size: 13px;
  color: var(--c-text-muted);
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
}
.loading-msg.visible { display: flex; }

.btn-primary {
  width: 100%;
  height: 38px;
  background: var(--c-primary);
  color: #fff;
  border: none;
  border-radius: var(--c-radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s;
}
.btn-primary:hover { background: var(--c-primary-dk); }
.btn-primary:disabled { opacity: .6; cursor: not-allowed; }

.login-note {
  font-size: 11px;
  color: var(--c-text-hint);
  text-align: center;
  margin-top: 1rem;
}

@keyframes spin { to { transform: rotate(360deg); } }
.spin { display: inline-block; animation: spin .8s linear infinite; }

/* ═══════════════════════════════════════════
   APP SHELL
═══════════════════════════════════════════ */
#screen-app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── Topbar ── */
.topbar {
  height: var(--topbar-h);
  background: var(--c-bg);
  border-bottom: 0.5px solid var(--c-border);
  display: flex;
  align-items: center;
  padding: 0 1rem;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.sidebar-toggle {
  background: none;
  border: none;
  color: var(--c-text-muted);
  font-size: 20px;
  cursor: pointer;
  padding: 4px;
  border-radius: var(--c-radius-sm);
  display: none;
}
.sidebar-toggle:hover { background: var(--c-bg-2); color: var(--c-text); }

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 600;
  color: var(--c-text);
}
.brand-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--c-primary);
}
.topbar-spacer { flex: 1; }

.user-pill {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  color: var(--c-text-muted);
}
.user-pill .ti { font-size: 16px; }

.role-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 20px;
  font-weight: 500;
}
.role-badge.admin        { background: var(--c-primary-lt); color: var(--c-primary-dk); }
.role-badge.manutenzione { background: var(--c-success-bg); color: var(--c-success); }

.btn-logout {
  font-size: 13px;
  color: var(--c-text-muted);
  background: none;
  border: 0.5px solid var(--c-border);
  border-radius: var(--c-radius-sm);
  padding: 5px 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
}
.btn-logout:hover { background: var(--c-bg-2); color: var(--c-text); }

/* ── Layout ── */
.layout {
  display: flex;
  flex: 1;
  min-height: calc(100vh - var(--topbar-h));
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--c-bg-2);
  border-right: 0.5px solid var(--c-border);
  padding: 1rem 0;
  flex-shrink: 0;
  overflow-y: auto;
  transition: transform .2s ease;
}

.nav-section { padding: 0 .75rem; margin-bottom: .75rem; }
.nav-section-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--c-text-hint);
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: 0 .5rem;
  margin-bottom: 4px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 8px;
  border-radius: var(--c-radius);
  font-size: 13px;
  color: var(--c-text-muted);
  background: none;
  border: none;
  cursor: pointer;
  text-align: left;
  transition: background .12s, color .12s;
}
.nav-item .ti { font-size: 16px; }
.nav-item:hover  { background: var(--c-bg); color: var(--c-text); }
.nav-item.active { background: var(--c-bg); color: var(--c-primary); font-weight: 500; }

.nav-admin-only { display: none; }

/* ── Content ── */
.content {
  flex: 1;
  padding: 1.5rem;
  overflow-y: auto;
  background: var(--c-bg-3);
}

.page { display: none; }
.page.active { display: block; }

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 1.5rem;
}
.page-title {
  font-size: 20px;
  font-weight: 600;
  color: var(--c-text);
}
.page-date {
  font-size: 13px;
  color: var(--c-text-muted);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* ── Stats ── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 12px;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--c-bg);
  border: 0.5px solid var(--c-border);
  border-radius: var(--c-radius);
  padding: 1rem;
}
.stat-label {
  font-size: 12px;
  color: var(--c-text-muted);
  margin-bottom: 4px;
}
.stat-val {
  font-size: 26px;
  font-weight: 600;
  color: var(--c-text);
}

/* ── Table ── */
.table-wrap {
  background: var(--c-bg);
  border: 0.5px solid var(--c-border);
  border-radius: var(--c-radius-lg);
  overflow-x: auto;
}
.table-header {
  padding: 12px 16px;
  border-bottom: 0.5px solid var(--c-border);
}
.table-title { font-size: 14px; font-weight: 500; color: var(--c-text); }

table { width: 100%; border-collapse: collapse; white-space: nowrap; }
th {
  text-align: left;
  padding: 10px 14px;
  font-size: 11px;
  font-weight: 600;
  color: var(--c-text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  border-bottom: 0.5px solid var(--c-border);
  background: var(--c-bg-2);
}
td {
  padding: 10px 14px;
  font-size: 13px;
  border-bottom: 0.5px solid var(--c-border);
  color: var(--c-text);
}
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--c-bg-2); }
.empty-row { color: var(--c-text-hint); font-style: italic; }

/* Status badges */
.badge-attivo    { font-size: 11px; padding: 2px 8px; border-radius: 20px; background: var(--c-success-bg); color: var(--c-success); font-weight: 500; }
.badge-inattivo  { font-size: 11px; padding: 2px 8px; border-radius: 20px; background: var(--c-danger-bg);  color: var(--c-danger);  font-weight: 500; }
.badge-E         { font-size: 11px; padding: 2px 8px; border-radius: 20px; background: var(--c-primary-lt); color: var(--c-primary-dk); font-weight: 500; }
.badge-U         { font-size: 11px; padding: 2px 8px; border-radius: 20px; background: var(--c-warn-bg);    color: var(--c-warn-text);  font-weight: 500; }

/* ── Buttons ── */
.btn-add {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  padding: 7px 14px;
  background: var(--c-primary);
  color: #fff;
  border: none;
  border-radius: var(--c-radius);
  cursor: pointer;
  transition: background .15s;
}
.btn-add:hover { background: var(--c-primary-dk); }

.btn-sm {
  font-size: 12px;
  padding: 4px 10px;
  border: 0.5px solid var(--c-border-md);
  border-radius: var(--c-radius-sm);
  background: none;
  cursor: pointer;
  color: var(--c-text-muted);
  transition: background .12s, color .12s;
}
.btn-sm:hover { background: var(--c-bg-2); color: var(--c-text); }
.btn-sm.danger:hover { background: var(--c-danger-bg); color: var(--c-danger); border-color: var(--c-danger-bd); }

.btn-danger {
  font-size: 13px;
  padding: 7px 14px;
  background: var(--c-danger);
  color: #fff;
  border: none;
  border-radius: var(--c-radius);
  cursor: pointer;
  font-weight: 500;
}
.btn-danger:hover { opacity: .85; }

/* ── Alerts ── */
.alert-success, .alert-info {
  display: none;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  border-radius: var(--c-radius);
  padding: 9px 14px;
  margin-bottom: 1rem;
}
.alert-success { background: var(--c-success-bg); color: var(--c-success); border: 0.5px solid var(--c-success-bd); }
.alert-info    { background: var(--c-warn-bg);    color: var(--c-warn-text); border: 0.5px solid var(--c-warn-bd); display: flex; }
.alert-success.visible { display: flex; }

/* ── Search ── */
.search-box {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--c-bg);
  border: 0.5px solid var(--c-border-md);
  border-radius: var(--c-radius);
  padding: 0 10px;
  height: 34px;
}
.search-box .ti { font-size: 15px; color: var(--c-text-muted); flex-shrink: 0; }
.search-box input {
  border: none;
  background: none;
  font-size: 13px;
  color: var(--c-text);
  width: 160px;
  outline: none;
}
.search-box input::placeholder { color: var(--c-text-hint); }

/* ═══════════════════════════════════════════
   MODALI
═══════════════════════════════════════════ */
.modal-bg {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.40);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 1rem;
}
.modal-bg.open { display: flex; }

.modal {
  background: var(--c-bg);
  border: 0.5px solid var(--c-border);
  border-radius: var(--c-radius-lg);
  padding: 1.5rem;
  width: 100%;
  max-width: 460px;
  max-height: 90vh;
  overflow-y: auto;
  animation: modal-in .15s ease;
}
.modal.modal-sm { max-width: 360px; }
.modal.modal-lg { max-width: 680px; }

@keyframes modal-in {
  from { opacity: 0; transform: translateY(-8px) scale(.98); }
  to   { opacity: 1; transform: translateY(0)   scale(1);    }
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}
.modal-title { font-size: 16px; font-weight: 600; color: var(--c-text); }
.modal-close {
  background: none;
  border: none;
  color: var(--c-text-muted);
  font-size: 18px;
  cursor: pointer;
  padding: 2px;
  border-radius: var(--c-radius-sm);
}
.modal-close:hover { background: var(--c-bg-2); color: var(--c-text); }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.form-grid .full { grid-column: 1 / -1; }

.form-field { display: flex; flex-direction: column; gap: 4px; }
.form-field label {
  font-size: 12px;
  font-weight: 500;
  color: var(--c-text-muted);
}
.form-field input,
.form-field select {
  height: 36px;
  padding: 0 10px;
  border: 0.5px solid var(--c-border-md);
  border-radius: var(--c-radius);
  font-size: 13px;
  background: var(--c-bg);
  color: var(--c-text);
  transition: box-shadow .15s;
}
.form-field input:focus,
.form-field select:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(24,95,165,.18);
  border-color: var(--c-primary);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 1.25rem;
}
.btn-cancel {
  font-size: 13px;
  padding: 7px 16px;
  border: 0.5px solid var(--c-border-md);
  background: none;
  border-radius: var(--c-radius);
  cursor: pointer;
  color: var(--c-text-muted);
}
.btn-cancel:hover { background: var(--c-bg-2); }
.btn-save {
  font-size: 13px;
  padding: 7px 18px;
  background: var(--c-primary);
  color: #fff;
  border: none;
  border-radius: var(--c-radius);
  cursor: pointer;
  font-weight: 500;
}
.btn-save:hover { background: var(--c-primary-dk); }

/* ── Hidden admin elements ── */
.admin-only { display: none; }

/* Mostra gli elementi riservati SOLO quando l'utente è admin.
   La classe `is-admin` viene applicata al <body> da app.js (initApp).
   Ogni elemento riceve il suo display naturale: block / flex / inline-flex / table-cell. */
body.is-admin .nav-section.nav-admin-only { display: block; }
body.is-admin .nav-item.nav-admin-only    { display: flex; }
body.is-admin .btn-add.admin-only          { display: inline-flex; }
body.is-admin th.admin-only,
body.is-admin td.admin-only                 { display: table-cell; }

/* ═══════════════════════════════════════════
   RESPONSIVE
═══════════════════════════════════════════ */
@media (max-width: 768px) {
  .sidebar-toggle { display: flex; }

  .sidebar {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    bottom: 0;
    z-index: 100;
    transform: translateX(-100%);
    box-shadow: 2px 0 8px rgba(0,0,0,.1);
  }
  .sidebar.open {
    transform: translateX(0);
  }

  .user-pill span:not(.role-badge) { display: none; }
  .content { padding: 1rem; }
  .stats-row { grid-template-columns: 1fr 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .full { grid-column: 1; }
  .header-actions { width: 100%; }
  .search-box { flex: 1; }
  .search-box input { width: 100%; }
}

@media print {
  .topbar, .sidebar, .btn-add, .btn-sm, .btn-logout { display: none !important; }
  .content { padding: 0; }
  .table-wrap { border: none; }
}

/* ═══════════════════════════════════════════
   FILTRO SOCIETÀ — pill bar e chip
═══════════════════════════════════════════ */

.soc-filter-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.soc-pill {
  display: inline-flex;
  align-items: center;
  height: 28px;
  padding: 0 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  border: 0.5px solid var(--c-border-md);
  background: var(--c-bg);
  color: var(--c-text-muted);
  cursor: pointer;
  transition: background .12s, color .12s, border-color .12s;
}
.soc-pill:hover {
  background: var(--c-bg-2);
  color: var(--c-text);
}
.soc-pill.active {
  background: var(--c-text);
  color: var(--c-bg);
  border-color: var(--c-text);
}
/* Società specifiche usano CSS vars impostate inline da JS */
.soc-pill:not(.active)[style] {
  background: var(--pill-bg);
  color: var(--pill-color);
  border-color: var(--pill-border);
}
.soc-pill.active[style] {
  background: var(--pill-color);
  color: var(--pill-bg);
  border-color: var(--pill-color);
}

/* Chip inline nelle righe tabella */
.soc-chip {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  border: 0.5px solid;
  letter-spacing: .01em;
}

/* ── Page loader ── */
.page-loader {
  display: none;
  align-items: center;
  justify-content: center;
  padding: 3rem;
  color: var(--c-text-hint);
  font-size: 13px;
  gap: 8px;
}
.page-loader::before {
  content: '';
  width: 18px;
  height: 18px;
  border: 2px solid var(--c-border-md);
  border-top-color: var(--c-primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex-shrink: 0;
}

/* ═══════════════════════════════════════════
   GRIGLIA ORARI SETTIMANALI (maschera Periodo)
═══════════════════════════════════════════ */
.week-grid {
  display: flex;
  flex-direction: column;
  gap: 6px;
  border: 0.5px solid var(--c-border-md);
  border-radius: var(--c-radius);
  padding: 8px;
  background: var(--c-bg-2);
}
.week-day {
  display: grid;
  grid-template-columns: 96px 1fr;
  align-items: center;
  gap: 8px;
}
.week-day-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--c-text-muted);
}
.week-day select {
  height: 32px;
  padding: 0 8px;
  border: 0.5px solid var(--c-border-md);
  border-radius: var(--c-radius-sm);
  font-size: 12px;
  background: var(--c-bg);
  color: var(--c-text);
}
.week-day select:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(24,95,165,.18);
  border-color: var(--c-primary);
}

/* ═══════════════════════════════════════════════════════════════════
   TEMA "OROLOGIO DA STAZIONE"  (theme v2)
   Firma: orologio analogico live in topbar (quadrante bianco, lancette
   nere, secondi rossi a scatto). Chrome blu-notte strumentale.
   Blocco additivo: sovrascrive via cascata, non rimuove regole esistenti.
═══════════════════════════════════════════════════════════════════ */
:root {
  --topbar-h:      58px;
  --c-ink:         #14233A;   /* blu-notte chrome */
  --c-ink-2:       #1B2E4A;
  --c-on-ink:      #EAF0F8;
  --c-on-ink-mut:  #93A4BE;
  --c-accent:      #E2231A;   /* rosso "lancetta dei secondi" */
  --c-accent-dk:   #B81710;
  --c-face:        #FBFAF7;   /* quadrante */
  --dial-ring:     rgba(20,35,58,.05);
  --font-display:  'Space Grotesk', var(--font);
  --font-mono:     'IBM Plex Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root { --dial-ring: rgba(255,255,255,.035); }
}

/* numeri allineati (tabular) nelle tabelle dati */
td { font-variant-numeric: tabular-nums; }

/* ── Chrome: topbar blu-notte ── */
.topbar {
  background: linear-gradient(180deg, var(--c-ink-2), var(--c-ink));
  border-bottom: 1px solid rgba(0,0,0,.35);
  box-shadow: 0 1px 0 rgba(255,255,255,.04) inset, 0 2px 10px rgba(0,0,0,.18);
  gap: 14px;
}
.topbar .sidebar-toggle { color: var(--c-on-ink-mut); }
.topbar .sidebar-toggle:hover { background: rgba(255,255,255,.08); color: #fff; }

.brand {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -.01em;
  color: var(--c-on-ink);
}
.brand-dot {
  background: var(--c-accent);
  box-shadow: 0 0 0 0 rgba(226,35,26,.55);
  animation: pulse-dot 2.4s ease-out infinite;
}
@keyframes pulse-dot {
  0%   { box-shadow: 0 0 0 0 rgba(226,35,26,.5); }
  70%  { box-shadow: 0 0 0 7px rgba(226,35,26,0); }
  100% { box-shadow: 0 0 0 0 rgba(226,35,26,0); }
}

.topbar .user-pill { color: var(--c-on-ink-mut); }
.topbar .user-pill #topbar-user { color: var(--c-on-ink); }
.topbar .btn-logout {
  color: var(--c-on-ink-mut);
  border-color: rgba(255,255,255,.16);
  background: rgba(255,255,255,.03);
}
.topbar .btn-logout:hover { background: rgba(255,255,255,.10); color: #fff; }
.role-badge.admin        { background: rgba(124,176,255,.18); color: #BFD8FF; }
.role-badge.manutenzione { background: rgba(170,221,124,.16); color: #C7E6A3; }

/* ── Orologio analogico live ── */
.clock { display: flex; align-items: center; gap: 11px; }
.clock-analog {
  width: 38px; height: 38px; flex-shrink: 0;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,.4));
}
.clk-face   { fill: var(--c-face); stroke: rgba(0,0,0,.10); stroke-width: 1; }
.tick-maj   { stroke: var(--c-ink); stroke-width: 3;   stroke-linecap: round; }
.tick-min   { stroke: #9aa6b6;      stroke-width: 1.1; stroke-linecap: round; }
.clk-hand   { stroke: var(--c-ink); stroke-linecap: round; }
.clk-hour   { stroke-width: 4.4; }
.clk-min    { stroke-width: 2.8; }
.clk-sec     { stroke: var(--c-accent); stroke-width: 1.5; stroke-linecap: round; }
.clk-sec-tip { fill: var(--c-accent); }
.clk-pin     { fill: var(--c-ink); }
.clk-pin-r   { fill: var(--c-accent); }

.clock-readout { display: flex; flex-direction: column; line-height: 1.05; }
.clock-digital {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 16px;
  letter-spacing: .02em;
  color: var(--c-on-ink);
  font-variant-numeric: tabular-nums;
}
.clock-date {
  font-size: 10.5px;
  color: var(--c-on-ink-mut);
  text-transform: capitalize;
  letter-spacing: .02em;
  margin-top: 1px;
}

/* ── Sidebar blu-notte ── */
.sidebar {
  background: linear-gradient(180deg, var(--c-ink) 0%, #11203A 100%);
  border-right: 1px solid rgba(0,0,0,.3);
}
.sidebar .nav-section-label { color: rgba(255,255,255,.38); }
.sidebar .nav-item { color: var(--c-on-ink-mut); }
.sidebar .nav-item:hover { background: rgba(255,255,255,.07); color: #fff; }
.sidebar .nav-item.active {
  background: rgba(255,255,255,.08);
  color: #fff;
  font-weight: 600;
  position: relative;
}
/* tacca rossa "ora attiva" sull'elemento selezionato */
.sidebar .nav-item.active::before {
  content: '';
  position: absolute;
  left: -.75rem;
  top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 18px;
  border-radius: 0 3px 3px 0;
  background: var(--c-accent);
}
.sidebar .nav-item.active .ti { color: var(--c-accent); }

/* ── Titoli pagina con il display face ── */
.page-title {
  font-family: var(--font-display);
  letter-spacing: -.015em;
}

/* ── Login: quadrante di sfondo + logo a forma di orologio ── */
.login-wrap {
  background:
    repeating-radial-gradient(circle at 50% 38%,
      transparent 0 41px, var(--dial-ring) 41px 42px),
    var(--c-bg-3);
}
.login-card { box-shadow: 0 10px 40px rgba(20,35,58,.12); }
.logo-mark {
  background: radial-gradient(circle at 50% 42%, #ffffff 0 58%, #eef1f5 60%, #dfe4ea 100%);
  border: 2px solid var(--c-ink);
  color: var(--c-ink);
  box-shadow: inset 0 0 0 2px #fff, 0 2px 6px rgba(20,35,58,.18);
  position: relative;
}
.logo-mark .ti { color: var(--c-ink); }
.logo-mark::after {            /* puntino rosso centrale "perno" */
  content: '';
  position: absolute;
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--c-accent);
}
.logo-name { font-family: var(--font-display); font-weight: 600; letter-spacing: -.01em; }

/* accenti coordinati */
.btn-primary { background: var(--c-primary); }
.btn-primary:focus-visible,
.field input:focus { box-shadow: 0 0 0 3px rgba(24,95,165,.18); }

/* fuochi tastiera visibili */
.nav-item:focus-visible,
.btn-add:focus-visible,
.btn-sm:focus-visible,
.btn-logout:focus-visible {
  outline: 2px solid var(--c-accent);
  outline-offset: 1px;
}

/* ── Responsive ── */
@media (max-width: 768px) {
  .clock-readout { display: none; }
  .topbar { gap: 10px; }
}
@media (max-width: 480px) {
  .clock-analog { width: 32px; height: 32px; }
  .brand { font-size: 14px; }
}

@media print {
  .clock { display: none !important; }
}

@media (prefers-reduced-motion: reduce) {
  .brand-dot { animation: none; }
  .brand-dot { animation: none; } /* lancette: scatto istantaneo */
}

.nav-footer {
  margin-top: auto;
  padding: 12px 8px 4px;
  font-size: 11px;
  color: var(--c-text-hint);
  text-align: center;
  border-top: 0.5px solid var(--c-border);
}
.login-copy {
  margin-top: 10px;
  font-size: 11px;
  color: var(--c-text-hint);
  text-align: center;
}

/* ═══════════════════════════════════════════════════════
   UI v9 — Toast, dashboard charts, stat-card, mobile cards
   Blocco additivo: sovrascrive via cascata, non rimuove regole.
   ═══════════════════════════════════════════════════════ */

/* ── Toast notifications ── */
.toast-stack {
  position: fixed;
  top: calc(var(--topbar-h) + 12px);
  right: 16px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(360px, calc(100vw - 32px));
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 10px 12px;
  border-radius: var(--c-radius);
  background: var(--c-bg);
  border: 0.5px solid var(--c-border-md);
  box-shadow: 0 6px 24px rgba(20,35,58,.18);
  font-size: 13px;
  color: var(--c-text);
  opacity: 0;
  transform: translateX(12px);
  transition: opacity .2s ease, transform .2s ease;
}
.toast.in  { opacity: 1; transform: translateX(0); }
.toast.out { opacity: 0; transform: translateX(12px); }
.toast > .ti { font-size: 17px; flex-shrink: 0; margin-top: 1px; }
.toast-msg { flex: 1; white-space: pre-line; line-height: 1.4; }
.toast-x {
  background: none; border: none; cursor: pointer; padding: 0;
  color: var(--c-text-hint); font-size: 14px; line-height: 1; flex-shrink: 0;
}
.toast-x:hover { color: var(--c-text); }
.toast-success { border-left: 3px solid var(--c-success-bd); }
.toast-success > .ti { color: var(--c-success); }
.toast-error   { border-left: 3px solid var(--c-danger-bd); }
.toast-error   > .ti { color: var(--c-danger); }
.toast-warn    { border-left: 3px solid var(--c-warn-bd); }
.toast-warn    > .ti { color: var(--c-warn-text); }
.toast-info    { border-left: 3px solid var(--c-primary); }
.toast-info    > .ti { color: var(--c-primary); }
@media (max-width: 560px) {
  .toast-stack { top: auto; bottom: 14px; left: 16px; right: 16px; max-width: none; }
  .toast { transform: translateY(12px); }
  .toast.in { transform: translateY(0); }
  .toast.out { transform: translateY(12px); }
}
@media (prefers-reduced-motion: reduce) {
  .toast { transition: opacity .2s ease; transform: none !important; }
}

/* ── Stat-card con icona e accento ── */
.stat-card { display: flex; align-items: center; gap: 12px; }
.stat-card .stat-body { min-width: 0; }
.stat-ico {
  width: 40px; height: 40px; flex-shrink: 0;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
}
.stat-card.accent-blue   .stat-ico { background: var(--c-primary-lt); color: var(--c-primary); }
.stat-card.accent-green  .stat-ico { background: var(--c-success-bg); color: var(--c-success); }
.stat-card.accent-amber  .stat-ico { background: var(--c-warn-bg);    color: var(--c-warn-text); }
.stat-card.accent-violet .stat-ico { background: rgba(124,92,176,.16); color: #7C5CB0; }
@media (prefers-color-scheme: dark) {
  .stat-card.accent-violet .stat-ico { background: rgba(160,130,210,.16); color: #B79CE0; }
}
.stat-card .stat-val { font-family: var(--font-mono); }

/* ── Griglia grafici dashboard ── */
.dash-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 12px;
  margin-bottom: 1.5rem;
}
.chart-card {
  background: var(--c-bg);
  border: 0.5px solid var(--c-border);
  border-radius: var(--c-radius-lg);
  padding: 14px 16px;
}
.chart-card.hero-presenti { grid-column: span 2; display: flex; flex-direction: column; justify-content: center; }
.chart-card.chart-span    { grid-column: span 4; }
.chart-card.chart-wide    { grid-column: span 6; }
.chart-title {
  display: flex; align-items: center; gap: 7px;
  font-size: 12px; font-weight: 600; letter-spacing: .03em; text-transform: uppercase;
  color: var(--c-text-muted);
  margin-bottom: 10px;
}
.chart-title .ti { font-size: 15px; color: var(--c-primary); }
.hero-num {
  font-family: var(--font-display);
  font-size: 52px; font-weight: 700; line-height: 1;
  color: var(--c-text);
  font-variant-numeric: tabular-nums;
}
.hero-sub { font-size: 12px; color: var(--c-text-muted); margin-top: 6px; }
.chart-body { width: 100%; overflow-x: auto; }
.dash-svg { width: 100%; height: auto; display: block; }
.chart-empty {
  display: flex; align-items: center; justify-content: center;
  height: 120px; color: var(--c-text-hint); font-size: 13px; font-style: italic;
}
.chart-legend {
  display: flex; gap: 16px; margin-top: 8px;
  font-size: 12px; color: var(--c-text-muted);
}
.chart-legend span { display: inline-flex; align-items: center; gap: 5px; }
.chart-legend .dot { width: 9px; height: 9px; border-radius: 2px; display: inline-block; }
.chart-legend .dot-e { background: var(--c-primary); }
.chart-legend .dot-u { background: var(--c-warn-bd); }

/* Barre SVG (usano le CSS vars, dark-mode aware) */
.bar-e  { fill: var(--c-primary); }
.bar-u  { fill: var(--c-warn-bd); }
.bar-h  { fill: var(--c-primary); }
.dash-svg .ax-ln  { stroke: var(--c-border-md); stroke-width: 1; }
.dash-svg .ax-tx  { fill: var(--c-text-hint); font-size: 10px; font-family: var(--font-mono); }
.dash-svg .ax-tx2 { fill: var(--c-text-hint); font-size: 8.5px; font-family: var(--font-mono); }
.dash-svg .ax-val { fill: var(--c-text-muted); font-size: 10px; font-weight: 600; font-family: var(--font-mono); }

/* Skeleton shimmer */
.chart-skel {
  height: 168px; border-radius: var(--c-radius);
  background: linear-gradient(90deg, var(--c-bg-2) 25%, var(--c-bg-3) 37%, var(--c-bg-2) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
}
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }
@media (prefers-reduced-motion: reduce) { .chart-skel { animation: none; } }

@media (max-width: 900px) {
  .dash-grid { grid-template-columns: repeat(2, 1fr); }
  .chart-card.hero-presenti { grid-column: span 2; }
  .chart-card.chart-span,
  .chart-card.chart-wide { grid-column: span 2; }
}

/* ── Zebratura tabelle (hover resta prioritario) ── */
.table-wrap tbody tr:nth-child(even) td { background: var(--c-row-alt); }
.table-wrap tbody tr:hover td { background: var(--c-bg-2); }
:root { --c-row-alt: rgba(0,0,0,.022); }
@media (prefers-color-scheme: dark) { :root { --c-row-alt: rgba(255,255,255,.025); } }

/* ── Accento riga "straordinario" (causale ST) ── */
tr.row-str td:first-child { box-shadow: inset 3px 0 0 var(--c-warn-bd); }

/* ── Tabelle come card su mobile (label da <thead> via data-label) ── */
@media (max-width: 640px) {
  .table-wrap { overflow-x: visible; }
  .table-wrap table { white-space: normal; }
  .table-wrap thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .table-wrap tbody tr {
    display: block;
    border-bottom: 0.5px solid var(--c-border);
    padding: 4px 0;
  }
  .table-wrap tbody tr:nth-child(even) td { background: transparent; }
  .table-wrap tbody td {
    display: flex; justify-content: space-between; align-items: center; gap: 14px;
    border: none; padding: 7px 14px; text-align: right;
  }
  .table-wrap tbody td::before {
    content: attr(data-label);
    font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
    color: var(--c-text-hint); text-align: left; flex-shrink: 0;
  }
  .table-wrap tbody td.empty-row { justify-content: center; }
  .table-wrap tbody td.empty-row::before { display: none; }
}

/* ── Intestazione di stampa (solo in stampa) ── */
.print-head { display: none; }
@media print {
  .print-head {
    display: block;
    margin-bottom: 14px;
    padding-bottom: 8px;
    border-bottom: 1.5px solid #000;
  }
  .print-head .ph-title { font-size: 18px; font-weight: 700; }
  .print-head .ph-sub   { font-size: 12px; color: #333; margin-top: 2px; }
  .dash-grid, .toast-stack, .alert-info, .alert-success { display: none !important; }
  .table-wrap tbody tr:nth-child(even) td { background: transparent; }
}
/* ── Parametri di sistema (pagina impostazioni) ── */
.imp-table td { vertical-align: top; }
.imp-table th.imp-def, .imp-table td.imp-def { text-align: center; color: var(--c-text-muted); white-space: nowrap; }
.imp-name { font-weight: 600; }
.imp-hint { font-size: 12px; color: var(--c-text-hint); margin-top: 3px; max-width: 440px; line-height: 1.35; }
.imp-unit { font-size: 11px; color: var(--c-text-hint); }
.imp-na   { color: var(--c-text-hint); text-align: center; font-style: italic; }
.imp-inp  { width: 92px; padding: 6px 8px; text-align: right; border: 1px solid var(--c-border-md); border-radius: 8px; background: var(--c-bg); color: var(--c-text); font: inherit; -moz-appearance: textfield; }
.imp-inp::-webkit-outer-spin-button, .imp-inp::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.imp-inp:focus { outline: none; border-color: var(--c-primary); box-shadow: 0 0 0 3px var(--c-primary-lt); }
.u-id { color: var(--c-text-hint); font-size: 12px; }
