:root {
  --orange: #f60;
  --orange-dark: #e25a00;
  --nav-bg: #2b2b2b;
  --nav-hover: #3d3d3d;
  --green: #5cb85c;
  --green-dark: #4ca64c;
  --ink: #333;
  --muted: #8a8a8a;
  --line: #e6e6e6;
  --bg: #f0f2f4;
  --white: #fff;
  --shadow: 0 1px 3px rgba(0,0,0,.08);
  --radius: 6px;

  --st-aperta: #3a9fd6;
  --st-elaborazione: #f0a202;
  --st-approvata: #9aa0a6;
  --st-verificata: #9b59b6;
  --st-rimborsata: #46b450;
  --c-distanza: #3a9fd6;
  --c-forfait: #e2574c;
  --c-vari: #8bc34a;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
/* niente scroll orizzontale della pagina (a livello html: non rompe le barre sticky) + niente zoom accidentale */
html { overflow-x: hidden; }
body { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; touch-action: manipulation; }
body { font-family: "Segoe UI", system-ui, sans-serif; background: var(--bg); color: var(--ink); font-size: 14px; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }

/* ---------- TOP BAR ---------- */
.topbar {
  background: var(--orange); color: #fff; height: 52px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 18px; position: sticky; top: 0; z-index: 20;
}
.topbar-left { display: flex; align-items: center; gap: 14px; }
.logo { font-size: 26px; font-weight: 900; letter-spacing: -1px; transform: skewX(-8deg); }
.logo span { color: #2b2b2b; }
.topbar-title { font-size: 18px; font-weight: 300; border-left: 1px solid rgba(255,255,255,.4); padding-left: 14px; }
.topbar-right { display: flex; align-items: center; gap: 20px; }
.topbar-link { font-size: 13px; cursor: pointer; opacity: .95; }
.topbar-link:hover { opacity: 1; text-decoration: underline; }
.topbar-user { display: flex; align-items: center; gap: 9px; position: relative; cursor: pointer; padding: 5px 8px; border-radius: 6px; }
.topbar-user:hover { background: rgba(255,255,255,.12); }
.caret { font-size: 11px; opacity: .9; }
.profile-menu { position: absolute; top: 110%; right: 0; background: #fff; color: var(--ink); min-width: 240px;
  border-radius: 8px; box-shadow: 0 8px 30px rgba(0,0,0,.25); padding: 6px; z-index: 30; cursor: default; }
.profile-menu .pm-head { font-size: 11px; text-transform: uppercase; color: var(--muted); padding: 8px 10px 4px; }
.profile-menu .pm-item { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 6px; cursor: pointer; }
.profile-menu .pm-item:hover { background: #f2f4f4; }
.profile-menu .pm-item.active { background: var(--orange); color: #fff; }
.profile-menu .pm-item.active .pm-av { background: #fff; color: var(--orange); }
.profile-menu .pm-av { width: 30px; height: 30px; border-radius: 50%; background: var(--nav-bg); color: #fff;
  display: grid; place-items: center; font-size: 12px; font-weight: 700; flex: none; }
.profile-menu .pm-sep { height: 1px; background: var(--line); margin: 6px 4px; }
.profile-menu .pm-action { padding: 9px 10px; border-radius: 6px; cursor: pointer; color: var(--orange); font-weight: 600; font-size: 13px; }
.profile-menu .pm-action:hover { background: #fff4ec; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: #fff; color: var(--orange);
  font-weight: 700; display: grid; place-items: center; font-size: 13px; }
.user-meta { display: flex; flex-direction: column; line-height: 1.2; }
.user-meta small { opacity: .85; font-size: 11px; }

/* ---------- NAV ---------- */
.mainnav { background: var(--nav-bg); display: flex; align-items: stretch; position: sticky; top: 52px; z-index: 19; }
.mainnav button { background: none; border: none; color: #cfcfcf; cursor: pointer;
  padding: 0 18px; height: 44px; font-size: 14px; font-family: inherit; transition: background .15s; }
.mainnav button:hover { background: var(--nav-hover); color: #fff; }
.nav-home { font-size: 18px; }
.nav-item.active { background: var(--orange); color: #fff; }
.nav-toggle { display: none; align-items: center; gap: 8px; background: none; border: none; color: #fff;
  font-family: inherit; font-size: 16px; font-weight: 600; cursor: pointer; height: 44px; padding: 0 16px; width: 100%; text-align: left; }

/* ---------- MAIN ---------- */
.main { max-width: 1200px; margin: 0 auto; padding: 22px 18px; }
.view { display: flex; flex-direction: column; gap: 16px; }
.page-head { display: flex; align-items: center; justify-content: space-between; }
.page-head h2 { font-size: 24px; font-weight: 400; color: #555; }
/* lista note raggruppata per anno */
.year-group { margin-bottom: 20px; }
.year-group:last-child { margin-bottom: 0; }
.year-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
  padding: 4px 2px 8px; margin-bottom: 6px; border-bottom: 2px solid var(--orange); }
.year-head .year-num { font-size: 18px; font-weight: 700; color: #333; }
.ph-actions { display: flex; align-items: center; gap: 12px; }

/* ---------- CARD ---------- */
.card { background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.card-head h3 { font-size: 15px; font-weight: 600; color: #555; }
.card-foot { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.card-foot .btn { flex: 1 1 150px; padding: 12px 14px; font-size: 13.5px; min-height: 44px; }

/* ---------- DASHBOARD GRID ---------- */
.dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.card-wide { grid-column: 1 / -1; }
.kpi-list { display: flex; flex-direction: column; gap: 4px; }
.kpi-row { display: flex; justify-content: space-between; padding: 9px 4px; border-bottom: 1px dashed var(--line); }
.kpi-row.total { border-bottom: none; border-top: 2px solid var(--line); margin-top: 4px; font-size: 16px; }
.kpi-row.total strong { color: var(--orange); }

.current-report { display: flex; align-items: center; justify-content: space-between; padding: 14px;
  border: 1px solid var(--line); border-radius: var(--radius); cursor: pointer; }
.current-report:hover { background: #fafafa; }
.cr-left { display: flex; align-items: center; gap: 10px; }
.cr-amount { color: var(--orange); font-weight: 700; font-size: 18px; }

/* ---------- BUTTONS ---------- */
.btn { border: none; cursor: pointer; padding: 8px 15px; border-radius: var(--radius);
  font-size: 13px; font-weight: 600; font-family: inherit; transition: all .15s; }
.btn-green { background: var(--green); color: #fff; }
.btn-green:hover { background: var(--green-dark); }
.btn-primary { background: var(--orange); color: #fff; }
.btn-primary:hover { background: var(--orange-dark); }
.btn-ghost { background: #f3f3f3; color: #555; border: 1px solid var(--line); }
.btn-ghost:hover { background: #e9e9e9; }
.btn-danger { background: #fdecec; color: #d9534f; }
.btn-danger:hover { background: #d9534f; color: #fff; }
.btn-danger-ghost { background: none; color: #d9534f; border: 1px solid var(--line); }
.link { background: none; border: none; color: var(--orange); cursor: pointer; font-weight: 600; font-size: 13px; }
.link-green { color: var(--green-dark); }
.icon-btn { background: none; border: none; font-size: 18px; cursor: pointer; color: #fff; }
.row-gap { display: flex; gap: 10px; }

/* ---------- TABLE ---------- */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 10px 12px; border-bottom: 2px solid var(--line); }
td { padding: 11px 12px; border-bottom: 1px solid var(--line); }
tbody tr { cursor: pointer; }
tbody tr:hover td { background: #fafbfc; }
.amount { font-weight: 700; text-align: right; white-space: nowrap; }
.empty { padding: 36px; text-align: center; color: var(--muted); }
.subdesc { color: var(--muted); font-size: 12px; }

/* ---------- BADGES ---------- */
.badge { padding: 4px 12px; border-radius: 3px; font-size: 12px; font-weight: 600; color: #fff; display: inline-block;
  position: relative; }
.badge.aperta { background: var(--st-aperta); }
.badge.elaborazione { background: var(--st-elaborazione); }
.badge.approvata { background: var(--st-approvata); }
.badge.verificata { background: var(--st-verificata); }
.badge.rimborsata { background: var(--st-rimborsata); }

/* ---------- TYPE ICONS ---------- */
.type-ico { width: 28px; height: 28px; border-radius: 5px; display: grid; place-items: center; color: #fff; font-size: 14px; }
.type-ico.km { background: var(--c-distanza); }
.type-ico.forfait { background: var(--c-forfait); }
.type-ico.vari { background: var(--c-vari); }

/* ---------- FILTERS SIDEBAR ---------- */
#view-reports { display: grid; grid-template-columns: 220px 1fr; gap: 16px; }
.filters { background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; height: fit-content; }
.filters-title { font-weight: 600; color: #555; margin-bottom: 14px; }
.filter-check { display: flex; flex-direction: row; align-items: center; gap: 8px; padding: 9px 8px; border-radius: 4px; cursor: pointer; font-size: 13px; }
.filter-check:hover { background: #f6f6f6; }
.dot { width: 12px; height: 12px; border-radius: 3px; }
.dot.aperta { background: var(--st-aperta); }
.dot.elaborazione { background: var(--st-elaborazione); }
.dot.approvata { background: var(--st-approvata); }
.dot.verificata { background: var(--st-verificata); }
.dot.rimborsata { background: var(--st-rimborsata); }
.reports-main { display: flex; flex-direction: column; gap: 14px; }

/* ---------- LISTA "LE MIE NOTE SPESE" — card con un colore diverso per mese ---------- */
.rep-list { display: flex; flex-direction: column; gap: 12px; }
.rep-card { cursor: pointer; padding: 15px 16px;
  background: #eef1f5; /* fallback se color-mix non è supportato */
  background: color-mix(in srgb, var(--mc, var(--orange)) 16%, #fff); /* tinta UNIFORME del colore-mese su tutta la riga */
  border: 1px solid var(--line); border-left: 7px solid var(--mc, var(--orange)); border-radius: 12px;
  box-shadow: 0 1px 4px rgba(0,0,0,.07); transition: box-shadow .12s ease, transform .06s ease; }
.rep-card:hover { box-shadow: 0 3px 12px rgba(0,0,0,.13); }
.rep-card:active { transform: scale(.995); }
.rep-top { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.rep-month { font-size: 23px; font-weight: 800; letter-spacing: -.01em; color: var(--mc, var(--ink)); line-height: 1.15; }
.rep-amt { font-size: 21px; font-weight: 800; color: #1b1b1b; white-space: nowrap; }
.rep-badge { display: inline-block; margin-top: 10px; padding: 5px 20px 5px 12px; color: #fff; font-weight: 700;
  font-size: 12.5px; background: var(--st-approvata);
  clip-path: polygon(0 0, 100% 0, calc(100% - 11px) 100%, 0 100%); }
.rep-badge.aperta { background: var(--st-aperta); }
.rep-badge.elaborazione { background: var(--st-elaborazione); }
.rep-badge.approvata { background: var(--st-approvata); }
.rep-badge.pagata { background: var(--st-pagata); }
.rep-sub { margin-top: 9px; color: var(--muted); font-size: 14px; }
@media (max-width: 600px) {
  .rep-month { font-size: 25px; }
  .rep-amt { font-size: 22px; }
  .rep-card { padding: 18px 4px 18px 18px; }
}

/* ---------- REPORT DETAIL ---------- */
.report-header .rh-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.report-header h2 { font-size: 20px; font-weight: 400; color: #555; }
.rh-actions { display: flex; gap: 8px; }
.rh-body { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.rh-title { flex: 1; min-width: 220px; }
.rh-title label { display: block; font-size: 11px; color: var(--muted); margin-bottom: 3px; }
.rh-title input { width: 100%; }
.rh-total { margin-left: auto; text-align: right; }
.rh-total strong { display: block; font-size: 24px; color: var(--orange); }

/* ---------- FORM ---------- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }
.form-grid .full { grid-column: 1 / -1; }
label { font-size: 12px; font-weight: 600; color: #555; display: flex; flex-direction: column; gap: 5px; }
input, select { padding: 9px 10px; border: 1px solid #ccc; border-radius: 4px; font-size: 14px; font-family: inherit; background: #fff; }
input:focus, select:focus { outline: none; border-color: var(--orange); }
input[readonly] { background: #f5f5f5; color: #666; }
.subform { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-top: 14px; }
.subform legend { font-size: 12px; font-weight: 700; color: var(--orange); padding: 0 6px; text-transform: uppercase; }
.toggles { display: flex; gap: 24px; margin-bottom: 14px; }
.switch-label { flex-direction: row; align-items: center; gap: 8px; cursor: pointer; }

/* ---------- MODAL ---------- */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: grid; place-items: start center;
  z-index: 50; padding: 30px 20px; overflow-y: auto; }
.modal { background: var(--white); border-radius: var(--radius); width: 100%; max-width: 720px; box-shadow: 0 10px 50px rgba(0,0,0,.3); }
.modal-head { background: var(--orange); color: #fff; padding: 14px 18px; border-radius: var(--radius) var(--radius) 0 0;
  display: flex; justify-content: space-between; align-items: center; }
.modal-head h3 { font-size: 16px; font-weight: 600; }
#expenseForm, #routeForm { padding: 20px 22px; }

/* autocomplete indirizzi (stile Google Maps, dati OpenStreetMap) */
.ac-list { position: absolute; top: 100%; left: 0; right: 0; background: #fff; border: 1px solid #ccc; border-top: none;
  border-radius: 0 0 6px 6px; z-index: 60; max-height: 240px; overflow-y: auto; box-shadow: 0 8px 20px rgba(0,0,0,.14); }
.ac-item { padding: 9px 12px; font-size: 13px; cursor: pointer; border-bottom: 1px solid #f1f1f1; line-height: 1.35; }
.ac-item:last-child { border-bottom: none; }
.ac-item:hover, .ac-item.active { background: #fff4ec; }
.ac-item .pin { color: var(--orange); margin-right: 6px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }

/* ---------- CHARTS ---------- */
.chart svg, .chart-donut svg { display: block; }
.chart svg { width: 100%; height: auto; }
.chart-donut { display: flex; align-items: center; gap: 18px; }
.legend { display: flex; flex-direction: column; gap: 9px; flex: 1; }
.legend-item { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.legend-dot { width: 12px; height: 12px; border-radius: 3px; }

/* ---------- VEHICLES ---------- */
.vehicle-row, .cat-row { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.vehicle-row:last-child, .cat-row:last-child { border-bottom: none; }
.vehicle-row input[type=text] { flex: 1; }
.vehicle-row .plate, .vehicle-row .rate { width: 130px; flex: none; }
.danger-zone { border: 1px solid #f3d6d6; }

/* ---------- VIEW TOGGLE ---------- */
.head-right { display: flex; align-items: center; gap: 12px; }
.view-toggle { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.view-toggle .vt { background: #fff; border: none; padding: 7px 13px; font-size: 13px; cursor: pointer; color: #666;
  border-right: 1px solid var(--line); font-family: inherit; }
.view-toggle .vt:last-child { border-right: none; }
.view-toggle .vt:hover { background: #f6f6f6; }
.view-toggle .vt.active { background: var(--orange); color: #fff; }

/* ---------- RECEIPT / GIUSTIFICATIVO ---------- */
.receipt-row { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.upload-btn { flex-direction: row; align-items: center; background: #f3f3f3; border: 1px dashed #bbb;
  padding: 10px 16px; border-radius: var(--radius); cursor: pointer; color: #555; font-weight: 600; }
.upload-btn:hover { background: #ececec; border-color: var(--orange); }
.receipt-preview { display: flex; align-items: center; gap: 10px; }
.receipt-preview img { width: 56px; height: 56px; object-fit: cover; border-radius: 5px; border: 1px solid var(--line); cursor: pointer; }
.km-counter { font-size: 12px; color: var(--muted); background: #f6f9fb; border-left: 3px solid var(--c-distanza);
  padding: 7px 10px; border-radius: 3px; }
.receipt-cell img { width: 30px; height: 30px; object-fit: cover; border-radius: 4px; border: 1px solid var(--line); cursor: pointer; }
.receipt-icon { color: var(--muted); font-size: 16px; }

/* ---------- MAPPA PERCORSO ---------- */
.km-input { display: flex; gap: 8px; }
.km-input input { flex: 1; }
.km-input .btn { white-space: nowrap; padding: 0 12px; }
.rt-label { flex-direction: row; align-items: center; gap: 8px; align-self: end; padding-bottom: 9px; }
.map-wrap { grid-column: 1 / -1; margin-top: 14px; }
.map-wrap .map-placeholder { width: 100%; height: 240px; border: 1px dashed #ccc; border-radius: var(--radius);
  display: grid; place-items: center; color: var(--muted); text-align: center; padding: 20px; background: #fafbfc; }
.map-wrap iframe { width: 100%; height: 280px; border: 0; border-radius: var(--radius); }
.map-wrap #openMaps { display: inline-block; margin-top: 8px; }

/* mappa Google interattiva + autocomplete Google (pac-container) */
.gmap { width: 100%; height: 300px; border-radius: var(--radius); border: 1px solid var(--line); }
.pac-container { z-index: 100000 !important; }

/* ---------- LIGHTBOX ---------- */
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.85); display: grid; place-items: center; z-index: 80; }
.lightbox img { max-width: 90vw; max-height: 88vh; border-radius: 6px; box-shadow: 0 10px 50px rgba(0,0,0,.5); }
.lightbox-close { position: absolute; top: 18px; right: 22px; background: none; border: none; color: #fff; font-size: 30px; cursor: pointer; }

/* ---------- CATEGORY / CALENDAR VIEWS ---------- */
.cat-group { margin-bottom: 18px; }
.cat-group-head { display: flex; align-items: center; gap: 10px; font-weight: 600; color: #555; margin-bottom: 8px;
  padding-bottom: 6px; border-bottom: 2px solid var(--line); }
.cat-group-head .cat-total { margin-left: auto; color: var(--orange); }
.calendar { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-head { text-align: center; font-size: 11px; color: var(--muted); font-weight: 600; text-transform: uppercase; padding: 4px; }
.cal-cell { min-height: 76px; border: 1px solid var(--line); border-radius: 5px; padding: 5px; font-size: 11px; }
.cal-cell.empty { background: #fafafa; border-style: dashed; }
.cal-day { color: var(--muted); font-weight: 600; margin-bottom: 3px; }
.cal-exp { background: var(--c-distanza); color: #fff; border-radius: 3px; padding: 2px 4px; margin-bottom: 2px;
  font-size: 10px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-exp.forfait { background: var(--c-forfait); }
.cal-exp.vari { background: var(--c-vari); }

/* ---------- IMPOSTAZIONI ---------- */
.settings-layout { display: grid; grid-template-columns: 240px 1fr; gap: 16px; }
.settings-nav { background: var(--nav-bg); border-radius: var(--radius); padding: 8px; height: fit-content; }
.settings-nav .snav { display: block; width: 100%; text-align: left; background: none; border: none; color: #cfcfcf;
  padding: 12px 14px; border-radius: 6px; cursor: pointer; font-size: 13.5px; font-family: inherit; }
.settings-nav .snav:hover { background: var(--nav-hover); color: #fff; }
.settings-nav .snav.active { background: var(--orange); color: #fff; font-weight: 600; }
.settings-content { min-width: 0; }
/* indicatore di scroll orizzontale della barra tab impostazioni (mobile): frecce a sfumatura ai lati */
.snav-wrap { position: relative; min-width: 0; }
.snav-edge { position: absolute; top: 0; bottom: 0; width: 48px; display: flex; align-items: center;
  color: #fff; font-size: 26px; line-height: 1; opacity: 0; pointer-events: none; transition: opacity .18s; z-index: 3; }
.snav-edge.left { left: 0; justify-content: flex-start; padding-left: 8px;
  background: linear-gradient(to right, var(--nav-bg), transparent); border-radius: var(--radius) 0 0 var(--radius); }
.snav-edge.right { right: 0; justify-content: flex-end; padding-right: 8px;
  background: linear-gradient(to left, var(--nav-bg), transparent); border-radius: 0 var(--radius) var(--radius) 0; }
.snav-wrap.can-left .snav-edge.left,
.snav-wrap.can-right .snav-edge.right { opacity: 1; }
.snav-edge span { display: inline-block; animation: snavPulseR 1.2s ease-in-out infinite; }
.snav-edge.left span { animation-name: snavPulseL; }
@keyframes snavPulseR { 0%,100% { transform: translateX(0); opacity: .8; } 50% { transform: translateX(3px); opacity: 1; } }
@keyframes snavPulseL { 0%,100% { transform: translateX(0); opacity: .8; } 50% { transform: translateX(-3px); opacity: 1; } }
.settings-title { font-size: 24px; font-weight: 400; color: #555; margin-bottom: 16px; }
.settings-pagehead { display: flex; align-items: center; justify-content: space-between; }

.sect { background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 16px; }
.sect-head { color: var(--orange); font-weight: 700; font-size: 14px; padding-bottom: 10px; margin-bottom: 14px; border-bottom: 1px solid var(--line); }
.sect-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 24px; }
.sect-grid label { font-size: 13px; }
.seg-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.seg-row > span { font-size: 13px; font-weight: 600; color: #555; }

/* segmented control (Km/Miglia ecc.) */
.seg { display: inline-flex; border: 1px solid #2f6fbf; border-radius: 6px; overflow: hidden; }
.seg button { background: #fff; color: #2f6fbf; border: none; padding: 8px 18px; cursor: pointer; font-size: 13px; font-family: inherit; }
.seg button + button { border-left: 1px solid #2f6fbf; }
.seg button.on { background: #2f6fbf; color: #fff; }

/* toggle switch */
.switch-lines { margin-top: 6px; }
.switch-line { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px dashed var(--line);
  font-size: 13px; font-weight: 600; color: #555; flex-direction: row; }
.switch-line:last-child { border-bottom: none; }
.sw { appearance: none; -webkit-appearance: none; width: 42px; height: 22px; border-radius: 12px; background: #ccc; position: relative; cursor: pointer; transition: background .15s; flex: none; }
.sw::after { content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: left .15s; }
.sw:checked { background: #2f6fbf; }
.sw:checked::after { left: 22px; }

/* tabella notifiche */
.notif-table { width: 100%; border-collapse: collapse; }
.notif-table th { text-align: center; font-size: 12px; color: var(--muted); padding: 8px; }
.notif-table th:first-child { text-align: left; }
.notif-table td { padding: 10px 8px; border-top: 1px solid var(--line); font-size: 13px; }
.notif-table td.sc { text-align: center; width: 110px; }
.notif-table .sw { display: inline-block; }

/* toolbar veicoli */
.veh-toolbar { display: flex; align-items: center; gap: 16px; margin-bottom: 14px; }
.vt-show { flex-direction: row; align-items: center; gap: 8px; font-size: 13px; color: #555; }
.veh-toolbar #vehSearch { margin-left: auto; min-width: 220px; }

/* tabella veicoli (griglia) */
.veh-grid { display: grid; grid-template-columns: 1.3fr 1.6fr 1.1fr 0.9fr 1fr 36px; gap: 10px; align-items: center; }
.veh-grid input { width: 100%; }
.veh-head { color: var(--muted); font-size: 12px; font-weight: 600; padding: 6px 0 10px; border-bottom: 2px solid var(--line); margin-bottom: 8px; }
.veh-grid.vehicle-row { padding: 7px 0; border-bottom: 1px solid var(--line); }
.veh-grid.vehicle-row:last-child { border-bottom: none; }
/* desktop: gli input riempiono la cella della griglia; etichette per-campo e titolo veicolo nascosti (li mostra il mobile) */
.vf { display: block; min-width: 0; }
.vf input { width: 100%; }
.vf-lbl, .vf-title, .veh-del .vf-del-lbl { display: none; }
/* mobile: ogni veicolo diventa una scheda a righe etichettate, con sfondo alternato e bordo marcato */
@media (max-width: 600px) {
  .veh-head { display: none; }
  .veh-grid.vehicle-row { display: block; padding: 12px 14px; border: 2px solid #c9d4e0;
    border-radius: 12px; margin-bottom: 16px; }
  .veh-grid.vehicle-row:last-child { margin-bottom: 0; border-bottom: 2px solid #c9d4e0; }
  .vr-even { background: #ffffff; }
  .vr-odd { background: #eef4fb; }
  .vf-title { display: block; font-weight: 700; font-size: 15px; color: var(--orange);
    margin: 0 0 10px; padding-bottom: 9px; border-bottom: 2px solid var(--line); }
  .vf { display: flex; align-items: center; gap: 10px; padding: 8px 0; }
  .vf + .vf { border-top: 1px solid rgba(0,0,0,.07); }
  .vf-lbl { display: block; flex: 0 0 44%; color: #555; font-size: 13px; font-weight: 600; }
  .vf input { flex: 1 1 auto; width: auto; min-width: 0; }
  .veh-del { width: 100%; margin-top: 12px; padding: 11px; border: 1px solid #f0c5c5;
    border-radius: 8px; background: #fdecec; color: #d9534f; font-weight: 700; font-size: 14px; text-align: center; }
  .veh-del .vf-del-lbl { display: inline; }
}

/* route toolbar */
.route-toolbar { margin-bottom: 12px; }
.route-pick { margin-bottom: 12px; }
.route-pick select { border-color: var(--orange); }

@media (max-width: 880px) { .settings-layout { grid-template-columns: 1fr; } .sect-grid { grid-template-columns: 1fr; } }

/* ---------- TOAST ---------- */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #2b2b2b; color: #fff;
  padding: 12px 22px; border-radius: 6px; font-weight: 600; z-index: 100; box-shadow: var(--shadow); }

@media (max-width: 880px) {
  .dash-grid { grid-template-columns: 1fr; }
  #view-reports { grid-template-columns: 1fr; }
  /* menu navigazione: striscia scorrevole orizzontale invece che accavallarsi */
  .mainnav { overflow-x: auto; scrollbar-width: none; }
  .mainnav::-webkit-scrollbar { display: none; }
  .mainnav button { flex: 0 0 auto; white-space: nowrap; }
}

/* ---------- TELEFONO (≤600px) ---------- */
@media (max-width: 600px) {
  /* topbar compatta */
  .topbar { padding: 0 8px; gap: 6px; }
  .topbar-left { gap: 6px; min-width: 0; }
  .logo { font-size: 18px; letter-spacing: -.5px; }
  .topbar-title { font-size: 12px; padding-left: 7px; white-space: nowrap; }
  .topbar-right { gap: 8px; }
  .topbar-user { padding: 3px 3px; gap: 5px; }
  .avatar { width: 30px; height: 30px; font-size: 12px; }
  .user-meta strong { font-size: 12px; white-space: nowrap; max-width: 92px; overflow: hidden; text-overflow: ellipsis; }
  .user-meta small { display: none; }
  .view-as-badge { display: none !important; }

  /* menu hamburger */
  .nav-toggle { display: flex; }
  .mainnav { flex-wrap: wrap; overflow: visible; }
  .mainnav .nav-home, .mainnav .nav-item { display: none; width: 100%; text-align: left; height: 46px; padding: 0 18px; font-size: 15px; }
  .mainnav.open .nav-home, .mainnav.open .nav-item { display: flex; align-items: center; border-top: 1px solid rgba(255,255,255,.09); }

  /* contenuto */
  .main { padding: 12px 10px; }
  .card { padding: 14px 13px; }
  /* solo i contenitori di tabella scorrono (non tutta la card): intestazioni e pulsanti restano fermi */
  #reportsTable, #expensesTable, #approvalTable, #reportVehicle, #reportByReport, #confrontoTable, #vehiclesList, #routesList { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .page-head { flex-direction: column; align-items: flex-start; gap: 10px; }
  .page-head h2 { font-size: 19px; }
  .page-head .btn { width: 100%; }
  .ph-actions { width: 100%; flex-direction: column; align-items: stretch; gap: 8px; }
  .ph-actions .cf-yearpick { width: 100%; }
  .ph-actions .cf-yearpick select { flex: 1; }

  /* tabelle: scrollano dentro la card, celle compatte */
  table { font-size: 12px; }
  th { font-size: 11px; padding: 7px 7px; }
  td { padding: 7px 7px; }
  .amount { font-size: 12px; }
  .badge { padding: 3px 8px; font-size: 11px; white-space: nowrap; }

  /* bottoni tap-friendly */
  .btn { min-height: 44px; padding: 11px 15px; display: inline-flex; align-items: center; justify-content: center; }
  .icon-btn { min-width: 40px; min-height: 40px; font-size: 22px; }

  /* dashboard */
  .chart-donut { flex-direction: column; align-items: center; gap: 12px; }
  .chart-donut svg { width: 140px; height: 140px; }
  .legend { width: 100%; }

  /* lista note: filtri come striscia di chip */
  #view-reports { grid-template-columns: 1fr; }
  .filters { display: flex; flex-wrap: wrap; gap: 6px 14px; height: auto; }
  .filters-title { flex: 1 1 100%; margin-bottom: 4px; }
  .filter-check { flex: 0 0 auto; white-space: nowrap; }

  /* dettaglio nota */
  .rh-top { flex-direction: column; align-items: stretch; gap: 10px; }
  .rh-actions { display: flex; flex-wrap: wrap; gap: 6px; }
  .rh-body { flex-direction: column; align-items: stretch; gap: 12px; }
  .rh-title { min-width: 0; }
  .rh-total { margin-left: 0; text-align: left; }
  /* dettaglio nota: intestazione "Spese della nota" + toggle + Nuova spesa vanno a capo, niente overflow */
  .card-head { flex-wrap: wrap; gap: 8px; }
  .card-head .head-right { width: 100%; flex-direction: column; align-items: stretch; gap: 8px; }
  .view-toggle { width: 100%; }
  .view-toggle .vt { flex: 1; padding: 8px 5px; font-size: 12px; }
  .card-head .head-right .btn { width: 100%; }
  /* tabella spese "Lista": nascondi la colonna icona-tipo e giustificativo così sta nello schermo senza scroll */
  #expensesTable .exp-list th:nth-child(2), #expensesTable .exp-list td:nth-child(2),
  #expensesTable .exp-list th:nth-child(5), #expensesTable .exp-list td:nth-child(5) { display: none; }

  /* modali — a prova di overflow orizzontale su qualsiasi larghezza */
  .modal-overlay { padding: 8px 6px 120px; overflow-x: hidden; }
  .modal { max-width: calc(100vw - 12px); width: 100%; border-radius: 8px; }
  .modal-head { padding: 11px 14px; }
  .modal-head h3 { font-size: 15px; }
  #expenseForm, #routeForm { padding: 16px 14px; overflow-x: hidden; }
  .subform, .form-grid, .map-wrap { max-width: 100%; min-width: 0; }
  .map-wrap, .gmap, #expMap, #routeMap, .map-wrap iframe { max-width: 100%; overflow: hidden; }
  .form-grid, .sect-grid { grid-template-columns: minmax(0, 1fr); gap: 11px; }
  /* i campi si restringono davvero (niente min-width:auto che forza la larghezza e taglia) */
  .modal label, .form-grid > *, .sect-grid > *, .addr-row, .km-input, .route-toolbar, .receipt-row { min-width: 0; }
  .modal input, .modal select, .modal textarea { max-width: 100%; min-width: 0; }
  .km-counter { white-space: normal; word-break: break-word; min-width: 0; max-width: 100%; }
  label { font-size: 13px; }
  input, select, textarea { font-size: 16px; padding: 11px 11px; }
  .modal-foot { flex-direction: column-reverse; gap: 8px; }
  .modal-foot .btn { width: 100%; }
  .map-wrap .map-placeholder, .map-wrap iframe, #expMap, #routeMap, .gmap { height: 180px; }
  .route-add-btn { position: static; width: 100%; margin-bottom: 10px; }
  .route-pick { display: flex; flex-direction: column; }
  .route-pick select { width: 100%; }
  .toggles { flex-direction: column; gap: 12px; align-items: flex-start; }
  .receipt-row { flex-direction: column; align-items: stretch; gap: 10px; }

  /* impostazioni */
  .settings-layout { grid-template-columns: 1fr; }
  .settings-nav { display: flex; overflow-x: auto; gap: 4px; padding: 6px; }
  .settings-nav .snav { flex: 0 0 auto; white-space: nowrap; width: auto; }
  .settings-pagehead { flex-direction: column; align-items: flex-start; gap: 8px; }
  .settings-pagehead .btn { width: 100%; }
  .seg { width: 100%; }
  .seg button { flex: 1; padding: 8px 6px; font-size: 12px; }
  .veh-toolbar { flex-direction: column; align-items: stretch; gap: 8px; }
  .veh-toolbar #vehSearch { min-width: 0; width: 100%; margin-left: 0; }

  /* confronto */
  .cf-sumbar { padding: 12px 12px; }

  /* banner impronta */
  .bio-offer { flex-direction: column; align-items: stretch; gap: 8px; }
  .bio-offer-actions { display: flex; gap: 8px; }
  .bio-offer-actions .btn { flex: 1; }

  /* login */
  .login-overlay { padding: 12px 10px; }
  .login-card { max-width: 100%; padding: 26px 20px; }

  /* menu profilo a tutta larghezza */
  .profile-menu { position: fixed; top: 52px; left: 0; right: 0; width: 100%; min-width: 0; max-height: 60vh; overflow-y: auto; border-radius: 0; }
}

/* ============ Login overlay + indicatore sync ============ */
.login-overlay { position: fixed; inset: 0; z-index: 5000; display: grid; place-items: center;
  background: linear-gradient(135deg, #2b2b2b 0%, #1a1a1a 100%); padding: 20px; }
.login-card { background: var(--white); border-radius: 10px; box-shadow: 0 20px 60px rgba(0,0,0,.45);
  width: 100%; max-width: 380px; padding: 32px 30px 30px; display: flex; flex-direction: column; }
.login-logo { font-size: 30px; font-weight: 800; color: var(--nav-bg); letter-spacing: .5px; align-self: center; }
.login-logo span { color: var(--orange); }
.login-title { font-size: 16px; color: var(--muted); align-self: center; margin-top: 2px; }
.login-sub { text-align: center; color: var(--muted); font-size: 13px; margin: 14px 0 20px; }
.login-card label { font-size: 12px; font-weight: 600; color: var(--muted); margin: 10px 2px 5px; }
.login-card input { padding: 11px 12px; border: 1px solid var(--line); border-radius: var(--radius);
  font-size: 14px; outline: none; transition: border-color .15s; }
.login-card input:focus { border-color: var(--orange); }
.login-err { color: var(--c-forfait); font-size: 13px; min-height: 18px; margin: 8px 2px 0; }
.login-btn { margin-top: 12px; padding: 12px; border: none; border-radius: var(--radius); cursor: pointer;
  background: var(--orange); color: #fff; font-size: 15px; font-weight: 600; transition: background .15s; }
.login-btn:hover { background: var(--orange-dark); }
.login-btn:disabled { opacity: .7; cursor: default; }

/* accesso con impronta: pulsante nel login */
.login-bio { margin-top: 8px; padding: 13px; border: 2px solid var(--orange); border-radius: var(--radius);
  background: #fff6ef; color: var(--orange-dark); font-size: 15px; font-weight: 700; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 8px; transition: all .15s; }
.login-bio:hover { background: var(--orange); color: #fff; }
.login-bio:disabled { opacity: .7; cursor: default; }
.login-div { display: flex; align-items: center; text-align: center; color: var(--muted); font-size: 12px; margin: 16px 0 4px; }
.login-div::before, .login-div::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.login-div span { padding: 0 10px; }

.sync-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-right: 6px;
  background: var(--muted); flex: 0 0 auto; }
.sync-dot.ok { background: var(--green); }
.sync-dot.sync { background: var(--st-elaborazione); animation: syncpulse 1s infinite; }
.sync-dot.err { background: var(--c-forfait); }
@keyframes syncpulse { 0%,100% { opacity: 1; } 50% { opacity: .3; } }

/* ============ Admin: "vedi come" (switch profilo) ============ */
.view-as-badge { margin-left: 12px; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 600;
  background: rgba(255,255,255,.22); color: #fff; white-space: nowrap; align-self: center; }
.pm-you { color: var(--muted); font-weight: 400; }

/* ============ Stato "Pagata" + tabella spese ordinabile + errore spesa ============ */
:root { --st-pagata: #2d9d5a; }
.badge.pagata { background: var(--st-pagata); }
.dot.pagata { background: var(--st-pagata); }
.th-sort { cursor: pointer; user-select: none; }
.th-sort:hover { color: var(--orange); }
.exp-error { color: var(--c-forfait); font-size: 13px; font-weight: 600; min-height: 18px; margin: 8px 2px 0; text-align: right; }

/* badge "Pagata" sbloccabile (sicurezza con possibilità di modifica) */
.badge-lock { cursor: pointer; }
.badge-lock:hover { filter: brightness(1.12); box-shadow: 0 0 0 2px rgba(255,255,255,.6); }

/* pulsante "Nuovo percorso" in alto a destra del riquadro percorso (modale spesa) */
#fieldsKm { position: relative; }
.route-add-btn { position: absolute; top: -15px; right: 10px; z-index: 3; padding: 6px 14px;
  font-size: 13px; font-weight: 600; box-shadow: 0 2px 8px rgba(0,0,0,.22); }

/* suggerimento sotto la mappa (percorso trascinabile) */
.map-hint { display: block; margin-top: 6px; color: var(--muted); font-size: 12px; line-height: 1.4; }

/* campo indirizzo con tasto casa 🏠 */
.addr-row { display: flex; gap: 6px; align-items: stretch; }
.addr-row input { flex: 1; min-width: 0; }
.home-btn { flex: none; border: 1px solid var(--line); background: #f3f3f3; border-radius: var(--radius);
  cursor: pointer; font-size: 16px; padding: 0 12px; line-height: 1; }
.home-btn:hover { background: #ffe9d6; border-color: var(--orange); }

/* ============ Confronto rimborsi (solo admin) ============ */
#view-confronto { display: flex; flex-direction: column; gap: 14px; }
.cf-yearpick { display: flex; align-items: center; gap: 8px; font-size: 13px; color: #555; }
.cf-yearpick select { padding: 6px 10px; border: 1px solid var(--line); border-radius: 6px; font-family: inherit; font-size: 14px; }
.cf-tablewrap { overflow-x: auto; }
.cf-table { min-width: 460px; }
.cf-table th.cf-h { text-align: center; color: var(--ink); font-size: 13px; }
.cf-table th.cf-diff, .cf-table td.cf-diff { text-align: center; white-space: nowrap; color: #777; font-weight: 600; }
.cf-table td.cf-month { font-weight: 600; color: #555; white-space: nowrap; }
.cf-table tbody tr { cursor: default; }
.cf-table td.cf-cell { text-align: center; padding: 6px; }
.cf-table td.cf-empty { color: #ccc; }
.cf-pick { display: inline-flex; align-items: center; gap: 9px; cursor: pointer; padding: 6px 12px; border-radius: 7px; transition: background .12s; }
.cf-pick:hover { background: #fff4ec; }
.cf-pick input { width: 17px; height: 17px; accent-color: var(--orange); cursor: pointer; flex: none; }
.cf-pick:has(input:checked) { background: #ffe9d6; outline: 1px solid var(--orange); }
.cf-amt { font-weight: 700; white-space: nowrap; display: flex; flex-direction: column; align-items: flex-start; line-height: 1.1; }
.cf-paid { font-weight: 600; font-size: 10px; color: var(--st-pagata); margin-top: 2px; }
.cf-diff small { color: var(--orange); font-weight: 700; }
.cf-table tfoot .cf-totrow td { border-top: 2px solid var(--orange); border-bottom: none; text-align: center;
  font-weight: 800; color: var(--orange-dark); background: #fff8f2; }
.cf-table tfoot .cf-totrow td:first-child { text-align: left; color: #555; }

/* barra somma bonifico (resta visibile in basso) */
.cf-sumbar { position: sticky; bottom: 14px; border: 2px solid var(--orange); box-shadow: 0 6px 20px rgba(0,0,0,.12); }
.cf-sum-empty { color: var(--muted); font-size: 13px; }
.cf-sum-title { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 8px; }
.cf-sum-row { display: flex; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.cf-sum-name { font-weight: 700; flex: 1; }
.cf-sum-n { color: var(--muted); font-size: 12px; }
.cf-sum-val { font-size: 18px; color: var(--orange-dark); min-width: 120px; text-align: right; }
.cf-sum-grand { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 10px; padding-top: 10px; border-top: 2px solid var(--line); }
.cf-sum-grand strong { font-size: 21px; color: var(--orange); }
.cf-sumbar #cfClear { margin-top: 12px; }

/* ============ Accesso con impronta: banner + impostazioni ============ */
.bio-offer { background: #fff6ef; border-bottom: 1px solid #ffd9b8; padding: 12px 18px;
  display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; }
.bio-offer > span { color: #8a3d00; font-weight: 600; font-size: 14px; }
.bio-offer-actions { display: flex; gap: 8px; }
.bio-pw { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.bio-pw input { padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); font-size: 14px;
  outline: none; min-width: 220px; flex: 1; }
.bio-pw input:focus { border-color: var(--orange); }
