* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}
:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #dbeafe;
    --green: #16a34a;
    --green-light: #dcfce7;
    --red: #dc2626;
    --red-light: #fee2e2;
    --yellow: #f59e0b;
    --yellow-light: #fef3c7;
    --gray-50: #f8fafc;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-400: #94a3b8;
    --gray-500: #64748b;
    --gray-600: #475569;
    --gray-700: #334155;
    --gray-800: #1e293b;
    --gray-900: #0f172a;
    --shadow: 0 1px 3px rgba(0,0,0,.1),0 1px 2px rgba(0,0,0,.06);
    --shadow-md: 0 4px 6px rgba(0,0,0,.07),0 2px 4px rgba(0,0,0,.06);
    --shadow-lg: 0 10px 15px rgba(0,0,0,.1),0 4px 6px rgba(0,0,0,.05);
    --radius: 8px;
    --sidebar: 260px;
}
html, body { height: 100%; font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; font-size: 14px; color: var(--gray-800); background: var(--gray-100); }

/* Login */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: linear-gradient(135deg, var(--primary) 0%, #1e40af 100%); }
.login-card { background: #fff; border-radius: 16px; padding: 48px 40px; width: 420px; box-shadow: var(--shadow-lg); }
.login-card h1 { font-size: 24px; font-weight: 700; color: var(--gray-900); margin-bottom: 4px; }
.login-card .subtitle { color: var(--gray-500); margin-bottom: 32px; font-size: 14px; }
.login-card .form-group { margin-bottom: 20px; }
.login-card .form-group label { display: block; font-size: 13px; font-weight: 600; color: var(--gray-700); margin-bottom: 6px; }
.login-card .form-group input { width: 100%; padding: 10px 14px; border: 1.5px solid var(--gray-200); border-radius: var(--radius); font-size: 14px; transition: border-color .2s; }
.login-card .form-group input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
.login-error { background: var(--red-light); color: var(--red); padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px; font-size: 13px; display: none; }

/* Layout */
.app-layout { display: flex; height: 100vh; overflow: hidden; }
.sidebar { width: var(--sidebar); background: var(--gray-900); color: #fff; display: flex; flex-direction: column; flex-shrink: 0; }
.sidebar-header { padding: 20px 20px 16px; border-bottom: 1px solid rgba(255,255,255,.08); }
.sidebar-header h2 { font-size: 18px; font-weight: 700; letter-spacing: -.3px; }
.sidebar-header .sub { font-size: 11px; color: var(--gray-400); margin-top: 2px; }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 12px 12px; }
.nav-item { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-radius: var(--radius); cursor: pointer; transition: all .15s; color: var(--gray-300); font-size: 14px; font-weight: 500; margin-bottom: 2px; }
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-item .icon { width: 20px; text-align: center; font-size: 16px; }
.nav-item .badge { margin-left: auto; background: var(--red); color: #fff; font-size: 11px; font-weight: 600; padding: 1px 8px; border-radius: 10px; }
.nav-section { padding: 16px 14px 6px; font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 1px; color: var(--gray-500); }

.sidebar-footer { padding: 12px; border-top: 1px solid rgba(255,255,255,.08); }
.sidebar-user { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius); cursor: pointer; }
.sidebar-user:hover { background: rgba(255,255,255,.06); }
.sidebar-user .avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--primary); display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 13px; color: #fff; }
.sidebar-user .info { flex: 1; }
.sidebar-user .name { font-size: 13px; font-weight: 600; }
.sidebar-user .role { font-size: 11px; color: var(--gray-400); }
.sidebar-user .logout { color: var(--gray-500); font-size: 16px; cursor: pointer; padding: 4px; }
.sidebar-user .logout:hover { color: var(--red); }

.main-area { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.topbar { background: #fff; padding: 12px 28px; border-bottom: 1px solid var(--gray-200); display: flex; align-items: center; justify-content: space-between; flex-shrink: 0; }
.mobile-menu-btn { display: none; font-size: 20px; cursor: pointer; color: var(--gray-700); margin-right: 12px; }
.topbar h1 { font-size: 18px; font-weight: 600; color: var(--gray-800); }
.topbar .actions { display: flex; gap: 8px; align-items: center; }
.content { flex: 1; overflow-y: auto; padding: 24px 28px; }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px; border-radius: var(--radius); font-size: 13px; font-weight: 600; cursor: pointer; border: none; transition: all .15s; white-space: nowrap; text-decoration: none; }
.btn-primary { background: var(--custom-primary, var(--primary)); color: #fff; }
.btn-primary:hover { background: var(--custom-primary, var(--primary-dark)); filter: brightness(.9); }
.btn-green { background: var(--green); color: #fff; }
.btn-green:hover { background: #15803d; }
.btn-red { background: var(--red); color: #fff; }
.btn-red:hover { background: #b91c1c; }
.btn-outline { background: transparent; color: var(--gray-600); border: 1.5px solid var(--gray-300); }
.btn-outline:hover { background: var(--gray-50); border-color: var(--gray-400); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon { padding: 6px 10px; }

/* Cards */
.card { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 20px; }
.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.card-header h3 { font-size: 16px; font-weight: 600; }
.card-title { font-size: 14px; font-weight: 600; margin-bottom: 12px; }

/* Stats Grid */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: #fff; border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.stat-card .label { font-size: 12px; font-weight: 500; color: var(--gray-500); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 6px; }
.stat-card .value { font-size: 28px; font-weight: 700; color: var(--gray-900); }
.stat-card .sub { font-size: 12px; color: var(--gray-500); margin-top: 4px; }
.stat-card .icon-bg { width: 40px; height: 40px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 18px; margin-bottom: 12px; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th { background: var(--gray-50); padding: 10px 12px; text-align: left; font-weight: 600; color: var(--gray-600); border-bottom: 2px solid var(--gray-200); white-space: nowrap; }
tbody td { padding: 10px 12px; border-bottom: 1px solid var(--gray-100); color: var(--gray-700); }
tbody tr:hover { background: var(--gray-50); }
.status-badge { display: inline-block; padding: 2px 10px; border-radius: 12px; font-size: 11px; font-weight: 600; text-transform: capitalize; }
.status-badge.approved { background: var(--green-light); color: var(--green); }
.status-badge.rejected { background: var(--red-light); color: var(--red); }
.status-badge.pending { background: var(--yellow-light); color: var(--yellow); }
.status-badge.draft { background: var(--gray-100); color: var(--gray-600); }

/* Forms */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid .full { grid-column: 1 / -1; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; color: var(--gray-700); margin-bottom: 6px; }
.form-group input, .form-group select, .form-group textarea { width: 100%; padding: 9px 12px; border: 1.5px solid var(--gray-200); border-radius: var(--radius); font-size: 14px; font-family: inherit; transition: border-color .2s; background: #fff; }
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
.form-group textarea { resize: vertical; min-height: 80px; }

/* Modal */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 1000; align-items: center; justify-content: center; padding: 20px; }
.modal-overlay.show { display: flex; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 700px; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow-lg); }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 20px 24px; border-bottom: 1px solid var(--gray-200); }
.modal-header h2 { font-size: 18px; font-weight: 700; }
.modal-close { background: none; border: none; font-size: 24px; cursor: pointer; color: var(--gray-400); padding: 4px; line-height: 1; }
.modal-close:hover { color: var(--gray-700); }
.modal-body { padding: 24px; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--gray-200); display: flex; justify-content: flex-end; gap: 8px; }
.modal-wide { max-width: 900px; }

/* Charts grid */
.charts-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 24px; }
.chart-card { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.chart-card h3 { font-size: 14px; font-weight: 600; margin-bottom: 12px; }
.chart-card canvas { max-height: 300px; }

/* Filter bar */
.filter-bar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 20px; background: #fff; padding: 12px 16px; border-radius: var(--radius); box-shadow: var(--shadow); }
.filter-bar select, .filter-bar input { padding: 7px 10px; border: 1.5px solid var(--gray-200); border-radius: 6px; font-size: 13px; background: #fff; }
.filter-bar select:focus, .filter-bar input:focus { outline: none; border-color: var(--primary); }

/* Inline items table */
.items-table input { width: 100%; padding: 6px 8px; border: 1px solid var(--gray-200); border-radius: 4px; font-size: 13px; }
.items-table input:focus { outline: none; border-color: var(--primary); }
.items-table .remove-item { color: var(--red); cursor: pointer; font-weight: 600; font-size: 16px; }

/* Loading */
.loading { display: flex; align-items: center; justify-content: center; padding: 60px; color: var(--gray-400); }
.spinner { width: 32px; height: 32px; border: 3px solid var(--gray-200); border-top-color: var(--primary); border-radius: 50%; animation: spin .6s linear infinite; margin-right: 12px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Empty state */
.empty-state { text-align: center; padding: 60px 20px; color: var(--gray-400); }
.empty-state .icon { font-size: 48px; margin-bottom: 12px; }
.empty-state h3 { font-size: 16px; color: var(--gray-600); margin-bottom: 4px; }

/* Toast */
.toast-container { position: fixed; top: 20px; right: 20px; z-index: 2000; display: flex; flex-direction: column; gap: 8px; }
.toast { padding: 12px 20px; border-radius: var(--radius); box-shadow: var(--shadow-lg); color: #fff; font-size: 13px; font-weight: 500; animation: slideIn .3s ease; display: flex; align-items: center; gap: 8px; }
.toast-success { background: var(--green); }
.toast-error { background: var(--red); }
.toast-info { background: var(--primary); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

@media (max-width: 768px) {
    .mobile-menu-btn { display: block; }
    .sidebar { display: none; position: fixed; inset: 0; z-index: 1001; width: 260px; }
    .sidebar.active { display: flex; }
    .form-grid { grid-template-columns: 1fr; }
    .charts-grid { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .content { padding: 16px; }
}

/* Tema personalizzato per azienda */
:root {
    --custom-primary: #2563eb;
    --custom-secondary: #f8fafc;
    --custom-bg: #ffffff;
}
.main-area {
    background: var(--custom-secondary, var(--gray-100));
}
.content {
    background: var(--custom-bg, #ffffff);
    min-height: 100%;
}
.app-layout.has-header-image .main-area {
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
}
.main-area.with-header-image::before {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--header-image);
    background-size: cover;
    background-position: center;
    opacity: 0.15;
    pointer-events: none;
    z-index: 0;
}
.main-area {
    position: relative;
    background: var(--custom-secondary, var(--gray-100));
}
.main-area > * {
    position: relative;
    z-index: 1;
}
.topbar {
    background: var(--custom-bg, #fff);
}

/* ================ Aggiornamenti page ================ */
.updates-page h2 { margin-bottom:16px; }
.update-tabs { display:flex; gap:8px; margin-bottom:16px; border-bottom:2px solid var(--gray-200); padding-bottom:0; }
.tab-btn { padding:8px 18px; border:none; background:none; cursor:pointer; font-size:14px; font-weight:500; color:var(--gray-500); border-bottom:2px solid transparent; margin-bottom:-2px; transition:all .15s; }
.tab-btn:hover { color:var(--primary); }
.tab-btn.active { color:var(--primary); border-bottom-color:var(--primary); }
.tab-content { display:none; }
.tab-content.active { display:block; }
.changelog-card { background:#fff; border:1px solid var(--gray-200); border-radius:8px; padding:16px; margin-bottom:10px; }
.changelog-header { display:flex; justify-content:space-between; align-items:center; margin-bottom:8px; }
.changelog-version { font-weight:700; font-size:15px; color:var(--primary); }
.changelog-date { font-size:12px; color:var(--gray-500); }
.changelog-body p { margin:0; font-size:13px; line-height:1.5; color:var(--gray-700); }
.changelog-footer { display:flex; gap:16px; margin-top:8px; font-size:11px; color:var(--gray-400); }
.backup-table { width:100%; border-collapse:collapse; font-size:13px; }
.backup-table th, .backup-table td { padding:8px 10px; text-align:left; border-bottom:1px solid var(--gray-200); }
.backup-table th { font-weight:600; color:var(--gray-600); font-size:12px; text-transform:uppercase; }
.backup-table .actions-cell { white-space:nowrap; }
.backup-table .actions-cell .btn { margin-right:4px; }
.card .warning { color:#dc2626; font-weight:500; font-size:13px; }
.card .success { color:#16a34a; font-weight:500; }
.card .error { color:#dc2626; }
.loading-msg { color:var(--gray-400); font-style:italic; }
.help-text { font-size:12px; color:var(--gray-400); margin-top:4px; }
.auto-hint { font-size:11px; color:var(--gray-400); font-weight:400; }
.confirm-modal { max-width:480px; }
.confirm-modal .modal-body { font-size:14px; line-height:1.6; color:var(--gray-700); padding:16px 0; }
.log-viewer { background:#1e293b; color:#e2e8f0; padding:14px 16px; border-radius:6px; font-family:Courier,monospace; font-size:11px; line-height:1.5; max-height:500px; overflow:auto; white-space:pre-wrap; word-break:break-all; margin:0; }
.table-search-input { width:100%; padding:8px 12px; border:1px solid var(--gray-200); border-radius:6px; font-size:14px; box-sizing:border-box; }
.table-search-input:focus { outline:none; border-color:var(--primary); box-shadow:0 0 0 3px rgba(37,99,235,.15); }
.pagination-bar { display:flex; align-items:center; justify-content:space-between; margin-top:12px; padding:8px 0; }
.pagination-bar .page-info { font-size:13px; color:var(--gray-500); }
.pagination-bar .btn:disabled { opacity:.4; cursor:default; }
