:root{
    --bg:#f3f3f3;
    --page:#ffffff;
    --ink:#454545;
    --muted:#777;
    --line:#d8d8d8;
    --head:#3f3f3f;
    --side1:#4b4b4b;
    --side2:#2f2f2f;
    --orange:#ff8d28;
    --orange2:#ff6f00;
    --green:#74b24a;
    --blue:#4b93c8;
    --soft:#f7f7f7;
    --shadow:0 2px 6px rgba(0,0,0,.18);
}

*{box-sizing:border-box}

html,body{
    min-height:100%;
    margin:0;
    font-family:Arial,Helvetica,sans-serif;
    background:var(--bg);
    color:var(--ink);
    font-size:14px;
}

body.menu-open{
    overflow:hidden;
}

/* TOPBAR MOBILE */
.mobile-topbar{
    display:none;
    position:sticky;
    top:0;
    z-index:1100;
    height:56px;
    align-items:center;
    gap:12px;
    padding:8px 12px;
    background:linear-gradient(#4b4b4b,#333);
    color:#fff;
    border-bottom:3px solid var(--orange);
    box-shadow:0 2px 8px rgba(0,0,0,.22);
}

.mobile-topbar strong{
    font-size:20px;
    color:#ffd18c;
    text-shadow:0 1px 1px #000;
}

.mobile-sale{
    margin-left:auto;
    color:#fff;
    text-decoration:none;
    font-weight:900;
    padding:8px 12px;
    border-radius:9px;
    background:linear-gradient(#ffa844,#ff7d13);
    border:1px solid rgba(0,0,0,.25);
}

.menu-toggle{
    width:42px;
    height:40px;
    border:1px solid rgba(0,0,0,.3);
    border-radius:9px;
    background:linear-gradient(#666,#3f3f3f);
    display:grid;
    place-items:center;
    gap:3px;
    padding:8px;
    box-shadow:inset 0 1px rgba(255,255,255,.18);
}

.menu-toggle span{
    display:block;
    width:22px;
    height:3px;
    background:#fff;
    border-radius:99px;
}

.side-backdrop{
    display:none;
}

/* MENU LATERALE DESKTOP */
.side{
    position:fixed;
    left:0;
    top:0;
    bottom:0;
    width:224px;
    height:100vh;
    max-height:100vh;
    overflow-y:auto;
    overflow-x:hidden;
    padding:12px 16px 28px;
    background:linear-gradient(180deg,var(--side1),var(--side2));
    color:#fff;
    box-shadow:inset -1px 0 0 rgba(0,0,0,.45),4px 0 12px rgba(0,0,0,.15);
    scrollbar-width:thin;
    scrollbar-color:rgba(255,255,255,.35) transparent;
    z-index:1000;
}

.side::-webkit-scrollbar{width:8px}
.side::-webkit-scrollbar-thumb{background:rgba(255,255,255,.35);border-radius:99px}
.side::-webkit-scrollbar-track{background:transparent}

.quick-actions{
    display:grid;
    gap:9px;
    margin:0 0 14px;
}

.quick-actions a{
    display:block;
    color:#fff;
    text-decoration:none;
    text-align:center;
    font-size:17px;
    font-weight:900;
    line-height:1;
    padding:11px 10px;
    border-radius:11px;
    border:1px solid rgba(0,0,0,.32);
    background:linear-gradient(#ffa844,#ff7d13);
    box-shadow:inset 0 1px rgba(255,255,255,.5),0 2px 4px rgba(0,0,0,.25);
    text-shadow:0 1px 1px rgba(0,0,0,.35);
}

.brand{
    font-size:21px;
    font-weight:900;
    color:#ffd18c;
    margin:12px 0 14px;
    text-shadow:0 1px 2px #000;
    letter-spacing:-.02em;
}

.side-nav{
    display:grid;
    gap:8px;
}

.nav-section{
    margin:14px 4px 2px;
    padding-top:8px;
    border-top:1px solid rgba(255,255,255,.14);
    color:#ffd18c;
    text-transform:uppercase;
    font-size:11px;
    font-weight:900;
    letter-spacing:.08em;
}

.side-nav a{
    min-height:58px;
    display:flex;
    align-items:center;
    gap:14px;
    padding:8px 12px;
    border-radius:10px;
    color:#fff;
    text-decoration:none;
    font-size:16px;
    font-weight:900;
    background:linear-gradient(#666,#3f3f3f);
    border:1px solid rgba(0,0,0,.42);
    box-shadow:inset 0 1px rgba(255,255,255,.18),0 1px 2px rgba(0,0,0,.22);
    text-shadow:0 1px 1px rgba(0,0,0,.45);
}

.side-nav a:hover,
.side-nav a.active{
    background:linear-gradient(#777,#4d4d4d);
    transform:translateY(-1px);
}

.side-nav .ico{
    width:36px;
    min-width:36px;
    height:36px;
    display:grid;
    place-items:center;
    font-size:24px;
    filter:drop-shadow(0 1px 1px rgba(0,0,0,.45));
}

.side-footer{
    margin:20px 0 0;
    padding:13px 6px 28px;
    text-align:center;
    color:#eee;
    font-size:12px;
    line-height:1.35;
    text-shadow:0 1px 1px #000;
}

/* CONTENUTO */
.main{
    margin-left:224px;
    min-height:100vh;
    padding:0 0 48px;
    background:#f7f7f7;
}

h1{
    margin:0 0 18px;
    padding:12px 18px;
    background:linear-gradient(#4b4b4b,#3b3b3b);
    color:#fff;
    font-size:24px;
    line-height:1.2;
    letter-spacing:.01em;
    border-bottom:3px solid var(--orange);
    text-shadow:0 1px 1px #000;
}

h2{
    margin:0 0 14px;
    font-size:20px;
    color:#333;
}

h3{margin-top:0}

.panel{
    background:#fff;
    border:1px solid #ddd;
    border-radius:0;
    margin:18px 18px;
    padding:18px;
    box-shadow:0 1px 3px rgba(0,0,0,.08);
}

.flash{
    margin:14px 18px;
    padding:12px 14px;
    background:#e8f4de;
    border:1px solid #b9d7a2;
    color:#375b23;
    font-weight:700;
    border-radius:4px;
}

.cards{
    display:grid;
    grid-template-columns:repeat(4,minmax(0,1fr));
    gap:15px;
    margin:18px;
}

.cards div{
    background:linear-gradient(#fff,#f3f3f3);
    border:1px solid #d8d8d8;
    border-radius:8px;
    padding:18px;
    min-height:96px;
    box-shadow:0 1px 4px rgba(0,0,0,.08);
}

.cards b{
    display:block;
    font-size:32px;
    line-height:1;
    color:#202020;
    margin-bottom:8px;
}

.cards span,.muted{color:#6e6e6e}

.status-strip{
    display:grid;
    grid-template-columns:repeat(4,minmax(0,1fr));
    gap:12px;
}

.status-card{
    display:block;
    text-decoration:none;
    color:#333;
    background:linear-gradient(#fff,#f1f1f1);
    border:1px solid #d6d6d6;
    border-radius:8px;
    padding:14px;
    min-height:86px;
    box-shadow:0 1px 4px rgba(0,0,0,.08);
}

.status-card:hover{
    border-color:var(--orange);
    box-shadow:0 0 0 2px rgba(255,141,40,.12);
}

.status-card b{
    display:block;
    font-size:28px;
    color:var(--orange2);
    margin-bottom:4px;
}

.status-card span{
    display:block;
    color:#333;
    font-weight:900;
}

.status-card small{
    display:block;
    margin-top:3px;
    color:#777;
}

/* PAGINE A MODULI */
.module-grid{
    display:grid;
    grid-template-columns:repeat(3,minmax(0,1fr));
    gap:18px;
}

.module-tile{
    display:flex;
    align-items:center;
    justify-content:center;
    flex-direction:column;
    min-height:130px;
    text-align:center;
    color:#444;
    text-decoration:none;
    font-weight:900;
    font-size:18px;
    background:linear-gradient(#fff,#f2f2f2);
    border:1px solid #d5d5d5;
    border-radius:8px;
    box-shadow:0 1px 4px rgba(0,0,0,.08);
}

.module-tile .bigico{
    font-size:42px;
    margin-bottom:10px;
}

.module-tile:hover{
    border-color:var(--orange);
    transform:translateY(-1px);
}

/* FORM */
.grid{
    display:grid;
    grid-template-columns:repeat(3,minmax(0,1fr));
    gap:14px;
}

.full{grid-column:1/-1}

label{
    display:flex;
    flex-direction:column;
    gap:6px;
    color:#333;
    font-weight:700;
}

input,select,textarea{
    width:100%;
    min-height:34px;
    padding:7px 9px;
    border:1px solid #d3d3d3;
    border-radius:3px;
    background:#fff;
    font:inherit;
    color:#333;
}

textarea{min-height:90px}

.checks{
    display:flex;
    gap:12px;
    align-items:center;
    flex-wrap:wrap;
}

.checks label{
    flex-direction:row;
    align-items:center;
    font-weight:700;
}

button,.btn{
    display:inline-block;
    border:1px solid #b95b00;
    border-radius:6px;
    background:linear-gradient(#ffa642,#ff7b0c);
    color:#fff;
    padding:9px 13px;
    font-weight:900;
    text-decoration:none;
    cursor:pointer;
    box-shadow:inset 0 1px rgba(255,255,255,.45),0 1px 2px rgba(0,0,0,.18);
    text-shadow:0 1px 1px rgba(0,0,0,.35);
}

.btn:hover,button:hover{filter:brightness(1.04)}
.small{padding:5px 8px;font-size:12px;border-radius:4px}

/* TABELLE */
.table-wrap{
    width:100%;
    overflow-x:auto;
    -webkit-overflow-scrolling:touch;
}

table{
    width:100%;
    border-collapse:collapse;
    background:#fff;
    border:1px solid #d5d5d5;
}

th,td{
    padding:8px 9px;
    border:1px solid #e1e1e1;
    text-align:left;
    vertical-align:middle;
}

th{
    background:#4c4c4c;
    color:#fff;
    font-size:13px;
    font-weight:900;
    text-shadow:0 1px 1px #000;
}

tbody tr:nth-child(even){background:#f2f2f2}
tbody tr:hover{background:#fff7e9}

.badge{
    display:inline-block;
    background:#eee;
    color:#333;
    border:1px solid #ddd;
    border-radius:999px;
    padding:4px 8px;
    font-size:12px;
    font-weight:900;
}

.thumb{
    width:58px;
    height:58px;
    object-fit:cover;
    border-radius:5px;
    border:1px solid #ddd;
}


.table-actions{display:grid;gap:8px;min-width:180px}
.table-actions .btn{display:block;width:100%;text-align:center;white-space:normal;line-height:1.15;padding:9px 10px}
.actions-cell{vertical-align:top}
.qr-mini{width:96px;height:96px;object-fit:contain;border:1px solid #ddd;border-radius:8px;background:#fff;padding:4px}
@media(max-width:980px){
    .table-wrap{overflow-x:auto;-webkit-overflow-scrolling:touch}
    .table-wrap table{min-width:1120px}
    .table-wrap .actions-cell{min-width:190px}
    .table-wrap .thumb{width:84px;height:84px}
    .table-wrap .qr-mini{width:110px;height:110px}
    .table-wrap .btn.small{font-size:14px;padding:10px 12px;border-radius:8px}
    .filters .full .btn, .filters .full button{margin-bottom:8px}
}
.inline{
    display:flex;
    align-items:end;
    gap:10px;
}

.mandate-head{
    display:flex;
    justify-content:space-between;
    gap:18px;
}

.linkbtn{
    background:transparent;
    border:0;
    color:#0b62aa;
    box-shadow:none;
    padding:0 4px;
    text-decoration:underline;
    font-weight:900;
    text-shadow:none;
}

/* CONSENSI / MODALI */
.consent-checks{
    display:flex;
    gap:10px;
    flex-wrap:wrap;
}

.consent-checks label{
    flex-direction:row;
    align-items:center;
    background:#fff;
    border:1px solid #ddd;
    border-radius:5px;
    padding:8px 10px;
}

.legal-item{
    border-bottom:1px solid #ddd;
    padding:16px 0;
}

.legal-item:last-child{border-bottom:0}

.modal-backdrop{
    position:fixed;
    inset:0;
    z-index:9999;
    display:none;
    align-items:center;
    justify-content:center;
    padding:20px;
    background:rgba(0,0,0,.5);
}

.modal-backdrop.open{display:flex}

.modal{
    width:min(780px,96vw);
    max-height:86vh;
    overflow:auto;
    background:#fff;
    border-radius:8px;
    border:1px solid #ccc;
    padding:22px;
    box-shadow:0 24px 80px rgba(0,0,0,.28);
}

.modal .modal-text{
    white-space:pre-line;
    line-height:1.55;
}

/* LOGIN / STAMPA */
.login{
    display:grid;
    place-items:center;
    min-height:100vh;
    background:linear-gradient(#f9f9f9,#ececec);
}

.login-card{
    width:min(430px,92vw);
    background:#fff;
    border:1px solid #ddd;
    border-radius:8px;
    padding:30px;
    box-shadow:0 12px 40px rgba(0,0,0,.18);
}

.login-card h1{
    margin:-30px -30px 20px;
}

.print{background:#fff}
.print-page{max-width:980px;margin:20px auto;padding:30px;background:#fff}
.sign{display:flex;justify-content:space-between;margin-top:60px}
.no-print{margin-top:30px}

/* MOBILE: menu apri/chiudi, non sopra tutto sempre */
@media(max-width:980px){
    .mobile-topbar{
        display:flex;
    }

    .side{
        top:0;
        left:0;
        bottom:0;
        width:min(86vw,320px);
        height:100vh;
        max-height:100vh;
        padding-top:14px;
        transform:translateX(-105%);
        transition:transform .22s ease;
        z-index:1200;
    }

    body.menu-open .side{
        transform:translateX(0);
    }

    .side-backdrop{
        position:fixed;
        inset:0;
        background:rgba(0,0,0,.38);
        z-index:1150;
        display:none;
    }

    body.menu-open .side-backdrop{
        display:block;
    }

    .main{
        margin-left:0;
        width:auto;
        padding-bottom:70px;
    }

    h1{
        font-size:22px;
        padding:10px 14px;
    }

    .panel{
        margin:12px;
        padding:14px;
    }

    .cards,
    .status-strip,
    .grid,
    .module-grid{
        grid-template-columns:1fr;
        margin-left:12px;
        margin-right:12px;
    }

    .cards{
        gap:10px;
    }

    .cards div{
        min-height:auto;
        padding:14px;
    }

    .status-card{
        min-height:auto;
    }

    .mandate-head,
    .inline{
        display:block;
    }

    table{
        min-width:1120px;
    }
}

@media print{
    .side,.mobile-topbar,.side-backdrop,.no-print,.btn,button,.flash{display:none!important}
    .main{margin:0!important;width:auto!important;padding:0!important;background:#fff}
    .panel{box-shadow:none;border:0;margin:0 0 12px;padding:0}
    h1{background:#fff;color:#111;border:0;text-shadow:none;padding:0}
    .print-page{margin:0;max-width:none}
    .modal-backdrop{display:none!important}
}
.btn.danger, button.danger{background:linear-gradient(#d9534f,#b52b27);border-color:#8d201d}.check-inline{display:inline-flex;flex-direction:row;gap:6px;align-items:center}.actions{white-space:nowrap}.table-wrap{width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch}

/* Gestione foto articolo: sostituzione/eliminazione semplice */
.photo-manager-grid{
  display:grid;
  grid-template-columns:repeat(auto-fit,minmax(220px,1fr));
  gap:16px;
  margin-top:18px;
}
.photo-manager-card{
  border:1px solid #d9d9d9;
  border-radius:14px;
  background:#fff;
  padding:12px;
  box-shadow:0 8px 22px rgba(0,0,0,.06);
}
.photo-manager-card.is-main{
  border-color:#ff7a00;
  box-shadow:0 10px 24px rgba(255,122,0,.14);
}
.photo-manager-image{
  position:relative;
  overflow:hidden;
  border-radius:10px;
  background:#f5f5f5;
  border:1px solid #eee;
}
.photo-manager-image img{
  display:block;
  width:100%;
  max-height:230px;
  object-fit:contain;
}
.photo-manager-image span{
  position:absolute;
  left:8px;
  top:8px;
  background:#ff7a00;
  color:#fff;
  border-radius:999px;
  padding:5px 10px;
  font-weight:700;
  font-size:.85rem;
}
.photo-manager-actions{
  display:grid;
  gap:10px;
  margin-top:12px;
}
.photo-replace-form{
  display:grid;
  gap:8px;
  padding:10px;
  background:#f8f8f8;
  border-radius:10px;
}
.photo-replace-form label{
  font-size:.9rem;
  font-weight:700;
}
.photo-replace-form input[type=file]{
  margin-top:6px;
  width:100%;
}
.check-inline{
  display:flex;
  gap:8px;
  align-items:center;
}
@media (max-width:700px){
  .photo-manager-grid{grid-template-columns:1fr;}
  .photo-manager-actions form button,
  #foto-articolo > form button{width:100%;}
}

/* Fix vendita: riepilogo IVA e quota cliente */
.sale-totals-box{
    margin:14px 0 18px auto;
    max-width:520px;
    background:#fff7ef;
    border:2px solid #ff7a12;
    border-radius:12px;
    padding:12px 14px;
    text-align:right;
    box-shadow:0 4px 12px rgba(0,0,0,.08);
}
.sale-totals-box p{margin:4px 0;font-size:16px;line-height:1.35}
.sale-totals-box p:first-child{font-size:20px}
@media(max-width:700px){
    .sale-totals-box{max-width:none;text-align:left;margin:12px 0;width:100%}
    .sale-totals-box p{font-size:15px}
    .sale-totals-box p:first-child{font-size:17px}
}


/* Logo Mercantico nuovo */
.mobile-brand{display:flex;align-items:center;gap:10px;color:inherit;text-decoration:none;font-weight:800;min-width:0}
.mobile-brand img{height:38px;width:auto;display:block}
.mobile-brand span{font-size:20px;line-height:1}
.brand-with-logo{display:flex;flex-direction:column;align-items:center;gap:8px;text-decoration:none;color:inherit}
.brand-with-logo img{width:min(220px,100%);height:auto;display:block;filter:drop-shadow(0 8px 18px rgba(0,0,0,.16))}
.brand-with-logo span{font-size:0;line-height:0}
.login-logo-wrap{display:flex;justify-content:center;margin:0 0 10px}
.login-logo{width:min(240px,70vw);height:auto;display:block}
.actions-cell-all-visible{display:flex;flex-wrap:wrap;gap:8px;align-items:flex-start;min-width:260px}
.actions-cell-all-visible .inline-form{display:inline-flex}
.actions-cell-all-visible .btn{white-space:nowrap}
.actions-cell-all-visible .btn.small{padding:8px 12px}
@media(max-width:980px){.actions-cell-all-visible{min-width:220px}}
@media(max-width:640px){
  .mobile-brand img{height:34px}
  .mobile-brand span{font-size:18px}
  .actions-cell-all-visible{display:grid;grid-template-columns:1fr 1fr;gap:8px}
  .actions-cell-all-visible .btn,.actions-cell-all-visible .inline-form,.actions-cell-all-visible .inline-form button{width:100%}
}


/* Elenco clienti: nelle azioni immediate resta solo Scheda cliente.
   Tutte le altre opzioni sono dentro la scheda cliente. */
.actions-cell-scheda-only{min-width:130px;white-space:nowrap}
.actions-cell-scheda-only .btn{width:100%;text-align:center;white-space:nowrap}
.cliente-actions-title{grid-column:1/-1;margin:0 0 4px;font-size:18px;line-height:1.2;color:#111}
.cliente-actions-help{grid-column:1/-1;margin:0 0 12px;color:#666;font-weight:600}
.cliente-actions-grid,.cliente-secondary-grid{display:flex;flex-wrap:wrap;gap:10px;width:100%;align-items:stretch}
.cliente-secondary-grid .inline-form{display:inline-flex}
.cliente-secondary-grid .btn,.cliente-secondary-grid .inline-form button{min-height:42px}
@media(max-width:760px){.cliente-actions-grid,.cliente-secondary-grid{display:grid;grid-template-columns:1fr 1fr}.cliente-actions-grid .tool-btn,.cliente-secondary-grid .btn,.cliente-secondary-grid .inline-form,.cliente-secondary-grid .inline-form button{width:100%}}
@media(max-width:420px){.cliente-actions-grid,.cliente-secondary-grid{grid-template-columns:1fr}}


/* Mobile fix logo trasparente */
.mobile-brand img{background:transparent !important;object-fit:contain !important}
.brand-with-logo img{background:transparent !important;object-fit:contain !important}
.login-logo{background:transparent !important;object-fit:contain !important}


/* Logo admin con targa chiara per leggibilità */
.brand-with-logo img,.mobile-brand img,.login-logo{background:linear-gradient(180deg,#fffdf8 0%,#f7efdf 100%);padding:6px 8px;border-radius:16px;border:1px solid rgba(193,150,84,.58);box-shadow:0 1px 0 rgba(255,255,255,.92) inset,0 10px 20px rgba(0,0,0,.18);object-fit:contain}
.mobile-brand img{padding:4px 6px;border-radius:12px}
.login-logo{padding:8px 10px;border-radius:18px}

/* Fix login desktop/mobile: due loghi senza sovrapposizioni */
body.login{
    display:flex !important;
    align-items:center !important;
    justify-content:center !important;
    min-height:100vh !important;
    padding:28px 12px !important;
}
body.login .login-card{
    width:min(460px, calc(100vw - 32px)) !important;
    padding:28px 30px 30px !important;
    overflow:visible !important;
}
body.login .login-logo-wrap,
body.login .login-logo-wrap[style]{
    display:flex !important;
    flex-wrap:wrap !important;
    gap:12px !important;
    align-items:center !important;
    justify-content:center !important;
    width:100% !important;
    margin:0 auto 16px !important;
}
body.login .login-logo-wrap .login-logo,
body.login .login-logo{
    flex:1 1 185px !important;
    width:auto !important;
    max-width:205px !important;
    height:145px !important;
    max-height:145px !important;
    display:block !important;
    object-fit:contain !important;
    padding:10px !important;
    margin:0 !important;
}
body.login .login-card h1{
    clear:both !important;
    margin:0 -30px 20px !important;
    padding:14px 20px !important;
    line-height:1.2 !important;
    position:relative !important;
    z-index:1 !important;
}
@media(max-width:480px){
    body.login{padding:16px 10px !important;align-items:flex-start !important;}
    body.login .login-card{padding:18px 18px 22px !important;width:100% !important;}
    body.login .login-logo-wrap{gap:8px !important;margin-bottom:12px !important;}
    body.login .login-logo-wrap .login-logo,
    body.login .login-logo{
        flex:1 1 135px !important;
        max-width:160px !important;
        height:105px !important;
        max-height:105px !important;
        padding:7px !important;
        border-radius:14px !important;
    }
    body.login .login-card h1{margin:0 -18px 16px !important;padding:12px 18px !important;font-size:22px !important;}
}
