@import url('https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,300;0,14..32,400;0,14..32,500;0,14..32,600;0,14..32,700;0,14..32,800;1,14..32,400&display=swap');

/* ═══════════════════════════════════════════════════════
   LIGHT THEME (default)
   ═══════════════════════════════════════════════════════ */
:root {
  /* Brand */
  --primary:        #6366f1;
  --primary-hover:  #4f46e5;
  --primary-soft:   #eef2ff;

  --accent:         #f97316;
  --accent-hover:   #ea6c0a;
  --accent-soft:    #fff7ed;

  /* Sidebar — light theme */
  --sidebar-bg:             #ffffff;
  --sidebar-border:         #e8edf3;
  --sidebar-text:           #1e293b;
  --sidebar-muted:          #94a3b8;
  --sidebar-active-bg:      #eef2ff;
  --sidebar-active-border:  #6366f1;
  --sidebar-active-text:    #4f46e5;
  --sidebar-hover-bg:       #f4f6fb;
  --sidebar-width:          248px;

  /* Page backgrounds */
  --bg:             #f4f6fb;
  --bg-card:        #ffffff;
  --bg-hover:       #f8fafc;
  --topbar-h:       60px;

  /* Text */
  --text:           #0f172a;
  --text-2:         #334155;
  --text-muted:     #64748b;
  --text-faint:     #94a3b8;

  /* Borders */
  --border:         #e2e8f0;
  --border-light:   #f0f4f8;

  /* Semantic */
  --danger:         #ef4444;
  --danger-soft:    #fef2f2;
  --success:        #22c55e;
  --success-soft:   #f0fdf4;
  --warning:        #f59e0b;
  --warning-soft:   #fffbeb;
  --info:           #3b82f6;
  --info-soft:      #eff6ff;

  /* Radii */
  --radius:      12px;
  --radius-sm:   8px;
  --radius-xs:   6px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-xs:  0 1px 2px rgba(0,0,0,0.04);
  --shadow-sm:  0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md:  0 4px 12px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.04);
  --shadow-lg:  0 20px 48px rgba(0,0,0,0.10), 0 8px 16px rgba(0,0,0,0.06);
  --shadow-glow: 0 0 0 3px rgba(99,102,241,0.16);

  --ease: cubic-bezier(0.4,0,0.2,1);
  --t: 150ms;
}

/* ═══════════════════════════════════════════════════════
   DARK THEME
   ═══════════════════════════════════════════════════════ */
[data-theme="dark"] {
  --primary-soft: rgba(99,102,241,0.14);
  --accent-soft:  rgba(249,115,22,0.12);

  /* Sidebar — dark theme */
  --sidebar-bg:            #0b0e17;
  --sidebar-border:        rgba(255,255,255,0.06);
  --sidebar-text:          #d1d5db;
  --sidebar-muted:         #6b7280;
  --sidebar-active-bg:     rgba(99,102,241,0.14);
  --sidebar-active-text:   #a5b4fc;
  --sidebar-hover-bg:      rgba(255,255,255,0.05);

  --bg:          #0f1117;
  --bg-card:     #181b26;
  --bg-hover:    #1e2233;

  --text:        #eef1f7;
  --text-2:      #bdc6d8;
  --text-muted:  #7a8599;
  --text-faint:  #3d4560;

  --border:       #242840;
  --border-light: #1d2035;

  --danger-soft:  rgba(239,68,68,0.12);
  --success-soft: rgba(34,197,94,0.12);
  --warning-soft: rgba(245,158,11,0.12);
  --info-soft:    rgba(59,130,246,0.12);

  --shadow-xs:  0 1px 2px rgba(0,0,0,0.4);
  --shadow-sm:  0 1px 3px rgba(0,0,0,0.5), 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md:  0 4px 16px rgba(0,0,0,0.5), 0 2px 4px rgba(0,0,0,0.3);
  --shadow-lg:  0 20px 48px rgba(0,0,0,0.6), 0 8px 16px rgba(0,0,0,0.4);
  --shadow-glow: 0 0 0 3px rgba(99,102,241,0.22);
}

/* ═══════════════════════════════════════════════════════
   RESET
   ═══════════════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
a { color: inherit; text-decoration: none; }
button { cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; }

/* ═══════════════════════════════════════════════════════
   LAYOUT
   ═══════════════════════════════════════════════════════ */
.layout { display: flex; height: 100vh; overflow: hidden; }

/* ═══════════════════════════════════════════════════════
   SIDEBAR
   ═══════════════════════════════════════════════════════ */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  transition: width var(--t) var(--ease), min-width var(--t) var(--ease);
  z-index: 100;
  flex-shrink: 0;
  border-right: 1px solid var(--sidebar-border);
}
.sidebar.collapsed { width: 64px; min-width: 64px; }
.sidebar.collapsed .brand-name,
.sidebar.collapsed .nav-item span,
.sidebar.collapsed .sidebar-version { display: none; }
.sidebar.collapsed .sidebar-brand { justify-content: center; padding: 0 16px; }
.sidebar.collapsed .nav-item { justify-content: center; padding: 12px 0; }
.sidebar.collapsed .nav-separator { margin: 6px 12px; }

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  height: var(--topbar-h);
  border-bottom: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}
.brand-icon {
  width: 32px; height: 32px;
  background: var(--primary);
  border-radius: var(--radius-xs);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(99,102,241,0.3);
}
.brand-icon svg { width: 18px; height: 18px; color: #fff; }
.brand-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--sidebar-text);
  letter-spacing: -0.2px;
  flex: 1;
}
.brand-tag {
  font-size: 10px;
  font-weight: 500;
  color: var(--sidebar-muted);
  letter-spacing: 0.5px;
  text-transform: uppercase;
  display: block;
  margin-top: -2px;
}
.sidebar-toggle {
  background: none; border: none;
  color: var(--sidebar-muted);
  display: flex; padding: 6px;
  border-radius: var(--radius-xs);
  transition: color var(--t);
  margin-left: auto;
}
.sidebar-toggle:hover { color: var(--sidebar-text); }
.sidebar-toggle svg { width: 16px; height: 16px; }

.sidebar-nav {
  display: flex;
  flex-direction: column;
  padding: 12px 8px;
  flex: 1;
  gap: 1px;
}
.nav-section-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--sidebar-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 8px 10px 4px;
  margin-top: 8px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--sidebar-muted);
  transition: background var(--t), color var(--t);
  font-size: 13.5px;
  font-weight: 500;
  position: relative;
}
.nav-item svg { width: 17px; height: 17px; flex-shrink: 0; }
.nav-item:hover { background: var(--sidebar-hover-bg); color: var(--sidebar-text); }
.nav-item.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active-text);
}
.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 20%; bottom: 20%;
  width: 3px;
  background: var(--primary);
  border-radius: 0 3px 3px 0;
}
.nav-separator {
  height: 1px;
  background: var(--sidebar-border);
  margin: 6px;
}
.sidebar-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--sidebar-border);
}
.sidebar-version { font-size: 11px; color: var(--sidebar-muted); }

/* ═══════════════════════════════════════════════════════
   MAIN WRAPPER
   ═══════════════════════════════════════════════════════ */
.main-wrapper { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }

/* ═══════════════════════════════════════════════════════
   TOPBAR
   ═══════════════════════════════════════════════════════ */
.topbar {
  height: var(--topbar-h);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px;
  flex-shrink: 0;
  z-index: 50;
  position: relative;
}

/* subtle accent line top */
.topbar::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--primary) 0%, var(--accent) 100%);
  opacity: 0;
  transition: opacity var(--t);
}

.topbar-left { display: flex; align-items: center; gap: 14px; }
.page-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.3px;
}
.topbar-right { display: flex; align-items: center; gap: 8px; }

/* Theme toggle */
.btn-theme {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-muted);
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px;
  border-radius: var(--radius-sm);
  transition: color var(--t), background var(--t), border-color var(--t);
  cursor: pointer;
  flex-shrink: 0;
}
.btn-theme:hover { color: var(--text); background: var(--bg-hover); border-color: var(--text-faint); }
.btn-theme svg { width: 16px; height: 16px; }

.topbar-user {
  display: flex; align-items: center; gap: 7px;
  color: var(--text-muted); font-size: 13px; font-weight: 500;
  padding: 5px 12px;
  border-radius: var(--radius-full);
  background: var(--bg);
  border: 1px solid var(--border);
}
.topbar-user svg { width: 16px; height: 16px; }

/* ═══════════════════════════════════════════════════════
   MAIN CONTENT
   ═══════════════════════════════════════════════════════ */
.main-content { flex: 1; overflow-y: auto; padding: 28px; background: var(--bg); }

/* ═══════════════════════════════════════════════════════
   CARDS
   ═══════════════════════════════════════════════════════ */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  overflow: hidden;
}
.card-header {
  padding: 16px 22px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.card-header h2, .card-header h3 {
  font-size: 13.5px; font-weight: 600; color: var(--text); margin: 0; letter-spacing: -0.1px;
}
.card-body { padding: 22px; }
.card-body.no-padding { padding: 0; }
.card + .card { margin-top: 20px; }

/* ═══════════════════════════════════════════════════════
   KPI CARDS
   ═══════════════════════════════════════════════════════ */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.kpi-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 10px;
  transition: box-shadow var(--t), transform var(--t);
  position: relative;
  overflow: hidden;
}
.kpi-card::after {
  content: '';
  position: absolute;
  top: 0; right: 0;
  width: 72px; height: 72px;
  border-radius: 50%;
  opacity: 0.07;
  transform: translate(20px,-20px);
}
.kpi-card.accent::after { background: var(--accent); }
.kpi-card.danger::after { background: var(--danger); }
.kpi-card.success::after { background: var(--success); }
.kpi-card.info::after { background: var(--info); }
.kpi-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.kpi-top { display: flex; align-items: flex-start; justify-content: space-between; }
.kpi-icon-wrap {
  width: 38px; height: 38px;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
}
.kpi-card.accent .kpi-icon-wrap { background: var(--accent-soft); color: var(--accent); }
.kpi-card.danger .kpi-icon-wrap { background: var(--danger-soft); color: var(--danger); }
.kpi-card.success .kpi-icon-wrap { background: var(--success-soft); color: var(--success); }
.kpi-card.info .kpi-icon-wrap { background: var(--info-soft); color: var(--info); }
.kpi-icon-wrap svg { width: 20px; height: 20px; }
.kpi-value { font-size: 34px; font-weight: 800; color: var(--text); line-height: 1; letter-spacing: -1.5px; }
.kpi-label { font-size: 12px; font-weight: 500; color: var(--text-muted); }

/* ═══════════════════════════════════════════════════════
   SECTION GRID
   ═══════════════════════════════════════════════════════ */
.section-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

/* ═══════════════════════════════════════════════════════
   TABLE
   ═══════════════════════════════════════════════════════ */
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th {
  background: var(--bg);
  padding: 9px 16px;
  text-align: left;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table td {
  padding: 11px 16px;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-2);
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr { transition: background var(--t); }
.data-table tbody tr:hover { background: var(--bg-hover); }
.data-table .col-actions { width: 120px; text-align: right; }
.table-empty {
  text-align: center;
  color: var(--text-faint);
  padding: 48px 20px;
  font-size: 13px;
}

/* ═══════════════════════════════════════════════════════
   BUTTONS
   ═══════════════════════════════════════════════════════ */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 15px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 13px; font-weight: 500;
  transition: all var(--t) var(--ease);
  cursor: pointer; line-height: 1.4; white-space: nowrap;
  letter-spacing: -0.1px;
}
.btn svg { width: 14px; height: 14px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary {
  background: var(--primary); color: #fff; border-color: var(--primary);
  box-shadow: 0 1px 3px rgba(99,102,241,0.25), inset 0 1px 0 rgba(255,255,255,0.1);
}
.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
  box-shadow: 0 4px 12px rgba(99,102,241,0.35);
}

.btn-accent {
  background: var(--accent); color: #fff; border-color: var(--accent);
  box-shadow: 0 1px 3px rgba(249,115,22,0.25);
}
.btn-accent:hover:not(:disabled) { background: var(--accent-hover); }

.btn-secondary {
  background: var(--bg-card); color: var(--text-2); border-color: var(--border);
  box-shadow: var(--shadow-xs);
}
.btn-secondary:hover:not(:disabled) { background: var(--bg); border-color: var(--text-faint); }

.btn-danger { background: var(--danger); color: #fff; box-shadow: 0 1px 3px rgba(239,68,68,0.25); }
.btn-danger:hover:not(:disabled) { background: #dc2626; }

.btn-ghost {
  background: transparent; color: var(--text-muted); border-color: transparent;
}
.btn-ghost:hover:not(:disabled) { background: var(--bg); color: var(--text); }

.btn-sm { padding: 5px 11px; font-size: 12px; }
.btn-sm svg { width: 12px; height: 12px; }

.btn-icon {
  background: none; border: none;
  padding: 7px; display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-muted); border-radius: var(--radius-xs);
  transition: color var(--t), background var(--t);
}
.btn-icon:hover { color: var(--text); background: var(--bg); }
.btn-icon svg { width: 16px; height: 16px; }

/* ═══════════════════════════════════════════════════════
   BADGES
   ═══════════════════════════════════════════════════════ */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px;
  border-radius: var(--radius-full);
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.2px; white-space: nowrap;
}
.badge::before {
  content: ''; width: 5px; height: 5px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.7;
}

/* Light theme badge colors */
.badge-bozza          { background: #f1f5f9; color: #64748b; }
.badge-aperta         { background: #eff6ff; color: #2563eb; }
.badge-in_lavorazione { background: #fffbeb; color: #d97706; }
.badge-controlli      { background: #faf5ff; color: #7c3aed; }
.badge-pronta         { background: #f0fdf4; color: #16a34a; }
.badge-consegnata     { background: #ecfdf5; color: #059669; }
.badge-fatturazione   { background: #fff7ed; color: #ea580c; }
.badge-chiusa         { background: #f8fafc; color: #94a3b8; }
.badge-pianificato    { background: #eff6ff; color: #3b82f6; }
.badge-in_attesa      { background: #fffbeb; color: #ca8a04; }
.badge-lavorazione    { background: #fff7ed; color: #ea580c; }
.badge-fatto          { background: #f8fafc; color: #64748b; }
.badge-consegnato     { background: #ecfdf5; color: #059669; }
.badge-info           { background: #fff7ed; color: #c2410c; }
.badge-ritirare       { background: #fefce8; color: #a16207; }
.badge-consegnare     { background: #fefce8; color: #a16207; }
.badge-pronto         { background: #f0fdf4; color: #16a34a; }

/* Dark theme badge overrides */
[data-theme="dark"] .badge-bozza          { background: rgba(100,116,139,0.15); color: #94a3b8; }
[data-theme="dark"] .badge-aperta         { background: rgba(37,99,235,0.14);   color: #93c5fd; }
[data-theme="dark"] .badge-in_lavorazione { background: rgba(217,119,6,0.14);   color: #fbbf24; }
[data-theme="dark"] .badge-controlli      { background: rgba(124,58,237,0.14);  color: #c4b5fd; }
[data-theme="dark"] .badge-pronta         { background: rgba(22,163,74,0.14);   color: #86efac; }
[data-theme="dark"] .badge-consegnata     { background: rgba(5,150,105,0.14);   color: #6ee7b7; }
[data-theme="dark"] .badge-fatturazione   { background: rgba(234,88,12,0.14);   color: #fdba74; }
[data-theme="dark"] .badge-chiusa         { background: rgba(148,163,184,0.08); color: #64748b; }
[data-theme="dark"] .badge-pianificato    { background: rgba(59,130,246,0.14);  color: #93c5fd; }
[data-theme="dark"] .badge-in_attesa      { background: rgba(202,138,4,0.14);   color: #fde68a; }
[data-theme="dark"] .badge-lavorazione    { background: rgba(234,88,12,0.14);   color: #fdba74; }
[data-theme="dark"] .badge-fatto          { background: rgba(100,116,139,0.10); color: #94a3b8; }
[data-theme="dark"] .badge-consegnato     { background: rgba(5,150,105,0.14);   color: #6ee7b7; }
[data-theme="dark"] .badge-info           { background: rgba(194,65,12,0.14);   color: #fb923c; }
[data-theme="dark"] .badge-ritirare       { background: rgba(161,98,7,0.14);    color: #fcd34d; }
[data-theme="dark"] .badge-consegnare     { background: rgba(161,98,7,0.14);    color: #fcd34d; }
[data-theme="dark"] .badge-pronto         { background: rgba(22,163,74,0.14);   color: #86efac; }

/* ═══════════════════════════════════════════════════════
   FORMS
   ═══════════════════════════════════════════════════════ */
.form-group { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.form-label {
  font-size: 12px; font-weight: 600; color: var(--text-2);
  letter-spacing: 0.2px;
}
.form-label .required { color: var(--danger); margin-left: 2px; }

.form-control {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13.5px; color: var(--text);
  background: var(--bg-card);
  transition: border-color var(--t), box-shadow var(--t), background var(--t);
  width: 100%; outline: none;
}
.form-control::placeholder { color: var(--text-faint); }
.form-control:focus {
  border-color: var(--primary);
  box-shadow: var(--shadow-glow);
}
.form-control.is-invalid { border-color: var(--danger); box-shadow: 0 0 0 3px rgba(239,68,68,0.12); }

/* Select arrow — light */
select.form-control {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

/* Select arrow — dark */
[data-theme="dark"] select.form-control {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%237a8599' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
}

textarea.form-control { resize: vertical; min-height: 80px; }

.form-row   { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.form-error { font-size: 11px; color: var(--danger); margin-top: 2px; }
.form-hint  { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* ═══════════════════════════════════════════════════════
   FILTER BAR
   ═══════════════════════════════════════════════════════ */
.filter-bar {
  display: flex; gap: 10px; align-items: flex-end;
  margin-bottom: 20px; flex-wrap: wrap;
}
.filter-bar .form-group { margin-bottom: 0; min-width: 140px; flex: 1; }
.filter-bar .form-group:first-child { flex: 2; min-width: 200px; }

/* ═══════════════════════════════════════════════════════
   MODAL
   ═══════════════════════════════════════════════════════ */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(2,6,23,0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  animation: fadeIn 0.15s var(--ease);
}
[data-theme="dark"] .modal-overlay {
  background: rgba(0,0,0,0.7);
}
.modal {
  background: var(--bg-card);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  width: 100%; max-width: 640px; max-height: 90vh;
  display: flex; flex-direction: column; overflow: hidden;
  animation: slideUp 0.2s var(--ease);
}
.modal.modal-lg { max-width: 900px; }
.modal.modal-sm { max-width: 420px; }
.modal-header {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
}
.modal-header h3 { font-size: 15px; font-weight: 700; color: var(--text); letter-spacing: -0.3px; }
.modal-header h4 { font-size: 14px; font-weight: 700; color: var(--text); letter-spacing: -0.2px; margin: 0; }
.modal-body { padding: 22px; overflow-y: auto; flex: 1; }
.modal-footer {
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  display: flex; gap: 8px; justify-content: flex-end;
  flex-shrink: 0;
  background: var(--bg);
}

/* Modal close button */
.modal-close {
  background: none; border: none;
  color: var(--text-muted);
  font-size: 20px; line-height: 1;
  padding: 4px 8px;
  border-radius: var(--radius-xs);
  cursor: pointer;
  transition: color var(--t), background var(--t);
  flex-shrink: 0;
}
.modal-close:hover { color: var(--text); background: var(--bg); }

/* ═══════════════════════════════════════════════════════
   TOAST
   ═══════════════════════════════════════════════════════ */
.toast-container {
  position: fixed; bottom: 20px; right: 20px; z-index: 2000;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
.toast {
  pointer-events: all;
  background: #1e293b;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  padding: 12px 16px;
  min-width: 280px; max-width: 400px;
  display: flex; align-items: center; gap: 10px;
  animation: slideInRight 0.2s var(--ease);
  font-size: 13px; color: #f1f5f9;
  border: 1px solid rgba(255,255,255,0.06);
}
.toast.success { background: #14532d; border-color: rgba(34,197,94,0.2); }
.toast.error   { background: #7f1d1d; border-color: rgba(239,68,68,0.2); }
.toast.warning { background: #78350f; border-color: rgba(245,158,11,0.2); }
.toast svg { width: 16px; height: 16px; flex-shrink: 0; color: rgba(255,255,255,0.75); }
.toast-message { flex: 1; }

/* ═══════════════════════════════════════════════════════
   ANIMATIONS
   ═══════════════════════════════════════════════════════ */
@keyframes slideInRight {
  from { transform: translateX(40px); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}
@keyframes fadeOut {
  from { opacity: 1; }
  to   { opacity: 0; transform: translateY(8px); }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes slideUp {
  from { transform: translateY(12px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}
@keyframes spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}
.toast.removing { animation: fadeOut 0.2s var(--ease) forwards; }
.spin { animation: spin 0.8s linear infinite; }

/* ═══════════════════════════════════════════════════════
   LOADING
   ═══════════════════════════════════════════════════════ */
.loading-spinner {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 80px 20px; color: var(--text-faint); gap: 12px;
}
.loading-spinner svg { width: 26px; height: 26px; }
.loading-spinner p { font-size: 13px; }

/* ═══════════════════════════════════════════════════════
   INLINE EDIT
   ═══════════════════════════════════════════════════════ */
.editable-field {
  cursor: pointer;
  border-bottom: 1.5px dashed var(--border);
  padding: 2px 6px;
  border-radius: 4px;
  min-width: 60px;
  display: inline-block;
  transition: background var(--t), border-color var(--t);
}
.editable-field:hover { background: var(--primary-soft); border-bottom-color: var(--primary); }

/* ═══════════════════════════════════════════════════════
   SECTION HEADER
   ═══════════════════════════════════════════════════════ */
.section-title {
  font-size: 11px; font-weight: 700; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 1px;
  margin-bottom: 14px; padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px;
}
.section-title svg { width: 14px; height: 14px; color: var(--primary); }

/* ═══════════════════════════════════════════════════════
   PAGINATION
   ═══════════════════════════════════════════════════════ */
.pagination {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  font-size: 12px; color: var(--text-muted);
}
.pagination-buttons { display: flex; gap: 6px; }

/* ═══════════════════════════════════════════════════════
   STATO BAR
   ═══════════════════════════════════════════════════════ */
.stato-bar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 24px; }

/* ═══════════════════════════════════════════════════════
   DATE COLORS
   ═══════════════════════════════════════════════════════ */
.date-late    { color: var(--danger); font-weight: 600; }
.date-warning { color: var(--warning); font-weight: 600; }

/* ═══════════════════════════════════════════════════════
   DETAIL LAYOUT
   ═══════════════════════════════════════════════════════ */
.detail-layout { display: grid; grid-template-columns: 1fr 340px; gap: 20px; align-items: start; }
.detail-sidebar { display: flex; flex-direction: column; gap: 16px; }
.detail-field { margin-bottom: 14px; }
.detail-field label {
  display: block; font-size: 11px; font-weight: 600;
  color: var(--text-muted); text-transform: uppercase;
  letter-spacing: 0.5px; margin-bottom: 3px;
}
.detail-field span { display: block; font-size: 14px; color: var(--text-2); }
.detail-section { margin-bottom: 28px; }

/* ═══════════════════════════════════════════════════════
   GANTT
   ═══════════════════════════════════════════════════════ */
.gantt-wrapper { overflow-x: auto; }
.gantt-grid { display: grid; min-width: max-content; font-size: 12px; }
.gantt-row { display: contents; }
.gantt-cell {
  padding: 6px 10px;
  border-right: 1px solid var(--border-light);
  border-bottom: 1px solid var(--border-light);
  white-space: nowrap; height: 36px;
  display: flex; align-items: center;
}
.gantt-header .gantt-cell {
  background: var(--bg); font-weight: 600; color: var(--text-muted);
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px;
  position: sticky; top: 0; z-index: 5;
}
.gantt-day-cell {
  justify-content: center; cursor: pointer;
  transition: filter var(--t), opacity var(--t);
}
.gantt-day-cell:hover { filter: brightness(0.92); }

/* Gantt status colors — light */
.gantt-day-active.pianificato { background: #dbeafe; }
.gantt-day-active.in_attesa   { background: #fef3c7; }
.gantt-day-active.lavorazione { background: #dcfce7; }
.gantt-day-active.fatto       { background: #f1f5f9; }
.gantt-day-active.info        { background: #ffedd5; }
.gantt-day-active.ritirare    { background: #fef9c3; }
.gantt-day-active.consegnare  { background: #fef9c3; }
.gantt-day-active.pronto      { background: #bbf7d0; }

/* Gantt status colors — dark */
[data-theme="dark"] .gantt-day-active.pianificato { background: rgba(59,130,246,0.22); }
[data-theme="dark"] .gantt-day-active.in_attesa   { background: rgba(245,158,11,0.22); }
[data-theme="dark"] .gantt-day-active.lavorazione { background: rgba(34,197,94,0.18); }
[data-theme="dark"] .gantt-day-active.fatto       { background: rgba(100,116,139,0.18); }
[data-theme="dark"] .gantt-day-active.info        { background: rgba(249,115,22,0.2); }
[data-theme="dark"] .gantt-day-active.ritirare    { background: rgba(234,179,8,0.2); }
[data-theme="dark"] .gantt-day-active.consegnare  { background: rgba(234,179,8,0.2); }
[data-theme="dark"] .gantt-day-active.pronto      { background: rgba(34,197,94,0.25); }

/* ═══════════════════════════════════════════════════════
   EMPTY STATE
   ═══════════════════════════════════════════════════════ */
.empty-state {
  text-align: center; padding: 60px 20px;
  display: flex; flex-direction: column; align-items: center; gap: 12px;
}
.empty-state svg { width: 40px; height: 40px; color: var(--text-faint); }
.empty-state h3 { font-size: 15px; font-weight: 600; color: var(--text-2); }
.empty-state p { font-size: 13px; color: var(--text-muted); max-width: 320px; }

/* ═══════════════════════════════════════════════════════
   DIVIDER
   ═══════════════════════════════════════════════════════ */
.divider { height: 1px; background: var(--border); margin: 20px 0; }

/* ═══════════════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════════════ */
#mobileMenuBtn { display: none; }
@media (max-width: 900px) {
  .sidebar {
    position: fixed; left: 0; top: 0; height: 100vh;
    transform: translateX(-100%);
    transition: transform var(--t) var(--ease);
    box-shadow: 4px 0 24px rgba(0,0,0,0.25);
  }
  .sidebar.mobile-open { transform: translateX(0); }
  .main-wrapper { margin-left: 0 !important; }
  #mobileMenuBtn { display: flex; }
  .section-grid, .detail-layout { grid-template-columns: 1fr; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .main-content { padding: 16px; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .filter-bar { flex-direction: column; }
  .filter-bar .form-group { min-width: 100%; }
}

/* ═══════════════════════════════════════════════════════
   UTILITIES
   ═══════════════════════════════════════════════════════ */
.flex            { display: flex; }
.flex-col        { flex-direction: column; }
.gap-2           { gap: 8px; }
.gap-3           { gap: 12px; }
.items-center    { align-items: center; }
.justify-between { justify-content: space-between; }
.text-muted      { color: var(--text-muted); }
.text-sm         { font-size: 12px; }
.text-right      { text-align: right; }
.mt-2            { margin-top: 8px; }
.mt-3            { margin-top: 12px; }
.mt-4            { margin-top: 16px; }
.mb-2            { margin-bottom: 8px; }
.mb-3            { margin-bottom: 12px; }
.mb-4            { margin-bottom: 16px; }
.fw-bold         { font-weight: 700; }
.fw-semibold     { font-weight: 600; }
.w-full          { width: 100%; }
.overflow-x-auto { overflow-x: auto; }
.hidden          { display: none !important; }
.clickable       { cursor: pointer; }
.truncate        { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rounded-full    { border-radius: var(--radius-full); }

/* ═══════════════════════════════════════════════════════
   STAMPO AUTOCOMPLETE
   ═══════════════════════════════════════════════════════ */
.stampo-ac { position: relative; }
.stampo-ac-dropdown {
  position: absolute; z-index: 1100; top: calc(100% + 2px); left: 0; right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  max-height: 220px; overflow-y: auto;
  box-shadow: var(--shadow-md);
}
.stampo-ac-opt {
  padding: 7px 12px; cursor: pointer; font-size: 13px;
  display: flex; align-items: baseline; gap: 6px;
  border-bottom: 1px solid var(--border-light);
  transition: background var(--t);
}
.stampo-ac-opt:last-child { border-bottom: none; }
.stampo-ac-opt:hover, .stampo-ac-opt.ac-active { background: var(--accent-soft); }
.stampo-ac-opt .ac-code { font-weight: 600; color: var(--text); white-space: nowrap; }
.stampo-ac-opt .ac-desc { color: var(--text-muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stampo-ac-opt .ac-cli  { color: var(--text-muted); font-size: 11px; white-space: nowrap; margin-left: auto; }

/* ═══════════════════════════════════════════════════════
   LOGIN SCREEN
   ═══════════════════════════════════════════════════════ */
.login-screen {
  position: fixed; inset: 0; z-index: 9999;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  padding: 1.5rem;
}
.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2.5rem;
  width: 100%; max-width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.08);
}
.login-logo {
  display: flex; align-items: center; gap: 1rem;
  margin-bottom: 2rem;
}
.login-logo .brand-icon {
  width: 48px; height: 48px; border-radius: 14px;
  background: var(--primary); display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.login-logo .brand-icon i { color: #fff; width: 24px; height: 24px; }
.login-title { font-size: 1.25rem; font-weight: 700; color: var(--text); }
.login-subtitle { font-size: 0.8rem; color: var(--text-muted); margin-top: 2px; }
.login-form { display: flex; flex-direction: column; gap: 1.1rem; }
.login-error { color: var(--danger); font-size: 0.82rem; min-height: 1.2em; margin: 0; }
.w-full { width: 100%; }

/* ═══════════════════════════════════════════════════════
   ROLE BADGE + LOGOUT
   ═══════════════════════════════════════════════════════ */
.role-badge {
  font-size: 10px; font-weight: 600; padding: 2px 7px;
  border-radius: 20px; letter-spacing: 0.03em;
  text-transform: uppercase; white-space: nowrap;
}
.role-admin       { background: rgba(99,102,241,0.12); color: var(--primary); }
.role-operatore   { background: rgba(34,197,94,0.12);  color: var(--success); }
.role-viewer      { background: rgba(100,116,139,0.12); color: var(--text-muted); }
.topbar-logout { margin-left: 4px; color: var(--text-muted); }
.topbar-logout:hover { color: var(--danger); }

/* Users table */
.users-table { width: 100%; border-collapse: collapse; }
.users-table th, .users-table td { padding: 10px 14px; text-align: left; font-size: 13.5px; border-bottom: 1px solid var(--border-light); }
.users-table th { font-weight: 600; color: var(--text-muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; background: var(--bg-hover); }
.users-table tr:hover td { background: var(--bg-hover); }
