  :root {
    --ink: #1c2b2e;
    --paper: #fbfaf6;
    --panel: #ffffff;
    --line: #d9d3c4;
    --accent: #0f6e56;
    --accent-dark: #085041;
    --accent-soft: #e1f5ee;
    --warn: #993c1d;
    --warn-soft: #faece7;
    --muted: #6b675c;
  }
  * { box-sizing: border-box; }
  body { margin: 0; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: var(--paper); color: var(--ink); }
  .app { max-width: 720px; margin: 0 auto; padding: 16px 16px 80px; }
  .brand { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
  .brand .mark { width: 36px; height: 36px; border-radius: 8px; background: var(--accent-dark); color: #fff; display: flex; align-items: center; justify-content: center; font-family: Georgia, serif; font-size: 18px; flex-shrink: 0; }
  .brand h1 { font-size: 17px; margin: 0; font-weight: 600; }
  .brand p { font-size: 12px; margin: 1px 0 0; color: var(--muted); } 

  .stepper { display: flex; gap: 6px; margin-bottom: 20px; flex-wrap: wrap; }
  .stepper button { flex: 1; min-width: 60px; border: none; background: var(--line); color: var(--ink); padding: 8px 4px; font-size: 11px; border-radius: 6px; cursor: pointer; opacity: .55; }
  .stepper button.active { background: var(--accent-dark); color: #fff; opacity: 1; }
  .stepper button.done { background: var(--accent-soft); color: var(--accent-dark); opacity: 1; } 

  .panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px; margin-bottom: 14px; }
  .panel h2 { font-size: 14px; margin: 0 0 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--accent-dark); }
  label { display: block; font-size: 12px; color: var(--muted); margin: 10px 0 4px; }
  label:first-child { margin-top: 0; }
  input[type=text], input[type=password], input[type=date], input[type=time], textarea, select {
    width: 100%; border: 1px solid var(--line); border-radius: 6px; padding: 9px 10px; font-size: 14px;
    font-family: inherit; background: #fff; color: var(--ink);
  }
  input[readonly] { background-color: #f0ede6; color: var(--accent-dark); font-weight: 600; }
  textarea { resize: vertical; min-height: 64px; }
  .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; } 

  .checkbox-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 8px;
    background: #fdfcf9;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 6px;
    margin-bottom: 6px;
  }
  .checkbox-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--ink);
    cursor: pointer;
    margin: 0 !important;
  }
  .checkbox-item input[type=checkbox] {
    cursor: pointer;
    width: 15px;
    height: 15px;
    accent-color: var(--accent-dark);
  }

  .element-card, .sturazione-card { border: 1px solid var(--line); border-radius: 8px; padding: 12px; margin-bottom: 10px; background: #fdfcf9; position: relative; }
  .element-card .top, .sturazione-card .top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
  .element-card .top input, .sturazione-card .top select { font-weight: 600; }
  .remove-btn { border: none; background: none; color: var(--warn); font-size: 12px; cursor: pointer; padding: 4px 6px; white-space: nowrap; flex-shrink: 0; }
  .add-btn { width: 100%; padding: 10px; border: 1px dashed var(--line); border-radius: 8px; background: none; color: var(--accent-dark); font-size: 13px; cursor: pointer; margin-top: 4px; } 

  .btn { border: none; border-radius: 7px; padding: 11px 14px; font-size: 14px; font-weight: 600; cursor: pointer; width: 100%; }
  .btn-primary { background: var(--accent-dark); color: #fff; }
  .btn-primary:disabled { opacity: .5; }
  .btn-ghost { background: var(--accent-soft); color: var(--accent-dark); }
  .btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; } 

  .nav-row { display: flex; gap: 8px; margin-top: 16px; }
  .nav-row .btn { width: auto; flex: 1; }
  .btn-secondary { background: var(--line); color: var(--ink); } 

  .status { font-size: 12px; color: var(--muted); margin-top: 8px; text-align: center; min-height: 14px; }
  .status.error { color: var(--warn); } 

  /* textarea, non contenteditable: gli a capo si conservano esattamente,
     anche quando lo step è nascosto (innerText su display:none li perdeva) */
  .report-preview { display: block; width: 100%; white-space: pre-wrap; font-size: 13px;
    line-height: 1.55; background: #fff; border: 1px solid var(--line); border-radius: 8px;
    padding: 14px; font-family: Georgia, 'Times New Roman', serif; min-height: 200px;
    resize: vertical; overflow: hidden; color: var(--ink); }
  .report-preview:focus { outline: 2px solid var(--accent-soft); } 

  .hint { font-size: 11.5px; color: var(--muted); margin-top: -4px; margin-bottom: 10px; }
  .spinner { display: inline-block; width: 13px; height: 13px; border: 2px solid var(--accent-soft); border-top-color: var(--accent-dark); border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -2px; margin-right: 6px; }
  @keyframes spin { to { transform: rotate(360deg); } } 

  .photo-strip { display: flex; flex-wrap: wrap; gap: 10px; margin: 6px 0 4px; }
  .photo-item { position: relative; width: 80px; }
  .photo-item img { width: 80px; height: 80px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); display: block; background: #eee; }
  .photo-item .photo-caption { width: 80px; font-size: 9px; padding: 3px 4px; margin-top: 3px; border-radius: 4px; border: 1px solid var(--line); }
  .photo-item .photo-remove { position: absolute; top: -7px; right: -7px; width: 18px; height: 18px; border-radius: 50%; border: none; background: var(--warn); color: #fff; font-size: 11px; line-height: 1; cursor: pointer; padding: 0; }
  .photo-add-btn { border: 1px dashed var(--line); background: none; color: var(--accent-dark); font-size: 12px; padding: 7px 12px; border-radius: 6px; cursor: pointer; }
  .photo-summary-row { font-size: 12.5px; margin-bottom: 6px; }
  
  @media print {
    body { background: #fff; color: #000; }
    .app { max-width: 100%; padding: 0; }
    .stepper, .nav-row, .btn-row, .brand, .hint, .photo-add-btn, .photo-remove,
    .photo-input, #export-status, .panel h2, .no-print { display: none !important; }
    .panel { border: none; padding: 0; margin: 0; }
    .report-preview { border: none; padding: 0; font-size: 11pt; height: auto !important; overflow: visible; }
    /* Le foto restano: prima venivano nascoste e la stampa usciva senza allegati. */
    #print-photos { display: block !important; page-break-before: always; }
    #print-photos img { max-width: 100%; page-break-inside: avoid; }
    #print-photos figure { page-break-inside: avoid; margin: 0 0 14px; }
    #print-photos figcaption { font-size: 9pt; color: #555; font-style: italic; }
  }


  /* ---------- aggiunte: archivio, condivisione, avvisi ---------- */

  #print-photos { display: none; }

  .toolbar { display: flex; gap: 8px; margin-left: auto; flex-shrink: 0; }
  .icon-btn { border: 1px solid var(--line); background: var(--panel); color: var(--accent-dark);
    border-radius: 7px; padding: 7px 10px; font-size: 12px; cursor: pointer; white-space: nowrap; }
  .icon-btn:hover { background: var(--accent-soft); }

  .banner { border-radius: 8px; padding: 10px 12px; font-size: 12.5px; margin-bottom: 12px;
    border: 1px solid var(--line); background: var(--accent-soft); color: var(--accent-dark); }
  .banner.warn { background: var(--warn-soft); color: var(--warn); border-color: #e8c4b6; }
  .banner button { border: none; background: none; color: inherit; font-weight: 600;
    text-decoration: underline; cursor: pointer; padding: 0; font-size: inherit; font-family: inherit; }

  .archive-item { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px;
    margin-bottom: 8px; background: #fdfcf9; }
  .archive-item .t { font-weight: 600; font-size: 13.5px; }
  .archive-item .m { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
  .archive-actions { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
  .archive-actions button { border: 1px solid var(--line); background: #fff; border-radius: 6px;
    padding: 5px 9px; font-size: 11.5px; cursor: pointer; color: var(--ink); }
  .archive-actions button.danger { color: var(--warn); border-color: #e8c4b6; }
  .empty { font-size: 12.5px; color: var(--muted); text-align: center; padding: 14px 0; }

  #manual-download { margin-top: 10px; }
  #manual-download a { display: block; text-align: center; background: var(--warn-soft);
    color: var(--warn); border: 1px solid #e8c4b6; border-radius: 7px; padding: 10px;
    font-size: 13px; font-weight: 600; text-decoration: none; }

  .install-hint { position: fixed; left: 12px; right: 12px; bottom: 12px; z-index: 50;
    background: var(--accent-dark); color: #fff; border-radius: 10px; padding: 12px 14px;
    display: flex; align-items: center; gap: 10px; font-size: 13px;
    box-shadow: 0 6px 20px rgba(0,0,0,.25); max-width: 696px; margin: 0 auto; }
  .install-hint button { border: none; border-radius: 6px; padding: 7px 12px; font-size: 12.5px;
    font-weight: 600; cursor: pointer; background: #fff; color: var(--accent-dark); }
  .install-hint .close { background: none; color: #fff; opacity: .8; padding: 4px 6px; }
