/* =====================================================================
   Gestionale Clienti - Foglio di stile (tema chiaro, responsive)
   ===================================================================== */
:root {
    --bg:          #f4f6fb;
    --surface:     #ffffff;
    --border:      #e2e6ef;
    --text:        #2b3040;
    --muted:       #79808f;
    --primary:     #3b6ef6;
    --primary-dk:  #2f5ad6;
    --danger:      #e0554d;
    --danger-dk:   #c8443d;
    --success-bg:  #e6f6ec;
    --success-tx:  #1f7a45;
    --error-bg:    #fdeceb;
    --error-tx:    #b23b34;
    --radius:      12px;
    --shadow:      0 1px 3px rgba(30, 40, 70, .06), 0 6px 20px rgba(30, 40, 70, .05);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 1.5rem; margin: 0 0 .25rem; }
h1, h2, h3 { color: var(--text); }

.muted { color: var(--muted); margin: .25rem 0; }
.hint  { color: var(--muted); font-weight: 400; font-size: .8rem; }

/* ---------- Topbar ---------- */
.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 20;
}
.topbar-inner {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 60px;
}
.brand {
    font-weight: 700;
    font-size: 1.15rem;
    color: var(--text);
    display: flex;
    align-items: center;
}
.brand img { height: 32px; width: auto; max-width: 190px; object-fit: contain; display: block; }
.brand:hover { text-decoration: none; }
.auth-logo { display: block; width: auto; max-width: 170px; height: auto; margin: 0 auto 10px; }
.menu-toggle {
    margin-left: auto;
    display: none;
    background: none;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1.3rem;
    padding: 4px 10px;
    cursor: pointer;
    color: var(--text);
}
.topnav {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 18px;
}
.topnav a { color: var(--text); font-weight: 500; }
.topnav-user { color: var(--muted); }
.topnav-logout { color: var(--danger) !important; }
.topnav-install {
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 7px 12px;
    font-weight: 600;
    font-size: .9rem;
    cursor: pointer;
    font-family: inherit;
}
.topnav-install:hover { background: var(--primary-dk); }

/* ---------- Layout ---------- */
.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 24px 16px 60px;
}
.page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

/* ---------- Bottoni ---------- */
.btn {
    display: inline-block;
    border: 1px solid transparent;
    border-radius: 9px;
    padding: 9px 16px;
    font-size: .92rem;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    transition: background .15s, border-color .15s;
    white-space: nowrap;
    font-family: inherit;
    line-height: 1.25;
    vertical-align: middle;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dk); color: #fff; }
.btn-light { background: #eef1f7; color: var(--text); border-color: var(--border); }
.btn-light:hover { background: #e4e8f1; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-dk); }
.btn-sm { padding: 6px 11px; font-size: .82rem; }
.btn-block { width: 100%; }

/* ---------- Alert ---------- */
.alert {
    padding: 12px 16px;
    border-radius: 10px;
    margin-bottom: 18px;
    font-size: .93rem;
}
.alert ul { margin: 8px 0 0; padding-left: 20px; }
.alert-success { background: var(--success-bg); color: var(--success-tx); }
.alert-error   { background: var(--error-bg);   color: var(--error-tx); }

/* ---------- Search ---------- */
.searchbar {
    display: flex;
    gap: 10px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}
.searchbar input[type="search"] {
    flex: 1 1 260px;
    padding: 11px 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: .95rem;
    background: var(--surface);
}

/* ---------- Card / Form ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 22px;
}
.form fieldset {
    border: none;
    border-top: 1px solid var(--border);
    padding: 18px 0 4px;
    margin: 0;
}
.form fieldset:first-of-type { border-top: none; padding-top: 0; }
.form legend {
    font-weight: 700;
    font-size: .95rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .03em;
    padding: 0;
    margin-bottom: 10px;
}
label {
    display: block;
    font-weight: 600;
    font-size: .88rem;
    margin-bottom: 12px;
}
input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"],
select,
textarea {
    width: 100%;
    margin-top: 5px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 9px;
    font-size: .95rem;
    font-family: inherit;
    background: var(--surface);
    color: var(--text);
}
select { cursor: pointer; }
input:disabled {
    background: #f2f4f8;
    color: var(--muted);
    cursor: not-allowed;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59, 110, 246, .15);
}
textarea { resize: vertical; }

/* Galleria allegati */
.gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 14px;
}
.allegato {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 8px;
    background: var(--surface);
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.allegato-anteprima {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 120px;
    background: #f7f9fd;
    border-radius: 8px;
    overflow: hidden;
}
.allegato-anteprima img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.allegato-anteprima .file-icon { font-size: 2.6rem; }
.allegato-info {
    display: flex;
    flex-direction: column;
    font-size: .82rem;
    word-break: break-word;
}
.allegato form { margin: 0; }

/* Scheda cliente */
.toolbar {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 18px;
}
.btn-maps { background: #1a73e8; color: #fff; }
.btn-maps:hover { background: #1667cc; color: #fff; }
.dati {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2px 24px;
    margin-bottom: 8px;
}
.dato {
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    line-height: 1.5;
}
.dato-label { color: var(--muted); font-weight: 600; margin-right: 6px; }
.dato-val { color: var(--text); }

.gps-actions {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.section-title {
    font-size: 1.1rem;
    margin: 8px 0 12px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--border);
}

/* Modifica in linea (configurazione tipologie) */
.inline-edit { display: flex; gap: 8px; align-items: center; margin: 0; }
.inline-edit .edit-nome { margin-top: 0; max-width: 320px; }

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 18px;
}
.grid-2 .span-2 { grid-column: 1 / -1; }

.radio-row { display: flex; gap: 22px; }
.radio { font-weight: 600; display: flex; align-items: center; gap: 7px; }
.radio input { width: auto; margin: 0; }

.form-actions {
    display: flex;
    gap: 12px;
    margin-top: 22px;
    flex-wrap: wrap;
}

/* ---------- Tabella clienti ---------- */
.table-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow-x: auto;
}
table.clienti {
    width: 100%;
    border-collapse: collapse;
    font-size: .92rem;
}
table.clienti thead th {
    text-align: left;
    padding: 13px 16px;
    background: #f7f9fd;
    color: var(--muted);
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .03em;
    border-bottom: 1px solid var(--border);
}
table.clienti tbody td {
    padding: 13px 16px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
table.clienti tbody tr:last-child td { border-bottom: none; }
table.clienti tbody tr:hover { background: #fafbfe; }
.cell-title { font-weight: 600; }
.cell-stack { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; }
/* Azioni di riga: i pulsanti vanno a capo invece di uscire dalla tabella */
.col-actions { white-space: normal; text-align: right; }
.col-actions > .btn,
.col-actions > .inline-form { margin: 3px 0 3px 4px; vertical-align: middle; }
.inline-form { display: inline-block; margin: 0; vertical-align: middle; }
/* Pulsanti di riga dell'elenco clienti: griglia 2x2 a larghezza uguale,
   compatta e allineata in ogni riga */
.row-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    min-width: 190px;
    margin-left: auto;
}
.row-actions .btn { width: 100%; }
.row-actions .inline-form { display: block; }
td .linea-badge { white-space: normal; }
/* Contatti lunghi (email) possono andare a capo */
.cell-stack a { overflow-wrap: anywhere; }

.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: .75rem;
    font-weight: 700;
}
.badge-privato { background: #eaf0fe; color: var(--primary-dk); }
.badge-azienda { background: #eafaf1; color: #1f7a45; }
.badge-off { background: #f0f1f4; color: var(--muted); }
.badge-satellitare { background: #eef1fe; color: #3b46c4; }
.badge-internet { background: #fff2e6; color: #b5641a; }

.empty {
    background: var(--surface);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    padding: 40px 20px;
    text-align: center;
    color: var(--muted);
}
.empty .btn { margin-top: 10px; }

/* ---------- Footer ---------- */
.site-footer {
    text-align: center;
    color: var(--muted);
    font-size: .82rem;
    padding: 24px 16px 34px;
}

/* ---------- Pagine di login / install ---------- */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
}
.auth-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: var(--shadow);
    padding: 32px 28px;
    width: 100%;
    max-width: 400px;
}
.auth-card h1 { text-align: center; margin-bottom: 2px; }
.auth-subtitle { text-align: center; color: var(--muted); margin: 0 0 22px; }

/* =====================================================================
   Responsive: tablet e smartphone
   ===================================================================== */
@media (max-width: 760px) {
    .menu-toggle { display: block; }
    .topnav {
        display: none;
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
        width: 100%;
        margin: 0;
        padding: 8px 0 12px;
    }
    .topnav.open { display: flex; }
    .topnav a, .topnav-user {
        width: 100%;
        padding: 9px 4px;
        border-top: 1px solid var(--border);
    }
    .topbar-inner { flex-wrap: wrap; }

    .grid-2 { grid-template-columns: 1fr; }
    .dati { grid-template-columns: 1fr; }

    /* Tabella -> schede impilate */
    table.clienti thead { display: none; }
    table.clienti, table.clienti tbody, table.clienti tr, table.clienti td { display: block; width: 100%; }
    table.clienti tr {
        border: 1px solid var(--border);
        border-radius: 10px;
        margin-bottom: 12px;
        padding: 6px 4px;
        background: var(--surface);
    }
    table.clienti tbody td {
        border: none;
        padding: 8px 14px;
        display: flex;
        justify-content: space-between;
        gap: 12px;
        text-align: right;
    }
    table.clienti tbody td::before {
        content: attr(data-label);
        font-weight: 700;
        color: var(--muted);
        text-align: left;
        flex: 0 0 40%;
    }
    .cell-stack { align-items: flex-end; }
    .col-actions { text-align: left; justify-content: flex-start; flex-wrap: wrap; }
    .col-actions::before { display: none; }
    .table-wrap {
        border: none;
        background: none;
        box-shadow: none;
        overflow: visible;
    }
}

/* ---------- Miniature foto e anteprima (lightbox) ---------- */
.thumbs { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.thumbs .thumb {
    width: 40px; height: 40px; border-radius: 8px; object-fit: cover;
    border: 1px solid var(--border); cursor: pointer; display: block; background: #f2f4f8;
    transition: transform .08s;
}
.thumbs .thumb:hover { transform: scale(1.06); }
.thumbs .thumb-more {
    width: 40px; height: 40px; border-radius: 8px; border: 1px solid var(--border);
    background: #eef1f7; color: var(--muted); font-weight: 700; font-size: .8rem;
    display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.thumbs .paperclip { color: var(--muted); font-weight: 700; font-size: .85rem; }

#lightbox { position: fixed; inset: 0; background: rgba(10,15,25,.88); display: none; align-items: center; justify-content: center; z-index: 100; }
#lightbox.open { display: flex; }
#lightbox .stage { max-width: 94vw; max-height: 90vh; display: flex; flex-direction: column; align-items: center; gap: 10px; }
#lightbox img { max-width: 94vw; max-height: 80vh; border-radius: 10px; box-shadow: 0 10px 40px rgba(0,0,0,.5); background: #fff; }
#lightbox .cap { color: #fff; font-size: .9rem; opacity: .9; text-align: center; }
#lightbox .lb-x { position: absolute; top: 14px; right: 20px; color: #fff; font-size: 2rem; line-height: 1; cursor: pointer; opacity: .85; }
#lightbox .lb-nav { position: absolute; top: 50%; transform: translateY(-50%); color: #fff; font-size: 2.4rem; cursor: pointer; opacity: .8; user-select: none; padding: 12px; }
#lightbox .lb-prev { left: 6px; } #lightbox .lb-next { right: 6px; }
#lightbox .lb-nav:hover, #lightbox .lb-x:hover { opacity: 1; }

/* --- Creazione rapida cliente dal form intervento --- */
.cliente-row {
    display: flex;
    gap: 8px;
    align-items: stretch;
}
.cliente-row select {
    flex: 1 1 auto;
    min-width: 0;
}
.cliente-row .btn {
    flex: 0 0 auto;
    white-space: nowrap;
}
.quickadd {
    margin-top: 20px;
    border: 1px solid var(--primary);
    box-shadow: var(--shadow);
}
.quickadd-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.quickadd-head .section-title {
    margin: 0;
}
.form-grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 16px;
}
@media (max-width: 560px) {
    .cliente-row {
        flex-direction: column;
    }
    .form-grid-2 {
        grid-template-columns: 1fr;
    }
}

/* --- Linea internet attivata (badge stato) --- */
.linea-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 999px;
    font-weight: 700;
    font-size: .82rem;
    white-space: nowrap;
}
.linea-badge.linea-attiva  { background: var(--success-bg); color: var(--success-tx); }
.linea-badge.linea-cessata { background: #f1f2f5; color: #6b7280; }
.filtro-linea {
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text);
    font-size: .92rem;
    font-family: inherit;
}
/* Barra di ricerca su una sola riga: campo, filtro e pulsante affiancati */
.searchbar input[type="search"],
.searchbar select,
.searchbar .btn { margin-top: 0; }
.searchbar .filtro-linea { width: auto; flex: 0 0 auto; }
@media (max-width: 560px) {
    .searchbar .filtro-linea { flex: 1 1 100%; }
}
@media (max-width: 760px) {
    .row-actions { display: flex; flex-wrap: wrap; gap: 6px; min-width: 0; margin-left: 0; }
    .row-actions .btn { width: auto; }
}
