:root{
  --bg:#f6f7fb;
  --card:#ffffff;
  --text:#0f172a;
  --muted:#475569;
  --border:#e2e8f0;
  --shadow: 0 10px 30px rgba(2,8,23,.08);
  --shadow-sm: 0 6px 18px rgba(2,8,23,.06);
  --primary:#2563eb;
  --primary-contrast:#ffffff;
  --danger:#dc2626;
  --success:#16a34a;
  --violet:#7c3aed;
  --secondary:#334155;
  --warning:#f59e0b;
  --info:#0ea5e9;
  --radius:16px;
  --topbar-h: 76px;
}

*{ box-sizing:border-box; }
html,body{ height:100%; }
body{
  margin:0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji","Segoe UI Emoji";
  background:var(--bg);
  color:var(--text);
}

a{ color:var(--primary); }

.topbar{
  position:fixed;
  top:0;
  left:0;
  right:0;
  z-index:50;
  width:100%;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:16px;
  padding:14px 18px;
  border-bottom:1px solid var(--border);
  background:rgba(246,247,251,.9);
  backdrop-filter: blur(10px);
  box-shadow: 0 10px 24px rgba(2,8,23,.10);
}

.brand{ display:flex; gap:12px; align-items:center; }
.brand__icon{ width:36px; height:36px; }
.brand__name{ font-weight:800; letter-spacing:.2px; }
.brand__sub{ font-size:12px; color:var(--muted); margin-top:2px; }

.topbar__right{ display:flex; gap:8px; flex-wrap:wrap; justify-content:flex-end; }

.container{
  width:100%;
  max-width: none;
  /* spazio per topbar fixed */
  margin: calc(var(--topbar-h) + 18px) auto 18px;
  padding: 0 14px 28px;
  display:flex;
  flex-direction:column;
  gap:14px;
}

.banner{
  width:100%;
  border:1px solid rgba(220,38,38,.25);
  background:rgba(220,38,38,.06);
  border-radius: var(--radius);
  padding:14px;
}
.banner__title{ font-weight:800; }
.banner__body{ color:var(--muted); margin-top:4px; }

.card{
  width:100%;
  background:var(--card);
  border:1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 16px;
}

/* Card tints: colori leggeri per distinguere le sezioni */
.card--doc{ background:#f4f8ff; border-color: rgba(37,99,235,.18); }
.card--dich{ background:#f7f5ff; border-color: rgba(99,102,241,.18); }
.card--parti{ background:#f4fff7; border-color: rgba(34,197,94,.18); }
.card--impianto{ background:#f1fbff; border-color: rgba(14,165,233,.18); }
.card--verifiche{ background:#fffaf1; border-color: rgba(245,158,11,.22); }
.card--schema{ background:#fff5f5; border-color: rgba(244,63,94,.18); }
.card--finale{ background:#f7f8fa; border-color: rgba(100,116,139,.20); }

.card__header{
  display:flex;
  flex-direction:column;
  gap:2px;
  margin-bottom: 12px;
}
.card__title{
  margin:0;
  font-size:18px;
  letter-spacing:.1px;
}
.card__subtitle{
  font-size:13px;
  color:var(--muted);
}

.subcard{
  margin-top:12px;
  padding:12px;
  border:1px dashed var(--border);
  border-radius: 14px;
  background: #fbfcff;
}
.subcard__title{
  font-weight:700;
  margin-bottom:10px;
}

.grid{
  display:grid;
  gap:12px;
}
.grid--2{ grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid--3{ grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid--1{ grid-template-columns: 1fr; }

@media (max-width: 900px){
  .grid--2, .grid--3{ grid-template-columns: 1fr; }
  .topbar{ align-items:flex-start; }
}

.field label{
  display:block;
  font-size:12px;
  color:var(--muted);
  margin: 2px 0 6px;
}
.field input, .field select, .field textarea{
  width:100%;
  border:1px solid var(--border);
  border-radius: 12px;
  padding:10px 12px;
  background:#fff;
  color:var(--text);
  outline:none;
  transition: box-shadow .15s ease, border-color .15s ease;
}
.field input:focus, .field select:focus, .field textarea:focus{
  border-color: rgba(37,99,235,.5);
  box-shadow: 0 0 0 4px rgba(37,99,235,.12);
}
.hint{
  font-size:12px;
  color:var(--muted);
  margin-top:6px;
}

.divider{
  height:1px;
  background:var(--border);
  margin: 14px 0;
}

.row{
  display:flex;
  align-items:center;
  gap:10px;
}
.row--right{ justify-content:flex-end; }
.row--wrap{ flex-wrap:wrap; }
.spacer{ flex:1; }

.btn{
  border:1px solid var(--border);
  background:#fff;
  color:var(--text);
  padding:10px 12px;
  border-radius: 12px;
  font-weight:650;
  cursor:pointer;
  transition: transform .05s ease, box-shadow .15s ease, border-color .15s ease;
  box-shadow: 0 6px 18px rgba(2,8,23,.06);
  display:inline-flex;
  align-items:center;
  gap:8px;
}
.btn:hover{ border-color: rgba(37,99,235,.35); }
.btn:active{ transform: translateY(1px); }

.btn--ghost{
  /* "ghost" ma comunque colorato (richiesta: pulsanti colorati) */
  background: rgba(37,99,235,.10);
  border-color: rgba(37,99,235,.22);
  color: #1d4ed8;
}
.btn--primary{
  background: var(--primary);
  border-color: rgba(37,99,235,.9);
  color: var(--primary-contrast);
}
.btn--secondary{
  background: rgba(51,65,85,.12);
  border-color: rgba(51,65,85,.22);
  color: #0f172a;
}
.btn--info{
  background: rgba(14,165,233,.16);
  border-color: rgba(14,165,233,.28);
  color: #075985;
}
.btn--warning{
  background: rgba(245,158,11,.18);
  border-color: rgba(245,158,11,.28);
  color: #92400e;
}
.btn--success{
  background: rgba(34,197,94,.16);
  border-color: rgba(34,197,94,.28);
  color: #166534;
}
.btn--violet{
  background: rgba(124,58,237,.14);
  border-color: rgba(124,58,237,.26);
  color: #5b21b6;
}
.btn--danger{
  background: var(--danger);
  border-color: rgba(220,38,38,.9);
  color: #fff;
}

.alert{
  border-radius: 14px;
  padding: 12px;
  border:1px solid var(--border);
  background:#f8fafc;
  color:var(--text);
  margin-top:12px;
}
.alert--warning{ border-color: rgba(245,158,11,.3); background: rgba(245,158,11,.07); }
.alert--info{ border-color: rgba(14,165,233,.3); background: rgba(14,165,233,.08); }
.alert--danger{ border-color: rgba(220,38,38,.3); background: rgba(220,38,38,.06); }

.checklist{ display:flex; flex-direction:column; gap:10px; }
.check{ display:flex; gap:10px; align-items:flex-start; font-size:14px; }
.check input{ transform: translateY(2px); }

.tableWrap{ width:100%; overflow:auto; border-radius:14px; border:1px solid var(--border); }
.table{
  width:100%;
  border-collapse: collapse;
  min-width: 860px;
}
.table th, .table td{
  border-bottom:1px solid var(--border);
  padding:10px;
  vertical-align: top;
  font-size: 13px;
}
.table th{ color:var(--muted); text-align:left; background:#f8fafc; position:sticky; top:0; }
.table td input{
  width:100%;
  border:1px solid var(--border);
  border-radius:12px;
  padding:10px 12px;
}

/* Select "esito" nelle tabelle (check-list / voci personalizzate): stesso look degli input */
.table td select{
  width:100%;
  border:1px solid var(--border);
  border-radius:12px;
  padding:10px 12px;
  background:#fff;
  color:var(--text);
  outline:none;
  transition: box-shadow .15s ease, border-color .15s ease;
}
.table td select:focus{
  border-color: rgba(37,99,235,.5);
  box-shadow: 0 0 0 4px rgba(37,99,235,.12);
}

.canvasWrap{
  border:1px solid var(--border);
  border-radius: 14px;
  /* finestra compatta: riquadro più piccolo con scroll se necessario */
  height: 380px;
  overflow:auto;
  background:#fff;
}
canvas{ display:block; width:100%; height:auto; background: transparent; }

/* Griglia "carta millimetrata" sul canvas schema (la CSS background non entra nell'export, ma aiuta la compilazione) */
#schemaCanvas{
  background:
    linear-gradient(to right, rgba(15,23,42,.05) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(15,23,42,.05) 1px, transparent 1px);
  background-size: 24px 24px;
}

.footer{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  padding: 12px 6px 0;
}
.small{ font-size: 12px; color: var(--muted); }

.modal[hidden],
.modal[aria-hidden="true"]{
  display:none !important;
}

.modal{
  position:fixed;
  inset:0;
  display:flex;
  align-items:stretch;
  justify-content:center;
  z-index:100;
}
.modal__backdrop{
  position:absolute;
  inset:0;
  background: rgba(2,8,23,.55);
}
.modal__panel{
  position:relative;
  margin: 26px 12px;
  width: min(980px, 100%);
  max-height: calc(100vh - 52px);
  background:#fff;
  border-radius: 18px;
  border:1px solid rgba(226,232,240,.9);
  box-shadow: var(--shadow);
  display:flex;
  flex-direction:column;
  overflow:hidden;
}
.modal__header{
  padding:14px 16px;
  border-bottom:1px solid var(--border);
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap:12px;
}
.modal__title{ font-weight:900; font-size:16px; }
.modal__subtitle{ font-size:12px; color:var(--muted); margin-top:2px; }
.modal__body{
  padding: 14px 16px;
  overflow:auto;
}
.modal__footer{
  padding: 12px 16px;
  border-top:1px solid var(--border);
  display:flex;
  justify-content:flex-end;
  gap:8px;
  flex-wrap:wrap;
}
.iconBtn{
  width:40px;
  height:40px;
  border-radius: 12px;
  border:1px solid var(--border);
  background:#fff;
  cursor:pointer;
}
.iconBtn:hover{ border-color: rgba(37,99,235,.35); }

.pill{
  display:inline-flex;
  align-items:center;
  gap:8px;
  border:1px solid var(--border);
  border-radius:999px;
  padding:6px 10px;
  background:#f8fafc;
  color:var(--muted);
  font-size:12px;
}
.list{
  display:flex;
  flex-direction:column;
  gap:10px;
}
.listItem{
  border:1px solid var(--border);
  border-radius: 14px;
  padding:12px;
  display:flex;
  gap:12px;
  align-items:flex-start;
  justify-content:space-between;
}
.listItem__main{ flex:1; min-width:0; }
.listItem__title{ font-weight:800; }
.listItem__meta{ font-size:12px; color:var(--muted); margin-top:4px; }
.listItem__actions{ display:flex; gap:8px; flex-wrap:wrap; justify-content:flex-end; }

.kbd{
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 12px;
  padding: 3px 7px;
  border:1px solid var(--border);
  border-bottom-width:2px;
  border-radius:8px;
  background:#fff;
}
