/* Totaro Impianti - stile condiviso (mobile-first) */
:root {
  --brand: #0b5cab;
  --brand-dark: #08457f;
  --brand-soft: #e7f0fb;
  --bg: #f3f5f8;
  --card: #ffffff;
  --text: #17202b;
  --muted: #5f6b7a;
  --line: #d9dee6;
  --ok: #1a8f4c;
  --ok-soft: #e4f5eb;
  --err: #c9302c;
  --err-soft: #fdecea;
  --idr: #1d6fd1;
  --ele: #c27c00;
  --mis: #6b46c1;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(15, 30, 60, .08), 0 4px 14px rgba(15, 30, 60, .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --brand: #4c9bf0; --brand-dark: #2f7fd6; --brand-soft: #16263a;
    --bg: #0f141a; --card: #18202a; --text: #e7edf4; --muted: #94a2b3; --line: #2b3643;
    --ok: #3cc178; --ok-soft: #12291d; --err: #ff6b66; --err-soft: #331816;
    --idr: #5aa2f5; --ele: #f0b232; --mis: #a58bf0;
    --shadow: none; 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 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
a { color: var(--brand); }
small { font-size: .82em; }
.muted { color: var(--muted); }
h1, h2, h3 { line-height: 1.2; }

/* ---------- barra in alto ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--brand); color: #fff;
}
.topbar .logo { font-weight: 800; letter-spacing: .3px; font-size: 1.05rem; white-space: nowrap; }
.topbar .logo span { opacity: .75; font-weight: 500; }
.topbar .spacer { flex: 1; }
.topbar .who { font-size: .9rem; opacity: .9; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar button, .topbar a.tb {
  background: rgba(255,255,255,.16); color: #fff; border: 0; border-radius: 10px;
  padding: 8px 12px; font-size: .9rem; text-decoration: none; cursor: pointer;
}

main { max-width: 760px; margin: 0 auto; padding: 14px 16px 120px; }
main.wide { max-width: 1100px; }

/* ---------- card e campi ---------- */
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin-bottom: 14px; border: 1px solid var(--line);
}
.card h2 { font-size: 1.08rem; margin: 0 0 12px; display: flex; align-items: center; gap: 8px; }
.card h2 small { color: var(--muted); font-weight: 400; }
.step {
  display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%;
  background: var(--brand); color: #fff; font-size: .85rem; flex: none;
}
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: .9rem; font-weight: 600; margin-bottom: 5px; color: var(--muted); }
input, select, textarea {
  width: 100%; font: inherit; font-size: 16px; color: var(--text);
  background: var(--card); border: 1.5px solid var(--line); border-radius: 11px;
  padding: 12px 12px; min-height: 48px; outline: none; appearance: none; -webkit-appearance: none;
}
select {
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
  background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px;
}
textarea { resize: vertical; min-height: 84px; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
input[type="checkbox"] { width: 22px; height: 22px; min-height: 0; padding: 0; appearance: auto; -webkit-appearance: checkbox; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row2 > * { min-width: 0; }
.row2 .field { margin-bottom: 12px; }
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }

/* ---------- pulsanti ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 10px 18px; border-radius: 12px; border: 0;
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
  background: var(--brand); color: #fff;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .55; }
.btn-block { display: flex; width: 100%; }
.btn-outline { background: transparent; color: var(--brand); border: 2px dashed var(--brand); }
.btn-light { background: var(--brand-soft); color: var(--brand); }
.btn-danger { background: var(--err); }
.btn-ok { background: var(--ok); }
.btn-sm { min-height: 38px; padding: 6px 12px; font-size: .9rem; border-radius: 10px; }
.btn-big { min-height: 58px; font-size: 1.1rem; }
.icon-btn {
  flex: none; width: 44px; height: 48px; border-radius: 11px; border: 1.5px solid var(--line);
  background: var(--card); color: var(--muted); font-size: 1rem; cursor: pointer;
}
.file-btn { margin-top: 4px; }

/* ---------- selettore settore ---------- */
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.seg-btn {
  min-height: 56px; border-radius: 12px; border: 2px solid var(--line); background: var(--card);
  font: inherit; font-weight: 700; color: var(--text); cursor: pointer; padding: 6px;
}
.seg-btn.s-idraulico.active { border-color: var(--idr); background: var(--idr); color: #fff; }
.seg-btn.s-elettrico.active { border-color: var(--ele); background: var(--ele); color: #fff; }
.seg-btn.s-misto.active { border-color: var(--mis); background: var(--mis); color: #fff; }

/* ---------- chips ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.chips-label { width: 100%; font-size: .85rem; color: var(--muted); }
.chip {
  min-height: 40px; padding: 8px 13px; border-radius: 999px; border: 1.5px solid var(--line);
  background: var(--card); color: var(--text); font: inherit; font-size: .92rem; cursor: pointer; text-align: left;
}
.chip.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.chip.t-idraulico.active { background: var(--idr); border-color: var(--idr); }
.chip.t-elettrico.active { background: var(--ele); border-color: var(--ele); }
.chip.t-misto.active { background: var(--mis); border-color: var(--mis); }

/* ---------- autocompletamento ---------- */
.ac { position: relative; }
.ac-list {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 30;
  list-style: none; margin: 0; padding: 4px; background: var(--card);
  border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 8px 24px rgba(0,0,0,.15);
  max-height: 280px; overflow-y: auto;
}
.ac-list button {
  display: block; width: 100%; text-align: left; padding: 12px; border: 0; background: none;
  font: inherit; color: var(--text); border-radius: 8px; cursor: pointer;
}
.ac-list button:hover, .ac-list button:focus { background: var(--brand-soft); }

/* ---------- materiali e costi ---------- */
.mat-row, .costo-row {
  border: 1.5px solid var(--line); border-radius: 12px; padding: 10px; margin-bottom: 10px;
  display: grid; gap: 8px; background: color-mix(in srgb, var(--bg) 45%, var(--card));
}
.mat-top { display: flex; gap: 8px; }
.mat-top > :first-child { flex: 1; min-width: 0; }
.mat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
@media (min-width: 560px) { .mat-grid { grid-template-columns: 1fr 1fr 1.2fr 1.2fr; } }
.file-list { display: flex; flex-wrap: wrap; gap: 6px; }
.file-list:empty { display: none; }
.file-pill {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%;
  background: var(--brand-soft); color: var(--text); border-radius: 999px; padding: 4px 4px 4px 10px; font-size: .85rem;
}
.file-pill .x { border: 0; background: var(--card); color: var(--muted); width: 28px; height: 28px; border-radius: 50%; cursor: pointer; }

/* ---------- barra di salvataggio fissa ---------- */
.savebar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
  padding: 10px 16px; padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--card) 92%, transparent); backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
}
.savebar .inner { max-width: 760px; margin: 0 auto; display: grid; gap: 8px; }
.progress { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.progress > div { height: 100%; width: 0; background: var(--ok); transition: width .2s; }
.msg { padding: 12px 14px; border-radius: 12px; font-weight: 600; }
.msg-err { background: var(--err-soft); color: var(--err); }
.msg-ok { background: var(--ok-soft); color: var(--ok); }
.msg-info { background: var(--brand-soft); color: var(--brand); }

/* ---------- schermata di successo ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 24px;
  background: color-mix(in srgb, var(--bg) 70%, transparent); backdrop-filter: blur(4px);
}
.success {
  width: 100%; max-width: 420px; text-align: center; background: var(--card); border-radius: 20px;
  padding: 28px 22px; box-shadow: 0 20px 50px rgba(0,0,0,.2); border: 1px solid var(--line);
}
.success .check {
  width: 86px; height: 86px; margin: 0 auto 14px; border-radius: 50%; background: var(--ok); color: #fff;
  display: grid; place-items: center; font-size: 46px; animation: pop .35s ease-out;
}
.success h2 { margin: 0 0 6px; font-size: 1.4rem; }
.success p { margin: 0 0 18px; color: var(--muted); }
.success .btn { margin-top: 8px; }
@keyframes pop { from { transform: scale(.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ---------- login ---------- */
.login { max-width: 420px; margin: 6vh auto 0; }
.login h1 { text-align: center; color: var(--brand); margin: 0 0 4px; font-size: 1.7rem; }
.login .sub { text-align: center; color: var(--muted); margin: 0 0 22px; }
.op-list { display: grid; gap: 10px; }
.op-list button { justify-content: flex-start; font-size: 1.05rem; background: var(--card); color: var(--text); border: 1.5px solid var(--line); }
.pin-input { text-align: center; font-size: 28px; letter-spacing: 10px; }

/* ---------- elenchi (gestione) ---------- */
.list-item {
  display: block; text-decoration: none; color: inherit; background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 14px; margin-bottom: 8px; box-shadow: var(--shadow);
}
.list-item:hover { border-color: var(--brand); }
.li-top { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.li-title { font-weight: 700; }
.li-sub { color: var(--muted); font-size: .9rem; margin-top: 2px; }
.li-money { font-size: .88rem; white-space: nowrap; text-align: right; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .78rem; font-weight: 700; color: #fff; background: var(--muted); }
.badge.Idraulico { background: var(--idr); }
.badge.Elettrico { background: var(--ele); }
.badge.Misto { background: var(--mis); }
.badge.del { background: var(--err); }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.toolbar .grow { flex: 1; }
.tabs { display: flex; gap: 6px; overflow-x: auto; padding: 8px 16px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 52px; z-index: 15; }
.tabs a { padding: 8px 14px; border-radius: 10px; text-decoration: none; color: var(--muted); font-weight: 600; white-space: nowrap; }
.tabs a.active { background: var(--brand-soft); color: var(--brand); }
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.filters .full { grid-column: 1 / -1; }
@media (min-width: 800px) { .filters { grid-template-columns: repeat(4, 1fr); } }
.filters .field { margin: 0; }
.summary { display: flex; flex-wrap: wrap; gap: 8px 18px; font-size: .95rem; margin: 6px 0 12px; }
.summary b { color: var(--brand); }
details.card > summary { cursor: pointer; font-weight: 700; list-style: none; }
details.card > summary::-webkit-details-marker { display: none; }
details.card[open] > summary { margin-bottom: 12px; }

table.t { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.t th, table.t td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.t th { color: var(--muted); font-weight: 600; font-size: .82rem; text-transform: uppercase; letter-spacing: .3px; }
table.t td.n, table.t th.n { text-align: right; white-space: nowrap; }
.table-wrap { overflow-x: auto; }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; white-space: pre-wrap; }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; }
.thumb { position: relative; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); aspect-ratio: 1; background: var(--bg); display: grid; place-items: center; text-decoration: none; color: var(--text); }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb .cap { position: absolute; left: 0; right: 0; bottom: 0; font-size: .72rem; padding: 3px 6px; background: rgba(0,0,0,.55); color: #fff; }
.thumb .del { position: absolute; top: 4px; right: 4px; width: 30px; height: 30px; border-radius: 50%; border: 0; background: rgba(0,0,0,.6); color: #fff; cursor: pointer; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- notifiche ---------- */
.toast {
  position: fixed; left: 50%; bottom: 96px; transform: translate(-50%, 20px); opacity: 0; z-index: 60;
  padding: 12px 18px; border-radius: 12px; color: #fff; font-weight: 600; max-width: calc(100% - 32px);
  transition: all .25s; box-shadow: 0 6px 20px rgba(0,0,0,.2);
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.toast-ok { background: var(--ok); }
.toast-err { background: var(--err); }

.shake { animation: shake .45s; border-color: var(--err) !important; }
@keyframes shake { 0%,100% { transform: none; } 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.center { text-align: center; }
.mt { margin-top: 14px; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin 0.8s linear infinite; margin: 30px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
