/* ===================================
   BILANCIO POP – Design System
   =================================== */

:root {
  /* Brand Colors (UniTo Red) */
  --blue-900: #222222;
  --blue-800: #333333;
  --blue-700: #bb0021;
  --blue-600: #ea0029; /* Primary Red */
  --blue-500: #f23a59;
  --blue-400: #f76881;
  --blue-300: #fca8b6;
  --blue-200: #fdd8de;
  --blue-100: #feebef;
  --blue-50: #fff5f7;

  /* Secondary Colors (UniTo Grey) */
  --gold-600: #444648;
  --gold-500: #5a5c5e; /* Secondary Grey */
  --gold-400: #8d9092;
  --gold-300: #c2c4c5;
  --gold-100: #f4f5f6;

  /* Neutrals */
  --gray-900: #1a202c;
  --gray-800: #2d3748;
  --gray-700: #4a5568;
  --gray-600: #718096;
  --gray-500: #a0aec0;
  --gray-400: #cbd5e0;
  --gray-300: #e2e8f0;
  --gray-200: #edf2f7;
  --gray-100: #f7fafc;
  --gray-50: #fafbfc;
  --white: #ffffff;

  /* Status Colors */
  --green-500: #38a169;
  --green-100: #f0fff4;
  --red-500: #e53e3e;
  --red-100: #fff5f5;
  --orange-500: #dd6b20;
  --orange-100: #fffaf0;
  --purple-500: #805ad5;
  --purple-100: #faf5ff;

  /* Layout */
  --sidebar-w: 260px;
  --header-h: 64px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.12);
  --shadow-xl: 0 20px 60px rgba(0,0,0,0.15);

  /* Transitions */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --duration: 0.2s;
}

/* ===================================
   Tema Scuro
   Ribalta la scala dei neutri e dei toni pallidi usati come sfondo dei
   badge/chip; i colori satur (--blue-600, --green-500, --red-500, ecc.)
   restano invariati perché leggibili sia su sfondi chiari che scuri.
   =================================== */

:root[data-theme="dark"] {
  --blue-900: #f5f5f5;
  --blue-800: #e5e5e5;
  --blue-200: #4a1620;
  --blue-100: #3a121a;
  --blue-50:  #2e0f16;

  --gold-100: #262f3a;

  --gray-900: #f1f5f9;
  --gray-800: #e2e8f0;
  --gray-700: #cbd5e0;
  --gray-600: #94a3b8;
  --gray-500: #82909f;
  --gray-400: #4b5768;
  --gray-300: #334155;
  --gray-200: #263140;
  --gray-100: #171f2a;
  --gray-50:  #10151d;
  --white: #1c2531;

  --green-100: rgba(56, 161, 105, 0.16);
  --red-100: rgba(229, 62, 62, 0.16);
  --orange-100: rgba(221, 107, 32, 0.16);
  --purple-100: rgba(128, 90, 213, 0.16);

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.35);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.4);
  --shadow-xl: 0 20px 60px rgba(0,0,0,0.5);
}

:root[data-theme="dark"] .stat-icon.gold {
  background: rgba(148, 163, 184, 0.16);
  color: #cbd5e0;
}

/* ===================================
   Reset & Base
   =================================== */

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

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--gray-100);
  color: var(--gray-800);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 {
  font-weight: 700;
  line-height: 1.3;
  color: var(--gray-900);
}

a { color: var(--blue-600); text-decoration: none; transition: color var(--duration) var(--ease); }
a:hover { color: var(--blue-500); }

/* Focus Visible for accessibility */
:focus-visible {
  outline: 3px solid var(--blue-400);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ===================================
   Sidebar
   =================================== */

.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--white);
  border-right: 1px solid var(--gray-200);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 100;
  transition: transform 0.3s var(--ease);
}

.sidebar-header {
  padding: 24px 20px 20px;
  border-bottom: 1px solid var(--gray-100);
}

.logo-area {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-placeholder {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: rgba(255,255,255,0.1);
}

.logo-placeholder img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.logo-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  font-weight: 800;
  font-size: 12px;
  color: var(--gold-400);
  letter-spacing: 0.5px;
}

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.brand-name {
  font-weight: 700;
  font-size: 16px;
  color: var(--gray-900);
  letter-spacing: -0.3px;
}

.brand-dept {
  font-size: 10px;
  color: var(--gray-500);
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Sidebar Nav */
.sidebar-nav { flex: 1; padding: 16px 12px; overflow-y: auto; }
.sidebar-nav ul { list-style: none; display: flex; flex-direction: column; gap: 4px; }

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  color: var(--gray-600);
  font-size: 14px;
  font-weight: 500;
  transition: all var(--duration) var(--ease);
  text-decoration: none;
}

.nav-link:hover {
  background: var(--gray-50);
  color: var(--blue-600);
}

.nav-link.active {
  background: var(--blue-50);
  color: var(--blue-600);
  box-shadow: inset 3px 0 0 var(--blue-600);
}

.nav-icon { width: 20px; height: 20px; flex-shrink: 0; }

/* Sidebar footer */
.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--gray-100);
}

.user-info { display: flex; align-items: center; gap: 10px; }

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--gray-100);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 12px;
  color: var(--gray-700);
  flex-shrink: 0;
}

.user-details { display: flex; flex-direction: column; }
.user-name { font-size: 13px; font-weight: 600; color: var(--gray-900); }
.user-role { font-size: 11px; color: var(--gray-500); }

/* ===================================
   Mobile Header
   =================================== */

.mobile-header {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-h);
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  z-index: 90;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
}

.menu-toggle {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--gray-900);
  width: 28px;
  height: 28px;
  padding: 0;
}

.menu-toggle svg { width: 100%; height: 100%; }
.mobile-title { font-weight: 700; font-size: 18px; color: var(--gray-900); }

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 99;
  backdrop-filter: blur(2px);
}

/* ===================================
   Main Content
   =================================== */

.main-content {
  flex: 1;
  margin-left: var(--sidebar-w);
  padding: 32px;
  min-height: 100vh;
  max-width: 1200px;
}

/* ===================================
   Page Header
   =================================== */

.page-header {
  margin-bottom: 28px;
}

.page-header h1 {
  font-size: 26px;
  font-weight: 800;
  color: var(--blue-900);
  letter-spacing: -0.5px;
}

.page-header p {
  color: var(--gray-600);
  font-size: 14px;
  margin-top: 4px;
}

/* ===================================
   Cards
   =================================== */

.card {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--gray-200);
  transition: box-shadow var(--duration) var(--ease);
}

.card:hover { box-shadow: var(--shadow-md); }

.card-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--gray-900);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ===================================
   Stats Grid
   =================================== */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--gray-200);
  display: flex;
  align-items: flex-start;
  gap: 14px;
  transition: all var(--duration) var(--ease);
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.stat-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.stat-icon svg { width: 22px; height: 22px; }
.stat-icon.blue { background: var(--blue-100); color: var(--blue-600); }
.stat-icon.green { background: var(--green-100); color: var(--green-500); }
.stat-icon.gold { background: var(--gold-100); color: var(--gold-600); }
.stat-icon.purple { background: var(--purple-100); color: var(--purple-500); }

.stat-info { display: flex; flex-direction: column; }
.stat-value { font-size: 24px; font-weight: 800; color: var(--gray-900); line-height: 1.2; }
.stat-label { font-size: 12px; color: var(--gray-600); font-weight: 500; margin-top: 2px; }

/* ===================================
   Content Grid
   =================================== */

.content-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 24px;
}

.content-grid.full { grid-template-columns: 1fr; }

/* ===================================
   Tables
   =================================== */

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

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead th {
  text-align: left;
  padding: 10px 12px;
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--gray-600);
  border-bottom: 2px solid var(--gray-200);
}

tbody td {
  padding: 12px;
  border-bottom: 1px solid var(--gray-100);
  vertical-align: middle;
}

tbody tr:hover { background: var(--gray-50); }

/* ===================================
   Badges
   =================================== */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.badge.green { background: var(--green-100); color: var(--green-500); }
.badge.blue { background: var(--blue-100); color: var(--blue-600); }
.badge.orange { background: var(--orange-100); color: var(--orange-500); }
.badge.red { background: var(--red-100); color: var(--red-500); }
.badge.purple { background: var(--purple-100); color: var(--purple-500); }
.badge.gray { background: var(--gray-200); color: var(--gray-700); }

/* ===================================
   Buttons
   =================================== */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--duration) var(--ease);
  text-decoration: none;
}

.btn svg { width: 18px; height: 18px; }

.btn-primary {
  background: var(--blue-600);
  color: var(--white);
  box-shadow: none;
}

.btn-primary:hover {
  background: var(--blue-700);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
  color: var(--white);
}

.btn-secondary {
  background: var(--white);
  color: var(--gray-700);
  border: 1px solid var(--gray-300);
}

.btn-secondary:hover {
  background: var(--gray-50);
  border-color: var(--gray-400);
  color: var(--gray-700);
}

.btn-gold {
  background: var(--gold-500);
  color: var(--white);
  box-shadow: none;
}

.btn-gold:hover {
  background: var(--gold-600);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
  color: var(--white);
}

.btn-sm { padding: 6px 14px; font-size: 12px; }
.btn-sm svg { width: 14px; height: 14px; }

/* ===================================
   Forms
   =================================== */

.form-group { margin-bottom: 20px; }

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--gray-700);
  margin-bottom: 6px;
}

.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 14px;
  color: var(--gray-800);
  background: var(--white);
  transition: all var(--duration) var(--ease);
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--blue-400);
  box-shadow: 0 0 0 3px rgba(66,153,225,0.15);
}

.form-textarea { resize: vertical; min-height: 100px; }

.form-input[readonly] {
  background: var(--gray-100);
  color: var(--gray-600);
  cursor: not-allowed;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.form-hint {
  font-size: 11px;
  color: var(--gray-500);
  margin-top: 4px;
}

.bf-field-warning {
  font-size: 11px;
  color: var(--red-500);
  margin-top: 4px;
  font-weight: 500;
}

.checkbox-list {
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  padding: 6px 10px;
  background: var(--gray-50);
}

.checkbox-list-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 2px;
  font-size: 14px;
  color: var(--gray-700);
  cursor: pointer;
}

.checkbox-list-item input[type="checkbox"] {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  cursor: pointer;
}

/* ===================================
   Progress Bar
   =================================== */

.progress-bar-container { margin-bottom: 16px; }

.progress-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.progress-label span:first-child { font-size: 13px; font-weight: 500; color: var(--gray-700); }
.progress-label span:last-child { font-size: 12px; font-weight: 600; color: var(--gray-600); }

.progress-bar {
  height: 8px;
  background: var(--gray-200);
  border-radius: 10px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 10px;
  transition: width 0.6s var(--ease);
  background: var(--blue-600);
}

.progress-fill.green { background: var(--green-500); }
.progress-fill.gold { background: var(--gold-500); }
.progress-fill.red { background: var(--red-500); }

/* ===================================
   Section List (Sezioni POP)
   =================================== */

.section-list { display: flex; flex-direction: column; gap: 10px; }

.section-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-md);
  transition: all var(--duration) var(--ease);
  cursor: pointer;
}

.section-item:hover {
  border-color: var(--blue-300);
  box-shadow: var(--shadow-sm);
  transform: translateX(4px);
}

.section-number {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--blue-100);
  color: var(--blue-600);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
}

.section-item.completed .section-number {
  background: var(--green-100);
  color: var(--green-500);
}

.section-info { flex: 1; min-width: 0; }
.section-name { font-size: 14px; font-weight: 600; color: var(--gray-900); }
.section-desc { font-size: 12px; color: var(--gray-500); margin-top: 2px; }

.section-status { flex-shrink: 0; }

/* ===================================
   Validation Items
   =================================== */

.validation-item {
  padding: 16px;
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-md);
  margin-bottom: 10px;
  transition: all var(--duration) var(--ease);
}

.validation-item:hover { border-color: var(--blue-200); }

.validation-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 8px;
}

.validation-title { font-size: 14px; font-weight: 600; color: var(--gray-900); }
.validation-source { font-size: 12px; color: var(--gray-500); margin-top: 4px; }
.validation-text { font-size: 13px; color: var(--gray-700); line-height: 1.5; margin-bottom: 10px; }

.validation-actions { display: flex; gap: 8px; }

/* ===================================
   Export Options
   =================================== */

.export-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
}

.export-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 28px 20px;
  background: var(--white);
  border: 2px solid var(--gray-200);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: all var(--duration) var(--ease);
  text-align: center;
}

.export-card:hover {
  border-color: var(--blue-400);
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
}

.export-icon {
  width: 52px;
  height: 52px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
  font-size: 22px;
  font-weight: 800;
}

.export-icon.word { background: #dbeafe; color: #2563eb; }
.export-icon.ppt { background: #fef3c7; color: #d97706; }
.export-icon.excel { background: #d1fae5; color: #059669; }
.export-icon.pdf { background: #fee2e2; color: #dc2626; }
.export-icon.html { background: #ede9fe; color: #7c3aed; }
.export-icon.json { background: #e0e7ff; color: #4338ca; }

.export-name { font-size: 14px; font-weight: 600; color: var(--gray-900); }
.export-desc { font-size: 11px; color: var(--gray-500); margin-top: 4px; }

/* ===================================
   Activity List
   =================================== */

.activity-list { display: flex; flex-direction: column; gap: 12px; }

.activity-item {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.activity-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 6px;
}

.activity-dot.blue { background: var(--blue-500); }
.activity-dot.green { background: var(--green-500); }
.activity-dot.gold { background: var(--gold-500); }

.activity-content { flex: 1; }
.activity-text { font-size: 13px; color: var(--gray-700); }
.activity-time { font-size: 11px; color: var(--gray-500); margin-top: 2px; }

/* ===================================
   Empty state
   =================================== */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  text-align: center;
}

.empty-state svg { width: 64px; height: 64px; color: var(--gray-400); margin-bottom: 16px; }
.empty-state h3 { font-size: 16px; color: var(--gray-700); margin-bottom: 6px; }
.empty-state p { font-size: 13px; color: var(--gray-500); max-width: 320px; }

/* ===================================
   Il Mio Bilancio (comunale) – layout a due colonne con chat fissa a destra
   =================================== */

.mio-bilancio-layout {
  display: flex;
  gap: 20px;
  align-items: flex-start;
}

.mio-bilancio-main {
  flex: 1;
  min-width: 0;
}

.mio-bilancio-chat-sidebar {
  width: 340px;
  flex-shrink: 0;
  position: sticky;
  top: 20px;
}

.mio-chat-card {
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 40px);
}

/* Richieste e Obiezioni (ticket con thread) */
.req-card {
  padding: 14px 16px;
  border: 1px solid var(--gray-200);
  border-radius: 12px;
  margin-bottom: 12px;
  background: #fff;
}
.req-card.internal {
  background: var(--blue-50);
  border-color: var(--blue-200);
}
.req-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}
.req-head-actions { display: flex; align-items: center; gap: 6px; }
.req-origin { font-size: 12px; font-weight: 600; color: var(--gray-500); }
.req-msg { margin: 0; font-size: 14px; color: var(--gray-800); }
.req-submeta { font-size: 11px; color: var(--gray-400); margin-top: 4px; }

.req-thread {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
/* Voce del thread come una chat di gruppo: avatar (colore ruolo) + testo */
.req-reply {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 13px;
}
.req-reply-avatar {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  color: #fff;
}
.req-reply-avatar.role-comune { background: #16a34a; }
.req-reply-avatar.role-staff  { background: #2563eb; }
.req-reply-avatar.role-admin  { background: #7c3aed; }
.req-reply-main { flex: 1; min-width: 0; }
.req-reply-meta { font-size: 11px; color: var(--gray-500); margin-bottom: 2px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.req-reply-body { color: var(--gray-800); white-space: pre-wrap; word-break: break-word; }

.req-reply-form { display: flex; gap: 8px; margin-top: 10px; }
.req-reply-form .form-input { flex: 1; }

/* Membri della Giunta con foto obbligatoria */
.giunta-members { display: flex; flex-direction: column; gap: 10px; }
.giunta-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  border: 1px solid var(--gray-200);
  border-radius: 12px;
  padding: 10px 12px;
}
.giunta-card.missing-photo { border-color: #f59e0b; background: #fffbeb; }
.giunta-photo {
  width: 72px;
  height: 72px;
  flex-shrink: 0;
  border-radius: 8px;
  overflow: hidden;
  background: var(--gray-100);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: 1px dashed var(--gray-300);
  text-align: center;
}
.giunta-photo img { width: 100%; height: 100%; object-fit: cover; }
.giunta-photo-ph { font-size: 10px; color: var(--gray-500); line-height: 1.3; }
.giunta-fields { flex: 1; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.giunta-warn { font-size: 12px; color: #b45309; font-weight: 600; }
.giunta-del { background: none; border: none; color: var(--gray-400); font-size: 20px; cursor: pointer; line-height: 1; }
.giunta-del:hover { color: var(--red, #e53e3e); }

/* Galleria foto a miniature (File condivisi) */
.file-thumb {
  position: relative;
  width: 150px;
  margin: 0;
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: 10px;
  overflow: hidden;
}
.file-thumb img {
  display: block;
  width: 100%;
  height: 110px;
  object-fit: cover;
  background: var(--gray-100);
}
.file-thumb figcaption { padding: 6px 8px; font-size: 11px; }
.file-thumb-name {
  font-weight: 600;
  color: var(--gray-700);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.file-thumb-desc { color: var(--gray-600); margin-top: 2px; }
.file-thumb-meta { color: var(--gray-400); margin-top: 2px; }
.file-thumb-del {
  position: absolute;
  top: 4px;
  right: 4px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
}

/* Tabella documenti (File condivisi) */
.file-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.file-table th {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 2px solid var(--gray-200);
  color: var(--gray-500);
  font-weight: 600;
  white-space: nowrap;
}
.file-table th:hover { color: var(--gray-800); }
.file-table td { padding: 8px 10px; border-bottom: 1px solid var(--gray-100); vertical-align: top; }
.file-table tr:hover td { background: var(--gray-50); }

.mio-chat-messages {
  flex: 1;
  overflow-y: auto;
  min-height: 320px;
  max-height: 60vh;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px;
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: 12px;
}

.mio-chat-empty {
  margin: auto;
  text-align: center;
  color: var(--gray-500);
  font-size: 14px;
  max-width: 320px;
}

/* Separatore di giornata */
.mio-chat-day {
  text-align: center;
  margin: 12px 0 8px;
}
.mio-chat-day span {
  display: inline-block;
  padding: 3px 12px;
  font-size: 11px;
  color: var(--gray-500);
  background: var(--gray-200);
  border-radius: 999px;
  text-transform: capitalize;
}

/* Riga messaggio: allineamento sinistra/destra */
.mio-msg {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin-top: 4px;
}
.mio-msg.mine { justify-content: flex-end; }
.mio-msg.theirs { justify-content: flex-start; }

/* Avatar a iniziali, colorato per ruolo (Comune / Staff / Admin) */
.mio-msg-avatar {
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
}
.mio-msg-avatar.role-comune { background: #16a34a; }
.mio-msg-avatar.role-staff  { background: #2563eb; }
.mio-msg-avatar.role-admin  { background: #7c3aed; }

.mio-msg-bubble {
  max-width: 74%;
  padding: 8px 12px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.4;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.06);
  word-break: break-word;
}
.mio-msg.theirs .mio-msg-bubble {
  background: #fff;
  color: var(--gray-800);
  border-bottom-left-radius: 4px;
  border-left: 3px solid var(--gray-300);
}
.mio-msg.theirs.role-comune .mio-msg-bubble { border-left-color: #16a34a; }
.mio-msg.theirs.role-staff  .mio-msg-bubble { border-left-color: #2563eb; }
.mio-msg.theirs.role-admin  .mio-msg-bubble { border-left-color: #7c3aed; }
.mio-msg.mine .mio-msg-bubble {
  background: var(--blue-600);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.mio-msg-author {
  font-size: 12px;
  font-weight: 600;
  color: var(--gray-700);
  margin-bottom: 3px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.mio-msg-role {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 1px 6px;
  border-radius: 999px;
  color: #fff;
}
.mio-msg-role.role-comune { background: #16a34a; }
.mio-msg-role.role-staff  { background: #2563eb; }
.mio-msg-role.role-admin  { background: #7c3aed; }
.mio-msg-body { white-space: pre-wrap; }
.mio-msg-time {
  font-size: 10px;
  margin-top: 3px;
  text-align: right;
  opacity: 0.7;
}
.mio-msg.theirs .mio-msg-time { color: var(--gray-400); }
.mio-msg.mine .mio-msg-time { color: rgba(255, 255, 255, 0.85); }

/* ===================================
   Responsive
   =================================== */

@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.active { display: block; }
  .mobile-header { display: flex; }
  .main-content { margin-left: 0; padding: 80px 16px 24px; }
  .content-grid { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .mio-bilancio-layout { flex-direction: column; }
  .mio-bilancio-chat-sidebar { width: 100%; position: static; }
  .mio-chat-card { max-height: none; }
  .mio-chat-messages { max-height: 320px; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .export-grid { grid-template-columns: 1fr 1fr; }
}

/* ===================================
   Animations
   =================================== */

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.page-enter { animation: fadeIn 0.3s var(--ease) both; }

/* ===================================
   Wizard Steps (Creazione Bilancio)
   =================================== */

.wizard-steps {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  margin-bottom: 8px;
  padding: 16px 0;
}

/* Pallino di notifica "ci sono novità" (nav-link e schede) */
.has-badge { position: relative; }
.has-badge::after {
  content: '';
  position: absolute;
  top: 8px;
  right: 10px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--blue-600);
  box-shadow: 0 0 0 2px var(--white);
  pointer-events: none;
}
.proj-tab.has-badge::after { top: 4px; right: 4px; }

/* Schede del progetto (navigazione non lineare) */
.project-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--gray-200);
  padding-bottom: 0;
}
.proj-tab {
  appearance: none;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  color: var(--gray-500);
  cursor: pointer;
  border-radius: 8px 8px 0 0;
  transition: color .15s, background .15s, border-color .15s;
}
.proj-tab:hover { color: var(--gray-800); background: var(--gray-50); }
.proj-tab.active {
  color: var(--blue-600);
  border-bottom-color: var(--blue-600);
}

.wizard-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  position: relative;
}

.wizard-step-num {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--gray-200);
  color: var(--gray-500);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  transition: all 0.3s var(--ease);
  border: 2px solid transparent;
}

.wizard-step.active .wizard-step-num {
  background: var(--blue-600);
  color: var(--white);
  border-color: var(--blue-400);
  box-shadow: 0 0 0 4px rgba(234, 0, 41, 0.15);
}

.wizard-step.completed .wizard-step-num {
  background: var(--green-500);
  color: var(--white);
}

.wizard-step-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--gray-500);
  white-space: nowrap;
}

.wizard-step.active .wizard-step-label { color: var(--blue-600); }
.wizard-step.completed .wizard-step-label { color: var(--green-500); }

.wizard-connector {
  width: 60px;
  height: 2px;
  background: var(--gray-300);
  margin: 0 8px;
  margin-bottom: 20px;
  border-radius: 1px;
}

/* ===================================
   Drop Zone (File Upload)
   =================================== */

.drop-zone {
  border: 2px dashed var(--gray-300);
  border-radius: var(--radius-lg);
  padding: 32px;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s var(--ease);
  background: var(--gray-50);
}

.drop-zone:hover,
.drop-zone.drag-over {
  border-color: var(--blue-400);
  background: var(--blue-50);
}

.drop-zone.drag-over {
  transform: scale(1.01);
  box-shadow: 0 0 0 3px rgba(234, 0, 41, 0.1);
}

.drop-zone p {
  font-size: 14px;
  color: var(--gray-500);
  margin-top: 8px;
}

/* ===================================
   Extracted Data Cards (Step 2)
   =================================== */

.extracted-sections {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}

.extracted-card {
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-md);
  padding: 16px;
  transition: all 0.2s var(--ease);
}

.extracted-card:hover {
  border-color: var(--blue-300);
  box-shadow: var(--shadow-sm);
}

.extracted-card.empty {
  opacity: 0.5;
}

.extracted-card span:first-child {
  font-size: 24px;
  display: block;
  margin-bottom: 4px;
}

.extracted-card strong {
  font-size: 14px;
  color: var(--gray-900);
  display: block;
  margin-bottom: 8px;
}

.data-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 3px 0;
  font-size: 12px;
  border-bottom: 1px dotted var(--gray-200);
}

.data-key {
  color: var(--gray-600);
  text-transform: capitalize;
}

.data-val {
  font-weight: 600;
  color: var(--gray-900);
  text-align: right;
}

/* ===================================
   Editor Layout (Step 3)
   =================================== */

.editor-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 16px;
  align-items: start;
}

.editor-sidebar {
  position: sticky;
  top: 16px;
  max-height: calc(100vh - 200px);
  overflow-y: auto;
}

.editor-main {
  min-height: 400px;
}

.chapter-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.15s var(--ease);
  margin-bottom: 2px;
  border: 1px solid transparent;
}

.chapter-item:hover {
  background: var(--gray-50);
}

.chapter-item.selected {
  background: var(--blue-50);
  border-color: var(--blue-300);
}

.chapter-status {
  font-size: 14px;
  flex-shrink: 0;
}

.chapter-title {
  flex: 1;
  font-size: 13px;
  font-weight: 500;
  color: var(--gray-800);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chapter-delete {
  background: none;
  border: none;
  color: var(--gray-400);
  cursor: pointer;
  font-size: 16px;
  padding: 0 4px;
  line-height: 1;
  border-radius: 4px;
  transition: all 0.15s;
  opacity: 0;
}

.chapter-item:hover .chapter-delete { opacity: 1; }
.chapter-delete:hover { color: var(--red-500); background: var(--red-100); }

/* ===================================
   Slide Preview (Step 3)
   =================================== */

.slide-preview {
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  margin-bottom: 10px;
}

.slide-preview-header {
  font-size: 13px;
  font-weight: 700;
  color: var(--gray-800);
  margin-bottom: 6px;
}

.slide-elements {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

/* ===================================
   Spinner
   =================================== */

.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  vertical-align: middle;
}

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

/* ===================================
   Responsive – Wizard/Editor
   =================================== */

@media (max-width: 768px) {
  .wizard-steps { flex-wrap: wrap; gap: 4px; }
  .wizard-connector { width: 24px; }
  .editor-layout { grid-template-columns: 1fr; }
  .editor-sidebar { position: static; max-height: none; }
  .extracted-sections { grid-template-columns: 1fr; }
}

/* ===================================
   Calendar Export Panel
   =================================== */

.export-success-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 8px 0;
}

.export-success-icon {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--green-100);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
  animation: exportBounceIn 0.5s var(--ease) both;
}

.export-success-icon svg {
  color: var(--green-500);
}

.export-success-text {
  font-size: 16px;
  font-weight: 700;
  color: var(--gray-900);
  margin-bottom: 4px;
}

.export-success-hint {
  font-size: 13px;
  color: var(--gray-500);
  margin-bottom: 20px;
}

.export-calendar-buttons {
  display: flex;
  gap: 10px;
  width: 100%;
  margin-bottom: 4px;
}

.export-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--duration) var(--ease);
  border: 1px solid var(--gray-200);
}

.export-btn-google {
  background: #f8f9ff;
  color: #1a73e8;
  border-color: #dadce0;
}

.export-btn-google:hover {
  background: #e8f0fe;
  border-color: #1a73e8;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(26, 115, 232, 0.15);
}

.export-btn-apple {
  background: var(--gray-50);
  color: var(--gray-800);
  border-color: var(--gray-300);
}

.export-btn-apple:hover {
  background: var(--gray-100);
  border-color: var(--gray-500);
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

/* ===================================
   Progress bar – variante compatta
   =================================== */

.progress-bar.sm {
  height: 4px;
  display: block;
}

/* ===================================
   Compilazione Guidata Dati (bilancio-form.js)
   =================================== */

.bf-topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.bf-progress-wrap { flex: 1; min-width: 220px; }

.bf-progress-label {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--gray-600);
  margin-bottom: 6px;
}

.bf-progress-label strong { color: var(--gray-900); }

.bf-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 16px;
  align-items: start;
}

.bf-section-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 16px;
}

.bf-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  background: var(--white);
  cursor: pointer;
  text-align: left;
  transition: all var(--duration) var(--ease);
}

.bf-nav-item:hover { background: var(--gray-50); }

.bf-nav-item.active {
  background: var(--blue-50);
  border-color: var(--blue-300);
}

.bf-nav-icon { font-size: 16px; flex-shrink: 0; }

.bf-nav-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.bf-nav-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--gray-800);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bf-nav-pct {
  font-size: 11px;
  font-weight: 600;
  color: var(--gray-500);
  flex-shrink: 0;
}

.bf-panel {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-md);
  padding: 20px;
  min-height: 400px;
}

.bf-panel-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--gray-200);
}

.bf-panel-header h3 { margin: 0; font-size: 16px; color: var(--gray-900); }
.bf-panel-header p { margin: 0; font-size: 12px; color: var(--gray-500); flex-basis: 100%; }

.bf-save-indicator {
  font-size: 11px;
  color: var(--green-500);
  font-weight: 600;
}

/* Indicatore di presenza (editing simultaneo) */
.bf-presence {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  align-items: center;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 8px;
  background: var(--blue-50);
  border: 1px solid var(--blue-200);
}
.bf-presence-editing { color: var(--blue-700); }
.bf-presence-viewing { color: var(--gray-500); font-weight: 500; }

.bf-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px 22px;
}

.bf-field-full { grid-column: 1 / -1; }

/* Leggibilità form: etichetta sopra ogni campo più grande e in grassetto,
   con un po' più di respiro (pensato per utenti meno tecnici). */
.bf-panel .form-label {
  font-size: 15px;
  font-weight: 700;
  color: var(--gray-900);
  margin-bottom: 8px;
}
.bf-panel .form-hint { font-size: 13px; line-height: 1.5; }
.bf-panel .form-group { margin-bottom: 22px; }

.field-with-unit {
  display: flex;
  align-items: center;
  gap: 8px;
}

.field-with-unit .form-input { flex: 1; }

.field-unit {
  font-size: 12px;
  font-weight: 600;
  color: var(--gray-500);
  white-space: nowrap;
}

/* ===================================
   Tabelle ripetibili (campi "table")
   =================================== */

.repeatable-table {
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-md);
  overflow: hidden;
  margin-top: 6px;
}

.repeatable-table-header,
.repeatable-row {
  display: grid;
  grid-template-columns: repeat(var(--bf-cols, 3), 1fr) 32px;
  gap: 8px;
  align-items: center;
  padding: 8px 10px;
}

.repeatable-table-header {
  background: var(--gray-50);
  font-size: 11px;
  font-weight: 700;
  color: var(--gray-600);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.repeatable-row { border-top: 1px solid var(--gray-100); }

.repeatable-row .form-input,
.repeatable-row .form-select {
  padding: 6px 8px;
  font-size: 13px;
}

.bf-row-delete {
  background: none;
  border: none;
  color: var(--gray-400);
  cursor: pointer;
  font-size: 16px;
  border-radius: 4px;
  transition: all 0.15s;
}

.bf-row-delete:hover { color: var(--red-500); background: var(--red-100); }

.bf-field-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.bf-field-clear {
  background: none;
  border: none;
  color: var(--gray-400);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  padding: 0 4px;
  border-radius: 4px;
  transition: all 0.15s;
  flex-shrink: 0;
}

.bf-field-clear:hover { color: var(--red-500); background: var(--red-100); }

.bf-add-row { margin: 10px; }

/* ===================================
   Prompt per Claude Design
   =================================== */

.bf-prompt-card { border: 1px solid var(--blue-200); }

.prompt-output-wrap { display: flex; flex-direction: column; gap: 10px; }

.prompt-output {
  background: var(--gray-900);
  color: var(--gray-100);
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: 12.5px;
  line-height: 1.6;
  padding: 16px;
  border-radius: var(--radius-md);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 480px;
  overflow-y: auto;
  margin: 0;
}

.prompt-output-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ===================================
   Filtri sessioni (Dashboard)
   =================================== */

.session-filters {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.session-filters .form-input { flex: 2; min-width: 200px; margin-bottom: 0; }
.session-filters .form-select { flex: 1; min-width: 160px; margin-bottom: 0; }

@media (max-width: 768px) {
  .bf-layout { grid-template-columns: 1fr; }
  .bf-section-nav { position: static; flex-direction: row; overflow-x: auto; }
  .bf-fields { grid-template-columns: 1fr; }
  .repeatable-table-header,
  .repeatable-row { grid-template-columns: 1fr; }
  .repeatable-table-header span:last-child { display: none; }
}

@keyframes exportBounceIn {
  0% { opacity: 0; transform: scale(0.3); }
  50% { opacity: 1; transform: scale(1.08); }
  70% { transform: scale(0.95); }
  100% { transform: scale(1); }
}

/* ===================================
   Editor Prompt a Blocchi (prompt-editor.js)
   =================================== */

.pe-hero {
  border-radius: var(--radius-lg);
  padding: 28px 24px;
  box-shadow: var(--shadow-md);
  position: relative;
  overflow: hidden;
}

.pe-hero-inner {
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: rgba(15, 20, 30, 0.45);
  backdrop-filter: blur(2px);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  color: #fff;
  width: fit-content;
}

.pe-hero-inner strong { font-size: 20px; }
.pe-hero-inner span { font-size: 13px; opacity: 0.9; }

.pe-preset-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}

.pe-preset-card {
  border: 2px solid var(--gray-200);
  border-radius: var(--radius-md);
  padding: 16px;
  cursor: pointer;
  transition: all var(--duration) var(--ease);
  background: var(--white);
}

.pe-preset-card:hover { border-color: var(--gray-400); transform: translateY(-2px); }

.pe-preset-card.active {
  border-color: var(--blue-600);
  background: var(--blue-50);
  box-shadow: var(--shadow-sm);
}

.pe-preset-card strong { display: block; margin-bottom: 6px; color: var(--gray-900); }
.pe-preset-card p { margin: 0; font-size: 12.5px; color: var(--gray-600); }

.pe-pillars-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.pe-pillar-card {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-md);
  padding: 10px 12px;
}

.pe-pillar-card input[type="color"] {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 8px;
  padding: 0;
  cursor: pointer;
  flex-shrink: 0;
}

.pe-pillar-card .form-input { margin-bottom: 0; }

.pe-blocks {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.pe-block-card {
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-md);
  padding: 14px;
  background: var(--gray-50);
}

.pe-block-title {
  display: block;
  width: 100%;
  border: none;
  background: transparent;
  font-size: 14px;
  font-weight: 700;
  color: var(--gray-900);
  margin-bottom: 8px;
  padding: 0;
}

.pe-block-title:focus { outline: none; text-decoration: underline; }

.pe-block-content {
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: 12.5px;
  line-height: 1.6;
}

/* ===================================
   Accordion (dettagli/riepilogo collassabili)
   =================================== */

.pe-accordion > summary {
  list-style: none;
  justify-content: space-between;
  margin-bottom: 0;
  user-select: none;
}

.pe-accordion > summary::-webkit-details-marker { display: none; }

.pe-accordion > summary::after {
  content: '▸';
  margin-left: auto;
  color: var(--gray-400);
  font-size: 13px;
  transition: transform var(--duration) var(--ease);
  flex-shrink: 0;
}

.pe-accordion[open] > summary::after { transform: rotate(90deg); }
.pe-accordion > summary:hover { color: var(--blue-600); }

/* ── Switcher anni del Bilancio di Mandato ── */
.bf-year-switcher { background: var(--blue-50); border: 1px solid var(--blue-200); border-radius: 12px; padding: 12px 14px; margin-bottom: 16px; }
.bf-year-title { font-weight: 700; color: var(--gray-800); font-size: 0.9rem; margin-bottom: 10px; }
.bf-year-tabs { display: flex; gap: 8px; flex-wrap: wrap; }
.bf-year-tab { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 110px;
  padding: 8px 14px; border: 1px solid var(--gray-300); border-radius: 10px; background: var(--white);
  color: var(--gray-700); cursor: pointer; font-weight: 600; font-size: 0.9rem; transition: all var(--duration) var(--ease); }
.bf-year-tab:hover { border-color: var(--blue-400); }
.bf-year-tab.active { background: var(--blue-600); border-color: var(--blue-600); color: #fff; }
.bf-year-tab small { font-size: 0.72rem; opacity: 0.85; font-weight: 700; }
.bf-year-tab small.ok { color: var(--green-500); }
.bf-year-tab.active small.ok { color: #d1fadf; }

/* ── Precompilazione da fonti pubbliche: toolbar per-sezione e note di provenienza ── */
.bf-prefill-tools { display: flex; gap: 8px; flex-wrap: wrap; margin: 6px 0 2px; }
.bf-prefill-grp { white-space: nowrap; }
.bf-fonte { margin-top: 4px; font-size: 11px; color: var(--gray-500); font-style: italic; }

/* ── Avviso "un altro utente sta importando dati" + form in sola lettura ── */
.bf-presence-importing { color: var(--orange-500); font-weight: 700; }
.bf-import-banner {
  background: var(--orange-100); color: var(--orange-500);
  border: 1px solid var(--orange-500); border-radius: 10px;
  padding: 10px 14px; margin-bottom: 14px; font-weight: 600; font-size: 14px;
}
.bf-import-locked .bf-panel { pointer-events: none; opacity: 0.55; }

/* ── Toast / avvisi integrati (window.showToast, sostituiscono alert) ── */
.toast-container {
  position: fixed; top: 18px; right: 18px; z-index: 4000;
  display: flex; flex-direction: column; gap: 10px;
  max-width: min(92vw, 420px);
}
.toast {
  /* Colori espliciti (non le variabili del tema: --blue-600 è il rosso del brand). */
  --toast-bg: #2563eb;
  display: flex; align-items: flex-start; gap: 10px;
  background: var(--toast-bg); color: #fff;
  border: none; border-radius: 12px; box-shadow: var(--shadow-lg);
  padding: 12px 12px 12px 14px; font-size: 14px; line-height: 1.45; font-weight: 500;
  animation: toastIn .22s var(--ease); white-space: pre-line;
}
.toast.toast-out { animation: toastOut .25s var(--ease) forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateX(20px); } }
.toast-ic {
  flex-shrink: 0; width: 22px; height: 22px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: #fff; color: var(--toast-bg); font-weight: 800; font-size: 13px; margin-top: 1px;
}
.toast-msg { flex: 1; }
.toast-x { background: none; border: none; cursor: pointer; color: rgba(255,255,255,.8); font-size: 20px; line-height: 1; padding: 0 2px; }
.toast-x:hover { color: #fff; }
.toast-success { --toast-bg: #16a34a; }  /* verde: dati caricati, operazione riuscita */
.toast-error   { --toast-bg: #dc2626; }  /* rosso: errore */
.toast-warn    { --toast-bg: #d97706; }  /* arancione: riuscita in parte / attenzione */
.toast-info    { --toast-bg: #2563eb; }  /* blu: notifiche (es. eliminazioni) */

/* ── Modale credenziali (showCredentials) ── */
.cred-modal {
  position: fixed; inset: 0; z-index: 4100;
  background: rgba(15,18,24,.55); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; padding: 24px;
  animation: toastIn .18s var(--ease);
}
.cred-box {
  background: var(--white); border-radius: 16px; box-shadow: var(--shadow-xl);
  width: 100%; max-width: 460px; padding: 22px;
}
.cred-msg { color: var(--gray-800); font-size: 14px; line-height: 1.5; margin-bottom: 14px; white-space: pre-line; }
.cred-row { display: flex; gap: 8px; margin-bottom: 16px; }
.cred-input { flex: 1; font-family: monospace; font-size: 15px; font-weight: 600; }
.cred-copy { white-space: nowrap; }
.cred-actions { display: flex; justify-content: flex-end; }

/* Pulsante azione distruttiva (conferme di eliminazione) */
.btn-danger { background: var(--red-500); color: #fff; border: 1px solid var(--red-500); }
.btn-danger:hover { background: #c53030; border-color: #c53030; }
