/* =====================================================================
   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; }

/* ---------- 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;
}
.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: hidden;
}
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; }
.col-actions { white-space: nowrap; text-align: right; }
.inline-form { display: inline; }

.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;
    }
}
