/* ─── Area51 — Gestione Macchine Magazzino ─── */

#area51-view {
    padding: 0;
}

.area51-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px 12px;
    gap: 12px;
    flex-wrap: wrap;
    border-bottom: 1px solid #f1f5f9;
}

.area51-header h2 {
    margin: 0;
    font-size: 1.3rem;
    font-weight: 700;
    color: #1e293b;
}

.area51-header-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

/* ── Home — griglia sezioni ── */
.area51-home-grid {
    display: flex;
    flex-direction: column;
    gap: 0;
    padding: 12px 20px 24px;
    gap: 10px;
}

.stato-section-card {
    display: flex;
    align-items: center;
    gap: 16px;
    background: white;
    border: 1.5px solid #e2e8f0;
    border-radius: 14px;
    padding: 16px 18px;
    cursor: pointer;
    transition: box-shadow 0.18s, border-color 0.18s, transform 0.12s;
    user-select: none;
}

.stato-section-card:hover {
    box-shadow: 0 4px 18px rgba(0,0,0,0.09);
    transform: translateY(-1px);
}

.stato-section-card:active {
    transform: translateY(0);
}

.stato-section-card.empty {
    opacity: 0.55;
}

/* Colori accent per ogni sezione */
.stato-section-card.stato-valutazione  { border-left: 4px solid #94a3b8; }
.stato-section-card.stato-pronta       { border-left: 4px solid #22c55e; }
.stato-section-card.stato-demolire     { border-left: 4px solid #ef4444; }
.stato-section-card.stato-noleggiata   { border-left: 4px solid #3b82f6; }
.stato-section-card.stato-prestito     { border-left: 4px solid #a855f7; }
.stato-section-card.stato-venduta      { border-left: 4px solid #64748b; }

/* Sezione archivio collassabile nella list view */
.area51-archivio-section {
    margin: 0 20px 24px;
    border: 1.5px solid #e2e8f0;
    border-radius: 12px;
    overflow: hidden;
}

.area51-archivio-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: #f8fafc;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    color: #475569;
    user-select: none;
    transition: background 0.15s;
}

.area51-archivio-header:hover { background: #f1f5f9; }

.area51-archivio-count {
    background: #e2e8f0;
    color: #64748b;
    border-radius: 20px;
    padding: 1px 8px;
    font-size: 0.78rem;
    font-weight: 700;
}

.area51-archivio-toggle {
    margin-left: auto;
    font-size: 0.7rem;
    color: #94a3b8;
    transition: transform 0.2s;
}

.area51-archivio-section.open .area51-archivio-toggle {
    transform: rotate(90deg);
}

.area51-archivio-list {
    display: none;
    padding: 10px 12px;
    background: white;
}

.area51-archivio-section.open .area51-archivio-list {
    display: block;
}

.ssc-icon {
    font-size: 2rem;
    flex-shrink: 0;
    width: 44px;
    text-align: center;
}

.ssc-body {
    flex: 1;
    min-width: 0;
}

.ssc-label {
    font-weight: 700;
    font-size: 1rem;
    color: #1e293b;
    margin-bottom: 2px;
}

.ssc-desc {
    font-size: 0.8rem;
    color: #94a3b8;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ssc-count {
    font-size: 1.6rem;
    font-weight: 800;
    color: #1e293b;
    min-width: 36px;
    text-align: right;
    flex-shrink: 0;
}

.stato-section-card.empty .ssc-count {
    color: #cbd5e1;
}

/* ── Lista per stato ── */
.area51-list-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    border-bottom: 1px solid #f1f5f9;
    flex-wrap: wrap;
}

.btn-back {
    background: #f1f5f9;
    border: none;
    border-radius: 8px;
    padding: 7px 14px;
    font-size: 0.85rem;
    font-weight: 600;
    color: #475569;
    cursor: pointer;
    transition: background 0.15s;
    flex-shrink: 0;
}

.btn-back:hover { background: #e2e8f0; }

.area51-list-title {
    font-weight: 700;
    font-size: 1rem;
    color: #1e293b;
    flex: 1;
}

.area51-list-count {
    font-size: 0.82rem;
    color: #94a3b8;
    font-weight: 600;
    flex-shrink: 0;
}

/* ── Lista macchine ── */
.area51-list {
    padding: 12px 20px 24px;
    display: grid;
    gap: 10px;
}

/* ── Card macchina ── */
.machine-card {
    background: white;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
    padding: 14px 16px;
    display: flex;
    align-items: flex-start;
    gap: 14px;
    cursor: pointer;
    transition: box-shadow 0.2s, border-color 0.2s;
}

.machine-card:hover {
    box-shadow: 0 4px 16px rgba(0,0,0,0.08);
    border-color: #a5b4fc;
}

.machine-thumb {
    width: 72px;
    height: 72px;
    border-radius: 8px;
    background: #f1f5f9;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #94a3b8;
    font-size: 2rem;
    overflow: hidden;
}

.machine-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 8px;
}

.machine-info {
    flex: 1;
    min-width: 0;
}

.machine-title {
    font-weight: 700;
    font-size: 1rem;
    color: #1e293b;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.machine-sub {
    font-size: 0.8rem;
    color: #64748b;
    margin-bottom: 6px;
}

.machine-client {
    font-size: 0.78rem;
    color: #94a3b8;
}

.machine-extra-info {
    font-size: 0.8rem;
    color: #475569;
    font-weight: 600;
    margin-top: 4px;
}

/* Badge stato */
.stato-badge {
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
    flex-shrink: 0;
}

.stato-badge.stato-valutazione    { background: #f1f5f9; color: #475569; }
.stato-badge.stato-pronta         { background: #f0fdf4; color: #16a34a; }
.stato-badge.stato-demolire       { background: #fef2f2; color: #dc2626; }
.stato-badge.stato-demolita       { background: #fef2f2; color: #9f1239; opacity: 0.8; }
.stato-badge.stato-noleggiata     { background: #eff6ff; color: #1d4ed8; }
.stato-badge.stato-noleggio-term  { background: #eff6ff; color: #1e40af; opacity: 0.7; }
.stato-badge.stato-prestito       { background: #faf5ff; color: #7c3aed; }
.stato-badge.stato-prestito-rest  { background: #faf5ff; color: #6d28d9; opacity: 0.7; }
.stato-badge.stato-venduta        { background: #f8fafc; color: #64748b; }

/* Pulsante aggiungi */
.btn-add-machine {
    background: #6366f1;
    color: white;
    border: none;
    border-radius: 8px;
    padding: 9px 16px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: background 0.2s;
}

.btn-add-machine:hover { background: #4f46e5; }

.btn-scan-qr {
    background: #0f766e;
    color: white;
    border: none;
    border-radius: 8px;
    padding: 9px 16px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: background 0.2s;
}
.btn-scan-qr:hover { background: #0d9488; }

.btn-print-qr {
    background: #f1f5f9;
    color: #475569;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    padding: 8px 14px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
}
.btn-print-qr:hover { background: #e2e8f0; }

/* Scanner overlay */
.area51-scanner-box {
    background: white;
    border-radius: 16px;
    padding: 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    max-width: 500px;
    width: 100%;
    margin: auto;
}

/* Modal scheda macchina */
.machine-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 1000;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 20px;
    overflow-y: auto;
}

.machine-modal {
    background: white;
    border-radius: 16px;
    width: 100%;
    max-width: 680px;
    padding: 24px;
    position: relative;
    margin: auto;
}

.machine-modal-title {
    font-size: 1.2rem;
    font-weight: 700;
    margin-bottom: 20px;
    color: #1e293b;
}

.machine-modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    background: none;
    border: none;
    font-size: 1.4rem;
    cursor: pointer;
    color: #64748b;
    line-height: 1;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 12px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

/* Evita overflow orizzontale del modal su mobile: i grid item devono poter
   restringersi sotto il min-content dei <select> con opzioni lunghe
   (Motivo ritiro, Stato), altrimenti il modal sfora la viewport. */
.machine-modal .form-row,
.machine-modal .form-group {
    min-width: 0;
}
.machine-modal input,
.machine-modal select,
.machine-modal textarea {
    min-width: 0;
    max-width: 100%;
}

.form-group label {
    font-size: 0.8rem;
    font-weight: 600;
    color: #475569;
}

.form-group input,
.form-group select,
.form-group textarea {
    padding: 8px 10px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    font-size: 0.9rem;
    color: #1e293b;
    background: white;
}

.form-group textarea { resize: vertical; min-height: 70px; }

/* Campi stato extra */
.stato-extra-section {
    background: #f8fafc;
    border-radius: 10px;
    padding: 12px;
    margin: 12px 0;
    display: none;
}

.stato-extra-section.visible { display: block; }

/* Galleria foto */
.photo-gallery {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin: 8px 0;
}

.photo-item {
    position: relative;
    display: inline-block;
}

.photo-thumb {
    width: 90px;
    height: 90px;
    border-radius: 8px;
    object-fit: cover;
    border: 2px solid #e2e8f0;
    cursor: pointer;
    display: block;
}

.photo-delete-btn {
    position: absolute;
    top: 2px;
    right: 2px;
    background: #ef4444;
    color: white;
    border: none;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 0.65rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.btn-upload-photo {
    width: 90px;
    height: 90px;
    border: 2px dashed #cbd5e1;
    border-radius: 8px;
    background: #f8fafc;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #94a3b8;
    font-size: 0.75rem;
    gap: 4px;
    transition: border-color 0.2s;
}

.btn-upload-photo:hover { border-color: #6366f1; color: #6366f1; }

/* Actions modal */
.machine-modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 20px;
    flex-wrap: wrap;
}

.btn-save {
    background: #6366f1;
    color: white;
    border: none;
    border-radius: 8px;
    padding: 10px 20px;
    font-weight: 600;
    cursor: pointer;
}
.btn-save:hover { background: #4f46e5; }

.btn-cancel {
    background: #f1f5f9;
    color: #475569;
    border: none;
    border-radius: 8px;
    padding: 10px 20px;
    font-weight: 600;
    cursor: pointer;
}

.btn-delete-machine {
    background: #fef2f2;
    color: #dc2626;
    border: 1px solid #fca5a5;
    border-radius: 8px;
    padding: 10px 20px;
    font-weight: 600;
    cursor: pointer;
}

/* Empty state */
.area51-empty {
    text-align: center;
    padding: 48px 20px;
    color: #94a3b8;
}

.area51-empty .empty-icon {
    font-size: 3rem;
    margin-bottom: 12px;
}

.area51-empty p {
    font-size: 1rem;
}

.area51-loading {
    padding: 40px;
    text-align: center;
    color: #94a3b8;
    font-size: 0.9rem;
}

/* Ticket preview */
.ticket-preview-box {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 14px;
    font-size: 0.85rem;
}
.ticket-preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}
.ticket-preview-num {
    font-weight: 700;
    font-size: 0.95rem;
    color: #1e293b;
}
.ticket-preview-status {
    background: #e0f2fe;
    color: #0369a1;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.75rem;
    font-weight: 600;
}
.ticket-preview-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    color: #64748b;
    font-size: 0.8rem;
    margin-bottom: 8px;
}
.ticket-preview-problem {
    background: #fff7ed;
    border-left: 3px solid #fb923c;
    padding: 6px 10px;
    border-radius: 4px;
    margin-bottom: 10px;
    font-size: 0.82rem;
    color: #7c2d12;
}
.ticket-preview-section {
    margin-top: 10px;
}
.ticket-preview-section > strong {
    display: block;
    color: #475569;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 6px;
}
.ticket-preview-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}
.ticket-preview-table th {
    background: #f1f5f9;
    padding: 4px 8px;
    text-align: left;
    font-weight: 600;
    color: #475569;
}
.ticket-preview-table td {
    padding: 4px 8px;
    border-bottom: 1px solid #f1f5f9;
    color: #1e293b;
}
.ticket-preview-table tfoot td {
    background: #f8fafc;
    font-size: 0.82rem;
}
.rf-badge {
    padding: 1px 6px;
    border-radius: 8px;
    font-size: 0.72rem;
    font-weight: 700;
}
.rf-r { background: #dcfce7; color: #166534; }
.rf-f { background: #dbeafe; color: #1e40af; }

/* Responsive */
@media (max-width: 480px) {
    .form-row {
        grid-template-columns: 1fr;
    }
    .ssc-desc {
        display: none;
    }
    .area51-home-grid {
        padding: 10px 12px 20px;
    }
    .area51-list {
        padding: 10px 12px 20px;
    }
}
