:root {
  --bg: #f4f2ee;
  --card: #ffffff;
  --ink: #1f2430;
  --muted: #6b7080;
  --line: #e2ded6;
  --primary: #1f3a5f;
  --primary-ink: #ffffff;
  --accent: #b08d57;
  --danger: #a33a32;
  --ok: #2f6b45;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 20, 30, .06), 0 2px 10px rgba(20, 20, 30, .04);
  font-size: 16px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.5;
}
a { color: var(--primary); }
h1 { font-size: 1.6rem; margin: .2em 0 .6em; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 1.2rem; margin: 0 0 .7em; font-weight: 650; }
h3 { font-size: 1rem; margin: 1.2em 0 .5em; }
code { background: #f1ede5; padding: .05em .35em; border-radius: 4px; font-size: .92em; }
.mono, pre { font-family: Consolas, "SF Mono", Menlo, monospace; font-size: .88rem; }
pre { background: #f7f5f0; padding: .8em; border-radius: 6px; overflow: auto; }
.muted { color: var(--muted); }
.small { font-size: .9rem; }
.ok { color: var(--ok); }
.ko { color: var(--danger); }
[hidden] { display: none !important; }

/* barra superiore */
.topbar {
  display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap;
  background: var(--primary); color: #fff; padding: .6rem 1.4rem;
}
.brand { display: flex; align-items: center; gap: .6rem; }
.brand small { display: block; opacity: .75; font-size: .78rem; }
.logo { font-size: 1.6rem; color: var(--accent); }
.mainnav { display: flex; gap: .2rem; flex-wrap: wrap; flex: 1; }
.mainnav a { color: #fff; text-decoration: none; padding: .45rem .75rem; border-radius: 6px; opacity: .85; }
.mainnav a:hover { background: rgba(255,255,255,.1); opacity: 1; }
.mainnav a.active { background: rgba(255,255,255,.16); opacity: 1; }
.userbox { display: flex; gap: .8rem; align-items: center; }
.userbox a, .userbox .link { color: #fff; }
.container { max-width: 1100px; margin: 0 auto; padding: 1.4rem; }
.footer { text-align: center; color: var(--muted); font-size: .8rem; padding: 2rem 0; }

/* card */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.3rem 1.4rem; margin-bottom: 1.2rem; box-shadow: var(--shadow); }
.card.narrow, .narrow { max-width: 620px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1rem; }
.tipo-card { display: flex; flex-direction: column; margin: 0; }
.tipo-card h2 { margin-bottom: .3em; }
.tipo-card .btn-row { margin-top: auto; padding-top: .6rem; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: .6rem; }
.crumbs { margin: 0; font-size: .9rem; color: var(--muted); }
.crumbs a { color: var(--muted); }
.login-box { max-width: 400px; margin: 3rem auto; }

/* moduli */
label { display: block; margin-bottom: .9rem; font-weight: 500; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=time], input[type=number], input[type=search], input:not([type]), select, textarea {
  display: block; width: 100%; margin-top: .3rem;
  font: inherit; font-weight: 400; color: var(--ink);
  background: #fff; border: 1px solid #cfc9bd; border-radius: 7px; padding: .55rem .7rem;
}
input[type=file] { display: block; margin-top: .4rem; font-weight: 400; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(31,58,95,.25); border-color: var(--primary); }
.invalid { border-color: var(--danger) !important; background: #fff6f5 !important; }
label.check { display: flex; align-items: flex-start; gap: .5rem; font-weight: 400; cursor: pointer; }
label.check input { margin-top: .3rem; width: auto; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
.grid-auto { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 0 1rem; }
.field { margin-bottom: .9rem; }
.field-label { margin-bottom: 0; }
.field-testo_lungo, .field-elenco, .field-formule { grid-column: 1 / -1; }
.req { color: var(--danger); }
.help { display: block; color: var(--muted); font-size: .83rem; margin-top: .2rem; font-weight: 400; }
.field-error { color: var(--danger); font-size: .85rem; }
.field-error:empty { display: none; }
.search { max-width: 420px; margin-bottom: 1rem; }
.inline { display: inline; }
.inline-search { display: flex; gap: .5rem; }
.inline-search input { margin: 0; min-width: 260px; }

/* pulsanti */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .3rem;
  font: inherit; font-weight: 550; text-decoration: none; cursor: pointer;
  border: 1px solid transparent; border-radius: 7px; padding: .55rem 1rem; line-height: 1.2;
}
.btn-primary { background: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { background: #17304f; }
.btn-primary:disabled { opacity: .45; cursor: not-allowed; }
.btn-light { background: #fff; color: var(--ink); border-color: #cfc9bd; }
.btn-light:hover { background: #f6f3ed; }
.btn-danger { background: #fff; color: var(--danger); border-color: #e3b8b4; }
.btn-danger:hover { background: #fbeeed; }
.btn-sm { padding: .3rem .6rem; font-size: .88rem; }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-top: .6rem; }
.btn-icon { border: 1px solid var(--line); background: #fff; border-radius: 6px; width: 2rem; height: 2rem; cursor: pointer; font-size: .95rem; }
.btn-icon:hover { background: #f4f1ea; }
.btn-icon.danger { color: var(--danger); }
.link { background: none; border: 0; padding: 0; font: inherit; color: var(--primary); text-decoration: underline; cursor: pointer; }
.sticky-actions { position: sticky; bottom: 0; background: #fff; padding: .7rem 0; border-top: 1px solid var(--line); }

/* avvisi */
.alert { padding: .8rem 1rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid; }
.alert ul { margin: .4rem 0 0; padding-left: 1.2rem; }
.alert-error { background: #fbeeed; border-color: #ecc3bf; color: #6d221c; }
.alert-success { background: #edf6f0; border-color: #bcdcc7; color: #1f4a2f; }
.alert-info { background: #eef2f8; border-color: #c7d3e5; color: #1f3a5f; }
.alert .link { color: inherit; }
.badge { display: inline-block; background: #efe9dd; color: #6b5530; border-radius: 99px; padding: .1rem .6rem; font-size: .8rem; font-weight: 600; }
.tag { margin: .1rem; display: inline-block; }

/* procedura guidata */
.stepper { list-style: none; display: flex; flex-wrap: wrap; gap: .4rem; padding: 0; margin: 0 0 1rem; counter-reset: s; }
.stepper button {
  display: flex; align-items: center; gap: .4rem; background: #fff; border: 1px solid var(--line);
  border-radius: 99px; padding: .35rem .9rem .35rem .4rem; font: inherit; cursor: pointer; color: var(--muted);
}
.stepper .n { display: inline-grid; place-items: center; width: 1.6rem; height: 1.6rem; border-radius: 50%; background: #ece7dd; font-size: .85rem; font-weight: 600; }
.stepper li.active button { border-color: var(--primary); color: var(--primary); font-weight: 600; }
.stepper li.active .n { background: var(--primary); color: #fff; }
.stepper li.done .n { background: var(--ok); color: #fff; }
.wizard-bar { display: flex; gap: .6rem; align-items: center; position: sticky; bottom: 0; background: var(--bg); padding: .8rem 0; }
.wizard-bar .spacer { flex: 1; }
.step .grid-auto { margin-top: .4rem; }
.step > .field { max-width: 100%; }

.list-item, .formula-card { border: 1px solid var(--line); border-radius: 8px; padding: .7rem .9rem .2rem; margin-bottom: .7rem; background: #fcfbf8; }
.list-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .4rem; }
.list-actions { display: flex; gap: .3rem; }
.formule-toolbar { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: .8rem; }
.formule-toolbar select { flex: 1; min-width: 240px; margin: 0; }
.formula-preview { font-family: "Times New Roman", Georgia, serif; font-size: 1.02rem; background: #fff; border-left: 3px solid var(--accent); padding: .4rem .7rem; white-space: pre-line; margin: .2rem 0 .7rem; }
.formula-card details { margin-bottom: .5rem; font-size: .9rem; }
.formula-card summary { cursor: pointer; color: var(--muted); }

.summary-section { border-bottom: 1px solid var(--line); padding-bottom: .4rem; margin-bottom: .6rem; }
.summary-section h3 { margin-top: .4rem; }
.summary dl { display: grid; grid-template-columns: minmax(150px, 230px) 1fr; gap: .2rem 1rem; margin: 0; }
.summary dt { color: var(--muted); }
.summary dd { margin: 0; white-space: pre-line; }
.summary dd ol { margin: 0; padding-left: 1.2rem; }

/* tabelle */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: .55rem .5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { font-size: .85rem; color: var(--muted); font-weight: 600; }
.table input { margin: 0; }
.table .actions { text-align: right; white-space: nowrap; }
.table-wrap { overflow-x: auto; margin: 0 -.4rem; }
.grid-table { border-collapse: collapse; min-width: 100%; }
.grid-table th { font-size: .82rem; text-align: left; color: var(--muted); padding: .3rem .4rem; white-space: nowrap; }
.grid-table td { padding: .25rem .3rem; vertical-align: top; }
.grid-table td input, .grid-table td select, .grid-table td textarea { margin: 0; min-width: 140px; padding: .4rem .5rem; }
.grid-table td textarea { min-width: 260px; }
.grid-table .row-n { color: var(--muted); font-weight: 600; padding-top: .6rem; }
.grid-table .row-actions { white-space: nowrap; }
.paste-box { margin-top: 1rem; border-top: 1px dashed var(--line); padding-top: 1rem; }

/* amministrazione */
.copy { font-family: Consolas, Menlo, monospace; font-size: .85rem; background: #f1ede5; border: 1px solid transparent; border-radius: 5px; padding: .15rem .45rem; cursor: copy; text-align: left; }
.copy:hover { border-color: var(--accent); }
.copy.copied { background: #dcefe2; }
.cat-title { display: flex; align-items: center; gap: .8rem; margin-top: 1.4rem; }
.list-card { padding: 0; }
.formula-row { display: block; padding: .7rem 1rem; border-bottom: 1px solid var(--line); text-decoration: none; color: var(--ink); }
.formula-row:last-child { border-bottom: 0; }
.formula-row:hover { background: #faf8f3; }
.formula-row span { display: block; color: var(--muted); font-size: .9rem; }
.formula-row.disabled { opacity: .55; }
.help-card summary { cursor: pointer; }
.guide .table td:first-child { white-space: nowrap; }
#json-status { font-size: .9rem; }

@media (max-width: 700px) {
  .container { padding: .8rem; }
  .grid2 { grid-template-columns: 1fr; }
  .topbar { padding: .6rem .8rem; gap: .6rem; }
  .summary dl { grid-template-columns: 1fr; }
  .summary dt { margin-top: .4rem; }
}
@media print {
  .topbar, .footer, .wizard-bar, .stepper { display: none; }
}

.persona { display: block; }
.persona input[type=text] { margin-top: .4rem; }
.formula-vars .field-wide { grid-column: 1 / -1; }
.formula-preview strong { font-weight: 700; }
.steps-list { padding-left: 1.2rem; }
.steps-list li { margin-bottom: .6rem; }
.otp-key { display: flex; align-items: center; gap: .6rem; margin: .4rem 0; }
.otp-key code { font-size: 1.15rem; letter-spacing: .08em; padding: .3rem .6rem; }
.data-bar { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: .8rem; }
.alert.draft { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.grid-table input.w-xs { min-width: 0; width: auto; }
.grid-table input.w-sm { min-width: 110px; }
.grid-table input.w-md { min-width: 170px; }
.grid-table input.w-lg { min-width: 240px; }
.ruolo-azione { min-width: 160px; margin: 0; padding: .35rem .4rem; }
@media print {
  #ruolo-root .btn-row, #ruolo-root .paste-box, .ruolo-azione, .row-actions, .page-head + p { display: none !important; }
  .card { box-shadow: none; border: 0; padding: 0; }
  .grid-table input { border: 0; padding: 0; }
}
/* anteprima */
.modal { position: fixed; inset: 0; background: rgba(20, 24, 34, .55); display: flex; align-items: flex-start; justify-content: center; padding: 2rem 1rem; z-index: 50; overflow: auto; }
.modal-box { background: var(--bg); border-radius: var(--radius); width: min(900px, 100%); box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.modal-head { display: flex; align-items: center; gap: .5rem; padding: .8rem 1rem; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--bg); border-radius: var(--radius) var(--radius) 0 0; }
.modal-head .spacer { flex: 1; }
.modal-body { padding: 1rem; }
.paper { background: #fff; max-width: 21cm; margin: 0 auto; padding: 2cm 2.2cm; box-shadow: 0 1px 6px rgba(0,0,0,.15); font-family: "Times New Roman", Georgia, serif; font-size: 12pt; line-height: 1.35; color: #000; }
.paper p { margin: 0 0 .25em; }
.paper .pv-empty { min-height: .9em; }
.paper .pv-header { text-align: center; color: #333; margin-bottom: 1em; }
.paper .pv-tab { display: inline-block; width: 2.5em; }
.paper .pv-num { display: inline-block; min-width: 1.5em; }
.paper .pv-break { border: 0; border-top: 2px dashed #bbb; margin: 1.5em 0; }
.paper .pv-table { border-collapse: collapse; width: 100%; margin: .4em 0; }
.paper .pv-table td { border: 1px dotted #bbb; padding: .2em .4em; vertical-align: top; }
/* editor dei campi */
.tabs { display: flex; gap: .3rem; border-bottom: 1px solid var(--line); margin-bottom: .8rem; }
.tab { background: none; border: 1px solid transparent; border-bottom: 0; padding: .45rem .9rem; border-radius: 7px 7px 0 0; cursor: pointer; font: inherit; color: var(--muted); }
.tab.active { background: #fff; border-color: var(--line); color: var(--ink); font-weight: 600; margin-bottom: -1px; }
.fe-card { border: 1px solid var(--line); border-radius: 8px; padding: .5rem .9rem; margin-bottom: .5rem; background: #fcfbf8; }
.fe-card > summary { cursor: pointer; list-style: none; }
.fe-card > summary::-webkit-details-marker { display: none; }
.fe-card > summary .list-head { margin-bottom: 0; }
.fe-card[open] > summary { margin-bottom: .6rem; border-bottom: 1px solid var(--line); padding-bottom: .4rem; }
.fe-nested { background: #fff; }
.fe-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 0 1rem; }
.fe-l { font-size: .88rem; margin-bottom: .6rem; }
.fe-c { font-size: .9rem; margin: .2rem 1rem .4rem 0; display: inline-flex; }
.fe-checks { display: flex; flex-wrap: wrap; }
.fe-cats { display: flex; flex-wrap: wrap; }
.fe-subbox { border-left: 3px solid var(--accent); padding-left: .8rem; margin: .5rem 0; }
.fe-subs { margin: .5rem 0; }
/* accesso, registrazione, installazione */
.login-links { text-align: center; margin: 1rem 0 0; font-size: .92rem; }
.hp { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
.checklist { list-style: none; padding: 0; }
.checklist li { padding: .2rem 0; }
.checklist .ok { color: var(--ok); }
.checklist .ko { color: var(--danger); font-weight: 600; }
code.wrap { word-break: break-all; white-space: normal; }
.nav-badge { display: inline-block; background: var(--accent); color: #fff; border-radius: 99px; padding: 0 .45rem; font-size: .78rem; font-weight: 700; margin-left: .2rem; }
.attesa { border-color: var(--accent); }
.qr { display: inline-block; background: #fff; padding: .5rem; border: 1px solid var(--line); border-radius: 8px; line-height: 0; }
.qr svg { width: 190px; height: 190px; }
.codes { display: grid; grid-template-columns: repeat(2, max-content); gap: .3rem 1.5rem; font-family: Consolas, Menlo, monospace; font-size: 1.05rem; background: #f7f5f0; padding: .8rem 1rem; border-radius: 8px; margin: .5rem 0; }
@media print { .codes-print-hide { display: none !important; } }
