/* Sempre chiaro: niente tema scuro, anche se il telefono lo usa. */
:root {
    color-scheme: light;
    --bg: #ffffff;
    --fg: #1a1a1a;
    --muted: #6b6b6b;
    --accent: #2f5bd3;
    --border: #e5e5e5;
}

* {
    box-sizing: border-box;
}

html {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 16px;
    line-height: 1.5;
}

body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    color: var(--fg);
}

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

.topbar,
.footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
}

.topbar {
    border-bottom: 1px solid var(--border);
}

.brand {
    font-weight: 700;
    text-decoration: none;
    color: var(--fg);
}

main {
    flex: 1;
    width: 100%;
    max-width: 48rem;
    margin: 0 auto;
    padding: 2rem 1.5rem;
}

.hero h1 {
    font-size: clamp(1.75rem, 5vw, 2.75rem);
    line-height: 1.15;
    margin: 2rem 0 1rem;
}

.muted,
.footer {
    color: var(--muted);
}

.footer {
    border-top: 1px solid var(--border);
    font-size: 0.875rem;
}

/* --- Componenti dell'app ------------------------------------------------ */

:root {
    --surface: #f7f7f8;
    --ok: #1f7a4d;
    --ok-bg: #e7f5ee;
    --warn: #8a5a00;
    --warn-bg: #fff4dc;
    --danger: #b3261e;
    --danger-bg: #fdecea;
}

h1 { font-size: 1.75rem; line-height: 1.2; margin: 0 0 1rem; }
h2 { font-size: 1.25rem; margin: 2rem 0 0.75rem; }
h3 { font-size: 1.05rem; margin: 0; }

.small { font-size: 0.875rem; }
.prewrap { white-space: pre-line; }
.narrow { max-width: 32rem; }

.nav { display: flex; align-items: center; gap: 1rem; }
.nav form { margin: 0; }
.nav-user { font-size: 0.875rem; }

.button,
.link-button {
    font: inherit;
    cursor: pointer;
}

.button {
    display: inline-block;
    padding: 0.6rem 1rem;
    border: 1px solid var(--accent);
    border-radius: 6px;
    background: var(--accent);
    color: #fff;
    text-decoration: none;
    font-weight: 600;
}

.button:hover { filter: brightness(1.08); }

.button-secondary {
    background: transparent;
    color: var(--accent);
}

.button-quiet {
    background: transparent;
    border-color: var(--border);
    color: var(--muted);
    font-weight: 400;
}

.link-button {
    background: none;
    border: 0;
    padding: 0;
    color: var(--accent);
    text-decoration: underline;
}

.page-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.page-head h1 { margin: 0; }

.stack { display: flex; flex-direction: column; gap: 0.9rem; }

.row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
    gap: 0.9rem;
}

label { display: flex; flex-direction: column; gap: 0.3rem; font-weight: 600; font-size: 0.95rem; }
label .muted { font-weight: 400; }
label.checkbox { flex-direction: row; align-items: center; gap: 0.5rem; font-weight: 400; }

input,
select,
textarea {
    font: inherit;
    font-weight: 400;
    padding: 0.55rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg);
    color: var(--fg);
    width: 100%;
}

input[type="checkbox"] { width: auto; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.field-error, .alert-list { color: var(--danger); }
.alert-list ul { margin: 0 0 1rem; padding-left: 1.2rem; }
.alert-list.validation-summary-valid { display: none; }

.notice, .alert {
    padding: 0.75rem 1rem;
    border-radius: 6px;
    margin: 0 0 1rem;
}

.notice { background: var(--ok-bg); color: var(--ok); }
.alert { background: var(--danger-bg); color: var(--danger); }
.notice p, .alert p { margin: 0.25rem 0; }

.empty {
    padding: 2rem 1.5rem;
    border: 1px dashed var(--border);
    border-radius: 8px;
    text-align: center;
}

.list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--border); }

.list-item {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.9rem 0.25rem;
    border-bottom: 1px solid var(--border);
    color: var(--fg);
    text-decoration: none;
}

.list-item:hover { background: var(--surface); }
.list-title { font-weight: 600; }
.list-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; font-size: 0.875rem; }

.badge {
    display: inline-block;
    padding: 0.1rem 0.55rem;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 600;
    background: var(--surface);
    color: var(--muted);
    white-space: nowrap;
}

.badge-attention,
.status-step-4 { background: var(--warn-bg); color: var(--warn); }
.status-step-5,
.status-request-3 { background: var(--ok-bg); color: var(--ok); }
.status-step-6 { background: var(--danger-bg); color: var(--danger); }
.status-step-3,
.status-request-2 { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }

.card {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem 1.1rem;
    margin: 0 0 1rem;
}

.card-head { display: flex; justify-content: space-between; gap: 0.75rem; align-items: flex-start; }
.card-head p { margin: 0.2rem 0 0; font-size: 0.9rem; overflow-wrap: anywhere; }
.timeline { font-size: 0.85rem; }
.overdue { color: var(--danger); }

.submission {
    background: var(--surface);
    border-radius: 6px;
    padding: 0.75rem 1rem;
    margin: 0.75rem 0;
}

.submission p { margin: 0.3rem 0; }
.submission blockquote { margin: 0.5rem 0; padding-left: 0.75rem; border-left: 3px solid var(--border); }
.files { margin: 0.5rem 0; padding-left: 1.2rem; }

.actions { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: flex-start; margin-top: 0.75rem; }
.actions form { margin: 0; }

.inline-form summary { list-style: none; }
.inline-form summary::-webkit-details-marker { display: none; }
.inline-form[open] { flex-basis: 100%; }
.inline-form[open] form { margin-top: 0.75rem; }

.send-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 1rem 1.1rem;
    border-radius: 8px;
    background: color-mix(in srgb, var(--accent) 10%, transparent);
    margin: 1rem 0 1.5rem;
}

.send-bar p { margin: 0; flex: 1 1 16rem; }

.add-step summary { cursor: pointer; list-style: none; }
.add-step summary::-webkit-details-marker { display: none; }
.add-step summary h2 { display: inline; margin: 0; font-size: 1.1rem; }
.add-step summary h2::before { content: "+ "; color: var(--accent); }
.add-step[open] summary { margin-bottom: 1rem; }

.rename { margin: -0.5rem 0 1rem; font-size: 0.9rem; }
.rename summary { display: inline; }
.rename[open] form { margin-top: 0.75rem; max-width: 32rem; }

/* --- Navigazione, filtri, destinatari ------------------------------------ */

.nav a { text-decoration: none; }
.nav a.nav-active { font-weight: 700; text-decoration: underline; text-underline-offset: 6px; }

.filters {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(8.5rem, 1fr));
    gap: 0.6rem;
    margin: 0 0 1.25rem;
}

.filter {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    padding: 0.8rem 1rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--fg);
    text-decoration: none;
    background: var(--bg);
}

.filter:hover { background: var(--surface); }
.filter-label { font-size: 0.9rem; color: var(--muted); }
.filter-count { font-size: 1.6rem; font-weight: 700; line-height: 1.1; }

.filter-active {
    border-color: var(--accent);
    background: color-mix(in srgb, var(--accent) 10%, transparent);
}

.filter-active .filter-label { color: var(--accent); font-weight: 600; }

.list-item-stacked { flex-direction: column; align-items: stretch; gap: 0.45rem; }
.list-row { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 0.5rem; }
.list-sub { font-size: 0.875rem; }

.recipients { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.badge.recipient { font-weight: 500; }
.recipient-state { font-weight: 400; opacity: 0.8; }
.recipient-state::before { content: "· "; }

.nav a { white-space: nowrap; }

@media (max-width: 640px) {
    .topbar { flex-wrap: wrap; gap: 0.5rem; padding: 0.75rem 1rem; }
    .nav { width: 100%; flex-wrap: wrap; justify-content: flex-start; gap: 0.5rem 1.25rem; }
    .nav form { margin-left: auto; }
    .nav-user { display: none; }
    main { padding: 1.25rem 1rem; }
}

/* --- Caricamento asincrono ------------------------------------------------ */

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

.skeleton { display: flex; flex-direction: column; gap: 0.75rem; }

.skeleton-line,
.skeleton-card {
    border-radius: 6px;
    background: linear-gradient(90deg, var(--surface) 0%, var(--border) 50%, var(--surface) 100%);
    background-size: 200% 100%;
    animation: shimmer 1.2s ease-in-out infinite;
}

.skeleton-line { height: 1rem; width: 60%; }
.skeleton-title { height: 1.75rem; width: 40%; }
.skeleton-card { height: 5.5rem; }

@keyframes shimmer {
    from { background-position: 200% 0; }
    to { background-position: -200% 0; }
}

@media (prefers-reduced-motion: reduce) {
    .skeleton-line, .skeleton-card { animation: none; }
}

.async-content.is-loading > :not(.skeleton) { opacity: 0.55; transition: opacity 0.15s; }

/* --- Modulo del Next Step ------------------------------------------------- */

.output-types { border: 0; padding: 0; margin: 0; }
.output-types legend { font-weight: 600; font-size: 0.95rem; margin-bottom: 0.5rem; padding: 0; }

.output-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(7rem, 1fr));
    gap: 0.6rem;
}

.output-option { display: flex; font-weight: 400; }
.output-option .output-tile { flex: 1; }
.output-option input { position: absolute; opacity: 0; pointer-events: none; }

.output-tile {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    min-height: 5.5rem;
    padding: 0.75rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    text-align: center;
    font-size: 0.9rem;
    cursor: pointer;
    color: var(--muted);
    transition: border-color 0.1s, background 0.1s, color 0.1s;
}

.output-tile:hover { background: var(--surface); color: var(--fg); }
button.output-tile { background: transparent; font: inherit; font-size: 0.9rem; }
button.output-tile:disabled { opacity: 0.5; cursor: not-allowed; }
button.output-tile:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.output-option input:checked + .output-tile {
    border-color: var(--accent);
    background: color-mix(in srgb, var(--accent) 10%, transparent);
    color: var(--accent);
    font-weight: 600;
}

.output-option input:focus-visible + .output-tile { outline: 2px solid var(--accent); outline-offset: 2px; }

.row .grow { grid-column: span 2; }
@media (max-width: 640px) { .row .grow { grid-column: auto; } }

.collapsible { border: 1px solid var(--border); border-radius: 8px; padding: 0.6rem 0.9rem; }
.collapsible summary { cursor: pointer; font-weight: 600; font-size: 0.95rem; }
.collapsible[open] summary { margin-bottom: 0.6rem; }

/* --- Autocompletamento ---------------------------------------------------- */

.autocomplete { position: relative; }

.suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 10;
    margin: 0.25rem 0 0;
    padding: 0.25rem;
    list-style: none;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgb(0 0 0 / 0.12);
    font-weight: 400;
}

.suggestions li {
    display: flex;
    flex-direction: column;
    padding: 0.45rem 0.6rem;
    border-radius: 6px;
    cursor: pointer;
}

.suggestions li span { font-size: 0.85rem; color: var(--muted); }
.suggestions li:hover,
.suggestions li.active { background: var(--surface); }

.contact-item .inline-form form { margin-top: 0.75rem; }
.delete-form { margin-top: 0.5rem; }

/* --- Disponibilità -------------------------------------------------------- */

.availability { border: 1px solid var(--border); border-radius: 10px; padding: 0.8rem 1rem 1rem; margin: 0; }
.availability legend { font-weight: 600; padding: 0 0.25rem; }
.availability-rows { display: flex; flex-direction: column; gap: 0.6rem; margin-bottom: 0.75rem; }

.availability-row {
    display: grid;
    grid-template-columns: minmax(9rem, 1.5fr) minmax(7.5rem, 1fr) minmax(7.5rem, 1fr) auto;
    gap: 0.5rem;
    align-items: end;
}

.availability-row label { font-size: 0.85rem; }
.availability-remove { padding-bottom: 0.6rem; }

@media (max-width: 520px) {
    .availability-row { grid-template-columns: 1fr 1fr; padding-bottom: 0.6rem; border-bottom: 1px solid var(--border); }
    .availability-row label:first-child { grid-column: 1 / -1; }
    .availability-remove { grid-column: 1 / -1; justify-self: end; padding: 0; }
}

.availability-list { margin: 0.5rem 0; padding-left: 1.2rem; }
.availability-list li { margin: 0.2rem 0; }
.availability-list .muted { margin-left: 0.4rem; }

/* --- Consegne di un Next Step --------------------------------------------- */

.item-rows { list-style: none; margin: 0.75rem 0 0; padding: 0; display: flex; flex-direction: column; gap: 0.5rem; }
}

.item-list { list-style: none; margin: 0.75rem 0 0; padding: 0; display: flex; flex-direction: column; gap: 0.6rem; }
.item-card { border: 1px solid var(--border); border-radius: 8px; padding: 0.7rem 0.9rem; display: flex; flex-direction: column; gap: 0.4rem; }
.item-card.is-redo { border-color: var(--danger); }
.item-card-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 0.5rem; }
.item-card blockquote { margin: 0; padding-left: 0.75rem; border-left: 3px solid var(--border); }
.item-card p, .item-card ul { margin: 0; }
.item-status-3 { background: var(--warn-bg); color: var(--warn); }
.item-status-4 { background: var(--ok-bg); color: var(--ok); }
.item-status-5 { background: var(--danger-bg); color: var(--danger); }

.verdict { display: inline-flex; gap: 0.4rem; }
.verdict label {
    position: relative;
    display: inline-flex; flex-direction: row; align-items: center; gap: 0.3rem;
    min-height: 2.25rem; padding: 0 0.75rem;
    border: 1px solid var(--border); border-radius: 6px;
    font-size: 0.875rem; font-weight: 400; cursor: pointer;
}
.verdict input { position: absolute; inset: 0; width: 1px; height: 1px; margin: 0; opacity: 0; pointer-events: none; }
.verdict-ok:has(input:checked) { border-color: var(--ok); background: var(--ok-bg); color: var(--ok); font-weight: 600; }
.verdict-redo:has(input:checked) { border-color: var(--danger); background: var(--danger-bg); color: var(--danger); font-weight: 600; }
.verdict label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.review-item:not(:has(input[value="redo"]:checked)) .review-note { display: none; }
.button-danger { background: var(--danger); border-color: var(--danger); color: #fff; }

.progress { display: flex; flex-direction: column; gap: 0.35rem; margin: 1rem 0; }
.progress-text { display: flex; justify-content: space-between; font-size: 0.875rem; }
.progress-bar { height: 8px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); overflow: hidden; }
.progress-bar > div { height: 100%; background: var(--accent); }

.delivery-item { border: 1px solid var(--border); border-radius: 10px; padding: 0.85rem 1rem; display: flex; flex-direction: column; gap: 0.6rem; }
.delivery-item.is-done { border-color: color-mix(in srgb, var(--ok) 40%, var(--border)); }
.delivery-item.is-redo { border-color: var(--danger); }
.delivery-item-head { display: flex; justify-content: space-between; align-items: center; gap: 0.6rem; }
.delivery-item-title { display: flex; align-items: center; gap: 0.5rem; font-weight: 600; }
.item-check {
    width: 24px; height: 24px; flex: none; border-radius: 999px;
    border: 2px solid var(--border); display: inline-flex; align-items: center; justify-content: center;
}
.item-check.optional { border-style: dashed; }
.is-done .item-check { background: var(--ok); border-color: var(--ok); color: #fff; }
.item-note { margin: 0; padding: 0.5rem 0.7rem; border-radius: 6px; background: var(--danger-bg); color: var(--danger); font-size: 0.9rem; }
.file-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.35rem; }
.file-list li { display: flex; justify-content: space-between; align-items: center; gap: 0.6rem; padding: 0.45rem 0.65rem; border-radius: 8px; background: var(--surface); font-size: 0.9rem; }
.dropzone {
    display: flex; flex-direction: column; align-items: center; gap: 0.3rem;
    padding: 1rem; border: 2px dashed var(--border); border-radius: 10px;
    text-align: center; font-weight: 400; cursor: pointer;
}
.dropzone input[type="file"] { max-width: 100%; }

[hidden] { display: none !important; }
.delivery-item blockquote { margin: 0; padding-left: 0.75rem; border-left: 3px solid var(--border); }
.items-empty-alert { color: var(--danger); font-weight: 600; }

.item-due { font-size: 0.85rem; color: var(--muted); font-weight: 400; }
.item-due.overdue { color: var(--danger); }

/* --- Modulo del Next Step a passi ----------------------------------------- */

.next-step-form { display: flex; flex-direction: column; gap: 1.75rem; }
.form-step { display: flex; flex-direction: column; gap: 0.75rem; }
/* L'intestazione del passo resta in alto mentre si scorre dentro il passo. */
.step-header {
    position: sticky; top: 0; z-index: 4;
    display: flex; align-items: center; gap: 0.75rem;
    margin: 0 -0.5rem; padding: 0.5rem;
    background: var(--bg);
}
.step-number {
    width: 2rem; height: 2rem; flex: none; border-radius: 999px;
    background: var(--accent); color: #fff; font-weight: 700;
    display: flex; align-items: center; justify-content: center;
}
.step-body { display: flex; flex-direction: column; gap: 0.75rem; min-width: 0; }
.step-title { margin: 0; font-size: 1.15rem; }
.step-title label { font-weight: inherit; display: inline; }
@media (max-width: 640px) {
    .step-body { padding-left: 0; }
    .step-number { width: 1.75rem; height: 1.75rem; font-size: 0.9rem; }
    .step-header { border-bottom: 1px solid var(--border); }
}

.next-step-form .output-tile { min-height: 4.25rem; padding: 0.5rem; }
.next-step-form .output-tile .icon { width: 22px; height: 22px; }

.item-row { position: relative; border: 1px solid var(--border); border-radius: 0 0 10px 10px; padding: 0.6rem 0.7rem 0.55rem; display: flex; flex-direction: column; gap: 0.4rem; }
.item-rows { gap: 2.5rem !important; margin-top: 2.5rem !important; }
/* Il tipo è un'etichetta del riquadro: stesso bordo, appoggiata sopra, e
   copre il tratto di bordo sotto di sé così da sembrare un pezzo unico. */
.item-icon.item-kind {
    position: absolute; left: -1px; top: 0; transform: translateY(calc(-100% + 1px));
    display: inline-flex; align-items: center; gap: 0.35rem;
    box-sizing: border-box; height: 2rem; padding: 0 0.75rem;
    background: var(--bg);
    border: 1px solid var(--border); border-bottom: 0; border-radius: 8px 8px 0 0;
    color: var(--accent); font-size: 0.85rem; font-weight: 600; line-height: 1.3;
}
.item-icon.item-kind .icon { width: 15px; height: 15px; }
.item-main { display: flex; align-items: center; gap: 0.6rem; }
.item-icon { color: var(--accent); display: flex; }
.item-icon .icon { width: 20px; height: 20px; }
.item-main .item-title { flex: 1; min-width: 0; border-color: transparent; background: var(--surface); }
.item-main .item-title:focus { border-color: var(--accent); background: var(--bg); }
.item-remove {
    position: absolute; right: -1px; top: 0; transform: translateY(calc(-100% + 1px));
    display: inline-flex; align-items: center; justify-content: center;
    box-sizing: border-box; height: 2rem; min-width: 3rem; padding: 0 0.75rem;
    background: var(--bg); color: var(--muted); cursor: pointer;
    border: 1px solid var(--border); border-bottom: 0; border-radius: 8px 8px 0 0;
    font: inherit; font-size: 0.85rem; line-height: 1.3;
}
.item-remove .icon { width: 17px; height: 17px; }
.item-remove:hover, .item-remove:focus-visible { color: var(--danger); }
.item-chips { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.chip {
    display: inline-flex; flex-direction: row; align-items: center; gap: 0.35rem; min-height: 1.9rem;
    padding: 0.1rem 0.65rem; border-radius: 999px; border: 1px solid var(--border);
    background: var(--bg); color: var(--muted); font: inherit; font-size: 0.8rem; font-weight: 400; cursor: pointer;
}
.chip-add { border-style: dashed; }
.chip-set { border-color: color-mix(in srgb, var(--accent) 35%, var(--border)); background: color-mix(in srgb, var(--accent) 8%, transparent); color: var(--accent); font-weight: 600; }
.chip-toggle input { width: auto; margin: 0; accent-color: var(--warn); }
.chip-toggle:has(input:checked) { border-color: var(--warn); background: var(--warn-bg); color: var(--warn); font-weight: 600; }

.recipient-chip {
    display: inline-flex; align-items: center; gap: 0.6rem; align-self: flex-start; max-width: 100%;
    padding: 0.3rem 0.4rem 0.3rem 0.3rem; border-radius: 999px; background: var(--surface); border: 1px solid var(--border);
}
.avatar {
    width: 2rem; height: 2rem; flex: none; border-radius: 999px; background: var(--accent); color: #fff;
    font-size: 0.75rem; font-weight: 700; display: flex; align-items: center; justify-content: center;
}
.recipient-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; overflow-wrap: anywhere; }
.chip-remove { font-size: 1.2rem; text-decoration: none; color: var(--muted); padding: 0 0.4rem; min-height: 2rem; }
.recipient-name { max-width: 24rem; }

.optional-details { border: 1px solid var(--border); border-radius: 12px; background: #fafafa; }
.optional-details > summary { display: flex; justify-content: space-between; align-items: center; gap: 0.75rem; padding: 0.85rem 1rem; cursor: pointer; list-style: none; }
.optional-details > summary::-webkit-details-marker { display: none; }
.optional-details > summary > span { display: flex; flex-direction: column; gap: 0.1rem; }
.optional-details > summary::after { content: "▸"; color: var(--muted); }
.optional-details[open] > summary::after { content: "▾"; }
.optional-fields { padding: 0.25rem 1rem 1.1rem; display: flex; flex-direction: column; gap: 1.1rem; }
.optional-fields input, .optional-fields textarea { background: var(--bg); }
.due-field { border: 0; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.5rem; }
.due-field legend { font-weight: 600; font-size: 0.95rem; padding: 0; margin-bottom: 0.5rem; }
.due-quick { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
.pill {
    min-height: 2.5rem; padding: 0 0.9rem; border-radius: 999px; border: 1px solid var(--border);
    background: var(--bg); color: var(--fg); font: inherit; font-size: 0.95rem; cursor: pointer;
}
.pill[aria-pressed="true"] { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); color: var(--accent); font-weight: 600; }
.due-date { display: inline-flex; flex-direction: row; align-items: center; gap: 0.5rem; font-weight: 400; color: var(--muted); }
.due-date input { width: auto; }

.form-summary {
    display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.75rem;
    padding: 0.85rem 0; border-top: 1px solid var(--border);
}
.form-summary.is-sticky {
    position: sticky; bottom: 0; z-index: 5; background: var(--bg);
    margin: 0 -1rem; padding: 0.85rem 1rem calc(0.85rem + env(safe-area-inset-bottom));
    box-shadow: 0 -6px 16px rgba(0, 0, 0, 0.05);
}
.form-summary-text { flex: 1 1 18rem; display: flex; flex-direction: column; gap: 0.1rem; font-size: 0.9rem; min-width: 0; }
.form-summary-text strong { font-size: 0.98rem; }
.form-summary-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.button.is-waiting { opacity: 0.55; }
@media (max-width: 640px) {
    .form-summary-actions { width: 100%; }
    .form-summary-actions .button { flex: 1; }
}
@media (max-width: 640px) {
    .item-chips { padding-left: 0; }
    /* Su telefono il riepilogo resta corto, e mentre si scrive non copre i campi. */
    .form-summary.is-sticky .form-summary-text span { display: none; }
}

/* --- Riservatezza e richieste fatte agli altri ---------------------------- */

label.private-field { align-items: flex-start; gap: 0.6rem; }
label.private-field input { margin-top: 0.25rem; }
.private-field > span { display: flex; flex-direction: column; gap: 0.15rem; font-weight: 400; }
.step-badges { display: inline-flex; flex-wrap: wrap; gap: 0.35rem; justify-content: flex-end; }
.others { margin-top: 2.5rem; padding-top: 1.5rem; border-top: 1px solid var(--border); }
.others h2 { margin: 0 0 0.25rem; font-size: 1.1rem; }
.others-list, .other-items { list-style: none; margin: 0; padding: 0; }
.others-list { display: flex; flex-direction: column; gap: 0.6rem; margin-top: 0.75rem; }
.other-step { border: 1px solid var(--border); border-radius: 10px; padding: 0.7rem 0.85rem; display: flex; flex-direction: column; gap: 0.5rem; }
.other-head { display: flex; align-items: center; gap: 0.6rem; }
.other-who { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.3; overflow-wrap: anywhere; }
.other-items { display: flex; flex-direction: column; gap: 0.3rem; padding-left: 2.6rem; font-size: 0.9rem; }
.other-items li { display: flex; align-items: center; gap: 0.45rem; }
.other-items .icon { width: 16px; height: 16px; }

/* iOS ingrandisce la pagina sui campi con testo sotto i 16px: su telefono
   tutti i campi restano a 16px. Le date non escono dal loro riquadro. */
@media (max-width: 640px) {
    input, select, textarea { font-size: 16px !important; }
    main { padding-left: 0.75rem; padding-right: 0.75rem; }
    .item-row { padding: 0.5rem 0.55rem; }
    .item-main { gap: 0.4rem; }
    .optional-details > summary, .optional-fields { padding-left: 0.75rem; padding-right: 0.75rem; }
    .form-summary.is-sticky { margin: 0 -0.75rem; padding-left: 0.75rem; padding-right: 0.75rem; }
}
@media (max-width: 640px) {
    input[type="date"], input[type="time"] { min-width: 0; max-width: 100%; -webkit-appearance: none; appearance: none; text-align: left; min-height: 2.75rem; }
}

/* Le opzioni della consegna sono etichette: la data apre il selettore, il
   destinatario si trasforma nel campo con i suggerimenti. */
.chip-date { position: relative; overflow: hidden; }
.chip-date input[type="date"] {
    position: absolute; inset: 0; width: 100%; height: 100%; min-height: 0;
    margin: 0; padding: 0; border: 0; opacity: 0; cursor: pointer; font-size: 16px;
}
.chip-date input[type="date"]::-webkit-calendar-picker-indicator { position: absolute; inset: 0; width: 100%; height: 100%; cursor: pointer; }
.chip-date:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.chip-input { flex: 1 1 14rem; min-width: 12rem; }
.chip-input input { padding: 0.35rem 0.6rem; border-radius: 999px; }

/* Su telefono i tipi stanno tutti su una riga: icona e nome piccolo. */
@media (max-width: 640px) {
    .next-step-form .output-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 0.35rem; }
    .next-step-form .output-tile { min-height: 3.6rem; padding: 0.35rem 0.1rem; gap: 0.2rem; font-size: 0.68rem; border-radius: 8px; }
    .next-step-form .output-tile .icon { width: 20px; height: 20px; }
    .next-step-form .output-tile span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .next-step-form .output-tile .label-full { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
}
.output-tile .label-short { display: none; }
@media (max-width: 640px) { .next-step-form .output-tile .label-short { display: block; } }
.chip-missing { border-color: var(--danger); border-style: dashed; color: var(--danger); font-weight: 600; }
.item-rows:empty { display: none; }
.next-step-form .output-grid { margin-top: 0.25rem; }

/* Il tipo si cambia toccando la linguetta: la tendina è trasparente sopra. */
.item-icon.item-kind { cursor: pointer; flex-direction: row; }
.item-kind [data-kind-icon] { display: flex; }
.item-kind .kind-caret { font-size: 0.7rem; color: var(--muted); }
.item-kind select {
    position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; padding: 0;
    border: 0; opacity: 0; cursor: pointer; font-size: 16px; appearance: none;
}
.item-kind:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }

/* --- Accesso nella pagina: email e codice --------------------------------- */

.auth-panel { border: 2px solid var(--accent); border-radius: 12px; padding: 1rem; display: flex; flex-direction: column; gap: 0.75rem; background: color-mix(in srgb, var(--accent) 4%, var(--bg)); }
.auth-panel h2 { margin: 0; font-size: 1.1rem; }
.auth-panel p { margin: 0; }
.auth-panel > div { display: flex; flex-direction: column; gap: 0.6rem; }
.auth-fields { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0.6rem; }
@media (max-width: 640px) { .auth-fields { grid-template-columns: minmax(0, 1fr); } }
.auth-code input { max-width: 12rem; font-size: 1.4rem !important; letter-spacing: 0.3em; text-align: center; }
.auth-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem; }
.request-tools { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 1.25rem; }
.request-tools form { margin: 0; }
.danger-link { color: var(--danger); }

/* --- Intestazione: menu laterale, sezioni, menu utente ------------------- */

.topbar { justify-content: flex-start; gap: 0.5rem; padding: 0.55rem 1rem; flex-wrap: nowrap; }
.topbar .brand { font-size: 1.05rem; }
.topbar .nav-main { margin-left: 1.25rem; gap: 1.25rem; width: auto; flex-wrap: nowrap; }
.topbar .nav-main form { margin: 0; }
.user-menu, .nav-login { margin-left: auto; }
.icon-button {
    display: inline-flex; align-items: center; justify-content: center;
    width: 2.5rem; height: 2.5rem; border: 0; border-radius: 8px;
    background: transparent; color: var(--fg); font: inherit; font-size: 1.5rem; cursor: pointer;
}
.icon-button:hover { background: var(--surface); }

.user-menu { position: relative; }
.user-menu > summary { list-style: none; cursor: pointer; border-radius: 999px; }
.user-menu > summary::-webkit-details-marker { display: none; }
.user-menu > summary .avatar { width: 2.25rem; height: 2.25rem; font-size: 0.8rem; }
.user-menu-panel {
    position: absolute; right: 0; top: calc(100% + 0.4rem); z-index: 40; min-width: 15rem;
    background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12); padding: 0.4rem;
}
.user-menu-who { display: flex; flex-direction: column; gap: 0.1rem; margin: 0; padding: 0.6rem 0.7rem; border-bottom: 1px solid var(--border); overflow-wrap: anywhere; }
.user-menu-panel form { margin: 0; }
.user-menu-item {
    display: block; width: 100%; text-align: left; padding: 0.65rem 0.7rem; margin-top: 0.3rem;
    border: 0; border-radius: 6px; background: transparent; color: var(--fg); font: inherit; cursor: pointer;
}
.user-menu-item:hover { background: var(--surface); }

.drawer-backdrop { position: fixed; inset: 0; z-index: 60; background: rgba(20, 20, 20, 0.35); }
.drawer {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 61; width: min(18rem, 85vw);
    background: var(--bg); box-shadow: 10px 0 30px rgba(0, 0, 0, 0.15);
    display: flex; flex-direction: column; gap: 0.15rem; padding: 0.6rem 0.75rem;
}
.drawer-head { display: flex; justify-content: space-between; align-items: center; padding: 0 0.25rem 0.5rem; border-bottom: 1px solid var(--border); margin-bottom: 0.5rem; }
.drawer a { display: block; padding: 0.7rem 0.75rem; border-radius: 8px; color: var(--fg); text-decoration: none; }
.drawer a:hover { background: var(--surface); }
.drawer a.is-active { background: color-mix(in srgb, var(--accent) 10%, transparent); color: var(--accent); font-weight: 600; }
.drawer a.drawer-primary { color: var(--accent); font-weight: 600; }
body.drawer-open { overflow: hidden; }

@media (max-width: 640px) {
    .topbar { padding: 0.45rem 0.6rem; flex-wrap: nowrap; }
    .topbar .nav-main { display: none; }
    main { padding-top: 0.85rem; }
}

/* --- Meno spazio vuoto nel modulo ------------------------------------------ */

.page-title-compact { font-size: 1.5rem; margin: 0 0 0.25rem; }
.next-step-form { gap: 1.25rem; }
.next-step-form .items-empty { margin: 0; }
.item-rows[hidden] { display: none !important; }

/* La barra con Salva bozza / Invia sta sempre sul fondo dello schermo, anche
   quando il modulo è corto; la pagina lascia lo spazio per non coprire niente. */
.form-summary.is-sticky {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; margin: 0;
    padding: 0.75rem max(1rem, calc((100% - 48rem) / 2 + 1.5rem)) calc(0.75rem + env(safe-area-inset-bottom));
    border-top: 1px solid var(--border); background: var(--bg);
    box-shadow: 0 -6px 16px rgba(0, 0, 0, 0.06);
}
body:has(.form-summary.is-sticky) { padding-bottom: 8.5rem; }
@media (min-width: 641px) { body:has(.form-summary.is-sticky) { padding-bottom: 5.5rem; } }
body:has(.form-summary.is-sticky) .footer { display: none; }

/* --- Pagina della richiesta ----------------------------------------------- */

.request-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 0.5rem; margin-bottom: 0.5rem; }
.request-title { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem 0.75rem; min-width: 0; }
.request-title h1 { margin: 0; overflow-wrap: anywhere; }
.request-description { margin: 0 0 0.75rem; }
.more-menu { position: relative; flex: none; }
.more-menu > summary { list-style: none; font-size: 1.4rem; line-height: 1; }
.more-menu > summary::-webkit-details-marker { display: none; }
.more-panel {
    position: absolute; right: 0; top: calc(100% + 0.3rem); z-index: 40; min-width: 13rem;
    background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12); padding: 0.35rem;
}
.more-panel form { margin: 0; }
.menu-item {
    display: block; width: 100%; text-align: left; padding: 0.65rem 0.7rem;
    border: 0; border-radius: 6px; background: transparent; color: var(--fg); font: inherit; cursor: pointer;
}
.menu-item:hover { background: var(--surface); }
.menu-item.danger-link { color: var(--danger); }
.rename-form { margin-bottom: 1rem; }
.section-title { margin: 1.25rem 0 0.6rem; font-size: 1.05rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }

.step-who { display: flex; align-items: center; gap: 0.65rem; min-width: 0; }
.step-who h3 { margin: 0; overflow-wrap: anywhere; }
.step-who p { margin: 0.1rem 0 0; overflow-wrap: anywhere; }
.step-meta { display: flex; flex-wrap: wrap; gap: 0.15rem 0; margin: 0.6rem 0 0; }
.step-meta span + span::before { content: "·"; margin: 0 0.4rem; }
.muted-link { color: var(--muted); font-size: 0.875rem; }
.card .actions { justify-content: flex-end; }
.page-head.request-head { flex-wrap: nowrap; }
.request-head .request-title { flex: 1 1 auto; }
.card-head { flex-wrap: wrap; }
.card-head .step-who { flex: 1 1 14rem; }
.step-who p { overflow-wrap: break-word; word-break: normal; }

/* --- Caricamento ------------------------------------------------------------ */

.top-loader {
    position: fixed; top: 0; left: 0; right: 0; z-index: 100; height: 3px; overflow: hidden;
    background: color-mix(in srgb, var(--accent) 20%, transparent);
}
.top-loader::after {
    content: ""; position: absolute; top: 0; bottom: 0; width: 40%;
    background: var(--accent); border-radius: 999px;
    animation: top-loader 1.1s ease-in-out infinite;
}
@keyframes top-loader { from { left: -40%; } to { left: 100%; } }

.is-busy { position: relative; color: transparent !important; pointer-events: none; }
.is-busy::after {
    content: ""; position: absolute; inset: 0; margin: auto; width: 1.1rem; height: 1.1rem;
    border: 2px solid currentColor; border-color: var(--accent); border-right-color: transparent;
    border-radius: 999px; animation: spin 0.7s linear infinite;
}
.button:not(.button-secondary).is-busy::after { border-color: #fff; border-right-color: transparent; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
    .top-loader::after { animation-duration: 3s; }
    .is-busy::after { animation-duration: 2s; }
}

/* --- Le mie richieste -------------------------------------------------------- */

.list-head { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; margin-bottom: 0.75rem; }
.list-head h1 { margin: 0; }
.button-small { padding: 0.45rem 0.9rem; font-size: 0.9rem; }

/* Filtri: una riga di pillole che scorre, invece dei riquadri grandi. */
.filters {
    display: flex; gap: 0.4rem; overflow-x: auto; scrollbar-width: none;
    margin: 0 -1rem 1rem; padding: 0.1rem 1rem 0.3rem;
}
.filters::-webkit-scrollbar { display: none; }
.filter {
    flex: none; flex-direction: row; align-items: center; gap: 0.4rem;
    padding: 0.4rem 0.8rem; border-radius: 999px; min-height: 2.25rem;
}
.filter-label { font-size: 0.9rem; }
.filter-count { font-size: 0.8rem; font-weight: 700; line-height: 1; padding: 0.15rem 0.45rem; border-radius: 999px; background: var(--surface); color: var(--muted); }
.filter-active .filter-count { background: var(--accent); color: #fff; }

.request-cards { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.6rem; }
.request-card {
    display: flex; flex-direction: column; gap: 0.45rem;
    padding: 0.8rem 0.9rem; border: 1px solid var(--border); border-radius: 12px;
    color: var(--fg); text-decoration: none; background: var(--bg);
}
.request-card:hover { border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); background: var(--surface); }
.request-card.needs-review { border-left: 4px solid var(--warn); }
.request-card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 0.6rem; }
.request-card-top .list-title { overflow-wrap: anywhere; }
.request-card-top .badge { flex: none; }
.request-card-meta { display: flex; flex-wrap: wrap; font-size: 0.85rem; color: var(--muted); }
.request-card-meta span + span::before { content: "·"; margin: 0 0.4rem; }
.request-card-meta .attention { color: var(--warn); font-weight: 700; }
.recipient-dots { display: flex; flex-wrap: wrap; gap: 0.3rem 0.9rem; font-size: 0.85rem; color: var(--fg); }
.recipient-dot { display: inline-flex; align-items: center; gap: 0.35rem; min-width: 0; overflow-wrap: anywhere; }
.recipient-dot .dot { width: 0.55rem; height: 0.55rem; border-radius: 999px; flex: none; background: var(--border); }
.recipient-dot.step-3 .dot, .recipient-dot.step-2 .dot { background: var(--accent); }
.recipient-dot.step-4 .dot { background: var(--warn); }
.recipient-dot.step-5 .dot { background: var(--ok); }
.recipient-dot.step-6 .dot, .recipient-dot.step-7 .dot { background: var(--danger); }
.recipient-dot.step-1 .dot { background: transparent; border: 1.5px solid var(--muted); }

.fab { display: none; }
@media (max-width: 640px) {
    .new-desktop { display: none; }
    .fab {
        display: flex; align-items: center; justify-content: center;
        position: fixed; right: 1rem; bottom: calc(1rem + env(safe-area-inset-bottom)); z-index: 30;
        width: 3.5rem; height: 3.5rem; border-radius: 999px;
        background: var(--accent); color: #fff; font-size: 2rem; line-height: 1; text-decoration: none;
        box-shadow: 0 8px 20px rgba(47, 91, 211, 0.35);
    }
    .request-cards { padding-bottom: 4.5rem; }
}
@media (max-width: 640px) { .filters { margin: 0 -0.75rem 0.85rem; padding-left: 0.75rem; padding-right: 0.75rem; } }

/* --- Chiesti a me ------------------------------------------------------------ */

.assigned-from { display: flex; align-items: flex-start; gap: 0.6rem; min-width: 0; }
.assigned-from > span:last-child { display: flex; flex-direction: column; gap: 0.1rem; min-width: 0; }
.assigned-from .list-title { overflow-wrap: anywhere; }
.assigned-sender { overflow-wrap: anywhere; }
.assigned-card .request-card-meta { padding-left: 2.6rem; }
.assigned-card.is-todo { border-left: 4px solid var(--accent); }
.assigned-card.is-late { border-left-color: var(--danger); }
.request-card-meta .overdue { color: var(--danger); font-weight: 600; }

/* --- Segreti e cassaforte -------------------------------------------- */

.secret-field textarea { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.secret-hint { display: flex; gap: 0.4rem; align-items: flex-start; margin: 0.35rem 0 0; }
.secret-hint .icon, .secret-view .icon, .muted .icon { width: 16px; height: 16px; flex: none; vertical-align: -3px; }
.secret-view .button { display: inline-flex; gap: 0.4rem; align-items: center; }
.secret-shown pre {
    margin: 0 0 0.5rem;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    overflow-wrap: anywhere;
}
.vault-locks { list-style: none; margin: 0; padding: 0; }
.vault-locks li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
}
.vault h2 { display: flex; gap: 0.4rem; align-items: center; }
.danger-zone summary { cursor: pointer; color: var(--danger); }
.vault-dialog {
    width: min(26rem, calc(100vw - 2rem));
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.25rem;
}
.vault-dialog::backdrop { background: rgb(0 0 0 / 0.35); }
.vault-dialog h2 { margin-top: 0; }
.vault-dialog input { font-size: 16px; }
.recovery-code {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 1.05rem;
    letter-spacing: 0.04em;
    padding: 0.75rem;
    border-radius: 8px;
    background: var(--surface);
    text-align: center;
    overflow-wrap: anywhere;
    user-select: all;
}
.vault .card > *, .vault-dialog form > * { margin-top: 0; margin-bottom: 0; }
.vault .actions, .vault-dialog .actions, .secret-shown .actions { justify-content: flex-start; flex-wrap: wrap; align-items: center; }
