/* ===== CANTIERI PRO — UNIFIED RESPONSIVE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Colors */
  --primary: #4f46e5; --primary-light: #6366f1; --primary-dark: #3730a3;
  --primary-50: #eef2ff; --primary-100: #e0e7ff; --primary-200: #c7d2fe;
  --success: #059669; --success-light: #d1fae5; --success-bg: #ecfdf5;
  --warning: #d97706; --warning-light: #fef3c7; --warning-bg: #fffbeb;
  --danger: #dc2626; --danger-light: #fee2e2; --danger-bg: #fef2f2;
  --info: #0891b2; --info-light: #cffafe; --info-bg: #ecfeff;
  --gray-25: #fcfcfd; --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;
  --sidebar-bg: #0f172a;
  /* Layout */
  --sidebar-w: 260px; --header-h: 64px; --bottom-nav-h: 64px; --radius: 12px;
  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0,0,0,.04);
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,.06), 0 2px 4px -2px rgba(0,0,0,.04);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.08), 0 4px 6px -4px rgba(0,0,0,.04);
  --shadow-xl: 0 20px 25px -5px rgba(0,0,0,.1), 0 8px 10px -6px rgba(0,0,0,.04);
  --transition: .2s cubic-bezier(.4,0,.2,1);
}

html { font-size: 14px; -webkit-font-smoothing: antialiased; }
body { font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif; background: var(--gray-50); color: var(--gray-800); min-height: 100vh; }

/* ===== LAYOUTS ===== */

/* Desktop Sidebar */
.desktop-layout { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w); position: fixed; left: 0; top: 0; bottom: 0;
  background: var(--sidebar-bg); z-index: 100; display: flex; flex-direction: column;
  border-right: 1px solid rgba(255,255,255,.06);
}
.sidebar-header { padding: 20px; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand-icon { width: 36px; height: 36px; background: linear-gradient(135deg, var(--primary), var(--primary-light)); border-radius: 10px; display: flex; align-items: center; justify-content: center; color: #fff; font-size: 16px; }
.brand-text { color: #fff; font-size: 16px; font-weight: 800; }
.sidebar-nav { flex: 1; padding: 12px; overflow-y: auto; }
.nav-section { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--gray-500); padding: 16px 12px 8px; }
.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; margin-bottom: 2px;
  border-radius: 8px; color: var(--gray-400); text-decoration: none; font-size: 14px;
  font-weight: 500; cursor: pointer; transition: var(--transition); white-space: nowrap;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; box-shadow: 0 4px 12px rgba(79,70,229,.35); }
.nav-item i { width: 20px; text-align: center; }
.nav-badge { margin-left: auto; background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; min-width: 20px; height: 20px; border-radius: 10px; display: flex; align-items: center; justify-content: center; }
.nav-badge:empty { display: none; }

.main-content { margin-left: var(--sidebar-w); flex: 1; min-height: 100vh; }
.top-header {
  height: var(--header-h); background: rgba(255,255,255,.8); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--gray-200); padding: 0 28px; display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 50;
}
.header-left { display: flex; align-items: center; gap: 16px; }
.breadcrumb { display: flex; align-items: center; gap: 8px; color: var(--gray-400); font-size: 14px; }
.breadcrumb .sep { font-size: 10px; }
#breadcrumbPage { color: var(--gray-800); font-weight: 600; }
.header-right { display: flex; align-items: center; gap: 16px; }
.search-box { position: relative; }
.search-box input {
  width: 280px; padding: 10px 16px 10px 40px; border: 1px solid var(--gray-200);
  border-radius: var(--radius); font-family: inherit; font-size: 14px; background: var(--gray-50);
  transition: var(--transition);
}
.search-box input:focus { outline: none; border-color: var(--primary-light); background: #fff; box-shadow: 0 0 0 3px var(--primary-100); }
.search-box i { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--gray-400); font-size: 14px; }
.page-content { padding: 28px; max-width: 1400px; }

/* Mobile Layout */
.mobile-layout { min-height: 100vh; padding-bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom)); }
.mobile-header {
  position: sticky; top: 0; background: var(--gray-50); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--gray-200); padding: 12px 16px;
  display: flex; justify-content: space-between; align-items: center; z-index: 100;
}
.mh-brand { display: flex; align-items: center; gap: 10px; }
.mh-brand i { font-size: 22px; color: var(--primary); }
.mh-brand span { font-size: 17px; font-weight: 700; color: var(--gray-900); }
.mh-actions { display: flex; gap: 8px; }
.mobile-content { padding: 16px; }

.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; height: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom); background: #fff; border-top: 1px solid var(--gray-200);
  display: flex; justify-content: space-around; z-index: 100;
}
.bottom-nav button { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; border: none; background: none; color: var(--gray-400); font-size: 10px; cursor: pointer; transition: var(--transition); }
.bottom-nav button i { font-size: 20px; }
.bottom-nav button.active { color: var(--primary); }

/* ===== COMPONENTS ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px; border-radius: 8px; font-family: inherit; font-size: 13px;
  font-weight: 600; border: none; cursor: pointer; transition: var(--transition);
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); transform: translateY(-1px); }
.btn-secondary { background: var(--gray-100); color: var(--gray-700); }
.btn-secondary:hover { background: var(--gray-200); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-icon { width: 36px; height: 36px; padding: 0; border-radius: 8px; background: transparent; color: var(--gray-500); }
.btn-icon:hover { background: var(--gray-100); color: var(--gray-700); }

/* Cards */
.card { background: #fff; border-radius: var(--radius); border: 1px solid var(--gray-200); box-shadow: var(--shadow-sm); margin-bottom: 16px; overflow: hidden; }
.card:hover { box-shadow: var(--shadow-md); }
.card-header { padding: 16px 20px; border-bottom: 1px solid var(--gray-100); display: flex; justify-content: space-between; align-items: center; }
.card-header h3 { font-size: 15px; font-weight: 700; display: flex; align-items: center; gap: 10px; }
.card-header h3 i { color: var(--primary); }
.card-body { padding: 20px; }
.card-row { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--gray-100); cursor: pointer; transition: var(--transition); }
.card-row:hover { background: var(--gray-50); }
.card-row:last-child { border-bottom: none; }
.fw-700 { font-weight: 700; }
.text-sm { font-size: 13px; }
.text-muted { color: var(--gray-500); }
.card-sub { font-size: 13px; color: var(--gray-500); margin-top: 2px; }

/* KPI */
.kpi-grid { display: grid; gap: 16px; margin-bottom: 24px; }
.kpi-grid.mobile { grid-template-columns: repeat(2, 1fr); }
.kpi-grid.desktop { grid-template-columns: repeat(4, 1fr); }
.kpi-card { background: #fff; border-radius: var(--radius); padding: 20px; border: 1px solid var(--gray-200); display: flex; justify-content: space-between; box-shadow: var(--shadow-sm); cursor: pointer; transition: var(--transition); position: relative; }
.kpi-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.kpi-info h4 { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--gray-500); margin-bottom: 8px; }
.kpi-value { font-size: 28px; font-weight: 800; color: var(--gray-900); line-height: 1; }
.kpi-change { font-size: 12px; margin-top: 8px; display: flex; align-items: center; gap: 4px; font-weight: 600; }
.kpi-change.up { color: var(--success); }
.kpi-change.down { color: var(--danger); }
.kpi-icon { width: 48px; height: 48px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 20px; }
.kpi-icon.blue { background: var(--primary-50); color: var(--primary); }
.kpi-icon.green { background: var(--success-bg); color: var(--success); }
.kpi-icon.orange { background: var(--warning-bg); color: var(--warning); }
.kpi-icon.red { background: var(--danger-bg); color: var(--danger); }

/* Tables */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; padding: 12px 16px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--gray-500); background: var(--gray-50); border-bottom: 2px solid var(--gray-200); white-space: nowrap; }
.table td { padding: 14px 16px; border-bottom: 1px solid var(--gray-100); color: var(--gray-700); }
.table tr:hover td { background: var(--gray-50); }
.table tr.clickable { cursor: pointer; }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-attivo { background: var(--success-bg); color: var(--success); }
.badge-sospeso { background: var(--warning-bg); color: var(--warning); }
.badge-completato { background: var(--primary-100); color: var(--primary); }
.badge-pending { background: var(--warning-bg); color: var(--warning); }
.badge-approvato { background: var(--success-bg); color: var(--success); }
.badge-rifiutato { background: var(--danger-bg); color: var(--danger); }

/* Progress */
.progress-bar { height: 8px; background: var(--gray-200); border-radius: 4px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 4px; background: linear-gradient(90deg, var(--primary), var(--primary-light)); transition: width .5s ease; }
.progress-fill.success { background: linear-gradient(90deg, var(--success), #34d399); }
.progress-fill.warning { background: linear-gradient(90deg, var(--warning), #fbbf24); }
.progress-fill.danger { background: linear-gradient(90deg, var(--danger), #f87171); }

/* Avatar */
.avatar { width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; color: #fff; }
.avatar-sm { width: 28px; height: 28px; font-size: 11px; }
.avatar-lg { width: 48px; height: 48px; font-size: 16px; }

/* Grid */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }

/* Empty state */
.empty-state { text-align: center; padding: 60px 20px; color: var(--gray-400); }
.empty-state i { font-size: 48px; margin-bottom: 16px; opacity: .5; }
.empty-state h4 { font-size: 16px; font-weight: 600; color: var(--gray-600); margin-bottom: 8px; }

/* Toast */
.toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
.toast { display: flex; align-items: center; gap: 12px; padding: 14px 20px; background: var(--gray-800); color: #fff; border-radius: 10px; font-size: 14px; animation: slideIn .3s ease; }
@keyframes slideIn { from { opacity: 0; transform: translateX(40px); } }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

/* Modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 400; display: none; align-items: center; justify-content: center; backdrop-filter: blur(4px); }
.modal-overlay.open { display: flex; }
.modal { background: #fff; border-radius: var(--radius); width: 90%; max-width: 600px; max-height: 90vh; overflow: hidden; display: flex; flex-direction: column; box-shadow: var(--shadow-xl); animation: modalIn .25s ease; }
@keyframes modalIn { from { opacity: 0; transform: scale(.95); } }
.modal-header { padding: 20px 24px; border-bottom: 1px solid var(--gray-200); display: flex; justify-content: space-between; align-items: center; }
.modal-header h3 { font-size: 16px; font-weight: 700; }
.modal-close { background: none; border: none; color: var(--gray-400); font-size: 20px; cursor: pointer; }
.modal-body { padding: 24px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--gray-200); display: flex; justify-content: flex-end; gap: 12px; }

/* Drill Panel */
.drill-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 300; display: none; backdrop-filter: blur(4px); }
.drill-overlay.open { display: flex; justify-content: flex-end; }
.drill-panel { width: 480px; max-width: 100%; background: #fff; height: 100%; box-shadow: var(--shadow-xl); animation: slidePanel .25s ease; display: flex; flex-direction: column; }
@keyframes slidePanel { from { transform: translateX(100%); } }
.drill-header { padding: 20px 24px; border-bottom: 1px solid var(--gray-200); display: flex; justify-content: space-between; align-items: center; }
.drill-header h3 { font-size: 16px; font-weight: 700; }
.drill-close { width: 32px; height: 32px; border-radius: 8px; border: none; background: var(--gray-100); color: var(--gray-500); cursor: pointer; transition: var(--transition); }
.drill-close:hover { background: var(--gray-200); color: var(--gray-700); }
.drill-body { flex: 1; overflow-y: auto; padding: 24px; }

/* Mobile page (for drill-down on mobile) */
.mobile-page { position: fixed; inset: 0; background: var(--gray-50); z-index: 200; animation: fadeIn .2s ease; display: flex; flex-direction: column; }
@keyframes fadeIn { from { opacity: 0; } }
.mobile-page-header { padding: 16px; background: #fff; border-bottom: 1px solid var(--gray-200); display: flex; align-items: center; gap: 12px; }
.mobile-page-header h2 { font-size: 17px; font-weight: 700; flex: 1; }
.mobile-page-content { flex: 1; overflow-y: auto; padding: 16px; }

/* Charts */
.chart-container { position: relative; height: 300px; }
.chart-container canvas { max-height: 100% !important; }

/* Alerts */
.alert { padding: 14px 18px; border-radius: 10px; margin-bottom: 16px; display: flex; align-items: flex-start; gap: 12px; font-size: 14px; }
.alert i { margin-top: 2px; }
.alert-info { background: var(--info-bg); color: var(--info); border: 1px solid var(--info-light); }
.alert-success { background: var(--success-bg); color: var(--success); border: 1px solid var(--success-light); }
.alert-warning { background: var(--warning-bg); color: var(--warning); border: 1px solid var(--warning-light); }
.alert-danger { background: var(--danger-bg); color: var(--danger); border: 1px solid var(--danger-light); }

/* Animations */
.fade-in { animation: fadeIn .3s ease; }
.clickable { cursor: pointer; }

/* Responsive */
@media (max-width: 1023px) {
  .desktop-only { display: none !important; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .sidebar, .main-content { display: none; }
}

@media (min-width: 1024px) {
  .mobile-only { display: none !important; }
  .mobile-layout, .bottom-nav { display: none; }
}

/* Print */
@media print {
  .sidebar, .bottom-nav, .top-header, .btn, .drill-close, .modal-close { display: none !important; }
  .main-content, .mobile-page { margin: 0 !important; }
}
