/* Extractify Sales CRM — Light Professional Theme */
:root {
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --bg-hover: #f1f5f9;
  --bg-input: #ffffff;
  --text-primary: #0f172a;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --border: #e2e8f0;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-light: #eef2ff;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --purple: #7c3aed;
  --orange: #ea580c;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow-lg: 0 4px 16px rgba(0,0,0,.08), 0 2px 6px rgba(0,0,0,.04);
  --sidebar-width: 240px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif; background: var(--bg-primary); color: var(--text-primary); font-size: 14px; }

/* Login Page */
.login-page {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; background: linear-gradient(135deg, #f0f4ff 0%, #e8ecff 50%, #f5f3ff 100%);
}
.login-card {
  background: var(--bg-card); border-radius: 16px; padding: 40px;
  width: 420px; max-width: 90vw; box-shadow: 0 8px 32px rgba(99,102,241,.12), 0 2px 8px rgba(0,0,0,.06);
  border: 1px solid var(--border);
}
.login-card h1 { font-size: 24px; margin-bottom: 6px; color: var(--text-primary); font-weight: 700; }
.login-card p { color: var(--text-secondary); margin-bottom: 28px; font-size: 14px; }
.login-card .logo { font-size: 36px; margin-bottom: 16px; display: block; }
.login-error { color: var(--danger); font-size: 13px; margin-top: 12px; display: none; background: #fef2f2; padding: 8px 12px; border-radius: 6px; border: 1px solid #fecaca; }

/* Form elements */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 12px; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; }
input, select, textarea {
  width: 100%; padding: 10px 12px; background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text-primary); font-size: 14px; outline: none; transition: border .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(99,102,241,.1); }
textarea { resize: vertical; min-height: 80px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 9px 16px;
  border: none; border-radius: var(--radius); font-size: 14px; font-weight: 500;
  cursor: pointer; transition: all .15s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text-primary); }
.btn-outline:hover { background: var(--bg-hover); }
.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn-full { width: 100%; justify-content: center; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* Layout */
.app-layout { display: flex; height: 100vh; }
.sidebar {
  width: var(--sidebar-width); background: var(--bg-secondary); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; flex-shrink: 0;
}
.sidebar-header { padding: 20px 16px 16px; border-bottom: 1px solid var(--border); }
.sidebar-header h2 { font-size: 17px; font-weight: 700; display: flex; align-items: center; gap: 8px; color: var(--text-primary); }
.sidebar-header .user-info { font-size: 12px; color: var(--text-secondary); margin-top: 6px; cursor: pointer; transition: color .15s; }
.sidebar-header .user-info:hover { color: var(--accent); }

.sidebar-nav { flex: 1; padding: 12px 8px; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px;
  border-radius: var(--radius); color: var(--text-secondary); cursor: pointer;
  transition: all .15s; text-decoration: none; font-size: 14px; font-weight: 500;
  margin-bottom: 2px;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-item.active { background: var(--accent-light); color: var(--accent); font-weight: 600; }
.nav-item .icon { font-size: 16px; width: 22px; text-align: center; }

.sidebar-footer { padding: 12px 8px; border-top: 1px solid var(--border); }

.main-content { flex: 1; overflow-y: auto; padding: 28px; background: var(--bg-primary); }
.main-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.main-header h1 { font-size: 22px; font-weight: 700; color: var(--text-primary); }
.header-actions { display: flex; gap: 8px; }

/* Cards */
.card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 20px; box-shadow: var(--shadow);
}
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.card-title { font-size: 15px; font-weight: 600; color: var(--text-primary); }

/* Stats grid */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 20px; box-shadow: var(--shadow);
}
.stat-card .stat-label { font-size: 12px; color: var(--text-secondary); font-weight: 500; margin-bottom: 8px; }
.stat-card .stat-value { font-size: 26px; font-weight: 700; color: var(--text-primary); }
.stat-card .stat-sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.stat-card.accent .stat-value { color: var(--accent); }
.stat-card.success .stat-value { color: var(--success); }
.stat-card.warning .stat-value { color: var(--warning); }
.stat-card.danger .stat-value { color: var(--danger); }

/* Kanban */
.kanban-container { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 16px; min-height: 60vh; align-items: flex-start; }
.kanban-column {
  min-width: 260px; max-width: 280px; background: var(--bg-primary);
  border: 1px solid var(--border); border-radius: var(--radius-lg); display: flex; flex-direction: column;
}
.kanban-column-header {
  padding: 12px 14px; border-bottom: 1px solid var(--border); display: flex;
  align-items: center; justify-content: space-between; flex-shrink: 0; background: var(--bg-card);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
.kanban-column-title { font-size: 12px; font-weight: 600; display: flex; align-items: center; gap: 8px; color: var(--text-primary); text-transform: uppercase; letter-spacing: .4px; }
.kanban-count { background: var(--bg-hover); color: var(--text-secondary); border-radius: 10px; padding: 2px 8px; font-size: 11px; font-weight: 600; }
.kanban-cards { flex: 1; padding: 8px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; min-height: 80px; }

.kanban-card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px; cursor: pointer; transition: all .15s; box-shadow: var(--shadow);
}
.kanban-card:hover { border-color: var(--accent); box-shadow: var(--shadow-lg); transform: translateY(-1px); }
.kanban-card .lead-name { font-weight: 600; font-size: 13px; margin-bottom: 3px; color: var(--text-primary); }
.kanban-card .lead-company { color: var(--text-secondary); font-size: 12px; }
.kanban-card .lead-meta { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; font-size: 11px; color: var(--text-muted); }
.kanban-card .lead-value { color: var(--success); font-weight: 700; font-size: 12px; }
.kanban-card .lead-channel { font-size: 13px; }

/* Badges */
.badge {
  display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 20px;
  font-size: 11px; font-weight: 600;
}
.badge-sdr { background: #dbeafe; color: #1d4ed8; }
.badge-seller { background: #fef3c7; color: #b45309; }
.badge-manager { background: #ede9fe; color: #6d28d9; }
.stage-badge {
  display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 20px;
  font-size: 11px; font-weight: 600;
}

/* SLA indicators */
.sla-ok { color: var(--success); font-size: 12px; font-weight: 600; }
.sla-warning { color: var(--warning); font-size: 12px; font-weight: 600; }
.sla-overdue { color: var(--danger); font-size: 12px; font-weight: 600; animation: pulse 1.5s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .5; } }

/* Lead Detail */
.lead-detail { max-width: 900px; }
.lead-detail .back-btn { color: var(--text-secondary); cursor: pointer; margin-bottom: 16px; display: inline-flex; align-items: center; gap: 4px; font-size: 13px; }
.lead-detail .back-btn:hover { color: var(--accent); }
.lead-detail-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 24px; }
.lead-detail-header h1 { font-size: 22px; font-weight: 700; }
.lead-info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 24px; }
.info-item label { display: block; font-size: 11px; color: var(--text-muted); text-transform: uppercase; margin-bottom: 4px; letter-spacing: .4px; }
.info-item span { font-size: 14px; color: var(--text-primary); font-weight: 500; }

/* Timeline */
.timeline { position: relative; padding-left: 24px; }
.timeline::before { content: ''; position: absolute; left: 8px; top: 0; bottom: 0; width: 2px; background: var(--border); }
.timeline-item { position: relative; margin-bottom: 12px; padding: 12px 14px; background: var(--bg-primary); border-radius: var(--radius); border: 1px solid var(--border); }
.timeline-item::before { content: ''; position: absolute; left: -20px; top: 14px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); border: 2px solid var(--bg-card); }
.timeline-item .time { font-size: 11px; color: var(--text-muted); }
.timeline-item .event { font-size: 13px; margin-top: 3px; color: var(--text-primary); }

/* Tables */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  text-align: left; padding: 10px 14px; font-size: 11px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .5px; border-bottom: 2px solid var(--border); font-weight: 600; background: var(--bg-primary);
}
.data-table td { padding: 12px 14px; border-bottom: 1px solid var(--border); font-size: 13px; color: var(--text-primary); }
.data-table tr:hover td { background: var(--bg-hover); }

/* Attachments */
.attachment-list { display: flex; flex-direction: column; gap: 8px; }
.attachment-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; background: var(--bg-primary); border: 1px solid var(--border);
  border-radius: var(--radius);
}
.attachment-item .file-name { font-size: 13px; display: flex; align-items: center; gap: 8px; }
.attachment-item .file-type { font-size: 11px; color: var(--text-muted); }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,.3); display: flex;
  align-items: center; justify-content: center; z-index: 1000; backdrop-filter: blur(2px);
}
.modal {
  background: var(--bg-card); border-radius: var(--radius-lg); padding: 28px;
  width: 500px; max-width: 90vw; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow-lg); border: 1px solid var(--border);
}
.modal h2 { font-size: 18px; font-weight: 700; margin-bottom: 20px; color: var(--text-primary); }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 24px; }

/* Charts area */
.chart-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 24px; }
.chart-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px; box-shadow: var(--shadow); }
.chart-card h3 { font-size: 13px; font-weight: 600; margin-bottom: 16px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .4px; }

/* Bar chart (CSS) */
.bar-chart { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: flex; align-items: center; gap: 10px; }
.bar-label { min-width: 90px; font-size: 12px; color: var(--text-secondary); text-align: right; }
.bar-track { flex: 1; height: 22px; background: #f1f5f9; border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 4px; transition: width .6s ease; display: flex; align-items: center; padding-left: 8px; font-size: 11px; font-weight: 600; color: #fff; }
.bar-value { min-width: 40px; text-align: right; font-size: 12px; font-weight: 600; color: var(--text-secondary); }

/* Responsive */
@media (max-width: 768px) {
  .app-layout { flex-direction: column; }
  .sidebar { width: 100%; height: auto; flex-direction: row; overflow-x: auto; }
  .sidebar-header { display: none; }
  .sidebar-nav { display: flex; flex-direction: row; padding: 8px; gap: 4px; }
  .nav-item { white-space: nowrap; padding: 8px 12px; font-size: 12px; }
  .sidebar-footer { display: none; }
  .main-content { padding: 16px; }
  .kanban-container { flex-direction: column; }
  .kanban-column { min-width: 100%; max-width: 100%; }
  .chart-grid { grid-template-columns: 1fr; }
  .lead-info-grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}

/* Scrollbar */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* Transitions */
.fade-in { animation: fadeIn .25s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

/* Filter bar */
.filter-bar { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.filter-bar select, .filter-bar input { width: auto; min-width: 140px; }

/* Empty state */
.empty-state { text-align: center; padding: 48px 24px; color: var(--text-muted); }
.empty-state .icon { font-size: 40px; margin-bottom: 12px; }
.empty-state p { font-size: 14px; }

/* Toast */
.toast {
  position: fixed; bottom: 24px; right: 24px; padding: 12px 20px;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); z-index: 2000; animation: slideUp .25s ease; font-size: 13px;
}
.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }
@keyframes slideUp { from { transform: translateY(16px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* Drag and Drop */
.kanban-card[draggable] { cursor: grab; }
.kanban-card.dragging { opacity: 0.4; cursor: grabbing; pointer-events: none; }
.kanban-column.drag-over .kanban-cards { background: var(--accent-light); outline: 2px dashed var(--accent); outline-offset: 2px; border-radius: 6px; }

/* NEW badge */
.badge-new { background: #fef3c7; color: #b45309; padding: 1px 6px; border-radius: 4px; font-size: 9px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; }

/* Global Search in Sidebar */
.search-wrapper { padding: 8px 8px 0; position: relative; }
.search-input-sidebar { width: 100%; padding: 8px 10px; background: var(--bg-primary); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text-primary); font-size: 13px; outline: none; transition: border .15s; }
.search-input-sidebar:focus { border-color: var(--accent); }
.search-results-dropdown { position: absolute; top: calc(100% + 4px); left: 8px; right: 8px; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); z-index: 300; max-height: 280px; overflow-y: auto; box-shadow: var(--shadow-lg); }
.sr-item { padding: 10px 12px; cursor: pointer; border-bottom: 1px solid var(--border); }
.sr-item:last-child { border-bottom: none; }
.sr-item:hover { background: var(--bg-hover); }
.sr-item .sr-name { font-weight: 600; font-size: 13px; color: var(--text-primary); }
.sr-item .sr-meta { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* SLA badge on nav */
.nav-badge { background: var(--danger); color: #fff; border-radius: 10px; padding: 1px 6px; font-size: 10px; font-weight: 700; margin-left: auto; min-width: 18px; text-align: center; }

/* Date range filter */
.date-filter { display: flex; gap: 4px; align-items: center; }
.date-btn { padding: 5px 10px; border-radius: 6px; font-size: 12px; font-weight: 500; cursor: pointer; border: 1px solid var(--border); background: var(--bg-card); color: var(--text-secondary); transition: all .15s; }
.date-btn.active, .date-btn:hover { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Lost reason analysis */
.lost-reason-item { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.lost-reason-item:last-child { border-bottom: none; }
.lost-reason-bar { flex: 1; height: 8px; background: #f1f5f9; border-radius: 4px; overflow: hidden; }
.lost-reason-fill { height: 100%; background: var(--danger); border-radius: 4px; transition: width .6s ease; }
.lost-reason-label { min-width: 140px; font-size: 12px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lost-reason-count { font-size: 12px; font-weight: 600; color: var(--text-primary); min-width: 28px; text-align: right; }

/* Owner selector inline */
.owner-select-inline { background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text-primary); font-size: 13px; padding: 4px 8px; cursor: pointer; }
.owner-select-inline:focus { border-color: var(--accent); outline: none; }

/* SLA progress bar */
.sla-progress { height: 6px; background: #f1f5f9; border-radius: 3px; overflow: hidden; margin-top: 6px; }
.sla-progress-fill { height: 100%; border-radius: 3px; transition: width .4s ease; }
