/* =========================================
   CRM Lead Manager — Design System
   Dark mode premium look
   ========================================= */

:root {
  --bg-0: #0d0f14;
  --bg-1: #13161e;
  --bg-2: #1a1e2a;
  --bg-3: #222736;
  --bg-card: rgba(255, 255, 255, 0.04);
  --bg-card-hover: rgba(255, 255, 255, 0.07);
  --border: rgba(255, 255, 255, 0.08);
  --border-hover: rgba(255, 255, 255, 0.16);

  --primary: #6366f1;
  --primary-light: #818cf8;
  --primary-dark: #4f46e5;
  --primary-glow: rgba(99, 102, 241, 0.2);

  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #3b82f6;

  --text-1: #f1f5f9;
  --text-2: #94a3b8;
  --text-3: #64748b;

  --sidebar-w: 220px;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;

  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.6);
  --font: 'Inter', system-ui, sans-serif;
}

[data-theme="light"] {
  --bg-0: #f8fafc;
  --bg-1: #ffffff;
  --bg-2: #f1f5f9;
  --bg-3: #e2e8f0;
  --bg-card: #ffffff;
  --bg-card-hover: #f8fafc;
  --border: #e2e8f0;
  --border-hover: #cbd5e1;

  --primary: #4f46e5;
  --primary-light: #6366f1;
  --primary-dark: #4338ca;
  --primary-glow: rgba(79, 70, 229, 0.15);

  --text-1: #0f172a;
  --text-2: #475569;
  --text-3: #64748b;

  --shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.08);
}

/* RESET & BASE */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 14px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font);
  background: var(--bg-0);
  color: var(--text-1);
  min-height: 100vh;
  display: flex;
  overflow-x: hidden;
}

a {
  text-decoration: none;
  color: inherit;
}

button {
  cursor: pointer;
  font-family: var(--font);
}

input,
textarea,
select {
  font-family: var(--font);
}

/* SCROLLBAR */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: var(--bg-1);
}

::-webkit-scrollbar-thumb {
  background: var(--bg-3);
  border-radius: 3px;
}

/* =========================================
   SIDEBAR
   ========================================= */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-1);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 100;
  transition: transform .3s ease;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 24px 20px 20px;
  border-bottom: 1px solid var(--border);
}

.logo-icon {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  box-shadow: 0 0 20px var(--primary-glow);
}

.logo-text {
  font-size: 1.1rem;
  font-weight: 700;
  background: linear-gradient(135deg, #fff, var(--primary-light));
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.nav-menu {
  list-style: none;
  padding: 12px 0;
  flex: 1;
  overflow-y: auto;
}

.nav-menu li {
  margin: 2px 8px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  transition: all .2s ease;
  font-size: .875rem;
  font-weight: 500;
  position: relative;
}

.nav-link:hover {
  background: var(--bg-card-hover);
  color: var(--text-1);
}

.nav-link.active {
  background: linear-gradient(135deg, var(--primary-glow), rgba(99, 102, 241, 0.1));
  color: var(--primary-light);
  border: 1px solid rgba(99, 102, 241, 0.2);
}

.nav-label {
  flex: 1;
}

.nav-icon {
  font-size: 1rem;
}

.badge {
  background: var(--primary);
  color: white;
  border-radius: 10px;
  padding: 2px 6px;
  font-size: .7rem;
  font-weight: 600;
  min-width: 18px;
  text-align: center;
}

.badge:empty {
  display: none;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

.sidebar-version {
  color: var(--text-3);
  font-size: .75rem;
}

/* =========================================
   MAIN CONTENT
   ========================================= */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-height: 100vh;
  background: var(--bg-0);
}

#page-container {
  padding: 32px;
  max-width: 1200px;
}

/* =========================================
   PAGE HEADER
   ========================================= */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
  gap: 16px;
  flex-wrap: wrap;
}

.page-title {
  font-size: 1.5rem;
  font-weight: 700;
}

.page-subtitle {
  color: var(--text-2);
  font-size: .875rem;
  margin-top: 2px;
}

/* =========================================
   CARDS
   ========================================= */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  backdrop-filter: blur(10px);
  transition: border-color .2s, box-shadow .2s;
}

.card:hover {
  border-color: var(--border-hover);
}

.card-title {
  font-size: .8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-2);
  margin-bottom: 8px;
}

/* =========================================
   STATS GRID
   ========================================= */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: all .2s;
  cursor: default;
}

.stat-card:hover {
  border-color: var(--primary);
  box-shadow: 0 0 20px var(--primary-glow);
  transform: translateY(-2px);
}

.stat-icon {
  font-size: 1.5rem;
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1;
}

.stat-label {
  font-size: .8rem;
  color: var(--text-2);
  font-weight: 500;
}

/* =========================================
   BUTTONS
   ========================================= */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: .875rem;
  font-weight: 500;
  border: none;
  transition: all .2s;
  white-space: nowrap;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.3);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
}

.btn-secondary {
  background: var(--bg-3);
  color: var(--text-1);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-hover);
}

.btn-danger {
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.btn-danger:hover {
  background: rgba(239, 68, 68, 0.25);
}

.btn-success {
  background: rgba(16, 185, 129, 0.15);
  color: var(--success);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.btn-success:hover {
  background: rgba(16, 185, 129, 0.25);
}

.btn-sm {
  padding: 5px 10px;
  font-size: .8rem;
  border-radius: 6px;
}

.btn-icon {
  padding: 7px;
  border-radius: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-2);
}

.btn-icon:hover {
  border-color: var(--border-hover);
  color: var(--text-1);
}

/* =========================================
   FORM ELEMENTS
   ========================================= */
.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.form-control {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-1);
  padding: 9px 12px;
  font-size: .875rem;
  transition: border-color .2s, box-shadow .2s;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.form-control::placeholder {
  color: var(--text-3);
}

select.form-control {
  cursor: pointer;
}

textarea.form-control {
  min-height: 120px;
  resize: vertical;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.form-row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
}

/* =========================================
   TABLE
   ========================================= */
.table-wrapper {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.table {
  width: 100%;
  border-collapse: collapse;
}

.table th {
  background: var(--bg-2);
  color: var(--text-2);
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.table td {
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  font-size: .875rem;
  color: var(--text-1);
  vertical-align: middle;
}

.table tr:last-child td {
  border-bottom: none;
}

.table tbody tr {
  transition: background .15s;
}

.table tbody tr:hover {
  background: rgba(255, 255, 255, 0.025);
  cursor: pointer;
}

.table-actions {
  display: flex;
  gap: 6px;
}

/* =========================================
   STATUS BADGES
   ========================================= */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: .75rem;
  font-weight: 600;
  white-space: nowrap;
}

.status-badge::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.badge-da_contattare {
  background: rgba(100, 116, 139, 0.2);
  color: #94a3b8;
}

.badge-contattato {
  background: rgba(59, 130, 246, 0.2);
  color: #60a5fa;
}

.badge-in_trattativa {
  background: rgba(245, 158, 11, 0.2);
  color: #fbbf24;
}

.badge-chiuso {
  background: rgba(16, 185, 129, 0.2);
  color: #34d399;
}

.badge-non_interessato {
  background: rgba(239, 68, 68, 0.2);
  color: #f87171;
}

/* =========================================
   SEARCH & FILTERS BAR
   ========================================= */
.filter-bar {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.search-wrap {
  position: relative;
  flex: 1;
  min-width: 200px;
}

.search-wrap .search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-3);
  font-size: .875rem;
}

.search-input {
  width: 100%;
  padding-left: 34px !important;
}

.filter-tabs {
  display: flex;
  gap: 4px;
  background: var(--bg-2);
  padding: 4px;
  border-radius: var(--radius-sm);
  flex-wrap: wrap;
}

.filter-tab {
  padding: 5px 12px;
  border-radius: 6px;
  font-size: .8rem;
  font-weight: 500;
  color: var(--text-2);
  border: none;
  background: transparent;
  transition: all .2s;
  cursor: pointer;
}

.filter-tab.active {
  background: var(--primary);
  color: white;
}

.filter-tab:hover:not(.active) {
  background: var(--bg-card-hover);
  color: var(--text-1);
}

/* =========================================
   PIPELINE BAR
   ========================================= */
.pipeline {
  display: flex;
  height: 8px;
  border-radius: 4px;
  overflow: hidden;
  margin: 12px 0;
  background: var(--bg-3);
}

.pipeline-segment {
  transition: width .5s ease;
}

.seg-da_contattare {
  background: #64748b;
}

.seg-contattato {
  background: #3b82f6;
}

.seg-in_trattativa {
  background: #f59e0b;
}

.seg-chiuso {
  background: #10b981;
}

.seg-non_interessato {
  background: #ef4444;
}

/* =========================================
   MODAL
   ========================================= */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-overlay.hidden {
  display: none;
}

.modal-box {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: modalIn .2s ease;
}

@keyframes modalIn {
  from {
    opacity: 0;
    transform: scale(.96) translateY(8px);
  }

  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.modal-title {
  font-size: 1.1rem;
  font-weight: 700;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-3);
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
}

.modal-close:hover {
  color: var(--text-1);
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
}

/* =========================================
   TOAST
   ========================================= */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: .875rem;
  box-shadow: var(--shadow);
  animation: toastIn .3s ease;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 280px;
  max-width: 380px;
}

.toast-success {
  border-left: 3px solid var(--success);
}

.toast-error {
  border-left: 3px solid var(--danger);
}

.toast-info {
  border-left: 3px solid var(--info);
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateX(20px);
  }

  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* =========================================
   NOTES TIMELINE
   ========================================= */
.timeline {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.timeline-item {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  position: relative;
}

.timeline-date {
  font-size: .75rem;
  color: var(--text-3);
  margin-top: 4px;
}

.timeline-text {
  font-size: .875rem;
  line-height: 1.5;
}

/* =========================================
   EMAIL LOG
   ========================================= */
.email-item {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin-bottom: 8px;
}

.email-item-subject {
  font-weight: 600;
  font-size: .875rem;
  margin-bottom: 4px;
}

.email-item-meta {
  font-size: .75rem;
  color: var(--text-3);
}

/* =========================================
   GRID LAYOUTS
   ========================================= */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

/* =========================================
   EMPTY STATE
   ========================================= */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-3);
}

.empty-icon {
  font-size: 3rem;
  margin-bottom: 16px;
}

.empty-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 8px;
}

.empty-desc {
  font-size: .875rem;
}

/* =========================================
   PAGINATION
   ========================================= */
.pagination {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin-top: 16px;
  align-items: center;
}

.pagination button {
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-2);
  color: var(--text-2);
  font-size: .8rem;
  cursor: pointer;
  transition: all .2s;
}

.pagination button:hover:not(:disabled) {
  border-color: var(--primary);
  color: var(--primary-light);
}

.pagination button.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

.pagination button:disabled {
  opacity: .4;
  cursor: not-allowed;
}

.page-info {
  font-size: .8rem;
  color: var(--text-3);
}

/* =========================================
   PROGRESS BAR
   ========================================= */
.progress-wrap {
  background: var(--bg-3);
  border-radius: 4px;
  height: 6px;
  overflow: hidden;
  margin: 8px 0;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--primary-light));
  border-radius: 4px;
  transition: width .3s;
}

/* =========================================
   LEAD DETAIL
   ========================================= */
.detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.detail-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
}

.detail-name {
  font-size: 1.25rem;
  font-weight: 700;
}

.detail-meta {
  color: var(--text-2);
  font-size: .875rem;
  margin-top: 2px;
}

.detail-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 20px;
}

/* =========================================
   CHECKBOX CUSTOM
   ========================================= */
.checkbox-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.checkbox-wrap input[type=checkbox] {
  width: 15px;
  height: 15px;
  accent-color: var(--primary);
  cursor: pointer;
}

/* =========================================
   RESPONSIVE
   ========================================= */
@media (max-width: 768px) {
  :root {
    --sidebar-w: 0px;
  }

  .sidebar {
    transform: translateX(-220px);
  }

  .sidebar.open {
    transform: translateX(0);
    width: 220px;
  }

  #page-container {
    padding: 16px;
  }

  .form-row,
  .form-row-3 {
    grid-template-columns: 1fr;
  }

  .grid-2,
  .detail-grid {
    grid-template-columns: 1fr;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* =========================================
   UTILITY
   ========================================= */
.flex {
  display: flex;
}

.flex-center {
  display: flex;
  align-items: center;
  justify-content: center;
}

.gap-2 {
  gap: 8px;
}

.gap-3 {
  gap: 12px;
}

.mt-2 {
  margin-top: 8px;
}

.mt-3 {
  margin-top: 12px;
}

.mt-4 {
  margin-top: 16px;
}

.mb-3 {
  margin-bottom: 12px;
}

.mb-4 {
  margin-bottom: 16px;
}

.text-muted {
  color: var(--text-2);
}

.text-sm {
  font-size: .8rem;
}

.text-right {
  text-align: right;
}

.w-full {
  width: 100%;
}

.hidden {
  display: none !important;
}

.loading {
  opacity: .5;
  pointer-events: none;
}

.divider {
  height: 1px;
  background: var(--border);
  margin: 20px 0;
}