@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700;800&display=swap');

:root {
    --bg: #101827;
    --panel: #192437;
    --panel-light: #202e43;
    --border: #2c3a50;
    --text: #f1f5fb;
    --muted: #91a0b5;
    --blue: #5795f7;
    --blue-dark: #3478e5;
    --green: #39c99a;
    --orange: #f0a64b;
    --red: #ef7373;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: 'DM Sans', sans-serif;
    font-size: 14px;
}

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

button {
    cursor: pointer;
}

.app {
    width: 100%;
    max-width: 850px;
    margin: auto;
    padding: 30px 24px;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 27px;
}

.eyebrow {
    color: var(--blue);
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 1.5px;
    margin-bottom: 7px;
}

h1 {
    font-size: 29px;
    margin: 0;
    font-weight: 800;
    letter-spacing: -1px;
}

h1 span {
    color: var(--blue);
}

.topbar p {
    color: var(--muted);
    margin: 5px 0 0;
}

.top-icon {
    width: 49px;
    height: 49px;
    border-radius: 15px;
    display: grid;
    place-items: center;
    font-size: 25px;
    background: var(--panel-light);
    color: var(--blue);
}

.stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 11px;
    margin-bottom: 18px;
}

.stat-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 13px;
    padding: 16px 13px;
    min-width: 0;
}

.stat-card span {
    display: block;
    color: var(--muted);
    font-size: 9px;
    letter-spacing: .7px;
    font-weight: 700;
    margin-bottom: 9px;
}

.stat-card strong {
    font-size: 24px;
    font-weight: 800;
}

.stat-card.highlight strong {
    color: var(--orange);
}

.panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 17px;
    padding: 23px;
    margin-bottom: 17px;
}

.section-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 23px;
}

h2 {
    margin: 0;
    font-size: 21px;
    letter-spacing: -.5px;
}

.calendar-icon,
.backup-icon {
    font-size: 24px;
    color: var(--blue);
    background: var(--panel-light);
    border-radius: 11px;
    width: 43px;
    height: 43px;
    display: grid;
    place-items: center;
}

.field {
    margin-bottom: 16px;
}

.field label {
    display: block;
    color: #c5cfdd;
    font-weight: 600;
    font-size: 12px;
    margin-bottom: 8px;
}

.field input,
.field select,
.field textarea,
.filters input,
.filters select {
    width: 100%;
    border: 1px solid var(--border);
    outline: none;
    background: #111d2e;
    color: var(--text);
    border-radius: 9px;
    padding: 12px 13px;
    min-height: 44px;
    transition: border .2s;
}

.field textarea {
    resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.filters input:focus,
.filters select:focus {
    border-color: var(--blue);
}

.field input::placeholder,
.field textarea::placeholder {
    color: #65748a;
}

.place-input {
    display: flex;
    gap: 8px;
}

.place-input input {
    flex: 1;
    min-width: 0;
}

.location-btn {
    background: var(--panel-light);
    border: 1px solid var(--border);
    color: var(--blue);
    border-radius: 9px;
    width: 46px;
    font-size: 23px;
}

.location-btn:disabled {
    opacity: .5;
    cursor: wait;
}

.place-status {
    color: var(--muted);
    font-size: 11px;
    margin-top: 7px;
}

.trip-result {
    padding: 14px;
    border-radius: 10px;
    margin: 12px 0 22px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #193b34;
    border: 1px solid #28624f;
}

.trip-result.normal {
    background: #193b34;
    border-color: #28624f;
}

.trip-result.trip {
    background: #44321e;
    border-color: #79512a;
}

.trip-result strong,
.trip-result small {
    display: block;
}

.trip-result strong {
    font-size: 13px;
}

.trip-result small {
    margin-top: 4px;
    color: #b4c1ce;
    font-size: 11px;
}

.trip-result span {
    font-size: 22px;
}

.hidden {
    display: none !important;
}

.subheading {
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 17px 0 13px;
    margin-top: 8px;
    border-top: 1px solid var(--border);
}

.subheading > span {
    background: #243c5d;
    color: var(--blue);
    width: 31px;
    height: 31px;
    border-radius: 9px;
    display: grid;
    place-items: center;
    font-weight: 800;
    font-size: 11px;
}

.subheading strong,
.subheading small {
    display: block;
}

.subheading strong {
    font-size: 13px;
}

.subheading small {
    color: var(--muted);
    font-size: 11px;
    margin-top: 3px;
}

.time-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 13px;
}

.calculation {
    background: #111d2e;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 17px;
    margin: 20px 0;
}

.calc-title {
    color: var(--blue);
    font-weight: 800;
    letter-spacing: 1px;
    font-size: 10px;
    margin-bottom: 14px;
}

.calc-row,
.calc-total {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 9px 0;
    color: var(--muted);
    font-size: 12px;
}

.calc-row strong {
    color: var(--text);
    text-align: right;
    white-space: nowrap;
}

.calc-total {
    border-top: 1px solid var(--border);
    margin-top: 7px;
    padding-top: 15px;
    color: var(--text);
    font-weight: 700;
    font-size: 13px;
}

.calc-total strong {
    color: var(--green);
    font-size: 19px;
    white-space: nowrap;
}

.primary-btn,
.secondary-btn {
    border: 0;
    border-radius: 10px;
    min-height: 46px;
    padding: 12px 17px;
    font-weight: 700;
    transition: .2s;
}

.primary-btn {
    background: var(--blue);
    color: white;
    width: 100%;
    font-size: 14px;
}

.primary-btn:hover {
    background: var(--blue-dark);
    transform: translateY(-1px);
}

.secondary-btn {
    background: var(--panel-light);
    border: 1px solid var(--border);
    color: #dce5f2;
}

.secondary-btn:hover {
    border-color: var(--blue);
}

#cancelEdit {
    width: 100%;
    margin-top: 9px;
}

.error {
    color: #ff9b9b;
    background: #442525;
    border: 1px solid #783b3b;
    padding: 12px;
    border-radius: 9px;
    margin-bottom: 13px;
    font-size: 12px;
}

.history-panel {
    margin-top: 18px;
}

.history-count {
    color: var(--muted);
    font-size: 11px;
}

.filters {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 17px;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 11px;
}

.history-card {
    background: #111d2e;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
}

.history-top {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    align-items: flex-start;
}

.history-place {
    font-size: 15px;
    font-weight: 800;
}
.history-date {
    color: var(--muted);
    font-size: 11px;
    margin-top: 5px;
}

.status-tag {
    font-size: 9px;
    padding: 6px 8px;
    border-radius: 6px;
    font-weight: 800;
    white-space: nowrap;
}

.status-tag.trip {
    color: var(--orange);
    background: #44321e;
}

.status-tag.normal {
    color: var(--green);
    background: #193b34;
}

.history-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 7px;
    margin-top: 17px;
    padding-top: 13px;
    border-top: 1px solid var(--border);
}

.history-stats span {
    color: var(--muted);
    font-size: 10px;
    display: block;
    margin-bottom: 5px;
}

.history-stats strong {
    font-size: 14px;
}

.history-extra {
    margin-top: 12px;
    padding-top: 11px;
    border-top: 1px solid var(--border);
    color: var(--muted);
    font-size: 11px;
    display: flex;
    justify-content: space-between;
    gap: 8px;
}

.history-extra strong {
    color: var(--text);
}

.history-actions {
    display: flex;
    gap: 8px;
    margin-top: 14px;
}

.history-actions button {
    flex: 1;
    background: var(--panel-light);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 9px;
    border-radius: 8px;
    font-size: 11px;
    font-weight: 700;
}

.history-actions button.delete {
    color: #ff9696;
}

.empty-state {
    text-align: center;
    padding: 38px 10px;
    color: var(--muted);
}

.empty-state span {
    font-size: 32px;
    display: block;
    margin-bottom: 12px;
}

.empty-state strong {
    color: var(--text);
    display: block;
}

.empty-state p {
    font-size: 12px;
}

.backup-description {
    color: var(--muted);
    font-size: 12px;
    line-height: 1.6;
}

.backup-buttons {
    display: flex;
    gap: 9px;
    flex-wrap: wrap;
}

footer {
    display: flex;
    justify-content: space-between;
    color: #617188;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 1px;
    padding: 10px 3px 20px;
}

.toast {
    position: fixed;
    bottom: 25px;
    left: 50%;
    transform: translate(-50%, 20px);
    background: #263950;
    border: 1px solid #3e5878;
    color: white;
    padding: 13px 20px;
    border-radius: 10px;
    opacity: 0;
    pointer-events: none;
    transition: .25s;
    z-index: 10;
    font-size: 12px;
    text-align: center;
    max-width: calc(100% - 30px);
}

.toast.show {
    opacity: 1;
    transform: translate(-50%, 0);
}


/* PAGINE */

.page {
    display: none;
}

.page.active-page {
    display: block;
}


/* HOME */

.home-menu {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.home-button {
    width: 100%;
    min-height: 82px;
    border: 1px solid var(--border);
    border-radius: 15px;
    background: var(--panel);
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px;
    text-align: left;
    transition: .2s;
}

.home-button:hover {
    border-color: var(--blue);
    transform: translateY(-1px);
}

.home-primary {
    min-height: 100px;
    background: linear-gradient(
        135deg,
        var(--panel),
        var(--panel-light)
    );
}

.home-row {
    display: grid;
    grid-template-columns: 1.55fr 1fr;
    gap: 12px;
}

.home-history,
.home-backup {
    min-height: 90px;
}

.home-button-icon {
    width: 43px;
    height: 43px;
    flex: 0 0 43px;
    border-radius: 11px;
    background: #243c5d;
    color: var(--blue);
    display: grid;
    place-items: center;
    font-size: 22px;
    font-weight: 700;
}

.home-button small {
    display: block;
    color: var(--blue);
    font-size: 9px;
    font-weight: 800;
    letter-spacing: 1px;
    margin-bottom: 4px;
}

.home-button strong {
    display: block;
    font-size: 16px;
}

.home-arrow {
    margin-left: auto;
    color: var(--muted);
    font-size: 27px;
    line-height: 1;
}


/* NAVIGAZIONE INFERIORE */

.bottom-nav {
    position: sticky;
    bottom: 14px;
    z-index: 5;

    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 5px;

    background: rgba(16, 24, 39, .96);
    border: 1px solid var(--border);
    border-radius: 15px;

    padding: 7px;
    margin: 18px 0 8px;

    backdrop-filter: blur(12px);
}

.bottom-nav button {
    border: 0;
    background: transparent;
    color: var(--muted);

    border-radius: 10px;

    min-height: 55px;
    padding: 6px 4px;

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

    gap: 2px;
}

.bottom-nav button span {
    font-size: 19px;
    line-height: 1;
}

.bottom-nav button small {
    font-size: 9px;
    font-weight: 700;
}

.bottom-nav button.active {
    color: var(--blue);
    background: var(--panel-light);
}

.bottom-nav button:active,
.home-button:active,
.primary-btn:active,
.secondary-btn:active {
    transform: scale(.98);
}


/* RESPONSIVE */

@media(max-width: 600px) {

    .app {
        padding: 23px 14px;
    }

    h1 {
        font-size: 25px;
    }

    .stats {
        grid-template-columns: 1fr 1fr;
        gap: 9px;
    }

    .stat-card {
        padding: 14px;
    }

    .stat-card strong {
        font-size: 22px;
    }

    .panel {
        padding: 17px;
        border-radius: 14px;
    }

    h2 {
        font-size: 19px;
    }

    .time-grid {
        gap: 9px;
    }

    .filters {
        grid-template-columns: 1fr;
    }

    .history-stats strong {
        font-size: 13px;
    }

    .backup-buttons > button {
        flex: 1;
    }

    .bottom-nav {
        bottom: 8px;
        margin-left: -1px;
        margin-right: -1px;
    }

    .bottom-nav button small {
        font-size: 8px;
    }

    .home-row {
        grid-template-columns: 1.45fr 1fr;
        gap: 9px;
    }

    .home-button {
        padding: 14px;
        gap: 10px;
    }

    .home-button strong {
        font-size: 14px;
    }

    .home-button-icon {
        width: 39px;
        height: 39px;
        flex-basis: 39px;
    }
}

@media(max-width: 350px) {

    .time-grid {
        grid-template-columns: 1fr;
    }

    .history-top {
        flex-direction: column;
    }
}


/* MAPPA */

.map-preview {
    margin-top: 13px;
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    background: #111d2e;
}

.map-preview iframe {
    display: block;
    width: 100%;
    height: 240px;
    border: 0;
}

.map-info {
    padding: 13px;
}

.map-info strong {
    display: block;
    font-size: 13px;
    margin-bottom: 5px;
}

.map-info small {
    color: var(--muted);
    display: block;
    font-size: 11px;
    line-height: 1.5;
}

.confirm-place-btn {
    width: 100%;
    margin-top: 12px;
    border: 0;
    background: var(--green);
    color: #10251f;
    font-weight: 800;
    border-radius: 9px;
    padding: 12px;
    min-height: 43px;
    cursor: pointer;
}

.confirm-place-btn:disabled {
    opacity: .6;
    cursor: default;
}

.map-confirmed {    color: var(--green) !important;
    font-weight: 700;
}


/* MODIFICHE NAVIGAZIONE FISSA E DETTAGLIO GIORNATA */

.app {
    padding-bottom: 110px;
}

.bottom-nav {
    position: fixed;
    left: 50%;
    bottom: 14px;
    width: min(802px, calc(100% - 48px));
    margin: 0;
    transform: translateX(-50%);
}

/* GIORNATE: solo le informazioni principali in una riga compatta */
.history-day-card {
    width: 100%;
    min-height: 47px;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto auto auto auto;
    align-items: center;
    gap: 10px;
    text-align: left;
    color: var(--text);
    background: #111d2e;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 7px 10px;
}

.history-day-card:active {
    transform: scale(.99);
}

.history-day-date {
    color: var(--blue);
    font-size: 10px;
    font-weight: 800;
    white-space: nowrap;
}

.history-day-client {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text);
    font-size: 11px;
    font-weight: 700;
}

.history-day-metric {
    display: inline-flex;
    align-items: baseline;
    gap: 3px;
    white-space: nowrap;
}

.history-day-metric small {
    color: var(--muted);
    font-size: 8px;
    font-weight: 800;
}

.history-day-metric strong {
    font-size: 11px;
}

.history-day-dot {
    width: 10px;
    height: 10px;
    flex: 0 0 10px;
    border-radius: 50%;
}

.history-day-dot.trip {
    background: var(--orange);
}

.history-day-dot.normal {
    background: var(--green);
}

.history-day-arrow {
    color: var(--blue);
    font-size: 18px;
    line-height: 1;
}

/* DETTAGLIO GIORNATA: mantiene il formato precedente, più leggibile */
.day-detail-modal {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 18px;
    background: rgba(0, 0, 0, .72);
}

.day-detail-card {
    width: min(100%, 620px);
    max-height: 88vh;
    overflow-y: auto;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 17px;
    padding: 21px;
}

.day-detail-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 15px;
    margin-bottom: 18px;
}

.day-detail-heading h2 {
    text-transform: capitalize;
}

.day-detail-close {
    width: 36px;
    height: 36px;
    flex: 0 0 36px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: var(--panel-light);
    color: var(--text);
    font-size: 23px;
    line-height: 1;
}

.day-detail-place {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    padding: 13px;
    margin-bottom: 17px;
    background: #111d2e;
    border: 1px solid var(--border);
    border-radius: 11px;
}

.day-detail-place > strong {
    font-size: 16px;
}

.day-detail-place > span:not(.status-tag) {
    color: var(--muted);
    font-size: 11px;
}

.day-detail-card h3 {
    margin: 19px 0 8px;
    font-size: 13px;
}

.day-detail-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 9px 0;
    border-bottom: 1px solid var(--border);
    color: var(--muted);
    font-size: 12px;
}

.day-detail-row strong {
    color: var(--text);
    text-align: right;
}

.day-detail-notes {
    color: var(--muted);
    font-size: 12px;
    line-height: 1.5;
    white-space: pre-wrap;
}

.day-detail-actions {
    margin-top: 18px;
}

@media(max-width: 600px) {
    .app {
        padding-bottom: 110px;
    }

    .bottom-nav {
        bottom: 8px;
        width: calc(100% - 28px);
        margin: 0;
    }

    .history-day-card {
        grid-template-columns: auto minmax(0, 1fr) auto auto auto auto;
        gap: 6px;
        min-height: 44px;
        padding: 7px 8px;
    }

    .history-day-date {
        font-size: 9px;
    }

    .history-day-client {
        font-size: 10px;
    }

    .history-day-metric small {
        font-size: 7px;
    }

    .history-day-metric strong {
        font-size: 10px;
    }

    .history-day-card .status-tag {
        font-size: 6px;
        padding: 3px 4px;
    }

    .history-day-arrow {
        font-size: 16px;
    }

    .day-detail-modal {
        align-items: flex-end;
        padding: 10px;
    }

    .day-detail-card {
        max-height: 90vh;
        padding: 17px;
    }
}

@media(max-width: 360px) {
    .history-day-card {
        grid-template-columns: auto minmax(0, 1fr) auto auto auto;
    }

    .history-day-arrow {
        display: none;
    }
}

/* CREAZIONE GIORNATA - PIU CHIARA E OTTIMIZZATA PER TELEFONO */
.dayForm .field {
    margin-bottom: 13px;
}

.dayForm label {
    display: block;
    margin-bottom: 6px;
    font-size: 11px;
    font-weight: 700;
}

.dayForm input,
.dayForm select,
.dayForm textarea {
    min-height: 44px;
}

.dayForm .subheading {
    margin-top: 12px;
    padding: 13px 0 9px;
}

.dayForm .subheading strong {
    font-size: 12px;
}

.dayForm .subheading small {
    font-size: 10px;
}

.dayForm .time-grid {
    gap: 9px;
}

.dayForm .calculation {
    margin: 15px 0 13px;
    padding: 12px;
    border-radius: 10px;
}

.dayForm .calc-title {
    margin-bottom: 6px;
    font-size: 9px;
}

.dayForm .calc-row {
    min-height: 32px;
    align-items: center;
    padding: 6px 0;
    font-size: 10px;
}

.dayForm .calc-row span {
    min-width: 0;
}

.dayForm .calc-row strong {
    font-size: 12px;
}

.dayForm .calc-total {
    align-items: center;
    gap: 8px;
    margin-top: 5px;
    padding-top: 10px;
    font-size: 11px;
}

.dayForm .calc-total strong {
    font-size: 18px;
}

.dayForm #saveBtn {
    margin-top: 2px;
}

@media(max-width: 600px) {
    .page[data-page="create"] .panel {
        padding: 14px;
    }

    .page[data-page="create"] .section-heading {
        margin-bottom: 13px;
    }

    .page[data-page="create"] .section-heading h2 {
        font-size: 19px;
    }

    .dayForm .field {
        margin-bottom: 11px;
    }

    .dayForm label {
        margin-bottom: 5px;
        font-size: 10px;
    }

    .dayForm input,
    .dayForm select,
    .dayForm textarea {
        min-height: 42px;
    }

    .dayForm .subheading {
        gap: 9px;
        padding: 11px 0 8px;
        margin-top: 9px;
    }

    .dayForm .subheading > span {
        width: 27px;
        height: 27px;
        border-radius: 8px;
        font-size: 9px;
    }

    .dayForm .subheading strong {
        font-size: 11px;
    }

    .dayForm .subheading small {
        margin-top: 2px;
        font-size: 9px;
    }

    .dayForm .time-grid {
        gap: 7px;
    }

    .dayForm .time-grid .field {
        min-width: 0;
    }

    .dayForm .time-grid label {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .dayForm .calculation {
        margin: 12px 0;
        padding: 10px;
    }

    .dayForm .calc-row {
        min-height: 30px;
        padding: 5px 0;
    }

    .dayForm .calc-row span {
        font-size: 9px;
    }

    .dayForm .calc-row strong {
        font-size: 11px;
    }

    .dayForm .calc-total {
        font-size: 10px;
        padding-top: 9px;
    }

    .dayForm .calc-total strong {
        font-size: 17px;
    }

    .dayForm .primary-btn,
    .dayForm .secondary-btn {
        min-height: 45px;
    }
}

@media(max-width: 360px) {
    .page[data-page="create"] .panel {
        padding: 12px;
    }

    .dayForm .time-grid {
        gap: 5px;
    }

    .dayForm .subheading small {
        display: none;
    }

    .dayForm .calc-row span {
        font-size: 8px;
    }
}
