/* Base Variables */
:root {
    --accent-color: #006D77; /* Teal Green (Green with a note of blue) */
    --accent-dark: #004B52;
    --accent-light: #E6F2F2;
    --mint-bg: #F2F8F8;
    --text-main: #2C3E50;
    --text-muted: #607D8B;
    --border-color: #D1D9E0;
    --bg-gray: #F8FAFB;
}

[v-cloak] { display: none; }
.print-only { display: none; }

body {
    font-family: 'Inter', sans-serif;
    color: var(--text-main);
    margin: 0;
    padding: 0;
    background-color: var(--bg-gray);
    font-size: 0.9rem;
}

/* App Header (No Print) */
.app-header {
    background-color: white;
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    position: sticky;
    top: 0;
    z-index: 100;
}

body:has(> .app-user-bar) .app-header {
    top: var(--app-user-bar-height, 2.75rem);
}

.app-header h1 {
    margin: 0;
    font-size: 1.5rem;
    color: var(--accent-dark);
}

.header-actions {
    display: flex;
    gap: 1rem;
}

/* Buttons */
.btn {
    padding: 0.5rem 1rem;
    border-radius: 6px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    font-size: 0.9rem;
    border: none;
}

.btn-primary {
    background-color: var(--accent-color);
    color: white;
}

.btn-primary:hover {
    background-color: var(--accent-dark);
}

.btn-outline {
    background-color: transparent;
    border: 1px solid var(--accent-color);
    color: var(--accent-color);
}

.btn-outline:hover {
    background-color: var(--accent-light);
}

.btn-outline-danger {
    background-color: transparent;
    border: 1px solid #e57373;
    color: #c62828;
}

.btn-outline-danger:hover {
    background-color: #ffebee;
}

.btn-success {
    background-color: #2e7d32;
    color: white;
}
.btn-success:hover {
    background-color: #1b5e20;
}

.btn-danger {
    background-color: #d32f2f;
    color: white;
}
.btn-danger:hover {
    background-color: #c62828;
}

.btn-small {
    padding: 0.3rem 0.6rem;
    font-size: 0.8rem;
}

.btn-full {
    width: 100%;
    margin-top: 1rem;
}

.btn-full--flush {
    margin-top: 0;
}

/* Layout */
.main-container {
    display: flex;
    gap: 2rem;
    padding: 2rem;
    max-width: 1400px;
    margin: 0 auto;
}

/* Sidebar */
.editor-sidebar {
    width: 320px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.panel {
    background: white;
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.panel h3 {
    margin-top: 0;
    margin-bottom: 1rem;
    font-size: 1.1rem;
    color: var(--accent-dark);
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.5rem;
}

.panel h3:not(:first-child) {
    margin-top: 1.5rem;
}

/* Forms */
.form-group {
    margin-bottom: 1rem;
}

.form-row {
    display: flex;
    gap: 1rem;
}

.form-row .form-group {
    flex: 1;
    min-width: 0;
}

.form-row:has(> .form-group:first-child input[type="date"]):has(> .form-group:nth-child(2) input[type="date"]) {
    flex-direction: row;
    gap: 1rem;
}

label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    margin-bottom: 0.4rem;
    color: var(--text-muted);
}

input[type="text"], input[type="email"], input[type="password"], input[type="date"], input[type="number"], select, textarea {
    width: 100%;
    max-width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-family: inherit;
    box-sizing: border-box;
}

input[type="date"] {
    min-width: 0;
}

select {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    padding-right: 2.25rem;
    background-color: #fff;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none'%3E%3Cpath d='M4 6l4 4 4-4' stroke='%23607D8B' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 0.85rem;
    cursor: pointer;
}

select:disabled {
    cursor: not-allowed;
    opacity: 0.7;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px var(--accent-light);
}

.toggle-group {
    margin-bottom: 0.8rem;
}

.toggle-label {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 0.95rem;
    color: var(--text-main);
}

.toggle-label__content {
    flex: 1;
    min-width: 0;
    line-height: 1.4;
}

hr {
    border: 0;
    border-top: 1px solid var(--border-color);
    margin: 1.5rem 0;
}

/* Document Preview Wrapper */
.document-preview-wrapper {
    flex-grow: 1;
    display: flex;
    justify-content: center;
}

.page-fatturazione .document-preview-wrapper {
    min-width: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.page-fatturazione .a4-document {
    flex-shrink: 0;
}

.page-note-spese .document-preview-wrapper {
    min-width: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.page-note-spese .a4-document {
    flex-shrink: 0;
}

/* A4 Document */
.a4-document {
    background: white;
    width: 210mm;
    min-height: 297mm;
    padding: 20mm;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    box-sizing: border-box;
    position: relative;
    display: flex;
    flex-direction: column;
}

/* Doc Header */
.doc-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 2rem;
    border-bottom: 2px solid var(--accent-color);
    padding-bottom: 1rem;
    align-items: flex-end;
}

.doc-meta-info {
    text-align: right;
}

.doc-badge {
    display: inline-block;
    color: var(--accent-dark);
    padding: 0;
    font-weight: 700;
    font-size: 1.2rem;
    letter-spacing: 1px;
    margin-bottom: 0.5rem;
    text-transform: uppercase;
}

.proforma-warning {
    color: #d32f2f;
    font-size: 0.75rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    text-transform: uppercase;
}

.meta-table {
    margin-left: auto;
    font-size: 0.85rem;
}

.meta-table td {
    padding: 0.2rem 0;
}

.meta-table td:first-child {
    color: var(--text-muted);
    padding-right: 1rem;
    text-align: right;
}

.doc-example-text {
    color: var(--text-muted);
    font-weight: 500;
}

.doc-header--expense {
    display: grid;
    grid-template-columns: auto 1fr;
    grid-template-rows: auto auto;
    column-gap: 1.5rem;
    row-gap: 0.15rem;
    align-items: baseline;
}

.doc-header--expense .doc-type-info {
    grid-row: 1;
    grid-column: 1;
}

.doc-header--expense .doc-badge {
    margin-bottom: 0;
}

.expense-header-line {
    grid-column: 2;
    display: flex;
    justify-content: flex-end;
    align-items: baseline;
    flex-wrap: nowrap;
    gap: 1.5rem;
    font-size: 0.85rem;
}

.expense-header-line:not(.expense-header-line--end) {
    grid-row: 1;
}

.expense-header-line--end {
    grid-row: 2;
}

.expense-meta-chip {
    display: inline-flex;
    align-items: baseline;
    gap: 0.5rem;
    white-space: nowrap;
}

.expense-meta-chip .meta-label,
.doc-header--expense .meta-label {
    color: var(--text-muted);
    white-space: nowrap;
}

.expense-trip-date {
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

/* Addresses Section */
.addresses-section {
    display: flex;
    justify-content: space-between;
    margin-bottom: 2rem;
    gap: 3rem;
}

.issuer-box, .client-box {
    flex: 1;
}

.address-label {
    margin: 0 0 0.3rem 0;
    color: var(--accent-color);
    font-size: 0.7rem;
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: 1px;
    border-bottom: 1px solid var(--accent-light);
    display: inline-block;
    padding-bottom: 2px;
}

.issuer-name, .client-name {
    margin: 0.5rem 0 0.5rem 0;
    font-size: 1rem;
    color: var(--text-main);
}

.issuer-box p, .client-box p {
    margin: 0;
    font-size: 0.8rem;
    line-height: 1.4;
    color: var(--text-muted);
}

.subject-section {
    margin: 0 0 1rem 0;
}

.subject-label {
    margin: 0 0 0.3rem 0;
    color: var(--accent-color);
    font-size: 0.7rem;
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: 1px;
}

.subject-text {
    margin: 0;
    font-size: 0.85rem;
    line-height: 1.4;
    color: var(--text-main);
}

/* Items Table */
.items-section {
    margin-bottom: 1.5rem;
}

.items-table {
    width: 100%;
    border-collapse: collapse;
}

.items-table th {
    background-color: var(--accent-light);
    color: var(--accent-dark);
    text-align: left;
    padding: 0.6rem;
    font-weight: 600;
    font-size: 0.8rem;
}

.items-table td {
    padding: 0.6rem;
    border-bottom: 1px solid var(--border-color);
    vertical-align: top;
    font-size: 0.8rem;
}

.items-table tbody tr:nth-child(even) {
    background-color: #fafbfa;
}

.col-um {
    width: 8%;
    text-align: center;
}

.col-qty, .col-price, .col-total {
    text-align: right;
    width: 13%;
}

.items-table th.col-um {
    text-align: center;
}

.items-table th.col-qty, .items-table th.col-price, .items-table th.col-total {
    text-align: right;
}

.col-actions {
    width: 5%;
    text-align: center;
}

/* Inline Inputs for Table */
.items-table .inline-input {
    border: 1px solid transparent;
    background: transparent;
    padding: 0.35rem 0.4rem;
    width: 100%;
    font-family: inherit;
    font-size: inherit;
    color: inherit;
    box-sizing: border-box;
    line-height: 1.5;
    border-radius: 4px;
}

.inline-input:focus, .inline-input:hover {
    border: 1px solid var(--border-color);
    background: white;
}

.desc-input {
    resize: none;
    overflow: hidden;
    min-height: calc(1.5em + 0.7rem);
    field-sizing: content;
}

.um-input {
    text-align: center;
}

.num-input {
    text-align: right;
    -moz-appearance: textfield;
}

.num-input::-webkit-outer-spin-button,
.num-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.currency-input {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.15rem;
}

/* Invoice items table — editor desktop */
.invoice-items-table {
    table-layout: fixed;
}

.invoice-items-table .col-desc {
    width: 34%;
}

.invoice-items-table .col-qty {
    width: 9%;
    text-align: right;
}

.invoice-items-table .col-um {
    width: 9%;
    min-width: 2.75rem;
    text-align: center;
}

.invoice-items-table .col-price {
    width: 14%;
    text-align: right;
}

.invoice-items-table .col-total {
    width: 12%;
    text-align: right;
}

.invoice-items-table th.col-qty,
.invoice-items-table th.col-um,
.invoice-items-table th.col-price,
.invoice-items-table th.col-total {
    white-space: nowrap;
}

.invoice-items-table th.col-um {
    text-align: center;
}

.invoice-items-table td.col-qty,
.invoice-items-table td.col-um,
.invoice-items-table td.col-price,
.invoice-items-table td.col-total,
.invoice-items-table td.col-actions {
    vertical-align: top;
}

.invoice-items-table .desc-input {
    word-break: break-word;
    overflow-wrap: anywhere;
}

.invoice-items-table .invoice-cell-static {
    display: block;
    padding: 0.35rem 0.4rem;
    line-height: 1.5;
    text-align: right;
    box-sizing: border-box;
}

.invoice-items-table .currency-input {
    display: flex;
    align-items: flex-start;
    justify-content: flex-end;
    flex-wrap: nowrap;
    gap: 0.15rem;
}

.invoice-items-table .currency-input > span.no-print {
    padding: 0.35rem 0;
    line-height: 1.5;
}

.invoice-items-table .currency-input .inline-input {
    width: auto;
    min-width: 2.5rem;
    max-width: 100%;
    flex: 0 1 auto;
}

.invoice-items-table .col-qty .inline-input {
    text-align: right;
}

.invoice-items-table .um-input {
    text-align: center;
}

.invoice-items-table td.col-actions {
    padding-top: calc(0.6rem + 0.15rem);
}

.btn-icon {
    background: none;
    border: none;
    color: #f44336;
    font-size: 1.2rem;
    cursor: pointer;
    opacity: 0.5;
}

.btn-icon:hover {
    opacity: 1;
}

.add-row-wrapper {
    margin-top: 1rem;
}

/* Totals Section */
.totals-section {
    width: 100%;
    display: flex;
    justify-content: flex-end;
    margin-bottom: 2rem;
}

.totals-box {
    background-color: var(--mint-bg);
    border-radius: 8px;
    padding: 1.5rem;
    width: 50%;
}

/* Spacer */
.doc-spacer {
    flex-grow: 1;
}

/* Notes Section */
.notes-section {
    border-left: 4px solid var(--accent-color);
    padding-left: 1rem;
    width: 100%;
    margin-bottom: 2rem;
    page-break-inside: avoid;
}

.notes-label {
    font-weight: 600;
    color: var(--accent-dark);
    margin: 0 0 0.5rem 0;
    font-size: 0.8rem;
}

.banking-coords {
    margin-bottom: 0.75rem;
}

.banking-coords .coord-line {
    margin: 0 0 0.35rem 0;
    font-size: 0.8rem;
    line-height: 1.5;
}

.notes-extra-hint {
    margin: 0 0 0.25rem 0;
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 400;
}

.notes-textarea {
    border: 1px solid transparent;
    background: transparent;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    display: block;
    resize: none;
    overflow: hidden;
    font-family: inherit;
    font-size: 0.8rem;
    line-height: 1.5;
    padding: 0;
    min-height: 1.5em;
    field-sizing: content;
}

.notes-textarea:focus, .notes-textarea:hover {
    border: 1px solid var(--border-color);
    background: #fff;
    padding: 0.5rem;
}

.total-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.8rem;
    font-size: 0.8rem;
    align-items: center;
}

.total-row span:last-child {
    white-space: nowrap;
}

.total-row:last-child {
    margin-bottom: 0;
}

.final-total {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 2px solid var(--accent-color);
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--accent-dark);
}

/* Footer */
.doc-footer {
    margin-top: auto;
    border-top: 1px solid var(--border-color);
    padding-top: 1rem;
    font-size: 0.7rem;
    color: var(--text-muted);
    text-align: justify;
    page-break-inside: avoid;
}

.doc-footer p {
    margin: 0 0 0.4rem 0;
}

/* Modals — native <dialog> */
html:has(dialog[open]),
body:has(dialog[open]),
html.dialog-scroll-locked,
body.dialog-scroll-locked {
    overflow: hidden;
    max-width: 100%;
}

dialog.modal-overlay {
    border: none;
    padding: 0;
    margin: 0;
    max-width: none;
    max-height: none;
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    background: rgba(0, 0, 0, 0.5);
    overflow: visible;
    overscroll-behavior: contain;
}

dialog.modal-overlay::backdrop {
    background: transparent;
}

dialog.modal-overlay[open] {
    display: flex;
    justify-content: center;
    align-items: center;
}

dialog.pdf-generating-overlay {
    border: none;
    padding: 0;
    margin: 0;
    max-width: none;
    max-height: none;
    width: 100%;
    height: 100%;
    background: transparent;
    overflow: visible;
}

dialog.pdf-generating-overlay::backdrop {
    background: rgba(44, 62, 80, 0.32);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

dialog.pdf-generating-overlay[open] {
    display: flex;
    justify-content: center;
    align-items: center;
}

.pdf-generating-overlay {
    pointer-events: all;
}

.pdf-generating-overlay__card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.85rem;
    padding: 2rem 2.75rem;
    min-width: 260px;
    text-align: center;
    background: rgba(255, 255, 255, 0.98);
    border: 1px solid rgba(0, 109, 119, 0.14);
    border-radius: 14px;
    box-shadow:
        0 1px 2px rgba(0, 77, 82, 0.06),
        0 16px 40px rgba(0, 0, 0, 0.14);
    animation: pdf-overlay-enter 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}

.pdf-generating-overlay__spinner {
    width: 38px;
    height: 38px;
    border: 2.5px solid var(--accent-light);
    border-top-color: var(--accent-color);
    border-radius: 50%;
    animation: pdf-overlay-spin 0.9s cubic-bezier(0.45, 0.05, 0.55, 0.95) infinite;
}

.pdf-generating-overlay__title {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    color: var(--accent-dark);
}

.pdf-generating-overlay__subtitle {
    margin: -0.35rem 0 0;
    font-size: 0.82rem;
    font-weight: 400;
    color: var(--text-muted);
    letter-spacing: 0.01em;
}

@keyframes pdf-overlay-spin {
    to { transform: rotate(360deg); }
}

@keyframes pdf-overlay-enter {
    from {
        opacity: 0;
        transform: scale(0.96) translateY(8px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal-content {
    background: white;
    padding: 2rem;
    border-radius: 8px;
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    box-sizing: border-box;
}

.modal-content.large {
    max-width: 800px;
}

.history-cards {
    display: none;
    flex-direction: column;
    gap: 0.75rem;
    margin-top: 1rem;
}

.history-cards-empty {
    margin: 0;
    padding: 1.5rem 0.5rem;
    text-align: center;
}

.history-doc-card {
    background: var(--bg-gray);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.85rem 1rem;
}

.history-doc-card__header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.65rem;
}

.history-doc-card__number {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--accent-dark);
    line-height: 1.3;
    min-width: 0;
    word-break: break-word;
}

.history-doc-card__total {
    flex-shrink: 0;
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-main);
}

.history-doc-card__meta {
    display: grid;
    gap: 0.45rem;
    margin: 0 0 0.75rem;
}

.history-doc-card__field {
    display: grid;
    grid-template-columns: 4.5rem 1fr;
    gap: 0.5rem;
    align-items: baseline;
    margin: 0;
}

.history-doc-card__field dt {
    margin: 0;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.history-doc-card__field dd {
    margin: 0;
    font-size: 0.85rem;
    color: var(--text-main);
    word-break: break-word;
}

.history-doc-card__actions {
    padding-top: 0.65rem;
    border-top: 1px solid var(--border-color);
}

.history-doc-card__meta--compact {
    margin-bottom: 0;
}

.history-doc-card--total {
    background: var(--accent-light);
    border-color: var(--accent-color);
}

.history-doc-card--total .history-doc-card__number {
    color: var(--text-main);
}

.history-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-top: 1rem;
}

.history-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.history-table th, .history-table td {
    padding: 0.65rem 0.75rem;
    border-bottom: 1px solid var(--border-color);
    text-align: left;
    vertical-align: middle;
}

.history-table th {
    background: var(--accent-light);
    color: var(--accent-dark);
    font-weight: 600;
    font-size: 0.8rem;
}

.history-table tbody tr:hover {
    background-color: #fafbfa;
}

.history-table .col-total,
.history-table th.col-total {
    text-align: right;
    white-space: nowrap;
}

.history-table .col-actions,
.history-table th.col-actions {
    width: 1%;
    white-space: nowrap;
}

.page-note-spese .history-table .col-number,
.page-note-spese .history-table th.col-number {
    min-width: 14rem;
    white-space: nowrap;
}

.page-note-spese .history-table .col-period,
.page-note-spese .history-table th.col-period {
    min-width: 7.5rem;
}

.page-note-spese .history-table .actions-cell {
    white-space: nowrap;
    width: 1%;
}

.trip-period-lines {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    line-height: 1.35;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.currency-cell {
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.doc-type-badge {
    display: inline-block;
    font-size: 0.72rem;
    font-weight: 600;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    white-space: nowrap;
}

.doc-type-badge--fattura {
    background: var(--accent-light);
    color: var(--accent-dark);
}

.doc-type-badge--proforma {
    background: #fff3e0;
    color: #e65100;
}

.history-actions {
    display: flex;
    flex-wrap: nowrap;
    gap: 0.35rem;
    align-items: center;
}

.modal-content.doc-history-modal {
    padding: 1.25rem 2rem 2rem;
    max-width: 960px;
}

.modal-content.doc-history-modal h2 {
    margin: 0 0 0.35rem;
}

.doc-history-tabs {
    display: flex;
    gap: 0.35rem;
    margin: 1rem 0 0.75rem;
    border-bottom: 1px solid var(--border-color);
}

.doc-history-tab {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    margin: 0 0 -1px;
    padding: 0.55rem 0.85rem;
    border: none;
    border-bottom: 2px solid transparent;
    background: none;
    color: var(--text-muted);
    font: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
}

.doc-history-tab:hover {
    color: var(--text-main);
}

.doc-history-tab--active {
    color: var(--accent-color);
    border-bottom-color: var(--accent-color);
}

.doc-history-tab-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.35rem;
    padding: 0.1rem 0.4rem;
    border-radius: 999px;
    background: var(--bg-gray);
    color: var(--text-muted);
    font-size: 0.75rem;
    font-variant-numeric: tabular-nums;
}

.doc-history-tab--active .doc-history-tab-count {
    background: var(--accent-light);
    color: var(--accent-dark);
}

.modal-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
    margin-top: 1.5rem;
}

.success-message {
    color: #2e7d32;
    font-size: 0.9rem;
    margin-top: 0.5rem;
    text-align: center;
    font-weight: 500;
}

/* Statistiche fatturato */
.modal-content.stats-modal {
    padding: 1.25rem 2rem 2rem;
    max-width: 1280px;
}

.modal-content.stats-modal h2 {
    margin: 0 0 0.35rem;
}

.stats-hint {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin: 0 0 1rem;
}

.stats-params {
    display: grid;
    grid-template-columns: repeat(3, 1fr) auto;
    gap: 1rem;
    align-items: end;
    margin-bottom: 1.25rem;
    padding-bottom: 1.25rem;
    border-bottom: 1px solid var(--border-color);
}

.stats-params-actions {
    display: flex;
    align-items: center;
}

.stats-params-actions .btn {
    white-space: nowrap;
    height: 2.375rem;
    padding-block: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
}

.stats-params .form-group {
    margin: 0;
    display: flex;
    flex-direction: column;
}

.stats-params label {
    font-size: 0.8rem;
    min-height: 2.6em;
    line-height: 1.3;
    margin-bottom: 0.4rem;
}

.stats-params input,
.stats-params select {
    width: 100%;
    box-sizing: border-box;
    height: 2.375rem;
    margin: 0;
    padding: 0.5rem 2.25rem 0.5rem 0.5rem;
    background-color: #fff;
}

.stats-params input {
    padding-right: 0.5rem;
}

@media (max-width: 640px) {
    .stats-params {
        grid-template-columns: 1fr;
    }

    .stats-params-actions {
        justify-content: flex-start;
    }
}

.stats-history-warning {
    margin-top: 0.75rem;
    line-height: 1.45;
}

.stats-history-save-error {
    margin-bottom: 1rem;
}

.stats-history-warning-link {
    display: inline;
    margin: 0;
    padding: 0;
    border: none;
    background: none;
    color: inherit;
    font: inherit;
    font-weight: 600;
    text-decoration: underline;
    cursor: pointer;
}

.stats-history-warning-link:hover {
    color: #bf360c;
}

.stats-prior-year-calc {
    margin-top: 1rem;
    padding: 0.85rem 1rem;
    background: var(--bg-gray);
    border: 1px solid var(--border-color);
    border-radius: 8px;
}

.stats-prior-year-calc-label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.stats-prior-year-calc-table {
    font-size: 0.8rem;
}

.stats-prior-year-calc-table td:not(:first-child) {
    color: var(--accent-dark);
    font-weight: 600;
}

.modal-content.stats-history-modal {
    padding: 1.25rem 2rem 2rem;
    max-width: 960px;
}

.stats-history-empty {
    margin-bottom: 1rem;
    padding: 0.85rem 1rem;
    background: var(--bg-gray);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.stats-history-year {
    margin-bottom: 1.25rem;
    padding-bottom: 1.25rem;
    border-bottom: 1px solid var(--border-color);
}

.stats-history-year:last-of-type {
    border-bottom: none;
}

.stats-history-year-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.stats-history-year-title {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--accent-dark);
}

.stats-history-fields {
    margin-bottom: 0.75rem;
    grid-template-columns: repeat(2, 1fr);
}

@media (max-width: 640px) {
    .stats-history-fields {
        grid-template-columns: 1fr;
    }
}

.stats-history-calc {
    margin-top: 0;
}

.stats-history-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
    margin: 0 0 1.25rem;
}

.stats-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.stats-deadlines {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: stretch;
    column-gap: 1rem;
    row-gap: 3.75rem;
    margin-bottom: 3.5rem;
    min-width: 0;
}

.stats-deadlines + .stats-section-title {
    margin-top: 1.25rem;
}

@media (max-width: 960px) {
    .stats-deadlines {
        grid-template-columns: 1fr;
    }
}

.stats-deadline-card {
    background: var(--mint-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    height: 100%;
    min-height: 0;
    min-width: 0;
    max-width: 100%;
}

.stats-deadline-card-body {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.stats-deadline-table-wrap {
    flex: 1 1 auto;
    min-width: 0;
}

.stats-deadline-footer-wrap {
    flex-shrink: 0;
    margin-top: auto;
    min-width: 0;
}

.stats-deadline-title {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--accent-dark);
}

.stats-deadline-card .stats-breakdown {
    margin-top: 0;
    padding-top: 0;
    border-top: none;
}

.stats-deadline-table {
    width: 100%;
    min-width: 28rem;
    table-layout: fixed;
    border-collapse: collapse;
    font-size: 0.7rem;
}

.stats-deadline-table-credit th:not(:first-child),
.stats-deadline-table-credit td:not(:first-child) {
    width: 14%;
}

.stats-deadline-col-label {
    width: 24%;
}

.stats-deadline-col-amount {
    width: 19%;
}

.stats-deadlines-hint {
    margin-top: -0.25rem;
    margin-bottom: 0.75rem;
}

.stats-compensato-col {
    color: var(--text-muted);
    font-size: 0.68rem;
}

.stats-compensato-used {
    color: var(--accent-dark);
}

.stats-compensato-gen {
    color: #2e7d32;
}

.stats-versare-col {
    font-weight: 600;
}

.stats-versare-total {
    font-size: 0.85rem;
    color: var(--accent-dark);
}

.stats-credit-col {
    color: var(--text-muted);
}

.stats-deadline-credit-row td {
    font-size: 0.68rem;
    color: var(--text-muted);
    border-top: 1px dashed var(--border-color);
}

.stats-deadline-credit-row .stats-credit-col,
.stats-deadline-credit-row .stats-versare-col {
    color: var(--accent-dark);
    font-weight: 600;
}

.stats-deadline-table th,
.stats-deadline-table td {
    padding: 0.35rem 0.4rem;
    text-align: right;
    vertical-align: top;
}

.stats-deadline-table th:not(:first-child),
.stats-deadline-table td:not(:first-child) {
    white-space: nowrap;
}

.stats-deadline-table thead th:not(:first-child) {
    white-space: normal;
    line-height: 1.25;
    font-size: 0.65rem;
    hyphens: auto;
}

.stats-deadline-table th:first-child,
.stats-deadline-table td:first-child {
    width: 30%;
    text-align: left;
    padding-left: 0;
    white-space: normal;
}

.stats-deadline-table thead th {
    color: var(--text-muted);
    font-weight: 600;
    border-bottom: 1px solid var(--border-color);
}

.stats-deadline-table th:last-child,
.stats-deadline-table td:last-child {
    font-weight: 600;
    color: var(--text-main);
}

.stats-deadline-label {
    color: var(--text-muted);
    padding-right: 0.5rem;
    line-height: 1.35;
}

.stats-deadline-total-row td {
    padding-top: 0.55rem;
    border-top: 1px solid var(--border-color);
    font-weight: 600;
    color: var(--accent-dark);
}

.stats-deadline-total-row td:last-child {
    font-size: 0.9rem;
}

.stats-card {
    background: var(--mint-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.stats-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
}

.stats-value {
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--accent-dark);
}

.stats-formula {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.stats-breakdown {
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.stats-breakdown-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.stats-breakdown-row span:last-child {
    font-weight: 600;
    color: var(--text-main);
}

.stats-section-title {
    margin: 0 0 1rem;
    font-size: 1rem;
    color: var(--accent-dark);
}

.stats-empty {
    color: var(--text-muted);
    text-align: center;
    padding: 1.5rem 0;
}

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

.stats-pie-layout {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 1.5rem;
    margin-bottom: 0.25rem;
}

.stats-modal-actions {
    margin-top: 2rem;
    padding-top: 0.25rem;
}

.stats-pie {
    width: 180px;
    height: 180px;
    border-radius: 50%;
    flex-shrink: 0;
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.06);
}

.stats-pie-legend {
    flex: 0 1 auto;
    width: max-content;
    max-width: 100%;
    min-width: 220px;
    display: table;
    border-collapse: collapse;
}

.stats-pie-legend-row {
    display: table-row;
    font-size: 0.85rem;
}

.stats-pie-name,
.stats-pie-pct,
.stats-pie-amount {
    display: table-cell;
    vertical-align: middle;
    padding: 0.35rem 0;
}

.stats-pie-name {
    font-weight: 500;
    white-space: nowrap;
    padding-right: 0.75rem;
}

.stats-pie-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    margin-right: 0.5rem;
    vertical-align: 0.08em;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.07);
}

.stats-pie-pct {
    font-weight: 600;
    color: var(--accent-dark);
    white-space: nowrap;
    padding-right: 0.75rem;
    text-align: right;
}

.stats-pie-amount {
    font-weight: 600;
    text-align: right;
    white-space: nowrap;
}

/* Print Styles */
    @media print {
    body {
        background-color: white;
    }
    .no-print {
        display: none !important;
    }
    .print-only {
        display: block !important;
    }
    .inline-input.print-only {
        display: inline !important;
    }
    .main-container {
        padding: 0;
        margin: 0;
        display: block;
        max-width: none;
    }
    .document-preview-wrapper {
        display: block;
    }
    .a4-document {
        box-shadow: none;
        width: 100%;
        height: auto;
        min-height: 0;
        padding: 0 !important;
        margin: 0;
        display: block;
    }

    .addresses-section {
        display: flex !important;
        flex-direction: row !important;
        justify-content: space-between;
        gap: 2rem !important;
    }

    .issuer-box,
    .client-box {
        flex: 1;
        min-width: 0;
    }

    .monthly-recap-document,
    .monthly-recap-note-document {
        display: none !important;
    }

    /* flex-grow on spacer + min-height A4 causes an empty trailing page when content overflows */
    .doc-spacer {
        display: none;
    }

    .doc-footer {
        margin-top: 2rem;
    }

    @page {
        size: A4;
        margin: 20mm;
    }

    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
        color-adjust: exact !important;
    }
    
    .inline-input, .notes-textarea {
        border: none !important;
        background: transparent !important;
        padding: 0 !important;
        resize: none !important;
    }

    /* Evita che il testo segnaposto compaia in anteprima/stampa (Safari/WebKit) */
    .notes-textarea::placeholder,
    .inline-input::placeholder {
        color: transparent !important;
        opacity: 0 !important;
    }
}

/* Header title with back link (fatturazione) */
.header-title {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.back-home {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-decoration: none;
    font-weight: 500;
}

.back-home:hover {
    color: var(--accent-color);
}

/* Homepage */
.home-body {
    position: relative;
    isolation: isolate;
    min-height: 100vh;
    min-height: 100svh;
    display: flex;
    flex-direction: column;
    background-color: #fff;
    overflow-x: hidden;
}

/* Sfondo fisso su lvh: non si ricalcola quando la barra indirizzi mobile si nasconde (dvh). */
.home-body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    height: 100lvh;
    z-index: -1;
    background-color: #fff;
    background-image: url('../img/home-bg.png');
    background-repeat: no-repeat;
    background-position: right center;
    background-size: cover;
    pointer-events: none;
}

.home-body .home {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    margin: 0 auto;
}

.home {
    width: 100%;
    max-width: 720px;
    padding: 2rem 1.5rem;
    box-sizing: border-box;
}

.home-header {
    text-align: center;
    margin-bottom: 2.5rem;
}

.home-header h1 {
    margin: 0;
    font-size: 1.75rem;
    color: var(--accent-dark);
}

.home-subtitle {
    display: block;
    margin-top: 0.35rem;
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-muted);
}

.home-nav {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    width: 100%;
    min-width: 0;
}

.home-card {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.35rem;
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
    padding: 1.25rem 1.5rem;
    background: white;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    text-decoration: none;
    color: inherit;
    transition: border-color 0.2s, box-shadow 0.2s, transform 0.15s;
}

@media (hover: hover) and (pointer: fine) {
    .home-card:hover {
        border-color: var(--accent-color);
        box-shadow: 0 4px 16px rgba(0, 109, 119, 0.12);
        transform: translateY(-2px);
    }
}

.home-card:active {
    border-color: var(--accent-color);
    background: var(--accent-light);
}

.home-card-icon {
    font-size: 1.5rem;
    line-height: 1;
}

.home-card-title {
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--accent-dark);
    min-width: 0;
    overflow-wrap: break-word;
}

.home-card-desc {
    font-size: 0.85rem;
    color: var(--text-muted);
    line-height: 1.4;
    min-width: 0;
    overflow-wrap: break-word;
}

.home-card--disabled {
    cursor: not-allowed;
    opacity: 0.55;
    background: #f5f7f8;
    border-color: #d8dee2;
    pointer-events: none;
}

.home-card--disabled .home-card-title {
    color: var(--text-muted);
}

@media (hover: hover) and (pointer: fine) {
    .home-card--disabled:hover {
        border-color: #d8dee2;
        box-shadow: none;
        transform: none;
    }
}

/* Gestione contabile */
.page-gestione-contabile .accounting-main {
    max-width: 1280px;
    margin: 0 auto;
    padding: 1.25rem 1.5rem 2.5rem;
}

.page-gestione-contabile .accounting-shell {
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    overflow: hidden;
}

.page-gestione-contabile .accounting-shell-tabs {
    margin: 0;
    padding: 0 1.25rem;
    gap: 0.25rem;
}

.page-gestione-contabile .accounting-shell-panel {
    min-width: 0;
}

.page-gestione-contabile .accounting-shell-panel .accounting-panel {
    border: none;
    border-radius: 0;
    padding-top: 1rem;
    min-width: 0;
}

.page-gestione-contabile .accounting-loading {
    color: var(--text-muted);
    padding: 2rem 1.5rem;
    text-align: center;
}

.page-gestione-contabile .accounting-panel {
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1.25rem 1.5rem 1.5rem;
}

.page-gestione-contabile .accounting-panel h2 {
    margin: 0 0 0.35rem;
}

.page-gestione-contabile .accounting-panel-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-top: 1.5rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border-color);
}

.page-gestione-contabile .stats-history-panel {
    max-width: none;
}

/* Note spese */
.status-badge {
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    margin-left: 0.5rem;
}
.status-badge--draft { background: #fff3e0; color: #e65100; }
.status-badge--locked { background: #e8f5e9; color: #2e7d32; }

.history-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
    align-items: center;
}
.history-filters input,
.history-filters select {
    flex: 1;
    min-width: 120px;
}

.history-filters__search {
    flex: 2 1 160px;
    min-width: 160px;
}

.history-filters__date {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    flex: 0 1 auto;
}

.history-filters__date-label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-muted, #6b7280);
    white-space: nowrap;
}

.history-filters__date input[type="date"] {
    flex: 0 1 auto;
    min-width: 10.5rem;
    width: auto;
}

.modal-content.expense-history-modal {
    max-width: 1024px;
    width: min(96vw, 1024px);
}

.drop-zone {
    border: 2px dashed var(--border-color);
    border-radius: 8px;
    padding: 1.5rem;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
    font-size: 0.9rem;
    color: var(--text-muted);
}
.drop-zone:hover, .drop-zone--active {
    border-color: var(--accent-color);
    background: var(--accent-light);
}
.drop-zone--loading { opacity: 0.6; pointer-events: none; }
.drop-zone-hint { font-size: 0.8rem; }
.hidden-input { display: none; }
.field-hint { font-size: 0.75rem; color: var(--text-muted); margin: 0.25rem 0 0; }

.field-info-hint {
    position: relative;
    display: inline-flex;
    flex-shrink: 0;
    vertical-align: -0.1em;
    margin-left: 0.2rem;
}

.field-info-hint__btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.125rem;
    height: 1.125rem;
    padding: 0;
    border: 1px solid var(--text-muted);
    border-radius: 50%;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.7rem;
    font-weight: 700;
    font-family: Georgia, 'Times New Roman', serif;
    font-style: italic;
    line-height: 1;
    cursor: pointer;
}

.field-info-hint__btn:hover,
.field-info-hint__btn:focus-visible,
.field-info-hint__btn[aria-expanded="true"] {
    border-color: var(--accent-color);
    color: var(--accent-color);
    background: var(--accent-light);
    outline: none;
}

.field-info-hint__popover {
    position: absolute;
    z-index: 20;
    top: calc(100% + 0.35rem);
    left: 0;
    right: auto;
    width: max-content;
    max-width: min(280px, calc(100vw - 2rem));
    padding: 0.5rem 0.65rem;
    font-size: 0.75rem;
    font-weight: 400;
    font-style: normal;
    line-height: 1.45;
    color: var(--text-main);
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
    cursor: default;
}

.warning-banner {
    background: #fff3e0;
    color: #e65100;
    padding: 0.5rem 0.75rem;
    border-radius: 4px;
    font-size: 0.85rem;
    margin-bottom: 1rem;
}
.info-banner {
    background: var(--accent-light);
    color: var(--accent-dark);
    padding: 0.5rem 0.75rem;
    border-radius: 4px;
    font-size: 0.85rem;
    margin-bottom: 1rem;
}

.error-message { color: #c62828; font-size: 0.85rem; margin-top: 0.5rem; }
.locked-notice { font-size: 0.9rem; color: var(--text-muted); margin: 0 0 1rem; }
.locked-sidebar { width: 280px; }

.expense-subtitle { margin: 0; font-size: 0.85rem; color: var(--text-muted); }
.trip-summary {
    margin-bottom: 1.5rem;
    font-size: 0.85rem;
    line-height: 1.5;
}
.trip-summary p { margin: 0.25rem 0; }

.expense-notes-section {
    margin: 0 0 1.5rem;
    padding-left: 0.75rem;
    border-left: 3px solid var(--accent-color);
    font-size: 0.8rem;
    line-height: 1.5;
    page-break-inside: avoid;
}
.expense-notes-section .notes-label {
    margin: 0 0 0.35rem;
    font-weight: 600;
    color: var(--accent-dark);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.expense-note-text {
    margin: 0;
    color: var(--text-muted);
}
.expense-note-text + .expense-note-text {
    margin-top: 0.5rem;
}

.expense-items-table { font-size: 0.75rem; }

.expense-items-table:has(th.col-desc) {
    table-layout: fixed;
}

/* Tabella editabile (anteprima nota spese) */
.expense-items-table--editable .col-date {
    width: 6.4rem;
}

.expense-items-table--editable .col-desc { width: 27%; }
.expense-items-table--editable .col-cat { width: 15%; }
.expense-items-table--editable .col-loc { width: 16%; }
.expense-items-table--editable .col-amount { width: 9%; text-align: right; }
.expense-items-table--editable .col-rcpt { width: 10%; text-align: center; }

/* Tabella stampa (senza Ricevuta) */
.expense-items-table:has(th.col-desc):not(:has(th.col-rcpt)) .col-date { width: 6.5rem; }
.expense-items-table:has(th.col-desc):not(:has(th.col-rcpt)) .col-desc { width: 32%; }
.expense-items-table:has(th.col-desc):not(:has(th.col-rcpt)) .col-cat { width: 15%; }
.expense-items-table:has(th.col-desc):not(:has(th.col-rcpt)) .col-loc { width: 17%; }
.expense-items-table:has(th.col-desc):not(:has(th.col-rcpt)) .col-amount { width: 11%; text-align: right; }

.expense-items-table th.col-date,
.expense-items-table th.col-cat,
.expense-items-table th.col-loc,
.expense-items-table th.col-amount,
.expense-items-table th.col-rcpt {
    white-space: nowrap;
}

.expense-items-table td.col-date,
.expense-items-table td.col-desc,
.expense-items-table td.col-cat,
.expense-items-table td.col-loc,
.expense-items-table td.col-amount,
.expense-items-table td.col-rcpt,
.expense-items-table td.col-actions {
    vertical-align: top;
}

.expense-items-table--editable .col-desc .desc-input,
.expense-items-table--editable .col-loc .desc-input {
    word-break: break-word;
    overflow-wrap: break-word;
}

.expense-items-table td.col-desc,
.expense-items-table td.col-loc {
    word-break: break-word;
    overflow-wrap: break-word;
}

.expense-items-table--editable .col-amount .inline-input {
    text-align: right;
}

.expense-items-table--editable th.col-date,
.expense-items-table--editable td.col-date {
    padding-left: 0.4rem;
    padding-right: 0.25rem;
}

.expense-items-table--editable input[type="date"].inline-input {
    min-width: 0;
    width: 100%;
    padding: 0.35rem 0;
    font-size: 0.7rem;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.02em;
}

.expense-items-table--editable input[type="date"].inline-input::-webkit-datetime-edit {
    padding: 0;
    letter-spacing: -0.02em;
}

.expense-items-table--editable input[type="date"].inline-input::-webkit-datetime-edit-fields-wrapper {
    padding: 0;
}

.expense-items-table--editable input[type="date"].inline-input::-webkit-datetime-edit-day-field,
.expense-items-table--editable input[type="date"].inline-input::-webkit-datetime-edit-month-field,
.expense-items-table--editable input[type="date"].inline-input::-webkit-datetime-edit-year-field {
    padding: 0 0.04em;
}

.expense-items-table--editable input[type="date"].inline-input::-webkit-calendar-picker-indicator {
    width: 0.85rem;
    height: 0.85rem;
    margin: 0;
    padding: 0;
    opacity: 0.75;
}

.expense-items-table--editable select.inline-input {
    padding-right: 1.35rem;
    background-position: right 0.3rem center;
    background-size: 0.75rem;
    font-size: 0.68rem;
}

.expense-items-table td.col-date > span:not(.print-only),
.expense-items-table td.col-desc > span:not(.print-only),
.expense-items-table td.col-cat > span:not(.print-only),
.expense-items-table td.col-loc > span:not(.print-only),
.expense-items-table td.col-amount > span:not(.print-only) {
    display: block;
    padding: 0.35rem 0.4rem;
    line-height: 1.5;
    box-sizing: border-box;
}

.expense-items-table td.col-amount > span:not(.print-only) {
    text-align: right;
}

.expense-items-table--editable td.col-rcpt,
.expense-items-table--editable td.col-actions {
    padding-top: calc(0.6rem + 0.15rem);
}

.monthly-recap-document {
    display: none;
}
.monthly-recap-note-document {
    display: none;
}
.recap-categories {
    margin-top: 1rem;
    font-size: 0.85rem;
}
.recap-categories h3 {
    margin: 0 0 0.5rem;
    font-size: 0.9rem;
}
.recap-categories ul {
    margin: 0;
    padding-left: 1.25rem;
}
.recap-total-row td {
    border-top: 2px solid var(--border-color);
    padding-top: 0.75rem;
}
.recap-categories--print {
    margin-top: 1.5rem;
    font-size: 0.8rem;
}

.declaration-section {
    border-top: 1px solid var(--border-color);
    padding-top: 1rem;
    font-size: 0.8rem;
    line-height: 1.5;
}
.declaration-text { text-align: justify; margin-bottom: 2rem; }
.signature-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 2.5rem;
    margin-top: 1.5rem;
}
.signature-block { flex: 1; min-width: 0; max-width: 48%; }
.signature-block--client { margin-left: auto; text-align: right; }
.signature-block--client .signature-line { margin-left: auto; }
.signature-party { margin: 0 0 0.25rem; font-weight: 600; }
.signature-line {
    margin-top: 2.5rem;
    border-top: 1px solid var(--text-main);
    width: 200px;
    max-width: 100%;
    padding-top: 0.25rem;
    font-size: 0.75rem;
}

.receipt-ok { color: #2e7d32; font-weight: 700; }
.receipt-upload-btn { cursor: pointer; font-size: 0.7rem; padding: 0.2rem 0.4rem; display: inline-flex; align-items: center; justify-content: center; }
.receipt-camera-btn { font-size: 0.75rem; padding: 0.2rem 0.35rem; vertical-align: middle; }
.receipt-files-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.receipt-file-row {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    padding: 0.5rem;
    background: var(--bg-gray);
    border-radius: 6px;
    border: 1px solid var(--border-color);
}
.receipt-file-name {
    font-size: 0.85rem;
    font-weight: 500;
    word-break: break-all;
}
.receipt-file-item {
    font-size: 0.75rem;
    color: var(--text-muted, #666);
}
.receipt-file-badge {
    font-size: 0.7rem;
    color: #e65100;
    font-weight: 500;
}
.receipt-file-actions,
.receipt-inline-actions {
    display: flex;
    gap: 0.35rem;
    flex-wrap: wrap;
    align-items: center;
}

.receipt-inline-actions {
    display: inline-flex;
    justify-content: center;
}
.actions-cell {
    white-space: nowrap;
    width: 1%;
}

.upload-actions {
    display: grid;
    gap: 0.5rem;
    margin-top: 0.75rem;
}
.upload-actions .btn {
    min-height: 2.75rem;
    font-size: 0.9rem;
}
.upload-actions--mobile {
    display: none;
    grid-template-columns: 1fr 1fr;
}
.upload-actions--desktop {
    grid-template-columns: 1fr;
}
.upload-hint--mobile {
    display: none;
}

.expense-items-cards { display: none; }
.invoice-items-cards { display: none; }
.invoice-item-card__total {
    margin: 0;
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-main);
}

.expense-item-card {
    background: var(--bg-gray);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1rem;
}
.expense-item-card__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}
.expense-item-card__n {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--accent-dark);
}
.expense-item-card__receipt {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
    margin-top: 0.5rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border-color);
}

/* Note spese — layout responsive */
.page-note-spese {
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.page-note-spese .app-header {
    justify-content: flex-start;
    align-items: flex-end;
    gap: 1rem;
    flex-wrap: nowrap;
    min-width: 0;
}

.page-note-spese .header-title {
    flex: 0 1 auto;
    min-width: 0;
}

.page-note-spese .header-title h1 {
    display: inline;
}

.page-note-spese .header-title .status-badge {
    display: inline;
    vertical-align: middle;
}

.page-note-spese .header-client-select {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-width: 0;
    padding: 0 0.5rem;
}

@media (min-width: 1201px) {
    .page-note-spese .app-header {
        display: grid;
        grid-template-columns: auto 1fr auto;
        align-items: end;
        gap: 1rem;
    }

    .page-note-spese .header-title {
        justify-self: start;
    }

    .page-note-spese .header-client-select {
        justify-self: center;
        width: 100%;
        max-width: 21rem;
        padding: 0;
    }

    .page-note-spese .header-actions {
        margin-left: 0;
        justify-self: end;
    }

    .page-fatturazione .app-header {
        display: grid;
        grid-template-columns: 1fr auto;
        align-items: end;
        gap: 1rem;
    }

    .page-fatturazione .header-title {
        justify-self: start;
        min-width: 0;
    }

    .page-fatturazione .header-actions {
        margin-left: 0;
        justify-self: end;
    }
}

.page-note-spese .header-client-select__label {
    display: flex;
    align-items: center;
    height: 2.375rem;
    margin: 0;
    font-size: 0.9rem;
    font-weight: 500;
    line-height: 1.2;
    color: var(--text-color, #1f2937);
    white-space: nowrap;
}

.page-fatturazione .app-header {
    justify-content: flex-start;
    align-items: flex-end;
    gap: 1rem;
    flex-wrap: nowrap;
    min-width: 0;
}

.page-fatturazione .header-title {
    flex: 0 1 auto;
    min-width: 0;
}

.page-note-spese .header-actions,
.page-fatturazione .header-actions {
    flex: 0 0 auto;
    align-items: center;
    justify-content: flex-end;
    margin-left: auto;
}

.page-note-spese .header-toolbar,
.page-fatturazione .header-toolbar {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.page-note-spese .header-toolbar__btn,
.page-fatturazione .header-toolbar__btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 2.125rem;
    padding: 0 0.875rem;
    border: 1px solid transparent;
    border-radius: 7px;
    background: #fff;
    color: var(--text-main);
    font-family: inherit;
    font-size: 0.8125rem;
    font-weight: 500;
    line-height: 1;
    white-space: nowrap;
    cursor: pointer;
    box-sizing: border-box;
    transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.page-note-spese .header-toolbar__btn--ghost,
.page-fatturazione .header-toolbar__btn--ghost {
    border-color: var(--accent-color);
    color: var(--accent-color);
}

.page-note-spese .header-toolbar__btn--ghost:hover:not(:disabled),
.page-fatturazione .header-toolbar__btn--ghost:hover:not(:disabled) {
    background: var(--accent-light);
    color: var(--accent-dark);
}

.page-note-spese .header-toolbar__btn--primary,
.page-fatturazione .header-toolbar__btn--primary {
    background: var(--accent-color);
    color: #fff;
    padding: 0 1rem;
    border-color: var(--accent-color);
}

.page-note-spese .header-toolbar__btn--primary:hover:not(:disabled),
.page-fatturazione .header-toolbar__btn--primary:hover:not(:disabled) {
    background: var(--accent-dark);
    border-color: var(--accent-dark);
}

.page-note-spese .header-toolbar__btn--icon,
.page-fatturazione .header-toolbar__btn--icon {
    width: 2.125rem;
    padding: 0;
    flex-shrink: 0;
    border-color: var(--border-color);
    color: var(--text-muted);
}

.page-note-spese .header-toolbar__btn--icon:hover:not(:disabled),
.page-note-spese .header-toolbar__btn--icon[aria-expanded="true"],
.page-fatturazione .header-toolbar__btn--icon:hover:not(:disabled),
.page-fatturazione .header-toolbar__btn--icon[aria-expanded="true"] {
    background: var(--accent-light);
    border-color: var(--accent-color);
    color: var(--accent-dark);
}

.page-note-spese .header-toolbar__btn:disabled,
.page-fatturazione .header-toolbar__btn:disabled {
    opacity: 0.42;
    cursor: not-allowed;
}

.page-note-spese .header-toolbar__icon,
.page-fatturazione .header-toolbar__icon {
    display: block;
    flex-shrink: 0;
}

.page-note-spese .header-toolbar__more,
.page-fatturazione .header-toolbar__more {
    position: relative;
    display: inline-flex;
    flex: 0 0 auto;
    width: 2.125rem;
}

.page-note-spese .header-toolbar__menu,
.page-fatturazione .header-toolbar__menu {
    position: absolute;
    top: calc(100% + 0.4rem);
    right: 0;
    z-index: 200;
    min-width: 11.5rem;
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    box-shadow: 0 10px 28px rgba(0, 77, 82, 0.12), 0 2px 8px rgba(15, 23, 42, 0.06);
    padding: 0.35rem;
}

.page-note-spese .header-toolbar__menu-item,
.page-fatturazione .header-toolbar__menu-item {
    display: block;
    width: 100%;
    padding: 0.5rem 0.65rem;
    text-align: left;
    background: none;
    border: none;
    border-radius: 6px;
    font-family: inherit;
    font-size: 0.8125rem;
    font-weight: 500;
    line-height: 1.3;
    cursor: pointer;
    color: var(--text-main);
    white-space: nowrap;
}

.page-note-spese .header-toolbar__menu-item:hover:not(:disabled),
.page-fatturazione .header-toolbar__menu-item:hover:not(:disabled) {
    background: var(--mint-bg);
    color: var(--accent-dark);
}

.page-note-spese .header-toolbar__menu-item:disabled,
.page-fatturazione .header-toolbar__menu-item:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.page-note-spese .header-toolbar__menu-item--success,
.page-fatturazione .header-toolbar__menu-item--success {
    color: #2e7d32;
}

.page-note-spese .header-toolbar__menu-item--success:hover:not(:disabled),
.page-fatturazione .header-toolbar__menu-item--success:hover:not(:disabled) {
    background: #edf7ee;
    color: #1b5e20;
}

.page-note-spese .header-toolbar__menu-divider,
.page-fatturazione .header-toolbar__menu-divider {
    height: 1px;
    margin: 0.25rem 0.35rem;
    background: var(--border-color);
}

.page-note-spese .header-client-select__input {
    padding: 0 2.25rem 0 0.75rem;
    border-radius: 6px;
    border: 1px solid var(--border-color, #d1d5db);
    background-color: #fff;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    width: 100%;
    min-width: 0;
    max-width: 21rem;
    height: 2.375rem;
    margin: 0;
    box-sizing: border-box;
    color: var(--text-color, #1f2937);
}

.page-note-spese .header-client-select__input:focus {
    outline: 2px solid var(--accent-color);
    outline-offset: 1px;
}

@media (min-width: 1201px) {
    .page-note-spese .header-client-select__input {
        width: 100%;
        min-width: 16.5rem;
        max-width: 21rem;
    }
}

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

.page-note-spese .expense-editor-layout {
    align-items: start;
}

.page-note-spese .expense-sidebar {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.page-note-spese .panel--save {
    padding: 1rem 1.5rem;
}

@media (min-width: 1521px) {
    .page-note-spese .expense-editor-layout {
        display: grid;
        grid-template-columns: 320px minmax(0, 1fr) 320px;
        gap: 1.5rem;
        max-width: 1680px;
    }

    .page-note-spese .expense-editor-layout .editor-sidebar {
        width: auto;
    }

    .page-note-spese .document-preview-wrapper {
        min-width: 0;
    }
}

@media (min-width: 1201px) and (max-width: 1520px) {
    .page-note-spese .expense-editor-layout {
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        position: relative;
        max-width: 1680px;
        gap: 1rem;
        min-height: 0;
    }

    .page-note-spese .expense-sidebar--primary,
    .page-note-spese .expense-sidebar--secondary,
    .page-note-spese .locked-sidebar {
        display: contents;
    }

    .page-note-spese .expense-editor-layout .expense-sidebar-messages,
    .page-note-spese .expense-editor-layout .expense-panel--trip,
    .page-note-spese .expense-editor-layout .expense-panel--locked,
    .page-note-spese .expense-editor-layout .expense-panel--ai,
    .page-note-spese .expense-editor-layout .expense-panel--files,
    .page-note-spese .expense-editor-layout .expense-panel--movement {
        width: 320px;
        max-width: 100%;
        box-sizing: border-box;
    }

    .page-note-spese .expense-editor-layout .expense-sidebar-messages {
        order: 0;
    }

    .page-note-spese .expense-editor-layout .expense-panel--trip,
    .page-note-spese .expense-editor-layout .expense-panel--locked {
        order: 1;
    }

    .page-note-spese .expense-editor-layout .expense-panel--ai {
        order: 2;
    }

    .page-note-spese .expense-editor-layout .expense-panel--files {
        order: 3;
    }

    .page-note-spese .expense-editor-layout .expense-panel--movement {
        order: 4;
    }

    .page-note-spese .expense-editor-layout .document-preview-wrapper {
        position: absolute;
        top: 0;
        left: calc(320px + 1.5rem);
        right: 0;
        width: auto;
        min-width: 0;
        margin: 0;
    }

    .page-note-spese .editor-sidebar,
    .page-note-spese .locked-sidebar {
        width: auto;
        max-width: none;
    }
}

.movement-section {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

.movement-section__title {
    margin: 0 0 0.75rem;
    font-size: 0.95rem;
    font-weight: 600;
}

.movement-stop {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
}

.movement-segments-list {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.movement-segment__drag-handle {
    flex: 0 0 auto;
    align-self: center;
    margin-bottom: 0.35rem;
    padding: 0.15rem 0.35rem;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: var(--text-muted, #64748b);
    font-size: 0.85rem;
    line-height: 1;
    cursor: grab;
    touch-action: none;
}

.movement-segment__drag-handle:active {
    cursor: grabbing;
}

.movement-segment--ghost {
    opacity: 0.45;
}

.movement-segment--chosen {
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.25);
    border-radius: 6px;
}

.movement-day-break .movement-segment__drag-handle {
    margin-bottom: 0;
}

.movement-stop__field {
    flex: 1;
    min-width: 0;
}

.movement-stop__btn {
    margin-bottom: 0.35rem;
    font-size: 1.25rem;
    line-height: 1;
}

.movement-add-stop {
    margin-bottom: 0;
}

.movement-stop-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.movement-day-break {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin: 0.35rem 0 0.75rem;
    padding: 0.35rem 0.65rem;
    border-left: 3px solid var(--primary-color, #2563eb);
    background: rgba(37, 99, 235, 0.06);
    border-radius: 0 4px 4px 0;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted, #64748b);
    cursor: grab;
    touch-action: none;
}

.movement-day-break:active {
    cursor: grabbing;
}

.movement-day-break-hint {
    margin: -0.35rem 0 0.75rem;
}

.movement-day-break__btn {
    font-size: 1.1rem;
    line-height: 1;
}

@media (max-width: 768px) {
    .doc-history-modal .history-table-wrap--desktop,
    .expense-history-modal .history-table-wrap--desktop,
    .monthly-recap-modal .history-table-wrap--desktop {
        display: none;
    }

    .doc-history-modal .history-cards,
    .expense-history-modal .history-cards,
    .monthly-recap-modal .history-cards {
        display: flex;
        margin-top: 0.75rem;
    }

    .history-table-wrap:not(.history-table-wrap--desktop) {
        margin: 0 -0.5rem;
    }
    .history-table:not(.history-table--desktop) {
        min-width: 640px;
        font-size: 0.8rem;
    }
    .history-actions .btn-small {
        padding: 0.25rem 0.45rem;
        font-size: 0.75rem;
    }
}

@media (max-width: 1200px) {
    .page-note-spese .main-container {
        flex-direction: column;
        padding: 1rem;
        gap: 1.25rem;
    }
    .page-note-spese .expense-editor-layout {
        align-items: stretch;
    }
    .page-note-spese .expense-sidebar--primary,
    .page-note-spese .expense-sidebar--secondary,
    .page-note-spese .locked-sidebar {
        display: contents;
    }
    .page-note-spese .expense-editor-layout .expense-sidebar-messages {
        order: 0;
    }
    .page-note-spese .expense-editor-layout .expense-panel--trip,
    .page-note-spese .expense-editor-layout .expense-panel--locked {
        order: 1;
    }
    .page-note-spese .expense-editor-layout .document-preview-wrapper {
        order: 2;
    }
    .page-note-spese .expense-editor-layout .expense-panel--movement {
        order: 3;
    }
    .page-note-spese .expense-editor-layout .expense-panel--ai {
        order: 4;
    }
    .page-note-spese .expense-editor-layout .expense-panel--files {
        order: 5;
    }
    .page-note-spese .editor-sidebar,
    .page-note-spese .locked-sidebar {
        width: 100%;
        max-width: none;
    }
    .page-note-spese .document-preview-wrapper {
        width: 100%;
        align-self: stretch;
        justify-content: flex-start;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .page-note-spese .a4-document {
        width: 100%;
        max-width: 100%;
        min-width: 0;
        min-height: auto;
        padding: 1.25rem;
    }
    .page-note-spese .addresses-section {
        flex-direction: column;
        gap: 1rem;
    }

    .page-fatturazione .main-container {
        flex-direction: column;
        padding: 1rem;
        gap: 1.25rem;
    }

    .page-fatturazione .editor-sidebar {
        width: 100%;
        max-width: none;
    }

    .page-fatturazione .document-preview-wrapper {
        justify-content: stretch;
    }

    .page-fatturazione .a4-document {
        width: 100%;
        max-width: 100%;
        min-width: 0;
        min-height: auto;
        padding: 1rem;
        box-shadow: none;
        border: 1px solid var(--border-color);
        border-radius: 8px;
        background: #fff;
    }

    .page-fatturazione .doc-spacer {
        display: none;
    }

    .page-fatturazione .addresses-section {
        flex-direction: column;
        gap: 0.75rem;
    }

    .page-fatturazione .issuer-box,
    .page-fatturazione .client-box {
        background: var(--bg-gray);
        border: 1px solid var(--border-color);
        border-radius: 8px;
        padding: 1rem;
    }

    .page-fatturazione .totals-section {
        justify-content: stretch;
        margin-bottom: 1rem;
    }

    .page-fatturazione .totals-box {
        width: 100%;
    }

    .page-fatturazione .form-row {
        flex-direction: column;
        gap: 0;
    }

    .page-fatturazione .doc-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
        margin-bottom: 1rem;
        padding-bottom: 0.75rem;
    }

    .page-fatturazione .doc-meta-info {
        text-align: left;
        width: 100%;
    }

    .page-fatturazione .meta-table {
        margin-left: 0;
    }

    .page-fatturazione .items-section {
        overflow-x: visible;
        margin-left: 0;
        margin-right: 0;
        padding-left: 0;
        padding-right: 0;
    }

    .page-fatturazione .invoice-items-table--desktop {
        display: none;
    }

    .page-fatturazione .invoice-items-cards {
        display: flex;
        flex-direction: column;
        gap: 1rem;
    }

    .page-fatturazione .add-row-wrapper {
        margin-top: 0.5rem;
    }

    .page-fatturazione .notes-section {
        box-sizing: border-box;
        min-width: 0;
    }

    .page-fatturazione .notes-textarea {
        border: 1px solid var(--border-color);
        background: #fff;
        padding: 0.5rem;
        border-radius: 6px;
        min-height: 3rem;
    }

    .page-fatturazione .doc-footer {
        font-size: 0.65rem;
        color: var(--text-muted);
        margin-top: 0.5rem;
    }
}

@media (max-width: 1200px) {
    .page-note-spese .app-header,
    .page-fatturazione .app-header {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
    }
    .page-note-spese .header-client-select {
        flex: none;
        justify-content: flex-start;
        padding: 0;
        width: 100%;
    }
    .page-note-spese .header-client-select__input {
        flex: 1;
        width: auto;
        max-width: none;
        min-width: 0;
    }
    .page-note-spese .header-actions,
    .page-fatturazione .header-actions {
        margin-left: 0;
        width: 100%;
    }
    .page-note-spese .header-toolbar,
    .page-fatturazione .header-toolbar {
        display: flex;
        align-items: stretch;
        gap: 0.4rem;
        width: 100%;
    }
    .page-note-spese .header-toolbar__btn--ghost,
    .page-note-spese .header-toolbar__btn--primary,
    .page-fatturazione .header-toolbar__btn--ghost,
    .page-fatturazione .header-toolbar__btn--primary {
        flex: 1 1 0;
        min-width: 0;
        width: auto;
        height: 2.375rem;
    }
    .page-note-spese .header-toolbar__more,
    .page-fatturazione .header-toolbar__more {
        flex: 0 0 2.375rem;
        width: 2.375rem;
    }
    .page-note-spese .header-toolbar__btn--icon,
    .page-fatturazione .header-toolbar__btn--icon {
        width: 2.375rem;
        height: 2.375rem;
        padding: 0;
    }

    .page-fatturazione .app-header {
        padding: 0.75rem 1rem;
    }

    .page-fatturazione .header-title h1 {
        font-size: 1.2rem;
    }

    .page-fatturazione .header-toolbar__btn--ghost,
    .page-fatturazione .header-toolbar__btn--primary {
        padding: 0 0.5rem;
        font-size: 0.75rem;
    }

    .page-fatturazione .header-toolbar__btn--primary {
        white-space: normal;
        line-height: 1.1;
        min-height: 2.375rem;
        height: auto;
        padding: 0.35rem 0.4rem;
    }

    .page-fatturazione .header-toolbar__menu {
        right: 0;
        left: auto;
        min-width: min(12rem, calc(100vw - 2rem));
    }
}

@media (max-width: 768px) {
    .page-note-spese .header-title h1 {
        font-size: 1.2rem;
    }
    .page-note-spese .header-toolbar__btn--ghost,
    .page-note-spese .header-toolbar__btn--primary {
        padding: 0 0.5rem;
        font-size: 0.75rem;
    }
    .page-note-spese .header-toolbar__btn--primary {
        white-space: normal;
        line-height: 1.1;
        min-height: 2.375rem;
        height: auto;
        padding: 0.35rem 0.4rem;
    }
    .page-note-spese .header-toolbar__menu {
        right: 0;
        left: auto;
        min-width: min(12rem, calc(100vw - 2rem));
    }
    .page-note-spese .header-client-select__input {
        height: 2.75rem;
    }
    .page-note-spese .form-row {
        flex-direction: column;
        gap: 0;
    }
    .page-note-spese .drop-zone--desktop {
        display: none;
    }
    .page-note-spese .upload-actions--mobile {
        display: grid;
        grid-template-columns: 1fr;
    }
    .page-note-spese .upload-actions--desktop {
        display: none;
    }
    .page-note-spese .upload-hint--mobile {
        display: block;
    }
    .page-note-spese .upload-hint--desktop {
        display: none;
    }
    .page-note-spese .expense-items-table--desktop {
        display: none;
    }
    .page-note-spese .expense-items-cards {
        display: flex;
        flex-direction: column;
        gap: 1rem;
    }
    .page-note-spese .add-row-wrapper {
        margin-top: 0.5rem;
    }
    .page-note-spese .modal-content {
        width: 100%;
        max-width: 100%;
        max-height: none;
        overflow-y: visible;
        margin: 0;
        padding: 1.25rem;
    }
    .page-note-spese .modal-content.large,
    .page-note-spese .modal-content.expense-history-modal {
        width: calc(100% - 1rem);
    }
    .page-note-spese .history-table-wrap:not(.history-table-wrap--desktop) {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -0.5rem;
    }
    .page-note-spese .history-table:not(.history-table--desktop) {
        min-width: 720px;
        font-size: 0.8rem;
    }
    .page-note-spese .doc-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }
    .page-note-spese .doc-header--expense {
        display: flex;
        flex-direction: column;
        align-items: flex-start;
    }
    .page-note-spese .doc-header--expense .expense-header-line {
        width: 100%;
        justify-content: flex-start;
        flex-wrap: wrap;
    }
    .page-note-spese .doc-header--expense .expense-header-line--end {
        padding-left: 4.5rem;
    }
    .page-note-spese .totals-box {
        width: 100%;
    }
}

@media (min-width: 769px) {
    .page-note-spese .expense-items-cards {
        display: none !important;
    }

    .page-note-spese .items-section {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .page-note-spese .expense-items-table--desktop {
        min-width: 40rem;
    }
}

@media (min-width: 1201px) {
    .page-fatturazione .invoice-items-cards {
        display: none !important;
    }

    .page-fatturazione .items-section {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .page-fatturazione .invoice-items-table--desktop {
        min-width: 36rem;
    }
}

@media (max-width: 480px) {
    .page-note-spese .main-container {
        padding: 0.75rem;
    }
    .page-note-spese .panel {
        padding: 1rem;
    }
    .page-note-spese .status-badge {
        display: inline-block;
        margin-left: 0;
        margin-top: 0.25rem;
    }
}

@media print {
    .page-note-spese .expense-items-cards {
        display: none !important;
    }
    .page-note-spese .expense-items-table--desktop {
        display: table !important;
    }
    .page-fatturazione .invoice-items-cards {
        display: none !important;
    }
    .page-fatturazione .invoice-items-table--desktop {
        display: table !important;
    }
    .doc-history-modal .history-cards,
    .expense-history-modal .history-cards,
    .monthly-recap-modal .history-cards {
        display: none !important;
    }
    .doc-history-modal .history-table-wrap--desktop,
    .expense-history-modal .history-table-wrap--desktop,
    .monthly-recap-modal .history-table-wrap--desktop {
        display: block !important;
    }
    .expense-items-table input,
    .expense-items-table select {
        display: none !important;
    }
    .expense-items-table .print-cell {
        display: table-cell !important;
    }
    body.printing-monthly-recap #printable-area {
        display: none !important;
    }
    body.printing-monthly-recap .monthly-recap-document,
    body.printing-monthly-recap .monthly-recap-note-document {
        display: block !important;
    }

    body.printing-monthly-recap .monthly-recap-note-document {
        page-break-before: always;
        break-before: page;
    }

    .monthly-recap-document .addresses-section,
    .monthly-recap-document .totals-section,
    .monthly-recap-document .recap-categories--print,
    .monthly-recap-document .declaration-section {
        page-break-inside: avoid;
        break-inside: avoid;
    }
    .monthly-recap-note-document .totals-section,
    .monthly-recap-note-document .expense-notes-section {
        page-break-inside: avoid;
        break-inside: avoid;
    }
    .monthly-recap-document .items-table thead {
        display: table-header-group;
    }
    .monthly-recap-document .items-table tr {
        page-break-inside: avoid;
        break-inside: avoid;
    }
}

/* Auth */
.auth-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f4f6f8;
    padding: 1rem;
}

.auth-card {
    width: 100%;
    max-width: 400px;
    background: #fff;
    border-radius: 12px;
    padding: 2rem;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
}

.auth-card h1 {
    margin: 0 0 0.25rem;
    font-size: 1.5rem;
}

.auth-subtitle {
    color: #666;
    margin: 0 0 1.5rem;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.auth-label {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    font-size: 0.875rem;
    font-weight: 500;
}

.auth-label input {
    padding: 0.6rem 0.75rem;
    border: 1px solid #d0d5dd;
    border-radius: 8px;
    font-size: 1rem;
}

.auth-submit {
    margin-top: 0.5rem;
    width: 100%;
}

.auth-error {
    background: #fdecea;
    color: #b42318;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    font-size: 0.875rem;
}

.auth-success {
    color: #027a48;
    margin: 1rem 0 0;
}

.app-user-bar {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: nowrap;
    gap: 0.75rem;
    width: 100%;
    padding: 0.625rem 1.5rem;
    background: #fff;
    border-bottom: 1px solid var(--border-color);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    font-size: 0.875rem;
    position: sticky;
    top: 0;
    z-index: 200;
    flex-shrink: 0;
    box-sizing: border-box;
}

.app-user-bar__name {
    color: #555;
    font-weight: 400;
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-right: auto;
}

.app-user-bar__nav {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.65rem;
}

.app-user-bar__sep {
    display: inline-block;
    width: 1px;
    height: 1em;
    background: #9eacb8;
    flex-shrink: 0;
    user-select: none;
}

.app-user-bar__link {
    background: none;
    border: none;
    padding: 0;
    margin: 0;
    -webkit-appearance: none;
    appearance: none;
    font-family: inherit;
    font-size: inherit;
    font-weight: 500;
    line-height: inherit;
    letter-spacing: inherit;
    color: var(--accent-color);
    cursor: pointer;
    text-decoration: underline;
    text-decoration-color: rgba(0, 109, 119, 0.35);
    text-underline-offset: 0.15em;
    white-space: nowrap;
    transition: color 0.15s, text-decoration-color 0.15s;
}

.app-user-bar__link:hover {
    color: var(--accent-dark);
    text-decoration-color: var(--accent-dark);
}

.app-user-bar__logout {
    margin: 0;
}

.app-user-bar__menu {
    display: none;
    position: relative;
    flex-shrink: 0;
}

.app-user-bar__menu-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    height: 1.5rem;
    padding: 0;
    margin: 0;
    border: none;
    background: none;
    color: #666;
    cursor: pointer;
    transition: color 0.15s;
}

.app-user-bar__menu-toggle:hover {
    color: var(--accent-color);
}

.app-user-bar__menu-toggle[aria-expanded="true"] {
    color: var(--accent-color);
}

.app-user-bar__menu-icon {
    display: block;
}

.app-user-bar__dropdown {
    position: absolute;
    top: calc(100% + 0.35rem);
    right: 0;
    z-index: 210;
    min-width: 11rem;
    padding: 0.35rem 0;
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
}

.app-user-bar__dropdown-item {
    display: block;
    width: 100%;
    padding: 0.55rem 1rem;
    border: none;
    background: none;
    font-family: inherit;
    font-size: inherit;
    font-weight: 500;
    line-height: 1.3;
    text-align: left;
    color: #333;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s, color 0.15s;
}

.app-user-bar__dropdown-item:hover {
    background: #f4f6f8;
    color: var(--accent-color);
}

.change-password-body {
    min-height: 100vh;
    background: var(--bg-gray, #f4f6f8);
}

.change-password-card {
    margin: 2rem auto;
}

.change-password-form-actions {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-top: 0.5rem;
}

.change-password-form-actions .auth-submit {
    margin-top: 0;
}

.change-password-cancel {
    text-align: center;
}

.change-password-actions {
    margin: 1.25rem 0 0;
}

.change-password-logout {
    margin: 1.5rem 0 0;
    text-align: center;
}

.onboarding-card {
    margin: 2rem auto;
    max-width: 36rem;
}

.onboarding-form-actions {
    margin-top: 0.5rem;
}

/* Tier 1 modals — header / scrollable body / fixed footer */
.modal-shell {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 0;
}

.modal-shell__header {
    flex-shrink: 0;
    padding: 2rem 2rem 0;
}

.modal-shell__header h2 {
    margin: 0 0 1rem;
}

.modal-shell__body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding: 0.75rem 2rem;
}

.modal-shell > .modal-shell__footer {
    flex-shrink: 0;
    padding: 1rem 2rem 2rem;
    margin-top: 0;
    border-top: 1px solid var(--border-color);
}

.modal-shell > .modal-shell__footer.modal-actions {
    margin-top: 0;
}

.modal-shell--nested {
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.modal-shell--nested > .modal-shell__header {
    padding: 0 0 0.75rem;
}

.modal-shell--nested > .modal-shell__header h3 {
    margin: 0;
}

.modal-shell--nested > .modal-shell__body {
    padding: 0;
}

.modal-shell--nested > .modal-shell__footer {
    padding: 0.75rem 0 0;
    margin-top: 0;
    border-top: none;
}

.account-settings-overlay .modal-content.account-settings-modal {
    max-width: 32rem;
    max-height: min(90vh, 52rem);
}

.account-settings-section + .account-settings-section {
    margin-top: 1.75rem;
    padding-top: 1.75rem;
    border-top: 1px solid var(--border-color);
}

.account-settings-section h3 {
    margin: 0 0 1rem;
    font-size: 1rem;
    font-weight: 600;
}

.account-settings-hint {
    margin: -0.5rem 0 1rem;
    font-size: 0.875rem;
    color: var(--text-muted, #667085);
}

.account-settings-section-actions {
    margin-top: 0.25rem;
}

#account-settings-flash,
#account-settings-success,
#clients-flash,
#clients-success {
    margin-bottom: 0;
    margin-top: 0.75rem;
}

.account-settings-modal textarea {
    min-height: 6.5rem;
    line-height: 1.5;
    resize: vertical;
}

.clients-overlay .modal-content.clients-modal {
    max-width: 52rem;
    max-height: min(90vh, 44rem);
}

.clients-modal-layout {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    align-items: stretch;
}

.modal-tier-1 .modal-shell-header__top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    width: 100%;
    margin-bottom: 0.75rem;
}

.modal-tier-1 .modal-shell-header__top h2 {
    margin: 0;
    line-height: 1.25;
    flex: 1 1 auto;
    min-width: 0;
}

.modal-tier-1 .modal-shell-header__actions {
    display: flex;
    align-items: center;
    gap: 0;
    flex-shrink: 0;
    margin: -0.125rem -0.125rem -0.125rem 0;
}

.modal-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.875rem;
    height: 1.875rem;
    padding: 0;
    border: none;
    border-radius: 4px;
    background: none;
    color: var(--text-muted);
    cursor: pointer;
    flex-shrink: 0;
    transition: color 0.15s, background-color 0.15s;
}

.modal-icon-btn svg {
    width: 1.125rem;
    height: 1.125rem;
}

.modal-icon-btn:hover {
    color: var(--accent-dark);
    background: var(--accent-light);
}

.modal-icon-btn--save,
.modal-icon-btn--add {
    color: var(--accent-color);
}

.modal-icon-btn--danger {
    color: #b42318;
}

.modal-icon-btn--danger:hover {
    color: #912018;
    background: #fff5f5;
}

.clients-picker-toolbar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.clients-import-toolbar {
    display: flex;
    align-items: stretch;
}

.clients-import-toolbar.is-dragover .clients-ai-import-btn {
    color: var(--accent-dark);
    background: var(--accent-light);
    border-color: var(--accent-color);
}

.clients-ai-import-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: 100%;
    min-height: 2.5rem;
    padding: 0.5rem 0.75rem;
    border: 1px dashed var(--border-color, #c9cdd3);
    border-radius: 6px;
    background: var(--surface-muted, #f7f8fa);
    color: var(--text-muted);
    font-size: 0.9375rem;
    cursor: pointer;
    transition: color 0.15s, background-color 0.15s, border-color 0.15s;
}

.clients-ai-import-btn svg {
    width: 1.125rem;
    height: 1.125rem;
    flex-shrink: 0;
}

.clients-ai-import-btn__text {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.125rem;
    line-height: 1.25;
    text-align: left;
}

.clients-ai-import-btn__text strong {
    font-weight: 600;
}

.clients-ai-import-btn__text small {
    font-size: 0.8125rem;
    font-weight: 400;
    opacity: 0.85;
}

.clients-ai-import-btn:hover:not(:disabled) {
    color: var(--accent-dark);
    background: var(--accent-light);
    border-color: var(--accent-color);
}

.clients-ai-import-btn:disabled {
    opacity: 0.65;
    cursor: wait;
}

.clients-import-hint {
    margin: -0.25rem 0 0;
}

.clients-select {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 2.5rem;
    font-size: 1rem;
    margin: 0;
}

.clients-form .form-group:last-child {
    margin-bottom: 0;
}

@media (max-width: 768px) {
    .modal-tier-1 .modal-shell-header__top {
        margin-bottom: 0.5rem;
    }

    .modal-tier-1 .modal-icon-btn {
        width: 2.5rem;
        height: 2.5rem;
    }

    .clients-select {
        min-height: 2.75rem;
    }
}

.field-hint {
    margin: 0.35rem 0 0;
    font-size: 0.8rem;
    color: var(--text-muted, #667085);
    line-height: 1.4;
}

/* Admin */
.admin-body {
    min-height: 100vh;
    background: var(--bg-gray);
}

.admin-badge {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--accent-dark);
    background: var(--accent-light);
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
}

.admin-page {
    max-width: 1100px;
    margin: 0 auto;
    padding: 2rem 1.5rem 3rem;
}

.admin-header h1 {
    margin: 0 0 0.35rem;
    font-size: 1.75rem;
    color: var(--accent-dark);
}

.admin-subtitle {
    margin: 0 0 2rem;
    color: var(--text-muted);
}

.admin-section {
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 1.25rem 1.5rem;
    margin-bottom: 1.5rem;
}

.admin-section h2 {
    margin: 0 0 1rem;
    font-size: 1.1rem;
    color: var(--text-main);
}

.admin-section--accounts {
    padding: 0;
    overflow: hidden;
}

.admin-section--accounts > h2 {
    padding: 1.25rem 1.5rem 0;
}

.admin-table-wrap {
    overflow-x: auto;
    margin-top: 1rem;
    -webkit-overflow-scrolling: touch;
}

.admin-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.875rem;
}

.admin-table th,
.admin-table td {
    text-align: left;
    padding: 0.875rem 1rem;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
}

.admin-table th {
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    background: var(--mint-bg);
    border-bottom-color: var(--border-color);
    white-space: nowrap;
}

.admin-table th:first-child {
    padding-left: 1.5rem;
}

.admin-table td:first-child {
    padding-left: 1.5rem;
}

.admin-table th:last-child,
.admin-table td:last-child {
    padding-right: 1.5rem;
}

.admin-table tbody tr {
    transition: background-color 0.15s ease;
}

.admin-table tbody tr:hover {
    background: var(--mint-bg);
}

.admin-table tbody tr:last-child td {
    border-bottom: none;
}

.admin-account-user {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    white-space: nowrap;
}

.admin-user-avatar {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    background: var(--accent-light);
    color: var(--accent-dark);
    font-size: 0.8rem;
    font-weight: 600;
}

.admin-username {
    font-size: 0.85em;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    color: var(--text-main);
    background: none;
    padding: 0;
}

.admin-account-cell {
    min-width: 7rem;
}

.admin-cell-row {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    min-width: 0;
}

.admin-cell-value {
    min-width: 0;
    color: var(--text-main);
    line-height: 1.4;
}

.admin-icon-btn {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    height: 1.5rem;
    padding: 0;
    border: none;
    border-radius: 4px;
    background: none;
    color: var(--text-muted);
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s ease, color 0.15s ease, background-color 0.15s ease;
}

.admin-table tbody tr:hover .admin-icon-btn,
.admin-icon-btn:focus-visible {
    opacity: 1;
}

.admin-icon-btn:hover {
    color: var(--accent-color);
    background: var(--accent-light);
}

.admin-icon-btn:focus-visible {
    opacity: 1;
    outline: 2px solid var(--accent-color);
    outline-offset: 1px;
}

.admin-icon {
    display: block;
}

@media (hover: none) {
    .admin-icon-btn {
        opacity: 1;
    }
}

.admin-tag {
    display: inline-block;
    font-size: 0.72rem;
    font-weight: 600;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    letter-spacing: 0.01em;
    white-space: nowrap;
}

.admin-tag--ok {
    color: #1b5e20;
    background: #e8f5e9;
}

.admin-tag--warn {
    color: #bf360c;
    background: #fff3e0;
}

.admin-tag--muted {
    color: #616161;
    background: #eeeeee;
}

.admin-tenant-status {
    display: flex;
    gap: 0.75rem;
}

.admin-tenant-item {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

.admin-tenant-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
}

.admin-dot {
    display: inline-block;
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    flex-shrink: 0;
}

.admin-dot--ok {
    background: #43a047;
    box-shadow: 0 0 0 2px #e8f5e9;
}

.admin-dot--warn {
    background: #ef6c00;
    box-shadow: 0 0 0 2px #fff3e0;
}

.admin-password-status {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.admin-password-status--warn {
    color: #bf360c;
}

.admin-date {
    font-size: 0.8rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.admin-password-modal {
    max-width: 420px;
}

.admin-password-modal h2 {
    margin: 0 0 0.5rem;
    font-size: 1.15rem;
}

.admin-password-hint {
    margin: 0 0 1rem;
    font-size: 0.85rem;
    color: var(--text-muted);
    line-height: 1.45;
}

.admin-password-modal .admin-form {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.admin-password-modal .admin-form > input:not([type="hidden"]) {
    padding: 0.6rem 0.75rem;
    border: 1px solid #d0d5dd;
    border-radius: 8px;
    font-size: 1rem;
    font-family: inherit;
}

.admin-muted {
    color: var(--text-muted);
    font-size: 0.85em;
}

.admin-empty {
    margin: 0;
    color: var(--text-muted);
}

.admin-note {
    background: #fff;
    border: 1px solid var(--border-color);
    border-left: 4px solid var(--accent-color);
    border-radius: 10px;
    padding: 1.25rem 1.5rem;
}

.admin-note h2 {
    margin: 0 0 0.75rem;
    font-size: 1rem;
}

.admin-note p {
    margin: 0 0 0.75rem;
    color: var(--text-main);
    line-height: 1.5;
}

.admin-note p:last-child {
    margin-bottom: 0;
}

.admin-cli {
    margin: 0 0 0.75rem;
    padding: 0.875rem 1rem;
    background: var(--bg-gray);
    border-radius: 6px;
    overflow-x: auto;
    font-size: 0.8rem;
    line-height: 1.6;
}

.admin-cli code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    white-space: pre;
}

.admin-flash {
    margin: 0 0 1.25rem;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    font-size: 0.875rem;
}

.admin-flash--ok {
    background: #e8f5e9;
    color: #1b5e20;
    border: 1px solid #a5d6a7;
}

.admin-flash--error {
    background: #ffebee;
    color: #c62828;
    border: 1px solid #ef9a9a;
}

.admin-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.admin-form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

.admin-form-options {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.admin-checkbox {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-main);
    cursor: pointer;
}

.admin-expense-defaults-cell {
    max-width: 12rem;
}

.admin-expense-defaults-summary {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* ==========================================================================
   Responsive — tablet e mobile (desktop invariato sopra i breakpoint)
   ========================================================================== */

/* Barra account */
@media (max-width: 768px) {
    .app-user-bar {
        padding: 0.5rem 1rem;
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
        gap: 0.5rem;
    }

    .app-user-bar__nav--desktop {
        display: none;
    }

    .app-user-bar__menu {
        display: block;
    }
}

/* Modali globali */
@media (max-width: 768px) {
    dialog.modal-overlay,
    dialog.modal-overlay[open] {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 100%;
        max-width: 100%;
        margin: 0;
        padding:
            max(0.75rem, env(safe-area-inset-top, 0px))
            max(0.75rem, env(safe-area-inset-right, 0px))
            max(0.75rem, env(safe-area-inset-bottom, 0px))
            max(0.75rem, env(safe-area-inset-left, 0px));
        transform: none;
        overflow-x: clip;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        touch-action: pan-y;
        overscroll-behavior: contain;
    }

    dialog.modal-overlay[open] {
        display: block;
    }

    dialog.modal-overlay.modal-tier-1[open] {
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    dialog.modal-overlay[open] > .modal-content {
        flex-shrink: 0;
        min-height: min-content;
        overflow-x: clip;
    }

    dialog.modal-overlay.modal-tier-1[open] > .modal-content.modal-shell {
        flex: 1 1 auto;
        min-height: 0;
        max-height: none;
        overflow: hidden;
    }

    .modal-content {
        width: 100%;
        max-width: 100%;
        min-width: 0;
        max-height: none;
        overflow-y: visible;
        overflow-x: clip;
        margin: 0;
        padding: 1.25rem;
    }

    .modal-content.large,
    .modal-content.doc-history-modal,
    .modal-content.stats-modal,
    .modal-content.stats-history-modal {
        width: 100%;
        max-width: 100%;
        max-height: none;
        overflow-y: visible;
        padding: 1.25rem 1rem 1.5rem;
    }

    .modal-content.modal-shell,
    .account-settings-overlay .modal-content.account-settings-modal,
    .clients-overlay .modal-content.clients-modal {
        width: 100%;
        max-width: 100%;
        max-height: none;
        overflow: hidden;
        padding: 0;
    }

    .modal-shell__header {
        padding: 1.25rem 1rem 0;
    }

    .modal-shell__header h2 {
        margin: 0 0 0.75rem;
    }

    .modal-shell__body {
        padding: 0.75rem 1rem;
    }

    .modal-shell > .modal-shell__footer {
        padding: 0.75rem 1rem max(1rem, env(safe-area-inset-bottom, 0px));
    }

    .modal-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .modal-actions .btn {
        width: 100%;
        min-height: 2.75rem;
    }

    .history-actions {
        flex-wrap: wrap;
    }

    .doc-history-tabs {
        flex-wrap: wrap;
    }

    .doc-history-modal .history-doc-card__actions {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.5rem;
    }

    .expense-history-modal .history-doc-card__actions {
        display: flex;
        flex-wrap: nowrap;
        gap: 0.35rem;
    }

    .doc-history-modal .history-doc-card__actions .btn {
        width: 100%;
        min-height: 2.5rem;
        justify-content: center;
    }

    .expense-history-modal .history-doc-card__actions .btn {
        flex: 1 1 0;
        min-width: 0;
        width: auto;
        min-height: 2.5rem;
        padding: 0.35rem 0.25rem;
        font-size: 0.75rem;
        justify-content: center;
    }

    .history-filters {
        flex-direction: column;
        align-items: stretch;
    }

    .history-filters input,
    .history-filters select,
    .history-filters__search {
        width: 100%;
        min-width: 0;
        flex: none;
    }

    .history-filters__date {
        flex-direction: column;
        align-items: stretch;
        width: 100%;
    }

    .account-settings-section-actions .btn {
        width: 100%;
        min-height: 2.75rem;
    }

    .modal-content .form-row {
        flex-direction: column;
        gap: 0;
    }
}

/* Header app (gestione contabile) */
@media (max-width: 768px) {
    .page-gestione-contabile .app-header {
        flex-direction: column;
        align-items: stretch;
        padding: 0.75rem 1rem;
        gap: 0.75rem;
    }

    .page-gestione-contabile .header-title h1 {
        font-size: 1.2rem;
    }
}

/* Fatturazione — mobile stretto (layout principale a 1200px) */
@media (max-width: 480px) {
    .page-fatturazione .main-container {
        padding: 0.75rem;
    }

    .page-fatturazione .panel {
        padding: 1rem;
    }

    .page-fatturazione .a4-document {
        padding: 1rem;
    }
}

/* Gestione contabile — tablet e mobile */
@media (max-width: 1024px) {
    .page-gestione-contabile .accounting-main {
        padding: 1rem 1rem 2rem;
    }

    .page-gestione-contabile .stats-panel {
        min-width: 0;
    }

    .page-gestione-contabile .accounting-shell-tabs {
        padding: 0 0.75rem;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        flex-wrap: nowrap;
    }

    .page-gestione-contabile .doc-history-tab {
        white-space: nowrap;
        flex-shrink: 0;
    }

    .page-gestione-contabile .accounting-panel {
        padding: 1rem 1rem 1.25rem;
    }
}

@media (max-width: 768px) {
    .stats-pie-layout {
        flex-direction: column;
        align-items: center;
    }

    .stats-pie-legend {
        width: 100%;
        min-width: 0;
    }

    .page-gestione-contabile .accounting-panel-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .page-gestione-contabile .accounting-panel-actions .btn {
        width: 100%;
        min-height: 2.75rem;
    }

    .page-gestione-contabile .stats-history-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .page-gestione-contabile .stats-history-actions .btn {
        width: 100%;
        min-height: 2.75rem;
    }

    .page-gestione-contabile .stats-history-year-header {
        flex-direction: column;
        align-items: flex-start;
    }
}

@media (max-width: 480px) {
    .page-gestione-contabile .accounting-main {
        padding: 0.75rem 0.75rem 1.5rem;
    }

    .page-gestione-contabile .stats-summary {
        grid-template-columns: 1fr;
    }
}

/* Admin — tablet e mobile */
@media (max-width: 768px) {
    .admin-page {
        padding: 1.25rem 1rem 2rem;
    }

    .admin-header h1 {
        font-size: 1.4rem;
    }

    .admin-section {
        padding: 1rem;
    }

    .admin-table {
        min-width: 44rem;
        font-size: 0.8rem;
    }

    .admin-table th,
    .admin-table td {
        padding: 0.65rem 0.75rem;
    }

    .admin-form-grid {
        grid-template-columns: 1fr;
    }

    .admin-password-modal {
        width: calc(100% - 1rem);
    }
}

@media (max-width: 480px) {
    .admin-page {
        padding: 1rem 0.75rem 1.5rem;
    }

    .admin-subtitle {
        margin-bottom: 1.25rem;
        font-size: 0.85rem;
    }
}

/* Home — mobile */
@media (max-width: 768px) {
    .home-body .home {
        justify-content: flex-start;
        padding: 1.25rem max(1rem, env(safe-area-inset-right)) 1.5rem;
        padding-left: max(1rem, env(safe-area-inset-left));
    }

    .home-header {
        margin-bottom: 1.75rem;
    }

    .home-header h1 {
        font-size: 1.4rem;
    }

    .home-nav {
        gap: 0.75rem;
    }

    .home-card {
        display: grid;
        grid-template-columns: auto 1fr;
        grid-template-rows: auto auto;
        column-gap: 0.875rem;
        row-gap: 0.2rem;
        align-items: center;
        padding: 0.9rem 1rem;
        min-height: 3.25rem;
        -webkit-tap-highlight-color: transparent;
    }

    .home-card-icon {
        grid-row: 1 / 3;
        font-size: 1.6rem;
    }

    .home-card-title {
        font-size: 1.05rem;
    }

    .home-card-desc {
        font-size: 0.82rem;
    }

    .auth-body {
        align-items: flex-start;
        padding: 1rem;
        padding-top: max(1rem, env(safe-area-inset-top));
    }

    .auth-card,
    .onboarding-card,
    .change-password-card {
        padding: 1.5rem;
    }

    .onboarding-card {
        margin: 1rem auto;
    }

    .change-password-card {
        margin: 1rem auto;
    }
}

@media (max-width: 480px) {
    .home {
        padding: 1rem 0.875rem 1.5rem;
    }

    .home-header {
        margin-bottom: 1.5rem;
    }

    .home-header h1 {
        font-size: 1.2rem;
    }

    .home-card {
        padding: 0.8rem 0.9rem;
        min-height: 3rem;
    }

    .home-card-icon {
        font-size: 1.45rem;
    }

    .home-card-title {
        font-size: 1rem;
    }

    .home-card-desc {
        font-size: 0.78rem;
    }

    .auth-card,
    .onboarding-card,
    .change-password-card {
        padding: 1.25rem;
        border-radius: 10px;
    }
}

/* Safe area su pagine principali */
.page-fatturazione,
.page-gestione-contabile,
.page-note-spese,
.admin-body,
.home-body {
    padding-bottom: env(safe-area-inset-bottom, 0);
}
