:root {
  --bg-dark: #0f172a;
  --bg-card: #1e293b;
  --bg-header: rgba(15, 23, 42, 0.8);
  --accent: #6366f1;
  --accent-light: #818cf8;
  --text-main: #f8fafc;
  --text-dim: #94a3b8;
  --border: rgba(255, 255, 255, 0.1);
  --prime: #10b981;
  --medium: #f59e0b;
  --disqualified: #ef4444;
  --font-main: 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background-color: var(--bg-dark);
  color: var(--text-main);
  font-family: var(--font-main);
  line-height: 1.5;
  overflow-x: hidden;
}

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* ─── HEADER ─── */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-header);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 1rem 2rem;
}

.header-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 1600px;
  margin: 0 auto;
}

.header-brand { display: flex; align-items: center; gap: 1rem; }
.brand-name { font-size: 1.25rem; font-weight: 800; letter-spacing: -0.025em; }
.brand-sub { font-size: 0.75rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.1em; }

.header-meta { display: flex; gap: 0.75rem; }
.zone-badge, .sector-badge, .update-badge {
  font-size: 0.75rem;
  padding: 0.4rem 0.8rem;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-weight: 500;
}

/* ─── STATS ─── */
.stats-bar { padding: 1.5rem 2rem; }
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  max-width: 1600px;
  margin: 0 auto;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  transition: transform 0.2s;
}

.stat-card:hover { transform: translateY(-2px); border-color: var(--accent); }
.stat-icon { font-size: 1.25rem; margin-bottom: 0.25rem; }
.stat-value { font-size: 1.5rem; font-weight: 800; }
.stat-label { font-size: 0.75rem; color: var(--text-dim); text-transform: uppercase; }

.stat-card.prime .stat-value { color: var(--prime); }
.stat-card.medium .stat-value { color: var(--medium); }

/* ─── FILTERS ─── */
.filters-bar {
  padding: 0 2rem 1.5rem;
  position: sticky;
  top: 73px;
  z-index: 90;
  background: var(--bg-dark);
}

.filters-inner {
  max-width: 1600px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  gap: 2rem;
  background: var(--bg-card);
  padding: 0.75rem 1.25rem;
  border: 1px solid var(--border);
  border-radius: 12px;
}

.search-wrap { display: flex; align-items: center; gap: 0.75rem; flex: 1; overflow: hidden; }
.search-icon { color: var(--text-dim); flex-shrink: 0; }
.search-input {
  background: transparent;
  border: none;
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.9rem;
  width: 100%;
  outline: none;
}

.filter-group { display: flex; gap: 0.5rem; }
.filter-select {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  color: var(--text-main);
  padding: 0.4rem 0.75rem;
  border-radius: 8px;
  font-size: 0.85rem;
  outline: none;
  cursor: pointer;
}

/* ─── LAYOUT ─── */
.main-layout {
  display: grid;
  grid-template-columns: 450px 1fr;
  gap: 1.5rem;
  padding: 0 2rem 2rem;
  max-width: 1600px;
  margin: 0 auto;
  height: calc(100vh - 320px);
}

.leads-panel {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  overflow-y: hidden;
}

.panel-header { display: flex; justify-content: space-between; align-items: center; }
.leads-count { font-size: 0.85rem; font-weight: 600; color: var(--text-dim); }

.leads-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  overflow-y: auto;
  padding-right: 0.5rem;
}

.lead-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
  overflow: hidden;
}

.lead-item:hover { border-color: var(--accent-light); background: rgba(99, 102, 241, 0.05); }
.lead-item.active { border-color: var(--accent); background: rgba(99, 102, 241, 0.1); border-width: 2px; }

.lead-item-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 0.5rem; }
.lead-name { font-weight: 700; font-size: 0.95rem; }
.lead-tier { font-size: 0.65rem; font-weight: 800; padding: 0.2rem 0.5rem; border-radius: 4px; }
.lead-tier.PRIME { background: rgba(16, 185, 129, 0.2); color: var(--prime); }
.lead-tier.MEDIUM { background: rgba(245, 158, 11, 0.2); color: var(--medium); }
.lead-tier.DISQUALIFIED { background: rgba(239, 68, 68, 0.2); color: var(--disqualified); }

.lead-meta { font-size: 0.75rem; color: var(--text-dim); display: flex; gap: 0.75rem; }

.lead-excerpt {
  margin-top: 0.5rem;
  font-size: 0.8rem;
  color: var(--text-dim);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.lead-tags {
  margin-top: 0.75rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.tag-mini {
  background: rgba(255, 255, 255, 0.05);
  font-size: 0.65rem;
  padding: 0.15rem 0.4rem;
  border-radius: 3px;
  color: var(--text-dim);
}

.reviewed-check {
  position: absolute;
  top: 0.5rem;
  left: 0.5rem;
  width: 6px;
  height: 6px;
  background: var(--prime);
  border-radius: 50%;
}

/* ─── DETAIL ─── */
.detail-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow-y: auto;
  position: relative;
}

.detail-header {
  padding: 2rem;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(to bottom, rgba(99, 102, 241, 0.05), transparent);
}

.detail-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.detail-title { font-size: 1.75rem; font-weight: 800; line-height: 1.1; }
.detail-url { color: var(--accent-light); font-size: 0.9rem; text-decoration: none; margin-top: 0.25rem; display: inline-block; }

.detail-section { padding: 2rem; border-bottom: 1px solid var(--border); }
.section-title { font-size: 0.8rem; font-weight: 800; text-transform: uppercase; color: var(--text-dim); margin-bottom: 1.25rem; letter-spacing: 0.05em; display: flex; align-items: center; gap: 0.5rem; }

.reason-box {
  background: rgba(16, 185, 129, 0.05);
  border: 1px solid rgba(16, 185, 129, 0.2);
  border-radius: 12px;
  padding: 1.5rem;
  font-size: 0.95rem;
  color: #d1fae5;
  line-height: 1.6;
}

.email-box {
  background: #0f172a;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: #cbd5e1;
  white-space: pre-wrap;
  position: relative;
  line-height: 1.5;
}

.copy-btn {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: var(--accent);
  border: none;
  color: white;
  padding: 0.4rem 0.8rem;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
}

.tech-tags { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.tech-tag {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  padding: 0.4rem 0.75rem;
  border-radius: 8px;
  font-size: 0.8rem;
}

.contact-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.contact-item { display: flex; align-items: center; gap: 0.75rem; font-size: 0.9rem; }
.contact-label { color: var(--text-dim); width: 80px; }

.notes-area {
  width: 100%;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  color: var(--text-main);
  font-family: inherit;
  resize: vertical;
  min-height: 100px;
  outline: none;
}

.detail-actions {
  padding: 1.5rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(15, 23, 42, 0.4);
}

.btn {
  padding: 0.6rem 1.25rem;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: all 0.2s;
}

.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-light); }
.btn-ghost { background: transparent; color: var(--text-dim); border: 1px solid var(--border); }
.btn-ghost:hover { background: rgba(255, 255, 255, 0.05); color: var(--text-main); }
.btn-danger { background: rgba(239, 68, 68, 0.1); color: var(--disqualified); border: 1px solid rgba(239, 68, 68, 0.2); }
.btn-danger:hover { background: var(--disqualified); color: white; }

/* ─── MODAL ─── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.8); backdrop-filter: blur(4px); display: flex; align-items: center; justify-content: center; z-index: 1000; }
.modal-box { background: var(--bg-card); border: 1px solid var(--border); padding: 2rem; border-radius: 16px; width: 400px; text-align: center; }
.modal-actions { display: flex; gap: 1rem; justify-content: center; margin-top: 1.5rem; }

/* ─── UTILS ─── */
.loading-state, .empty-state, .detail-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-dim);
  text-align: center;
  padding: 2rem;
}

.spinner { width: 30px; height: 30px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; margin-bottom: 1rem; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  background: var(--bg-card);
  border: 1px solid var(--accent);
  padding: 1rem 1.5rem;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.5);
  transform: translateY(200%);
  transition: transform 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28);
  z-index: 2000;
}
.toast.show { transform: translateY(0); }

/* ─── NEW: STAT CARD DRAFT ─── */
.stat-card.draft .stat-value { color: #c084fc; }

/* ─── NEW: AI BUTTON ─── */
.btn-ai {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: white;
  border: none;
}
.btn-ai:hover { opacity: 0.88; transform: translateY(-1px); }
.btn-ai:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

/* ─── NEW: SMALL BUTTON ─── */
.btn-sm { padding: 0.3rem 0.65rem; font-size: 0.78rem; border-radius: 6px; }

/* ─── NEW: CONTACT BADGES EN LISTA ─── */
.has-contact {
  font-size: 0.65rem;
  padding: 0.1rem 0.35rem;
  border-radius: 3px;
  background: rgba(99, 102, 241, 0.12);
  color: var(--accent-light);
}
.has-draft {
  font-size: 0.65rem;
  padding: 0.1rem 0.35rem;
  border-radius: 3px;
  background: rgba(16, 185, 129, 0.12);
  color: var(--prime);
  font-weight: 700;
}

/* ─── NEW: EMAIL EDIT AREA ─── */
.email-edit-area {
  width: 100%;
  background: #0a1020;
  border: 1px solid var(--accent);
  border-radius: 12px;
  padding: 1.5rem;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: #cbd5e1;
  line-height: 1.6;
  resize: vertical;
  min-height: 280px;
  outline: none;
  margin-top: 0.5rem;
  transition: border-color 0.2s;
}
.email-edit-area:focus { border-color: var(--accent-light); }

/* ─── NEW: SECTION TITLE WITH ACTIONS ─── */
.section-title-with-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
}
.section-title-with-actions .section-title { margin-bottom: 0; }
.email-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }

/* ─── NEW: EXPORT BUTTON ─── */
.btn-export {
  background: rgba(99, 102, 241, 0.08);
  border: 1px solid rgba(99, 102, 241, 0.4);
  color: var(--accent-light);
  padding: 0.4rem 0.85rem;
  border-radius: 8px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  transition: all 0.2s;
  font-family: inherit;
}
.btn-export:hover { background: var(--accent); color: white; border-color: var(--accent); }
