/* Dettaglio preventivo / fattura — solo telefono (≤767.98px) */

/* Titolo + stato sulla stessa riga (stato a destra) */
.document-show-heading {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    column-gap: 0.5rem;
    row-gap: 0.25rem;
}

.document-show-heading > .document-back,
.document-show-heading > .document-back--mobile,
.document-show-heading > a.document-back {
    grid-column: 1 / -1;
}

.document-show-heading > .h3 {
    grid-column: 1;
    margin-bottom: 0 !important;
    min-width: 0;
    align-self: center;
}

.document-show-heading > .h3 + div {
    grid-column: 2;
    justify-self: end;
    align-self: center;
    display: flex !important;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 0.35rem;
    max-width: min(52vw, 14rem);
}

.document-show-heading > .h3 + div + * {
    grid-column: 1 / -1;
}

.document-back {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    margin: 0 0 0.75rem;
    padding: 0.35rem 0;
    min-height: 44px;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--section-color, #4f46e5);
    text-decoration: none;
    line-height: 1.2;
}

.document-back:hover,
.document-back:focus {
    color: var(--section-color, #4f46e5);
    text-decoration: underline;
}

.document-back--mobile {
    display: none;
}

@media (max-width: 767.98px) {
    .document-back--mobile {
        display: inline-flex;
    }

    .document-show-actions .document-show-back-desktop,
    .page-header__actions .document-show-back-desktop,
    .document-show-back-desktop {
        display: none !important;
    }

    .document-show-header {
        flex-direction: column;
        align-items: stretch !important;
        gap: 0.85rem;
        margin-bottom: 1.1rem !important;
    }

    .document-show-heading .h3 {
        font-size: 1.25rem;
        letter-spacing: -0.02em;
    }

    .document-show-actions,
    .document-show-actions.d-flex {
        display: grid !important;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 0 !important;
        width: 100%;
        border: 1px solid var(--surface-border, #e2e8f0);
        border-radius: 0.5rem;
        overflow: hidden;
        background: var(--surface-card, #fff);
        flex-wrap: unset !important;
        align-items: stretch !important;
        justify-content: stretch !important;
    }

    .document-show-actions > .btn,
    .document-show-actions > a.btn,
    .document-show-actions > form {
        width: 100%;
        margin: 0 !important;
        min-width: 0;
        border: 0 !important;
        border-right: 1px solid var(--surface-border, #e2e8f0) !important;
        border-bottom: 1px solid var(--surface-border, #e2e8f0) !important;
        border-radius: 0 !important;
        box-shadow: none !important;
        background: transparent !important;
        color: var(--text-muted, #64748b) !important;
    }

    .document-show-actions > .btn,
    .document-show-actions > a.btn,
    .document-show-actions > form > .btn {
        display: flex !important;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 0.35rem;
        min-height: 4.5rem;
        height: 100%;
        width: 100%;
        padding: 0.55rem 0.3rem 0.45rem !important;
        font-size: 0.68rem !important;
        font-weight: 500 !important;
        letter-spacing: 0.01em;
        line-height: 1.2 !important;
        text-align: center;
        white-space: normal;
        overflow: hidden;
        text-decoration: none !important;
    }

    .document-show-actions > form {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        justify-content: stretch;
        min-height: 4.5rem;
        padding: 0;
    }

    .document-show-actions > form > .btn {
        border: 0 !important;
        border-radius: 0 !important;
        background: transparent !important;
        color: var(--text-muted, #64748b) !important;
        box-shadow: none !important;
    }

    .document-show-actions > *:nth-child(3n) {
        border-right: 0 !important;
    }

    .document-show-actions > *:nth-child(3n+1):nth-last-child(-n+3),
    .document-show-actions > *:nth-child(3n+1):nth-last-child(-n+3) ~ * {
        border-bottom: 0 !important;
    }

    .document-show-actions .btn:active,
    .document-show-actions > form > .btn:active {
        background: color-mix(in srgb, var(--text-primary, #0f172a) 5%, transparent) !important;
    }

    .document-show-actions .btn .bi,
    .document-show-actions .btn .exo-i,
    .document-show-actions .btn .exo-lucide {
        margin: 0 !important;
        font-size: 1.15rem !important;
        line-height: 1;
        color: var(--text-muted, #64748b);
        flex: 0 0 auto;
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
    }

    .document-show-actions .btn .exo-lucide__svg,
    .document-show-actions .btn .exo-i svg,
    .document-show-actions .btn svg.lucide {
        width: 1.15rem !important;
        height: 1.15rem !important;
        display: block;
        stroke: currentColor;
    }

    .document-show-actions .btn.btn-danger,
    .document-show-actions .btn.btn-outline-danger,
    .document-show-actions .btn.text-danger {
        color: var(--bs-danger, #dc3545) !important;
    }

    .document-show-actions .btn.btn-danger .bi,
    .document-show-actions .btn.btn-outline-danger .bi,
    .document-show-actions .btn.btn-danger .exo-i,
    .document-show-actions .btn.btn-outline-danger .exo-i {
        color: var(--bs-danger, #dc3545);
    }

    [data-bs-theme="dark"] .document-show-actions {
        border-color: rgba(255, 255, 255, 0.1);
        background: var(--surface-card, #1e1e1e);
    }

    [data-bs-theme="dark"] .document-show-actions > .btn,
    [data-bs-theme="dark"] .document-show-actions > a.btn,
    [data-bs-theme="dark"] .document-show-actions > form {
        border-right-color: rgba(255, 255, 255, 0.1) !important;
        border-bottom-color: rgba(255, 255, 255, 0.1) !important;
    }

    /* Anteprima documento */
    .doc-preview {
        padding: 0.15rem 0 0;
    }

    .doc-preview__header {
        margin-bottom: 0.85rem;
        padding-bottom: 0.75rem;
    }

    .doc-preview__grid {
        grid-template-columns: 1fr;
        gap: 0.65rem;
        margin-bottom: 0.9rem;
    }

    .doc-preview__panel {
        padding: 0.75rem 0.85rem;
    }

    .doc-preview__contacts {
        flex-wrap: wrap;
    }

    .doc-preview__table-wrap {
        border: none;
        overflow: visible;
    }

    .doc-preview__table--lines thead {
        display: none;
    }

    .doc-preview__table--lines tbody tr {
        display: block;
        margin-bottom: 0.65rem;
        padding: 0.75rem 0.85rem;
        border: 1px solid var(--doc-preview-line, #e2e8f0);
        border-radius: 0.65rem;
        background: var(--doc-preview-soft, #f8fafc);
    }

    .doc-preview__table--lines tbody td {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        gap: 0.75rem;
        padding: 0.3rem 0;
        border: none;
        text-align: right !important;
        white-space: normal !important;
    }

    .doc-preview__table--lines tbody td::before {
        content: attr(data-label);
        font-size: 0.72rem;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.03em;
        color: var(--doc-preview-muted, #64748b);
        text-align: left;
        flex: 0 0 auto;
        max-width: 42%;
    }

    .doc-preview__table--lines tbody td[data-label="Descrizione"] {
        flex-direction: column;
        align-items: stretch;
        gap: 0.2rem;
        padding-bottom: 0.55rem;
        margin-bottom: 0.25rem;
        border-bottom: 1px solid var(--doc-preview-line, #e2e8f0) !important;
        text-align: left !important;
        font-weight: 600;
    }

    .doc-preview__table--lines tbody td[data-label="Descrizione"]::before {
        max-width: none;
    }

    .doc-preview__table--lines tfoot {
        display: block;
        margin-top: 0.35rem;
        padding: 0.65rem 0.85rem;
        border: 1px solid var(--doc-preview-line, #e2e8f0);
        border-radius: 0.65rem;
        background: var(--surface-card, #fff);
    }

    .doc-preview__table--lines tfoot tr {
        display: flex;
        justify-content: space-between;
        align-items: baseline;
        gap: 0.75rem;
        padding: 0.35rem 0;
        border: none;
    }

    .doc-preview__table--lines tfoot th {
        display: none;
    }

    .doc-preview__table--lines tfoot td {
        display: flex;
        justify-content: space-between;
        align-items: baseline;
        width: 100%;
        border: none;
        padding: 0;
        background: transparent;
    }

    .doc-preview__table--lines tfoot td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--doc-preview-muted, #64748b);
        font-size: 0.85rem;
    }

    .doc-preview__table--lines tfoot .doc-preview__total-row--grand td {
        padding-top: 0.45rem;
        margin-top: 0.2rem;
        border-top: 1px solid var(--doc-preview-line, #e2e8f0);
        font-size: 1.05rem;
    }

    .doc-preview__table--lines tfoot .doc-preview__total-row--grand td::before {
        color: var(--doc-preview-ink, #0f172a);
        font-weight: 700;
    }

    .app-main .row.g-4 > [class*="col-"] > .card.table-card {
        margin-bottom: 0.85rem;
    }

    .app-main .row.g-4 > [class*="col-"] > .card.table-card .card-header {
        padding: 0.75rem 0.9rem;
    }

    .app-main .row.g-4 > [class*="col-"] > .card.table-card .card-body {
        padding: 0.85rem 0.9rem;
    }

    .alert.d-flex code {
        display: block;
        max-width: 100%;
        overflow-wrap: anywhere;
        word-break: break-all;
        margin-top: 0.35rem;
    }
}

@media (max-width: 380px) {
    .document-show-actions,
    .document-show-actions.d-flex {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .document-show-actions > *:nth-child(3n) {
        border-right: 1px solid var(--surface-border, #e2e8f0) !important;
    }

    .document-show-actions > *:nth-child(2n) {
        border-right: 0 !important;
    }

    .document-show-actions > *:nth-child(3n+1):nth-last-child(-n+3),
    .document-show-actions > *:nth-child(3n+1):nth-last-child(-n+3) ~ * {
        border-bottom: 1px solid var(--surface-border, #e2e8f0) !important;
    }

    .document-show-actions > *:nth-child(2n+1):nth-last-child(-n+2),
    .document-show-actions > *:nth-child(2n+1):nth-last-child(-n+2) ~ * {
        border-bottom: 0 !important;
    }
}

/* APP nativa: stessa griglia anche se il webview è più largo di 768 */
html.exofattura-native .document-show-actions,
html.exofattura-native .document-show-actions.d-flex {
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0 !important;
    width: 100%;
    border: 1px solid var(--surface-border, #e2e8f0);
    border-radius: 0.5rem;
    overflow: hidden;
    background: var(--surface-card, #fff);
    flex-wrap: unset !important;
}

html.exofattura-native .document-show-header {
    flex-direction: column;
    align-items: stretch !important;
    gap: 0.85rem;
}

html.exofattura-native .document-show-actions .document-show-back-desktop,
html.exofattura-native .document-show-back-desktop {
    display: none !important;
}

html.exofattura-native .document-show-actions > .btn,
html.exofattura-native .document-show-actions > a.btn,
html.exofattura-native .document-show-actions > form {
    width: 100%;
    margin: 0 !important;
    min-width: 0;
    border: 0 !important;
    border-right: 1px solid var(--surface-border, #e2e8f0) !important;
    border-bottom: 1px solid var(--surface-border, #e2e8f0) !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    background: transparent !important;
    color: var(--text-muted, #64748b) !important;
}

html.exofattura-native .document-show-actions > .btn,
html.exofattura-native .document-show-actions > a.btn,
html.exofattura-native .document-show-actions > form > .btn {
    display: flex !important;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    min-height: 4.5rem;
    height: 100%;
    width: 100%;
    padding: 0.55rem 0.3rem 0.45rem !important;
    font-size: 0.68rem !important;
    font-weight: 500 !important;
    line-height: 1.2 !important;
    text-align: center;
    white-space: normal;
    overflow: hidden;
    text-decoration: none !important;
}

html.exofattura-native .document-show-actions > form {
    display: flex;
    flex-direction: column;
    min-height: 4.5rem;
    padding: 0;
}

html.exofattura-native .document-show-actions > form > .btn {
    border: 0 !important;
    border-radius: 0 !important;
    background: transparent !important;
    color: var(--text-muted, #64748b) !important;
    box-shadow: none !important;
}

html.exofattura-native .document-show-actions > *:nth-child(3n) {
    border-right: 0 !important;
}

html.exofattura-native .document-show-actions > *:nth-child(3n+1):nth-last-child(-n+3),
html.exofattura-native .document-show-actions > *:nth-child(3n+1):nth-last-child(-n+3) ~ * {
    border-bottom: 0 !important;
}

html.exofattura-native .document-show-actions .btn .bi,
html.exofattura-native .document-show-actions .btn .exo-i,
html.exofattura-native .document-show-actions .btn .exo-lucide {
    margin: 0 !important;
    font-size: 1.15rem !important;
    line-height: 1;
    color: var(--text-muted, #64748b);
    flex: 0 0 auto;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
}

html.exofattura-native .document-show-actions .btn .exo-lucide__svg,
html.exofattura-native .document-show-actions .btn .exo-i svg,
html.exofattura-native .document-show-actions .btn svg.lucide {
    width: 1.15rem !important;
    height: 1.15rem !important;
    display: block;
    stroke: currentColor;
}

html.exofattura-native .document-show-actions .btn.btn-danger,
html.exofattura-native .document-show-actions .btn.btn-outline-danger {
    color: var(--bs-danger, #dc3545) !important;
}

html.exofattura-native .document-show-actions .btn.btn-danger .bi,
html.exofattura-native .document-show-actions .btn.btn-outline-danger .bi,
html.exofattura-native .document-show-actions .btn.btn-danger .exo-i,
html.exofattura-native .document-show-actions .btn.btn-outline-danger .exo-i {
    color: var(--bs-danger, #dc3545);
}
