/* Saturata CRM Dashboard */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
  --bg: #0a0e1a;
  --surface: #111827;
  --surface-hover: #1f2937;
  --surface-raised: #1a2236;
  --text: #f3f4f6;
  --text-muted: #9ca3af;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --primary-glow: rgba(59,130,246,0.15);
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #06b6d4;
  --border: #1f2937;
  --border-light: #374151;
  --radius: 12px;
  --shadow: 0 10px 40px rgba(0,0,0,0.4);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg); color: var(--text);
  min-height: 100vh; font-size: 14px; line-height: 1.5;
}

/* LOGIN */
.login-screen {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; background: radial-gradient(ellipse at top, #1e3a5f 0%, var(--bg) 60%);
}
.login-box {
  background: var(--surface); padding: 48px; border-radius: var(--radius);
  width: 100%; max-width: 400px; box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.login-box h1 { font-size: 1.6rem; margin-bottom: 8px; text-align: center; }
.login-box p { color: var(--text-muted); text-align: center; margin-bottom: 28px; font-size: 0.9rem; }
.login-box input {
  width: 100%; padding: 14px 16px; margin-bottom: 16px;
  background: var(--bg); border: 1px solid var(--border-light); border-radius: 10px;
  color: var(--text); font-size: 1rem; outline: none; transition: border-color 0.2s;
}
.login-box input:focus { border-color: var(--primary); }
.login-box button {
  width: 100%; padding: 14px; background: var(--primary); color: white;
  border: none; border-radius: 10px; font-size: 1rem; font-weight: 600; cursor: pointer;
  transition: background 0.2s;
}
.login-box button:hover { background: var(--primary-hover); }
.login-error { color: var(--danger); text-align: center; margin-top: 12px; font-size: 0.85rem; display: none; }

/* LAYOUT */
.app { display: none; }
.app.active { display: flex; min-height: 100vh; }

.sidebar {
  width: 260px; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 24px 0; position: fixed; height: 100vh;
}
.sidebar .brand {
  font-size: 1.4rem; font-weight: 700; padding: 0 24px 24px; display: flex; align-items: center; gap: 10px;
}
.sidebar .brand .dot { width: 10px; height: 10px; background: var(--success); border-radius: 50%; box-shadow: 0 0 8px var(--success); }
.sidebar nav { flex: 1; }
.sidebar nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 24px; margin: 2px 12px; color: var(--text-muted); text-decoration: none; font-size: 0.95rem;
  border-radius: 8px; transition: all 0.15s;
}
.sidebar nav a:hover, .sidebar nav a.active {
  background: var(--primary-glow); color: var(--text);
}
.sidebar nav a.active { color: var(--primary); font-weight: 500; }
.sidebar .logout {
  padding: 16px 24px;
}
.sidebar .logout button {
  width: 100%; padding: 10px; background: transparent; border: 1px solid var(--border-light);
  color: var(--text-muted); border-radius: 8px; cursor: pointer; font-size: 0.9rem; transition: all 0.2s;
}
.sidebar .logout button:hover { color: var(--danger); border-color: var(--danger); background: rgba(239,68,68,0.05); }

.main {
  flex: 1; display: flex; flex-direction: column; margin-left: 260px; min-height: 100vh;
}
.header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 28px; border-bottom: 1px solid var(--border); background: var(--surface);
  position: sticky; top: 0; z-index: 10;
}
.header h2 { font-size: 1.25rem; font-weight: 600; }
.header .user { color: var(--text-muted); font-size: 0.85rem; }

.content { flex: 1; padding: 24px; overflow-y: auto; }

/* KPI */
.kpi-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px;
}
.kpi-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; position: relative; overflow: hidden;
}
.kpi-card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px; background: var(--primary);
}
.kpi-card:nth-child(2)::before { background: var(--success); }
.kpi-card:nth-child(3)::before { background: var(--warning); }
.kpi-card:nth-child(4)::before { background: var(--danger); }
.kpi-card .label { font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 8px; }
.kpi-card .value { font-size: 2rem; font-weight: 700; }

/* FILTRI */
.toolbar {
  display: flex; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; align-items: center;
}
.toolbar select, .toolbar input {
  background: var(--surface); border: 1px solid var(--border-light); color: var(--text);
  padding: 10px 14px; border-radius: 8px; font-size: 0.9rem; outline: none;
}
.toolbar select:focus, .toolbar input:focus { border-color: var(--primary); }
.toolbar .btn {
  padding: 10px 18px; border-radius: 8px; font-size: 0.85rem; font-weight: 500; cursor: pointer;
  border: none; transition: all 0.15s;
}
.toolbar .btn-primary { background: var(--primary); color: white; }
.toolbar .btn-primary:hover { background: var(--primary-hover); }
.toolbar .btn-ghost { background: var(--surface); color: var(--text-muted); border: 1px solid var(--border-light); }
.toolbar .btn-ghost:hover { color: var(--text); border-color: var(--text-muted); }

/* TABELLA */
.table-wrap {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden;
}
table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
th, td { padding: 14px 16px; text-align: left; }
th {
  background: rgba(255,255,255,0.02); font-weight: 600; color: var(--text-muted);
  font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.5px; white-space: nowrap;
}
tr { cursor: pointer; transition: background 0.1s; }
tr:not(:last-child) td { border-bottom: 1px solid var(--border); }
tr:hover td { background: var(--surface-hover); }
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 20px; font-size: 0.75rem; font-weight: 600;
}
.badge.nuovo { background: rgba(156,163,175,0.12); color: #9ca3af; }
.badge.assegnato { background: rgba(59,130,246,0.12); color: var(--primary); }
.badge.contattato { background: rgba(6,182,212,0.12); color: var(--info); }
.badge.in_trattativa { background: rgba(245,158,11,0.12); color: var(--warning); }
.badge.convertito { background: rgba(16,185,129,0.12); color: var(--success); }
.badge.perso { background: rgba(239,68,68,0.12); color: var(--danger); }
.badge.attivo { background: rgba(16,185,129,0.12); color: var(--success); }
.badge.in_prova { background: rgba(245,158,11,0.12); color: var(--warning); }
.badge.inattivo { background: rgba(239,68,68,0.12); color: var(--danger); }

/* DRAWER DETTAGLIO */
.drawer-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 100;
  display: none; opacity: 0; transition: opacity 0.3s;
}
.drawer-overlay.open { display: block; opacity: 1; }
.drawer {
  position: fixed; top: 0; right: 0; width: 600px; max-width: 95vw; height: 100vh;
  background: var(--surface); border-left: 1px solid var(--border); z-index: 101;
  transform: translateX(100%); transition: transform 0.3s cubic-bezier(0.4,0,0.2,1);
  display: flex; flex-direction: column; overflow: hidden;
}
.drawer.open { transform: translateX(0); }
.drawer-header {
  padding: 20px 24px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.drawer-header h3 { font-size: 1.1rem; font-weight: 600; }
.drawer-header .close-btn {
  background: none; border: none; color: var(--text-muted); font-size: 1.5rem; cursor: pointer;
}
.drawer-body { flex: 1; overflow-y: auto; padding: 24px; }
.drawer-footer {
  padding: 16px 24px; border-top: 1px solid var(--border);
  display: flex; gap: 10px; justify-content: flex-end;
}

/* SEZIONI DETTAGLIO */
.detail-section { margin-bottom: 28px; }
.detail-section h4 {
  font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--text-muted); margin-bottom: 12px; padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.detail-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px;
}
.detail-field { background: var(--bg); padding: 12px 14px; border-radius: 8px; border: 1px solid var(--border); }
.detail-field .label { font-size: 0.75rem; color: var(--text-muted); margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.3px; }
.detail-field .value { font-size: 0.95rem; font-weight: 500; word-break: break-word; }
.detail-field.full { grid-column: 1 / -1; }

/* PIPELINE STATO */
.pipeline {
  display: flex; gap: 8px; margin-bottom: 24px;
}
.pipeline-step {
  flex: 1; text-align: center; padding: 10px 8px; border-radius: 8px;
  font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.3px;
  background: var(--bg); border: 1px solid var(--border); color: var(--text-muted);
  cursor: pointer; transition: all 0.2s;
}
.pipeline-step.active { background: var(--primary-glow); border-color: var(--primary); color: var(--primary); }
.pipeline-step.done { background: rgba(16,185,129,0.1); border-color: var(--success); color: var(--success); }

/* NOTE */
.note-box {
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 12px;
  margin-bottom: 12px;
}
.note-box .meta { font-size: 0.75rem; color: var(--text-muted); margin-bottom: 6px; }
.note-box .text { font-size: 0.9rem; line-height: 1.5; }
.note-input {
  width: 100%; background: var(--bg); border: 1px solid var(--border-light); color: var(--text);
  padding: 12px; border-radius: 8px; font-size: 0.9rem; resize: vertical; min-height: 80px; outline: none;
}
.note-input:focus { border-color: var(--primary); }

/* TOGGLE */
.toggle {
  appearance: none; width: 40px; height: 22px; background: var(--border-light); border-radius: 20px;
  position: relative; cursor: pointer; outline: none; transition: background 0.2s;
}
.toggle::after { content: ''; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; background: white; border-radius: 50%; transition: transform 0.2s; }
.toggle:checked { background: var(--success); }
.toggle:checked::after { transform: translateX(18px); }

input.inline {
  background: var(--bg); border: 1px solid var(--border-light); color: var(--text);
  padding: 6px 10px; border-radius: 6px; font-size: 0.85rem; width: 70px;
}

.loading, .empty { text-align: center; padding: 40px; color: var(--text-muted); }

@media (max-width: 900px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .sidebar { width: 64px; }
  .sidebar .brand span, .sidebar nav a span, .sidebar .logout span { display: none; }
  .sidebar nav a { justify-content: center; padding: 14px 0; margin: 2px 4px; }
  .main { margin-left: 64px; }
  .detail-grid { grid-template-columns: 1fr; }
}
