@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;700&family=Space+Grotesk:wght@400;700&display=swap');

/* --- VARIABILI & RESET --- */
:root {
    --primary-color: #6699aa;
    --orange-color:  #f97316;
    --green-color:   #16a34a;
    --red-color:     #dc2626;
    --bg-color:      #f9fafb;
    --text-main:     #1f2937;
    --text-muted:    #6b7280;
    --border-color:  #e5e7eb;
}

*, *::before, *::after { box-sizing: border-box; }

body {
    font-family: 'Inter', 'Space Grotesk', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    line-height: 1.5;
    margin: 0;
    padding: 16px;
}

/* Centrato su desktop */
.page-wrapper {
    max-width: 600px;
    margin: 0 auto;
}

h1, h2, h3, h4, h5, h6 { font-weight: 700; }

@media (min-width: 600px) {
    body {
        padding: 32px 16px;
    }
}

/* --- HEADER --- */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 24px;
}

.header-left { display: flex; align-items: center; gap: 8px; }

.brand-label {
    color: var(--primary-color);
    font-weight: 800;
    font-size: 20px;
    letter-spacing: -0.5px;
}

.app-sub-title {
    color: var(--text-muted);
    font-size: 14px;
    font-weight: 400;
    margin-left: 4px;
    border-left: 1px solid var(--border-color);
    padding-left: 8px;
}

.app-sub-title-mobile {
    display: none;
}

@media (max-width: 520px) {
    .app-sub-title {
        font-size: 12px;
        padding-left: 6px;
        margin-left: 2px;
    }
    .app-sub-title-desktop {
        display: none;
    }
    .app-sub-title-mobile {
        display: inline;
    }
}

.logout-link { font-size: 14px; color: var(--primary-color); text-decoration: none; }

/* --- FLASH MESSAGES --- */
.flash-messages { margin-bottom: 16px; }

.alert {
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 14px;
    margin-bottom: 8px;
}

.alert-error {
    background-color: #fef2f2;
    border: 1px solid #fecaca;
    color: #991b1b;
}

.alert-success {
    background-color: #f0fdf4;
    border: 1px solid #bbf7d0;
    color: #166534;
}

/* --- CARDS --- */
.card {
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.card-title {
    margin-top: 0;
    margin-bottom: 12px;
    font-size: 16px;
    color: var(--text-muted);
    font-weight: 600;
}

/* --- BADGES --- */
.badge {
    padding: 4px 12px;
    border-radius: 99px;
    font-size: 12px;
    font-weight: 600;
    color: #ffffff;
    white-space: nowrap;
}
.badge-arancione { background-color: var(--orange-color); }
.badge-viola     { background-color: var(--primary-color); }
.badge-verde     { background-color: var(--green-color); }
.badge-rosso     { background-color: var(--red-color); }
.badge-grigio    { background-color: var(--text-muted); }

/* --- INTESTAZIONE PRATICA --- */
.pratica-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}
.pratica-title { margin: 0; font-size: 20px; }

/* --- TABELLA PRODOTTI --- */
.prodotti-table { width: 100%; border-collapse: collapse; margin-top: 10px; }
.prodotti-table td { padding: 8px 0; font-size: 15px; }
.prodotti-table tr { border-bottom: 1px solid #f3f4f6; }
.prodotti-table .qty { text-align: right; font-weight: bold; }

/* --- FORM ELEMENTS --- */
label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 6px;
    margin-top: 14px;
}

input[type="text"],
input[type="password"],
input[type="date"],
input[type="datetime-local"],
select,
textarea {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    font-size: 16px;  /* evita zoom iOS */
    font-family: inherit;
    background: #fff;
    color: var(--text-main);
}

/* Contesto chiaro per controlli nativi (calendario, select) */
#form-appuntamento,
#form-chiudi {
    color-scheme: light;
}

/* Picker nativo (data / datetime): colore accento ~ brand #6699aa.
   In Chromium/Edge la selezione nel calendario popup segue accent-color.
   Safari/macOS e alcuni temi possono ignorare in parte: limite del motore. */
input[type="date"],
input[type="datetime-local"] {
    accent-color: var(--primary-color) !important;
    color-scheme: light;
}

/* Ora/min appuntamento desktop: stesso accento del bottone Conferma */
#form-appuntamento select.date-display-input {
    accent-color: var(--primary-color) !important;
    color-scheme: light;
}

/* Icona calendario WebKit → tonalità vicina a --primary-color */
input[type="date"]::-webkit-calendar-picker-indicator,
input[type="datetime-local"]::-webkit-calendar-picker-indicator {
    cursor: pointer;
    opacity: 0.92;
    filter: invert(58%) sepia(20%) saturate(480%) hue-rotate(152deg) brightness(94%) contrast(88%);
}

textarea { resize: vertical; }

.radio-group {
    display: flex;
    gap: 20px;
    margin-top: 8px;
}
.radio-group label {
    margin: 0;
    font-weight: normal;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* --- BUTTONS --- */
.btn-primary {
    width: 100%;
    padding: 14px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    font-size: 16px;
    margin-top: 20px;
    cursor: pointer;
}

.btn-outline {
    width: 100%;
    padding: 12px;
    background: transparent;
    color: var(--primary-color);
    border: 1px solid var(--primary-color);
    border-radius: 8px;
    font-weight: 600;
    font-size: 15px;
    margin-top: 10px;
    cursor: pointer;
    text-decoration: none;
    display: block;
    text-align: center;
}

.btn-primary:active,
.btn-outline:active { opacity: 0.85; }

/* --- LINK TORNA INDIETRO --- */
.back-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 14px;
    color: var(--primary-color);
    text-decoration: none;
    margin-bottom: 20px;
}

/* --- RIEPILOGO READ-ONLY --- */
.card-completata { border-left: 4px solid var(--green-color); }
.card-ko         { border-left: 4px solid var(--red-color); }
.card-rifiutato  { border-left: 4px solid var(--text-muted); }

.riepilogo-row { margin: 8px 0; font-size: 15px; }

/* --- DATE DISPLAY INPUT --- */
.date-display-input {
    background: #fafaff;
    cursor: pointer;
    text-align: center;
    font-weight: 500;
    color: var(--primary-color);
    border: 1.5px solid rgba(102, 153, 170, 0.22);
    border-radius: 12px;
    box-shadow: 0 1px 4px rgba(102, 153, 170, 0.07);
    transition: border-color 0.2s, box-shadow 0.2s;
}
.date-display-input:focus {
    outline: none;
    border-color: rgba(102, 153, 170, 0.55);
    box-shadow: 0 0 0 3px rgba(102, 153, 170, 0.10);
}

/* --- iOS PICKER --- */
.ios-picker-overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    align-items: flex-end;
    z-index: 1000;
}

.ios-picker-container {
    background: #fff;
    width: 100%;
    border-radius: 20px 20px 0 0;
    padding-bottom: env(safe-area-inset-bottom, 20px);
    animation: slideUp 0.3s ease-out;
}

.ios-picker-header {
    display: flex;
    justify-content: space-between;
    padding: 15px 20px;
    border-bottom: 1px solid #eee;
}

.ios-picker-btn-cancel { color: #94a3b8; border: none; background: none; font-size: 17px; cursor: pointer; }
.ios-picker-btn-confirm { color: var(--primary-color); font-weight: bold; border: none; background: none; font-size: 17px; cursor: pointer; }

.ios-picker-wheels {
    display: flex;
    height: 200px;
    position: relative;
    overflow: hidden;
}

/* Fade visivo top/bottom senza mask-image (che blocca pointer-events nelle zone trasparenti) */
.ios-picker-wheels::before,
.ios-picker-wheels::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    height: 40%;
    z-index: 2;
    pointer-events: none;
}
.ios-picker-wheels::before {
    top: 0;
    background: linear-gradient(to bottom, #ffffff, rgba(255,255,255,0));
}
.ios-picker-wheels::after {
    bottom: 0;
    background: linear-gradient(to top, #ffffff, rgba(255,255,255,0));
}

.wheel {
    flex: 1;
    overflow-y: scroll;
    scroll-snap-type: y mandatory;
    text-align: center;
    scrollbar-width: none;
}
.wheel::-webkit-scrollbar { display: none; }

.wheel-item {
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    scroll-snap-align: center;
    font-size: 18px;
}

.picker-highlight {
    position: absolute;
    top: 80px;
    width: 100%;
    height: 40px;
    border-top: 1px solid #ddd;
    border-bottom: 1px solid #ddd;
    pointer-events: none;
    background: rgba(102, 153, 170, 0.05);
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to   { transform: translateY(0); }
}

/* --- LOGIN PAGE --- */
.login-container {
    max-width: 400px;
    margin: 40px auto 0;
}

.login-title {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 4px;
}

.login-subtitle {
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 24px;
}

.login-help {
    margin-top: 16px;
    font-size: 13px;
    color: var(--text-muted);
    text-align: center;
}

/* --- QUANTITÀ PREVISTA (suffix /N nella tabella riepilogo) --- */
.qty-max {
    font-size: 12px;
    font-weight: 400;
    color: var(--text-muted);
    margin-left: 2px;
}

/* --- MATERIALE INSTALLATO NEL RIEPILOGO --- */
.riepilogo-divider {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 16px 0;
}

.riepilogo-materiali-label {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-muted);
    margin: 0 0 10px;
}

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

.riepilogo-materiali-table thead th {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-align: right;
    padding: 0 0 6px;
}

.riepilogo-materiali-table thead th:first-child {
    text-align: left;
}

.riepilogo-materiali-table tbody td {
    font-size: 15px;
    padding: 8px 0;
    text-align: right;
    border-top: 1px solid #f3f4f6;
}

.riepilogo-materiali-table tbody td:first-child {
    text-align: left;
}

/* --- QUANTITÀ INSTALLATE --- */
.prodotto-qty-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.prodotto-qty-row .prodotto-nome {
    flex: 1;
    font-size: 14px;
    color: var(--text-main);
}

.prodotto-qty-row .prodotto-nome small {
    color: var(--text-muted);
}

.input-quantita {
    width: 90px;
    flex-shrink: 0;
    padding: 8px 10px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 15px;
    text-align: center;
}

/* Ampliamento table */
.amp-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
    margin-top: 8px;
}
.amp-table th {
    text-align: left;
    font-size: 12px;
    padding: 4px 6px;
    color: var(--text-muted);
    font-weight: 500;
    border-bottom: 1px solid #e5e7eb;
}
.amp-table td {
    padding: 4px 4px;
    vertical-align: middle;
}
.amp-codice-display {
    background: #f3f4f6;
    font-size: 13px;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    padding: 6px 8px;
    width: 100%;
    min-width: 90px;
}
.amp-select {
    width: 100%;
    min-width: 140px;
    font-size: 14px;
}
.amp-qty {
    width: 60px !important;
    min-width: unset;
}
.btn-amp-add,
.btn-amp-del {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    border: none;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: auto;
}
.btn-amp-add { background: var(--primary-color); color: #fff; }
.btn-amp-del { background: var(--red-color);     color: #fff; }
