:root {
  --blue: #1b3a6e; --blue2: #2a5298; --pink: #e6007e; --bg: #f3f5f9; --card: #fff; --line: #dfe4ec;
  --text: #1f2430; --muted: #6c7a90; --ok: #1f9d55; --warn: #e8a33d; --bad: #c62828; --radius: 10px;
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 15px/1.4 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; background: var(--bg); color: var(--text); -webkit-tap-highlight-color: transparent; }
a { color: var(--blue2); text-decoration: none; }
button, input, select, textarea { font: inherit; }
h1 { font-size: 22px; margin: 0 0 12px; color: var(--blue); }
h2 { font-size: 17px; margin: 0 0 10px; color: var(--blue); }
h3 { font-size: 14px; margin: 14px 0 6px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

/* layout */
#app { display: flex; min-height: 100vh; }
.sidebar { width: 230px; background: var(--blue); color: #fff; padding: calc(14px + var(--sat)) 12px 14px; position: sticky; top: 0; height: 100vh; flex-shrink: 0; display: flex; flex-direction: column; }
.sidebar .brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; font-weight: 800; font-size: 19px; }
.sidebar .brand img { height: 34px; background: #fff; border-radius: 6px; padding: 2px 6px; }
.sidebar nav a { display: flex; align-items: center; gap: 10px; color: #dbe4f3; padding: 10px 12px; border-radius: 8px; margin: 2px 0; font-weight: 500; }
.sidebar nav a.active, .sidebar nav a:hover { background: rgba(255,255,255,.14); color: #fff; }
.sidebar nav a .ic { width: 22px; text-align: center; font-size: 17px; }
.sidebar .user { margin-top: auto; font-size: 13px; color: #c7d3e8; padding: 10px 12px; border-top: 1px solid rgba(255,255,255,.15); }
.sidebar .user b { color: #fff; display: block; }
.sidebar .user button { margin-top: 8px; }
.main { flex: 1; min-width: 0; padding: calc(18px + var(--sat)) 22px calc(28px + var(--sab)); }
.topbar { display: none; }
.tabbar { display: none; }

@media (max-width: 900px) {
  .sidebar { display: none; }
  .main { padding: calc(58px + var(--sat)) 12px calc(76px + var(--sab)); }
  .topbar { display: flex; position: fixed; top: 0; left: 0; right: 0; height: calc(50px + var(--sat)); padding-top: var(--sat); background: var(--blue); color: #fff; align-items: center; justify-content: space-between; padding-left: 14px; padding-right: 10px; z-index: 20; font-weight: 700; font-size: 17px; }
  .topbar img { height: 26px; background: #fff; border-radius: 5px; padding: 2px 5px; }
  .tabbar { display: flex; position: fixed; bottom: 0; left: 0; right: 0; background: #fff; border-top: 1px solid var(--line); z-index: 20; padding-bottom: var(--sab); }
  .tabbar a { flex: 1; text-align: center; padding: 8px 2px 6px; font-size: 11px; color: var(--muted); }
  .tabbar a .ic { display: block; font-size: 21px; }
  .tabbar a.active { color: var(--blue); font-weight: 700; }
  h1 { font-size: 20px; }
}

/* components */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.card.tight { padding: 10px 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.grid.g2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid.g4 { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.kpi .l { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.kpi .v { font-size: 24px; font-weight: 800; color: var(--blue); margin-top: 2px; }
.kpi .v.ok { color: var(--ok); } .kpi .v.bad { color: var(--bad); }
.kpi .s { font-size: 12px; color: var(--muted); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; background: var(--blue2); color: #fff; border: 0; border-radius: 8px; padding: 10px 16px; font-weight: 600; cursor: pointer; min-height: 42px; white-space: nowrap; }
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.sec { background: #e8edf5; color: var(--blue); }
.btn.ghost { background: transparent; color: var(--blue2); border: 1px solid var(--line); }
.btn.danger { background: var(--bad); }
.btn.ok { background: var(--ok); }
.btn.pink { background: var(--pink); }
.btn.sm { padding: 6px 10px; min-height: 32px; font-size: 13px; }
.btn.lg { padding: 14px 22px; font-size: 17px; min-height: 52px; }
.btn.block { width: 100%; }
.btn.light { background: #fff; color: var(--blue); }

label.f { display: block; margin-bottom: 10px; }
label.f span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 3px; font-weight: 600; }
input, select, textarea { width: 100%; border: 1px solid #c9d1de; border-radius: 8px; padding: 10px 11px; background: #fff; min-height: 42px; color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid #9db6e6; border-color: var(--blue2); }
textarea { min-height: 70px; resize: vertical; }
input[type=checkbox] { width: auto; min-height: 0; transform: scale(1.3); margin-right: 8px; }
.form { display: grid; gap: 0 14px; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.form .full { grid-column: 1 / -1; }
.help { color: var(--muted); font-size: 12px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; color: var(--muted); letter-spacing: .03em; }
td.r, th.r { text-align: right; }
tr.click { cursor: pointer; } tr.click:hover td { background: #f6f8fc; }
.tbl { overflow-x: auto; }

.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.b-disponibile, .b-chiuso { background: #dff3e6; color: #1f7a3f; }
.b-noleggiato, .b-in_corso { background: #dbe7fb; color: #1b4b9e; }
.b-prenotato { background: #fff1d6; color: #9a5a00; }
.b-manutenzione { background: #ece4ff; color: #5a2ea6; }
.b-fuori_servizio, .b-annullato, .b-late { background: #fde0e0; color: #a01717; }
.b-lieve { background: #fff1d6; color: #9a5a00; } .b-medio { background: #ffe0d1; color: #a13a12; } .b-grave { background: #fde0e0; color: #a01717; }

.list a.item, .list .item { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 6px; border-bottom: 1px solid var(--line); color: var(--text); }
.list .item:last-child { border-bottom: 0; }
.list .item .t { font-weight: 600; } .list .item .s { color: var(--muted); font-size: 13px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.right { text-align: right; }
.money { font-variant-numeric: tabular-nums; white-space: nowrap; }
.empty { color: var(--muted); padding: 24px; text-align: center; }
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tabs a { padding: 9px 14px; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -2px; white-space: nowrap; }
.tabs a.active { color: var(--blue); border-color: var(--blue); }
.steps { display: flex; gap: 6px; margin-bottom: 14px; flex-wrap: wrap; }
.steps span { flex: 1; text-align: center; padding: 8px 4px; border-radius: 8px; background: #e8edf5; color: var(--muted); font-size: 12px; font-weight: 700; min-width: 90px; }
.steps span.done { background: #dff3e6; color: #1f7a3f; } .steps span.cur { background: var(--blue); color: #fff; }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(20,30,50,.55); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
@media (min-width: 700px) { .modal-bg { align-items: center; } }
.modal { background: #fff; width: 100%; max-width: 760px; max-height: 94vh; overflow: auto; border-radius: 14px 14px 0 0; padding: 18px; }
@media (min-width: 700px) { .modal { border-radius: 14px; } }
.modal.wide { max-width: 1000px; }
.modal h2 { display: flex; justify-content: space-between; align-items: center; }
.modal .x { background: none; border: 0; font-size: 24px; cursor: pointer; color: var(--muted); }

/* toast */
#toasts { position: fixed; top: calc(12px + var(--sat)); right: 12px; left: 12px; z-index: 100; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; pointer-events: none; }
.toast { background: #222; color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,.25); max-width: 480px; font-weight: 500; }
.toast.err { background: var(--bad); } .toast.ok { background: var(--ok); }

/* login */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; background: linear-gradient(140deg, var(--blue) 0%, var(--blue2) 60%, #4a7bd0 100%); width: 100%; }
.login .card { width: 100%; max-width: 380px; padding: 28px; }
.login img { display: block; margin: 0 auto 16px; height: 56px; }

/* fuel */
.fuel { display: flex; gap: 4px; }
.fuel button { flex: 1; height: 44px; border: 1px solid #c9d1de; background: #fff; border-radius: 6px; cursor: pointer; font-size: 12px; color: var(--muted); }
.fuel button.on { background: var(--blue2); border-color: var(--blue2); color: #fff; }
.fuel button.cur { outline: 2px solid var(--pink); }

/* car map */
.carmap { position: relative; display: inline-block; width: 100%; max-width: 380px; user-select: none; touch-action: manipulation; }
.carmap img { width: 100%; display: block; pointer-events: none; }
.carmap .mark { position: absolute; width: 26px; height: 26px; margin: -13px 0 0 -13px; border-radius: 50%; color: #fff; font-weight: 800; font-size: 12px; text-align: center; line-height: 24px; border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.4); cursor: pointer; }
.carmap .mark.lieve { background: var(--warn); } .carmap .mark.medio { background: #e05a2b; } .carmap .mark.grave { background: var(--bad); }
.carmap .mark.prev { background: #6c7a90; }
.carmap .mark.sel { outline: 3px solid var(--pink); }
.carmap.crosshair { cursor: crosshair; }

/* photos */
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.photos .ph { position: relative; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); background: #eef1f6; aspect-ratio: 4/3; }
.photos .ph img { width: 100%; height: 100%; object-fit: cover; display: block; cursor: zoom-in; }
.photos .ph .cap { position: absolute; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,.55); color: #fff; font-size: 11px; padding: 3px 6px; }
.photos .ph .del { position: absolute; top: 4px; right: 4px; background: rgba(0,0,0,.6); color: #fff; border: 0; border-radius: 50%; width: 26px; height: 26px; cursor: pointer; }
.photos .add { border: 2px dashed #b8c2d3; border-radius: 8px; display: flex; align-items: center; justify-content: center; color: var(--muted); aspect-ratio: 4/3; cursor: pointer; font-size: 13px; text-align: center; }
.compare { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.compare .ph { aspect-ratio: 4/3; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); background: #eef1f6; }
.compare .ph img { width: 100%; height: 100%; object-fit: cover; display: block; }
.compare .lab { text-align: center; font-size: 12px; color: var(--muted); font-weight: 700; margin-bottom: 4px; }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.9); z-index: 90; display: flex; align-items: center; justify-content: center; }
.lightbox img { max-width: 98vw; max-height: 96vh; object-fit: contain; }

/* signature */
.sigpad { border: 2px dashed #9aa5b5; border-radius: 10px; background: #fff; touch-action: none; width: 100%; height: 220px; display: block; }
.sigimg { max-height: 90px; border: 1px solid var(--line); border-radius: 8px; background: #fff; padding: 4px; }

/* calendar */
.cal { overflow-x: auto; }
.cal table { border-collapse: separate; border-spacing: 0; min-width: 900px; }
.cal th, .cal td { padding: 0; border-bottom: 1px solid var(--line); border-right: 1px solid #edf0f5; height: 36px; }
.cal th { font-size: 11px; padding: 6px 2px; text-align: center; background: #f6f8fc; position: sticky; top: 0; }
.cal th.today, .cal td.today { background: #fff7e0; }
.cal th.we { color: #a01717; }
.cal td.veh { position: sticky; left: 0; background: #fff; padding: 4px 8px; font-size: 13px; font-weight: 600; white-space: nowrap; min-width: 160px; z-index: 2; }
.cal td.veh .p { color: var(--muted); font-weight: 400; font-size: 12px; }
.cal .bar { position: absolute; top: 5px; height: 26px; border-radius: 6px; color: #fff; font-size: 11px; line-height: 26px; padding: 0 8px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; cursor: pointer; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.cal .bar.in_corso { background: var(--blue2); } .cal .bar.prenotato { background: var(--warn); } .cal .bar.chiuso { background: #8fa3bf; } .cal .bar.manutenzione, .cal .bar.fuori_servizio { background: #7e57c2; }
.cal .track { position: relative; height: 36px; }
.cal .month { font-size: 12px; font-weight: 800; color: var(--blue); text-align: left !important; padding-left: 6px !important; }

/* misc */
.bar-h { height: 10px; background: #e8edf5; border-radius: 6px; overflow: hidden; }
.bar-h i { display: block; height: 100%; background: var(--blue2); }
.chart { display: flex; gap: 6px; align-items: flex-end; height: 140px; padding-top: 10px; }
.chart .c { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 10px; color: var(--muted); height: 100%; justify-content: flex-end; }
.chart .c .bars { display: flex; gap: 2px; align-items: flex-end; height: 100%; width: 100%; justify-content: center; }
.chart .c .bars i { display: block; width: 40%; max-width: 22px; border-radius: 3px 3px 0 0; }
.chart .c .bars i.rev { background: var(--blue2); } .chart .c .bars i.cost { background: #e07a5f; }
.pill-row { display: flex; gap: 6px; flex-wrap: wrap; }
.pill { padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: #fff; cursor: pointer; font-size: 13px; font-weight: 600; color: var(--muted); }
.pill.on { background: var(--blue); color: #fff; border-color: var(--blue); }
.warn-box { background: #fff7e0; border: 1px solid #f3d27a; border-radius: 8px; padding: 10px 12px; color: #7a4d00; }
.ok-box { background: #e6f6ec; border: 1px solid #a9dcb8; border-radius: 8px; padding: 10px 12px; color: #1f7a3f; }
.bad-box { background: #fde0e0; border: 1px solid #f1a5a5; border-radius: 8px; padding: 10px 12px; color: #a01717; }
.sticky-actions { position: sticky; bottom: calc(var(--sab)); background: linear-gradient(transparent, var(--bg) 30%); padding: 14px 0 4px; display: flex; gap: 10px; }
@media (max-width: 900px) { .sticky-actions { bottom: calc(60px + var(--sab)); } }
.hide-m { } @media (max-width: 900px) { .hide-m { display: none !important; } }
.only-m { display: none !important; } @media (max-width: 900px) { .only-m { display: initial !important; } }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 0; }
dl.kv dt { color: var(--muted); font-size: 13px; } dl.kv dd { margin: 0; font-weight: 600; }

/* scansione documenti (OCR) */
.scan-slots { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.scan-slots .add { background-size: cover; background-position: center; position: relative; }
.scan-slots .add > span { position: relative; z-index: 1; background: rgba(255,255,255,.85); border-radius: 6px; padding: 6px 8px; }
.scan-slots .add.done { border-style: solid; border-color: var(--ok); }
.scan-slots .add.busy { opacity: .6; pointer-events: none; }
.ocr-hit { background: #fff8dc !important; border-color: var(--warn) !important; }
