/* ===== Garage — stile ===== */
:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #eef1f7;
  --border: #e2e7f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-ink: #ffffff;
  --primary-soft: #e0eaff;
  --ok: #16a34a;     --ok-soft: #dcfce7;
  --warn: #d97706;   --warn-soft: #fef3c7;
  --bad: #dc2626;    --bad-soft: #fee2e2;
  --done: #94a3b8;   --done-soft: #f1f5f9;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 16px rgba(15, 23, 42, .06);
  --shadow-lg: 0 10px 40px rgba(15, 23, 42, .18);
  --radius: 18px;
  --radius-sm: 12px;
  --nav-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1120; --surface: #131c2e; --surface-2: #1b2638; --border: #253149;
    --text: #e8edf6; --muted: #94a3b8; --primary: #4f8cff; --primary-soft: #1c2c4d;
    --ok: #22c55e; --ok-soft: #12301f; --warn: #f59e0b; --warn-soft: #3a2a0c;
    --bad: #f87171; --bad-soft: #3b1515; --done: #64748b; --done-soft: #1b2638;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1120; --surface: #131c2e; --surface-2: #1b2638; --border: #253149;
  --text: #e8edf6; --muted: #94a3b8; --primary: #4f8cff; --primary-soft: #1c2c4d;
  --ok: #22c55e; --ok-soft: #12301f; --warn: #f59e0b; --warn-soft: #3a2a0c;
  --bad: #f87171; --bad-soft: #3b1515; --done: #64748b; --done-soft: #1b2638;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
a { color: var(--primary); text-decoration: none; }
img { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.6rem; font-weight: 750; letter-spacing: -.02em; }
h2 { font-size: 1.15rem; font-weight: 700; }
h3 { font-size: 1rem; font-weight: 650; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .03em; }
.splash { min-height: 100vh; display: grid; place-items: center; }
.splash img { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(.92); opacity: .7; } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: none; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* ===== Layout ===== */
.layout { min-height: 100vh; }
.main {
  max-width: 1100px; margin: 0 auto;
  padding: calc(16px + var(--safe-t)) 16px calc(var(--nav-h) + 96px + var(--safe-b));
  animation: fadeUp .25s ease;
}
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.page-head h1 { flex: 1; min-width: 0; }
.back { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; background: var(--surface); box-shadow: var(--shadow); border: 0; cursor: pointer; flex: none; }

.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  height: calc(var(--nav-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  display: flex; background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); border-top: 1px solid var(--border);
}
.bottom-nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font-size: .72rem; font-weight: 600; position: relative;
}
.bottom-nav a.active { color: var(--primary); }
.bottom-nav .dot { position: absolute; top: 8px; left: calc(50% + 8px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--bad); color: #fff; font-size: .68rem; display: grid; place-items: center; }

.side-nav { display: none; }
@media (min-width: 900px) {
  .bottom-nav { display: none; }
  .side-nav {
    display: flex; flex-direction: column; gap: 4px; position: fixed; top: 0; bottom: 0; left: 0; width: 232px;
    padding: 24px 14px; background: var(--surface); border-right: 1px solid var(--border); z-index: 20;
  }
  .side-nav .brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.2rem; padding: 0 10px 18px; }
  .side-nav a { display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: 12px; color: var(--muted); font-weight: 600; position: relative; }
  .side-nav a:hover { background: var(--surface-2); }
  .side-nav a.active { background: var(--primary-soft); color: var(--primary); }
  .side-nav .dot { margin-left: auto; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px; background: var(--bad); color: #fff; font-size: .75rem; display: grid; place-items: center; }
  .layout.with-nav .main { margin-left: 232px; padding-left: 32px; padding-right: 32px; padding-bottom: 120px; max-width: 1180px; }
}

/* ===== Card & griglie ===== */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card + .card { margin-top: 12px; }
.section { margin-top: 24px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.stats { display: grid; gap: 10px; grid-template-columns: repeat(2, 1fr); }
@media (min-width: 700px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--surface); border-radius: var(--radius-sm); box-shadow: var(--shadow); padding: 12px 14px; }
.stat .v { font-size: 1.45rem; font-weight: 750; letter-spacing: -.02em; }
.stat .l { color: var(--muted); font-size: .8rem; font-weight: 600; }
.stat.bad .v { color: var(--bad); } .stat.warn .v { color: var(--warn); }

.vcard { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; cursor: pointer; transition: transform .15s ease, box-shadow .15s ease; display: block; color: inherit; }
.vcard:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.vcard:active { transform: scale(.985); }
.vcard .cover { aspect-ratio: 16 / 10; background: var(--surface-2); position: relative; display: grid; place-items: center; color: var(--muted); }
.vcard .cover img { width: 100%; height: 100%; object-fit: cover; }
.vcard .cover .badges { position: absolute; top: 10px; left: 10px; right: 10px; display: flex; justify-content: space-between; gap: 6px; }
.vcard .body { padding: 12px 14px 14px; }
.vcard .title { font-weight: 700; font-size: 1.05rem; }
.vcard .meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin-top: 6px; color: var(--muted); font-size: .85rem; }
.plate { display: inline-block; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-weight: 700; font-size: .8rem; letter-spacing: .06em; padding: 2px 8px; border-radius: 6px; background: var(--surface); color: var(--text); border: 1.5px solid var(--border); }

/* ===== Stati colorati ===== */
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 999px; font-size: .75rem; font-weight: 700; white-space: nowrap; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.soon { background: var(--warn-soft); color: var(--warn); }
.pill.overdue { background: var(--bad-soft); color: var(--bad); }
.pill.done { background: var(--done-soft); color: var(--done); }
.pill.neutral { background: var(--surface-2); color: var(--muted); }
.pill.glass { background: rgba(15, 23, 42, .55); color: #fff; backdrop-filter: blur(6px); }

.ritem { display: flex; gap: 12px; align-items: center; padding: 12px 14px; border-radius: var(--radius-sm); background: var(--surface); box-shadow: var(--shadow); border-left: 5px solid var(--ok); cursor: pointer; color: inherit; }
.ritem + .ritem { margin-top: 8px; }
.ritem.soon { border-left-color: var(--warn); }
.ritem.overdue { border-left-color: var(--bad); }
.ritem.done { border-left-color: var(--done); opacity: .75; }
.ritem .grow { flex: 1; min-width: 0; }
.ritem .t { font-weight: 650; }
.ritem .s { color: var(--muted); font-size: .84rem; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.list { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.list .row { display: flex; align-items: center; gap: 12px; padding: 13px 14px; border-bottom: 1px solid var(--border); color: inherit; cursor: pointer; }
.list .row:last-child { border-bottom: 0; }
.list .row:hover { background: var(--surface-2); }
.list .row .grow { flex: 1; min-width: 0; }
.thumb { width: 52px; height: 52px; border-radius: 10px; object-fit: cover; background: var(--surface-2); display: grid; place-items: center; color: var(--muted); flex: none; overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }

/* ===== Hero della scheda mezzo ===== */
.hero { border-radius: var(--radius); overflow: hidden; background: var(--surface); box-shadow: var(--shadow); }
.hero .photo { aspect-ratio: 16 / 9; max-height: 380px; width: 100%; background: var(--surface-2); position: relative; display: grid; place-items: center; color: var(--muted); }
.hero .photo img { width: 100%; height: 100%; object-fit: cover; }
.hero .info { padding: 14px 16px 16px; display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.hero .info .grow { flex: 1; min-width: 200px; }
.km-btn { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: 14px; background: var(--primary-soft); color: var(--primary); border: 0; cursor: pointer; font-weight: 700; }
.km-btn .n { font-size: 1.2rem; }

.tabs { display: flex; gap: 6px; overflow-x: auto; padding: 4px; margin: 16px 0 14px; background: var(--surface-2); border-radius: 14px; scrollbar-width: none; position: sticky; top: calc(var(--safe-t) + 6px); z-index: 10; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { flex: 1 0 auto; border: 0; background: transparent; padding: 9px 14px; border-radius: 10px; font-weight: 650; color: var(--muted); cursor: pointer; white-space: nowrap; font-size: .92rem; }
.tabs button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.gallery .g { position: relative; aspect-ratio: 1; border-radius: 12px; overflow: hidden; background: var(--surface-2); cursor: pointer; border: 3px solid transparent; }
.gallery .g.cover { border-color: var(--primary); }
.gallery .g img { width: 100%; height: 100%; object-fit: cover; }
.gallery .g .star { position: absolute; top: 4px; right: 4px; }

.kv { display: grid; grid-template-columns: 1fr; gap: 0; }
@media (min-width: 600px) { .kv { grid-template-columns: 1fr 1fr; column-gap: 24px; } }
.kv div { padding: 9px 0; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; gap: 12px; }
.kv dt { color: var(--muted); font-size: .9rem; }
.kv dd { margin: 0; font-weight: 600; text-align: right; overflow-wrap: anywhere; }

/* ===== Pulsanti ===== */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding: 0 18px; border-radius: 14px; border: 0; background: var(--surface-2); color: var(--text); font-weight: 650; cursor: pointer; transition: transform .1s ease, filter .15s; text-align: center; }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--primary); color: var(--primary-ink); }
.btn.danger { background: var(--bad-soft); color: var(--bad); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 36px; padding: 0 12px; border-radius: 10px; font-size: .88rem; }
.btn.block { width: 100%; }
.btn.icon { width: 44px; padding: 0; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row > .btn { flex: 1 1 auto; }

.fab {
  position: fixed; right: 18px; bottom: calc(var(--nav-h) + 18px + var(--safe-b)); z-index: 35;
  width: 62px; height: 62px; border-radius: 22px; border: 0; cursor: pointer;
  background: var(--primary); color: #fff; box-shadow: 0 8px 24px color-mix(in srgb, var(--primary) 45%, transparent);
  display: grid; place-items: center; transition: transform .2s ease;
}
.fab.open { transform: rotate(45deg); }
@media (min-width: 900px) { .fab { bottom: 28px; right: 28px; } }
.fab-menu { position: fixed; right: 18px; bottom: calc(var(--nav-h) + 92px + var(--safe-b)); z-index: 35; display: flex; flex-direction: column; align-items: flex-end; gap: 10px; }
@media (min-width: 900px) { .fab-menu { bottom: 102px; right: 28px; } }
.fab-menu button { display: flex; align-items: center; gap: 10px; border: 0; cursor: pointer; padding: 12px 18px 12px 14px; border-radius: 16px; background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg); font-weight: 650; animation: fadeUp .18s ease both; }
.fab-menu button .ic { width: 36px; height: 36px; border-radius: 11px; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; }
.scrim { position: fixed; inset: 0; background: rgba(2, 6, 23, .45); z-index: 34; animation: fadeIn .15s ease; }

/* ===== Ricerca e filtri ===== */
.search { display: flex; align-items: center; gap: 10px; background: var(--surface); border-radius: 14px; padding: 0 14px; box-shadow: var(--shadow); height: 48px; }
.search input { flex: 1; border: 0; outline: 0; background: transparent; height: 100%; min-width: 0; font-size: 1rem; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 6px; margin-top: 12px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1.5px solid var(--border); background: var(--surface); padding: 7px 14px; border-radius: 999px; font-weight: 600; font-size: .88rem; cursor: pointer; color: var(--muted); }
.chip.active { background: var(--text); border-color: var(--text); color: var(--bg); }

/* ===== Moduli ===== */
.form { display: grid; gap: 14px; }
.form .two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field { display: grid; gap: 6px; }
.field > span { font-size: .85rem; font-weight: 650; color: var(--muted); }
.field input, .field select, .field textarea {
  width: 100%; min-height: 48px; padding: 10px 14px; border-radius: 12px; border: 1.5px solid var(--border);
  background: var(--surface); outline: none; font-size: 16px; /* 16px evita lo zoom automatico su iPhone */
}
.field textarea { min-height: 90px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-soft); }
.field .hint { font-size: .8rem; color: var(--muted); }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; }
.check input { width: 22px; height: 22px; accent-color: var(--primary); }
.seg { display: flex; background: var(--surface-2); border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { flex: 1; border: 0; background: transparent; border-radius: 9px; padding: 9px 6px; font-weight: 650; color: var(--muted); cursor: pointer; font-size: .9rem; }
.seg button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.error { background: var(--bad-soft); color: var(--bad); padding: 10px 14px; border-radius: 12px; font-weight: 600; white-space: pre-line; }
.notice { background: var(--primary-soft); color: var(--primary); padding: 10px 14px; border-radius: 12px; font-size: .9rem; }

/* ===== Finestre (sheet) ===== */
.sheet-wrap { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet-wrap .scrim { z-index: 0; }
.sheet {
  position: relative; z-index: 1; width: 100%; max-width: 640px; max-height: 92vh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--bg); border-radius: 24px 24px 0 0; padding: 8px 18px calc(22px + var(--safe-b)); animation: slideUp .22s cubic-bezier(.2, .8, .2, 1);
}
.sheet .grip { width: 44px; height: 5px; border-radius: 3px; background: var(--border); margin: 4px auto 12px; }
.sheet .sheet-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.sheet .sheet-head h2 { flex: 1; }
@media (min-width: 700px) {
  .sheet-wrap { align-items: center; padding: 24px; }
  .sheet { border-radius: 24px; padding-bottom: 22px; animation: fadeUp .2s ease; }
  .sheet .grip { display: none; }
}

.toast-wrap { position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + 96px + var(--safe-b)); z-index: 60; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 16px; }
.toast { background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 14px; box-shadow: var(--shadow-lg); font-weight: 600; animation: fadeUp .2s ease; max-width: 520px; pointer-events: auto; }
.toast.err { background: var(--bad); color: #fff; }

/* ===== Visualizzatore file ===== */
.viewer { position: fixed; inset: 0; z-index: 70; background: #000; display: flex; flex-direction: column; animation: fadeIn .15s ease; }
.viewer .bar { display: flex; align-items: center; gap: 8px; padding: calc(10px + var(--safe-t)) 12px 10px; color: #fff; background: rgba(0, 0, 0, .6); }
.viewer .bar .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.viewer .bar .btn { background: rgba(255, 255, 255, .14); color: #fff; }
.viewer .stage { flex: 1; overflow: auto; display: grid; place-items: center; touch-action: pan-x pan-y pinch-zoom; }
.viewer .stage img { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer .stage iframe { width: 100%; height: 100%; border: 0; background: #fff; }
.viewer .nav { position: absolute; top: 50%; transform: translateY(-50%); width: 48px; height: 48px; border-radius: 50%; border: 0; background: rgba(255, 255, 255, .18); color: #fff; display: grid; place-items: center; cursor: pointer; }
.viewer .nav.prev { left: 10px; } .viewer .nav.next { right: 10px; }
.viewer .count { text-align: center; color: #cbd5e1; padding: 8px 0 calc(10px + var(--safe-b)); font-size: .85rem; }

.files { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
.files .f { position: relative; aspect-ratio: 1; border-radius: 12px; overflow: hidden; background: var(--surface-2); cursor: pointer; display: grid; place-items: center; color: var(--muted); text-align: center; font-size: .72rem; padding: 4px; }
.files .f img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.files .f .x { position: absolute; top: 4px; right: 4px; width: 28px; height: 28px; border-radius: 50%; background: rgba(15, 23, 42, .65); color: #fff; border: 0; display: grid; place-items: center; cursor: pointer; z-index: 1; }
.files .add { border: 2px dashed var(--border); background: transparent; color: var(--primary); font-weight: 650; gap: 4px; }

.empty { text-align: center; padding: 36px 16px; color: var(--muted); }
.empty .ic { width: 64px; height: 64px; border-radius: 20px; background: var(--surface-2); display: grid; place-items: center; margin: 0 auto 12px; color: var(--primary); }

/* ===== Calendario & varie ===== */
.timeline { position: relative; padding-left: 18px; }
.timeline::before { content: ""; position: absolute; left: 5px; top: 6px; bottom: 6px; width: 2px; background: var(--border); }
.timeline .ev { position: relative; margin-bottom: 10px; }
.timeline .ev::before { content: ""; position: absolute; left: -18px; top: 18px; width: 12px; height: 12px; border-radius: 50%; background: var(--primary); border: 3px solid var(--bg); }
.total { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-radius: var(--radius-sm); background: var(--primary-soft); color: var(--primary); font-weight: 700; margin-bottom: 12px; }
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login .card { width: 100%; max-width: 380px; padding: 28px 22px; text-align: center; }
.login img { margin: 0 auto 14px; }
.spacer { height: 12px; }
hr { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }
