:root {
  /* 🎨 Colori */
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --success: #10b981; --success-bg: #dcfce7;
  --warning: #f59e0b; --warning-bg: #fef3c7;
  --error: #ef4444; --error-bg: #fee2e2;
  --info: #3b82f6; --info-bg: #dbeafe;
  
  /* 🖼️ Superfici */
  --bg: #f8fafc; --surface: #ffffff; --text: #0f172a; --text-muted: #64748b; --border: #e2e8f0;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 2px 8px rgba(0,0,0,0.06);
  --shadow-lg: 0 4px 16px rgba(0,0,0,0.1);
  
  /* 📏 Spaziatura */
  --sp-xs: 0.25rem; --sp-sm: 0.5rem; --sp-md: 1rem; --sp-lg: 1.5rem; --sp-xl: 2rem;
  
  /* 🔘 Raggi */
  --radius-sm: 6px; --radius: 10px; --radius-lg: 14px;
  
  /* 🔤 Tipografia */
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

/* 🌙 Dark Mode Nativo */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120; --surface: #1e293b; --text: #f8fafc; --text-muted: #94a3b8; --border: #334155;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.3); --shadow: 0 2px 8px rgba(0,0,0,0.4); --shadow-lg: 0 4px 16px rgba(0,0,0,0.5);
    --primary-light: #1e3a8a; --success-bg: #052e16; --warning-bg: #451a03; --error-bg: #450a0a; --info-bg: #1e3a8a;
  }
}

/* 🔄 Reset & Base */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: var(--font-sans); background: var(--bg); color: var(--text); line-height: 1.5; -webkit-font-smoothing: antialiased; min-height: 100vh; }
h1, h2, h3, h4 { line-height: 1.25; font-weight: 600; margin-bottom: var(--sp-sm); }
h1 { font-size: 1.75rem; } h2 { font-size: 1.5rem; } h3 { font-size: 1.25rem; }
p { margin-bottom: var(--sp-md); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* 📐 Layout */
.container { max-width: 1200px; margin: 0 auto; padding: var(--sp-md); }
.header { display: flex; justify-content: space-between; align-items: center; margin-bottom: var(--sp-lg); flex-wrap: wrap; gap: var(--sp-sm); }
.grid { display: grid; gap: var(--sp-md); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.flex { display: flex; align-items: center; gap: var(--sp-sm); flex-wrap: wrap; }

/* 🃏 Componenti Base */
.card { background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow); padding: var(--sp-md); border: 1px solid var(--border); transition: transform 0.2s var(--ease), box-shadow 0.2s var(--ease); }
.card:hover { box-shadow: var(--shadow-lg); }

/* 🔘 Bottoni */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-xs); padding: 0.75rem 1.25rem; border: none; border-radius: var(--radius); font-weight: 500; font-size: 0.95rem; cursor: pointer; transition: all 0.2s var(--ease); text-decoration: none; min-height: 44px; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); transform: translateY(-1px); }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-secondary:hover:not(:disabled) { background: #cbd5e1; }
.btn-danger { background: var(--error); color: white; }
.btn-danger:hover:not(:disabled) { background: #dc2626; }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--bg); }

/* 📝 Input */
.input, select, textarea { width: 100%; padding: 0.8rem 1rem; border: 2px solid var(--border); border-radius: var(--radius); background: var(--bg); color: var(--text); font-size: 1rem; transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease); }
.input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.15); background: var(--surface); }
label { display: block; margin-bottom: var(--sp-xs); font-weight: 500; font-size: 0.85rem; color: var(--text-muted); }

/* 📊 Tabelle */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 0.85rem 1rem; text-align: left; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
th { background: var(--bg); font-weight: 600; color: var(--text-muted); text-transform: uppercase; font-size: 0.75rem; letter-spacing: 0.5px; position: sticky; top: 0; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(37,99,235,0.03); }

/* 🏷️ Badge */
.badge { display: inline-flex; align-items: center; padding: 0.25rem 0.6rem; border-radius: 999px; font-size: 0.75rem; font-weight: 600; text-transform: capitalize; }
.badge-success { background: var(--success-bg); color: #166534; }
.badge-warning { background: var(--warning-bg); color: #92400e; }
.badge-error { background: var(--error-bg); color: #991b1b; }
.badge-info { background: var(--info-bg); color: #1e40af; }

/* 🪟 Modali */
.modal { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 1000; align-items: flex-end; justify-content: center; padding: var(--sp-md); backdrop-filter: blur(4px); }
.modal.open { display: flex; }
.modal-content { background: var(--surface); width: 100%; max-width: 600px; max-height: 90vh; border-radius: var(--radius-lg) var(--radius-lg) 0 0; padding: var(--sp-lg); overflow-y: auto; animation: slideUp 0.3s var(--ease); }
@keyframes slideUp { from { transform: translateY(100%); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* 🔔 Toast */
.toast-container { position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 9999; display: flex; flex-direction: column-reverse; gap: 0.75rem; pointer-events: none; }
.toast { background: var(--surface); color: var(--text); padding: 0.9rem 1.2rem; border-radius: var(--radius); box-shadow: var(--shadow-lg); font-size: 0.9rem; font-weight: 500; display: flex; align-items: center; gap: 0.6rem; animation: toastIn 0.3s var(--ease); pointer-events: auto; max-width: 360px; border-left: 4px solid var(--border); }
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--error); }
.toast.warning { border-left-color: var(--warning); }
@keyframes toastIn { from { transform: translateX(100%) scale(0.9); opacity: 0; } to { transform: translateX(0) scale(1); opacity: 1; } }
@keyframes toastOut { from { transform: translateX(0) scale(1); opacity: 1; } to { transform: translateX(100%) scale(0.9); opacity: 0; } }

/* 🦴 Skeleton */
.skeleton { background: linear-gradient(90deg, var(--border) 25%, var(--bg) 50%, var(--border) 75%); background-size: 200% 100%; animation: pulse 1.5s infinite; border-radius: var(--radius-sm); }
@keyframes pulse { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* 📭 Empty State */
.empty-state { text-align: center; padding: var(--sp-xl) var(--sp-md); color: var(--text-muted); }
.empty-state svg { width: 48px; height: 48px; margin-bottom: var(--sp-sm); opacity: 0.5; }

/* 🛠️ Utility */
.text-center { text-align: center; } .text-right { text-align: right; } .text-muted { color: var(--text-muted); }
.mt-1 { margin-top: var(--sp-xs); } .mt-2 { margin-top: var(--sp-sm); } .mt-3 { margin-top: var(--sp-md); } .mt-4 { margin-top: var(--sp-lg); }
.mb-1 { margin-bottom: var(--sp-xs); } .mb-2 { margin-bottom: var(--sp-sm); } .mb-3 { margin-bottom: var(--sp-md); }
.w-full { width: 100%; } .hidden { display: none; }

/* 📱 Mobile First */
@media (max-width: 640px) {
  h1 { font-size: 1.5rem; } h2 { font-size: 1.25rem; }
  .container { padding: var(--sp-sm); }
  .modal-content { border-radius: var(--radius-lg) var(--radius-lg) 0 0; max-height: 95vh; }
  th, td { padding: 0.7rem 0.8rem; font-size: 0.85rem; }
  .grid { gap: var(--sp-sm); }
}

/* 🖨️ Stampa Pulita */
@media print {
  body { background: white; color: black; }
  .no-print, header, .btn, .toast-container, nav, .fab { display: none !important; }
  .card, .table-wrap { box-shadow: none; border: 1px solid #ddd; break-inside: avoid; }
  th { background: #f3f4f6 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  @page { size: A4; margin: 12mm; }
}