/* ═══════════════════════════════════════════════════════════════
   nexergia Design System v3
   Monochrome premium UI · light sidebar · targeted tenant accent
   Tenant theming: override --primary / --secondary on :root
   ═══════════════════════════════════════════════════════════════ */
:root {
  --primary: #11807C;
  --secondary: #3FB6A8;

  /* Derived automatically from the (possibly tenant-overridden) primary */
  --primary-dark: color-mix(in srgb, var(--primary) 82%, black);
  --primary-light: color-mix(in srgb, var(--primary) 9%, white);
  --primary-soft: color-mix(in srgb, var(--primary) 16%, white);
  --primary-glow: color-mix(in srgb, var(--primary) 22%, transparent);

  --gradient-brand: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
  --gradient-brand-soft: linear-gradient(135deg, color-mix(in srgb, var(--primary) 12%, white), color-mix(in srgb, var(--secondary) 12%, white));

  --accent: #10b981;
  --accent-amber: #E8A33D;
  --danger: #ef4444;
  --warning: #f59e0b;
  --success: #10b981;
  --info: #0ea5e9;

  /* Neutral, monochrome-leaning surface scale (no blue tint) */
  --ink: #16171c;
  --bg: #f7f7f8;
  --surface: #ffffff;
  --surface-2: #f4f4f5;
  --surface-3: #ececee;
  --border: #e8e8ea;
  --border-strong: #d8d8dc;
  --border-focus: var(--primary);

  /* Light sidebar palette (tenant accent shows only in targeted spots) */
  --sidebar-bg: var(--surface);
  --sidebar-text: #6b6c76;
  --sidebar-text-hover: #101114;
  --sidebar-border: var(--border);

  --text-primary: #101114;
  --text-secondary: #55575f;
  --text-muted: #97989f;
  --text-on-primary: #ffffff;

  --sidebar-width: 264px;
  --topbar-height: 64px;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 22px;
  --radius-full: 9999px;

  --shadow-xs: 0 1px 2px 0 rgb(20 20 24 / .04);
  --shadow-sm: 0 1px 3px 0 rgb(20 20 24 / .06), 0 1px 2px -1px rgb(20 20 24 / .05);
  --shadow-md: 0 8px 20px -6px rgb(20 20 24 / .08), 0 2px 6px -2px rgb(20 20 24 / .05);
  --shadow-lg: 0 16px 36px -10px rgb(20 20 24 / .12), 0 4px 10px -4px rgb(20 20 24 / .06);
  --shadow-xl: 0 26px 60px -14px rgb(20 20 24 / .18), 0 8px 18px -8px rgb(20 20 24 / .08);
  --shadow-glow: 0 0 0 3px var(--primary-glow);
  --shadow-btn: 0 1px 2px 0 rgb(20 20 24 / .08);

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-display: 'Plus Jakarta Sans', 'Inter', -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

  --transition: 160ms cubic-bezier(.4, 0, .2, 1);
  --transition-slow: 320ms cubic-bezier(.4, 0, .2, 1);
  --spring: 400ms cubic-bezier(.34, 1.4, .44, 1);
}

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

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: var(--font-sans);
  color: var(--text-primary);
  background: var(--bg);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--primary); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--primary-dark); }

img { max-width: 100%; display: block; }
button, input, select, textarea { font-family: inherit; }

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

/* ─── Typography ─────────────────────────────────────────────── */
h1, h2 { font-family: var(--font-display); }
h1 { font-size: 2rem; font-weight: 800; line-height: 1.15; letter-spacing: -0.03em; }
h2 { font-size: 1.5rem; font-weight: 700; line-height: 1.25; letter-spacing: -0.02em; }
h3 { font-size: 1.125rem; font-weight: 700; line-height: 1.4; letter-spacing: -0.01em; }
h4 { font-size: 1rem; font-weight: 600; }
p { color: var(--text-secondary); }

.text-xs { font-size: .75rem; }
.text-sm { font-size: .875rem; }
.text-base { font-size: 1rem; }
.text-lg { font-size: 1.125rem; }
.text-xl { font-size: 1.25rem; }
.text-2xl { font-size: 1.5rem; }
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }

.text-gradient {
  background: var(--gradient-brand);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* ─── Layout ─────────────────────────────────────────────────── */
.app-layout { display: flex; min-height: 100vh; }

/* ─── Sidebar (light, monochrome) ─────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform var(--transition-slow);
}

.sidebar-logo {
  padding: 20px 18px;
  border-bottom: 1px solid var(--sidebar-border);
  display: flex;
  align-items: center;
  gap: 12px;
  position: relative;
  z-index: 1;
}

.sidebar-logo .logo-chip {
  width: 42px; height: 42px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}
.sidebar-logo .logo-chip img { max-height: 30px; width: auto; object-fit: contain; }
.sidebar-logo img.logo-plain { height: 34px; width: auto; object-fit: contain; }
.sidebar-logo .logo-text { font-weight: 700; font-size: .95rem; color: var(--text-primary); letter-spacing: -.01em; }
.sidebar-logo .logo-sub { font-size: .65rem; color: var(--text-muted); margin-top: 1px; }

.sidebar-nav { flex: 1; padding: 14px 12px; overflow-y: auto; position: relative; z-index: 1; }

.nav-section-label {
  font-size: .62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--text-muted);
  padding: 18px 10px 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  color: var(--sidebar-text);
  font-size: .875rem;
  font-weight: 500;
  transition: all var(--transition);
  margin-bottom: 2px;
  cursor: pointer;
  position: relative;
}

.nav-item:hover { background: var(--surface-2); color: var(--sidebar-text-hover); }

.nav-item.active {
  background: var(--primary-dark);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 4px 12px -4px color-mix(in srgb, var(--primary) 55%, transparent);
}

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

/* Un punto accanto alla voce dove sta il prossimo passo: si nota con la coda
   dell'occhio e non chiede niente. Il respiro lento lo distingue da un badge
   di notifica senza diventare un lampeggio. */
.nav-item .nav-next-dot {
  margin-left: auto;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 22%, transparent);
  animation: navNextBreathe 2.6s ease-in-out infinite;
}
.nav-item.active .nav-next-dot { background: #fff; box-shadow: 0 0 0 3px rgba(255,255,255,.28); }
@keyframes navNextBreathe {
  0%, 100% { opacity: 1; }
  50% { opacity: .45; }
}
@media (prefers-reduced-motion: reduce) { .nav-item .nav-next-dot { animation: none; } }
.nav-item .badge {
  margin-left: auto;
  background: var(--danger);
  color: #fff;
  font-size: .65rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: var(--radius-full);
}

.sidebar-plan-card {
  margin: 18px 8px 0;
  padding: 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}
.sidebar-plan-card .plan-eyebrow {
  font-size: .62rem; font-weight: 800; text-transform: uppercase;
  letter-spacing: .1em; color: var(--text-muted);
  margin-bottom: 4px;
}
.sidebar-plan-card .plan-name { font-size: .95rem; font-weight: 800; color: var(--text-primary); }
.sidebar-plan-card .plan-note { font-size: .7rem; color: var(--text-muted); margin-top: 2px; }

.sidebar-footer {
  padding: 14px 12px;
  border-top: 1px solid var(--sidebar-border);
  position: relative; z-index: 1;
}

.user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: var(--radius-md);
  transition: background var(--transition);
  cursor: pointer;
}
.user-card:hover { background: var(--surface-2); }
.user-avatar {
  width: 38px; height: 38px;
  border-radius: var(--radius-full);
  background: var(--primary-dark);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: .875rem; flex-shrink: 0;
}
.user-info { flex: 1; min-width: 0; }
.user-name { font-size: .85rem; font-weight: 600; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: .7rem; color: var(--text-muted); }
.user-card svg { color: var(--text-muted); flex-shrink: 0; }

.user-menu {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-top: 8px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.user-menu a {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px;
  font-size: .8rem;
  color: var(--text-secondary);
  transition: all var(--transition);
}
.user-menu a:hover { background: var(--surface-2); color: var(--text-primary); }
.user-menu a.danger { color: #dc2626; }
.user-menu a.danger:hover { background: #fef2f2; color: #b91c1c; }

/* ─── Main content & Topbar ──────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  /* Senza questo un flex item non scende sotto la larghezza del suo contenuto:
     una tabella larga (o un blocco di codice) allargava tutta la pagina invece
     di scrollare dentro il proprio .table-wrapper. */
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  height: var(--topbar-height);
  background: rgb(255 255 255 / .82);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 32px;
  gap: 16px;
  position: sticky; top: 0; z-index: 50;
}

.topbar-title { font-weight: 700; font-size: 1rem; color: var(--text-primary); letter-spacing: -.01em; }
.topbar-spacer { flex: 1; }
.topbar-divider { width: 1px; height: 24px; background: var(--border); }

.tenant-pill {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  font-size: .8rem; color: var(--text-secondary); font-weight: 500;
}
.tenant-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 3px color-mix(in srgb, var(--success) 20%, transparent); }

.page-content { padding: 32px; flex: 1; max-width: 1320px; width: 100%; }

/* ─── Language Switcher ──────────────────────────────────────── */
.lang-switch { position: relative; }
.lang-switch summary {
  list-style: none;
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 12px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: .8rem; font-weight: 600; color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
  user-select: none;
}
.lang-switch summary::-webkit-details-marker { display: none; }
.lang-switch summary:hover { border-color: var(--border-strong); box-shadow: var(--shadow-sm); color: var(--text-primary); }
.lang-switch .chev { transition: transform var(--transition); }
.lang-switch[open] .chev { transform: rotate(180deg); }

.lang-menu {
  position: absolute;
  right: 0; top: calc(100% + 8px);
  min-width: 170px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  z-index: 300;
  animation: popIn .18s var(--spring);
}
.lang-menu a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  font-size: .85rem; font-weight: 500;
  color: var(--text-secondary);
  transition: all var(--transition);
}
.lang-menu a:hover { background: var(--surface-2); color: var(--text-primary); }
.lang-menu a.active { background: var(--primary-light); color: var(--primary); font-weight: 700; }
.lang-menu a .check { margin-left: auto; }

/* dark-context variant (auth hero) */
.lang-switch.on-dark summary {
  background: rgb(255 255 255 / .12);
  border-color: rgb(255 255 255 / .22);
  color: #fff;
  backdrop-filter: blur(6px);
}
.lang-switch.on-dark summary:hover { background: rgb(255 255 255 / .2); }

/* ─── Cards ──────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-xs);
  transition: box-shadow var(--transition), border-color var(--transition);
}
.card:hover { box-shadow: var(--shadow-sm); }

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.card-title { font-size: 1rem; font-weight: 700; color: var(--text-primary); letter-spacing: -.01em; }
.card-subtitle { font-size: .8rem; color: var(--text-muted); margin-top: 2px; }

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  display: flex;
  align-items: flex-start;
  gap: 16px;
  position: relative;
  overflow: hidden;
  transition: box-shadow var(--transition), transform var(--transition), border-color var(--transition);
}
.stat-card::before {
  content: '';
  position: absolute; inset: 0 0 auto 0; height: 3px;
  background: var(--gradient-brand);
  opacity: 0;
  transition: opacity var(--transition);
}
.stat-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); border-color: var(--border-strong); }
.stat-card:hover::before { opacity: 1; }

.stat-icon {
  width: 48px; height: 48px;
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  background: var(--surface-2);
  color: var(--text-secondary);
}
.stat-icon svg { width: 22px; height: 22px; }

.stat-icon.tint-primary { background: var(--primary-light); color: var(--primary); }
.stat-icon.tint-green   { background: #e7f8f1; color: #059669; }
.stat-icon.tint-amber   { background: #fdf3e0; color: #d97706; }
.stat-icon.tint-violet  { background: #f2ecfe; color: #7c3aed; }
.stat-icon.tint-sky     { background: #e6f5fd; color: #0284c7; }
.stat-icon.tint-rose    { background: #fdecef; color: #e11d48; }

.stat-value { font-size: 1.8rem; font-weight: 800; color: var(--text-primary); line-height: 1.1; font-family: var(--font-display); letter-spacing: -.02em; }
.stat-label { font-size: .8rem; color: var(--text-muted); margin-top: 4px; font-weight: 500; }
.stat-change {
  display: inline-flex; align-items: center;
  font-size: .72rem; font-weight: 700;
  margin-top: 6px;
  padding: 2px 8px;
  border-radius: var(--radius-full);
}
.stat-change.up { color: #0d7a55; background: #e3f7ef; }
.stat-change.down { color: #d92d2d; background: #fdebeb; }

/* ─── Buttons ────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 18px;
  border-radius: var(--radius-md);
  font-size: .875rem; font-weight: 600;
  border: none; cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
  white-space: nowrap;
  position: relative;
}

.btn:active { transform: translateY(1px) scale(.99); }
.btn:focus-visible { outline: none; box-shadow: var(--shadow-glow); }

/* Monochrome primary CTA tenant accent surfaces on hover/focus only */
.btn-primary,
.btn-gradient {
  background: var(--ink);
  color: #fff;
  box-shadow: var(--shadow-btn);
}
.btn-primary:hover,
.btn-gradient:hover {
  background: #000;
  color: #fff;
  transform: translateY(-1px);
  box-shadow: 0 10px 22px -6px var(--primary-glow);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text-primary);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
}
.btn-secondary:hover { background: var(--surface-2); border-color: var(--border-strong); color: var(--text-primary); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; color: #fff; }

.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text-primary); }

.btn-sm { padding: 6px 12px; font-size: .8rem; border-radius: var(--radius-sm); }
.btn-lg { padding: 13px 28px; font-size: 1rem; border-radius: var(--radius-md); }
.btn-icon { padding: 8px; }

/* ─── Forms ──────────────────────────────────────────────────── */
.form-group { margin-bottom: 20px; }
.form-label {
  display: block;
  font-size: .85rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
}
.form-label .required { color: var(--danger); margin-left: 2px; }

.form-control {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  font-size: .875rem;
  color: var(--text-primary);
  background: var(--surface);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}
.form-control:hover { border-color: var(--border-strong); }
.form-control:focus {
  border-color: var(--primary);
  box-shadow: var(--shadow-glow);
}
.form-control::placeholder { color: var(--text-muted); }
.form-control.error { border-color: var(--danger); }

.form-hint { font-size: .75rem; color: var(--text-muted); margin-top: 5px; }
.form-error { font-size: .75rem; color: var(--danger); margin-top: 5px; font-weight: 500; }

.input-group { position: relative; }
.input-group .input-prefix {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  color: var(--text-muted); font-size: .875rem; pointer-events: none;
}
.input-group .form-control { padding-left: 36px; }

.color-input-group { display: flex; align-items: center; gap: 10px; }
.color-input-group input[type="color"] {
  width: 44px; height: 38px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: 3px;
  cursor: pointer;
  background: var(--surface);
}
.color-input-group input[type="text"] { flex: 1; }

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

table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}

thead th {
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: .68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
tbody td { padding: 14px 16px; color: var(--text-primary); vertical-align: middle; }

/* ─── Badges ─────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .02em;
}

.badge-green  { background: #e3f7ef; color: #0d7a55; }
.badge-red    { background: #fdebeb; color: #d92d2d; }
.badge-yellow { background: #fdf5d7; color: #97700a; }
.badge-blue   { background: var(--primary-light); color: var(--primary-dark); }
.badge-purple { background: #f2ecfe; color: #7c3aed; }
.badge-gray   { background: var(--surface-3); color: var(--text-secondary); }

.comm-channel-icon {
  width: 36px; height: 36px;
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  background: #64748b;
  box-shadow: var(--shadow-sm);
}
.comm-channel-push  { background: linear-gradient(135deg, #6366f1, #4f46e5); }
.comm-channel-email { background: linear-gradient(135deg, #38bdf8, #2563eb); }
.comm-channel-sms   { background: linear-gradient(135deg, #34d399, #059669); }

.dist-status-card  { border-left: 4px solid var(--border); }
.dist-status-active { border-left-color: var(--success); }
.dist-store-card   { border-left: 4px solid var(--border); }
.dist-store-active { border-left-color: var(--warning); }

/* ─── Alerts / Flash ─────────────────────────────────────────── */
.alert {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  font-size: .875rem;
  margin-bottom: 16px;
  border: 1px solid transparent;
}
.alert-success { background: #f2fbf7; border-color: #c4ecd9; color: #0d7a55; }
.alert-error, .alert-danger { background: #fef4f4; border-color: #f8caca; color: #c92a2a; }
.alert-warning { background: #fffaf0; border-color: #fbe3ac; color: #92580e; }
.alert-info { background: var(--primary-light); border-color: color-mix(in srgb, var(--primary) 25%, white); color: var(--primary-dark); }

/* ─── Dropzone ───────────────────────────────────────────────── */
.dropzone {
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 40px 24px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  background: var(--surface);
  position: relative;
}
.dropzone:hover, .dropzone.drag-over {
  border-color: var(--primary);
  background: var(--primary-light);
  box-shadow: inset 0 0 0 1px var(--primary-glow);
}
.dropzone input[type="file"] {
  position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%;
}
.dropzone-icon { width: 48px; height: 48px; margin: 0 auto 12px; opacity: .45; }
.dropzone p { font-size: .875rem; color: var(--text-muted); }
.dropzone strong { color: var(--primary); }

/* ─── Progress ───────────────────────────────────────────────── */
.progress-bar-wrap {
  height: 6px;
  background: var(--surface-3);
  border-radius: var(--radius-full);
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  background: var(--gradient-brand);
  border-radius: var(--radius-full);
  transition: width var(--transition-slow);
}

/* ─── Onboarding ─────────────────────────────────────────────── */
.onboarding-layout {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.onboarding-header {
  background: rgb(255 255 255 / .8);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  padding: 0 40px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky; top: 0; z-index: 50;
}

.onboarding-header .logo { display: flex; align-items: center; gap: 12px; }
.onboarding-header .logo img { height: 32px; }

.step-progress { display: flex; align-items: center; gap: 0; }
.step-item { display: flex; align-items: center; gap: 8px; }

.step-dot {
  width: 34px; height: 34px;
  border-radius: var(--radius-full);
  display: flex; align-items: center; justify-content: center;
  font-size: .8rem; font-weight: 700;
  transition: all var(--spring);
}

.step-dot.completed { background: var(--success); color: #fff; box-shadow: 0 3px 10px -2px color-mix(in srgb, var(--success) 55%, transparent); }
.step-dot.active {
  background: var(--gradient-brand);
  color: #fff;
  box-shadow: 0 0 0 5px var(--primary-glow);
  transform: scale(1.08);
}
.step-dot.pending {
  background: var(--surface-2);
  color: var(--text-muted);
  border: 2px solid var(--border);
}

.step-label { font-size: .75rem; font-weight: 600; color: var(--text-muted); }
.step-label.active { color: var(--primary); }
.step-label.completed { color: var(--text-secondary); }

.step-connector { width: 40px; height: 2px; background: var(--border); margin: 0 4px; border-radius: 2px; }
.step-connector.completed { background: var(--success); }

.onboarding-body {
  flex: 1;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 48px 24px;
}

.onboarding-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 48px;
  width: 100%;
  max-width: 680px;
  box-shadow: var(--shadow-xl);
  animation: slideUp .45s cubic-bezier(.16, 1, .3, 1);
}

.onboarding-card.wide { max-width: 900px; }

.step-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--gradient-brand-soft);
  color: var(--primary);
  font-size: .7rem;
  font-weight: 800;
  padding: 5px 12px;
  border-radius: var(--radius-full);
  letter-spacing: .05em;
  text-transform: uppercase;
  margin-bottom: 16px;
}

.step-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 40px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

/* ─── Plan Cards ─────────────────────────────────────────────── */
.plan-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin: 24px 0;
}

.plan-card {
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
  background: var(--surface);
}

.plan-card:hover {
  border-color: color-mix(in srgb, var(--primary) 45%, var(--border));
  box-shadow: var(--shadow-md);
  transform: translateY(-3px);
}

.plan-card.selected {
  border-color: var(--primary);
  background: linear-gradient(180deg, var(--primary-light), var(--surface) 70%);
  box-shadow: 0 0 0 3px var(--primary-glow), var(--shadow-md);
}

.plan-card .plan-badge {
  position: absolute;
  top: -11px; left: 50%; transform: translateX(-50%);
  background: var(--gradient-brand);
  color: #fff;
  font-size: .65rem; font-weight: 800;
  padding: 4px 12px;
  border-radius: var(--radius-full);
  white-space: nowrap;
  letter-spacing: .04em;
  box-shadow: var(--shadow-sm);
}

/* Plan/product card shown but not yet selectable ("coming soon") */
.plan-card.disabled {
  cursor: not-allowed;
  background: var(--surface-2);
  color: var(--text-muted);
}
.plan-card.disabled:hover { border-color: var(--border); box-shadow: none; transform: none; }
.plan-card.disabled .plan-badge { background: var(--surface-3); color: var(--text-muted); box-shadow: none; }

.plan-price {
  font-size: 2.1rem; font-weight: 800; color: var(--text-primary); line-height: 1;
  font-family: var(--font-display); letter-spacing: -.02em;
}
.plan-price sup { font-size: 1rem; vertical-align: top; margin-top: 6px; font-weight: 700; }
.plan-price-note { font-size: .75rem; color: var(--text-muted); }

.plan-features { margin-top: 16px; list-style: none; }
.plan-features li {
  display: flex; align-items: center; gap: 8px;
  font-size: .875rem; color: var(--text-secondary);
  padding: 5px 0;
}
.plan-features li svg { color: var(--success); flex-shrink: 0; width: 16px; height: 16px; }
.plan-features li.disabled { opacity: .4; }
.plan-features li.disabled svg { color: var(--text-muted); }

/* ─── Branding Preview ───────────────────────────────────────── */
.brand-preview {
  background: var(--preview-primary, var(--primary));
  border-radius: var(--radius-lg);
  padding: 24px;
  color: #fff;
  text-align: center;
  min-height: 180px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  transition: all var(--transition-slow);
  box-shadow: var(--shadow-md);
}

.brand-preview img { height: 48px; width: auto; object-fit: contain; }
.brand-preview h2 { font-size: 1.25rem; font-weight: 700; color: #fff; }
.brand-preview p { font-size: .875rem; opacity: .85; color: #fff; }

/* ─── File List ──────────────────────────────────────────────── */
.file-list { margin-top: 16px; display: flex; flex-direction: column; gap: 8px; }

.file-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px;
  background: var(--surface-2);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  animation: fadeIn .2s ease;
}

.file-item-icon { width: 36px; height: 36px; border-radius: var(--radius-sm); background: var(--primary-light); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.file-item-icon svg { color: var(--primary); width: 18px; height: 18px; }
.file-item-name { flex: 1; font-size: .875rem; font-weight: 500; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-item-size { font-size: .75rem; color: var(--text-muted); }
.file-item-status { flex-shrink: 0; }

/* ─── Modals ─────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgb(16 17 20 / .5);
  backdrop-filter: blur(5px);
  z-index: 200;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  opacity: 0; pointer-events: none;
  transition: opacity var(--transition);
}
.modal-backdrop.open { opacity: 1; pointer-events: all; }

.modal {
  background: var(--surface);
  border-radius: var(--radius-xl);
  padding: 32px;
  width: 100%; max-width: 520px;
  box-shadow: var(--shadow-xl);
  transform: translateY(12px) scale(.97);
  transition: transform var(--spring);
}
.modal-backdrop.open .modal { transform: translateY(0) scale(1); }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.modal-title { font-size: 1.125rem; font-weight: 700; }
.modal-close { background: none; border: none; cursor: pointer; color: var(--text-muted); padding: 4px; border-radius: var(--radius-sm); transition: all var(--transition); }
.modal-close:hover { background: var(--surface-2); color: var(--text-primary); }
.modal-footer { display: flex; gap: 12px; justify-content: flex-end; margin-top: 28px; }

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

.auth-hero {
  background:
    radial-gradient(900px 600px at 110% -10%, color-mix(in srgb, var(--secondary) 55%, transparent), transparent 60%),
    radial-gradient(700px 500px at -20% 110%, color-mix(in srgb, #E8A33D 25%, transparent), transparent 55%),
    linear-gradient(150deg, #0C3B3C 0%, #0F5352 55%, #11807C 100%);
  padding: 60px;
  display: flex; flex-direction: column; justify-content: space-between;
  color: #fff;
  position: relative;
  overflow: hidden;
}

.auth-hero::before {
  content: '';
  position: absolute;
  top: -120px; right: -120px;
  width: 440px; height: 440px;
  background: radial-gradient(closest-side, rgb(255 255 255 / .09), transparent);
  border-radius: var(--radius-full);
}

.auth-hero::after {
  content: '';
  position: absolute;
  bottom: -100px; left: -100px;
  width: 360px; height: 360px;
  background: radial-gradient(closest-side, rgb(255 255 255 / .07), transparent);
  border-radius: var(--radius-full);
}

.auth-hero-content { position: relative; z-index: 1; }
.auth-hero-logo { display: flex; align-items: center; gap: 14px; margin-bottom: 48px; }
.auth-hero h1 {
  font-size: 2.7rem; margin-bottom: 18px; line-height: 1.08; color: #fff;
  letter-spacing: -.035em;
}
.auth-hero h1 .hl {
  background: linear-gradient(90deg, #7DD9C9, #DCEAE7);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.auth-hero p { font-size: 1.05rem; opacity: .82; max-width: 400px; color: #fff; line-height: 1.65; }

.auth-feature-list { margin-top: 44px; display: flex; flex-direction: column; gap: 12px; }
.auth-feature {
  display: flex; align-items: center; gap: 13px;
  font-size: .9rem;
  padding: 11px 14px;
  background: rgb(255 255 255 / .06);
  border: 1px solid rgb(255 255 255 / .1);
  border-radius: var(--radius-md);
  backdrop-filter: blur(8px);
  transition: all var(--transition);
}
.auth-feature:hover { background: rgb(255 255 255 / .11); transform: translateX(4px); }
.auth-feature-icon {
  width: 34px; height: 34px;
  background: linear-gradient(135deg, rgb(255 255 255 / .22), rgb(255 255 255 / .08));
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.auth-hero-footer { position: relative; z-index: 1; font-size: .8rem; opacity: .55; }

/* Vetrina prodotti nell'hero auth: un blocco per prodotto (app clientela,
   tariffa dinamica) invece della lista piatta di feature, che raccontava
   solo l'app. Stessa materia di .auth-feature — vetro sul gradiente. */
.auth-product-list { margin-top: 40px; display: flex; flex-direction: column; gap: 14px; }
.auth-product {
  padding: 16px 18px;
  background: rgb(255 255 255 / .06);
  border: 1px solid rgb(255 255 255 / .1);
  border-radius: var(--radius-md);
  backdrop-filter: blur(8px);
  transition: all var(--transition);
}
.auth-product:hover { background: rgb(255 255 255 / .11); transform: translateX(4px); }
.auth-product-head { display: flex; align-items: center; gap: 12px; margin-bottom: 9px; }
.auth-product-head .auth-feature-icon { width: 32px; height: 32px; }
.auth-product-name { font-weight: 700; font-size: .95rem; letter-spacing: -.01em; }
/* max-width e font-size vengono da .auth-hero p: qui la colonna e' la scheda */
.auth-hero .auth-product-desc {
  font-size: .82rem; line-height: 1.5; opacity: .72;
  max-width: none; margin: 0 0 11px;
}
.auth-product ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 7px; }
.auth-product li {
  display: flex; align-items: flex-start; gap: 9px;
  font-size: .8rem; line-height: 1.45; opacity: .88;
}
.auth-product li svg { flex-shrink: 0; margin-top: 3px; opacity: .85; }

/* Versione compatta della vetrina: sulla registrazione i tre passi occupano
   gia' la colonna, quindi i prodotti si annunciano con due pillole. */
.auth-chips { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 26px; }
.auth-chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 7px 13px 7px 9px;
  font-size: .8rem; font-weight: 600;
  background: rgb(255 255 255 / .09);
  border: 1px solid rgb(255 255 255 / .14);
  border-radius: var(--radius-full);
}
.auth-chip svg { flex-shrink: 0; opacity: .9; }

/* Con due prodotti al posto della lista di feature l'hero e' cresciuto: sotto
   i ~900px di altezza (1280x720 e simili) la seconda scheda finiva tagliata.
   Si stringe la spaziatura invece di togliere contenuto — i prodotti a
   catalogo sono il messaggio della pagina. */
@media (max-height: 900px) {
  .auth-hero { padding: 36px 48px; }
  .auth-hero-logo { margin-bottom: 24px; }
  .auth-hero h1 { font-size: 2.15rem; margin-bottom: 12px; }
  .auth-hero p { font-size: .95rem; }
  .auth-product-list { margin-top: 24px; gap: 11px; }
  .auth-product { padding: 13px 16px; }
  .auth-hero .auth-product-desc { margin-bottom: 9px; }
  .auth-chips { margin-top: 20px; }
}



.auth-panel {
  display: flex; align-items: center; justify-content: center;
  padding: 60px 80px;
  background: var(--surface);
  position: relative;
}

.auth-panel .lang-corner { position: absolute; top: 24px; right: 28px; }

.auth-form-wrap { width: 100%; max-width: 400px; animation: slideUp .5s cubic-bezier(.16,1,.3,1); }
.auth-logo { display: flex; align-items: center; gap: 12px; margin-bottom: 40px; }
.auth-logo img { height: 36px; }

.auth-divider {
  display: flex; align-items: center; gap: 12px; margin: 24px 0;
  color: var(--text-muted); font-size: .8rem;
}
.auth-divider::before, .auth-divider::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}

.trial-note {
  margin-top: 36px; padding: 14px 16px;
  background: var(--gradient-brand-soft);
  border: 1px solid color-mix(in srgb, var(--primary) 18%, white);
  border-radius: var(--radius-md);
  text-align: center;
}
.trial-note p { font-size: .78rem; color: var(--primary-dark); font-weight: 600; }

/* ─── Animations ─────────────────────────────────────────────── */
@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes popIn {
  from { opacity: 0; transform: translateY(-6px) scale(.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .6s linear infinite;
  display: inline-block;
}

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

/* ─── Utilities ──────────────────────────────────────────────── */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.justify-between { justify-content: space-between; }
.justify-end { justify-content: flex-end; }
.justify-center { justify-content: center; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.gap-6 { gap: 24px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mt-6 { margin-top: 24px; }
.mt-8 { margin-top: 32px; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.mb-8 { margin-bottom: 32px; }
.p-0 { padding: 0 !important; }
.w-full { width: 100%; }
.hidden { display: none !important; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.divider { height: 1px; background: var(--border); margin: 24px 0; }

/* ─── Responsive ─────────────────────────────────────────────── */
@media (max-width: 1024px) {
  .plan-grid { grid-template-columns: 1fr; }
  .auth-layout { grid-template-columns: 1fr; }
  .auth-hero { display: none; }
  .auth-panel { padding: 40px 24px; }
}

@media (max-width: 768px) {
  :root { --sidebar-width: 0px; }
  .sidebar { transform: translateX(-264px); }
  .sidebar.open { transform: translateX(0); width: 264px; box-shadow: var(--shadow-xl); }
  .main-content { margin-left: 0; }
  .topbar { padding: 0 16px; }
  .page-content { padding: 20px 16px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .onboarding-card { padding: 24px; }
  .onboarding-header { padding: 0 16px; }
  .step-progress { display: none; }
}

/* ─── Scrollbar & Selection ──────────────────────────────────── */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

::selection { background: var(--primary-soft); color: var(--primary-dark); }

/* ── Guida passo-passo (js/guide.js) ──────────────────────────────────────
   Un fumetto accanto al pulsante da premere, non un wizard che sequestra la
   pagina: niente velo scuro, niente blocco dei clic. Compare solo arrivando
   dal pannello «dai dati al prezzo» e sparisce appena hai premuto. */
.guide-pop {
  position: fixed;
  z-index: 1200;
  width: 290px;
  max-width: calc(100vw - 20px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 15px 17px 14px;
  box-shadow: 0 18px 40px -12px rgba(15, 23, 42, .28), 0 2px 8px -2px rgba(15, 23, 42, .12);
  opacity: 0;
  transform: translateY(4px);
  transition: opacity .22s ease, transform .22s ease;
  pointer-events: none;
}
.guide-pop.open { opacity: 1; transform: none; pointer-events: auto; }

.guide-arrow {
  position: absolute;
  width: 11px;
  height: 11px;
  background: var(--surface);
  border: 1px solid var(--border);
  transform: rotate(45deg);
}
.guide-pop[data-side="right"] .guide-arrow { left: -6px; margin-top: -6px; border-right: 0; border-top: 0; }
.guide-pop[data-side="left"]  .guide-arrow { right: -6px; margin-top: -6px; border-left: 0; border-bottom: 0; }
.guide-pop[data-side="bottom"] .guide-arrow { top: -6px; margin-left: -6px; border-right: 0; border-bottom: 0; }
.guide-pop[data-side="top"]    .guide-arrow { bottom: -6px; margin-left: -6px; border-left: 0; border-top: 0; }

.guide-title { font-size: .875rem; font-weight: 700; padding-right: 18px; }
.guide-body { font-size: .8rem; color: var(--text-secondary); line-height: 1.55; margin-top: 5px; }
.guide-foot { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.guide-count { font-size: .72rem; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.guide-ok {
  border: 0;
  background: var(--primary-dark);
  color: #fff;
  font-size: .78rem;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: var(--radius-md);
  cursor: pointer;
}
.guide-ok:hover { opacity: .9; }
.guide-x {
  position: absolute;
  top: 8px; right: 9px;
  border: 0; background: none; cursor: pointer;
  color: var(--text-muted);
  font-size: 1.05rem;
  line-height: 1;
  padding: 2px 5px;
  border-radius: 6px;
}
.guide-x:hover { background: var(--surface-2); color: var(--text); }

/* Il pulsante indicato si illumina: un anello più un alone che respirano
   piano. Serve a trovarlo con la coda dell'occhio mentre leggi il fumetto,
   senza spegnere il resto della pagina con un velo scuro. */
.guide-target {
  position: relative;
  z-index: 1201;
  border-radius: var(--radius-md);
  animation: guideRing 1.9s ease-in-out infinite;
}
@keyframes guideRing {
  0%, 100% {
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 36%, transparent),
                0 0 18px 1px color-mix(in srgb, var(--primary) 42%, transparent);
  }
  50% {
    box-shadow: 0 0 0 8px color-mix(in srgb, var(--primary) 12%, transparent),
                0 0 30px 4px color-mix(in srgb, var(--primary) 22%, transparent);
  }
}
@media (prefers-reduced-motion: reduce) {
  .guide-target {
    animation: none;
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 36%, transparent),
                0 0 18px 1px color-mix(in srgb, var(--primary) 40%, transparent);
  }
  .guide-pop { transition: none; }
}

/* ═══════════════════════════════════════════════════════════════
   Legal · contratto di servizio + DPA
   Usato dal popup di accettazione (partials/_legal_modal.html) e
   dalla pagina pubblica /legale/contratto.
   ═══════════════════════════════════════════════════════════════ */

/* ─── Testo del documento ────────────────────────────────────── */
.legal-doc {
  position: relative;
  font-size: .875rem;
  line-height: 1.72;
  color: var(--text-secondary);
  counter-reset: legal-part;
}
.legal-doc h1 {
  font-family: var(--font-display);
  font-size: 1.6rem; line-height: 1.2; font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -.02em;
  margin-bottom: 18px;
  max-width: 24ch;
}
.legal-doc h2.legal-part {
  font-family: var(--font-display);
  font-size: 1.02rem; font-weight: 800; letter-spacing: -.01em;
  color: var(--text-primary);
  margin: 44px 0 20px;
  padding: 13px 18px;
  border-radius: var(--radius-md);
  background: var(--gradient-brand-soft);
  border: 1px solid color-mix(in srgb, var(--primary) 18%, transparent);
  scroll-margin-top: 12px;
}
.legal-doc h3 {
  font-family: var(--font-display);
  font-size: .95rem; font-weight: 700;
  color: var(--text-primary);
  margin: 30px 0 10px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  scroll-margin-top: 12px;
}
.legal-doc h2.legal-part + p,
.legal-doc h3 + p { margin-top: 0; }
.legal-doc p { margin-bottom: 11px; }
.legal-doc a { font-weight: 600; text-decoration: underline; text-underline-offset: 2px; }
.legal-doc strong { color: var(--text-primary); font-weight: 650; }

/* Numero di clausola nel margine: rientro + numero in posizione assoluta,
   NON display:grid sul paragrafo — in un grid container ogni <strong> e ogni
   spezzone di testo diventerebbe una cella a sé e la clausola si sfalderebbe. */
.legal-doc p.cl {
  position: relative;
  padding-left: 54px;
  margin-bottom: 9px;
}
.legal-doc .cl-n {
  position: absolute; left: 0; top: 2px;
  width: 46px;
  font-variant-numeric: tabular-nums;
  font-weight: 700; font-size: .78rem;
  color: var(--primary);
}

.legal-doc-head { margin-bottom: 26px; }
.legal-eyebrow {
  font-size: .68rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase;
  color: var(--primary);
  margin-bottom: 10px;
}
.legal-facts {
  display: flex; flex-wrap: wrap; gap: 8px;
  margin-top: 18px;
}
.legal-facts > div {
  flex: 1 1 140px;
  padding: 10px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.legal-facts dt { font-size: .66rem; text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted); font-weight: 700; }
.legal-facts dd { font-size: .82rem; font-weight: 650; color: var(--text-primary); margin-top: 2px; }

.legal-parties, .legal-preamble, .legal-closing {
  padding: 16px 18px;
  border-radius: var(--radius-lg);
  background: var(--surface-2);
  border: 1px solid var(--border);
  margin-bottom: 16px;
}
.legal-parties p, .legal-preamble p, .legal-closing p { margin-bottom: 8px; }
.legal-parties p:last-child, .legal-preamble p:last-child, .legal-closing p:last-child { margin-bottom: 0; }
.legal-closing { border-color: color-mix(in srgb, var(--primary) 26%, transparent); background: var(--primary-light); }
.legal-closing h3 { border-top: none; padding-top: 0; margin-top: 0; }
.legal-note { font-size: .8rem; color: var(--text-muted); }

.legal-doc ol.legal-list { margin: 6px 0 12px 20px; display: flex; flex-direction: column; gap: 7px; }
.legal-doc ol.legal-list li { padding-left: 4px; }
.legal-doc ol.legal-list li::marker { color: var(--primary); font-weight: 700; font-size: .8rem; }

.legal-table-wrap { overflow-x: auto; margin: 8px 0 14px; border: 1px solid var(--border); border-radius: var(--radius-md); }
.legal-table { width: 100%; border-collapse: collapse; font-size: .82rem; min-width: 420px; }
.legal-table th, .legal-table td { padding: 10px 14px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--border); }
.legal-table tbody th { width: 30%; font-weight: 700; color: var(--text-primary); background: var(--surface-2); }
.legal-table thead th { background: var(--surface-3); font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-secondary); }
.legal-table tr:last-child th, .legal-table tr:last-child td { border-bottom: none; }

/* ─── Popup ──────────────────────────────────────────────────── */
body.legal-modal-open { overflow: hidden; }

.legal-modal-backdrop {
  position: fixed; inset: 0;
  z-index: 400;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background: rgb(16 17 20 / .58);
  backdrop-filter: blur(6px);
  opacity: 0;
  transition: opacity var(--transition);
}
.legal-modal-backdrop.open { opacity: 1; }
.legal-modal-backdrop[hidden] { display: none; }

.legal-modal {
  display: flex; flex-direction: column;
  width: 100%; max-width: 1020px;
  max-height: min(940px, 94vh);
  background: var(--surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  overflow: hidden;
  transform: translateY(16px) scale(.975);
  opacity: .6;
  transition: transform var(--spring), opacity var(--transition);
}
.legal-modal-backdrop.open .legal-modal { transform: none; opacity: 1; }

.legal-modal-head {
  position: relative;
  padding: 17px 24px 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.legal-modal-head::before {
  content: ''; position: absolute; inset: 0 0 auto; height: 3px;
  background: var(--gradient-brand);
}
.legal-modal-head-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.legal-modal-head h2 {
  font-family: var(--font-display);
  font-size: 1.1rem; font-weight: 800; letter-spacing: -.02em;
  color: var(--text-primary);
  margin: 8px 0 2px;
}
.legal-modal-head p { font-size: .8rem; line-height: 1.45; color: var(--text-secondary); max-width: 66ch; }

.legal-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  background: var(--primary-light);
  border: 1px solid color-mix(in srgb, var(--primary) 22%, transparent);
  color: var(--primary);
  font-size: .68rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase;
}
.legal-modal-head-actions { display: flex; gap: 6px; flex-shrink: 0; }
.legal-icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  color: var(--text-muted);
  background: var(--surface);
  transition: all var(--transition);
}
.legal-icon-btn:hover { color: var(--text-primary); background: var(--surface-2); border-color: var(--border-strong); }

.legal-progress {
  height: 4px; margin-top: 12px;
  border-radius: var(--radius-full);
  background: var(--surface-3);
  overflow: hidden;
}
.legal-progress-bar {
  height: 100%; width: 0;
  border-radius: inherit;
  background: var(--gradient-brand);
  transition: width 120ms linear;
}
.legal-progress-meta {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 0 10px;
  font-size: .73rem; font-weight: 600; color: var(--text-muted);
}
.legal-progress-pct { font-variant-numeric: tabular-nums; }
.legal-modal.is-read .legal-progress-meta,
.is-read .legal-progress-meta { color: var(--success); }

.legal-modal-body {
  display: grid;
  /* minmax(0,1fr): senza il minimo a 0 la colonna del documento si allarga
     fino al min-content delle tabelle degli allegati e sfonda il popup. */
  grid-template-columns: 236px minmax(0, 1fr);
  min-height: 0; flex: 1;
}

.legal-toc {
  position: relative;
  border-right: 1px solid var(--border);
  background: var(--surface-2);
  padding: 18px 10px 18px 18px;
  overflow-y: auto;
  scrollbar-width: thin;
}
.legal-toc-title {
  font-size: .66rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.legal-toc ul { list-style: none; display: flex; flex-direction: column; gap: 1px; }
.legal-toc a {
  display: block;
  padding: 5px 9px;
  border-radius: var(--radius-sm);
  font-size: .77rem; line-height: 1.35;
  color: var(--text-secondary);
  border-left: 2px solid transparent;
  transition: all var(--transition);
}
.legal-toc a:hover { background: var(--surface); color: var(--text-primary); }
.legal-toc a.active { background: var(--surface); color: var(--primary); border-left-color: var(--primary); font-weight: 650; }
.legal-toc a.legal-toc-part { font-weight: 800; color: var(--text-primary); margin-top: 10px; font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; }

.legal-doc-wrap { position: relative; min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.legal-doc-wrap > .legal-doc {
  overflow-y: auto;
  padding: 24px 30px 40px;
  scroll-behavior: smooth;
  outline: none;
  scrollbar-width: thin;
}
.legal-doc-wrap > .legal-doc:focus-visible { box-shadow: inset 0 0 0 2px var(--primary-glow); }
.legal-doc-fade {
  position: absolute; left: 0; right: 10px; bottom: 0; height: 56px;
  pointer-events: none;
  background: linear-gradient(to top, var(--surface), transparent);
  transition: opacity var(--transition);
}
.is-read .legal-doc-fade { opacity: 0; }

.legal-doc-end {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  margin-top: 26px; padding: 13px;
  border-radius: var(--radius-md);
  border: 1px dashed var(--border-strong);
  color: var(--text-muted);
  font-size: .8rem; font-weight: 650;
}
.is-read .legal-doc-end { color: var(--success); border-color: color-mix(in srgb, var(--success) 40%, transparent); background: color-mix(in srgb, var(--success) 7%, transparent); }

.legal-jump {
  position: absolute; right: 22px; bottom: 18px;
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 14px;
  border: none; cursor: pointer;
  border-radius: var(--radius-full);
  background: var(--ink); color: #fff;
  font-size: .76rem; font-weight: 650;
  box-shadow: var(--shadow-lg);
  transition: all var(--transition), opacity var(--transition);
  animation: legalJumpIn var(--spring);
}
.legal-jump:hover { transform: translateY(-1px); }
.is-read .legal-jump { opacity: 0; pointer-events: none; transform: translateY(6px); }
@keyframes legalJumpIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.legal-translation-notice {
  display: flex; align-items: center; gap: 8px;
  margin: 14px 30px -6px;
  padding: 9px 13px;
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--warning) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--warning) 30%, transparent);
  color: var(--text-secondary);
  font-size: .78rem;
}
.legal-translation-notice svg { color: var(--warning); flex-shrink: 0; }

.legal-modal-foot {
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  padding: 13px 24px 15px;
  display: flex; flex-direction: column; gap: 11px;
}
.legal-checks { display: flex; flex-direction: column; gap: 7px; transition: opacity var(--transition); }
.legal-checks[data-locked="1"] { opacity: .5; }
.legal-checks[data-locked="0"] .legal-locked-hint { display: none; }

.legal-check { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; font-size: .78rem; line-height: 1.45; color: var(--text-secondary); }
.legal-checks[data-locked="1"] .legal-check { cursor: not-allowed; }
.legal-check input {
  width: 17px; height: 17px; flex-shrink: 0; margin-top: 1px;
  accent-color: var(--primary);
  cursor: inherit;
}
.legal-check span strong { color: var(--text-primary); font-weight: 650; }
.legal-check a { font-weight: 600; }

.legal-locked-hint {
  display: flex; align-items: center; gap: 7px;
  font-size: .73rem; font-weight: 600; color: var(--warning);
}

.legal-actions { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.legal-fingerprint { display: flex; align-items: center; gap: 7px; font-size: .72rem; color: var(--text-muted); }
.legal-fingerprint code { font-family: var(--font-mono); font-size: .72rem; }
.legal-buttons { display: flex; align-items: center; gap: 10px; margin-left: auto; }
#legalAccept:disabled { opacity: .45; cursor: not-allowed; transform: none; box-shadow: none; }

@media (max-width: 900px) {
  .legal-modal-backdrop { padding: 0; }
  .legal-modal { max-width: none; max-height: 100vh; height: 100vh; border-radius: 0; }
  .legal-modal-body { grid-template-columns: minmax(0, 1fr); }
  .legal-toc { display: none; }
  /* Sul telefono l'altezza è tutta per il testo: sottotitolo e impronta
     stanno nel documento e nella pagina pubblica, qui sono rumore. */
  .legal-modal-head > .legal-modal-head-top p { display: none; }
  .legal-check { font-size: .75rem; }
  .legal-checks { gap: 6px; }
  /* Finché il testo non è stato letto le caselle sono comunque bloccate:
     tenerle nascoste restituisce al documento l'altezza che occupano. */
  .legal-checks[data-locked="1"] .legal-check { display: none; }
  .legal-fingerprint { display: none; }
  .legal-doc-wrap > .legal-doc { padding: 20px 20px 36px; }
  .legal-translation-notice { margin: 12px 20px -4px; }
  .legal-modal-head, .legal-modal-foot { padding-left: 20px; padding-right: 20px; }
  .legal-doc p.cl { padding-left: 44px; }
  .legal-doc .cl-n { width: 40px; }
  .legal-buttons { width: 100%; }
  .legal-buttons .btn { flex: 1; }
}

/* ─── Pagina pubblica /legale/contratto ──────────────────────── */
.legal-page { max-width: 900px; margin: 0 auto; padding: 48px 24px 96px; }
.legal-page-bar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 24px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.legal-page-bar img { height: 24px; }
.legal-page-bar .legal-page-actions { display: flex; align-items: center; gap: 8px; }
.legal-page .legal-doc { font-size: .9rem; }

@media print {
  .legal-page-bar, .legal-jump, .legal-doc-fade { display: none !important; }
  .legal-page { max-width: none; padding: 0; }
  .legal-doc { font-size: 10pt; color: #000; }
  .legal-doc h2.legal-part { background: none; border: 1px solid #999; break-after: avoid; }
  .legal-doc h3 { break-after: avoid; }
  .legal-doc p.cl { break-inside: avoid; }
  .legal-table-wrap { break-inside: avoid; }
}

/* Viewport basse: ogni pixel dell'intestazione è spazio tolto al testo del
   contratto, che è la cosa che va letta. */
@media (max-height: 760px) {
  .legal-modal-head > .legal-modal-head-top p { display: none; }
  .legal-modal-head h2 { font-size: 1rem; }
  .legal-modal-foot { padding-top: 11px; padding-bottom: 13px; }
}
