:root {
  --bg: #f3f4f6;
  --card: #ffffff;
  --text: #1f2328;
  --muted: #667085;
  --line: #e4e7ec;
  --accent: #d6336c;
  --accent-soft: #fdecf2;
  --ok: #1a7f5a;
  --warn: #b54708;
  --err: #c0262d;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Open Sans", sans-serif;
}

.wrap { max-width: 1200px; margin: 0 auto; padding: 0 16px; }

/* ---------- Testata ---------- */
.topbar { background: #fff; border-bottom: 1px solid var(--line); padding: 12px 0; }
.topbar .wrap { display: flex; align-items: center; gap: 12px 24px; flex-wrap: wrap; }
.logo { height: 48px; width: auto; display: block; }
.topbar h1 { margin: 0; padding-left: 24px; border-left: 1px solid var(--line); font-size: 20px; font-weight: 600; }
.topbar h1 span { font-weight: 400; color: var(--muted); font-size: 15px; margin-left: 6px; }

@media (max-width: 600px) {
  .logo { height: 40px; }
  .topbar h1 { padding-left: 0; border-left: 0; font-size: 18px; width: 100%; }
}

/* ---------- Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 20px;
  padding-top: 20px;
  padding-bottom: 40px;
  align-items: start;
}
.risultato { position: sticky; top: 16px; display: grid; gap: 16px; }
.modulo { display: grid; gap: 16px; }

@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .risultato { position: static; scroll-margin-top: 12px; }
}

/* ---------- Barra prezzo fissa (solo mobile) ---------- */
.barra-prezzo { display: none; }

@media (max-width: 900px) {
  body { padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
  html { scroll-behavior: smooth; }

  .barra-prezzo {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
    background: #1f2328;
    color: #fff;
    text-decoration: none;
    border-top: 3px solid var(--accent);
    box-shadow: 0 -4px 16px rgba(16, 24, 40, .18);
  }
  .barra-prezzo.errore { border-top-color: var(--err); }
  .bp-voce { display: flex; flex-direction: column; min-width: 0; }
  .bp-voce small { font-size: 11px; color: #aab0bb; white-space: nowrap; }
  .bp-voce strong { font-size: 15px; white-space: nowrap; }
  .bp-pubblico strong { font-size: 22px; line-height: 1.1; }
  .bp-errore { font-weight: 600; color: #ffb4b8; }
  .bp-vai { margin-left: auto; font-size: 13px; color: #aab0bb; white-space: nowrap; }
}

@media (max-width: 380px) {
  .barra-prezzo { gap: 10px; }
  .bp-voce strong { font-size: 13px; }
  .bp-pubblico strong { font-size: 19px; }
}

/* ---------- Card ---------- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
}
.card h2 {
  margin: 0 0 14px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  font-weight: 600;
}

/* ---------- Campi ---------- */
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
@media (max-width: 600px) {
  .grid, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > span, .field > .lbl { font-size: 13px; font-weight: 600; }
.field small, .check small { font-weight: 400; color: var(--muted); }

input[type="number"], select {
  width: 100%;
  font: inherit;
  padding: 8px 10px;
  border: 1px solid #cfd4dc;
  border-radius: 8px;
  background: #fff;
  color: inherit;
  min-height: 38px;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
select:disabled, input:disabled { background: #f2f4f7; color: var(--muted); }

.checks { display: flex; flex-wrap: wrap; gap: 8px 20px; margin-top: 14px; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; }
.check input { width: 17px; height: 17px; accent-color: var(--accent); margin: 0; }
.check.sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.check[hidden] { display: none; }
.check:has(input:disabled) { opacity: .5; cursor: default; }

.info {
  align-self: end;
  font-size: 13px;
  color: var(--muted);
  background: #f9fafb;
  border-radius: 8px;
  padding: 8px 10px;
  min-height: 38px;
  justify-content: center;
}
.info:empty { visibility: hidden; }
.info strong { color: var(--text); }

/* ---------- Risultato ---------- */
.prezzi { border-top: 4px solid var(--accent); }

.categoria { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }
.categoria small { color: var(--muted); font-size: 12px; }
.badge {
  align-self: flex-start;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  background: #eef0f3;
  color: #344054;
}
.badge-ristampa { background: #e8f4ff; color: #175cd3; }
.badge-urgenza { background: #fef3f2; color: var(--err); }
.badge-micro-commessa { background: #fffaeb; color: var(--warn); }
.badge-unit-rapida { background: #ecfdf3; color: var(--ok); }

.prezzo-principale { display: flex; flex-direction: column; }
.prezzo-principale span { font-size: 13px; color: var(--muted); }
.prezzo-principale strong { font-size: 40px; line-height: 1.1; letter-spacing: -.02em; }
.prezzo-principale small { color: var(--muted); }

.prezzi-secondari {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.prezzi-secondari div { display: flex; flex-direction: column; }
.prezzi-secondari span { font-size: 13px; color: var(--muted); }
.prezzi-secondari strong { font-size: 22px; }
.prezzi-secondari small { font-size: 11px; color: var(--warn); }

.riga {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 0;
  border-bottom: 1px dashed var(--line);
  font-size: 14px;
}
.riga:last-of-type { border-bottom: 0; }
.riga span { color: var(--muted); }
.riga strong { font-weight: 600; text-align: right; }
.riga small { color: var(--muted); font-weight: 400; }
.riga.totale strong { font-size: 16px; }
.riga.nota strong { color: var(--warn); }

.nota { font-size: 12px; color: var(--muted); margin: 10px 0 0; }

details { margin-top: 12px; }
details summary { cursor: pointer; font-size: 13px; font-weight: 600; color: var(--accent); }
details[open] summary { margin-bottom: 8px; }
.composizione { margin-top: 16px; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 6px 4px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; }
td small { display: block; color: var(--muted); font-size: 11px; }
.num { text-align: right; white-space: nowrap; }
tfoot td { font-weight: 700; border-bottom: 0; }

.errori { border-top: 4px solid var(--err); }
.errori h2 { color: var(--err); }
.errori ul { margin: 0; padding-left: 18px; }
.errori li { margin: 4px 0; }

.avviso {
  font-size: 13px;
  background: #fffaeb;
  color: var(--warn);
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 12px;
}
/* ---------- Testo per il cliente ---------- */
.testo-cliente textarea {
  width: 100%;
  font: inherit;
  font-size: 14px;
  line-height: 1.5;
  padding: 10px 12px;
  border: 1px solid #cfd4dc;
  border-radius: 8px;
  background: #f9fafb;
  color: inherit;
  resize: vertical;
  field-sizing: content;   /* si allunga con il testo (dove supportato) */
}
.testo-cliente textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); background: #fff; }
.testo-azioni { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-top: 10px; }
.testo-azioni small { font-size: 12px; color: var(--muted); }
.copia-testo {
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 8px 16px;
  min-height: 38px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}
.copia-testo:hover { filter: brightness(.95); }
.copia-testo:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.copia-testo.fatto { background: var(--ok); }

.field[hidden] { display: none; }
#campoCostoCordonatura input { border-color: var(--warn); background: #fffaeb; }

/* ---------- Pagina iniziale ---------- */
.home { padding-top: 28px; padding-bottom: 48px; }
.home-intro { margin: 0 0 18px; color: var(--muted); }
.home-griglia {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 16px;
}
.home-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-decoration: none;
  color: inherit;
  border-top: 4px solid var(--accent);
  transition: transform .15s ease, box-shadow .15s ease;
}
.home-card h2 { margin: 0; font-size: 20px; text-transform: none; letter-spacing: 0; color: var(--text); }
.home-card p { margin: 0; color: var(--muted); font-size: 14px; flex: 1; }
.home-tag { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--accent); }
.home-vai { font-size: 14px; font-weight: 600; color: var(--accent); margin-top: 6px; }
a.home-card:hover, a.home-card:focus-visible { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(16, 24, 40, .12); }
a.home-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.home-card-off { border-top-color: var(--line); opacity: .7; }
.home-card-off .home-tag, .home-card-off .home-vai { color: var(--muted); }
.home-nota { margin-top: 24px; }
.home-nota code { background: #eef0f3; padding: 1px 5px; border-radius: 4px; }

/* Link di ritorno all'elenco dei calcolatori */
.torna { margin-left: auto; font-size: 14px; font-weight: 600; color: var(--accent); text-decoration: none; white-space: nowrap; }
.torna:hover { text-decoration: underline; }
@media (max-width: 600px) {
  .torna { margin-left: 0; order: -1; width: 100%; }
}
