/* Gestionale dipendenti — stile applicazione (sopra Bootstrap 5) */
:root {
  --gd-paper: #f3f5f7;
  --gd-ink: #1b2633;
  --gd-muted: #5d6b7a;
  --gd-line: #dfe4ea;
  --gd-side: #22313f;
  --gd-side-ink: #c9d3dd;
  --gd-action: #2f6fa3;
  --gd-ok: #2e8b57;
  --gd-warn: #d9a200;
  --gd-bad: #c8372d;
  --gd-none: #c3cbd4;
  --bs-primary: var(--gd-action);
  --bs-primary-rgb: 47, 111, 163;
  --bs-body-color: var(--gd-ink);
  --bs-border-color: var(--gd-line);
  --bs-link-color-rgb: 47, 111, 163;
  --bs-font-sans-serif: 'Segoe UI', system-ui, -apple-system, 'Ubuntu', 'Helvetica Neue', Arial, sans-serif;
}

body { font-size: 0.925rem; background: var(--gd-paper); }
.form-check-input:checked { background-color: var(--gd-action); border-color: var(--gd-action); }
.form-control:focus, .form-select:focus, .form-check-input:focus { border-color: #7fa9cc; box-shadow: 0 0 0 .2rem rgba(47, 111, 163, .2); }
.btn-check:checked + .btn-outline-primary { background: var(--gd-action); border-color: var(--gd-action); }
.num, .table td.date, .date { font-variant-numeric: tabular-nums; }

.btn-primary { --bs-btn-bg: var(--gd-action); --bs-btn-border-color: var(--gd-action); --bs-btn-hover-bg: #275d8a; --bs-btn-hover-border-color: #275d8a; --bs-btn-active-bg: #214f75; }
.btn-outline-primary { --bs-btn-color: var(--gd-action); --bs-btn-border-color: var(--gd-action); --bs-btn-hover-bg: var(--gd-action); --bs-btn-hover-border-color: var(--gd-action); }
a { color: var(--gd-action); }

/* ─── Layout ─────────────────────────────────────────── */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; flex-shrink: 0; background: var(--gd-side); color: var(--gd-side-ink);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.sidebar .brand { padding: 1.1rem 1.25rem 1rem; color: #fff; font-weight: 600; font-size: 1.02rem; line-height: 1.25; border-bottom: 1px solid rgba(255,255,255,.08); }
.sidebar .brand small { display: block; font-weight: 400; color: var(--gd-side-ink); font-size: .78rem; margin-top: 2px; }
.sidebar nav { padding: .75rem .6rem; flex: 1; overflow-y: auto; }
.sidebar nav a {
  display: flex; align-items: center; gap: .7rem; padding: .5rem .75rem; border-radius: 6px;
  color: var(--gd-side-ink); text-decoration: none; margin-bottom: 2px;
}
.sidebar nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar nav a.active { background: rgba(255,255,255,.12); color: #fff; box-shadow: inset 3px 0 0 #7fb0da; }
.sidebar nav a .bi { font-size: 1.05rem; opacity: .9; }
.sidebar nav .sep { height: 1px; background: rgba(255,255,255,.08); margin: .6rem .5rem; }
.sidebar .user { padding: .8rem 1rem; border-top: 1px solid rgba(255,255,255,.08); font-size: .85rem; }
.sidebar .user .name { color: #fff; }
.sidebar .user button { color: var(--gd-side-ink); padding: 0; font-size: .82rem; }
.sidebar .user button:hover { color: #fff; }

main.content { flex: 1; min-width: 0; padding: 1.5rem 2rem 3rem; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: .75rem; margin-bottom: 1.25rem; }
.page-head h1 { font-size: 1.45rem; font-weight: 600; margin: 0; }
.page-head .sub { color: var(--gd-muted); margin-top: .15rem; }

.mobile-bar { display: none; }
@media (max-width: 991.98px) {
  .sidebar { position: fixed; left: -240px; z-index: 1045; transition: left .2s ease; }
  .sidebar.open { left: 0; box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); }
  .mobile-bar { display: flex; align-items: center; gap: .75rem; background: var(--gd-side); color: #fff; padding: .6rem 1rem; position: sticky; top: 0; z-index: 1040; }
  .mobile-bar button { color: #fff; font-size: 1.4rem; padding: 0; }
  main.content { padding: 1rem 1rem 3rem; }
  .app { flex-direction: column; }
}

/* ─── Pannelli ───────────────────────────────────────── */
.panel { background: #fff; border: 1px solid var(--gd-line); border-radius: 8px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .8rem 1rem; border-bottom: 1px solid var(--gd-line); }
.panel-head h2 { font-size: 1rem; font-weight: 600; margin: 0; }
.panel-body { padding: 1rem; }
.panel .table { margin: 0; }
.panel .table > :not(caption) > * > * { padding: .55rem .9rem; }
.table thead th { font-weight: 600; color: var(--gd-muted); font-size: .82rem; background: #f8f9fb; border-bottom-width: 1px; }
.table-hover tbody tr { cursor: default; }
tr.clickable { cursor: pointer; }

/* ─── Semaforo scadenze (elemento distintivo) ────────── */
.signal { display: inline-flex; gap: 3px; vertical-align: middle; }
.signal span { width: 22px; height: 8px; border-radius: 2px; background: var(--gd-none); }
.signal span.ok { background: var(--gd-ok); }
.signal span.in_scadenza { background: var(--gd-warn); }
.signal span.scaduto { background: var(--gd-bad); }
.signal-legend { display: flex; flex-wrap: wrap; gap: 1rem; font-size: .8rem; color: var(--gd-muted); }
.signal-legend i { display: inline-block; width: 14px; height: 8px; border-radius: 2px; margin-right: .35rem; vertical-align: middle; }

.state { display: inline-flex; align-items: center; gap: .4rem; font-weight: 500; white-space: nowrap; }
.state::before { content: ''; width: 9px; height: 9px; border-radius: 50%; background: var(--gd-none); flex-shrink: 0; }
.state.ok::before { background: var(--gd-ok); }
.state.in_scadenza::before { background: var(--gd-warn); }
.state.scaduto::before { background: var(--gd-bad); }
.state.scaduto { color: var(--gd-bad); }
.state.in_scadenza { color: #8a6700; }

tr.row-scaduto > td:first-child { box-shadow: inset 4px 0 0 var(--gd-bad); }
tr.row-in_scadenza > td:first-child { box-shadow: inset 4px 0 0 var(--gd-warn); }
tr.row-ok > td:first-child { box-shadow: inset 4px 0 0 var(--gd-ok); }

/* Contatori dashboard */
.counters { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 1px; background: var(--gd-line); border: 1px solid var(--gd-line); border-radius: 8px; overflow: hidden; margin-bottom: 1.5rem; }
.counter { background: #fff; padding: 1rem 1.2rem; text-decoration: none; color: inherit; display: block; }
a.counter:hover { background: #f8fafc; }
.counter .value { font-size: 1.9rem; font-weight: 600; line-height: 1.1; font-variant-numeric: tabular-nums; }
.counter .label { color: var(--gd-muted); font-size: .85rem; }
.counter.bad .value { color: var(--gd-bad); }
.counter.warn .value { color: #a77c00; }

/* ─── Scheda dipendente ──────────────────────────────── */
.emp-head { display: flex; flex-wrap: wrap; gap: 1rem; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.emp-head h1 { font-size: 1.6rem; font-weight: 600; margin: 0; }
.badge-stato { font-weight: 500; font-size: .78rem; padding: .3em .6em; border-radius: 4px; }
.badge-stato.attivo { background: #e3f1e8; color: #1f6b41; }
.badge-stato.cessato { background: #f6e1df; color: #9b2a22; }

.nav-tabs .nav-link { color: var(--gd-muted); }
.nav-tabs .nav-link.active { color: var(--gd-ink); font-weight: 500; }
.nav-tabs .nav-link .count { font-size: .75rem; color: var(--gd-muted); margin-left: .25rem; }

/* Campo copiabile */
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: .25rem 1.5rem; }
.field { padding: .55rem 0; border-bottom: 1px dashed var(--gd-line); min-width: 0; }
.field .k { font-size: .78rem; color: var(--gd-muted); }
.field .v { display: flex; align-items: center; gap: .4rem; min-height: 1.6rem; }
.field .v .text { user-select: all; overflow-wrap: anywhere; font-size: .98rem; }
.field .v .text.empty { color: var(--gd-none); user-select: none; }
.field .v .text.mono { font-family: ui-monospace, 'Cascadia Mono', Consolas, monospace; letter-spacing: .02em; }
.btn-copy { border: 0; background: none; color: var(--gd-muted); padding: 0 .25rem; line-height: 1; }
.btn-copy:hover { color: var(--gd-action); }
.btn-copy.done { color: var(--gd-ok); }

/* Allegati */
.att-list { list-style: none; margin: 0; padding: 0; }
.att-item { display: flex; align-items: center; gap: .75rem; padding: .5rem .25rem; border-bottom: 1px solid #eef1f4; }
.att-item:last-child { border-bottom: 0; }
.att-icon { font-size: 1.4rem; width: 1.6rem; text-align: center; }
.att-icon.pdf { color: #b8312f; }
.att-icon.img { color: #2f6fa3; }
.att-main { flex: 1; min-width: 0; }
.att-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-meta { font-size: .78rem; color: var(--gd-muted); }
.att-actions { display: flex; gap: .15rem; flex-shrink: 0; }
.att-actions .btn { padding: .2rem .45rem; }
.att-empty { color: var(--gd-muted); font-size: .85rem; padding: .4rem .25rem; }

.dropzone { border: 2px dashed var(--gd-line); border-radius: 8px; padding: 1.5rem; text-align: center; color: var(--gd-muted); cursor: pointer; }
.dropzone.over { border-color: var(--gd-action); background: #eef4fa; color: var(--gd-action); }

/* Sezioni record (formazione, documenti...) */
.record-block + .record-block { margin-top: 1rem; }
.course-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 1rem; }
.course { background: #fff; border: 1px solid var(--gd-line); border-radius: 8px; padding: .9rem 1rem; }
.course h3 { font-size: .98rem; font-weight: 600; margin: 0; }
.course .rule { font-size: .78rem; color: var(--gd-muted); }
.course .history { font-size: .8rem; color: var(--gd-muted); margin-top: .5rem; }

/* Anteprima pagine (copia immagini) */
.pages { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: .75rem; }
.page-thumb { border: 1px solid var(--gd-line); border-radius: 6px; background: #fff; padding: .4rem; text-align: center; }
.page-thumb img { max-width: 100%; max-height: 240px; display: block; margin: 0 auto .4rem; background: #f6f7f9; }
.page-thumb .btn { padding: .15rem .45rem; font-size: .8rem; }

/* Componi */
.compose-list { list-style: none; padding: 0; margin: 0; }
.compose-list li { display: flex; align-items: center; gap: .6rem; padding: .5rem .6rem; border: 1px solid var(--gd-line); border-radius: 6px; background: #fff; margin-bottom: .4rem; }
.compose-list li.dragging { opacity: .5; }
.compose-list li.drop-before { box-shadow: 0 -3px 0 var(--gd-action); }
.compose-list .handle { cursor: grab; color: var(--gd-muted); }
.compose-list .pos { width: 1.6rem; text-align: right; color: var(--gd-muted); font-variant-numeric: tabular-nums; }

/* Storico */
.diff { font-size: .8rem; margin: 0; }
.diff td { padding: .1rem .5rem .1rem 0; vertical-align: top; }
.diff .old { color: var(--gd-bad); text-decoration: line-through; }
.diff .new { color: var(--gd-ok); }

/* QR WhatsApp */
.qr-box { width: 290px; height: 290px; display: flex; align-items: center; justify-content: center; border: 1px solid var(--gd-line); border-radius: 8px; background: #fff; }

/* Toast */
.toast-container { z-index: 1090; }

/* Login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem; background: var(--gd-side); }
.login-card { width: 100%; max-width: 380px; background: #fff; border-radius: 10px; padding: 2rem; }
.login-card h1 { font-size: 1.3rem; font-weight: 600; }

.form-label { font-size: .85rem; margin-bottom: .2rem; color: var(--gd-muted); }
.invalid-feedback { display: block; }
:focus-visible { outline: 2px solid var(--gd-action); outline-offset: 2px; }

@media print {
  .sidebar, .mobile-bar, .no-print, .btn { display: none !important; }
  main.content { padding: 0; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ─── Calendario assenze e griglia presenze ──────────── */
.cal-wrap { overflow-x: auto; }
.cal { border-collapse: separate; border-spacing: 0; font-size: .8rem; min-width: 100%; }
.cal th, .cal td { border-bottom: 1px solid var(--gd-line); border-right: 1px solid #eef1f4; padding: 0; text-align: center; height: 34px; }
.cal thead th { position: sticky; top: 0; background: #f8f9fb; color: var(--gd-muted); font-weight: 500; line-height: 1.15; padding: .3rem 0; min-width: 34px; z-index: 1; }
.cal thead th.today { color: var(--gd-action); font-weight: 700; box-shadow: inset 0 -2px 0 var(--gd-action); }
.cal .name { position: sticky; left: 0; background: #fff; text-align: left; padding: 0 .75rem; min-width: 180px; white-space: nowrap; z-index: 2; border-right: 1px solid var(--gd-line); }
.cal thead .name { background: #f8f9fb; z-index: 3; }
.cal td.off, .cal th.off { background: #f1f3f6; }
.cal td.closure { background: repeating-linear-gradient(135deg, #fff, #fff 4px, #f1f3f6 4px, #f1f3f6 8px); }
.cal td.clickable { cursor: pointer; }
.cal td.clickable:hover { background: #eef4fa; }
.cal .chip { display: block; margin: 3px 2px; padding: 2px 0; border-radius: 3px; color: #fff; font-weight: 600; font-size: .7rem; cursor: pointer; line-height: 1.4; }
.cal .chip.partial { background-image: repeating-linear-gradient(135deg, rgba(255,255,255,.25) 0 3px, transparent 3px 6px); }
.cal .hours { font-variant-numeric: tabular-nums; font-size: .74rem; color: var(--gd-ink); }
.cal td.bad { background: #f8d7da; }
.cal td.bad .hours { color: #8a1c14; font-weight: 600; }
.cal td.live .hours { color: var(--gd-ok); font-weight: 600; }
.cal .tot { font-variant-numeric: tabular-nums; padding: 0 .6rem; white-space: nowrap; font-weight: 500; }
.legend { display: flex; flex-wrap: wrap; gap: .4rem 1rem; font-size: .8rem; color: var(--gd-muted); }
.legend span { display: inline-flex; align-items: center; gap: .35rem; }
.legend i { display: inline-block; min-width: 26px; padding: 0 3px; border-radius: 3px; color: #fff; font-style: normal; font-weight: 600; font-size: .7rem; text-align: center; }

.month-nav { display: inline-flex; align-items: center; gap: .5rem; }
.month-nav strong { min-width: 150px; text-align: center; font-size: 1.05rem; }

/* Timbrature */
.tap { display: inline-flex; align-items: center; gap: .25rem; padding: .1rem .45rem; border-radius: 4px; font-size: .8rem; font-variant-numeric: tabular-nums; margin: 0 .2rem .2rem 0; border: 1px solid var(--gd-line); background: #fff; }
.tap.entrata .bi { color: var(--gd-ok); }
.tap.uscita .bi { color: var(--gd-bad); }
.tap.manuale { border-style: dashed; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--gd-none); margin-right: .35rem; }
.dot.on { background: var(--gd-ok); box-shadow: 0 0 0 3px rgba(46,139,87,.18); }
.presence-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: .5rem; }
.presence-list .p { background: #fff; border: 1px solid var(--gd-line); border-left: 4px solid var(--gd-ok); border-radius: 6px; padding: .55rem .8rem; }
.presence-list .p.out { border-left-color: var(--gd-none); }
.token-box { font-family: ui-monospace, Consolas, monospace; background: #f6f8fa; border: 1px solid var(--gd-line); border-radius: 6px; padding: .6rem .8rem; word-break: break-all; user-select: all; }
pre.code { background: #1f2a37; color: #e6edf3; border-radius: 6px; padding: .8rem 1rem; font-size: .8rem; white-space: pre-wrap; }
.week-hours { display: grid; grid-template-columns: repeat(7, minmax(52px, 1fr)); gap: .4rem; }
.week-hours label { font-size: .75rem; color: var(--gd-muted); text-align: center; display: block; }
.week-hours input { text-align: center; }
.saldo-card { border: 1px solid var(--gd-line); border-radius: 8px; padding: .7rem .9rem; background: #fff; min-width: 170px; }
.saldo-card .v { font-size: 1.4rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.saldo-card .v.neg { color: var(--gd-bad); }
