/* ============================================================
   GestImpianti - Stili Principali
   ============================================================ */

:root {
    --sidebar-width: 230px;
    --sidebar-bg: #1e2a3a;
    --sidebar-hover: #2d3f55;
    --sidebar-active: #0d6efd;
}

/* ---- Allegati dropzone ---- */
.dropzone-area {
    border: 2px dashed #0d6efd;
    border-radius: 8px;
    background: #f0f5ff;
    text-align: center;
    padding: 2rem 1rem;
    color: #0d6efd;
    font-size: .9rem;
    margin: 0.75rem;
    pointer-events: none;
}
#card-allegati.drag-over .dropzone-area { display: flex !important; flex-direction: column; align-items: center; justify-content: center; }
#card-allegati.drag-over .card-body     { display: none; }
.allegato-row:last-child { border-bottom: none !important; }

/* ---- Autocomplete cliente ---- */
.cliente-autocomplete-wrap {
    position: relative;
}
.cliente-autocomplete-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 1060;
    background: #fff;
    border: 1px solid #dee2e6;
    border-top: none;
    border-radius: 0 0 6px 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,.12);
    max-height: 220px;
    overflow-y: auto;
    display: none;
}
.cliente-autocomplete-dropdown .ac-item {
    padding: 6px 10px;
    cursor: pointer;
    font-size: .875rem;
    border-bottom: 1px solid #f0f0f0;
}
.cliente-autocomplete-dropdown .ac-item:last-child { border-bottom: none; }
.cliente-autocomplete-dropdown .ac-item:hover,
.cliente-autocomplete-dropdown .ac-item.ac-active { background: #e9f0ff; }
.cliente-autocomplete-dropdown .ac-empty {
    padding: 8px 10px;
    color: #6c757d;
    font-size: .8rem;
    font-style: italic;
}

/* ---- Sidebar ---- */
.sidebar {
    background-color: var(--sidebar-bg) !important;
    min-height: calc(100vh - 56px);
    flex-shrink: 0;
}

.sidebar-section {
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    color: #6c8099;
    text-transform: uppercase;
    padding: 1rem 1rem 0.3rem;
    margin-top: 0.5rem;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.55rem 1rem;
    color: #b0c4d8;
    text-decoration: none;
    font-size: 0.875rem;
    border-radius: 6px;
    margin: 2px 8px;
    transition: all 0.15s ease;
}

.sidebar-link:hover {
    background-color: var(--sidebar-hover);
    color: #fff;
}

.sidebar-link.active {
    background-color: var(--sidebar-active);
    color: #fff;
    font-weight: 600;
}

.sidebar-link i {
    width: 18px;
    text-align: center;
    font-size: 0.95rem;
    flex-shrink: 0;
}

.sidebar-link .badge {
    margin-left: auto;
}

/* ---- Pagine ---- */
.page-header {
    background: #fff;
    border-bottom: 1px solid #e5e7eb;
    padding: 1rem 1.5rem;
}

.page-header h1 {
    font-size: 1.4rem;
    font-weight: 700;
    margin: 0;
    color: #1e2a3a;
}

.page-body {
    padding: 1.5rem;
}

/* ---- Card Stats ---- */
.stat-card {
    border: none;
    border-radius: 12px;
    transition: transform 0.15s ease;
}

.stat-card:hover {
    transform: translateY(-2px);
}

.stat-card .stat-icon {
    width: 52px;
    height: 52px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
}

.stat-card .stat-value {
    font-size: 2rem;
    font-weight: 700;
    line-height: 1.1;
}

.stat-card .stat-label {
    font-size: 0.8rem;
    color: #6c757d;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ---- Tabelle ---- */
.table th {
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #6c757d;
    border-top: none;
    background-color: #f8f9fa;
}

.table td {
    vertical-align: middle;
    font-size: 0.9rem;
}

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

/* ---- Calendario ---- */
#calendar {
    background: #fff;
    border-radius: 12px;
    padding: 1rem;
    box-shadow: 0 1px 4px rgba(0,0,0,0.07);
}

.fc-event {
    cursor: pointer;
    border-radius: 4px !important;
    padding: 1px 4px !important;
    font-size: 0.82rem !important;
}

.fc-event:hover {
    opacity: 0.9;
}

.fc-toolbar-title {
    font-size: 1.2rem !important;
    font-weight: 700 !important;
}

/* ---- Form e Modal ---- */
.modal-header {
    background-color: #f8f9fa;
    border-bottom: 1px solid #dee2e6;
}

label.form-label {
    font-size: 0.82rem;
    font-weight: 600;
    color: #374151;
    margin-bottom: 0.25rem;
}

/* ---- Magazzino scorta ---- */
.scorta-ok    { color: #198754; font-weight: 600; }
.scorta-bassa { color: #dc3545; font-weight: 600; }
.scorta-warn  { color: #fd7e14; font-weight: 600; }

/* ---- Badge priorità ---- */
.badge { font-size: 0.72rem; font-weight: 600; letter-spacing: 0.03em; }

/* ---- Checklist attività ---- */
.attivita-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid #f0f0f0;
}

.attivita-item:last-child { border-bottom: none; }

.attivita-completata .attivita-text {
    text-decoration: line-through;
    color: #9ca3af;
}

/* ---- Prodotti intervento ---- */
.prodotto-card {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 0.75rem 1rem;
    margin-bottom: 0.5rem;
    border-left: 3px solid #0d6efd;
}

/* ---- Ordini ---- */
.ordine-stato-bozza    { border-left: 4px solid #6c757d; }
.ordine-stato-inviato  { border-left: 4px solid #0dcaf0; }
.ordine-stato-parziale { border-left: 4px solid #ffc107; }
.ordine-stato-completato { border-left: 4px solid #198754; }
.ordine-stato-annullato  { border-left: 4px solid #dc3545; }

/* ---- Sidebar overlay (mobile) ---- */
#sidebarOverlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.55);
    z-index: 1040;
}
#sidebarOverlay.active { display: block; }

/* ---- Responsive ---- */
@media (max-width: 767.98px) {
    /* Sidebar off-canvas */
    #mainSidebar {
        position: fixed !important;
        top: 56px;
        left: 0;
        bottom: 0;
        z-index: 1045;
        width: 240px !important;
        min-width: 240px !important;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        overflow-y: auto;
    }
    #mainSidebar.sidebar-open {
        transform: translateX(0);
    }

    /* Contenuto occupa tutta la larghezza */
    .d-flex > main.flex-grow-1 {
        width: 100% !important;
    }

    /* Spaziatura ridotta */
    .page-body {
        padding: 0.75rem 0.5rem;
    }
    .page-header {
        padding: 0.6rem 0.75rem;
    }
    .page-header h1 {
        font-size: 1.1rem;
    }
    .page-header .btn {
        padding: 0.35rem 0.65rem;
        font-size: 0.85rem;
    }

    /* Bottoni touch più grandi */
    .btn-action {
        padding: 0.4rem 0.7rem;
        font-size: 0.875rem;
        min-height: 36px;
    }
    .btn {
        min-height: 38px;
    }
    .btn-sm {
        min-height: 32px;
    }

    /* Card stats */
    .stat-card .stat-value {
        font-size: 1.5rem;
    }
    .stat-card .card-body {
        padding: 0.75rem;
    }
    .stat-icon {
        width: 36px !important;
        height: 36px !important;
        font-size: 1rem !important;
    }

    /* Header calendario: stack verticale */
    .page-header.flex-wrap .d-flex.gap-2 {
        flex-wrap: wrap;
        width: 100%;
    }
    .page-header.flex-wrap .d-flex.gap-2 .form-select {
        flex: 1;
        min-width: 0 !important;
    }

    /* FullCalendar mobile */
    .fc .fc-toolbar-title {
        font-size: 1rem !important;
    }
    .fc .fc-button {
        padding: 0.3rem 0.5rem !important;
        font-size: 0.8rem !important;
    }
    .fc .fc-list-event-title a {
        font-size: 0.9rem;
    }

    /* Tabelle: scroll orizzontale */
    .table-responsive {
        -webkit-overflow-scrolling: touch;
    }
    .table td, .table th {
        white-space: nowrap;
        font-size: 0.85rem;
        padding: 0.45rem 0.6rem;
    }

    /* Form inputs più alti per touch */
    .form-control, .form-select {
        min-height: 42px;
        font-size: 1rem;
    }
    .form-label {
        font-size: 0.9rem;
        margin-bottom: 0.25rem;
    }

    /* Modal full-screen */
    .modal-dialog {
        margin: 0.25rem;
        max-width: calc(100vw - 0.5rem);
    }
    .modal-dialog-scrollable .modal-body {
        max-height: calc(100vh - 140px);
    }
    .modal-header {
        padding: 0.75rem 1rem;
    }
    .modal-footer {
        padding: 0.5rem 0.75rem;
        gap: 0.4rem;
    }
    .modal-footer .btn {
        flex: 1;
    }

    /* Card intervento dettaglio: stack verticale */
    .card-body .row.g-3 > [class^="col-"] {
        margin-bottom: 0;
    }

    /* Sidebar link area più alta */
    .sidebar-link {
        padding: 0.65rem 1.2rem;
        font-size: 0.95rem;
    }

    /* Nascondi colonne non essenziali nelle liste interventi */
    .table .col-hide-mobile {
        display: none;
    }

    /* Badge e label */
    .badge {
        font-size: 0.75rem;
        padding: 0.3em 0.55em;
    }

    /* Gap ridotto nelle griglie */
    .row.g-4 {
        --bs-gutter-x: 0.75rem;
        --bs-gutter-y: 0.75rem;
    }
    .row.g-3 {
        --bs-gutter-x: 0.5rem;
        --bs-gutter-y: 0.5rem;
    }
}

/* ---- Utility ---- */
.btn-action { padding: 0.25rem 0.5rem; font-size: 0.8rem; }
.text-nowrap { white-space: nowrap; }
.cursor-pointer { cursor: pointer; }

/* ---- Loading overlay ---- */
.loading-overlay {
    position: fixed; inset: 0;
    background: rgba(255,255,255,0.7);
    display: flex; align-items: center; justify-content: center;
    z-index: 9999;
    display: none;
}

/* ---- Nominatim address autocomplete ---- */
.nominatim-drop {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 1060;
    background: #fff;
    border: 1px solid #ced4da;
    border-top: none;
    border-radius: 0 0 6px 6px;
    box-shadow: 0 6px 16px rgba(0,0,0,0.12);
    max-height: 220px;
    overflow-y: auto;
}
.nominatim-item {
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
    outline: none;
    line-height: 1.35;
}
.nominatim-item:last-child { border-bottom: none; }
.nominatim-item:hover,
.nominatim-item:focus { background: #f0f7ff; color: #0d6efd; }

/* Giorni bloccati nel calendario */
.fc-giorno-bloccato { opacity: 0.55 !important; }
.fc .fc-daygrid-day.fc-day-blocked { background: rgba(220,53,69,.08) !important; }
