/* Font serviti dal server (nessuna richiesta a servizi esterni) */
@font-face { font-family: 'Inter'; font-style: normal; font-weight: 400 800; font-display: swap; src: url(fonts/inter-latin-ext.woff2) format('woff2'); unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: 'Inter'; font-style: normal; font-weight: 400 800; font-display: swap; src: url(fonts/inter-latin.woff2) format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'JetBrains Mono'; font-style: normal; font-weight: 500 700; font-display: swap; src: url(fonts/jetbrains-mono-latin-ext.woff2) format('woff2'); unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: 'JetBrains Mono'; font-style: normal; font-weight: 500 700; font-display: swap; src: url(fonts/jetbrains-mono-latin.woff2) format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }

/* ========== Token ========== */
:root {
  color-scheme: dark;
  --bg: #070a13;
  --bg-elev: #0d1220;
  --card: #111827;
  --card-2: #172033;
  --line: #243049;
  --line-soft: #1a2336;
  --fg: #f4f6fb;
  --fg-2: #c3cad8;
  --muted: #8d97ab;
  --accent: #34d399;
  --accent-strong: #10b981;
  --on-accent: #04130d;
  --accent-soft: rgba(52, 211, 153, .14);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, .14);
  --warn: #fbbf24;
  --scrim: rgba(2, 4, 10, .66);
  --shadow: 0 10px 30px -12px rgba(0, 0, 0, .7);
  --hero-grad: radial-gradient(120% 140% at 100% 0%, rgba(52, 211, 153, .22) 0%, rgba(52, 211, 153, 0) 55%), linear-gradient(160deg, #121a2c 0%, #0c1220 100%);

  --c-pasti: #fbbf24;
  --c-carburante: #fb7185;
  --c-alloggio: #a78bfa;
  --c-trasporti: #38bdf8;
  --c-pedaggi: #2dd4bf;
  --c-forniture: #a3e635;
  --c-altro: #94a3b8;

  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-xl: 28px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --t-fast: 140ms;
  --t-med: 240ms;

  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #f4f6f9;
    --bg-elev: #ffffff;
    --card: #ffffff;
    --card-2: #eef1f6;
    --line: #d9dee8;
    --line-soft: #e7ebf2;
    --fg: #0b1220;
    --fg-2: #2f3a4f;
    --muted: #5b6579;
    --accent: #059669;
    --accent-strong: #047857;
    --on-accent: #ffffff;
    --accent-soft: rgba(5, 150, 105, .1);
    --danger: #dc2626;
    --danger-soft: rgba(220, 38, 38, .08);
    --scrim: rgba(15, 23, 42, .45);
    --shadow: 0 10px 30px -14px rgba(15, 23, 42, .25);
    --hero-grad: radial-gradient(120% 140% at 100% 0%, rgba(16, 185, 129, .35) 0%, rgba(16, 185, 129, 0) 55%), linear-gradient(160deg, #0f1a2e 0%, #0b1324 100%);

    --c-pasti: #d97706;
    --c-carburante: #e11d48;
    --c-alloggio: #7c3aed;
    --c-trasporti: #0284c7;
    --c-pedaggi: #0d9488;
    --c-forniture: #65a30d;
    --c-altro: #64748b;
  }
}

/* ========== Base ========== */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
[hidden] { display: none !important; }
h1, h2, h3, p { margin: 0; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
a { color: inherit; }
img { display: block; max-width: 100%; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.ico { width: 22px; height: 22px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ico-lg { width: 36px; height: 36px; stroke-width: 1.5; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; letter-spacing: -.02em; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 8px; }

/* ========== Layout app ========== */
.app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: calc(var(--safe-t) + 8px) 16px calc(120px + var(--safe-b));
}

.topbar { display: flex; align-items: center; justify-content: space-between; height: 52px; }
.topbar-title { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; letter-spacing: -.01em; }
.brand-dot { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 11px; background: var(--accent); color: var(--on-accent); }
.brand-dot .ico { width: 19px; height: 19px; }
.topbar-actions { display: flex; gap: 4px; }

.icon-btn {
  display: grid; place-items: center;
  width: 44px; height: 44px; border-radius: 14px;
  color: var(--fg-2);
  transition: background var(--t-fast) var(--ease), transform var(--t-fast) var(--ease), color var(--t-fast);
}
.icon-btn:hover { background: var(--card-2); color: var(--fg); }
.icon-btn:active { transform: scale(.94); }
.icon-btn.danger { color: var(--danger); }
.icon-btn.danger:hover { background: var(--danger-soft); }
.icon-btn:disabled { opacity: .35; pointer-events: none; }

.month-switch { display: flex; align-items: center; justify-content: space-between; margin: 8px 0 14px; }
.month-switch h2 { font-size: 15px; font-weight: 600; text-transform: capitalize; color: var(--fg-2); }

/* ========== Hero ========== */
.hero-card {
  position: relative; overflow: hidden;
  padding: 22px 20px 18px;
  border-radius: var(--r-xl);
  background: var(--hero-grad);
  color: #f4f6fb;
  border: 1px solid rgba(255, 255, 255, .06);
  box-shadow: var(--shadow);
}
.hero-label { font-size: 13px; font-weight: 500; color: rgba(244, 246, 251, .72); }
.hero-amount { font-family: var(--mono); font-weight: 700; font-size: clamp(34px, 11vw, 44px); line-height: 1.15; letter-spacing: -.04em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.hero-bar { display: flex; gap: 3px; height: 8px; margin: 18px 0 16px; border-radius: 99px; overflow: hidden; background: rgba(255, 255, 255, .08); }
.hero-bar span { display: block; height: 100%; min-width: 4px; border-radius: 99px; transition: flex-grow var(--t-med) var(--ease); }
.hero-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 0; }
.hero-stats div { padding: 10px 12px; border-radius: var(--r-md); background: rgba(255, 255, 255, .06); }
.hero-stats dt { font-size: 12px; color: rgba(244, 246, 251, .66); }
.hero-stats dd { margin: 2px 0 0; font-family: var(--mono); font-weight: 600; font-size: 17px; font-variant-numeric: tabular-nums; }

/* ========== Toolbar ========== */
.toolbar { margin: 18px 0 6px; display: grid; gap: 12px; }
.search {
  display: flex; align-items: center; gap: 10px;
  height: 48px; padding: 0 14px;
  border-radius: var(--r-md);
  background: var(--card); border: 1px solid var(--line-soft);
  color: var(--muted);
  transition: border-color var(--t-fast);
}
.search:focus-within { border-color: var(--accent); }
.search .ico { width: 19px; height: 19px; }
.search input { flex: 1; min-width: 0; height: 100%; border: 0; background: transparent; outline: none; color: var(--fg); font-size: 16px; }
.search input::placeholder { color: var(--muted); }

.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px 2px; scroll-padding: 16px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; display: inline-flex; align-items: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: 99px;
  background: var(--card); border: 1px solid var(--line-soft);
  font-size: 14px; font-weight: 500; color: var(--fg-2);
  transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast);
}
.chip .ico { width: 16px; height: 16px; color: var(--cc, currentColor); }
.chip[aria-pressed="true"] { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.chip[aria-pressed="true"] .ico { color: inherit; }

/* ========== Lista ========== */
.list { display: grid; gap: 4px; }
.day-head { display: flex; justify-content: space-between; align-items: baseline; padding: 18px 4px 8px; font-size: 13px; font-weight: 600; color: var(--muted); }
.day-head .num { font-size: 13px; font-weight: 500; }
.day-group { display: grid; gap: 8px; }

.item {
  display: grid; grid-template-columns: 56px 1fr auto; align-items: center; gap: 14px;
  width: 100%; padding: 10px 14px 10px 10px; text-align: left;
  border-radius: var(--r-lg);
  background: var(--card); border: 1px solid var(--line-soft);
  transition: transform var(--t-fast) var(--ease), background var(--t-fast);
  animation: rise var(--t-med) var(--ease) both;
  animation-delay: calc(var(--i, 0) * 30ms);
}
.item:active { transform: scale(.985); background: var(--card-2); }
.thumb {
  position: relative; width: 56px; height: 56px; border-radius: 14px; overflow: hidden;
  background: color-mix(in srgb, var(--cc) 16%, var(--card-2));
  color: var(--cc); display: grid; place-items: center;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb .badge-ico {
  position: absolute; right: 3px; bottom: 3px; width: 20px; height: 20px; border-radius: 7px;
  display: grid; place-items: center; background: var(--cc); color: #0b1220;
}
.thumb .badge-ico .ico { width: 12px; height: 12px; stroke-width: 2.4; }
.item-main { min-width: 0; }
.item-title { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-meta { display: flex; align-items: center; gap: 6px; margin-top: 2px; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; }
.item-meta .dot { width: 3px; height: 3px; border-radius: 50%; background: currentColor; opacity: .6; flex: none; }
.item-amount { font-family: var(--mono); font-weight: 600; font-size: 16px; font-variant-numeric: tabular-nums; text-align: right; }
.item-tag { display: block; margin-top: 2px; font-family: var(--font); font-size: 11px; font-weight: 600; color: var(--warn); text-align: right; }

.empty { text-align: center; padding: 48px 24px 24px; color: var(--muted); }
.empty-art { width: 92px; height: 92px; margin: 0 auto 18px; border-radius: 28px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.empty h3 { color: var(--fg); font-size: 18px; margin-bottom: 6px; }
.empty .btn { margin-top: 20px; }

.skeleton { height: 78px; border-radius: var(--r-lg); background: linear-gradient(90deg, var(--card) 0%, var(--card-2) 50%, var(--card) 100%); background-size: 200% 100%; animation: shimmer 1.2s linear infinite; }

/* ========== Riepilogo ========== */
.panel { padding: 18px; border-radius: var(--r-lg); background: var(--card); border: 1px solid var(--line-soft); margin-bottom: 12px; }
.panel h3 { font-size: 16px; font-weight: 700; }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 14px; }
.panel-head .muted { font-family: var(--mono); font-size: 14px; }
.bars { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; }
.bar-row { display: grid; grid-template-columns: 36px 1fr; gap: 12px; align-items: center; }
.bar-ico { width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center; color: var(--cc); background: color-mix(in srgb, var(--cc) 16%, transparent); }
.bar-ico .ico { width: 18px; height: 18px; }
.bar-top { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; }
.bar-top span:first-child { font-weight: 500; }
.bar-top .num { font-weight: 600; }
.bar-track { height: 6px; margin-top: 6px; border-radius: 99px; background: var(--card-2); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 99px; background: var(--cc); transform-origin: left; animation: grow 600ms var(--ease) both; }
.bar-pct { font-size: 12px; color: var(--muted); }

.pay-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.pay-grid li { padding: 12px; border-radius: var(--r-md); background: var(--card-2); }
.pay-grid .ico { width: 18px; height: 18px; color: var(--muted); }
.pay-grid p { font-size: 12px; color: var(--muted); margin-top: 6px; line-height: 1.3; }
.pay-grid strong { display: block; margin-top: 2px; font-family: var(--mono); font-size: 15px; font-variant-numeric: tabular-nums; }

.export { display: grid; gap: 14px; background: linear-gradient(160deg, var(--accent-soft), transparent 70%), var(--card); }
.export p { font-size: 14px; margin-top: 4px; }

.months { list-style: none; margin: 0; padding: 0; }
.months li + li { border-top: 1px solid var(--line-soft); }
.months button { display: flex; width: 100%; align-items: center; justify-content: space-between; min-height: 52px; padding: 6px 2px; text-align: left; }
.months .m-name { text-transform: capitalize; font-weight: 500; }
.months .m-sub { font-size: 13px; color: var(--muted); }
.months .num { font-weight: 600; }
.months button[aria-current="true"] .m-name { color: var(--accent); }

/* ========== Tab bar ========== */
.tabbar {
  position: fixed; left: 50%; bottom: calc(12px + var(--safe-b)); transform: translateX(-50%);
  width: min(calc(100% - 32px), 420px); height: 68px;
  display: grid; grid-template-columns: 1fr 84px 1fr; align-items: center;
  border-radius: 24px;
  background: color-mix(in srgb, var(--bg-elev) 82%, transparent);
  backdrop-filter: blur(18px) saturate(1.4); -webkit-backdrop-filter: blur(18px) saturate(1.4);
  border: 1px solid var(--line-soft);
  box-shadow: var(--shadow);
  z-index: 20;
}
.tab { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; height: 100%; font-size: 12px; font-weight: 600; color: var(--muted); transition: color var(--t-fast); }
.tab .ico { width: 22px; height: 22px; }
.tab.is-active { color: var(--fg); }
.tab.is-active .ico { color: var(--accent); }
.fab {
  justify-self: center; width: 64px; height: 64px; margin-top: -30px;
  border-radius: 22px; display: grid; place-items: center;
  background: var(--accent); color: var(--on-accent);
  box-shadow: 0 12px 28px -8px color-mix(in srgb, var(--accent) 70%, transparent), 0 0 0 6px var(--bg);
  transition: transform var(--t-fast) var(--ease), background var(--t-fast);
}
.fab .ico { width: 28px; height: 28px; stroke-width: 2.2; }
.fab:hover { background: var(--accent-strong); }
.fab:active { transform: scale(.92); }

/* ========== Bottoni & campi ========== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; padding: 0 22px; border-radius: 16px;
  font-weight: 700; font-size: 16px; text-decoration: none;
  transition: transform var(--t-fast) var(--ease), background var(--t-fast), opacity var(--t-fast);
}
.btn:active { transform: scale(.97); }
.btn-block { width: 100%; }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-strong); }
.btn-ghost { background: var(--card-2); color: var(--fg); }
.btn-danger { background: var(--danger); color: #fff; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; pointer-events: none; }

.field { display: grid; gap: 6px; align-content: start; border: 0; padding: 0; margin: 0; min-width: 0; }
.field-label { font-size: 13px; font-weight: 600; color: var(--fg-2); padding: 0; }
.field-label .opt { font-weight: 400; color: var(--muted); }
.field-hint { font-size: 13px; color: var(--muted); min-height: 1em; }
.field-error { font-size: 13px; color: var(--danger); min-height: 0; }
.field-error:empty { display: none; }
.field input, .field textarea {
  width: 100%; min-height: 50px; padding: 12px 14px;
  border-radius: var(--r-md); border: 1px solid var(--line);
  background: var(--bg-elev); color: var(--fg); font-size: 16px; outline: none;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.field textarea { resize: vertical; min-height: 76px; line-height: 1.4; }
.field input:focus, .field textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field input::placeholder, .field textarea::placeholder { color: var(--muted); opacity: .8; }
.field input[aria-invalid="true"] { border-color: var(--danger); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field.is-ai .field-label::after {
  content: var(--ai-badge, 'rilevato'); white-space: nowrap; margin-left: 6px; padding: 1px 8px; border-radius: 99px;
  font-size: 11px; font-weight: 600; color: var(--accent); background: var(--accent-soft);
}

.field-amount .amount-wrap { position: relative; display: block; }
.field-amount .amount-cur { position: absolute; left: 16px; top: 50%; transform: translateY(-50%); font-family: var(--mono); font-size: 26px; font-weight: 600; color: var(--muted); }
.field-amount input { min-height: 68px; padding-left: 44px; font-family: var(--mono); font-size: 30px; font-weight: 700; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }

.cat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.cat-opt {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  min-height: 74px; padding: 8px 4px; border-radius: var(--r-md);
  background: var(--bg-elev); border: 1px solid var(--line);
  font-size: 12px; font-weight: 600; color: var(--fg-2); text-align: center; line-height: 1.15;
  transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast);
}
.cat-opt .ico { color: var(--cc); }
.cat-opt[aria-checked="true"] { border-color: var(--cc); background: color-mix(in srgb, var(--cc) 14%, var(--bg-elev)); color: var(--fg); box-shadow: inset 0 0 0 1px var(--cc); }

.segmented { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px; border-radius: 16px; background: var(--card-2); }
.seg-opt { display: flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; border-radius: 12px; font-size: 13px; font-weight: 600; color: var(--muted); transition: background var(--t-fast), color var(--t-fast); }
.seg-opt .ico { width: 17px; height: 17px; }
.seg-opt[aria-checked="true"] { background: var(--bg-elev); color: var(--fg); box-shadow: 0 1px 3px rgba(0, 0, 0, .18); }

/* ========== Sheet ========== */
.sheet { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet-scrim { position: absolute; inset: 0; background: var(--scrim); animation: fade var(--t-med) var(--ease) both; }
.sheet-panel {
  position: relative; width: 100%; max-width: 560px; height: calc(100dvh - var(--safe-t) - 12px);
  display: flex; flex-direction: column;
  background: var(--bg); border-radius: 26px 26px 0 0; border: 1px solid var(--line-soft); border-bottom: 0;
  animation: slide-up 320ms var(--ease) both;
}
.sheet.is-closing .sheet-panel { animation: slide-down 200ms ease-in both; }
.sheet.is-closing .sheet-scrim { animation: fade 200ms ease-in reverse both; }
.sheet-head { display: grid; grid-template-columns: 44px 1fr 44px; align-items: center; padding: 10px 10px 6px; }
.sheet-head h2 { text-align: center; font-size: 17px; font-weight: 700; }
.sheet-body { flex: 1; overflow-y: auto; padding: 6px 16px 24px; display: grid; gap: 18px; align-content: start; overscroll-behavior: contain; }
.sheet-foot { padding: 12px 16px calc(12px + var(--safe-b)); border-top: 1px solid var(--line-soft); background: var(--bg); }

.photo-box { position: relative; height: 210px; border-radius: var(--r-lg); overflow: hidden; background: var(--card-2); border: 1px solid var(--line-soft); }
.photo-btn { width: 100%; height: 100%; display: block; }
.photo-btn img { width: 100%; height: 100%; object-fit: cover; object-position: center top; }
.photo-empty { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 8px; color: var(--muted); font-size: 14px; pointer-events: none; }
.photo-actions { position: absolute; right: 10px; bottom: 10px; display: flex; gap: 8px; }
.pill-btn {
  display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 0 14px; border-radius: 99px;
  background: rgba(7, 10, 19, .72); color: #fff; font-size: 13px; font-weight: 600;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.pill-btn .ico { width: 17px; height: 17px; }

.ocr { padding: 12px 14px; border-radius: var(--r-md); background: var(--accent-soft); color: var(--fg); }
.ocr-row { display: flex; align-items: center; gap: 10px; font-size: 14px; font-weight: 500; }
.ocr-ico { color: var(--accent); animation: pulse 1.4s ease-in-out infinite; }
.ocr.is-done .ocr-ico { animation: none; }
.ocr.is-error { background: var(--danger-soft); }
.ocr.is-error .ocr-ico { color: var(--danger); animation: none; }
.progress { height: 4px; margin-top: 10px; border-radius: 99px; background: color-mix(in srgb, var(--accent) 20%, transparent); overflow: hidden; }
.progress span { display: block; height: 100%; width: 0; background: var(--accent); border-radius: inherit; transition: width var(--t-med) var(--ease); }
.ocr.is-done .progress, .ocr.is-error .progress { display: none; }

/* ========== Viewer, conferma, toast ========== */
.viewer { position: fixed; inset: 0; z-index: 70; background: #000; animation: fade var(--t-med) both; }
.viewer-scroll { position: absolute; inset: 0; overflow: auto; display: grid; place-items: center; touch-action: pan-x pan-y pinch-zoom; }
.viewer-scroll img { max-width: 100%; max-height: 100dvh; object-fit: contain; transition: max-width var(--t-med); }
.viewer-scroll.is-zoomed { place-items: start; }
.viewer-scroll.is-zoomed img { max-width: none; max-height: none; width: 250%; }
.viewer-close { position: absolute; z-index: 2; top: calc(10px + var(--safe-t)); right: 10px; color: #fff; background: rgba(255, 255, 255, .12); }

.confirm { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; padding: 24px; background: var(--scrim); animation: fade var(--t-fast) both; }
.confirm-card { width: 100%; max-width: 360px; padding: 22px; border-radius: var(--r-lg); background: var(--bg-elev); border: 1px solid var(--line-soft); box-shadow: var(--shadow); animation: pop var(--t-med) var(--ease) both; }
.confirm-card h3 { font-size: 18px; margin-bottom: 8px; }
.confirm-card p { font-size: 14px; }
.confirm-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 20px; }

.toast {
  position: fixed; left: 50%; bottom: calc(96px + var(--safe-b)); transform: translateX(-50%); z-index: 90;
  max-width: calc(100% - 32px); padding: 12px 18px; border-radius: 14px;
  background: var(--fg); color: var(--bg); font-size: 14px; font-weight: 600; box-shadow: var(--shadow);
  animation: toast-in var(--t-med) var(--ease) both;
}
.toast.is-error { background: var(--danger); color: #fff; }

/* ========== Login ========== */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 380px; text-align: center; }
.login-card h1 { font-size: 26px; letter-spacing: -.02em; margin: 18px 0 6px; }
.login-card form { display: grid; gap: 14px; margin-top: 28px; text-align: left; }
.brand-mark { width: 72px; height: 72px; margin: 0 auto; border-radius: 22px; display: grid; place-items: center; background: var(--accent); color: var(--on-accent); }
.brand-mark .ico { width: 36px; height: 36px; }

.view { animation: fade var(--t-med) var(--ease) both; }

/* ========== Animazioni ========== */
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes slide-up { from { transform: translateY(100%); } to { transform: none; } }
@keyframes slide-down { from { transform: none; } to { transform: translateY(100%); } }
@keyframes pop { from { opacity: 0; transform: scale(.94); } to { opacity: 1; transform: none; } }
@keyframes grow { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@keyframes shimmer { to { background-position: -200% 0; } }
@keyframes pulse { 50% { opacity: .35; } }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%, 0); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; }
}

@media (max-width: 360px) {
  .cat-grid { grid-template-columns: repeat(3, 1fr); }
  .field-row { grid-template-columns: 1fr; }
  .seg-opt .ico { display: none; }
}

@media (min-width: 720px) {
  .sheet { align-items: center; }
  .sheet-panel { height: min(860px, calc(100dvh - 48px)); border-radius: 26px; border-bottom: 1px solid var(--line-soft); }
}

/* ========== Multiutente, lingua, impostazioni ========== */
.avatar {
  display: grid; place-items: center; width: 36px; height: 36px; flex: none; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent); font-size: 13px; font-weight: 700; letter-spacing: .02em;
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
}
.avatar-lg { width: 56px; height: 56px; font-size: 19px; }
.avatar-btn { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; transition: transform var(--t-fast) var(--ease); }
.avatar-btn:active { transform: scale(.94); }

.viewing { display: flex; align-items: center; gap: 10px; margin-top: 6px; }
.viewing-select {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; height: 44px; padding: 0 12px;
  border-radius: var(--r-md); background: var(--card); border: 1px solid var(--line-soft); color: var(--muted);
}
.viewing-select .ico { width: 18px; height: 18px; }
.viewing-select select {
  flex: 1; min-width: 0; height: 100%; border: 0; background: transparent; color: var(--fg);
  font-size: 15px; font-weight: 600; outline: none; appearance: none; -webkit-appearance: none; cursor: pointer;
}
.viewing-select select option { background: var(--bg-elev); color: var(--fg); }
.viewing-select:focus-within { border-color: var(--accent); }
.link-btn { flex: none; min-height: 44px; padding: 0 4px; font-size: 14px; font-weight: 600; color: var(--accent); }
.viewing-other .add-only { visibility: hidden; pointer-events: none; }
.viewing-other .hero-card { background: linear-gradient(160deg, #1d2440 0%, #11172a 100%); }

.lang-switch { display: inline-flex; gap: 2px; padding: 3px; margin-bottom: 22px; border-radius: 99px; background: var(--card-2); }
.lang-switch button { min-width: 44px; min-height: 36px; padding: 0 12px; border-radius: 99px; font-size: 13px; font-weight: 700; color: var(--muted); }
.lang-switch button[aria-pressed="true"] { background: var(--bg-elev); color: var(--fg); box-shadow: 0 1px 3px rgba(0, 0, 0, .18); }
.login-sub { text-align: center; margin-bottom: 4px; }
.login-help { font-size: 13px; text-align: center; }

.report-for { font-size: 14px; font-weight: 600; color: var(--fg-2); }

.settings-body { gap: 12px; }
.profile-card { display: flex; align-items: center; gap: 14px; padding: 4px 2px 8px; }
.profile-name { font-size: 18px; font-weight: 700; }
.profile-sub { font-size: 14px; }
.set-panel { display: grid; gap: 14px; margin: 0; }
.seg-2 { grid-template-columns: 1fr 1fr; }
.seg-opt:disabled { opacity: .5; cursor: not-allowed; }

.btn-small { min-height: 40px; padding: 0 14px; font-size: 14px; border-radius: 12px; }
.btn-small .ico { width: 17px; height: 17px; }
.btn-danger-ghost { background: var(--danger-soft); color: var(--danger); }
.btn-danger-ghost:hover { background: color-mix(in srgb, var(--danger) 20%, transparent); }

.team-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.team-row {
  display: grid; grid-template-columns: 36px 1fr auto; align-items: center; gap: 12px; width: 100%;
  min-height: 60px; padding: 10px 12px; border-radius: var(--r-md); background: var(--card-2); text-align: left;
  transition: transform var(--t-fast) var(--ease);
}
.team-row:active { transform: scale(.985); }
.team-row.is-inactive { opacity: .6; }
.team-main { min-width: 0; display: grid; }
.team-name { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.team-sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.team-stats { display: grid; justify-items: end; font-size: 12px; color: var(--muted); text-align: right; white-space: nowrap; }
.team-stats span:last-child { font-family: var(--mono); color: var(--fg-2); font-weight: 600; }
.tag { display: inline-block; padding: 0 7px; border-radius: 99px; font-size: 11px; font-weight: 600; background: var(--accent-soft); color: var(--accent); vertical-align: 1px; }
.tag-muted { background: var(--line-soft); color: var(--muted); }

.user-card { display: grid; gap: 14px; max-height: calc(100dvh - 48px); overflow-y: auto; }
.user-card .confirm-actions { margin-top: 4px; }
.user-extra { display: grid; gap: 8px; }

/* ========== Fatture PDF ========== */
.photo-actions { flex-wrap: wrap; justify-content: flex-end; left: 10px; }
.photo-pdf {
  position: absolute; inset: 0; width: 100%; display: flex; align-items: center; gap: 16px;
  padding: 18px 20px 64px; text-align: left; color: var(--fg);
  background: linear-gradient(160deg, color-mix(in srgb, var(--c-carburante) 10%, transparent), transparent 70%);
}
.pdf-icon { position: relative; flex: none; width: 64px; height: 76px; border-radius: 12px; display: grid; place-items: center; background: var(--bg-elev); border: 1px solid var(--line); color: var(--muted); }
.pdf-icon .ico { width: 34px; height: 34px; }
.pdf-tag {
  position: absolute; left: 50%; bottom: -7px; transform: translateX(-50%);
  padding: 1px 7px; border-radius: 6px; font-size: 10px; font-weight: 800; letter-spacing: .04em;
  background: #dc2626; color: #fff; line-height: 1.5;
}
.pdf-meta { min-width: 0; display: grid; gap: 2px; }
.pdf-name { font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pdf-open { font-size: 13px; color: var(--accent); font-weight: 600; }

.thumb .pdf-tag { bottom: 4px; left: 4px; transform: none; font-size: 9px; padding: 0 5px; }

.empty-actions { display: grid; gap: 10px; justify-content: center; margin-top: 20px; }
.empty-actions .btn { margin-top: 0; }

/* ========== Interruttore (report con/senza allegati) ========== */
.switch-row { display: flex; align-items: center; gap: 14px; padding: 12px 14px; border-radius: var(--r-md); background: var(--card-2); cursor: pointer; }
.switch-text { flex: 1; min-width: 0; display: grid; gap: 2px; }
.switch-title { font-weight: 600; font-size: 15px; }
.switch-hint { font-size: 13px; color: var(--muted); line-height: 1.35; }
.switch-row input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.switch {
  position: relative; flex: none; width: 50px; height: 30px; border-radius: 99px;
  background: var(--line); transition: background var(--t-fast) var(--ease);
}
.switch::after {
  content: ''; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: transform var(--t-med) var(--ease);
}
.switch-row input:checked + .switch { background: var(--accent); }
.switch-row input:checked + .switch::after { transform: translateX(20px); }
.switch-row input:focus-visible + .switch { outline: 2px solid var(--accent); outline-offset: 2px; }
