/* ═══════════════════════════════════════════════════════════════════════════
   SCADENZIARIO POLIZZE — Light Theme (Static deployment)
   ═══════════════════════════════════════════════════════════════════════════ */

/* ─── Login Overlay ─────────────────────────────────────────────────────── */
.login-overlay {
  position: fixed; inset: 0; z-index: 9999;
  background: linear-gradient(135deg, #1e3a5f 0%, #2a5298 50%, #0f1d30 100%);
  display: flex; align-items: center; justify-content: center; padding: 1rem;
}
.login-overlay.hidden { display: none; }
.login-box {
  background: white; border-radius: 20px; padding: 2.5rem 2rem;
  width: 100%; max-width: 400px; box-shadow: 0 25px 60px rgba(0,0,0,0.3);
  text-align: center; animation: loginAppear 0.5s ease;
}
@keyframes loginAppear {
  from { opacity: 0; transform: translateY(30px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.login-box .lock-icon { font-size: 3rem; margin-bottom: 0.8rem; }
.login-box h2 { font-size: 1.5rem; font-weight: 700; color: #1e3a5f; margin-bottom: 0.3rem; }
.login-box p { color: #6b7280; font-size: 0.9rem; margin-bottom: 1.5rem; }
.login-box input {
  width: 100%; height: 50px; padding: 0 1rem; font-size: 1rem; font-family: inherit;
  border: 2px solid #e5e7eb; border-radius: 12px; outline: none; margin-bottom: 1rem;
  transition: all 0.25s ease;
}
.login-box input:focus { border-color: #3b82f6; box-shadow: 0 0 0 3px rgba(59,130,246,0.15); }
.login-box button {
  width: 100%; height: 50px; border: none; border-radius: 12px;
  background: linear-gradient(135deg, #1e3a5f, #2a5298); color: white;
  font-size: 1rem; font-weight: 600; font-family: inherit; cursor: pointer;
  transition: all 0.25s ease;
}
.login-box button:hover { filter: brightness(1.1); transform: translateY(-1px); }
.login-error { color: #ef4444; font-size: 0.85rem; margin-top: 0.8rem; display: none; }
.login-error.show { display: block; animation: shake 0.3s ease; }
@keyframes shake { 0%,100%{transform:translateX(0)} 25%{transform:translateX(-6px)} 75%{transform:translateX(6px)} }
.login-back { display: block; margin-top: 1.2rem; color: #6b7280; font-size: 0.85rem; text-decoration: none; }
.login-back:hover { color: #1e3a5f; }

/* Loading overlay */
.loading-overlay {
  position: fixed; inset: 0; z-index: 9998;
  background: rgba(248,250,252,0.9); backdrop-filter: blur(4px);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 16px;
}
.loading-overlay.hidden { display: none; }
.spinner {
  width: 40px; height: 40px; border: 3px solid #e2e8f0;
  border-top-color: #4f46e5; border-radius: 50%; animation: spin 0.8s linear infinite;
}
.loading-overlay p { font-size: 14px; color: #64748b; font-weight: 500; }

.btn { padding: 7px 14px; border: 1px solid var(--border-color); border-radius: var(--radius-sm); font-size: 13px; font-family: inherit; cursor: pointer; transition: all 0.2s ease; background: var(--bg-card); color: var(--text-secondary); }
.btn:hover { border-color: var(--accent-primary); color: var(--accent-primary); }
.btn-icon { padding: 6px 12px; font-size: 14px; }
.btn-secondary { background: #f1f5f9; }
:root {
  /* Colors — Light palette */
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --bg-card-hover: #f1f5f9;
  --bg-glass: rgba(255, 255, 255, 0.85);

  --border-color: #e2e8f0;
  --border-hover: #818cf8;
  --border-glass: #f1f5f9;

  --text-primary: #1e293b;
  --text-secondary: #475569;
  --text-muted: #94a3b8;

  --accent-primary: #4f46e5;
  --accent-secondary: #7c3aed;
  --accent-gradient: linear-gradient(135deg, #4f46e5 0%, #7c3aed 50%, #a78bfa 100%);

  --success: #059669;
  --warning: #d97706;
  --danger: #dc2626;
  --info: #2563eb;

  --alert-bg: #fef3c7;
  --chart-grid: rgba(79, 70, 229, 0.08);

  /* Layout */
  --sidebar-width: 250px;
  --topbar-height: 60px;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;

  /* Shadows - Minimalist Flat */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.02);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.03);
  --shadow-lg: 0 10px 15px rgba(0,0,0,0.04);
  --shadow-glow: 0 0 16px rgba(79, 70, 229, 0.08);
}

/* ─── Reset & Base ──────────────────────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  display: flex;
  min-height: 100vh;
  overflow-x: hidden;
  line-height: 1.6;
}

::selection { background: var(--accent-primary); color: white; }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ─── Sidebar ───────────────────────────────────────────────────────────── */

.sidebar {
  width: var(--sidebar-width);
  height: 100vh;
  position: fixed;
  top: 0; left: 0;
  z-index: 100;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: var(--shadow-sm);
}

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

.logo { display: flex; align-items: center; gap: 12px; }
.logo-icon { font-size: 28px; }

.logo-title {
  font-size: 17px;
  font-weight: 700;
  display: block;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.logo-subtitle {
  font-size: 11px;
  color: var(--text-muted);
  display: block;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.nav-links { list-style: none; padding: 12px 10px; flex: 1; }
.nav-links li { margin-bottom: 2px; }

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s ease;
  position: relative;
}

.nav-link::before {
  content: '';
  position: absolute;
  left: 0; top: 50%;
  transform: translateY(-50%) scaleY(0);
  width: 3px; height: 60%;
  background: var(--accent-gradient);
  border-radius: 0 4px 4px 0;
  transition: transform 0.2s ease;
}

.nav-link:hover { color: var(--text-primary); background: #f1f5f9; }
.nav-link.active { color: var(--accent-primary); background: #eef2ff; font-weight: 600; }
.nav-link.active::before { transform: translateY(-50%) scaleY(1); }

.nav-icon { font-size: 18px; }

.sidebar-footer {
  padding: 14px 10px;
  border-top: 1px solid var(--border-color);
}

.sync-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: #eef2ff;
  color: var(--accent-primary);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  font-family: inherit;
}

.sync-btn:hover { background: #e0e7ff; border-color: var(--accent-primary); box-shadow: var(--shadow-glow); }
.sync-btn.syncing .sync-icon { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.sync-info {
  text-align: center;
  margin-top: 6px;
  font-size: 11px;
  color: var(--text-muted);
}

/* ─── Main Content ──────────────────────────────────────────────────────── */

.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: margin-left 0.3s ease;
}

.topbar {
  height: auto;
  min-height: var(--topbar-height);
  padding: 10px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  border-bottom: 1px solid var(--border-color);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-left { display: flex; align-items: center; gap: 16px; }

.menu-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 24px;
  cursor: pointer;
}

.page-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
}

.global-search {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: #f1f5f9;
  border: 1px solid var(--border-color);
  border-radius: 24px;
  min-width: 300px;
  max-width: 100%;
  transition: all 0.3s ease;
}

.global-search:focus-within {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
  background: white;
}

.global-search .search-icon { font-size: 14px; }

.global-search input {
  background: none;
  border: none;
  color: var(--text-primary);
  flex: 1;
  font-size: 14px;
  outline: none;
  font-family: inherit;
}

.global-search input::placeholder { color: var(--text-muted); }

.pages-container { flex: 1; padding: 24px; }

.page { display: none; animation: fadeIn 0.3s ease; }
.page.active { display: block; }

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

/* ─── KPI Cards ─────────────────────────────────────────────────────────── */

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

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow-sm);
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.kpi-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--accent-gradient);
  opacity: 0;
  transition: opacity 0.3s ease;
}

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

.kpi-card:hover::before { opacity: 1; }

.kpi-icon { font-size: 32px; }
.kpi-data { flex: 1; }

.kpi-value {
  font-size: 26px;
  font-weight: 800;
  line-height: 1.1;
  color: var(--text-primary);
}

.kpi-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
  font-weight: 500;
}

/* ─── Cards ─────────────────────────────────────────────────────────────── */

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  transition: all 0.3s ease;
  overflow: hidden;
}

.card:hover { box-shadow: var(--shadow-md); }
.card-wide { grid-column: span 2; }

.card-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border-glass);
}

.card-header h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
}

.card-body { padding: 20px; }

/* Alert Card */
.card-alert { border-color: #fde68a; }
.card-alert:hover { border-color: #fbbf24; }

.alert-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  transition: all 0.2s ease;
}

.alert-row:hover { transform: translateX(4px); }

.alert-row.urgent { background: #fef2f2; border-left: 3px solid var(--danger); }
.alert-row.warning { background: #fffbeb; border-left: 3px solid var(--warning); }
.alert-row.info { background: #eff6ff; border-left: 3px solid var(--info); }

.alert-label { font-size: 13px; font-weight: 500; }
.alert-count { font-size: 22px; font-weight: 800; min-width: 40px; text-align: right; }

.alert-row.urgent .alert-count { color: var(--danger); }
.alert-row.warning .alert-count { color: var(--warning); }
.alert-row.info .alert-count { color: var(--info); }

/* ─── Filters Bar ───────────────────────────────────────────────────────── */

.filters-bar {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  padding: 14px 18px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.filter-group { display: flex; flex-direction: column; gap: 4px; }

.filter-group label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}

.filter-group select,
.filter-group input {
  background: #f8fafc;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  color: var(--text-primary);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s ease;
  min-width: 125px;
}

.filter-group select:hover,
.filter-group input:hover { border-color: var(--accent-primary); }

.filter-group select:focus,
.filter-group input:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

/* ─── Table ─────────────────────────────────────────────────────────────── */

.table-info {
  padding: 6px 0;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.table-container {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  overflow: auto;
  max-height: calc(100vh - 320px);
  box-shadow: var(--shadow-sm);
}

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

.data-table thead { position: sticky; top: 0; z-index: 10; }

.data-table th {
  background: #f8fafc;
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
  color: var(--text-secondary);
  border-bottom: 2px solid var(--border-color);
  white-space: nowrap;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  user-select: none;
}

.data-table th.sortable { cursor: pointer; transition: color 0.2s ease; }
.data-table th.sortable:hover { color: var(--accent-primary); }
.data-table th.sort-active { color: var(--accent-primary); }

.data-table td {
  padding: 9px 12px;
  border-bottom: 1px solid #f1f5f9;
  transition: background 0.15s ease;
  white-space: nowrap;
}

.data-table tr:hover td { background: #fafbfd; }

.data-table .importo {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--success);
}

.data-table .targa {
  font-family: 'Courier New', monospace;
  font-weight: 600;
  color: #9333ea;
  letter-spacing: 1px;
}

.data-table .veicolo {
  font-size: 12px;
  color: #0369a1;
  font-weight: 500;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.badge {
  display: inline-block;
  padding: 4px 10px; /* Migliorata area touch */
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.3px;
}

.badge-rca { background: #eef2ff; color: #4338ca; }
.badge-inf { background: #ecfdf5; color: #047857; }
.badge-casa { background: #fffbeb; color: #b45309; }
.badge-rami { background: #fdf2f8; color: #be185d; }
.badge-salute { background: #eff6ff; color: #1d4ed8; }
.badge-tcm { background: #f5f3ff; color: #6d28d9; }
.badge-default { background: #f1f5f9; color: #475569; }

.badge-qz { background: #ecfdf5; color: #047857; }
.badge-nuova { background: #eef2ff; color: #4338ca; }

.expand-btn {
  background: none;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  padding: 3px 7px;
  font-size: 11px;
  transition: all 0.2s ease;
  font-family: inherit;
}

.expand-btn:hover { border-color: var(--accent-primary); color: var(--accent-primary); }

.detail-row td {
  background: #fafbfd !important;
  padding: 0 !important;
  border-bottom: 2px solid var(--border-color) !important;
}

.detail-content {
  padding: 14px 18px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 10px;
}

.detail-item { display: flex; flex-direction: column; gap: 2px; }

.detail-label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.detail-value { font-size: 13px; font-weight: 500; }

/* ─── Pagination ────────────────────────────────────────────────────────── */

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  margin-top: 14px;
}

.pagination button {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  padding: 7px 12px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s ease;
}

.pagination button:hover { border-color: var(--accent-primary); color: var(--accent-primary); }
.pagination button.active { background: var(--accent-primary); border-color: var(--accent-primary); color: white; }
.pagination button:disabled { opacity: 0.3; cursor: not-allowed; }

/* ─── Calendar ──────────────────────────────────────────────────────────── */

.calendar-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.calendar-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--accent-primary);
  min-width: 180px;
  text-align: center;
  flex: 1;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 3px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow-sm);
  overflow-x: auto;
}

.cal-header-cell {
  text-align: center;
  padding: 8px;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.cal-cell {
  min-height: 76px;
  border-radius: var(--radius-sm);
  padding: 6px;
  transition: all 0.2s ease;
  cursor: pointer;
  border: 1px solid transparent;
}

.cal-cell:hover { background: #f1f5f9; border-color: var(--border-color); }
.cal-cell.empty { cursor: default; opacity: 0.3; }
.cal-cell.today { border-color: var(--accent-primary); background: #eef2ff; }
.cal-cell.has-policies { background: #fffbeb; }

.cal-day { font-size: 13px; font-weight: 600; margin-bottom: 3px; }
.cal-count { font-size: 10px; color: var(--warning); font-weight: 600; }

.cal-dots { display: flex; gap: 2px; flex-wrap: wrap; margin-top: 3px; }
.cal-dot { width: 5px; height: 5px; border-radius: 50%; }
.cal-dot.rca { background: #4f46e5; }
.cal-dot.inf { background: #059669; }
.cal-dot.casa { background: #d97706; }
.cal-dot.other { background: #94a3b8; }

.calendar-detail {
  margin-top: 20px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.calendar-detail h3 {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 14px;
  color: var(--accent-primary);
}

/* ─── Clienti ───────────────────────────────────────────────────────────── */

.clienti-search {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
  transition: all 0.3s ease;
}

.clienti-search:focus-within {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.clienti-search input {
  background: none;
  border: none;
  color: var(--text-primary);
  flex: 1;
  font-size: 14px;
  outline: none;
  font-family: inherit;
}

.clienti-search input::placeholder { color: var(--text-muted); }

.clienti-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 14px;
}

.cliente-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 18px;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}

.cliente-card::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 2px;
  background: var(--accent-gradient);
  transform: scaleX(0);
  transition: transform 0.3s ease;
}

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

.cliente-card:hover::after { transform: scaleX(1); }

.cliente-name { font-size: 15px; font-weight: 700; margin-bottom: 6px; }

.cliente-stats { display: flex; gap: 16px; margin-bottom: 10px; }

.cliente-stat { font-size: 11px; color: var(--text-muted); }
.cliente-stat strong { color: var(--text-primary); font-size: 15px; display: block; }

.cliente-tags { display: flex; flex-wrap: wrap; gap: 5px; }

.tag {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.3px;
  background: #eef2ff;
  color: #4338ca;
}

.tag.compagnia { background: #fdf2f8; color: #be185d; }
.tag.targa { background: #f5f3ff; color: #6d28d9; font-family: monospace; }

/* ─── Modal ─────────────────────────────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease;
  backdrop-filter: blur(4px);
}

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 900px;
  max-height: 80vh;
  overflow: auto;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.3s ease;
}

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

.modal-close {
  position: absolute;
  top: 14px; right: 14px;
  background: none;
  border: 1px solid var(--border-color);
  border-radius: 50%;
  width: 34px; height: 34px;
  color: var(--text-secondary);
  font-size: 16px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-close:hover { border-color: var(--danger); color: var(--danger); }

.modal-header {
  padding: 20px 24px 14px;
  border-bottom: 1px solid var(--border-color);
  position: relative;
}

.modal-header h2 { font-size: 20px; font-weight: 700; }
.modal-header .subtitle { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

.modal-body { padding: 20px; }
.modal-body .data-table { font-size: 12px; }
.modal-body .data-table th { padding: 7px 10px; }
.modal-body .data-table td { padding: 7px 10px; }

/* ─── Buttons ───────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s ease;
  border: 1px solid transparent;
}

.btn-primary { background: var(--accent-gradient); color: white; border: none; }
.btn-primary:hover { box-shadow: var(--shadow-glow); transform: translateY(-1px); }

.btn-secondary {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--border-color);
}

.btn-secondary:hover { border-color: var(--accent-primary); color: var(--accent-primary); }

.btn-icon {
  background: #eef2ff;
  border: 1px solid var(--border-color);
  color: var(--accent-primary);
  border-radius: var(--radius-sm);
  width: 36px; height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
}

.btn-icon:hover { background: #e0e7ff; border-color: var(--accent-primary); }

/* ─── Loading ───────────────────────────────────────────────────────────── */

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(248, 250, 252, 0.95);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  transition: opacity 0.3s ease;
}

.loading-overlay.hidden { opacity: 0; pointer-events: none; }

.spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--border-color);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.loading-overlay p { color: var(--text-muted); font-size: 14px; }

/* ─── Toast ─────────────────────────────────────────────────────────────── */

.toast {
  position: fixed;
  bottom: 24px; right: 24px;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  z-index: 3000;
  animation: slideUp 0.3s ease;
  box-shadow: var(--shadow-lg);
}

.toast.success { background: #059669; color: white; }
.toast.error { background: #dc2626; color: white; }

/* ─── Responsive ────────────────────────────────────────────────────────── */

/* Sidebar overlay for mobile */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  z-index: 99;
  backdrop-filter: blur(2px);
  animation: fadeIn 0.2s ease;
}
.sidebar-overlay.active { display: block; }

@media (max-width: 1024px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.mobile-open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .main-content { margin-left: 0; }
  .menu-toggle { display: block; }
  .dashboard-grid { grid-template-columns: 1fr; }
  .card-wide { grid-column: span 1; }
  .global-search { min-width: 0; flex: 1; }
  .topbar { padding: 10px 16px; }
  .topbar-left { flex: 0 0 auto; }
  .topbar-right { flex: 1; min-width: 0; }
  .page-title { font-size: 17px; }

  /* Calendar responsive */
  .calendar-header { justify-content: center; }
  .calendar-title { font-size: 18px; min-width: 160px; }
  .calendar-grid { padding: 8px; gap: 2px; }
  .cal-cell { min-height: 52px; padding: 3px; }
  .cal-day { font-size: 12px; }
  .cal-count { font-size: 9px; }
  .cal-header-cell { font-size: 10px; padding: 6px 2px; }

  /* Calendar detail table as cards on mobile */
  .calendar-detail { padding: 14px; }
  .calendar-detail .data-table { font-size: 11px; }
  .calendar-detail .data-table th,
  .calendar-detail .data-table td { padding: 6px 8px; }

  /* Tables horizontal scroll fallback */
  .table-container { -webkit-overflow-scrolling: touch; }
  .data-table td { white-space: nowrap; }
}

/* ─── Responsive Card View per Tabelle (Meno di 768px) ─── */
@media (max-width: 768px) {
  .table-container {
    background: transparent;
    border: none;
    box-shadow: none;
    max-height: none;
    overflow: visible;
  }
  .data-table, .data-table tbody { display: block; width: 100%; }
  .data-table thead { display: none; }
  .data-table tr {
    display: flex;
    flex-direction: column;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 12px;
    margin-bottom: 12px;
    box-shadow: var(--shadow-sm);
  }
  .data-table tr:hover td { background: transparent; }
  .data-table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-glass);
    white-space: normal;
    text-align: right;
  }
  .data-table td:last-child { border-bottom: none; }
  .data-table td::before {
    content: attr(data-label);
    font-size: 11px;
    text-transform: uppercase;
    color: var(--text-muted);
    font-weight: 600;
    text-align: left;
    margin-right: 12px;
  }
  .data-table .importo { font-size: 16px; }
  .btn-hide-scaduta { width: 100%; height: 44px; margin-top: 8px; font-size: 16px; }
}

@media (max-width: 640px) {
  .pages-container { padding: 10px; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .kpi-card { padding: 14px 12px; gap: 10px; }
  .kpi-icon { font-size: 24px; }
  .kpi-value { font-size: 20px; }
  .kpi-label { font-size: 11px; }
  .filters-bar { flex-direction: column; padding: 10px 12px; }
  .global-search { min-width: 0; flex: 1; padding: 8px 12px; }
  .global-search input { font-size: 14px; }
  .page-title { font-size: 16px; }

  /* Calendar — more compact on small screens */
  .calendar-grid { padding: 6px; gap: 1px; }
  .cal-cell { min-height: 44px; padding: 2px; }
  .cal-day { font-size: 11px; margin-bottom: 1px; }
  .cal-count { font-size: 8px; }
  .cal-dots { gap: 1px; margin-top: 1px; }
  .cal-dot { width: 4px; height: 4px; }
  .cal-header-cell { font-size: 9px; padding: 4px 1px; letter-spacing: 0; }
  .calendar-title { font-size: 16px; min-width: 140px; }

  /* Calendar detail as card list instead of table */
  .calendar-detail-cards {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }
  .cal-detail-card {
    background: #f8fafc;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 12px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
  }
  .cal-detail-card .cal-detail-name {
    grid-column: span 2;
    font-weight: 700;
    font-size: 14px;
    color: var(--text-primary);
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 2px;
  }
  .cal-detail-card .cal-detail-field {
    display: flex;
    flex-direction: column;
    gap: 1px;
  }
  .cal-detail-card .cal-detail-label {
    font-size: 9px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
  }
  .cal-detail-card .cal-detail-val {
    font-size: 13px;
    font-weight: 500;
  }

  /* Scadute search */
  .clienti-search { padding: 8px 12px; margin-bottom: 12px; }
  .clienti-search input { font-size: 14px; }

  /* Export button on mobile — must be full-width in column-direction flex */
  #exportPolizze {
    width: 100%;
  }
  #exportScadute {
    width: 100%;
    min-width: 120px;
    flex-shrink: 0;
  }

  /* Clienti grid */
  .clienti-grid { grid-template-columns: 1fr; gap: 10px; }

  /* Modal */
  .modal { width: 95%; max-height: 90vh; border-radius: var(--radius); }
  .modal-header { padding: 16px 16px 12px; }
  .modal-header h2 { font-size: 17px; }
  .modal-body { padding: 12px; }
  .modal-body .data-table td,
  .modal-body .data-table th { padding: 5px 6px; font-size: 11px; }

  /* Scadute table — horizontal scroll is key */
  #page-scadute .table-container { max-height: calc(100vh - 420px); }
}

/* ─── Scadute (polizze senza rinnovo) ───────────────────────────────────── */

.badge-ritardo-urgente {
  background: #fef2f2;
  color: #dc2626;
  font-weight: 700;
  padding: 3px 10px;
}

.badge-ritardo-medio {
  background: #fffbeb;
  color: #d97706;
  font-weight: 700;
  padding: 3px 10px;
}

.badge-ritardo-vecchio {
  background: #f1f5f9;
  color: #64748b;
  font-weight: 700;
  padding: 3px 10px;
}

.scadute-kpi-urgent { border-left: 4px solid #dc2626; }
.scadute-kpi-urgent .kpi-value { color: #dc2626; }

.scadute-kpi-warning { border-left: 4px solid #d97706; }
.scadute-kpi-warning .kpi-value { color: #d97706; }

.scadute-kpi-old { border-left: 4px solid #94a3b8; }
.scadute-kpi-old .kpi-value { color: #64748b; }

.scadute-kpi-total { border-left: 4px solid #4f46e5; }
.scadute-kpi-total .kpi-value { color: #4f46e5; }

/* Period filter buttons */
.btn-period {
  padding: 6px 14px; border: 1px solid var(--border-color); border-radius: 20px;
  font-size: 12px; font-weight: 600; font-family: inherit; cursor: pointer;
  background: var(--bg-card); color: var(--text-secondary); transition: all 0.2s ease;
}
.btn-period:hover { border-color: var(--accent-primary); color: var(--accent-primary); }
.btn-period.active { background: var(--accent-primary); border-color: var(--accent-primary); color: white; }

/* ─── New Badge Types ────────────────────────────────────────────────── */
.badge-natcat { background: linear-gradient(135deg, #f59e0b, #d97706); color: white; }
.badge-europ { background: linear-gradient(135deg, #0891b2, #0e7490); color: white; }
.badge-qz { background: linear-gradient(135deg, #3b82f6, #2563eb); color: white; }
.badge-nuova { background: linear-gradient(135deg, #10b981, #059669); color: white; }
.badge-sosti { background: linear-gradient(135deg, #f59e0b, #d97706); color: white; }
.badge-ria { background: linear-gradient(135deg, #8b5cf6, #7c3aed); color: white; }

/* ─── Hide Scaduta Button ────────────────────────────────────────────── */
.btn-hide-scaduta {
  background: none; border: 1px solid #94a3b8; color: #64748b;
  border-radius: 50%; width: 28px; height: 28px; font-size: 14px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: all 0.2s ease; padding: 0;
}
.btn-hide-scaduta:hover {
  background: #059669; border-color: #059669; color: white;
  transform: scale(1.1);
}

/* ─── Retention Bars ─────────────────────────────────────────────────── */
.retention-bar {
  height: 8px; background: #e2e8f0; border-radius: 4px; overflow: hidden;
}
.retention-bar-fill {
  height: 100%; border-radius: 4px; transition: width 0.6s ease;
}

/* ─── Concentrazione Grid ────────────────────────────────────────────── */
.concentrazione-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 24px; align-items: start;
}
.concentrazione-card {
  text-align: center; padding: 24px;
  background: linear-gradient(135deg, rgba(79,70,229,0.05), rgba(79,70,229,0.1));
  border-radius: 12px; border: 1px solid rgba(79,70,229,0.15);
}
.concentrazione-value {
  font-size: 48px; font-weight: 800; line-height: 1;
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.concentrazione-value.text-warning {
  background: linear-gradient(135deg, #d97706, #dc2626);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.concentrazione-value.text-success {
  background: linear-gradient(135deg, #059669, #10b981);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.concentrazione-label { font-size: 14px; color: var(--text-secondary); margin-top: 8px; }
.concentrazione-desc { font-size: 12px; margin-top: 12px; color: var(--text-muted); }
.concentrazione-fasce h4 { margin: 0 0 16px; font-size: 14px; font-weight: 600; }

/* ─── Fascia Bars ────────────────────────────────────────────────────── */
.fascia-item {
  display: grid; grid-template-columns: 80px 1fr 100px; gap: 12px;
  align-items: center; margin-bottom: 12px;
}
.fascia-item > span:first-child { font-size: 13px; font-weight: 600; color: var(--text-secondary); }
.fascia-item > span:last-child { font-size: 12px; color: var(--text-muted); text-align: right; }
.fascia-bar {
  height: 20px; background: #e2e8f0; border-radius: 10px; overflow: hidden;
}
.fascia-bar > div {
  height: 100%; border-radius: 10px; transition: width 0.6s ease;
  min-width: 4px;
}

/* ─── Velocita Incasso ───────────────────────────────────────────────── */
.velocita-header { text-align: center; padding: 16px 0 8px; }
.velocita-kpi {
  display: inline-flex; flex-direction: column; align-items: center;
  padding: 16px 32px; border-radius: 12px;
  background: linear-gradient(135deg, rgba(79,70,229,0.05), rgba(79,70,229,0.1));
  border: 1px solid rgba(79,70,229,0.15);
}
.velocita-value {
  font-size: 36px; font-weight: 800;
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.velocita-label { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ─── Garanzie List ──────────────────────────────────────────────────── */
.garanzie-list { padding: 4px 0; }
.garanzia-item {
  display: grid; grid-template-columns: 180px 1fr 50px; gap: 12px;
  align-items: center; margin-bottom: 8px;
}
.garanzia-name { font-size: 12px; font-weight: 600; color: var(--text-primary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.garanzia-bar {
  height: 16px; background: #e2e8f0; border-radius: 8px; overflow: hidden;
}
.garanzia-bar-fill {
  height: 100%; border-radius: 8px;
  background: linear-gradient(90deg, #4f46e5, #7c3aed);
  transition: width 0.6s ease; min-width: 4px;
}
.garanzia-count { font-size: 12px; font-weight: 700; color: var(--text-secondary); text-align: right; }

/* ─── Responsive Concentrazione ──────────────────────────────────────── */
@media (max-width: 768px) {
  .concentrazione-grid { grid-template-columns: 1fr; }
  .garanzia-item { grid-template-columns: 120px 1fr 40px; }
  .fascia-item { grid-template-columns: 70px 1fr 80px; }
}
