:root {
  --green: #1b6b50;
  --green-dark: #14523d;
  --ok: #1b8a4b;
  --ok-bg: #e6f4ea;
  --warn: #c0392b;
  --warn-bg: #fdecea;
  --neutral: #6b7280;
  --neutral-bg: #eef1f4;
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #d8dee5;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 12px rgba(0,0,0,.05);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

.topbar {
  background: var(--green);
  color: #fff;
  padding: 14px 16px;
  padding-top: calc(14px + env(safe-area-inset-top));
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 { font-size: 1.2rem; margin: 0; line-height: 1.1; }
.subtitle { margin: 0; font-size: .78rem; opacity: .9; }
.logo { display: block; }
.lang select {
  background: rgba(255,255,255,.15); color: #fff; border: 1px solid rgba(255,255,255,.4);
  border-radius: 8px; padding: 6px 8px; font-size: .9rem; font-weight: 600;
}
.lang select option { color: #000; }

.disclaimer {
  background: #fff7e6; color: #7a5a10; border-bottom: 1px solid #f0e0b8;
  margin: 0; padding: 10px 16px; font-size: .82rem;
}

main { max-width: 640px; margin: 0 auto; padding: 16px; }

.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin-bottom: 16px;
}
.card h2 { font-size: 1rem; margin: 0 0 12px; color: var(--green-dark); }

.field { margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
.field label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 6px; }
.field small { display: block; color: var(--muted); font-size: .78rem; margin-top: 4px; }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }
.grow { flex: 1; }

.input-unit { display: flex; align-items: stretch; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: #fff; }
.input-unit input { border: 0; }
.input-unit .unit { display: flex; align-items: center; padding: 0 12px; background: var(--neutral-bg); color: var(--muted); font-size: .85rem; white-space: nowrap; }
.input-unit.invalid { border-color: var(--warn); background: var(--warn-bg); }
.input-unit.invalid input { color: var(--warn); }

input[type="number"], input[type="text"] {
  width: 100%; padding: 12px; font-size: 1rem; border: 1px solid var(--border);
  border-radius: 10px; background: #fff; color: var(--text);
}
input:focus { outline: 2px solid var(--green); outline-offset: 1px; border-color: var(--green); }

button { font-family: inherit; font-size: .95rem; cursor: pointer; border-radius: 10px; padding: 11px 16px; border: 0; font-weight: 600; }
.btn-primary { background: var(--green); color: #fff; }
.btn-primary:active { background: var(--green-dark); }
.btn-secondary { background: var(--neutral-bg); color: var(--text); border: 1px solid var(--border); }
.btn-secondary.reset { width: 100%; margin-top: 12px; }

.accessori-list { margin: 8px 0; display: flex; flex-direction: column; gap: 8px; }
.accessorio-item { display: flex; gap: 8px; align-items: center; }
.accessorio-item input.acc-nome { flex: 2; }
.accessorio-item .input-unit { flex: 1; }
.accessorio-item .acc-remove { background: var(--warn-bg); color: var(--warn); border: 1px solid #f3c6c0; padding: 10px 12px; }

/* Esito */
.result { border-left: 6px solid var(--neutral); }
.result.ok { border-left-color: var(--ok); background: var(--ok-bg); }
.result.sforamento { border-left-color: var(--warn); background: var(--warn-bg); }
.result.incomplete { border-left-color: var(--neutral); }
.result-badge { font-size: 1.15rem; font-weight: 800; margin-bottom: 12px; }
.result.ok .result-badge { color: var(--ok); }
.result.sforamento .result-badge { color: var(--warn); }
.result.incomplete .result-badge { color: var(--neutral); }

.bar { height: 12px; background: #dfe4e8; border-radius: 999px; overflow: hidden; margin-bottom: 14px; }
.bar-fill { height: 100%; width: 0; background: var(--ok); transition: width .2s ease, background .2s ease; }
.result.sforamento .bar-fill { background: var(--warn); }

.result-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.result-grid .lbl { display: block; font-size: .74rem; color: var(--muted); }
.result-grid strong { font-size: 1.05rem; }
.result-msg { margin: 12px 0 0; font-weight: 700; }
.result.ok .result-msg { color: var(--ok); }
.result.sforamento .result-msg { color: var(--warn); }

.save-row { align-items: flex-end; }
.save-msg { font-size: .85rem; color: var(--ok); min-height: 1.1em; margin: 6px 0 0; }
.saved-list { list-style: none; padding: 0; margin: 12px 0 0; }
.saved-item { display: flex; align-items: center; gap: 8px; padding: 10px; border: 1px solid var(--border); border-radius: 10px; margin-bottom: 8px; }
.saved-item .saved-name { flex: 1; font-weight: 600; }
.saved-item button { padding: 8px 12px; font-size: .82rem; }
.saved-item .load-btn { background: var(--green); color: #fff; }
.saved-item .del-btn { background: var(--warn-bg); color: var(--warn); border: 1px solid #f3c6c0; }
.saved-empty { color: var(--muted); font-size: .88rem; }

.footer { text-align: center; color: var(--muted); font-size: .72rem; padding: 8px 16px 24px; padding-bottom: calc(24px + env(safe-area-inset-bottom)); }

@media (max-width: 480px) {
  .result-grid { grid-template-columns: 1fr; }
  .field-row { flex-direction: column; gap: 0; }
}
