:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --primary: #0f766e;
  --primary-dark: #115e59;
  --accent: #f59e0b;
  --text: #0f172a;
  --muted: #475569;
  --border: #cbd5e1;
  --danger: #dc2626;
  --success: #15803d;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

.hidden { display: none !important; }

/* === LOGIN === */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.login-card {
  background: var(--surface);
  border-radius: 14px;
  padding: 32px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.1);
  border: 1px solid #e2e8f0;
}

/* === SHELL TOPBAR === */
.topbar {
  background: #0f172a;
  color: #ffffff;
  padding: 12px 20px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.topbar-brand {
  font-weight: 800;
  font-size: 1.1rem;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.nav-btn {
  background: rgba(255, 255, 255, 0.1);
  color: #e2e8f0;
  border: none;
  padding: 8px 14px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
}

.nav-btn:hover { background: rgba(255, 255, 255, 0.2); }
.nav-btn.active { background: var(--primary); color: #ffffff; }
.nav-btn.accent { background: var(--accent); color: #0f172a; }

.main-wrap {
  max-width: 1260px;
  margin: 0 auto;
  padding: 20px 16px 60px;
}

/* === CARD, GRID, FORM === */
.card {
  background: var(--surface);
  border: 1px solid #e2e8f0;
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.04);
  margin-bottom: 18px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid #e2e8f0;
  border-radius: var(--radius);
  padding: 16px 18px;
}

.kpi-label { font-size: 0.82rem; color: var(--muted); font-weight: 600; text-transform: uppercase; }
.kpi-val { font-size: 1.75rem; font-weight: 800; color: var(--primary); margin-top: 4px; }

.form-grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 14px;
}

.form-grid-3 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
}

.fg { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.fg label { font-size: 0.88rem; font-weight: 600; color: #1e293b; }
.fg small { font-size: 0.78rem; color: var(--muted); }

input[type="text"],
input[type="password"],
input[type="number"],
input[type="datetime-local"],
input[type="search"],
input[type="url"],
select,
textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: 7px;
  font-size: 0.94rem;
  font-family: inherit;
  background: #ffffff;
  color: var(--text);
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
}

input[type="color"] {
  width: 60px;
  height: 38px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  padding: 2px;
  cursor: pointer;
}

/* === BOTTONI === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 15px;
  border-radius: 7px;
  border: none;
  font-weight: 600;
  font-size: 0.9rem;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
}

.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-sm { padding: 6px 10px; font-size: 0.82rem; }
.btn-primary { background: var(--primary); color: #ffffff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #e2e8f0; color: #0f172a; }
.btn-warning { background: #d97706; color: #ffffff; }
.btn-danger { background: var(--danger); color: #ffffff; }
.btn-outline { background: transparent; border: 1.5px solid var(--border); color: var(--text); }
.btn-gemini { background: linear-gradient(135deg, #2563eb, #7c3aed); color: #ffffff; }

/* === BADGES === */
.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 700;
}
.badge-ATTIVO, .badge-PAGATO { background: #dcfce7; color: #166534; }
.badge-BOZZA, .badge-SOSTITUITA { background: #fef3c7; color: #92400e; }
.badge-CHIUSO, .badge-ANNULLATA, .badge-DA_PAGARE { background: #fee2e2; color: #991b1b; }
.badge-dup { background: #ffedd5; color: #9a3412; border: 1px solid #fdba74; }

/* === LISTA EVENTI === */
.event-item {
  background: var(--surface);
  border: 1px solid #e2e8f0;
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.progress-track {
  width: 220px;
  max-width: 100%;
  height: 8px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
  margin-top: 6px;
}
.progress-fill { height: 100%; background: var(--primary); }

/* === EDITOR SUB-TABS === */
.ed-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  border-bottom: 2px solid #e2e8f0;
  padding-bottom: 10px;
  margin-bottom: 18px;
}

.ed-tab-btn {
  background: #e2e8f0;
  color: #334155;
  border: none;
  padding: 9px 16px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
}

.ed-tab-btn.active {
  background: var(--primary);
  color: #ffffff;
}

/* === IMMAGINI & GEMINI PREVIEW === */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.gallery-card {
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 10px;
  background: #f8fafc;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.gallery-card img {
  width: 100%;
  height: 130px;
  object-fit: cover;
  border-radius: 6px;
  background: #e2e8f0;
}

.preview-frame {
  border: 2px solid #cbd5e1;
  border-radius: 10px;
  background: #ffffff;
  margin: 12px auto;
  overflow: hidden;
  transition: width 0.2s;
}

/* === FORM BUILDER === */
.fb-row {
  border: 1.5px solid #cbd5e1;
  border-radius: 9px;
  padding: 14px;
  background: #f8fafc;
  margin-bottom: 12px;
}

.fb-row-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

/* === TABELLA ISCRITTI === */
.table-wrap {
  overflow-x: auto;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #ffffff;
}

table.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
}

table.admin-table th {
  background: #0f172a;
  color: #ffffff;
  padding: 10px;
  text-align: left;
  white-space: nowrap;
}

table.admin-table td {
  padding: 9px 10px;
  border-bottom: 1px solid #e2e8f0;
  vertical-align: top;
}

table.admin-table tr.dup-row td { background: #fff7ed; }
table.admin-table tr.inactive-row td { opacity: 0.55; }

/* === MODALI & TOAST === */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 900;
}

.modal-card {
  background: #ffffff;
  border-radius: 12px;
  width: 100%;
  max-width: 960px;
  max-height: 92vh;
  overflow-y: auto;
  padding: 22px;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.28);
}

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: #0f172a;
  color: #ffffff;
  padding: 12px 18px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.92rem;
  z-index: 1200;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}
.toast.ok { background: #15803d; }
.toast.err { background: #dc2626; }

/* === CHECKLIST COLONNE === */
.cols-checklist {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px;
  margin-top: 8px;
}

.chk-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  font-size: 0.86rem;
  cursor: pointer;
}

/* === STAMPA A4 PERSONALIZZATA DALLA DASHBOARD === */
#print-preview-area {
  background: #ffffff;
  border: 1px solid #cbd5e1;
  padding: 14px;
  border-radius: 8px;
  overflow-x: auto;
}

table.print-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 9pt;
}

table.print-table th,
table.print-table td {
  border: 1px solid #64748b;
  padding: 4px 6px;
  text-align: left;
  word-break: break-word;
  vertical-align: top;
}

table.print-table th {
  background: #e2e8f0;
  font-weight: 700;
}

@media print {
  body { background: #ffffff !important; }
  body > *:not(#print-modal) { display: none !important; }
  #print-modal {
    position: static !important;
    background: #ffffff !important;
    padding: 0 !important;
    display: block !important;
  }
  #print-modal .modal-card {
    box-shadow: none !important;
    border: none !important;
    max-width: 100% !important;
    max-height: none !important;
    padding: 0 !important;
    overflow: visible !important;
  }
  .no-print { display: none !important; }
  #print-preview-area {
    border: none !important;
    padding: 0 !important;
    overflow: visible !important;
  }
  table.print-table th {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}