:root {
    --sb-primary:    #0ea371;
    --sb-primary-d:  #057857;
    --sb-accent:     #0891b2;
    --sb-sidebar-bg: #0f1f1a;
    --sb-sidebar-bg2:#112a22;
    --sb-sidebar-fg: #d7e4df;
    --sb-sidebar-muted: #7a9089;
    --sb-content-bg: #f5f7f9;
    --sb-border:     #e4e8ec;
    --sb-radius:     14px;
    --sb-shadow:     0 1px 2px rgba(15,31,26,.04), 0 6px 18px rgba(15,31,26,.05);
}

* { font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif; }

body { background: var(--sb-content-bg); color: #1f2937; }

/* Bootstrap overrides */
.btn-primary { background: var(--sb-primary); border-color: var(--sb-primary); }
.btn-primary:hover, .btn-primary:focus { background: var(--sb-primary-d); border-color: var(--sb-primary-d); }
.btn-outline-primary { color: var(--sb-primary); border-color: var(--sb-primary); }
.btn-outline-primary:hover, .btn-outline-primary.active { background: var(--sb-primary); border-color: var(--sb-primary); }
a { color: var(--sb-primary-d); }
.text-primary { color: var(--sb-primary) !important; }
.bg-primary   { background-color: var(--sb-primary) !important; }

/* ---------- Shell ---------- */
.sb-shell { display: flex; min-height: 100vh; }
.sb-main  { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.sb-content { padding: 24px 28px; flex: 1; }

/* ---------- Sidebar ---------- */
.sb-sidebar {
    width: 240px; flex-shrink: 0;
    background: linear-gradient(180deg, var(--sb-sidebar-bg) 0%, var(--sb-sidebar-bg2) 100%);
    color: var(--sb-sidebar-fg);
    display: flex; flex-direction: column;
    position: sticky; top: 0; height: 100vh;
    padding: 18px 14px;
}
.sb-brand { display: flex; align-items: center; gap: 12px; padding: 6px 8px 22px; border-bottom: 1px solid rgba(255,255,255,.06); margin-bottom: 14px; }
.sb-brand-logo {
    width: 42px; height: 42px; border-radius: 12px;
    background: linear-gradient(135deg, var(--sb-primary) 0%, var(--sb-accent) 100%);
    display: grid; place-items: center; font-size: 22px; color: #fff;
    box-shadow: 0 4px 14px rgba(14,163,113,.35);
}
.sb-brand-name { font-weight: 700; font-size: 17px; line-height: 1; color: #fff; }
.sb-brand-sub  { font-size: 11px; text-transform: uppercase; letter-spacing: .12em; color: var(--sb-sidebar-muted); margin-top: 3px; }

.sb-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sb-nav-item {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 12px; border-radius: 10px;
    color: var(--sb-sidebar-fg); text-decoration: none;
    font-size: 14px; font-weight: 500;
    transition: all .15s ease;
}
.sb-nav-item i { font-size: 17px; opacity: .9; width: 20px; text-align: center; }
.sb-nav-item:hover { background: rgba(255,255,255,.05); color: #fff; }
.sb-nav-item.active {
    background: linear-gradient(135deg, rgba(14,163,113,.22), rgba(8,145,178,.14));
    color: #fff;
    box-shadow: inset 0 0 0 1px rgba(14,163,113,.35);
}

.sb-nav-sep { height: 1px; background: rgba(255,255,255,.06); margin: 10px 8px; }
.sb-sidebar-footer { border-top: 1px solid rgba(255,255,255,.06); padding-top: 12px; }
.sb-user { display: flex; align-items: center; gap: 10px; padding: 6px; }
.sb-user-avatar {
    width: 38px; height: 38px; border-radius: 50%;
    background: linear-gradient(135deg, var(--sb-primary), var(--sb-accent));
    display: grid; place-items: center; font-weight: 700; color: #fff; font-size: 13px;
}
.sb-user-info { flex: 1; min-width: 0; }
.sb-user-name { font-weight: 600; color: #fff; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-user-role { font-size: 11px; color: var(--sb-sidebar-muted); text-transform: capitalize; }

/* ---------- Topbar ---------- */
.sb-topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 28px; background: #fff; border-bottom: 1px solid var(--sb-border);
    position: sticky; top: 0; z-index: 10;
}
.sb-page-title { font-size: 20px; font-weight: 700; margin: 0; color: #0f172a; }

/* ---------- KPI ---------- */
.sb-kpi {
    background: #fff; border: 1px solid var(--sb-border); border-radius: var(--sb-radius);
    box-shadow: var(--sb-shadow);
    padding: 18px; display: flex; gap: 16px; align-items: center;
    transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
    position: relative;
    text-decoration: none; color: inherit;
}
a.sb-kpi { cursor: pointer; }
.sb-kpi:hover { transform: translateY(-2px); box-shadow: 0 10px 28px rgba(15,31,26,.09); border-color: #cfd8e0; color: inherit; text-decoration: none; }
.sb-kpi-arrow {
    position: absolute; top: 14px; right: 14px;
    width: 26px; height: 26px; border-radius: 8px;
    display: grid; place-items: center;
    background: #f1f5f9; color: #64748b; font-size: 13px;
    opacity: 0; transform: translateX(-4px);
    transition: opacity .15s ease, transform .15s ease, background .15s ease;
}
.sb-kpi:hover .sb-kpi-arrow { opacity: 1; transform: translateX(0); background: var(--sb-primary); color: #fff; }
.sb-kpi-icon {
    width: 52px; height: 52px; border-radius: 12px;
    display: grid; place-items: center; font-size: 24px; color: #fff; flex-shrink: 0;
}
.sb-kpi-primary .sb-kpi-icon { background: linear-gradient(135deg, var(--sb-primary), var(--sb-accent)); }
.sb-kpi-success .sb-kpi-icon { background: linear-gradient(135deg, #10b981, #059669); }
.sb-kpi-warning .sb-kpi-icon { background: linear-gradient(135deg, #f59e0b, #d97706); }
.sb-kpi-danger  .sb-kpi-icon { background: linear-gradient(135deg, #ef4444, #dc2626); }
.sb-kpi-label { font-size: 12px; color: #64748b; text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.sb-kpi-value { font-size: 26px; font-weight: 700; line-height: 1.1; color: #0f172a; margin-top: 2px; }
.sb-kpi-sub   { font-size: 12px; color: #94a3b8; margin-top: 2px; }

/* ---------- Cards / tables ---------- */
.sb-card { border: 1px solid var(--sb-border); border-radius: var(--sb-radius); box-shadow: var(--sb-shadow); background: #fff; }
.sb-card .card-header { background: #fff; border-bottom: 1px solid var(--sb-border); padding: 14px 18px; }
.sb-card .card-header h5 { font-size: 15px; font-weight: 600; color: #0f172a; }

/* altezze fisse per mappa e grafici (evita auto-sizing di Chart.js) */
.sb-map         { height: 420px; border-radius: 0 0 var(--sb-radius) var(--sb-radius); }
.sb-chart-wrap  { position: relative; height: 360px; }
.sb-chart-wrap-sm { position: relative; height: 280px; }

.sb-table thead th { background: #fafbfc; color: #475569; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; font-weight: 600; border-bottom: 1px solid var(--sb-border); }
.sb-table tbody td { vertical-align: middle; }

/* ---------- Progress bars ---------- */
.sb-progress { height: 8px; background: #e5e7eb; border-radius: 999px; overflow: hidden; }
.sb-progress-bar { height: 100%; border-radius: 999px; transition: width .3s ease; }

/* ---------- Misc ---------- */
.sb-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: baseline; }
.sb-fraction-badge { display: inline-block; width: 14px; height: 14px; border-radius: 4px; }
.sb-alert-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-top: 7px; flex-shrink: 0; }
.sb-container-card { transition: transform .15s, box-shadow .15s; cursor: pointer; }
.sb-container-card:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(15,31,26,.08); }

/* ---------- Auth page ---------- */
.sb-auth-body { background: #f5f7f9; min-height: 100vh; margin: 0; }
.sb-auth-wrap { display: grid; grid-template-columns: 1fr 1fr; min-height: 100vh; }
.sb-auth-flash { position: fixed; top: 20px; right: 20px; z-index: 1050; max-width: 380px; }

.sb-auth-left {
    background: linear-gradient(135deg, #0f1f1a 0%, #0ea371 60%, #0891b2 120%);
    color: #fff; display: flex; align-items: center; justify-content: center;
    padding: 40px; position: relative; overflow: hidden;
}
.sb-auth-left::before {
    content: ''; position: absolute; inset: 0;
    background-image: radial-gradient(circle at 20% 20%, rgba(255,255,255,.1) 0, transparent 40%),
                      radial-gradient(circle at 80% 80%, rgba(255,255,255,.08) 0, transparent 40%);
}
.sb-auth-hero { position: relative; z-index: 1; max-width: 440px; }
.sb-auth-logo { width: 64px; height: 64px; border-radius: 18px; background: rgba(255,255,255,.14); backdrop-filter: blur(10px); display: grid; place-items: center; font-size: 32px; margin-bottom: 24px; }
.sb-auth-hero h1 { font-size: 44px; font-weight: 700; line-height: 1.1; margin-bottom: 16px; }
.sb-auth-hero h1 span { font-weight: 400; opacity: .85; }
.sb-auth-hero .lead { font-size: 16px; opacity: .9; margin-bottom: 28px; }
.sb-auth-features { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.sb-auth-features li { display: flex; align-items: center; gap: 12px; font-size: 14px; opacity: .92; }
.sb-auth-features i { color: #a7f3d0; font-size: 18px; }

.sb-auth-right { display: flex; align-items: center; justify-content: center; padding: 40px; }
.sb-auth-card { width: 100%; max-width: 420px; background: #fff; border-radius: 18px; padding: 36px; box-shadow: var(--sb-shadow); }
.sb-auth-card h2 { font-weight: 700; font-size: 24px; margin-bottom: 4px; }
.sb-auth-card .form-control { border-radius: 10px; }
.sb-auth-card .input-group-text { background: #f8fafc; border-right: 0; border-radius: 10px 0 0 10px; }
.sb-auth-card .input-group .form-control { border-left: 0; border-radius: 0 10px 10px 0; }
.sb-auth-card .btn { border-radius: 10px; font-weight: 600; }
.sb-auth-foot { text-align: center; margin-top: 28px; }

@media (max-width: 900px) {
    .sb-auth-wrap { grid-template-columns: 1fr; }
    .sb-auth-left { display: none; }
    .sb-sidebar { position: fixed; left: -240px; z-index: 1030; transition: left .25s; }
    .sb-sidebar.open { left: 0; }
    .sb-content { padding: 16px; }
}
