/* Stile condiviso — ottimizzato per uso touch da tablet */
:root {
    --primary: #1e5fc4;
    --primary-dark: #16478f;
    --bg: #f2f5fa;
    --card: #ffffff;
    --text: #1c2733;
    --muted: #64748b;
    --border: #d7dee8;
    --ok: #16a34a;
    --warn: #d97706;
    --danger: #dc2626;
    --radius: 14px;
}

* { box-sizing: border-box; }

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

.container {
    max-width: 760px;
    margin: 0 auto;
    padding: 24px 20px 60px;
}


/* ===== Guscio dell'area riservata (vedi includes/header.php e footer.php) =====
   Mobile-first: sotto i 900px barra superiore sottile + barra in basso con 5 voci;
   da 900px style-desktop.css la sostituisce con la barra laterale. */
.app { display: block; }
.sidebar { display: none; }
.app-main { padding-bottom: 76px; min-width: 0; }

.mobilebar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 16px;
    background: #fff;
    border-bottom: 1px solid var(--border);
    color: var(--muted);
    font-size: 14px;
}
.mobilebar .mb-brand { display: block; line-height: 0; }
.mobilebar .mb-brand img { height: 32px; width: auto; }

.tabbar {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 50;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    background: #fff;
    border-top: 1px solid var(--border);
    box-shadow: 0 -2px 10px rgba(30, 50, 80, .08);
}
.tabbar a, .tabbar button {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 58px;
    padding: 6px 2px;
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    color: var(--muted);
    text-decoration: none;
    background: none;
    border: 0;
    cursor: pointer;
}
.tabbar .on { color: var(--primary); }
.tabbar .tb-plus { color: var(--primary); }
.tabbar .tb-plus i {
    display: grid;
    place-items: center;
    width: 36px; height: 36px;
    margin-top: -16px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    font-style: normal;
    font-size: 24px;
    line-height: 1;
    box-shadow: 0 2px 8px rgba(30, 95, 196, .4);
}
.tb-n {
    position: absolute;
    top: 6px; left: calc(50% + 8px);
    min-width: 18px; padding: 0 5px;
    border-radius: 999px;
    background: var(--danger); color: #fff;
    font-size: 11px; line-height: 18px; font-weight: 700;
}
.tb-n-ambra { background: var(--warn); }

.sheet-backdrop { position: fixed; inset: 0; z-index: 60; background: rgba(15, 25, 45, .5); }
.sheet {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 61;
    max-height: 80vh;
    overflow-y: auto;
    padding: 10px 18px 20px;
    background: #fff;
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -8px 30px rgba(0, 0, 0, .25);
}
.sheet-grab { width: 38px; height: 4px; margin: 0 auto 8px; border-radius: 4px; background: var(--border); }
.sheet a {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 52px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    font-weight: 600;
    text-decoration: none;
}
.sheet a:last-child { border-bottom: 0; }
.sheet a.on { color: var(--primary); }

/* Badge numerici (barra laterale e pannello "Altro") */
.sb-n { min-width: 20px; padding: 0 7px; border-radius: 999px; font-size: 12px; line-height: 20px; font-weight: 700; text-align: center; color: #fff; }
.sb-n-rosso { background: var(--danger); }
.sb-n-ambra { background: var(--warn); }

/* Sotto-menu a pillole (es. Configurazione, Contratti) */
.subnav { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 20px; }
.subnav a {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    padding: 0 16px;
    border-radius: 999px;
    background: #eef2f9;
    color: var(--text);
    text-decoration: none;
    font-weight: 600;
    font-size: 14px;
    transition: background-color .15s ease, color .15s ease;
}
.subnav a:hover { background: #e0e9f7; }
.subnav a.active { background: var(--primary); color: #fff; }

/* Link dentro ai sottotitoli (back-link, testo descrittivo) */
.subtitle a { color: var(--primary); font-weight: 600; text-decoration: none; }
.subtitle a:hover { text-decoration: underline; }

/* Barra leggera con il solo link "torna alla home" (pagine pubbliche/portale/login) */
.hometop { background: #fff; border-bottom: 1px solid var(--border); padding: 12px 20px; }
.hometop a { color: var(--primary); text-decoration: none; font-weight: 700; font-size: 15px; }
.hometop a:hover { text-decoration: underline; }

/* Card */
.card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 28px;
    box-shadow: 0 2px 10px rgba(30,50,80,.06);
    border: 1px solid var(--border);
    margin-bottom: 20px;
}

h1 { font-size: 28px; margin: 0 0 6px; }
h2 { font-size: 22px; margin: 0 0 16px; }
.subtitle { color: var(--muted); margin: 0 0 24px; }

/* Indicatore di step */
.steps {
    display: flex;
    gap: 8px;
    margin-bottom: 24px;
}
.steps .step {
    flex: 1;
    height: 8px;
    border-radius: 4px;
    background: var(--border);
}
.steps .step.active { background: var(--primary); }
.steps .step.done { background: var(--ok); }

/* Form */
label.field {
    display: block;
    margin-bottom: 18px;
}
label.field > span {
    display: block;
    font-weight: 600;
    margin-bottom: 6px;
}
input[type=text], input[type=email], input[type=tel], input[type=password],
input[type=number], textarea, select {
    width: 100%;
    padding: 14px 16px;
    font-size: 18px;
    border: 2px solid var(--border);
    border-radius: 10px;
    background: #fff;
    color: var(--text);
    font-family: inherit;
}
input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--primary);
}
textarea { min-height: 110px; resize: vertical; }

/* Checkbox materiale consegnato: pulsanti grandi */
.check-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px;
}
.check-grid label {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px;
    border: 2px solid var(--border);
    border-radius: 10px;
    cursor: pointer;
    font-weight: 600;
    user-select: none;
}
.check-grid input { width: 22px; height: 22px; }
.check-grid label:has(input:checked) {
    border-color: var(--primary);
    background: #eaf1fd;
}

/* Pulsanti */
.btn {
    display: inline-block;
    min-height: 52px;
    padding: 14px 28px;
    font-size: 18px;
    font-weight: 700;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    text-decoration: none;
    text-align: center;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #e6ebf3; color: var(--text); }
.btn-success { background: var(--ok); color: #fff; }
.btn-success:hover { background: #128238; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-block { display: block; width: 100%; }
.btn-row { display: flex; gap: 12px; margin-top: 8px; }
.btn-row .btn { flex: 1; }

/* Timeline tracking cliente */
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li {
    position: relative;
    padding: 0 0 26px 34px;
    border-left: 3px solid var(--border);
}
.timeline li:last-child { border-left-color: transparent; padding-bottom: 0; }
.timeline li::before {
    content: "";
    position: absolute;
    left: -11px;
    top: 0;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--border);
    border: 3px solid var(--bg);
}
.timeline li.done::before { background: var(--ok); }
.timeline li.current::before { background: var(--primary); }
.timeline .stato-nome { font-weight: 700; }
.timeline .stato-data { color: var(--muted); font-size: 15px; }
.timeline .stato-nota { color: var(--muted); font-size: 15px; margin-top: 2px; }

/* Badge stato */
.badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 999px;
    font-size: 14px;
    font-weight: 700;
    background: #e6ebf3;
    color: var(--primary-dark);
}
/* Stato intervento: in ritardo (accettato da più di 3 giorni, non ancora pronto/consegnato)
   o pronto per il ritiro — vedi tecnico/dashboard.php */
.badge-ritardo { background: var(--danger); color: #fff; }
.badge-pronto { background: var(--ok); color: #fff; }

/* Tabelle */
table { width: 100%; border-collapse: collapse; margin-bottom: 16px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
th { font-size: 14px; text-transform: uppercase; color: var(--muted); letter-spacing: .03em; }
td input { padding: 8px 10px; font-size: 16px; }

/* Colonna azioni con più controlli per riga (es. Admin -> Utenti): due righe distinte
   (azioni rapide / reset password) che occupano sempre tutta la larghezza disponibile,
   invece di un unico blocco compresso a sinistra con spazio vuoto a destra. */
.azioni-utente { display: flex; flex-direction: column; gap: 8px; min-width: 260px; }
.azioni-riga { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 0; width: 100%; }
.azioni-riga .btn { min-height: 36px; padding: 7px 14px; font-size: 14px; white-space: nowrap; }
.azioni-riga input[type=password] { flex: 1 1 140px; min-width: 140px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; }

/* Riquadro QR */
.qr-box { text-align: center; }
.qr-box img { width: 220px; height: 220px; image-rendering: pixelated; }

/* Messaggi */
.alert { padding: 14px 18px; border-radius: 10px; margin-bottom: 20px; font-weight: 600; }
.alert-error { background: #fde8e8; color: var(--danger); }
.alert-ok { background: #e7f7ec; color: var(--ok); }
.alert-info { background: #eaf1fd; color: var(--primary-dark); }

.muted { color: var(--muted); }
.text-center { text-align: center; }
.mt { margin-top: 20px; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 520px) { .row-2 { grid-template-columns: 1fr; } }

/* Evidenza SLA nell'elenco ticket */
tr.tr-scaduto td { background: #fdeaea; }
tr.tr-scaduto td:first-child { box-shadow: inset 4px 0 0 var(--danger); }
tr.tr-scadenza td { background: #fef6e7; }
tr.tr-scadenza td:first-child { box-shadow: inset 4px 0 0 var(--warn); }
.sla-scaduto { color: var(--danger); font-weight: 700; }
.sla-scadenza { color: var(--warn); font-weight: 700; }
.sla-ok { color: var(--muted); }

/* Nome cliente cliccabile nell'elenco interventi */
.cliente-link { color: var(--primary); font-weight: 700; text-decoration: none; display: inline-block; padding: 2px 0; }
.cliente-link:hover { text-decoration: underline; }

/* Ricambi — righe con campi etichettati, si adattano a schermi stretti */
.ricambio {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    flex-wrap: wrap;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fafbfe;
    margin-bottom: 10px;
}
.ricambio .ric-f { margin: 0; }
.ricambio .ric-f > span { display: block; font-size: 13px; font-weight: 700; color: var(--muted); margin-bottom: 4px; text-transform: uppercase; letter-spacing: .02em; }
.ricambio .ric-f input { width: 100%; padding: 12px; }
.ricambio .ric-desc { flex: 1 1 220px; }
.ricambio .ric-prezzo { flex: 0 0 130px; }
.ricambio .ric-qta { flex: 0 0 100px; }
.ricambio .ric-barcode { flex: 0 0 170px; }
.ricambio .ric-del { flex: 0 0 auto; min-height: 50px; padding: 8px 16px; font-size: 20px; line-height: 1; }
@media (max-width: 560px) {
    .ricambio .ric-desc { flex: 1 1 100%; }
    .ricambio .ric-prezzo { flex: 1 1 0; }
    .ricambio .ric-qta { flex: 1 1 0; }
    .ricambio .ric-barcode { flex: 1 1 100%; }
}

/* Galleria foto (accettazione/ticket) */
.foto-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 12px;
}
.foto-thumb {
    position: relative;
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    background: #f3f4f6;
}
.foto-thumb img {
    display: block;
    width: 100%;
    height: 110px;
    object-fit: cover;
}
.foto-thumb a img { cursor: pointer; }
.foto-thumb form {
    position: absolute;
    top: 4px;
    right: 4px;
    margin: 0;
}
.foto-thumb .btn-danger {
    min-height: auto;
    padding: 2px 9px;
    font-size: 16px;
    line-height: 1.2;
}

/* Ottimizzazioni per smartphone in verticale */
@media (max-width: 640px) {
    body { font-size: 16px; }
    .container { padding: 16px 14px 48px; }
    h1 { font-size: 24px; }
    h2 { font-size: 19px; }
    .card { padding: 18px; }
    /* font-size 16px sugli input evita lo zoom automatico di iOS al focus */
    input[type=text], input[type=email], input[type=tel], input[type=password],
    input[type=number], textarea, select { font-size: 16px; }
    .btn { padding: 13px 18px; }
    .btn-row { flex-wrap: wrap; }
    /* Tabelle dati scrollabili in orizzontale invece di sfondare la pagina */
    table { display: block; overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch; }
    .card.text-center .btn { margin: 4px 0; }
}

/* Logo aziendale in home (sfondo nero, il PNG ha già lo sfondo trasparente) */
.logo-card {
    background: #000;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 24px;
}
.logo-card img { max-width: 420px; width: 100%; height: auto; display: block; }

/* Dati di contatto azienda in home */
.company-info p { margin: 0 0 6px; color: var(--muted); }
.company-info p:last-child { margin-bottom: 0; }
.company-info strong { color: var(--text); }
.company-info a { color: var(--primary); text-decoration: none; }
.company-info a:hover { text-decoration: underline; }

/* Login */
.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
/* Variante per pagine di login con logo/footer sopra e sotto (es. portale clienti):
   niente centratura a piena altezza, altrimenti il footer finirebbe lontanissimo. */
.login-wrap.con-intestazione { min-height: 0; padding: 40px 20px; }
.login-card { width: 100%; max-width: 400px; }

/* Finestra modale (es. invio resoconto ticket via email) */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(20, 30, 50, .55);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 1000;
}
.modal-box {
    background: var(--card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: 0 10px 40px rgba(0,0,0,.25);
    padding: 28px;
    width: 100%;
    max-width: 480px;
}
.modal-box h3 { margin: 0 0 10px; font-size: 20px; }
@media (max-width: 640px) {
    .modal-box { padding: 18px; }
}

/* ===== Pagina "Oggi", contatori e segmenti ===== */
.btn-sm { min-height: auto; padding: 8px 16px; font-size: 15px; }
.badge-red { background: #fde8e8; color: #b91c1c; }
.badge-amb { background: #fef3c7; color: #92400e; }
.badge-grn { background: #dcfce7; color: #166534; }

.oggi-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; }
.seg { display: inline-flex; background: #e6ebf3; border-radius: 10px; padding: 3px; }
.seg a { padding: 8px 18px; border-radius: 8px; font-weight: 700; font-size: 15px; color: var(--muted); text-decoration: none; }
.seg a.on { background: #fff; color: var(--primary); box-shadow: 0 1px 3px rgba(0, 0, 0, .15); }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi {
    display: block;
    padding: 16px 18px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    text-decoration: none;
    box-shadow: 0 2px 10px rgba(30, 50, 80, .06);
    transition: border-color .15s ease, transform .15s ease;
}
.kpi:hover { border-color: var(--primary); }
.kpi:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
.kpi b { display: block; font-size: 34px; line-height: 1.1; }
.kpi span { display: block; color: var(--muted); font-size: 15px; }
.kpi em { display: block; margin-top: 6px; font-style: normal; font-size: 14px; font-weight: 700; color: var(--primary); }
.kpi-bad b { color: var(--danger); }
.kpi-warn b { color: var(--warn); }
.kpi-ok b { color: var(--ok); }

.oggi-cols { display: grid; grid-template-columns: 1fr; gap: 0 18px; align-items: start; }

/* ===== Elenchi (classe .lista): sotto i 900px ogni riga diventa una scheda ===== */
.lista .sub { display: block; color: var(--muted); font-size: 14px; font-weight: 400; }
@media (max-width: 899px) {
    table.lista { display: block; overflow: visible; white-space: normal; margin-bottom: 6px; }
    table.lista thead { display: none; }
    table.lista tbody { display: block; }
    table.lista tr {
        display: grid;
        grid-template-columns: 1fr auto;
        grid-template-areas: "codice sla" "main main" "stato act";
        gap: 4px 10px;
        align-items: center;
        padding: 12px 14px;
        margin-bottom: 10px;
        background: #fff;
        border: 1px solid var(--border);
        border-radius: 12px;
    }
    table.lista td { display: block; padding: 0; border: 0; white-space: normal; background: transparent; box-shadow: none; }
    table.lista .c-codice { grid-area: codice; }
    table.lista .c-sla { grid-area: sla; text-align: right; }
    table.lista .c-main { grid-area: main; }
    table.lista .c-stato { grid-area: stato; }
    table.lista .c-act { grid-area: act; text-align: right; }
    table.lista tr.tr-scaduto { background: #fdeaea; border-color: #f3b8b8; }
    table.lista tr.tr-scadenza { background: #fef6e7; border-color: #f3dca5; }
    table.lista tr.tr-scaduto td:first-child, table.lista tr.tr-scadenza td:first-child { box-shadow: none; }
}

/* Elenchi: codici e badge su una sola riga (a capo solo nella versione a schede) */
.lista .c-codice, .lista .badge, .lista th { white-space: nowrap; }
@media (min-width: 1400px) {
    .oggi-cols { grid-template-columns: minmax(0, 1.7fr) minmax(300px, 1fr); }
}
.oggi-cols .card { overflow-x: auto; }

/* Smartphone: contatori 2x2, azioni rapide già nella barra in basso, filtri richiudibili */
.solo-desktop { display: none; }
.filtri summary { cursor: pointer; display: flex; align-items: center; min-height: 44px; margin-bottom: 8px; font-weight: 700; color: var(--primary); }
@media (max-width: 599px) {
    .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .kpi { padding: 12px 14px; }
    .kpi b { font-size: 28px; }
    .kpi span { font-size: 14px; }
}

/* ===== Scheda di dettaglio a cruscotto (stile B) — vedi tecnico/intervento.php =====
   Mobile-first: tutto in colonna; da 900px style-desktop.css affianca riquadri e colonne. */
.det-head { display: flex; flex-direction: column; gap: 14px; }
.det-title { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.det-title h1 { margin: 0; }
.det-sub { color: var(--muted); font-size: 16px; }
.det-azioni { display: flex; flex-wrap: wrap; gap: 8px; }
.det-azioni .btn { min-height: 44px; padding: 8px 14px; font-size: 15px; }

/* Avanzamento degli stati: su smartphone una barra a segmenti con il riepilogo sopra */
.stepper { list-style: none; margin: 0; padding: 0; display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 4px; }
.stepper li { height: 6px; border-radius: 3px; background: var(--border); overflow: hidden; color: transparent; font-size: 0; }
.stepper li.done { background: #8fb0e3; }
.stepper li.cur { background: var(--primary); }
.stepper-sum { display: flex; justify-content: space-between; font-size: 14px; font-weight: 600; color: var(--primary-dark); margin-bottom: 6px; }
.stepper-sum span:last-child { color: var(--muted); }

.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 20px; }
.tile { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; min-width: 0; overflow-wrap: anywhere; }
.tile h2 { margin: 0 0 4px; font-size: 13px; font-weight: 600; color: var(--muted); }
.tile .tile-main { font-weight: 700; font-size: 17px; }
.tile .tile-sub { font-size: 14px; color: var(--muted); line-height: 1.5; }
.tile .tile-sub strong { color: var(--text); }
@media (max-width: 380px) { .tiles { grid-template-columns: 1fr; } }

.difetto-box { background: #fff8eb; border: 1px solid #f5d9a8; border-radius: 12px; padding: 12px 16px; margin-bottom: 20px; }
.difetto-box p { margin: 4px 0 0; }

.det-cols { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0 20px; align-items: start; }

/* Storico dei cambi di stato (colonna laterale delle schede di dettaglio) */
.storico { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; font-size: 15px; }
.storico li { padding-left: 14px; border-left: 3px solid var(--border); }
.storico li:first-child { border-left-color: var(--primary); }
.storico .muted { display: block; font-size: 14px; }

/* Riquadri riassuntivi a tre colonne (es. scheda contratto) */
.tiles-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

