:root {
    --dbe-primary: #5c35a0;
    --dbe-primary-dark: #3e1f7a;
    --dbe-primary-light: #7b57c4;
    --dbe-accent: #f0a500;
    --dbe-success: #28a745;
    --dbe-warning: #ffc107;
    --dbe-danger: #dc3545;
    --dbe-info: #17a2b8;
    --dbe-sidebar-bg: #1a1035;
    --dbe-sidebar-width: 250px;
    --dbe-topbar-height: 60px;
    --dbe-text-muted: #6c757d;
    --dbe-border: #e0e0e0;
    --dbe-bg-light: #f8f9fc;
}

* { box-sizing: border-box; }

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--dbe-bg-light);
    color: #333;
    margin: 0;
}

/* ===== SIDEBAR ===== */
.dbe-sidebar {
    position: fixed;
    top: 0; left: 0;
    width: var(--dbe-sidebar-width);
    height: 100vh;
    background: var(--dbe-sidebar-bg);
    display: flex;
    flex-direction: column;
    z-index: 100;
    overflow-y: auto;
}

.dbe-sidebar .brand {
    padding: 20px 16px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    display: flex;
    align-items: center;
    gap: 10px;
}
.dbe-sidebar .brand img { width: 36px; height: 36px; object-fit: contain; }
.dbe-sidebar .brand span {
    color: #fff;
    font-weight: 700;
    font-size: 0.85rem;
    line-height: 1.2;
}

.dbe-nav { flex: 1; padding: 12px 0; }
.dbe-nav .nav-section {
    padding: 8px 16px 4px;
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: rgba(255,255,255,0.35);
}
.dbe-nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    color: rgba(255,255,255,0.65);
    text-decoration: none;
    font-size: 0.88rem;
    border-left: 3px solid transparent;
    transition: all 0.15s;
}
.dbe-nav a:hover, .dbe-nav a.active {
    color: #fff;
    background: rgba(255,255,255,0.07);
    border-left-color: var(--dbe-primary-light);
}
.dbe-nav a svg { opacity: 0.7; flex-shrink: 0; }
.dbe-nav a:hover svg, .dbe-nav a.active svg { opacity: 1; }

.dbe-sidebar-footer {
    padding: 12px 16px;
    border-top: 1px solid rgba(255,255,255,0.08);
    font-size: 0.78rem;
    color: rgba(255,255,255,0.4);
}
.dbe-sidebar-footer a { color: rgba(255,255,255,0.55); text-decoration: none; }
.dbe-sidebar-footer a:hover { color: #fff; }

/* ===== MAIN CONTENT ===== */
.dbe-main {
    margin-left: var(--dbe-sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.dbe-topbar {
    height: var(--dbe-topbar-height);
    background: #fff;
    border-bottom: 1px solid var(--dbe-border);
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 16px;
    position: sticky;
    top: 0;
    z-index: 50;
}
.dbe-topbar .page-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: #222;
    flex: 1;
}
.dbe-topbar .user-info {
    font-size: 0.85rem;
    color: var(--dbe-text-muted);
    display: flex;
    align-items: center;
    gap: 8px;
}

.dbe-content { padding: 24px; flex: 1; }

/* ===== CARDS KPI ===== */
.kpi-card {
    background: #fff;
    border-radius: 12px;
    padding: 20px;
    border: 1px solid var(--dbe-border);
    transition: box-shadow 0.2s;
}
.kpi-card:hover { box-shadow: 0 4px 16px rgba(0,0,0,0.08); }
.kpi-card .kpi-label { font-size: 0.78rem; color: var(--dbe-text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; }
.kpi-card .kpi-value { font-size: 2rem; font-weight: 700; color: #1a1035; margin: 4px 0 2px; line-height: 1; }
.kpi-card .kpi-sub { font-size: 0.8rem; color: var(--dbe-text-muted); }
.kpi-card .kpi-icon { width: 42px; height: 42px; border-radius: 10px; display: flex; align-items: center; justify-content: center; margin-bottom: 12px; }
.kpi-icon.purple { background: rgba(92,53,160,0.1); color: var(--dbe-primary); }
.kpi-icon.green  { background: rgba(40,167,69,0.1);  color: var(--dbe-success); }
.kpi-icon.amber  { background: rgba(240,165,0,0.1);  color: var(--dbe-accent); }
.kpi-icon.red    { background: rgba(220,53,69,0.1);  color: var(--dbe-danger); }
.kpi-icon.teal   { background: rgba(23,162,184,0.1); color: var(--dbe-info); }

/* ===== CARD GENERICA ===== */
.dbe-card {
    background: #fff;
    border-radius: 12px;
    border: 1px solid var(--dbe-border);
    overflow: hidden;
}
.dbe-card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--dbe-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.dbe-card-header h5 {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 600;
    color: #1a1035;
}
.dbe-card-body { padding: 20px; }

/* ===== BADGE STATO ===== */
.badge-stato {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.73rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.stato-bozza       { background: #f1f1f1; color: #555; }
.stato-inviata     { background: #cce5ff; color: #004085; }
.stato-accettata   { background: #d4edda; color: #155724; }
.stato-rifiutata   { background: #f8d7da; color: #721c24; }
.stato-scaduta     { background: #fff3cd; color: #856404; }
.stato-emessa      { background: #cce5ff; color: #004085; }
.stato-inviata_sdi { background: #d6d8f7; color: #2c3a7e; }
.stato-incassata   { background: #d4edda; color: #155724; }
.stato-stornata    { background: #e2e3e5; color: #383d41; }

/* ===== BUTTONS ===== */
.btn-dbe {
    background: var(--dbe-primary);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 8px 18px;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    text-decoration: none;
}
.btn-dbe:hover { background: var(--dbe-primary-dark); color: #fff; }
.btn-dbe.outline {
    background: transparent;
    border: 1.5px solid var(--dbe-primary);
    color: var(--dbe-primary);
}
.btn-dbe.outline:hover { background: var(--dbe-primary); color: #fff; }
.btn-dbe.sm { padding: 5px 12px; font-size: 0.8rem; }
.btn-dbe.danger { background: var(--dbe-danger); }
.btn-dbe.danger:hover { background: #b02a37; }
.btn-dbe.success { background: var(--dbe-success); }
.btn-dbe.success:hover { background: #1e7e34; }

/* ===== FORMS ===== */
.dbe-form-group { margin-bottom: 16px; }
.dbe-form-group label {
    display: block;
    font-size: 0.82rem;
    font-weight: 600;
    color: #444;
    margin-bottom: 5px;
}
.dbe-form-control {
    width: 100%;
    padding: 9px 12px;
    border: 1.5px solid var(--dbe-border);
    border-radius: 8px;
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.15s;
    background: #fff;
    color: #333;
}
.dbe-form-control:focus { border-color: var(--dbe-primary); box-shadow: 0 0 0 3px rgba(92,53,160,0.1); }
.dbe-form-control.error { border-color: var(--dbe-danger); }
select.dbe-form-control { cursor: pointer; }

/* ===== TABLE ===== */
.dbe-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.dbe-table th {
    background: #f5f5f8;
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--dbe-text-muted);
    padding: 10px 14px;
    border-bottom: 1px solid var(--dbe-border);
    text-align: left;
}
.dbe-table td { padding: 11px 14px; border-bottom: 1px solid #f0f0f0; vertical-align: middle; }
.dbe-table tbody tr:hover { background: #fafafa; }
.dbe-table tbody tr:last-child td { border-bottom: none; }

/* ===== OFFERTA RIGHE FORM ===== */
.righe-offerta { width: 100%; border-collapse: collapse; }
.righe-offerta th { background: #f5f5f8; padding: 8px 10px; font-size: 0.78rem; font-weight: 600; color: #666; border: 1px solid #e8e8e8; }
.righe-offerta td { padding: 6px 8px; border: 1px solid #e8e8e8; vertical-align: top; }
.righe-offerta input, .righe-offerta select { width: 100%; padding: 6px 8px; border: 1.5px solid #ddd; border-radius: 6px; font-size: 0.85rem; outline: none; }
.righe-offerta input:focus, .righe-offerta select:focus { border-color: var(--dbe-primary); }
.btn-rimuovi-riga { background: none; border: none; cursor: pointer; color: var(--dbe-danger); padding: 4px; }
/* Riga nota (prezzo=0): evidenziazione visiva */
.righe-offerta tr.riga-nota td { background: #fafaf6; }
.righe-offerta tr.riga-nota .r-cell-num input { opacity: 0.35; pointer-events: none; }

/* ===== LOGIN PAGE ===== */
.login-wrapper {
    min-height: 100vh;
    background: linear-gradient(135deg, #1a1035 0%, #3e1f7a 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.login-box {
    background: #fff;
    border-radius: 16px;
    padding: 40px 36px;
    width: 100%;
    max-width: 380px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.login-box .login-logo { text-align: center; margin-bottom: 24px; }
.login-box .login-logo img { height: 50px; object-fit: contain; }
.login-box h2 { text-align: center; font-size: 1.3rem; font-weight: 700; color: #1a1035; margin-bottom: 4px; }
.login-box .login-sub { text-align: center; font-size: 0.83rem; color: var(--dbe-text-muted); margin-bottom: 28px; }

/* ===== TABS ===== */
.dbe-tabs { display: flex; gap: 0; border-bottom: 2px solid var(--dbe-border); margin-bottom: 20px; }
.dbe-tab {
    padding: 10px 18px;
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--dbe-text-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all 0.15s;
    background: none;
    border-top: none;
    border-left: none;
    border-right: none;
    text-decoration: none;
}
.dbe-tab.active, .dbe-tab:hover { color: var(--dbe-primary); border-bottom-color: var(--dbe-primary); }
.dbe-tab-pane { display: none; }
.dbe-tab-pane.active { display: block; }

/* ===== ALERT ===== */
.dbe-alert {
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 0.88rem;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.dbe-alert.success { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
.dbe-alert.danger  { background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }
.dbe-alert.info    { background: #cce5ff; color: #004085; border: 1px solid #b8daff; }
.dbe-alert.warning { background: #fff3cd; color: #856404; border: 1px solid #ffeeba; }

/* ===== MODAL ===== */
.dbe-modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 200;
    display: flex; align-items: center; justify-content: center;
    padding: 20px;
    opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
.dbe-modal-overlay.show { opacity: 1; pointer-events: auto; }
.dbe-modal {
    background: #fff;
    border-radius: 14px;
    width: 100%;
    max-width: 560px;
    max-height: 90vh;
    overflow-y: auto;
    transform: translateY(20px);
    transition: transform 0.2s;
}
.dbe-modal-overlay.show .dbe-modal { transform: translateY(0); }
.dbe-modal-header {
    padding: 18px 20px;
    border-bottom: 1px solid var(--dbe-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.dbe-modal-header h5 { margin: 0; font-size: 1rem; font-weight: 600; }
.dbe-modal-body { padding: 20px; }
.dbe-modal-footer { padding: 14px 20px; border-top: 1px solid var(--dbe-border); display: flex; justify-content: flex-end; gap: 10px; }

/* ===== TOTALI OFFERTA ===== */
.totali-offerta {
    background: #f8f9fc;
    border: 1px solid var(--dbe-border);
    border-radius: 10px;
    padding: 16px;
}
.totale-row { display: flex; justify-content: space-between; align-items: center; padding: 4px 0; font-size: 0.9rem; }
.totale-row.grand { border-top: 2px solid var(--dbe-primary); margin-top: 8px; padding-top: 10px; font-size: 1.05rem; font-weight: 700; color: var(--dbe-primary); }

/* ===== SCADENZARIO ===== */
.scad-overdue { background: #fff5f5 !important; }
.scad-soon    { background: #fffbf0 !important; }
.scad-ok      { background: #f5fff7 !important; }

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    .dbe-sidebar { transform: translateX(-100%); transition: transform 0.25s; }
    .dbe-sidebar.open { transform: translateX(0); }
    .dbe-main { margin-left: 0; }
    .dbe-topbar { padding: 0 14px; }
    .dbe-content { padding: 14px; }
}

/* ===== MISC ===== */
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-mono { font-family: 'Courier New', monospace; }
.fw-600 { font-weight: 600; }
.color-purple { color: var(--dbe-primary); }
.color-green  { color: var(--dbe-success); }
.color-red    { color: var(--dbe-danger); }
.gap-2 { gap: 8px; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.mt-0{margin-top:0} .mt-1{margin-top:6px} .mt-2{margin-top:12px} .mt-3{margin-top:18px} .mt-4{margin-top:24px}
.mb-0{margin-bottom:0} .mb-1{margin-bottom:6px} .mb-2{margin-bottom:12px} .mb-3{margin-bottom:18px} .mb-4{margin-bottom:24px}
.p-0{padding:0} .p-3{padding:18px}
