:root {
    --b2b-sidebar: 256px;
    --b2b-bg: #f6f7f9;
    --b2b-border: #ececf1;
    --b2b-ink: #0f172a;
    --b2b-muted: #6b7280;
    --b2b-primary: #2b54e6;
    --b2b-grad: linear-gradient(135deg, #2b6fff 0%, #3b2db5 60%, #1b1463 100%);
}

* { font-feature-settings: "cv11", "ss01"; }
body {
    background: var(--b2b-bg);
    color: var(--b2b-ink);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
}

/* ============ AUTH (split moderno) ============ */
.auth-split { min-height: 100vh; display: flex; }
.auth-split > div { flex: 1 1 50%; }
.auth-hero {
    position: relative; overflow: hidden; color: #e5e7eb;
    background:
        radial-gradient(900px 500px at 85% -10%, rgba(37,99,235,.45), transparent 60%),
        radial-gradient(700px 600px at -10% 110%, rgba(16,185,129,.28), transparent 55%),
        linear-gradient(160deg, #0b1220 0%, #0a1018 100%);
    display: flex; flex-direction: column; justify-content: space-between; padding: 2.4rem 3rem;
}
.auth-hero .hero-logo {
    display: inline-flex; align-items: center; justify-content: center;
    background: #fff; border-radius: 14px; padding: .6rem 1rem;
    box-shadow: 0 8px 24px rgba(2,6,23,.35);
}
.auth-hero .hero-logo-img { height: 40px; width: auto; display: block; }
.auth-form-logo { height: 46px; width: auto; display: block; }
.auth-hero h1 { font-weight: 800; font-size: clamp(2.1rem, 3.4vw, 3rem); line-height: 1.08; letter-spacing: -1px; color: #fff; margin: 0 0 1.1rem; }
.auth-hero h1 .accent { color: #34d399; }
.auth-hero .hero-sub { color: #94a3b8; max-width: 30rem; font-size: 1.02rem; }
.auth-hero .hero-foot { color: #64748b; font-size: .82rem; }
.auth-form-side { background: #f8fafc; display: flex; align-items: center; justify-content: center; padding: 2rem; }
.auth-form { width: 100%; max-width: 380px; }
.auth-form h2 { font-weight: 800; letter-spacing: -.5px; color: #0f172a; }
.auth-form .form-label { font-weight: 600; font-size: .82rem; color: #334155; margin-bottom: .3rem; }
.auth-form .form-control { border-radius: 11px; padding: .72rem .9rem; border: 1px solid #e2e8f0; background: #fff; font-size: .98rem; }
.auth-form .form-control:focus { border-color: #2563eb; box-shadow: 0 0 0 4px rgba(37,99,235,.12); }
.auth-form .btn-login { border-radius: 11px; padding: .8rem 1rem; font-weight: 700; background: var(--b2b-grad); border: none; color: #fff; box-shadow: 0 10px 24px rgba(37,99,235,.32); }
.auth-form .btn-login:hover { filter: brightness(1.08); }
.auth-creds { border: 1px dashed #cbd5e1; border-radius: 12px; background: #fff; padding: .85rem 1rem; font-size: .85rem; color: #475569; }
.auth-creds code { color: #0f172a; }
@media (max-width: 860px) { .auth-split { flex-direction: column; } .auth-hero { padding: 1.8rem; gap: 1.4rem; } .auth-hero h1 { font-size: 1.9rem; } }

/* ============ SIDEBAR (bianca, a sezioni) ============ */
.app-sidebar {
    position: fixed; top: 0; bottom: 0; left: 0; width: var(--b2b-sidebar);
    background: #fff; border-right: 1px solid var(--b2b-border); overflow-y: auto; z-index: 1045;
    overscroll-behavior: contain;
}
/* scrollbar discreta */
.app-sidebar::-webkit-scrollbar { width: 6px; }
.app-sidebar::-webkit-scrollbar-thumb { background: #e2e8f0; border-radius: 999px; }
.app-sidebar::-webkit-scrollbar-thumb:hover { background: #cbd5e1; }

.app-brand {
    display: flex; align-items: center; justify-content: space-between; gap: .5rem;
    padding: 1.1rem 1.15rem; border-bottom: 1px solid var(--b2b-border);
    position: sticky; top: 0; background: #fff; z-index: 2;
}
.app-brand .brand-img { width: 160px; max-width: 100%; height: auto; }
.sidebar-close { border: 0; background: transparent; color: #94a3b8; font-size: 1.5rem; line-height: 1; padding: .1rem .3rem; }
.sidebar-close:hover { color: #0f172a; }

.nav-section { padding: 1.05rem 1.35rem .4rem; font-size: .66rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: #aab2c0; }
.app-sidebar .nav-link {
    display: flex; align-items: center; gap: .7rem; position: relative;
    color: #475569; border-radius: 11px; padding: .56rem .8rem; margin: .12rem .7rem; font-size: .9rem; font-weight: 500;
    transition: background .15s ease, color .15s ease, transform .12s ease;
}
.app-sidebar .nav-link i { font-size: 1.08rem; color: #94a3b8; width: 1.25rem; text-align: center; transition: color .15s ease; }
.app-sidebar .nav-link:hover { background: #f5f7fb; color: #0f172a; }
.app-sidebar .nav-link:hover i { color: #475569; }
.app-sidebar .nav-link:active { transform: scale(.985); }
.app-sidebar .nav-link.active {
    background: linear-gradient(90deg, rgba(43,111,255,.12), rgba(59,45,181,.06));
    color: #2b54e6; font-weight: 600;
}
.app-sidebar .nav-link.active i { color: #2b54e6; }
/* barretta accent a sinistra dell'item attivo */
.app-sidebar .nav-link.active::before {
    content: ""; position: absolute; left: -.7rem; top: 50%; transform: translateY(-50%);
    width: 4px; height: 60%; border-radius: 0 4px 4px 0; background: var(--b2b-grad);
}
.app-sidebar .nav-link.active::after { content: ""; width: 6px; height: 6px; border-radius: 50%; background: #22c55e; margin-left: auto; box-shadow: 0 0 0 3px rgba(34,197,94,.15); }

/* Backdrop drawer mobile */
.sidebar-backdrop {
    position: fixed; inset: 0; background: rgba(15,23,42,.45); backdrop-filter: blur(2px);
    z-index: 1040; opacity: 0; visibility: hidden; transition: opacity .2s ease, visibility .2s ease;
}
.sidebar-backdrop.show { opacity: 1; visibility: visible; }

/* ============ MAIN / TOPBAR ============ */
.app-main { margin-left: var(--b2b-sidebar); }
.app-topbar { background: #fff; border-bottom: 1px solid var(--b2b-border); height: 64px; }
.topbar-search { position: relative; max-width: 520px; width: 100%; }
.topbar-search i { position: absolute; left: .9rem; top: 50%; transform: translateY(-50%); color: #9aa3b2; }
.topbar-search input { border-radius: 11px; border: 1px solid var(--b2b-border); background: #f8fafc; padding: .55rem .9rem .55rem 2.3rem; font-size: .9rem; }
.topbar-search input:focus { background: #fff; border-color: #c7d2fe; box-shadow: 0 0 0 4px rgba(37,99,235,.1); }
.btn-ghost { border: 1px solid var(--b2b-border); background: #fff; color: #475569; border-radius: 10px; font-size: .85rem; font-weight: 500; padding: .42rem .8rem; }
.btn-ghost:hover { background: #f8fafc; color: #0f172a; }
.user-avatar { width: 38px; height: 38px; border-radius: 11px; background: var(--b2b-grad); color: #fff; font-weight: 700; font-size: .82rem; display: flex; align-items: center; justify-content: center; }

.sidebar-close { display: none; }

@media (max-width: 991.98px) {
    .app-sidebar {
        width: min(82vw, 300px);
        transform: translateX(-100%); transition: transform .24s cubic-bezier(.4,0,.2,1);
    }
    .app-sidebar.show { transform: translateX(0); box-shadow: 0 0 50px rgba(2,6,23,.28); }
    .sidebar-close { display: inline-flex; align-items: center; }
    .app-main { margin-left: 0; }
    body.sidebar-open { overflow: hidden; }
}

@media (max-width: 575.98px) {
    .app-topbar { gap: .5rem !important; }
    .topbar-search input { padding-left: 2.3rem; }
    .page-title { font-size: 1.35rem; }
    main.p-3 { padding: .9rem !important; }
}

/* Tabelle: scroll orizzontale fluido su mobile */
.table-responsive { -webkit-overflow-scrolling: touch; }

/* ============ PAGE / CARD / TABLE ============ */
.page-title { font-weight: 800; letter-spacing: -.6px; font-size: 1.7rem; color: #0f172a; }
.page-sub { color: var(--b2b-muted); font-size: .95rem; }
.card-soft { background: #fff; border: 1px solid var(--b2b-border); border-radius: 16px; box-shadow: 0 1px 2px rgba(16,24,40,.04); }

.btn-primary { background: var(--b2b-grad); border: none; border-radius: 10px; font-weight: 600; padding: .5rem .95rem; box-shadow: 0 8px 18px rgba(37,99,235,.22); }
.btn-primary:hover { filter: brightness(1.08); }

.table { margin: 0; }
.table thead th {
    font-size: .7rem; text-transform: uppercase; letter-spacing: .05em; color: #9aa3b2;
    font-weight: 700; border-bottom: 1px solid var(--b2b-border); padding: .8rem 1rem; white-space: nowrap;
}
.table tbody td { padding: .85rem 1rem; border-bottom: 1px solid #f3f4f7; vertical-align: middle; font-size: .9rem; color: #334155; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: #fafbfc; }
.table .col-strong { font-weight: 600; color: #0f172a; }

/* Badge di stato (pill con pallino) */
.badge-status { display: inline-flex; align-items: center; gap: .4rem; border-radius: 999px; padding: .22rem .65rem; font-size: .76rem; font-weight: 600; line-height: 1; }
.badge-status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.bs-success { background: #ecfdf3; color: #15803d; }
.bs-muted   { background: #f1f5f9; color: #64748b; }
.bs-info    { background: #eff6ff; color: #2563eb; }
.bs-primary { background: #eef2ff; color: #4338ca; }
.bs-warning { background: #fffbeb; color: #b45309; }
.bs-danger  { background: #fef2f2; color: #dc2626; }

/* Dashboard */
.stat-card .display-6 { font-weight: 800; }
.cursor-pointer { cursor: pointer; }

/* Toast realtime */
.b2b-toast { position: fixed; top: 76px; right: 20px; z-index: 1080; background: #0f172a; color: #fff; padding: .7rem 1rem; border-radius: 12px; font-size: .88rem; box-shadow: 0 12px 30px rgba(2,6,23,.25); opacity: 0; transform: translateY(-8px); transition: all .25s; max-width: 320px; }
.b2b-toast.show { opacity: 1; transform: translateY(0); }

/* Agenti — card performance */
.agent-card { background: #fff; border: 1px solid var(--b2b-border); border-radius: 16px; box-shadow: 0 1px 2px rgba(16,24,40,.04); }
.agent-stat { background: #f8fafc; border: 1px solid var(--b2b-border); border-radius: 12px; padding: .7rem .9rem; text-align: center; }
.agent-stat .v { font-weight: 800; font-size: 1.3rem; color: #0f172a; line-height: 1; }
.agent-stat .l { font-size: .68rem; text-transform: uppercase; letter-spacing: .05em; color: #9aa3b2; margin-top: .25rem; }
.agent-stat.green .v { color: #15803d; }
.target-bar { height: 8px; border-radius: 999px; background: #eef1f6; overflow: hidden; }
.target-bar > span { display: block; height: 100%; background: linear-gradient(90deg, #2563eb, #22c55e); }
.agent-qr { width: 64px; height: 64px; border-radius: 10px; border: 1px solid var(--b2b-border); padding: 3px; cursor: pointer; background: #fff; }
.mini-field { border: 1px solid var(--b2b-border); border-radius: 10px; padding: .5rem .7rem; }
.mini-field .l { font-size: .64rem; text-transform: uppercase; letter-spacing: .05em; color: #9aa3b2; }
.mini-field .v { font-weight: 600; color: #0f172a; font-size: .9rem; }

/* PWA */
.pwa-body { background: #0b1220; min-height: 100vh; color: #e5e7eb; }
.pwa-card { background: #111a2e; border: 1px solid #1e293b; border-radius: 16px; }
.pwa-topbar { background: #0b1220; border-bottom: 1px solid #1e293b; }

/* Contenuto: spazio in fondo per non finire sotto la bottom nav */
.pwa-main { padding-top: 1rem; padding-bottom: calc(84px + env(safe-area-inset-bottom)); }

/* Tab: solo la sezione attiva è visibile */
.pwa-tab { display: none; }
.pwa-tab.active { display: block; animation: pwaFade .18s ease; }
@keyframes pwaFade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* Bottom navigation stile app nativa */
.pwa-bottomnav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 1040;
    display: flex; justify-content: space-around; align-items: stretch;
    background: rgba(11,18,32,.92); backdrop-filter: blur(12px);
    border-top: 1px solid #1e293b;
    padding: .35rem .25rem calc(.35rem + env(safe-area-inset-bottom));
}
.pwa-navbtn {
    flex: 1; border: 0; background: transparent; color: #64748b;
    display: flex; flex-direction: column; align-items: center; gap: .15rem;
    padding: .45rem 0; font-size: .7rem; font-weight: 600;
    transition: color .15s; cursor: pointer;
}
.pwa-navbtn i { font-size: 1.35rem; }
.pwa-navbtn.active { color: #fff; }
.pwa-navbtn.active i { color: #6b8afd; }
.pwa-navadd i {
    background: var(--b2b-grad); color: #fff; width: 44px; height: 44px;
    border-radius: 14px; display: flex; align-items: center; justify-content: center;
    margin-top: -16px; box-shadow: 0 8px 20px rgba(43,84,230,.4);
}
.pwa-navadd.active i { color: #fff; }

/* Righe prodotto del nuovo ordine */
.pwa-riga { display: flex; gap: .4rem; align-items: center; margin-bottom: .5rem; }
.pwa-riga .pwa-riga-prod { flex: 1 1 auto; min-width: 0; }
.pwa-riga .pwa-riga-qta { width: 68px; flex: 0 0 auto; text-align: center; }
.pwa-riga .pwa-riga-del { flex: 0 0 auto; border: 0; background: transparent; color: #ef4444; font-size: 1.2rem; line-height: 1; padding: .2rem .35rem; cursor: pointer; }
.modal-content { border: none; border-radius: 16px; }
.modal-header, .modal-footer { border-color: var(--b2b-border); }
.form-control, .form-select { border-radius: 10px; }
.form-control:focus, .form-select:focus { border-color: #c7d2fe; box-shadow: 0 0 0 4px rgba(37,99,235,.1); }
