:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --ink: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #1d4ed8;
  --primary-ink: #ffffff;
  --accent: #0ea5e9;
  --danger: #dc2626;
  --success: #16a34a;
  --warn: #d97706;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 1px 8px rgba(15, 23, 42, 0.05);
}

* { box-sizing: border-box; }

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

.hidden { display: none !important; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
  flex-wrap: wrap;
  gap: 8px;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand-home {
  text-decoration: none; color: var(--muted); font-size: 18px; line-height: 1;
  padding: 2px 4px; border-radius: 6px;
}
.brand-home:hover { background: var(--bg); color: var(--ink); }
.brand-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--primary); display: inline-block; }
.brand h1 { font-size: 18px; margin: 0; font-weight: 600; }
.brand h1 small { font-weight: 400; color: var(--muted); font-size: 13px; margin-left: 6px; }

.topbar-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.user-pill {
  font-size: 12px; color: var(--muted); padding: 6px 10px;
  background: var(--bg); border-radius: 20px; border: 1px solid var(--border);
}

.btn {
  border: 1px solid var(--border);
  background: var(--panel);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  color: var(--ink);
  text-decoration: none;
  display: inline-block;
}
.btn:hover { background: #f1f5f9; }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn.primary:hover { background: #1e40af; }
.btn.ghost { background: transparent; }
.btn.danger { background: transparent; color: var(--danger); border-color: #fecaca; }
.btn.danger:hover { background: #fef2f2; }

.filters {
  display: flex;
  gap: 10px;
  padding: 12px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.filters input, .filters select {
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 13px;
}
.filters input { flex: 1; max-width: 260px; }

.dashboard {
  padding: 16px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.dash-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}
.dash-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.dash-card .num { font-size: 20px; font-weight: 700; }
.dash-card .label { font-size: 12px; color: var(--muted); }

.dash-block h3 { font-size: 14px; margin: 0 0 8px; }
.cobros-list { display: flex; flex-direction: column; gap: 6px; }
.cobro-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px; border-radius: 8px; border: 1px solid var(--border);
  font-size: 13px;
}
.cobro-item.vencido { border-color: #fecaca; background: #fef2f2; }
.cobro-item.proximo { border-color: #fde68a; background: #fffbeb; }

.board {
  display: flex;
  gap: 14px;
  padding: 18px 24px;
  overflow-x: auto;
  align-items: flex-start;
}

.column {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 260px;
  min-width: 260px;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 220px);
}
.column-header {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.column-count {
  background: var(--bg);
  color: var(--muted);
  border-radius: 20px;
  padding: 1px 8px;
  font-size: 11px;
}
.column-body {
  padding: 8px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.column-body.dragover { background: #eff6ff; }

.card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  cursor: grab;
  font-size: 12.5px;
}
.card:active { cursor: grabbing; }
.card .card-cliente { font-weight: 600; margin-bottom: 4px; }
.card .card-marca {
  display: inline-block;
  font-size: 11px;
  background: #e0e7ff;
  color: #3730a3;
  border-radius: 20px;
  padding: 1px 8px;
  margin-bottom: 6px;
}
.card .card-oc {
  font-size: 11px;
  font-weight: 600;
  color: #334155;
  background: #f1f5f9;
  border-radius: 6px;
  padding: 2px 6px;
  display: inline-block;
  margin-bottom: 6px;
}
.card .card-valor { color: var(--muted); margin-bottom: 6px; }
.card .progress-row { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.card .progress-track {
  flex: 1;
  height: 5px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
}
.card .progress-fill { height: 100%; background: var(--primary); }
.card .progress-label { font-size: 10px; color: var(--muted); min-width: 30px; text-align: right; }
.card .card-tags { display: flex; gap: 4px; flex-wrap: wrap; }
.tag { font-size: 10px; padding: 1px 6px; border-radius: 20px; border: 1px solid var(--border); }
.tag.credito { background: #fff7ed; color: var(--warn); border-color: #fed7aa; }
.tag.pagado { background: #f0fdf4; color: var(--success); border-color: #bbf7d0; }
.tag.oc-ok { background: #eff6ff; color: var(--primary); border-color: #bfdbfe; }
.tag.oc-pendiente { background: #fef2f2; color: var(--danger); border-color: #fecaca; }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
}
.modal {
  background: var(--panel);
  border-radius: 12px;
  width: 620px;
  max-width: 92vw;
  max-height: 88vh;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow);
}
.modal.small { width: 460px; }
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 16px; margin: 0; }
.modal-close { border: none; background: none; font-size: 20px; cursor: pointer; color: var(--muted); }
.modal-body { padding: 16px 18px; overflow-y: auto; }
.modal-footer {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 18px; border-top: 1px solid var(--border);
}
.spacer { flex: 1; }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 14px;
}
.form-grid label, .notas-label {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 12px; color: var(--muted);
}
.form-grid input, .form-grid select, .notas-label textarea,
.oc-box input, .modal-body textarea {
  font-size: 13px; color: var(--ink);
  padding: 7px 9px; border: 1px solid var(--border); border-radius: 7px;
  font-family: inherit;
}
.notas-label { margin-top: 10px; }
.checkbox-label { flex-direction: row !important; align-items: center; gap: 6px !important; font-size: 13px; color: var(--ink) !important; }

.oc-box, .historial-box {
  margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border);
}
.oc-box h3, .historial-box h3 { font-size: 13px; margin: 0 0 8px; }
.oc-info { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.oc-info a { color: var(--primary); }

#historialLista { list-style: none; padding: 0; margin: 0; font-size: 12px; color: var(--muted); }
#historialLista li { padding: 3px 0; }

/* Login */
.login-body {
  display: flex; align-items: center; justify-content: center;
  height: 100vh;
}
.login-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px 26px;
  width: 320px;
  box-shadow: var(--shadow);
  text-align: center;
}
.login-box h1 { font-size: 18px; margin: 0 0 2px; }
.login-sub { color: var(--muted); font-size: 12px; margin: 0 0 16px; }
.login-box label {
  display: flex; flex-direction: column; gap: 4px; text-align: left;
  font-size: 12px; color: var(--muted); margin-bottom: 10px;
}
.login-box input {
  font-size: 13px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 7px;
}
.login-error {
  background: #fef2f2; color: var(--danger); border: 1px solid #fecaca;
  border-radius: 8px; padding: 8px 10px; font-size: 12px; margin-bottom: 12px;
}

/* Landing (home) */
.home-main { padding: 40px 24px; max-width: 900px; margin: 0 auto; }
.home-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 18px; }
.home-card {
  display: block; background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  padding: 24px; text-decoration: none; color: var(--ink); box-shadow: var(--shadow);
  transition: transform 0.15s, box-shadow 0.15s;
}
.home-card:hover { transform: translateY(-2px); box-shadow: 0 4px 16px rgba(15,23,42,0.1); }
.home-card-icon { font-size: 28px; margin-bottom: 10px; }
.home-card h2 { font-size: 16px; margin: 0 0 6px; }
.home-card p { font-size: 12.5px; color: var(--muted); margin: 0; }
.home-card.disabled { opacity: 0.55; cursor: default; }
.home-card.disabled:hover { transform: none; box-shadow: var(--shadow); }

/* Usuarios */
.usuarios-list { display: flex; flex-direction: column; gap: 6px; }
.usuario-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 12.5px;
  flex-wrap: wrap; gap: 6px;
}
.usuario-item .u-info { display: flex; flex-direction: column; }
.usuario-item .u-info small { color: var(--muted); }
.usuario-item .u-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.usuario-item .u-actions select {
  font-size: 12px; padding: 5px 6px; border: 1px solid var(--border); border-radius: 6px;
}

/* Pestañas (subnav) */
.subnav {
  display: flex; gap: 4px; padding: 10px 24px 0; background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.tab-btn {
  border: none; background: transparent; padding: 8px 14px; font-size: 13px;
  color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent;
}
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

/* Valor + moneda */
.valor-moneda-row { display: flex; gap: 6px; }
.valor-moneda-row input { flex: 1; }
.valor-moneda-row select { width: 78px; }

/* Etapas completadas (modal) */
.etapas-completadas-box { display: flex; flex-direction: column; gap: 6px; }
.etapa-completada-item {
  display: flex !important; flex-direction: row !important; align-items: center; gap: 8px !important;
  font-size: 13px; color: var(--ink) !important;
}
.etapas-completadas-nota { font-size: 11.5px; color: var(--muted); margin-top: 8px; }

/* Vista de lista del Pipeline (tabla) */
.pv-lista { padding: 18px 24px; }
.tabla-tareas {
  width: 100%; border-collapse: collapse; background: var(--panel);
  border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
  font-size: 12.5px;
}
.tabla-tareas thead th {
  text-align: left; padding: 10px 12px; background: var(--bg);
  border-bottom: 1px solid var(--border); font-weight: 600; color: var(--muted);
  font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.02em;
}
.tabla-tareas tbody tr { border-bottom: 1px solid var(--border); cursor: pointer; }
.tabla-tareas tbody tr:hover { background: #f8fafc; }
.tabla-tareas tbody tr:last-child { border-bottom: none; }
.pv-tabla td { padding: 8px 12px; vertical-align: middle; }

.pv-mini-progreso { display: flex; align-items: center; gap: 6px; }
.pv-mini-ring { width: 34px; height: 34px; transform: rotate(-90deg); flex-shrink: 0; }
.pv-ring-bg { fill: none; stroke: var(--border); stroke-width: 4; }
.pv-ring-fg { fill: none; stroke: var(--primary); stroke-width: 4; stroke-linecap: round; transition: stroke-dashoffset 0.3s; }
.pv-ring-fg.completo { stroke: var(--success); }

.pv-cobrado-check { display: flex; justify-content: center; cursor: pointer; }
.pv-cobrado-check input { width: 17px; height: 17px; cursor: pointer; accent-color: var(--success); }

.pv-etapa-trigger {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  min-width: 190px; padding: 7px 10px; border-radius: 8px; border: 1px solid #1e3a8a;
  background: #1e3a8a; color: #fff; font-size: 12.5px; font-weight: 600; cursor: pointer;
}
.pv-etapa-trigger:hover { background: #1c3577; }
.pv-etapa-trigger-arrow { font-size: 10px; opacity: 0.85; }

.pv-etapa-menu {
  position: fixed; z-index: 300; background: var(--panel); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: var(--shadow); overflow-y: auto; max-height: 260px;
}
.pv-etapa-opcion {
  display: block; width: 100%; text-align: left; padding: 9px 12px; font-size: 12.5px;
  border: none; border-bottom: 1px solid var(--border); background: var(--panel);
  color: var(--ink); cursor: pointer;
}
.pv-etapa-opcion:last-child { border-bottom: none; }
.pv-etapa-opcion:hover { background: #f1f5f9; }
.pv-etapa-opcion.completada { background: #f0fdf4; color: var(--success); font-weight: 600; }
.pv-etapa-opcion.completada:hover { background: #dcfce7; }
.pv-etapa-opcion.actual { background: #1e3a8a; color: #fff; font-weight: 700; cursor: default; }
.pv-etapa-opcion.actual:hover { background: #1e3a8a; }

.tag.vencido { background: #fef2f2; color: var(--danger); border-color: #fecaca; }
.tag.proximo-tag { background: #fffbeb; color: var(--warn); border-color: #fde68a; }

/* Auditoria */
.auditoria-list { display: flex; flex-direction: column; gap: 6px; max-height: 60vh; overflow-y: auto; }
.auditoria-item {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: baseline;
  padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 12px;
}
.auditoria-item .a-fecha { color: var(--muted); min-width: 140px; }
.auditoria-item .a-usuario { font-weight: 600; }
.auditoria-item .a-accion { color: var(--primary); }
.auditoria-item .a-detalle { color: var(--muted); flex-basis: 100%; }

/* ===================== Gestion de Actividades ===================== */

.calendar-toolbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 24px 0;
}
.calendar-nav { display: flex; align-items: center; gap: 8px; }
.calendar-mes-label { font-size: 14px; font-weight: 600; min-width: 150px; text-align: center; }
.calendar-filtros { display: flex; align-items: center; gap: 8px; }
.calendar-filtros select {
  padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px;
}

.calendar-weekdays {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px;
  padding: 14px 24px 4px; font-size: 11px; font-weight: 600; color: var(--muted); text-align: center;
}
.calendar-grid {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px;
  padding: 0 24px 24px;
}
.calendar-day {
  border: 1px solid var(--border); border-radius: 8px; min-height: 90px;
  padding: 6px; cursor: pointer; transition: border-color 0.15s ease;
}
.calendar-day:hover { border-color: var(--primary); }
.calendar-day.otro-mes { opacity: 0.4; }
.calendar-day.hoy { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
.calendar-day-num { font-size: 12px; font-weight: 600; color: var(--muted); }
.calendar-day-events { display: flex; flex-direction: column; gap: 3px; overflow-y: auto; max-height: 70px; margin-top: 4px; }
.event-chip {
  font-size: 10.5px; padding: 2px 6px; border-radius: 6px; cursor: pointer; line-height: 1.4;
}
.event-chip.general { background: #dbeafe; color: #1e40af; }
.event-chip.empleado { background: #ede9fe; color: #5b21b6; }
.event-chip:hover { filter: brightness(0.95); }

.tag.prioridad-alta { background: #fef2f2; color: var(--danger); border-color: #fecaca; }
.tag.prioridad-media { background: #fff7ed; color: var(--warn); border-color: #fed7aa; }
.tag.prioridad-baja { background: #f0fdf4; color: var(--success); border-color: #bbf7d0; }
.tag.sin-leer { background: #eff6ff; color: var(--primary); border-color: #bfdbfe; font-weight: 600; }
.tag.leida-ok { background: #f0fdf4; color: var(--success); border-color: #bbf7d0; }
.tag.enviado-correo { background: #eff6ff; color: var(--primary); border-color: #bfdbfe; }

.adjuntos-lista { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; font-size: 12px; }
.adjunto-item a { color: var(--primary); }

.empleados-resumen { display: flex; flex-direction: column; gap: 6px; }
.empleado-resumen-item {
  display: flex; gap: 14px; align-items: center; font-size: 12.5px;
  padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px;
}
.empleado-nombre { font-weight: 600; }

.vista-switcher { display: flex; gap: 6px; padding: 14px 24px 0; flex-wrap: wrap; }
.vista-btn {
  padding: 6px 12px; border: 1px solid var(--border); border-radius: 20px;
  background: #fff; font-size: 12.5px; cursor: pointer;
}
.vista-btn:hover { background: #f1f5f9; }
.vista-btn.active { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }

.fila-vencida { border-left: 3px solid var(--danger); }

.lista-container { padding: 16px 24px; overflow-x: auto; }

.estado-box {
  display: flex; align-items: center; gap: 12px; margin-bottom: 12px;
}
.estado-box label { flex-direction: row !important; align-items: center; gap: 8px !important; font-size: 12px; color: var(--muted); }
.estado-box select { font-size: 13px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 7px; }
.lectura-info { font-size: 12px; padding: 3px 8px; border-radius: 20px; }
.lectura-info.leida { background: #f0fdf4; color: var(--success); }
.lectura-info.sin-leer { background: #eff6ff; color: var(--primary); font-weight: 600; }

.resp-detalle {
  display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; margin-bottom: 10px;
}
.resp-detalle strong { color: var(--muted); font-weight: 600; margin-right: 4px; }

/* Vista por empleado (checklist) */
.empleado-vista { padding: 16px 24px; display: flex; flex-direction: column; gap: 16px; }
.empleado-bloque { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.empleado-bloque-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px; background: #f8fafc; font-size: 13px;
}
.empleado-bloque-count { font-size: 11.5px; color: var(--muted); }
.empleado-bloque-lista { display: flex; flex-direction: column; }
.checklist-item {
  display: flex; align-items: center; gap: 8px; padding: 9px 14px;
  border-top: 1px solid var(--border); font-size: 12.5px; cursor: pointer;
}
.checklist-item:hover { background: #f8fafc; }
.checklist-estado { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; background: var(--muted); }
.checklist-estado.estado-pendiente { background: var(--warn); }
.checklist-estado.estado-en_progreso { background: var(--primary); }
.checklist-estado.estado-finalizada { background: var(--success); }
.checklist-titulo { flex: 1; }
.checklist-fecha { font-size: 11px; color: var(--muted); }

/* Vista agenda por urgencia */
.agenda-vista { padding: 16px 24px; display: flex; flex-direction: column; gap: 16px; }
.agenda-bloque { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.agenda-bloque-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px; background: #f8fafc; font-size: 13px; font-weight: 600;
}
.agenda-bloque-lista { display: flex; flex-direction: column; }

/* Vista linea de tiempo */
.linea-vista { padding: 16px 24px; display: flex; flex-direction: column; gap: 10px; }
.linea-header { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.linea-fila { display: flex; flex-direction: column; gap: 4px; cursor: pointer; }
.linea-label { font-size: 12.5px; }
.linea-track { position: relative; height: 14px; background: #f1f5f9; border-radius: 7px; }
.linea-hoy { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--danger); }
.linea-barra {
  position: absolute; top: 0; bottom: 0; border-radius: 7px; background: var(--primary); opacity: 0.85;
}
.linea-barra.estado-finalizada { background: var(--success); }
.linea-barra.estado-pendiente { background: var(--warn); }
