:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --border: #e1e4e8;
  --text: #1f2328;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #15803d;
  --success-bg: #dcfce7;
  --danger: #b91c1c;
  --danger-bg: #fee2e2;
  --warn-bg: #fef9c3;
  --warn: #854d0e;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

header.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

header.topbar .brand {
  font-weight: 700;
  font-size: 18px;
  color: var(--primary-dark);
  text-decoration: none;
}

header.topbar .nav { display: flex; gap: 18px; }
header.topbar .nav a { color: var(--text); font-size: 14px; font-weight: 500; }
header.topbar .nav a:hover { color: var(--primary); text-decoration: none; }

main {
  max-width: 1080px;
  margin: 24px auto;
  padding: 0 20px 60px;
}

h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 17px; margin: 24px 0 10px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 18px 20px;
  margin-bottom: 18px;
}

.flash {
  padding: 10px 14px;
  border-radius: 6px;
  margin-bottom: 16px;
  font-size: 14px;
}
.flash.success { background: var(--success-bg); color: var(--success); }
.flash.error { background: var(--danger-bg); color: var(--danger); }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
tr:hover td { background: #fafbfc; }

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  text-transform: uppercase;
}
.badge.yes { background: var(--success-bg); color: var(--success); }
.badge.no { background: #eef0f3; color: var(--muted); }
.badge.DRAFT { background: var(--warn-bg); color: var(--warn); }
.badge.SENT { background: var(--success-bg); color: var(--success); }
.badge.FAILED { background: var(--danger-bg); color: var(--danger); }
.badge.OPENED { background: #dbeafe; color: #1e40af; }
.badge.EMAIL { background: #e0e7ff; color: #3730a3; }
.badge.WHATSAPP { background: #dcfce7; color: #166534; }
.badge.MILESTONE { background: #fef3c7; color: #92400e; }
.badge.SECTOR_PAIN { background: #fee2e2; color: #991b1b; }
.badge.VALUE_PROPOSITION { background: #dbeafe; color: #1e40af; }
.badge.DIRECT_MILESTONE { background: #fef3c7; color: #92400e; }
.badge.SECTOR_VALUE_PAIN { background: #fee2e2; color: #991b1b; }
.badge.LOCAL_REFERENCE { background: #ede9fe; color: #5b21b6; }
.badge.COLD_LEAD { background: #dbeafe; color: #1e40af; }
.badge.CONFIRMED_OPPORTUNITY { background: #fef3c7; color: #92400e; }
.badge.READY_FOR_OUTREACH { background: var(--success-bg); color: var(--success); }
.badge.PROJECT_B2B { background: #ede9fe; color: #5b21b6; }
.badge.HIRING_POSITION { background: #dbeafe; color: #1e40af; }
.badge.NEW { background: #eef0f3; color: var(--muted); }
.badge.MATCHED { background: var(--success-bg); color: var(--success); }
.badge.DISCARDED { background: #eef0f3; color: var(--muted); }
.badge.PENDING { background: #eef0f3; color: var(--muted); }
.badge.EXTRACTING_LINKS { background: #dbeafe; color: #1e40af; }
.badge.PARSING_COMPANIES { background: var(--warn-bg); color: var(--warn); }
.badge.COMPLETED { background: var(--success-bg); color: var(--success); }
.badge.FAILED { background: var(--danger-bg); color: var(--danger); }

.dossier-card .btn.pulse { animation: arse-pulse 1.6s infinite; }
@keyframes arse-pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.5); } 50% { box-shadow: 0 0 0 6px rgba(37, 99, 235, 0); } }

.arse-console {
  background: #0b1020;
  color: #c7d2fe;
  border-radius: 8px;
  padding: 12px 14px;
  margin: 12px 0;
  font-family: "SFMono-Regular", Consolas, Menlo, monospace;
  font-size: 12.5px;
}
.arse-console-header { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; color: #818cf8; }
.arse-console-dot { width: 8px; height: 8px; border-radius: 50%; background: #22c55e; animation: arse-blink 1s infinite; }
.arse-console-dot.done { background: #818cf8; animation: none; }
.arse-console-dot.failed { background: var(--danger); animation: none; }
@keyframes arse-blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.2; } }
.arse-console pre { margin: 0; max-height: 180px; overflow-y: auto; white-space: pre-wrap; }

.pipeline-stepper { display: flex; gap: 6px; margin: 10px 0; }
.pipeline-stepper .badge { opacity: 0.35; }
.pipeline-stepper .badge.active { opacity: 1; }

.dossier-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; margin-top: 12px; }
.dossier-grid .subcard {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  background: #fafbfc;
  max-height: 420px;
  overflow-y: auto;
  overflow-x: hidden;
  min-width: 0;
}
.dossier-grid .subcard h3 { margin: 0 0 8px; font-size: 14px; }
.dossier-grid .subcard ul { margin: 0; padding-left: 18px; font-size: 13px; }
.dossier-grid .subcard pre {
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: break-word;
  max-width: 100%;
  font-family: inherit;
}
.dossier-grid .slot-chip { display: inline-block; background: #eef2ff; color: #3730a3; border-radius: 6px; padding: 3px 8px; font-size: 12px; margin: 2px 4px 0 0; }
.leader-photo { width: 24px; height: 24px; border-radius: 50%; object-fit: cover; vertical-align: middle; margin-right: 6px; }

.btn {
  display: inline-block;
  font-size: 13px;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: 6px;
  border: 1px solid var(--primary);
  background: var(--primary);
  color: #fff;
  cursor: pointer;
}
.btn:hover { background: var(--primary-dark); }
.btn.secondary { background: #fff; color: var(--primary); }
.btn.secondary:hover { background: #eff6ff; }
.btn.small { font-size: 12px; padding: 4px 10px; }

form.inline { display: inline; }

.filters { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.filters input, .filters select {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
}

.field-row { margin-bottom: 12px; }
.field-row label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.field-row input, .field-row select, .field-row textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
}

.opportunity-box {
  background: #f8fafc;
  border: 1px dashed var(--border);
  border-radius: 6px;
  padding: 12px 14px;
  font-size: 14px;
  line-height: 1.5;
}
.opportunity-box dt { font-weight: 600; color: var(--muted); font-size: 12px; margin-top: 8px; }
.opportunity-box dt:first-child { margin-top: 0; }
.opportunity-box dd { margin: 2px 0 0; }

.comm-card {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px 14px;
  margin-bottom: 12px;
}
.comm-card .meta-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 8px; }
.comm-card pre { white-space: pre-wrap; font-family: inherit; font-size: 14px; margin: 0 0 10px; }
.comm-card .wa-link { word-break: break-all; font-size: 12px; }

.signal-card {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 14px;
  margin-bottom: 10px;
  font-size: 14px;
}
.signal-card .meta-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 6px; }
.signal-card p { margin: 4px 0; }

/* Fila de badges de estado/relación bajo un título: nunca se solapan con el
   texto porque el contenedor envuelve (flex-wrap) en vez de superponerse. */
.badge-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 8px 0;
}

/* Tarjeta de contacto (red LinkedIn / líderes clave): avatar + datos en fila,
   con el resumen de IA debajo en bloque propio para que nunca se corte. */
.contact-card {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.contact-card:last-child { border-bottom: none; }
.contact-card .avatar-initials {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #eef2ff;
  color: #3730a3;
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  object-fit: cover;
}
.contact-card .contact-body { flex: 1 1 auto; min-width: 0; }
.contact-card .contact-name-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.contact-card .contact-role { color: var(--muted); font-size: 13px; margin: 2px 0 0; }
.contact-card .contact-summary {
  margin-top: 6px;
  font-size: 13px;
  color: var(--text);
  white-space: normal;
  overflow-wrap: break-word;
  background: #f8fafc;
  border-radius: 6px;
  padding: 8px 10px;
}

/* Enlaces "pill" para URLs crudas (fuentes, señales, ofertas): nunca se
   muestran como texto plano sin formato. */
.link-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #eef2ff;
  color: #3730a3;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  margin: 2px 4px 2px 0;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: middle;
}
.link-pill:hover { background: #e0e7ff; text-decoration: none; }

.muted { color: var(--muted); font-size: 13px; }
.pagination { display: flex; gap: 10px; margin-top: 16px; align-items: center; }

.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card { width: 100%; max-width: 360px; }
.login-card h1 { margin-top: 0; font-size: 20px; }

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  opacity: 0;
  transition: opacity 0.2s ease;
  z-index: 40;
}
.drawer-backdrop.open { opacity: 1; }

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  height: 100vh;
  width: min(640px, 92vw);
  background: var(--card);
  box-shadow: -8px 0 24px rgba(0, 0, 0, 0.15);
  transform: translateX(100%);
  transition: transform 0.25s ease;
  z-index: 50;
  overflow-y: auto;
  padding-bottom: 40px;
}
.drawer.open { transform: translateX(0); }

.drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 14px;
  position: sticky;
  top: 0;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  z-index: 1;
}
.drawer-view-full {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--primary);
  text-decoration: none;
  padding: 4px 10px;
  border-radius: 6px;
}
.drawer-view-full:hover { background: #eff6ff; text-decoration: none; }
.drawer-close {
  background: none;
  border: none;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
  padding: 2px 8px;
}
.drawer-close:hover { color: var(--text); }

.drawer-body { padding: 4px 20px 20px; }
.drawer-body .card { margin-bottom: 14px; }

tr[data-company-row] { cursor: pointer; }

/* Tarjeta de Inteligencia de Mercado & Indicadores: métricas compactas +
   gráfico SVG nativo de financialHistory (sin dependencias de frontend). */
.metric-row { display: flex; gap: 12px; flex-wrap: wrap; margin: 12px 0; }
.metric-box {
  flex: 1 1 140px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  min-width: 120px;
}
.metric-box .metric-label { display: block; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.metric-box .metric-value { display: block; font-size: 18px; font-weight: 700; margin-top: 4px; }
.metric-box .metric-value .estimated-tag { font-size: 10px; font-weight: 500; color: var(--muted); text-transform: none; }
.metric-box.impact-LOW .metric-value { color: var(--muted); }
.metric-box.impact-MEDIUM .metric-value { color: var(--warn); }
.metric-box.impact-HIGH .metric-value { color: var(--success); }

.market-chart-wrap { margin-top: 6px; overflow-x: auto; }
.market-chart-wrap svg { display: block; }

.key-clients-row { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.key-clients-row .pill-neutral {
  display: inline-flex;
  align-items: center;
  background: #eef0f3;
  color: var(--text);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
}

/* Layout de doble columna: izquierda captura/IA, derecha métricas/gráficos. */
.market-intel-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
  margin-top: 10px;
}
@media (min-width: 760px) {
  .market-intel-grid { grid-template-columns: 1fr 1fr; align-items: start; }
}
.market-intel-col-visual { position: sticky; top: 76px; }
@media (max-width: 759px) {
  .market-intel-col-visual { position: static; }
}

.ai-assist-box { margin-bottom: 16px; }
.ai-assist-panel {
  margin-top: 10px;
  padding: 12px 14px;
  background: #f8fafc;
  border: 1px dashed var(--border);
  border-radius: 8px;
}
.ai-assist-panel textarea { font-family: "SFMono-Regular", Consolas, Menlo, monospace; font-size: 12.5px; }

.badge-selector { display: flex; gap: 6px; flex-wrap: wrap; }
.badge-option {
  font-size: 12px;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--muted);
  cursor: pointer;
}
.badge-option:hover { border-color: var(--primary); color: var(--primary); }
.badge-option.active { border-color: transparent; color: #fff; }
.badge-option.level-LOW.active { background: var(--muted); }
.badge-option.level-MEDIUM.active { background: var(--warn); }
.badge-option.level-HIGH.active { background: var(--success); }
.badge-option.level-auto.active { background: var(--primary); }

.chart-card { margin-top: 14px; }
.chart-card h4 { margin: 0 0 6px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }

/* Barra de filtros visuales horizontales de Empresas: carrusel de sectores
   arriba + sub-filtros de etapa/investigación debajo. */
.pill-scroller { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.pill-scroller-track { display: flex; gap: 8px; overflow-x: auto; scroll-behavior: smooth; padding: 2px 0; }
.pill-scroller-track.scrollbar-hide { scrollbar-width: none; -ms-overflow-style: none; }
.pill-scroller-track.scrollbar-hide::-webkit-scrollbar { display: none; }

.pill-scroll-btn {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.pill-scroll-btn:hover { border-color: var(--primary); color: var(--primary); }
.pill-scroll-btn.active { border-color: var(--primary); color: var(--primary); background: #eff6ff; }

.filter-pill {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  cursor: pointer;
}
.filter-pill:hover { border-color: var(--primary); color: var(--primary); }
.filter-pill.active { border-color: var(--primary); background: var(--primary); color: #fff; }
.filter-pill .count { opacity: 0.75; font-weight: 500; }

.subfilters-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}
.subfilters-group { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* Modal de selección múltiple de sectores (buscador + checkboxes). */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-backdrop.open { opacity: 1; visibility: visible; }

.modal {
  background: var(--card);
  border-radius: 10px;
  width: min(420px, 92vw);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.2);
  transform: translateY(8px);
  opacity: 0;
  transition: transform 0.2s ease, opacity 0.2s ease;
}
.modal-backdrop.open .modal { transform: translateY(0); opacity: 1; }

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { margin: 0; font-size: 16px; }
.modal-close {
  background: none;
  border: none;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
  padding: 0 4px;
}
.modal-close:hover { color: var(--text); }

.modal-body { padding: 14px 18px; overflow-y: auto; flex: 1 1 auto; }
.modal-search {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  margin-bottom: 12px;
}

.modal-sector-list { display: flex; flex-direction: column; gap: 2px; }
.modal-sector-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 6px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
}
.modal-sector-option:hover { background: #f8fafc; }
.modal-sector-option input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; flex: 0 0 auto; }
.modal-sector-option .count { color: var(--muted); font-size: 12px; margin-left: auto; }
.modal-empty { color: var(--muted); font-size: 13px; padding: 10px 6px; }

.modal-footer {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 18px;
  border-top: 1px solid var(--border);
}
