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

:root {
  --bg: #f0f2f5;
  --sidebar-bg: #111827;
  --sidebar-text: #d1d5db;
  --sidebar-active: #1d4ed8;
  --card-bg: #ffffff;
  --border: #e5e7eb;
  --text: #111827;
  --text-muted: #6b7280;
  --green: #16a34a;
  --green-bg: #dcfce7;
  --orange: #d97706;
  --orange-bg: #fef3c7;
  --red: #dc2626;
  --red-bg: #fee2e2;
  --blue: #1d4ed8;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ── Header ── */
header {
  background: var(--sidebar-bg);
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  z-index: 10;
}

header h1 {
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: .02em;
}

header .header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #6b7280;
  transition: background .3s;
}
.status-dot.online { background: #22c55e; }
.status-dot.offline { background: #ef4444; }

.status-label {
  font-size: 12px;
  color: var(--sidebar-text);
}

/* ── Layout ── */
.layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── Sidebar ── */
aside {
  width: 200px;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
  padding: 16px 0;
}

.sidebar-section {
  padding: 0 12px 8px;
}

.sidebar-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #4b5563;
  padding: 0 4px 8px;
}

.run-btn {
  width: 100%;
  padding: 9px 12px;
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: background .15s;
  margin-bottom: 16px;
}
.run-btn:hover { background: #1e40af; }
.run-btn:disabled { background: #374151; cursor: not-allowed; }

.date-list { padding: 0 8px; }

.date-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 8px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--sidebar-text);
  font-size: 13px;
  transition: background .1s;
  user-select: none;
}
.date-item:hover { background: #1f2937; }
.date-item.active { background: #1e3a8a; color: #fff; }

.date-badge {
  font-size: 11px;
  background: #374151;
  color: #9ca3af;
  padding: 1px 6px;
  border-radius: 10px;
  min-width: 20px;
  text-align: center;
}
.date-item.active .date-badge { background: #1d4ed8; color: #bfdbfe; }

/* ── Main ── */
main {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 12px;
  color: var(--text-muted);
}

.empty-state .icon { font-size: 48px; }
.empty-state p { font-size: 14px; }

/* ── Stats bar ── */
.stats-bar {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  box-shadow: var(--shadow);
  min-width: 100px;
}

.stat-card .stat-value {
  font-size: 24px;
  font-weight: 700;
  line-height: 1;
}

.stat-card .stat-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: .04em;
}

/* ── Barra de filtros ── */
.filters-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  box-shadow: var(--shadow);
}

.filter-input {
  flex: 1;
  min-width: 220px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
}
.filter-input:focus { outline: 2px solid #bfdbfe; border-color: var(--blue); }

.filter-select {
  padding: 7px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  background: var(--card-bg);
  cursor: pointer;
}

.filter-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  cursor: pointer;
  user-select: none;
}

.filter-count {
  font-size: 12px;
  color: var(--text-muted);
  margin-left: auto;
}

/* ── Job cards ── */
.jobs-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.job-card {
  display: grid;
  grid-template-rows: auto auto auto;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: box-shadow .15s, opacity .15s;
}
.job-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,.1); }
.job-card.hidden { display: none; }

/* Estados CRM en la tarjeta */
.job-card.estado-aplicado { border-left: 3px solid var(--green); }
.job-card.estado-descartado { border-left: 3px solid var(--red); opacity: .55; }

.job-head {
  padding: 14px 16px 10px;
}

.job-title {
  font-size: 14px;
  font-weight: 600;
}

.job-company {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Badges agrupados bajo el título — colores pastel con propósito */
.job-badges {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
}
.badge-nueva     { background: #dcfce7; color: #15803d; }
.badge-salario   { background: #fef3c7; color: #92400e; }
.badge-modalidad { background: #ede9fe; color: #6d28d9; }
.badge-fuente    { background: var(--bg); color: var(--text-muted); font-weight: 500; }
.badge-exp.exp-none { background: #dcfce7; color: #15803d; }
.badge-exp.exp-low  { background: #dbeafe; color: #1d4ed8; }
.badge-exp.exp-mid  { background: #fef9c3; color: #a16207; }
.badge-exp.exp-high { background: #fee2e2; color: #b91c1c; }

/* Descripción: 3 líneas con fade + "Leer más" */
.job-desc-wrap {
  padding: 0 16px 10px;
}

.job-desc {
  position: relative;
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
}

.job-desc.clamp {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.job-desc.clamp::after {
  content: '';
  position: absolute;
  inset: auto 0 0 0;
  height: 1.5em;
  background: linear-gradient(to bottom, transparent, var(--card-bg));
  pointer-events: none;
}

.leer-mas {
  background: none;
  border: none;
  color: var(--blue);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 0 0;
}
.leer-mas:hover { text-decoration: underline; }

/* Resaltado del stack de Mario en la descripción */
mark.stack-hl {
  background: #dbeafe;
  color: #1d4ed8;
  font-weight: 600;
  border-radius: 3px;
  padding: 0 3px;
}

/* Pie de tarjeta: estado CRM + acciones */
.job-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  border-top: 1px solid var(--border);
  padding: 10px 16px;
  background: #fafbfc;
}

.estado-control {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}

.estado-btn {
  padding: 5px 10px;
  font-size: 12px;
  border: none;
  background: var(--card-bg);
  color: var(--text-muted);
  cursor: pointer;
  transition: background .1s;
}
.estado-btn + .estado-btn { border-left: 1px solid var(--border); }
.estado-btn:hover { background: var(--bg); }
.estado-btn.active.pendiente  { background: #f3f4f6; color: var(--text); font-weight: 600; }
.estado-btn.active.aplicado   { background: var(--green-bg); color: #15803d; font-weight: 600; }
.estado-btn.active.descartado { background: var(--red-bg); color: #b91c1c; font-weight: 600; }

.job-actions {
  display: flex;
  gap: 8px;
}

.btn {
  padding: 7px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: background .1s;
}
.btn:hover { background: var(--bg); }
.btn.primary { background: var(--blue); color: #fff; border-color: var(--blue); }
.btn.primary:hover { background: #1e40af; }

/* Ofertas ya gestionadas: botón secundario gris/outline */
.btn.secondary {
  background: #f3f4f6;
  color: var(--text-muted);
  border-color: var(--border);
}
.btn.secondary:hover { background: #e5e7eb; }

/* ── Carta ── */
.carta-box {
  background: #f9fafb;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 16px;
  margin-top: 12px;
  font-size: 13px;
  line-height: 1.7;
  white-space: pre-wrap;
  font-family: Georgia, serif;
  color: #1f2937;
}

.carta-loading {
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 12px;
}

/* ── Modal de run en vivo ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }

.modal {
  background: #111827;
  border-radius: 12px;
  width: 640px;
  max-width: 95vw;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,.4);
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid #1f2937;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h2 { color: #fff; font-size: 15px; }

.modal-close {
  background: none;
  border: none;
  color: #9ca3af;
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
  padding: 2px 6px;
}
.modal-close:hover { color: #fff; }

.log-area {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  font-family: 'Fira Code', 'Cascadia Code', monospace;
  font-size: 12px;
  line-height: 1.6;
  min-height: 300px;
}

.log-line { color: #d1d5db; }
.log-line.error { color: #f87171; }
.log-line.done { color: #4ade80; font-weight: 600; margin-top: 8px; }

.modal-footer {
  padding: 12px 20px;
  border-top: 1px solid #1f2937;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.btn-modal-close {
  padding: 8px 16px;
  background: #374151;
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}
.btn-modal-close:hover { background: #4b5563; }

/* ── Panel lateral de cartas (slide-over) ── */
.panel-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.35);
  z-index: 90;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}
.panel-overlay.open { opacity: 1; pointer-events: all; }

.carta-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 520px;
  max-width: 92vw;
  background: var(--card-bg);
  box-shadow: -8px 0 30px rgba(0,0,0,.2);
  z-index: 95;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform .25s ease;
}
.carta-panel.open { transform: translateX(0); }

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.panel-header .modal-close { color: var(--text-muted); }
.panel-header .modal-close:hover { color: var(--text); }

.panel-titles { min-width: 0; }

.panel-title {
  font-size: 14px;
  font-weight: 600;
}

.panel-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
}

.panel-body .carta-box { margin-top: 0; }

.panel-footer {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
}

/* ── Móvil ── */
@media (max-width: 768px) {
  header {
    padding: 0 16px;
  }

  /* Sidebar pasa a tira horizontal bajo el header */
  .layout {
    flex-direction: column;
  }

  aside {
    width: 100%;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    overflow-y: visible;
  }

  .sidebar-section {
    display: flex;
    align-items: center;
    flex-shrink: 0;
    padding: 0;
  }

  .sidebar-label { display: none; }

  .run-btn {
    width: auto;
    margin-bottom: 0;
    white-space: nowrap;
  }

  .date-list {
    display: flex;
    gap: 6px;
    padding: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .date-item {
    flex-shrink: 0;
    gap: 6px;
    white-space: nowrap;
  }

  main {
    padding: 12px;
  }

  .stats-bar {
    flex-wrap: wrap;
    gap: 8px;
  }

  .stat-card {
    flex: 1;
    padding: 10px 12px;
  }

  .stat-card .stat-value {
    font-size: 18px;
    white-space: nowrap;
  }

  .filter-input { min-width: 100%; }
  .filter-select { flex: 1; }
  .filter-count { width: 100%; margin-left: 0; }

  .job-foot {
    flex-direction: column;
    align-items: stretch;
  }

  .estado-control { justify-content: stretch; }
  .estado-btn { flex: 1; }

  .job-actions { flex-direction: column; }
  .job-actions .btn { justify-content: center; }

  /* Panel de cartas a pantalla completa */
  .carta-panel {
    width: 100%;
    max-width: 100%;
  }

  .modal {
    max-height: 90vh;
    max-height: 90dvh;
  }

  .log-area { min-height: 200px; }
}
