/* Workshop Platform - Custom Styles */
:root {
  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --sidebar-w: 260px;
}

* { box-sizing: border-box; }

body { margin: 0; font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif; background: #f1f5f9; }

/* Layout */
#app { display: flex; min-height: 100vh; }
.sidebar { width: var(--sidebar-w); background: #1e293b; color: #e2e8f0; display: flex; flex-direction: column; position: fixed; top: 0; left: 0; height: 100vh; z-index: 100; overflow-y: auto; transition: transform 0.3s; }
.main-content { margin-left: var(--sidebar-w); flex: 1; display: flex; flex-direction: column; min-height: 100vh; }
.topbar { background: #fff; border-bottom: 1px solid #e2e8f0; padding: 0 24px; height: 64px; display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 50; box-shadow: 0 1px 3px rgba(0,0,0,.05); }
.page-content { flex: 1; padding: 24px; }

/* Sidebar */
.sidebar-logo { padding: 20px 20px 16px; border-bottom: 1px solid #334155; }
.sidebar-logo h1 { font-size: 18px; font-weight: 700; color: #fff; margin: 0; display: flex; align-items: center; gap: 8px; }
.sidebar-logo span { font-size: 11px; color: #94a3b8; display: block; margin-top: 2px; }
.sidebar-nav { padding: 12px 0; flex: 1; }
.nav-section { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.1em; color: #64748b; padding: 12px 20px 4px; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 10px 20px; cursor: pointer; color: #94a3b8; font-size: 13.5px; transition: all .15s; border-left: 3px solid transparent; text-decoration: none; }
.nav-item:hover { background: #1a3148; color: #e2e8f0; }
.nav-item.active { background: #1e40af22; color: #60a5fa; border-left-color: #3b82f6; }
.nav-item i { width: 18px; text-align: center; font-size: 14px; }
.sidebar-footer { padding: 16px 20px; border-top: 1px solid #334155; }
.user-info { font-size: 12px; color: #94a3b8; }
.user-info .name { font-weight: 600; color: #e2e8f0; font-size: 13px; }
.badge-role { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 10px; font-weight: 600; text-transform: uppercase; background: #334155; color: #94a3b8; margin-top: 4px; }
.badge-role.admin { background: #7c3aed22; color: #a78bfa; }
.badge-role.owner { background: #7c3aed22; color: #a78bfa; }
.badge-role.amministratore { background: #4f46e522; color: #818cf8; }
.badge-role.commerciale { background: #059669` + '22' + `; color: #34d399; }
.badge-role.viewer { background: #d97706` + '22' + `; color: #fbbf24; }
.badge-role.manager { background: #3730a322; color: #6366f1; }

/* Cards */
.card { background: #fff; border-radius: 12px; padding: 20px; box-shadow: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04); border: 1px solid #f1f5f9; }
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.card-title { font-size: 15px; font-weight: 600; color: #1e293b; margin: 0; }

/* KPI Cards */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; margin-bottom: 24px; }
.kpi-card { background: #fff; border-radius: 12px; padding: 20px; border: 1px solid #f1f5f9; box-shadow: 0 1px 3px rgba(0,0,0,.06); position: relative; overflow: hidden; }
.kpi-card::before { content: ''; position: absolute; top: 0; left: 0; width: 4px; height: 100%; }
.kpi-card.blue::before { background: #3b82f6; }
.kpi-card.green::before { background: #10b981; }
.kpi-card.red::before { background: #ef4444; }
.kpi-card.amber::before { background: #f59e0b; }
.kpi-card.purple::before { background: #8b5cf6; }
.kpi-card.indigo::before { background: #6366f1; }
.kpi-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: #64748b; margin-bottom: 8px; display: flex; align-items: center; gap: 6px; }
.kpi-value { font-size: 28px; font-weight: 700; color: #1e293b; line-height: 1; }
.kpi-sub { font-size: 12px; color: #64748b; margin-top: 6px; }
.kpi-trend { font-size: 12px; font-weight: 600; margin-top: 4px; }
.kpi-trend.ok { color: #10b981; }
.kpi-trend.warn { color: #f59e0b; }
.kpi-trend.bad { color: #ef4444; }
.progress-bar { height: 4px; background: #f1f5f9; border-radius: 999px; margin-top: 10px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 999px; transition: width .5s; }

/* Tables */
.table-wrapper { overflow-x: auto; border-radius: 8px; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th { background: #f8fafc; color: #64748b; font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; padding: 10px 14px; text-align: left; border-bottom: 1px solid #e2e8f0; white-space: nowrap; vertical-align: top; }
tbody tr { border-bottom: 1px solid #f1f5f9; transition: background .1s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: #f8fafc; }
tbody td { padding: 12px 14px; color: #374151; vertical-align: middle; }
.clickable-row { cursor: pointer; }

/* Badges/Pills */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.badge-blue { background: #dbeafe; color: #1d4ed8; }
.badge-green { background: #d1fae5; color: #065f46; }
.badge-red { background: #fee2e2; color: #991b1b; }
.badge-amber { background: #fef3c7; color: #92400e; }
.badge-gray { background: #f3f4f6; color: #4b5563; }
.badge-purple { background: #ede9fe; color: #5b21b6; }
.badge-indigo { background: #e0e7ff; color: #3730a3; }
.badge-teal { background: #ccfbf1; color: #134e4a; }

/* Forms */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 12.5px; font-weight: 600; color: #374151; margin-bottom: 6px; }
.form-input, .form-select, .form-textarea { width: 100%; padding: 9px 12px; border: 1.5px solid #e2e8f0; border-radius: 8px; font-size: 13.5px; color: #1e293b; background: #fff; transition: border-color .15s, box-shadow .15s; outline: none; font-family: inherit; box-sizing: border-box; line-height: 1.4; vertical-align: middle; }
.form-input:focus, .form-select:focus, .form-textarea:focus { border-color: #3b82f6; box-shadow: 0 0 0 3px rgba(59,130,246,.1); }
/* Fix8: .form-select — stile moderno uniforme con chevron SVG + fix testo tagliato */
.form-select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='7'%3E%3Cpath d='M0 0l6 7 6-7z' fill='%2364748b'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-color: #fff;
  padding-right: 36px;
  cursor: pointer;
  box-sizing: border-box;
  line-height: 1.4;
  overflow: visible;
}
.form-select:disabled {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='7'%3E%3Cpath d='M0 0l6 7 6-7z' fill='%23cbd5e1'/%3E%3C/svg%3E");
  background-color: #f8fafc;
  color: #94a3b8;
  cursor: not-allowed;
  opacity: 0.7;
}
/* Fix8: select/input nei filtri con height inline — assicura testo non tagliato */
.filters-bar .form-select,
.filters-bar .form-input {
  box-sizing: border-box;
  padding-top: 6px;
  padding-bottom: 6px;
}
.form-textarea { resize: vertical; min-height: 80px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.checkbox-group { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.checkbox-group input { width: 16px; height: 16px; cursor: pointer; accent-color: #3b82f6; }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: 7px; padding: 9px 18px; border-radius: 8px; font-size: 13.5px; font-weight: 600; cursor: pointer; transition: all .15s; border: none; font-family: inherit; text-decoration: none; }
.btn-primary { background: #2563eb; color: #fff; }
.btn-primary:hover { background: #1d4ed8; }
.btn-secondary { background: #f1f5f9; color: #374151; }
.btn-secondary:hover { background: #e2e8f0; }
.btn-danger { background: #fee2e2; color: #991b1b; }
.btn-danger:hover { background: #fecaca; }
.btn-success { background: #d1fae5; color: #065f46; }
.btn-success:hover { background: #a7f3d0; }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-xs { padding: 4px 8px; font-size: 11px; }
.btn-icon { padding: 8px; width: 36px; height: 36px; justify-content: center; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* Modals */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 1000; display: flex; align-items: center; justify-content: center; padding: 20px; backdrop-filter: blur(2px); }
.modal { background: #fff; border-radius: 16px; width: 100%; max-width: 600px; max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,.2); }
.modal-lg { max-width: 800px; }
.modal-header { padding: 20px 24px 0; display: flex; align-items: center; justify-content: space-between; }
.modal-title { font-size: 17px; font-weight: 700; color: #1e293b; }
.modal-body { padding: 20px 24px; }
.modal-footer { padding: 0 24px 20px; display: flex; gap: 10px; justify-content: flex-end; }
.modal-close { background: none; border: none; cursor: pointer; color: #94a3b8; font-size: 20px; padding: 4px; border-radius: 6px; }
.modal-close:hover { color: #1e293b; background: #f1f5f9; }

/* Alerts/Messages */
.alert { padding: 12px 16px; border-radius: 8px; font-size: 13px; display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.alert-success { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }
.alert-info { background: #dbeafe; color: #1d4ed8; border: 1px solid #bfdbfe; }
.alert-warn { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }

/* Filters bar */
.filters-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; background: #fff; padding: 12px 16px; border-radius: 10px; border: 1px solid #f1f5f9; }
.filters-bar .form-input, .filters-bar .form-select { min-width: 160px; }
.filters-bar .search-input { flex: 1; min-width: 200px; }

/* Page header */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.page-title { font-size: 22px; font-weight: 700; color: #1e293b; }
.page-subtitle { font-size: 13px; color: #64748b; margin-top: 2px; }

/* Tabs */
.tabs { display: flex; gap: 0; border-bottom: 2px solid #e2e8f0; margin-bottom: 20px; }
.tab-btn { padding: 10px 18px; font-size: 13.5px; font-weight: 600; color: #64748b; border: none; background: none; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -2px; transition: all .15s; font-family: inherit; }
.tab-btn.active { color: #2563eb; border-bottom-color: #2563eb; }
.tab-btn:hover:not(.active) { color: #374151; }

/* Login */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #1e3a8a 0%, #1e293b 100%); padding: 20px; }
.login-card { background: #fff; border-radius: 20px; padding: 40px; width: 100%; max-width: 400px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.login-logo { text-align: center; margin-bottom: 32px; }
.login-logo h1 { font-size: 24px; font-weight: 800; color: #1e293b; margin: 0; }
.login-logo p { color: #64748b; font-size: 13px; margin: 6px 0 0; }

/* Funnel chart */
.funnel-bar { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.funnel-label { font-size: 12px; color: #64748b; width: 130px; text-align: right; flex-shrink: 0; }
.funnel-track { flex: 1; background: #f1f5f9; border-radius: 999px; height: 24px; overflow: hidden; }
.funnel-fill { height: 100%; border-radius: 999px; display: flex; align-items: center; padding-left: 8px; font-size: 11px; font-weight: 700; color: #fff; transition: width .5s; }
.funnel-count { font-size: 12px; font-weight: 600; color: #374151; width: 40px; }

/* CTA indicators */
.cta-dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; transition: transform .15s, box-shadow .15s; }
.cta-on { background: #10b981; }
.cta-off { background: #e2e8f0; }
.cta-clickable { cursor: pointer; }
.cta-clickable:hover { transform: scale(1.35); box-shadow: 0 0 0 3px rgba(16,185,129,.25); }
.cta-clickable.cta-off:hover { box-shadow: 0 0 0 3px rgba(100,116,139,.2); }

/* Inline selects nella tabella Lead CRM */
.inline-select {
  appearance: none;
  -webkit-appearance: none;
  background: #f8fafc url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%2364748b'/%3E%3C/svg%3E") no-repeat right 6px center;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 4px 22px 4px 7px;
  font-size: 12px;
  color: #1e293b;
  cursor: pointer;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  min-width: 100px;
  max-width: 160px;
}
.inline-select:hover { border-color: #94a3b8; }
.inline-select:focus { border-color: #3b82f6; box-shadow: 0 0 0 2px rgba(59,130,246,.2); }

/* Timeline */
.timeline { display: flex; flex-direction: column; gap: 0; }
.timeline-item { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid #f1f5f9; }
.timeline-icon { width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-size: 13px; }
.timeline-icon.nota { background: #dbeafe; color: #1d4ed8; }
.timeline-icon.stato { background: #fef3c7; color: #92400e; }
.timeline-icon.call { background: #d1fae5; color: #065f46; }
.timeline-icon.vendita { background: #ede9fe; color: #5b21b6; }
.timeline-content .title { font-size: 13px; font-weight: 600; color: #1e293b; }
.timeline-content .meta { font-size: 11.5px; color: #94a3b8; margin-top: 2px; }

/* Status chip helpers */
.stato-discovery { background: #dbeafe; color: #1d4ed8; }
.stato-materiale { background: #e0e7ff; color: #3730a3; }
.stato-ghost { background: #fee2e2; color: #991b1b; }
.stato-non-risponde { background: #fef3c7; color: #92400e; }
.stato-non-target { background: #f3f4f6; color: #4b5563; }
.stato-fake { background: #f3f4f6; color: #9ca3af; }

/* Interest badge */
.interesse-alto { background: #d1fae5; color: #065f46; }
.interesse-medio { background: #fef3c7; color: #92400e; }
.interesse-basso { background: #fee2e2; color: #991b1b; }

/* Responsive */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
}

/* Utilities */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.text-sm { font-size: 13px; }
.text-xs { font-size: 11.5px; }
.text-gray { color: #64748b; }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }
.w-full { width: 100%; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.hidden { display: none !important; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.rounded { border-radius: 8px; }
.p-4 { padding: 16px; }
.divider { border: none; border-top: 1px solid #f1f5f9; margin: 16px 0; }
.empty-state { text-align: center; padding: 48px 20px; color: #94a3b8; }
.empty-state i { font-size: 40px; margin-bottom: 12px; display: block; }
.loading { display: flex; align-items: center; justify-content: center; padding: 60px; color: #94a3b8; }
.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Toast notifications */
#toast-container { position: fixed; top: 20px; right: 20px; z-index: 9999; display: flex; flex-direction: column; gap: 10px; }
.toast { background: #1e293b; color: #fff; padding: 12px 18px; border-radius: 10px; font-size: 13.5px; font-weight: 500; box-shadow: 0 8px 24px rgba(0,0,0,.2); animation: slideIn .3s ease; display: flex; align-items: center; gap: 10px; max-width: 380px; }
.toast.success { background: #065f46; }
.toast.error { background: #991b1b; }
.toast.warn { background: #92400e; }
@keyframes slideIn { from { opacity: 0; transform: translateX(50px); } to { opacity: 1; transform: translateX(0); } }

/* Filtri inline nell'intestazione tabella Lead CRM */
th.th-with-filter {
  white-space: nowrap;
  padding-right: 4px;
}
/* Contenitore th: label + freccia sulla stessa riga */
th.th-with-filter .th-label {
  display: inline;
  margin-right: 2px;
}
/* Il select è ridotto a una freccia ▼ visibile accanto al testo */
.th-filter-arrow {
  display: inline-block;
  width: 20px;
  height: 18px;
  padding: 0;
  margin: 0;
  border: none;
  background: transparent url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%2394a3b8'/%3E%3C/svg%3E") no-repeat center center;
  color: transparent;
  font-size: 0;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  vertical-align: middle;
  outline: none;
  border-radius: 3px;
  transition: background-color .15s;
}
.th-filter-arrow:hover {
  background-color: rgba(59,130,246,.1);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%233b82f6'/%3E%3C/svg%3E");
}
/* Quando un filtro è attivo, la freccia diventa blu */
.th-filter-arrow.th-filter-active {
  background-color: rgba(59,130,246,.15);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%232563eb'/%3E%3C/svg%3E");
  border-radius: 3px;
}
.th-filter-arrow:focus { outline: none; box-shadow: 0 0 0 2px rgba(59,130,246,.25); border-radius: 3px; }

/* =====================================================
   Rate & Pagamenti — stati inline select
   ===================================================== */
.rata-dasaldare-sel {
  background-color: #fef3c7;
  color: #92400e;
  border-color: #f59e0b;
  font-weight: 600;
  font-size: 12px;
  padding: 2px 6px;
  border-radius: 4px;
  cursor: pointer;
}
.rata-pagata-sel {
  background-color: #d1fae5;
  color: #065f46;
  border-color: #10b981;
  font-weight: 600;
  font-size: 12px;
  padding: 2px 6px;
  border-radius: 4px;
  cursor: pointer;
}
.rata-scaduta-sel {
  background-color: #fee2e2;
  color: #991b1b;
  border-color: #ef4444;
  font-weight: 700;
  font-size: 12px;
  padding: 2px 6px;
  border-radius: 4px;
  cursor: pointer;
}
.rata-dasaldare-sel:focus,
.rata-pagata-sel:focus,
.rata-scaduta-sel:focus {
  outline: none;
  box-shadow: 0 0 0 2px rgba(59,130,246,.25);
}
