/* ==========================================================================
   EasyShifts - foglio di stile unico
   Target: desktop e tablet (touch). Grafica sobria, alta leggibilita'.
   ========================================================================== */

:root {
    --bg:            #f1f5f9;
    --surface:       #ffffff;
    --surface-2:     #f8fafc;
    --border:        #e2e8f0;
    --border-strong: #cbd5e1;
    --text:          #0f172a;
    --text-muted:    #64748b;
    --text-soft:     #94a3b8;

    --primary:       #1d4ed8;
    --primary-dark:  #1e40af;
    --primary-soft:  #eff6ff;

    --green:         #16a34a;
    --green-soft:    #dcfce7;
    --yellow:        #ca8a04;
    --yellow-soft:   #fef9c3;
    --red:           #dc2626;
    --red-soft:      #fee2e2;

    --radius:        10px;
    --radius-sm:     6px;
    --shadow:        0 1px 2px rgba(15, 23, 42, .06), 0 4px 12px rgba(15, 23, 42, .05);
    --shadow-lg:     0 10px 40px rgba(15, 23, 42, .18);

    --header-h:      56px;
    --touch:         42px;
}

* { box-sizing: border-box; }

/* L'attributo hidden deve prevalere sui display espliciti definiti sotto
   (.btn e' inline-flex, .modal-backdrop e' flex): senza questa regola gli
   elementi nascosti resterebbero visibili come riquadri vuoti. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }

/* ---------- barra superiore ---------------------------------------------- */
.topbar {
    position: sticky; top: 0; z-index: 60;
    display: flex; align-items: center; gap: 6px;
    height: var(--header-h); padding: 0 14px;
    background: #0f172a; color: #e2e8f0;
}
.topbar .brand {
    font-weight: 700; font-size: 17px; color: #fff; letter-spacing: -.02em;
    margin-right: 14px; white-space: nowrap;
}
.topbar .brand span { color: #60a5fa; }
.topbar nav { display: flex; gap: 2px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.topbar nav::-webkit-scrollbar { display: none; }
.topbar nav a {
    display: flex; align-items: center; height: 36px; padding: 0 13px;
    border-radius: var(--radius-sm); color: #cbd5e1; font-size: 14px;
    font-weight: 500; white-space: nowrap; text-decoration: none;
}
.topbar nav a:hover { background: rgba(255,255,255,.08); color: #fff; text-decoration: none; }
.topbar nav a.active { background: var(--primary); color: #fff; }
.topbar .user { display: flex; align-items: center; gap: 10px; font-size: 13px; color: #94a3b8; }
.topbar .user form { margin: 0; }
.topbar .user button {
    height: 34px; padding: 0 12px; border: 1px solid rgba(255,255,255,.18);
    background: transparent; color: #e2e8f0; border-radius: var(--radius-sm);
    font-size: 13px; cursor: pointer;
}
.topbar .user button:hover { background: rgba(255,255,255,.1); }

/* ---------- struttura ----------------------------------------------------- */
.wrap { padding: 16px; max-width: 1800px; margin: 0 auto; }
.wrap.full { max-width: none; }

.page-head {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; flex-wrap: wrap; margin-bottom: 14px;
}
.page-head .sub { color: var(--text-muted); font-size: 13px; margin-top: 2px; }

.card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow);
}
.card + .card { margin-top: 14px; }
.card-head {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 12px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.card-body { padding: 16px; }

/* ---------- pulsanti ------------------------------------------------------ */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    min-height: var(--touch); padding: 0 16px;
    border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
    background: var(--surface); color: var(--text);
    font-size: 14px; font-weight: 550; font-family: inherit;
    cursor: pointer; white-space: nowrap; text-decoration: none;
    transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-danger { background: #fff; border-color: #fecaca; color: var(--red); }
.btn-danger:hover { background: var(--red-soft); }
.btn-lg { min-height: 48px; padding: 0 24px; font-size: 15px; font-weight: 650; }
.btn-sm { min-height: 34px; padding: 0 10px; font-size: 13px; }
.btn-icon { min-width: var(--touch); padding: 0 10px; }

/* ---------- form ---------------------------------------------------------- */
.field { margin-bottom: 14px; }
.field label, .lbl {
    display: block; font-size: 12.5px; font-weight: 600; color: var(--text-muted);
    text-transform: uppercase; letter-spacing: .03em; margin-bottom: 5px;
}
input[type=text], input[type=password], input[type=number], input[type=time],
input[type=date], input[type=search], select, textarea {
    width: 100%; min-height: var(--touch); padding: 8px 11px;
    border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
    background: #fff; color: var(--text); font: inherit; font-size: 14.5px;
}
input:focus, select:focus, textarea:focus {
    outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(29,78,216,.12);
}
input[type=color] { width: 52px; height: var(--touch); padding: 3px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: #fff; }
textarea { min-height: 76px; resize: vertical; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 140px; }
.hint { font-size: 12.5px; color: var(--text-muted); margin-top: 5px; }

.check {
    display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
    min-height: 38px; font-size: 14px; user-select: none;
}
.check input { width: 20px; height: 20px; accent-color: var(--primary); cursor: pointer; }

.days-picker { display: flex; flex-wrap: wrap; gap: 6px; }
.days-picker label {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 62px; min-height: var(--touch); padding: 0 10px; margin: 0;
    border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
    background: #fff; font-size: 13.5px; font-weight: 500; cursor: pointer;
    text-transform: none; letter-spacing: 0; color: var(--text);
}
.days-picker input { position: absolute; opacity: 0; pointer-events: none; }
.days-picker input:checked + span { }
.days-picker label:has(input:checked) {
    background: var(--primary-soft); border-color: var(--primary); color: var(--primary-dark); font-weight: 650;
}

/* ---------- tabelle ------------------------------------------------------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th, table.data td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); }
table.data th {
    position: sticky; top: 0; z-index: 2; background: var(--surface-2);
    font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted);
    white-space: nowrap;
}
table.data tbody tr:hover { background: var(--surface-2); }
table.data td.actions { text-align: right; white-space: nowrap; }
table.data tr.inactive td { opacity: .55; }

/* ---------- badge / pill -------------------------------------------------- */
.badge {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 3px 9px; border-radius: 999px;
    font-size: 12px; font-weight: 600; line-height: 1.5;
    background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border);
}
.badge.green  { background: var(--green-soft);  color: #166534; border-color: #bbf7d0; }
.badge.yellow { background: var(--yellow-soft); color: #854d0e; border-color: #fde68a; }
.badge.red    { background: var(--red-soft);    color: #991b1b; border-color: #fecaca; }
.badge.role { color: #fff; border: none; }
.badge.off  { background: #f1f5f9; color: var(--text-soft); }

/* giorni di riposo cliccabili nella lista del personale */
.dayoff-picker { display: inline-flex; gap: 3px; }
.dayoff-picker .dayoff {
    width: 24px; height: 24px; padding: 0; border-radius: 50%;
    border: 1px solid var(--border); background: var(--surface-2); color: var(--text-soft);
    font-size: 11.5px; font-weight: 700; line-height: 1; cursor: pointer;
    transition: background .12s, color .12s, border-color .12s;
}
.dayoff-picker .dayoff:hover { border-color: var(--primary); color: var(--primary); }
.dayoff-picker .dayoff.on { background: var(--primary); border-color: var(--primary); color: #fff; }
.dayoff-picker .dayoff:disabled { opacity: .5; cursor: wait; }

/* stato attivo/disabilitato cliccabile nella lista del personale */
.badge.active-toggle { cursor: pointer; font-family: inherit; }
.badge.active-toggle:hover { filter: brightness(.94); }
.badge.active-toggle:disabled { opacity: .5; cursor: wait; }
table.data tr.inactive td .active-toggle { opacity: 1; }

/* ---------- avvisi -------------------------------------------------------- */
.alert {
    display: flex; align-items: flex-start; gap: 10px;
    padding: 11px 14px; border-radius: var(--radius); font-size: 14px;
    border: 1px solid var(--border); background: var(--surface-2); margin-bottom: 14px;
}
.alert.success { background: var(--green-soft); border-color: #bbf7d0; color: #14532d; }
.alert.error   { background: var(--red-soft);   border-color: #fecaca; color: #7f1d1d; }
.alert.warn    { background: var(--yellow-soft);border-color: #fde68a; color: #713f12; }
.alert.info    { background: var(--primary-soft); border-color: #bfdbfe; color: #1e3a8a; }
/* il flash resta agganciato sotto l'header anche se la pagina è scorsa */
.alert.flash { position: sticky; top: calc(var(--header-h) + 8px); z-index: 50; box-shadow: var(--shadow-lg); }

.empty { padding: 40px 20px; text-align: center; color: var(--text-muted); }

/* ---------- toast --------------------------------------------------------- */
#toasts {
    position: fixed; right: 16px; bottom: 16px; z-index: 200;
    display: flex; flex-direction: column; gap: 8px; max-width: min(440px, calc(100vw - 32px));
}
.toast {
    padding: 12px 15px; border-radius: var(--radius); box-shadow: var(--shadow-lg);
    background: #0f172a; color: #f8fafc; font-size: 14px; line-height: 1.45;
    animation: toast-in .18s ease-out;
}
.toast.error   { background: #991b1b; }
.toast.success { background: #166534; }
.toast.warn    { background: #854d0e; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- modale / drawer ---------------------------------------------- */
.modal-backdrop {
    position: fixed; inset: 0; z-index: 150; background: rgba(15,23,42,.45);
    display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal {
    background: var(--surface); border-radius: var(--radius);
    box-shadow: var(--shadow-lg); width: min(640px, 100%);
    max-height: calc(100vh - 32px); display: flex; flex-direction: column;
}
.modal-head {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.modal-body { padding: 18px; overflow-y: auto; }
.modal-foot {
    display: flex; justify-content: flex-end; gap: 10px;
    padding: 13px 18px; border-top: 1px solid var(--border); background: var(--surface-2);
    border-radius: 0 0 var(--radius) var(--radius);
}
.modal-close {
    border: none; background: none; font-size: 26px; line-height: 1; cursor: pointer;
    color: var(--text-muted); width: 38px; height: 38px; border-radius: var(--radius-sm);
}
.modal-close:hover { background: var(--surface-2); }

/* ==========================================================================
   CALENDARIO
   ========================================================================== */
.toolbar {
    display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
    padding: 12px 14px; background: var(--surface);
    border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow); margin-bottom: 12px;
}
.week-nav { display: flex; align-items: center; gap: 6px; }
.week-nav .week-label {
    min-width: 220px; text-align: center; font-weight: 650; font-size: 15px;
    padding: 0 10px; line-height: 1.25;
}
.week-nav .week-label small { display: block; font-weight: 500; color: var(--text-muted); font-size: 12px; }
.toolbar .spacer { flex: 1; }

.stat-strip { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.stat {
    flex: 1; min-width: 118px; padding: 10px 13px; background: var(--surface);
    border: 1px solid var(--border); border-radius: var(--radius);
}
.stat .n { font-size: 21px; font-weight: 700; line-height: 1.15; }
.stat .l { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .03em; margin-top: 2px; }
.stat.ok .n   { color: var(--green); }
.stat.bad .n  { color: var(--red); }
.stat.warn .n { color: var(--yellow); }

/* --- griglia -------------------------------------------------------------- */
.cal-scroll {
    overflow: auto; -webkit-overflow-scrolling: touch;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow);
    max-height: calc(100vh - 250px);
}
table.cal { border-collapse: separate; border-spacing: 0; width: 100%; min-width: 1180px; }
table.cal th, table.cal td { border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); }

table.cal thead th {
    position: sticky; top: 0; z-index: 30;
    background: var(--surface-2); padding: 9px 10px; text-align: center;
    font-size: 13px; font-weight: 650; color: var(--text);
}
table.cal thead th .dnum { display: block; font-size: 11.5px; font-weight: 500; color: var(--text-muted); }
table.cal thead th.today { background: var(--primary-soft); color: var(--primary-dark); }
table.cal thead th.corner {
    left: 0; z-index: 40; width: 210px; min-width: 210px; text-align: left;
}

table.cal td.shiftcol, table.cal th.corner { position: sticky; left: 0; z-index: 20; background: var(--surface); }
table.cal td.shiftcol {
    width: 210px; min-width: 210px; padding: 9px 10px; vertical-align: top;
    border-right: 2px solid var(--border-strong);
}
.shift-name { font-weight: 700; font-size: 15px; display: flex; align-items: center; gap: 7px; }
.shift-dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.shift-meta { font-size: 12px; color: var(--text-muted); margin-top: 1px; }

/* barra proporzionale alla durata effettiva del turno */
.timeline { position: relative; height: 14px; margin-top: 6px; background: var(--surface-2);
    border: 1px solid var(--border); border-radius: 4px; overflow: hidden; }
.timeline .bar { position: absolute; top: 0; bottom: 0; border-radius: 3px; opacity: .92; }
.timeline .tick { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--border); }
.timeline-axis { position: relative; height: 13px; margin-top: 3px; font-size: 9.5px; color: var(--text-soft); }
.timeline-axis span { position: absolute; transform: translateX(-50%); white-space: nowrap; }

table.cal td.daycell {
    vertical-align: top; padding: 6px; min-width: 150px; background: var(--surface);
}
table.cal td.daycell.today { background: #fbfdff; }
table.cal td.daycell.drop-ok { background: var(--green-soft); box-shadow: inset 0 0 0 2px var(--green); }
table.cal td.daycell.drop-no { background: var(--red-soft); box-shadow: inset 0 0 0 2px var(--red); }
table.cal tbody tr:nth-child(even) td.daycell { background: #fcfdfe; }

.rolegroup { margin-bottom: 7px; }
.rolegroup:last-child { margin-bottom: 0; }
.rolegroup-head {
    display: flex; align-items: center; justify-content: space-between; gap: 6px;
    font-size: 11.5px; font-weight: 650; margin-bottom: 3px; padding: 1px 2px;
}
.rolegroup-head .rname { display: flex; align-items: center; gap: 5px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .02em; }
.rolegroup-head .rdot { width: 8px; height: 8px; border-radius: 2px; flex: none; }
.cov { font-weight: 700; font-size: 11.5px; padding: 1px 6px; border-radius: 999px; white-space: nowrap; }
.cov.ok    { background: var(--green-soft); color: #166534; }
.cov.short { background: var(--red-soft);   color: #991b1b; }
.cov.over  { background: var(--yellow-soft);color: #854d0e; }

.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip {
    display: inline-flex; align-items: center; gap: 5px;
    max-width: 100%; padding: 4px 8px; min-height: 30px;
    border-radius: 999px; border: 1px solid var(--border-strong);
    background: #fff; font-size: 13px; line-height: 1.2;
    cursor: grab; user-select: none; touch-action: none;
}
.chip:active { cursor: grabbing; }
.chip .cdot { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.chip .cname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 118px; }
.chip .cx {
    border: none; background: none; color: var(--text-soft); cursor: pointer;
    font-size: 15px; line-height: 1; padding: 0 1px; width: 18px; height: 22px; border-radius: 4px;
}
.chip .cx:hover { background: var(--red-soft); color: var(--red); }
.chip.dragging { opacity: .35; }
.chip.manual { border-style: dashed; }
/* persona assegnata a un ruolo diverso dal proprio (copertura cross-ruolo) */
.chip.cross .cname::after { content: '\21C4'; margin-left: 3px; font-size: 10px; color: var(--text-muted); }
.chip.inactive { background: #f8fafc; color: var(--text-soft); text-decoration: line-through; }
.chip .cload { font-size: 10.5px; font-weight: 700; padding: 0 4px; border-radius: 4px; }
.chip .cload.green  { background: var(--green-soft);  color: #166534; }
.chip .cload.yellow { background: var(--yellow-soft); color: #854d0e; }
.chip .cload.red    { background: var(--red-soft);    color: #991b1b; }

.slot-empty {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 30px; height: 30px; padding: 0 8px; border-radius: 999px;
    border: 1px dashed #fca5a5; background: #fff5f5; color: #b91c1c;
    font-size: 12px; font-weight: 600;
}
.add-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 30px; height: 30px; border-radius: 999px; border: 1px dashed var(--border-strong);
    background: #fff; color: var(--text-muted); font-size: 17px; cursor: pointer; line-height: 1;
}
.add-btn:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }

.drag-ghost {
    position: fixed; z-index: 300; pointer-events: none;
    box-shadow: var(--shadow-lg); opacity: .95; transform: translate(-50%, -50%);
}

/* --- pannello persone ----------------------------------------------------- */
.people-panel .filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.people-panel .filters input, .people-panel .filters select { min-width: 150px; flex: 1; }
.people-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 8px;
    max-height: 380px; overflow-y: auto;
}
.person {
    display: flex; align-items: center; gap: 9px; padding: 8px 10px;
    border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface);
}
.person .pmain { flex: 1; min-width: 0; }
.person .pname {
    font-weight: 600; font-size: 14px; cursor: pointer; color: var(--primary);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.person .pname:hover { text-decoration: underline; }
.person .pmeta { font-size: 11.5px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person .pload {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    min-width: 54px; padding: 4px 6px; border-radius: var(--radius-sm); text-align: center;
}
.person .pload b { font-size: 15px; line-height: 1.1; }
.person .pload i { font-style: normal; font-size: 10.5px; opacity: .85; }
.person .pload.green  { background: var(--green-soft);  color: #166534; }
.person .pload.yellow { background: var(--yellow-soft); color: #854d0e; }
.person .pload.red    { background: var(--red-soft);    color: #991b1b; }

.warn-list { max-height: 210px; overflow-y: auto; font-size: 13.5px; }
.warn-list div { padding: 5px 0; border-bottom: 1px solid var(--border); }
.warn-list div:last-child { border-bottom: none; }
.warn-list div.underload { color: var(--text-soft); }

/* --- selettore candidati -------------------------------------------------- */
.cand-list { max-height: 50vh; overflow-y: auto; }
.cand {
    display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
    padding: 9px 11px; border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: #fff; margin-bottom: 6px; cursor: pointer; font: inherit; min-height: var(--touch);
}
.cand:hover { border-color: var(--primary); background: var(--primary-soft); }
.cand.blocked { opacity: .62; cursor: not-allowed; background: var(--surface-2); }
.cand.blocked:hover { border-color: var(--border); background: var(--surface-2); }
.cand .cinfo { flex: 1; min-width: 0; }
.cand .cn, .cand .cr, .cand .cw { display: block; }
.cand .cn { font-weight: 600; }
.cand .cr { font-size: 12px; color: var(--text-muted); margin-top: 1px; }
.cand .cw { font-size: 11.5px; color: var(--red); margin-top: 3px; line-height: 1.35; }
.cand .cn { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.cand .crole {
    display: inline-block; padding: 1px 8px; border-radius: 999px;
    font-size: 11px; font-weight: 700; color: #fff; letter-spacing: .2px;
}
.cand-group {
    position: sticky; top: 0; z-index: 1; background: var(--surface);
    padding: 9px 2px 5px; font-size: 12px; font-weight: 700;
    color: var(--text-muted); text-transform: uppercase; letter-spacing: .4px;
}
.cand-group:first-child { padding-top: 2px; }

/* gruppo-ruolo bersaglio del drag & drop */
.rolegroup.drop-role { outline: 2px dashed var(--primary); outline-offset: 1px; border-radius: 6px; }

/* ==========================================================================
   FABBISOGNO - matrice
   ========================================================================== */
.matrix-wrap { overflow: auto; max-height: calc(100vh - 260px); -webkit-overflow-scrolling: touch; }
table.matrix { border-collapse: separate; border-spacing: 0; font-size: 14px; min-width: 900px; width: 100%; }
table.matrix th, table.matrix td { border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); padding: 0; }
table.matrix thead th {
    position: sticky; top: 0; z-index: 30; background: var(--surface-2);
    padding: 8px 10px; font-size: 12.5px; font-weight: 650; text-align: center; white-space: nowrap;
}
table.matrix thead th.corner { left: 0; z-index: 40; text-align: left; min-width: 190px; }
table.matrix td.rowhead, table.matrix th.corner {
    position: sticky; left: 0; z-index: 20; background: var(--surface);
    min-width: 190px; padding: 7px 10px; border-right: 2px solid var(--border-strong);
}
table.matrix td.rowhead .rh-shift { font-weight: 700; }
table.matrix td.rowhead .rh-role { font-size: 12.5px; color: var(--text-muted); display: flex; align-items: center; gap: 6px; }
table.matrix td.qty { text-align: center; }
table.matrix input.q {
    width: 100%; min-width: 62px; height: 40px; border: none; background: transparent;
    text-align: center; font-size: 15px; font-weight: 600; border-radius: 0; padding: 0;
}
table.matrix input.q:focus { background: var(--primary-soft); box-shadow: inset 0 0 0 2px var(--primary); }
table.matrix input.q.zero { color: var(--text-soft); font-weight: 400; }
table.matrix input.q.changed { background: #fffbeb; }
table.matrix tr.shift-start td { border-top: 2px solid var(--border-strong); }
table.matrix tfoot td { background: var(--surface-2); font-weight: 700; text-align: center; padding: 8px; }
table.matrix tfoot tr.role-total-row td { font-weight: 500; color: var(--text-muted); padding: 4px 8px; font-size: 12.5px; }
table.matrix tfoot tr.role-total-row td.rowhead { padding-left: 18px; }
table.matrix tfoot tr.hours-total-row td { border-top: 2px solid var(--border); }
.matrix-tools { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; }
.matrix-tools .field { margin-bottom: 0; }

/* ==========================================================================
   LOGIN
   ========================================================================== */
.login-page {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    padding: 20px; background: linear-gradient(160deg, #0f172a, #1e3a8a);
}
.login-card {
    width: min(400px, 100%); background: #fff; border-radius: 14px;
    box-shadow: var(--shadow-lg); padding: 30px 28px;
}
.login-card .logo { font-size: 26px; font-weight: 700; letter-spacing: -.03em; margin-bottom: 3px; }
.login-card .logo span { color: var(--primary); }
.login-card .tag { color: var(--text-muted); font-size: 13.5px; margin-bottom: 22px; }

/* ==========================================================================
   RESPONSIVE / TABLET
   ========================================================================== */
@media (max-width: 1024px) {
    .wrap { padding: 12px; }
    .cal-scroll { max-height: calc(100vh - 230px); }
    table.cal td.daycell { min-width: 168px; }
    /* su tablet la zona informativa sopra il calendario resta compatta */
    .stat { padding: 7px 10px; min-width: 92px; }
    .stat .n { font-size: 17px; }
    .stat .l { font-size: 10.5px; letter-spacing: 0; }
    .stat-strip, .toolbar { margin-bottom: 8px; }
    .warn-list { max-height: 130px; }
}

@media (max-width: 780px) {
    :root { --header-h: 52px; }
    .topbar .brand { margin-right: 8px; font-size: 16px; }
    .topbar .user .uname { display: none; }
    .week-nav .week-label { min-width: 150px; font-size: 14px; }
    .toolbar { gap: 8px; }
    .toolbar .btn { flex: 1; }
    .stat { min-width: 96px; }
    .stat .n { font-size: 18px; }
    .people-grid { grid-template-columns: 1fr 1fr; max-height: 300px; }
    table.cal td.shiftcol, table.cal th.corner { width: 150px; min-width: 150px; }
}

@media (max-width: 520px) {
    .people-grid { grid-template-columns: 1fr; }
    .row > * { min-width: 100%; }
}

@media print {
    .topbar, .toolbar, .people-panel, .btn, .add-btn, .chip .cx { display: none !important; }
    .cal-scroll { max-height: none; overflow: visible; border: none; box-shadow: none; }
    body { background: #fff; }
}

/* ---------- periodi di ferie / assenza ----------------------------------- */
.leave-row {
    display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
    padding: 8px; margin-bottom: 8px;
    border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2);
}
.leave-row input[type=date] { max-width: 165px; }
.leave-row select { max-width: 140px; }
.leave-row .lsep { color: var(--text-muted); font-size: 13px; }
.leave-row .lnotes { flex: 1; min-width: 130px; }
.leave-row .lremove {
    border: 1px solid #fecaca; background: #fff; color: var(--red);
    width: 38px; height: 38px; border-radius: var(--radius-sm); cursor: pointer; font-size: 17px; line-height: 1;
}
.leave-row .lremove:hover { background: var(--red-soft); }
.leave-empty { color: var(--text-muted); font-size: 13px; padding: 6px 2px; }

/* ---------- evidenziazione di una persona sulla settimana ---------------- */
.hl-banner {
    display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
    padding: 9px 14px; margin-bottom: 12px;
    background: #eef4ff; border: 1px solid #bfdbfe; border-left: 4px solid var(--primary);
    border-radius: var(--radius); font-size: 14px;
}
.hl-banner .hl-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.hl-banner .hl-meta { color: var(--text-muted); font-size: 13px; }
.hl-banner .hl-spacer { flex: 1; }

.chip.dim { opacity: .3; }
.chip.hl {
    border-color: var(--primary); border-width: 2px;
    background: #eef4ff; font-weight: 650;
    box-shadow: 0 0 0 3px rgba(29,78,216,.16);
}
.chip.hl .cname { color: var(--primary-dark); }
.person.dim { opacity: .38; }
.person.hl { border-color: var(--primary); background: #eef4ff; box-shadow: 0 0 0 2px rgba(29,78,216,.14); }

/* il nome resta chiaramente cliccabile */
.chip .cname { cursor: pointer; }
.chip .cname:hover { text-decoration: underline; }

/* ---------- scelta del metodo di assegnazione ---------------------------- */
.gen-choice { display: flex; flex-direction: column; gap: 10px; }
.gen-option {
    display: flex; gap: 11px; align-items: flex-start;
    padding: 13px 15px; border: 1px solid var(--border-strong);
    border-radius: var(--radius); background: #fff; cursor: pointer;
}
.gen-option:hover { border-color: var(--primary); background: var(--primary-soft); }
.gen-option:has(input:checked) {
    border-color: var(--primary); background: var(--primary-soft);
    box-shadow: 0 0 0 3px rgba(29,78,216,.12);
}
.gen-option > input { margin-top: 3px; width: 20px; height: 20px; accent-color: var(--primary); flex: none; }
.gen-option .go-body { display: block; }
.gen-option .go-title { display: block; font-weight: 650; font-size: 15px; }
.gen-option .go-desc { display: block; font-size: 13px; color: var(--text-muted); margin-top: 3px; line-height: 1.45; }
.gen-option .go-extra { display: block; margin-top: 9px; }
.gen-option:not(:has(input:checked)) .go-extra { display: none; }

.src-list { max-height: 230px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.src {
    display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
    padding: 9px 11px; border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: #fff; cursor: pointer; font: inherit; min-height: var(--touch);
}
.src:hover { border-color: var(--primary); }
.src.selected { border-color: var(--primary); background: #fff; box-shadow: inset 3px 0 0 var(--primary); }
.src .s-main { flex: 1; min-width: 0; }
.src .s-week, .src .s-meta { display: block; }
.src .s-week { font-weight: 600; }
.src .s-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* ---------- situazione ore lavorate -------------------------------------- */
table.data th.num, table.data td.num { text-align: right; white-space: nowrap; }
.delta { font-weight: 650; padding: 2px 7px; border-radius: 999px; font-size: 12.5px; }
.delta.ok   { background: var(--green-soft);  color: #166534; }
.delta.low  { background: var(--yellow-soft); color: #854d0e; }
.delta.high { background: var(--red-soft);    color: #991b1b; }
#hours-table td.name { font-weight: 600; }
#hours-table tbody tr.hl { background: var(--primary-soft); }

/* le due barre di copia del fabbisogno restano allineate su una griglia */
.matrix-tools > form.matrix-tools { flex-wrap: wrap; }
.matrix-tools .field select { min-width: 140px; }
