:root {
  --accent-from: #4f46e5;
  --accent-to: #9333ea;
  --grad: linear-gradient(135deg, var(--accent-from), var(--accent-to));
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --bg: #f6f7fb;
  --card: #ffffff;
  --ok: #059669;
  --err: #dc2626;
  --radius: 16px;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  /* Gradiente marcato bianco → grigio, con sfumature neutre */
  background:
    radial-gradient(1000px 420px at 88% -6%, rgba(148, 163, 184, 0.16), transparent 65%),
    radial-gradient(800px 380px at 0% 0%, rgba(203, 213, 225, 0.3), transparent 60%),
    linear-gradient(180deg, #ffffff 0%, #eef0f5 38%, #d9dee6 100%);
  background-attachment: fixed;
  min-height: 100vh;
}

a { color: var(--accent-from); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Footer sempre in fondo, anche con poco contenuto */
body.site { display: flex; flex-direction: column; }
body.site main { flex: 1 0 auto; }

h1, h2, h3, h4 { line-height: 1.2; margin: 0 0 0.5em; }
p { margin: 0 0 1em; }
.muted { color: var(--muted); }
.small { font-size: 0.85em; }
.center { text-align: center; }
code { background: #f1f5f9; padding: 1px 6px; border-radius: 6px; font-size: 0.9em; }

.container { max-width: 1080px; margin: 0 auto; padding: 0 20px; }
.main { padding: 40px 20px 60px; }
.narrow { max-width: 520px; margin: 0 auto; }

/* Header */
.site-header {
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}
.nav { display: flex; align-items: center; justify-content: space-between; height: 64px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.1em; color: var(--ink); }
.brand:hover { text-decoration: none; }
.brand .logo { height: 34px; width: auto; }
.main-nav { display: flex; gap: 10px; align-items: center; }
.main-nav a {
  color: var(--ink);
  font-weight: 600;
  font-size: 0.92em;
  padding: 9px 18px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.8);
  border: 1px solid var(--line);
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
  transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, transform 0.1s ease;
}
.main-nav a:hover {
  background: var(--grad);
  color: #fff;
  border-color: transparent;
  text-decoration: none;
  box-shadow: 0 6px 16px rgba(79, 70, 229, 0.35);
  transform: translateY(-1px);
}
.main-nav a:active { transform: translateY(0); }

/* Hero */
.hero { text-align: center; padding: 70px 0 40px; }
.hero-badge {
  display: inline-block;
  background: var(--grad);
  color: #fff;
  padding: 6px 16px;
  border-radius: 999px;
  font-size: 0.8em;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 20px;
}
.hero h1 {
  font-size: clamp(2rem, 5vw, 3.2rem);
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin-bottom: 12px;
}
.hero-tagline { font-size: 1.15em; color: var(--muted); max-width: 560px; margin: 0 auto 28px; }
.hero-election {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 12px 20px;
  margin: 0 auto 26px;
  max-width: 640px;
  text-align: left;
}
.hero-election-label {
  font-size: 0.68em;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
  color: var(--muted);
  white-space: nowrap;
}
.hero-election strong { font-size: 1.02em; font-weight: 700; color: var(--ink); }
.hero-cta { margin-bottom: 30px; }

/* Countdown */
.countdown { margin-top: 12px; }
.countdown-label { color: var(--muted); margin-bottom: 14px; }
.countdown-boxes { display: flex; gap: 14px; justify-content: center; }
.cd {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 20px;
  min-width: 78px;
  display: flex;
  flex-direction: column;
}
.cd span { font-size: 1.9rem; font-weight: 800; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.cd small { color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; font-size: 0.7em; }

/* Features */
.features { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; margin-top: 20px; }
.feature {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
}
.feature-icon { font-size: 1.8rem; margin-bottom: 10px; }
.feature h3 { margin-bottom: 8px; }
.feature p { color: var(--muted); margin: 0; }

/* Cards & forms */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
  margin-bottom: 24px;
}
.stack { display: flex; flex-direction: column; gap: 16px; }
label { display: flex; flex-direction: column; gap: 6px; font-weight: 500; font-size: 0.92em; color: var(--ink); }
input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="datetime-local"], input[type="file"], select, textarea {
  font: inherit;
  color: var(--ink);
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent-from) 45%, transparent); border-color: transparent; }

/* Select professionali: niente aspetto nativo, chevron personalizzato */
select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20width='16'%20height='16'%20viewBox='0%200%2024%2024'%20fill='none'%20stroke='%2364748b'%20stroke-width='2'%20stroke-linecap='round'%20stroke-linejoin='round'%3E%3Cpolyline%20points='6%209%2012%2015%2018%209'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  background-size: 16px 16px;
  padding-right: 42px;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
select:hover { border-color: #c7d2fe; }
textarea { resize: vertical; }
.input-code { text-align: center; font-size: 1.3em; letter-spacing: 0.15em; text-transform: uppercase; }
.inline { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.inline input:not([type="checkbox"]):not([type="hidden"]) { flex: 1 1 160px; }
.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; }
.check input { width: auto; }

/* Buttons */
.btn {
  display: inline-block;
  font: inherit;
  font-weight: 600;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 20px;
  cursor: pointer;
  transition: transform 0.1s ease, box-shadow 0.15s ease;
}
.btn:hover { text-decoration: none; box-shadow: var(--shadow); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--grad); color: #fff; border: none; }
.btn-primary:hover { filter: brightness(1.05); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-danger { color: var(--err); border-color: #fecaca; }
.btn-small { padding: 7px 12px; font-size: 0.82em; border-radius: 8px; }
.btn-lg { padding: 14px 34px; font-size: 1.05em; border-radius: 12px; }

/* Alerts */
.alert { padding: 12px 16px; border-radius: 10px; margin-bottom: 18px; font-weight: 500; }
.alert-error { background: #fef2f2; color: var(--err); border: 1px solid #fecaca; }
.alert-success { background: #ecfdf5; color: var(--ok); border: 1px solid #a7f3d0; }

/* Ballot */
.role-block { border: 1px solid var(--line); border-radius: 12px; padding: 18px; margin: 0 0 20px; }
.role-block legend { font-weight: 700; padding: 0 8px; }
.choice {
  display: flex; flex-direction: row; align-items: center; gap: 12px;
  padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 10px; cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.choice:hover { border-color: var(--accent-from); }
.choice input { width: auto; }
.choice-body { display: flex; flex-direction: column; }
.choice-name { font-weight: 600; }
.choice-body small { color: var(--muted); }

/* Results */
.result-election { border-top: 1px solid var(--line); padding-top: 22px; margin-top: 22px; }
.result-election:first-of-type { border-top: none; padding-top: 0; margin-top: 0; }
.role-results { margin: 18px 0; }
.bar-row { margin-bottom: 12px; }
.bar-label { display: flex; justify-content: space-between; margin-bottom: 5px; font-size: 0.92em; }
.bar-count { color: var(--muted); }
.bar { height: 10px; background: #eef2f7; border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--grad); border-radius: 999px; transition: width 0.6s ease; }

/* Tables */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-size: 0.8em; text-transform: uppercase; letter-spacing: 0.04em; }
tr:last-child td { border-bottom: none; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.actions form { display: inline; }

/* Badges */
.badge { display: inline-block; padding: 4px 10px; border-radius: 999px; font-size: 0.75em; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; }
.badge-active { background: #ecfdf5; color: #059669; }
.badge-upcoming { background: #fffbeb; color: #b45309; }
.badge-closed { background: #f1f5f9; color: #475569; }
.badge-published { background: #eef2ff; color: #4f46e5; }

/* Admin shell */
.admin-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 240px; flex-shrink: 0;
  background: var(--card);
  border-right: 1px solid var(--line);
  padding: 24px 16px;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 8px;
  font-weight: 800; font-size: 1.1em;
  background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent;
  padding: 0 8px 18px;
}
.sidebar-logo { height: 26px; width: auto; }
.side-nav { display: flex; flex-direction: column; gap: 8px; }
.side-nav a {
  color: var(--ink);
  padding: 11px 14px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 0.94em;
  background: #f8fafc;
  border: 1px solid var(--line);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
  transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, transform 0.1s ease;
}
.side-nav a:hover {
  background: var(--grad);
  color: #fff;
  border-color: transparent;
  text-decoration: none;
  box-shadow: 0 6px 16px rgba(79, 70, 229, 0.3);
  transform: translateY(-1px);
}
.side-nav a:active { transform: translateY(0); }
.logout { margin-top: auto; }
.logout .btn { width: 100%; }
.admin-main { flex: 1; padding: 32px; max-width: 1100px; }
.admin-main h1 { margin-bottom: 22px; }

/* Election cards (dashboard) */
.election-card { padding: 22px 24px; }
.election-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.election-title { margin: 0 0 5px; font-size: 1.15em; }
.election-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; color: var(--muted); font-size: 0.88em; }
.election-meta .dot { opacity: 0.5; }
.election-section { padding-top: 14px; margin-top: 14px; border-top: 1px solid var(--line); }
.election-section-label {
  font-size: 0.7em; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted); font-weight: 700; margin-bottom: 8px;
}
.election-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.election-actions form { display: inline-flex; }

/* Stats */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; display: flex; flex-direction: column; }
.stat strong { font-size: 2rem; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.stat span { color: var(--muted); }

/* Grid & misc */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.row-between { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.scroll-list { max-height: 220px; overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; padding: 12px; display: flex; flex-direction: column; gap: 6px; }
.logo-preview { max-height: 56px; margin-bottom: 8px; border-radius: 8px; }

/* Login page */
.login-logo { height: 48px; width: auto; margin-bottom: 8px; }
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
.login-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 36px; width: 100%; max-width: 400px; text-align: center; }

/* Footer */
.site-footer { border-top: 1px solid var(--line); background: rgba(255,255,255,0.6); }
.site-footer .container { display: flex; justify-content: space-between; padding: 22px 20px; color: var(--muted); font-size: 0.9em; }

/* Error page */
.error-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
.error-page .card { width: 100%; }

@media (max-width: 820px) {
  .features { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .grid2 { grid-template-columns: 1fr; }
  .admin-shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; flex-direction: row; align-items: center; position: static; }
  .side-nav { flex-direction: row; flex-wrap: wrap; }
  .logout { margin: 0 0 0 auto; }
  .admin-main { padding: 20px; }
  .main-nav { gap: 6px; }
  .main-nav a { padding: 8px 13px; font-size: 0.85em; }
}

/* Campi form (etichetta + controllo) */
.field { display: flex; flex-direction: column; gap: 6px; }
.field.is-invalid .dtp-input { border-color: var(--err); }

/* DatePicker data/ora */
.dtp { position: relative; }
.dtp-input {
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20width='16'%20height='16'%20viewBox='0%200%2024%2024'%20fill='none'%20stroke='%2364748b'%20stroke-width='2'%20stroke-linecap='round'%20stroke-linejoin='round'%3E%3Crect%20x='3'%20y='4'%20width='18'%20height='18'%20rx='2'/%3E%3Cline%20x1='16'%20y1='2'%20x2='16'%20y2='6'/%3E%3Cline%20x1='8'%20y1='2'%20x2='8'%20y2='6'/%3E%3Cline%20x1='3'%20y1='10'%20x2='21'%20y2='10'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 40px;
}
.dtp-pop {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  min-width: 300px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 18px 50px rgba(15, 23, 42, 0.18);
  padding: 14px;
  z-index: 50;
}
.dtp-pop.is-open { display: block; }
.dtp-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.dtp-title { font-weight: 700; font-size: 0.95em; }
.dtp-nav {
  width: 30px; height: 30px; border: none; border-radius: 8px;
  background: #f1f5f9; color: var(--ink); font-size: 1.2em; line-height: 1;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
  transition: background 0.15s ease, color 0.15s ease;
}
.dtp-nav:hover { background: var(--grad); color: #fff; }
.dtp-week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; margin-bottom: 4px; }
.dtp-week span { text-align: center; font-size: 0.68em; text-transform: uppercase; color: var(--muted); letter-spacing: 0.05em; padding: 4px 0; }
.dtp-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.dtp-day {
  height: 34px; border: none; border-radius: 8px; background: transparent;
  font: inherit; font-size: 0.9em; cursor: pointer; color: var(--ink);
  display: inline-flex; align-items: center; justify-content: center;
  transition: background 0.12s ease, color 0.12s ease;
}
.dtp-day:hover { background: #eef2ff; }
.dtp-day.is-today { box-shadow: inset 0 0 0 1px var(--accent-from); }
.dtp-day.is-selected { background: var(--grad); color: #fff; font-weight: 700; }
.dtp-time { display: flex; gap: 10px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.dtp-time label { flex: 1; font-size: 0.78em; color: var(--muted); }
.dtp-time select { width: 100%; padding: 8px 26px 8px 10px; border-radius: 8px; border: 1px solid var(--line); font: inherit; background-color: #fff; color: var(--ink); background-position: right 7px center; background-size: 12px 12px; }
.dtp-foot { display: flex; gap: 8px; margin-top: 12px; justify-content: flex-end; }
