: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;
    transition: width .18s ease;
    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: flex; align-items: center; gap: 9px; white-space: nowrap; overflow: hidden; 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 .ni { flex: 0 0 22px; text-align: center; font-size: 16px; }
.nav-item .nl { overflow: hidden; text-overflow: ellipsis; }
.nav-toggle { background: none; border: 1px solid var(--bordo); border-radius: 8px; width: 36px; height: 34px; font-size: 17px;
    line-height: 1; cursor: pointer; color: var(--blu-scuro); margin-right: 12px; flex-shrink: 0; }
.nav-toggle:hover { background: var(--grigio); }
.topbar .brand { margin-right: auto; }
/* Menu chiuso: resta una colonna stretta con le sole icone */
.nav-chiuso .sidebar { width: 58px; }
.nav-chiuso .nav { padding: 14px 8px; }
.nav-chiuso .nav-item { justify-content: center; padding: 10px 0; }
.nav-chiuso .nav-item .nl, .nav-chiuso .logo-sub, .nav-chiuso .nav-aiact { display: none; }
.nav-chiuso .logo-box { padding: 4px; border-radius: 7px; }
.nav-chiuso .nav-brand { margin-bottom: 14px; }
.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: 58px; }
    .nav { padding: 14px 8px; }
    .nav-item { justify-content: center; padding: 10px 0; }
    .nav-item .nl, .logo-sub, .nav-aiact, .nav-toggle { display: none; }
    .logo-box { padding: 4px; }
    .form-grid { grid-template-columns: 1fr; }
    .field.wide { grid-column: span 1; }
}

/* ===== Planning giornaliero: lavagna con una corsia per autista ===== */
.board, .sem-leg, .aut-strip, .cal-wrap {
    /* Semaforo: stato di completezza della pianificazione (testo, sfondo, bordo) */
    --sem-r: #c8271b; --sem-r-bg: #fdecea; --sem-r-bd: #f3b5ae;
    --sem-g: #a87400; --sem-g-bg: #fff5d1; --sem-g-bd: #ecd27a;
    --sem-v: #18794a; --sem-v-bg: #e3f5e9; --sem-v-bd: #a5d9b6;
    --sem-b: #1860a8; --sem-b-bg: #e4edf9; --sem-b-bd: #b7cdec;
    --sem-n: #5d6779; --sem-n-bg: #eef0f4; --sem-n-bd: #d3d8e1; }
.board { display: flex; gap: 12px; align-items: flex-start; }

/* Riepilogo del giorno e legenda */
.sem-leg { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0 0 10px; }
.sem-pill { display: inline-flex; align-items: baseline; gap: 6px; padding: 5px 12px 5px 10px; border-radius: 8px; font-size: 12.5px;
    border: 1px solid var(--bd); background: var(--bg); color: var(--fg); border-left: 5px solid var(--fg); }
.sem-pill b { font-size: 17px; font-weight: 800; font-variant-numeric: tabular-nums; }
.sem-sep { flex: 1; }
.s-rosso { --fg: var(--sem-r); --bg: var(--sem-r-bg); --bd: var(--sem-r-bd); }
.s-giallo { --fg: var(--sem-g); --bg: var(--sem-g-bg); --bd: var(--sem-g-bd); }
.s-verde { --fg: var(--sem-v); --bg: var(--sem-v-bg); --bd: var(--sem-v-bd); }
.s-fatta { --fg: var(--sem-b); --bg: var(--sem-b-bg); --bd: var(--sem-b-bd); }
.s-sosp { --fg: var(--sem-n); --bg: var(--sem-n-bg); --bd: var(--sem-n-bd); }
.st-libero { --fg: var(--sem-v); --bg: var(--sem-v-bg); --bd: var(--sem-v-bd); }
.st-imp { --fg: var(--sem-g); --bg: var(--sem-g-bg); --bd: var(--sem-g-bd); }
.st-inc { --fg: var(--sem-r); --bg: var(--sem-r-bg); --bd: var(--sem-r-bd); }
.st-fine { --fg: var(--sem-b); --bg: var(--sem-b-bg); --bd: var(--sem-b-bd); }

/* Targhe: T = trattore (blu pieno), R = rimorchio (verde acqua, solo bordo) */
.targa { display: inline-flex; align-items: center; gap: 5px; border-radius: 4px; padding: 0 6px 0 0; font-size: 11px; font-weight: 800;
    letter-spacing: .4px; white-space: nowrap; overflow: hidden; line-height: 17px; border: 1px solid #0b3f78; background: #fff; color: #0b2c50;
    font-family: Consolas, "Cascadia Mono", monospace; }
.targa i { font-style: normal; font-family: "Segoe UI", system-ui, sans-serif; background: #0b3f78; color: #fff; padding: 0 5px; font-size: 10px;
    align-self: stretch; display: inline-flex; align-items: center; }
.targa.mot { background: #0b3f78; color: #fff; }
.targa.mot i { background: #fff; color: #0b3f78; }
.targa.rim { border-color: #0f7f86; color: #0a4f54; background: #fff; }
.targa.rim i { background: #0f7f86; }
.targa.manca { background: #fff; border-style: dashed; font-family: inherit; font-weight: 600; letter-spacing: 0; }
.targa.mot.manca { border-color: var(--sem-r); color: var(--sem-r); }
.targa.mot.manca i { background: var(--sem-r); color: #fff; }
.targa.rim.manca { border-color: var(--sem-g); color: var(--sem-g); }
.targa.rim.manca i { background: var(--sem-g); }
.targa.conflict { border-color: var(--sem-r); color: var(--sem-r); }
.targa.conflict i { background: var(--sem-r); }
.targa.vet { border-color: #b9770a; color: #7a4d00; font-family: inherit; font-weight: 700; letter-spacing: 0; max-width: 100%; }
.targa.vet i { background: #d9920f; }
.sem-leg .targa { font-family: inherit; font-weight: 600; letter-spacing: 0; }

/* Autisti da trascinare sulle attività */
.avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--fg, var(--blu)); color: #fff; font-size: 11px; font-weight: 700;
    display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; letter-spacing: .3px; }
.avatar.ext { background: #f4e3c8; font-size: 14px; }
.aut-strip { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; background: #fff; border: 1px solid var(--bordo); border-radius: 10px;
    padding: 8px 10px; margin-bottom: 12px; }
.aut-strip-tit { display: flex; flex-direction: column; margin-right: 6px; font-size: 14px; }
.baut { display: inline-flex; align-items: center; gap: 7px; padding: 4px 11px 4px 4px; border-radius: 20px; cursor: grab; user-select: none;
    background: var(--bg); border: 1px solid var(--bd); transition: box-shadow .12s, transform .12s; }
.baut:hover { box-shadow: 0 2px 8px rgba(0,48,96,.16); transform: translateY(-1px); }
.baut.dragging { opacity: .45; }
.baut-txt { display: flex; flex-direction: column; line-height: 1.2; }
.baut-nome { font-size: 12.5px; font-weight: 700; color: var(--testo); }
.baut-stato { font-size: 10.5px; color: var(--fg); font-weight: 600; }
.aut-leg { margin-left: auto; display: inline-flex; align-items: center; gap: 5px; font-size: 11px; color: var(--muted); }
.aut-leg .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--fg); margin-left: 7px; }

/* Lavagna */
.board-side { width: 236px; flex-shrink: 0; background: #fff; border: 1px solid var(--bordo); border-radius: 10px; padding: 10px;
    position: sticky; top: 0; max-height: 88vh; overflow-y: auto; }
.board-side h3 { margin: 0 0 6px; font-size: 14px; display: flex; align-items: center; gap: 7px; }
.conta { background: var(--blu-scuro); color: #fff; border-radius: 10px; padding: 0 7px; font-size: 11px; line-height: 18px; font-weight: 700; }
.board-filters { display: flex; gap: 6px; margin-bottom: 6px; }
.board-filters select { flex: 1; min-width: 0; padding: 4px 6px; border: 1px solid var(--bordo); border-radius: 6px; font-size: 12px; background: #fff; }
.board-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.board-row { display: flex; background: #fff; border: 1px solid var(--bordo); border-left: 5px solid var(--fg, var(--bordo)); border-radius: 10px;
    min-height: 78px; overflow: hidden; box-shadow: 0 1px 2px rgba(0,48,96,.05); }
.board-row.ext { border-left-color: #d9a441; }
.board-row.warn { background: #fff5f5; border-color: #f0a3a3; }
.board-rowhead { width: 172px; flex-shrink: 0; padding: 8px 10px; border-right: 1px solid var(--bordo); display: flex; flex-direction: column;
    align-items: flex-start; gap: 4px; font-size: 13px; background: var(--bg, #fafbfd); }
.board-row.ext .board-rowhead { background: #fff8ec; }
.rh-top { display: flex; align-items: center; gap: 7px; min-width: 0; width: 100%; }
.rh-top strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; line-height: 1.2; }
.rh-stato { font-size: 11px; font-weight: 600; color: var(--fg, var(--muted)); }
.board-rowhead select { width: 100%; padding: 4px 6px; border: 1px solid var(--bordo); border-radius: 6px; font-size: 12px; background: #fff; }
.board-row .board-cards { flex: 1; min-width: 0; display: flex; flex-wrap: wrap; gap: 7px; padding: 8px; align-content: flex-start; }
.board-side .board-cards { display: flex; flex-direction: column; gap: 7px; min-height: 60px; }
.lane-vuota { color: #a3adbd; font-size: 12px; align-self: center; border: 1px dashed #d5dce8; border-radius: 6px; padding: 9px 14px; }
.bdrop { outline: 2px dashed var(--blu); outline-offset: -2px; }
.board-row.bdrop .board-cards, .board-side.bdrop { background: #eef4ff; }

/* Attività: il colore dice quanto è completa la pianificazione */
.bcard { width: 204px; background: var(--bg); border: 1px solid var(--bd); border-left: 5px solid var(--fg); border-radius: 7px; padding: 5px 7px 6px;
    font-size: 11.5px; line-height: 1.32; cursor: grab; min-width: 0; transition: box-shadow .12s, transform .12s; }
.bcard:hover { box-shadow: 0 3px 10px rgba(0,48,96,.16); transform: translateY(-1px); }
.bcard.bdrop { outline: 2px solid var(--blu); outline-offset: 1px; }
.board-side .bcard { width: auto; }
.bcard.dragging, .bres.dragging { opacity: .45; }
.bcard.s-fatta { cursor: pointer; }
.bcard.s-fatta .bcard-cli, .bcard.s-fatta .bcard-tratta { opacity: .8; }
.bcard.s-sosp { background: repeating-linear-gradient(135deg, var(--sem-n-bg) 0 8px, #f8f9fb 8px 16px); }
.bcard.late { box-shadow: inset 0 0 0 1px var(--sem-r); }
.bcard-head { display: flex; align-items: center; gap: 5px; margin-bottom: 2px; }
.bcard-seq { background: var(--fg); color: #fff; border-radius: 50%; width: 18px; height: 18px; display: inline-flex; align-items: center; justify-content: center; font-size: 10.5px; font-weight: 700; flex-shrink: 0; }
.bcard-num { font-weight: 700; color: var(--blu-scuro); flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bcard .badge { font-size: 10px; padding: 1px 6px; background: #fff; color: var(--fg); border: 1px solid var(--bd); font-weight: 600; }
.bcard-cli { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bcard-tratta { color: #4d5768; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bcard-res { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.bchip-x { background: none; border: 0; color: inherit; cursor: pointer; font-size: 10px; padding: 0 0 0 2px; line-height: 1; opacity: .7; }
.bchip-x:hover { opacity: 1; }

/* Trattori e rimorchi da trascinare */
.bres { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; background: #fff; border: 1px solid var(--bordo); border-left: 4px solid var(--sem-v);
    border-radius: 7px; padding: 6px 8px; margin-bottom: 6px; cursor: grab; font-size: 12px; transition: box-shadow .12s; }
.bres:hover { box-shadow: 0 2px 8px rgba(0,48,96,.14); }
.bres.uso { border-left-color: var(--sem-g); background: #fffdf4; }
.bres.conflict { border-color: var(--sem-r-bd); border-left-color: var(--sem-r); background: var(--sem-r-bg); }
.bres-info { color: #586273; }
@media (max-width: 900px) { .board { flex-direction: column; } .board-side { width: auto; position: static; max-height: none; align-self: stretch; } }

/* ===== Lettera di vettura: blocchi di campi richiudibili e riquadro di stampa/invio ===== */
.ldv-dati { margin-top: 14px; border: 1px solid var(--bordo); border-radius: 8px; padding: 8px 12px; background: #fbfcfe; }
.ldv-dati summary { cursor: pointer; font-size: 13px; font-weight: 600; color: #44506a; }
.ldv-dati .form-grid { margin-top: 10px; }
.form-grid.tre { grid-template-columns: repeat(3, 1fr); }
.form-grid.tre .field.wide { grid-column: 1 / -1; }
.ldv-box { margin-top: 14px; }
@media (max-width: 760px) { .form-grid.tre { grid-template-columns: 1fr; } }

/* ===== Consuntivazione e distinte ===== */
.cons-grid input[type=number] { width: 95px; text-align: right; }
.cons-grid input[type=date] { width: 135px; }
.cons-grid input { padding: 5px 7px; border: 1px solid var(--bordo); border-radius: 6px; font-size: 13px; background: #fff; }
.distinta-testa { display: flex; justify-content: space-between; gap: 20px; margin-bottom: 14px; font-size: 14px; }
@media print {
    .sidebar, .topbar, .no-print, .site-footer, footer { display: none !important; }
    .content { padding: 0 !important; }
    .form-card.distinta-foglio { border: 0; box-shadow: none; padding: 0; }
    body { background: #fff; }
}

/* ---------- Utenti e permessi ---------- */
.topbar a.who { color: inherit; text-decoration: none; font-weight: 600; }
.topbar a.who:hover { text-decoration: underline; }
.avviso-lettura { background: #fff7e0; color: #7a5200; }
/* Sola lettura: i comandi che salvano spariscono (il server li rifiuterebbe comunque). */
.sola-lettura form[method="post"] button[type="submit"],
.sola-lettura form[method="post"] button:not([type]),
.sola-lettura a[href^="/ordini/nuovo"],
.sola-lettura a[href^="/ordini/riga/nuova"] { display: none !important; }
@media print { .avviso-lettura { display: none; } }

/* ---------- App dell'autista (pensata per il telefono) ---------- */
.aut-nav { justify-content: center; gap: 14px; }
.aut-nav .cal-arrow { font-size: 22px; padding: 6px 16px; }
.aut-card { background: #fff; border-radius: 12px; box-shadow: 0 1px 3px rgba(0,0,0,.08); padding: 14px; margin: 0 auto 14px; max-width: 640px; border-left: 5px solid var(--blu); }
.aut-card.fatta { border-left-color: #2e7d32; opacity: .8; }
.aut-testa { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.aut-testa > div { flex: 1; min-width: 0; }
.aut-num { flex: none; width: 34px; height: 34px; border-radius: 50%; background: var(--blu); color: #fff; font-weight: 700; display: flex; align-items: center; justify-content: center; }
.aut-luogo { background: #f5f8fc; border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; font-size: 14px; }
.aut-luogo a { white-space: nowrap; margin-left: 6px; }
.aut-dati { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin: 8px 0; font-size: 14px; }
.aut-dati dt { color: var(--muted); }
.aut-dati dd { margin: 0; font-weight: 600; word-break: break-word; }
.aut-istruzioni { background: #fff7e0; border-radius: 8px; padding: 8px 10px; font-size: 14px; margin-bottom: 8px; white-space: pre-line; }
.aut-azioni { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.aut-azioni form { display: flex; flex: 1; gap: 8px; min-width: 240px; margin: 0; }
.aut-azioni .btn, .aut-azioni .btn-add { padding: 10px 14px; font-size: 15px; }
.aut-prossimi { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.aut-push { max-width: 640px; margin: 18px auto; }
[data-push-box] [hidden] { display: none !important; }

/* ===== Planning settimanale: stessa grafica della vista Giorno ===== */
.cal-col { border-radius: 10px; box-shadow: 0 1px 2px rgba(0,48,96,.05); }
.cal-col.festivo { background: #f7f9fc; }
.cal-col.today { border-color: var(--blu); box-shadow: 0 0 0 2px rgba(24,96,168,.18); }
a.cal-colhead, .cal-colhead { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 6px; padding: 7px 9px; border-radius: 10px 10px 0 0;
    background: #fafbfd; border-bottom: 1px solid var(--bordo); text-decoration: none; color: var(--testo); font-weight: 400; }
.cal-col.today .cal-colhead { background: var(--blu); color: #fff; border-bottom-color: var(--blu); }
.cal-col.today a.cal-colhead:hover { background: var(--blu-scuro); color: #fff; }
.ch-giorno { display: flex; align-items: center; gap: 7px; min-width: 0; color: inherit; }
.ch-giorno b { font-size: 20px; font-weight: 800; line-height: 1; color: inherit; }
.cal-colhead .ch-giorno, .cal-colhead .ch-giorno span { color: inherit; }
.cal-colhead .ch-giorno span { font-size: 12px; font-weight: 600; opacity: .8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-colhead .ch-conta { display: inline-flex; gap: 3px; flex-shrink: 0; }
.cal-colhead .ch-conta i { font-style: normal; font-size: 10.5px; font-weight: 800; min-width: 18px; height: 18px; padding: 0 4px; border-radius: 9px;
    display: inline-flex; align-items: center; justify-content: center; background: var(--fg); color: #fff; }
.cal-col.today .ch-conta i { box-shadow: 0 0 0 1px rgba(255,255,255,.7); }
.cal-drop .lane-vuota { align-self: stretch; text-align: center; padding: 14px 6px; }
.trip-card { background: var(--bg, #eef4ff); border: 1px solid var(--bd, #cdddf6); border-left: 5px solid var(--fg, var(--blu)); border-radius: 7px; padding: 5px 7px 6px;
    line-height: 1.32; transition: box-shadow .12s; }
.trip-card:hover { box-shadow: 0 3px 10px rgba(0,48,96,.16); }
.trip-card.s-sosp { background: repeating-linear-gradient(135deg, var(--sem-n-bg) 0 8px, #f8f9fb 8px 16px); }
.trip-card.conflict { border-color: var(--sem-r-bd); border-left-color: var(--sem-r); }
.trip-ok { color: var(--fg); font-weight: 800; }
.trip-chi { display: flex; flex-wrap: wrap; align-items: center; gap: 3px 4px; margin-top: 4px; min-width: 0; }
.trip-aut { flex: 1 1 100%; min-width: 0; font-weight: 600; color: #36404f; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.trip-nd { font-size: 10.5px; font-weight: 700; color: var(--fg); text-transform: uppercase; letter-spacing: .4px; }
.trip-chi .targa { font-size: 10px; line-height: 15px; padding-right: 4px; gap: 3px; }
.trip-chi .targa i { padding: 0 3px; font-size: 9px; }
.cal-unassigned h3, .cal-mezzi h3 { display: flex; align-items: center; gap: 7px; }
.mezzo-chip { align-items: flex-start; gap: 2px; background: #fff; border: 1px solid var(--bordo); border-left: 4px solid #0b3f78; transition: box-shadow .12s; }
.mezzo-chip:hover { box-shadow: 0 2px 8px rgba(0,48,96,.14); }

/* Targhe leggibili: i tre gruppi (AA 123 BB) staccati di mezzo spazio */
.tgw { display: inline-flex; }
.tgw .tg + .tg { margin-left: .5ch; }
/* Vista settimana: rimorchi trascinabili nel pannello dei mezzi */
.mezzo-chip.rim { border-left-color: #0f7f86; }

/* ===== Telefono: niente scritte o riquadri che escono dal proprio spazio ===== */
fieldset { min-width: 0; }
@media (max-width: 760px) {
    /* Struttura: menu a icone più stretto, margini ridotti */
    .sidebar { width: 46px; }
    .nav { padding: 10px 4px; }
    .nav-item { padding: 9px 0; margin-bottom: 2px; }
    .logo-box { padding: 3px; border-radius: 6px; }
    .content { padding: 12px 10px; }
    /* Intestazione: resta il nome dell'azienda, troncato se serve; "Esci" sempre visibile */
    .topbar { height: auto; min-height: 46px; padding: 6px 10px; gap: 8px; }
    .topbar .brand { font-size: 12.5px; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .brand-app, .topbar .role { display: none; }
    .topbar .user { gap: 8px; font-size: 13px; flex-shrink: 0; }
    .topbar a.who { max-width: 96px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    /* Titoli e linguette */
    h1 { font-size: 19px; margin-bottom: 10px; }
    .page-head { flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
    .page-head h1 { margin: 0; }
    .page-head .tabs { margin-bottom: 0; }
    .tabs { flex-wrap: wrap; margin-bottom: 10px; }
    .tab { padding: 6px 10px; font-size: 13px; }
    /* Tabelle: scorrono in orizzontale dentro il proprio riquadro */
    table.grid { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .grid th, .grid td { padding: 7px 9px; font-size: 12.5px; }
    /* Moduli su una colonna, senza campi più larghi dello schermo */
    .form-card { padding: 12px; }
    .form-grid, .form-grid.tre { grid-template-columns: minmax(0, 1fr); }
    .field { min-width: 0; }
    .field input, .field select, .field textarea { max-width: 100%; min-width: 0; }
    .input-row, .form-actions { flex-wrap: wrap; }
    .plan-filters .field, .plan-filters .field.wide { min-width: 0; flex: 1 1 130px; }
    .wide-input { min-width: 0; flex: 1 1 100%; }
    .storord-body { overflow-x: auto; padding: 10px; }
    .distinta-testa { flex-direction: column; gap: 8px; }
    /* Planning: barra dei giorni e riepilogo a colori più compatti */
    .cal-nav { flex-wrap: wrap; justify-content: center; gap: 6px; margin-bottom: 10px; }
    .cal-nav form { flex-wrap: wrap; justify-content: center; }
    .cal-arrow { padding: 6px 9px; font-size: 12.5px; white-space: nowrap; }
    .cal-range { font-size: 13px; text-align: center; }
    .cal-nav > .cal-range { flex: 1 1 90px; min-width: 0; }
    .sem-leg { gap: 5px; }
    .sem-pill { padding: 3px 8px 3px 7px; font-size: 11.5px; border-left-width: 4px; }
    .sem-pill b { font-size: 14px; }
    .sem-sep { display: none; }
    .cal-grid { grid-template-columns: repeat(7, minmax(132px, 1fr)); }
    .ch-giorno b { font-size: 17px; }
    /* Vista giorno: nome dell'autista sopra, attività sotto a tutta larghezza */
    .aut-strip { padding: 6px 8px; gap: 5px; }
    .aut-leg { margin-left: 0; flex-wrap: wrap; }
    .board-row { flex-direction: column; }
    .board-rowhead { width: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 4px 8px; border-right: 0;
        border-bottom: 1px solid var(--bordo); padding: 6px 8px; }
    .rh-top { width: auto; }
    .board-rowhead select { width: auto; flex: 1 1 140px; }
    .board-row .bcard { width: auto; flex: 1 1 170px; }
}
@media (max-width: 900px) { .board { align-items: stretch; } }
/* Nome del vettore troppo lungo: si tronca con i puntini */
.targa.vet { display: inline-block; text-overflow: ellipsis; vertical-align: middle; }
.targa.vet i { display: inline-block; margin-right: 5px; }
.trip-chi .targa.vet i { margin-right: 3px; }
/* Moduli: una colonna non si allarga mai oltre il proprio spazio (a qualsiasi larghezza) */
.form-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.form-grid.tre { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field { min-width: 0; }
.field input, .field select, .field textarea { max-width: 100%; min-width: 0; }
.storord-body { overflow-x: auto; }
/* Tablet: una tabella larga scorre dentro la pagina, senza spostare menu e intestazione */
@media (max-width: 1100px) { .content { overflow-x: auto; } }
@media (max-width: 760px) {
    .form-grid, .form-grid.tre { grid-template-columns: minmax(0, 1fr); }
    .inline-row { flex-wrap: wrap; }
    .tab { font-size: 12.5px; padding: 6px 9px; }
    /* Barra dei giorni: data in alto, frecce affiancate sotto, "Avvisa" su una riga sua */
    .cal-nav > .cal-range, .cal-nav > form.inline-row { order: -1; flex: 1 1 100%; }
    .cal-nav > .cal-arrow { flex: 1 1 0; text-align: center; }
    .cal-nav > form[method="post"] { order: 2; flex: 1 1 100%; text-align: center; margin: 0; }
    /* Autisti: una sola riga che scorre di lato, per non spingere in basso la lavagna */
    .aut-strip { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .aut-strip > * { flex-shrink: 0; }
    .aut-leg { flex-wrap: nowrap; }
    .board-rowhead select { min-width: 0; max-width: 100%; }
}

/* ===== Viaggi: note che si allargano, Imp/Exp e tipo del servizio ===== */
.field textarea { padding: 8px 10px; border: 1px solid var(--bordo); border-radius: 7px; font-size: 14px; background: #fff; font-family: inherit;
    line-height: 1.4; resize: vertical; min-height: 72px; overflow: hidden; }
.input-row > .ss-combo { flex: 1; min-width: 0; margin-top: 0; }
.badge.dir-IMP { background: #e4edf9; color: #1860a8; font-weight: 600; }
.badge.dir-EXP { background: #fdf0dc; color: #8a5a00; font-weight: 600; }
.badge[class*="tipo-"] { font-weight: 600; }
.badge.tipo-Trazione { background: #e4edf9; color: #0b3f78; }
.badge.tipo-Posizionamento { background: #e3f5e9; color: #18794a; }
.badge.tipo-Consegna { background: #fff5d1; color: #8a5a00; }
.badge.tipo-Varie { background: #eef0f4; color: #4d5768; }

/* ===== Sottoservizi (righe sotto un servizio) e viaggi annullati ===== */
#sottoservizi .add-row { display: grid; grid-template-columns: 150px minmax(120px, 1fr) 80px 100px 170px 90px 34px; gap: 8px; align-items: center; }
#sottoservizi .add-row > * { min-width: 0; width: 100%; }
#sottoservizi .add-row select { padding: 8px 6px; border: 1px solid var(--bordo); border-radius: 7px; font-size: 13.5px; background: #fff; }
#sottoservizi .add-head { font-size: 11px; color: #586273; font-weight: 600; text-transform: uppercase; letter-spacing: .3px; margin-bottom: 4px; }
#sottoservizi .add-tot { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
@media (max-width: 760px) { #sottoservizi .add-row { grid-template-columns: 1fr 1fr; } #sottoservizi .add-head { display: none; } }
tr.riga-annullata td { color: #9aa3b2; }
tr.riga-annullata td a strong { text-decoration: line-through; }

/* Scadenza delivery del container sulle attività del planning */
.bcard-scad { font-size: 11px; font-weight: 600; color: #4d5768; }
.bcard-scad.vicina { color: var(--sem-g); }
.bcard-scad.scaduta { color: var(--sem-r); }

/* Servizi in più parti: pallini per scegliere la parte e scheda più chiara quando ne resta una da piazzare */
.bcard-parti { display: flex; align-items: center; gap: 5px; margin: 3px 0 4px; flex-wrap: wrap; }
.pdot { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--fg); background: #fff; color: var(--fg); font-size: 11px; font-weight: 800;
    cursor: pointer; padding: 0; line-height: 1; display: inline-flex; align-items: center; justify-content: center; }
.pdot.sel { background: var(--fg); color: #fff; box-shadow: 0 0 0 2px rgba(0,0,0,.12); }
.pdot.fatta { border-style: dashed; opacity: .45; cursor: default; background: transparent; }
.pdot-txt { font-size: 10.5px; color: #586273; }
.bcard.parziale { background: #fff; border-style: dashed; border-left-style: solid; opacity: .9; }
tr.riga-parte td { background: #fafbfd; font-size: 12.5px; }
#vcl-err { background: #fdecea; color: #b71c1c; padding: 8px 12px; border-radius: 7px; margin-top: 10px; font-size: 13.5px; }
/* Sottoservizi: la nota occupa una seconda riga sotto i campi */
#sottoservizi .add-row .add-nota { grid-column: 2 / -2; font-size: 13px; padding: 6px 10px; }
#sottoservizi .add-row { margin-bottom: 10px; }
