:root {
    --bg: #f4f5f7;
    --surface: #ffffff;
    --text: #1d2330;
    --muted: #667085;
    --border: #d9dde5;
    --primary: #1f5eff;
    --primary-text: #ffffff;
    --ok: #1a8f4c;
    --warn-bg: #fff4e0;
    --warn-text: #8a5300;
    --offline-bg: #2d3342;
    --offline-text: #ffffff;
    --error: #c62828;
    --error-bg: #fdecec;
    --pending: #d98a00;
    --selected-bg: #e8efff;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #12151c;
        --surface: #1c212b;
        --text: #e8ebf1;
        --muted: #9aa3b5;
        --border: #313847;
        --primary: #5b8cff;
        --primary-text: #0b1020;
        --ok: #4cc27f;
        --warn-bg: #3a2c12;
        --warn-text: #ffcf7a;
        --offline-bg: #3a4152;
        --error: #ff7b7b;
        --error-bg: #3b1e22;
        --pending: #f2b441;
        --selected-bg: #22304f;
        color-scheme: dark;
    }
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    -webkit-tap-highlight-color: transparent;
}

.shell {
    max-width: 560px;
    margin: 0 auto;
    padding: max(16px, env(safe-area-inset-top)) 16px calc(32px + env(safe-area-inset-bottom));
}

h1 { font-size: 1.4rem; margin: 0; }
.section { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 24px 0 8px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.strong { font-weight: 600; }
.center { text-align: center; }
.error { color: var(--error); }
.grow { flex: 1; min-width: 0; }

.topbar { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 12px; }

.banner { border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; font-size: .9rem; }
.banner-offline { background: var(--offline-bg); color: var(--offline-text); }
.banner-warn { background: var(--warn-bg); color: var(--warn-text); }
.banner a { color: inherit; font-weight: 600; }

.syncbar { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; }
.syncbar .link { margin-left: auto; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.dot-ok { background: var(--ok); }
.dot-off { background: var(--pending); }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    min-height: 48px; padding: 0 18px; border-radius: 12px; border: 1px solid transparent;
    font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--primary); color: var(--primary-text); }
.btn-secondary { background: var(--surface); color: var(--primary); border-color: var(--border); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-big { width: 100%; min-height: 56px; font-size: 1.05rem; margin-top: 16px; }
.link { background: none; border: none; color: var(--primary); font: inherit; cursor: pointer; padding: 4px; }
.link:disabled { color: var(--muted); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; margin-bottom: 10px; }
.card-pending { border-left: 4px solid var(--pending); }
.card-error { border-left: 4px solid var(--error); }
.card { overflow-wrap: anywhere; }
.card .row { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 2px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

.badge { font-size: .75rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--border); white-space: nowrap; }
.badge-inviato { background: #dbe7ff; color: #1b3f99; }
.badge-approvato { background: #d8f3e3; color: #13663a; }
.badge-respinto { background: var(--error-bg); color: var(--error); }
.badge-bozza { background: var(--border); color: var(--text); }
.badge-pending { background: var(--warn-bg); color: var(--warn-text); }

.label { display: block; font-size: .85rem; color: var(--muted); margin: 12px 0 4px; }
.field {
    width: 100%; min-height: 48px; padding: 10px 12px; border-radius: 10px;
    border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit;
}
.textarea { min-height: 110px; resize: vertical; }

.selected-info { margin: 6px 2px 0; }
/* Date/select nativi su Android e iOS hanno una larghezza minima propria che sfonda il bordo. */
input.field, select.field { display: block; min-width: 0; max-width: 100%; }
input[type=date].field { -webkit-appearance: none; appearance: none; }
select.field { text-overflow: ellipsis; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
    min-height: 40px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--border);
    background: var(--surface); color: var(--text); font: inherit; text-transform: capitalize; cursor: pointer;
}
.chip.selected { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }

.steppers { display: flex; flex-direction: column; gap: 8px; }
.stepper {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 8px 8px 8px 14px;
}
.stepper-label { font-weight: 600; min-width: 0; }
.stepper-row { display: flex; align-items: center; gap: 6px; flex: none; }
.stepper-row button {
    width: 48px; height: 48px; border-radius: 10px; border: 1px solid var(--border);
    background: var(--bg); color: var(--text); font-size: 1.4rem; line-height: 1; cursor: pointer;
    touch-action: manipulation; /* niente zoom da doppio tap quando si preme + più volte */
}
.stepper-row button:disabled { opacity: .4; }
.stepper-row .value { min-width: 64px; text-align: center; font-weight: 600; font-variant-numeric: tabular-nums; }
.total { text-align: right; margin: 8px 2px 0; }

.gps { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
       background: var(--surface); border: 1px dashed var(--border); border-radius: 12px; padding: 10px 12px; }
.gps-ok { border-style: solid; border-color: var(--ok); }

.spesa { display: flex; align-items: center; gap: 12px; }
.spesa img { width: 52px; height: 52px; object-fit: cover; border-radius: 8px; }
.preview { display: block; max-width: 100%; max-height: 220px; border-radius: 10px; margin-top: 10px; }
.file { position: relative; overflow: hidden; margin-top: 12px; }
.file input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.login { padding-top: 12vh; }
.login h1 { font-size: 1.8rem; }
.login .btn { width: 100%; margin-top: 16px; }

#update-banner {
    display: none; position: fixed; left: 16px; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom));
    max-width: 528px; margin: 0 auto; z-index: 1000;
    background: var(--offline-bg); color: var(--offline-text); border-radius: 12px; padding: 12px 14px;
    align-items: center; justify-content: space-between; gap: 12px;
}
#update-banner button { background: var(--primary); color: var(--primary-text); border: 0; border-radius: 8px; padding: 8px 14px; font: inherit; font-weight: 600; }

#blazor-error-ui {
    background: var(--warn-bg); color: var(--warn-text);
    bottom: 0; box-sizing: border-box; display: none; left: 0; padding: .6rem 1.25rem .7rem;
    position: fixed; width: 100%; z-index: 1000;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: .75rem; top: .5rem; }

.loading-progress { position: absolute; display: block; width: 8rem; height: 8rem; inset: 20vh 0 auto 0; margin: 0 auto; }
.loading-progress circle { fill: none; stroke: var(--border); stroke-width: .6rem; transform-origin: 50% 50%; transform: rotate(-90deg); }
.loading-progress circle:last-child {
    stroke: var(--primary);
    stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
    transition: stroke-dasharray .05s ease-in-out;
}
.loading-progress-text { position: absolute; text-align: center; font-weight: bold; inset: calc(20vh + 3.25rem) 0 auto .2rem; }
.loading-progress-text:after { content: var(--blazor-load-percentage-text, "Caricamento"); }
