/* ============================================================
   MUSEKE — Design System v1.0
   Palette: Warm Stone + Forest Green (shadcn-inspired)
   Typography: Instrument Serif (display) + DM Sans (body)
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Instrument+Serif:ital@0;1&family=DM+Sans:ital,opsz,wght@0,9..40,300..700;1,9..40,300..400&family=DM+Mono:wght@400;500&display=swap');

/* ── CSS Variables ─────────────────────────────────────────── */
:root {
  /* Radius */
  --radius:       0.5rem;
  --radius-sm:    0.25rem;
  --radius-md:    0.625rem;
  --radius-lg:    0.75rem;
  --radius-xl:    1rem;
  --radius-2xl:   1.5rem;
  --radius-full:  9999px;

  /* Colors — Light Mode */
  --background:         0 0% 99%;
  --foreground:         25 15% 10%;

  --card:               0 0% 100%;
  --card-foreground:    25 15% 10%;

  --popover:            0 0% 100%;
  --popover-foreground: 25 15% 10%;

  --primary:            152 55% 30%;
  --primary-foreground: 150 60% 97%;

  --secondary:          30 10% 94%;
  --secondary-foreground: 25 15% 20%;

  --muted:              30 10% 96%;
  --muted-foreground:   25 8% 50%;

  --accent:             30 10% 92%;
  --accent-foreground:  25 15% 12%;

  --success:            152 55% 30%;
  --success-foreground: 150 60% 97%;
  --success-muted:      152 40% 94%;

  --warning:            38 90% 50%;
  --warning-foreground: 38 80% 15%;
  --warning-muted:      38 80% 94%;

  --destructive:        4 86% 52%;
  --destructive-foreground: 0 0% 98%;
  --destructive-muted:  4 80% 95%;

  --info:               215 70% 48%;
  --info-foreground:    215 80% 97%;
  --info-muted:         215 70% 94%;

  --border:             30 12% 88%;
  --input:              30 12% 88%;
  --ring:               152 55% 30%;

  /* Sidebar */
  --sidebar-bg:             25 20% 97%;
  --sidebar-border:         30 12% 90%;
  --sidebar-item-hover:     152 30% 92%;
  --sidebar-item-active:    152 55% 30%;
  --sidebar-item-active-fg: 150 60% 97%;
  --sidebar-text:           25 15% 28%;
  --sidebar-text-muted:     25 8% 55%;

  /* Status colors */
  --status-attivo:     152 55% 30%;
  --status-attivo-bg:  152 40% 93%;
  --status-sospeso:    38 90% 50%;
  --status-sospeso-bg: 38 80% 93%;
  --status-concluso:   215 20% 55%;
  --status-concluso-bg:215 20% 93%;
  --status-archiviato: 25 8% 55%;
  --status-archiviato-bg: 25 8% 93%;
  --status-bozza:      260 40% 60%;
  --status-bozza-bg:   260 40% 93%;

  /* Typography */
  --font-sans:    'DM Sans', system-ui, sans-serif;
  --font-display: 'Instrument Serif', Georgia, serif;
  --font-mono:    'DM Mono', 'Fira Code', monospace;

  /* Shadows */
  --shadow-xs: 0 1px 2px 0 hsl(25 15% 10% / 0.04);
  --shadow-sm: 0 1px 3px 0 hsl(25 15% 10% / 0.06), 0 1px 2px -1px hsl(25 15% 10% / 0.06);
  --shadow-md: 0 4px 6px -1px hsl(25 15% 10% / 0.06), 0 2px 4px -2px hsl(25 15% 10% / 0.06);
  --shadow-lg: 0 10px 15px -3px hsl(25 15% 10% / 0.08), 0 4px 6px -4px hsl(25 15% 10% / 0.06);
  --shadow-xl: 0 20px 25px -5px hsl(25 15% 10% / 0.08), 0 8px 10px -6px hsl(25 15% 10% / 0.06);

  /* Spacing */
  --sidebar-width: 240px;
  --header-height: 56px;
  --content-max:   1280px;

  /* Transitions */
  --transition-fast:   150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-base:   200ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow:   300ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Reset & Base ──────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  font-family: var(--font-sans);
  font-size: 0.9rem;
  line-height: 1.6;
  background-color: hsl(var(--background));
  color: hsl(var(--foreground));
  min-height: 100vh;
}

/* ── Typography Scale ──────────────────────────────────────── */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-sans);
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.25;
  color: hsl(var(--foreground));
}

.display-title {
  font-family: var(--font-display);
  font-weight: 400;
  letter-spacing: -0.02em;
}

h1 { font-size: 1.75rem; }
h2 { font-size: 1.375rem; }
h3 { font-size: 1.125rem; }
h4 { font-size: 1rem; }

.text-xs    { font-size: 0.75rem; line-height: 1rem; }
.text-sm    { font-size: 0.8125rem; line-height: 1.25rem; }
.text-base  { font-size: 0.9rem; }
.text-lg    { font-size: 1rem; font-weight: 500; }
.text-xl    { font-size: 1.125rem; }
.text-2xl   { font-size: 1.375rem; }
.text-3xl   { font-size: 1.75rem; }

.text-muted        { color: hsl(var(--muted-foreground)); }
.text-primary      { color: hsl(var(--primary)); }
.text-destructive  { color: hsl(var(--destructive)); }
.font-medium       { font-weight: 500; }
.font-semibold     { font-weight: 600; }
.font-mono         { font-family: var(--font-mono); font-size: 0.82em; }

a {
  color: hsl(var(--primary));
  text-decoration: none;
  transition: color var(--transition-fast);
}
a:hover { color: hsl(var(--primary) / 0.8); text-decoration: underline; }

/* ── Layout Shell ──────────────────────────────────────────── */
.app-shell {
  display: flex;
  min-height: 100vh;
  background: hsl(var(--background));
}

/* ── Sidebar ───────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  min-height: 100vh;
  background: hsl(var(--sidebar-bg));
  border-right: 1px solid hsl(var(--sidebar-border));
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 40;
  transition: transform var(--transition-slow);
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-logo {
  padding: 1.25rem 1.25rem 1rem;
  border-bottom: 1px solid hsl(var(--sidebar-border));
  display: flex;
  align-items: center;
  gap: 0.625rem;
  flex-shrink: 0;
}

.sidebar-logo-mark {
  width: 30px;
  height: 30px;
  background: hsl(var(--primary));
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 1rem;
  color: hsl(var(--primary-foreground));
  flex-shrink: 0;
}

.sidebar-logo-text {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}
.sidebar-logo-name {
  font-weight: 600;
  font-size: 0.9375rem;
  color: hsl(var(--foreground));
  letter-spacing: -0.01em;
}
.sidebar-logo-sub {
  font-size: 0.6875rem;
  color: hsl(var(--sidebar-text-muted));
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.sidebar-nav {
  flex: 1;
  padding: 0.75rem 0.625rem;
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}

.sidebar-section-label {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: hsl(var(--sidebar-text-muted));
  padding: 0.75rem 0.625rem 0.25rem;
  margin-top: 0.25rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  font-size: 0.8375rem;
  font-weight: 450;
  color: hsl(var(--sidebar-text));
  cursor: pointer;
  transition: background-color var(--transition-fast), color var(--transition-fast);
  text-decoration: none;
  white-space: nowrap;
  position: relative;
}

.nav-item:hover {
  background: hsl(var(--sidebar-item-hover));
  color: hsl(var(--foreground));
  text-decoration: none;
}

.nav-item.active {
  background: hsl(var(--sidebar-item-active));
  color: hsl(var(--sidebar-item-active-fg));
  font-weight: 500;
}

.nav-item .nav-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  opacity: 0.85;
}

.nav-item .nav-badge {
  margin-left: auto;
  font-size: 0.6875rem;
  font-weight: 600;
  background: hsl(var(--destructive));
  color: hsl(var(--destructive-foreground));
  padding: 0.0625rem 0.375rem;
  border-radius: var(--radius-full);
  min-width: 18px;
  text-align: center;
  line-height: 1.4;
}

.nav-item.active .nav-badge {
  background: hsl(var(--primary-foreground) / 0.25);
  color: hsl(var(--primary-foreground));
}

.sidebar-footer {
  padding: 0.75rem 0.625rem;
  border-top: 1px solid hsl(var(--sidebar-border));
  flex-shrink: 0;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.5rem 0.625rem;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background-color var(--transition-fast);
}
.sidebar-user:hover { background: hsl(var(--sidebar-item-hover)); }

.avatar {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-full);
  background: hsl(var(--primary) / 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 600;
  color: hsl(var(--primary));
  flex-shrink: 0;
  text-transform: uppercase;
}
.avatar-sm { width: 24px; height: 24px; font-size: 0.6875rem; }
.avatar-lg { width: 40px; height: 40px; font-size: 0.9375rem; }
.avatar-xl { width: 52px; height: 52px; font-size: 1.125rem; }

.sidebar-user-name {
  font-size: 0.8125rem;
  font-weight: 500;
  color: hsl(var(--foreground));
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sidebar-user-role {
  font-size: 0.6875rem;
  color: hsl(var(--sidebar-text-muted));
}

/* ── Main Content Area ─────────────────────────────────────── */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Top Header Bar ────────────────────────────────────────── */
.topbar {
  height: var(--header-height);
  background: hsl(var(--card));
  border-bottom: 1px solid hsl(var(--border));
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 30;
}

.topbar-breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.8125rem;
  color: hsl(var(--muted-foreground));
}
.topbar-breadcrumb-current {
  color: hsl(var(--foreground));
  font-weight: 500;
}
.topbar-breadcrumb-sep { opacity: 0.4; }

.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* ── Page Content ──────────────────────────────────────────── */
.page-content {
  flex: 1;
  padding: 1.75rem 1.75rem;
  max-width: var(--content-max);
  width: 100%;
}

.page-header {
  margin-bottom: 1.5rem;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.page-title {
  font-size: 1.375rem;
  font-weight: 600;
  color: hsl(var(--foreground));
  letter-spacing: -0.02em;
}

.page-description {
  font-size: 0.8375rem;
  color: hsl(var(--muted-foreground));
  margin-top: 0.2rem;
}

.page-header-actions {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
  align-items: center;
}

/* ── Cards ─────────────────────────────────────────────────── */
.card {
  background: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.card-header {
  padding: 1.125rem 1.375rem 0.875rem;
  border-bottom: 1px solid hsl(var(--border));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.card-title {
  font-size: 0.9375rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.card-description {
  font-size: 0.8125rem;
  color: hsl(var(--muted-foreground));
  margin-top: 0.125rem;
}

.card-body {
  padding: 1.375rem;
}

.card-footer {
  padding: 0.875rem 1.375rem;
  border-top: 1px solid hsl(var(--border));
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* ── KPI / Stat Cards ──────────────────────────────────────── */
.stat-card {
  background: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.375rem;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition-base), transform var(--transition-base);
}
.stat-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.stat-card-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: hsl(var(--muted-foreground));
  margin-bottom: 0.5rem;
}

.stat-card-value {
  font-size: 1.875rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: hsl(var(--foreground));
  line-height: 1;
  margin-bottom: 0.4rem;
}

.stat-card-meta {
  font-size: 0.78rem;
  color: hsl(var(--muted-foreground));
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.stat-card-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.stat-card-icon.green  { background: hsl(var(--status-attivo-bg)); color: hsl(var(--status-attivo)); }
.stat-card-icon.amber  { background: hsl(var(--status-sospeso-bg)); color: hsl(var(--status-sospeso)); }
.stat-card-icon.blue   { background: hsl(215 70% 94%); color: hsl(215 70% 40%); }
.stat-card-icon.violet { background: hsl(260 40% 93%); color: hsl(260 40% 50%); }
.stat-card-icon.rose   { background: hsl(350 80% 94%); color: hsl(350 80% 48%); }

.trend-up   { color: hsl(var(--status-attivo)); }
.trend-down { color: hsl(var(--destructive)); }

/* ── Grid Utilities ────────────────────────────────────────── */
.grid { display: grid; }
.grid-cols-1 { grid-template-columns: repeat(1, minmax(0, 1fr)); }
.grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-cols-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.gap-1  { gap: 0.25rem; }
.gap-2  { gap: 0.5rem; }
.gap-3  { gap: 0.75rem; }
.gap-4  { gap: 1rem; }
.gap-5  { gap: 1.25rem; }
.gap-6  { gap: 1.5rem; }

@media (max-width: 1200px) {
  .grid-cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-cols-5 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .grid-cols-3, .grid-cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .grid-cols-2, .grid-cols-3, .grid-cols-4 { grid-template-columns: repeat(1, minmax(0, 1fr)); }
}

/* ── Flex Utilities ────────────────────────────────────────── */
.flex          { display: flex; }
.flex-col      { flex-direction: column; }
.flex-wrap     { flex-wrap: wrap; }
.items-center  { align-items: center; }
.items-start   { align-items: flex-start; }
.items-end     { align-items: flex-end; }
.justify-center{ justify-content: center; }
.justify-between { justify-content: space-between; }
.justify-end   { justify-content: flex-end; }
.flex-1        { flex: 1 1 0%; }
.flex-shrink-0 { flex-shrink: 0; }
.gap-1  { gap: 0.25rem; }
.gap-2  { gap: 0.5rem; }
.gap-3  { gap: 0.75rem; }
.gap-4  { gap: 1rem; }

/* ── Spacing Utilities ─────────────────────────────────────── */
.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 0.75rem; }
.mt-4 { margin-top: 1rem; }
.mt-6 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.25rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 0.75rem; }
.mb-4 { margin-bottom: 1rem; }
.mb-6 { margin-bottom: 1.5rem; }
.mr-auto { margin-right: auto; }
.ml-auto { margin-left: auto; }

.p-1  { padding: 0.25rem; }
.p-2  { padding: 0.5rem; }
.p-3  { padding: 0.75rem; }
.p-4  { padding: 1rem; }
.p-5  { padding: 1.25rem; }
.p-6  { padding: 1.5rem; }
.px-2 { padding-left: 0.5rem; padding-right: 0.5rem; }
.px-3 { padding-left: 0.75rem; padding-right: 0.75rem; }
.px-4 { padding-left: 1rem; padding-right: 1rem; }
.py-1 { padding-top: 0.25rem; padding-bottom: 0.25rem; }
.py-2 { padding-top: 0.5rem; padding-bottom: 0.5rem; }
.py-3 { padding-top: 0.75rem; padding-bottom: 0.75rem; }

.w-full  { width: 100%; }
.h-full  { height: 100%; }

/* ── Buttons ───────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4375rem;
  padding: 0.5rem 0.875rem;
  font-family: var(--font-sans);
  font-size: 0.8375rem;
  font-weight: 500;
  line-height: 1;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
  text-decoration: none;
  user-select: none;
  -webkit-font-smoothing: antialiased;
}
.btn:focus-visible {
  outline: 2px solid hsl(var(--ring));
  outline-offset: 2px;
}
.btn:disabled {
  pointer-events: none;
  opacity: 0.5;
}
.btn svg { width: 14px; height: 14px; flex-shrink: 0; }

.btn-primary {
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  border-color: hsl(var(--primary));
}
.btn-primary:hover {
  background: hsl(var(--primary) / 0.88);
  color: hsl(var(--primary-foreground));
  text-decoration: none;
}

.btn-secondary {
  background: hsl(var(--secondary));
  color: hsl(var(--secondary-foreground));
  border-color: hsl(var(--border));
}
.btn-secondary:hover {
  background: hsl(var(--secondary) / 0.7);
  text-decoration: none;
}

.btn-outline {
  background: transparent;
  color: hsl(var(--foreground));
  border-color: hsl(var(--border));
}
.btn-outline:hover {
  background: hsl(var(--accent));
  text-decoration: none;
}

.btn-ghost {
  background: transparent;
  color: hsl(var(--foreground));
  border-color: transparent;
}
.btn-ghost:hover {
  background: hsl(var(--accent));
  text-decoration: none;
}

.btn-destructive {
  background: hsl(var(--destructive));
  color: hsl(var(--destructive-foreground));
  border-color: hsl(var(--destructive));
}
.btn-destructive:hover { background: hsl(var(--destructive) / 0.88); text-decoration: none; }

.btn-sm {
  padding: 0.3125rem 0.625rem;
  font-size: 0.78rem;
  gap: 0.3125rem;
}
.btn-sm svg { width: 12px; height: 12px; }

.btn-lg {
  padding: 0.6875rem 1.25rem;
  font-size: 0.9375rem;
  gap: 0.5rem;
}
.btn-lg svg { width: 16px; height: 16px; }

.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: var(--radius);
}
.btn-icon-sm { width: 26px; height: 26px; }
.btn-icon-lg { width: 40px; height: 40px; }

/* ── Form Controls ─────────────────────────────────────────── */
.form-group { margin-bottom: 1.125rem; }

.form-label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 500;
  color: hsl(var(--foreground));
  margin-bottom: 0.375rem;
}
.form-label-required::after {
  content: ' *';
  color: hsl(var(--destructive));
}

.form-hint {
  font-size: 0.75rem;
  color: hsl(var(--muted-foreground));
  margin-top: 0.3rem;
}

.form-error {
  font-size: 0.75rem;
  color: hsl(var(--destructive));
  margin-top: 0.3rem;
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.input {
  width: 100%;
  height: 36px;
  padding: 0 0.75rem;
  font-family: var(--font-sans);
  font-size: 0.8375rem;
  color: hsl(var(--foreground));
  background: hsl(var(--card));
  border: 1px solid hsl(var(--input));
  border-radius: var(--radius);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  outline: none;
}
.input:focus {
  border-color: hsl(var(--primary));
  box-shadow: 0 0 0 3px hsl(var(--primary) / 0.12);
}
.input::placeholder { color: hsl(var(--muted-foreground) / 0.7); }
.input.input-error { border-color: hsl(var(--destructive)); }
.input.input-error:focus { box-shadow: 0 0 0 3px hsl(var(--destructive) / 0.12); }
.input-sm { height: 30px; font-size: 0.78rem; padding: 0 0.5rem; }
.input-lg { height: 44px; font-size: 0.9375rem; padding: 0 1rem; }

textarea.input {
  height: auto;
  padding: 0.5rem 0.75rem;
  resize: vertical;
  min-height: 80px;
  line-height: 1.5;
}

select.input {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23999' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.625rem center;
  padding-right: 2.25rem;
  cursor: pointer;
}

.input-group {
  display: flex;
  align-items: stretch;
}
.input-group .input {
  border-radius: 0;
  flex: 1;
}
.input-group .input:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.input-group .input:last-child  { border-radius: 0 var(--radius) var(--radius) 0; }
.input-group-addon {
  display: flex;
  align-items: center;
  padding: 0 0.75rem;
  background: hsl(var(--muted));
  border: 1px solid hsl(var(--input));
  font-size: 0.8125rem;
  color: hsl(var(--muted-foreground));
  white-space: nowrap;
}
.input-group-addon:first-child { border-radius: var(--radius) 0 0 var(--radius); border-right: none; }
.input-group-addon:last-child  { border-radius: 0 var(--radius) var(--radius) 0; border-left: none; }

.input-with-icon { position: relative; }
.input-with-icon .input { padding-left: 2.25rem; }
.input-with-icon .input-icon {
  position: absolute;
  left: 0.625rem;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: hsl(var(--muted-foreground));
  pointer-events: none;
}
.input-with-icon.icon-right .input { padding-left: 0.75rem; padding-right: 2.25rem; }
.input-with-icon.icon-right .input-icon { left: auto; right: 0.625rem; }

/* Checkbox & Radio */
.checkbox-group, .radio-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
}
.checkbox-group input[type="checkbox"],
.radio-group input[type="radio"] {
  width: 15px;
  height: 15px;
  cursor: pointer;
  accent-color: hsl(var(--primary));
  flex-shrink: 0;
}
.checkbox-group label, .radio-group label {
  font-size: 0.8375rem;
  cursor: pointer;
  user-select: none;
}

/* ── Tables ────────────────────────────────────────────────── */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid hsl(var(--border));
}

table.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8375rem;
  background: hsl(var(--card));
}

.table thead tr {
  border-bottom: 1px solid hsl(var(--border));
}

.table th {
  padding: 0.6875rem 1rem;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: hsl(var(--muted-foreground));
  white-space: nowrap;
  background: hsl(var(--muted) / 0.4);
}

.table th:first-child { border-radius: var(--radius-lg) 0 0 0; }
.table th:last-child  { border-radius: 0 var(--radius-lg) 0 0; }

.table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid hsl(var(--border) / 0.6);
  color: hsl(var(--foreground));
  vertical-align: middle;
}

.table tbody tr:last-child td { border-bottom: none; }

.table tbody tr {
  transition: background-color var(--transition-fast);
}
.table tbody tr:hover {
  background: hsl(var(--muted) / 0.4);
}

.table .col-actions {
  width: 1%;
  white-space: nowrap;
  text-align: right;
}

.table .col-check {
  width: 40px;
  text-align: center;
}

/* ── Badges / Status Pills ─────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.1875rem 0.5rem;
  border-radius: var(--radius-full);
  font-size: 0.71875rem;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
}

.badge-dot::before {
  content: '';
  display: inline-block;
  width: 5px;
  height: 5px;
  border-radius: var(--radius-full);
  background: currentColor;
}

.badge-attivo      { background: hsl(var(--status-attivo-bg)); color: hsl(var(--status-attivo)); }
.badge-sospeso     { background: hsl(var(--status-sospeso-bg)); color: hsl(var(--status-sospeso)); }
.badge-concluso    { background: hsl(var(--status-concluso-bg)); color: hsl(var(--status-concluso)); }
.badge-archiviato  { background: hsl(var(--status-archiviato-bg)); color: hsl(var(--status-archiviato)); }
.badge-bozza       { background: hsl(var(--status-bozza-bg)); color: hsl(var(--status-bozza)); }
.badge-in-attesa   { background: hsl(38 80% 93%); color: hsl(38 90% 38%); }
.badge-validata    { background: hsl(var(--status-attivo-bg)); color: hsl(var(--status-attivo)); }
.badge-primary     { background: hsl(var(--primary) / 0.12); color: hsl(var(--primary)); }
.badge-secondary   { background: hsl(var(--secondary)); color: hsl(var(--secondary-foreground)); }
.badge-destructive { background: hsl(var(--destructive-muted)); color: hsl(var(--destructive)); }
.badge-info        { background: hsl(var(--info-muted)); color: hsl(var(--info)); }

/* ── Tabs ──────────────────────────────────────────────────── */
.tabs-list {
  display: flex;
  gap: 0;
  border-bottom: 1px solid hsl(var(--border));
  margin-bottom: 1.5rem;
}

.tab-trigger {
  padding: 0.6875rem 1rem;
  font-size: 0.8375rem;
  font-weight: 500;
  color: hsl(var(--muted-foreground));
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  cursor: pointer;
  transition: color var(--transition-fast), border-color var(--transition-fast);
  white-space: nowrap;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 0.375rem;
}
.tab-trigger:hover { color: hsl(var(--foreground)); text-decoration: none; }
.tab-trigger.active {
  color: hsl(var(--primary));
  border-bottom-color: hsl(var(--primary));
}

/* ── Alerts ────────────────────────────────────────────────── */
.alert {
  display: flex;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
  border-radius: var(--radius-md);
  font-size: 0.8375rem;
  line-height: 1.5;
  border: 1px solid transparent;
}
.alert svg { width: 16px; height: 16px; flex-shrink: 0; margin-top: 0.1rem; }
.alert-title { font-weight: 600; margin-bottom: 0.2rem; }

.alert-info        { background: hsl(var(--info-muted)); color: hsl(215 60% 35%); border-color: hsl(215 70% 85%); }
.alert-success     { background: hsl(var(--success-muted)); color: hsl(var(--success)); border-color: hsl(152 40% 82%); }
.alert-warning     { background: hsl(var(--warning-muted)); color: hsl(38 80% 32%); border-color: hsl(38 80% 82%); }
.alert-destructive { background: hsl(var(--destructive-muted)); color: hsl(var(--destructive)); border-color: hsl(4 80% 85%); }

/* ── Pagination ────────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.8125rem;
}

.page-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 32px;
  padding: 0 0.5rem;
  border-radius: var(--radius);
  color: hsl(var(--foreground));
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
  font-weight: 450;
}
.page-link:hover { background: hsl(var(--accent)); text-decoration: none; }
.page-link.active {
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  border-color: hsl(var(--primary));
}
.page-link.disabled {
  pointer-events: none;
  opacity: 0.4;
}

.pagination-info {
  font-size: 0.78rem;
  color: hsl(var(--muted-foreground));
  margin-left: auto;
}

/* ── Search / Filter Bar ───────────────────────────────────── */
.filter-bar {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}

.filter-bar .input { width: auto; min-width: 220px; }

/* ── Dropdown Menu ─────────────────────────────────────────── */
.dropdown { position: relative; display: inline-flex; }

.dropdown-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  min-width: 160px;
  background: hsl(var(--popover));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 0.25rem;
  z-index: 50;
  display: none;
  animation: dropdown-in 150ms ease;
}
.dropdown-menu.open { display: block; }

@keyframes dropdown-in {
  from { opacity: 0; transform: translateY(-4px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4375rem 0.625rem;
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  color: hsl(var(--foreground));
  cursor: pointer;
  transition: background-color var(--transition-fast);
  text-decoration: none;
  width: 100%;
  border: none;
  background: none;
  font-family: var(--font-sans);
  text-align: left;
}
.dropdown-item:hover { background: hsl(var(--accent)); text-decoration: none; }
.dropdown-item.destructive { color: hsl(var(--destructive)); }
.dropdown-item.destructive:hover { background: hsl(var(--destructive-muted)); }
.dropdown-item svg { width: 14px; height: 14px; flex-shrink: 0; opacity: 0.75; }

.dropdown-separator {
  height: 1px;
  background: hsl(var(--border));
  margin: 0.25rem 0;
}

.dropdown-label {
  padding: 0.25rem 0.625rem;
  font-size: 0.71875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: hsl(var(--muted-foreground));
}

/* ── Modal / Dialog ────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: hsl(25 15% 10% / 0.5);
  backdrop-filter: blur(2px);
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  animation: backdrop-in 200ms ease;
}
@keyframes backdrop-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal {
  background: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  max-width: 520px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  animation: modal-in 200ms cubic-bezier(0.34, 1.56, 0.64, 1);
}
.modal-lg { max-width: 720px; }
.modal-sm { max-width: 380px; }

@keyframes modal-in {
  from { opacity: 0; transform: scale(0.95) translateY(8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  padding: 1.375rem 1.5rem 1rem;
  border-bottom: 1px solid hsl(var(--border));
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}
.modal-title { font-size: 1.0625rem; font-weight: 600; letter-spacing: -0.01em; }
.modal-body  { padding: 1.375rem 1.5rem; }
.modal-footer {
  padding: 1rem 1.5rem 1.375rem;
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

/* ── Empty State ───────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3.5rem 2rem;
  text-align: center;
}
.empty-state-icon {
  width: 48px;
  height: 48px;
  background: hsl(var(--muted));
  border-radius: var(--radius-xl);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 1rem;
  color: hsl(var(--muted-foreground));
}
.empty-state-title {
  font-size: 0.9375rem;
  font-weight: 600;
  margin-bottom: 0.375rem;
}
.empty-state-description {
  font-size: 0.8125rem;
  color: hsl(var(--muted-foreground));
  max-width: 360px;
  line-height: 1.6;
  margin-bottom: 1.25rem;
}

/* ── Progress Bar ──────────────────────────────────────────── */
.progress {
  height: 6px;
  background: hsl(var(--muted));
  border-radius: var(--radius-full);
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  background: hsl(var(--primary));
  border-radius: var(--radius-full);
  transition: width var(--transition-slow);
}
.progress-bar.warning { background: hsl(var(--warning)); }
.progress-bar.danger  { background: hsl(var(--destructive)); }

/* ── Separator ─────────────────────────────────────────────── */
.separator {
  height: 1px;
  background: hsl(var(--border));
  margin: 1rem 0;
}
.separator-vertical {
  width: 1px;
  background: hsl(var(--border));
  align-self: stretch;
}

/* ── Tooltip ───────────────────────────────────────────────── */
[data-tooltip] {
  position: relative;
}
[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: hsl(var(--foreground));
  color: hsl(var(--background));
  font-size: 0.71875rem;
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--transition-fast);
  z-index: 100;
}
[data-tooltip]:hover::after { opacity: 1; }

/* ── Detail/Info List ──────────────────────────────────────── */
.detail-list {
  display: grid;
  gap: 0;
}
.detail-item {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 0.5rem;
  padding: 0.625rem 0;
  border-bottom: 1px solid hsl(var(--border) / 0.6);
  font-size: 0.8375rem;
}
.detail-item:last-child { border-bottom: none; }
.detail-label { color: hsl(var(--muted-foreground)); font-size: 0.8125rem; }
.detail-value { color: hsl(var(--foreground)); font-weight: 450; }

/* ── Section Divider with Title ────────────────────────────── */
.section-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: hsl(var(--muted-foreground));
  padding-bottom: 0.5rem;
  border-bottom: 1px solid hsl(var(--border));
  margin-bottom: 1rem;
}

/* ── Code ──────────────────────────────────────────────────── */
code {
  font-family: var(--font-mono);
  font-size: 0.82em;
  background: hsl(var(--muted));
  padding: 0.125rem 0.375rem;
  border-radius: var(--radius-sm);
  color: hsl(var(--foreground));
}

/* ── Utility: truncate, overflow, hidden ──────────────────── */
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hidden   { display: none !important; }
.sr-only  { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
.overflow-hidden { overflow: hidden; }
.rounded    { border-radius: var(--radius); }
.rounded-lg { border-radius: var(--radius-lg); }
.rounded-full { border-radius: var(--radius-full); }
.border { border: 1px solid hsl(var(--border)); }

/* ── Auth Layout ───────────────────────────────────────────── */
.auth-layout {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.auth-panel-left {
  background: hsl(var(--primary));
  display: flex;
  flex-direction: column;
  padding: 3rem;
  position: relative;
  overflow: hidden;
}

.auth-panel-left::before {
  content: '';
  position: absolute;
  top: -80px;
  right: -80px;
  width: 320px;
  height: 320px;
  border-radius: var(--radius-full);
  background: hsl(var(--primary-foreground) / 0.06);
}
.auth-panel-left::after {
  content: '';
  position: absolute;
  bottom: -60px;
  left: -40px;
  width: 220px;
  height: 220px;
  border-radius: var(--radius-full);
  background: hsl(var(--primary-foreground) / 0.06);
}

.auth-panel-right {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3rem 2rem;
  background: hsl(var(--background));
}

.auth-card {
  width: 100%;
  max-width: 380px;
}

.auth-logo {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  margin-bottom: 2rem;
}

.auth-logo-mark {
  width: 36px;
  height: 36px;
  background: hsl(var(--primary-foreground) / 0.18);
  border: 1px solid hsl(var(--primary-foreground) / 0.25);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 1.125rem;
  color: hsl(var(--primary-foreground));
}

.auth-tagline {
  color: hsl(var(--primary-foreground));
  opacity: 0.9;
}

.auth-headline {
  font-family: var(--font-display);
  font-size: 2.25rem;
  color: hsl(var(--primary-foreground));
  line-height: 1.15;
  margin-top: auto;
  letter-spacing: -0.02em;
}

@media (max-width: 768px) {
  .auth-layout { grid-template-columns: 1fr; }
  .auth-panel-left { display: none; }
  .main-content { margin-left: 0; }
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
}

/* ── Scrollbar ─────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: hsl(var(--border));
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover { background: hsl(var(--muted-foreground) / 0.5); }

/* ── Print ─────────────────────────────────────────────────── */
@media print {
  .sidebar, .topbar, .page-header-actions { display: none !important; }
  .main-content { margin-left: 0; }
  .card { box-shadow: none; border: 1px solid #ccc; }
}