:root {
  --bg: #F8F9FA;
  --card: #FFFFFF;
  --sidebar-bg: #FFFFFF;
  --accent: #5B8DEF;
  --accent-hover: #4A7DE0;
  --accent-light: #EBF1FD;
  --success: #48BB78;
  --success-light: #E8F8EE;
  --warning: #D69E2E;
  --warning-light: #FFF8E7;
  --danger: #E53E3E;
  --danger-light: #FEE;
  --info: #5B8DEF;
  --info-light: #EBF5FB;
  --purple: #805AD5;
  --purple-light: #F0EBFA;
  --text: #2D3748;
  --text-light: #718096;
  --text-lighter: #A0AEC0;
  /* Alias mantenuti per coerenza con template che usano nomi alternativi */
  --text-muted: #718096;
  --primary: #5B8DEF;
  --bg-card: #FFFFFF;
  --bg-hover: #F1F5F9;
  --border: #E2E8F0;
  --border-light: #EDF2F7;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.05), 0 2px 4px rgba(0,0,0,0.03);
  --shadow-lg: 0 10px 24px rgba(0,0,0,0.08);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 6px;
  --font: 'Inter', -apple-system, 'SF Pro Display', 'Segoe UI', system-ui, sans-serif;
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

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

/* Sidebar */
.sidebar {
  width: 230px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  padding: 24px 14px;
  position: fixed;
  height: 100vh;
  display: flex;
  flex-direction: column;
  z-index: 100;
  overflow-y: auto;
}

.logo-area {
  padding: 0 8px 20px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.logo-img {
  height: 56px;
  width: auto;
}
.logo-text {
  font-size: 22px;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: -0.5px;
}
.logo-sub {
  font-size: 13px;
  color: var(--text-light);
  font-weight: 500;
}

.nav { flex: 1; padding-top: 8px; }
.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-light);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  transition: all 0.15s;
  margin-bottom: 2px;
}
.nav-link svg { width: 18px; height: 18px; flex-shrink: 0; opacity: 0.7; }
.nav-link:hover { background: var(--bg); color: var(--text); }
.nav-link:hover svg { opacity: 1; }
.nav-link.active { background: var(--accent-light); color: var(--accent); font-weight: 600; }
.nav-link.active svg { opacity: 1; stroke: var(--accent); }
.nav-section {
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-light);
  text-transform: none;
  letter-spacing: 0;
  padding: 9px 12px;
}
.nav-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  transition: background 0.15s;
}
.nav-toggle > svg:first-child { width: 18px; height: 18px; opacity: 0.5; flex-shrink: 0; }
.nav-toggle > span { flex: 1; }
.nav-toggle:hover { background: var(--bg); color: var(--text); }
.nav-toggle:hover > svg:first-child { opacity: 0.8; }
.nav-toggle-arrow { transition: transform 0.2s; flex-shrink: 0; margin-left: auto; }
.nav-toggle.open .nav-toggle-arrow { transform: rotate(90deg); }
.nav-submenu { display: none; overflow: hidden; }
.nav-submenu.open { display: block; }
.nav-link.nav-sub { padding-left: 24px; font-size: 13px; }
.nav-link.nav-sub svg { width: 16px; height: 16px; }

.sidebar-footer {
  padding-top: 4px;
  border-top: 1px solid var(--border-light);
  margin-top: auto;
}
.sidebar-prefs-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-light);
  cursor: pointer;
  transition: color 0.15s;
}
.sidebar-prefs-toggle:hover { color: var(--text); }
.sidebar-prefs-toggle svg:first-child { flex-shrink: 0; }
.prefs-arrow {
  margin-left: auto;
  transition: transform 0.2s;
}
.sidebar-prefs-toggle.open .prefs-arrow { transform: rotate(90deg); }
.sidebar-prefs-toggle.open { color: var(--text); }
.sidebar-prefs-menu {
  display: none;
  padding: 0 0 4px;
}
.sidebar-prefs-menu.open { display: block; }
.sidebar-footer-user {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-top: 1px solid var(--border-light);
}
.user-info {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
  font-weight: 500;
}
.user-info svg { color: var(--text-light); }
.logout-link {
  padding: 4px 10px;
  font-size: 12px;
  color: var(--text-lighter);
  text-decoration: none;
  border-radius: var(--radius-xs);
  transition: background 0.15s, color 0.15s;
}
.logout-link:hover { background: var(--danger-light); color: var(--danger); }

/* Main */
.main {
  margin-left: 230px;
  padding: 18px 24px 36px;
  flex: 1;
  max-width: 1400px;
}

/* Page header */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 28px;
  padding-right: 70px; /* spazio per la campanella notifiche fissa in alto a destra */
}
.page-header h1 {
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.3px;
}
.subtitle {
  color: var(--text-light);
  font-size: 14px;
  margin-top: 2px;
}

/* Stats */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.stat-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}
.stat-icon svg { width: 18px; height: 18px; }
.stat-icon.blue { background: var(--accent-light); color: var(--accent); }
.stat-icon.blue svg { stroke: var(--accent); }
.stat-icon.green { background: var(--success-light); color: var(--success); }
.stat-icon.green svg { stroke: var(--success); }
.stat-icon.orange { background: var(--warning-light); color: var(--warning); }
.stat-icon.orange svg { stroke: var(--warning); }
.stat-icon.purple { background: var(--purple-light); color: var(--purple); }
.stat-icon.purple svg { stroke: var(--purple); }
.stat-icon.teal { background: #E0F7F4; color: #38B2AC; }
.stat-icon.teal svg { stroke: #38B2AC; }
.stat-icon.red { background: var(--danger-light); color: var(--danger); }
.stat-icon.red svg { stroke: var(--danger); }
.stat-val { font-size: 22px; font-weight: 700; color: var(--text); letter-spacing: -0.5px; white-space: nowrap; }
.stat-lbl { font-size: 12px; color: var(--text-light); font-weight: 500; white-space: nowrap; }

/* Cards */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}
.card-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 16px;
}

/* Grid */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

/* Dashboard grid */
.dash-grid {
  display: grid;
  grid-template-columns: 3fr 2fr;
  gap: 16px;
}

/* Tables */
.table-wrap, .table-container { overflow-x: auto; max-width: 100%; }
.table, .data-table { width: 100%; border-collapse: collapse; }
.data-table th { padding: 8px 10px; text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-light); font-weight: 600; border-bottom: 2px solid var(--border); white-space: nowrap; background: var(--card); }
.data-table td { padding: 8px 10px; border-bottom: 1px solid var(--border-light); font-size: 13px; }
.data-table tbody tr:nth-child(even) { background: #F7FAFC; }
.data-table tbody tr:hover { background: #EDF2F7; }
.table th {
  padding: 5px 8px;
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-light);
  font-weight: 600;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
  position: sticky;
  top: 0;
  background: var(--card);
}
.table td {
  padding: 5px 8px;
  border-bottom: 1px solid var(--border-light);
  font-size: 13px;
  white-space: nowrap;
}
.table td.text-light { white-space: normal; }
.table tbody tr { transition: background 0.1s; }
.table tbody tr:nth-child(even) { background: #F7FAFC; }
.table tbody tr:hover { background: #EDF2F7; }
.table tfoot td {
  font-weight: 800;
  font-size: 14px;
  border-top: 2px solid var(--border);
  background: #EDF2F7;
  padding: 12px;
}
.table tbody tr.section-header {
  background: var(--accent-light) !important;
  border-top: 2px solid var(--accent);
}
.table tbody tr.section-header td {
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
  padding: 10px 12px;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}
.table tbody tr.section-header:hover { background: var(--accent-light) !important; cursor: default; }
.table tbody tr.section-subtotal td {
  font-weight: 700;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
  background: #EDF2F7;
  color: var(--text);
}
.turno-ore {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  min-height: 34px;
}
.turno-time {
  padding: 6px 8px !important;
  font-size: 13px !important;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.text-right { text-align: right; white-space: nowrap; }

.btn-print {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: 1px solid var(--accent);
  color: var(--accent);
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  flex-shrink: 0;
}

/* Scheda link badge — pillola coerente in tabelle (Anagrafiche, Sicurezza fornitori) */
.scheda-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  background: var(--accent-light);
  color: var(--accent);
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  text-decoration: none;
  border: 1px solid #C7D2FE;
  transition: background 0.15s;
}
.scheda-link:hover { background: #DDE7FE; }

/* === Toggle a pillole (tabs Attive/Passive, viste, modalità) === */
.sf-vista-toggle, .pill-toggle {
  display: flex; gap: 4px; padding: 4px;
  background: #f1f5f9; border-radius: 10px;
}
.sf-vista-btn, .pill-toggle-btn {
  flex: 1; padding: 8px 12px;
  background: transparent; border: none; border-radius: 7px;
  cursor: pointer; font-weight: 600; font-size: 13px;
  color: var(--text-light); transition: all 0.15s;
  text-align: center;
}
.sf-vista-btn:hover, .pill-toggle-btn:hover { color: var(--text); }
.sf-vista-btn.active, .pill-toggle-btn.active {
  background: #fff; color: var(--accent);
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

/* === Avatar utente (foto o iniziali colorate) === */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px; height: 32px;
  border-radius: 50%;
  color: #fff;
  font-weight: 700;
  font-size: 12px;
  letter-spacing: -0.3px;
  flex-shrink: 0;
  overflow: hidden;
  background: var(--accent);
  user-select: none;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
/* Quando c'è una foto, nascondiamo lo sfondo colorato (no flash arancione durante caricamento) */
.avatar.has-img { background: var(--bg) !important; }
.avatar.avatar-xs { width: 22px; height: 22px; font-size: 9px; }
.avatar.avatar-sm { width: 26px; height: 26px; font-size: 10px; }
.avatar.avatar-md { width: 36px; height: 36px; font-size: 13px; }
.avatar.avatar-lg { width: 64px; height: 64px; font-size: 22px; }
.avatar.avatar-xl { width: 96px; height: 96px; font-size: 32px; }

/* Pop-up notifica nuovo messaggio chat con avatar pulsante */
.chat-popup {
  position: fixed;
  bottom: calc(90px + env(safe-area-inset-bottom, 0px));
  right: 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 28px;
  padding: 8px 16px 8px 8px;
  box-shadow: var(--shadow-lg);
  z-index: 250;
  cursor: pointer;
  max-width: calc(100vw - 48px);
  animation: chatPopupIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.chat-popup .avatar {
  width: 44px; height: 44px;
  font-size: 16px;
  animation: chatPopupPulse 1.2s ease-in-out infinite;
  box-shadow: 0 0 0 0 rgba(91, 141, 239, 0.5);
}
.chat-popup-text { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.chat-popup-name { font-weight: 700; font-size: 13px; color: var(--text); }
.chat-popup-msg {
  font-size: 12px;
  color: var(--text-light);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}
.chat-popup-close {
  background: none;
  border: none;
  color: var(--text-lighter);
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
  padding: 4px;
  margin-left: 4px;
}
.chat-popup-close:hover { color: var(--text); }
@keyframes chatPopupIn {
  from { transform: translateY(20px) scale(0.8); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}
@keyframes chatPopupPulse {
  0% { box-shadow: 0 0 0 0 rgba(91, 141, 239, 0.55), 0 0 0 0 rgba(91, 141, 239, 0); }
  60% { box-shadow: 0 0 0 12px rgba(91, 141, 239, 0), 0 0 0 18px rgba(91, 141, 239, 0); }
  100% { box-shadow: 0 0 0 0 rgba(91, 141, 239, 0), 0 0 0 0 rgba(91, 141, 239, 0); }
}
@media (max-width: 576px) {
  .chat-popup { right: 8px; left: 8px; bottom: calc(80px + env(safe-area-inset-bottom, 0px)); border-radius: 18px; }
  .chat-popup-msg { max-width: none; flex: 1; }
}

/* ── Utility classes per ridurre stili inline (Sicurezza + altri) ── */
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.flex-row { display: flex; align-items: center; gap: 8px; }
.flex-row-end { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.flex-col { display: flex; flex-direction: column; gap: 8px; }
.flex-wrap { flex-wrap: wrap; }

.text-helper { font-size: 11px; color: var(--text-lighter); }
.text-small { font-size: 12px; }
.text-tiny { font-size: 11px; }

.alert-box { padding: 12px 14px; border-radius: var(--radius-sm); margin-bottom: 12px; }
.alert-box.alert-danger { background: var(--danger-light); border: 1px solid #FCA5A5; }
.alert-box.alert-danger strong { color: var(--danger); }
.alert-box.alert-warning { background: var(--warning-light); border: 1px solid #FCD34D; }
.alert-box.alert-warning strong { color: var(--warning); }
.alert-box.alert-success { background: var(--success-light); border: 1px solid #BBF7D0; }
.alert-box.alert-success strong { color: var(--success); }
.alert-box.alert-info { background: var(--info-light); border: 1px solid #BFDBFE; }
.alert-box.alert-info strong { color: var(--info); }

/* Riepilogo verticale (label + valore in righe) — usato in modali costo */
.recap-box { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 16px; margin-bottom: 16px; }
.recap-row { display: flex; justify-content: space-between; padding: 5px 0; font-size: 14px; }
.recap-row.tot { border-top: 1px solid var(--border-light); margin-top: 4px; padding-top: 8px; }
.btn-print:hover {
  background: var(--accent);
  color: #fff;
}
@media print { .btn-print { display: none; } }

/* Badges */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.3px;
}
.badge-bozza { background: var(--border-light); color: var(--text-light); }
.badge-da-fatturare, .badge-da_fatturare { background: var(--warning-light); color: var(--warning); }
.badge-emessa { background: var(--info-light); color: var(--info); }
.badge-pagata { background: var(--success-light); color: var(--success); }
.badge-annullata { background: var(--danger-light); color: var(--danger); }
.badge-pianificato { background: var(--border-light); color: var(--text-light); }
.badge-confermato { background: var(--accent-light); color: var(--accent); }
.badge-in-corso { background: var(--warning-light); color: var(--warning); }
.badge-completato { background: var(--success-light); color: var(--success); }
.badge-fornitore { background: var(--accent-light); color: var(--accent); }
.badge-sponsor { background: var(--purple-light); color: var(--purple); }
.badge-servizio { background: var(--success-light); color: var(--success); }
.badge-noleggio { background: var(--warning-light); color: var(--warning); }
.badge-consulenza { background: #FFF0F5; color: #D53F8C; }
.badge-sicurezza { background: var(--danger-light); color: var(--danger); }
.badge-beverage { background: #E0F7FA; color: #00838F; }
.badge-ente { background: #E8EAF6; color: #3949AB; }
.badge-facchinaggio { background: #FFF3E0; color: #E65100; }
.badge-food { background: #FBE9E7; color: #BF360C; }
.badge-ingegneria { background: #E3F2FD; color: #1565C0; }
.badge-ticketing { background: #F3E5F5; color: #7B1FA2; }
.badge-altro { background: var(--border-light); color: var(--text-light); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-success { background: var(--success-light); color: var(--success); }
.badge-info { background: var(--info-light); color: var(--info); }
.badge-in-trattativa { background: var(--warning-light); color: var(--warning); }
.badge-da-fatturare { background: var(--info-light); color: var(--info); }
.badge-fatturato { background: var(--success-light); color: var(--success); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: all 0.15s;
  font-family: inherit;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); box-shadow: var(--shadow-md); }
.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border-light); }
.btn-danger { background: var(--danger-light); color: var(--danger); }
.btn-danger:hover { background: #FCC; }
.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-full { width: 100%; justify-content: center; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Action buttons in tables */
.actions { display: flex; gap: 4px; justify-content: flex-end; }
.action-btn {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-xs);
  border: none;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-light);
  transition: all 0.15s;
}
.action-btn:hover { background: var(--bg); color: var(--text); }
.action-btn.delete:hover { background: var(--danger-light); color: var(--danger); }
.action-btn.paid { color: var(--success); }
.action-btn.paid:hover { background: var(--success-light); color: var(--success); }
.action-btn svg { width: 15px; height: 15px; }

/* Forms */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-light);
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.input, select, textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: var(--card);
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
}
.input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(91,141,239,0.12);
}
textarea { min-height: 80px; resize: vertical; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }

/* Filters */
.filters {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.filters .input, .filters select { width: auto; min-width: 180px; flex: 1; }

/* Tipo accordo selector */
.tipo-selector { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; margin-bottom: 20px; }
.tipo-option {
  padding: 14px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  text-align: center;
  transition: all 0.15s;
}
.tipo-option:hover { border-color: var(--accent); background: var(--accent-light); }
.tipo-option.active { border-color: var(--accent); background: var(--accent-light); }
.tipo-option .tipo-name { font-weight: 600; font-size: 14px; color: var(--text); }
.tipo-option .tipo-desc { font-size: 11px; color: var(--text-light); margin-top: 2px; }

/* Preview calculation */
.calc-preview {
  background: #F7FAFC;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 16px;
  margin-top: 16px;
}
.calc-row { display: flex; justify-content: space-between; padding: 4px 0; font-size: 13px; }
.calc-row.total { font-weight: 700; font-size: 15px; border-top: 2px solid var(--border); padding-top: 8px; margin-top: 4px; }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 60px;
  overflow-y: auto;
}
.modal {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 680px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  animation: modalIn 0.2s ease;
}
@keyframes modalIn { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-light);
}
.modal-header h2 { font-size: 17px; font-weight: 600; }
.modal-close {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-xs);
  border: none;
  background: transparent;
  font-size: 20px;
  cursor: pointer;
  color: var(--text-light);
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-close:hover { background: var(--bg); }
.modal-body { padding: 24px; overflow-y: auto; flex: 1; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }
.hidden { display: none !important; }

/* Toast */
#toast-container { position: fixed; bottom: 20px; right: 20px; z-index: 2000; display: flex; flex-direction: column; gap: 8px; }
.toast {
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  animation: toastIn 0.25s ease, toastOut 0.25s ease 2.5s forwards;
  max-width: 360px;
}
.toast-success { background: var(--success); color: #fff; }
.toast-error { background: var(--danger); color: #fff; }
.toast-info { background: var(--accent); color: #fff; }
@keyframes toastIn { from { opacity: 0; transform: translateX(20px); } }
@keyframes toastOut { to { opacity: 0; transform: translateX(20px); } }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 40px;
  color: var(--text-lighter);
  font-size: 14px;
}

/* Alerts */
.alert { padding: 12px 16px; border-radius: var(--radius-sm); font-size: 13px; margin-bottom: 16px; }
.alert-error { background: var(--danger-light); color: var(--danger); border: 1px solid #FCC; }
.alert-success { background: var(--success-light); color: #276749; border: 1px solid #C6F6D5; }

/* Summary grid */
.summary-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; }
.aging-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 16px; }
.aging-cell { padding: 10px; border-radius: 8px; border: 1px solid; text-align: center; }
.aging-cell .v { font-size: 18px; font-weight: 700; }
.aging-cell .l { font-size: 11px; }
.aging-cell.danger { background: var(--danger-light); border-color: #FECACA; }
.aging-cell.danger .v { color: var(--danger); }
.aging-cell.danger .l { color: #991B1B; }
.aging-cell.warning { background: var(--warning-light); border-color: #FED7AA; }
.aging-cell.warning .v { color: #EA580C; }
.aging-cell.warning .l { color: #9A3412; }
.aging-cell.danger-dark { background: #FFF1F0; border-color: #FED7AA; }
.aging-cell.danger-dark .v { color: #B91C1C; }
.aging-cell.danger-dark .l { color: #7F1D1D; }
.aging-cell.success { background: var(--success-light); border-color: #BBF7D0; }
.aging-cell.success .v { color: var(--success); }
.aging-cell.success .l { color: #166534; }
.aging-cell.info { background: var(--bg); border-color: var(--border); }
.aging-cell.info .v { font-size: 14px; color: #475569; }
.aging-cell.info .l { color: var(--text-light); }
@media (max-width: 768px) {
  .aging-grid { grid-template-columns: 1fr 1fr; }
  /* Le griglie inline 3-cols/2-cols nelle dashboard si comprimono su mobile */
  .section-grid { grid-template-columns: 1fr !important; }
}
.summary-item { display: flex; flex-direction: column; align-items: center; padding: 12px 8px; background: var(--bg); border-radius: var(--radius-sm); text-align: center; }
.summary-label { font-size: 12px; color: var(--text-light); margin-top: 4px; }
.summary-value { font-size: 20px; font-weight: 700; }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-danger { color: var(--danger); }
.text-info { color: var(--info); }
.text-light { color: var(--text-light); }

/* File upload */
.file-upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 30px;
  text-align: center;
  cursor: pointer;
  transition: all 0.15s;
  position: relative;
}
.file-upload-area:hover { border-color: var(--accent); background: var(--accent-light); }
.file-input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.file-upload-label { display: flex; flex-direction: column; align-items: center; gap: 8px; color: var(--text-light); }
.file-upload-label svg { color: var(--text-lighter); }

/* Login */
.login-body {
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}
.login-container { width: 100%; max-width: 380px; padding: 20px; }
.login-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px 32px;
  box-shadow: var(--shadow-md);
}
.login-logo {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 28px;
  justify-content: center;
}
.login-form .form-group { margin-bottom: 18px; }

/* Currency format */
.currency::before { content: '\20AC '; }

/* Responsive */
/* Mobile hamburger */
.mobile-header {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 56px;
  background: var(--sidebar-bg);
  border-bottom: 1px solid var(--border);
  z-index: 200;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
}
.mobile-header .logo-img { height: 32px; }
.mobile-header .logo-sub { font-size: 12px; color: var(--text-light); }
.hamburger {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  background: none; border: none; cursor: pointer;
  border-radius: var(--radius-xs);
}
.hamburger:active { background: var(--border-light); }
.hamburger svg { width: 22px; height: 22px; stroke: var(--text); }
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 150;
}
.sidebar-overlay.open { display: block; }

/* === BLOCCA SCROLL ORIZZONTALE === */
html { overflow-y: auto; }
body { width: 100%; overflow-x: hidden; }

/* === TABLET (iPad) === */
/* === LAPTOP MEDIO (1281-1600px): nasconde colonne ridondanti per evitare scroll orizzontale === */
@media (max-width: 1600px) {
  .table .hide-laptop { display: none; }
  .table th.hide-laptop { display: none; }
  /* Compatta padding celle */
  .table th, .table td { padding: 8px 8px; }
  /* Riduci spaziatura azioni */
  .actions { gap: 2px; }
  .action-btn { padding: 5px; }
}

@media (max-width: 1280px) {
  .mobile-header { display: flex; }
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 200;
  }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; padding: 68px 20px 24px; max-width: 100%; }
  .page-header { flex-direction: column; gap: 10px; padding-right: 0; }
  .page-header h1 { font-size: 22px; }
  .stats { grid-template-columns: 1fr 1fr; gap: 12px; }
  .stat-card { padding: 16px; }
  .stat-val { font-size: 22px; }
  .stat-lbl { font-size: 11px; }
  .grid-2 { grid-template-columns: 1fr; }
  .dash-grid { grid-template-columns: 1fr 1fr; }
  .filters { flex-wrap: wrap; }
  .filters .input, .filters select { min-width: 140px; }
  .card { overflow: visible; position: relative; }
  .table-wrap { margin: 0; padding: 0; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table-wrap::after { content: ''; position: sticky; right: 0; top: 0; bottom: 0; width: 30px; pointer-events: none; background: linear-gradient(to right, transparent, rgba(255,255,255,0.8)); display: block; margin-top: -100%; float: right; height: 100%; }
  .table { min-width: 900px; }
  .table th, .table td { font-size: 13px; padding: 8px 6px; }
  .table .hide-tablet { display: none; }
  .table th.hide-tablet { display: none; }
  .actions .edit-btn { display: none; }
}

/* === MOBILE (iPhone) === */
@media (max-width: 576px) {
  .main { padding: 60px 10px 16px; }
  .page-header h1 { font-size: 18px; }
  .subtitle { font-size: 11px; }

  /* Tap target minimo 40px su mobile per pulsanti principali */
  .btn { min-height: 36px; }
  .btn-sm { min-height: 32px; padding: 6px 10px; }
  /* Le icone-only btn-sm restano compatte (non forzo larghezza) */

  /* Stats: 2 colonne compatte */
  .stats { grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
  .stat-card { padding: 10px; border-radius: var(--radius-sm); }
  .stat-icon { width: 26px; height: 26px; }
  .stat-icon svg { width: 13px; height: 13px; }
  .stat-val { font-size: 14px; letter-spacing: -0.3px; }
  .stat-lbl { font-size: 9px; overflow: hidden; text-overflow: ellipsis; }

  /* Card e grafici */
  .card { padding: 4px; border-radius: var(--radius-sm); overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .card-title { font-size: 13px; margin-bottom: 10px; }
  .dash-grid { grid-template-columns: 1fr; }

  /* Filtri impilati */
  .filters { flex-direction: column; gap: 6px; margin-bottom: 10px; }
  .filters .input, .filters select { width: 100%; min-width: 0; font-size: 13px; padding: 8px 10px; }

  /* Tabelle mobile */
  .table-wrap { margin: 0 -2px; padding: 0; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table { width: 100%; table-layout: auto; min-width: 360px; }
  .table th { padding: 4px 3px; font-size: 9px; letter-spacing: 0.2px; }
  .table td { padding: 6px 3px; font-size: 12px; }
  .table td.text-right { white-space: nowrap; font-size: 9px; letter-spacing: -0.5px; }
  .table tfoot td { padding: 6px 3px; font-size: 12px; }
  .table tbody tr.section-header td { font-size: 12px; padding: 8px 6px; }
  .table tbody tr.section-subtotal td { font-size: 11px; padding: 6px 4px; }

  /* Nascondi colonne su mobile: Tipo, IVA, Note, Costo */
  .table .hide-mobile { display: none; }
  .table .hide-mobile-actions { display: none; }
  .table th.hide-mobile-actions { display: none; }

  /* Badge compatto su mobile */
  .badge { font-size: 9px; padding: 2px 6px; }

  /* Azioni: solo delete, nascondi edit */
  .btn { padding: 7px 12px; font-size: 11px; }
  .actions { gap: 0; flex-wrap: nowrap; }
  .actions button { width: 26px; height: 26px; min-width: 26px; }
  .actions button svg { width: 12px; height: 12px; }
  .actions .edit-btn { display: none; }

  /* Form nel modal */
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .modal-overlay { padding-top: 10px; align-items: flex-start; }
  .modal { max-width: 100vw; margin: 0; border-radius: var(--radius-sm) var(--radius-sm) 0 0; max-height: 95vh; }
  .modal-body { padding: 12px; }
  .modal-header { padding: 10px 12px; }
  .modal-header h2 { font-size: 15px; }

  /* Tipo selector compatto */
  .tipo-selector { grid-template-columns: 1fr 1fr; gap: 6px; }
  .tipo-option { padding: 8px 6px; }
  .tipo-name { font-size: 11px; }
  .tipo-desc { font-size: 9px; }

  /* Summary grid */
  .summary-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .summary-item { padding: 8px; }
  .summary-label { font-size: 10px; }
  .summary-value { font-size: 14px; }

  /* Sidebar */
  .sidebar { width: 260px; }
  .sidebar-footer { padding: 10px 8px; font-size: 12px; }

  /* Toast in basso al centro */
  #toast-container { right: 10px; left: 10px; bottom: 10px; }
  .toast { font-size: 12px; padding: 10px 14px; }
}

/* Scheda Azienda */
.scheda-azienda { display: flex; flex-direction: column; gap: 24px; }
.scheda-section { }
.scheda-section-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; border-bottom: 1px solid var(--border-light); padding-bottom: 8px; }
.scheda-section-header h3 { margin: 0; font-size: 15px; font-weight: 600; color: var(--text); }
.scheda-row { display: flex; padding: 6px 0; border-bottom: 1px solid var(--border-light); }
.scheda-row:last-child { border-bottom: none; }
.scheda-label { flex: 0 0 160px; font-size: 13px; color: var(--text-light); font-weight: 500; }
.scheda-value { font-size: 13px; color: var(--text); flex: 1; }
.btn-sm { padding: 4px 12px; font-size: 12px; }
.referente-card { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; background: var(--bg); border-radius: var(--radius-sm); margin-bottom: 6px; }
.referente-info { flex: 1; }
.referente-info strong { font-size: 13px; }
.referente-contacts { display: flex; gap: 16px; font-size: 12px; color: var(--text-light); margin-top: 2px; }
.table-sm { font-size: 13px; }
.table-sm td, .table-sm th { padding: 6px 8px; }

/* Calendario */
.cal-toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; flex-wrap: wrap; gap: 12px; }
.cal-nav { display: flex; align-items: center; gap: 8px; }
.cal-month-title { margin: 0; font-size: 18px; font-weight: 700; min-width: 180px; text-align: center; }
.cal-filters { display: flex; gap: 8px; }
.cal-legend { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; font-size: 12px; color: var(--text-light); }
.cal-legend-item { display: flex; align-items: center; gap: 4px; }
.cal-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.cal-dot-lg { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; display: inline-block; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border-bottom: 1px solid var(--border-light); }
.cal-header { padding: 8px 4px; text-align: center; font-size: 11px; font-weight: 600; text-transform: uppercase; color: var(--text-light); letter-spacing: 0.5px; }
.cal-header.cal-weekend { color: var(--text-lighter); }
.cal-days { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.cal-day { min-height: 90px; min-width: 0; border: 1px solid var(--border-light); border-top: none; border-left: none; padding: 4px; position: relative; }
.cal-day:nth-child(7n+1) { border-left: 1px solid var(--border-light); }
.cal-day:nth-child(-n+7) { border-top: 1px solid var(--border-light); }
.cal-day-empty { background: var(--bg); }
.cal-day-weekend { background: #FAFBFC; }
.cal-day-oggi { background: var(--accent-light); }
.cal-day-oggi .cal-day-num { color: var(--accent); font-weight: 700; }
.cal-day-num { font-size: 12px; font-weight: 500; color: var(--text-light); padding: 2px 4px; }
.cal-day-events { display: flex; flex-direction: column; gap: 2px; margin-top: 2px; }
.cal-event { padding: 2px 4px; border-radius: 3px; cursor: pointer; background: #fff; transition: background 0.15s; overflow: hidden; }
.cal-event:hover { background: var(--bg); }
.cal-event-scaduta { background: var(--danger-light); }
.cal-event-text { font-size: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; color: var(--text); }
.cal-event-more { font-size: 10px; color: var(--accent); cursor: pointer; padding: 2px 4px; font-weight: 500; }
.cal-event-more:hover { text-decoration: underline; }
.cal-detail { text-align: center; }
.cal-detail-tipo { display: flex; align-items: center; justify-content: center; gap: 6px; font-size: 12px; color: var(--text-light); text-transform: uppercase; letter-spacing: 0.5px; }
.cal-detail-data { font-size: 14px; color: var(--text-light); }
.cal-all-events { display: flex; flex-direction: column; gap: 8px; }
.cal-event-list-item { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--bg); border-radius: var(--radius-sm); cursor: pointer; transition: background 0.15s; }
.cal-event-list-item:hover { background: var(--border-light); }

/* Allegati */
/* Import documenti dropzone */
.import-dropzone { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 48px 24px; border: 2px dashed var(--border); border-radius: var(--radius); transition: all 0.2s; cursor: default; }
.import-dropzone.dragover { border-color: var(--accent); background: var(--accent-light); }
.tipo-doc-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.spinner { width: 40px; height: 40px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Allegati dropzone */
.allegati-dropzone { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 14px; margin-bottom: 10px; border: 2px dashed var(--border); border-radius: var(--radius-sm); color: var(--text-lighter); font-size: 13px; transition: all 0.2s; cursor: default; }
.allegati-dropzone svg { color: var(--text-lighter); flex-shrink: 0; }
.allegati-dropzone.dragover { border-color: var(--accent); background: var(--accent-light); color: var(--accent); }
.allegati-dropzone.dragover svg { color: var(--accent); }
.allegati-dropzone.uploading { border-color: var(--accent); border-style: solid; padding: 10px 14px; }
.upload-progress-info { display: flex; justify-content: space-between; align-items: center; width: 100%; margin-bottom: 6px; }
.upload-filename { font-size: 12px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 80%; }
.upload-percent { font-size: 13px; font-weight: 700; color: var(--accent); flex-shrink: 0; }
.upload-progress-bar { width: 100%; height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; }
.upload-progress-fill { height: 100%; background: var(--accent); border-radius: 3px; transition: width 0.15s ease; }

.allegato-item { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: var(--radius-xs); background: var(--bg); margin-bottom: 4px; }
.allegato-link { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--text); flex: 1; min-width: 0; }
.allegato-link:hover .allegato-name { color: var(--accent); }
.allegato-ext { display: inline-flex; align-items: center; justify-content: center; min-width: 36px; height: 22px; border-radius: 4px; font-size: 9px; font-weight: 700; text-transform: uppercase; background: var(--accent-light); color: var(--accent); letter-spacing: 0.5px; flex-shrink: 0; }
.allegato-name { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: color 0.15s; }
.allegato-date { font-size: 11px; color: var(--text-lighter); flex-shrink: 0; }
.allegato-item .action-btn { width: 24px; height: 24px; flex-shrink: 0; }

/* Maps button */
.maps-btn { color: var(--success) !important; }
.maps-btn:hover { color: #2d8a4e !important; }

/* Allegato button in table rows */
.allegato-btn { color: var(--accent) !important; position: relative; }
.allegato-btn:hover { color: var(--accent-hover, #4a7de0) !important; }
.allegato-count { position: absolute; top: -4px; right: -4px; background: var(--accent); color: #fff; font-size: 9px; font-weight: 700; width: 15px; height: 15px; border-radius: 50%; display: flex; align-items: center; justify-content: center; line-height: 1; }
.allegato-dropdown-wrap .allegato-dropdown { display: none; position: absolute; right: 0; top: 100%; z-index: 100; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: var(--shadow); min-width: 200px; max-width: 300px; padding: 4px 0; }
.allegato-dropdown-wrap.open .allegato-dropdown { display: block; }
.allegato-dropdown-item { display: block; padding: 6px 12px; font-size: 12px; color: var(--text); text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.allegato-dropdown-item:hover { background: var(--bg); color: var(--accent); }

/* Chat */
.chat-fab { position: fixed; bottom: 24px; right: 24px; width: 56px; height: 56px; border-radius: 50%; background: var(--accent); color: #fff; border: none; cursor: pointer; box-shadow: 0 4px 12px rgba(91,141,239,.4); z-index: 200; display: flex; align-items: center; justify-content: center; transition: transform .15s, box-shadow .15s; }
.chat-fab:hover { transform: scale(1.08); box-shadow: 0 6px 20px rgba(91,141,239,.5); }
.chat-fab.pulse { animation: chatPulse 1.5s ease-in-out infinite; }
@keyframes chatPulse {
  0%, 100% { transform: scale(1); box-shadow: 0 4px 12px rgba(91,141,239,.4); }
  25% { transform: scale(1.18); box-shadow: 0 0 0 8px rgba(91,141,239,.25), 0 4px 12px rgba(91,141,239,.4); }
  50% { transform: scale(1); box-shadow: 0 4px 12px rgba(91,141,239,.4); }
  75% { transform: scale(1.12); box-shadow: 0 0 0 5px rgba(91,141,239,.15), 0 4px 12px rgba(91,141,239,.4); }
}
.chat-badge { position: absolute; top: -2px; right: -2px; background: var(--danger); color: #fff; font-size: 10px; font-weight: 700; min-width: 18px; height: 18px; border-radius: 9px; display: flex; align-items: center; justify-content: center; padding: 0 5px; line-height: 1; }
.chat-panel { position: fixed; bottom: 90px; right: 24px; width: 380px; max-height: 70vh; background: var(--card); border-radius: var(--radius); box-shadow: 0 8px 30px rgba(0,0,0,.15); z-index: 200; display: none; flex-direction: column; overflow: hidden; }
.chat-panel.open { display: flex; }
.chat-header { background: var(--accent); color: #fff; padding: 14px 16px; display: flex; align-items: center; font-weight: 600; font-size: 15px; gap: 10px; }
.chat-header > span:first-child { white-space: nowrap; }
.chat-online-indicator { flex: 1; font-size: 11px; font-weight: 400; opacity: .9; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; align-items: center; gap: 5px; }
.online-dot { width: 7px; height: 7px; border-radius: 50%; background: #48BB78; display: inline-block; flex-shrink: 0; box-shadow: 0 0 4px rgba(72,187,120,.6); }
.chat-close { background: none; border: none; color: #fff; font-size: 22px; cursor: pointer; line-height: 1; opacity: .8; flex-shrink: 0; }
.chat-close:hover { opacity: 1; }
.chat-messages { flex: 1; overflow-y: auto; padding: 12px; background: var(--bg); min-height: 250px; max-height: 50vh; display: flex; flex-direction: column; gap: 6px; }
.chat-msg { max-width: 80%; padding: 8px 12px; border-radius: 12px; font-size: 13px; line-height: 1.4; word-break: break-word; }
.chat-msg.mine { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.chat-msg.other { align-self: flex-start; background: var(--card); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.chat-msg-user { font-size: 11px; font-weight: 700; color: var(--accent); margin-bottom: 2px; }
.chat-msg-text { white-space: pre-wrap; }
.chat-msg-time { font-size: 10px; opacity: .6; margin-top: 3px; text-align: right; }
.chat-msg.mine .chat-msg-time { color: rgba(255,255,255,.7); }
.chat-msg-file { display: flex; align-items: center; gap: 6px; margin-top: 4px; padding: 4px 8px; background: rgba(0,0,0,.05); border-radius: 6px; text-decoration: none; font-size: 12px; color: inherit; }
.chat-msg.mine .chat-msg-file { background: rgba(255,255,255,.15); color: #fff; }
.chat-msg-file:hover { background: rgba(0,0,0,.1); }
.chat-msg.mine .chat-msg-file:hover { background: rgba(255,255,255,.25); }
.chat-msg-file .allegato-ext { font-size: 8px; min-width: 28px; height: 18px; }
.chat-input-area { display: flex; align-items: center; gap: 6px; padding: 10px 12px; border-top: 1px solid var(--border); background: var(--card); }
.chat-input { flex: 1; border: 1px solid var(--border); border-radius: 20px; padding: 8px 14px; font-size: 13px; font-family: inherit; outline: none; transition: border-color .15s; }
.chat-input:focus { border-color: var(--accent); }
.chat-attach-btn { cursor: pointer; color: var(--text-light); display: flex; align-items: center; padding: 4px; border-radius: 50%; transition: color .15s; }
.chat-attach-btn:hover { color: var(--accent); }
.chat-send-btn { background: var(--accent); color: #fff; border: none; border-radius: 50%; width: 34px; height: 34px; display: flex; align-items: center; justify-content: center; cursor: pointer; flex-shrink: 0; transition: background .15s; }
.chat-send-btn:hover { background: var(--accent-hover, #4a7de0); }
@media (max-width: 768px) {
  /* FAB: rispetta safe-area iOS (home bar) */
  .chat-fab {
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    right: 16px;
    width: 52px;
    height: 52px;
  }
  /* Pannello chat: usa dvh (dynamic viewport height) per gestire tastiera iOS */
  .chat-panel {
    left: 8px;
    right: 8px;
    bottom: calc(80px + env(safe-area-inset-bottom, 0px));
    width: auto;
    max-height: 75vh;
    max-height: 75dvh;
  }
  .chat-messages {
    min-height: 180px;
    max-height: 55vh;
    max-height: 55dvh;
    padding: 10px;
    font-size: 14px;
  }
  /* font-size 16px evita il pinch-zoom automatico iOS al focus */
  .chat-input {
    font-size: 16px;
    padding: 10px 14px;
  }
  .chat-send-btn { width: 38px; height: 38px; }
  .chat-attach-btn { padding: 8px; }
  .chat-header { padding: 12px 14px; font-size: 14px; }
  .chat-close { font-size: 26px; padding: 0 4px; }
  .chat-input-area { padding: 10px 10px calc(10px + env(safe-area-inset-bottom, 0px)); }
}
@media (max-width: 576px) {
  /* iPhone piccoli: ridotto ulteriormente */
  .chat-messages { min-height: 140px; max-height: 50dvh; }
  .chat-panel { max-height: 70dvh; }
  /* Spazio sotto il contenuto per non essere coperto dal FAB */
  .main { padding-bottom: calc(90px + env(safe-area-inset-bottom, 0px)) !important; }
}
