/* ==========================================================================
   Design system — Calendario
   Tutti i colori sono variabili CSS: il file /theme.css (generato dall'admin)
   sovrascrive i valori per tema chiaro (:root) e scuro ([data-theme="dark"]).
   ========================================================================== */

:root {
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 18px;
  --sidebar-width: 260px;
  --topbar-height: 64px;
  --transition: 160ms cubic-bezier(.4, 0, .2, 1);

  /* Tema chiaro (default) */
  --bg: #f4f6fb;
  --bg-gradient: radial-gradient(1200px 600px at 100% -10%, rgba(99, 102, 241, .10), transparent 60%), radial-gradient(900px 500px at -10% 110%, rgba(236, 72, 153, .07), transparent 60%);
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #eef2f7;
  --border: #e3e8ef;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-muted: #64748b;
  --text-soft: #94a3b8;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-soft: rgba(99, 102, 241, .12);
  --primary-contrast: #ffffff;
  --accent: #ec4899;
  --success: #10b981;
  --success-soft: rgba(16, 185, 129, .12);
  --warning: #f59e0b;
  --warning-soft: rgba(245, 158, 11, .14);
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, .12);
  --info: #0ea5e9;
  --info-soft: rgba(14, 165, 233, .12);
  --sidebar-bg: #0f172a;
  --sidebar-text: #cbd5e1;
  --sidebar-text-active: #ffffff;
  --sidebar-active: rgba(99, 102, 241, .22);
  --sidebar-border: rgba(255, 255, 255, .06);
  --topbar-bg: rgba(255, 255, 255, .78);
  --input-bg: #ffffff;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
  --shadow: 0 1px 3px rgba(15, 23, 42, .06), 0 6px 24px rgba(15, 23, 42, .06);
  --shadow-lg: 0 20px 50px rgba(15, 23, 42, .16);
  --focus-ring: 0 0 0 3px rgba(99, 102, 241, .35);
  --hero-gradient: linear-gradient(135deg, #6366f1 0%, #8b5cf6 45%, #ec4899 100%);
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #0b1020;
  --bg-gradient: radial-gradient(1200px 600px at 100% -10%, rgba(99, 102, 241, .16), transparent 60%), radial-gradient(900px 500px at -10% 110%, rgba(236, 72, 153, .08), transparent 60%);
  --surface: #121a2e;
  --surface-2: #172036;
  --surface-3: #1e2943;
  --border: #243150;
  --border-strong: #334466;
  --text: #e6eaf3;
  --text-muted: #94a3b8;
  --text-soft: #64748b;
  --primary: #818cf8;
  --primary-hover: #a5b4fc;
  --primary-soft: rgba(129, 140, 248, .16);
  --primary-contrast: #0b1020;
  --accent: #f472b6;
  --success: #34d399;
  --success-soft: rgba(52, 211, 153, .14);
  --warning: #fbbf24;
  --warning-soft: rgba(251, 191, 36, .14);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, .14);
  --info: #38bdf8;
  --info-soft: rgba(56, 189, 248, .14);
  --sidebar-bg: #080c18;
  --sidebar-text: #94a3b8;
  --sidebar-text-active: #ffffff;
  --sidebar-active: rgba(129, 140, 248, .18);
  --sidebar-border: rgba(255, 255, 255, .05);
  --topbar-bg: rgba(11, 16, 32, .75);
  --input-bg: #0f1628;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow: 0 1px 3px rgba(0, 0, 0, .3), 0 8px 28px rgba(0, 0, 0, .25);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, .5);
  --focus-ring: 0 0 0 3px rgba(129, 140, 248, .4);
  --hero-gradient: linear-gradient(135deg, #4f46e5 0%, #7c3aed 45%, #db2777 100%);
  color-scheme: dark;
}

/* ---------------------------------------------------------------- Base */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  background-image: var(--bg-gradient);
  background-attachment: fixed;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  transition: background-color var(--transition), color var(--transition);
}
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); text-decoration: underline; }
img { max-width: 100%; height: auto; }
h1, h2, h3, h4, h5 { line-height: 1.25; margin: 0 0 .6em; font-weight: 700; letter-spacing: -.01em; }
h1 { font-size: 1.85rem; }
h2 { font-size: 1.45rem; }
h3 { font-size: 1.15rem; }
h4 { font-size: 1rem; }
p { margin: 0 0 1em; }
hr { border: 0; border-top: 1px solid var(--border); margin: 1.5rem 0; }
code, pre, kbd { font-family: var(--font-mono); font-size: .88em; }
code { background: var(--surface-3); padding: .12em .4em; border-radius: 6px; }
pre { background: var(--surface-3); padding: 1rem; border-radius: var(--radius-sm); overflow: auto; }
kbd { background: var(--surface-2); border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 6px; padding: .05em .45em; font-size: .8em; }
::selection { background: var(--primary-soft); }
.icon { flex-shrink: 0; vertical-align: middle; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); border: 0; }
[hidden] { display: none !important; }

/* Scrollbar */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 10px; border: 2px solid transparent; background-clip: padding-box; }

/* ---------------------------------------------------------------- Utility */
.text-muted { color: var(--text-muted) !important; }
.text-soft { color: var(--text-soft) !important; }
.text-success { color: var(--success) !important; }
.text-danger { color: var(--danger) !important; }
.text-warning { color: var(--warning) !important; }
.text-primary { color: var(--primary) !important; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-sm { font-size: .875rem; }
.text-xs { font-size: .78rem; }
.text-lg { font-size: 1.1rem; }
.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }
.mono { font-family: var(--font-mono); }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.break { word-break: break-word; overflow-wrap: anywhere; }
.flex { display: flex; }
.inline-flex { display: inline-flex; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.justify-end { justify-content: flex-end; }
.flex-wrap { flex-wrap: wrap; }
.flex-1 { flex: 1 1 0; min-width: 0; }
.gap-1 { gap: .25rem; } .gap-2 { gap: .5rem; } .gap-3 { gap: .75rem; } .gap-4 { gap: 1rem; } .gap-6 { gap: 1.5rem; }
.mt-0 { margin-top: 0 !important; } .mt-1 { margin-top: .25rem; } .mt-2 { margin-top: .5rem; } .mt-3 { margin-top: .75rem; } .mt-4 { margin-top: 1rem; } .mt-6 { margin-top: 1.5rem; } .mt-8 { margin-top: 2rem; }
.mb-0 { margin-bottom: 0 !important; } .mb-1 { margin-bottom: .25rem; } .mb-2 { margin-bottom: .5rem; } .mb-3 { margin-bottom: .75rem; } .mb-4 { margin-bottom: 1rem; } .mb-6 { margin-bottom: 1.5rem; } .mb-8 { margin-bottom: 2rem; }
.ml-auto { margin-left: auto; }
.p-0 { padding: 0 !important; }
.w-100 { width: 100%; }
.hide-mobile { }
.show-mobile { display: none !important; }
@media (max-width: 768px) {
  .hide-mobile { display: none !important; }
  .show-mobile { display: initial !important; }
}

/* Grid */
.grid { display: grid; gap: 1.25rem; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-auto { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.col-span-2 { grid-column: span 2; }
@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 720px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: minmax(0, 1fr); } .col-span-2 { grid-column: auto; } }

/* ---------------------------------------------------------------- Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  padding: .58rem 1.05rem; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; font-size: .9rem; line-height: 1.2;
  cursor: pointer; text-decoration: none !important; white-space: nowrap;
  transition: background var(--transition), border-color var(--transition), color var(--transition), box-shadow var(--transition), transform var(--transition);
  user-select: none;
}
.btn:hover { background: var(--surface-2); border-color: var(--border-strong); color: var(--text); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.btn:disabled, .btn.disabled { opacity: .55; pointer-events: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-contrast); box-shadow: 0 4px 14px -4px var(--primary); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); color: var(--primary-contrast); }
.btn-gradient { background: var(--hero-gradient); border: 0; color: #fff; box-shadow: 0 8px 24px -8px rgba(99, 102, 241, .7); }
.btn-gradient:hover { color: #fff; filter: brightness(1.08); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.08); background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-success:hover { filter: brightness(1.08); background: var(--success); color: #fff; }
.btn-warning { background: var(--warning); border-color: var(--warning); color: #111; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-3); border-color: transparent; }
.btn-outline { background: transparent; border-color: var(--primary); color: var(--primary); }
.btn-outline:hover { background: var(--primary-soft); color: var(--primary); border-color: var(--primary); }
.btn-soft-danger { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
.btn-soft-danger:hover { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-sm { padding: .38rem .72rem; font-size: .82rem; border-radius: 7px; }
.btn-lg { padding: .82rem 1.4rem; font-size: 1rem; border-radius: var(--radius); }
.btn-block { width: 100%; }
.btn-icon { padding: .5rem; width: 38px; height: 38px; }
.btn-icon.btn-sm { width: 32px; height: 32px; padding: .35rem; }
.btn.loading { position: relative; color: transparent !important; pointer-events: none; }
.btn.loading::after { content: ""; position: absolute; width: 16px; height: 16px; border: 2px solid currentColor; border-color: var(--primary-contrast) transparent var(--primary-contrast) transparent; border-radius: 50%; animation: spin .7s linear infinite; }
.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; margin-left: -1px; }
.btn-group .btn:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); margin-left: 0; }
.btn-group .btn:last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.btn-group .btn.active { background: var(--primary-soft); color: var(--primary); border-color: var(--primary); z-index: 1; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------- Cards */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm); padding: 1.5rem; position: relative;
}
.card + .card { margin-top: 1.25rem; }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin: -1.5rem -1.5rem 1.25rem; padding: 1.1rem 1.5rem; border-bottom: 1px solid var(--border); }
.card-header h2, .card-header h3, .card-header h4 { margin: 0; font-size: 1.05rem; }
.card-footer { margin: 1.25rem -1.5rem -1.5rem; padding: 1rem 1.5rem; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--radius-lg) var(--radius-lg); display: flex; gap: .75rem; justify-content: flex-end; flex-wrap: wrap; }
.card-title { font-size: 1.05rem; font-weight: 700; margin: 0 0 .25rem; }
.card-subtitle { color: var(--text-muted); font-size: .88rem; margin: 0 0 1rem; }
.card-hover { transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition); }
.card-hover:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--border-strong); }
.card-flush { padding: 0; overflow: hidden; }
.card-flush .card-header { margin: 0; }
.card-danger { border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); }
.card-danger .card-header { background: var(--danger-soft); }

/* Stat tiles */
.stat { display: flex; align-items: center; gap: 1rem; }
.stat-icon { width: 48px; height: 48px; border-radius: 14px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); flex-shrink: 0; }
.stat-icon.success { background: var(--success-soft); color: var(--success); }
.stat-icon.warning { background: var(--warning-soft); color: var(--warning); }
.stat-icon.danger { background: var(--danger-soft); color: var(--danger); }
.stat-icon.info { background: var(--info-soft); color: var(--info); }
.stat-value { font-size: 1.6rem; font-weight: 800; line-height: 1.1; letter-spacing: -.02em; }
.stat-label { color: var(--text-muted); font-size: .85rem; }
.stat-delta { font-size: .8rem; font-weight: 600; }
.stat-delta.up { color: var(--success); } .stat-delta.down { color: var(--danger); }

/* ---------------------------------------------------------------- Forms */
.form-group { margin-bottom: 1.1rem; }
.form-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.form-row-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; }
@media (max-width: 640px) { .form-row, .form-row-3 { grid-template-columns: minmax(0, 1fr); } }
label, .label { display: block; font-weight: 600; font-size: .86rem; margin-bottom: .4rem; color: var(--text); }
.label-hint { font-weight: 400; color: var(--text-muted); }
.input, .select, .textarea,
input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="url"], input[type="tel"], input[type="search"], input[type="date"], input[type="time"], input[type="datetime-local"], select, textarea {
  width: 100%; padding: .62rem .85rem; font: inherit; font-size: .93rem; color: var(--text);
  background: var(--input-bg); border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
  appearance: none; -webkit-appearance: none;
}
select, .select { 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='%2394a3b8' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right .8rem center; padding-right: 2.2rem; }
select[multiple] { background-image: none; padding-right: .85rem; }
textarea { min-height: 110px; resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus, .input:focus { outline: none; border-color: var(--primary); box-shadow: var(--focus-ring); }
input::placeholder, textarea::placeholder { color: var(--text-soft); }
input:disabled, select:disabled, textarea:disabled { opacity: .6; cursor: not-allowed; }
input[type="color"] { width: 46px; height: 38px; padding: 3px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--input-bg); cursor: pointer; }
input[type="file"] { font: inherit; font-size: .88rem; color: var(--text-muted); }
input[type="file"]::file-selector-button { font: inherit; font-weight: 600; font-size: .85rem; padding: .45rem .9rem; margin-right: .75rem; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text); cursor: pointer; }
input[type="range"] { width: 100%; accent-color: var(--primary); }
.input-sm { padding: .4rem .65rem !important; font-size: .85rem !important; }
.is-invalid { border-color: var(--danger) !important; }
.form-hint { font-size: .8rem; color: var(--text-muted); margin-top: .35rem; }
.form-error { font-size: .8rem; color: var(--danger); margin-top: .35rem; }
.input-group { display: flex; align-items: stretch; }
.input-group > input, .input-group > select { border-radius: 0; flex: 1; min-width: 0; }
.input-group > :first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.input-group > :last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.input-group > * + * { margin-left: -1px; }
.input-group-text { display: flex; align-items: center; padding: 0 .8rem; background: var(--surface-3); border: 1px solid var(--border-strong); color: var(--text-muted); font-size: .88rem; white-space: nowrap; }
.input-icon { position: relative; }
.input-icon > .icon { position: absolute; left: .8rem; top: 50%; transform: translateY(-50%); color: var(--text-soft); pointer-events: none; }
.input-icon > input { padding-left: 2.4rem; }
.password-wrap { position: relative; }
.password-wrap input { padding-right: 2.8rem; }
.password-toggle { position: absolute; right: .35rem; top: 50%; transform: translateY(-50%); background: none; border: 0; color: var(--text-soft); cursor: pointer; padding: .4rem; border-radius: 6px; display: grid; place-items: center; }
.password-toggle:hover { color: var(--text); background: var(--surface-3); }
.otp-input { font-family: var(--font-mono); font-size: 1.6rem !important; letter-spacing: .5em; text-align: center; padding-left: 1rem !important; }

/* Checkbox / radio */
.check { display: flex; align-items: flex-start; gap: .6rem; font-weight: 500; cursor: pointer; margin-bottom: .5rem; font-size: .92rem; }
.check input { width: 18px; height: 18px; margin: .15rem 0 0; accent-color: var(--primary); flex-shrink: 0; cursor: pointer; }
.check small { display: block; color: var(--text-muted); font-weight: 400; }

/* Switch */
.switch { display: flex; align-items: center; justify-content: space-between; gap: 1rem; cursor: pointer; padding: .7rem 0; font-weight: 500; margin: 0; }
.switch + .switch { border-top: 1px solid var(--border); }
.switch-text { flex: 1; }
.switch-text small { display: block; color: var(--text-muted); font-weight: 400; font-size: .82rem; margin-top: .1rem; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-ui { position: relative; width: 44px; height: 24px; border-radius: 99px; background: var(--border-strong); transition: background var(--transition); flex-shrink: 0; }
.switch-ui::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: transform var(--transition); }
.switch input:checked + .switch-ui { background: var(--primary); }
.switch input:checked + .switch-ui::after { transform: translateX(20px); }
.switch input:focus-visible + .switch-ui { box-shadow: var(--focus-ring); }

/* Color swatches */
.swatches { display: flex; flex-wrap: wrap; gap: .45rem; }
.swatch { width: 28px; height: 28px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; position: relative; padding: 0; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .1); }
.swatch.active, .swatch[aria-pressed="true"] { border-color: var(--surface); box-shadow: 0 0 0 2px var(--text); }
.swatch input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }

/* ---------------------------------------------------------------- Alerts / badges */
.alert { display: flex; gap: .75rem; align-items: flex-start; padding: .9rem 1.1rem; border-radius: var(--radius); border: 1px solid transparent; margin-bottom: 1rem; font-size: .92rem; }
.alert > .icon { margin-top: 2px; }
.alert-success { background: var(--success-soft); color: var(--text); border-color: color-mix(in srgb, var(--success) 35%, transparent); }
.alert-success > .icon { color: var(--success); }
.alert-error, .alert-danger { background: var(--danger-soft); color: var(--text); border-color: color-mix(in srgb, var(--danger) 35%, transparent); }
.alert-error > .icon, .alert-danger > .icon { color: var(--danger); }
.alert-warning { background: var(--warning-soft); color: var(--text); border-color: color-mix(in srgb, var(--warning) 40%, transparent); }
.alert-warning > .icon { color: var(--warning); }
.alert-info { background: var(--info-soft); color: var(--text); border-color: color-mix(in srgb, var(--info) 35%, transparent); }
.alert-info > .icon { color: var(--info); }
.alert p:last-child { margin-bottom: 0; }
.alert-title { font-weight: 700; margin-bottom: .2rem; }

.badge { display: inline-flex; align-items: center; gap: .3rem; padding: .18rem .55rem; border-radius: 99px; font-size: .74rem; font-weight: 700; background: var(--surface-3); color: var(--text-muted); white-space: nowrap; letter-spacing: .01em; }
.badge-primary { background: var(--primary-soft); color: var(--primary); }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-info { background: var(--info-soft); color: var(--info); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: currentColor; flex-shrink: 0; }

/* ---------------------------------------------------------------- Tables */
.table-wrap { overflow-x: auto; border-radius: var(--radius); }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th { text-align: left; font-weight: 600; font-size: .76rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); padding: .7rem 1rem; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap; }
.table td { padding: .75rem 1rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background var(--transition); }
.table tbody tr:hover { background: var(--surface-2); }
.table .actions { text-align: right; white-space: nowrap; }
.table-compact td, .table-compact th { padding: .45rem .75rem; }
.card-flush .table th:first-child, .card-flush .table td:first-child { padding-left: 1.5rem; }
.card-flush .table th:last-child, .card-flush .table td:last-child { padding-right: 1.5rem; }

/* ---------------------------------------------------------------- Tabs */
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: 1.5rem; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { display: inline-flex; align-items: center; gap: .45rem; padding: .7rem 1rem; color: var(--text-muted); font-weight: 600; font-size: .9rem; border: 0; background: none; border-bottom: 2px solid transparent; margin-bottom: -1px; cursor: pointer; white-space: nowrap; text-decoration: none !important; font-family: inherit; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.pills { display: inline-flex; gap: .25rem; padding: .25rem; background: var(--surface-3); border-radius: 10px; }
.pill { padding: .4rem .85rem; border-radius: 8px; border: 0; background: none; font: inherit; font-weight: 600; font-size: .85rem; color: var(--text-muted); cursor: pointer; text-decoration: none !important; }
.pill.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

/* ---------------------------------------------------------------- Dropdown */
.dropdown { position: relative; display: inline-block; }
.dropdown-menu { position: absolute; right: 0; top: calc(100% + 6px); min-width: 210px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: .4rem; z-index: 200; display: none; animation: pop .14s ease-out; }
.dropdown-menu.left { right: auto; left: 0; }
.dropdown.open > .dropdown-menu { display: block; }
.dropdown-item { display: flex; align-items: center; gap: .6rem; width: 100%; padding: .55rem .75rem; border-radius: 8px; color: var(--text); font-size: .9rem; background: none; border: 0; font-family: inherit; cursor: pointer; text-align: left; text-decoration: none !important; }
.dropdown-item:hover { background: var(--surface-3); color: var(--text); }
.dropdown-item.danger { color: var(--danger); }
.dropdown-item.active { color: var(--primary); background: var(--primary-soft); }
.dropdown-divider { height: 1px; background: var(--border); margin: .35rem 0; }
.dropdown-header { padding: .5rem .75rem; font-size: .75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .06em; font-weight: 700; }
@keyframes pop { from { opacity: 0; transform: translateY(-4px) scale(.98); } to { opacity: 1; transform: none; } }

/* ---------------------------------------------------------------- Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(2, 6, 23, .55); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); z-index: 1000; display: none; align-items: flex-start; justify-content: center; padding: 5vh 1rem; overflow-y: auto; }
.modal-backdrop.open { display: flex; animation: fade .16s ease-out; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); width: 100%; max-width: 560px; animation: modalIn .2s cubic-bezier(.2, .9, .3, 1.2); margin: auto 0; }
.modal-lg { max-width: 820px; }
.modal-sm { max-width: 420px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 1.1rem 1.5rem; border-bottom: 1px solid var(--border); gap: 1rem; }
.modal-header h3 { margin: 0; font-size: 1.1rem; }
.modal-body { padding: 1.5rem; }
.modal-footer { display: flex; justify-content: flex-end; gap: .6rem; padding: 1rem 1.5rem; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--radius-lg) var(--radius-lg); flex-wrap: wrap; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes modalIn { from { opacity: 0; transform: translateY(12px) scale(.98); } to { opacity: 1; transform: none; } }
body.modal-open { overflow: hidden; }

/* ---------------------------------------------------------------- Toast */
.toasts { position: fixed; right: 1rem; bottom: 1rem; z-index: 2000; display: flex; flex-direction: column; gap: .6rem; max-width: calc(100vw - 2rem); width: 380px; pointer-events: none; }
.toast { display: flex; gap: .7rem; align-items: flex-start; padding: .9rem 1rem; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-lg); animation: toastIn .25s cubic-bezier(.2, .9, .3, 1.2); pointer-events: auto; font-size: .9rem; border-left: 4px solid var(--info); }
.toast.success { border-left-color: var(--success); } .toast.success > .icon { color: var(--success); }
.toast.error { border-left-color: var(--danger); } .toast.error > .icon { color: var(--danger); }
.toast.warning { border-left-color: var(--warning); } .toast.warning > .icon { color: var(--warning); }
.toast.info > .icon { color: var(--info); }
.toast .toast-close { margin-left: auto; background: none; border: 0; color: var(--text-soft); cursor: pointer; padding: 0; }
.toast.hide { animation: toastOut .2s ease-in forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateX(30px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateX(30px); } }

/* ---------------------------------------------------------------- Avatar */
.avatar { border-radius: 50%; object-fit: cover; flex-shrink: 0; display: inline-block; background: var(--surface-3); }
.avatar-initials { display: inline-grid; place-items: center; background: var(--hero-gradient); color: #fff; font-weight: 700; letter-spacing: .02em; }

/* ---------------------------------------------------------------- Empty state */
.empty { text-align: center; padding: 3rem 1rem; color: var(--text-muted); }
.empty .icon { color: var(--text-soft); margin-bottom: .75rem; }
.empty h3 { color: var(--text); margin-bottom: .35rem; }

/* ---------------------------------------------------------------- Pagination */
.pagination { display: flex; gap: .3rem; justify-content: center; flex-wrap: wrap; margin-top: 1.25rem; }
.pagination a, .pagination span { min-width: 36px; height: 36px; padding: 0 .6rem; display: inline-grid; place-items: center; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: .88rem; font-weight: 600; text-decoration: none; }
.pagination a:hover { border-color: var(--primary); color: var(--primary); }
.pagination .active { background: var(--primary); border-color: var(--primary); color: var(--primary-contrast); }
.pagination .disabled { opacity: .45; }

/* ---------------------------------------------------------------- App shell (area riservata / admin) */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-width); background: var(--sidebar-bg); color: var(--sidebar-text);
  display: flex; flex-direction: column; z-index: 300; border-right: 1px solid var(--sidebar-border);
  transition: transform var(--transition);
}
.sidebar-brand { display: flex; align-items: center; gap: .7rem; padding: 1.1rem 1.25rem; height: var(--topbar-height); color: var(--sidebar-text-active); font-weight: 800; font-size: 1.08rem; text-decoration: none !important; border-bottom: 1px solid var(--sidebar-border); }
.sidebar-brand:hover { color: var(--sidebar-text-active); }
.sidebar-brand img { max-height: 34px; width: auto; }
.brand-mark { width: 34px; height: 34px; border-radius: 10px; background: var(--hero-gradient); display: grid; place-items: center; color: #fff; flex-shrink: 0; box-shadow: 0 6px 16px -6px rgba(99, 102, 241, .8); }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 1rem .75rem; }
.nav-section { font-size: .7rem; text-transform: uppercase; letter-spacing: .1em; font-weight: 700; color: var(--sidebar-text); opacity: .55; padding: 1rem .75rem .45rem; }
.nav-section:first-child { padding-top: .25rem; }
.nav-link { display: flex; align-items: center; gap: .75rem; padding: .6rem .8rem; border-radius: 10px; color: var(--sidebar-text); font-weight: 500; font-size: .92rem; text-decoration: none !important; transition: background var(--transition), color var(--transition); margin-bottom: 2px; }
.nav-link:hover { background: rgba(255, 255, 255, .05); color: var(--sidebar-text-active); }
.nav-link.active { background: var(--sidebar-active); color: var(--sidebar-text-active); font-weight: 600; }
.nav-link.active .icon { color: var(--primary); }
.nav-link .badge { margin-left: auto; background: var(--primary); color: var(--primary-contrast); }
.sidebar-footer { padding: .9rem; border-top: 1px solid var(--sidebar-border); }
.sidebar-user { display: flex; align-items: center; gap: .7rem; padding: .5rem; border-radius: 10px; color: var(--sidebar-text-active); text-decoration: none !important; }
.sidebar-user:hover { background: rgba(255, 255, 255, .05); color: var(--sidebar-text-active); }
.sidebar-user small { display: block; color: var(--sidebar-text); font-size: .76rem; }

.main { flex: 1; margin-left: var(--sidebar-width); min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 100; height: var(--topbar-height); display: flex; align-items: center; gap: .75rem; padding: 0 1.75rem; background: var(--topbar-bg); backdrop-filter: saturate(180%) blur(14px); -webkit-backdrop-filter: saturate(180%) blur(14px); border-bottom: 1px solid var(--border); }
.topbar-title { font-weight: 700; font-size: 1.05rem; margin: 0; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: .5rem; }
.content { padding: 1.75rem; flex: 1; width: 100%; max-width: 1440px; margin: 0 auto; }
.content-narrow { max-width: 920px; }
.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1.5rem; flex-wrap: wrap; }
.page-header h1 { margin: 0; font-size: 1.6rem; }
.page-header p { margin: .25rem 0 0; color: var(--text-muted); }
.page-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.sidebar-toggle { display: none; }
.sidebar-overlay { display: none; }
.app-footer { padding: 1rem 1.75rem; color: var(--text-soft); font-size: .8rem; border-top: 1px solid var(--border); display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.app-footer a { color: var(--text-muted); }

@media (max-width: 1024px) {
  .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: none; }
  .sidebar-overlay.open { display: block; position: fixed; inset: 0; background: rgba(2, 6, 23, .5); z-index: 250; }
  .main { margin-left: 0; }
  .sidebar-toggle { display: inline-flex; }
  .topbar { padding: 0 1rem; }
  .content { padding: 1.25rem 1rem; }
}

/* Theme toggle */
.theme-toggle .icon-sun, .theme-toggle .icon-moon, .theme-toggle .icon-auto { display: none; }
html[data-theme-pref="light"] .theme-toggle .icon-sun { display: inline; }
html[data-theme-pref="dark"] .theme-toggle .icon-moon { display: inline; }
html[data-theme-pref="auto"] .theme-toggle .icon-auto, html:not([data-theme-pref]) .theme-toggle .icon-auto { display: inline; }

/* Banner avvisi admin */
.system-banner { display: flex; align-items: center; gap: .6rem; padding: .6rem 1.75rem; font-size: .86rem; background: var(--warning-soft); border-bottom: 1px solid color-mix(in srgb, var(--warning) 40%, transparent); color: var(--text); }
.system-banner.danger { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.system-banner .icon { color: var(--warning); }
.system-banner.danger .icon { color: var(--danger); }

/* ---------------------------------------------------------------- Sito pubblico */
.public-header { position: sticky; top: 0; z-index: 100; background: var(--topbar-bg); backdrop-filter: saturate(180%) blur(14px); -webkit-backdrop-filter: saturate(180%) blur(14px); border-bottom: 1px solid var(--border); }
.public-header .container { display: flex; align-items: center; gap: 1rem; height: 68px; }
.public-brand { display: flex; align-items: center; gap: .65rem; font-weight: 800; font-size: 1.1rem; color: var(--text); text-decoration: none !important; }
.public-brand:hover { color: var(--text); }
.public-brand img { max-height: 38px; width: auto; }
.public-nav { display: flex; align-items: center; gap: .35rem; margin-left: auto; }
.public-nav a.nav-item { padding: .5rem .8rem; border-radius: 8px; color: var(--text-muted); font-weight: 600; font-size: .92rem; text-decoration: none; }
.public-nav a.nav-item:hover, .public-nav a.nav-item.active { color: var(--text); background: var(--surface-3); }
.container { width: 100%; max-width: 1200px; margin: 0 auto; padding: 0 1.25rem; }
.container-sm { max-width: 820px; }
.section { padding: 5rem 0; }
.section-sm { padding: 3rem 0; }
.section-title { text-align: center; max-width: 680px; margin: 0 auto 3rem; }
.section-title h2 { font-size: clamp(1.6rem, 3vw, 2.3rem); }
.section-title p { color: var(--text-muted); font-size: 1.08rem; }
.eyebrow { display: inline-flex; align-items: center; gap: .4rem; font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .1em; color: var(--primary); background: var(--primary-soft); padding: .35rem .8rem; border-radius: 99px; margin-bottom: 1rem; }
.prose { font-size: 1rem; line-height: 1.75; }
.prose h1, .prose h2, .prose h3 { margin-top: 1.8em; }
.prose h2 { font-size: 1.35rem; }
.prose h3 { font-size: 1.12rem; }
.prose ul, .prose ol { padding-left: 1.4rem; margin: 0 0 1em; }
.prose li { margin-bottom: .35em; }
.prose table { width: 100%; border-collapse: collapse; margin: 1rem 0 1.5rem; font-size: .92rem; }
.prose th, .prose td { border: 1px solid var(--border); padding: .55rem .75rem; text-align: left; vertical-align: top; }
.prose th { background: var(--surface-2); }
.prose blockquote { margin: 1rem 0; padding: .75rem 1.25rem; border-left: 4px solid var(--primary); background: var(--surface-2); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.prose img { border-radius: var(--radius); }
.public-footer { border-top: 1px solid var(--border); background: var(--surface); padding: 3rem 0 1.5rem; margin-top: 4rem; color: var(--text-muted); font-size: .9rem; }
.public-footer a { color: var(--text-muted); }
.public-footer a:hover { color: var(--primary); }
@media (max-width: 768px) {
  .public-nav .nav-item { display: none; }
  .public-nav.open { position: absolute; top: 68px; left: 0; right: 0; background: var(--surface); border-bottom: 1px solid var(--border); flex-direction: column; align-items: stretch; padding: .75rem; box-shadow: var(--shadow); }
  .public-nav.open .nav-item { display: block; }
  .section { padding: 3.5rem 0; }
}

/* ---------------------------------------------------------------- Pagine auth */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 2rem 1rem; position: relative; overflow: hidden; }
.auth-wrap::before { content: ""; position: absolute; width: 620px; height: 620px; border-radius: 50%; background: var(--hero-gradient); filter: blur(120px); opacity: .22; top: -220px; right: -180px; pointer-events: none; }
.auth-wrap::after { content: ""; position: absolute; width: 520px; height: 520px; border-radius: 50%; background: var(--accent); filter: blur(130px); opacity: .12; bottom: -220px; left: -180px; pointer-events: none; }
.auth-card { position: relative; z-index: 1; width: 100%; max-width: 440px; background: var(--surface); border: 1px solid var(--border); border-radius: 22px; box-shadow: var(--shadow-lg); padding: 2.25rem; }
.auth-card.wide { max-width: 620px; }
.auth-brand { display: flex; align-items: center; justify-content: center; gap: .65rem; font-weight: 800; font-size: 1.2rem; margin-bottom: 1.5rem; color: var(--text); text-decoration: none !important; }
.auth-brand img { max-height: 46px; width: auto; }
.auth-card h1 { font-size: 1.45rem; text-align: center; margin-bottom: .35rem; }
.auth-sub { text-align: center; color: var(--text-muted); margin-bottom: 1.75rem; font-size: .93rem; }
.auth-links { text-align: center; margin-top: 1.5rem; font-size: .9rem; color: var(--text-muted); }
.auth-top { position: absolute; top: 1rem; right: 1rem; z-index: 2; display: flex; gap: .5rem; }
.auth-footer { position: relative; z-index: 1; text-align: center; margin-top: 1.5rem; font-size: .8rem; color: var(--text-soft); }
.auth-footer a { color: var(--text-muted); }
.divider-text { display: flex; align-items: center; gap: .75rem; color: var(--text-soft); font-size: .8rem; margin: 1.25rem 0; }
.divider-text::before, .divider-text::after { content: ""; flex: 1; height: 1px; background: var(--border); }
@media (max-width: 480px) { .auth-card { padding: 1.5rem; border-radius: 18px; } }

/* ---------------------------------------------------------------- Varie */
.list-group { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.list-item { display: flex; align-items: center; gap: .9rem; padding: .85rem 1rem; border-bottom: 1px solid var(--border); background: var(--surface); }
.list-item:last-child { border-bottom: 0; }
.list-item:hover { background: var(--surface-2); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .45rem 1.25rem; font-size: .9rem; }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; font-weight: 500; word-break: break-word; }
.progress { height: 8px; background: var(--surface-3); border-radius: 99px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--primary); border-radius: 99px; transition: width .4s; }
.code-box { font-family: var(--font-mono); background: var(--surface-3); border: 1px dashed var(--border-strong); border-radius: var(--radius-sm); padding: .75rem 1rem; word-break: break-all; font-size: .9rem; }
.codes-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: .5rem; font-family: var(--font-mono); font-size: 1rem; }
.codes-grid span { background: var(--surface-3); padding: .5rem; border-radius: 8px; text-align: center; letter-spacing: .08em; }
.skeleton { background: linear-gradient(90deg, var(--surface-3) 25%, var(--surface-2) 50%, var(--surface-3) 75%); background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: 6px; }
@keyframes shimmer { to { background-position: -200% 0; } }
.spinner { width: 22px; height: 22px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; }
.tooltip { position: relative; }
[data-tooltip] { position: relative; }
[data-tooltip]:hover::after { content: attr(data-tooltip); position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%); background: #0f172a; color: #fff; padding: .3rem .55rem; border-radius: 6px; font-size: .75rem; white-space: nowrap; z-index: 500; pointer-events: none; font-weight: 500; }
.color-dot { width: 12px; height: 12px; border-radius: 4px; display: inline-block; flex-shrink: 0; }
.drop-zone { border: 2px dashed var(--border-strong); border-radius: var(--radius); padding: 2rem; text-align: center; color: var(--text-muted); transition: border-color var(--transition), background var(--transition); cursor: pointer; }
.drop-zone.dragover, .drop-zone:hover { border-color: var(--primary); background: var(--primary-soft); }

@media print {
  .sidebar, .topbar, .app-footer, .no-print, .toasts, .cookie-bar { display: none !important; }
  .main { margin: 0; }
  body { background: #fff; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
