/* Strumenti PDF (tool "pdf-tools", categoria "docs").
   Usa le variabili di style.css quando ci sono; i valori dopo la virgola sono solo di riserva. */

.pdf-note { display: flex; align-items: flex-start; gap: 10px; margin: 14px 0 0; font-size: 14px; color: var(--muted, #5b5870); }
.pdf-note svg { flex: 0 0 auto; }
body.pdf-lock { overflow: hidden; }

.pdf { max-width: 1100px; margin: 22px auto 0; display: grid; gap: 14px; position: relative; }
.pdf > * { min-width: 0; }

/* ---------- Pulsanti ---------- */
.pdf-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    min-height: 40px; padding: 8px 14px;
    border: 1px solid var(--line, #dcd9e8); border-radius: 999px;
    background: #fff; color: var(--ink, #0b0b14);
    font: inherit; font-size: 14px; cursor: pointer; white-space: nowrap;
    touch-action: manipulation; user-select: none; -webkit-user-select: none;
}
.pdf-btn:hover:not(:disabled) { border-color: var(--ink, #0b0b14); }
.pdf-btn:disabled { opacity: 0.45; cursor: default; }
.pdf-btn.primary { background: var(--accent, #0b7a6d); border-color: var(--accent, #0b7a6d); color: #fff; font-weight: 600; }
.pdf-btn.primary:hover:not(:disabled) { filter: brightness(1.1); border-color: var(--accent, #0b7a6d); }
.pdf-btn.danger { color: #b3261e; }
.pdf-btn.big { min-height: 50px; padding: 12px 26px; font-size: 16px; }
.pdf-btn.on { background: var(--tint, #e6f4f1); border-color: var(--accent, #0b7a6d); }
summary.pdf-btn { list-style: none; }
summary.pdf-btn::-webkit-details-marker { display: none; }

/* ---------- Zona di caricamento ---------- */
.pdf-drop {
    display: grid; justify-items: center; gap: 10px; text-align: center;
    padding: 48px 20px; border: 2px dashed var(--line, #dcd9e8); border-radius: 18px;
    background: var(--tint, #f4f3fb); cursor: pointer;
}
.pdf-drop[hidden] { display: none; }
.pdf-drop strong { font-size: 20px; }
.pdf-drop span { color: var(--muted, #5b5870); max-width: 46ch; }
.pdf.dragging .pdf-drop, .pdf.dragging .pdf-grid { outline: 3px dashed var(--accent, #0b7a6d); outline-offset: 4px; }

/* ---------- Barra degli strumenti ---------- */
.pdf-work { display: grid; gap: 12px; }
.pdf-work[hidden] { display: none; }
.pdf-bar { display: flex; flex-wrap: wrap; gap: 8px; }
.pdf-range { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pdf-range label { font-size: 14px; color: var(--muted, #5b5870); }
.pdf-range input {
    flex: 1 1 140px; min-width: 0; max-width: 260px; min-height: 40px; padding: 8px 12px;
    border: 1px solid var(--line, #dcd9e8); border-radius: 12px; font: inherit; font-size: 16px; background: #fff; color: var(--ink, #0b0b14);
}
.pdf-files { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; padding: 0; list-style: none; }
.pdf-file {
    display: inline-flex; align-items: center; gap: 8px; max-width: 100%;
    padding: 4px 6px 4px 12px; border: 1px solid var(--line, #dcd9e8); border-radius: 999px; background: #fff; font-size: 13px;
}
.pdf-file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 34ch; }
.pdf-file-n { color: var(--muted, #5b5870); white-space: nowrap; }
.pdf-file-x { border: 0; background: transparent; width: 28px; height: 28px; border-radius: 50%; cursor: pointer; color: var(--muted, #5b5870); font-size: 13px; }
.pdf-file-x:hover { background: var(--tint, #f0eff8); color: var(--ink, #0b0b14); }
.pdf-status { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }
.pdf-tip { margin: -6px 0 0; font-size: 13px; color: var(--muted, #5b5870); }

/* ---------- Griglia delle pagine ---------- */
.pdf-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 14px; align-items: start; }
.pdf-card, .pdf-btn, .pdf-cbtn { -webkit-tap-highlight-color: transparent; }
.pdf-card {
    position: relative; display: grid; gap: 6px; padding: 8px;
    border: 2px solid var(--line, #dcd9e8); border-radius: 14px; background: #fff;
    cursor: pointer; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.pdf-card.sel { border-color: var(--accent, #0b7a6d); background: var(--tint, #e6f4f1); }
.pdf-card.drag-ghost { opacity: 0.35; }
.pdf-card.drag-chosen { box-shadow: 0 10px 28px rgba(11, 11, 20, 0.25); }
.pdf-thumb { position: relative; width: 100%; background: #f1f0f7; border-radius: 6px; overflow: hidden; box-shadow: 0 1px 4px rgba(11, 11, 20, 0.15); }
.pdf-thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; opacity: 0; transition: opacity 0.2s; pointer-events: none; }
.pdf-card.ready .pdf-thumb img { opacity: 1; }
.pdf-num {
    position: absolute; left: 6px; bottom: 6px; min-width: 22px; padding: 1px 6px;
    border-radius: 999px; background: rgba(11, 11, 20, 0.72); color: #fff; font-size: 12px; text-align: center; font-variant-numeric: tabular-nums;
}
.pdf-tick {
    position: absolute; right: 6px; top: 6px; width: 24px; height: 24px; display: grid; place-items: center;
    border-radius: 50%; border: 2px solid #fff; background: rgba(11, 11, 20, 0.35); color: transparent; font-size: 14px; font-weight: 700;
}
.pdf-card.sel .pdf-tick { background: var(--accent, #0b7a6d); color: #fff; }
.pdf-edited { position: absolute; left: 6px; top: 6px; width: 22px; height: 22px; display: grid; place-items: center; border-radius: 50%; background: #ffd24a; font-size: 12px; }
.pdf-card-bar { display: flex; justify-content: space-between; gap: 4px; }
.pdf-cbtn {
    flex: 1 1 0; min-height: 36px; border: 1px solid var(--line, #dcd9e8); border-radius: 10px;
    background: #fff; color: var(--ink, #0b0b14); font-size: 16px; cursor: pointer; touch-action: manipulation;
}
.pdf-cbtn:hover { border-color: var(--ink, #0b0b14); }
.pdf-cbtn.del:hover { color: #b3261e; border-color: #b3261e; }
.pdf-fn { font-size: 11px; color: var(--muted, #5b5870); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Salvataggio ---------- */
.pdf-export { padding: 16px; border: 1px solid var(--line, #dcd9e8); border-radius: 16px; background: #fff; display: grid; gap: 12px; }
.pdf-export h2 { margin: 0; font-size: 18px; }
.pdf-opts { display: flex; flex-wrap: wrap; gap: 14px; }
.pdf-opts label { display: grid; gap: 4px; font-size: 13px; color: var(--muted, #5b5870); }
.pdf-opts select, .pdf-ed-props select {
    min-height: 40px; padding: 6px 10px; border: 1px solid var(--line, #dcd9e8); border-radius: 12px;
    background: #fff; color: var(--ink, #0b0b14); font: inherit; font-size: 15px;
}
.pdf-hint { margin: 0; font-size: 13px; color: var(--muted, #5b5870); }
.pdf-hint[hidden] { display: none; }
.pdf-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-start; }
.pdf-more { position: relative; }
.pdf-more-list { display: grid; gap: 8px; margin-top: 8px; }
.pdf-more-list .pdf-btn { justify-content: flex-start; }
.pdf-msg { margin: 0; min-height: 1.4em; font-size: 14px; color: var(--accent, #0b7a6d); font-weight: 600; }
.pdf-msg.bad { color: #b3261e; }

@media (max-width: 640px) {
    .pdf-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
    .pdf-actions .pdf-btn.big { flex: 1 1 auto; }
    .pdf-bar { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; -webkit-overflow-scrolling: touch; }
    .pdf-bar .pdf-btn { flex: 0 0 auto; }
    .pdf-fab:not([hidden]) { display: inline-flex; }
}

/* Pulsante "Scarica PDF" sempre a portata di dito sul telefono (compare quando il pannello di salvataggio non e' in vista) */
.pdf-fab {
    display: none; position: fixed; left: 50%; transform: translateX(-50%); z-index: 50;
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 8px 24px rgba(11, 11, 20, 0.3);
}
.pdf-fab[hidden] { display: none; }

/* ---------- Avanzamento ---------- */
.pdf-progress { position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center; padding: 16px; background: rgba(11, 11, 20, 0.5); }
.pdf-progress[hidden] { display: none; }
.pdf-progress-box { width: min(420px, 100%); display: grid; gap: 12px; padding: 22px; border-radius: 18px; background: #fff; text-align: center; }
.pdf-bar-track { height: 10px; border-radius: 999px; background: var(--line, #e7e5f2); overflow: hidden; }
.pdf-bar-fill { height: 100%; width: 0; background: var(--accent, #0b7a6d); transition: width 0.15s; }
#pdf-prog-text { font-size: 13px; color: var(--muted, #5b5870); min-height: 1.3em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Editor di pagina ---------- */
.pdf-editor {
    position: fixed; inset: 0; z-index: 900; display: flex; flex-direction: column; background: #e9e8f1;
    padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px);
}
.pdf-editor[hidden] { display: none; }
.pdf-ed-top, .pdf-ed-tools, .pdf-ed-props { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px 12px; background: #fff; border-bottom: 1px solid var(--line, #dcd9e8); }
.pdf-ed-tools, .pdf-ed-props { overflow-x: auto; flex-wrap: nowrap; }
.pdf-ed-props[hidden], .pdf-ed-group[hidden] { display: none; }
.pdf-ed-sp { flex: 1 1 auto; }
.pdf-ed-count { font-variant-numeric: tabular-nums; min-width: 4.5em; text-align: center; }
.pdf-ed-group { display: inline-flex; align-items: center; gap: 8px; }
.pdf-sw { width: 30px; height: 30px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 1px var(--line, #cfcde0); cursor: pointer; padding: 0; }
.pdf-sw.sel { box-shadow: 0 0 0 2px var(--accent, #0b7a6d); }
#pdf-ed-bold.on { background: var(--tint, #e6f4f1); border-color: var(--accent, #0b7a6d); }
.pdf-ed-hint { margin: 0; padding: 6px 12px; font-size: 13px; color: var(--muted, #5b5870); min-height: 2em; }
.pdf-ed-scroll { flex: 1 1 auto; overflow: auto; padding: 10px 12px 40px; -webkit-overflow-scrolling: touch; }
.pdf-sheet { position: relative; margin: 0 auto; background: #fff; box-shadow: 0 6px 24px rgba(11, 11, 20, 0.25); }
.pdf-sheet canvas { display: block; }
.pdf-layer { position: absolute; inset: 0; touch-action: pan-x pan-y pinch-zoom; }
.pdf-layer.drawing { touch-action: none; cursor: crosshair; }
.pdf-layer.placing { cursor: text; }
.pdf-obj { position: absolute; touch-action: none; cursor: move; user-select: none; -webkit-user-select: none; line-height: 1.2; white-space: pre; }
.pdf-obj.t-text { min-width: 1.2em; min-height: 1.2em; outline: 1px dashed transparent; }
.pdf-obj.t-text.editing { outline: 1px dashed var(--accent, #0b7a6d); cursor: text; user-select: text; -webkit-user-select: text; touch-action: auto; }
.pdf-obj.t-text.editing:empty::before { content: attr(data-ph); opacity: 0.4; }
.pdf-obj.t-img img { width: 100%; height: 100%; display: block; pointer-events: none; }
.pdf-obj.t-high { background: rgba(255, 230, 25, 0.42); }
.pdf-obj.t-cover { background: #fff; outline: 1px dashed rgba(11, 11, 20, 0.3); }
.pdf-obj.t-check svg { width: 100%; height: 100%; display: block; pointer-events: none; }
.pdf-obj.sel { outline: 2px solid var(--accent, #0b7a6d); }
.pdf-h { display: none; position: absolute; right: -9px; bottom: -9px; width: 18px; height: 18px; border-radius: 50%; background: var(--accent, #0b7a6d); border: 2px solid #fff; cursor: nwse-resize; touch-action: none; }
.pdf-obj.sel:not(.editing) .pdf-h { display: block; }
@media (pointer: coarse) { .pdf-h { width: 26px; height: 26px; right: -13px; bottom: -13px; } }

/* ---------- Firma ---------- */
.pdf-sign { position: absolute; inset: 0; z-index: 10; display: grid; place-items: center; padding: 12px; background: rgba(11, 11, 20, 0.5); }
.pdf-sign[hidden] { display: none; }
.pdf-sign-box { width: min(560px, 100%); display: grid; gap: 10px; padding: 18px; border-radius: 18px; background: #fff; }
#pdf-sign-pad {
    width: 100%; height: auto; aspect-ratio: 720 / 260; touch-action: none; cursor: crosshair;
    border: 1px dashed var(--line, #b9b6d0); border-radius: 12px;
    background: linear-gradient(transparent calc(100% - 52px), #cfcde0 calc(100% - 52px), #cfcde0 calc(100% - 51px), transparent calc(100% - 51px)) #fff;
}
.pdf-check { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.pdf-sign-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }

/* ---------- Come funziona e domande frequenti ---------- */
.pdf-info { max-width: 920px; margin: 44px auto 0; }
.pdf-info h2 { margin: 0 0 14px; font-size: 22px; }
.pdf-steps { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; margin: 0 0 40px; padding: 0; list-style: none; }
.pdf-steps li { padding: 16px; border: 1px solid var(--line, #dcd9e8); border-radius: 14px; background: #fff; font-size: 15px; line-height: 1.5; }
.pdf-steps strong { display: block; margin-bottom: 6px; }
.pdf-faq details { padding: 12px 0; border-bottom: 1px solid var(--line, #dcd9e8); }
.pdf-faq summary { cursor: pointer; font-weight: 600; }
.pdf-faq p { margin: 8px 0 0; color: var(--muted, #5b5870); line-height: 1.55; }
