/* ==========================================================================
   FunnelAI Dashboard — design system
   Un solo file: token, layout, componenti. Nessun build step.
   ========================================================================== */

:root {
  /* Brand */
  --brand-500: #4f46e5;
  --brand-600: #4338ca;
  --brand-400: #6366f1;
  --brand-300: #a5b4fc;
  --accent-500: #06b6d4;

  /* Feedback */
  --success-500: #10b981;
  --success-050: #ecfdf5;
  --warning-500: #f59e0b;
  --warning-050: #fffbeb;
  --danger-500: #f43f5e;
  --danger-050: #fff1f2;
  --info-500: #3b82f6;
  --info-050: #eff6ff;

  /* Surfaces (light) */
  --bg: #f4f5fb;
  --surface: #ffffff;
  --surface-2: #fafbff;
  --surface-3: #f1f3fa;
  --border: #e4e7f2;
  --border-strong: #d2d7e8;

  /* Text */
  --text: #131829;
  --text-muted: #5f6885;
  --text-faint: #8a93ad;
  --text-invert: #ffffff;

  /* Sidebar */
  --nav-bg: #0e1424;
  --nav-bg-2: #161d31;
  --nav-text: #a9b2cc;
  --nav-text-active: #ffffff;
  --nav-hover: rgba(255, 255, 255, 0.06);

  /* Shape */
  --radius-xs: 6px;
  --radius-sm: 9px;
  --radius: 13px;
  --radius-lg: 18px;

  --shadow-xs: 0 1px 2px rgba(19, 24, 41, 0.05);
  --shadow-sm: 0 2px 8px rgba(19, 24, 41, 0.06);
  --shadow: 0 8px 24px -8px rgba(19, 24, 41, 0.14), 0 2px 6px rgba(19, 24, 41, 0.05);
  --shadow-lg: 0 24px 48px -16px rgba(19, 24, 41, 0.22);

  --sidebar-w: 268px;
  --topbar-h: 66px;

  --font: 'Inter', 'Segoe UI Variable Text', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'Cascadia Code', ui-monospace, 'SFMono-Regular', Consolas, monospace;

  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

html[data-theme='dark'] {
  --bg: #0b0f1a;
  --surface: #131a2a;
  --surface-2: #172032;
  --surface-3: #1d2739;
  --border: #253048;
  --border-strong: #32405c;

  --text: #e8ecf7;
  --text-muted: #9aa5c0;
  --text-faint: #6f7b99;

  --nav-bg: #0a0e18;
  --nav-bg-2: #101728;

  --success-050: rgba(16, 185, 129, 0.12);
  --warning-050: rgba(245, 158, 11, 0.12);
  --danger-050: rgba(244, 63, 94, 0.12);
  --info-050: rgba(59, 130, 246, 0.12);

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.4);
  --shadow: 0 10px 28px -10px rgba(0, 0, 0, 0.6);
  --shadow-lg: 0 28px 56px -18px rgba(0, 0, 0, 0.7);
}

/* --------------------------------------------------------------- reset -- */

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -0.015em; line-height: 1.25; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
p { margin: 0 0 10px; }

a { color: var(--brand-500); text-decoration: none; }
a:hover { text-decoration: underline; }

button, input, select, textarea { font: inherit; color: inherit; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 8px; border: 3px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); background-clip: content-box; }

:focus-visible { outline: 2px solid var(--brand-400); outline-offset: 2px; border-radius: 4px; }

/* -------------------------------------------------------------- layout -- */

.app { display: flex; min-height: 100vh; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  background: linear-gradient(180deg, var(--nav-bg) 0%, var(--nav-bg-2) 100%);
  border-right: 1px solid rgba(255, 255, 255, 0.05);
  display: flex;
  flex-direction: column;
  z-index: 40;
  transition: transform 0.28s var(--ease);
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: 11px;
  height: var(--topbar-h);
  padding: 0 20px;
  flex: 0 0 auto;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.sidebar__logo {
  width: 34px; height: 34px;
  flex: 0 0 34px;
  border-radius: 10px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--brand-400), var(--accent-500));
  box-shadow: 0 6px 16px -4px rgba(99, 102, 241, 0.6);
  color: #fff;
}

.sidebar__name { color: #fff; font-weight: 680; font-size: 15.5px; letter-spacing: -0.02em; }
.sidebar__tag { display: block; color: var(--nav-text); font-size: 11px; font-weight: 500; letter-spacing: 0.04em; text-transform: uppercase; }

.sidebar__nav { flex: 1 1 auto; overflow-y: auto; padding: 14px 12px 20px; }
.sidebar__nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.14); background-clip: content-box; }

.nav-group + .nav-group { margin-top: 18px; }
.nav-group__title {
  padding: 0 10px 7px;
  font-size: 10.5px;
  font-weight: 650;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(169, 178, 204, 0.55);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 11px;
  margin-bottom: 2px;
  border-radius: var(--radius-sm);
  color: var(--nav-text);
  font-weight: 520;
  font-size: 13.5px;
  position: relative;
  transition: background 0.15s, color 0.15s;
}
.nav-item:hover { background: var(--nav-hover); color: #e5e9f5; text-decoration: none; }
.nav-item.is-active {
  background: linear-gradient(90deg, rgba(99, 102, 241, 0.22), rgba(99, 102, 241, 0.06));
  color: var(--nav-text-active);
}
.nav-item.is-active::before {
  content: '';
  position: absolute; left: -12px; top: 50%; translate: 0 -50%;
  width: 3px; height: 20px; border-radius: 0 3px 3px 0;
  background: linear-gradient(180deg, var(--brand-400), var(--accent-500));
}
.nav-item .ico { flex: 0 0 18px; opacity: 0.85; }
.nav-item.is-active .ico { opacity: 1; }
.nav-item__badge {
  margin-left: auto;
  min-width: 20px;
  padding: 1px 6px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 650;
  text-align: center;
  background: var(--danger-500);
  color: #fff;
}

.nav-sub { margin: 2px 0 6px 28px; padding-left: 12px; border-left: 1px solid rgba(255,255,255,0.08); }
.nav-sub .nav-item { padding: 6px 10px; font-size: 13px; }
.nav-sub .nav-item.is-active::before { display: none; }
.nav-sub .nav-item.is-active { background: var(--nav-hover); }

.sidebar__footer { flex: 0 0 auto; padding: 12px; border-top: 1px solid rgba(255,255,255,0.06); }

.svc-health { display: flex; flex-direction: column; gap: 6px; padding: 10px 11px; border-radius: var(--radius-sm); background: rgba(255,255,255,0.03); }
.svc-health__row { display: flex; align-items: center; gap: 8px; font-size: 11.5px; color: var(--nav-text); }
.svc-dot { width: 7px; height: 7px; border-radius: 50%; flex: 0 0 7px; background: var(--text-faint); }
.svc-dot.is-up { background: var(--success-500); box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.18); }
.svc-dot.is-down { background: var(--danger-500); box-shadow: 0 0 0 3px rgba(244, 63, 94, 0.18); }

.main { flex: 1 1 auto; min-width: 0; margin-left: var(--sidebar-w); display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 14px;
  padding: 0 26px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar__title { display: flex; flex-direction: column; min-width: 0; }
.topbar__title h1 { font-size: 17px; }
.topbar__sub { font-size: 12.5px; color: var(--text-muted); }
.topbar__actions { margin-left: auto; display: flex; align-items: center; gap: 9px; }

.icon-btn {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: 0.15s;
}
.icon-btn:hover { color: var(--text); border-color: var(--border-strong); background: var(--surface-3); }

.user-chip { display: flex; align-items: center; gap: 9px; padding: 5px 11px 5px 5px; border: 1px solid var(--border); border-radius: 40px; background: var(--surface); }
.avatar { width: 27px; height: 27px; border-radius: 50%; display: grid; place-items: center; font-size: 11.5px; font-weight: 650; color: #fff; background: linear-gradient(135deg, var(--brand-500), var(--accent-500)); }
.user-chip__name { font-size: 12.5px; font-weight: 580; }

.page { padding: 24px 26px 48px; flex: 1 1 auto; }
.page__head { display: flex; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page__head .spacer { flex: 1 1 auto; }
.page__lead { color: var(--text-muted); font-size: 13.5px; max-width: 72ch; }

.sidebar-toggle { display: none; }

/* ----------------------------------------------------------- utilities -- */

.grid { display: grid; gap: 16px; }
.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-kpi { grid-template-columns: repeat(auto-fit, minmax(212px, 1fr)); }
.grid-2-1 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.grid-1-2 { grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); }

.row { display: flex; gap: 10px; align-items: center; }
.row-wrap { flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: 10px; }
.spacer { flex: 1 1 auto; }

.mt-0 { margin-top: 0; } .mt-1 { margin-top: 8px; } .mt-2 { margin-top: 16px; } .mt-3 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; } .mb-1 { margin-bottom: 8px; } .mb-2 { margin-bottom: 16px; } .mb-3 { margin-bottom: 24px; }

.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.small { font-size: 12.5px; }
.tiny { font-size: 11.5px; }
.bold { font-weight: 650; }
.mono { font-family: var(--font-mono); font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.hidden { display: none !important; }

.tone-success { color: var(--success-500); }
.tone-danger { color: var(--danger-500); }
.tone-warning { color: var(--warning-500); }
.tone-info { color: var(--info-500); }

/* ----------------------------------------------------------- surfaces -- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-xs);
}
.card__head {
  display: flex; align-items: center; gap: 12px;
  padding: 15px 18px;
  border-bottom: 1px solid var(--border);
}
.card__head h2, .card__head h3 { margin: 0; }
.card__head .spacer { flex: 1 1 auto; }
.card__sub { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }
.card__body { padding: 18px; }
.card__body--flush { padding: 0; }
.card__foot { padding: 12px 18px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--radius) var(--radius); }

/* KPI tile */
.kpi {
  position: relative;
  padding: 17px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-xs);
  overflow: hidden;
  transition: transform 0.2s var(--ease), box-shadow 0.2s var(--ease);
}
.kpi:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.kpi::after {
  content: ''; position: absolute; inset: 0 0 auto 0; height: 3px;
  background: linear-gradient(90deg, var(--brand-500), var(--accent-500));
  opacity: 0.9;
}
.kpi--success::after { background: linear-gradient(90deg, var(--success-500), #34d399); }
.kpi--warning::after { background: linear-gradient(90deg, var(--warning-500), #fbbf24); }
.kpi--danger::after { background: linear-gradient(90deg, var(--danger-500), #fb7185); }
.kpi--muted::after { background: linear-gradient(90deg, var(--border-strong), var(--border)); }

.kpi__top { display: flex; align-items: center; gap: 9px; margin-bottom: 9px; }
.kpi__icon {
  width: 32px; height: 32px; border-radius: 9px;
  display: grid; place-items: center;
  background: var(--surface-3); color: var(--brand-500);
}
.kpi--success .kpi__icon { background: var(--success-050); color: var(--success-500); }
.kpi--warning .kpi__icon { background: var(--warning-050); color: var(--warning-500); }
.kpi--danger .kpi__icon { background: var(--danger-050); color: var(--danger-500); }
.kpi__label { font-size: 12.5px; color: var(--text-muted); font-weight: 560; }
.kpi__value { font-size: 27px; font-weight: 680; letter-spacing: -0.03em; line-height: 1.1; }
.kpi__unit { font-size: 15px; font-weight: 600; color: var(--text-muted); margin-left: 2px; }
.kpi__foot { margin-top: 7px; font-size: 12px; color: var(--text-muted); display: flex; align-items: center; gap: 6px; }

.delta { display: inline-flex; align-items: center; gap: 3px; font-weight: 620; font-size: 12px; }
.delta--up { color: var(--success-500); }
.delta--down { color: var(--danger-500); }

/* Progress / meter */
.meter { height: 7px; border-radius: 6px; background: var(--surface-3); overflow: hidden; }
.meter__fill { height: 100%; border-radius: 6px; background: linear-gradient(90deg, var(--brand-500), var(--accent-500)); transition: width 0.6s var(--ease); }
.meter--success .meter__fill { background: linear-gradient(90deg, var(--success-500), #34d399); }
.meter--warning .meter__fill { background: linear-gradient(90deg, var(--warning-500), #fbbf24); }
.meter--danger .meter__fill { background: linear-gradient(90deg, var(--danger-500), #fb7185); }

/* ------------------------------------------------------------ buttons -- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 8px 15px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 13.5px; font-weight: 580;
  cursor: pointer;
  white-space: nowrap;
  transition: 0.16s var(--ease);
  text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn:disabled, .btn.is-loading { opacity: 0.6; pointer-events: none; }

.btn--primary { background: linear-gradient(135deg, var(--brand-500), var(--brand-600)); color: #fff; box-shadow: 0 4px 12px -4px rgba(79, 70, 229, 0.55); }
.btn--primary:hover { filter: brightness(1.07); box-shadow: 0 6px 18px -4px rgba(79, 70, 229, 0.6); color: #fff; }

.btn--ghost { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn--ghost:hover { background: var(--surface-3); border-color: var(--border-strong); }

.btn--subtle { background: var(--surface-3); color: var(--text-muted); }
.btn--subtle:hover { color: var(--text); }

.btn--success { background: var(--success-500); color: #fff; }
.btn--success:hover { filter: brightness(1.07); color: #fff; }

.btn--danger { background: var(--danger-500); color: #fff; }
.btn--danger:hover { filter: brightness(1.07); color: #fff; }

.btn--sm { padding: 5px 10px; font-size: 12.5px; border-radius: var(--radius-xs); }
.btn--lg { padding: 11px 22px; font-size: 15px; }
.btn--block { width: 100%; }
.btn--icon { padding: 7px; width: 32px; height: 32px; }

.btn-group { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; background: var(--surface); }
.btn-group > * { border: 0; border-radius: 0; background: transparent; padding: 6px 12px; font-size: 12.5px; color: var(--text-muted); cursor: pointer; }
.btn-group > * + * { border-left: 1px solid var(--border); }
.btn-group > .is-active { background: var(--brand-500); color: #fff; font-weight: 600; }

/* ------------------------------------------------------------- badges -- */

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px;
  border-radius: 30px;
  font-size: 11.5px; font-weight: 620;
  line-height: 1.7;
  white-space: nowrap;
}
.badge--neutral { background: var(--surface-3); color: var(--text-muted); }
.badge--info { background: var(--info-050); color: var(--info-500); }
.badge--success { background: var(--success-050); color: var(--success-500); }
.badge--warning { background: var(--warning-050); color: #b45309; }
.badge--danger { background: var(--danger-050); color: var(--danger-500); }
html[data-theme='dark'] .badge--warning { color: var(--warning-500); }

.badge--dot::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 11px; border-radius: 30px; background: var(--surface-3); font-size: 12px; color: var(--text-muted); }

/* ------------------------------------------------------------- tables -- */

.table-wrap { overflow-x: auto; }

table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.tbl th {
  text-align: left;
  padding: 10px 16px;
  font-size: 11.5px; font-weight: 650;
  letter-spacing: 0.05em; text-transform: uppercase;
  color: var(--text-faint);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky; top: 0; z-index: 1;
}
table.tbl td { padding: 11px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.tbl tbody tr { transition: background 0.12s; }
table.tbl tbody tr:hover { background: var(--surface-2); }
table.tbl tbody tr:last-child td { border-bottom: 0; }
table.tbl td.tight { width: 1%; white-space: nowrap; }
table.tbl .row-actions { display: flex; gap: 4px; justify-content: flex-end; opacity: 0.35; transition: opacity 0.15s; }
table.tbl tbody tr:hover .row-actions { opacity: 1; }

.cell-primary { font-weight: 600; color: var(--text); }
.cell-sub { font-size: 12px; color: var(--text-muted); }

.empty { padding: 48px 24px; text-align: center; color: var(--text-muted); }
.empty__icon { width: 52px; height: 52px; margin: 0 auto 14px; display: grid; place-items: center; border-radius: 16px; background: var(--surface-3); color: var(--text-faint); }
.empty h3 { margin-bottom: 6px; color: var(--text); }

/* --------------------------------------------------------------- forms -- */

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 15px; }
.field__label { font-size: 12.5px; font-weight: 600; color: var(--text); }
.field__hint { font-size: 12px; color: var(--text-muted); }
.field__error { font-size: 12px; color: var(--danger-500); }
.req::after { content: ' *'; color: var(--danger-500); }

.input, .select, .textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 13.5px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input:hover, .select:hover, .textarea:hover { border-color: var(--text-faint); }
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--brand-400);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.16);
}
.input::placeholder, .textarea::placeholder { color: var(--text-faint); }
.textarea { resize: vertical; min-height: 96px; line-height: 1.6; }

.select {
  appearance: none;
  padding-right: 32px;
  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='%238a93ad' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}

.input-group { display: flex; align-items: stretch; }
.input-group .input { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.input-group .btn { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }

.search {
  position: relative;
  flex: 1 1 240px;
  min-width: 180px;
}
.search .input { padding-left: 34px; }
.search .ico { position: absolute; left: 11px; top: 50%; translate: 0 -50%; color: var(--text-faint); pointer-events: none; }

.check { display: flex; align-items: flex-start; gap: 9px; cursor: pointer; padding: 3px 0; }
.check input { width: 16px; height: 16px; margin: 2px 0 0; accent-color: var(--brand-500); cursor: pointer; flex: 0 0 16px; }
.check__text { font-size: 13.5px; }
.check__text small { display: block; color: var(--text-muted); font-size: 12px; }

.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch__track { width: 38px; height: 21px; border-radius: 20px; background: var(--border-strong); position: relative; transition: background 0.2s; flex: 0 0 38px; }
.switch__track::after { content: ''; position: absolute; top: 2px; left: 2px; width: 17px; height: 17px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-xs); transition: transform 0.2s var(--ease); }
.switch input:checked + .switch__track { background: var(--brand-500); }
.switch input:checked + .switch__track::after { transform: translateX(17px); }

.filters {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
  padding: 13px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: var(--radius) var(--radius) 0 0;
}
.filters .select, .filters .input { width: auto; min-width: 140px; }

/* dropzone */
.dropzone {
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 32px 24px;
  text-align: center;
  background: var(--surface-2);
  cursor: pointer;
  transition: 0.18s var(--ease);
}
.dropzone:hover, .dropzone.is-over { border-color: var(--brand-400); background: color-mix(in srgb, var(--brand-500) 5%, var(--surface-2)); }
.dropzone__icon { width: 46px; height: 46px; margin: 0 auto 12px; display: grid; place-items: center; border-radius: 14px; background: var(--surface-3); color: var(--brand-500); }
.dropzone input[type='file'] { display: none; }

/* --------------------------------------------------------------- misc -- */

.alert {
  display: flex; gap: 11px; align-items: flex-start;
  padding: 12px 15px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 13px;
  margin-bottom: 16px;
}
.alert__body { flex: 1 1 auto; }
.alert strong { display: block; margin-bottom: 2px; }
.alert--info { background: var(--info-050); border-color: color-mix(in srgb, var(--info-500) 26%, transparent); color: var(--info-500); }
.alert--success { background: var(--success-050); border-color: color-mix(in srgb, var(--success-500) 26%, transparent); color: var(--success-500); }
.alert--warning { background: var(--warning-050); border-color: color-mix(in srgb, var(--warning-500) 30%, transparent); color: #b45309; }
.alert--danger { background: var(--danger-050); border-color: color-mix(in srgb, var(--danger-500) 26%, transparent); color: var(--danger-500); }
html[data-theme='dark'] .alert--warning { color: var(--warning-500); }
.alert .alert__body { color: var(--text); }
.alert--info .alert__body strong { color: var(--info-500); }
.alert--warning .alert__body strong { color: var(--warning-500); }
.alert--danger .alert__body strong { color: var(--danger-500); }
.alert--success .alert__body strong { color: var(--success-500); }

.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 90; display: flex; flex-direction: column; gap: 9px; max-width: 380px; }
.toast {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 15px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--brand-500);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  animation: toast-in 0.3s var(--ease);
}
.toast--success { border-left-color: var(--success-500); }
.toast--danger { border-left-color: var(--danger-500); }
.toast--warning { border-left-color: var(--warning-500); }
@keyframes toast-in { from { opacity: 0; transform: translateX(24px); } to { opacity: 1; transform: none; } }

.modal-backdrop {
  position: fixed; inset: 0; z-index: 80;
  background: rgba(10, 14, 24, 0.55);
  backdrop-filter: blur(3px);
  display: grid; place-items: center;
  padding: 24px;
  animation: fade-in 0.18s var(--ease);
}
.modal {
  width: min(560px, 100%);
  max-height: calc(100vh - 48px);
  overflow: auto;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  animation: modal-in 0.24s var(--ease);
}
.modal--wide { width: min(880px, 100%); }
.modal__head { display: flex; align-items: center; gap: 12px; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.modal__body { padding: 20px; }
.modal__foot { display: flex; gap: 9px; justify-content: flex-end; padding: 14px 20px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-in { from { opacity: 0; transform: translateY(14px) scale(0.98); } to { opacity: 1; transform: none; } }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; }
.tab {
  padding: 9px 15px;
  font-size: 13.5px; font-weight: 560;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  cursor: pointer; white-space: nowrap;
  background: none; border-top: 0; border-left: 0; border-right: 0;
}
.tab:hover { color: var(--text); text-decoration: none; }
.tab.is-active { color: var(--brand-500); border-bottom-color: var(--brand-500); }

.pagination { display: flex; align-items: center; gap: 6px; justify-content: space-between; flex-wrap: wrap; }
.pagination__pages { display: flex; gap: 4px; }
.pagination a, .pagination span.page {
  min-width: 32px; height: 32px;
  display: grid; place-items: center;
  padding: 0 9px;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  font-size: 13px;
  color: var(--text-muted);
  background: var(--surface);
}
.pagination a:hover { border-color: var(--brand-400); color: var(--brand-500); text-decoration: none; }
.pagination .is-active { background: var(--brand-500); border-color: var(--brand-500); color: #fff; font-weight: 620; }
.pagination .is-disabled { opacity: 0.4; pointer-events: none; }

.chart-box { position: relative; height: 280px; }
.chart-box--sm { height: 200px; }
.chart-box--lg { height: 340px; }

.timeline { position: relative; padding-left: 22px; }
.timeline::before { content: ''; position: absolute; left: 5px; top: 5px; bottom: 5px; width: 2px; background: var(--border); }
.timeline__item { position: relative; padding-bottom: 16px; }
.timeline__item::before { content: ''; position: absolute; left: -21px; top: 5px; width: 10px; height: 10px; border-radius: 50%; background: var(--brand-500); box-shadow: 0 0 0 3px var(--surface); }
.timeline__item:last-child { padding-bottom: 0; }

.kv { display: grid; grid-template-columns: minmax(120px, 34%) 1fr; gap: 9px 14px; font-size: 13.5px; }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; font-weight: 550; }

.sms-preview {
  max-width: 300px;
  padding: 13px 15px;
  border-radius: 16px 16px 16px 4px;
  background: linear-gradient(135deg, #e7eaf6, #f2f4fc);
  color: #101828;
  font-size: 13.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  box-shadow: var(--shadow-xs);
}
html[data-theme='dark'] .sms-preview { background: linear-gradient(135deg, #223052, #1b2640); color: #e8ecf7; }

.counter-bar { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--text-muted); }

.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: var(--radius-xs); }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ---------------------------------------------------------- login page -- */

.login-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--bg);
}
.login-aside {
  position: relative;
  padding: 48px;
  display: flex; flex-direction: column; justify-content: space-between;
  background: linear-gradient(150deg, #10152a 0%, #1b2447 45%, #26306b 100%);
  color: #fff;
  overflow: hidden;
}
.login-aside::before {
  content: ''; position: absolute; width: 520px; height: 520px; right: -180px; top: -160px;
  background: radial-gradient(circle, rgba(99,102,241,0.45), transparent 65%);
}
.login-aside::after {
  content: ''; position: absolute; width: 420px; height: 420px; left: -140px; bottom: -160px;
  background: radial-gradient(circle, rgba(6,182,212,0.32), transparent 65%);
}
.login-aside > * { position: relative; z-index: 1; }
.login-aside h2 { font-size: 30px; line-height: 1.25; margin-bottom: 14px; }
.login-aside p { color: rgba(255,255,255,0.75); max-width: 44ch; }
.login-points { list-style: none; padding: 0; margin: 26px 0 0; display: flex; flex-direction: column; gap: 13px; }
.login-points li { display: flex; gap: 11px; align-items: flex-start; color: rgba(255,255,255,0.86); font-size: 14px; }
.login-points .ico { color: var(--accent-500); flex: 0 0 20px; margin-top: 1px; }

.login-main { display: grid; place-items: center; padding: 40px; }
.login-card { width: min(390px, 100%); }
.login-card__logo { width: 46px; height: 46px; border-radius: 13px; display: grid; place-items: center; background: linear-gradient(135deg, var(--brand-400), var(--accent-500)); color: #fff; margin-bottom: 20px; box-shadow: 0 8px 20px -6px rgba(99,102,241,0.6); }

/* --------------------------------------------------------- responsive -- */

@media (max-width: 1240px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2-1, .grid-1-2 { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 1024px) {
  .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  .sidebar.is-open { transform: none; }
  .main { margin-left: 0; }
  .sidebar-toggle { display: grid; }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .login-shell { grid-template-columns: 1fr; }
  .login-aside { display: none; }
}

@media (max-width: 720px) {
  .page { padding: 18px 16px 40px; }
  .topbar { padding: 0 16px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: minmax(0, 1fr); }
  .user-chip__name { display: none; }
  h1 { font-size: 19px; }
}

.nav-scrim { display: none; }
@media (max-width: 1024px) {
  .nav-scrim.is-open { display: block; position: fixed; inset: 0; z-index: 35; background: rgba(10,14,24,0.5); }
}


/* --- Barra di avanzamento (analisi elenchi) ------------------------------ */
.progress {
  height: 8px;
  border-radius: 999px;
  background: var(--surface-2, rgba(127,127,127,.15));
  overflow: hidden;
}
.progress__bar {
  height: 100%;
  border-radius: 999px;
  background: var(--brand, #6366f1);
  transition: width .4s ease;
}
.progress--success .progress__bar { background: #10b981; }
.progress--danger .progress__bar { background: #f43f5e; }

/* Pastiglia del punteggio di idoneita 0-100 */
.score {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 38px;
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  font-size: 12.5px;
}
.score--high { background: rgba(16,185,129,.16); color: #0b7a5b; }
.score--mid  { background: rgba(245,158,11,.18); color: #8a5a06; }
.score--low  { background: rgba(244,63,94,.15); color: #a1213a; }
.score--none { background: rgba(127,127,127,.15); color: var(--text-muted); }

[data-theme="dark"] .score--high { color: #4ade9f; }
[data-theme="dark"] .score--mid  { color: #fbbf24; }
[data-theme="dark"] .score--low  { color: #fb7185; }

@media print {
  .sidebar, .topbar, .btn, .filters { display: none !important; }
  .main { margin-left: 0; }
  .card { box-shadow: none; border-color: #ddd; }
}
