/* =========================================================
   ML - STYLE
   ========================================================= */

:root {
    --background: #071A2E;
    --surface: #0E2742;
    --surface-soft: #132F4F;

    --text: #FFFFFF;
    --text-secondary: #A8B7C7;
    --text-light: #A8B7C7;

    --primary: #2E90FF;
    --primary-light: #5EC6FF;

    --border: #28506C;

    --success: #2ECC71;
    --success-soft: #123D37;

    --danger: #FF5B5B;
    --danger-soft: #432933;

    --shadow: 0 4px 18px rgba(15, 23, 42, 0.07);

    --radius: 16px;
    --radius-small: 10px;

    --header-height: 62px;
    --navigation-height: 76px;
}


/* =========================================================
   RESET
   ========================================================= */

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    width: 100%;
    height: 100%;
}

body {
    width: 100%;
    min-height: 100%;
    background: var(--background);
    color: var(--text);

    font-family:
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        Roboto,
        Helvetica,
        Arial,
        sans-serif;

    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;

    overflow-x: hidden;
    overflow-y: auto;

    -webkit-overflow-scrolling: touch;
}

button,
input,
select,
textarea {
    font: inherit;
}

button {
    border: 0;
    cursor: pointer;
}

input,
select,
textarea {
    outline: none;
}


/* =========================================================
   HEADER
   ========================================================= */

.app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;

    height: var(--header-height);

    display: flex;
    align-items: center;
    justify-content: space-between;

    padding: 0 18px;

    background: var(--surface);

    border-bottom: 1px solid var(--border);

    z-index: 100;
}

.app-title {
    font-size: 22px;
    font-weight: 800;
    letter-spacing: 0.5px;
}

.icon-button {
    width: 42px;
    height: 42px;

    display: flex;
    align-items: center;
    justify-content: center;

    background: transparent;

    border-radius: 50%;

    font-size: 20px;

    transition:
        background 0.15s ease,
        transform 0.15s ease;
}

.icon-button:active {
    background: var(--background);
    transform: scale(0.92);
}


/* =========================================================
   MAIN CONTENT
   ========================================================= */

.app-content {
    width: 100%;
    max-width: 900px;

    margin: 0 auto;

    padding-top: calc(var(--header-height) + 18px);
    padding-bottom: calc(var(--navigation-height) + env(safe-area-inset-bottom) + 24px);
}

.page {
    display: none;
    padding: 0 16px;
}

.page.active {
    display: block;
}


/* =========================================================
   PAGE TITLE
   ========================================================= */

.page-title {
    margin-bottom: 22px;
}

.page-title h1 {
    font-size: 28px;
    line-height: 1.15;

    font-weight: 800;

    margin-bottom: 6px;
}

.page-title p {
    color: var(--text-secondary);

    font-size: 14px;
}


/* =========================================================
   SECTION
   ========================================================= */

.summary-section {
    margin-bottom: 26px;
}

.section-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;

    margin-bottom: 12px;
}

.section-header h2 {
    font-size: 18px;
    font-weight: 750;
}

.section-header span {
    color: var(--text-secondary);

    font-size: 13px;
}


/* =========================================================
   SUMMARY CARDS
   ========================================================= */

.summary-grid {
    display: grid;

    grid-template-columns:
        repeat(2, minmax(0, 1fr));

    gap: 10px;
}

.summary-card {
    min-height: 100px;

    display: flex;
    flex-direction: column;
    justify-content: space-between;

    padding: 16px;

    background: var(--surface);

    border: 1px solid var(--border);
    border-radius: var(--radius);

    box-shadow: var(--shadow);
}

.summary-card.highlight {
    background: var(--success-soft);

    border-color: rgba(22, 128, 60, 0.12);
}

.summary-label {
    color: var(--text-secondary);

    font-size: 13px;
    font-weight: 500;
}

.summary-card strong {
    font-size: 21px;
    font-weight: 800;
    min-width: 0;
    overflow-wrap: anywhere;
}

.summary-card.highlight strong {
    color: var(--success);
}


/* =========================================================
   FILTERS
   ========================================================= */

.filters-card {
    padding: 16px;

    margin-bottom: 18px;

    background: var(--surface);

    border: 1px solid var(--border);
    border-radius: var(--radius);

    box-shadow: var(--shadow);
}

.filters-title {
    margin-bottom: 14px;

    font-size: 16px;
    font-weight: 750;
}

.filter-row {
    display: grid;

    grid-template-columns:
        repeat(3, minmax(0, 1fr));

    gap: 10px;

    margin-bottom: 12px;
}

.filter-field {
    display: flex;
    flex-direction: column;

    gap: 6px;
}

.filter-field.full {
    margin-bottom: 12px;
}

.filter-field label {
    color: var(--text-secondary);

    font-size: 12px;
    font-weight: 600;
}

.filter-field input,
.filter-field select {
    width: 100%;
    height: 42px;

    padding: 0 11px;

    background: var(--surface-soft);

    border: 1px solid var(--border);
    border-radius: var(--radius-small);

    color: var(--text);

    font-size: 14px;
}

.filter-field input:focus,
.filter-field select:focus {
    border-color: var(--primary);
}


/* =========================================================
   BUTTONS
   ========================================================= */

.primary-button,
.secondary-button,
.danger-button {
    min-height: 44px;

    padding: 0 18px;

    border-radius: var(--radius-small);

    font-size: 14px;
    font-weight: 700;

    transition:
        transform 0.12s ease,
        opacity 0.12s ease;
}

.primary-button {
    background: var(--primary);
    color: #FFFFFF;
}

.secondary-button {
    background: var(--surface-soft);
    color: var(--text);

    border: 1px solid var(--border);
}

.danger-button {
    background: var(--danger);
    color: #FFFFFF;
}

.primary-button:active,
.secondary-button:active,
.danger-button:active {
    transform: scale(0.97);
}

.primary-button:hover,
.secondary-button:hover,
.danger-button:hover {
    opacity: 0.9;
}


/* =========================================================
   JOB LIST
   ========================================================= */

.jobs-list {
    display: flex;
    flex-direction: column;

    gap: 10px;
}

.job-card {
    position: relative;

    padding: 16px;

    background: var(--surface);

    border: 1px solid var(--border);
    border-radius: var(--radius);

    box-shadow: var(--shadow);

    cursor: pointer;

    transition:
        transform 0.12s ease,
        box-shadow 0.12s ease;
}

.job-card:active {
    transform: scale(0.99);
}

.job-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;

    gap: 12px;

    margin-bottom: 12px;
}

.job-client {
    font-size: 16px;
    font-weight: 750;
}

.job-date {
    flex-shrink: 0;

    color: var(--text-secondary);

    font-size: 12px;
}

.job-description {
    display: block;
    width: 100%;

    margin-bottom: 14px;

    color: var(--text-secondary);

    font-size: 13px;
    line-height: 1.45;

    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.job-details {
    display: grid;

    grid-template-columns:
        repeat(3, minmax(0, 1fr));

    gap: 8px;
}

.job-detail {
    display: flex;
    flex-direction: column;

    gap: 3px;
}

.job-detail span {
    color: var(--text-light);

    font-size: 11px;
}

.job-detail strong {
    font-size: 14px;
    min-width: 0;
    overflow-wrap: anywhere;
}

.job-detail.profit strong {
    color: var(--success);
}

.job-actions {
    display: flex;

    justify-content: flex-end;

    gap: 8px;

    margin-top: 14px;

    padding-top: 12px;

    border-top: 1px solid var(--border);
}

.job-action-button {
    min-height: 36px;

    padding: 0 12px;

    border-radius: 8px;

    font-size: 12px;
    font-weight: 700;
}

.edit-job-button {
    background: var(--surface-soft);

    color: var(--text);
}

.delete-job-button {
    background: var(--danger-soft);

    color: var(--danger);
}


/* =========================================================
   EMPTY STATE
   ========================================================= */

.empty-state {
    padding: 42px 20px;

    text-align: center;

    background: var(--surface);

    border: 1px dashed var(--border);
    border-radius: var(--radius);
}

.empty-icon {
    margin-bottom: 12px;

    font-size: 38px;
}

.empty-state h3 {
    margin-bottom: 6px;

    font-size: 17px;
}

.empty-state p {
    max-width: 280px;

    margin: 0 auto;

    color: var(--text-secondary);

    font-size: 13px;
    line-height: 1.5;
}


/* =========================================================
   SETTINGS
   ========================================================= */

.settings-list {
    display: flex;
    flex-direction: column;

    gap: 10px;
}
.settings-section { display:grid; gap:12px; padding:18px; background:var(--surface-soft); border:1px solid var(--border); border-radius:var(--radius); }
.settings-section h2 { margin:0; font-size:18px; }
.settings-section > input,.settings-section select { width:100%; min-width:0; box-sizing:border-box; }
.business-logo-row { display:flex; align-items:center; gap:14px; flex-wrap:wrap; }
.business-logo-row img { width:76px; height:76px; object-fit:contain; border-radius:12px; background:white; padding:6px; box-sizing:border-box; }
.business-logo-row > div { display:flex; gap:8px; flex-wrap:wrap; }
.report-period { display:grid; grid-template-columns:auto minmax(0,1fr) auto minmax(0,1fr); align-items:center; gap:8px; }
.settings-toggle { display:flex; align-items:center; gap:8px; }
.settings-toggle input { width:auto; }
.backup-reminder { margin:0; padding:10px 12px; border-radius:10px; background:#ffd1661f; color:#ffd166; }
.settings-section details { padding:10px 0; border-bottom:1px solid var(--border); }
.settings-section summary { cursor:pointer; font-weight:700; }
@media (max-width:480px){.report-period{grid-template-columns:1fr 1fr}.report-period label{grid-column:auto}.report-period select{grid-row:2}}

.settings-item {
    width: 100%;

    display: flex;
    align-items: center;

    gap: 14px;

    padding: 15px;

    background: var(--surface);

    border: 1px solid var(--border);
    border-radius: var(--radius);

    text-align: left;

    box-shadow: var(--shadow);
}

.settings-item:active {
    transform: scale(0.99);
}

.settings-icon {
    width: 42px;
    height: 42px;

    flex-shrink: 0;

    display: flex;
    align-items: center;
    justify-content: center;

    background: var(--surface-soft);

    border-radius: 11px;

    font-size: 19px;
}

.settings-text {
    display: flex;
    flex-direction: column;

    gap: 3px;
}

.settings-text strong {
    font-size: 14px;
}

.settings-text span {
    color: var(--text-secondary);

    font-size: 12px;
}

.settings-divider {
    height: 1px;

    margin: 10px 0;

    background: var(--border);
}

.settings-info {
    display: flex;
    flex-direction: column;

    align-items: center;

    gap: 4px;

    padding: 20px;

    color: var(--text-secondary);

    text-align: center;
}

.settings-info span {
    color: var(--text);

    font-size: 18px;
    font-weight: 800;
}

.settings-info small {
    font-size: 12px;
}

.legal-page { max-width:760px; margin:0 auto; padding:32px 20px 80px; line-height:1.65; }
.legal-page h1 { margin-top:28px; }
.legal-page h2 { margin-top:30px; font-size:20px; }
.legal-back { display:inline-flex; text-decoration:none; width:auto; }


/* =========================================================
   MODALS
   ========================================================= */

.modal {
    position: fixed;

    inset: 0;

    z-index: 10000;

    display: flex;

    align-items: flex-end;
    justify-content: center;
}

.modal.hidden {
    display: none;
}

.modal-overlay {
    position: absolute;

    inset: 0;

    background: rgba(15, 23, 42, 0.55);

    backdrop-filter: blur(2px);
}

.modal-content,
.confirm-content {
    position: relative;

    width: 100%;
    max-width: 520px;

    background: var(--surface);

    border-radius:
        22px
        22px
        0
        0;

    padding: 22px 18px 24px;

    box-shadow:
        0 -8px 35px rgba(15, 23, 42, 0.16);

    animation: modalUp 0.2s ease;
}

.confirm-content {
    margin: 16px;

    border-radius: 22px;

    padding: 26px 20px;

    text-align: center;
}

@keyframes modalUp {
    from {
        transform: translateY(30px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}


/* =========================================================
   MODAL HEADER
   ========================================================= */

.modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;

    gap: 15px;

    margin-bottom: 22px;
}

.modal-header h2 {
    margin-bottom: 4px;

    font-size: 20px;
    font-weight: 800;
}

.modal-header p {
    color: var(--text-secondary);

    font-size: 12px;
}

.modal-close {
    width: 36px;
    height: 36px;

    flex-shrink: 0;

    display: flex;
    align-items: center;
    justify-content: center;

    background: var(--surface-soft);

    border-radius: 50%;

    color: var(--text-secondary);

    font-size: 25px;
    line-height: 1;
}


/* =========================================================
   FORM
   ========================================================= */

.form-group {
    width: 100%;
    min-width: 0;

    margin-bottom: 16px;
}

.form-group label {
    display: block;

    margin-bottom: 7px;

    color: var(--text-secondary);

    font-size: 13px;
    font-weight: 650;
}

.form-group input {
    display: block;

    width: 100%;
    max-width: 100%;
    min-width: 0;

    height: 48px;

    padding: 0 13px;

    box-sizing: border-box;

    background: var(--surface-soft);

    border: 1px solid var(--border);
    border-radius: var(--radius-small);

    color: var(--text);

    font-size: 15px;
}

.form-group input:focus {
    border-color: var(--primary);
}

.money-input {
    position: relative;

    width: 100%;
    min-width: 0;
}

.money-input > span {
    position: absolute;

    left: 13px;
    top: 50%;

    transform: translateY(-50%);

    color: var(--text-secondary);

    font-size: 14px;
    font-weight: 700;

    pointer-events: none;
}

.money-input input {
    width: 100%;
    max-width: 100%;
    min-width: 0;

    padding-left: 32px;
}

.form-group textarea {
    display: block;

    width: 100%;
    max-width: 100%;
    min-width: 0;

    min-height: 100px;

    padding: 12px 13px;

    box-sizing: border-box;

    background: var(--surface-soft);

    border: 1px solid var(--border);
    border-radius: var(--radius-small);

    color: var(--text);

    font-size: 15px;
    font-family: inherit;

    line-height: 1.4;

    resize: vertical;
}

.form-group textarea:focus {
    border-color: var(--primary);
}


/* =========================================================
   CAMPO DATA
   ========================================================= */

.date-group {
    width: 100%;
    min-width: 0;
}

.date-input-wrapper {
    width: 100%;
    max-width: 100%;
    min-width: 0;

    box-sizing: border-box;
}

.date-input-wrapper input[type="date"] {
    display: block;

    width: 100%;
    max-width: 100%;
    min-width: 0;

    height: 48px;

    margin: 0;
    padding: 0 13px;

    box-sizing: border-box;

    background: var(--surface-soft);

    border: 1px solid var(--border);
    border-radius: var(--radius-small);

    color: var(--text);

    font-family: inherit;
    font-size: 15px;

    -webkit-appearance: none;
    appearance: none;

    text-align: center;
    line-height: 48px;
}

.date-input-wrapper input[type="date"]:focus {
    border-color: var(--primary);
}


/* =========================================================
   PROFIT PREVIEW
   ========================================================= */

.profit-preview {
    display: flex;
    align-items: center;
    justify-content: space-between;

    padding: 14px 15px;

    margin-top: 4px;
    margin-bottom: 20px;

    background: var(--success-soft);

    border: 1px solid rgba(22, 128, 60, 0.12);

    border-radius: var(--radius-small);
}

.profit-preview span {
    color: var(--text-secondary);

    font-size: 13px;
}

.profit-preview strong {
    color: var(--success);

    font-size: 18px;
}


/* =========================================================
   MODAL ACTIONS
   ========================================================= */

.modal-actions {
    display: grid;

    grid-template-columns:
        1fr 1fr;

    gap: 10px;
}

.modal-actions button {
    width: 100%;
}


/* =========================================================
   CONFIRM DELETE
   ========================================================= */

.confirm-icon {
    margin-bottom: 12px;

    font-size: 40px;
}

.confirm-content h2 {
    margin-bottom: 7px;

    font-size: 20px;
}

.confirm-content p {
    margin-bottom: 22px;

    color: var(--text-secondary);

    font-size: 13px;
}


/* =========================================================
   BOTTOM NAVIGATION
   ========================================================= */

.bottom-navigation {
    position: fixed;

    left: 0;
    right: 0;
    bottom: 0;

    width: 100%;
    height: calc(var(--navigation-height) + env(safe-area-inset-bottom));

    display: flex;
    align-items: center;
    justify-content: space-around;

    padding:
        7px
        max(10px, env(safe-area-inset-right))
        calc(7px + env(safe-area-inset-bottom))
        max(10px, env(safe-area-inset-left));

    background: rgba(14, 39, 66, 0.98);

    border-top: 1px solid var(--border);

    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);

    z-index: 9999;

    transform: translateZ(0);
    -webkit-transform: translateZ(0);

    will-change: transform;
}

.nav-button {
    width: 90px;
    height: 60px;

    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;

    gap: 3px;

    background: transparent;

    color: var(--text-light);

    border-radius: 12px;

    transition:
        color 0.15s ease,
        background 0.15s ease;
}

.nav-button.active {
    color: var(--text);
}

.nav-button:active {
    background: var(--background);
}

.nav-icon {
    font-size: 19px;
    line-height: 1;
}

.nav-label {
    font-size: 11px;
    font-weight: 650;
}


/* =========================================================
   CENTRAL ADD BUTTON
   ========================================================= */

.nav-add-button {
    width: 58px;
    height: 58px;

    flex-shrink: 0;

    display: flex;
    align-items: center;
    justify-content: center;

    margin-top: -22px;

    background: var(--primary);

    color: #FFFFFF;

    border-radius: 50%;

    border: 5px solid var(--background);

    box-shadow:
        0 5px 18px rgba(15, 23, 42, 0.22);

    transition:
        transform 0.12s ease,
        box-shadow 0.12s ease;
}

.nav-add-button span {
    margin-top: -2px;

    font-size: 30px;
    font-weight: 300;

    line-height: 1;
    transition: transform 0.16s ease;
}

.nav-add-button.menu-open span { transform: rotate(45deg); }

.nav-add-button:active {
    transform: scale(0.92);

    box-shadow:
        0 3px 10px rgba(15, 23, 42, 0.18);
}


/* =========================================================
   RESPONSIVE
   ========================================================= */

@media (min-width: 700px) {

    .app-content {
        padding-left: 18px;
        padding-right: 18px;
    }

    .page {
        padding-left: 0;
        padding-right: 0;
    }

    .summary-grid {
        grid-template-columns:
            repeat(4, minmax(0, 1fr));
    }

    .modal {
        align-items: center;
    }

    .modal-content {
        border-radius: 22px;
        padding: 26px;
    }

    .confirm-content {
        margin: 0;
    }
}


/* =========================================================
   MOBILE
   ========================================================= */

@media (max-width: 699px) {

    .modal {
        position: fixed;

        inset: 0;

        width: 100%;
        max-width: 100%;

        display: flex;
        align-items: flex-end;
        justify-content: center;

        padding: 0;
    }

    .modal-content {
        position: relative;

        width: 100%;
        max-width: 520px;

        margin: 0;

        padding: 22px 18px 24px;

        overflow-x: hidden;
        overflow-y: auto;

        box-sizing: border-box;
    }

    #jobForm {
        width: 100%;
        min-width: 0;

        box-sizing: border-box;
    }

    #jobForm .form-group {
        width: 100%;
        min-width: 0;

        box-sizing: border-box;
    }

    #jobForm input,
    #jobForm textarea,
    #jobForm .money-input,
    #jobForm .date-input-wrapper {
        width: 100%;
        max-width: 100%;
        min-width: 0;

        box-sizing: border-box;
    }


    /* =====================================================
       DATA
       ===================================================== */

    .date-group {
        width: 100%;
        min-width: 0;

        overflow: hidden;
    }

    .date-input-wrapper {
        display: block;

        width: 100%;
        max-width: 100%;
        min-width: 0;

        overflow: hidden;

        box-sizing: border-box;
    }

    .date-input-wrapper input[type="date"] {
        display: block;

        width: 100%;
        max-width: 100%;
        min-width: 0;

        height: 48px;

        margin: 0;
        padding: 0 10px;

        border: 1px solid var(--border);
        border-radius: var(--radius-small);

        background: var(--surface-soft);

        color: var(--text);

        font-family: inherit;
        font-size: 15px;

        box-sizing: border-box;

        -webkit-appearance: none;
        appearance: none;
    }


    /* =====================================================
       DESCRIZIONE
       ===================================================== */

    #jobForm textarea {
        display: block;

        width: 100%;
        max-width: 100%;
        min-width: 0;

        height: 110px;
        min-height: 110px;

        padding: 12px 13px;

        box-sizing: border-box;

        line-height: 1.4;

        resize: vertical;
    }

}


/* =========================================================
   SMALL PHONES
   ========================================================= */

@media (max-width: 360px) {

    .modal-content {
        padding-left: 16px;
        padding-right: 16px;
    }

    .date-input-wrapper input[type="date"] {
        width: 100%;
        max-width: 100%;

        padding-left: 8px;
        padding-right: 8px;

        font-size: 13px;
    }

    #jobForm textarea {
        height: 105px;
        min-height: 105px;
    }

    .page-title h1 {
        font-size: 25px;
    }

    .summary-card {
        padding: 13px;
    }

    .summary-card strong {
        font-size: 18px;
    }

    .filter-row {
        grid-template-columns: 1fr;
    }

    .job-details {
        grid-template-columns: 1fr 1fr;
    }

}


/* =========================================================
   ACCESSIBILITY
   ========================================================= */

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* Riepilogo: selezione del periodo */
.summary-controls { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.summary-controls [hidden], #page-summary [hidden] { display: none !important; }
.summary-controls .filter-field { min-width: 0; }
.summary-controls input, .summary-controls select { width: 100%; min-width: 0; max-width: 100%; box-sizing: border-box; font-size: 16px; }
.summary-controls input { min-height: 48px; padding: 10px; border: 1px solid var(--border); border-radius: var(--radius-small); background: var(--surface-soft); color: var(--text); font-family: inherit; }
.summary-controls input:focus { outline-color: var(--primary); }
.summary-link { width: 100%; min-height: 48px; }
.summary-link:disabled { opacity: .5; cursor: default; }
.summary-message { margin-top: 16px; color: var(--text-secondary, #64748b); }
#summaryHeading { overflow-wrap: anywhere; }
@media (max-width: 380px) { .summary-controls { grid-template-columns: 1fr; } }

/* Il campo nativo apre il calendario; il contenitore controlla la resa su iOS. */
.summary-date-control {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    width: 100%;
    min-width: 0;
    height: 48px;
    box-sizing: border-box;
    overflow: hidden;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-small);
    background: var(--surface-soft);
    color: var(--text);
    font-size: 16px;
}
#summaryDateDisplay { white-space: nowrap; }
.summary-date-icon { flex-shrink: 0; }
.summary-date-control:focus-within {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}
.summary-controls .summary-date-control input[type="date"] {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    height: 100%;
    min-height: 0;
    margin: 0;
    padding: 0;
    border: 0;
    opacity: 0;
    cursor: pointer;
    font-size: 16px;
}
.summary-date-control input::-webkit-calendar-picker-indicator {
    position: absolute;
    inset: 0;
    width: auto;
    height: auto;
    margin: 0;
    padding: 0;
    cursor: pointer;
}

/* Popup sopra la navigazione, scorrevole anche su schermi bassi. */
body.modal-open .bottom-navigation { visibility: hidden; pointer-events: none; }
body.modal-open { overflow: hidden; }
.modal {
    top: var(--modal-viewport-top, 0px);
    bottom: auto;
    height: var(--modal-viewport-height, 100dvh);
}
.modal-content,
.confirm-content {
    max-height: calc(100vh - 32px);
    max-height: calc(100dvh - 32px - env(safe-area-inset-top));
    overflow-y: auto;
    overscroll-behavior: contain;
}
#jobModal .modal-content {
    display: flex;
    flex-direction: column;
    max-height: calc(var(--modal-viewport-height, 100dvh) - 16px - env(safe-area-inset-top));
    overflow: hidden;
}
#jobModal .modal-header { flex-shrink: 0; }
#jobForm {
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 1px;
}
#jobForm .modal-actions {
    position: sticky;
    bottom: -1px;
    z-index: 1;
    background: var(--surface);
    padding-top: 12px;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
}
@media (max-width: 699px) {
    .modal-content,
    .confirm-content {
        padding-bottom: calc(24px + env(safe-area-inset-bottom));
    }
}

/* Identità ML approvata, v1.0 */
:root { color-scheme: dark; }
body { font-family: ui-rounded, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
.app-title { display:flex; align-items:center; gap:10px; }
.app-title img { border-radius:10px; }
.app-title b { color:var(--primary); }
input, select, textarea { color-scheme:dark; }

/* Rubrica clienti */
#page-clients [hidden] { display:none !important; }
#page-clients > label { display:block; margin:24px 0 8px; }
#clientSearch { width:100%; }
.client-list { display:grid; gap:10px; margin:18px 0; }
.client-row { display:flex; flex-direction:column; gap:5px; min-height:62px; padding:12px 14px; border:1px solid var(--border); border-radius:14px; background:var(--surface); color:var(--text); text-align:left; overflow-wrap:anywhere; cursor:pointer; }
.client-row strong { font-size:15px; line-height:1.25; }
.client-row span { color:var(--text-secondary); font-size:12px; line-height:1.3; }
.client-actions { display:flex; flex-wrap:wrap; gap:8px; margin:10px 0; }
.client-actions a { color:var(--primary-light); padding:10px; }
.client-actions .contact-action { display:grid; place-items:center; width:44px; height:44px; min-width:44px; padding:0; border:1px solid var(--border); border-radius:12px; background:var(--surface-soft); color:var(--text); text-decoration:none; }
.contact-action-icon { display:grid; place-items:center; width:34px; height:34px; border-radius:11px; background:#e2e8f0; color:#0f2747; font-size:19px; font-weight:900; line-height:1; }
.contact-action-icon svg { width:23px; height:23px; fill:none; stroke:currentColor; stroke-width:1.9; stroke-linecap:round; stroke-linejoin:round; }
.contact-action[href^="https://wa.me/"] .contact-action-icon svg { fill:none; stroke-width:1.7; }
.contact-action[href^="https://wa.me/"] .contact-action-icon { background:#25d366; color:#fff; }
.contact-action[href*="google.com/maps"] .contact-action-icon { background:#4285f4; color:#fff; }
.visually-hidden { position:absolute !important; width:1px !important; height:1px !important; padding:0 !important; margin:-1px !important; overflow:hidden !important; clip:rect(0,0,0,0) !important; white-space:nowrap !important; border:0 !important; }
.contact-action:active { transform:scale(.98); }
#clientEditor { scroll-margin-top:85px; }
#clientEditor h2 { margin-bottom:20px; overflow-wrap:anywhere; }
#clientHistory p { padding:12px 0; border-bottom:1px solid var(--border); overflow-wrap:anywhere; }
.address-editor { margin:18px 0; padding:14px; border:1px solid var(--border); border-radius:14px; }
.address-editor legend { padding:0 6px; font-weight:700; }
.address-editor > small { display:block; margin-top:10px; color:var(--text-secondary); }
.address-row { display:grid; grid-template-columns:minmax(95px,.7fr) minmax(0,2fr); gap:8px; align-items:center; padding:10px 0; border-bottom:1px solid var(--border); }
.address-row input[type="text"],.address-row select { width:100%; min-width:0; padding:10px; border:1px solid var(--border); border-radius:10px; background:var(--surface-soft); color:var(--text); }
.address-primary { font-size:12px; color:var(--text-secondary); }
.address-row button { padding:9px; }
.bottom-navigation { grid-template-columns:repeat(4, minmax(0,1fr)); }

#clientSearch { min-height:48px; padding:12px 14px; border:1px solid var(--border); border-radius:12px; background:var(--surface); color:var(--text); }
/* Struttura ispirata alle tavole ML approvate */
body { background:radial-gradient(ellipse at top left,#0a3555 0, #071a2e 45%,#041423 100%); background-attachment:fixed; }
.bottom-navigation { grid-template-columns:repeat(5,minmax(0,1fr)); }
.nav-label { font-size:10px; }
.period-tabs { display:grid; grid-template-columns:repeat(4,1fr); border-radius:30px; background:#0e2742; padding:4px; margin-bottom:18px; }
.period-tabs button { border:0; border-radius:24px; background:none; color:var(--text); min-height:40px; }
.period-tabs button.active,.primary-button,.nav-add-button { background:linear-gradient(135deg,#24b7ff,#0084ff); }
.summary-controls .filter-field:has(#summaryPeriod) { display:none; }
.summary-grid { grid-template-columns:repeat(3,minmax(0,1fr)); gap:10px; }
.summary-card { border:1px solid #28506c; background:linear-gradient(135deg,#0e2742,#102e48); padding:16px 12px; }
.summary-card strong { font-size:21px; }
.summary-card.highlight { grid-column:1/-1; background:linear-gradient(120deg,#132f4f,#082238); }
.summary-card.highlight strong { font-size:32px; }
#summaryCosts { color:#ff5b5b; } #summaryRevenue { color:#2ecc71; }
.section-header { margin-top:24px; }
.text-link { border:0; background:none; color:#5ec6ff; padding:10px; }
.recent-job { width:100%; display:flex; gap:16px; justify-content:space-between; align-items:center; padding:18px 4px; border:0; border-bottom:1px solid var(--border); background:transparent; color:var(--text); text-align:left; }
.recent-job small { display:block; color:var(--text-secondary); margin-top:6px; }
.recent-job strong { white-space:nowrap; }
.calendar-toolbar { display:flex; align-items:center; justify-content:space-between; margin-bottom:20px; }
.calendar-title { border:0; background:transparent; color:var(--text); font-size:20px; font-weight:750; text-transform:capitalize; padding:10px; border-radius:12px; }
.calendar-toolbar button,.calendar-grid button { background:var(--surface); color:var(--text); border:1px solid var(--border); border-radius:12px; min-height:44px; padding:8px; }
.calendar-toolbar .calendar-title { background:transparent; border-color:transparent; }
.calendar-jump { display:grid; grid-template-columns:1fr 1fr; gap:8px 10px; padding:12px; margin:-8px 0 18px; border:1px solid var(--border); border-radius:14px; background:var(--surface); }
.calendar-jump[hidden] { display:none; }
.calendar-jump label { color:var(--text-secondary); font-size:12px; }
.calendar-jump select { width:100%; min-width:0; padding:10px; border:1px solid var(--border); border-radius:10px; background:var(--surface-soft); color:var(--text); }
.calendar-jump button { grid-column:1/-1; }
.calendar-grid { display:grid; grid-template-columns:repeat(7,minmax(0,1fr)); gap:6px; margin-bottom:24px; text-align:center; }
.calendar-grid .selected { background:var(--primary); border-color:var(--primary-light); }
.agenda-card { border:1px solid var(--border); border-radius:16px; background:linear-gradient(130deg,#132f4f,#082238); padding:16px; margin:12px 0; overflow-wrap:anywhere; }
.agenda-card p { margin:8px 0; } .agenda-card small { color:var(--text-secondary); }
.agenda-card .overdue-label { color:#ff9a9a; font-weight:700; }
.agenda-card h3 { font-size:16px; } .agenda-card button { padding:10px; }
.agenda-card .client-actions { flex-wrap:nowrap; gap:clamp(4px,1.5vw,7px); margin:8px 0 0; }
.agenda-card .appointment-action-button { display:grid; place-items:center; width:clamp(40px,12vw,46px); height:clamp(40px,12vw,46px); min-width:0; min-height:40px; flex:0 1 46px; padding:0; border-radius:12px; }
.appointment-action-button svg { width:25px; height:25px; fill:none; stroke:currentColor; stroke-width:2; stroke-linecap:round; stroke-linejoin:round; }
.appointment-action-button[aria-label="Completa"] { color:#79e6a2; border-color:rgba(121,230,162,.4); background:rgba(21,128,61,.2); }
.appointment-action-button[aria-label="Modifica"] { color:#8fc7ff; border-color:rgba(143,199,255,.4); background:rgba(30,96,145,.2); }
.appointment-action-button[aria-label="Elimina"] { color:#ff6b6b; border-color:rgba(255,107,107,.45); background:rgba(127,29,29,.2); }
.contact-action svg[data-icon="whatsapp"] { width:31px; height:31px; overflow:visible; }
.contact-action svg[data-icon="whatsapp"] .whatsapp-bubble { fill:none; stroke:currentColor; stroke-width:1.9; stroke-linecap:round; stroke-linejoin:round; }
.contact-action svg[data-icon="whatsapp"] .whatsapp-handset { fill:#fff; stroke:none; }
.agenda-card .contact-action { width:clamp(40px,12vw,46px); height:clamp(40px,12vw,46px); min-width:0; min-height:40px; flex:0 1 46px; }
.agenda-card .contact-action-icon { width:36px; height:36px; }
.agenda-card .contact-action-icon svg:not([data-icon="whatsapp"]) { width:25px; height:25px; }
dialog { margin:auto; width:min(500px,calc(100vw - 16px)); max-width:calc(100vw - 16px); max-height:calc(100dvh - 32px); overflow:auto; box-sizing:border-box; border:1px solid var(--border); border-radius:22px; padding:clamp(16px,5vw,24px); background:#0e2742; color:var(--text); }
dialog::backdrop { background:#001020cc; backdrop-filter:blur(6px); }
body:has(dialog[open]) { overflow:hidden; }
.client-autocomplete { position:relative; min-width:0; }
.client-autocomplete > input { width:100%; box-sizing:border-box; }
.client-suggestion-list { position:absolute; z-index:30; top:calc(100% + 5px); left:0; right:0; max-height:240px; overflow:auto; padding:6px; border:1px solid var(--border); border-radius:12px; background:#0e2742; box-shadow:0 14px 36px #00102099; }
.client-suggestion-list button { display:block; width:100%; padding:11px 12px; border:0; border-radius:8px; background:transparent; color:var(--text); text-align:left; }
.client-suggestion-list button:hover,.client-suggestion-list button:focus-visible { background:var(--surface-hover,#183b5f); }
.client-suggestion-list .create-suggestion { color:var(--accent); }
.client-suggestion-list .restore-suggestion { color:#ffd166; }
.quick-client-trigger { border:0; padding:0; background:transparent; color:inherit; font:inherit; font-weight:inherit; text-align:left; text-decoration:underline; text-decoration-color:transparent; text-underline-offset:3px; }
.quick-client-trigger:hover,.quick-client-trigger:focus-visible { color:var(--accent); text-decoration-color:currentColor; }
.client-quick-dialog { width:min(94vw,560px); }
.client-quick-dialog .section-header { align-items:flex-start; }
.client-quick-dialog .section-header p { margin:.25rem 0 0; color:var(--text-muted); }
.quick-client-section { margin:18px 0; padding-top:14px; border-top:1px solid var(--border); }
.quick-client-section h3 { margin:0 0 10px; }
.quick-client-totals { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:10px; }
.quick-client-total { padding:12px; border-radius:12px; background:var(--surface,#123352); min-width:0; }
.quick-client-total small,.quick-client-total strong { display:block; }
.quick-client-total strong { margin-top:4px; overflow-wrap:anywhere; }
.quick-client-job { display:flex; width:100%; justify-content:space-between; gap:12px; padding:10px 0; border:0; border-bottom:1px solid var(--border); background:transparent; color:var(--text); text-align:left; }
.summary-averages { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:8px; margin-top:12px; padding:12px; border:1px solid var(--border); border-radius:12px; color:var(--text-secondary); }
.summary-averages strong { color:var(--text); }
.update-banner { position:fixed; z-index:20000; left:50%; bottom:calc(88px + env(safe-area-inset-bottom)); transform:translateX(-50%); width:min(92vw,560px); padding:12px; border:1px solid var(--accent); border-radius:14px; background:#0e2742; box-shadow:0 16px 40px #001020cc; display:flex; align-items:center; gap:10px; flex-wrap:wrap; }
.update-banner[hidden] { display:none; }
.update-banner span { flex:1 1 180px; }
.load-more { display:block; margin:16px auto 0; }
.load-more[hidden] { display:none; }
.job-notes { margin-top:8px; color:var(--text-secondary); font-size:13px; white-space:pre-wrap; overflow-wrap:anywhere; }
.overlap-warning { margin:8px 0; padding:9px 11px; border-radius:10px; background:#ffd1661f; color:#ffd166; font-size:13px; }
.quick-menu { position:fixed; inset:auto auto calc(var(--navigation-height) + env(safe-area-inset-bottom) + 12px) 50%; transform:translateX(-50%); width:min(88vw,330px); margin:0; padding:8px; overflow:visible; border-radius:18px; background:#0e2742; box-shadow:0 14px 40px #001020b8; }
.quick-menu button { display:block; width:100%; min-height:44px; padding:10px 14px; border-radius:12px; background:transparent; color:var(--text); text-align:left; font-weight:650; }
.quick-menu button + button { border-top:1px solid var(--border); border-radius:0; }
.quick-menu button:active { background:var(--surface-soft); }
#appointmentForm label { display:block; margin:18px 0 8px; }
#appointmentForm input,#appointmentForm textarea { width:100%; min-height:48px; border:1px solid var(--border); border-radius:12px; background:var(--surface-soft); color:var(--text); padding:12px; min-width:0; }
.dialog-actions { position:sticky; bottom:-24px; background:#0e2742; padding:16px 0; display:grid; gap:10px; }
.summary-controls { padding:12px 16px; margin-bottom:14px; background:transparent; border:0; }
.summary-controls .filter-field { min-width:0; }
.summary-controls label { font-size:11px; }
.summary-card.highlight strong { color:#fff; }
.nav-button.active { color:#24b7ff; }
.nav-icon { display:flex; justify-content:center; }
@media(max-width:420px){ .summary-card strong {font-size:18px;} .summary-card.highlight strong {font-size:30px;} }

/* Controlli nativi iOS: impedisce che data/ora impongano una larghezza intrinseca. */
input[type="date"],
input[type="time"],
input[type="datetime-local"] {
    display:block;
    width:100%;
    inline-size:100%;
    max-width:100%;
    min-width:0;
    box-sizing:border-box;
}
#appointmentForm { width:100%; min-width:0; max-width:100%; box-sizing:border-box; }
#appointmentForm > * { min-width:0; max-width:100%; box-sizing:border-box; }
#appointmentForm input[type="date"],
#appointmentForm input[type="time"],
#jobForm input[type="date"] { width:100%; inline-size:100%; min-width:0; max-width:100%; height:48px; min-height:48px; padding:0 12px; line-height:normal; overflow:visible; box-sizing:border-box; }
input[type="date"]::-webkit-date-and-time-value,
input[type="time"]::-webkit-date-and-time-value,
input[type="datetime-local"]::-webkit-date-and-time-value { min-width:0; width:100%; text-align:left; }
input[type="date"]::-webkit-datetime-edit,
input[type="time"]::-webkit-datetime-edit,
input[type="datetime-local"]::-webkit-datetime-edit { min-width:0; overflow:visible; padding:0; }
input[type="date"]::-webkit-calendar-picker-indicator,
input[type="time"]::-webkit-calendar-picker-indicator { flex:0 0 auto; margin:0; padding:6px; }
.date-input-wrapper { min-width:0; max-width:100%; }

/* Controlli data/ora stabili: stessa soluzione visuale già collaudata nelle altre app. */
.native-date-time-control { position:relative; width:100%; max-width:100%; min-width:0; height:48px; overflow:hidden; border:1px solid var(--border); border-radius:12px; background:var(--surface-soft); box-sizing:border-box; }
.native-date-time-control input { position:absolute; inset:0; z-index:2; width:100% !important; height:46px !important; min-height:46px !important; margin:0 !important; padding:0 !important; border:0 !important; opacity:0; cursor:pointer; }
.native-date-time-value { position:absolute; inset:0; z-index:1; display:flex; align-items:center; padding:0 46px 0 13px; color:var(--text); font-size:16px; line-height:1; pointer-events:none; box-sizing:border-box; }
.native-control-glyph { position:absolute; z-index:1; right:14px; top:50%; width:18px; height:18px; color:var(--text); transform:translateY(-50%); pointer-events:none; box-sizing:border-box; }
.date-glyph { border:2px solid currentColor; border-radius:3px; }
.date-glyph::before { content:""; position:absolute; left:-2px; right:-2px; top:3px; border-top:2px solid currentColor; }
.date-glyph::after { content:""; position:absolute; left:3px; top:-4px; width:2px; height:5px; border-left:2px solid currentColor; border-right:2px solid currentColor; }
.time-glyph { border:2px solid currentColor; border-radius:50%; }
.time-glyph::before { content:""; position:absolute; left:7px; top:3px; width:4px; height:6px; border-left:2px solid currentColor; border-bottom:2px solid currentColor; }
.native-date-time-control:focus-within { border-color:var(--primary); box-shadow:0 0 0 2px rgba(58,143,255,.2); }
.appointment-date-shortcuts { display:flex; gap:8px; margin:8px 0 0; }
.appointment-date-shortcuts button { min-height:38px; padding:7px 14px; border:1px solid var(--border); border-radius:10px; background:var(--surface-soft); color:var(--text); font-weight:700; text-decoration:none; }

/* Gli importi devono restare dentro le card anche con cifre eccezionalmente lunghe. */
.summary-card,
.job-detail,
.recent-job,
.recent-job > * { min-width:0; }
.recent-job strong { max-width:52%; overflow:hidden; text-overflow:ellipsis; }
