/* ============================================================
   TEOREMA ERP — STYLESHEET
   ============================================================ */

/* 1. VARIABILI */
:root {
    --sidebar-width:  260px;
    --sidebar-collapsed-width: 64px;
    --sidebar-bg:     #0f172a;
    --sidebar-text:   #94a3b8;
    --sidebar-active: #3b82f6;
    --topbar-height:  60px;
    --font-main:      'Inter', sans-serif;
    --radius:         10px;
    --radius-sm:      6px;
    --shadow:         0 1px 3px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
    --shadow-lg:      0 4px 24px rgba(0,0,0,.12);
    --transition:     .2s ease;
    --content-pad:    24px;
    --content-pad-sm: 14px;
}

/* 2. BASE */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; padding: 0; }
body { font-family: var(--font-main); background: #f1f5f9; color: #1e293b; }

/* 3. SIDEBAR */
.sidebar {
    width:          var(--sidebar-width);
    background:     var(--sidebar-bg);
    position:       fixed;
    top:    0;
    left:   0;
    bottom: 0;
    z-index: 1000;
    display:        flex;
    flex-direction: column;
    transition:     width var(--transition), transform var(--transition);
    overflow:       hidden;
}


.sidebar-header {
    padding:         20px 16px 16px;
    border-bottom:   1px solid rgba(255,255,255,.06);
    display:         flex;
    align-items:     center;
    justify-content: space-between;
    flex-shrink:     0;
    min-height:      64px;
}

.sidebar-brand {
    display:         flex;
    align-items:     center;
    text-decoration: none;
    color:           #fff;
    font-size:       1.05rem;
    font-weight:     700;
    letter-spacing:  -.3px;
    gap:             8px;
    overflow:        hidden;
    white-space:     nowrap;
}

.sidebar-user {
    padding:       12px 16px;
    display:       flex;
    align-items:   center;
    gap:           10px;
    border-bottom: 1px solid rgba(255,255,255,.06);
    flex-shrink:   0;
    overflow:      hidden;
    white-space:   nowrap;
}

.user-avatar {
    width:           38px;
    height:          38px;
    border-radius:   50%;
    background:      linear-gradient(135deg, #3b82f6, #8b5cf6);
    display:         flex;
    align-items:     center;
    justify-content: center;
    color:           #fff;
    font-weight:     700;
    font-size:       .8rem;
    flex-shrink:     0;
}

.user-name      { color: #e2e8f0; font-size: .875rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role      { font-size: .7rem; margin-top: 3px; }

/* Il nav occupa tutto lo spazio disponibile e scrolla */
.sidebar-nav {
    flex:       1 1 0;       /* 1 1 0 invece di solo 1: il basis 0 forza il calc dell'altezza */
    padding:    8px 12px;
    overflow-y: scroll;      /* scroll invece di auto — sempre scrollabile */
    overflow-x: hidden;
    min-height: 0;
    height:     0;           /* con flex:1 1 0 → cresce fino allo spazio disponibile */
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,.2) transparent;
}
.sidebar-nav::-webkit-scrollbar       { width: 4px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 2px; }

.nav-section-title {
    font-size:      .65rem;
    font-weight:    700;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color:          #475569;
    padding:        8px 8px 4px;
    white-space:    nowrap;
    overflow:       hidden;
}

.sidebar-nav .nav-link {
    display:         flex;
    align-items:     center;
    gap:             10px;
    padding:         9px 12px;
    border-radius:   var(--radius-sm);
    color:           var(--sidebar-text);
    font-size:       .875rem;
    font-weight:     500;
    text-decoration: none;
    transition:      all var(--transition);
    margin-bottom:   2px;
    white-space:     nowrap;
    overflow:        hidden;
}
.sidebar-nav .nav-link i    { font-size: 1.05rem; width: 20px; text-align: center; flex-shrink: 0; }
.sidebar-nav .nav-link:hover  { background: rgba(255,255,255,.06); color: #e2e8f0; }
.sidebar-nav .nav-link.active { background: rgba(59,130,246,.15);  color: #60a5fa; }

/* Sotto-voci menu (es. PrestaShop) */
.sidebar-nav .nav-sub {
    padding-left: 2.6rem;
    font-size: .82rem;
    opacity: .85;
}
.sidebar-nav .nav-sub i { font-size: .85rem; }
.sidebar-nav .nav-sub:hover  { opacity: 1; }
.sidebar-nav .nav-sub.active { opacity: 1; }

.sidebar-footer {
    padding:    12px;
    border-top: 1px solid rgba(255,255,255,.06);
    flex-shrink: 0;
}

/* Pulsante collapse desktop */
.btn-sidebar-collapse {
    color:       #64748b;
    background:  transparent;
    border:      none;
    width:       28px;
    height:      28px;
    padding:     0;
    border-radius: 6px;
    display:     flex;
    align-items: center;
    justify-content: center;
    cursor:      pointer;
    flex-shrink: 0;
    transition:  color var(--transition), background var(--transition);
}
.btn-sidebar-collapse:hover { color: #e2e8f0; background: rgba(255,255,255,.08); }

/* Overlay mobile */
.sidebar-overlay {
    display:         none;
    position:        fixed;
    inset:           0;
    background:      rgba(0,0,0,.55);
    z-index:         999;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}
.sidebar-overlay.show { display: block; }

/* ---- SIDEBAR COLLASSATA (desktop) ---- */
/* sidebar-collapsed solo su desktop xl+ */
.sidebar-collapsed .sidebar {
    width: var(--sidebar-collapsed-width);
}
.sidebar-collapsed .sidebar .sidebar-brand span,
.sidebar-collapsed .sidebar .sidebar-brand i,
.sidebar-collapsed .sidebar .user-info,
.sidebar-collapsed .sidebar .nav-section-title,
.sidebar-collapsed .sidebar .nav-link span,
.sidebar-collapsed .sidebar .sidebar-footer .nav-link span,
.sidebar-collapsed .sidebar .sidebar-nav .badge {
    display: none;
}
.sidebar-collapsed .sidebar .nav-link        { justify-content: center; padding: 10px 0; }
.sidebar-collapsed .sidebar .nav-link i      { width: auto; }
.sidebar-collapsed .sidebar .sidebar-user    { justify-content: center; padding: 12px 8px; }
.sidebar-collapsed .sidebar .sidebar-brand   { justify-content: center; }
.sidebar-collapsed .sidebar .sidebar-header  { justify-content: center; padding: 16px 8px; }
.sidebar-collapsed .sidebar-nav              { padding:0px !important; }
.sidebar-collapsed .main-wrapper {
    margin-left: var(--sidebar-collapsed-width) !important;
    width: calc(100% - var(--sidebar-collapsed-width)) !important;
}

/* 4. TOPBAR */
.topbar {
    height:          var(--topbar-height);
    background:      #fff;
    border-bottom:   1px solid #e2e8f0;
    display:         flex;
    align-items:     center;
    justify-content: space-between;
    padding:         0 20px;
    position:        sticky;
    top:             0;
    z-index:         100;
    box-shadow:      0 1px 0 rgba(0,0,0,.04);
    gap:             12px;
    flex-shrink:     0;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 8px; min-width: 0; }
.topbar-left { flex: 1; }
.topbar-toggle, .topbar-user { border: none; background: transparent; color: #64748b; }
.topbar-user { display: flex; align-items: center; gap: 8px; font-size: .875rem; white-space: nowrap; }
.topbar-avatar {
    width: 30px; height: 30px; border-radius: 50%;
    background: linear-gradient(135deg, #3b82f6, #8b5cf6);
    color: #fff; font-weight: 700; font-size: .75rem;
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.breadcrumb { font-size: .82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin: 0; }
.breadcrumb-item a { color: #3b82f6; text-decoration: none; }

/* 5. LAYOUT */
.main-wrapper {
    margin-left:    var(--sidebar-width);
    min-height:     100vh;
    display:        flex;
    flex-direction: column;
    overflow-x:     hidden;
    width:          calc(100% - var(--sidebar-width));
    transition:     margin var(--transition), width var(--transition);
}
.content-area  { flex: 1; padding: var(--content-pad); }
.content-footer { padding: 12px 24px; border-top: 1px solid #e2e8f0; background: #fff; text-align: right; flex-shrink: 0; }
.page-header   { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 20px; flex-wrap: wrap; gap: 12px; }
.page-title    { font-size: 1.4rem; font-weight: 700; color: #0f172a; margin: 0; line-height: 1.2; }
.page-subtitle { color: #64748b; font-size: .875rem; margin: 4px 0 0; }

/* 6. COMPONENTI */
.card { border: 1px solid #e2e8f0; border-radius: var(--radius); box-shadow: var(--shadow); background: #fff; }
.card-header { background: transparent; border-bottom: 1px solid #f1f5f9; padding: 14px 18px; font-weight: 600; font-size: .9rem; display: flex; align-items: center; }
.card-body   { padding: 18px; }

.stat-card { border-radius: var(--radius); padding: 18px; background: #fff; border: 1px solid #e2e8f0; box-shadow: var(--shadow); transition: transform .15s, box-shadow .15s; }
@media (hover:hover) { .stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); } }
.stat-icon  { width: 44px; height: 44px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 1.3rem; }
.stat-value { font-size: 1.75rem; font-weight: 700; line-height: 1; }
.stat-label { color: #64748b; font-size: .8rem; font-weight: 500; margin-top: 4px; }

.table         { margin: 0; font-size: .875rem; }
.table thead th { background: #f8fafc; color: #64748b; font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .5px; border-bottom: 2px solid #e2e8f0; padding: 10px 14px; white-space: nowrap; }
.table tbody td { padding: 11px 14px; vertical-align: middle; border-color: #f1f5f9; }
.table tbody tr:hover { background: #f8fafc; }
.table-actions { white-space: nowrap; }

.form-label     { font-weight: 600; font-size: .82rem; color: #374151; margin-bottom: 4px; }
.form-control, .form-select { border-color: #e2e8f0; border-radius: var(--radius-sm); font-size: .875rem; }
@media (max-width: 767.98px) { .form-control, .form-select { font-size: 16px; } }
.form-control:focus, .form-select:focus { border-color: #3b82f6; box-shadow: 0 0 0 3px rgba(59,130,246,.12); }

.btn          { font-size: .875rem; font-weight: 500; border-radius: var(--radius-sm); }
.btn-primary  { background: #3b82f6; border-color: #3b82f6; }
.btn-primary:hover { background: #2563eb; border-color: #2563eb; }
.btn-icon     { width: 32px; height: 32px; padding: 0; display: inline-flex; align-items: center; justify-content: center; border-radius: var(--radius-sm); }

.badge { font-size: .72rem; font-weight: 600; padding: 4px 8px; border-radius: 5px; }

.filter-bar { background: #fff; border: 1px solid #e2e8f0; border-radius: var(--radius); padding: 14px 18px; margin-bottom: 16px; box-shadow: var(--shadow); }

.empty-state { text-align: center; padding: 50px 20px; color: #94a3b8; }
.empty-state i  { font-size: 2.5rem; margin-bottom: 14px; }
.empty-state h5 { color: #64748b; }

/* 7. LOGIN */
.login-page   { min-height: 100vh; background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 100%); display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card   { background: #fff; border-radius: 16px; padding: 36px; width: 100%; max-width: 420px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.login-logo    { font-size: 2rem; margin-bottom: 8px; }
.login-title   { font-size: 1.5rem; font-weight: 700; color: #0f172a; }
.login-subtitle { color: #64748b; font-size: .875rem; }

/* 8. MOBILE */
@media (max-width: 1199.98px) {
    /* ── Sidebar: fuori schermo, overlay al tap ── */
    .sidebar {
        transform: translateX(-260px);
        z-index: 1055;
        position: fixed;
        width: 260px !important;
        box-shadow: none;
        transition: transform .25s ease;
    }
    .sidebar.show {
        transform: translateX(0);
        box-shadow: 4px 0 30px rgba(0,0,0,.35);
    }
    /* Le voci del menu tornano estese (non collassate) */
    .sidebar .sidebar-brand span,
    .sidebar .user-info,
    .sidebar .nav-section-title,
    .sidebar .nav-link span,
    .sidebar .sidebar-footer .nav-link span,
    .sidebar .sidebar-nav .badge {
        display: block !important;
        opacity: 1 !important;
    }
    .sidebar .nav-link { justify-content: flex-start !important; padding: 10px 16px !important; }
    .sidebar .nav-link i { width: 20px; }

    /* ── Main wrapper: tutta la larghezza, nessun margine ── */
    .main-wrapper {
        margin-left: 0 !important;
        width: 100% !important;
        transition: none;
    }

    /* ── Overlay semi-trasparente dietro il menu aperto ── */
    .sidebar-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,.5);
        z-index: 1054;
        display: none;
        backdrop-filter: blur(1px);
    }
    .sidebar-overlay.show { display: block; }

    /* ── Resto layout mobile ── */
    .content-area { padding: var(--content-pad-sm); }
    .topbar       { padding: 0 12px; }
    .page-header  { flex-direction: column; align-items: stretch; gap: 8px; }
    .page-header .btn { width: 100%; justify-content: center; display: flex; }
    .page-header .d-flex { flex-wrap: wrap; }
    .page-header .d-flex .btn { flex: 1 1 140px; }
    .filter-bar .col-md-auto { display: flex; gap: 8px; }
    .filter-bar .col-md-auto .btn { flex: 1; }
    .btn-icon { min-width: 44px !important; min-height: 44px !important; }
    .login-card { padding: 28px 20px; }
    .breadcrumb { display: none; }
    .btn-sidebar-collapse { display: none !important; }
}

@media (max-width: 575.98px) {
    :root { --content-pad-sm: 12px; }
    .page-title    { font-size: 1.1rem; }
    .page-subtitle { font-size: .78rem; }
    .card-header   { padding: 10px 12px; font-size: .83rem; }
    .card-body     { padding: 12px; }
    .table tbody td { padding: 8px 10px; }
    .table thead th { padding: 8px 10px; }
    .stat-card     { padding: 12px; }
    .stat-value    { font-size: 1.35rem; }
    #ceste-ordine-list { flex-wrap: wrap !important; }
    #select-cesta  { max-width: 100% !important; width: 100%; }
    #form-cesta-container .d-flex { flex-wrap: wrap; gap: 8px; }
    #form-cesta-container .btn { flex: 1 1 80px; }
    #input-scanner-usb { max-width: 100% !important; width: 100%; }
    #qr-reader     { max-width: 100% !important; }
    #lightbox img  { max-width: 96vw !important; max-height: 80vh !important; }
}

/* 9. UTILITIES */
.text-truncate-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.cursor-pointer  { cursor: pointer; }
.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }
.fw-800 { font-weight: 800; }
.fs-7   { font-size: .8rem; }
.font-monospace { font-family: 'Courier New', monospace; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.fade-in { animation: fadeIn .3s ease forwards; }
