:root {
    /* Palette brand Puntosistemi (estratta dal logo aziendale) */
    --blu: #1860a8;        /* blu primario */
    --blu-scuro: #003060;  /* navy intestazioni */
    --azzurro: #00a8f0;    /* azzurro accento */
    --ciano: #60d8f0;      /* ciano chiaro */
    --grigio: #f4f7fb;
    --bordo: #dde5ef;
    --testo: #1f2a3a;
    --muted: #7b879a;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
    color: var(--testo);
    background: var(--grigio);
}

.app { display: flex; min-height: 100vh; }

.sidebar {
    width: 230px;
    background: var(--blu-scuro);
    color: #fff;
    flex-shrink: 0;
}

.nav { padding: 18px 12px; position: sticky; top: 0; }
.nav-brand { display: flex; justify-content: center; margin-bottom: 8px; }
.logo-box { background: #fff; border-radius: 10px; padding: 10px 12px; width: 100%;
    display: inline-flex; justify-content: center; box-shadow: 0 2px 8px rgba(0,0,0,.18); }
.nav-logo { width: 100%; max-width: 170px; height: auto; display: block; }
.logo-sub { font-size: 12px; opacity: .7; margin-bottom: 18px; text-transform: uppercase; text-align: center; letter-spacing: .5px; }
.nav-aiact { margin-top: 22px; padding-top: 14px; border-top: 1px solid rgba(255,255,255,.12);
    font-size: 11px; line-height: 1.45; color: #9fb2cd; }
.nav-aiact a { color: var(--azzurro); font-weight: 600; text-decoration: none; }
.nav-aiact a:hover { text-decoration: underline; }
.nav-item {
    display: block; color: #cdd8ea; text-decoration: none;
    padding: 10px 12px; border-radius: 8px; margin-bottom: 4px; font-size: 14px;
}
.nav-item:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-item.active { background: var(--blu); color: #fff; font-weight: 600; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
    height: 56px; background: #fff; border-bottom: 1px solid var(--bordo);
    display: flex; align-items: center; justify-content: space-between; padding: 0 20px;
}
.topbar .brand { font-size: 15px; }
.topbar .user { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.topbar .role { color: var(--muted); font-size: 12px; }
.logout-form { margin: 0; }

.content { padding: 22px; }

h1 { font-size: 22px; margin: 0 0 16px; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }

.btn {
    background: var(--blu); color: #fff; border: none; padding: 9px 16px;
    border-radius: 8px; cursor: pointer; font-size: 14px;
}
.btn:hover { background: var(--blu-scuro); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-link { background: none; border: none; color: var(--blu); cursor: pointer; font-size: 14px; text-decoration: none; }

table.grid { width: 100%; border-collapse: collapse; background: #fff; border-radius: 10px; overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.grid th, .grid td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--bordo); font-size: 13.5px; }
.grid th { background: #f7f9fc; color: #586273; font-weight: 600; text-transform: uppercase; font-size: 11px; letter-spacing: .3px; }
.grid tr:last-child td { border-bottom: none; }
.grid .num { text-align: right; white-space: nowrap; }

.badge { background: #eef2f8; color: #44506a; padding: 2px 8px; border-radius: 20px; font-size: 12px; }
.muted { color: var(--muted); font-size: 13px; }

.form-card { background: #fff; border-radius: 10px; padding: 20px; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 20px; }
.field { display: flex; flex-direction: column; }
.field.wide { grid-column: span 2; }
.field label { font-size: 12px; color: #586273; margin-bottom: 4px; font-weight: 600; }
.field input, .field select {
    padding: 8px 10px; border: 1px solid var(--bordo); border-radius: 7px; font-size: 14px; background: #fff;
}
.field input[readonly] { background: #f4f6f9; color: #586273; }
.form-actions { margin-top: 18px; display: flex; gap: 12px; align-items: center; }

.autocomplete { position: relative; margin-top: 6px; }
.autocomplete input { width: 100%; }
.suggestions { list-style: none; margin: 2px 0 0; padding: 0; border: 1px solid var(--bordo); border-radius: 7px; background: #fff; position: absolute; z-index: 10; width: 100%; max-height: 220px; overflow-y: auto; box-shadow: 0 4px 12px rgba(0,0,0,.1); }
.suggestions li { padding: 8px 10px; cursor: pointer; font-size: 13px; border-bottom: 1px solid #f0f2f6; }
.suggestions li:hover { background: #eef4ff; }
.hint { font-size: 12px; color: var(--muted); padding: 4px 2px; }
.maps-link { margin-left: 8px; color: var(--blu); font-weight: 600; text-decoration: none; white-space: nowrap; }
.maps-link:hover { text-decoration: underline; }

.alert { background: #fdecea; color: #b71c1c; padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 14px; }
.ok-alert { background: #e6f4ea; color: #1b5e20; }   /* conferma verde (es. "salvato") */

/* Campo con pulsante "Crea nuovo" a fianco */
.input-row { display: flex; gap: 8px; align-items: stretch; }
.input-row select { flex: 1; min-width: 0; }

/* Select ricercabile (type-ahead): nasconde il <select>, l'input guida la scelta */
.ss-select { display: none; }
.input-row .ss-combo { flex: 1; min-width: 0; margin-top: 0; }
.suggestions.ss-list { max-height: 260px; overflow-y: auto; }
.suggestions li.ss-empty { cursor: default; color: var(--muted); }
.suggestions li.ss-empty:hover { background: none; }
.suggestions li.ss-active { background: #dbe9ff; }

/* Ordine fatturato: campi disabilitati visivamente (#4) */
.form-fields { border: 0; margin: 0; padding: 0; min-width: 0; }
.form-fields:disabled input, .form-fields:disabled select, .form-fields:disabled textarea {
    background: #eef1f6; color: #8a94a6; cursor: not-allowed; }
.form-fields:disabled .btn, .form-fields:disabled .btn-add { opacity: .5; cursor: not-allowed; }

/* Validazione senza reload: campi obbligatori mancanti (#3) */
.input-invalid { border-color: #d92d20 !important; box-shadow: 0 0 0 2px rgba(217,45,32,.15) !important; }
/* Con JS attivo la validazione client sostituisce l'avviso server "campi mancanti" (evita doppioni). */
.has-js .srv-fallback { display: none; }
.btn-add { white-space: nowrap; background: #eef4ff; color: var(--blu); border: 1px solid #cdddf6;
    border-radius: 7px; padding: 0 12px; font-size: 13px; font-weight: 600; cursor: pointer; }
.btn-add:hover { background: #dfeaff; }
.btn-add:disabled { opacity: .6; cursor: default; }

/* Righe addebiti extra (scheda ordine) */
.addebiti-extra { margin-top: 16px; }
.add-row { display: flex; gap: 8px; margin-bottom: 6px; align-items: center; }
.add-row input { padding: 8px 10px; border: 1px solid var(--bordo); border-radius: 7px; font-size: 14px; background: #fff; }
.add-row input[name="addDesc"] { flex: 1; min-width: 0; }
.add-row input[name="addImp"] { width: 120px; }
.add-del { color: #b71c1c; background: #fdecea; border-color: #f0c4c0; }
.add-del:hover { background: #f9d7d3; }
.lookup-status { display: block; margin-top: 5px; font-size: 12px; min-height: 15px; }
.lookup-status.loading { color: var(--blu); }
.lookup-status.ok { color: #2e7d32; }
.lookup-status.warn { color: #b71c1c; }

/* Modale "Crea nuovo" */
.modal-overlay { position: fixed; inset: 0; background: rgba(8,16,32,.5); z-index: 200;
    display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 480px; max-height: 90vh;
    display: flex; flex-direction: column; box-shadow: 0 18px 50px rgba(0,0,0,.35); overflow: hidden; }
.modal-head { display: flex; align-items: center; justify-content: space-between;
    padding: 14px 18px; background: var(--blu-scuro); color: #fff; font-weight: 700; font-size: 15px; }
.modal-x { background: none; border: none; color: #fff; font-size: 16px; cursor: pointer; line-height: 1; opacity: .85; }
.modal-x:hover { opacity: 1; }
.modal-body { padding: 16px 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.modal-body .field input { width: 100%; }
.modal-err { padding: 0 18px 6px; color: #b71c1c; font-size: 13px; }
.modal-foot { padding: 14px 18px; border-top: 1px solid var(--bordo); display: flex; gap: 12px; align-items: center; }
.modal-head h3 { margin: 0; font-size: 15px; font-weight: 700; }
.modal-lg { max-width: 720px; }

/* Modali Anagrafiche: nascosti finché non aperti */
.anag-modal { display: none; }
.anag-modal.open { display: flex; }
.anag-modal .modal-body .form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.anag-modal .modal-body .form-grid .field.wide { grid-column: 1 / -1; }
.anag-modal .modal-body .form-actions { display: flex; gap: 12px; align-items: center; margin-top: 4px; }
.list-head { display: flex; justify-content: flex-end; margin-bottom: 12px; }

/* ===== Planning › Elenco: barra filtri ===== */
.plan-filters { padding: 12px 16px; margin-bottom: 12px; }
.plan-filters-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.plan-filters .field { display: flex; flex-direction: column; gap: 4px; min-width: 150px; }
.plan-filters .field label { font-size: 12px; color: #586273; font-weight: 600; }
.plan-filters .field.wide { flex: 1; min-width: 220px; }
.plan-filters .field.actions { flex-direction: row; align-items: center; gap: 10px; min-width: 0; }
/* Interruttore "Mostra completati" nella testata del planning */
.comp-toggle { margin-left: auto; font-size: 13px; }

/* ===== Storico clienti ===== */
.storico-card { padding: 16px 18px; }
.storico-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.storico-info { display: flex; gap: 22px; flex-wrap: wrap; margin-top: 12px; font-size: 13.5px; }
.storico-stats { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 14px; }
.storico-stats .stat { background: #eef4ff; border: 1px solid #cdddf6; border-radius: 10px; padding: 10px 14px; min-width: 130px; }
.storico-stats .stat-n { font-size: 20px; font-weight: 800; color: var(--blu-scuro); line-height: 1.1; }
.storico-stats .stat-l { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
@media (max-width: 640px) { .anag-modal .modal-body .form-grid { grid-template-columns: 1fr; } }

.tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.tab { background: #fff; border: 1px solid var(--bordo); padding: 8px 14px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.tab.active { background: var(--blu); color: #fff; border-color: var(--blu); }

.inline-add { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.inline-add input { padding: 8px 10px; border: 1px solid var(--bordo); border-radius: 7px; font-size: 14px; }
.inline-add input.small { width: 70px; }
.wide-input { flex: 1; min-width: 280px; }

.hits { list-style: none; padding: 0; margin: 14px 0 0; }
.hits li { background: #fff; border: 1px solid var(--bordo); border-radius: 8px; padding: 12px 14px; margin-bottom: 10px; }
.hit-score { font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.hit-text { font-size: 14px; line-height: 1.5; }

/* Login */
.login-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, var(--blu-scuro), var(--blu)); }
.login-card { background: #fff; padding: 32px; border-radius: 14px; width: 340px; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.login-logo { font-size: 24px; font-weight: 700; color: var(--blu); }
.login-tenant { font-size: 13px; color: var(--muted); margin-bottom: 20px; }
.login-card form { display: flex; flex-direction: column; }
.login-card label { font-size: 12px; color: #586273; margin: 10px 0 4px; font-weight: 600; }
.login-card input { padding: 9px 11px; border: 1px solid var(--bordo); border-radius: 7px; font-size: 14px; }
.login-btn { margin-top: 18px; width: 100%; padding: 11px; }
.login-hint { margin-top: 16px; text-align: center; }

h2.sub { font-size: 15px; color: #586273; margin: 4px 0 12px; font-weight: 600; }
.small { font-size: 12px; }

/* Azioni CRUD nelle tabelle */
/* Colonna azioni: NIENTE display:flex sul <td> (romperebbe il layout tabella e farebbe
   sovrapporre le icone alla colonna Stato). Elementi inline-block, allineati a destra. */
.grid th.actions, .grid td.actions { width: 1%; white-space: nowrap; text-align: right; vertical-align: middle; }
.grid td.actions .icon-btn { display: inline-block; vertical-align: middle; }
.grid td.actions form { margin: 0; display: inline-block; vertical-align: middle; }
.grid td.actions > * { margin-left: 4px; }
.grid td.actions > *:first-child { margin-left: 0; }
.icon-btn { background: #eef2f8; border: 1px solid var(--bordo); border-radius: 6px; padding: 3px 7px; cursor: pointer; font-size: 13px; text-decoration: none; line-height: 1.4; }
.icon-btn:hover { background: #e1e8f4; }
.btn-danger { background: #fff; color: #b71c1c; border: 1px solid #f0c4c0; padding: 8px 14px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.btn-danger:hover { background: #fdecea; }
.delete-row { margin-top: 12px; }

/* Fatturazione — righe fatture emesse compatte */
.fatt-docs { display: flex; gap: 16px; flex-wrap: wrap; align-items: center; }
.doc-group { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .3px; }
.doc-group b { font-weight: 700; }
.mini-btn { display: inline-block; background: #eef4ff; color: var(--blu); border: 1px solid #cdddf6; border-radius: 6px;
    padding: 3px 9px; font-size: 12px; font-weight: 600; text-decoration: none; cursor: pointer; line-height: 1.5; }
.mini-btn:hover { background: #dfeaff; }
.mini-btn.danger { background: #fdecea; color: #b71c1c; border-color: #f0c4c0; }
.mini-btn.danger:hover { background: #f9d7d3; }
.fatt-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.fatt-actions form { margin: 0; }
.invia-form { display: flex; gap: 4px; align-items: center; margin: 0; }
.invia-form input { padding: 5px 8px; border: 1px solid var(--bordo); border-radius: 6px; font-size: 13px; width: 160px; }

/* Fatturazione — schede "da fatturare" con viaggi selezionabili */
.dafatt-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.warn-badge { color: #b45309; font-size: 12px; font-weight: 600; white-space: nowrap; }
.grid tr.riga-avviso td { background: #fff8e1; }

/* Cambio stato rapido nell'elenco ordini */
.stato-quick { padding: 4px 6px; border: 1px solid var(--bordo); border-radius: 6px; font-size: 12.5px; background: #fff; }
.stato-quick:disabled { background: #f4f6f9; color: #586273; cursor: not-allowed; }
.stato-quick.stato-saved { border-color: #2e7d32; box-shadow: 0 0 0 2px rgba(46,125,50,.2); }

/* Tabelle ordinabili + filtro per colonna */
table.sortable thead tr:first-child th:not([data-nosort]) { cursor: pointer; user-select: none; white-space: nowrap; }
table.sortable thead tr:first-child th:not([data-nosort]):hover { background: #eef2f8; }
.sort-ind { color: var(--blu); font-size: 11px; }
.col-filters th { padding: 4px 6px; background: #fbfcfe; border-bottom: 1px solid var(--bordo); }
.col-filters input, .col-filters select { width: 100%; min-width: 40px; padding: 4px 6px; border: 1px solid var(--bordo); border-radius: 5px; font-size: 12px; font-weight: 400; text-transform: none; letter-spacing: 0; }

/* Ricerca globale + riga filtri di colonna a scomparsa */
.table-toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.table-search { flex: 1; min-width: 220px; max-width: 440px; padding: 8px 12px; border: 1px solid var(--bordo); border-radius: 8px; font-size: 14px; }
table.sortable .col-filters { display: none; }
table.sortable.filters-open .col-filters { display: table-row; }
[data-table-filters-toggle].active { background: #dfeaff; }

/* Storico ordini: sezioni per mese comprimibili (<details>/<summary>) */
.storord-group { background: #fff; border: 1px solid var(--bordo); border-radius: 10px; margin-bottom: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,.06); overflow: hidden; }
.storord-group summary { list-style: none; cursor: pointer; padding: 13px 16px; font-weight: 600; font-size: 14px;
    display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.storord-group summary::-webkit-details-marker { display: none; }
.storord-group summary::before { content: '▸'; color: var(--muted); font-weight: 400; transition: transform .15s; }
.storord-group[open] summary::before { transform: rotate(90deg); }
.storord-group summary:hover { background: #f7f9fc; }
.storord-group[open] summary { border-bottom: 1px solid var(--bordo); }
.storord-body { padding: 14px 16px; }

/* Calendario settimanale */
.cal-nav { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.cal-range { font-weight: 600; color: var(--testo); }
.cal-arrow { background: #fff; border: 1px solid var(--bordo); border-radius: 8px; padding: 8px 14px; text-decoration: none; color: var(--blu); font-size: 14px; }
.cal-arrow:hover { background: #eef4ff; }

.cal-wrap { display: flex; gap: 12px; align-items: flex-start; }
.cal-unassigned { width: 210px; flex-shrink: 0; background: #fff; border: 1px solid var(--bordo); border-radius: 10px; padding: 10px; min-height: 120px;
    position: sticky; top: 0; align-self: flex-start; max-height: 85vh; overflow-y: auto; }
.cal-unassigned h3 { margin: 0 0 6px; font-size: 14px; }
/* Colonne RESTRINGIBILI (minmax(0,1fr) + min-width:0): la griglia entra sempre nel suo spazio e non
   può mai "sbordare" sotto i pannelli laterali (causa della sovrapposizione vista dal cliente). */
.cal-grid { flex: 1; display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; min-width: 0; }

/* Pannello destro: elenco mezzi trascinabili sulle card */
.cal-mezzi { width: 180px; flex-shrink: 0; background: #fff; border: 1px solid var(--bordo); border-radius: 10px; padding: 10px; align-self: flex-start; max-height: 85vh; overflow-y: auto;
    position: sticky; top: 0; }
.cal-mezzi h3 { margin: 0 0 6px; font-size: 14px; }
.mezzo-chip { display: flex; flex-direction: column; gap: 1px; background: #eef4ff; border: 1px solid #cdddf6; border-left: 3px solid #1860a8; border-radius: 7px; padding: 6px 8px; margin-bottom: 6px; cursor: grab; font-size: 12px; }
.mezzo-chip:active { cursor: grabbing; }
.mezzo-chip.dragging { opacity: .45; }
.mezzo-targa { font-weight: 800; color: var(--blu-scuro); letter-spacing: .3px; }
.mezzo-autista { color: #586273; }
.cal-col { background: #fff; border: 1px solid var(--bordo); border-radius: 10px; display: flex; flex-direction: column; min-height: 220px; min-width: 0; }
.cal-col.today { border-color: var(--blu); box-shadow: 0 0 0 2px rgba(13,71,161,.12); }
/* Intestazione giorno: resta fissa in alto (sticky) mentre si scorre la pagina, ed è
   cliccabile per aprire la vista Giorno. */
.cal-colhead { position: sticky; top: 0; z-index: 3; background: #fff; padding: 8px 10px;
    border-bottom: 1px solid var(--bordo); border-radius: 10px 10px 0 0; text-decoration: none;
    font-size: 12px; font-weight: 600; color: #586273; display: flex; justify-content: space-between; }
a.cal-colhead:hover { background: #eef4ff; color: var(--blu); }
.cal-colhead span { color: var(--muted); font-weight: 400; }
/* Colonne a piena altezza: crescono con i viaggi, si scorre la PAGINA (niente scroll annidato). */
.cal-drop { padding: 8px; display: flex; flex-direction: column; gap: 7px; flex: 1; }
/* Nelle colonne il dettaglio si apre col click sulla card (vedi app.js); il tooltip resta nei pannelli. */
.cal-drop .trip-tip, .day-grid .trip-tip { display: none; }
.cal-col .trip-card, .day-grid .trip-card { cursor: pointer; }

/* Vista Giorno: card in griglia fluida a tutta larghezza (tutti i viaggi visibili). */
.day-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; align-items: start; }

.trip-card { position: relative; background: #eef4ff; border: 1px solid #cdddf6; border-left: 3px solid var(--blu); border-radius: 6px; padding: 4px 7px; font-size: 11.5px; line-height: 1.25; cursor: grab; }
.trip-card:active { cursor: grabbing; }
.trip-card.dragging { opacity: .45; }
/* Numero+ora sulla stessa riga del badge; cliente e tratta troncati su una riga */
.trip-num { font-weight: 700; color: var(--blu-scuro); font-size: 11px; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.trip-card { overflow: hidden; min-width: 0; }   /* la card si restringe con la colonna, il testo si tronca */
.trip-cli { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.trip-tratta { color: #586273; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Badge esecutore: colore di fondo uniforme per tipologia */
.trip-head { display: flex; align-items: center; gap: 5px; margin-bottom: 2px; min-width: 0; }
.trip-badge { font-weight: 800; font-size: 10.5px; letter-spacing: .3px; line-height: 1;
    padding: 2px 6px; border-radius: 5px; color: #fff; text-transform: uppercase; white-space: nowrap; }
.trip-badge.mezzo { background: #1860a8; }     /* mezzi propri */
.trip-badge.vettore { background: #e06f00; }   /* vettori esterni */
.trip-badge.nd { background: #8a94a6; }        /* esecutore non assegnato */
.trip-warn { margin-left: auto; color: #d92d20; font-size: 14px; line-height: 1; }
.tip-warn { color: #ffb4b4; font-weight: 600; }

.trip-card.conflict { border-color: #f0a3a3; border-left-color: #d92d20;
    background: #fff5f5; box-shadow: 0 0 0 1px rgba(217,45,32,.15); }

/* Card spostata in un'altra settimana: lampeggia per attirare l'attenzione */
@keyframes tripblink {
    0%, 100% { background: #eef4ff; box-shadow: 0 0 0 0 rgba(0,168,240,0); }
    50%      { background: #cfe8ff; box-shadow: 0 0 0 3px rgba(0,168,240,.9); }
}
.trip-card.trip-hl { animation: tripblink 1s ease-in-out infinite; border-color: var(--azzurro); }

/* Legenda calendario */
.cal-legend { display: flex; gap: 18px; flex-wrap: wrap; align-items: center;
    font-size: 12px; color: var(--muted); margin: 4px 0 12px; }
.cal-legend .lg { display: inline-block; width: 12px; height: 12px; border-radius: 3px;
    vertical-align: middle; margin-right: 5px; }
.cal-legend .lg.mezzo { background: #1860a8; }
.cal-legend .lg.vettore { background: #e06f00; }
.cal-legend .lg.warn { width: auto; height: auto; background: none; color: #d92d20; font-style: normal; }

.trip-tip { display: none; position: absolute; left: 100%; top: 0; margin-left: 8px; width: 240px; background: #1f2430; color: #fff; padding: 9px 11px; border-radius: 8px; font-size: 12px; line-height: 1.55; z-index: 50; box-shadow: 0 6px 20px rgba(0,0,0,.3); }
.trip-card:hover .trip-tip { display: block; }
.cal-unassigned .trip-tip { left: auto; right: 100%; margin-left: 0; margin-right: 8px; }

.drop-hi { outline: 2px dashed var(--blu); outline-offset: -2px; background: #f3f8ff; }
.cal-arrow.drop-hi { background: #dbe9ff; }

/* Contenitore delle card nei pannelli laterali: verticale su desktop */
.panel-items { display: flex; flex-direction: column; gap: 6px; }

/* ===== Pannelli laterali collassabili (Non assegnati / Mezzi) ===== */
.cal-panel { position: relative; }
.cal-panel h3 { padding-right: 30px; }   /* spazio per il pulsante di collasso */
.panel-toggle { position: absolute; top: 8px; right: 8px; width: 24px; height: 24px; padding: 0;
    border: 1px solid var(--bordo); border-radius: 6px; background: #fff; color: #586273;
    cursor: pointer; font-size: 15px; line-height: 1; }
.panel-toggle:hover { background: #eef4ff; color: var(--blu); }
.panel-vlabel { display: none; }
/* Collassato: linguetta sottile con etichetta verticale; la griglia guadagna lo spazio */
.cal-panel.collapsed { width: 34px; min-width: 34px; padding: 40px 4px 10px; overflow: hidden; }
.cal-panel.collapsed h3, .cal-panel.collapsed p, .cal-panel.collapsed .panel-items { display: none; }
.cal-panel.collapsed .panel-toggle { left: 5px; right: 5px; width: auto; }
.cal-panel.collapsed .panel-vlabel { display: block; writing-mode: vertical-rl; transform: rotate(180deg);
    font-size: 12px; font-weight: 600; color: #586273; white-space: nowrap; margin: 0 auto; }

/* ===== Login: mostra/nascondi password ===== */
.pwd-wrap { position: relative; display: flex; }
.pwd-wrap input { flex: 1; min-width: 0; padding-right: 40px; }
.pwd-toggle { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); background: none; border: none;
    cursor: pointer; font-size: 16px; line-height: 1; padding: 4px; opacity: .65; }
.pwd-toggle:hover { opacity: 1; }

/* ===== Campi data: armonizzati agli altri input (selettore nativo mantenuto) ===== */
input[type="date"], input[type="month"], input[type="datetime-local"] {
    font-family: inherit; font-size: 14px; color: var(--testo); padding: 7px 10px; min-height: 38px;
    border: 1px solid var(--bordo); border-radius: 7px; background: #fff; box-sizing: border-box; }
input[type="date"]::-webkit-calendar-picker-indicator, input[type="month"]::-webkit-calendar-picker-indicator,
input[type="datetime-local"]::-webkit-calendar-picker-indicator { cursor: pointer; opacity: .6; }
input[type="date"]:focus, input[type="month"]:focus, input[type="datetime-local"]:focus {
    outline: none; border-color: var(--blu); box-shadow: 0 0 0 2px rgba(13,71,161,.15); }

/* Tooltip: sulle colonne di destra si apre verso sinistra per non uscire dallo schermo */
.cal-col:nth-child(n+5) .trip-tip { left: auto; right: 100%; margin-left: 0; margin-right: 8px; }

/* ===== Centro notifiche (campanello topbar) ===== */
.notif { position: relative; display: inline-flex; }
.notif-bell { position: relative; background: none; border: none; cursor: pointer; font-size: 18px; line-height: 1; padding: 4px 7px; border-radius: 8px; color: inherit; }
.notif-bell:hover { background: #eef2f8; }
.notif-bell.has { animation: notifpulse 2s ease-in-out infinite; }
@keyframes notifpulse { 0%,100% { transform: none; } 10% { transform: rotate(-12deg); } 20% { transform: rotate(10deg); } 30% { transform: rotate(-6deg); } 40% { transform: rotate(0); } }
.notif-badge { position: absolute; top: 0; right: 0; min-width: 16px; height: 16px; padding: 0 4px; background: #d92d20; color: #fff; font-size: 10px; font-weight: 700; line-height: 16px; text-align: center; border-radius: 9px; }
.notif-panel { display: none; position: absolute; right: 0; top: calc(100% + 8px); width: 340px; max-width: 86vw; max-height: 70vh; overflow-y: auto; background: #fff; color: var(--testo); border: 1px solid var(--bordo); border-radius: 10px; box-shadow: 0 12px 34px rgba(0,0,0,.22); z-index: 300; }
.notif.open .notif-panel { display: block; }
.notif-head { padding: 10px 14px; font-weight: 700; font-size: 14px; background: var(--blu-scuro); color: #fff; border-radius: 10px 10px 0 0; position: sticky; top: 0; }
.notif-sub { padding: 9px 14px 2px; margin: 0; font-size: 12px; color: var(--muted); }
.notif-empty { padding: 18px 14px; margin: 0; font-size: 13px; color: var(--muted); }
.notif-list { list-style: none; margin: 4px 0 8px; padding: 0; }
.notif-list li a { display: block; padding: 8px 14px; text-decoration: none; color: inherit; border-top: 1px solid var(--bordo); }
.notif-list li a:hover { background: #f3f8ff; }
.notif-num { font-weight: 700; margin-right: 6px; }
.notif-meta { display: block; font-size: 12px; color: var(--muted); margin-top: 3px; }

@media (max-width: 1100px) {
    /* Pannelli laterali -> strisce orizzontali sopra la griglia settimana (no schiacciamento) */
    .cal-wrap { flex-direction: column; align-items: stretch; }
    .cal-unassigned, .cal-mezzi { width: auto; max-height: none; align-self: auto; position: static; overflow: visible; }
    .cal-unassigned { order: -1; }
    /* Qui i pannelli sono strisce: il collasso non si applica */
    .panel-toggle, .panel-vlabel { display: none !important; }
    .cal-panel.collapsed { width: auto; min-width: 0; padding: 10px; overflow: visible; }
    .cal-panel.collapsed h3, .cal-panel.collapsed p { display: block; }
    .cal-panel.collapsed .panel-items { display: flex; }
    .panel-items { flex-direction: row; overflow-x: auto; gap: 8px; padding-bottom: 4px; }
    .panel-items > .trip-card, .panel-items > .mezzo-chip { flex: 0 0 auto; width: 165px; margin-bottom: 0; }
    /* In striscia orizzontale i tooltip sforerebbero: li disattivo (resta "Apri"/tap) */
    .panel-items .trip-tip { display: none !important; }
    /* La settimana scorre in orizzontale come blocco unico */
    .cal-grid { grid-template-columns: repeat(7, minmax(140px, 1fr)); overflow-x: auto; }
}

@media (max-width: 760px) {
    .sidebar { width: 64px; }
    .logo-sub, .nav-item { font-size: 0; }
    .nav-item { text-align: center; }
    .logo-box { padding: 5px; }
    .nav-logo { max-width: 40px; }
    .nav-aiact { display: none; }
    .form-grid { grid-template-columns: 1fr; }
    .field.wide { grid-column: span 1; }
}
